Пример #1
0
 /**
  * Replace all of the category pairs with the correct data.
  *
  * @param String	The tagdata to be parsed
  * @param Object	The channel parser object
  * @param Mixed		The results from the preparse method
  *
  * @return String	The processed tagdata
  */
 public function replace($tagdata, EE_Channel_data_parser $obj, $cat_chunk)
 {
     $data = $obj->row();
     $prefix = $obj->prefix();
     $categories = $obj->data('categories', array());
     $tagname = $prefix . 'categories';
     // Check to see if the category chunks still exist; if not, check
     // the tagdata in case they've been modified since pre-processing
     foreach ($cat_chunk as $chunk) {
         if (strpos($tagdata, $chunk[2]) === FALSE) {
             $cat_chunk = $this->_get_cat_chunks($tagdata, $prefix);
             $obj->preparsed()->set_once_data($this, $cat_chunk);
             break;
         }
     }
     if (isset($categories[$data['entry_id']]) and is_array($categories[$data['entry_id']]) and count($cat_chunk) > 0) {
         // Get category ID from URL for {if active} conditional
         ee()->load->helper('segment');
         $active_cat = $obj->channel()->pagination->dynamic_sql && $obj->channel()->cat_request ? parse_category($obj->channel()->query_string) : FALSE;
         foreach ($cat_chunk as $catkey => $catval) {
             $cats = '';
             $i = 0;
             $not_these = array();
             $these = array();
             $not_these_groups = array();
             $these_groups = array();
             if (isset($catval[1]['show'])) {
                 if (strncmp($catval[1]['show'], 'not ', 4) == 0) {
                     $not_these = explode('|', trim(substr($catval[1]['show'], 3)));
                 } else {
                     $these = explode('|', trim($catval[1]['show']));
                 }
             }
             if (isset($catval[1]['show_group'])) {
                 if (strncmp($catval[1]['show_group'], 'not ', 4) == 0) {
                     $not_these_groups = explode('|', trim(substr($catval[1]['show_group'], 3)));
                 } else {
                     $these_groups = explode('|', trim($catval[1]['show_group']));
                 }
             }
             foreach ($categories[$data['entry_id']] as $k => $v) {
                 if (in_array($v[0], $not_these) or isset($v[5]) && in_array($v[5], $not_these_groups)) {
                     continue;
                 } elseif (count($these) > 0 && !in_array($v[0], $these) or count($these_groups) > 0 && isset($v[5]) && !in_array($v[5], $these_groups)) {
                     continue;
                 }
                 $temp = $catval[0];
                 if (preg_match_all("#" . LD . "path=(.+?)" . RD . "#", $temp, $matches)) {
                     foreach ($matches[1] as $match) {
                         if ($obj->channel()->use_category_names == TRUE) {
                             $temp = preg_replace("#" . LD . "path=.+?" . RD . "#", reduce_double_slashes(ee()->functions->create_url($match) . '/' . $obj->channel()->reserved_cat_segment . '/' . $v[6]), $temp, 1);
                         } else {
                             $temp = preg_replace("#" . LD . "path=.+?" . RD . "#", reduce_double_slashes(ee()->functions->create_url($match) . '/C' . $v[0]), $temp, 1);
                         }
                     }
                 } else {
                     $temp = preg_replace("#" . LD . "path=.+?" . RD . "#", ee()->functions->create_url("SITE_INDEX"), $temp);
                 }
                 ee()->load->library('file_field');
                 $cat_image = ee()->file_field->parse_field($v[3]);
                 $cat_vars = array('category_name' => $v[2], 'category_url_title' => $v[6], 'category_description' => isset($v[4]) ? $v[4] : '', 'category_group' => isset($v[5]) ? $v[5] : '', 'category_image' => $cat_image['url'], 'category_id' => $v[0], 'parent_id' => $v[1], 'active' => $active_cat == $v[0] || $active_cat == $v[6]);
                 // add custom fields for conditionals prep
                 foreach ($obj->channel()->catfields as $cv) {
                     $cat_vars[$cv['field_name']] = !isset($v['field_id_' . $cv['field_id']]) ? '' : $v['field_id_' . $cv['field_id']];
                 }
                 $temp = ee()->functions->prep_conditionals($temp, $cat_vars);
                 $temp = str_replace(array(LD . "category_id" . RD, LD . "category_name" . RD, LD . "category_url_title" . RD, LD . "category_image" . RD, LD . "category_group" . RD, LD . 'category_description' . RD, LD . 'parent_id' . RD), array($v[0], ee()->functions->encode_ee_tags($v[2]), $v[6], $cat_image['url'], isset($v[5]) ? $v[5] : '', isset($v[4]) ? ee()->functions->encode_ee_tags($v[4]) : '', $v[1]), $temp);
                 foreach ($obj->channel()->catfields as $cv2) {
                     if (isset($v['field_id_' . $cv2['field_id']]) and $v['field_id_' . $cv2['field_id']] != '') {
                         $field_content = ee()->typography->parse_type($v['field_id_' . $cv2['field_id']], array('text_format' => $v['field_ft_' . $cv2['field_id']], 'html_format' => $v['field_html_formatting'], 'auto_links' => 'n', 'allow_img_url' => 'y'));
                         $temp = str_replace(LD . $cv2['field_name'] . RD, $field_content, $temp);
                     } else {
                         // garbage collection
                         $temp = str_replace(LD . $cv2['field_name'] . RD, '', $temp);
                     }
                     $temp = reduce_double_slashes($temp);
                 }
                 $cats .= $temp;
                 if (is_array($catval[1]) && isset($catval[1]['limit']) && $catval[1]['limit'] == ++$i) {
                     break;
                 }
             }
             if (is_array($catval[1]) and isset($catval[1]['backspace'])) {
                 $cats = substr($cats, 0, -$catval[1]['backspace']);
             }
             // Check to see if we need to parse {filedir_n}
             if (strpos($cats, '{filedir_') !== FALSE) {
                 ee()->load->library('file_field');
                 $cats = ee()->file_field->parse_string($cats);
             }
             $tagdata = str_replace($catval[2], $cats, $tagdata);
         }
     } else {
         $tagdata = preg_replace('/{' . $tagname . '[^}]*}(.+?){\\/' . $tagname . '[^}]*}/is', '', $tagdata);
     }
     return $tagdata;
 }
Пример #2
0
 /**
  *  Build SQL Query
  */
 private function _get_file_data($pagination = '')
 {
     $file_id = '';
     $category_id = FALSE;
     $category_group = FALSE;
     $category_params = array('category' => 'category_id', 'category_group' => 'category_group');
     $dynamic = ee()->TMPL->fetch_param('dynamic') !== 'no' ? TRUE : FALSE;
     // Parse the URL query string
     $query_string = ee()->uri->page_query_string != '' ? ee()->uri->page_query_string : ee()->uri->query_string;
     $uristr = ee()->uri->uri_string;
     if ($dynamic && !empty($query_string)) {
         // If the query string is a number, treat it as a file ID
         if (is_numeric($query_string)) {
             $file_id = $query_string;
         } else {
             if ($this->enable['categories']) {
                 ee()->load->helper('segment');
                 $category_id = parse_category($query_string);
             }
         }
     }
     // Check the file_id parameter and override the one fetched from the
     // query string
     if (ee()->TMPL->fetch_param('file_id')) {
         $file_id = ee()->TMPL->fetch_param('file_id');
     }
     // Chec	k for category parameters
     foreach ($category_params as $param => $variable) {
         if ($this->enable['categories'] && ($temp = ee()->TMPL->fetch_param($param))) {
             ${$variable} = $temp;
         }
     }
     // Start the cache so we can use for pagination
     ee()->db->start_cache();
     // Join the categories table if we're dealing with categories at all
     if ($category_id or $category_group) {
         ee()->db->distinct();
         // We use 'LEFT' JOIN when there is a 'not' so that we get entries
         // that are not assigned to a category.
         if ((substr($category_group, 0, 3) == 'not' or substr($category_id, 0, 3) == 'not') && ee()->TMPL->fetch_param('uncategorized_entries') !== 'n') {
             ee()->db->join('file_categories', 'exp_files.file_id = exp_file_categories.file_id', 'LEFT');
             ee()->db->join('categories', 'exp_file_categories.cat_id = exp_categories.cat_id', 'LEFT');
         } else {
             ee()->db->join('file_categories', 'exp_files.file_id = exp_file_categories.file_id', 'INNER');
             ee()->db->join('categories', 'exp_file_categories.cat_id = exp_categories.cat_id', 'INNER');
         }
     }
     // Start pulling File IDs to both paginate on then pull data
     ee()->db->select('exp_files.file_id');
     ee()->db->from('files');
     // Specify file ID(s) if supplied
     if ($file_id != '') {
         ee()->functions->ar_andor_string($file_id, 'exp_files.file_id');
     }
     // Specify directory ID(s) if supplied
     if (($directory_ids = ee()->TMPL->fetch_param('directory_id')) != FALSE) {
         ee()->functions->ar_andor_string($directory_ids, 'upload_location_id');
     } else {
         ee()->db->where_in('exp_files.site_id', ee()->TMPL->site_ids);
     }
     // Specify category and category group ID(s) if supplied
     foreach ($category_params as $param => $variable) {
         if (${$variable}) {
             $cat_field_name = $param == 'category' ? 'exp_categories.cat_id' : 'exp_categories.group_id';
             $include_uncategorized = substr(${$variable}, 0, 3) == 'not' && ee()->TMPL->fetch_param('uncategorized_entries') !== 'n' ? TRUE : FALSE;
             ee()->functions->ar_andor_string(${$variable}, $cat_field_name, '', $include_uncategorized);
         }
     }
     ee()->db->stop_cache();
     // Set the limit
     $limit = (int) ee()->TMPL->fetch_param('limit', 0);
     $offset = (int) ee()->TMPL->fetch_param('offset', 0);
     if ($limit > 0 && $this->enable['pagination'] && $pagination->paginate == TRUE) {
         $pagination->build(ee()->db->count_all_results(), $limit);
         ee()->db->limit($pagination->per_page, $pagination->offset);
     } else {
         if ($limit > 0 && $offset >= 0) {
             ee()->db->limit($limit, $offset);
         } else {
             ee()->db->limit(100);
         }
     }
     // Set order and sort
     $allowed_orders = array('date', 'upload_date', 'random');
     $order_by = strtolower(ee()->TMPL->fetch_param('orderby', 'upload_date'));
     $order_by = ($order_by == 'date' or !in_array($order_by, $allowed_orders)) ? 'upload_date' : $order_by;
     $random = $order_by == 'random' ? TRUE : FALSE;
     $sort = strtolower(ee()->TMPL->fetch_param('sort', 'desc'));
     $sort = $random ? 'random' : $sort;
     ee()->db->order_by($order_by, $sort);
     // Run the query and pass it to the final query
     $query = ee()->db->get();
     ee()->db->flush_cache();
     if ($query->num_rows() == 0) {
         return array();
     }
     foreach ($query->result() as $row) {
         $file_ids[] = $row->file_id;
     }
     //  Build the full SQL query
     ee()->db->select('*')->join('upload_prefs', 'upload_prefs.id = files.upload_location_id', 'LEFT')->where_in('file_id', $file_ids)->order_by($order_by, $sort);
     return ee()->db->get('files');
 }
Пример #3
0
 /**
  *  Category Sub-tree
  */
 public function category_subtree($cdata = array())
 {
     $default = array('parent_id', 'path', 'template', 'depth', 'channel_array', 'show_empty');
     foreach ($default as $val) {
         ${$val} = !isset($cdata[$val]) ? '' : $cdata[$val];
     }
     $open = 0;
     if ($depth == '') {
         $depth = 1;
     }
     $tab = '';
     for ($i = 0; $i <= $depth; $i++) {
         $tab .= "\t";
     }
     $total_results = count($this->cat_array);
     // Get category ID from URL for {if active} conditional
     $this->EE->load->helper('segment');
     $active_cat = parse_category($this->query_string);
     foreach ($this->cat_array as $key => $val) {
         if ($parent_id == $val[0]) {
             if ($open == 0) {
                 $open = 1;
                 $this->category_list[] = "\n" . $tab . "<ul>\n";
             }
             $chunk = $template;
             $this->EE->load->library('file_field');
             $cat_image = $this->EE->file_field->parse_field($val[2]);
             $cat_vars = array('category_name' => $val[1], 'category_url_title' => $val[4], 'category_description' => $val[3], 'category_image' => $cat_image['url'], 'category_id' => $key, 'parent_id' => $val[0], 'active' => $active_cat == $key || $active_cat == $val[4]);
             // add custom fields for conditionals prep
             foreach ($this->catfields as $v) {
                 $cat_vars[$v['field_name']] = !isset($val['field_id_' . $v['field_id']]) ? '' : $val['field_id_' . $v['field_id']];
             }
             $cat_vars['count'] = ++$this->category_count;
             $cat_vars['total_results'] = $total_results;
             $chunk = $this->EE->functions->prep_conditionals($chunk, $cat_vars);
             $chunk = str_replace(array(LD . 'category_id' . RD, LD . 'category_name' . RD, LD . 'category_url_title' . RD, LD . 'category_image' . RD, LD . 'category_description' . RD, LD . 'parent_id' . RD), array($key, $val[1], $val[4], $cat_image['url'], $val[3], $val[0]), $chunk);
             foreach ($path as $pkey => $pval) {
                 if ($this->use_category_names == TRUE) {
                     $chunk = str_replace($pkey, $this->EE->functions->remove_double_slashes($pval . '/' . $this->reserved_cat_segment . '/' . $val[4]), $chunk);
                 } else {
                     $chunk = str_replace($pkey, $this->EE->functions->remove_double_slashes($pval . '/C' . $key), $chunk);
                 }
             }
             // parse custom fields
             foreach ($this->catfields as $ccv) {
                 if (isset($val['field_id_' . $ccv['field_id']]) and $val['field_id_' . $ccv['field_id']] != '') {
                     $field_content = $this->EE->typography->parse_type($val['field_id_' . $ccv['field_id']], array('text_format' => $val['field_ft_' . $ccv['field_id']], 'html_format' => $val['field_html_formatting'], 'auto_links' => 'n', 'allow_img_url' => 'y'));
                     $chunk = str_replace(LD . $ccv['field_name'] . RD, $field_content, $chunk);
                 } else {
                     // garbage collection
                     $chunk = str_replace(LD . $ccv['field_name'] . RD, '', $chunk);
                 }
             }
             /** --------------------------------
             				/**  {count}
             				/** --------------------------------*/
             if (strpos($chunk, LD . 'count' . RD) !== FALSE) {
                 $chunk = str_replace(LD . 'count' . RD, $this->category_count, $chunk);
             }
             /** --------------------------------
             				/**  {total_results}
             				/** --------------------------------*/
             if (strpos($chunk, LD . 'total_results' . RD) !== FALSE) {
                 $chunk = str_replace(LD . 'total_results' . RD, $total_results, $chunk);
             }
             $this->category_list[] = $tab . "\t<li>" . $chunk;
             if (is_array($channel_array)) {
                 $fillable_entries = 'n';
                 foreach ($channel_array as $k => $v) {
                     $k = substr($k, strpos($k, '_') + 1);
                     if ($key == $k) {
                         if (!isset($fillable_entries) or $fillable_entries == 'n') {
                             $this->category_list[] = "\n{$tab}\t\t<ul>\n";
                             $fillable_entries = 'y';
                         }
                         $this->category_list[] = "{$tab}\t\t\t{$v}";
                     }
                 }
             }
             if (isset($fillable_entries) && $fillable_entries == 'y') {
                 $this->category_list[] = "{$tab}\t\t</ul>\n";
             }
             $t = '';
             if ($this->category_subtree(array('parent_id' => $key, 'path' => $path, 'template' => $template, 'depth' => $depth + 2, 'channel_array' => $channel_array)) != 0) {
             }
             if (isset($fillable_entries) && $fillable_entries == 'y') {
                 $t .= "{$tab}\t";
             }
             $this->category_list[] = $t . "</li>\n";
             unset($this->temp_array[$key]);
             $this->close_ul($parent_id, $depth + 1);
         }
     }
     return $open;
 }