private function ParseHeaderFooter($str, $uid = null) { $str = preg_replace_callback('/%sort_?link:([a-z0-9_]+)%/i', array(__CLASS__, 'GenSortlink'), $str); if (strpos($str, '%search_form%') !== false) { wpfb_loadclass('Output'); $str = str_replace('%search_form%', WPFB_Output::GetSearchForm("", $_GET), $str); } $str = preg_replace_callback('/%print_?(script|style):([a-z0-9_-]+)%/i', array(__CLASS__, 'PrintScriptCallback'), $str); if (empty($uid)) { $uid = uniqid(); } $str = str_replace('%uid%', $uid, $str); $count = 0; $str = preg_replace("/jQuery\\((.+?)\\)\\.dataTable\\s*\\((.*?)\\)(\\.?.*?)\\s*;/", 'jQuery($1).dataTable((function(options){/*%WPFB_DATA_TABLE_OPTIONS_FILTER%*/})($2))$3;', $str, -1, $count); if ($count > 0) { $dataTableOptions = array(); list($sort_field, $sort_dir) = wpfb_call('Output', 'ParseSorting', $this->current_list->file_order); $file_tpl = WPFB_Core::GetTpls('file', $this->file_tpl_tag); if (($p = strpos($file_tpl, "%{$sort_field}%")) > 0) { // get the column index of field to sort $col_index = substr_count($file_tpl, "</t", 0, $p); $dataTableOptions["aaSorting"] = array(array($col_index, strtolower($sort_dir))); } if ($this->current_list->page_limit > 0) { $dataTableOptions["iDisplayLength"] = $this->current_list->page_limit; } $str = str_replace('/*%WPFB_DATA_TABLE_OPTIONS_FILTER%*/', " var wpfbOptions = " . json_encode($dataTableOptions) . "; " . " if('object' == typeof(options)) { for (var v in options) { wpfbOptions[v] = options[v]; } }" . " return wpfbOptions; ", $str); } return $str; }
static function Display() { wpfb_loadclass('Output', 'File', 'Category', 'TplLib'); $content = ''; $file_tpls = WPFB_Core::GetTpls('file'); $cat_tpls = WPFB_Core::GetTpls('cat'); if (true || !isset($file_tpls['filebrowser_admin'])) { $file_tpls['filebrowser_admin'] = '%file_small_icon% ' . '%file_display_name% (<a href="%file_url%">%file_name%</a>, %file_size%) ' . '<!-- IF %file_user_can_edit% --><a href="%file_edit_url%" class="edit" onclick="wpfbFBEditFile(event)">%\'Edit\'%</a><!-- ENDIF -->' . '<!-- IF %file_user_can_edit% --><a href="#" class="delete" onclick="return confirm(\'Sure?\') && wpfbFBDelete(event) && false;">%\'Delete\'%</a><!-- ENDIF -->'; WPFB_Core::SetFileTpls($file_tpls); //WPFB_Admin::ParseTpls(); } if (true || !isset($cat_tpls['filebrowser_admin'])) { $cat_tpls['filebrowser_admin'] = '<span class="cat-icon" style="background-image:url(\'%cat_icon_url%\');"><span class="cat-icon-overlay"></span></span>' . '%cat_name% (%cat_num_files% / %cat_num_files_total%)' . '<!-- IF %cat_user_can_edit% --><a href="%cat_edit_url%" class="edit" onclick="wpfbFBEditCat(event)">%\'Edit\'%</a><!-- ENDIF -->' . '<!-- IF %cat_user_can_edit% --><a href="#" class="delete" onclick="return confirm(\'Sure?\') && wpfbFBDelete(event) && false;">%\'Delete\'%</a><!-- ENDIF -->'; WPFB_Core::SetCatTpls($cat_tpls); WPFB_Admin::ParseTpls(); } WPFB_Output::FileBrowser($content, 0, empty($_GET['wpfb_cat']) ? 0 : intval($_GET['wpfb_cat'])); wpfb_call('Output', 'PrintJS'); ?> <div class="wrap filebrowser-admin"> <h2><?php _e('File Browser', 'wp-filebase'); ?> </h2> <?php echo '<div>' . __('You can Drag & Drop (multiple) files directly on Categories to upload them. Dragging a category or an existing file to another category is also possible.', 'wp-filebase') . '</div>'; echo $content; ?> </div> <script> function wpfbFBEditCat(e) { e.stopPropagation(); } function wpfbFBEditFile(e) { e.stopPropagation(); } function wpfbFBDelete(e) { e.stopPropagation(); var t = jQuery(e.currentTarget).parents('li').first(); var d = {wpfb_action: 'delete'}; var tid = t.attr('id').split('-'); d[tid[tid.length-2]+'_id'] = +tid[tid.length-1]; jQuery.ajax({type: 'POST', url: wpfbConf.ajurl, data: d, //async: false, success: (function (data) { if (data == '1') { t.fadeOut(300, function() { t.remove(); }); } }) }); return false; } </script> <?php }
static function CheckTraffic($file_size) { $traffic = wpfb_call('Misc', 'GetTraffic'); $limit_month = WPFB_Core::$settings->traffic_month * 1073741824; //GiB $limit_day = WPFB_Core::$settings->traffic_day * 1048576; // MiB return ($limit_month == 0 || $traffic['month'] + $file_size < $limit_month) && ($limit_day == 0 || $traffic['today'] + $file_size < $limit_day); }
static function PluginsApiFilter($res, $action, $args) { global $user_ID; $res = wpfb_call('ExtensionLib', 'QueryAvailableExtensions'); if ($user_ID && !empty($res->info['tag_time'])) { update_user_option($user_ID, 'wpfb_ext_tagtime', $res->info['tag_time']); } return $res; }
static function TplFieldsSelect($input, $short = false, $for_cat = false) { $out = __('Add template variable:', WPFB) . ' <select name="_wpfb_tpl_fields" onchange="WPFB_AddTplVar(this, \'' . $input . '\')"><option value="">' . __('Select') . '</option>'; foreach (wpfb_call('Models', 'TplVarsDesc', $for_cat) as $tag => $desc) { $out .= '<option value="' . $tag . '" title="' . $desc . '">' . $tag . ($short ? '' : ' (' . $desc . ')') . '</option>'; } $out .= '</select>'; $out .= '<small>(' . __('For some files there are more tags available. You find a list of all tags below the form when editing a file.', WPFB) . '</small>'; return $out; }
static function PluginsApiFilter($res, $action, $args) { global $user_ID; $res = wpfb_call('ExtensionLib', 'QueryAvailableExtensions'); if (!$res || empty($res->info)) { wp_die('WP-Filebase extension directory is currently not available.'); return false; } if ($user_ID && !empty($res->info['tag_time'])) { update_user_option($user_ID, 'wpfb_ext_tagtime', $res->info['tag_time']); } return $res; }
static function AdminBar() { global $wp_admin_bar; wpfb_call('Output', 'PrintJS'); $wp_admin_bar->add_menu(array('id' => WPFB, 'title' => WPFB_PLUGIN_NAME, 'href' => admin_url('admin.php?page=wpfilebase_manage'))); $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-add-file', 'title' => __('Add File', 'wp-filebase'), 'href' => admin_url('admin.php?page=wpfilebase_files#addfile'))); $current_object = get_queried_object(); $is_filebrowser = false; if (!empty($current_object) && !empty($current_object->post_type) && $current_object->ID > 0) { if ($current_object->post_type != 'wpfb_filepage') { $is_filebrowser = $current_object->ID == WPFB_Core::$settings->file_browser_post_id; $link = esc_attr(admin_url('admin.php?wpfilebase-screen=editor-plugin&manage_attachments=1&post_id=' . $current_object->ID)); $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-attachments', 'title' => __('Manage attachments', 'wp-filebase'), 'href' => $link, 'meta' => array('onclick' => 'window.open("' . $link . '", "wpfb-manage-attachments", "width=680,height=400,menubar=no,location=no,resizable=no,status=no,toolbar=no,scrollbars=yes");return false;'))); } else { $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-edit-file', 'title' => __('Edit File', 'wp-filebase'), 'href' => get_edit_post_link($current_object->ID))); } } $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-add-file', 'title' => __('Sync Filebase', 'wp-filebase'), 'href' => admin_url('admin.php?page=wpfilebase_manage&action=sync'))); $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-toggle-context-menu', 'title' => !empty(WPFB_Core::$settings->file_context_menu) ? __('Disable file context menu', 'wp-filebase') : __('Enable file context menu', 'wp-filebase'), 'href' => 'javascript:;', 'meta' => array('onclick' => 'return wpfb_toggleContextMenu();'))); if ($is_filebrowser) { $wp_admin_bar->add_menu(array('parent' => WPFB, 'id' => WPFB . '-toggle-drag-drop', 'title' => get_user_option('wpfb_set_fbdd') ? __('Disable file browser Drag & Drop', 'wp-filebase') : __('Enable file browser Drag & Drop', 'wp-filebase'), 'href' => 'javascript:;', 'meta' => array('onclick' => 'jQuery.ajax({url:wpfbConf.ajurl,type:"POST",data:{wpfb_action:"set-user-setting",name:"fbdd",value:' . (get_user_option('wpfb_set_fbdd') ? 0 : 1) . '},async:false});location.reload();return false;'))); } }
public function Display() { wpfb_call('Output', 'PrintJS'); wp_print_scripts('utils'); // setUserSetting ?> <style type="text/css" media="screen">@import url(<?php echo WPFB_PLUGIN_URI . 'css/batch-uploader.css'; ?> );</style> <div id="<?php echo $this->prefix; ?> -uploader-wrap"> <div id="<?php echo $this->prefix; ?> -uploader-interface" class="wpfb-batch-uploader-interface"> <div class="form-wrap uploader-presets" id="<?php echo $this->prefix; ?> -uploader-presets"> <form method="POST" action="" class="validate" name="batch_presets"> <h2><?php _e('Upload Presets', 'wp-filebase'); ?> </h2> <?php self::DisplayUploadPresets($this->prefix); //wp_nonce_field('batch-presets'); // TODO validate this! ?> </form> </div> <div id="<?php echo $this->prefix; ?> -drag-drop-uploader" class="drag-drop-uploader"> <h2>Drag & Drop</h2> <div id="<?php echo $this->prefix; ?> -drag-drop-area" class="drag-drop-area"> <div style="margin: 70px auto 0;"> <p class="drag-drop-info"><?php _e('Drop files here'); ?> </p> <p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?> </p> <p class="drag-drop-buttons"><input id="<?php echo $this->prefix; ?> -browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?> " class="button" /></p> </div> </div> <div id="<?php echo $this->prefix; ?> -uploader-errors"></div> </div> <div style="clear: both;"></div> </div> <div id="<?php echo $this->prefix; ?> -uploader-files" style="position:relative;"></div> </div> <?php wp_print_scripts('jquery-color'); wp_print_scripts('jquery-deserialize'); ?> <script type="text/javascript"> var mouseDragPos = []; var presetData = ''; var morePresets = 0; jQuery(document).ready( function() { var form = jQuery('#<?php echo $this->prefix; ?> -uploader-presets').find('form'); jQuery('#<?php echo $this->prefix; ?> -drag-drop-area').bind('dragover', function(e){ mouseDragPos = [e.originalEvent.pageX, e.originalEvent.pageY]; }); <?php ?> wpfb_setupFormAutoSave(form,'batch_presets'); <?php ?> // "more" toggle init form.find('tr.more').hide(); form.find('tr.more-more').hide(); morePresets = 0; jQuery('#<?php echo $this->prefix; ?> -uploader-presets-more-toggle').click(function() { batchUploaderSetPresetsMore(morePresets = ((morePresets+1)%3)); }); batchUploaderSetPresetsMore(typeof(getUserSetting) !== 'function' || getUserSetting('wpfb_batch_presets_more') || 0); }); function batchUploaderSetPresetsMore(m) { if(isNaN(m)) m = 0; var form = jQuery('#<?php echo $this->prefix; ?> -uploader-presets').find('form'); form.find('tr.more')[m == 0 ? 'hide' : 'show'](400); form.find('tr.more-more')[m != 2 ? 'hide' : 'show'](400); // TODO show any field with non-default value!! //form.find('tr.more').toggle(morePresets > 0); //form.find('tr.more-more').toggle(morePresets > 1); if(typeof(setUserSetting) !== 'undefined') setUserSetting('wpfb_batch_presets_more',''+morePresets); jQuery('#<?php echo $this->prefix; ?> -uploader-presets-more-toggle td span').html(m==2?'<?php _e('less'); ?> ':'<?php _e('more'); ?> '); } function batchUploaderFilesQueued(up, files) { var form = jQuery('#<?php echo $this->prefix; ?> -uploader-presets').find('form'); up.settings.multipart_params["presets"] = form.serialize(); var hidden_params = form.find('input[type=hidden]').serializeArray(); for (var i = 0; i < hidden_params.length; ++i) { up.settings.multipart_params[hidden_params[i].name] = hidden_params[i].value; } form .css({ background: "rgba(255,255,0,0.0)" }) .animate({ backgroundColor: "rgba(255,255,0,0.5)"}, 100) .animate({ backgroundColor: "rgba(255,255,0,0.0)"}, 400); form.find('input,textarea,select') .animate({ opacity: 0.2}, 100) .animate({ opacity: 1.0}, 400); form.find("input[name='file_display_name']").val(''); } function batchUploaderFileQueued(up, file) { //file.name, file.size jQuery('#<?php echo $this->prefix; ?> -uploader-files').prepend('<div id="<?php echo $this->prefix; ?> -uploader-file-'+file.id+'-spacer" class="batch-uploader-file-spacer"></div>'); jQuery('#<?php echo $this->prefix; ?> -uploader-files').prepend('<div id="'+file.dom_id+'" class="media-item batch-uploader-file">'+ '<div class="progress"><div class="percent">0%</div><div class="bar"></div></div>'+ '<img src="<?php echo site_url(WPINC . '/images/crystal/default.png'); ?> " alt="Loading..." /><span class="filename">'+file.name+'</span><span class="error"></span></div>'); var fileEl = jQuery('#'+file.dom_id); var spacerEl = jQuery('#<?php echo $this->prefix; ?> -uploader-file-'+file.id+'-spacer'); var dest = fileEl.offset(); var ppos = fileEl.parent().offset(); var destWidth = fileEl.width(); fileEl.css({position:'absolute', zIndex:100, top:mouseDragPos[1]-ppos.top, left:mouseDragPos[0]-ppos.left-15}); fileEl.animate({ //opacity: 0.25, left: dest.left-ppos.left, top: dest.top-ppos.top }, 400, function() { spacerEl.remove(); var startWidth = jQuery(this).width(); jQuery(this) .css({position:'',top:0,left:0,width:startWidth}) .animate({width: destWidth}, 200); }); spacerEl.animate({height: fileEl.outerHeight(true)}, 400); jQuery('.error', fileEl).hide(); } function batchUploaderSuccess(file, serverData) { var item = jQuery('#'+file.dom_id); if(!serverData || serverData == -1 || 'object' != typeof(serverData)) { jQuery('.error', item).show().html('Server response error! '+serverData); console.log(serverData); return; } var url = serverData.file_cur_user_can_edit ? serverData.file_edit_url : serverData.file_download_url; jQuery('.filename', item).html('<a href="'+url+'" target="_blank">'+serverData.file_display_name+'</a> <span class="ok"><?php _e('Upload OK!', 'wp-filebase'); ?> </span>'); jQuery('img', item).attr('src', serverData.file_thumbnail_url); } </script> <?php wpfb_loadclass('PLUploader'); $uploader = new WPFB_PLUploader(); $uploader->js_file_queued = 'batchUploaderFileQueued'; $uploader->js_files_queued = 'batchUploaderFilesQueued'; $uploader->js_upload_success = 'batchUploaderSuccess'; $uploader->post_params['file_add_now'] = true; if (!empty($this->hidden_vars)) { $uploader->post_params = array_merge($uploader->post_params, $this->hidden_vars); } $uploader->Init($this->prefix . '-drag-drop-area', $this->prefix . '-browse-button', $this->prefix . '-uploader-errors'); }
static function GetMemStats() { static $limit = -2; if ($limit == -2) { $limit = wpfb_call("Misc", "ParseIniFileSize", ini_get('memory_limit')); } return array('limit' => $limit, 'used' => max(memory_get_usage(true), memory_get_usage())); }
static function GetTreeItems($parent_id, $type = 'browser', $args = array()) { /* $args = array( * sort_cats * sort_files * cats_only * exclude_attached * priv * cat_id_fmt => * file_id_fmt => * onselect * ); */ $parent_id = is_object($parent_id) ? $parent_id->cat_id : intval($parent_id); $browser = $type === 'browser'; $filesel = $type === 'fileselect'; $catsel = $type === 'catselect'; if ($parent_id > 0 && (is_null($cat = WPFB_Category::GetCat($parent_id)) || !$cat->CurUserCanAccess())) { return array((object) array('id' => 0, 'text' => WPFB_Core::$settings->cat_inaccessible_msg)); } $sql_sort_files = $browser ? WPFB_Core::GetSortSql((WPFB_Core::$settings->file_browser_file_sort_dir ? '>' : '<') . WPFB_Core::$settings->file_browser_file_sort_by) : 'file_display_name'; $sql_sort_cats = $browser ? WPFB_Core::GetSortSql((WPFB_Core::$settings->file_browser_cat_sort_dir ? '>' : '<') . WPFB_Core::$settings->file_browser_cat_sort_by, false, true) : 'cat_name'; $cat_id_format = empty($args['cat_id_fmt']) ? 'wpfb-cat-%d' : $args['cat_id_fmt']; $file_id_format = empty($args['file_id_fmt']) ? 'wpfb-file-%d' : $args['file_id_fmt']; if ($filesel || $catsel) { $onselect = $args['onselect']; } $files_before_cats = $browser && WPFB_Core::$settings->file_browser_fbc; $where = " cat_parent = {$parent_id} "; if ($browser) { $where .= " AND cat_exclude_browser <> '1' "; } $cats = WPFB_Category::GetCats("WHERE {$where} ORDER BY {$sql_sort_cats}"); $cat_items = array(); $i = 0; foreach ($cats as $c) { if ($c->CurUserCanAccess(true)) { $cat_items[$i++] = (object) array('id' => sprintf($cat_id_format, $c->cat_id), 'cat_id' => $c->cat_id, 'text' => $catsel ? '<a href="javascript:' . sprintf($onselect, $c->cat_id, str_replace('\'', '\\\'', htmlspecialchars(stripslashes($c->cat_name)))) . '">' . esc_html($c->GetTitle(24)) . '</a>' : ($filesel ? esc_html($c->cat_name) . " ({$c->cat_num_files} / {$c->cat_num_files_total})" : $c->GenTpl2('filebrowser', false)), 'hasChildren' => $c->HasChildren($catsel), 'classes' => $filesel || $catsel ? 'folder' : null); } } if ($parent_id == 0 && $catsel && $i == 0) { return array((object) array('id' => sprintf($cat_id_format, 0), 'text' => sprintf(__('You did not create a category. <a href="%s" target="_parent">Click here to create one.</a>', WPFB), admin_url('admin.php?page=wpfilebase_cats#addcat')), 'hasChildren' => false)); } $file_items = array(); $i = 0; if (empty($args['cats_only']) && !$catsel) { $where = WPFB_File::GetSqlCatWhereStr($parent_id); if (!empty($args['exclude_attached'])) { $where .= " AND `file_post_id` = 0"; } // $files = WPFB_File::GetFiles2(WPFB_File::GetSqlCatWhereStr($root_id), WPFB_Core::$settings->hide_inaccessible, $sql_file_order); //$files = WPFB_File::GetFiles2(WPFB_File::GetSqlCatWhereStr($root_id), WPFB_Core::$settings->hide_inaccessible, $sql_file_order); $files = WPFB_File::GetFiles2($where, WPFB_Core::$settings->hide_inaccessible && !($filesel && wpfb_call('Admin', 'CurUserCanUpload')), $sql_sort_files); foreach ($files as $f) { $file_items[$i++] = (object) array('id' => sprintf($file_id_format, $f->file_id), 'text' => $filesel ? '<a href="javascript:' . sprintf($onselect, $f->file_id, str_replace('\'', '\\\'', htmlspecialchars(stripslashes($f->file_display_name)))) . '">' . esc_html($f->GetTitle(24)) . '</a> <span style="font-size:75%;vertical-align:top;">' . esc_html($f->file_name) . '</span>' : $f->GenTpl2('filebrowser', false), 'classes' => $filesel ? 'file' : null, 'hasChildren' => false); } } return $files_before_cats ? array_merge($file_items, $cat_items) : array_merge($cat_items, $file_items); }
function ChangeCategoryOrName($new_cat_id, $new_name = null, $add_existing = false, $overwrite = false) { // 1. apply new values (inherit permissions if nothing (Everyone) set!) // 2. check for name collision and rename // 3. move stuff // 4. notify parents // 5. update child paths if (empty($new_name)) { $new_name = $this->GetName(); } elseif (!$add_existing) { $new_name = sanitize_file_name($new_name); } // also removes ()! $this->Lock(true); $new_cat_id = intval($new_cat_id); $old_cat_id = $this->GetParentId(); $old_path_rel = $this->GetLocalPathRel(true); $old_path = $this->GetLocalPath(); $old_name = $this->GetName(); if ($this->is_file) { $old_thumb_path = $this->GetThumbPath(); } $old_cat = $this->GetParent(); $new_cat = WPFB_Category::GetCat($new_cat_id); if (!$new_cat) { $new_cat_id = 0; } $cat_changed = $new_cat_id != $old_cat_id; if ($cat_changed && $new_cat_id > 0 && $this->IsAncestorOf($new_cat)) { return array('error' => __('Cannot move category into a sub-category of itself.', 'wp-filebase')); } // strip accents/umlauts if ($new_name != $old_name) { if ($this->is_file && $add_existing) { $this->file_name_original = rawurldecode($new_name); // expect utf8 chars to be urlencoded on disk, so decode them } else { $prev_new_name = $new_name; $new_name = remove_accents($new_name); // sanitize, but make sure not to strip too much $sani = sanitize_file_name($new_name); if (strlen($sani) >= 6) { $new_name = $sani; } if (wpfb_call('Misc', 'IsUtf8', $new_name)) { $new_name = rawurlencode($new_name); } if ($this->is_file) { $this->file_name_original = $prev_new_name; } } } // unset original name if equal to actual if ($this->is_file && $new_name === $this->file_name_original) { $this->file_name_original = ''; } if ($this->is_file) { $this->file_category = $new_cat_id; $this->file_name = $new_name; $this->file_category_name = $new_cat_id == 0 ? '' : $new_cat->GetTitle(); } else { $this->cat_parent = $new_cat_id; $this->cat_folder = $new_name; } // inherit user roles if (count($this->GetReadPermissions()) == 0) { $this->SetReadPermissions($new_cat_id != 0 ? $new_cat->GetReadPermissions() : WPFB_Core::$settings->default_roles); } // flush cache $this->last_parent_id = -1; $new_path_rel = $this->GetLocalPathRel(true); $new_path = $this->GetLocalPath(); if ($new_path_rel != $old_path_rel) { $i = 1; if (!$add_existing) { $name = $this->GetName(); if ($overwrite) { if (@file_exists($new_path)) { $ex_file = WPFB_File::GetByPath($new_path_rel); if (!is_null($ex_file)) { $ex_file->Remove(); } else { @unlink($new_path); } } } else { // rename item if filename collision (ignore if coliding with $this and ignore existing folders that does not belong to categories) while (@file_exists($new_path) && ($this->is_file || !is_dir($new_path) || !is_null(WPFB_Item::GetByPath($new_path_rel))) || !is_null($ex_file = WPFB_Item::GetByPath($new_path_rel)) && !$this->Equals($ex_file)) { $i++; if ($this->is_file) { $p = strrpos($name, '.'); $this->file_name = $p <= 0 ? "{$name}_{$i}" : substr($name, 0, $p) . "_{$i}" . substr($name, $p); } else { $this->cat_folder = "{$name}_{$i}"; } $new_path_rel = $this->GetLocalPathRel(true); $new_path = $this->GetLocalPath(); } } } // finally move it! if (!empty($old_name) && @file_exists($old_path)) { //echo "MOVING! $old_path -> $new_path"; if ($this->is_file) { if (!@rename($old_path, $new_path)) { return array('error' => sprintf('Unable to move file %s!', $old_path)); } @chmod($new_path, octdec(WPFB_PERM_FILE)); } else { if (!@is_dir($new_path)) { wp_mkdir_p($new_path); } wpfb_loadclass('FileUtils'); if (!@WPFB_FileUtils::MoveDir($old_path, $new_path)) { return array('error' => sprintf('Could not move folder %s to %s', $old_path, $new_path)); } } } else { if ($this->is_category) { if (!@is_dir($new_path) && !wp_mkdir_p($new_path)) { return array('error' => sprintf(__('Unable to create directory %s. Is it\'s parent directory writable?'), $new_path)); } } } // move thumb if ($this->is_file && !empty($old_thumb_path) && @is_file($old_thumb_path)) { $thumb_path = $this->GetThumbPath(); if ($i > 1) { $p = strrpos($thumb_path, '-'); if ($p <= 0) { $p = strrpos($thumb_path, '.'); } $thumb_path = substr($thumb_path, 0, $p) . "_{$i}" . substr($thumb_path, $p); $this->file_thumbnail = basename($thumb_path); } if (!is_dir(dirname($thumb_path))) { WPFB_Admin::Mkdir(dirname($thumb_path)); } if (!@rename($old_thumb_path, $thumb_path)) { return array('error' => 'Unable to move thumbnail! ' . $thumb_path); } @chmod($thumb_path, octdec(WPFB_PERM_FILE)); } $all_files = $this->is_file || $this->GetId() > 0 ? $this->GetChildFiles(true) : array(); // all children files (recursively) if (!empty($all_files)) { foreach ($all_files as $file) { if ($cat_changed) { if ($old_cat) { $old_cat->NotifyFileRemoved($file); } // notify parent cat to remove files if ($new_cat) { $new_cat->NotifyFileAdded($file); } } $file->GetLocalPathRel(true); // update file's path } } unset($all_files); if ($this->is_category && $this->GetId() > 0) { $cats = $this->GetChildCats(true); if (!empty($cats)) { foreach ($cats as $cat) { $cat->GetLocalPathRel(true); // update cats's path } } unset($cats); } } $this->Lock(false); if (!$this->locked) { $this->DBSave(); } return array('error' => false); /* * // create the directory if it doesnt exist // move file if($this->IsLocal() && !empty($old_file_path) && @is_file($old_file_path) && $new_file_path != $old_file_path) { if(!@rename($old_file_path, $new_file_path)) return array( 'error' => sprintf('Unable to move file %s!', $this->GetLocalPath())); @chmod($new_file_path, octdec(WPFB_PERM_FILE)); } */ }
static function PluginsApiFilter($value, $action = null, $args = null) { if (!is_object($args)) { $args = (object) $args; } return $action === 'plugin_information' && (strpos($args->slug, "wp-filebase") === 0 || strpos($args->slug, "wpfb-") === 0) ? wpfb_call('ExtensionLib', 'GetApiPluginInfo', $args->slug) : $value; }
static function Display() { global $wpdb, $user_ID; require_once ABSPATH . 'wp-admin/includes/dashboard.php'; wpfb_loadclass('AdminDashboard'); add_thickbox(); wp_enqueue_script('dashboard'); if (wp_is_mobile()) { wp_enqueue_script('jquery-touch-punch'); } //register_shutdown_function( create_function('','$error = error_get_last(); if( $error && $error[\'type\'] != E_STRICT ){print_r( $error );}else{return true;}') ); wpfb_loadclass('File', 'Category', 'Admin', 'Output'); $_POST = stripslashes_deep($_POST); $_GET = stripslashes_deep($_GET); $action = !empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''); $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync', 'doit', 'ids', 'files', 'cats', 'batch_sync')); // keep search keyword WPFB_Admin::PrintFlattrHead(); ?> <script type="text/javascript"> /* Liking/Donate Bar */ if(typeof(jQuery) != 'undefined') { jQuery(document).ready(function(){ if(getUserSetting("wpfilebase_hidesuprow",false) == 1) { jQuery('#wpfb-liking').hide(); jQuery('#wpfb-liking-toggle').addClass('closed'); } jQuery('#wpfb-liking-toggle').click(function(){ jQuery('#wpfb-liking').slideToggle(); jQuery(this).toggleClass('closed'); setUserSetting("wpfilebase_hidesuprow", 1-getUserSetting("wpfilebase_hidesuprow",false), 0); }); }); } </script> <div class="wrap"> <div id="icon-wpfilebase" class="icon32"><br /></div> <h2><?php echo WPFB_PLUGIN_NAME; ?> </h2> <?php switch ($action) { default: $clean_uri = remove_query_arg('pagenum', $clean_uri); $upload_dir = WPFB_Core::UploadDir(); $upload_dir_rel = str_replace(ABSPATH, '', $upload_dir); $chmod_cmd = "CHMOD " . WPFB_PERM_DIR . " " . $upload_dir_rel; if (!is_dir($upload_dir)) { $result = WPFB_Admin::Mkdir($upload_dir); if ($result['error']) { $error_msg = sprintf(__('The upload directory <code>%s</code> does not exists. It could not be created automatically because the directory <code>%s</code> is not writable. Please create <code>%s</code> and make it writable for the webserver by executing the following FTP command: <code>%s</code>', 'wp-filebase'), $upload_dir_rel, str_replace(ABSPATH, '', $result['parent']), $upload_dir_rel, $chmod_cmd); } else { wpfb_call('Setup', 'ProtectUploadPath'); } } elseif (!is_writable($upload_dir)) { $error_msg = sprintf(__('The upload directory <code>%s</code> is not writable. Please make it writable for PHP by executing the follwing FTP command: <code>%s</code>', 'wp-filebase'), $upload_dir_rel, $chmod_cmd); } if (!empty($error_msg)) { echo '<div class="error default-password-nag"><p>' . $error_msg . '</p></div>'; } if (!empty(WPFB_Core::$settings->tag_conv_req)) { echo '<div class="updated"><p><a href="' . add_query_arg('action', 'convert-tags') . '">'; _e('WP-Filebase content tags must be converted', 'wp-filebase'); echo '</a></p></div><div style="clear:both;"></div>'; } ?> <?php if (self::PluginHasBeenUsedAWhile(true)) { self::ProUpgradeNag(); } if (self::PluginHasBeenUsedAWhile()) { ?> <div id="wpfb-support-col"> <div id="wpfb-liking-toggle"></div> <h3><?php _e('Like WP-Filebase?', 'wp-filebase'); ?> </h3> <div id="wpfb-liking"> <!-- <div style="text-align: center;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwordpress.org%2Fextend%2Fplugins%2Fwp-filebase%2F&send=false&layout=button_count&width=150&show_faces=false&action=like&colorscheme=light&font&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:140px; height:21px; display:inline-block; text-align:center;" <?php echo ' allowTransparency="true"'; ?> ></iframe></div> --> <div style="text-align: center;" ><a href="https://twitter.com/wpfilebase" class="twitter-follow-button" data-show-count="false">Follow @wpfilebase</a> <script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></div> <p>Please <a href="http://wordpress.org/support/view/plugin-reviews/wp-filebase">give it a good rating</a>.</p> <p>For Cloud support and lots of other advanced features consider an</p> <p style="text-align: center;"><a href="https://wpfilebase.com/?ref=dblike" class="button-primary">Upgrade to Pro</a></p> <p style="text-align: center;"><a href="http://demo.wpfilebase.com/?ref=dblike" class="button">Live Pro Demo</a></p> <p style="text-align:right;float:right;font-style:italic;">Thanks, Fabian</p> <!-- <div style="text-align: center;"> <?php //WPFB_Admin::PrintPayPalButton() ?> <?php //WPFB_Admin::PrintFlattrButton() ?> </div> --> </div> </div> <?php } ?> <div id="dashboard-widgets-wrap"> <?php wp_dashboard(); ?> </div><!-- dashboard-widgets-wrap --> <?php break; case 'convert-tags': ?> <h2><?php _e('Tag Conversion'); ?> </h2><?php if (empty($_REQUEST['doit'])) { echo '<div class="updated"><p>'; _e('<strong>Important:</strong> before updating, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>. For help with updates, visit the <a href="http://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.'); echo '</p></div>'; echo '<p><a href="' . add_query_arg('doit', 1) . '" class="button">' . __('Continue') . '</a></p>'; break; } $result = wpfb_call('Setup', 'ConvertOldTags'); ?> <p><?php printf(__('%d Tags in %d Posts has been converted.'), $result['n_tags'], count($result['tags'])); ?> </p> <ul> <?php if (!empty($result['tags'])) { foreach ($result['tags'] as $post_title => $tags) { echo "<li><strong>" . esc_html($post_title) . "</strong><ul>"; foreach ($tags as $old => $new) { echo "<li>{$old} => {$new}</li>"; } echo "</ul></li>"; } } ?> </ul> <?php if (!empty($result['errors'])) { ?> <h2><?php _e('Errors'); ?> </h2> <ul><?php foreach ($result['errors'] as $post_title => $err) { echo "<li><strong>" . esc_html($post_title) . ": </strong> " . esc_html($err) . "<ul>"; } ?> </ul> <?php } $opts = WPFB_Core::GetOpt(); unset($opts['tag_conv_req']); update_option(WPFB_OPT_NAME, $opts); WPFB_Core::$settings = (object) $opts; break; // convert-tags // convert-tags case 'del': if (!empty($_REQUEST['files']) && WPFB_Core::CurUserCanUpload()) { $ids = explode(',', $_REQUEST['files']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($file = WPFB_File::GetFile($id)) != null && $file->CurUserCanDelete()) { $file->Remove(true); $nd++; } } WPFB_File::UpdateTags(); echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Files removed'), $nd) . '</p></div>'; } if (!empty($_REQUEST['cats']) && WPFB_Core::CurUserCanCreateCat()) { $ids = explode(',', $_REQUEST['cats']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($cat = WPFB_Category::GetCat($id)) != null) { $cat->Delete(); $nd++; } } echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Categories removed'), $nd) . '</p></div>'; } case 'sync': echo '<h2>' . __('Synchronisation') . '</h2>'; wpfb_loadclass('Sync'); $result = WPFB_Sync::Sync(!empty($_GET['hash_sync']), true); if (!is_null($result)) { WPFB_Sync::PrintResult($result); } if (empty($_GET['hash_sync'])) { echo '<p><a href="' . add_query_arg('hash_sync', 1) . '" class="button">' . __('Complete file sync', 'wp-filebase') . '</a> ' . __('Checks files for changes, so more reliable but might take much longer. Do this if you uploaded/changed files with FTP.', 'wp-filebase') . '</p>'; } if (empty($_GET['debug'])) { echo '<p><a href="' . add_query_arg('debug', 1) . '" class="button">' . __('Debug Sync', 'wp-filebase') . '</a> ' . __('Run to get more Debug Info in case Sync crashes', 'wp-filebase') . '</p>'; } break; // sync // sync case 'batch-upload': wpfb_loadclass('BatchUploader'); $batch_uploader = new WPFB_BatchUploader(); $batch_uploader->Display(); break; case 'reset-hits': global $wpdb; $n = 0; if (current_user_can('manage_options')) { $n = $wpdb->query("UPDATE `{$wpdb->wpfilebase_files}` SET file_hits = 0 WHERE 1=1"); } echo "<p>"; printf(__('Done. %d Files affected.'), $n); echo "</p>"; break; case 'install-extensions': wpfb_call('AdmInstallExt', 'Display'); break; } // switch if (!empty($_GET['action'])) { echo '<p><a href="' . $clean_uri . '" class="button">' . __('Go back') . '</a></p>'; } ?> </div> <!-- wrap --> <?php }
?> </label> <input type="radio" name="list-cat-sort-order" id="list-cat-sort-order-desc" value="desc" /> <label for="list-cat-sort-order-desc" class="radio"><?php _e('Descending'); ?> </label> </p> </form> <?php do_action('wpfilebase_editor_plugin_tabs'); } /*manage_attachments*/ ?> <?php do_action('admin_print_footer_scripts'); ?> <script type="text/javascript"> initEditorPlugin(); if(typeof wpOnload=='function')wpOnload(); </script> <?php wpfb_call('Output', 'PrintJS'); /* only required for wpfbConf */ ?> </body> </html>
static function GetTreeItems($parent_id, $args = array()) { /* $args = array( * sort_cats * sort_files * cats_only * exclude_attached * priv * idp => * onselect * ); */ $parent_id = is_object($parent_id) ? $parent_id->cat_id : intval($parent_id); $args = self::fileBrowserArgs($args); $type = $args['type']; $browser = $type === 'browser'; $filesel = $type === 'fileselect'; $catsel = $type === 'catselect'; $args['idp'] = wp_strip_all_tags($args['idp']); $idp_cat = $args['idp'] . 'cat-'; $idp_file = $args['idp'] . 'file-'; $file_tpl = $cat_tpl = !empty($args['tpl']) ? $args['tpl'] : (($is_admin = !empty($args['is_admin'])) ? 'filebrowser_admin' : 'filebrowser'); if ($parent_id > 0 && (is_null($cat = WPFB_Category::GetCat($parent_id)) || !$cat->CurUserCanAccess())) { return array((object) array('id' => 0, 'text' => WPFB_Core::$settings->cat_inaccessible_msg)); } $sql_sort_files = $browser ? WPFB_Core::GetSortSql((WPFB_Core::$settings->file_browser_file_sort_dir ? '>' : '<') . WPFB_Core::$settings->file_browser_file_sort_by) : 'file_display_name'; $sql_sort_cats = $browser ? WPFB_Core::GetSortSql((WPFB_Core::$settings->file_browser_cat_sort_dir ? '>' : '<') . WPFB_Core::$settings->file_browser_cat_sort_by, false, true) : 'cat_name'; $files_before_cats = $browser && WPFB_Core::$settings->file_browser_fbc; $inline_add_cat = WPFB_Core::CurUserCanCreateCat(); $where = " cat_parent = {$parent_id} "; if ($browser) { $where .= " AND cat_exclude_browser <> '1' "; } $cats = WPFB_Category::GetCats("WHERE {$where} ORDER BY {$sql_sort_cats}"); $cat_items = array(); $i = 0; $folder_class = $filesel || $catsel ? 'folder' : ''; foreach ($cats as $c) { if ($c->CurUserCanAccess(true)) { $cat_items[$i++] = (object) array('id' => $idp_cat . $c->cat_id, 'cat_id' => $c->cat_id, 'text' => self::fileBrowserCatItemText($catsel, $filesel, $c, $args['onselect'], $cat_tpl), 'hasChildren' => $inline_add_cat || $c->HasChildren($catsel), 'classes' => $folder_class); } } if ($inline_add_cat) { $is = WPFB_Core::$settings->small_icon_size > 0 ? WPFB_Core::$settings->small_icon_size : 32; $cat_items[$i++] = (object) array('id' => $idp_cat . '0', 'cat_id' => 0, 'text' => '<form action="" style="display:none;"><input type="text" placeholder="' . __('Category Name', WPFB) . '" name="cat_name" /></form> ' . '<a href="#" style="text-decoration:none;" onclick=\'return wpfb_newCatInput(this,' . $parent_id . ');\'><span style="' . ($browser ? 'font-size:' . $is . 'px;width:' . $is . 'px' : 'font-size:200%') . ';line-height:0;vertical-align:sub;display:inline-block;text-align:center;">+</span>' . __('Add Category', WPFB) . '</a>' . '<span style="font-size: 200%;vertical-align: sub;line-height: 0;font-weight: lighter;"> / </span>' . '<a href="#" style="text-decoration:none;" class="add-file"><span style="' . ($browser ? 'font-size:' . $is . 'px;width:' . $is . 'px' : 'font-size:200%') . ';line-height:0;vertical-align:sub;display:inline-block;text-align:center;">+</span>' . __('Add File', WPFB) . '</a>', 'hasChildren' => false, 'classes' => 'add-item'); } elseif ($parent_id == 0 && $catsel && $i == 0) { return array((object) array('id' => $idp_cat . '0', 'text' => sprintf(__('You did not create a category. <a href="%s" target="_parent">Click here to create one.</a>', WPFB), admin_url('admin.php?page=wpfilebase_cats#addcat')), 'hasChildren' => false)); } $file_items = array(); $i = 0; if (empty($args['cats_only']) && !$catsel) { $where = WPFB_File::GetSqlCatWhereStr($parent_id); if (!empty($args['exclude_attached'])) { $where .= " AND `file_post_id` = 0"; } // $files = WPFB_File::GetFiles2(WPFB_File::GetSqlCatWhereStr($root_id), WPFB_Core::$settings->hide_inaccessible, $sql_file_order); //$files = WPFB_File::GetFiles2(WPFB_File::GetSqlCatWhereStr($root_id), WPFB_Core::$settings->hide_inaccessible, $sql_file_order); $files = WPFB_File::GetFiles2($where, WPFB_Core::$settings->hide_inaccessible && !($filesel && wpfb_call('Core', 'CurUserCanUpload')), $sql_sort_files); foreach ($files as $f) { $file_items[$i++] = (object) array('id' => $idp_file . $f->file_id, 'text' => $filesel ? '<a href="javascript:;" onclick="' . sprintf($args['onselect'], $f->file_id) . '">' . esc_html($f->GetTitle(24)) . '</a> <span style="font-size:75%;vertical-align:top;">' . esc_html($f->file_name) . '</span>' : $f->GenTpl2($file_tpl, false), 'classes' => $filesel ? 'file' : null, 'hasChildren' => false); } } return $files_before_cats ? array_merge($file_items, $cat_items) : array_merge($cat_items, $file_items); }
static function GetMaxUlSize() { return wpfb_call('Misc', 'ParseIniFileSize', ini_get('upload_max_filesize')); }
static function Display() { global $wpdb, $user_ID; //register_shutdown_function( create_function('','$error = error_get_last(); if( $error && $error[\'type\'] != E_STRICT ){print_r( $error );}else{return true;}') ); wpfb_loadclass('File', 'Category', 'Admin', 'Output'); $_POST = stripslashes_deep($_POST); $_GET = stripslashes_deep($_GET); $action = !empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''); $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync', 'doit', 'ids', 'files', 'cats', 'batch_sync')); // keep search keyword // switch simple/extended form if (isset($_GET['exform'])) { $exform = !empty($_GET['exform']) && $_GET['exform'] == 1; update_user_option($user_ID, WPFB_OPT_NAME . '_exform', $exform, true); } else { $exform = (bool) get_user_option(WPFB_OPT_NAME . '_exform'); } if (!empty($_GET['wpfb-hide-how-start'])) { update_user_option($user_ID, WPFB_OPT_NAME . '_hide_how_start', 1); } $show_how_start = !(bool) get_user_option(WPFB_OPT_NAME . '_hide_how_start'); WPFB_Admin::PrintFlattrHead(); ?> <script type="text/javascript"> /* Liking/Donate Bar */ if(typeof(jQuery) != 'undefined') { jQuery(document).ready(function(){ if(getUserSetting("wpfilebase_hidesuprow",false) == 1) { jQuery('#wpfb-liking').hide(); jQuery('#wpfb-liking-toggle').addClass('closed'); } jQuery('#wpfb-liking-toggle').click(function(){ jQuery('#wpfb-liking').slideToggle(); jQuery(this).toggleClass('closed'); setUserSetting("wpfilebase_hidesuprow", 1-getUserSetting("wpfilebase_hidesuprow",false), 0); }); }); } </script> <div class="wrap"> <div id="icon-wpfilebase" class="icon32"><br /></div> <h2><?php echo WPFB_PLUGIN_NAME; ?> </h2> <?php if ($show_how_start) { wpfb_call('AdminHowToStart', 'Display'); } if (!empty($_GET['action'])) { echo '<p><a href="' . $clean_uri . '" class="button">' . __('Go back') . '</a></p>'; } switch ($action) { default: $clean_uri = remove_query_arg('pagenum', $clean_uri); $upload_dir = WPFB_Core::UploadDir(); $upload_dir_rel = str_replace(ABSPATH, '', $upload_dir); $chmod_cmd = "CHMOD " . WPFB_PERM_DIR . " " . $upload_dir_rel; if (!is_dir($upload_dir)) { $result = WPFB_Admin::Mkdir($upload_dir); if ($result['error']) { $error_msg = sprintf(__('The upload directory <code>%s</code> does not exists. It could not be created automatically because the directory <code>%s</code> is not writable. Please create <code>%s</code> and make it writable for the webserver by executing the following FTP command: <code>%s</code>', WPFB), $upload_dir_rel, str_replace(ABSPATH, '', $result['parent']), $upload_dir_rel, $chmod_cmd); } else { wpfb_call('Setup', 'ProtectUploadPath'); } } elseif (!is_writable($upload_dir)) { $error_msg = sprintf(__('The upload directory <code>%s</code> is not writable. Please make it writable for PHP by executing the follwing FTP command: <code>%s</code>', WPFB), $upload_dir_rel, $chmod_cmd); } if (!empty($error_msg)) { echo '<div class="error default-password-nag"><p>' . $error_msg . '</p></div>'; } if (!empty(WPFB_Core::$settings->tag_conv_req)) { echo '<div class="updated"><p><a href="' . add_query_arg('action', 'convert-tags') . '">'; _e('WP-Filebase content tags must be converted', WPFB); echo '</a></p></div><div style="clear:both;"></div>'; } if (!get_post(WPFB_Core::$settings->file_browser_post_id)) { echo '<div class="updated"><p>'; printf(__('File Browser post or page not set! Some features like search will not work. <a href="%s">Click here to set the File Browser Post ID.</a>', WPFB), esc_attr(admin_url('admin.php?page=wpfilebase_sets#' . sanitize_title(__('File Browser', WPFB))))); echo '</p></div><div style="clear:both;"></div>'; } /* wpfb_loadclass('Config'); if(!WPFB_Config::IsWritable()) { echo '<div class="updated"><p>'; printf(__('The config file %s is not writable or could not be created. Please create the file and make it writable for the webserver.',WPFB), WPFB_Config::$file); echo '</p></div><div style="clear:both;"></div>'; } */ ?> <?php if (self::PluginHasBeenUsedAWhile(true)) { self::ProUpgradeNag(); } if (self::PluginHasBeenUsedAWhile()) { ?> <div id="wpfb-support-col"> <div id="wpfb-liking-toggle"></div> <h3><?php _e('Like WP-Filebase?', WPFB); ?> </h3> <div id="wpfb-liking"> <!-- <div style="text-align: center;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwordpress.org%2Fextend%2Fplugins%2Fwp-filebase%2F&send=false&layout=button_count&width=150&show_faces=false&action=like&colorscheme=light&font&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:140px; height:21px; display:inline-block; text-align:center;" <?php echo ' allowTransparency="true"'; ?> ></iframe></div> --> <div style="text-align: center;" ><a href="https://twitter.com/wpfilebase" class="twitter-follow-button" data-show-count="false">Follow @wpfilebase</a> <script type="text/javascript">!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></div> <p>Please <a href="http://wordpress.org/support/view/plugin-reviews/wp-filebase">give it a good rating</a>.</p> <p>For Cloud support and lots of other advanced features consider an</p> <p style="text-align: center;"><a href="https://wpfilebase.com/?ref=dblike" class="button-primary">Upgrade to Pro</a></p> <p style="text-align:right;float:right;font-style:italic;">Thanks, Fabian</p> <!-- <div style="text-align: center;"> <?php //WPFB_Admin::PrintPayPalButton() ?> <?php //WPFB_Admin::PrintFlattrButton() ?> </div> --> </div> </div> <?php } ?> <div id="wpfb-stats-wrap" style="float:right; border-left: 1px solid #eee; margin-left: 5px;"> <div id="col-container"> <div id="col-right"> <div class="col-wrap"> <h3><?php _e('Traffic', WPFB); ?> </h3> <table class="wpfb-stats-table"> <?php $traffic_stats = wpfb_call('Misc', 'GetTraffic'); $limit_day = WPFB_Core::$settings->traffic_day * 1048576; $limit_month = WPFB_Core::$settings->traffic_month * 1073741824; ?> <tr> <td><?php if ($limit_day > 0) { self::ProgressBar($traffic_stats['today'] / $limit_day, WPFB_Output::FormatFilesize($traffic_stats['today']) . '/' . WPFB_Output::FormatFilesize($limit_day)); } else { echo WPFB_Output::FormatFilesize($traffic_stats['today']); } ?> </td> <th scope="row"><?php _e('Today', WPFB); ?> </th> </tr> <tr> <td><?php if ($limit_month > 0) { self::ProgressBar($traffic_stats['month'] / $limit_month, WPFB_Output::FormatFilesize($traffic_stats['month']) . '/' . WPFB_Output::FormatFilesize($limit_month)); } else { echo WPFB_Output::FormatFilesize($traffic_stats['month']); } ?> </td> <th scope="row"><?php _e('This Month', WPFB); ?> </th> </tr> <tr> <td><?php echo WPFB_Output::FormatFilesize($wpdb->get_var("SELECT SUM(file_size) FROM {$wpdb->wpfilebase_files}")); ?> </td> <th scope="row"><?php _e('Total File Size', WPFB); ?> </th> </tr> </table> </div> </div><!-- /col-right --> <div id="col-left"> <div class="col-wrap"> <h3><?php _e('Statistics', WPFB); ?> </h3> <table class="wpfb-stats-table"> <tr> <td><?php echo WPFB_File::GetNumFiles(); ?> </td> <th scope="row"><?php _e('Files', WPFB); ?> </th> </tr> <tr> <td><?php echo WPFB_Category::GetNumCats(); ?> </td> <th scope="row"><?php _e('Categories', WPFB); ?> </th> </tr> <tr> <td><?php echo "" . (int) $wpdb->get_var("SELECT SUM(file_hits) FROM {$wpdb->wpfilebase_files}"); ?> </td> <th scope="row"><?php _e('Downloads', WPFB); ?> </th> </tr> </table> </div> </div><!-- /col-left --> </div><!-- /col-container --> </div> <div> <!-- <h2><?php _e('Tools'); ?> </h2> --> <?php $cron_sync_desc = ''; if (WPFB_Core::$settings->cron_sync) { $cron_sync_desc .= __('Automatic sync is enabled. Cronjob scheduled hourly.'); $last_sync_time = intval(get_option(WPFB_OPT_NAME . '_cron_sync_time')); $cron_sync_desc .= $last_sync_time > 0 ? " (" . sprintf(__('Last cron sync on %1$s at %2$s.', WPFB), date_i18n(get_option('date_format'), $last_sync_time), date_i18n(get_option('time_format'), $last_sync_time)) . ")" : ''; } else { $cron_sync_desc .= __('Cron sync is disabled.', WPFB); } $tools = array(array('url' => add_query_arg(array('action' => 'sync')), 'icon' => 'activity', 'label' => __('Sync Filebase', WPFB), 'desc' => __('Synchronises the database with the file system. Use this to add FTP-uploaded files.', WPFB) . '<br />' . $cron_sync_desc)); if (current_user_can('install_plugins')) { // is admin? $new_tag = self::NewExtensionsAvailable() ? '<span class="wp-ui-notification new-exts">new</span>' : ''; $tools[] = array('url' => add_query_arg(array('action' => 'install-extensions')), 'icon' => 'plug', 'label' => __('Extensions', WPFB) . $new_tag, 'desc' => __('Install Extensions to extend functionality of WP-Filebase', WPFB)); } ?> <div id="wpfb-tools"> <h2><?php _e('Tools'); ?> </h2> <ul> <?php foreach ($tools as $id => $tool) { ?> <li id="wpfb-tool-<?php echo $id; ?> "><a href="<?php echo $tool['url']; ?> " <?php if (!empty($tool['confirm'])) { ?> onclick="return confirm('<?php echo $tool['confirm']; ?> ')" <?php } ?> class="button"><span style="background-image:url(<?php echo esc_attr(WPFB_PLUGIN_URI); ?> images/<?php echo $tool['icon']; ?> .png)"></span><?php echo $tool['label']; ?> </a></li> <?php } ?> </ul> <?php foreach ($tools as $id => $tool) { ?> <div id="wpfb-tool-desc-<?php echo $id; ?> " class="tool-desc"> <?php echo $tool['desc']; ?> </div> <?php } ?> <script> if(!jQuery(document.body).hasClass('mobile')) { jQuery('#wpfb-tools li').mouseenter(function(e) { jQuery('#wpfb-tools .tool-desc').hide(); jQuery('#wpfb-tool-desc-'+this.id.substr(10)).show(); }); } </script> <?php if (!empty(WPFB_Core::$settings->tag_conv_req)) { ?> <p><a href="<?php echo add_query_arg('action', 'convert-tags'); ?> " class="button"><?php _e('Convert old Tags', WPFB); ?> </a> <?php printf(__('Convert tags from versions earlier than %s.', WPFB), '0.2.0'); ?> </p> <?php } ?> <!-- <p><a href="<?php echo add_query_arg('action', 'add-urls'); ?> " class="button"><?php _e('Add multiple URLs', WPFB); ?> </a> <?php _e('Add multiple remote files at once.', WPFB); ?> </p> --> </div> <div style="clear: both;"></div> <?php if (WPFB_Core::CurUserCanUpload()) { WPFB_Admin::PrintForm('file', null, array('exform' => $exform)); } ?> <?php if (!$show_how_start) { // display how start here if its hidden wpfb_call('AdminHowToStart', 'Display'); } ?> <h2><?php _e('About'); ?> </h2> <p> <?php echo WPFB_PLUGIN_NAME . ' ' . WPFB_VERSION; ?> by Fabian Schlieper <a href="http://fabi.me/"> <?php if (strpos($_SERVER['SERVER_PROTOCOL'], 'HTTPS') === false) { ?> <img src="http://fabi.me/misc/wpfb_icon.gif?lang=<?php if (defined('WPLANG')) { echo WPLANG; } ?> " alt="" /><?php } ?> fabi.me</a><br/> Includes the great file analyzer <a href="http://www.getid3.org/">getID3()</a> by James Heinrich.<br /> Tools Icons by <a href="http://www.icondeposit.com/">Matt Gentile</a>. </p> <?php if (current_user_can('edit_files')) { ?> <p><a href="<?php echo admin_url('plugins.php?wpfb-uninstall=1'); ?> " class="button"><?php _e('Completely Uninstall WP-Filebase'); ?> </a></p> <?php } break; case 'convert-tags': ?> <h2><?php _e('Tag Conversion'); ?> </h2><?php if (empty($_REQUEST['doit'])) { echo '<div class="updated"><p>'; _e('<strong>Important:</strong> before updating, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>. For help with updates, visit the <a href="http://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.'); echo '</p></div>'; echo '<p><a href="' . add_query_arg('doit', 1) . '" class="button">' . __('Continue') . '</a></p>'; break; } $result = wpfb_call('Setup', 'ConvertOldTags'); ?> <p><?php printf(__('%d Tags in %d Posts has been converted.'), $result['n_tags'], count($result['tags'])); ?> </p> <ul> <?php if (!empty($result['tags'])) { foreach ($result['tags'] as $post_title => $tags) { echo "<li><strong>" . esc_html($post_title) . "</strong><ul>"; foreach ($tags as $old => $new) { echo "<li>{$old} => {$new}</li>"; } echo "</ul></li>"; } } ?> </ul> <?php if (!empty($result['errors'])) { ?> <h2><?php _e('Errors'); ?> </h2> <ul><?php foreach ($result['errors'] as $post_title => $err) { echo "<li><strong>" . esc_html($post_title) . ": </strong> " . esc_html($err) . "<ul>"; } ?> </ul> <?php } $opts = WPFB_Core::GetOpt(); unset($opts['tag_conv_req']); update_option(WPFB_OPT_NAME, $opts); WPFB_Core::$settings = (object) $opts; break; // convert-tags // convert-tags case 'del': if (!empty($_REQUEST['files']) && WPFB_Core::CurUserCanUpload()) { $ids = explode(',', $_REQUEST['files']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($file = WPFB_File::GetFile($id)) != null && $file->CurUserCanEdit()) { $file->Remove(true); $nd++; } } WPFB_File::UpdateTags(); echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Files removed'), $nd) . '</p></div>'; } if (!empty($_REQUEST['cats']) && WPFB_Core::CurUserCanCreateCat()) { $ids = explode(',', $_REQUEST['cats']); $nd = 0; foreach ($ids as $id) { $id = intval($id); if (($cat = WPFB_Category::GetCat($id)) != null) { $cat->Delete(); $nd++; } } echo '<div id="message" class="updated fade"><p>' . sprintf(__('%d Categories removed'), $nd) . '</p></div>'; } case 'sync': echo '<h2>' . __('Synchronisation') . '</h2>'; wpfb_loadclass('Sync'); $result = WPFB_Sync::Sync(!empty($_GET['hash_sync']), true); if (!is_null($result)) { WPFB_Sync::PrintResult($result); } if (empty($_GET['hash_sync'])) { echo '<p><a href="' . add_query_arg('hash_sync', 1) . '" class="button">' . __('Complete file sync', WPFB) . '</a> ' . __('Checks files for changes, so more reliable but might take much longer. Do this if you uploaded/changed files with FTP.', WPFB) . '</p>'; } break; // sync // sync case 'batch-upload': wpfb_loadclass('BatchUploader'); $batch_uploader = new WPFB_BatchUploader(); $batch_uploader->Display(); break; case 'reset-hits': global $wpdb; $n = 0; if (current_user_can('manage_options')) { $n = $wpdb->query("UPDATE `{$wpdb->wpfilebase_files}` SET file_hits = 0 WHERE 1=1"); } echo "<p>"; printf(__('Done. %d Files affected.'), $n); echo "</p>"; break; case 'install-extensions': wpfb_call('AdmInstallExt', 'Display'); break; } // switch ?> </div> <!-- wrap --> <?php }
public static function SettingsUpdated($old, &$new) { $messages = array(); wpfb_call('Setup', 'ProtectUploadPath'); // custom fields: $messages = array_merge($messages, WPFB_Admin::SyncCustomFields()); if ($old['thumbnail_path'] != $new['thumbnail_path']) { update_option(WPFB_OPT_NAME, $old); // temporaly restore old settings WPFB_Core::$settings = (object) $old; $items = array_merge(WPFB_File::GetFiles2(), WPFB_Category::GetCats()); $old_thumbs = array(); foreach ($items as $i => $item) { $old_thumbs[$i] = $item->GetThumbPath(true); } update_option(WPFB_OPT_NAME, $new); // restore new settings WPFB_Core::$settings = (object) $new; $n = 0; foreach ($items as $i => $item) { if (!empty($old_thumbs[$i]) && is_file($old_thumbs[$i])) { $new_path = $item->GetThumbPath(true); $dir = dirname($new_path); if (!is_dir($dir)) { self::Mkdir($dir); } if (rename($old_thumbs[$i], $new_path)) { $n++; } else { $messages[] = sprintf(__('Could not move thumnail %s to %s.', WPFB), $old_thumbs[$i], $new_path); } } } if (count($n > 0)) { $messages[] = sprintf(__('%d Thumbnails moved.', WPFB), $n); } } flush_rewrite_rules(); return $messages; }
public function get_tpl_var($name, $extra = null) { switch ($name) { case 'file_url': return htmlspecialchars($this->GetUrl()); case 'file_url_rel': return htmlspecialchars(WPFB_Core::$settings->download_base . '/' . str_replace('\\', '/', $this->GetLocalPathRel())); case 'file_post_url': return htmlspecialchars(!($url = $this->GetPostUrl()) ? $this->GetUrl() : $url); case 'file_icon_url': return htmlspecialchars($this->GetIconUrl()); case 'file_small_icon': return '<img src="' . esc_attr($this->GetIconUrl('small')) . '" alt="' . esc_attr(sprintf(__('Icon of %s', 'wp-filebase'), $this->file_display_name)) . '" style="vertical-align:middle;width:auto;' . (WPFB_Core::$settings->small_icon_size > 0 ? 'height:' . WPFB_Core::$settings->small_icon_size . 'px;' : '') . '" />'; case 'file_size': return $this->GetFormattedSize(); case 'file_path': return htmlspecialchars($this->GetLocalPathRel()); case 'file_category': return htmlspecialchars(is_object($cat = $this->GetParent()) ? $cat->cat_name : ''); case 'cat_small_icon': return is_null($cat = $this->GetParent()) ? '' : '<img src="' . htmlspecialchars($cat->GetIconUrl('small')) . '" alt="' . esc_attr(sprintf(__('Icon of %s', 'wp-filebase'), $cat->cat_name)) . '" style="width:auto;height:' . WPFB_Core::$settings->small_icon_size . 'px;vertical-align:middle;" />'; case 'cat_icon_url': return is_null($cat = $this->GetParent()) ? '' : htmlspecialchars($cat->GetIconUrl()); case 'cat_url': return is_null($cat = $this->GetParent()) ? '' : htmlspecialchars($cat->GetUrl()); case 'cat_id': return $this->file_category; case 'file_cat_folder': return htmlspecialchars(is_object($cat = $this->GetParent()) ? $cat->cat_folder : ''); case 'file_languages': return wpfb_call('Output', 'ParseSelOpts', array('languages', $this->file_language), true); case 'file_platforms': return wpfb_call('Output', 'ParseSelOpts', array('platforms', $this->file_platform), true); case 'file_requirements': return wpfb_call('Output', 'ParseSelOpts', array('requirements', $this->file_requirement, true), true); case 'file_license': return wpfb_call('Output', 'ParseSelOpts', array('licenses', $this->file_license, true), true); //case 'file_required_level': return ($this->file_required_level - 1); //case 'file_required_level': return ($this->file_required_level - 1); case 'file_user_can_access': return $this->CurUserCanAccess(); case 'file_user_can_edit': return $this->CurUserCanEdit(); case 'file_description': return nl2br($this->file_description); case 'file_tags': return esc_html(str_replace(',', ', ', trim($this->file_tags, ','))); case 'file_date': case 'file_last_dl_time': return htmlspecialchars($this->GetFormattedDate($name)); case 'file_extension': return strtolower(substr(strrchr($this->file_name, '.'), 1)); case 'file_type': return wpfb_call('Download', 'GetFileType', $this->file_name); case 'file_url_encoded': return htmlspecialchars(urlencode($this->GetUrl())); case 'file_added_by': return empty($this->file_added_by) || !($usr = get_userdata($this->file_added_by)) ? '' : esc_html($usr->display_name); case 'file_edit_url': return $this->GetEditUrl(); case 'uid': return self::$tpl_uid; } if (strpos($name, 'file_info/') === 0) { $path = explode('/', substr($name, 10)); return esc_html($this->getInfoValue($path)); } elseif (strpos($name, 'file_custom') === 0) { // dont esc custom return isset($this->{$name}) ? $this->{$name} : ''; } // string length limit: if (!isset($this->{$name}) && ($p = strpos($name, ':')) > 0) { $maxlen = (int) substr($name, $p + 1); $name = substr($name, 0, $p); $str = $this->get_tpl_var($name); if ($maxlen > 3 && strlen($str) > $maxlen) { $str = (function_exists('mb_substr') ? mb_substr($str, 0, $maxlen - 3, 'utf8') : mb_substr($str, 0, $maxlen - 3)) . '...'; } return $str; } if (isset($extra->{$name})) { return $extra->{$name}; } return isset($this->{$name}) ? esc_html($this->{$name}) : ''; }
static function Display() { global $wpdb, $user_ID, $user_identity; wpfb_loadclass('Admin', 'Output', 'TplLib', 'ListTpl'); WPFB_Core::PrintJS(); $_POST = stripslashes_deep($_POST); $_GET = stripslashes_deep($_GET); $action = !empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''); $clean_uri = remove_query_arg(array('message', 'action', 'file_id', 'cat_id', 'deltpl', 'hash_sync')); // keep search keyword // security nonce if (!empty($action) && $action != 'edit' && !check_admin_referer($action . '-' . $_REQUEST['type'], 'wpfb-tpl-nonce')) { wp_die(__('Cheatin’ uh?')); } if ($action == 'add' || $action == 'update') { if (empty($_POST['type'])) { wp_die(__('Type missing!', 'wp-filebase')); } if (empty($_POST['tpltag'])) { wp_die(__('Please enter a template tag.', 'wp-filebase')); } $type = $_POST['type']; $for_cat = $type == 'cat'; $tpl_tag = preg_replace('/[^a-z0-9_-]/', '', str_replace(' ', '_', strtolower($_POST['tpltag']))); if (empty($tpl_tag)) { wp_die('Tag is invalid!'); } if ($type == 'list') { $data = array('header' => $_POST['tpl-list-header'], 'footer' => $_POST['tpl-list-footer'], 'cat_tpl_tag' => $_POST['tpl-list-cat-tpl'], 'file_tpl_tag' => $_POST['tpl-list-file-tpl']); $tpl = new WPFB_ListTpl($tpl_tag, $data); $tpl->Save(); } else { if (empty($_POST['tplcode'])) { wp_die('Please enter some template code.'); } if ($tpl_tag == 'default') { // hanle default tpls a bit different WPFB_Core::UpdateOption("template_{$type}", $_POST['tplcode']); } else { $tpls = WPFB_Core::GetTpls($type); $tpls[$tpl_tag] = $_POST['tplcode']; if ($for_cat) { WPFB_Core::SetCatTpls($tpls); } else { WPFB_Core::SetFileTpls($tpls); } } } WPFB_Admin::ParseTpls(); unset($_POST['type'], $_POST['tpltag'], $_POST['tplcode']); } elseif ($action == 'del') { if (!empty($_GET['type']) && !empty($_GET['tpl']) && !in_array($_GET['tpl'], self::$protected_tags)) { $type = $_GET['type']; if ($type == 'list') { $tpl = WPFB_ListTpl::Get($_GET['tpl']); if ($tpl) { $tpl->Delete(); } } $for_cat = $type == 'cat'; $tpls = WPFB_Core::GetTpls($type); unset($tpls['default']); if (!empty($tpls)) { unset($tpls[$_GET['tpl']]); if ($for_cat) { WPFB_Core::SetCatTpls($tpls); } else { WPFB_Core::SetFileTpls($tpls); } } unset($_POST['type'], $_POST['tpl']); } WPFB_Admin::ParseTpls(); } if (!empty($_POST['reset-tpls'])) { wpfb_call('Setup', 'ResetTpls'); // also reset default templates stored in settings wpfb_loadclass('Admin'); $settings_schema = WPFB_Admin::SettingsSchema(); WPFB_Core::UpdateOption('template_file', $settings_schema['template_file']['default']); WPFB_Core::UpdateOption('template_cat', $settings_schema['template_cat']['default']); WPFB_Admin::ParseTpls(); } ?> <script type="text/javascript"> function WPFB_GenSuccess(data, textStatus, request) { this.html(data); } function WPFB_PreviewTpl(ta, ty) { var tplc = (ty != 'list') ? jQuery(ta).val() : { header: jQuery('#tpl-list-header').val(), footer: jQuery('#tpl-list-footer').val(), file_tpl_tag: jQuery('#tpl-list-file-tpl').val(), cat_tpl_tag: jQuery('#tpl-list-cat-tpl').val() }; var previewId = 'tplinp_'+ty+'_preview'; jQuery.ajax({ type: 'POST', url: '<?php echo WPFB_Core::$ajax_url; ?> ', data: { wpfb_action: "tpl-sample", tpl: tplc, type: ty }, async: true, success: WPFB_GenSuccess, context: jQuery('#'+previewId) }); } jQuery(document).ready( function() { try { jQuery('#wpfb-tabs').tabs(); } catch(ex) {} }); </script> <?php switch ($action) { case 'edit': if (empty($_REQUEST['type']) || empty($_REQUEST['tpl'])) { wp_die('Request error'); } $tpl_tag = $_REQUEST['tpl']; $type = $_REQUEST['type']; if ($type == 'list') { if (WPFB_ListTpl::Get($tpl_tag) == null) { wp_die('No such template!'); } } else { $for_cat = $type == 'cat'; $tpl_src = WPFB_Core::GetTpls($type, $tpl_tag); if (empty($tpl_src)) { wp_die('No such template!'); } } echo '<div class="wrap">'; self::TplForm($type, $tpl_tag); echo '</div>'; break; default: ?> <div class="wrap"> <h2><?php _e('Templates', 'wp-filebase'); if (empty(WPFB_Core::$settings->disable_css) && current_user_can('edit_themes')) { ?> <a href="<?php echo admin_url('admin.php?page=wpfilebase_css'); ?> " class="add-new-h2"><?php _e('Edit Stylesheet', 'wp-filebase'); ?> </a> <?php } ?> <a href="<?php echo add_query_arg('iframe-preview', (int) empty($_GET['iframe-preview'])); ?> " class="add-new-h2">iframe preview</a> </h2> <div id="wpfb-tabs"> <ul class="wpfb-tab-menu"> <li><a href="#file"><?php _e('Files', 'wp-filebase'); ?> </a></li> <li><a href="#cat"><?php _e('Categories'); ?> </a></li> <li><a href="#list"><?php _e('File List', 'wp-filebase'); ?> </a></li> </ul> <div id="file" class="wrap"> <p><?php _e('Templates used for single embedded files or file lists.', 'wp-filebase'); ?> </p> <?php self::TplsTable('file'); ?> </div> <div id="cat" class="wrap"> <p><?php _e('These templates can be used for categories.', 'wp-filebase'); ?> </p> <?php self::TplsTable('cat'); ?> </div> <div id="list" class="wrap"> <p><?php _e('A list-template consists of header, footer and file template. It can optionally have a category template to list sub-categories.', 'wp-filebase'); ?> </p> <?php self::TplsTable('list'); ?> </div> <div id="browser" class="wrap"> </div> </div> <!-- tabs --> <form action="<?php echo remove_query_arg(array('action', 'type', 'tpl')); ?> " method="post" onsubmit="return confirm('<?php _e('This will reset all File, Category and List Templates! Are your sure?', 'wp-filebase'); ?> ');"><p> <input type="submit" name="reset-tpls" value="<?php _e('Reset all Templates to default', 'wp-filebase'); ?> " class="button" /> </p></form> </div> <?php break; } }
static function GetFileTypeStats() { global $wpdb; $stats = get_transient('wpfb_file_type_stats'); if ($stats) { return $stats; } $stats = array(); $results = $wpdb->get_results("\n\t\tSELECT LOWER(SUBSTRING_INDEX(file_name,'.',-1)) as ext, COUNT(file_id) as cnt\n\t\tFROM `{$wpdb->wpfilebase_files}`\n\t\tWHERE LENGTH(SUBSTRING_INDEX(file_name,'.',-1)) < 10\n\t\tGROUP by LOWER(SUBSTRING_INDEX(file_name,'.',-1)) ORDER BY `cnt` DESC LIMIT 40", OBJECT_K); foreach ($results as $r) { $stats[$r->ext] = 0 + $r->cnt; } set_transient('wpfb_file_type_stats', $stats, 24 * HOUR_IN_SECONDS); // should (must) be on daily-base! wpfb_call('ExtensionLib', 'SendStatistics'); return $stats; }
static function Display() { global $wpdb; wpfb_loadclass('Admin', 'Output'); wpfb_call('Output', 'PrintJS'); wp_register_script('rvera-image-picker', WPFB_PLUGIN_URI . 'bower_components/image-picker/image-picker/image-picker.min.js', array('jquery'), WPFB_VERSION); wp_register_style('rvera-image-picker', WPFB_PLUGIN_URI . 'bower_components/image-picker/image-picker/image-picker.css', array(), WPFB_VERSION); if (!current_user_can('manage_options')) { wp_die(__('Cheatin’ uh?') . '<!-- manage_options -->'); } // nonce and referer check (security) if ((!empty($_POST['reset']) || !empty($_POST['submit'])) && !check_admin_referer('wpfb-update-settings', 'wpfb-nonce')) { wp_die(__('Cheatin’ uh?')); } $post = stripslashes_deep($_POST); $action = !empty($post['action']) ? $post['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''); $messages = array(); $errors = array(); $options = get_option(WPFB_OPT_NAME); $option_fields = WPFB_Admin::SettingsSchema(); if (isset($post['reset'])) { // keep templates $file_tpl = WPFB_Core::$settings->template_file; $cat_tpl = WPFB_Core::$settings->template_cat; wpfb_loadclass('Setup'); WPFB_Setup::ResetOptions(); WPFB_Core::UpdateOption('template_file', $file_tpl); WPFB_Core::UpdateOption('template_cat', $cat_tpl); $new_options = get_option(WPFB_OPT_NAME); $messages = array_merge($messages, WPFB_Admin::SettingsUpdated($options, $new_options)); unset($new_options); $messages[] = __('Settings reseted.', 'wp-filebase'); $options = get_option(WPFB_OPT_NAME); } elseif (isset($post['submit'])) { // cleanup foreach ($option_fields as $opt_tag => $opt_data) { if (isset($post[$opt_tag])) { if (!is_array($post[$opt_tag])) { $post[$opt_tag] = trim($post[$opt_tag]); } switch ($opt_data['type']) { case 'number': $post[$opt_tag] = intval($post[$opt_tag]); break; case 'select': // check if value is in options array, if not set to default if (!in_array($post[$opt_tag], array_keys($opt_data['options']))) { $post[$opt_tag] = $opt_data['default']; } break; case 'roles': $post[$opt_tag] = array_values(array_filter($post[$opt_tag])); // the following must not be removed! if the roles array is empty, permissions are assumed to be set for everyone! // so make sure that the admin is explicitly set! if (!empty($opt_data['not_everyone']) && !in_array('administrator', $post[$opt_tag])) { if (!is_array($post[$opt_tag])) { $post[$opt_tag] = array(); } array_unshift($post[$opt_tag], 'administrator'); } break; case 'cat': $post[$opt_tag] = empty($post[$opt_tag]) || is_null($cat = WPFB_Category::GetCat($post[$opt_tag])) ? 0 : intval($post[$opt_tag]); break; } } } $post['upload_path'] = str_replace(ABSPATH, '', $post['upload_path']); $options['upload_path'] = str_replace(ABSPATH, '', $options['upload_path']); $post['download_base'] = trim($post['download_base'], '/'); if (WPFB_Admin::WPCacheRejectUri($post['download_base'] . '/', $options['download_base'] . '/')) { $messages[] = sprintf(__('/%s/ added to rejected URIs list of WP Super Cache.', 'wp-filebase'), $post['download_base']); } $tpl_file = $post['template_file']; $tpl_cat = $post['template_cat']; if (!empty($tpl_file) && (empty($options['template_file_parsed']) || $tpl_file != $options['template_file'])) { wpfb_loadclass('TplLib'); $tpl_file = WPFB_TplLib::Parse($tpl_file); $result = WPFB_TplLib::Check($tpl_file); if (!$result['error']) { $options['template_file_parsed'] = $tpl_file; $messages[] = __('File template successfully parsed.', 'wp-filebase'); } else { $errors[] = sprintf(__('Could not parse template: error (%s) in line %s.', 'wp-filebase'), $result['msg'], $result['line']); } } if (!empty($tpl_cat) && (empty($options['template_cat_parsed']) || $tpl_cat != $options['template_cat'])) { wpfb_loadclass('TplLib'); $tpl_cat = WPFB_TplLib::Parse($tpl_cat); $result = WPFB_TplLib::Check($tpl_cat); if (!$result['error']) { $options['template_cat_parsed'] = $tpl_cat; $messages[] = __('Category template successfully parsed.', 'wp-filebase'); } else { $errors[] = sprintf(__('Could not parse template: error (%s) in line %s.', 'wp-filebase'), $result['msg'], $result['line']); } } $fb_sub_pages = get_pages(array('child_of' => $options['file_browser_post_id'])); if ($options['file_browser_post_id'] > 0 && count($fb_sub_pages)) { $messages[] = sprintf(__('Warning: The Filebrowser page <b>%s</b> has at least one subpage <b>%s</b>. This will cause unexpected behavior, since all requests to the subpages are redirected to the File Browser Page. Please choose a Page that does not have any subpages for File Browser.', 'wp-filebase'), get_the_title($post['file_browser_post_id']), get_the_title($fb_sub_pages[0]->ID)); } // save options foreach ($option_fields as $opt_tag => $opt_data) { $val = isset($post[$opt_tag]) ? $post[$opt_tag] : ''; $options[$opt_tag] = $val; } // make sure a short tag exists, if not append one $select_opts = array('languages', 'platforms', 'licenses', 'requirements', 'custom_fields'); foreach ($select_opts as $opt_tag) { if (empty($options[$opt_tag])) { $options[$opt_tag] = ''; continue; } $lines = explode("\n", $options[$opt_tag]); $lines2 = array(); for ($i = 0; $i < count($lines); $i++) { $lines[$i] = str_replace('||', '|', trim($lines[$i], "|\r")); if (empty($lines[$i]) || $lines[$i] == '|') { continue; } $pos = strpos($lines[$i], '|'); if ($pos <= 0) { $lines[$i] .= '|' . sanitize_key(substr($lines[$i], 0, min(8, strlen($lines[$i])))); } $lines2[] = $lines[$i]; } $options[$opt_tag] = implode("\n", $lines2); } $old_options = get_option(WPFB_OPT_NAME); update_option(WPFB_OPT_NAME, $options); WPFB_Core::$settings = (object) $options; $messages = array_merge($messages, WPFB_Admin::SettingsUpdated($old_options, $options)); if (count($errors) == 0) { $messages[] = __('Settings updated.', 'wp-filebase'); } //refresh any description which can contain opt values $option_fields = WPFB_Admin::SettingsSchema(); } if (WPFB_Core::$settings->allow_srv_script_upload) { $messages[] = __('WARNING: Script upload enabled!', 'wp-filebase'); } $upload_path = WPFB_Core::$settings->upload_path; if (!empty($old_options) && path_is_absolute($upload_path) && !path_is_absolute($old_options['upload_path'])) { $rel_path = str_replace('\\', '/', $upload_path); $rel_path = substr($rel_path, strpos($rel_path, '/') + 1); $messages[] = sprintf(__('NOTICE: The upload path <code>%s</code> is rooted to the filesystem. You should remove the leading slash if you want to use a folder inside your Wordpress directory (i.e: <code>%s</code>)', 'wp-filebase'), $upload_path, $rel_path); } $action_uri = admin_url('admin.php') . '?page=' . $_GET['page'] . '&updated=true'; if (!empty($messages)) { $message = ''; foreach ($messages as $msg) { $message .= '<p>' . $msg . '</p>'; } ?> <div id="message" class="updated fade"><?php echo $message; ?> </div> <?php } if (!empty($errors)) { $error = ''; foreach ($errors as $err) { $error .= '<p>' . $err . '</p>'; } ?> <div id="message" class="error fade"><?php echo $error; ?> </div> <?php } ?> <script type="text/javascript"> /* Option tabs */ jQuery(document).ready(function () { try { jQuery('#wpfb-tabs').tabs(); } catch (ex) { } /*if(typeof(CKEDITOR) != 'undefined') { CKEDITOR.plugins.addExternal('wpfilebase', ajaxurl+'/../../wp-content/plugins/wp-filebase/extras/ckeditor/'); alert( ajaxurl+'/../../wp-content/plugins/wp-filebase/extras/ckeditor/'); }*/ }); </script> <div class="wrap"> <div id="icon-options-general" class="icon32"><br /></div> <h2><?php echo WPFB_PLUGIN_NAME; echo ' '; _e("Settings"); ?> </h2> <form method="post" action="<?php echo $action_uri; ?> " name="wpfilebase-options"> <?php wp_nonce_field('wpfb-update-settings', 'wpfb-nonce'); ?> <p class="submit"> <input type="submit" name="submit" value="<?php _e('Save Changes'); ?> " class="button-primary" /> </p> <?php $misc_tags = array('disable_id3', 'search_id3', 'thumbnail_path', 'use_path_tags', 'no_name_formatting'); if (function_exists('wp_admin_bar_render')) { $misc_tags[] = 'admin_bar'; } $limits = array('bitrate_unregistered', 'bitrate_registered', 'traffic_day', 'traffic_month', 'traffic_exceeded_msg', 'file_offline_msg', 'daily_user_limits', 'daily_limit_subscriber', 'daily_limit_contributor', 'daily_limit_author', 'daily_limit_editor', 'daily_limit_exceeded_msg'); $option_categories = array(__('Common', 'wp-filebase') => array('upload_path', 'search_integration'), __('Display', 'wp-filebase') => array('file_date_format', 'thumbnail_size', 'auto_attach_files', 'attach_loop', 'attach_pos', 'filelist_sorting', 'filelist_sorting_dir', 'filelist_num', 'decimal_size_format', 'search_result_tpl', 'disable_css'), __('File Browser', 'wp-filebase') => array('file_browser_post_id', 'file_browser_cat_sort_by', 'file_browser_cat_sort_dir', 'file_browser_file_sort_by', 'file_browser_file_sort_dir', 'file_browser_fbc', 'late_script_loading', 'folder_icon', 'small_icon_size', 'disable_footer_credits', 'footer_credits_style', 'file_browser_inline_add'), __('Download', 'wp-filebase') => array('hide_links', 'disable_permalinks', 'download_base', 'force_download', 'range_download', 'http_nocache', 'ignore_admin_dls', 'accept_empty_referers', 'allowed_referers', 'use_fpassthru'), __('Form Presets', 'wp-filebase') => array('default_author', 'default_roles', 'default_cat', 'default_direct_linking', 'languages', 'platforms', 'licenses', 'requirements', 'custom_fields'), __('Limits', 'wp-filebase') => $limits, __('Security', 'wp-filebase') => array('allow_srv_script_upload', 'fext_blacklist', 'frontend_upload', 'hide_inaccessible', 'inaccessible_msg', 'inaccessible_redirect', 'cat_inaccessible_msg', 'login_redirect_src', 'protect_upload_path', 'private_files'), __('Templates and Scripts', 'wp-filebase') => array('template_file', 'template_cat', 'dlclick_js'), __('Sync', 'wp-filebase') => array('cron_sync', 'base_auto_thumb', 'remove_missing_files', 'fake_md5'), __('Misc') => $misc_tags); ?> <div id="wpfb-tabs"> <ul class="wpfb-tab-menu"> <?php foreach ($option_categories as $key => $val) { echo '<li><a href="#' . sanitize_title($key) . '">' . esc_html($key) . '</a></li>'; } ?> </ul> <?php $page_option_list = ''; $n = 0; foreach ($option_categories as $opt_cat => $opt_cat_fields) { //echo "\n".'<h3>'.$opt_cat.'</h3>'; echo "\n\n" . '<div id="' . sanitize_title($opt_cat) . '" class="wpfilebase-opttab"><h3>' . $opt_cat . '</h3><table class="form-table">'; foreach ($opt_cat_fields as $opt_tag) { $field_data = $option_fields[$opt_tag]; $opt_val = $options[$opt_tag]; echo "\n" . '<tr valign="top">' . "\n" . '<th scope="row">' . $field_data['title'] . '</th>' . "\n" . '<td>'; $style_class = ''; if (!empty($field_data['class'])) { $style_class .= ' class="' . $field_data['class'] . '"'; } if (!empty($field_data['style'])) { $style_class .= ' style="' . $field_data['style'] . '"'; } switch ($field_data['type']) { case 'text': case 'number': case 'checkbox': echo '<input name="' . $opt_tag . '" type="' . $field_data['type'] . '" id="' . $opt_tag . '"'; echo !empty($field_data['class']) ? ' class="' . $field_data['class'] . '"' : ''; if ($field_data['type'] == 'checkbox') { echo ' value="1" '; checked('1', $opt_val); } elseif ($field_data['type'] == 'number') { echo ' value="' . intval($opt_val) . '" size="5" style="text-align: right"'; } else { echo ' value="' . esc_attr($opt_val) . '"'; if (isset($field_data['size'])) { echo ' size="' . (int) $field_data['size'] . '"'; } } echo $style_class . ' />'; break; case 'textarea': $code_edit = strpos($opt_tag, 'template_') !== false || isset($field_data['class']) && strpos($field_data['class'], 'code') !== false; $nowrap = !empty($field_data['nowrap']); echo '<textarea name="' . $opt_tag . '" id="' . $opt_tag . '"'; if ($nowrap || $code_edit) { echo ' cols="100" wrap="off" style="width: 100%;' . ($code_edit ? 'font-size: 10px;' : '') . '"'; } else { echo ' cols="50"'; } echo ' rows="' . ($code_edit ? 20 : 5) . '"'; echo $style_class; echo '>'; echo esc_html($opt_val); echo '</textarea>'; break; case 'select': echo '<select name="' . $opt_tag . '" id="' . $opt_tag . '">'; foreach ($field_data['options'] as $opt_v => $opt_n) { echo '<option value="' . esc_attr($opt_v) . '"' . ($opt_v == $opt_val ? ' selected="selected" ' : '') . $style_class . '>' . (!is_numeric($opt_v) && $opt_v !== $opt_n ? esc_html($opt_v) . ': ' : '') . esc_html($opt_n) . '</option>'; } echo '</select>'; break; case 'roles': WPFB_Admin::RolesCheckList($opt_tag, $opt_val, empty($field_data['not_everyone'])); break; case 'icon': wp_print_scripts('rvera-image-picker'); wp_print_styles('rvera-image-picker'); echo '<select class="image-picker show-html" name="' . $opt_tag . '" id="' . $opt_tag . '">'; ?> <?php foreach ($field_data['icons'] as $icon) { echo '<option data-img-src="' . $icon['url'] . '" value="' . $icon['path'] . '" ' . ($icon['path'] === $opt_val ? ' selected="selected" ' : '') . '>' . basename($icon['path']) . '</option>'; } ?> </select> <script type="text/javascript"> jQuery(document).ready(function () { jQuery("#<?php echo $opt_tag; ?> ").imagepicker() .next() .find('img[src$=".svg"]').parent().append('<br>SVG'); }); </script> <?php break; case 'cat': echo "<select name='{$opt_tag}' id='{$opt_tag}'>"; echo WPFB_Output::CatSelTree(array('selected' => $opt_val)); echo "</select>"; break; } if (!empty($field_data['unit'])) { echo ' ' . $field_data['unit']; } if (!empty($field_data['desc'])) { echo "\n" . '<br />' . str_replace('%value%', is_array($opt_val) ? join(', ', $opt_val) : $opt_val, $field_data['desc']); } echo "\n</td>\n</tr>"; $page_option_list .= $opt_tag . ','; } echo '</table></div>' . "\n"; } ?> </div> <!--wpfilebase-opttabs--> <input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="<?php echo $page_option_list; ?> " /> <p class="submit"> <input type="submit" name="submit" value="<?php _e('Save Changes'); ?> " class="button-primary" /> <input type="submit" name="reset" value="<?php _e('Restore Default Settings', 'wp-filebase'); ?> " onclick="return confirm('<?php _e('All settings (except default file and category template) will be set to default values. Continue?', 'wp-filebase'); ?> ')" class="button delete" style="float: right;" /> </p> </form> </div> <!-- wrap --> <?php }
function GenTpl($parsed_tpl = null, $context = '') { if ($context != 'ajax') { WPFB_Core::$load_js = true; } if (empty($parsed_tpl)) { $tpo = $this->is_file ? 'template_file_parsed' : 'template_cat_parsed'; $parsed_tpl = WPFB_Core::GetOpt($tpo); if (empty($parsed_tpl)) { $parsed_tpl = wpfb_call('TplLib', 'Parse', WPFB_Core::GetOpt($this->is_file ? 'template_file' : 'template_cat')); WPFB_Core::UpdateOption($tpo, $parsed_tpl); } } /* if($this->is_file) { global $wpfb_file_paths; if(empty($wpfb_file_paths)) $wpfb_file_paths = array(); $wpfb_file_paths[(int)$this->file_id] = $this->GetLocalPathRel(); } */ self::$tpl_uid++; $f =& $this; return eval("return ({$parsed_tpl});"); }
static function WidgetStats() { global $wpdb; ?> <div id="col-container"> <div id="col-right"> <div class="col-wrap"> <h3><?php _e('Traffic', 'wp-filebase'); ?> </h3> <table class="wpfb-stats-table"> <?php $traffic_stats = wpfb_call('Misc', 'GetTraffic'); $limit_day = WPFB_Core::$settings->traffic_day * 1048576; $limit_month = WPFB_Core::$settings->traffic_month * 1073741824; ?> <tr> <td><?php if ($limit_day > 0) { WPFB_AdminGuiManage::ProgressBar($traffic_stats['today'] / $limit_day, WPFB_Output::FormatFilesize($traffic_stats['today']) . '/' . WPFB_Output::FormatFilesize($limit_day)); } else { echo WPFB_Output::FormatFilesize($traffic_stats['today']); } ?> </td> <th scope="row"><?php _e('Today', 'wp-filebase'); ?> </th> </tr> <tr> <td><?php if ($limit_month > 0) { WPFB_AdminGuiManage::ProgressBar($traffic_stats['month'] / $limit_month, WPFB_Output::FormatFilesize($traffic_stats['month']) . '/' . WPFB_Output::FormatFilesize($limit_month)); } else { echo WPFB_Output::FormatFilesize($traffic_stats['month']); } ?> </td> <th scope="row"><?php _e('This Month', 'wp-filebase'); ?> </th> </tr> <tr> <td><?php echo WPFB_Output::FormatFilesize($wpdb->get_var("SELECT SUM(file_size) FROM {$wpdb->wpfilebase_files}")); ?> </td> <th scope="row"><?php _e('Total File Size', 'wp-filebase'); ?> </th> </tr> </table> </div> </div><!-- /col-right --> <div id="col-left"> <div class="col-wrap"> <h3><?php _e('Statistics', 'wp-filebase'); ?> </h3> <table class="wpfb-stats-table"> <tr> <td><?php echo WPFB_File::GetNumFiles(); ?> </td> <th scope="row"><?php _e('Files', 'wp-filebase'); ?> </th> </tr> <tr> <td><?php echo WPFB_Category::GetNumCats(); ?> </td> <th scope="row"><?php _e('Categories'); ?> </th> </tr> <tr> <td><?php echo "" . (int) $wpdb->get_var("SELECT SUM(file_hits) FROM {$wpdb->wpfilebase_files}"); ?> </td> <th scope="row"><?php _e('Downloads', 'wp-filebase'); ?> </th> </tr> </table> </div> </div><!-- /col-left --> </div><!-- /col-container --> <?php }
function process_bulk_action() { if (!$this->current_action() || empty($_REQUEST['file']) && empty($_REQUEST['action2'])) { return; } // filter files current user can edit $files = isset($_REQUEST['file']) ? array_filter(array_map(array('WPFB_File', 'GetFile'), $_REQUEST['file']), create_function('$file', 'return ($file && $file->CurUserCan' . 'Edit' . '());')) : array(); $message = null; switch ($this->current_action()) { case 'delete': foreach ($files as $file) { $file->Remove(true); } WPFB_Admin::SyncCustomFields(); $message = sprintf(__("%d File(s) deleted.", WPFB), count($files)); break; case 'edit': if (isset($_REQUEST['action2']) && $_REQUEST['action2'] == 'apply') { $message = wpfb_call('AdminGuiBulkEdit', 'Process'); } else { wpfb_call('AdminGuiBulkEdit', 'Display'); exit; } break; case 'set_off': foreach ($files as $file) { $file->file_offline = 1; $file->DbSave(); } $message = sprintf(__("%d File(s) were set offline.", WPFB), count($files)); break; case 'set_on': foreach ($files as $file) { $file->file_offline = 0; $file->DbSave(); } $message = sprintf(__("%d File(s) were set online.", WPFB), count($files)); break; } if (!empty($message)) { ?> <div id="message" class="updated fade"><p><?php echo $message; ?> </p></div><?php } }
?> </div> <div id="flash-upload-ui"><?php $adv_uploader->Display(); ?> </div> <!-- flash-upload-ui --> <?php if ($update) { echo '<div>' . __('Rename') . ': '; ?> <input name="file_rename" id="file_rename" type="text" value="<?php echo esc_attr($file->file_name); ?> " style="width:280px;" /><br /> <?php echo ' (' . $file->GetFormattedSize() . ', ' . wpfb_call('Download', 'GetFileType', $file->file_name) . ', MD5: <code>' . $file->file_hash . '</code>)</div>'; } ?> </div> <div id="file-remote-wrap" <?php echo $file->IsRemote() ? '' : 'class="hidden"'; ?> > <label for="file_remote_uri"><?php _e('File URL'); ?> </label> <input name="file_remote_uri" id="file_remote_uri" type="text" value="<?php echo esc_attr($file->file_remote_uri); ?> " style="width:98%" /><br />
private static function CheckChangedVer() { $ver = wpfb_call('Core', 'GetOpt', 'version'); if ($ver != WPFB_VERSION) { wpfb_loadclass('Setup'); WPFB_Setup::OnActivateOrVerChange($ver); } }
function form($instance) { wpfb_call('WidgetForms', 'FileListWidget', array($this, $instance), true); }
static function AdminPrintScripts() { if (!empty($_GET['page']) && strpos($_GET['page'], 'wpfilebase_') !== false) { if ($_GET['page'] == 'wpfilebase_manage') { wpfb_loadclass('AdminDashboard'); WPFB_AdminDashboard::Setup(true); } wpfb_call('Output', 'PrintJS'); } if (has_filter('ckeditor_external_plugins')) { ?> <script type="text/javascript"> //<![CDATA[ /* CKEditor Plugin */ if (typeof(ckeditorSettings) == 'object') { ckeditorSettings.externalPlugins.wpfilebase = ajaxurl + '/../../wp-content/plugins/wp-filebase/extras/ckeditor/'; ckeditorSettings.additionalButtons.push(["WPFilebase"]); } //]]> </script> <?php } }
function wpfilebase_deactivate() { wpfb_loadclass('Core', 'Admin', 'Setup'); wpfb_call('ExtensionLib', 'PluginDeactivated'); WPFB_Setup::OnDeactivate(); }