예제 #1
0
 public static function get($_args)
 {
     if (empty($_args) || !is_array($_args)) {
         return false;
     }
     if (isset($_args['limit'])) {
         $limit = "LIMIT " . $_args['limit'];
         unset($_args['limit']);
     } else {
         $limit = null;
     }
     $where = [];
     foreach ($_args as $key => $value) {
         $where[] = "`{$key}` = '{$value}'";
     }
     $where = "WHERE " . join($where, " AND ");
     $query = "\n\t\t\tSELECT\n\t\t\t\tid,\n\t\t\t\tuser_id AS 'user_id',\n\t\t\t\toption_cat AS 'cat',\n\t\t\t\toption_key AS 'key',\n\t\t\t\toption_value AS 'value',\n\t\t\t\toption_meta AS 'meta',\n\t\t\t\toption_status AS 'status'\n\t\t\tFROM\n\t\t\t\toptions\n\t\t\t{$where}\n\t\t\t{$limit}\n\t\t";
     return \lib\utility\filter::meta_decode(self::select($query, "get"));
 }
예제 #2
0
 public function query_search($_parameter = array())
 {
     $search = array_key_exists('search', $_parameter) ? $_parameter['search'] : null;
     $image = array_key_exists('image', $_parameter) ? $_parameter['image'] : null;
     $video = array_key_exists('video', $_parameter) ? $_parameter['video'] : null;
     $audio = array_key_exists('audio', $_parameter) ? $_parameter['audio'] : null;
     $other = array_key_exists('other', $_parameter) ? $_parameter['other'] : null;
     $where = '';
     if ($search) {
         $where .= "(post_title LIKE '%{$search}%' OR post_content LIKE '%{$search}%')";
     }
     $_type = ['image', 'audio', 'video'];
     $type = array();
     if ($image) {
         array_push($type, 'image');
     }
     if ($video) {
         array_push($type, 'video');
     }
     if ($audio) {
         array_push($type, 'audio');
     }
     if ($other) {
         array_push($type, 'other');
     }
     if (count($type) > 0 && count($type) < 4) {
         $where .= empty($where) ? '' : " AND ";
         if ($other) {
             if (count($type) == 1) {
                 $_type = join("\"' ,'\"", $_type);
                 $where .= "json_extract(post_meta, '\$.type') NOT IN ('\"{$_type}\"')";
             } else {
                 $_type = join("\"' ,'\"", array_diff($_type, $type));
                 $type = count($type) > 1 ? "\"" . join("\"' ,'\"", $type) . "\"" : $type[0];
                 $where .= "(json_extract(post_meta, '\$.type') IN ('{$type}')";
                 $where .= " OR json_extract(post_meta, '\$.type') NOT IN ('\"{$_type}\"'))";
             }
         } else {
             $type = count($type) > 1 ? "\"" . join("\"' ,'\"", $type) . "\"" : $type[0];
             $where .= "json_extract(post_meta, '\$.type') in ('{$type}')";
         }
     }
     $where .= empty($where) ? '' : " AND ";
     $where .= "post_type = 'attachment'";
     $length = 5;
     $start = 0;
     if ($_parameter['pagnation']) {
         list($start, $length) = $this->controller->pagnation_make_limit($length);
     }
     $query = "SELECT SQL_CALC_FOUND_ROWS posts.*, FOUND_ROWS() FROM posts WHERE {$where} LIMIT {$start}, {$length}";
     $result = \lib\db::query($query);
     $query_rows = "SELECT FOUND_ROWS() as rows";
     $result_rows = \lib\db::query($query_rows);
     $rows = $result_rows->fetch_assoc()['rows'];
     if ($_parameter['pagnation']) {
         $this->controller->pagnation_make($rows);
         $pagnation = $this->controller->pagnation;
     } else {
         $pagnation['total_pages'] = intval(ceil($rows / $length));
         $pagnation['current'] = 1;
         $pagnation['next'] = $pagnation['current'] + 1 <= $pagnation['total_pages'] ? $pagnation['current'] + 1 : false;
         $pagnation['prev'] = $pagnation['current'] - 1 >= 1 ? $pagnation['current'] - 1 : false;
         $pagnation['count_link'] = 7;
         $pagnation['current_url'] = \lib\router::get_class() . '/attachments_data';
         $pagnation['length'] = $length;
     }
     $decode_result = \lib\utility\filter::meta_decode(\lib\db::fetch_all($result));
     return ['data' => $decode_result, 'pagnation' => $pagnation];
 }
예제 #3
0
 public static function get_post_meta($_post_id)
 {
     $query = "\n\t\t\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\toptions\n\t\t\tWHERE\n\t\t\t\toptions.post_id = {$_post_id} AND\n\t\t\t\toptions.option_cat = 'poll_{$_post_id}'\n\t\t";
     $result = \lib\db\options::select($query, "get");
     return \lib\utility\filter::meta_decode($result);
 }