Esempio n. 1
0
 function getCategoryStructure()
 {
     if (is_null($this->categoryStructure)) {
         $allcategories = query_full_array("SELECT * FROM " . prefix('news_categories') . " ORDER by sort_order");
         $structure = array();
         foreach ($allcategories as $cat) {
             $catobj = new ZenpageCategory($cat['titlelink']);
             if ($catobj->isMyItem(VIEW_NEWS_RIGHTS)) {
                 $cat['show'] = 1;
             } else {
                 if ($cat['show'] && $cat['parentid']) {
                     $cat['show'] = $structure[$cat['parentid']]['show'];
                 }
             }
             $structure[$cat['id']] = $cat;
         }
         $structure = sortMultiArray($structure, 'sort_order', false, false, false, true);
         $this->categoryStructure = $structure;
     }
     return $this->categoryStructure;
 }
Esempio n. 2
0
 /**
  * Gets all categories
  * @param bool $visible TRUE for published and unprotected
  * @param string $sorttype NULL for the standard order as sorted on the backend, "title", "id", "popular", "random"
  * @param bool $sortdirection TRUE for ascending or FALSE for descending order
  * @return array
  */
 function getAllCategories($visible = true, $sorttype = NULL, $sortdirection = NULL)
 {
     $structure = $this->getCategoryStructure();
     if (is_null($sortdirection)) {
         $sortdirection = $this->sortdirection;
     }
     switch ($sorttype) {
         case "id":
             $sortorder = "id";
             break;
         case "title":
             $sortorder = "title";
             break;
         case "popular":
             $sortorder = 'hitcounter';
             break;
         case "random":
             $sortorder = 'random';
             break;
         default:
             $sortorder = "sort_order";
             break;
     }
     if ($visible) {
         foreach ($structure as $key => $cat) {
             $catobj = new ZenpageCategory($cat['titlelink']);
             if ($catobj->getShow() || $catobj->isMyItem(LIST_RIGHTS)) {
                 $structure[$key]['show'] = 1;
             } else {
                 unset($structure[$key]);
             }
         }
     }
     if (!is_null($sorttype) || !is_null($sortdirection)) {
         if ($sorttype == 'random') {
             shuffle($structure);
         } else {
             //sortMultiArray descending = true
             if ($sortdirection) {
                 $sortdir = false;
             } else {
                 $sortdir = true;
             }
             $structure = sortMultiArray($structure, $sortorder, $sortdir, true, false, false);
         }
     }
     return $structure;
 }
/**
 * Prints the nested list for pages and categories
 *
 * @param string $listtype 'cats-checkboxlist' for a fake nested checkbock list of categories for the news article edit/add page
 * 												'cats-sortablelist' for a sortable nested list of categories for the admin categories page
 * 												'pages-sortablelist' for a sortable nested list of pages for the admin pages page
 * @param int $articleid Only for $listtype = 'cats-checkboxlist': For ID of the news article if the categories an existing articles is assigned to shall be shown, empty if this is a new article to be added.
 * @param string $option Only for $listtype = 'cats-checkboxlist': "all" to show all categories if creating a new article without categories assigned, empty if editing an existing article that already has categories assigned.
 * @return string | bool
 */
function printNestedItemsList($listtype = 'cats-sortablelist', $articleid = '', $option = '')
{
    global $_zp_zenpage;
    switch ($listtype) {
        case 'cats-checkboxlist':
        default:
            $ulclass = "";
            break;
        case 'cats-sortablelist':
        case 'pages-sortablelist':
            $ulclass = " class=\"page-list\"";
            break;
    }
    switch ($listtype) {
        case 'cats-checkboxlist':
        case 'cats-sortablelist':
            $items = $_zp_zenpage->getAllCategories(false);
            break;
        case 'pages-sortablelist':
            $items = $_zp_zenpage->getPages(false);
            break;
        default:
            $items = array();
            break;
    }
    $indent = 1;
    $open = array(1 => 0);
    $rslt = false;
    foreach ($items as $item) {
        switch ($listtype) {
            case 'cats-checkboxlist':
            case 'cats-sortablelist':
                $itemobj = new ZenpageCategory($item['titlelink']);
                $ismypage = $itemobj->isMyItem(ZENPAGE_NEWS_RIGHTS);
                break;
            case 'pages-sortablelist':
                $itemobj = new ZenpagePage($item['titlelink']);
                $ismypage = $itemobj->isMyItem(ZENPAGE_PAGES_RIGHTS);
                break;
        }
        $itemsortorder = $itemobj->getSortOrder();
        $itemid = $itemobj->getID();
        if ($ismypage) {
            $order = explode('-', $itemsortorder);
            $level = max(1, count($order));
            if ($toodeep = $level > 1 && $order[$level - 1] === '') {
                $rslt = true;
            }
            if ($level > $indent) {
                echo "\n" . str_pad("\t", $indent, "\t") . "<ul" . $ulclass . ">\n";
                $indent++;
                $open[$indent] = 0;
            } else {
                if ($level < $indent) {
                    while ($indent > $level) {
                        $open[$indent]--;
                        $indent--;
                        echo "</li>\n" . str_pad("\t", $indent, "\t") . "</ul>\n";
                    }
                } else {
                    // indent == level
                    if ($open[$indent]) {
                        echo str_pad("\t", $indent, "\t") . "</li>\n";
                        $open[$indent]--;
                    } else {
                        echo "\n";
                    }
                }
            }
            if ($open[$indent]) {
                echo str_pad("\t", $indent, "\t") . "</li>\n";
                $open[$indent]--;
            }
            switch ($listtype) {
                case 'cats-checkboxlist':
                    echo "<li>\n";
                    printCategoryCheckboxListEntry($itemobj, $articleid, $option);
                    break;
                case 'cats-sortablelist':
                    echo str_pad("\t", $indent - 1, "\t") . "<li id=\"id_" . $itemid . "\" class=\"clear-element page-item1 left\">";
                    printCategoryListSortableTable($itemobj, $toodeep);
                    break;
                case 'pages-sortablelist':
                    echo str_pad("\t", $indent - 1, "\t") . "<li id=\"id_" . $itemid . "\">";
                    printPagesListTable($itemobj, $toodeep);
                    break;
            }
            $open[$indent]++;
        }
    }
    while ($indent > 1) {
        echo "</li>\n";
        $open[$indent]--;
        $indent--;
        echo str_pad("\t", $indent, "\t") . "</ul>";
    }
    if ($open[$indent]) {
        echo "</li>\n";
    } else {
        echo "\n";
    }
    return $rslt;
}
Esempio n. 4
0
 /**
  * Checks if user is news author
  * @param bit $action what the caller wants to do
  *
  * returns true of access is allowed
  */
 function isMyItem($action)
 {
     global $_zp_current_admin_obj;
     if (parent::isMyItem($action)) {
         return true;
     }
     if (zp_loggedin($action)) {
         if (GALLERY_SECURITY != 'public' && $this->getShow() && $action == LIST_RIGHTS) {
             return LIST_RIGHTS;
         }
         if ($_zp_current_admin_obj->getUser() == $this->getAuthor()) {
             return true;
             //	he is the author
         }
         if ($this->getShow() && $action == LIST_RIGHTS) {
             return true;
         }
         $mycategories = $_zp_current_admin_obj->getObjects('news');
         if (!empty($mycategories)) {
             foreach ($this->getCategories() as $category) {
                 $cat = new ZenpageCategory($category['titlelink']);
                 if ($cat->isMyItem(ZENPAGE_NEWS_RIGHTS)) {
                     // only override item visibility if we "own" the category
                     return true;
                 }
             }
         }
     }
     return false;
 }