Пример #1
0
 /**
  * Get category objects
  *
  * @access public
  * 
  * @param $extra_sql Optional
  * @return WPFB_Category[] Categories
  */
 static function GetCats($extra_sql = null)
 {
     global $wpdb;
     if (empty($extra_sql)) {
         $extra_sql = 'ORDER BY cat_name ASC';
         if (self::$cache_complete) {
             return self::$cache;
         } else {
             self::$cache_complete = true;
         }
     }
     $cats = array();
     $results = $wpdb->get_results("SELECT * FROM {$wpdb->wpfilebase_cats} {$extra_sql}");
     if (!empty($results)) {
         foreach (array_keys($results) as $i) {
             $id = (int) $results[$i]->cat_id;
             if (!isset(self::$cache[$id])) {
                 self::$cache[$id] = new WPFB_Category($results[$i]);
             }
             $cats[$id] = self::$cache[$id];
             // always use items from cache
         }
     }
     // child cats
     foreach (array_keys($cats) as $id) {
         $cat =& $cats[$id];
         $pid = (int) $cat->cat_parent;
         if ($pid > 0 && isset(self::$cache[$pid])) {
             $pcat =& self::$cache[$pid];
             if (!isset($pcat->cat_childs) || !is_array($pcat->cat_childs)) {
                 $pcat->cat_childs = array();
             }
             $pcat->cat_childs[$id] = $cat;
         }
     }
     return $cats;
 }
Пример #2
0
 function Delete()
 {
     global $wpdb;
     // TODO: error handling
     $cats = $this->GetChildCats();
     $files = $this->GetChildFiles();
     $parent_id = $this->GetParentId();
     foreach ($cats as $cat) {
         $cat->ChangeCategoryOrName($parent_id);
     }
     foreach ($files as $file) {
         $file->ChangeCategoryOrName($parent_id);
     }
     self::$cache_complete = false;
     unset(self::$cache[0 + $this->cat_id]);
     // delete the category
     @unlink($this->GetLocalPath());
     @rmdir($this->GetLocalPath());
     $wpdb->query("DELETE FROM {$wpdb->wpfilebase_cats} WHERE cat_id = " . (int) $this->GetId());
     return array('error' => false);
 }