/**
 * Gets the statistic for pages, news articles or categories as an unordered list
 *
 * @param int $number The number of news items to get
 * @param string $option "all" pages, articles  and categories
 * 											 "news" for news articles
 * 											 "categories" for news categories
 * 											 "pages" for pages
 * @param string $mode "popular" most viewed for pages, news articles and categories
 * 										 "mostrated" for news articles and pages
 * 										 "toprated" for news articles and pages
 * @return array
 */
function getZenpageStatistic($number = 10, $option = "all", $mode = "popular")
{
    global $_zp_current_zenpage_news, $_zp_current_zenpage_pages;
    $statsarticles = array();
    $statscats = array();
    $statspages = array();
    switch ($mode) {
        case "popular":
            $sortorder = "hitcounter";
            break;
        case "mostrated":
            $sortorder = "total_votes";
            break;
        case "toprated":
            $sortorder = "rating";
            break;
    }
    if ($option == "all" or $option == "news") {
        $articles = query_full_array("SELECT titlelink FROM " . prefix('news') . " ORDER BY {$sortorder} DESC LIMIT {$number}");
        $counter = "";
        $statsarticles = array();
        foreach ($articles as $article) {
            $counter++;
            $obj = new ZenpageNews($article['titlelink']);
            $statsarticles[$counter] = array("id" => $obj->getID(), "title" => $obj->getTitle(), "titlelink" => $article['titlelink'], "hitcounter" => $obj->getHitcounter(), "total_votes" => $obj->get('total_votes'), "rating" => $obj->get('rating'), "content" => $obj->getContent(), "date" => $obj->getDateTime(), "type" => "News");
        }
        $stats = $statsarticles;
    }
    if (($option == "all" or $option == "categories") && $mode != "mostrated" && $mode != "toprated") {
        $categories = query_full_array("SELECT id, titlelink as title, title as titlelink, hitcounter FROM " . prefix('news_categories') . " ORDER BY {$sortorder} DESC LIMIT {$number}");
        $counter = "";
        $statscats = array();
        foreach ($categories as $cat) {
            $counter++;
            $statscats[$counter] = array("id" => $cat['id'], "title" => html_encode(get_language_string($cat['title'])), "titlelink" => getNewsCategoryURL($cat['titlelink']), "hitcounter" => $cat['hitcounter'], "total_votes" => "", "rating" => "", "content" => '', "date" => '', "type" => "Category");
        }
        $stats = $statscats;
    }
    if ($option == "all" or $option == "pages") {
        $pages = query_full_array("SELECT titlelink FROM " . prefix('pages') . " ORDER BY {$sortorder} DESC LIMIT {$number}");
        $counter = "";
        $statspages = array();
        foreach ($pages as $page) {
            $counter++;
            $pageobj = new ZenpagePage($page['titlelink']);
            $statspages[$counter] = array("id" => $pageobj->getID(), "title" => $pageobj->getTitle(), "titlelink" => $page['titlelink'], "hitcounter" => $pageobj->getHitcounter(), "total_votes" => $pageobj->get('total_votes'), "rating" => $pageobj->get('rating'), "content" => $pageobj->getContent(), "date" => $pageobj->getDateTime(), "type" => "Page");
        }
        $stats = $statspages;
    }
    if ($option == "all") {
        $stats = array_merge($statsarticles, $statscats, $statspages);
    }
    $stats = sortMultiArray($stats, $sortorder, true);
    return $stats;
}
/**
 * Gets the statistic for pages, news articles or categories as an unordered list
 *
 * @param int $number The number of news items to get
 * @param string $option "all" pages, articles  and categories
 * 											 "news" for news articles
 * 											 "categories" for news categories
 * 											 "pages" for pages
 * @param string $mode "popular" most viewed for pages, news articles and categories
 * 										 "mostrated" for news articles and pages
 * 										 "toprated" for news articles and pages
 * 										 "random" for pages and news articles
 * @param string $sortdirection "asc" for ascending otherwise descending (default)
 * @return array
 */
function getZenpageStatistic($number = 10, $option = "all", $mode = "popular", $sortdirection = 'desc')
{
    global $_zp_zenpage, $_zp_current_zenpage_news, $_zp_current_zenpage_pages;
    $sortdir = strtolower($sortdirection) != 'asc';
    $statsarticles = array();
    $statscats = array();
    $statspages = array();
    if ($option == "all" || $option == "news") {
        $articles = $_zp_zenpage->getArticles($number, NULL, true, $mode, $sortdir, false);
        $counter = "";
        $statsarticles = array();
        foreach ($articles as $article) {
            $counter++;
            $obj = new ZenpageNews($article['titlelink']);
            $statsarticles[$counter] = array("id" => $obj->getID(), "title" => $obj->getTitle(), "titlelink" => $article['titlelink'], "hitcounter" => $obj->getHitcounter(), "total_votes" => $obj->getTotal_votes(), "rating" => $obj->getRating(), "content" => $obj->getContent(), "date" => $obj->getDateTime(), "type" => "News");
        }
        $stats = $statsarticles;
    }
    if (($option == "all" || $option == "categories") && $mode != "mostrated" && $mode != "toprated") {
        $categories = $_zp_zenpage->getAllCategories(true, $mode, $sortdir);
        $counter = "";
        $statscats = array();
        foreach ($categories as $cat) {
            $counter++;
            $statscats[$counter] = array("id" => $cat['id'], "title" => html_encode(get_language_string($cat['title'])), "titlelink" => getNewsCategoryURL($cat['titlelink']), "hitcounter" => $cat['hitcounter'], "total_votes" => "", "rating" => "", "content" => '', "date" => '', "type" => "Category");
        }
        $stats = $statscats;
    }
    if ($option == "all" || $option == "pages") {
        $pages = $_zp_zenpage->getPages(NULL, false, $number, $mode, $sortdir);
        $counter = "";
        $statspages = array();
        foreach ($pages as $page) {
            $counter++;
            $pageobj = new ZenpagePage($page['titlelink']);
            $statspages[$counter] = array("id" => $pageobj->getID(), "title" => $pageobj->getTitle(), "titlelink" => $page['titlelink'], "hitcounter" => $pageobj->getHitcounter(), "total_votes" => $pageobj->get('total_votes'), "rating" => $pageobj->get('rating'), "content" => $pageobj->getContent(), "date" => $pageobj->getDateTime(), "type" => "Page");
        }
        $stats = $statspages;
    }
    if ($option == "all") {
        $stats = array_merge($statsarticles, $statscats, $statspages);
        if ($mode == 'random') {
            shuffle($stats);
        } else {
            switch ($sortdir) {
                case 'asc':
                    $desc = false;
                    break;
                case 'desc':
                    $desc = true;
                    break;
            }
            $stats = sortMultiArray($stats, $mode, $desc);
        }
    }
    return $stats;
}
Esempio n. 3
0
/**
 * Prints the x related articles based on a tag search
 *
 * @param int $number Number of items to get
 * @param string $type 'albums', 'images','news','pages', "all" for all combined.
 * @param string $specific If $type = 'albums' or 'images' name of album
 * @param bool $excerpt If a text excerpt (gallery items: description; Zenpage items: content) should be shown. NULL for none or number of length
 * @param bool $thumb For $type = 'albums' or 'images' if a thumb should be shown (default size as set on the options)
 */
function printRelatedItems($number = 5, $type = 'news', $specific = NULL, $excerpt = NULL, $thumb = false, $date = false)
{
    global $_zp_gallery, $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_page, $_zp_current_zenpage_news;
    $label = array('albums' => gettext('Albums'), 'images' => gettext('Images'), 'news' => gettext('News'), 'pages' => gettext('Pages'));
    $result = getRelatedItems($type, $specific);
    $resultcount = count($result);
    if ($resultcount != 0) {
        ?>
		<h3 class="relateditems">
			<?php 
        printf(gettext('Related %s'), $type);
        ?>
		</h3>
		<ul id="relateditems">
			<?php 
        $count = 0;
        foreach ($result as $item) {
            $count++;
            ?>
				<li class="<?php 
            echo $item['type'];
            ?>
">
					<?php 
            $category = '';
            switch ($item['type']) {
                case 'albums':
                    $obj = newAlbum($item['name']);
                    $url = $obj->getLink();
                    $text = $obj->getDesc();
                    $category = gettext('Album');
                    break;
                case 'images':
                    $alb = newAlbum($item['album']);
                    $obj = newImage($alb, $item['name']);
                    $url = $obj->getLink();
                    $text = $obj->getDesc();
                    $category = gettext('Image');
                    break;
                case 'news':
                    $obj = new ZenpageNews($item['name']);
                    $url = $obj->getLink();
                    $text = $obj->getContent();
                    $category = gettext('News');
                    break;
                case 'pages':
                    $obj = new ZenpagePage($item['name']);
                    $url = $obj->getLink();
                    $text = $obj->getContent();
                    $category = gettext('Page');
                    break;
            }
            ?>
					<?php 
            if ($thumb) {
                $thumburl = false;
                switch ($item['type']) {
                    case 'albums':
                        $thumburl = $obj->getThumb();
                        break;
                    case 'images':
                        $thumburl = $obj->getThumb();
                        break;
                }
                if ($thumburl) {
                    ?>
							<a href="<?php 
                    echo html_encode(pathurlencode($url));
                    ?>
" title="<?php 
                    echo html_encode($obj->getTitle());
                    ?>
" class="relateditems_thumb">
								<img src="<?php 
                    echo html_encode(pathurlencode($thumburl));
                    ?>
" alt="<?php 
                    echo html_encode($obj->getTitle());
                    ?>
" />
							</a>
							<?php 
                }
            }
            ?>
					<h4><a href="<?php 
            echo html_encode(pathurlencode($url));
            ?>
" title="<?php 
            echo html_encode($obj->getTitle());
            ?>
"><?php 
            echo html_encode($obj->getTitle());
            ?>
</a>
						<?php 
            if ($date) {
                switch ($item['type']) {
                    case 'albums':
                    case 'images':
                        $d = $obj->getDateTime();
                        break;
                    case 'news':
                    case 'pages':
                        $d = $obj->getDateTime();
                        break;
                }
                ?>
							<span class="relateditems_date">
								<?php 
                echo zpFormattedDate(DATE_FORMAT, strtotime($d));
                ?>
							</span>
							<?php 
            }
            ?>
						<?php 
            if ($type == 'all') {
                ?>
 (<small><?php 
                echo $category;
                ?>
</small>)<?php 
            }
            ?>

					</h4>
					<?php 
            if ($excerpt) {
                echo shortenContent($text, $excerpt, '...', true);
            }
            ?>
				</li>
				<?php 
            if ($count == $number) {
                break;
            }
        }
        // foreach
        if ($count) {
            ?>
			</ul>
			<?php 
        }
    }
}