Ejemplo n.º 1
0
 /**
  * Gets news articles and images of a gallery to show them together on the news section
  *
  * NOTE: This function does not exclude articles that are password protected via a category
  *
  * @param int $articles_per_page The number of articles to get
  * @param string $mode 	"latestimages-thumbnail"
  * 											"latestimages-thumbnail-customcrop"
  * 											"latestimages-sizedimage"
  * 											"latestalbums-thumbnail"
  * 		 									"latestalbums-thumbnail-customcrop"
  * 		 									"latestalbums-sizedimage"
  * 		 									"latestimagesbyalbum-thumbnail"
  * 		 									"latestimagesbyalbum-thumbnail-customcrop"
  * 		 									"latestimagesbyalbum-sizedimage"
  * 		 									"latestupdatedalbums-thumbnail" (for RSS and getLatestNews() used only)
  * 		 									"latestupdatedalbums-thumbnail-customcrop" (for RSS and getLatestNews() used only)
  * 		 									"latestupdatedalbums-sizedimage" (for RSS and getLatestNews() used only)
  * 	NOTE: The "latestupdatedalbums" variants do NOT support pagination as required on the news loop!
  *
  * @param string $published "published" for published articles,
  * 													"unpublished" for un-published articles,
  * 													"all" for all articles
  * @param string $sortorder 	id, date or mtime, only for latestimages-... modes
  * @param bool $sticky set to true to place "sticky" articles at the front of the list.
  * @param string $direction 	"desc" or "asc"
  * @return array
  * @deprecated since version 1.4.6
  */
 protected function getCombiNews($articles_per_page = '', $mode = '', $published = NULL, $sortorder = NULL, $sticky = true, $sortdirection = 'desc')
 {
     global $_zp_combiNews_cache, $_zp_gallery;
     if (is_null($published)) {
         if (zp_loggedin(ZENPAGE_NEWS_RIGHTS | ALL_NEWS_RIGHTS)) {
             $published = "all";
         } else {
             $published = "published";
         }
     }
     if (empty($mode)) {
         $mode = getOption('zenpage_combinews_mode');
     }
     if (isset($_zp_combiNews_cache[$published . $mode . $sticky . $sortorder . $sortdirection])) {
         return $_zp_combiNews_cache[$published . $mode . $sticky . $sortorder . $sortdirection];
     }
     if ($published == "published") {
         $show = " WHERE `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
         $imagesshow = " AND images.show = 1 ";
     } else {
         $show = "";
         $imagesshow = "";
     }
     getAllAccessibleAlbums($_zp_gallery, $albumlist, false);
     if (empty($albumlist)) {
         $albumWhere = 'albums.`id` is NULL';
     } else {
         $albumWhere = 'albums.`id` in (' . implode(',', $albumlist) . ')';
     }
     if ($articles_per_page) {
         $offset = self::getOffset($articles_per_page);
     } else {
         $offset = 0;
     }
     if (empty($sortorder)) {
         $combinews_sortorder = getOption("zenpage_combinews_sortorder");
     } else {
         $combinews_sortorder = $sortorder;
     }
     $stickyorder = '';
     if ($sticky) {
         $stickyorder = 'sticky DESC,';
     }
     switch (strtolower($sortdirection)) {
         case 'desc':
         default:
             $sortdir = 'DESC';
             break;
         case 'asc':
             $sortdir = 'ASC';
             break;
     }
     $type3 = query("SET @type3:='0'");
     switch ($mode) {
         case "latestimages-thumbnail":
         case "latestimages-thumbnail-customcrop":
         case "latestimages-sizedimage":
         case "latestimages-sizedimage-maxspace":
         case "latestimages-fullimage":
             $albumWhere = ' AND ' . $albumWhere;
             $sortorder = $combinews_sortorder;
             $type1 = query("SET @type1:='news'");
             $type2 = query("SET @type2:='images'");
             switch ($combinews_sortorder) {
                 case 'id':
                 case 'date':
                     $imagequery = "(SELECT albums.folder, images.filename, images.date, @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                     break;
                 case 'publishdate':
                     $imagequery = "(SELECT albums.folder, images.filename, IFNULL(images.publishdate,images.date), @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                 case 'mtime':
                     $imagequery = "(SELECT albums.folder, images.filename, FROM_UNIXTIME(images.mtime), @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                     break;
             }
             $result = $this->siftResults("(SELECT title as albumname, titlelink, date, @type1 as type, sticky FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $imagequery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY {$stickyorder} date " . $sortdir, $offset, $articles_per_page);
             break;
         case "latestalbums-thumbnail":
         case "latestalbums-thumbnail-customcrop":
         case "latestalbums-sizedimage":
         case "latestalbums-sizedimage-maxspace":
         case "latestalbums-fullimage":
         default:
             if (empty($show)) {
                 $albumWhere = ' WHERE ' . $albumWhere;
             } else {
                 $albumWhere = ' AND ' . $albumWhere;
             }
             $sortorder = $combinews_sortorder;
             $type1 = query("SET @type1:='news'");
             $type2 = query("SET @type2:='albums'");
             switch ($combinews_sortorder) {
                 case 'id':
                 case 'date':
                     $albumquery = "(SELECT albums.folder, albums.title, albums.date, @type2, @type3 as sticky FROM " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t" . $show . $albumWhere . ")";
                     break;
                 case 'publishdate':
                     $albumquery = "(SELECT albums.folder, albums.title, IFNULL(albums.publishdate,albums.date), @type2, @type3 as sticky FROM " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t\t\t\t\t\t\t" . $show . $albumWhere . ")";
                     break;
                 case 'mtime':
                 default:
                     $albumquery = "(SELECT albums.folder, albums.title, FROM_UNIXTIME(albums.mtime), @type2, @type3 as sticky FROM " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t" . $show . $albumWhere . ")";
                     break;
             }
             $result = $this->siftResults("(SELECT title as albumname, titlelink, date, @type1 as type, sticky FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $albumquery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY {$stickyorder} date " . $sortdir, $offset, $articles_per_page);
             break;
         case "latestimagesbyalbum-thumbnail":
         case "latestimagesbyalbum-thumbnail-customcrop":
         case "latestimagesbyalbum-sizedimage":
         case "latestimagesbyalbum-sizedimage-maxspace":
         case "latestimagesbyalbum-fullimage":
             $albumWhere = ' AND ' . $albumWhere;
             $type1 = query("SET @type1:='news'");
             $type2 = query("SET @type2:='albums'");
             if (empty($combinews_sortorder) || $combinews_sortorder != "date" || $combinews_sortorder != "mtime" || $combinews_sortorder != "publishdate") {
                 $combinews_sortorder = "date";
             }
             $sortorder = "images." . $combinews_sortorder;
             switch ($combinews_sortorder) {
                 case "date":
                     $imagequery = "(SELECT DISTINCT DATE_FORMAT(" . $sortorder . ",'%Y-%m-%d'), albums.folder, DATE_FORMAT(images.date,'%Y-%m-%d'), @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                     break;
                 case "mtime":
                     $imagequery = "(SELECT DISTINCT FROM_UNIXTIME(" . $sortorder . ",'%Y-%m-%d'), albums.folder, DATE_FORMAT(images.mtime,'%Y-%m-%d'), @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                 case "publishdate":
                     $imagequery = "(SELECT DISTINCT FROM_UNIXTIME(" . $sortorder . ",'%Y-%m-%d'), albums.folder, DATE_FORMAT(images.publishdate,'%Y-%m-%d'), @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                     break;
             }
             $result = $this->siftResults("(SELECT title as albumname, titlelink, date, @type1 as type, sticky FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $imagequery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER By {$stickyorder} date " . $sortdir, $offset, $articles_per_page);
             break;
         case "latestupdatedalbums-thumbnail":
         case "latestupdatedalbums-thumbnail-customcrop":
         case "latestupdatedalbums-sizedimage":
         case "latestupdatedalbums-sizedimage-maxspace":
         case "latestupdatedalbums-fullimage":
             $latest = $this->getArticles($articles_per_page, NULL, true, 'date', $sortdirection);
             $counter = '';
             foreach ($latest as $news) {
                 $article = new ZenpageNews($news['titlelink']);
                 if ($article->checkAccess()) {
                     $counter++;
                     $latestnews[$counter] = array("albumname" => $article->getTitle(), "titlelink" => $article->getTitlelink(), "date" => $article->getDateTime(), "type" => "news");
                 }
             }
             $albums = getAlbumStatistic($articles_per_page, "latestupdated", '', $sortdirection);
             $latestalbums = array();
             $counter = "";
             foreach ($albums as $album) {
                 $counter++;
                 $tempalbum = $album;
                 $tempalbumthumb = $tempalbum->getAlbumThumbImage();
                 $timestamp = $tempalbum->get('mtime');
                 if ($timestamp == 0) {
                     $albumdate = $tempalbum->getDateTime();
                 } else {
                     $albumdate = strftime('%Y-%m-%d %H:%M:%S', $timestamp);
                 }
                 $latestalbums[$counter] = array("albumname" => $tempalbum->getFileName(), "titlelink" => $tempalbum->getTitle(), "date" => $albumdate, "type" => 'albums');
             }
             //$latestalbums = array_merge($latestalbums, $item);
             $latest = array_merge($latestnews, $latestalbums);
             $result = sortMultiArray($latest, "date", $sortdirection != 'asc');
             if (count($result) > $articles_per_page) {
                 $result = array_slice($result, 0, $articles_per_page);
             }
             break;
     }
     $_zp_combiNews_cache[$published . $mode . $sticky . $sortorder . $sortdirection] = $result;
     return $result;
 }
/**
 * Gets the latest news either only news articles or with the latest images or albums
 *
 * NOTE: This function excludes articles that are password protected via a category for not logged in users!
 *
 * @param int $number The number of news items to get
 * @param string $option "none" for only news articles
 * 											 "with_latest_images" for news articles with the latest images by id
 * 											 "with_latest_images_date" for news articles with the latest images by date
 * 											 "with_latest_images_mtime" for news articles with the latest images by mtime (upload date)
 * 											 "with_latest_albums" for news articles with the latest albums by id
 * 											 "with_latestupdated_albums" for news articles with the latest updated albums
 * @param string $category Optional news articles by category (only "none" option)
 * @return array
 */
function getLatestNews($number = 2, $option = 'none', $category = '')
{
    global $_zp_zenpage, $_zp_current_zenpage_news;
    $latest = '';
    switch ($option) {
        case 'none':
            if (!empty($category)) {
                $catobj = new ZenpageCategory($category);
                $latest = $catobj->getArticles($number, NULL, true);
            } else {
                $latest = $_zp_zenpage->getNewsArticles($number, NULL, true);
            }
            $counter = '';
            $latestnews = array();
            foreach ($latest as $item) {
                $article = new ZenpageNews($item['titlelink']);
                if ($article->checkAccess($hint, $show)) {
                    $counter++;
                    $latestnews[$counter] = array("albumname" => $article->getTitle(), "titlelink" => $article->getTitlelink(), "date" => $article->getDateTime(), "type" => "news");
                }
                $latest = $latestnews;
            }
            break;
        case 'with_latest_images':
            $latest = $_zp_zenpage->getCombiNews($number, 'latestimages-thumbnail', NULL, 'id');
            break;
        case 'with_latest_images_date':
            $latest = $_zp_zenpage->getCombiNews($number, 'latestimages-thumbnail', NULL, 'date');
            break;
        case 'with_latest_images_mtime':
            $latest = $_zp_zenpage->getCombiNews($number, 'latestimages-thumbnail', NULL, 'mtime');
            break;
        case 'with_latest_albums':
            $latest = $_zp_zenpage->getCombiNews($number, 'latestalbums-thumbnail', NULL, 'id');
            break;
        case 'with_latestupdated_albums':
            $latest = $_zp_zenpage->getCombiNews($number, 'latestupdatedalbums-thumbnail', NULL, '');
            break;
            /*case "latestimagesbyalbum-thumbnail":
            		$latest = getCombiNews($number,'latestalbums-thumbnail',NULL,'id');
            		break; */
    }
    return $latest;
}
/**
 * Gets news articles and images of a gallery to show them together on the news section
 *
 * NOTE: This function does not exclude articles that are password protected via a category
 *
 * @param int $articles_per_page The number of articles to get
 * @param string $mode 	"latestimages-thumbnail"
 *											"latestimages-thumbnail-customcrop"
 *											"latestimages-sizedimage"
 *											"latestalbums-thumbnail"
 *		 									"latestalbums-thumbnail-customcrop"
 *		 									"latestalbums-sizedimage"
 *		 									"latestimagesbyalbum-thumbnail"
 *		 									"latestimagesbyalbum-thumbnail-customcrop"
 *		 									"latestimagesbyalbum-sizedimage"
 *		 									"latestupdatedalbums-thumbnail" (for RSS and getLatestNews() used only)
 *		 									"latestupdatedalbums-thumbnail-customcrop" (for RSS and getLatestNews() used only)
 *		 									"latestupdatedalbums-sizedimage" (for RSS and getLatestNews() used only)
 *	NOTE: The "latestupdatedalbums" variants do NOT support pagination as required on the news loop!
 *
 * @param string $published "published" for published articles,
 * 													"unpublished" for un-published articles,
 * 													"all" for all articles
 * @param string $sortorder 	id, date or mtime, only for latestimages-... modes
 * @param bool $sticky set to true to place "sticky" articles at the front of the list.
 * @return array
 */
function getCombiNews($articles_per_page = '', $mode = '', $published = NULL, $sortorder = '', $sticky = true)
{
    deprecated_function_notify(gettext('Use the Zenpage class method instead.'));
    global $_zp_gallery, $_zp_flash_player;
    processExpired('news');
    if (is_null($published)) {
        if (zp_loggedin(ZENPAGE_NEWS_RIGHTS)) {
            $published = "all";
        } else {
            $published = "published";
        }
    }
    if (empty($mode)) {
        $mode = getOption("zenpage_combinews_mode");
    }
    if ($published == "published") {
        $show = " WHERE `show` = 1 AND date <= '" . date('Y-m-d H:i:s') . "'";
        $imagesshow = " AND images.show = 1 ";
    } else {
        $show = "";
        $imagesshow = "";
    }
    $passwordcheck = "";
    if (zp_loggedin(ZENPAGE_NEWS_RIGHTS)) {
        $albumWhere = "";
        $passwordcheck = "";
    } else {
        $albumscheck = query_full_array("SELECT * FROM " . prefix('albums') . " ORDER BY title");
        foreach ($albumscheck as $albumcheck) {
            if (!checkAlbumPassword($albumcheck['folder'])) {
                $albumpasswordcheck = " AND albums.id != " . $albumcheck['id'];
                $passwordcheck = $passwordcheck . $albumpasswordcheck;
            }
        }
        $albumWhere = "AND albums.show=1" . $passwordcheck;
    }
    $limit = getLimitAndOffset($articles_per_page);
    if (empty($sortorder)) {
        $combinews_sortorder = getOption("zenpage_combinews_sortorder");
    } else {
        $combinews_sortorder = $sortorder;
    }
    $stickyorder = '';
    if ($sticky) {
        $stickyorder = 'sticky DESC,';
    }
    $type3 = query("SET @type3:='0'");
    switch ($mode) {
        case "latestimages-thumbnail":
        case "latestimages-thumbnail-customcrop":
        case "latestimages-sizedimage":
            $sortorder = "images." . $combinews_sortorder;
            $type1 = query("SET @type1:='news'");
            $type2 = query("SET @type2:='images'");
            switch ($combinews_sortorder) {
                case 'id':
                case 'date':
                    $imagequery = "(SELECT albums.folder, images.filename, images.date, @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
                case 'mtime':
                    $imagequery = "(SELECT albums.folder, images.filename, FROM_UNIXTIME(images.mtime), @type2, @type3 as sticky FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
            }
            $result = query_full_array("(SELECT title as albumname, titlelink, date, @type1 as type, sticky FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $imagequery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY {$stickyorder} date DESC {$limit}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
            break;
        case "latestalbums-thumbnail":
        case "latestalbums-thumbnail-customcrop":
        case "latestalbums-sizedimage":
            $sortorder = $combinews_sortorder;
            $type1 = query("SET @type1:='news'");
            $type2 = query("SET @type2:='albums'");
            switch ($combinews_sortorder) {
                case 'id':
                case 'date':
                    $albumquery = "(SELECT albums.folder, albums.title, albums.date, @type2, @type3 as sticky FROM " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t" . $show . $albumWhere . ")";
                    break;
                case 'mtime':
                    $albumquery = "(SELECT albums.folder, albums.title, FROM_UNIXTIME(albums.mtime), @type2, @type3 as sticky FROM " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t" . $show . $albumWhere . ")";
                    break;
            }
            $result = query_full_array("(SELECT title as albumname, titlelink, date, @type1 as type, sticky FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $albumquery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY {$stickyorder} date DESC {$limit}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
            break;
        case "latestimagesbyalbum-thumbnail":
        case "latestimagesbyalbum-thumbnail-customcrop":
        case "latestimagesbyalbum-sizedimage":
            $type1 = query("SET @type1:='news'");
            $type2 = query("SET @type2:='albums'");
            if (empty($combinews_sortorder) || $combinews_sortorder != "date" || $combinews_sortorder != "mtime") {
                $combinews_sortorder = "date";
            }
            $combinews_sortorder = "date";
            $sortorder = "images." . $combinews_sortorder;
            switch ($combinews_sortorder) {
                case "date":
                    $imagequery = "(SELECT DISTINCT DATE_FORMAT(" . $sortorder . ",'%Y-%m-%d'), albums.folder, DATE_FORMAT(images.`date`,'%Y-%m-%d'), @type2 FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
                case "mtime":
                    $imagequery = "(SELECT DISTINCT FROM_UNIXTIME(" . $sortorder . ",'%Y-%m-%d'), albums.folder, DATE_FORMAT(images.`mtime`,'%Y-%m-%d'), @type2 FROM " . prefix('images') . " AS images, " . prefix('albums') . " AS albums\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE albums.id = images.albumid " . $imagesshow . $albumWhere . ")";
                    break;
            }
            $result = query_full_array("(SELECT title as albumname, titlelink, date, @type1 as type FROM " . prefix('news') . " " . $show . ")\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" . $imagequery . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER By date DESC {$limit}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t");
            //echo "<pre>"; print_r($result); echo "</pre>";
            //$result = "";
            break;
        case "latestupdatedalbums-thumbnail":
        case "latestupdatedalbums-thumbnail-customcrop":
        case "latestupdatedalbums-sizedimage":
            $latest = getNewsArticles($articles_per_page, '', NULL, true);
            $counter = '';
            foreach ($latest as $news) {
                $article = new ZenpageNews($news['titlelink']);
                if ($article->checkAccess($hint, $show)) {
                    $counter++;
                    $latestnews[$counter] = array("albumname" => $article->getTitle(), "titlelink" => $article->getTitlelink(), "date" => $article->getDateTime(), "type" => "news");
                }
            }
            $albums = getAlbumStatistic($articles_per_page, "latestupdated");
            $latestalbums = array();
            $counter = "";
            foreach ($albums as $album) {
                $counter++;
                $tempalbum = new Album($_zp_gallery, $album['folder']);
                $tempalbumthumb = $tempalbum->getAlbumThumbImage();
                $timestamp = $tempalbum->get('mtime');
                if ($timestamp == 0) {
                    $albumdate = $tempalbum->getDateTime();
                } else {
                    $albumdate = strftime('%Y-%m-%d %H:%M:%S', $timestamp);
                }
                $latestalbums[$counter] = array("albumname" => $tempalbum->getFolder(), "titlelink" => $tempalbum->getTitle(), "date" => $albumdate, "type" => 'albums');
            }
            //$latestalbums = array_merge($latestalbums, $item);
            $latest = array_merge($latestnews, $latestalbums);
            $result = sortMultiArray($latest, "date", true);
            if (count($result) > $articles_per_page) {
                $result = array_slice($result, 0, 10);
            }
            break;
    }
    //$result = "";
    return $result;
}
Ejemplo n.º 4
0
/**
 * Gets all tags used by either all Zenpage news articles or pages.
 * @param string $mode "news" for Zenpage news article tags, "pages" for Zenpage pages tags
 *
 */
function getAllTagsFromZenpage($mode = 'news')
{
    global $_zp_gallery, $_zp_zenpage;
    if (!getOption('zp_plugin_zenpage')) {
        return FALSE;
    }
    $passwordcheck = '';
    $ids = array();
    $where = '';
    $tagWhere = "";
    switch ($mode) {
        case 'news':
            if (zp_loggedin(ZENPAGE_NEWS_RIGHTS)) {
                $published = 'all';
            } else {
                $published = 'published';
            }
            $type = 'news';
            $items = $_zp_zenpage->getNewsArticles('', $published);
            foreach ($items as $item) {
                $obj = new ZenpageNews($item['titlelink']);
                if ($obj->checkAccess($hint, $show)) {
                    $ids[] = $obj->getID();
                }
            }
            break;
        case 'pages':
            if (zp_loggedin(ZENPAGE_NEWS_RIGHTS)) {
                $published = 'all';
            } else {
                $published = 'published';
            }
            $type = 'pages';
            $items = $_zp_zenpage->getPages('', '', $published);
            foreach ($items as $item) {
                $obj = new ZenpagePage($item['titlelink']);
                if ($obj->checkAccess($hint, $show)) {
                    $ids[] = $obj->getID();
                }
            }
            break;
    }
    $count = '';
    if (count($ids) == 0) {
        return FALSE;
    } else {
        $tagWhere = " WHERE ";
        foreach ($ids as $id) {
            $count++;
            $tagWhere .= '(o.objectid =' . $id . " AND o.tagid = t.id AND o.type = '" . $type . "')";
            if ($count != count($ids)) {
                $tagWhere .= " OR ";
            }
        }
    }
    if (empty($tagWhere)) {
        return FALSE;
    } else {
        $tags = query_full_array("SELECT DISTINCT t.name, t.id, (SELECT DISTINCT COUNT(*) FROM " . prefix('obj_to_tag') . " WHERE tagid = t.id AND o.type = '" . $type . "') AS count FROM " . prefix('obj_to_tag') . " AS o," . prefix('tags') . " AS t" . $tagWhere . " ORDER BY t.name");
    }
    return $tags;
}