/** * Site URL * Added simple return if the url begins with http * * @access public * @param string the URI string * @return string */ function site_url($uri = '') { if (is_http_path($uri)) { return $uri; } $CI =& get_instance(); return $CI->config->site_url($uri); }
function get_link() { $url = $this->url; if (!is_http_path($url)) { $url = 'http://' . $url; } $label = !empty($this->name) ? $this->name : $this->url; $attrs = !empty($this->target) ? 'target="_' . $this->target . '"' : ''; return anchor($url, $label, $attrs); }
function get_link() { $set = $this->_parent_model->set; $url = $this->url; if (!is_http_path($url)) { $url = 'http://' . $url; } $label = !empty($this->name) ? $this->name : $this->url; $styles = array(); $styles[] = !empty($this->color) ? 'color: #' . $this->color : NULL; $style = implode(' ', $styles); $classes = array(); $classes[] = !empty($this->icon) ? $set . ' ' . $set . '-' . $this->icon : NULL; $class = implode(' ', $classes); $attrs = array(); $attrs[] = !empty($label) ? 'title="' . $label . '"' : NULL; $attrs[] = !empty($this->target) ? 'target="_' . $this->target . '"' : NULL; $attrs[] = $style ? 'style="' . $style . '"' : NULL; return anchor($url, '<i class="' . $class . '"></i>', implode(' ', $attrs)); }
function scrape_dom($url, $xpath_query = NULL) { if (is_http_path($url)) { $url = site_url($url); } // turn off the warnings for bad html $old_setting = libxml_use_internal_errors(TRUE); libxml_clear_errors(); $dom = new DOMDocument(); if (!@$dom->loadHTMLFile($url)) { return FALSE; } if ($xpath_query) { $xpath = new DOMXPath($dom); $results = $xpath->query($xpath_query); } // change errors back to original settings libxml_clear_errors(); libxml_use_internal_errors($old_setting); if (isset($results)) { return $results; } return $dom; }
/** * Will return a target="_blank" if the link is not from the same domain. * * @access public * @param string URL * @param array An array of extensions to check to force it to target="_blank" * @return boolean */ function link_target($link, $exts = array()) { $url_parts = parse_url($link); $test_domain = $_SERVER['SERVER_NAME']; $domain = ''; if (isset($url_parts['host'])) { if ($url_parts['host'] == $test_domain) { return ''; } $host_parts = explode('.', $url_parts['host']); $index = count($host_parts) - 1; if (isset($host_parts[$index - 1])) { $domain = $host_parts[$index - 1]; $domain .= '.'; $domain .= $host_parts[$index]; } else { if (count($host_parts) == 1) { $domain = $host_parts[0]; } } } // get the extension to check if (is_string($exts)) { $exts = array($exts); } $ext = end(explode('.', $link)); // check if an http path and that it is from a different domain if (is_http_path($link) and $test_domain != $domain or !empty($exts) and in_array($ext, $exts)) { return ' target="_blank"'; } return ''; }
function on_before_clean($values) { if (empty($values['nav_key'])) $values['nav_key'] = $values['location']; // if the path is local, then we clean it if (!is_http_path($values['location'])) { $values['location'] = str_replace(array('/', '#'), array('____', '___'), $values['location']); $values['location'] = url_title($values['location']); $values['location'] = str_replace(array('____', '___'), array('/', '#'), $values['location']); } return $values; }
/** * Displays related items on the right side * * @access public * @param array View variable data (optional) * @return mixed Can be an array of items or a string value */ public function related_items($values = array()) { $CI =& get_instance(); // don't display if it is disabled if ($CI->fuel->modules->get('navigation')->info('disabled') === TRUE) { return ''; } $CI->load->module_model(FUEL_FOLDER, 'fuel_navigation_model'); $where['location'] = $values['location']; $related_items = $CI->fuel_navigation_model->find_all_array_assoc('id', $where); $return = array(); if (!empty($related_items)) { $return['navigation'] = array(); foreach ($related_items as $key => $item) { $label = $item['label']; if (!empty($item['group_name'])) { $label .= ' (' . $item['group_name'] . ')'; } $return['navigation']['inline_edit/' . $key] = $label; } } else { if (!empty($values['location']) and $this->fuel->auth->has_permission('navigation', 'create')) { $return['navigation'] = array(); $label = !empty($values['page_vars']['page_title']) ? $values['page_vars']['page_title'] : ''; $parent_id = 0; $group_id = $CI->fuel->config('auto_page_navigation_group_id'); // determine parent based off of location $location_arr = explode('/', $values['location']); $parent_location = implode('/', array_slice($location_arr, 0, count($location_arr) - 1)); if (!empty($parent_location)) { $parent = $this->fuel_navigation_model->find_by_location($parent_location); } if (!empty($parent)) { $parent_id = $parent['id']; } $return['navigation']['inline_create?location=' . urlencode($values['location']) . '&label=' . $label . '&group_id=' . $group_id . '&parent_id=' . $parent_id] = lang('navigation_related'); } } $view = $this->load->module_view(FUEL_FOLDER, '_blocks/related_items_array', array('related_items' => $return), TRUE); $layout = $CI->fuel->layouts->get($values['layout']); if (!empty($layout->preview_image)) { $img_path = (is_http_path($layout->preview_image) or substr($layout->preview_image, 0, 1) == '/') ? $layout->preview_image : img_path($layout->preview_image); $view = '<img src="' . $img_path . '" alt="' . $layout->name() . '" class="layout_preview" />' . $view; } return $view; }
/** * Model hook right before the data is cleaned. Cleans up location value if needed * * @access public * @param array The values to be saved right the clean method is run * @return array Returns the values to be cleaned */ public function on_before_clean($values) { //if (empty($values['nav_key'])) $values['nav_key'] = $values['location']; // if the path is local, then we clean it if (!is_http_path($values['location'])) { $values['location'] = str_replace(array('/', '#', '.'), array('____', '___', '_X_'), $values['location']); $values['location'] = url_title($values['location']); $values['location'] = str_replace(array('____', '___', '_X_'), array('/', '#', '.'), $values['location']); } if (empty($values['language'])) { $CI =& get_instance(); $values['language'] = $CI->fuel->language->default_option(); } return $values; }
/** * Creates open graph meta tags * * @access protected * @param mixed An array or object of values with keys being title, url, description, image, site_name, or type * @return string An array of values */ public function og($values = array()) { $CI =& get_instance(); // normalize the values $values = $this->normalize_values($values); $str = ''; $defaults = array('url' => current_url(), 'title' => $CI->load->get_var('page_title'), 'description' => $CI->load->get_var('meta_description'), 'source' => $CI->fuel->config('site_name')); // If a post object exists, then we can auto create the information if they have the proper fields if ($values instanceof Base_post_item_model) { $values = array(); $values['url'] = $values->url; $values['title'] = $values->title; $values['url'] = $values->url; $values['description'] = $values->get_excerpt(80, '...'); } $values = array_merge($defaults, $values); $valid_types = array('title', 'url', 'description', 'image', 'site_name', 'type'); foreach ($values as $key => $val) { if (!empty($val) and in_array($key, $valid_types)) { // format image path if ($key == 'image' and !is_http_path($val)) { $val = img_path($val, NULL, TRUE); } elseif ($key == 'url') { $val = site_url($val); } $str .= "\t<meta property=\"og:" . $key . "\" content=\"" . $values[$key] . "\">\n"; } } return $str; }
/** * Creates an asset select/upload field * * @access public * @param array Fields parameters * @return string */ public function asset($params) { $this->CI->load->helper('file'); $this->CI->load->helper('html'); $form_builder =& $params['instance']; if (empty($params['folder'])) { $params['folder'] = 'images'; } $asset_class = ''; if (!isset($params['select']) or isset($params['select']) and $params['select'] !== FALSE) { $asset_class .= ' asset_select'; } if (!isset($params['upload']) or isset($params['upload']) and $params['upload'] !== FALSE) { $asset_class .= ' asset_upload'; } $asset_class .= ' ' . $params['folder']; $params['class'] = !empty($params['class']) ? $params['class'] . ' ' . $asset_class : $asset_class; // set the image preview containing class if (empty($params['img_container_styles'])) { $params['img_container_styles'] = 'overflow: auto; height: 200px; width: 400px; margin-top: 5px;'; } // set the styles specific to the image if (!isset($params['img_styles'])) { $params['img_styles'] = 'float: left; width: 100px;'; } // folders and intended contents $editable_filetypes = $this->fuel->config('editable_asset_filetypes'); // set data parameters so that we can use them with the JS // set multiple and separator data attributes so can be used by javascript if (!isset($params['multiple'])) { $multiple = !empty($params['multiple']) or strpos($params['value'], ',') !== FALSE; } else { $multiple = $params['multiple']; } // set the separator based on if it is multiple lines or just a single line $separator = (isset($params['multiline']) and $params['multiline'] === TRUE) ? "\n" : ', '; $params['data'] = array('multiple' => $multiple, 'separator' => $separator, 'folder' => $params['folder']); if (!empty($params['value'])) { if (is_string($params['value'])) { // unserialize if it is a serialized string if (is_json_str($params['value'])) { $assets = json_decode($params['value'], TRUE); //$assets = unserialize($params['value']); } else { if ($multiple) { // create assoc array with key being the image and the value being either the image name again or the caption $assets = preg_split('#\\s*,\\s*|\\n#', $params['value']); } else { $assets = array($params['value']); } } $preview_str = ''; // loop through all the assets and concatenate them foreach ($assets as $asset) { if (!empty($asset)) { $asset_path = ''; foreach ($editable_filetypes as $folder => $regex) { if (!is_http_path($asset)) { if (preg_match('#' . $regex . '#i', $asset)) { $path = trim($params['folder'], '/') . '/' . $asset; $asset_path = assets_path($path); break; } } else { $asset_path = $asset; } } if (!empty($asset_path)) { $preview_str .= '<a href="' . $asset_path . '" target="_blank">'; if (isset($params['is_image']) or !isset($params['is_image']) and is_image_file($asset)) { $preview_str .= '<img src="' . $asset_path . '" style="' . $params['img_styles'] . '"/>'; } else { $preview_str .= $asset; } $preview_str .= '</a>'; } } } } $preview = ''; if (!empty($preview_str)) { $img_container_styles = $params['img_container_styles']; if ($multiple == FALSE and !empty($params['img_styles'])) { $img_container_styles = $params['img_styles']; } $preview = '<br /><div class="noclone" style="' . $img_container_styles . '">'; $preview .= $preview_str; $preview .= '</div><div class="clear"></div>'; } $params['after_html'] = $preview; } $params['type'] = ''; if ($multiple) { $process_key = isset($params['subkey']) ? $params['subkey'] : $params['key']; // create an array with the key being the image name and the value being the caption (if it exists... otherwise the image name is used again) $func_str = ' if (is_array($value)) { foreach($value as $key => $val) { if (isset($val["' . $process_key . '"])) { if (is_string($val["' . $process_key . '"])) { $z = $val["' . $process_key . '"]; } else if (is_array($val["' . $process_key . '"]) AND isset($val["' . $process_key . '"]["' . $params['name'] . '"])) { $z = $val["' . $process_key . '"]["' . $params['name'] . '"]; } $z = trim($z); $assets = array(); $assets_arr = preg_split("#\\s*,\\s*|\\n#", $z); if (is_string($val["' . $process_key . '"])) { if (count($assets_arr) > 1) { $value[$key]["' . $process_key . '"] = json_encode($assets_arr); } else { $value[$key]["' . $process_key . '"] = $z; } } else if (is_array($val["' . $process_key . '"]) AND isset($val["' . $process_key . '"]["' . $params['name'] . '"])) { if (count($assets_arr) > 1) { $value[$key]["' . $process_key . '"]["' . $params['name'] . '"] = json_encode($assets_arr); } else { $value[$key]["' . $process_key . '"]["' . $params['name'] . '"] = $z; } } } } return $value; } else { $value = trim($value); $assets_arr = preg_split("#\\s*,\\s*|\\n#", $value); if (count($assets_arr) > 1) { return json_encode($assets_arr); } else { return $value; } } '; $func = create_function('$value', $func_str); $form_builder->set_post_process($params['key'], $func); } // unserialize value if it's serialized //$value = (is_serialized_str($params['value'])) ? unserialize($params['value']) : $params['value']; $value = (is_string($params['value']) and is_json_str($params['value'])) ? json_decode($params['value'], TRUE) : $params['value']; if (is_array($value)) { $params['value'] = ''; foreach ($value as $key => $val) { if (!empty($val)) { $params['value'] .= $val . $separator; } } } $params['value'] = trim($params['value'], ",\n "); //$params['comment'] = 'Add a caption value to your image by inserting a colon after the image name and then enter your caption like so: my_img.jpg:My caption goes here.'; // data params $data_params['asset_folder'] = $params['folder']; $data_params['subfolder'] = isset($params['subfolder']) ? $params['subfolder'] : ''; $data_params['userfile_file_name'] = isset($params['file_name']) ? $params['file_name'] : ''; $data_params['overwrite'] = isset($params['overwrite']) ? (bool) $params['overwrite'] : TRUE; $data_params['unzip'] = isset($params['unzip']) ? (bool) $params['unzip'] : TRUE; $data_params['create_thumb'] = isset($params['create_thumb']) ? (bool) $params['create_thumb'] : FALSE; $data_params['maintain_ratio'] = isset($params['maintain_ratio']) ? (bool) $params['maintain_ratio'] : FALSE; $data_params['width'] = isset($params['width']) ? (int) $params['width'] : ''; $data_params['height'] = isset($params['height']) ? (int) $params['height'] : ''; $data_params['master_dim'] = isset($params['master_dim']) ? $params['master_dim'] : ''; $data_params['resize_and_crop'] = isset($params['resize_and_crop']) ? $params['resize_and_crop'] : ''; $data_params['resize_method'] = isset($params['resize_method']) ? $params['resize_method'] : 'maintain_ratio'; $data_params['hide_options'] = isset($params['hide_options']) ? (bool) $params['hide_options'] : FALSE; $data_params['accept'] = isset($params['accept']) ? $params['accept'] : ''; if (isset($params['hide_image_options'])) { $data_params['hide_image_options'] = isset($params['hide_image_options']) ? (bool) $params['hide_image_options'] : FALSE; } else { if (!isset($params['hide_image_options']) and !preg_match('#^images#', $params['folder'])) { $data_params['hide_image_options'] = TRUE; } } $params['data']['params'] = http_build_query($data_params); if (!empty($params['multiline'])) { $params['class'] = 'no_editor ' . $params['class']; if (empty($params['style'])) { $params['style'] = 'float: left; width: 400px; height: 60px'; } $str = $form_builder->create_textarea($params); } else { $str = $form_builder->create_text($params); } $str .= $params['after_html']; return $str; }
/** * Convenience method to normalize a URL path * * @access protected * @param string The URL to use for the CURL session * @return string */ protected function _normalize_url($url) { if (is_http_path($url)) { $url = site_url($url); } return $url; }
/** * Renders a page in the admin * * @access public * @param string The name of the view file to display * @param array Variables to pass to the view file (optional) * @param string The display mode to use (can be the class constant Fuel_admin::DISPLAY_NO_ACTION, DISPLAY_COMPACT, DISPLAY_COMPACT_NO_ACTION, DISPLAY_COMPACT_TITLEBAR, DISPLAY_DEFAULT) (optional) * @param array The module to pull the view file from (optional) * @return void */ public function render($view, $vars = array(), $mode = '', $module = NULL) { // set the active state of the menu $this->nav_selected(); // set the module parameter to know where to look for view files if (!isset($module)) { $module = !empty($this->CI->view_location) ? $this->CI->view_location : $this->CI->router->fetch_module(); } // get notification if not already loaded in $vars and if any errors if (empty($vars['notifications'])) { $vars['error'] = $this->get_model_errors(); $vars['notifications'] = $this->CI->load->module_view(FUEL_FOLDER, '_blocks/notifications', $vars, TRUE); } // get titlebar only if there is no $vars set for it if (empty($vars['titlebar'])) { $vars['titlebar'] = $this->titlebar(); } // get titlebar icon only if there is no $vars set for it if (empty($vars['titlebar_icon'])) { $vars['titlebar_icon'] = $this->titlebar_icon(); } if (!empty($mode) or empty($this->display_mode)) { $this->set_display_mode($mode); } // set inline if (!empty($_POST['fuel_inline']) or (int) $this->CI->input->get('inline') != 0) { if (!empty($_POST['fuel_inline']) and $_POST['fuel_inline'] != 0) { $inline = $this->CI->input->post('fuel_inline'); } else { if ((int) $this->CI->input->get('inline') != 0) { $inline = $this->CI->input->get('inline'); } } $this->set_inline($inline); } // set the form action if (empty($vars['form_action'])) { $vars['form_action'] = site_url($this->CI->uri->uri_string() . '?inline=' . $this->is_inline()); } else { if (!empty($vars['form_action']) and !is_http_path($vars['form_action'])) { $vars['form_action'] = fuel_url($vars['form_action']); } } $layout = isset($vars['layout']) ? $vars['layout'] : $this->main_layout; if (!empty($layout)) { $vars['body'] = $this->CI->load->module_view($module, $view, $vars, TRUE); $vars['panels'] = $this->panels; if (is_array($layout)) { $layout_module = key($layout); $layout_view = current($layout); $this->CI->load->module_view($layout_module, $layout_view, $vars); } else { $this->CI->load->module_view(FUEL_FOLDER, '_layouts/' . $layout, $vars); } } else { $this->CI->load->module_view($module, $view, $vars); } // register the last page $this->set_last_page(); }