Пример #1
0
 /**
  * Returns a list of Zenpage news article IDs that the current viewer is not allowed to see
  * Helper function to be used with getAllTagsUnique() and getAllTagsCount() or db queries only
  * Note if the Zenpage plugin is not enabled but items exists this returns no IDs so you need an extra check afterwards!
  *
  * @return array
  */
 function getNotViewableNews()
 {
     global $_zp_not_viewable_news_list;
     if (zp_loggedin(ADMIN_RIGHTS | ALL_NEWS_RIGHTS)) {
         return array();
         //admins can see all
     }
     if (is_null($_zp_not_viewable_news_list)) {
         $items = $this->getArticles(0, 'published', true, NULL, NULL, NULL, NULL);
         if (!is_null($items)) {
             $_zp_not_viewable_news_list = array();
             foreach ($items as $item) {
                 $obj = new ZenpageNews($item['titlelink']);
                 if ($obj->isProtected()) {
                     $_zp_not_viewable_news_list[] = $obj->getID();
                 }
             }
         }
     }
     return $_zp_not_viewable_news_list;
 }
/**
 * 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;
}
/**
 * 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;
}
Пример #4
0
     $post['content'] = nl2br($post['content']);
 }
 $post['date'] = $post['date'];
 $post['lastchange'] = $post['lastchange'];
 $post['type'] = $post['type'];
 switch ($post['type']) {
     case 'post':
         //Add the post to Zenphoto database as Zenpage article
         if (query("INSERT INTO " . prefix('news') . " (title,titlelink,content,date,lastchange,`show`,permalink) VALUES (" . db_quote($post['title']) . "," . db_quote($titlelink) . "," . db_quote($post['content']) . "," . db_quote($post['date']) . "," . db_quote($post['lastchange']) . "," . $show . ",1)", false)) {
             $postinfo .= '<li class="import-success">' . sprintf(gettext('%1$s <em>%2$s</em> added'), $post['type'], $post['title']);
         } else {
             $postinfo .= '<li class="import-exists">' . sprintf(gettext('%1$s with the title/titlelink <em>%2$s</em> already exists!'), $post['type'], $post['title']);
         }
         // Get new id of the article
         $newarticle = new ZenpageNews($titlelink, true);
         $newarticleid = $newarticle->getID();
         // getting the categories and tags assigned to this post (Wordpress pages do not have tags or categories
         $termrelations = wp_query_full_array("\n\t\t\t\t\t\t\tSELECT rel.object_id, rel.term_taxonomy_id, tax.term_id, tax.taxonomy, terms.term_id, terms.name, terms.slug\n\t\t\t\t\t\t\tFROM " . wp_prefix('term_relationships', $wp_prefix) . " as rel,\n\t\t\t\t\t\t\t" . wp_prefix('term_taxonomy', $wp_prefix) . " as tax,\n\t\t\t\t\t\t\t" . wp_prefix('terms', $wp_prefix) . " as terms\n\t\t\t\t\t\t\tWHERE tax.term_taxonomy_id = rel.term_taxonomy_id\n\t\t\t\t\t\t\tAND tax.term_id = terms.term_id\n\t\t\t\t\t\t\tAND rel.object_id = '" . $post['id'] . "'", $wpdbconnection);
         //echo "<br /><strong>Categories:</strong><pre>"; print_r($termrelations); echo "</pre>"; // for debugging
         $postinfo .= "<ul>";
         if ($termrelations) {
             foreach ($termrelations as $term) {
                 $term['name'] = $_zp_UTF8->convert($term['name']);
                 $term['slug'] = $term['slug'];
                 $term['taxonomy'] = $term['taxonomy'];
                 switch ($term['taxonomy']) {
                     case 'category':
                         //Get new id of category
                         $getcat = query_single_row("SELECT titlelink, title,id from " . prefix('news_categories') . " WHERE titlelink = " . db_quote($term['slug']) . " AND title = " . db_quote($term['name']));
                         //Prevent double assignments
                         if (query_single_row("SELECT id from " . prefix('news2cat') . " WHERE news_id = " . $newarticleid . " AND cat_id=" . $getcat['id'], false)) {
Пример #5
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;
}