Example #1
0
/**
 * Returns a variable and allows for a default value
 *
 * @access	public
 * @param	string
 * @param	string
 * @param	string
 * @param	boolean
 * @return	string
 */
function fuel_var($key, $default = '', $edit_module = 'pages', $evaluate = TRUE)
{
	$CI =& get_instance();
	
	$CI->config->module_load('fuel', 'fuel', TRUE);
	$CI->load->helper('string');
	$CI->load->helper('inflector');

	if (isset($GLOBALS[$key]))
	{
		$val = $GLOBALS[$key];
	}
	else if (isset($CI->load->_ci_cached_vars[$key]))
	{
		$val = $CI->load->_ci_cached_vars[$key];
	}
	else
	{
		$val = $default;
	}
	if (is_string($val) AND $evaluate)
	{
		$val = eval_string($val);
	}
	else if (is_array($val) AND $evaluate)
	{
		foreach($val as $k => $v)
		{
			$val[$k] = eval_string($v);
		}
	}
	
	if ($edit_module === TRUE) $edit_module = 'pages';
	if (!empty($edit_module) AND $CI->config->item('fuel_mode', 'fuel') != 'views' AND !defined('USE_FUEL_MARKERS') OR (defined('USE_FUEL_MARKERS') AND USE_FUEL_MARKERS))
	{
		$marker = fuel_edit($key, humanize($key), $edit_module);
	}
	else
	{
		$marker = '';
	}
	
	if (is_string($val))
	{
		return $marker.$val;
	}
	else
	{
		if (!empty($marker))
		{
			// used to help with javascript positioning
			$marker = '<span>'.$marker.'</span>';
		}
		return $marker;
	}
}
Example #2
0
 /**
 * Returns the comment description. You can pass it an array of formatting parameters which include:
 	<ul>
 		<li><strong>markdown:</strong> applies the <a href="[user_guide_url]helpers/markdown_helper">markdown</a> function </li>
 		<li><strong>short:</strong> filters just the first paragraphs of the description if multiple paragraphs </li>
 		<li><strong>long:</strong> returns the entire description</li>
 		<li><strong>one_line:</strong> filters the description to appear on one line by removing returns</li>
 		<li><strong>entities:</strong> converts html entities</li>
 		<li><strong>eval:</strong> evaluates php code</li>
 		<li><strong>periods:</strong> adds periods at the end of lines that don't have them</li>
 		<li><strong>ucfirst:</strong> uppercases the first word</li>
 	</ul>
 *
 * @access	public
 * @param	int		The index (order) of the parameter to retrieve
 * @param	string	The part of the parameter to retrieve. Options are 'type' and 'comment'
 * @return	boolean
 */
 public function description($format = FALSE)
 {
     if (!isset($this->_description)) {
         preg_match('#/\\*\\*\\s*(.+ )(@|\\*\\/)#Ums', $this->_text, $matches);
         if (isset($matches[1])) {
             $this->_description = $matches[1];
             // removing preceding * and tabs
             $this->_description = preg_replace('#\\* *#m', "", $matches[1]);
             $this->_description = preg_replace("#^ +#m", "", $this->_description);
             // remove code examples since they are handled by the example method
             $this->_description = preg_replace('#<code>.+</code>#ms', '', $this->_description);
             $this->_description = trim($this->_description);
         } else {
             $this->_description = $this->_text;
         }
     }
     $desc = $this->_description;
     $desc = $this->filter($desc);
     // apply different formats
     if ($format) {
         if (is_string($format)) {
             $format = (array) $format;
         }
         foreach ($format as $f) {
             switch (strtolower($f)) {
                 case 'markdown':
                     // must escape underscores to prevent <em> tags
                     $desc = str_replace('_', '\\_', $desc);
                     $desc = markdown($desc);
                     // the we replace back any that didn't get processed'(e.g. ones inside links)
                     $desc = str_replace('\\_', '_', $desc);
                     break;
                 case 'short':
                     $desc_lines = explode(PHP_EOL, $desc);
                     $first_line = TRUE;
                     foreach ($desc_lines as $d) {
                         if (!empty($d)) {
                             if ($first_line) {
                                 $first_line = FALSE;
                                 $desc = $d;
                                 break;
                             }
                         }
                     }
                     break;
                 case 'long':
                     $desc_lines = explode(PHP_EOL, $desc);
                     $new_desc = '';
                     $first_line = TRUE;
                     foreach ($desc_lines as $d) {
                         if (!empty($d)) {
                             if ($first_line) {
                                 $first_line = FALSE;
                                 continue;
                             } else {
                                 $new_desc .= $d . ' ';
                             }
                         } else {
                             if (!$first_line) {
                                 $new_desc .= "\n\n";
                             }
                         }
                     }
                     $desc = $new_desc;
                     break;
                 case 'one_line':
                     $desc = str_replace(PHP_EOL, ' ', $desc);
                     break;
                 case 'entities':
                     $desc = htmlentities($desc);
                     break;
                 case 'eval':
                     $desc = eval_string($desc);
                     break;
                 case 'periods':
                     $desc_lines = explode(PHP_EOL, $desc);
                     $lines = '';
                     $past_first = FALSE;
                     foreach ($desc_lines as $d) {
                         $d = trim($d);
                         if (!empty($d)) {
                             if (!$past_first) {
                                 $d = preg_replace('#(.+[^\\.|>]\\s*)$#', '$1. ', $d);
                             }
                             $lines .= $d . ' ';
                             $past_first = TRUE;
                         } else {
                             if ($past_first) {
                                 $lines .= "\n\n";
                             }
                         }
                     }
                     $lines = preg_replace('#(.+[^\\.|>]\\s*)$#', '$1. ', trim($lines));
                     $desc = $lines;
                 case 'ucfirst':
                     $desc = ucfirst($desc);
                     break;
             }
         }
     }
     // auto link
     $desc = auto_link($desc);
     // trim white space
     $desc = trim($desc);
     // clean
     $desc = xss_clean($desc);
     $desc = strip_image_tags($desc);
     return $desc;
 }
/**
* Returns a variable and allows for a default value.
* Also creates inline editing marker.
* The <dfn>default</dfn> parameter will be used if the variable does not exist.
* The <dfn>edit_module</dfn> parameter specifies the module to include for inline editing.
* The <dfn>evaluate</dfn> parameter specifies whether to evaluate any php in the variables.
*
<p class="important">You should not use this function inside of another function because you may get unexepected results. This is
because it returns inline editing markers that later get parsed out by FUEL. For example:</p>

<code>
// NO
&lt;a href="&lt;?=site_url(fuel_var('my_url'))?&gt;"&gt;my link&lt;/a&gt;

// YES
&lt;?=fuel_edit('my_url', 'Edit Link')?&gt; &lt;a href="&lt;?=site_url($my_url)?&gt;"&gt;my link&lt;/a&gt;
</code>

* @access	public
* @param	string
* @param	string
* @param	boolean
* @return	string
*/
function fuel_var($key, $default = '', $edit_module = 'pagevariables', $evaluate = FALSE)
{
    $CI =& get_instance();
    $CI->load->helper('inflector');
    $key_arr = explode('|', $key);
    $key = $key_arr[0];
    if (isset($GLOBALS[$key])) {
        $val = $GLOBALS[$key];
    } else {
        if ($CI->load->get_var($key)) {
            $val = $CI->load->get_var($key);
        } else {
            $val = $default;
        }
    }
    if (is_string($val) and $evaluate) {
        $val = eval_string($val);
    } else {
        if (is_array($val) and $evaluate) {
            if (isset($key_arr[1])) {
                if (isset($val[$key_arr[1]])) {
                    $val = $val[$key_arr[1]];
                } else {
                    $val = $default;
                }
            } else {
                foreach ($val as $k => $v) {
                    $val[$k] = eval_string($v);
                }
            }
        }
    }
    if ($edit_module === TRUE) {
        $edit_module = 'pagevariables';
    }
    if (!empty($edit_module) and $CI->fuel->pages->mode() != 'views' and !defined('FUELIFY') or defined('FUELIFY') and FUELIFY) {
        $marker = fuel_edit($key, humanize($key), $edit_module);
    } else {
        $marker = '';
    }
    if (is_string($val)) {
        return $marker . $val;
    } else {
        if (!empty($marker)) {
            // used to help with javascript positioning
            $marker = '<span>' . $marker . '</span>';
        }
        return $marker;
    }
}