/** * 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 * @param bool $mine set to true/false to override ownership clause * @return array */ protected function sortImageArray($images, $sorttype, $sortdirection, $mine = NULL) { if (is_null($mine)) { $mine = $this->isMyItem(LIST_RIGHTS | MANAGE_ALL_ALBUM_RIGHTS); } if ($mine && !($mine & MANAGE_ALL_ALBUM_RIGHTS)) { // check for managed album view unpublished image rights $mine = $this->albumSubRights() & (MANAGED_OBJECT_RIGHTS_EDIT | MANAGED_OBJECT_RIGHTS_VIEW); } $sortkey = $this->getImageSortKey($sorttype); if ($sortkey == '`sort_order`' || $sortkey == 'RAND()') { // manual sort is always ascending $order = false; } else { if (!is_null($sortdirection)) { $order = strtoupper($sortdirection) == 'DESC'; } else { $order = $this->getSortDirection('image'); } } $result = query($sql = "SELECT * FROM " . prefix("images") . " WHERE `albumid`= " . $this->getID() . ' ORDER BY ' . $sortkey . ' ' . $sortdirection); $results = array(); while ($row = db_fetch_assoc($result)) { $filename = $row['filename']; if (($key = array_search($filename, $images)) !== false) { // the image exists in the filesystem $results[] = $row; unset($images[$key]); } else { // the image no longer exists $id = $row['id']; query("DELETE FROM " . prefix('images') . " WHERE `id`={$id}"); // delete the record query("DELETE FROM " . prefix('comments') . " WHERE `type` ='images' AND `ownerid`= '{$id}'"); // remove image comments } } db_free_result($result); foreach ($images as $filename) { // these images are not in the database $imageobj = newImage($this, $filename); $results[] = $imageobj->getData(); } // now put the results into the right order $results = sortByKey($results, str_replace('`', '', $sortkey), $order); // the results are now in the correct order $images_ordered = array(); foreach ($results as $key => $row) { // check for visible switch (checkPublishDates($row)) { case 1: $imageobj = newImage($this, $row['filename']); $imageobj->setShow(0); $imageobj->save(); case 2: $row['show'] = 0; break; } if ($row['show'] || $mine) { // don't display it $images_ordered[] = $row['filename']; } } return $images_ordered; }
/** * 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; }
/** * Checks if the item is either expired or in scheduled publishing * A class method wrapper of the functions.php function of the same name * @return boolean */ function checkPublishDates() { $row = array(); if (isAlbumClass($this) || isImageClass($this)) { $row = array('show' => $this->getShow(), 'expiredate' => $this->getExpireDate(), 'publishdate' => $this->getPublishDate()); } else { if ($this->table == 'news' || $this->table == 'pages') { $row = array('show' => $this->getShow(), 'expiredate' => $this->getExpireDate(), 'publishdate' => $this->getDateTime()); } } $check = checkPublishDates($row); if ($check == 1 || $check == 2) { return false; } else { return true; } }
/** * 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 * @param string $sortdirection * @param bool $mine set true/false to override ownership * @return array * * @author Todd Papaioannou (lucky@luckyspin.org) * @since 1.0.0 */ function sortAlbumArray($parentalbum, $albums, $sortkey = '`sort_order`', $sortdirection = NULL, $mine = NULL) { if (count($albums) == 0) { return array(); } if (is_null($mine) && zp_loggedin(MANAGE_ALL_ALBUM_RIGHTS)) { $mine = true; } if (is_null($parentalbum)) { $albumid = ' IS NULL'; $obj = $this; $viewUnpublished = $mine; } else { $albumid = '=' . $parentalbum->getID(); $obj = $parentalbum; $viewUnpublished = zp_loggedin() && $obj->albumSubRights() & (MANAGED_OBJECT_RIGHTS_EDIT | MANAGED_OBJECT_RIGHTS_VIEW); } if ($sortkey == '`sort_order`' || $sortkey == 'RAND()') { // manual sort is always ascending $order = false; } else { if (!is_null($sortdirection)) { $order = strtoupper($sortdirection) == 'DESC'; } else { $order = $obj->getSortDirection('album'); } } $sortkey = db_quote($sortkey, false); $sql = 'SELECT * FROM ' . prefix("albums") . ' WHERE `parentid`' . $albumid . ' ORDER BY ' . $sortkey . ' ' . $sortdirection; $result = query($sql); $results = array(); // check database aganist file system while ($row = db_fetch_assoc($result)) { $folder = $row['folder']; if (($key = array_search($folder, $albums)) !== false) { // album exists in filesystem $results[$row['folder']] = $row; unset($albums[$key]); } else { // album no longer exists $id = $row['id']; query("DELETE FROM " . prefix('albums') . " WHERE `id`={$id}"); // delete the record query("DELETE FROM " . prefix('comments') . " WHERE `type` ='images' AND `ownerid`= '{$id}'"); // remove image comments query("DELETE FROM " . prefix('obj_to_tag') . "WHERE `type`='albums' AND `objectid`=" . $id); query("DELETE FROM " . prefix('albums') . " WHERE `id` = " . $id); } } db_free_result($result); foreach ($albums as $folder) { // these albums are not in the database $albumobj = newAlbum($folder); if ($albumobj->exists) { // fail to instantiate? $results[$folder] = $albumobj->getData(); } } // now put the results in the right order $results = sortByKey($results, $sortkey, $order); // albums are now in the correct order $albums_ordered = array(); foreach ($results as $row) { // check for visible $folder = $row['folder']; $album = newAlbum($folder); switch (checkPublishDates($row)) { case 1: $album->setShow(0); $album->save(); case 2: $row['show'] = 0; } if ($mine || $row['show'] || ($list = $album->isMyItem(LIST_RIGHTS)) && is_null($album->getParent()) || is_null($mine) && $list && $viewUnpublished) { $albums_ordered[] = $folder; } } return $albums_ordered; }