first commit
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
/**
|
||||
* WP File Download
|
||||
*
|
||||
* @package WP File Download
|
||||
* @author Joomunited
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
use Joomunited\WPFramework\v1_0_4\Model;
|
||||
|
||||
defined( 'ABSPATH' ) || die();
|
||||
|
||||
class wpfdModelCategories extends Model
|
||||
{
|
||||
/**
|
||||
* get all categories by parent category
|
||||
* @param $idcategory
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCategories($idcategory){
|
||||
$user = wp_get_current_user();
|
||||
$roles = array();
|
||||
foreach($user->roles as $role){
|
||||
$roles[] = strtolower($role);
|
||||
}
|
||||
$result = array();
|
||||
$categories = get_terms( 'wpfd-category', 'orderby=term_group&hierarchical=1&hide_empty=0&parent='.$idcategory);
|
||||
if($categories) {
|
||||
foreach ($categories as $category) {
|
||||
$category->name=html_entity_decode($category->name);
|
||||
$term_meta = get_option( "taxonomy_".$category->term_id );
|
||||
$cat_roles = isset($term_meta['roles'])? (array)$term_meta['roles']: array();
|
||||
$cat_access= isset($term_meta['access'])? (int)$term_meta['access']: 0;
|
||||
$params = json_decode($category->description, true);
|
||||
$allows_single = false;
|
||||
|
||||
if (isset($params['canview']) && $params['canview'] != '') {
|
||||
if (($params['canview'] != 0 ) && $params['canview'] == $user->ID) {
|
||||
$allows_single = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($cat_access == 1) {
|
||||
$allows = array_intersect($roles, $cat_roles);
|
||||
if($allows || $allows_single) $result[] = $category;
|
||||
}else {
|
||||
$result[] = $category;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stripslashes_deep($result);
|
||||
}
|
||||
|
||||
public function getSubCategoriesCount($idcategory) {
|
||||
$count = wp_count_terms( 'wpfd-category', 'orderby=term_group&hierarchical=1&hide_empty=0&parent='.$idcategory);
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get level categories
|
||||
* @return array
|
||||
*/
|
||||
public function getLevelCategories(){
|
||||
|
||||
$results = array();
|
||||
$root = new stdClass();
|
||||
$root->level = 0;
|
||||
$root->term_id = 0;
|
||||
$this->getCategoriesRecursive($root,$results);
|
||||
|
||||
$user = wp_get_current_user();
|
||||
$roles = array();
|
||||
foreach($user->roles as $role){
|
||||
$roles[] = strtolower($role);
|
||||
}
|
||||
if ($results) {
|
||||
foreach ($results as $key => $category) {
|
||||
$cat = get_term($category->term_id,'wpfd-category');
|
||||
$params = array();
|
||||
if ($cat->description != '') {
|
||||
$params = json_decode($cat->description, true);
|
||||
}
|
||||
|
||||
$term_meta = get_option( "taxonomy_".$category->term_id );
|
||||
$cat_roles = isset($term_meta['roles'])? (array)$term_meta['roles']: array();
|
||||
$cat_access= isset($term_meta['access'])? (int)$term_meta['access']: 0;
|
||||
if (isset($params['canview']) && ($params['canview'] == '')) {
|
||||
$params['canview'] = 0;
|
||||
}
|
||||
if($cat_access == 1) {
|
||||
$allows = array_intersect($roles, $cat_roles);
|
||||
|
||||
if (isset($params['canview']) && $params['canview'] != 0 && !count($cat_roles)) {
|
||||
if ((int)$params['canview'] != $user->ID) {
|
||||
unset($results[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
} else if (isset($params['canview']) && $params['canview'] != 0 && count($cat_roles)) {
|
||||
if ((int)$params['canview'] == $user->ID || !empty($allows)) {
|
||||
|
||||
} else {
|
||||
unset($results[$key]);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (empty($allows)) {
|
||||
unset($results[$key]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$results[$key] = apply_filters('wpfd_level_category', $category);
|
||||
$results[$key] = apply_filters('wpfd_level_category_dropbox',$category);
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* get categories recursive
|
||||
* @param $cat
|
||||
* @param $results
|
||||
*/
|
||||
public function getCategoriesRecursive($cat, &$results) {
|
||||
if(!is_array($results)){$results=array();}
|
||||
$categories = get_terms( 'wpfd-category', 'orderby=term_group&hierarchical=1&hide_empty=0&parent='.$cat->term_id );
|
||||
if($categories) {
|
||||
foreach ($categories as $category) {
|
||||
$category->level = $cat->level + 1;
|
||||
$results[] = $category;
|
||||
$this->getCategoriesRecursive($category,$results);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get child categories
|
||||
* @param $catid
|
||||
* @return array
|
||||
*/
|
||||
public function getChildCategories($catid) {
|
||||
$results=array();
|
||||
|
||||
$categories = get_terms( 'wpfd-category', 'orderby=term_group&hierarchical=1&hide_empty=0&parent='.$catid );
|
||||
if($categories) {
|
||||
foreach ($categories as $category) {
|
||||
$results[] = $category;
|
||||
$this->getCategoriesRecursive($category,$results);
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getParentsCat($catid, $displaycat) {
|
||||
$results = array();
|
||||
$results[] = $catid;
|
||||
$this->getParentCat($catid, $results, $displaycat);
|
||||
return $results;
|
||||
}
|
||||
public function getParentCat($catid, &$results, $displaycat) {
|
||||
|
||||
if ($catid != 0) {
|
||||
$cat = get_term($catid,'wpfd-category');
|
||||
if ($cat->parent !=0 && $cat->parent != $displaycat) {
|
||||
$results[] = $cat->parent;
|
||||
$this->getParentCat($cat->parent, $results, $displaycat);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* WP File Download
|
||||
*
|
||||
* @package WP File Download
|
||||
* @author Joomunited
|
||||
* @version 1.0
|
||||
*/
|
||||
use Joomunited\WPFramework\v1_0_4\Application;
|
||||
use Joomunited\WPFramework\v1_0_4\Model;
|
||||
|
||||
defined( 'ABSPATH' ) || die();
|
||||
|
||||
class wpfdModelCategory extends Model {
|
||||
|
||||
/**
|
||||
* Get a category info
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public function getCategory($id){
|
||||
|
||||
$result = get_term($id,'wpfd-category');
|
||||
$app = Application::getInstance('wpfd', __FILE__);
|
||||
$modelConfig = $this->getInstance('Config');
|
||||
$main_config = $modelConfig->getGlobalConfig();
|
||||
|
||||
if(!empty($result) && !is_wp_error($result)){
|
||||
$term_meta = get_option( "taxonomy_$id" );
|
||||
$result->name=html_entity_decode($result->name);
|
||||
if ($result->description == 'null' || $result->description == '') {
|
||||
$result->params = array();
|
||||
} else {
|
||||
$result->params = json_decode($result->description,true);
|
||||
}
|
||||
|
||||
if(!isset($result->params['theme'])) {
|
||||
$result->params['theme'] = $main_config['defaultthemepercategory'];
|
||||
}
|
||||
|
||||
$ordering = isset($result->params['ordering'])? $result->params['ordering']: 'title';
|
||||
$orderingdir = isset($result->params['orderingdir'])? $result->params['orderingdir']: 'desc';
|
||||
|
||||
if ($main_config['catparameters'] == '0') {
|
||||
$result->params = array_merge( $result->params, $modelConfig->getConfig($main_config['defaultthemepercategory']) );
|
||||
$result->params['theme'] = $main_config['defaultthemepercategory'];
|
||||
}
|
||||
if(!empty($result->parent)) {
|
||||
$parentCat = get_term($result->parent,'wpfd-category');
|
||||
if(!empty($parentCat) && !is_wp_error($parentCat)){
|
||||
$result->parent_title = $parentCat->name;
|
||||
}
|
||||
}
|
||||
$result->roles = isset($term_meta['roles'])? (array)$term_meta['roles']: array();
|
||||
$result->access= isset($term_meta['access'])? (int)$term_meta['access']: 0;
|
||||
$result->ordering = $ordering;
|
||||
$result->orderingdir = $orderingdir;
|
||||
}else {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* WP File Download
|
||||
*
|
||||
* @package WP File Download
|
||||
* @author Joomunited
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
use Joomunited\WPFramework\v1_0_4\Model;
|
||||
|
||||
defined('ABSPATH') || die();
|
||||
|
||||
class WpfdModelConfig extends Model
|
||||
{
|
||||
/**
|
||||
* Get global configuration
|
||||
* @return array
|
||||
*/
|
||||
public function getGlobalConfig()
|
||||
{
|
||||
|
||||
$defaultConfig = array('allowedext' => '7z,ace,bz2,dmg,gz,rar,tgz,zip,csv,doc,docx,html,key,keynote,odp,ods,odt,pages,pdf,pps,ppt,pptx,rtf,tex,txt,xls,xlsx,xml,bmp,exif,gif,ico,jpeg,jpg,png,psd,tif,tiff,aac,aif,aiff,alac,amr,au,cdda,flac,m3u,m4a,m4p,mid,mp3,mp4,mpa,ogg,pac,ra,wav,wma,3gp,asf,avi,flv,m4v,mkv,mov,mpeg,mpg,rm,swf,vob,wmv,css,img');
|
||||
$defaultConfig['deletefiles'] = 0;
|
||||
$defaultConfig['catparameters'] = 1;
|
||||
$defaultConfig['defaultthemepercategory'] = 'default';
|
||||
$defaultConfig['date_format'] = 'd-m-Y';
|
||||
$defaultConfig['use_google_viewer'] = 'lightbox';
|
||||
$defaultConfig['extension_viewer'] = 'png,jpg,pdf,ppt,doc,xls,dxf,ps,eps,xps,psd,tif,tiff,bmp,svg,pages,ai,dxf,ttf,txt,mp3,mp4';
|
||||
$defaultConfig['show_file_import'] = 0;
|
||||
$defaultConfig['uri'] = "download";
|
||||
$defaultConfig['ga_download_tracking'] = 0;
|
||||
$defaultConfig['plain_text_search'] = 0;
|
||||
$defaultConfig['useeditor'] = 0;
|
||||
$defaultConfig['restrictfile'] = 0;
|
||||
$defaultConfig['enablewpfd'] = 0;
|
||||
$defaultConfig['shortcodecat'] = 1;
|
||||
$defaultConfig['paginationnunber'] = 100;
|
||||
$defaultConfig['open_pdf_in'] = 0;
|
||||
$config = get_option('_wpfd_global_config', $defaultConfig);
|
||||
$config = array_merge($defaultConfig,$config);
|
||||
return (array)$config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config of a theme
|
||||
* @param string $theme_name
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig($theme_name = '')
|
||||
{
|
||||
|
||||
if ($theme_name != '') {
|
||||
$theme = $theme_name;
|
||||
} else {
|
||||
$theme = get_option('_wpfd_theme', 'default');
|
||||
}
|
||||
|
||||
$deaults= array('default'=>'{"marginleft":"10","marginright":"10", "margintop":"10", "marginbottom":"10", "showsize":"1","showtitle":"1","croptitle":"0","showdescription":"1","showversion":"1","showhits":"1","showdownload":"1","bgdownloadlink":"#76bc58","colordownloadlink":"#ffffff","showdateadd":"1","showdatemodified":"0","showsubcategories":"1","showcategorytitle":"1","showbreadcrumb":"1","showfoldertree":"0"}',
|
||||
'ggd'=>'{"ggd_marginleft":"10","ggd_marginright":"10", "ggd_margintop":"10", "ggd_marginbottom":"10","ggd_croptitle":"0", "ggd_showsize":"1","ggd_showtitle":"1","ggd_showdescription":"1","ggd_showversion":"1","ggd_showhits":"1","ggd_showdownload":"1","ggd_bgdownloadlink":"#76bc58","ggd_colordownloadlink":"#ffffff","ggd_showdateadd":"1","ggd_showdatemodified":"0","ggd_showsubcategories":"1","ggd_showcategorytitle":"1","ggd_showbreadcrumb":"1","ggd_showfoldertree":"0"}',
|
||||
'table'=>'{"table_styling":"1","table_stylingmenu":"1","table_showsize":"1","table_showtitle":"1","table_showdescription":"1","table_showversion":"1","table_showhits":"1","table_showdownload":"1","table_croptitle":"0","table_bgdownloadlink":"#76bc58","table_colordownloadlink":"#ffffff","table_showdateadd":"1","table_showdatemodified":"0","table_showsubcategories":"1","table_showcategorytitle":"1","table_showbreadcrumb":"1","table_showfoldertree":"0"}',
|
||||
'tree'=>'{"tree_showbgtitle":"1","tree_showtreeborder":"1","tree_showsize":"1","tree_croptitle":"0","tree_showtitle":"1","tree_showdescription":"1","tree_showversion":"1","tree_showhits":"1","tree_showdownload":"1","tree_bgdownloadlink":"#76bc58","tree_colordownloadlink":"#ffffff","tree_showdateadd":"1","tree_showdatemodified":"0","tree_showsubcategories":"1","tree_showcategorytitle":"1"}',
|
||||
);
|
||||
if(!isset($deaults[$theme])) {
|
||||
$deaults[$theme]= "";
|
||||
}
|
||||
$theme_params = get_option('_wpfd_' . $theme . '_config', $deaults[$theme]);
|
||||
if (is_string($theme_params)) {
|
||||
$theme_params = json_decode($theme_params, true);
|
||||
}
|
||||
|
||||
return $theme_params;
|
||||
}
|
||||
|
||||
/**
|
||||
* get config for single file
|
||||
* @return array
|
||||
*/
|
||||
public function getFileConfig()
|
||||
{
|
||||
|
||||
$defaultConfig = array(
|
||||
'singlebg' => '#444444',
|
||||
'singlehover' => '#888888',
|
||||
'singlefontcolor' => '#ffffff',
|
||||
);
|
||||
|
||||
$config = get_option('_wpfd_global_file_config', $defaultConfig);
|
||||
|
||||
return (array)$config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get search config
|
||||
* @return array
|
||||
*/
|
||||
public function getSearchConfig(){
|
||||
|
||||
$defaultConfig = array(
|
||||
'search_page' => (int)get_option( '_wpfd_search_page_id' ),
|
||||
'plain_text_search' => 0,
|
||||
'cat_filter' => 1,
|
||||
'tag_filter' => 1,
|
||||
'display_tag' => 'searchbox',
|
||||
'create_filter' => 1,
|
||||
'update_filter' => 1,
|
||||
'file_per_page' => 15,
|
||||
'shortcode' => '[wpfd_search]'
|
||||
);
|
||||
|
||||
$config = get_option('_wpfd_global_search_config', $defaultConfig);
|
||||
|
||||
return (array)$config;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/**
|
||||
* WP File Download
|
||||
*
|
||||
* @package WP File Download
|
||||
* @author Joomunited
|
||||
* @version 1.0
|
||||
*/
|
||||
use Joomunited\WPFramework\v1_0_4\Application;
|
||||
use Joomunited\WPFramework\v1_0_4\Model;
|
||||
|
||||
defined('ABSPATH') || die();
|
||||
|
||||
class WpfdModelFile extends Model
|
||||
{
|
||||
|
||||
function getFileCategory($id_file) {
|
||||
$catid = 0;
|
||||
$term_list = wp_get_post_terms($id_file, 'wpfd-category', array("fields" => "ids"));
|
||||
|
||||
if (!is_wp_error($term_list)) {
|
||||
$catid = $term_list[0];
|
||||
}
|
||||
|
||||
return $catid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file info by ID
|
||||
* @param $id_file
|
||||
* @return mixed
|
||||
*/
|
||||
function getFile($id_file,$rootcat=0)
|
||||
{
|
||||
$app = Application::getInstance('wpfd', __FILE__);
|
||||
$modelConfig = $this->getInstance('config');
|
||||
$params = $modelConfig->getGlobalConfig();
|
||||
|
||||
|
||||
$user = wp_get_current_user();
|
||||
$roles = array();
|
||||
foreach ($user->roles as $role) {
|
||||
$roles[] = strtolower($role);
|
||||
}
|
||||
|
||||
$row = get_post($id_file, OBJECT);
|
||||
|
||||
if ($row == false || $row->post_status == 'private' || $row->post_date > current_time('mysql')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$row->title = $row->post_title;
|
||||
$row->description = trim($row->post_excerpt);
|
||||
|
||||
$row->created = mysql2date(wpfdBase::loadValue($params, 'date_format', get_option('date_format')), $row->post_date);
|
||||
$row->modified = mysql2date(wpfdBase::loadValue($params, 'date_format', get_option('date_format')), $row->post_modified);
|
||||
|
||||
$metadata = get_post_meta($id_file, '_wpfd_file_metadata', true);
|
||||
if (count($metadata)) {
|
||||
foreach ($metadata as $key => $value) {
|
||||
$row->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$term_list = wp_get_post_terms($id_file, 'wpfd-category', array("fields" => "ids"));
|
||||
$wpfd_term = get_term($term_list[0], 'wpfd-category');
|
||||
$row->catname = sanitize_title($wpfd_term->name);
|
||||
$row->cattitle = $wpfd_term->name;
|
||||
if (!is_wp_error($term_list)) {
|
||||
$row->catid = $term_list[0];
|
||||
} else {
|
||||
$row->catid = 0;
|
||||
}
|
||||
|
||||
$remote_url = isset($metadata['remote_url']) ? $metadata['remote_url'] : false;
|
||||
$viewer_type = wpfdBase::loadValue($params, 'use_google_viewer', 'lightbox');
|
||||
|
||||
$extension_viewer = explode(',', wpfdBase::loadValue($params, 'extension_viewer', 'pdf,ppt,doc,xls,dxf,ps,eps,xps,psd,tif,tiff,bmp,svg,pages,ai,dxf,ttf,txt,mp3,mp4'));
|
||||
$extension_viewer = array_map('trim', $extension_viewer);
|
||||
|
||||
if ($viewer_type != 'no' &&
|
||||
in_array($row->ext, $extension_viewer)
|
||||
&& ($remote_url == false)
|
||||
) {
|
||||
$row->viewer_type = $viewer_type;
|
||||
|
||||
$modelCategory = Model::getInstance('category');
|
||||
//check access
|
||||
$category = $modelCategory->getCategory($row->catid);
|
||||
$rootcategory = $modelCategory->getCategory($rootcat);
|
||||
if (empty($category) || is_wp_error($category)) return;
|
||||
|
||||
$roles = array();
|
||||
foreach ($user->roles as $role) {
|
||||
$roles[] = strtolower($role);
|
||||
}
|
||||
$allows = array_intersect($roles, $category->roles);
|
||||
|
||||
if (wpfdHelperFile::isMediaFile($row->ext)) {
|
||||
if ($category->access == 1) {
|
||||
if (!empty($allows)) {
|
||||
$row->viewerlink = wpfdHelperFile::getMediaViewerUrl($row->ID, $row->ext);
|
||||
}
|
||||
} else {
|
||||
$row->viewerlink = wpfdHelperFile::getMediaViewerUrl($row->ID, $row->ext);
|
||||
}
|
||||
|
||||
} else {
|
||||
$modelTokens = Model::getInstance('tokens');
|
||||
$sessionToken = isset($_SESSION['wpfdToken']) ? $_SESSION['wpfdToken'] : null;
|
||||
if ($sessionToken === null) {
|
||||
$token = $modelTokens->createToken();
|
||||
$_SESSION['wpfdToken'] = $token;
|
||||
} else {
|
||||
$tokenId = $modelTokens->tokenExists($sessionToken);
|
||||
if ($tokenId) {
|
||||
$modelTokens->updateToken($tokenId);
|
||||
$token = $sessionToken;
|
||||
} else {
|
||||
$token = $modelTokens->createToken();
|
||||
$_SESSION['wpfdToken'] = $token;
|
||||
}
|
||||
}
|
||||
if ($category->access == 1) {
|
||||
if (!empty($allows)) {
|
||||
$row->viewerlink = wpfdHelperFile::getViewerUrl($row->ID, $row->catid, $token);
|
||||
}
|
||||
} else {
|
||||
$row->viewerlink = wpfdHelperFile::getViewerUrl($row->ID, $row->catid, $token);
|
||||
}
|
||||
|
||||
}
|
||||
//crop file titles
|
||||
$row->crop_title = $row->post_title;
|
||||
if ($rootcat){
|
||||
$row->crop_title = wpfdBase::cropTitle($rootcategory->params,$rootcategory->params['theme'], $row->post_title);
|
||||
}else{
|
||||
$row->crop_title = wpfdBase::cropTitle($category->params,$category->params['theme'], $row->post_title);
|
||||
}
|
||||
}
|
||||
|
||||
$open_pdf_in = wpfdBase::loadValue($params, 'open_pdf_in', 0) ;
|
||||
|
||||
if ($open_pdf_in == 1 && $row->ext == 'pdf') {
|
||||
$row->openpdflink = wpfdHelperFile::getPdfUrl($row->ID,$row->catid,$token). '&preview=1';
|
||||
}
|
||||
|
||||
$config = get_option('_wpfd_global_config');
|
||||
if (empty($config) || empty($config['uri'])) {
|
||||
$seo_uri = 'download';
|
||||
} else {
|
||||
$seo_uri = $config['uri'];
|
||||
}
|
||||
$row->seouri = $seo_uri;
|
||||
|
||||
$perlink = get_option('permalink_structure');
|
||||
$rewrite_rules = get_option('rewrite_rules');
|
||||
if (!empty($rewrite_rules)) {
|
||||
if (strpos($perlink, 'index.php')) {
|
||||
$row->linkdownload = get_site_url() . '/index.php/' . $seo_uri . '/' . $row->catid . '/' . $row->catname . '/' . $row->ID . '/' . $row->post_name;
|
||||
} else {
|
||||
$row->linkdownload = get_site_url() . '/' . $seo_uri . '/' . $row->catid . '/' . $row->catname . '/' . $row->ID . '/' . $row->post_name;
|
||||
}
|
||||
if (isset($row->ext) && $row->ext) {
|
||||
$row->linkdownload .= '.' . $row->ext;
|
||||
};
|
||||
} else {
|
||||
$row->linkdownload = admin_url('admin-ajax.php') . '?juwpfisadmin=false&action=wpfd&task=file.download&wpfd_category_id=' . $row->catid . '&wpfd_file_id=' . $row->ID;
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* get full info for file
|
||||
* @param $id_file
|
||||
* @return bool
|
||||
*/
|
||||
function getFullFile($id_file)
|
||||
{
|
||||
$app = Application::getInstance('wpfd');
|
||||
$modelConfig = $this->getInstance('config');
|
||||
$params = $modelConfig->getGlobalConfig();
|
||||
|
||||
$row = get_post($id_file, OBJECT);
|
||||
if ($row === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
require_once $app->getPath() . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'wpfdBase.php';
|
||||
|
||||
$ob = new stdClass();
|
||||
$ob->ID = $row->ID ;
|
||||
$ob->post_name = $row->post_name ;
|
||||
$ob->title = $row->post_title;
|
||||
$ob->description = $row->post_excerpt;
|
||||
$ob->created = mysql2date(wpfdBase::loadValue($params, 'date_format', get_option('date_format')), $row->post_date);
|
||||
$ob->modified = mysql2date(wpfdBase::loadValue($params, 'date_format', get_option('date_format')), $row->post_modified);
|
||||
$metadata = get_post_meta($id_file, '_wpfd_file_metadata', true);
|
||||
if (count($metadata)) {
|
||||
foreach ($metadata as $key => $value) {
|
||||
$ob->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$term_list = wp_get_post_terms($id_file, 'wpfd-category', array("fields" => "ids"));
|
||||
if (!is_wp_error($term_list)) {
|
||||
$ob->catid = $term_list[0];
|
||||
} else {
|
||||
$ob->catid = 0;
|
||||
}
|
||||
|
||||
return $ob;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* increase hit for file
|
||||
* @param $id_file
|
||||
* @return bool
|
||||
*/
|
||||
public function hit($id_file)
|
||||
{
|
||||
|
||||
$metadata = get_post_meta($id_file, '_wpfd_file_metadata', true);
|
||||
$hits = (int)$metadata['hits'];
|
||||
$metadata['hits'] = $hits + 1;
|
||||
update_post_meta($id_file, '_wpfd_file_metadata', $metadata);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a file for statistic when downloading file
|
||||
* @param $file_id
|
||||
* @param $date
|
||||
*/
|
||||
public function addChart($file_id, $date)
|
||||
{
|
||||
global $wpdb;
|
||||
$query = "INSERT INTO {$wpdb->prefix}wpfd_statistics (related_id,type,date,count) VALUES (" . esc_sql($file_id) . ",'default','" . esc_sql($date) . "',1)";
|
||||
$wpdb->query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add file to chart
|
||||
* @param $file_id
|
||||
* @return bool
|
||||
*/
|
||||
public function addCountChart($file_id)
|
||||
{
|
||||
global $wpdb;
|
||||
$date = date("Y-m-d");
|
||||
$querycheck = "SELECT * FROM {$wpdb->prefix}wpfd_statistics WHERE related_id=" . esc_sql($file_id) . " AND date='" . esc_sql($date) . "'";
|
||||
|
||||
$object = $wpdb->get_row($querycheck);;
|
||||
|
||||
if ($object) {
|
||||
$query = "UPDATE {$wpdb->prefix}wpfd_statistics SET count=(count+1) WHERE related_id=" . esc_sql($file_id) . " AND date='" . esc_sql($date) . "'";
|
||||
$wpdb->query($query);
|
||||
} else {
|
||||
$this->addChart($file_id, $date);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
/**
|
||||
* WP File Download
|
||||
*
|
||||
* @package WP File Download
|
||||
* @author Joomunited
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
use Joomunited\WPFramework\v1_0_4\Application;
|
||||
use Joomunited\WPFramework\v1_0_4\Model;
|
||||
|
||||
defined( 'ABSPATH' ) || die();
|
||||
|
||||
class WpfdModelFiles extends Model{
|
||||
|
||||
/**
|
||||
* Get files by ordering
|
||||
* @param $category
|
||||
* @param string $ordering
|
||||
* @param string $ordering_dir
|
||||
* @return array
|
||||
*/
|
||||
function getFiles($category, $ordering = 'menu_order', $ordering_dir = 'ASC'){
|
||||
|
||||
|
||||
$modelCat = $this->getInstance('category');
|
||||
$categorys = $modelCat->getCategory($category);
|
||||
$modelConfig = $this->getInstance('config');
|
||||
$params = $modelConfig->getGlobalConfig();
|
||||
$user = wp_get_current_user();
|
||||
$roles = array();
|
||||
foreach($user->roles as $role){
|
||||
$roles[] = strtolower($role);
|
||||
}
|
||||
|
||||
$modelTokens = Model::getInstance('tokens');
|
||||
$sessionToken = isset($_SESSION['wpfdToken']) ? $_SESSION['wpfdToken'] : null ;
|
||||
if($sessionToken===null){
|
||||
$token = $modelTokens->createToken();
|
||||
$_SESSION['wpfdToken'] = $token;
|
||||
}else{
|
||||
$tokenId = $modelTokens->tokenExists($sessionToken);
|
||||
if($tokenId){
|
||||
$modelTokens->updateToken($tokenId);
|
||||
$token = $sessionToken;
|
||||
}else{
|
||||
$token = $modelTokens->createToken();
|
||||
$_SESSION['wpfdToken'] = $token;
|
||||
}
|
||||
}
|
||||
|
||||
if($ordering=='ordering') $ordering = 'menu_order';
|
||||
|
||||
$args = array(
|
||||
'posts_per_page' => -1,
|
||||
'post_type' => 'wpfd_file' ,
|
||||
'orderby' => $ordering,
|
||||
'order' => $ordering_dir,
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'wpfd-category',
|
||||
'terms' => (int)$category,
|
||||
'include_children' => false
|
||||
)
|
||||
),
|
||||
'suppress_filters' => false
|
||||
);
|
||||
$results = get_posts( $args );
|
||||
$files = array();
|
||||
|
||||
$viewer_type = wpfdBase::loadValue($params, 'use_google_viewer', 'lightbox') ;
|
||||
$extension_viewer = explode(',', wpfdBase::loadValue($params, 'extension_viewer', 'pdf,ppt,doc,xls,dxf,ps,eps,xps,psd,tif,tiff,bmp,svg,pages,ai,dxf,ttf,txt,mp3,mp4'));
|
||||
$extension_viewer = array_map('trim', $extension_viewer);
|
||||
$user = wp_get_current_user();
|
||||
$user_id = $user->ID;
|
||||
|
||||
foreach ($results as $result) {
|
||||
|
||||
$ob = new stdClass();
|
||||
$metaData = get_post_meta($result->ID,'_wpfd_file_metadata',true);
|
||||
if (wpfdBase::loadValue($params, 'restrictfile', 0)== 1) {
|
||||
$canview = isset($metaData['canview']) ? $metaData['canview'] : 0;
|
||||
if ($canview!=0 && $canview != $user_id) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$remote_url = isset($file_meta['remote_url']) ? $file_meta['remote_url'] : false;
|
||||
|
||||
$ob->ID = $result->ID ;
|
||||
$ob->post_title = $result->post_title ;
|
||||
$ob->post_name = $result->post_name ;
|
||||
$ob->ext = isset($metaData['ext'])? $metaData['ext']: '' ;
|
||||
$ob->hits = isset($metaData['hits'])?(int)$metaData['hits']: 0 ;
|
||||
$ob->versionNumber = isset($metaData['version'])? $metaData['version']: '' ;
|
||||
$ob->version = '';
|
||||
$ob->description = $result->post_excerpt ;
|
||||
$ob->size = isset($metaData['size'])? $metaData['size']: 0 ;
|
||||
$ob->created = mysql2date(wpfdBase::loadValue($params, 'date_format', get_option('date_format')), $result->post_date);
|
||||
$ob->modified = mysql2date(wpfdBase::loadValue($params, 'date_format', get_option('date_format')), $result->post_modified);
|
||||
|
||||
$term_list = wp_get_post_terms($result->ID, 'wpfd-category', array("fields" => "ids"));
|
||||
$wpfd_term = get_term($term_list[0], 'wpfd-category');
|
||||
$ob->catname = sanitize_title($wpfd_term->name);
|
||||
$ob->cattitle = $wpfd_term->name;
|
||||
if( !is_wp_error($term_list) ) {
|
||||
$ob->catid= $term_list[0];
|
||||
}else {
|
||||
$ob->catid= 0;
|
||||
}
|
||||
|
||||
if($viewer_type != 'no' &&
|
||||
in_array($ob->ext, $extension_viewer)
|
||||
&& ($remote_url == false)){
|
||||
$ob->viewer_type = $viewer_type;
|
||||
$ob->viewerlink = wpfdHelperFile::isMediaFile($ob->ext) ? wpfdHelperFile::getMediaViewerUrl($result->ID, $ob->ext) : wpfdHelperFile::getViewerUrl($result->ID,$ob->catid,$token);
|
||||
}
|
||||
|
||||
$open_pdf_in = wpfdBase::loadValue($params, 'open_pdf_in', 0) ;
|
||||
|
||||
if ($open_pdf_in == 1 && $ob->ext == 'pdf') {
|
||||
$ob->openpdflink = wpfdHelperFile::getPdfUrl($result->ID,$ob->catid,$token). '&preview=1';
|
||||
}
|
||||
$config = get_option('_wpfd_global_config');
|
||||
if(empty($config) || empty($config['uri'])){
|
||||
$seo_uri = 'download';
|
||||
}else{
|
||||
$seo_uri = $config['uri'];
|
||||
}
|
||||
$ob->seouri = $seo_uri;
|
||||
$perlink = get_option('permalink_structure');
|
||||
$rewrite_rules = get_option('rewrite_rules');
|
||||
|
||||
if(!empty($rewrite_rules)){
|
||||
if(strpos($perlink, 'index.php')){
|
||||
$ob->linkdownload = get_site_url().'/index.php/'.$seo_uri.'/'.$ob->catid.'/'.$ob->catname.'/'.$result->ID.'/'.$result->post_name;
|
||||
}else{
|
||||
$ob->linkdownload = get_site_url().'/'.$seo_uri.'/'.$ob->catid.'/'.$ob->catname.'/'.$result->ID.'/'.$result->post_name;
|
||||
}
|
||||
if($ob->ext) { $ob->linkdownload .= '.'.$ob->ext; };
|
||||
}else{
|
||||
$ob->linkdownload = admin_url('admin-ajax.php').'?juwpfisadmin=false&action=wpfd&task=file.download&wpfd_category_id='.$ob->catid.'&wpfd_file_id='.$result->ID;
|
||||
}
|
||||
//crop file titles
|
||||
$ob->crop_title = wpfdBase::cropTitle($categorys->params,$categorys->params['theme'], $result->post_title);
|
||||
$files[] = $ob;
|
||||
}
|
||||
|
||||
$reverse = strtoupper($ordering_dir) == 'DESC' ? true : false;
|
||||
|
||||
if ($ordering == 'size') {
|
||||
$files = wpfd_sort_by_property($files, 'ID', 'size', $reverse);
|
||||
} else if ($ordering == 'version') {
|
||||
$files = wpfd_sort_by_property($files, 'ID', 'version', $reverse);
|
||||
} else if ($ordering == 'hits') {
|
||||
$files = wpfd_sort_by_property($files, 'ID', 'hits', $reverse);
|
||||
} else if ($ordering == 'ext') {
|
||||
$files = wpfd_sort_by_property($files, 'ID', 'ext', $reverse);
|
||||
}
|
||||
|
||||
return $files;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* WP File Download
|
||||
*
|
||||
* @package WP File Download
|
||||
* @author Joomunited
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
use Joomunited\WPFramework\v1_0_4\Application;
|
||||
use Joomunited\WPFramework\v1_0_4\Model;
|
||||
|
||||
defined( 'ABSPATH' ) || die();
|
||||
|
||||
class WpfdModelTokens extends Model {
|
||||
/**
|
||||
* Create a new token
|
||||
*/
|
||||
public function createToken(){
|
||||
$token = md5(uniqid(mt_rand(), true));
|
||||
$tokens = get_option('_wpfd_tokens', array());
|
||||
$tokens[$token] = time();
|
||||
update_option('_wpfd_tokens', $tokens, false);
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode to check if a token exists
|
||||
* @param int $token
|
||||
* @return object file, false if an error occurs
|
||||
*/
|
||||
public function tokenExists($token){
|
||||
$tokens = get_option('_wpfd_tokens', array());
|
||||
if(array_key_exists($token, $tokens)) {
|
||||
return $token;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode to update a token
|
||||
* @param int $id_file
|
||||
* @return object file, false if an error occurs
|
||||
*/
|
||||
public function updateToken($id){
|
||||
$tokens = get_option('_wpfd_tokens', array());
|
||||
$tokens[$id] = time();
|
||||
update_option('_wpfd_tokens',$tokens, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete all tokens
|
||||
* @return number of affected rows, false if an error occurs
|
||||
*/
|
||||
public function removeTokens(){
|
||||
$tokens = get_option('_wpfd_tokens', array());
|
||||
$time = time() - 15 * 60; //15 mins
|
||||
if(count($tokens)>0) {
|
||||
foreach ($tokens as $key => $val) {
|
||||
if((int)$val < $time) {
|
||||
unset($tokens[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_option('_wpfd_tokens',$tokens, false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user