コード例 #1
0
 /**
  * Returns the DB field corresponding to the sort type desired
  *
  * @param string $sorttype the desired sort
  * @return string
  */
 function getGallerySortKey($sorttype = null)
 {
     if (empty($sorttype)) {
         $sorttype = getOption('gallery_sorttype');
     }
     return lookupSortKey($sorttype, 'sort_order', 'folder');
 }
コード例 #2
0
ファイル: class-album.php プロジェクト: JoniWeiss/JoniWebGirl
 /**
  * Returns the DB key associated with the subalbum sort type
  *
  * @param string $sorttype subalbum sort type
  * @return string
  */
 function getAlbumSortKey($sorttype = null)
 {
     if (empty($sorttype)) {
         $sorttype = $this->getSortType('album');
     }
     return lookupSortKey($sorttype, 'sort_order', 'albums');
 }
コード例 #3
0
 /**
  * Searches the table for tags
  * Returns an array of database records.
  *
  * @param string $searchstring
  * @param string $tbl set to 'albums' or 'images'
  * @param string $sorttype what to sort on
  * @param string $sortdirection what direction
  * @return array
  */
 function searchFieldsAndTags($searchstring, $tbl, $sorttype, $sortdirection)
 {
     $allIDs = null;
     $idlist = array();
     $exact = EXACT_TAG_MATCH;
     // create an array of [tag, objectid] pairs for tags
     $tag_objects = array();
     $fields = $this->fieldList;
     if (count($fields) == 0) {
         // then use the default ones
         $fields = $this->allowedSearchFields();
     }
     foreach ($fields as $key => $field) {
         if (strtolower($field) == 'tags') {
             unset($fields[$key]);
             $tagsql = 'SELECT t.`name`, o.`objectid` FROM ' . prefix('tags') . ' AS t, ' . prefix('obj_to_tag') . ' AS o WHERE t.`id`=o.`tagid` AND o.`type`="' . $tbl . '" AND (';
             foreach ($searchstring as $singlesearchstring) {
                 switch ($singlesearchstring) {
                     case '&':
                     case '!':
                     case '|':
                     case '(':
                     case ')':
                         break;
                     default:
                         $targetfound = true;
                         if ($exact) {
                             $tagsql .= '`name` = ' . db_quote($singlesearchstring) . ' OR ';
                         } else {
                             $tagsql .= '`name` LIKE ' . db_quote('%' . $singlesearchstring . '%') . ' OR ';
                         }
                 }
             }
             $tagsql = substr($tagsql, 0, strlen($tagsql) - 4) . ') ORDER BY t.`id`';
             $objects = query_full_array($tagsql, false);
             if (is_array($objects)) {
                 $tag_objects = $objects;
             }
             break;
         }
     }
     // create an array of [name, objectid] pairs for the search fields.
     $field_objects = array();
     if (count($fields) > 0) {
         $columns = array();
         $dbfields = db_list_fields($tbl);
         if (is_array($dbfields)) {
             foreach ($dbfields as $row) {
                 $columns[] = strtolower($row['Field']);
             }
         }
         foreach ($searchstring as $singlesearchstring) {
             switch ($singlesearchstring) {
                 case '&':
                 case '!':
                 case '|':
                 case '(':
                 case ')':
                     break;
                 default:
                     $targetfound = true;
                     query('SET @serachtarget=' . db_quote($singlesearchstring));
                     $fieldsql = '';
                     foreach ($fields as $fieldname) {
                         if ($tbl == 'albums' && $fieldname == 'filename') {
                             $fieldname = 'folder';
                         } else {
                             $fieldname = strtolower($fieldname);
                         }
                         if ($fieldname && in_array($fieldname, $columns)) {
                             $fieldsql .= ' `' . $fieldname . '` LIKE ' . db_quote('%' . $singlesearchstring . '%') . ' OR ';
                         }
                     }
                     if (!empty($fieldsql)) {
                         $fieldsql = substr($fieldsql, 0, strlen($fieldsql) - 4) . ') ORDER BY `id`';
                         $sql = 'SELECT @serachtarget AS name, `id` AS `objectid` FROM ' . prefix($tbl) . ' WHERE (' . $fieldsql;
                         $objects = query_full_array($sql, false);
                         if (is_array($objects)) {
                             $field_objects = array_merge($field_objects, $objects);
                         }
                     }
             }
         }
     }
     $objects = array_merge($tag_objects, $field_objects);
     if (count($objects) != 0) {
         $tagid = '';
         $taglist = array();
         foreach ($objects as $object) {
             $tagid = strtolower($object['name']);
             if (!isset($taglist[$tagid]) || !is_array($taglist[$tagid])) {
                 $taglist[$tagid] = array();
             }
             $taglist[$tagid][] = $object['objectid'];
         }
         $op = '';
         $idstack = array();
         $opstack = array();
         while (count($searchstring) > 0) {
             $singlesearchstring = array_shift($searchstring);
             switch ($singlesearchstring) {
                 case '&':
                 case '!':
                 case '|':
                     $op = $op . $singlesearchstring;
                     break;
                 case '(':
                     array_push($idstack, $idlist);
                     array_push($opstack, $op);
                     $idlist = array();
                     $op = '';
                     break;
                 case ')':
                     $objectid = $idlist;
                     $idlist = array_pop($idstack);
                     $op = array_pop($opstack);
                     switch ($op) {
                         case '&':
                             if (is_array($objectid)) {
                                 $idlist = array_intersect($idlist, $objectid);
                             } else {
                                 $idlist = array();
                             }
                             break;
                         case '!':
                             break;
                             // Paren followed by NOT is nonsensical?
                         // Paren followed by NOT is nonsensical?
                         case '&!':
                             if (is_array($objectid)) {
                                 $idlist = array_diff($idlist, $objectid);
                             }
                             break;
                         case '':
                         case '|':
                             if (is_array($objectid)) {
                                 $idlist = array_merge($idlist, $objectid);
                             }
                             break;
                     }
                     $op = '';
                     break;
                 default:
                     $lookfor = strtolower($singlesearchstring);
                     $objectid = NULL;
                     foreach ($taglist as $key => $objlist) {
                         if ($exact && $lookfor == $key || !$exact && preg_match('%' . $lookfor . '%', $key)) {
                             if (is_array($objectid)) {
                                 $objectid = array_merge($objectid, $objlist);
                             } else {
                                 $objectid = $objlist;
                             }
                         }
                     }
                     switch ($op) {
                         case '&':
                             if (is_array($objectid)) {
                                 $idlist = array_intersect($idlist, $objectid);
                             } else {
                                 $idlist = array();
                             }
                             break;
                         case '!':
                             if (is_null($allIDs)) {
                                 $allIDs = array();
                                 $result = query_full_array("SELECT `id` FROM " . prefix($tbl));
                                 if (is_array($result)) {
                                     foreach ($result as $row) {
                                         $allIDs[] = $row['id'];
                                     }
                                 }
                             }
                             if (is_array($objectid)) {
                                 $idlist = array_merge($idlist, array_diff($allIDs, $objectid));
                             }
                             break;
                         case '&!':
                             if (is_array($objectid)) {
                                 $idlist = array_diff($idlist, $objectid);
                             }
                             break;
                         case '':
                         case '|':
                             if (is_array($objectid)) {
                                 $idlist = array_merge($idlist, $objectid);
                             }
                             break;
                     }
                     $idlist = array_unique($idlist);
                     $op = '';
                     break;
             }
             $idlist = array_unique($idlist);
         }
     }
     if (count($idlist) == 0) {
         return NULL;
     }
     $sql = 'SELECT DISTINCT `id`,`show`,`title`,';
     switch ($tbl) {
         case 'pages':
         case 'news':
             $sql .= '`titlelink` ';
             break;
         case 'albums':
             $sql .= "`desc`,`folder` ";
             break;
         default:
             $sql .= "`desc`,`albumid`,`filename`,`location`,`city`,`state`,`country` ";
             break;
     }
     if (zp_loggedin()) {
         $show = '';
     } else {
         $show = "`show` = 1 AND ";
     }
     switch ($tbl) {
         case 'news':
             if (is_array($this->category_list)) {
                 $news_list = $this->subsetNewsCategories();
                 $idlist = array_intersect($news_list, $idlist);
                 if (count($idlist) == 0) {
                     return NULL;
                 }
             }
             if (empty($sorttype)) {
                 $key = '`date` DESC';
             } else {
                 $key = trim('`' . $sorttype . '` ' . $sortdirection);
             }
             if ($show) {
                 $show .= '`date`<=' . db_quote(date('Y-m-d H:i:s')) . ' AND ';
             }
             break;
         case 'pages':
             if ($show) {
                 $show .= '`date`<=' . db_quote(date('Y-m-d H:i:s')) . ' AND ';
             }
             $key = '`sort_order`';
             break;
         case 'albums':
             if (is_null($sorttype)) {
                 if (empty($this->dynalbumname)) {
                     $key = lookupSortKey($this->gallery->getSortType(), 'sort_order', 'folder');
                     if ($this->gallery->getSortDirection()) {
                         $key .= " DESC";
                     }
                 } else {
                     $gallery = new Gallery();
                     $album = new Album($gallery, $this->dynalbumname);
                     $key = $album->getAlbumSortKey();
                     if ($key != '`sort_order`' && $key != 'RAND()') {
                         if ($album->getSortDirection('album')) {
                             $key .= " DESC";
                         }
                     }
                 }
             } else {
                 $sorttype = lookupSortKey($sorttype, 'sort_order', 'folder');
                 $key = trim($sorttype . ' ' . $sortdirection);
             }
             break;
         default:
             if (is_null($sorttype)) {
                 if (empty($this->dynalbumname)) {
                     $key = lookupSortKey(IMAGE_SORT_TYPE, 'filename', 'filename');
                     if (IMAGE_SORT_DIRECTION) {
                         $key .= " DESC";
                     }
                 } else {
                     $gallery = new Gallery();
                     $album = new Album($gallery, $this->dynalbumname);
                     $key = $album->getImageSortKey();
                     if ($key != '`sort_order`') {
                         if ($album->getSortDirection('image')) {
                             $key .= " DESC";
                         }
                     }
                 }
             } else {
                 $sorttype = lookupSortKey($sorttype, 'filename', 'filename');
                 $key = trim($sorttype . ' ' . $sortdirection);
             }
             break;
     }
     $sql .= "FROM " . prefix($tbl) . " WHERE " . $show;
     $sql .= '(' . $this->compressedIDList($idlist) . ')';
     $sql .= " ORDER BY " . $key;
     $result = query_full_array($sql);
     return $result;
 }
コード例 #4
0
/**
 * Returns the DB key associated with the subalbum sort type
 *
 * @param string $sorttype subalbum sort type
 * @return string
 */
function subalbumSortKey($sorttype)
{
    return lookupSortKey($sorttype, 'sort_order', 'folder');
}
コード例 #5
0
ファイル: class-search.php プロジェクト: elpadi/dahlen-studio
 /**
  * get connical sort key and direction parameters.
  * @param type $sorttype sort field desired
  * @param type $sortdirection DESC or ASC
  * @param type $defaulttype if no sort type otherwise selected use this one
  * @param type $table the database table being searched
  * @return array
  */
 protected function sortKey($sorttype, $sortdirection, $defaulttype, $table)
 {
     if (is_null($sorttype)) {
         if (array_key_exists($table . 'sorttype', $this->extraparams)) {
             $sorttype = $this->extraparams[$table . 'sorttype'];
         } else {
             if (array_key_exists('sorttype', $this->extraparams)) {
                 $sorttype = $this->extraparams['sorttype'];
             }
         }
     }
     $sorttype = lookupSortKey($sorttype, $defaulttype, $table);
     if (is_null($sortdirection)) {
         if (array_key_exists($table . 'sortdirection', $this->extraparams)) {
             $sortdirection = $this->extraparams[$table . 'sortdirection'];
         } else {
             if (array_key_exists('sortdirection', $this->extraparams)) {
                 $sortdirection = $this->extraparams['sortdirection'];
             }
         }
     }
     return array($sorttype, $sortdirection);
 }