Exemplo n.º 1
0
 function before__route()
 {
     if (!$this->access('cp', 'attachments', 'view')) {
         return;
     }
     $this->get('search_attachments', 'search_attachments')->ALL(['url' => [\lib\router::get_class(), 'attachments_data'], 'property' => ['attachments_search_q' => ['/^.*$/', true, 'search'], 'attachments_search_image' => ['/^(on|off)$/', true, 'image'], 'attachments_search_video' => ['/^(on|off)$/', true, 'video'], 'attachments_search_audio' => ['/^(on|off)$/', true, 'audio'], 'attachments_search_other' => ['/^(on|off)$/', true, 'other']], 'max' => 1], function () {
         $this->on_search_attachments = true;
     });
 }
Exemplo n.º 2
0
 function max($max)
 {
     $url = \lib\router::get_url(-1);
     if (count($url) > 0 && \lib\router::get_class() == $url[0]) {
         array_shift($url);
     }
     if (count($url) > 0 && \lib\router::get_method() == $url[0]) {
         array_shift($url);
     }
     if (count($url) > $max) {
         $this->status = false;
     }
 }
Exemplo n.º 3
0
 public function ALL($route = null)
 {
     if ($route === null) {
         $this_url = '';
         if (\lib\router::get_class() != 'home') {
             $this_url = \lib\router::get_class();
         }
         if (\lib\router::get_method() != 'home') {
             $this_url .= '/' . \lib\router::get_method();
         }
         $route = array($this_url);
     } else {
         $route = func_get_args();
     }
     $this->REST(...$route)->SERVER();
     return $this;
 }
Exemplo n.º 4
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];
 }