Exemplo 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;
 }
Exemplo n.º 2
0
/**
 * Sort the album array based on either according to the sort key.
 * Default is to sort on the `sort_order` field.
 *
 * Returns an array with the albums in the desired sort order
 *
 * @param  array $albums array of album names
 * @param  string $sortkey the sorting scheme
 * @return array
 *
 * @author Todd Papaioannou (lucky@luckyspin.org)
 * @since  1.0.0
 */
function sortAlbumArray($parentalbum, $albums, $sortkey = '`sort_order`')
{
    global $_zp_gallery;
    if (count($albums) == 0) {
        return array();
    }
    if (is_null($parentalbum)) {
        $albumid = ' IS NULL';
    } else {
        $albumid = '="' . $parentalbum->id . '"';
    }
    $sql = 'SELECT `folder`, `sort_order`, `title`, `show`, `dynamic`, `search_params` FROM ' . prefix("albums") . ' WHERE `parentid`' . $albumid . ' ORDER BY ' . $sortkey;
    $loop = 0;
    do {
        $result = query($sql);
        $hidden = array();
        $results = array();
        while ($row = mysql_fetch_assoc($result)) {
            $results[] = $row;
        }
        if (strpos($sortkey, 'title') !== false) {
            $results = sortByMultilingual($results, 'title', strpos($sortkey, 'DESC') !== false);
        } else {
            if (strpos($sortkey, 'folder') !== false) {
                if (strpos($sortkey, 'DESC') !== false) {
                    $order = 'dsc';
                } else {
                    $order = 'asc';
                }
                $results = sortMultiArray($results, 'folder', $order, true, false);
            }
        }
        $i = 0;
        $albums_r = array_flip($albums);
        $albums_touched = array();
        foreach ($results as $row) {
            $folder = $row['folder'];
            $mine = isMyALbum($folder, ALL_RIGHTS);
            if (array_key_exists($folder, $albums_r)) {
                $albums_r[$folder] = $i;
                $albums_touched[] = $folder;
                if (!($row['show'] || $mine)) {
                    // you can see only your own unpublished content.
                    $hidden[] = $folder;
                }
            }
            $i++;
        }
        $albums_untouched = array_diff($albums, $albums_touched);
        if (count($albums_untouched) > 0) {
            //found new albums
            $loop++;
            foreach ($albums_untouched as $alb) {
                $albobj = new Album($_zp_gallery, $alb);
                // force load to DB
                $albums_r[$alb] = -$i;
                // place them in the front of the list
                $i++;
            }
        } else {
            $loop = 0;
        }
    } while ($loop == 1);
    foreach ($hidden as $alb) {
        unset($albums_r[$alb]);
    }
    $albums = array_flip($albums_r);
    ksort($albums);
    $albums_ordered = array();
    foreach ($albums as $album) {
        $albums_ordered[] = $album;
    }
    return $albums_ordered;
}
Exemplo n.º 3
0
/**
 * sorts the found albums (images) by the required key(s)
 *
 * NB: this sort is sensitive to the key(s) chosen and makes
 * the appropriate sorts based on same. Some multi-key sorts
 * will not make any sense and will give unexpected results.
 * Most notably any that contain the keys "title" or "desc"
 * as these require multi-lingual sorts.
 *
 * @param array $results
 * @param string $sortkey
 * @param string $order
 */
function sortByKey($results, $sortkey, $order)
{
    $sortkey = str_replace('`', '', $sortkey);
    switch ($sortkey) {
        case 'title':
        case 'desc':
            return sortByMultilingual($results, $sortkey, $order);
        case 'RAND()':
            shuffle($results);
            return $results;
        default:
            if (preg_match('`[\\/\\(\\)\\*\\+\\-!\\^\\%\\<\\>\\=\\&\\|]`', $sortkey)) {
                return $results;
                //	We cannot deal with expressions
            }
    }
    $indicies = explode(',', $sortkey);
    foreach ($indicies as $key => $index) {
        $indicies[$key] = trim($index);
    }
    $results = sortMultiArray($results, $indicies, $order, true, false, true);
    return $results;
}
Exemplo n.º 4
0
 /**
  * Returns an array of image names found in the search
  *
  * @param string $sorttype what to sort on
  * @param string $sortdirection what direction
  * @param bool $mine set true/false to overried ownership
  * @return array
  */
 private function getSearchImages($sorttype, $sortdirection, $mine = NULL)
 {
     if (getOption('search_no_images') || $this->search_no_images) {
         return array();
     }
     list($sorttype, $sortdirection) = $this->sortKey($sorttype, $sortdirection, 'title', 'images');
     if (is_null($mine) && zp_loggedin(MANAGE_ALL_ALBUM_RIGHTS)) {
         $mine = true;
     }
     $searchstring = $this->getSearchString();
     $searchdate = $this->dates;
     if (empty($searchstring) && empty($searchdate)) {
         return array();
     }
     // nothing to find
     $criteria = $this->getCacheTag('images', serialize($searchstring) . ' ' . $searchdate, $sorttype . ' ' . $sortdirection . ' ' . $mine);
     if ($criteria == $this->searches['images']) {
         return $this->images;
     }
     $images = $this->getCachedSearch($criteria);
     if (is_null($images)) {
         if (empty($searchdate)) {
             list($search_query, $weights) = $this->searchFieldsAndTags($searchstring, 'images', $sorttype, $sortdirection);
         } else {
             $search_query = $this->searchDate($searchstring, $searchdate, 'images', $sorttype, $sortdirection);
         }
         if (empty($search_query)) {
             $search_result = false;
         } else {
             $search_result = query($search_query);
         }
         $albums_seen = $images = array();
         if ($search_result) {
             while ($row = db_fetch_assoc($search_result)) {
                 $albumid = $row['albumid'];
                 if (array_key_exists($albumid, $albums_seen)) {
                     $albumrow = $albums_seen[$albumid];
                 } else {
                     $query = "SELECT folder, `show` FROM " . prefix('albums') . " WHERE id = {$albumid}";
                     $row2 = query_single_row($query);
                     // id is unique
                     if ($row2) {
                         $albumname = $row2['folder'];
                         $allow = false;
                         $album = newAlbum($albumname);
                         $uralbum = getUrAlbum($album);
                         $viewUnpublished = $this->search_unpublished || zp_loggedin() && $uralbum->albumSubRights() & (MANAGED_OBJECT_RIGHTS_EDIT | MANAGED_OBJECT_RIGHTS_VIEW);
                         switch (checkPublishDates($row)) {
                             case 1:
                                 $imageobj = newImage($this, $row['filename']);
                                 $imageobj->setShow(0);
                                 $imageobj->save();
                             case 2:
                                 $row['show'] = 0;
                                 break;
                         }
                         if ($mine || is_null($mine) && ($album->isMyItem(LIST_RIGHTS) || checkAlbumPassword($albumname) && ($album->getShow() || $viewUnpublished))) {
                             $allow = empty($this->album_list) || in_array($albumname, $this->album_list);
                         }
                         $albums_seen[$albumid] = $albumrow = array('allow' => $allow, 'viewUnpublished' => $viewUnpublished, 'folder' => $albumname, 'localpath' => ALBUM_FOLDER_SERVERPATH . internalToFilesystem($albumname) . '/');
                     } else {
                         $albums_seen[$albumid] = $albumrow = array('allow' => false, 'viewUnpublished' => false, 'folder' => '', 'localpath' => '');
                     }
                 }
                 if ($albumrow['allow'] && ($row['show'] || $albumrow['viewUnpublished'])) {
                     if (file_exists($albumrow['localpath'] . internalToFilesystem($row['filename']))) {
                         //	still exists
                         $data = array('title' => $row['title'], 'filename' => $row['filename'], 'folder' => $albumrow['folder']);
                         if (isset($weights)) {
                             $data['weight'] = $weights[$row['id']];
                         }
                         $images[] = $data;
                     }
                 }
             }
             db_free_result($search_result);
             if (is_null($sorttype) && isset($weights)) {
                 $images = sortMultiArray($images, 'weight', true, true, false, false, array('weight'));
             }
             if ($sorttype == '`title`') {
                 $images = sortByMultilingual($images, 'title', $sortdirection);
             }
         }
         if (empty($searchdate)) {
             zp_apply_filter('search_statistics', $searchstring, 'images', !empty($images), $this->dynalbumname, $this->iteration++);
         }
         $this->cacheSearch($criteria, $images);
     }
     $this->searches['images'] = $criteria;
     return $images;
 }
Exemplo n.º 5
0
 /**
  * sort search results
  *
  * @param string $sorttype
  * @param string $sortdirection
  * @param array $result
  * @param bool $weights
  * @return array
  */
 protected static function sortResults($sorttype, $sortdirection, $result, $weights)
 {
     $sorttype = trim($sorttype, '`');
     if ($weights) {
         $result = sortMultiArray($result, 'weight', true, true, false, false, array('weight'));
     }
     switch ($sorttype) {
         case 'title':
             $result = sortByMultilingual($result, $sorttype, $sortdirection == 'DESC');
     }
     return $result;
 }
Exemplo n.º 6
0
 /**
  * sortImageArray will sort an array of Images based on the given key. The
  * key must be one of (filename, title, sort_order) at the moment.
  *
  * @param array $images The array of filenames to be sorted.
  * @param  string $sorttype optional sort type
  * @param  string $sortdirection optional sort direction
  * @return array
  */
 function sortImageArray($images, $sorttype = NULL, $sortdirection = NULL)
 {
     $mine = isMyAlbum($this->name, ALL_RIGHTS);
     $key = $this->getSortKey($sorttype);
     $direction = '';
     if ($key != '`sort_order`') {
         // manual sort is always ascending
         if (!is_null($sortdirection)) {
             $direction = ' ' . $sortdirection;
         } else {
             if ($this->getSortDirection('image')) {
                 $direction = ' DESC';
             }
         }
     }
     $result = query($sql = "SELECT `filename`, `title`, `sort_order`, `title`, `show`, `id` FROM " . prefix("images") . " WHERE `albumid`= '" . $this->id . "' ORDER BY " . $key . $direction);
     $loop = 0;
     do {
         $hidden = array();
         $results = array();
         while ($row = mysql_fetch_assoc($result)) {
             $results[] = $row;
         }
         if ($key == 'title') {
             $results = sortByMultilingual($results, 'title', $direction == ' DESC');
         } else {
             if ($key == 'filename') {
                 if ($direction == 'DESC') {
                     $order = 'dsc';
                 } else {
                     $order = 'asc';
                 }
                 $results = sortMultiArray($results, 'filename', $order, true, false);
             }
         }
         $i = 0;
         $flippedimages = array_flip($images);
         $images_to_keys = array();
         $images_in_db = array();
         $images_invisible = array();
         foreach ($results as $row) {
             // see what images are in the database so we can check for visible
             $filename = $row['filename'];
             if (isset($flippedimages[$filename])) {
                 // ignore db entries for images that no longer exist.
                 if ($row['show'] || $mine) {
                     // unpublished content available only to someone with rights on the album
                     $images_to_keys[$filename] = $i;
                     $i++;
                 }
                 $images_in_db[] = $filename;
             } else {
                 $id = $row['id'];
                 query("DELETE FROM " . prefix('images') . " WHERE `id`={$id}");
                 // delete the record
                 query("DELETE FROM " . prefix('comments') . " WHERE `type` IN (" . zp_image_types("'") . ") AND `ownerid`= '{$id}'");
                 // remove image comments
             }
         }
         // Place the images not yet in the database before those with sort columns.
         // This is consistent with the sort oder of a NULL sort_order key in manual sorts
         // but will almost certainly be wrong in all other cases.
         $images_not_in_db = array_diff($images, $images_in_db);
         if (count($images_not_in_db) > 0) {
             $loop++;
             foreach ($images_not_in_db as $filename) {
                 $imgobj = newImage($this, $filename);
                 // force it into the database
                 $images_to_keys[$filename] = $i;
                 $i++;
             }
         } else {
             $loop = 0;
         }
     } while ($loop == 1);
     $images = array_flip($images_to_keys);
     ksort($images);
     $images_ordered = array();
     foreach ($images as $image) {
         $images_ordered[] = $image;
     }
     return $images_ordered;
 }
Exemplo n.º 7
0
/**
 * sorts the found albums (images) by the required key(s)
 *
 * NB: this sort is sensitive to the key(s) chosen and makes
 * the appropriate sorts based on same. Some multi-key sorts
 * will not make any sense and will give unexpected results.
 * Most notably any that contain the keys "title" or "desc"
 * as these require multi-lingual sorts.
 *
 * @param array $results
 * @param string $sortkey
 * @param string $order
 */
function sortByKey($results, $sortkey, $order)
{
    $sortkey = str_replace('`', '', $sortkey);
    switch ($sortkey) {
        case 'title':
        case 'desc':
            $results = sortByMultilingual($results, $sortkey, $order);
            break;
        case 'RAND()':
            shuffle($results);
            break;
        default:
            $indicies = explode(',', $sortkey);
            foreach ($indicies as $key => $index) {
                $indicies[$key] = trim($index);
            }
            $results = sortMultiArray($results, $indicies, $order);
            break;
    }
    return $results;
}
Exemplo n.º 8
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(ZENPAGE_NEWS_RIGHTS | VIEW_UNPUBLISHED_NEWS_RIGHTS)) {
             $published = "all";
         } else {
             $published = "published";
         }
     }
     $now = date('Y-m-d H:i:s');
     if ($category && $category->exists) {
         $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');
         if (empty($sortorder)) {
             $sortorder = 'date';
         }
     }
     $newsCacheIndex = "{$sortorder}-{$sortdirection}-{$published}-" . (int) $sticky;
     if ($category && $category->exists) {
         $newsCacheIndex .= '-' . $category->getTitlelink();
     }
     if (isset($_zp_newsCache[$newsCacheIndex])) {
         $result = $_zp_newsCache[$newsCacheIndex];
     } else {
         $cat = $show = $currentCat = false;
         if ($category) {
             if ($category->exists) {
                 if (is_object($_zp_current_category)) {
                     $currentCat = $_zp_current_category->getTitlelink();
                 }
                 // new code to get nested cats
                 $catid = $category->getID();
                 $subcats = $category->getSubCategories();
                 if ($subcats) {
                     $cat = " (cat.cat_id = '" . $catid . "'";
                     foreach ($subcats as $subcat) {
                         $subcatobj = newCategory($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 {
                 $category = NULL;
                 $cat = '(`id` NOT IN (';
                 $rslt = query_full_array('SELECT DISTINCT `news_id` FROM ' . prefix('news2cat'));
                 if (!empty($rslt)) {
                     $cat = ' `id` NOT IN (';
                     foreach ($rslt as $row) {
                         $cat .= $row['news_id'] . ',';
                     }
                     $cat = substr($cat, 0, -1) . ')';
                 }
             }
         }
         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 "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;
             default:
                 $sort1 = $sortorder . $dir;
                 break;
         }
         /** get all articles * */
         switch ($published) {
             case "published":
             default:
                 $show = "`show`=1";
                 $getUnpublished = false;
                 break;
             case "published-unpublished":
                 $show = "`show`=1";
                 $getUnpublished = true;
                 break;
             case "unpublished":
                 $show = "`show`=0";
                 $getUnpublished = true;
                 break;
             case 'sticky':
                 $show = "`sticky` <> 0";
                 $getUnpublished = true;
                 break;
             case "all":
                 $getUnpublished = zp_loggedin(MANAGE_ALL_NEWS_RIGHTS);
                 $show = false;
                 break;
         }
         $order = " ORDER BY {$sticky}";
         if (in_context(ZP_ZENPAGE_NEWS_DATE)) {
             switch ($published) {
                 case "published":
                 case "unpublished":
                 case "all":
                     $datesearch = "date LIKE '{$_zp_post_date}%' ";
                     break;
                 default:
                     $datesearch = '';
                     break;
             }
             if ($datesearch) {
                 if ($show) {
                     $datesearch = ' AND ' . $datesearch . ' ';
                 }
             }
             $order .= " date DESC";
         } else {
             $datesearch = "";
             if ($category) {
                 $order .= ' news.';
             } else {
                 $order .= ' ';
             }
             $order .= $sort1;
         }
         if ($category) {
             $sql = "SELECT DISTINCT news.date, news.publishdate, news.expiredate, news.lastchange, news.title, news.titlelink, news.sticky FROM " . prefix('news') . " as news, " . prefix('news2cat') . " as cat WHERE" . $cat;
             if ($show || $datesearch) {
                 $sql .= ' AND ' . $show . $datesearch;
             }
         } else {
             $sql = "SELECT * FROM " . prefix('news');
             if ($cat) {
                 $sql .= ' WHERE ' . $cat;
             }
             if ($show || $datesearch) {
                 if ($cat) {
                     $sql .= ' AND ';
                 } else {
                     $sql .= ' WHERE ';
                 }
                 $sql .= $show . $datesearch;
             }
         }
         $sql .= $order;
         $resource = query($sql);
         $result = array();
         if ($resource) {
             if (zp_loggedin(VIEW_UNPUBLISHED_NEWS_RIGHTS)) {
                 $getUnpublished = true;
             }
             while ($item = db_fetch_assoc($resource)) {
                 $article = newArticle($item['titlelink']);
                 if ($incurrent = $currentCat) {
                     $incurrent = $article->inNewsCategory($currentCat);
                 }
                 $subrights = $article->subRights();
                 if ($getUnpublished || $article->getShow() && ($incurrent || $article->categoryIsVisible() || $subrights) || $subrights & MANAGED_OBJECT_RIGHTS_VIEW || $article->isMyItem(ZENPAGE_NEWS_RIGHTS)) {
                     $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;
 }