Esempio n. 1
0
 /**
  * Gets all news articles titlelink.
  *
  * NOTE: Since this function only returns titlelinks for use with the object model it does not exclude articles that are password protected via a category
  *
  *
  * @param int $articles_per_page The number of articles to get
  * @param string $published "published" for an published articles,
  * 													"unpublished" for an unpublised articles,
  * 													"published-unpublished" for published articles only from an unpublished category,
  * 													"sticky" for sticky articles (published or not!) for admin page use only,
  * 													"all" for all articles
  * @param boolean $ignorepagination Since also used for the news loop this function automatically paginates the results if the "page" GET variable is set. To avoid this behaviour if using it directly to get articles set this TRUE (default FALSE)
  * @param string $sortorder "date" (default), "title", "id, "popular", "mostrated", "toprated", "random"
  * 													This parameter is not used for date archives
  * @param bool $sortdirection TRUE for descending, FALSE for ascending. Note: This parameter is not used for date archives
  * @param bool $sticky set to true to place "sticky" articles at the front of the list.
  * @return array
  */
 function getArticles($articles_per_page = 0, $published = NULL, $ignorepagination = false, $sortorder = NULL, $sortdirection = NULL, $sticky = NULL, $category = NULL)
 {
     global $_zp_current_category, $_zp_post_date, $_zp_newsCache;
     if (empty($published)) {
         if (zp_loggedin() || $category && $category->isMyItem(ZENPAGE_NEWS_RIGHTS)) {
             $published = "all";
         } else {
             $published = "published";
         }
     }
     if ($category) {
         $sortObj = $category;
     } else {
         $sortObj = $this;
     }
     if (is_null($sticky)) {
         $sticky = $sortObj->getSortSticky();
     }
     if (is_null($sortdirection)) {
         $sortdirection = $sortObj->getSortDirection('news');
     }
     if (is_null($sortorder)) {
         $sortorder = $sortObj->getSortType('news');
     }
     $newsCacheIndex = "{$sortorder}-{$sortdirection}-{$published}-" . (bool) $sticky;
     if ($category) {
         $newsCacheIndex .= '-' . $category->getTitlelink();
     }
     if (isset($_zp_newsCache[$newsCacheIndex])) {
         $result = $_zp_newsCache[$newsCacheIndex];
     } else {
         $show = $currentcategory = false;
         if ($category) {
             if (is_object($_zp_current_category)) {
                 $currentcategory = $_zp_current_category->getTitlelink();
             }
             $showConjunction = ' AND ';
             // new code to get nested cats
             $catid = $category->getID();
             $subcats = $category->getSubCategories();
             if ($subcats) {
                 $cat = " (cat.cat_id = '" . $catid . "'";
                 foreach ($subcats as $subcat) {
                     $subcatobj = new ZenpageCategory($subcat);
                     $cat .= "OR cat.cat_id = '" . $subcatobj->getID() . "' ";
                 }
                 $cat .= ") AND cat.news_id = news.id ";
             } else {
                 $cat = " cat.cat_id = '" . $catid . "' AND cat.news_id = news.id ";
             }
         } else {
             $showConjunction = ' WHERE ';
         }
         if ($sticky) {
             $sticky = 'sticky DESC,';
         }
         if ($sortdirection) {
             $dir = " DESC";
         } else {
             $dir = " ASC";
         }
         // sortorder and sortdirection (only used for all news articles and categories naturally)
         switch ($sortorder) {
             case "date":
             default:
                 $sort1 = "date" . $dir;
                 break;
             case 'lastchange':
                 $sort1 = 'lastchange' . $dir;
                 break;
             case "id":
                 $sort1 = "id" . $dir;
                 break;
             case "title":
                 $sort1 = "title" . $dir;
                 break;
             case "popular":
                 $sort1 = 'hitcounter' . $dir;
                 break;
             case "mostrated":
                 $sort1 = 'total_votes' . $dir;
                 break;
             case "toprated":
                 $sort1 = '(total_value/total_votes) DESC, total_value';
                 break;
             case "random":
                 $sort1 = 'RAND()';
                 break;
         }
         /** get all articles * */
         switch ($published) {
             case "published":
                 $show = "{$showConjunction} `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
                 $getUnpublished = false;
                 break;
             case "published-unpublished":
                 $show = "{$showConjunction} `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
                 $getUnpublished = true;
                 break;
             case "unpublished":
                 $show = "{$showConjunction} `show` = 0 AND date <= '" . date('Y-m-d H:i:s') . "'";
                 $getUnpublished = true;
                 break;
             case 'sticky':
                 $show = "{$showConjunction} `sticky` <> 0";
                 $getUnpublished = true;
                 break;
             case "all":
                 $getUnpublished = true;
                 $show = false;
                 break;
         }
         $order = " ORDER BY {$sticky}";
         if (in_context(ZP_ZENPAGE_NEWS_DATE)) {
             $datesearch = '';
             switch ($published) {
                 case "published":
                     $datesearch = "date LIKE '{$_zp_post_date}%' ";
                     break;
                 case "unpublished":
                     $datesearch = "date LIKE '{$_zp_post_date}%' ";
                     break;
                 case "all":
                     $datesearch = "date LIKE '{$_zp_post_date}%' ";
                     break;
             }
             if ($datesearch) {
                 if ($show) {
                     $datesearch = ' AND ' . $datesearch;
                 } else {
                     $datesearch = ' WHERE ' . $datesearch;
                 }
             }
             $order .= " date DESC";
         } else {
             $datesearch = "";
             if ($category) {
                 $order .= ' news.';
             } else {
                 $order .= ' ';
             }
             $order .= $sort1;
         }
         if ($category) {
             $sql = "SELECT DISTINCT news.date, news.title, news.titlelink, news.sticky FROM " . prefix('news') . " as news, " . prefix('news2cat') . " as cat WHERE" . $cat . $show . $order;
         } else {
             $sql = "SELECT date, title, titlelink, sticky FROM " . prefix('news') . $show . $datesearch . " " . $order;
         }
         $resource = query($sql);
         $result = array();
         if ($resource) {
             while ($item = db_fetch_assoc($resource)) {
                 $article = new ZenpageNews($item['titlelink']);
                 if ($getUnpublished || $article->isMyItem(ZENPAGE_NEWS_RIGHTS) || $currentcategory && $article->inNewsCategory($currentcategory) || $article->categoryIsVisible()) {
                     $result[] = $item;
                 }
             }
             db_free_result($resource);
             if ($sortorder == 'title') {
                 // multi-lingual field!
                 $result = sortByMultilingual($result, 'title', $sortdirection);
                 if ($sticky) {
                     $stickyItems = array();
                     foreach ($result as $key => $element) {
                         if ($element['sticky']) {
                             array_unshift($stickyItems, $element);
                             unset($result[$key]);
                         }
                     }
                     $stickyItems = sortMultiArray($stickyItems, 'sticky', true);
                     $result = array_merge($stickyItems, $result);
                 }
             }
         }
         $_zp_newsCache[$newsCacheIndex] = $result;
     }
     if ($articles_per_page) {
         if ($ignorepagination) {
             $offset = 0;
         } else {
             $offset = self::getOffset($articles_per_page);
         }
         $result = array_slice($result, $offset, $articles_per_page);
     }
     return $result;
 }
Esempio n. 2
0
/**
 * Checks if there is a layout inherited from a parent items (album, page or category) and returns it. Returns false otherwise.
 *
 * @param object $obj the object being selected
 * @param string $type For Zenphoto gallery items "multiple_layouts_albums"
 * 										 For Zenpage CMS items , "multiple_layouts_pages", , "multiple_layouts_news" , "multiple_layouts_news_categories"
 * @return result
 */
function checkParentLayouts($obj, $type)
{
    $parents = array();
    switch ($type) {
        case 'multiple_layouts_images':
            $type = 'multiple_layouts_albums_images';
            $obj = $obj->getAlbum();
            array_unshift($parents, $obj);
        case 'multiple_layouts_albums':
        case 'multiple_layouts_albums_images':
            while (!is_null($obj = $obj->getParent())) {
                array_unshift($parents, $obj);
            }
            if (count($parents) > 0) {
                $parents = array_reverse($parents);
                //reverse so we can check the direct parent first.
                foreach ($parents as $parentobj) {
                    $parentlayouts = query_single_row('SELECT * FROM ' . prefix('plugin_storage') . ' WHERE `aux`=' . $parentobj->getID() . ' AND `type` = "' . $type . '"');
                    if ($parentlayouts && $parentlayouts['data']) {
                        return $parentlayouts;
                    }
                }
            }
            break;
        case 'multiple_layouts_pages':
        case 'multiple_layouts_news_categories':
            $parents = $obj->getParents();
            if (count($parents) > 0) {
                $parents = array_reverse($parents);
                //reverse so we can check the direct parent first.
                foreach ($parents as $parent) {
                    if ($type === 'multiple_layouts_pages') {
                        $parentobj = new ZenpagePage($parent);
                    } else {
                        $parentobj = new ZenpageCategory($parent);
                    }
                    $parentlayouts = query_single_row('SELECT * FROM ' . prefix('plugin_storage') . ' WHERE `aux`=' . $parentobj->getID() . ' AND `type` = "' . $type . '"');
                    if ($parentlayouts && $parentlayouts['data']) {
                        return $parentlayouts;
                    }
                }
            }
            break;
    }
    return false;
}
/**
 * Prints a context sensitive menu of all pages as a unordered html list
 *
 * @param string $option The mode for the menu:
 * 												"list" context sensitive toplevel plus sublevel pages,
 * 												"list-top" only top level pages,
 * 												"omit-top" only sub level pages
 * 												"list-sub" lists only the current pages direct offspring
 * @param string $mode 'pages' or 'categories'
 * @param bool $counter Only $mode = 'categories': Count the articles in each category
 * @param string $css_id CSS id of the top level list
 * @param string $css_class_topactive class of the active item in the top level list
 * @param string $css_class CSS class of the sub level list(s)
 * @param string $$css_class_active CSS class of the sub level list(s)
 * @param string $indexname insert the name (default "Gallery Index") how you want to call the link to the gallery index, insert "" (default) if you don't use it, it is not printed then.
 * @param int $showsubs Set to depth of sublevels that should be shown always. 0 by default. To show all, set to a true! Only valid if option=="list".
 * @param bool $startlist set to true to output the UL tab (false automatically if you use 'omit-top' or 'list-sub')
 * @param int $limit truncation limit display strings
 * @return string
 */
function printNestedMenu($option = 'list', $mode = NULL, $counter = TRUE, $css_id = NULL, $css_class_topactive = NULL, $css_class = NULL, $css_class_active = NULL, $indexname = NULL, $showsubs = 0, $startlist = true, $limit = NULL)
{
    global $_zp_zenpage, $_zp_gallery_page, $_zp_current_zenpage_news, $_zp_current_zenpage_page, $_zp_current_category;
    if (is_null($limit)) {
        $limit = MENU_TRUNCATE_STRING;
    }
    if ($css_id != "") {
        $css_id = " id='" . $css_id . "'";
    }
    if ($css_class_topactive != "") {
        $css_class_topactive = " class='" . $css_class_topactive . "'";
    }
    if ($css_class != "") {
        $css_class = " class='" . $css_class . "'";
    }
    if ($css_class_active != "") {
        $css_class_active = " class='" . $css_class_active . "'";
    }
    if ($showsubs === true) {
        $showsubs = 9999999999.0;
    }
    switch ($mode) {
        case 'pages':
            $items = $_zp_zenpage->getPages();
            $currentitem_id = getPageID();
            if (is_object($_zp_current_zenpage_page)) {
                $currentitem_parentid = $_zp_current_zenpage_page->getParentID();
            } else {
                $currentitem_parentid = NULL;
            }
            $currentitem_sortorder = getPageSortorder();
            break;
        case 'categories':
        case 'allcategories':
            $items = $_zp_zenpage->getAllCategories();
            if (is_object($_zp_current_category) && $mode == 'categories') {
                $currentitem_sortorder = $_zp_current_category->getSortOrder();
                $currentitem_id = $_zp_current_category->getID();
                $currentitem_parentid = $_zp_current_category->getParentID();
            } else {
                $currentitem_sortorder = NULL;
                $currentitem_id = NULL;
                $currentitem_parentid = NULL;
            }
            break;
    }
    // don't highlight current pages or foldout if in search mode as next_page() sets page context
    if (in_context(ZP_SEARCH) && $mode == 'pages') {
        // categories are not searched
        $css_class_topactive = "";
        $css_class_active = "";
        rem_context(ZP_ZENPAGE_PAGE);
    }
    if (0 == count($items) + (int) ($mode == 'allcategories')) {
        return;
    }
    // nothing to do
    $startlist = $startlist && !($option == 'omit-top' || $option == 'list-sub');
    if ($startlist) {
        echo "<ul{$css_id}>";
    }
    // if index link and if if with count
    if (!empty($indexname)) {
        if ($limit) {
            $display = shortenContent($indexname, $limit, MENU_TRUNCATE_INDICATOR);
        } else {
            $display = $indexname;
        }
        switch ($mode) {
            case 'pages':
                if ($_zp_gallery_page == "index.php") {
                    echo "<li {$css_class_topactive}>" . html_encode($display) . "</li>";
                } else {
                    echo "<li><a href='" . html_encode(getGalleryIndexURL()) . "' title='" . html_encode($indexname) . "'>" . html_encode($display) . "</a></li>";
                }
                break;
            case 'categories':
            case 'allcategories':
                if ($_zp_gallery_page == "news.php" && !is_NewsCategory() && !is_NewsArchive() && !is_NewsArticle()) {
                    echo "<li {$css_class_topactive}>" . html_encode($display);
                } else {
                    echo "<li><a href=\"" . html_encode(getNewsIndexURL()) . "\" title=\"" . html_encode($indexname) . "\">" . html_encode($display) . "</a>";
                }
                if ($counter) {
                    if (in_context(ZP_ZENPAGE_NEWS_CATEGORY) && $mode == 'categories') {
                        $totalcount = count($_zp_current_category->getArticles(0));
                    } else {
                        save_context();
                        rem_context(ZP_ZENPAGE_NEWS_DATE);
                        $totalcount = count($_zp_zenpage->getArticles(0));
                        restore_context();
                    }
                    echo ' <span style="white-space:nowrap;"><small>(' . sprintf(ngettext('%u article', '%u articles', $totalcount), $totalcount) . ')</small></span>';
                }
                echo "</li>\n";
                break;
        }
    }
    $baseindent = max(1, count(explode("-", $currentitem_sortorder)));
    $indent = 1;
    $open = array($indent => 0);
    $parents = array(NULL);
    $order = explode('-', $currentitem_sortorder);
    $mylevel = count($order);
    $myparentsort = array_shift($order);
    for ($c = 0; $c <= $mylevel; $c++) {
        $parents[$c] = NULL;
    }
    foreach ($items as $item) {
        switch ($mode) {
            case 'pages':
                $catcount = 1;
                //	so page items all show.
                $pageobj = new ZenpagePage($item['titlelink']);
                $itemtitle = $pageobj->getTitle();
                $itemsortorder = $pageobj->getSortOrder();
                $itemid = $pageobj->getID();
                $itemparentid = $pageobj->getParentID();
                $itemtitlelink = $pageobj->getTitlelink();
                $itemurl = $pageobj->getLink();
                $count = '';
                break;
            case 'categories':
            case 'allcategories':
                $catobj = new ZenpageCategory($item['titlelink']);
                $itemtitle = $catobj->getTitle();
                $itemsortorder = $catobj->getSortOrder();
                $itemid = $catobj->getID();
                $itemparentid = $catobj->getParentID();
                $itemtitlelink = $catobj->getTitlelink();
                $itemurl = $catobj->getLink();
                $catcount = count($catobj->getArticles());
                if ($counter) {
                    $count = ' <span style="white-space:nowrap;"><small>(' . sprintf(ngettext('%u article', '%u articles', $catcount), $catcount) . ')</small></span>';
                } else {
                    $count = '';
                }
                break;
        }
        if ($catcount) {
            $level = max(1, count(explode('-', $itemsortorder)));
            $process = $level <= $showsubs && $option == "list" || ($option == 'list' || $option == 'list-top') && $level == 1 || ($option == 'list' || $option == 'omit-top' && $level > 1) && ($itemid == $currentitem_id || $itemparentid == $currentitem_id || $level < $mylevel && $level > 1 && strpos($itemsortorder, $myparentsort) === 0 || $level == $mylevel && $currentitem_parentid == $itemparentid) || $option == 'list-sub' && $itemparentid == $currentitem_id;
            if ($process) {
                if ($level > $indent) {
                    echo "\n" . str_pad("\t", $indent, "\t") . "<ul{$css_class}>\n";
                    $indent++;
                    $parents[$indent] = NULL;
                    $open[$indent] = 0;
                } else {
                    if ($level < $indent) {
                        $parents[$indent] = NULL;
                        while ($indent > $level) {
                            if ($open[$indent]) {
                                $open[$indent]--;
                                echo "</li>\n";
                            }
                            $indent--;
                            echo str_pad("\t", $indent, "\t") . "</ul>\n";
                        }
                    } else {
                        // level == indent, have not changed
                        if ($open[$indent]) {
                            // level = indent
                            echo str_pad("\t", $indent, "\t") . "</li>\n";
                            $open[$indent]--;
                        } else {
                            echo "\n";
                        }
                    }
                }
                if ($open[$indent]) {
                    // close an open LI if it exists
                    echo "</li>\n";
                    $open[$indent]--;
                }
                echo str_pad("\t", $indent - 1, "\t");
                $open[$indent]++;
                $parents[$indent] = $itemid;
                if ($level == 1) {
                    // top level
                    $class = $css_class_topactive;
                } else {
                    $class = $css_class_active;
                }
                if (!is_null($_zp_current_zenpage_page)) {
                    $gettitle = $_zp_current_zenpage_page->getTitle();
                    $getname = $_zp_current_zenpage_page->getTitlelink();
                } else {
                    if (!is_null($_zp_current_category)) {
                        $gettitle = $_zp_current_category->getTitle();
                        $getname = $_zp_current_category->getTitlelink();
                    } else {
                        $gettitle = '';
                        $getname = '';
                    }
                }
                $current = "";
                if ($itemtitlelink == $getname && !in_context(ZP_SEARCH)) {
                    switch ($mode) {
                        case 'pages':
                            if ($_zp_gallery_page == 'pages.php') {
                                $current = $class;
                            }
                            break;
                        case 'categories':
                        case 'allcategories':
                            if ($_zp_gallery_page == 'news.php') {
                                $current = $class;
                            }
                            break;
                    }
                }
                if ($limit) {
                    $itemtitle = shortenContent($itemtitle, $limit, MENU_TRUNCATE_INDICATOR);
                }
                echo "<li><a {$current} href=\"" . html_encode($itemurl) . "\" title=\"" . html_encode(getBare($itemtitle)) . "\">" . html_encode($itemtitle) . "</a>" . $count;
            }
        }
    }
    // cleanup any hanging list elements
    while ($indent > 1) {
        if ($open[$indent]) {
            echo "</li>\n";
            $open[$indent]--;
        }
        $indent--;
        echo str_pad("\t", $indent, "\t") . "</ul>";
    }
    if ($open[$indent]) {
        echo "</li>\n";
        $open[$indent]--;
    } else {
        echo "\n";
    }
    if ($startlist) {
        echo "</ul>\n";
    }
}
/**
 * Prints the checkboxes to select and/or show the category of an news article on the edit or add page
 *
 * @param int $id 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 "all" to show all categories if creating a new article without categories assigned, empty if editing an existing article that already has categories assigned.
 */
function printCategorySelection($id = '', $option = '')
{
    $selected = '';
    echo "<ul class='zenpagechecklist'>\n";
    foreach ($all_cats as $cats) {
        $catobj = new ZenpageCategory($cats['titlelink']);
        if ($option != "all") {
            $cat2news = query_single_row("SELECT cat_id FROM " . prefix('news2cat') . " WHERE news_id = " . $id . " AND cat_id = " . $catobj->getID());
            if ($cat2news['cat_id'] != "") {
                $selected = "checked ='checked'";
            }
        }
        $catname = $catobj->getTitle();
        $catlink = $catobj->getTitlelink();
        if ($catobj->isProtected() && GALLERY_SECURITY != 'private') {
            $protected = '<img src="' . WEBPATH . '/' . ZENFOLDER . '/images/lock.png" alt="' . gettext('password protected') . '" />';
        } else {
            $protected = '';
        }
        $catid = $catobj->getID();
        echo "<li class=\"hasimage\" ><label for='cat" . $catid . "'><input name='cat" . $catid . "' id='cat" . $catid . "' type='checkbox' value='" . $catid . "' " . $selected . " />" . $catname . " " . $protected . "</label></li>\n";
    }
    echo "</ul>\n";
}
/**
 * Counts news articles, either all or by category or archive date, published or un-published
 *
 * @param string $category The categorylink of the category to count
 * @param string $published "published" for an published articles,
 * 													"unpublished" for an unpublised articles,
 * 													"all" for all articles
 * @return array
 */
function countArticles($category = '', $published = 'published', $count_subcat_articles = true)
{
    deprecated_function_notify(gettext('Count the articles instead.'));
    global $_zp_post_date;
    if (zp_loggedin(ZENPAGE_NEWS_RIGHTS)) {
        $published = "all";
    } else {
        $published = "published";
    }
    $show = "";
    if (empty($category)) {
        switch ($published) {
            case "published":
                $show = " WHERE `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
                break;
            case "unpublished":
                $show = " WHERE `show` = 0 AND date <= '" . date('Y-m-d H:i:s') . "'";
                break;
            case "all":
                $show = "";
                break;
        }
        // date archive query addition
        if (in_context(ZP_ZENPAGE_NEWS_DATE)) {
            $postdate = $_zp_post_date;
            if (empty($show)) {
                $and = " WHERE ";
            } else {
                $and = " AND ";
            }
            $datesearch = $and . "date LIKE '{$postdate}%'";
        } else {
            $datesearch = "";
        }
        $result = query("SELECT COUNT(*) FROM " . prefix('news') . $show . $datesearch);
        $row = db_fetch_row($result);
        $count = $row[0];
        return $count;
    } else {
        $catobj = new ZenpageCategory($category);
        switch ($published) {
            case "published":
                $show = " AND news.show = 1 AND news.date <= '" . date('Y-m-d H:i:s') . "'";
                break;
            case "unpublished":
                $show = " AND news.show = 0 AND news.date <= '" . date('Y-m-d H:i:s') . "'";
                break;
            case "all":
                $show = "";
                break;
        }
        if ($count_subcat_articles) {
            $subcats = $catobj->getSubCategories();
        }
        if ($subcats && $count_subcat_articles) {
            $cat = " (cat.cat_id = '" . $catobj->getID() . "'";
            foreach ($subcats as $subcat) {
                $subcatobj = new ZenpageCategory($subcat);
                $cat .= "OR cat.cat_id = '" . $subcatobj->getID() . "' ";
            }
            $cat .= ") AND cat.news_id = news.id ";
        } else {
            $cat = " cat.cat_id = '" . $catobj->getID() . "' AND cat.news_id = news.id ";
        }
        $result = query_full_array("SELECT DISTINCT news.titlelink FROM " . prefix('news2cat') . " as cat, " . prefix('news') . " as news WHERE " . $cat . $show);
        $count = count($result);
        return $count;
    }
}
Esempio n. 6
0
        XSRFToken('save');
    } else {
        ?>
								<form class="dirty-check" method="post" name="update" id="form_zenpageitemedit" action="admin-edit.php?<?php 
        echo $admintype;
        ?>
&amp;update<?php 
        echo $page;
        ?>
">
									<?php 
        XSRFToken('update');
    }
    ?>
								<input type="hidden" name="id" value="<?php 
    echo $result->getID();
    ?>
" />
								<input type="hidden" name="titlelink-old" id="titlelink-old" value="<?php 
    echo html_encode($result->getTitlelink());
    ?>
" />
								<input type="hidden" name="lastchange" id="lastchange" value="<?php 
    echo date('Y-m-d H:i:s');
    ?>
" />
								<input type="hidden" name="lastchangeauthor" id="lastchangeauthor" value="<?php 
    echo $_zp_current_admin_obj->getUser();
    ?>
" />
								<input type="hidden" name="hitcounter" id="hitcounter" value="<?php 
/**
 * Prints the link to the edit page of a menu item. For gallery and Zenpage items it links to their normal edit pages, for custom pages and custom links to menu specific edit page.
 *
 * @param array $item Array of the menu item
 */
function printItemEditLink($item)
{
    $link = "";
    $array = getItemTitleAndURL($item);
    if (is_null($array['title'])) {
        $title = '<span class="notebox">' . gettext('The target for this menu element no longer exists') . '</span>';
    } else {
        $title = html_encode($array['title']);
    }
    switch ($item['type']) {
        case "album":
            $link = '<a href="../../admin-edit.php?page=edit&amp;album=' . $item['link'] . '">' . $title . '</a>';
            break;
        case "zenpagepage":
            $link = '<a href="../zenpage/admin-edit.php?page&amp;titlelink=' . $item['link'] . '">' . $title . '</a>';
            break;
        case "zenpagecategory":
            $cat = new ZenpageCategory($item['link']);
            $catid = $cat->getID();
            $link = '<a href="../zenpage/admin-categories.php?edit&amp;id=' . $catid . '&amp;tab=categories">' . $title . '</a>';
            break;
        default:
            $link = '<a href="menu_tab_edit.php?edit&amp;id=' . $item['id'] . "&amp;type=" . $item['type'] . "&amp;menuset=" . html_encode(checkChosenMenuset()) . '">' . $title . '</a>';
            break;
    }
    echo $link;
}
 /**
  * Gets the parent categories recursivly to the category whose parentid is passed or the current object
  *
  * @param int $parentid The parentid of the category to get the parents of
  * @param bool $initparents
  * @return array
  */
 function getParents(&$parentid = '', $initparents = true)
 {
     global $parentcats, $_zp_zenpage;
     $allitems = $_zp_zenpage->getAllCategories(false);
     if ($initparents) {
         $parentcats = array();
     }
     if (empty($parentid)) {
         $currentparentid = $this->getParentID();
     } else {
         $currentparentid = $parentid;
     }
     foreach ($allitems as $item) {
         $obj = new ZenpageCategory($item['titlelink']);
         $itemtitlelink = $obj->getTitlelink();
         $itemid = $obj->getID();
         $itemparentid = $obj->getParentID();
         if ($itemid == $currentparentid) {
             array_unshift($parentcats, $itemtitlelink);
             $obj->getParents($itemparentid, false);
         }
     }
     return $parentcats;
 }
Esempio n. 9
0
 /**
  *
  * Returns an array of News article IDs belonging to the search categories
  */
 protected function subsetNewsCategories()
 {
     global $_zp_zenpage;
     if (!is_array($this->category_list)) {
         return false;
     }
     $cat = '';
     $list = $_zp_zenpage->getAllCategories();
     if (!empty($list)) {
         foreach ($list as $category) {
             if (in_array($category['title'], $this->category_list)) {
                 $catobj = new ZenpageCategory($category['titlelink']);
                 $cat .= ' `cat_id`=' . $catobj->getID() . ' OR';
                 $subcats = $catobj->getSubCategories();
                 if ($subcats) {
                     foreach ($subcats as $subcat) {
                         $catobj = new ZenpageCategory($subcat);
                         $cat .= ' `cat_id`=' . $catobj->getID() . ' OR';
                     }
                 }
             }
         }
         if ($cat) {
             $cat = ' WHERE ' . substr($cat, 0, -3);
         }
     }
     $sql = 'SELECT DISTINCT `news_id` FROM ' . prefix('news2cat') . $cat;
     $result = query($sql);
     $list = array();
     if ($result) {
         while ($row = db_fetch_assoc($result)) {
             $list[] = $row['news_id'];
         }
         db_free_result($result);
     }
     return $list;
 }
 /**
  * Gets news articles titlelinks this category is attached to
  *
  * NOTE: Since this function only returns titlelinks for use with the object model it does not exclude articles that are password protected via a category
  *
  *
  * @param int $articles_per_page The number of articles to get
  * @param string $published "published" for published articles
  *													"published-unpublished" for published articles only from an unpublished category,
  * 													"unpublished" for unpublished articles,
  * 													"sticky" for sticky articles (published or not!) for Admin page use only,
  * 													"all" for all articles
  * @param boolean $ignorepagination Since also used for the news loop this function automatically paginates the results if the "page" GET variable is set. To avoid this behaviour if using it directly to get articles set this TRUE (default FALSE)
  * @param string $sortorder "date" for sorting by date (default)
  * 													"title" for sorting by title
  * 													This parameter is not used for date archives
  * @param string $sortdirection "desc" (default) for descending sort order
  * 													    "asc" for ascending sort order
  * 											        This parameter is not used for date archives
  * @param bool $sticky set to true to place "sticky" articles at the front of the list.
  * @return array
  */
 function getArticles($articles_per_page = '', $published = NULL, $ignorepagination = false, $sortorder = "date", $sortdirection = "desc", $sticky = true)
 {
     global $_zp_current_category, $_zp_post_date, $_zp_zenpage;
     $_zp_zenpage->processExpired('news');
     if (empty($published)) {
         $published = "published";
         if (zp_loggedin(ZENPAGE_NEWS_RIGHTS | VIEW_NEWS_RIGHTS)) {
             $published = "all";
         }
     }
     $show = "";
     // new code to get nested cats
     $catid = $this->getID();
     $subcats = $this->getSubCategories();
     if ($subcats) {
         $cat = " (cat.cat_id = '" . $catid . "'";
         foreach ($subcats as $subcat) {
             $subcatobj = new ZenpageCategory($subcat);
             $cat .= "OR cat.cat_id = '" . $subcatobj->getID() . "' ";
         }
         $cat .= ") AND cat.news_id = news.id ";
     } else {
         $cat = " cat.cat_id = '" . $catid . "' AND cat.news_id = news.id ";
     }
     if (in_context(ZP_ZENPAGE_NEWS_DATE)) {
         $postdate = $_zp_post_date;
     } else {
         $postdate = NULL;
     }
     if ($sticky) {
         $sticky = 'sticky DESC,';
     }
     // sortorder and sortdirection
     switch ($sortorder) {
         case "date":
         default:
             $sort1 = "date";
             break;
         case "title":
             $sort1 = "title";
             break;
     }
     switch ($sortdirection) {
         case "desc":
         default:
             $dir = "DESC";
             break;
         case "asc":
             $dir = "ASC";
             $sticky = false;
             //makes no sense
             break;
     }
     /*** get articles by category ***/
     switch ($published) {
         case "published":
             $show = " AND `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
             $getUnpublished = false;
             break;
         case "published-unpublished":
             $show = " AND `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
             $getUnpublished = true;
             break;
         case "unpublished":
             $show = " AND `show` = 0 AND date <= '" . date('Y-m-d H:i:s') . "'";
             $getUnpublished = true;
             break;
         case 'sticky':
             $show = ' AND `sticky` <> 0';
             $getUnpublished = true;
             break;
         case "all":
             $getUnpublished = true;
             $show = "";
             break;
     }
     $order = " ORDER BY " . $sticky . "news.{$sort1} {$dir}";
     $sql = "SELECT DISTINCT news.titlelink FROM " . prefix('news') . " as news, " . prefix('news2cat') . " as cat WHERE" . $cat . $show . $order;
     $resource = $result = query($sql);
     if ($resource) {
         if ($ignorepagination) {
             $offset = 0;
         } else {
             $offset = $_zp_zenpage->getOffset($articles_per_page);
         }
         if (is_object($_zp_current_category)) {
             $currentcategory = $_zp_current_category->getTitlelink();
         } else {
             $currentcategory = false;
         }
         $result = array();
         while ($item = db_fetch_assoc($resource)) {
             $article = new ZenpageNews($item['titlelink']);
             if ($getUnpublished || $currentcategory && $article->inNewsCategory($currentcategory) || $article->categoryIsVisible()) {
                 $offset--;
                 if ($offset < 0) {
                     $result[] = $item;
                     if ($articles_per_page && count($result) >= $articles_per_page) {
                         break;
                     }
                 }
             }
         }
     }
     return $result;
 }