/**
  * Get category objects
  *
  * @access public
  *
  * @param int $id ID 
  * @return WPFB_Category
  */
 static function GetCat($id)
 {
     $id = intval($id);
     if ($id > 0 && (isset(self::$cache[$id]) || WPFB_Category::GetCats("WHERE cat_id = {$id}"))) {
         return self::$cache[$id];
     }
     return null;
 }
Beispiel #2
0
 function WPFB_SyncData($init = false)
 {
     if ($init) {
         $this->files = WPFB_File::GetFiles2();
         $this->cats = WPFB_Category::GetCats();
         $this->log = array('missing_files' => array(), 'missing_folders' => array(), 'changed' => array(), 'not_added' => array(), 'error' => array(), 'updated_categories' => array(), 'warnings' => array());
         $this->known_filenames = array();
         $this->new_files = array();
         $this->missing_files = array();
         $this->num_files_to_add = 0;
         $this->num_all_files = 0;
         $this->num_files_processed = 0;
         $this->time_begin = microtime(true);
         $this->mem_peak = memory_get_peak_usage();
     }
 }
Beispiel #3
0
 static function GetByPath($path)
 {
     global $wpdb;
     $path = trim(str_replace('\\', '/', $path), '/');
     $items = WPFB_Category::GetCats("WHERE cat_path = '" . esc_sql($path) . "' LIMIT 1");
     if (empty($items)) {
         $items = WPFB_File::GetFiles2(array('file_path' => $path), false, null, 1);
         if (empty($items)) {
             return null;
         }
     }
     return reset($items);
 }
Beispiel #4
0
 function __construct($init = false)
 {
     if ($init) {
         $this->queryDbState();
         $this->cats = WPFB_Category::GetCats();
         $this->log = array('missing_files' => array(), 'missing_folders' => array(), 'changed' => array(), 'not_added' => array(), 'error' => array(), 'updated_categories' => array(), 'warnings' => array());
         $this->new_files = array();
         $this->missing_files = array();
         $this->num_files_to_add = 0;
         $this->num_all_files = 0;
         $this->num_files_processed = 0;
         $this->time_begin = microtime(true);
         $this->mem_peak = memory_get_peak_usage();
     }
 }
 function widget($args, $instance)
 {
     // if no filebrowser this widget doosnt work
     if (WPFB_Core::$settings->file_browser_post_id <= 0) {
         return;
     }
     wpfb_loadclass('Category', 'Output');
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     echo $before_widget, $before_title . (empty($title) ? __('File Categories', WPFB) : $title) . $after_title;
     $tree = !empty($instance['hierarchical']);
     // load all categories
     WPFB_Category::GetCats();
     $cats = WPFB_Category::GetCats(($tree ? 'WHERE cat_parent = ' . (empty($instance['root-cat']) ? 0 : (int) $instance['root-cat']) : '') . ' ORDER BY ' . $instance['sort-by'] . ' ' . ($instance['sort-asc'] ? 'ASC' : 'DESC'));
     echo '<ul>';
     foreach ($cats as $cat) {
         if ($tree) {
             WPFB_Widget::CatTree($cat);
         } elseif ($cat->CurUserCanAccess(true)) {
             echo '<li><a href="' . $cat->GetUrl() . '">' . esc_html($cat->cat_name) . '</a></li>';
         }
     }
     echo '</ul>';
     echo $after_widget;
 }
Beispiel #6
0
 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;
 }
Beispiel #7
0
 static function CatSelTree($args = null, $root_cat_id = 0, $depth = 0)
 {
     static $s_sel, $s_ex, $s_nol, $s_count, $s_add_cats;
     if (!is_null($args)) {
         if (is_array($args)) {
             $s_sel = empty($args['selected']) ? 0 : intval($args['selected']);
             $s_ex = empty($args['exclude']) ? 0 : intval($args['exclude']);
             $s_nol = empty($args['none_label']) ? 0 : $args['none_label'];
             $s_count = !empty($args['file_count']);
             $s_add_cats = !empty($args['add_cats']);
         } else {
             $s_sel = intval($args);
             $s_ex = 0;
             $s_nol = null;
             $s_count = false;
             $s_add_cats = false;
         }
     }
     $out = '';
     if ($root_cat_id <= 0) {
         $out .= '<option value="0"' . (0 == $s_sel ? ' selected="selected"' : '') . ' style="font-style:italic;">' . (empty($s_nol) ? __('None') : $s_nol) . ($s_count ? ' (' . WPFB_File::GetNumFiles(0) . ')' : '') . '</option>';
         $cats = WPFB_Category::GetCats();
         foreach ($cats as $c) {
             if ($c->cat_parent <= 0 && $c->cat_id != $s_ex && $c->CurUserCanAccess()) {
                 $out .= self::CatSelTree(null, $c->cat_id, 0);
             }
         }
         if ($s_add_cats) {
             $out .= '<option value="+0" class="add-cat">+ ' . __('Add Category', WPFB) . '</option>';
         }
     } else {
         $cat = WPFB_Category::GetCat($root_cat_id);
         $out .= '<option value="' . $root_cat_id . '"' . ($root_cat_id == $s_sel ? ' selected="selected"' : '') . '>' . str_repeat('&nbsp;&nbsp; ', $depth) . esc_html($cat->cat_name) . ($s_count ? ' (' . $cat->cat_num_files . ')' : '') . '</option>';
         if ($s_add_cats) {
             $out .= '<option value="+' . $root_cat_id . '" class="add-cat">' . str_repeat('&nbsp;&nbsp; ', $depth + 1) . '+ ' . __('Add Category', WPFB) . '</option>';
         }
         if (isset($cat->cat_childs)) {
             foreach ($cat->cat_childs as $c) {
                 if ($c->cat_id != $s_ex && $c->CurUserCanAccess()) {
                     $out .= self::CatSelTree(null, $c->cat_id, $depth + 1);
                 }
             }
         }
     }
     return $out;
 }
Beispiel #8
0
    static function Display()
    {
        global $wpdb, $user_ID;
        if (!WPFB_Admin::CurUserCanCreateCat()) {
            wp_die(__('Cheatin&#8217; uh?'));
        }
        wpfb_loadclass('Category', 'File', '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'));
        // 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);
        } else {
            $exform = (bool) get_user_option(WPFB_OPT_NAME . '_exform');
        }
        ?>
	<div class="wrap">
	<?php 
        switch ($action) {
            case 'editcat':
                $cat_id = (int) $_GET['cat_id'];
                $file_category = WPFB_Category::GetCat($cat_id);
                if (is_null($file_category) || !$file_category->CurUserCanEdit()) {
                    wp_die(__('Cheatin&#8217; uh?'));
                }
                WPFB_Admin::PrintForm('cat', $file_category);
                break;
            case 'updatecat':
                $cat_id = (int) $_POST['cat_id'];
                $update = true;
                $file_category = WPFB_Category::GetCat($cat_id);
                if (is_null($file_category) || !$file_category->CurUserCanEdit()) {
                    wp_die(__('Cheatin&#8217; uh?'));
                }
            case 'addcat':
                $update = !empty($update);
                $result = WPFB_Admin::InsertCategory(array_merge(stripslashes_deep($_POST), $_FILES));
                if (isset($result['error']) && $result['error']) {
                    $message = $result['error'];
                } else {
                    $message = $update ? __('Category updated.') : __('Category added.');
                    /*def*/
                }
                //wp_redirect($clean_uri . '&action=manage_cats&message=' . urlencode($message));
            //wp_redirect($clean_uri . '&action=manage_cats&message=' . urlencode($message));
            default:
                if (!empty($_POST['deleteit'])) {
                    foreach ((array) $_POST['delete'] as $cat_id) {
                        if (is_object($cat = WPFB_Category::GetCat($cat_id)) && $cat->CurUserCanEdit()) {
                            $cat->Delete();
                        }
                    }
                }
                ?>
	<h2><?php 
                echo str_replace(array('(<', '>)'), array('<', '>'), sprintf(__('Manage Categories (<a href="%s">add new</a>)', WPFB), '#addcat" class="add-new-h2'));
                if (isset($_GET['s']) && $_GET['s']) {
                    printf('<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html(stripslashes($_GET['s'])));
                }
                ?>
</h2>

	<?php 
                if (!empty($message)) {
                    ?>
<div id="message" class="updated fade"><p><?php 
                    echo $message;
                    ?>
</p></div><?php 
                }
                ?>
 

	<form class="search-form topmargin" action="" method="get"><p class="search-box">
		<input type="hidden" value="<?php 
                echo esc_attr($_GET['page']);
                ?>
" name="page" />
		<label class="hidden" for="category-search-input"><?php 
                _e('Search Categories');
                ?>
:</label>
		<input type="text" class="search-input" id="category-search-input" name="s" value="<?php 
                echo isset($_GET['s']) ? esc_attr($_GET['s']) : '';
                ?>
" />
		<input type="submit" value="<?php 
                _e('Search Categories');
                ?>
" class="button" />
	</p></form>	
	
	<br class="clear" />
	
	<form id="posts-filter" action="" method="post">
		<div class="tablenav">
			<?php 
                $pagenum = max(isset($_GET['pagenum']) ? absint($_GET['pagenum']) : 0, 1);
                if (!isset($catsperpage) || $catsperpage < 0) {
                    $catsperpage = 20;
                }
                $pagestart = ($pagenum - 1) * $catsperpage;
                $extra_sql = '';
                if (!empty($_GET['s'])) {
                    $s = esc_sql(trim($_GET['s']));
                    $extra_sql .= "WHERE cat_name LIKE '%{$s}%' OR cat_description LIKE '%{$s}%' OR cat_folder LIKE '%{$s}%' ";
                }
                if (!empty($_GET['order']) && in_array($_GET['order'], array_keys(get_class_vars('WPFB_Category')))) {
                    $extra_sql .= "ORDER BY " . $_GET['order'] . " " . (!empty($_GET['desc']) ? "DESC" : "ASC");
                }
                $cats = WPFB_Category::GetCats($extra_sql . " LIMIT {$pagestart}, {$catsperpage}");
                $page_links = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'total' => ceil(count(WPFB_Category::GetCats($extra_sql)) / $catsperpage), 'current' => $pagenum));
                if ($page_links) {
                    echo "<div class='tablenav-pages'>{$page_links}</div>";
                }
                ?>

			<div class="alignleft"><input type="submit" value="<?php 
                _e('Delete');
                ?>
" name="deleteit" class="button delete" /><?php 
                wp_nonce_field('bulk-categories');
                ?>
</div>
		</div>
	
		<br class="clear" />

		<table class="widefat">
			<thead>
			<tr>
				<th scope="col" class="check-column"><input type="checkbox" /></th>
				<th scope="col"><a href="<?php 
                echo WPFB_Admin::AdminTableSortLink('cat_name');
                ?>
"><?php 
                _e('Name');
                ?>
</a></th>
				<th scope="col"><a href="<?php 
                echo WPFB_Admin::AdminTableSortLink('cat_description');
                ?>
"><?php 
                _e('Description');
                ?>
</a></th>
				<th scope="col" class="num"><a href="<?php 
                echo WPFB_Admin::AdminTableSortLink('cat_num_files');
                ?>
"><?php 
                _e('Files', WPFB);
                ?>
</a></th>
				<th scope="col"><a href="<?php 
                echo WPFB_Admin::AdminTableSortLink('cat_parent');
                ?>
"><?php 
                _e('Parent Category');
                ?>
</a></th>
				<th scope="col"><a href="<?php 
                echo WPFB_Admin::AdminTableSortLink('cat_path');
                ?>
"><?php 
                _e('Path');
                ?>
</a></th>
				<th scope="col"><a href="<?php 
                echo WPFB_Admin::AdminTableSortLink('cat_user_roles');
                ?>
"><?php 
                _e('Access Permission', WPFB);
                ?>
</a></th>

				<th scope="col"><a href="<?php 
                echo WPFB_Admin::AdminTableSortLink('cat_owner');
                ?>
"><?php 
                _e('Owner', WPFB);
                ?>
</a></th>
				<th scope="col"><a href="<?php 
                echo WPFB_Admin::AdminTableSortLink('cat_order');
                ?>
"><?php 
                _e('Custom Sort Order', WPFB);
                ?>
</a></th>
			</tr>
			</thead>
			<tbody id="the-list" class="list:cat">
			
			<?php 
                foreach ($cats as $cat_id => &$cat) {
                    if ($cat->CurUserCanEdit()) {
                        self::CatRow($cat);
                    }
                }
                ?>
			
			</tbody>
		</table>
		<div class="tablenav"><?php 
                if ($page_links) {
                    echo "<div class='tablenav-pages'>{$page_links}</div>";
                }
                ?>
</div>
	</form>
	<br class="clear" />
	
	<?php 
                if (WPFB_Admin::CurUserCanCreateCat()) {
                    ?>
		<p><?php 
                    _e('<strong>Note:</strong><br />Deleting a category does not delete the files in that category. Instead, files that were assigned to the deleted category are set to the parent category.', WPFB);
                    ?>
</p><?php 
                    WPFB_Admin::PrintForm('cat');
                }
                break;
        }
        ?>
</div> <!-- wrap -->
<?php 
    }