public function test_trim_slashes() { $strs = array('//Slashes//\\/' => 'Slashes//\\', '/var/www/html/' => 'var/www/html'); foreach ($strs as $str => $expect) { $this->assertEquals($expect, trim_slashes($str)); } }
function catalogov() { parent::Controller(); $this->load->helper('string'); $protocolo = explode('/', $_SERVER['SERVER_PROTOCOL']); $this->_direccion = $protocolo[0] . '://' . $_SERVER['SERVER_NAME'] . '/' . trim_slashes($this->config->item('base_url')); }
function ver2() { $parametros = func_get_args(); $this->_direccion = 'http://localhost/' . trim_slashes($this->config->item('base_url')); if (count($parametros) > 0) { $_arch_nombre = implode('-', $parametros); $_fnombre = array_shift($parametros); $this->load->library('dompdf/cidompdf'); $query = $this->db->query("SELECT proteo FROM formatos WHERE nombre='{$_fnombre}'"); if ($query->num_rows() > 0) { $row = $query->row(); ob_start(); echo eval('?>' . preg_replace("/;*\\s*\\?>/", "; ?>", str_replace('<?=', '<?php echo ', $row->proteo)) . '<?php '); $_html = ob_get_contents(); @ob_end_clean(); if (strlen($_html) > 0) { $this->cidompdf->html2pdf($_html, $_arch_nombre); } else { echo 'Formato no definido'; } } else { echo 'Formato no existe'; } } else { echo 'Faltan parametros'; } }
/** * Parse N Indicator */ function parse_n($qstring, $uristr, $dynamic = TRUE) { $uristr = FALSE; if (preg_match("#^N(\\d+)|/N(\\d+)#", $qstring, $match)) { $uristr = $this->EE->functions->remove_double_slashes(str_replace($match[0], '', $uristr)); $qstring = trim_slashes(str_replace($match[0], '', $qstring)); } return array('uristr' => $uristr, 'qstring' => $qstring); }
function Formatos() { parent::Controller(); $this->load->library("rapyd"); //$this->load->library("numletra"); $this->load->plugin('numletra'); $this->load->helper('string'); $protocolo = explode('/', $_SERVER['SERVER_PROTOCOL']); $this->_direccion = $protocolo[0] . '://' . $_SERVER['SERVER_NAME'] . '/' . trim_slashes($this->config->item('base_url')); }
/** * Parse Year and Month */ function parse_year_month($qstring, $dynamic = TRUE) { // added (^|\/) to make sure this doesn't trigger with url titles like big_party_2006 if ($dynamic && preg_match("#(^|\\/)(\\d{4}/\\d{2})(\\/|\$)#", $qstring, $match)) { $ex = explode('/', $match[2]); $year = $ex[0]; $month = $ex[1]; $qstring = trim_slashes(str_replace($match[2], '', $qstring)); } return array('year' => $year, 'month' => $month, 'qstring' => $qstring); }
private function _create_links() { $CI =& get_instance(); $this->cur_page = trim_slashes($CI->uri->ruri_string()); $li = NULL; foreach ($this->_data() as $line) { if ($this->cur_display == TRUE) { $this->cur_page == $line['slug'] ? $line['class'] = $line['class'] . ' ' . $this->cur_class : $line['class']; } $li .= $this->item_tag_open . anchor($line['slug'], $line['name'], array('class' => $line['class'])) . $this->item_tag_close; } $this->output = $this->full_tag_open . $li . $this->full_tag_close; return $this->output; }
/** * Finds files in both the core and local directories and merges them into one listing * @author Matt Ryan * @date 2006-05-18 * @param string $dir_path * @param string $section * @return array $files */ function reason_get_merged_fileset($dir_path, $section = 'lib') { $areas = array('core', 'local'); $files = array(); foreach ($areas as $area) { $directory = REASON_INC . $section . '/' . $area . '/' . trim_slashes($dir_path) . '/'; if (is_dir($directory)) { $handle = opendir($directory); while ($entry = readdir($handle)) { if (is_file($directory . $entry)) { $files[$entry] = $entry; } } } } ksort($files); return $files; }
/** * @return string|NULL Canonical url, NULL if current page is canonical */ public function get_canonical_url() { foreach ($this->modules as $key => $module) { $this->data[$key]['non_canonical'] = $module->get_noncanonical_request_keys(); $this->data[$key]['all'] = array_keys($module->get_cleanup_rules()); $this->data[$key]['canonical'] = array_diff($this->data[$key]['non_canonical'], $this->data[$key]['all']); } $canonicalized_url = NULL; $non_cans_array = $this->get_non_canonical_url_params(); $curr_url = get_current_url(); $parsed_url = parse_url($curr_url); $non_cans_array = array_flip($non_cans_array); $canonicalized_url = $this->strip_non_canonical_url_params($non_cans_array, $parsed_url); if ($canonicalized_url == get_current_url()) { return; } else { return trim_slashes($canonicalized_url); } }
function save_settings() { $this->EE->load->helper('string'); unset($_POST['file'], $_POST['submit']); if ($_POST['old_url'] && $_POST['new_url']) { $original_url = trim_slashes(trim($_POST['old_url'])); $data = array('original_url' => xss_clean($original_url), 'new_url' => xss_clean($_POST['new_url']), 'detour_method' => xss_clean($_POST['new_detour_method'])); if ($original_url != $_POST['new_url']) { $this->EE->db->insert('exp_detours', $data); } else { $this->EE->session->set_flashdata('message_failure', $this->EE->lang->line('original_equals_redirect')); } } if (!empty($_POST['detour_delete'])) { $delete_sql = "DELETE \n\t\t\tFROM exp_detours \n\t\t\tWHERE detour_id IN (" . implode(',', $_POST['detour_delete']) . ")"; $this->EE->db->query($delete_sql); } if (!empty($_POST['hits_delete'])) { $delete_sql = "UPDATE \n\t\t\texp_detours SET hitcounter=0\n\t\t\tWHERE detour_id IN (" . implode(',', $_POST['hits_delete']) . ")"; $this->EE->db->query($delete_sql); } $this->EE->functions->redirect(BASE . AMP . 'C=addons_extensions' . AMP . 'M=extension_settings' . AMP . 'file=detour'); }
function ver($numero = '00042617') { $this->load->helper('string'); $protocolo = explode('/', $_SERVER['SERVER_PROTOCOL']); $_direccion = $protocolo[0] . '://' . $_SERVER['SERVER_NAME'] . '/' . trim_slashes($this->config->item('base_url')); $mSQL_1 = $this->db->query("SELECT fecha,numero,cod_cli,nombre,impuesto,gtotal,stotal FROM pmay WHERE numero={$numero}"); $mSQL_2 = $this->db->query("SELECT codigo,descrip,cantidad,fraccion,precio,importe from itpmay WHERE numero={$numero}"); $row = $mSQL_1->row(); $data['fecha'] = $row->fecha; $data['numero'] = $row->numero; $data['cod_cli'] = $row->cod_cli; $data['nombre'] = $row->nombre; $data['stotal'] = $row->stotal; $data['gtotal'] = $row->gtotal; $data['impuesto'] = $row->impuesto; $data['detalle'] = $mSQL_2->result(); $data['_direccion'] = $_direccion; $this->load->plugin('html2pdf'); $html = $this->load->view('view_vpresupuesto', $data, true); pdf_create($html, 'nombrepdf'); //echo $html; //http://192.168.0.99/proteoerp/ventas/vpresupuesto/ver/00042617 //$this->load->view('view_vpresupuesto', $data); }
/** ---------------------------------------- /** Show search results /** ----------------------------------------*/ function search_results() { // Fetch the search language file $this->EE->lang->loadfile('search'); // Load Pagination Object $this->EE->load->library('pagination'); $pagination = new Pagination_object(__CLASS__); // Capture Pagination Template $pagination->get_template(); // Check to see if we're using old style pagination // TODO: Remove once old pagination is phased out $old_pagination = strpos($this->EE->TMPL->template, LD . 'if paginate' . RD) !== FALSE ? TRUE : FALSE; // If we are using old pagination, log it as deprecated // TODO: Remove once old pagination is phased out if ($old_pagination) { $this->EE->load->library('logger'); $this->EE->logger->developer('Deprecated template tag {if paginate}. Old style pagination in the Search Module has been deprecated in 2.4 and will be removed soon. Switch to the new Channel style pagination.', TRUE); } // Check search ID number // If the QSTR variable is less than 32 characters long we // don't have a valid search ID number if (strlen($this->EE->uri->query_string) < 32) { return $this->EE->output->show_user_error('off', array(lang('search_no_result')), lang('search_result_heading')); } // Clear old search results $this->EE->db->delete('search', array('site_id' => $this->EE->config->item('site_id'), 'search_date <' => $this->EE->localize->now - $this->cache_expire * 3600)); // Fetch ID number and page number $pagination->offset = 0; $qstring = $this->EE->uri->query_string; // Parse page number if (preg_match("#^P(\\d+)|/P(\\d+)#", $qstring, $match)) { $pagination->offset = isset($match[2]) ? $match[2] : $match[1]; $search_id = trim_slashes(str_replace($match[0], '', $qstring)); } else { $pagination->offset = 0; $search_id = $qstring; } // If there is a slash in the search ID we'll kill everything after it. $search_id = trim($search_id); $search_id = preg_replace("#/.+#", "", $search_id); // Fetch the cached search query $query = $this->EE->db->get_where('search', array('search_id' => $search_id)); if ($query->num_rows() == 0 or $query->row('total_results') == 0) { return $this->EE->output->show_user_error('off', array(lang('search_no_result')), lang('search_result_heading')); } $fields = $query->row('custom_fields') == '' ? array() : unserialize(stripslashes($query->row('custom_fields'))); $sql = unserialize(stripslashes($query->row('query'))); $sql = str_replace('MDBMPREFIX', 'exp_', $sql); $pagination->per_page = (int) $query->row('per_page'); $res_page = $query->row('result_page'); // Run the search query $query = $this->EE->db->query(preg_replace("/SELECT(.*?)\\s+FROM\\s+/is", 'SELECT COUNT(*) AS count FROM ', $sql)); if ($query->row('count') == 0) { return $this->EE->output->show_user_error('off', array(lang('search_no_result')), lang('search_result_heading')); } // Calculate total number of pages and add total rows $pagination->current_page = $pagination->offset / $pagination->per_page + 1; $pagination->total_rows = $query->row('count'); // Figure out total number of pages for old style pagination // TODO: Remove once old pagination is phased out if ($old_pagination) { $total_pages = intval($pagination->total_rows / $pagination->per_page); if ($pagination->total_rows % $pagination->per_page) { $total_pages++; } $page_count = lang('page') . ' ' . $pagination->current_page . ' ' . lang('of') . ' ' . $total_pages; $pager = ''; if ($pagination->total_rows > $pagination->per_page) { $this->EE->load->library('pagination'); $config = array('base_url' => $this->EE->functions->create_url($res_page . '/' . $search_id, 0, 0), 'prefix' => 'P', 'total_rows' => $pagination->total_rows, 'per_page' => $pagination->per_page, 'cur_page' => $pagination->offset, 'first_link' => lang('pag_first_link'), 'last_link' => lang('pag_last_link'), 'uri_segment' => 0); $this->EE->pagination->initialize($config); $pager = $this->EE->pagination->create_links(); } } // Build pagination if enabled if ($pagination->paginate === TRUE) { $pagination->build($pagination->total_rows); } // If we're paginating, old or new, limit the query and do it again if ($pagination->paginate === TRUE or $old_pagination) { $sql .= " LIMIT " . $pagination->offset . ", " . $pagination->per_page; } else { if ($pagination->per_page > 0) { $sql .= " LIMIT 0, " . $pagination->per_page; } else { $sql .= " LIMIT 0, 100"; } } $query = $this->EE->db->query($sql); $output = ''; if (!class_exists('Channel')) { require PATH_MOD . 'channel/mod.channel.php'; } unset($this->EE->TMPL->var_single['auto_path']); unset($this->EE->TMPL->var_single['excerpt']); unset($this->EE->TMPL->var_single['id_auto_path']); unset($this->EE->TMPL->var_single['full_text']); unset($this->EE->TMPL->var_single['switch']); foreach ($this->EE->TMPL->var_single as $key => $value) { if (substr($key, 0, strlen('member_path')) == 'member_path') { unset($this->EE->TMPL->var_single[$key]); } } $channel = new Channel(); // This allows the channel {absolute_count} variable to work $channel->pagination->offset = $pagination->per_page * $pagination->current_page - $pagination->per_page; $channel->fetch_custom_channel_fields(); $channel->fetch_custom_member_fields(); $channel->query = $this->EE->db->query($sql); if ($channel->query->num_rows() == 0) { return $this->EE->TMPL->no_results(); } $this->EE->load->library('typography'); $this->EE->typography->initialize(array('convert_curly' => FALSE, 'encode_email' => FALSE)); $channel->fetch_categories(); $channel->parse_channel_entries(); $tagdata = $this->EE->TMPL->tagdata; // Does the tag contain "related entries" that we need to parse out? if (count($this->EE->TMPL->related_data) > 0 and count($channel->related_entries) > 0) { $channel->parse_related_entries(); } if (count($this->EE->TMPL->reverse_related_data) > 0 and count($channel->reverse_related_entries) > 0) { $channel->parse_reverse_related_entries(); } $output = $channel->return_data; $this->EE->TMPL->tagdata = $tagdata; // Fetch member path variable // We do it here in case it's used in multiple places. $m_paths = array(); if (preg_match_all("/" . LD . "member_path(\\s*=.*?)" . RD . "/s", $this->EE->TMPL->tagdata, $matches)) { for ($j = 0; $j < count($matches['0']); $j++) { $m_paths[] = array($matches['0'][$j], $this->EE->functions->extract_path($matches['1'][$j])); } } // Fetch switch param $switch1 = ''; $switch2 = ''; if ($switch = $this->EE->TMPL->fetch_param('switch')) { if (strpos($switch, '|') !== FALSE) { $x = explode("|", $switch); $switch1 = $x['0']; $switch2 = $x['1']; } else { $switch1 = $switch; } } /** ----------------------------- /** Result Loop - Legacy! /** -----------------------------*/ $i = 0; foreach ($query->result_array() as $row) { if (isset($row['field_id_' . $row['search_excerpt']]) and $row['field_id_' . $row['search_excerpt']]) { $format = !isset($row['field_ft_' . $row['search_excerpt']]) ? 'xhtml' : $row['field_ft_' . $row['search_excerpt']]; $full_text = $this->EE->typography->parse_type(strip_tags($row['field_id_' . $row['search_excerpt']]), array('text_format' => $format, 'html_format' => 'safe', 'auto_links' => 'y', 'allow_img_url' => 'n')); $excerpt = trim(strip_tags($full_text)); if (strpos($excerpt, "\r") !== FALSE or strpos($excerpt, "\n") !== FALSE) { $excerpt = str_replace(array("\r\n", "\r", "\n"), " ", $excerpt); } $excerpt = $this->EE->functions->word_limiter($excerpt, 50); } else { $excerpt = ''; $full_text = ''; } // Parse permalink path $url = $row['search_results_url'] != '' ? $row['search_results_url'] : $row['channel_url']; $path = $this->EE->functions->remove_double_slashes($this->EE->functions->prep_query_string($url) . '/' . $row['url_title']); $idpath = $this->EE->functions->remove_double_slashes($this->EE->functions->prep_query_string($url) . '/' . $row['entry_id']); $switch = $i++ % 2 ? $switch1 : $switch2; $output = preg_replace("/" . LD . 'switch' . RD . "/", $switch, $output, count(explode(LD . 'switch' . RD, $this->EE->TMPL->tagdata)) - 1); $output = preg_replace("/" . LD . 'auto_path' . RD . "/", $path, $output, count(explode(LD . 'auto_path' . RD, $this->EE->TMPL->tagdata)) - 1); $output = preg_replace("/" . LD . 'id_auto_path' . RD . "/", $idpath, $output, count(explode(LD . 'id_auto_path' . RD, $this->EE->TMPL->tagdata)) - 1); $output = preg_replace("/" . LD . 'excerpt' . RD . "/", preg_quote($excerpt), $output, count(explode(LD . 'excerpt' . RD, $this->EE->TMPL->tagdata)) - 1); $output = preg_replace("/" . LD . 'full_text' . RD . "/", preg_quote($full_text), $output, count(explode(LD . 'full_text' . RD, $this->EE->TMPL->tagdata)) - 1); // Parse member_path if (count($m_paths) > 0) { foreach ($m_paths as $val) { $output = preg_replace("/" . preg_quote($val['0'], '/') . "/", $this->EE->functions->create_url($val['1'] . '/' . $row['member_id']), $output, 1); } } } $this->EE->TMPL->tagdata = $output; // Add new pagination $this->EE->TMPL->tagdata = $pagination->render($this->EE->TMPL->tagdata); // Parse lang variables $swap = array('lang:total_search_results' => lang('search_total_results'), 'lang:search_engine' => lang('search_engine'), 'lang:search_results' => lang('search_results'), 'lang:search' => lang('search'), 'lang:title' => lang('search_title'), 'lang:channel' => lang('search_channel'), 'lang:excerpt' => lang('search_excerpt'), 'lang:author' => lang('search_author'), 'lang:date' => lang('search_date'), 'lang:total_comments' => lang('search_total_comments'), 'lang:recent_comments' => lang('search_recent_comment_date'), 'lang:keywords' => lang('search_keywords')); $this->EE->TMPL->template = $this->EE->functions->var_swap($this->EE->TMPL->template, $swap); // Add Old Style Pagination // TODO: Remove once old pagination is phased out if ($old_pagination) { if ($pager == '') { $this->EE->TMPL->template = preg_replace("#" . LD . "if paginate" . RD . ".*?" . LD . "/if" . RD . "#s", '', $this->EE->TMPL->template); } else { $this->EE->TMPL->template = preg_replace("#" . LD . "if paginate" . RD . "(.*?)" . LD . "/if" . RD . "#s", "\\1", $this->EE->TMPL->template); } $this->EE->TMPL->template = str_replace(LD . 'paginate' . RD, $pager, $this->EE->TMPL->template); $this->EE->TMPL->template = str_replace(LD . 'page_count' . RD, $page_count, $this->EE->TMPL->template); } return $this->EE->TMPL->tagdata; }
/** * @author go frendi * * @param slug * @param widget_name * * @return mixed * @desc return widgets */ public function cms_widgets($slug = null, $widget_name = null) { // get user_name, user_id, etc $user_name = $this->cms_user_name(); $user_id = $this->cms_user_id(); $user_id = $user_id == '' ? 0 : $user_id; $not_login = !$user_name ? '(1=1)' : '(1=2)'; $login = $user_name ? '(1=1)' : '(1=2)'; $super_user = $this->cms_user_is_super_admin() ? '(1=1)' : '(1=2)'; /* $slug_where = isset($slug)? "(((slug LIKE '".addslashes($slug)."') OR (slug LIKE '%".addslashes($slug)."%')) AND active=1)" : "1=1"; $widget_name_where = isset($widget_name)? "widget_name LIKE '".addslashes($widget_name)."'" : "1=1"; */ if (!self::$__cms_model_properties['is_widget_cached']) { $SQL = 'SELECT widget_id, widget_name, is_static, title, description, url, slug, static_content, active FROM ' . cms_table_name('main_widget') . " AS w WHERE\n (\n (authorization_id = 1) OR\n (authorization_id = 2 AND {$not_login}) OR\n (authorization_id = 3 AND {$login}) OR\n (\n (authorization_id = 4 AND {$login}) AND\n (\n {$super_user} OR\n (SELECT COUNT(*) FROM " . cms_table_name('main_group_widget') . ' AS gw WHERE gw.widget_id=w.widget_id AND gw.group_id IN (SELECT group_id FROM ' . cms_table_name('main_group_user') . ' WHERE user_id = ' . addslashes($user_id) . ")\n )>0\n )\n ) OR\n (\n (authorization_id = 5 AND {$login}) AND\n (\n (SELECT COUNT(*) FROM " . cms_table_name('main_group_widget') . ' AS gw WHERE gw.widget_id=w.widget_id AND gw.group_id IN (SELECT group_id FROM ' . cms_table_name('main_group_user') . ' WHERE user_id = ' . addslashes($user_id) . ') )>0 ) ) ) ORDER BY ' . $this->db->protect_identifiers('index'); $query = $this->db->query($SQL); self::$__cms_model_properties['widget'] = $query->result(); self::$__cms_model_properties['is_widget_cached'] = true; } $result = array(); foreach (self::$__cms_model_properties['widget'] as $row) { if (isset($slug) && $slug != '') { if ($row->active != 1 || stripos($row->slug === null ? '' : $row->slug, $slug) === false) { continue; } } if (isset($widget_name)) { if (strtolower($row->widget_name) != strtolower($widget_name)) { continue; } } // generate widget content $content = ''; if ($row->is_static == 1) { $content = $row->static_content; if (substr($row->widget_name, 0, 8) != 'section_' && $content != '' && $this->cms_editing_mode() && $this->cms_allow_navigate('main_widget_management')) { $content = '<div class="row" style="padding-top:10px; padding-bottom:10px;"><a class="btn btn-primary pull-right" href="{{ SITE_URL }}main/widget/edit/' . $row->widget_id . '">' . '<i class="glyphicon glyphicon-pencil"></i>' . '</a></div>' . $content; } } else { // url $url = $row->url; // content if ($slug) { $content .= '<div id="__cms_widget_' . $row->widget_id . '">'; } else { $content .= '<span id="__cms_widget_' . $row->widget_id . '" style="padding:0px; margin:0px;">'; } if (strpos(strtoupper($url), 'HTTP://') !== false || strpos(strtoupper($url), 'HTTPS://') !== false) { $response = null; // use CURL if (in_array('curl', get_loaded_extensions())) { $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, ''); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = @curl_exec($ch); curl_close($ch); } // use file get content if (!isset($response)) { $response = @file_get_contents($url); } // add the content if (isset($response)) { $response = preg_replace('#(href|src|action)="([^:"]*)(?:")#', '$1="' . $url . '/$2"', $response); $content .= $response; } } else { $url = trim_slashes($url); $url_segment = explode('/', $url); $module_path = $url_segment[0]; $response = ''; // ensure self::$__cms_model_properties['module_name'] exists. This variable's keys are all available module path $this->cms_module_name(); if ($module_path == 'main' || array_key_exists($module_path, self::$__cms_model_properties['module_name']) && self::$__cms_model_properties['module_name'][$module_path] != '') { $_REQUEST['__cms_dynamic_widget'] = 'TRUE'; $_REQUEST['__cms_dynamic_widget_module'] = $module_path; $url = trim($url, '/'); $response = @Modules::run($url); if (strlen($response) == 0) { $response = @Modules::run($url . '/index'); } unset($_REQUEST['__cms_dynamic_widget']); unset($_REQUEST['__cms_dynamic_widget_module']); } // fallback, Modules::run failed, use AJAX instead if (strlen($response) == 0) { $response = '<script type="text/javascript">'; $response .= '$(document).ready(function(){$("#__cms_widget_' . $row->widget_id . '").load("' . site_url($url) . '?__cms_dynamic_widget=TRUE");});'; $response .= '</script>'; } $content .= $response; } if ($slug) { $content .= '</div>'; } else { $content .= '</span>'; } } // make widget based on slug $slugs = explode(',', $row->slug); foreach ($slugs as $single_slug) { $single_slug = trim($single_slug); if (!isset($result[$single_slug])) { $result[$single_slug] = array(); } $result[$single_slug][] = array('widget_id' => $row->widget_id, 'widget_name' => $row->widget_name, 'title' => $this->cms_lang($row->title), 'description' => $row->description, 'content' => $this->cms_parse_keyword($content)); } } return $result; }
/** * Force the request to be redirected to HTTPS, or optionally show 404. * A strong security policy does not allow for redirection. */ protected function force_ssl() { // Force SSL if available if (USE_SSL !== 0 && $this->protocol == 'http') { // Allow redirect to the HTTPS page if (REDIRECT_TO_HTTPS !== 0) { // Load string helper for trim_slashes function $this->load->helper('string'); // 301 Redirect to the secure page header("Location: " . secure_site_url(trim_slashes($this->uri->uri_string())), TRUE, 301); } else { show_404(); } exit; } }
/** * @author goFrendiAsgard * @param slug * @param widget_name * @return mixed * @desc return widgets */ public function cms_widgets($slug = NULL, $widget_name = NULL) { $user_name = $this->cms_user_name(); $user_id = $this->cms_user_id(); $user_id = !isset($user_id) || is_null($user_id) ? 0 : $user_id; $not_login = !$user_name ? "TRUE" : "FALSE"; $login = $user_name ? "TRUE" : "FALSE"; $super_user = $user_id == 1 ? "TRUE" : "FALSE"; $slug_where = isset($slug) ? "(((slug LIKE '" . addslashes($slug) . "') OR (slug LIKE '%" . addslashes($slug) . "%')) AND active=1)" : "1=1"; $widget_name_where = isset($widget_name) ? "widget_name LIKE '" . addslashes($widget_name) . "'" : "1=1"; $SQL = "SELECT\n widget_id, widget_name, is_static, title,\n description, url, slug, static_content\n FROM " . cms_table_name('main_widget') . " AS w WHERE\n (\n (authorization_id = 1) OR\n (authorization_id = 2 AND {$not_login}) OR\n (authorization_id = 3 AND {$login}) OR\n (\n (authorization_id = 4 AND {$login}) AND\n (\n (SELECT COUNT(*) FROM " . cms_table_name('main_group_user') . " AS gu WHERE gu.group_id=1 AND gu.user_id ='" . addslashes($user_id) . "')>0\n OR {$super_user} OR\n (SELECT COUNT(*) FROM " . cms_table_name('main_group_widget') . " AS gw\n WHERE\n gw.widget_id=w.widget_id AND\n gw.group_id IN\n (SELECT group_id FROM " . cms_table_name('main_group_user') . " WHERE user_id = " . addslashes($user_id) . ")\n )>0\n )\n )\n ) AND {$slug_where} AND {$widget_name_where} ORDER BY " . $this->db->protect_identifiers('index'); $query = $this->db->query($SQL); $result = array(); foreach ($query->result() as $row) { // generate widget content $content = ''; if ($row->is_static == 1) { $content = $row->static_content; } else { // url $url = $row->url; // content if ($slug) { $content .= '<div id="_cms_widget_' . $row->widget_id . '">'; } else { $content .= '<span id="_cms_widget_' . $row->widget_id . '">'; } if (strpos(strtoupper($url), 'HTTP://') !== FALSE || strpos(strtoupper($url), 'HTTPS://') !== FALSE) { $response = NULL; // use CURL if (in_array('curl', get_loaded_extensions())) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = @curl_exec($ch); curl_close($ch); } // use file get content if (!isset($response)) { $response = @file_get_contents($url); } // add the content if (isset($response)) { $response = preg_replace('#(href|src|action)="([^:"]*)(?:")#', '$1="' . $url . '/$2"', $response); $content .= $response; } } else { // TODO: something wrong with this $url = trim_slashes($url); $url_partial = explode('/', $url); $this->cms_ci_session('cms_dynamic_widget', TRUE); $response = @Modules::run($url); if (strlen($response) == 0) { $response = @Modules::run($url . '/index'); } $content .= $response; $this->cms_unset_ci_session('cms_dynamic_widget'); } if ($slug) { $content .= '</div>'; } else { $content .= '</span>'; } } // make widget based on slug $slugs = explode(',', $row->slug); foreach ($slugs as $slug) { $slug = trim($slug); if (!isset($result[$slug])) { $result[$slug] = array(); } $result[$slug][] = array("widget_id" => $row->widget_id, "widget_name" => $row->widget_name, "title" => $this->cms_lang($row->title), "description" => $row->description, "content" => $this->cms_parse_keyword($content)); } } return $result; }
public function process_image() { $raw_str = trim_slashes($this->input->post("image")); $raw_arr = explode("/", $raw_str); $filename = end($raw_arr); return $filename; }
/** * @param dir string absolute path to cache directory (must be writable by web server, include trailing slash) */ public function set_cache_dir($dir) { $this->dir = '/' . trim_slashes($dir) . '/'; }
/** * Build the pagination out, storing it in the Pagination_object * * @param integer $count Number of rows we're paginating over * @param object $query Query object of the post you're field paginating over */ function build($count = 0, &$main_query = '', $query = '') { if (is_object($query)) { $row = $query->row_array(); } else { $row = ''; } // ------------------------------------------- // 'channel_module_create_pagination' hook. // - Rewrite the pagination function in the Channel module // - Could be used to expand the kind of pagination available // - Paginate via field length, for example // if ($this->EE->extensions->active_hook('channel_module_create_pagination') === TRUE) { $edata = $this->EE->extensions->universal_call('channel_module_create_pagination', $this, $count); if ($this->EE->extensions->end_script === TRUE) { return; } } // // ------------------------------------------- // Check again to see if we need to paginate if ($this->paginate == TRUE) { // If template_group and template are being specified in the // index.php and there's no other URI string, specify the basepath if (($this->EE->uri->uri_string == '' or $this->EE->uri->uri_string == '/') && $this->EE->config->item('template_group') != '' && $this->EE->config->item('template') != '') { $this->basepath = $this->EE->functions->create_url($this->EE->config->slash_item('template_group') . '/' . $this->EE->config->item('template')); } // If basepath is still nothing, create the url from the uri_string if ($this->basepath == '') { $this->basepath = $this->EE->functions->create_url($this->EE->uri->uri_string); $query_string = $this->EE->uri->page_query_string != '' ? $this->EE->uri->page_query_string : $this->EE->uri->query_string; if (preg_match("#^P(\\d+)|/P(\\d+)#", $query_string, $match)) { $this->offset = isset($match[2]) ? $match[2] : $match[1]; $this->basepath = $this->EE->functions->remove_double_slashes(str_replace($match[0], '', $this->basepath)); } } // Standard pagination, not field_pagination if ($this->field_pagination == FALSE) { // If we're not displaying by something, then we'll need // something to paginate, otherwise if we're displaying by // something (week, day) it's okay for it to be empty if ($this->type === "Channel" and $this->EE->TMPL->fetch_param('display_by') == '') { // If we're doing standard pagination and not using // display_by, clear out the query and get out of here if ($count == 0) { $main_query = ''; return; } $this->total_rows = $count; } // We need to establish the per_page limits if we're using // cached SQL because limits are normally created when building // the SQL query if ($this->dynamic_sql == FALSE) { // Check to see if we can actually deal with cat_limit. Has // to have dynamic != 'no' and channel set with a category // in the uri_string somewhere $cat_limit = FALSE; if ((in_array($this->EE->config->item("reserved_category_word"), explode("/", $this->EE->uri->uri_string)) or preg_match("#(^|\\/)C(\\d+)#", $this->EE->uri->uri_string, $match)) and $this->EE->TMPL->fetch_param('dynamic') != 'no' and $this->EE->TMPL->fetch_param('channel')) { $cat_limit = TRUE; } if ($cat_limit and is_numeric($this->EE->TMPL->fetch_param('cat_limit'))) { $this->per_page = $this->EE->TMPL->fetch_param('cat_limit'); } else { $this->per_page = !is_numeric($this->EE->TMPL->fetch_param('limit')) ? '100' : $this->EE->TMPL->fetch_param('limit'); } } $this->offset = ($this->offset == '' or $this->per_page > 1 and $this->offset == 1) ? 0 : $this->offset; // If we're far beyond where we should be, reset us back to // the first page if ($this->offset > $this->total_rows) { $this->offset = 0; } $this->current_page = floor($this->offset / $this->per_page + 1); $this->total_pages = intval(floor($this->total_rows / $this->per_page)); } else { // Field pagination - base values // If we're doing field pagination and there's not even one // entry, then clear out the sql and get out of here if ($count == 0) { $main_query = ''; return; } $m_fields = array(); foreach ($this->multi_fields as $val) { foreach ($this->cfields as $site_id => $cfields) { if (isset($cfields[$val])) { if (isset($row['field_id_' . $cfields[$val]]) and $row['field_id_' . $cfields[$val]] != '') { $m_fields[] = $val; } } } } $this->per_page = 1; $this->total_rows = count($m_fields); $this->total_pages = $this->total_rows; if ($this->total_pages == 0) { $this->total_pages = 1; } $this->offset = $this->offset == '' ? 0 : $this->offset; if ($this->offset > $this->total_rows) { $this->offset = 0; } $this->current_page = floor($this->offset / $this->per_page + 1); if (isset($m_fields[$this->offset])) { $this->EE->TMPL->tagdata = preg_replace("/" . LD . "multi_field\\=[\"'].+?[\"']" . RD . "/s", LD . $m_fields[$this->offset] . RD, $this->EE->TMPL->tagdata); $this->EE->TMPL->var_single[$m_fields[$this->offset]] = $m_fields[$this->offset]; } } // Create the pagination if ($this->total_rows > 0 && $this->per_page > 0) { if ($this->total_rows % $this->per_page) { $this->total_pages++; } } // Last check to make sure we actually need to paginate if ($this->total_rows > $this->per_page) { if (strpos($this->basepath, SELF) === FALSE && $this->EE->config->item('site_index') != '') { $this->basepath .= SELF; } // Check to see if a paginate_base was provided if ($this->EE->TMPL->fetch_param('paginate_base')) { $this->EE->load->helper('string'); $this->basepath = $this->EE->functions->create_url(trim_slashes($this->EE->TMPL->fetch_param('paginate_base'))); } $config['first_url'] = rtrim($this->basepath, '/'); $config['base_url'] = $this->basepath; $config['prefix'] = 'P'; $config['total_rows'] = $this->total_rows; $config['per_page'] = $this->per_page; // cur_page uses the offset because P45 (or similar) is a page $config['cur_page'] = $this->offset; $config['first_link'] = lang('pag_first_link'); $config['last_link'] = lang('pag_last_link'); $config['uri_segment'] = 0; // Allows $config['cur_page'] to override $this->EE->pagination->initialize($config); $this->page_links = $this->EE->pagination->create_links(); $this->EE->pagination->initialize($config); // Re-initialize to reset config $this->page_array = $this->EE->pagination->create_link_array(); // If a page_next should exist, create it if ($this->total_pages * $this->per_page - $this->per_page > $this->offset) { $this->page_next = reduce_double_slashes($this->basepath . '/P' . ($this->offset + $this->per_page)); } // If a page_previous should exist, create it if ($this->offset - $this->per_page >= 0) { $this->page_previous = reduce_double_slashes($this->basepath . '/P' . ($this->offset - $this->per_page)); } } else { $this->offset = 0; } } }
/** * Constructor */ public function Stats() { $this->EE =& get_instance(); $this->EE->stats->load_stats(); // Limit stats by channel // You can limit the stats by any combination of channels if ($channel_name = $this->EE->TMPL->fetch_param('channel')) { $sql = "SELECT\ttotal_entries, \n\t\t\t\t\t\t\ttotal_comments,\n\t\t\t\t\t\t\tlast_entry_date,\n\t\t\t\t\t\t\tlast_comment_date\n\t\t\t\t\tFROM exp_channels \n\t\t\t\t\tWHERE site_id IN ('" . implode("','", $this->EE->TMPL->site_ids) . "') "; $sql .= $this->EE->functions->sql_andor_string($channel_name, 'exp_channels.channel_name'); $cache_sql = md5($sql); if (!isset($this->EE->stats->stats_cache[$cache_sql])) { $query = $this->EE->db->query($sql); $sdata = array('total_entries' => 0, 'total_comments' => 0, 'last_entry_date' => 0, 'last_comment_date' => 0); if ($query->num_rows() > 0) { foreach ($query->result_array() as $row) { foreach ($sdata as $key => $val) { if (substr($key, 0, 5) == 'last_') { if ($row[$key] > $val) { $sdata[$key] = $row[$key]; } } else { $sdata[$key] = $sdata[$key] + $row[$key]; } } } foreach ($sdata as $key => $val) { $this->EE->stats->set_statdata($key, $val); $this->EE->stats->stats_cache[$cache_sql][$key] = $val; } } } else { foreach ($this->EE->stats->stats_cache[$cache_sql] as $key => $val) { $this->EE->stats->set_statdata($key, $val); } } } // Parse stat fields $fields = array('total_members', 'total_entries', 'total_forum_topics', 'total_forum_replies', 'total_forum_posts', 'total_comments', 'most_visitors', 'total_logged_in', 'total_guests', 'total_anon'); $cond = array(); foreach ($fields as $field) { if (isset($this->EE->TMPL->var_single[$field])) { $cond[$field] = $this->EE->stats->statdata($field); $this->EE->TMPL->tagdata = $this->EE->TMPL->swap_var_single($field, $this->EE->stats->statdata($field), $this->EE->TMPL->tagdata); } } if (count($cond) > 0) { $this->EE->TMPL->tagdata = $this->EE->functions->prep_conditionals($this->EE->TMPL->tagdata, $cond); } // Parse dates $dates = array('last_entry_date', 'last_forum_post_date', 'last_comment_date', 'last_visitor_date', 'most_visitor_date'); foreach ($this->EE->TMPL->var_single as $key => $val) { foreach ($dates as $date) { if (strncmp($key, $date, strlen($date)) == 0) { $this->EE->TMPL->tagdata = $this->EE->TMPL->swap_var_single($key, (!$this->EE->stats->statdata($date) or $this->EE->stats->statdata($date) == 0) ? '--' : $this->EE->localize->decode_date($val, $this->EE->stats->statdata($date)), $this->EE->TMPL->tagdata); } } } // Online user list $names = ''; if ($this->EE->stats->statdata('current_names')) { $chunk = $this->EE->TMPL->fetch_data_between_var_pairs($this->EE->TMPL->tagdata, 'member_names'); $backspace = ''; if (!preg_match("/" . LD . "member_names.*?backspace=[\"|'](.+?)[\"|']/", $this->EE->TMPL->tagdata, $match)) { if (preg_match("/" . LD . "name.*?backspace=[\"|'](.+?)[\"|']/", $this->EE->TMPL->tagdata, $match)) { $backspace = $match['1']; } } else { $backspace = $match['1']; } // Load the string helper $this->EE->load->helper('string'); $member_path = preg_match("/" . LD . "member_path=(.+?)" . RD . "/", $this->EE->TMPL->tagdata, $match) ? $match['1'] : ''; $member_path = str_replace("\"", "", $member_path); $member_path = str_replace("'", "", $member_path); $member_path = trim_slashes($member_path); foreach ($this->EE->stats->statdata('current_names') as $k => $v) { $temp = $chunk; if ($v['1'] == 'y') { if ($this->EE->session->userdata('group_id') == 1) { $temp = preg_replace("/" . LD . "name.*?" . RD . "/", $v['0'] . '*', $temp); } elseif ($this->EE->session->userdata('member_id') == $k) { $temp = preg_replace("/" . LD . "name.*?" . RD . "/", $v['0'] . '*', $temp); } else { continue; } } else { $temp = preg_replace("/" . LD . "name.*?" . RD . "/", $v['0'], $temp); } $path = $this->EE->functions->create_url($member_path . '/' . $k); $temp = preg_replace("/" . LD . "member_path=(.+?)" . RD . "/", $path, $temp); $names .= $temp; } if (is_numeric($backspace)) { $names = substr(trim($names), 0, -$backspace); } } $names = str_replace(LD . 'name' . RD, '', $names); $this->EE->TMPL->tagdata = preg_replace("/" . LD . 'member_names' . ".*?" . RD . "(.*?)" . LD . '\\/' . 'member_names' . RD . "/s", $names, $this->EE->TMPL->tagdata); // {if member_names} if ($names != '') { $this->EE->TMPL->tagdata = preg_replace("/" . LD . 'if member_names' . ".*?" . RD . "(.*?)" . LD . '\\/' . 'if' . RD . "/s", "\\1", $this->EE->TMPL->tagdata); } else { $this->EE->TMPL->tagdata = preg_replace("/" . LD . 'if member_names' . ".*?" . RD . "(.*?)" . LD . '\\/' . 'if' . RD . "/s", "", $this->EE->TMPL->tagdata); } $this->return_data = $this->EE->TMPL->tagdata; }
/** * @author goFrendiAsgard * @param slug * @param widget_name * @return mixed * @desc return widgets */ public function cms_widgets($slug = NULL, $widget_name = NULL) { // get user_name, user_id, etc $user_name = $this->cms_user_name(); $user_id = $this->cms_user_id(); $user_id = $user_id == '' ? 0 : $user_id; $not_login = !$user_name ? "(1=1)" : "(1=2)"; $login = $user_name ? "(1=1)" : "(1=2)"; $super_user = $user_id == 1 || in_array(1, $this->cms_user_group_id()) ? "(1=1)" : "(1=2)"; $slug_where = isset($slug) ? "(((slug LIKE '" . addslashes($slug) . "') OR (slug LIKE '%" . addslashes($slug) . "%')) AND active=1)" : "1=1"; $widget_name_where = isset($widget_name) ? "widget_name LIKE '" . addslashes($widget_name) . "'" : "1=1"; $SQL = "SELECT\n widget_id, widget_name, is_static, title,\n description, url, slug, static_content\n FROM " . cms_table_name('main_widget') . " AS w WHERE\n (\n (authorization_id = 1) OR\n (authorization_id = 2 AND {$not_login}) OR\n (authorization_id = 3 AND {$login}) OR\n (\n (authorization_id = 4 AND {$login}) AND\n (\n (SELECT COUNT(*) FROM " . cms_table_name('main_group_user') . " AS gu WHERE gu.group_id=1 AND gu.user_id ='" . addslashes($user_id) . "')>0\n OR {$super_user} OR\n (SELECT COUNT(*) FROM " . cms_table_name('main_group_widget') . " AS gw\n WHERE\n gw.widget_id=w.widget_id AND\n gw.group_id IN\n (SELECT group_id FROM " . cms_table_name('main_group_user') . " WHERE user_id = " . addslashes($user_id) . ")\n )>0\n )\n ) OR\n (\n (authorization_id = 5 AND {$login}) AND\n (\n (SELECT COUNT(*) FROM " . cms_table_name('main_group_widget') . " AS gw\n WHERE\n gw.widget_id=w.widget_id AND\n gw.group_id IN\n (SELECT group_id FROM " . cms_table_name('main_group_user') . " WHERE user_id = " . addslashes($user_id) . ")\n )>0\n )\n )\n ) AND {$slug_where} AND {$widget_name_where} ORDER BY " . $this->db->protect_identifiers('index'); $query = $this->db->query($SQL); $result = array(); foreach ($query->result() as $row) { // generate widget content $content = ''; if ($row->is_static == 1) { $content = $row->static_content; } else { // url $url = $row->url; // content if ($slug) { $content .= '<div id="__cms_widget_' . $row->widget_id . '">'; } else { $content .= '<span id="__cms_widget_' . $row->widget_id . '" style="padding:0px; margin:0px;">'; } if (strpos(strtoupper($url), 'HTTP://') !== FALSE || strpos(strtoupper($url), 'HTTPS://') !== FALSE) { $response = NULL; // use CURL if (in_array('curl', get_loaded_extensions())) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = @curl_exec($ch); curl_close($ch); } // use file get content if (!isset($response)) { $response = @file_get_contents($url); } // add the content if (isset($response)) { $response = preg_replace('#(href|src|action)="([^:"]*)(?:")#', '$1="' . $url . '/$2"', $response); $content .= $response; } } else { $url = trim_slashes($url); $url_segment = explode('/', $url); $module_path = $url_segment[0]; $response = ''; // look if module installed $query = $this->db->select('module_id, module_name')->from(cms_table_name('main_module'))->where('module_path', $module_path)->get(); if ($module_path == 'main' || $query->num_rows() > 0) { $_REQUEST['__cms_dynamic_widget'] = 'TRUE'; $_REQUEST['__cms_dynamic_widget_module'] = $module_path; $response = @Modules::run($url); if (strlen($response) == 0) { $response = @Modules::run($url . '/index'); } unset($_REQUEST['__cms_dynamic_widget']); unset($_REQUEST['__cms_dynamic_widget_module']); } // fallback, Modules::run failed, use AJAX instead if (strlen($response) == 0) { $response = '<script type="text/javascript">'; $response .= '$(document).ready(function(){$("#__cms_widget_' . $row->widget_id . '").load("' . site_url($url) . '?__cms_dynamic_widget=TRUE");});'; $response .= '</script>'; } $content .= $response; } if ($slug) { $content .= '</div>'; } else { $content .= '</span>'; } } // make widget based on slug $slugs = explode(',', $row->slug); foreach ($slugs as $slug) { $slug = trim($slug); if (!isset($result[$slug])) { $result[$slug] = array(); } $result[$slug][] = array("widget_id" => $row->widget_id, "widget_name" => $row->widget_name, "title" => $this->cms_lang($row->title), "description" => $row->description, "content" => $this->cms_parse_keyword($content)); } } return $result; }
/** * Prep the Request String */ public function _prep_request() { // Typcially the profile page URLs will be something like: // // index.php/member/123/ // index.php/member/memberlist/ // index.php/member/profile/ // etc... // // The second segment will be assigned to the $this->request variable. // This determines what page is shown. Anything after that will normally // be an ID number, so we'll assign it to the $this->cur_id variable. $this->request = trim_slashes(ee()->uri->uri_string); if (FALSE !== ($pos = strpos($this->request, $this->trigger . '/'))) { $this->request = substr($this->request, $pos); } if (preg_match("#/simple#", $this->request)) { $this->request = str_replace("/simple", '', $this->request); $this->show_headings = FALSE; } if ($this->request == $this->trigger) { $this->request = ''; } elseif (strpos($this->request, '/') !== FALSE) { $xr = explode("/", $this->request); $this->request = str_replace(current($xr) . '/', '', $this->request); } // Determine the ID number, if any $this->cur_id = ''; if (strpos($this->request, '/') !== FALSE) { $x = explode("/", $this->request); if (count($x) > 2) { $this->request = $x[0]; $this->cur_id = $x[1]; $this->uri_extra = $x[2]; } else { $this->request = $x[0]; $this->cur_id = $x[1]; } } // Is this a public profile request? // Public member profiles are found at: // // index.php/member/123/ // // Since the second segment contains a number instead of the // normal text string we know it's a public profile request. // We'll do a little reassignment... if (is_numeric($this->request)) { $this->cur_id = $this->request; $this->request = 'public_profile'; } if ($this->request == '') { $this->request = 'public_profile'; } // Disable the full page view if (in_array($this->request, $this->simple_page)) { $this->show_headings = FALSE; } if (in_array($this->request, $this->no_breadcrumb)) { $this->breadcrumb = FALSE; } // Validate ID number // The $this->cur_id variable can only contain a number. // There are a few exceptions like the memberlist page and the // subscriptions page if (!in_array($this->request, $this->id_override) && $this->cur_id != '' && !is_numeric($this->cur_id)) { return FALSE; } return TRUE; }
</style> </head> <body> <div id="container"> <h1>Selamat datang di pencarian informasi internal Bank DKI.</h1> <div id="body"> <?php $ambil = array("method" => "get"); echo form_open('welcome/search'); ?> <p>Silahkan mengisi data yang akan dicari:</p> <code align="center"> <input type="text" name="txt_cari" size="100px" value="<?php echo isset($_POST['txt_cari']) ? $_POST['txt_cari'] : trim_slashes(str_replace("-", " ", $this->uri->slash_segment(3, ""))); ?> " autofocus/> <input type="submit" value="Search" /> </code> </form> <p> <?php if (isset($hasil)) { ?> <?php for ($i = 0; $i < count($hasil); $i++) { ?> <b style="font-size:20px"><?php echo $hasil[$i]['judul'];
/** * Force the request to be redirected to HTTPS, or optionally show 404. * A strong security policy does not allow for redirection. */ protected function force_ssl() { // Force SSL if available if (USE_SSL !== 0 && $this->protocol == 'http') { // Allow redirect to the HTTPS page if (config_item('redirect_to_https') !== 0) { // Load string helper for trim_slashes function $this->load->helper('string'); // Load URL helper for the site_url function $this->load->helper('url'); // Set link protocol $link_protocol = USE_SSL ? 'https' : NULL; // 301 Redirect to the secure page header("Location: " . site_url(trim_slashes($this->uri->uri_string()), $link_protocol), TRUE, 301); } else { show_404(); } exit; } }
/** * Build the pagination out, storing it in the Pagination_object * * @param integer $total_items Number of rows we're paginating over * @param integer $per_page Number of items per page * @return Boolean TRUE if successful, FALSE otherwise */ function build($total_items, $per_page) { $this->total_items = $total_items; $this->per_page = $per_page; // ------------------------------------------- // 'channel_module_create_pagination' hook. // - Rewrite the pagination function in the Channel module // - Could be used to expand the kind of pagination available // - Paginate via field length, for example // if (ee()->extensions->active_hook('channel_module_create_pagination') === TRUE) { ee()->load->library('logger'); ee()->logger->deprecated_hook('channel_module_create_pagination', '2.8', 'pagination_create'); ee()->extensions->universal_call('channel_module_create_pagination', $this, $this->total_items); if (ee()->extensions->end_script === TRUE) { return; } } // // ------------------------------------------- // ------------------------------------------- // 'pagination_create' hook. // - Rewrite the pagination function in the Channel module // - Could be used to expand the kind of pagination available // - Paginate via field length, for example // if (ee()->extensions->active_hook('pagination_create') === TRUE) { ee()->extensions->universal_call('pagination_create', $this, $this->total_items); if (ee()->extensions->end_script === TRUE) { return; } } // // ------------------------------------------- // Check again to see if we need to paginate if ($this->paginate == TRUE) { // If template_group and template are being specified in the // index.php and there's no other URI string, specify the basepath if ((ee()->uri->uri_string == '' or ee()->uri->uri_string == '/') && ee()->config->item('template_group') != '' && ee()->config->item('template') != '') { $this->basepath = ee()->functions->create_url(ee()->config->slash_item('template_group') . '/' . ee()->config->item('template')); } // If basepath is still nothing, create the url from the uri_string if ($this->basepath == '') { $this->basepath = ee()->functions->create_url(ee()->uri->uri_string); } // Determine the offset if ($this->offset === 0) { $query_string = ee()->uri->page_query_string != '' ? ee()->uri->page_query_string : ee()->uri->query_string; if (preg_match("#^{$this->prefix}(\\d+)|/{$this->prefix}(\\d+)#", $query_string, $match)) { $this->offset = isset($match[2]) ? (int) $match[2] : (int) $match[1]; $this->basepath = reduce_double_slashes(str_replace($match[0], '', $this->basepath)); } } // Standard pagination, not field_pagination if ($this->field_pagination == FALSE) { // If we're not displaying by something, then we'll need // something to paginate, otherwise if we're displaying by // something (week, day) it's okay for it to be empty if ($this->_type === "Channel" && ee()->TMPL->fetch_param('display_by') == '' && $this->total_items == 0) { return FALSE; } $this->offset = ($this->offset == '' or $this->per_page > 1 and $this->offset == 1) ? 0 : $this->offset; // If we're far beyond where we should be, reset us back to // the first page if ($this->offset > $this->total_items) { return ee()->TMPL->no_results(); } $this->current_page = floor($this->offset / $this->per_page + 1); $this->total_pages = intval(floor($this->total_items / $this->per_page)); } else { // If we're doing field pagination and there's not even one // entry, then clear out the sql and get out of here if ($this->total_items == 0 or !is_object($this->field_pagination_query)) { return FALSE; } $m_fields = array(); $row = $this->field_pagination_query->row_array(); foreach ($this->_multi_fields as $val) { foreach ($this->cfields as $site_id => $cfields) { if (isset($cfields[$val])) { if (isset($row['field_id_' . $cfields[$val]]) and $row['field_id_' . $cfields[$val]] != '') { $m_fields[] = $val; } } } } $this->per_page = 1; $this->total_items = count($m_fields); $this->total_pages = $this->total_items; if ($this->total_pages == 0) { $this->total_pages = 1; } $this->offset = $this->offset == '' ? 0 : $this->offset; if ($this->offset > $this->total_items) { $this->offset = 0; } $this->current_page = floor($this->offset / $this->per_page + 1); if (isset($m_fields[$this->offset])) { ee()->TMPL->tagdata = preg_replace("/" . LD . "multi_field\\=[\"'].+?[\"']" . RD . "/s", LD . $m_fields[$this->offset] . RD, ee()->TMPL->tagdata); ee()->TMPL->var_single[$m_fields[$this->offset]] = $m_fields[$this->offset]; } } // Create the pagination if ($this->total_items > 0 && $this->per_page > 0) { if ($this->total_items % $this->per_page) { $this->total_pages++; } } // Last check to make sure we actually need to paginate if ($this->total_items > $this->per_page) { if (strpos($this->basepath, SELF) === FALSE && ee()->config->item('site_index') != '' && strpos($this->basepath, ee()->config->item('site_index')) === FALSE) { $this->basepath .= SELF; } // Check to see if a paginate_base was provided if (ee()->TMPL->fetch_param('paginate_base')) { $this->basepath = ee()->functions->create_url(trim_slashes(ee()->TMPL->fetch_param('paginate_base'))); } $config = array('first_url' => rtrim($this->basepath, '/'), 'base_url' => $this->basepath, 'prefix' => $this->prefix, 'total_rows' => $this->total_items, 'per_page' => $this->per_page, 'cur_page' => $this->offset, 'num_links' => $this->_page_links_limit, 'first_link' => lang('pag_first_link'), 'last_link' => lang('pag_last_link'), 'uri_segment' => 0); ee()->pagination->initialize($config); $this->_page_links = ee()->pagination->create_links(); ee()->pagination->initialize($config); // Re-initialize to reset config $this->_page_array = ee()->pagination->create_link_array(); // If a page_next should exist, create it if ($this->total_pages * $this->per_page - $this->per_page > $this->offset) { $this->_page_next = reduce_double_slashes($this->basepath . '/P' . ($this->offset + $this->per_page)); } // If a page_previous should exist, create it if ($this->offset - $this->per_page >= 0) { $this->_page_previous = reduce_double_slashes($this->basepath . '/P' . ($this->offset - $this->per_page)); } } else { $this->offset = 0; } } return TRUE; }
public function parse_template($entry_id = FALSE, $field_id = FALSE, $params = array(), $tagdata) { // Variable prefix $this->prefix = isset($params['prefix']) === FALSE ? 'image:' : $params['prefix'] . ':'; // Set a default value of false for the is_draft flag $is_draft = 0; // If we are loading a draft into the publish page update the flag to true if (isset($this->session->cache['ep_better_workflow']['is_draft']) && $this->session->cache['ep_better_workflow']['is_draft']) { $is_draft = 1; } // Params can override this if (isset($params['is_draft']) === TRUE) { if ($params['is_draft'] == 'yes') { $is_draft = 1; } elseif ($params['is_draft'] == 'no') { $is_draft = 0; } } $temp_params = $params; // Lets remove all unwanted params unset($temp_params['entry_id'], $temp_params['url_title']); // Make our hash $hash = crc32(serialize($temp_params)); if (isset($this->session->cache['channel_images']['images'][$hash]) == TRUE) { $images = $this->session->cache['channel_images']['images'][$hash][$entry_id]; } else { $images = $this->get_images($entry_id, $field_id, $params, $tagdata); } // Any Images? if (count($images) === 0) { $this->EE->TMPL->log_item("CHANNEL IMAGES: No images found."); return $this->EE->image_helper->custom_no_results_conditional($this->prefix . 'no_images', $tagdata); } $this->total_images = count($images); $this->absolute_total_images = count($images); $limit = isset($params['limit']) ? $params['limit'] : 30; $paginate = FALSE; $this->image_position = array(); // Loop over all images and store it's position of all images foreach ($images as $pos => $img) { $this->image_position[$img->image_id] = $pos + 1; } //---------------------------------------- // Pagination //---------------------------------------- if (preg_match('/' . LD . "{$this->prefix}paginate(.*?)" . RD . "(.+?)" . LD . '\\/' . "{$this->prefix}paginate" . RD . "/s", $tagdata, $match)) { // Pagination variables $paginate = TRUE; $paginate_data = $match['2']; $current_page = 0; $total_pages = 1; $qstring = $this->EE->uri->query_string; $uristr = $this->EE->uri->uri_string; $pagination_links = ''; $page_previous = ''; $page_next = ''; // We need to strip the page number from the URL for two reasons: // 1. So we can create pagination links // 2. So it won't confuse the query with an improper proper ID if (preg_match("#(^|/)CI(\\d+)(/|\$)#", $qstring, $match)) { $current_page = $match['2']; if (function_exists('reduce_double_slashes')) { $uristr = reduce_double_slashes(str_replace($match['0'], '/', $uristr)); $qstring = trim(reduce_double_slashes(str_replace($match['0'], '/', $qstring)), '/'); } else { $uristr = $this->EE->functions->remove_double_slashes(str_replace($match['0'], '/', $uristr)); $qstring = trim($this->EE->functions->remove_double_slashes(str_replace($match['0'], '/', $qstring)), '/'); } } // Remove the {paginate} $tagdata = preg_replace("/" . LD . "{$this->prefix}paginate.*?" . RD . ".+?" . LD . '\\/' . "{$this->prefix}paginate" . RD . "/s", "", $tagdata); // What is the current page? $current_page = ($current_page == '' or $limit > 1 and $current_page == 1) ? 0 : $current_page; if ($current_page > $this->total_images) { $current_page = 0; } $t_current_page = floor($current_page / $limit + 1); $total_pages = intval(floor($this->total_images / $limit)); if ($this->total_images % $limit) { $total_pages++; } if ($this->total_images > $limit) { $this->EE->load->library('pagination'); $deft_tmpl = ''; if ($uristr == '') { if ($this->EE->config->item('template_group') == '') { $this->EE->db->select('group_name'); $query = $this->EE->db->get_where('template_groups', array('is_site_default' => 'y')); $deft_tmpl = $query->row('group_name') . '/index'; } else { $deft_tmpl = $this->EE->config->item('template_group') . '/'; $deft_tmpl .= $this->EE->config->item('template') == '' ? 'index' : $this->EE->config->item('template'); } } if (function_exists('reduce_double_slashes')) { $basepath = reduce_double_slashes($this->EE->functions->create_url($uristr, FALSE) . '/' . $deft_tmpl); } else { $basepath = $this->EE->functions->remove_double_slashes($this->EE->functions->create_url($uristr, FALSE) . '/' . $deft_tmpl); } if (isset($params['paginate_base']) === TRUE) { // Load the string helper $this->EE->load->helper('string'); $pbase = trim_slashes($params['paginate_base']); $pbase = str_replace("/index", "/", $pbase); if (!strstr($basepath, $pbase)) { if (function_exists('reduce_double_slashes')) { $basepath = reduce_double_slashes($basepath . '/' . $pbase); } else { $basepath = $this->EE->functions->remove_double_slashes($basepath . '/' . $pbase); } } } // Load Language $this->EE->lang->loadfile('channel_images'); $config['first_url'] = rtrim($basepath, '/'); $config['base_url'] = $basepath; $config['prefix'] = 'CI'; $config['total_rows'] = $this->total_images; $config['per_page'] = $limit; $config['cur_page'] = $current_page; $config['suffix'] = ''; $config['first_link'] = $this->EE->lang->line('ci:pag_first_link'); $config['last_link'] = $this->EE->lang->line('ci:pag_last_link'); $config['full_tag_open'] = '<span class="ci_paginate_links">'; $config['full_tag_close'] = '</span>'; $config['first_tag_open'] = '<span class="ci_paginate_first">'; $config['first_tag_close'] = '</span> '; $config['last_tag_open'] = ' <span class="ci_paginate_last">'; $config['last_tag_close'] = '</span>'; $config['cur_tag_open'] = ' <strong class="ci_paginate_current">'; $config['cur_tag_close'] = '</strong>'; $config['next_tag_open'] = ' <span class="ci_paginate_next">'; $config['next_tag_close'] = '</span>'; $config['prev_tag_open'] = ' <span class="ci_paginate_prev">'; $config['prev_tag_close'] = '</span>'; $config['num_tag_open'] = ' <span class="ci_paginate_num">'; $config['num_tag_close'] = '</span>'; // Allows $config['cur_page'] to override $config['uri_segment'] = 0; $this->EE->pagination->initialize($config); $pagination_links = $this->EE->pagination->create_links(); if ($total_pages * $limit - $limit > $current_page) { $page_next = $basepath . $config['prefix'] . ($current_page + $limit) . '/'; } if ($current_page - $limit >= 0) { $page_previous = $basepath . $config['prefix'] . ($current_page - $limit) . '/'; } } else { $current_page = 0; } $images = array_slice($images, $current_page, $limit); $this->total_images = count($images); } //---------------------------------------- // Check for filesize (only for Local) Since it's an expensive operation //---------------------------------------- $this->parse_filesize = FALSE; if (strpos($tagdata, LD . $this->prefix . 'filesize') !== FALSE) { $this->parse_filesize = TRUE; } //---------------------------------------- // Check for image_dimensions (only for Local) Since it's an expensive operation //---------------------------------------- $this->parse_dimensions = FALSE; if (strpos($tagdata, LD . $this->prefix . 'width') !== FALSE or strpos($tagdata, LD . $this->prefix . 'height') !== FALSE) { $this->parse_dimensions = TRUE; } //---------------------------------------- // Switch="" //---------------------------------------- $this->parse_switch = FALSE; $this->switch_matches = array(); if (preg_match_all("/" . LD . "({$this->prefix}switch\\s*=.+?)" . RD . "/is", $tagdata, $this->switch_matches) > 0) { $this->parse_switch = TRUE; // Loop over all matches foreach ($this->switch_matches[0] as $key => $match) { $this->switch_vars[$key] = $this->EE->functions->assign_parameters($this->switch_matches[1][$key]); $this->switch_vars[$key]['original'] = $this->switch_matches[0][$key]; } } // Encode HTML Entities $this->encode_html = FALSE; if (isset($params['encode_html_entities']) === TRUE && $params['encode_html_entities'] == 'yes') { $this->encode_html = TRUE; } // Decode HTML Entities $this->decode_html = FALSE; if (isset($params['decode_html_entities']) === TRUE && $params['decode_html_entities'] == 'yes') { $this->decode_html = TRUE; } //---------------------------------------- // Locked URL? //---------------------------------------- $this->locked_url = FALSE; if (strpos($tagdata, $this->prefix . 'locked_url') !== FALSE) { $this->locked_url = TRUE; // IP $this->IP = $this->EE->input->ip_address(); // Grab Router URL $this->locked_act_url = $this->EE->image_helper->get_router_url('url', 'locked_image_url'); } //---------------------------------------- // IPTC? //---------------------------------------- $this->parse_iptc = FALSE; if (strpos($tagdata, $this->prefix . 'iptc') !== FALSE) { $this->parse_iptc = TRUE; } //---------------------------------------- // EXIF //---------------------------------------- $this->parse_exif = FALSE; if (strpos($tagdata, $this->prefix . 'exif') !== FALSE) { $this->parse_exif = TRUE; } //---------------------------------------- // XMP //---------------------------------------- $this->parse_xmp = FALSE; if (strpos($tagdata, $this->prefix . 'xmp') !== FALSE) { $this->parse_xmp = TRUE; } // SSL? $this->IS_SSL = $this->EE->image_helper->is_ssl(); //---------------------------------------- // Performance :) //---------------------------------------- if (isset($this->session->cache['channel_images']['locations']) == FALSE) { $this->session->cache['channel_images']['locations'] = array(); } $this->LOCS =& $this->session->cache['channel_images']['locations']; // Another Check, just to be sure if (is_array($this->LOCS) == FALSE) { $this->LOCS = array(); } $OUT = ''; //---------------------------------------- // Loop over all Images //---------------------------------------- foreach ($images as $count => $image) { $OUT .= $this->parse_single_image_row($count, $image, $tagdata); } //---------------------------------------- // Add pagination to result //---------------------------------------- if ($paginate == TRUE) { $paginate_data = str_replace(LD . $this->prefix . 'current_page' . RD, $t_current_page, $paginate_data); $paginate_data = str_replace(LD . $this->prefix . 'total_pages' . RD, $total_pages, $paginate_data); $paginate_data = str_replace(LD . $this->prefix . 'pagination_links' . RD, $pagination_links, $paginate_data); if (preg_match("/" . LD . "if {$this->prefix}previous_page" . RD . "(.+?)" . LD . '\\/' . "if" . RD . "/s", $paginate_data, $match)) { if ($page_previous == '') { $paginate_data = preg_replace("/" . LD . "if {$this->prefix}previous_page" . RD . ".+?" . LD . '\\/' . "if" . RD . "/s", '', $paginate_data); } else { $match['1'] = str_replace(array(LD . "{$this->prefix}path" . RD, LD . "{$this->prefix}auto_path" . RD), $page_previous, $match['1']); $paginate_data = str_replace($match['0'], $match['1'], $paginate_data); } } if (preg_match("/" . LD . "if {$this->prefix}next_page" . RD . "(.+?)" . LD . '\\/' . "if" . RD . "/s", $paginate_data, $match)) { if ($page_next == '') { $paginate_data = preg_replace("/" . LD . "if {$this->prefix}next_page" . RD . ".+?" . LD . '\\/' . "if" . RD . "/s", '', $paginate_data); } else { $match['1'] = str_replace(array(LD . "{$this->prefix}path" . RD, LD . "{$this->prefix}auto_path" . RD), $page_next, $match['1']); $paginate_data = str_replace($match['0'], $match['1'], $paginate_data); } } $position = isset($params['paginate']) === TRUE ? $params['paginate'] : ''; switch ($position) { case "top": $OUT = $paginate_data . $OUT; break; case "both": $OUT = $paginate_data . $OUT . $paginate_data; break; default: $OUT .= $paginate_data; break; } } // Apply Backspace $backspace = isset($params['backspace']) === TRUE ? $params['backspace'] : 0; $OUT = $backspace > 0 ? substr($OUT, 0, -$backspace) : $OUT; return $OUT; }
/** * Preview Handler * * @access public * @return void */ function preview_handler() { if (ee()->input->post('PRV') == '') { $error[] = ee()->lang->line('cmt_no_preview_template_specified'); return ee()->output->show_user_error('general', $error); } if (!isset($_POST['PRV']) or $_POST['PRV'] == '') { exit('Preview template not specified in your comment form tag'); } // Clean return value- segments only $clean_return = str_replace(ee()->functions->fetch_site_index(), '', $_POST['RET']); $_POST['PRV'] = trim_slashes(ee()->security->xss_clean($_POST['PRV'])); ee()->functions->clear_caching('all', $_POST['PRV']); ee()->functions->clear_caching('all', $clean_return); require APPPATH . 'libraries/Template.php'; ee()->TMPL = new EE_Template(); $preview = !ee()->input->post('PRV') ? '' : ee()->input->get_post('PRV'); if (strpos($preview, '/') === FALSE) { $preview = ''; } else { $ex = explode("/", $preview); if (count($ex) != 2) { $preview = ''; } } $group = ($preview = '') ? 'channel' : $ex[0]; $templ = ($preview = '') ? 'preview' : $ex[1]; // this makes sure the query string is seen correctly by tags on the template ee()->TMPL->parse_template_uri(); ee()->TMPL->run_template_engine($group, $templ); }
/** * _entry_id * * @access public * @param string type * @return bool id type found and set to $this->$type */ public function _entry_id($type = 'entry_id') { if ($this->{$type} != '') { return TRUE; } $cat_segment = ee()->config->item("reserved_category_word"); // -------------------------------------- // Set Via Parameter // -------------------------------------- if ($this->_numeric(trim(ee()->TMPL->fetch_param($type))) === TRUE) { $this->{$type} = trim(ee()->TMPL->fetch_param($type)); return TRUE; } // -------------------------------------- // Set Via the url_title parameter // -------------------------------------- if (ee()->TMPL->fetch_param('url_title') != '') { $sql = "SELECT \t{$this->sc->db->channel_titles}.entry_id\r\n\t\t\t\t\t FROM \t{$this->sc->db->channel_titles}, {$this->sc->db->channels}\r\n\t\t\t\t\t WHERE \t{$this->sc->db->channel_titles}.{$this->sc->db->channel_id} = " . "{$this->sc->db->channels}.{$this->sc->db->channel_id}\r\n\t\t\t\t\t AND \t{$this->sc->db->channel_titles}.url_title = '" . ee()->db->escape_str(ee()->TMPL->fetch_param('url_title')) . "'\r\n\t\t\t\t\t AND\t \t{$this->sc->db->channels}.site_id \r\n\t\t\t\t\t IN \t\t('" . implode("','", ee()->db->escape_str(ee()->TMPL->site_ids)) . "') "; if (ee()->TMPL->fetch_param($this->sc->channel) !== FALSE) { $sql .= ee()->functions->sql_andor_string(ee()->TMPL->fetch_param($this->sc->channel), $this->sc->db->channel_name, $this->sc->db->channels); } $query = ee()->db->query($sql); if ($query->num_rows() > 0) { $this->entry_id = $query->row('entry_id'); return TRUE; } } // -------------------------------------- // Found in the URI // -------------------------------------- $qstring = ee()->uri->page_query_string != '' ? ee()->uri->page_query_string : ee()->uri->query_string; $dynamic = !$this->check_no(ee()->TMPL->fetch_param('dynamic')); // ------------------------------------------- // Do we have a pure ID number? // ------------------------------------------- if ($this->_numeric($qstring) === TRUE) { $this->{$type} = $qstring; return TRUE; } elseif ($dynamic === TRUE) { // -------------------------------------- // Remove day // -------------------------------------- if (preg_match("#\\d{4}/\\d{2}/(\\d{2})#", $qstring, $match)) { $partial = substr($match['0'], 0, -3); $qstring = trim_slashes(str_replace($match['0'], $partial, $qstring)); } // -------------------------------------- // Remove /year/month/ // -------------------------------------- // added (^|\/) to make sure this doesn't trigger with url titles like big_party_2006 if (preg_match("#(^|\\/)(\\d{4}/\\d{2})#", $qstring, $match)) { $qstring = trim_slashes(str_replace($match['2'], '', $qstring)); } // -------------------------------------- // Remove ID indicator // -------------------------------------- if (preg_match("#^(\\d+)(.*)#", $qstring, $match)) { $seg = !isset($match['2']) ? '' : $match['2']; if (substr($seg, 0, 1) == "/" or $seg == '') { $this->entry_id = $match['1']; return TRUE; } } // -------------------------------------- // Remove page number // -------------------------------------- if (preg_match("#^P(\\d+)|/P(\\d+)#", $qstring, $match) and $dynamic) { $qstring = trim_slashes(str_replace($match['0'], '', $qstring)); } // -------------------------------------- // Parse category indicator // -------------------------------------- // Text version of the category if ($qstring != '' and $this->reserved_cat_segment != '' and in_array($this->reserved_cat_segment, explode("/", $qstring)) and ee()->TMPL->fetch_param($this->sc->channel)) { $qstring = preg_replace("/(.*?)" . preg_quote($this->reserved_cat_segment) . "\\//i", '', $qstring); } // Numeric version of the category if (preg_match("#(^|\\/)C(\\d+)#", $qstring, $match)) { $qstring = trim_slashes(str_replace($match['0'], '', $qstring)); } // -------------------------------------- // Remove "N" // -------------------------------------- // The recent comments feature uses "N" as the URL indicator // It needs to be removed if present if (preg_match("#^N(\\d+)|/N(\\d+)#", $qstring, $match)) { $qstring = trim_slashes(str_replace($match['0'], '', $qstring)); } // ---------------------------------------- // Remove 'delete' and 'private' // ---------------------------------------- $qstring = trim_slashes(str_replace(array('delete', 'private'), array('', ''), $qstring)); // ---------------------------------------- // Try numeric id again // ---------------------------------------- if (preg_match("/^(\\d+)\$/", $qstring, $match)) { $this->{$type} = $match['1']; return TRUE; } // ---------------------------------------- // Parse URL title or username // ---------------------------------------- if ($type == 'member_id') { // ---------------------------------------- // Parse username // ---------------------------------------- if (strstr($qstring, '/')) { $xe = explode('/', $qstring); $qstring = current($xe); } $sql = "SELECT \tmember_id \r\n\t\t\t\t\t\t FROM \texp_members \r\n\t\t\t\t\t\t WHERE \tusername = '******'"; $query = ee()->db->query($sql); if ($query->num_rows() > 0) { $this->member_id = $query->row('member_id'); return TRUE; } } else { // ---------------------------------------- // Parse URL title // ---------------------------------------- if (strstr($qstring, '/')) { $xe = explode('/', $qstring); $qstring = current($xe); } $sql = "SELECT \t{$this->sc->db->channel_titles}.entry_id\r\n\t\t\t\t\t\t FROM \t{$this->sc->db->channel_titles}, {$this->sc->db->channels}\r\n\t\t\t\t\t\t WHERE \t{$this->sc->db->channel_titles}.{$this->sc->db->channel_id} = " . "{$this->sc->db->channels}.{$this->sc->db->channel_id}\r\n\t\t\t\t\t\t AND \t{$this->sc->db->channel_titles}.url_title = '" . ee()->db->escape_str($qstring) . "'\r\n\t\t\t\t\t\t AND\t \t{$this->sc->db->channels}.site_id \r\n\t\t\t\t\t\t IN \t\t('" . implode("','", ee()->db->escape_str(ee()->TMPL->site_ids)) . "') "; if (ee()->TMPL->fetch_param($this->sc->channel) !== FALSE) { $sql .= ee()->functions->sql_andor_string(ee()->TMPL->fetch_param($this->sc->channel), $this->sc->db->channel_name, $this->sc->db->channels); } $query = ee()->db->query($sql); if ($query->num_rows() > 0) { $this->entry_id = $query->row('entry_id'); return TRUE; } } } return FALSE; }
function path() { // Load the string helper $this->EE->load->helper('string'); $src = $this->EE->TMPL->fetch_param('src'); $src = str_replace(array("'", '"'), '', $src); $src = preg_replace("/(.+?(\\/))index(\\/)(.*?)/", "\\1\\2", $src); $src = preg_replace("/(.+?(\\/))index\$/", "\\1", $src); $current = $this->EE->TMPL->fetch_param('use_current'); // Use current protocol on includes like javascript / css if (strtolower($current) == 'true') { if (isset($_SERVER["HTTPS"])) { $base = $this->_secure_url(trim_slashes($src)); $out = reduce_double_slashes($base); return $out; } else { return $this->EE->functions->create_url($src); } } // Else use http or https based on the target if (strpos($src, $this->_config["store"][$this->site_id]["checkout_url"]) !== false || strpos($src, $this->_config["store"][$this->site_id]["customer_url"]) !== false) { $base = $this->_secure_url(trim_slashes($src)); $out = reduce_double_slashes($base); return $out; } elseif (strtolower($src) == 'logout') { $qs = $this->EE->config->item('force_query_string') == 'y' ? '' : '?'; $XID = $this->EE->security->generate_xid(); return $this->_secure_url($qs . 'ACT=' . $this->EE->functions->fetch_action_id('Member', 'member_logout') . '&XID=' . $XID); } else { return $this->EE->functions->create_url($src); } }
/** * Extract path info * * We use this to extract the template group/template name * from path variables, like {some_var path="channel/index"} * * @access public * @param string * @return string */ public function extract_path($str) { if (preg_match("#=(.*)#", $str, $match)) { $match[1] = trim($match[1], '}'); if (isset($this->cached_path[$match[1]])) { return $this->cached_path[$match[1]]; } $path = trim_slashes(str_replace(array("'", '"'), "", $match[1])); if (substr($path, -6) == 'index/') { $path = str_replace('/index', '', $path); } if (substr($path, -5) == 'index') { $path = str_replace('/index', '', $path); } $this->cached_path[$match[1]] = $path; return $path; } else { return 'SITE_INDEX'; } }
/** * _entry_id, sets entry_id class var * * @access public * @param (string) id - entry id * @return boolean */ function _entry_id( $id = 'entry_id' ) { $cat_segment = ee()->config->item("reserved_category_word"); if ( $this->entry_id != '' ) { return TRUE; } elseif ( isset($GLOBALS['TMPL']) AND is_numeric( trim( ee()->TMPL->fetch_param($id) ) ) ) { $this->entry_id = trim( ee()->TMPL->fetch_param($id) ); return TRUE; } elseif ( is_numeric( ee()->input->get_post($id) ) ) { $this->entry_id = ee()->input->get_post($id); return TRUE; } elseif ( ee()->uri->query_string != '' AND $this->dynamic ) { $qstring = ee()->uri->query_string; // ---------------------------------------- // Do we have a pure ID number? // ---------------------------------------- if ( is_numeric( $qstring) ) { $this->entry_id = $qstring; return TRUE; } else { // ---------------------------------------- // Parse day // ---------------------------------------- if (preg_match("#\d{4}/\d{2}/(\d{2})#", $qstring, $match)) { $partial = substr($match['0'], 0, -3); $qstring = trim_slashes(str_replace($match['0'], $partial, $qstring)); } // ---------------------------------------- // Parse /year/month/ // ---------------------------------------- if (preg_match("#(\d{4}/\d{2})#", $qstring, $match)) { $qstring = trim_slashes(str_replace($match['1'], '', $qstring)); } // ---------------------------------------- // Parse page number // ---------------------------------------- if (preg_match("#^P(\d+)|/P(\d+)#", $qstring, $match)) { $qstring = trim_slashes(str_replace($match['0'], '', $qstring)); } // ---------------------------------------- // Parse category indicator // ---------------------------------------- // Text version of the category if (preg_match("#^".$cat_segment."/#", $qstring, $match) AND ee()->TMPL->fetch_param($this->sc->channel)) { $qstring = str_replace($cat_segment.'/', '', $qstring); $sql = "SELECT DISTINCT cat_group FROM {$this->sc->db->channels} WHERE "; if ( defined('USER_BLOG') AND defined('UB_BLOG_ID') AND USER_BLOG !== FALSE) { $sql .= " {$this->sc->db->id} ='" . UB_BLOG_ID . "'"; } else { $xsql = ee()->functions->sql_andor_string( ee()->TMPL->fetch_param($this->sc->channel), $this->sc->db->channel_name ); if (substr($xsql, 0, 3) == 'AND') $xsql = substr($xsql, 3); $sql .= ' '.$xsql; } $query = ee()->db->query($sql); if ($query->num_rows() == 1) { $result = ee()->db->query( "SELECT cat_id FROM exp_categories WHERE cat_name='" . ee()->db->escape_str($qstring) . "' AND group_id='" . $query->row('cat_group') . "'" ); if ($result->num_rows() == 1) { $qstring = 'C' . $result->row('cat_id'); } } } // ---------------------------------------- // Numeric version of the category // ---------------------------------------- if (preg_match("#^C(\d+)#", $qstring, $match)) { $qstring = trim_slashes(str_replace($match['0'], '', $qstring)); } // ---------------------------------------- // Remove "N" // ---------------------------------------- // The recent comments feature uses "N" as // the URL indicator // It needs to be removed if present // ---------------------------------------- if (preg_match("#^N(\d+)|/N(\d+)#", $qstring, $match)) { $qstring = trim_slashes(str_replace($match['0'], '', $qstring)); } // ---------------------------------------- // Try numeric id again // ---------------------------------------- if ( preg_match( "/(\d+)/", $qstring, $match ) ) { $this->entry_id = $match['1']; return TRUE; } // ---------------------------------------- // Parse URL title // ---------------------------------------- if (strstr($qstring, '/')) { $xe = explode('/', $qstring); $qstring = current($xe); } $sql = "SELECT {$this->sc->db->titles}.entry_id FROM {$this->sc->db->titles}, {$this->sc->db->channels} WHERE {$this->sc->db->titles}.{$this->sc->db->id} = {$this->sc->db->channels}.{$this->sc->db->id} AND {$this->sc->db->titles}.url_title = '" . ee()->db->escape_str($qstring) . "'"; //user blog is 1.6.x legacy and not defined in 2.x if (APP_VER < 2.0 AND defined('USER_BLOG') AND defined('UB_BLOG_ID') AND USER_BLOG !== FALSE) { $sql .= " AND {$this->sc->db->titles}.{$this->sc->db->id} = '" . UB_BLOG_ID . "'"; } //.is_user_blog elseif (APP_VER < 2.0 AND $this->_column_exists('is_user_blog', $this->sc->db->titles)) { $sql .= " AND {$this->sc->db->titles}.is_user_blog = 'n'"; } $query = ee()->db->query($sql); if ( $query->num_rows() > 0 ) { $this->entry_id = $query->row('entry_id'); return TRUE; } } } return FALSE; }