PageRenderTime 62ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/fuel/modules/fuel/helpers/fuel_helper.php

http://github.com/daylightstudio/FUEL-CMS
PHP | 792 lines | 383 code | 61 blank | 348 comment | 69 complexity | 9c79f7a49621f382be2f41c48b54ec21 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * FUEL CMS
  4. * http://www.getfuelcms.com
  5. *
  6. * An open source Content Management System based on the
  7. * Codeigniter framework (http://codeigniter.com)
  8. *
  9. * @package FUEL CMS
  10. * @author David McReynolds @ Daylight Studio
  11. * @copyright Copyright (c) 2018, Daylight Studio LLC.
  12. * @license http://docs.getfuelcms.com/general/license
  13. * @link http://www.getfuelcms.com
  14. * @filesource
  15. */
  16. // ------------------------------------------------------------------------
  17. /**
  18. * FUEL Helper
  19. *
  20. * Contains FUEL specific functions. This helper is automatically loaded with the autoload config.
  21. *
  22. * @package FUEL CMS
  23. * @subpackage Libraries
  24. * @category Libraries
  25. * @author David McReynolds @ Daylight Studio
  26. * @link http://docs.getfuelcms.com/helpers/fuel_helper
  27. */
  28. // --------------------------------------------------------------------
  29. /**
  30. * Returns the instance of the FUEL object
  31. *
  32. * @access public
  33. * @return object
  34. */
  35. function &fuel_instance()
  36. {
  37. return Fuel::get_instance();
  38. }
  39. /**
  40. * Returns the instance of the FUEL object just like fuel_instance but with a similar syntax to the CI() function which returns the CI object.
  41. *
  42. * @access public
  43. * @return object
  44. */
  45. function &FUEL()
  46. {
  47. $f = & fuel_instance();
  48. return $f;
  49. }
  50. // --------------------------------------------------------------------
  51. if ( ! function_exists('fuel_block'))
  52. {
  53. /**
  54. * Allows you to load a view and pass data to it.
  55. *
  56. * The <dfn>params</dfn> parameter can either be string value (in which case it will assume it is the name of the block view file) or an associative array that can have the following values:
  57. *
  58. * <ul>
  59. * <li><strong>view</strong> - the name of the view block file. Also can be the first parameter of the method</li>
  60. * <li><strong>vars</strong>: an array of variables to pass to the block. Also can be the second parameter of the method.</li>
  61. * <li><strong>view_string</strong> - a string variable that represents the block</li>
  62. * <li><strong>model</strong> - the name of a model to automatically load for the block</li>
  63. * <li><strong>find</strong> - the name of the find method to run on the loaded model</li>
  64. * <li><strong>select</strong> - select parameters to run for the find method</li>
  65. * <li><strong>where</strong> - where parameters to run for the find method</li>
  66. * <li><strong>order</strong> - the order the find method should return</li>
  67. * <li><strong>limit</strong> - the limit number of results to be returned by the find method</li>
  68. * <li><strong>offset</strong> - the find results returned offset value</li>
  69. * <li><strong>return_method</strong>: the return method the find query should use</li>
  70. * <li><strong>assoc_key</strong>: the column name to be used as the associative key in the find method</li>
  71. * <li><strong>data</strong>: the data values to be passed to the block. This variable get's automatically set if you specify the model and find method</li>
  72. * <li><strong>editable</strong>: css class styles to apply to menu items... can be a nested array</li>
  73. * <li><strong>parse</strong>: determines whether to parse the contents of the block. The default is set to 'auto'</li>
  74. * <li><strong>cache</strong>: determines whether to cache the block. Default is false</li>
  75. * <li><strong>mode</strong>: explicitly will look in either the CMS or the views/_blocks folder</li>
  76. * <li><strong>module</strong>: the name of the module to look in for the block</li>
  77. * <li><strong>language</strong>: the language version to use for the block. Must be a value specified found in the 'languages' options in the FUEL configuration</li>
  78. * <li><strong>use_default</strong>: determines whether to find a non-language specified version of a block with the same name if the specified language version is not available in the CMS</li>
  79. * </ul>
  80. *
  81. * @access public
  82. * @param array
  83. * @param array
  84. * @param boolean
  85. * @param string
  86. * @return string
  87. */
  88. function fuel_block($params, $vars = array(), $check_db = TRUE, $scope = NULL)
  89. {
  90. $CI =& get_instance();
  91. return $CI->fuel->blocks->render($params, $vars, $check_db, $scope);
  92. }
  93. }
  94. // --------------------------------------------------------------------
  95. if ( ! function_exists('fuel_nav'))
  96. {
  97. /**
  98. * Creates a menu structure
  99. *
  100. * The <dfn>params</dfn> parameter is an array of options to be used with the <a href="[user_guide_url]libraries/menu">Menu class</a>.
  101. * If FUEL's configuration mode is set to either <dfn>auto</dfn> or <dfn>cms</dfn>, then it will first look for data from the FUEL navigation module.
  102. * Otherwise it will by default look for the file <dfn>views/_variables/nav.php</dfn> (you can change the name of the file it looks for in the <dfn>file</dfn> parameter passed). That file should contain an array of menu information (see <a href="<?=user_guide_url('libraries/menu')?>">Menu class</a> for more information on the required data structure).
  103. * The parameter values are very similar to the <a href="[user_guide_url]libraries/menu">Menu class</a>, with a few additions shown below:
  104. *
  105. * <ul>
  106. * <li><strong>items</strong> - the navigation items to use. By default, this is empty and will look for the nav.php file or the records in the Navigation module</li>
  107. * <li><strong>file</strong> - the name of the file containing the navigation information</li>
  108. * <li><strong>var</strong> - the variable name in the file to use</li>
  109. * <li><strong>parent</strong> - the parent id you would like to start rendering from. This is either the database ID or the nav array key of the menu item</li>
  110. * <li><strong>root</strong> - the equivalent to the root_value attribute in the Menu class. It states what the root value of the menu structure should be. Normally you don't need to worry about this</li>
  111. * <li><strong>group_id</strong> - the group ID in the database to use. The default is <dfn>1</dfn>. Only applies to navigation items saved in the admin</li>
  112. * <li><strong>exclude</strong> - nav items to exclude from the menu. Can be an array or a regular expression string</li>
  113. * <li><strong>return_normalized</strong> - returns the raw normalized array that gets used to generate the menu</li>
  114. * <li><strong>render_type</strong>: options are basic, breadcrumb, page_title, collapsible, delimited, array. Default is 'basic'</li>
  115. * <li><strong>active_class</strong>: the active css class. Default is 'active'</li>
  116. * <li><strong>active</strong>: the active menu item</li>
  117. * <li><strong>styles</strong>: css class styles to apply to menu items... can be a nested array</li>
  118. * <li><strong>first_class</strong>: the css class for the first menu item. Default is first</li>
  119. * <li><strong>last_class</strong>: the css class for the last menu item. Default is last</li>
  120. * <li><strong>depth</strong>: the depth of the menu to render at</li>
  121. * <li><strong>use_titles</strong>: use the title attribute in the links. Default is FALSE</li>
  122. * <li><strong>container_tag</strong>: the html tag for the container of a set of menu items. Default is ul</li>
  123. * <li><strong>container_tag_attrs</strong>: html attributes for the container tag</li>
  124. * <li><strong>container_tag_id</strong>: html container id</li>
  125. * <li><strong>container_tag_class</strong>: html container class</li>
  126. * <li><strong>subcontainer_tag_class</strong>: an array of css classes to apply to subcontainers</li>
  127. * <li><strong>cascade_selected</strong>: cascade the selected items. Default is TRUE</li>
  128. * <li><strong>include_hidden</strong>: include menu items with the hidden attribute. Default is FALSE</li>
  129. * <li><strong>item_tag</strong>: the html list item element. Default is 'li'</li>
  130. * <li><strong>item_id_prefix</strong>: the prefix to the item id</li>
  131. * <li><strong>item_id_key</strong>: either id or location. Default is 'id'</li>
  132. * <li><strong>use_nav_key</strong>: determines whether to use the nav_key or the location for the active state. Default is "AUTO"</li>
  133. * <li><strong>pre_render_func</strong>: function to apply to menu labels before rendering</li>
  134. * <li><strong>delimiter</strong>: the html element between the links </li>
  135. * <li><strong>arrow_class</strong>: the class for the arrows used in breadcrumb type menus</li>
  136. * <li><strong>display_current</strong>: determines whether to display the current active breadcrumb item</li>
  137. * <li><strong>home_link</strong>: the root home link</li>
  138. * <li><strong>append</strong>: appends additional menu items to those items already set (e.g. from the $nav array or from the navigation module). Good to use on dynamic pages where you need to dynamically set a navigation item for a page</li>
  139. * <li><strong>order</strong>: the order to display... for page_title ONLY</li>
  140. * <li><strong>language</strong>: select the appropriate language</li>
  141. * <li><strong>include_default_language</strong>: will merge in the default language with the results. Default is FALSE</li>
  142. * <li><strong>language_default_group</strong>: the default group to be used when including a default language. Default is FALSE</li>
  143. * </ul>
  144. *
  145. * <p class="important">For more information see the <a href="<?=user_guide_url('libraries/menu')?>">Menu class</a>.</p>
  146. *
  147. * @access public
  148. * @param array $params
  149. * @return string
  150. */
  151. function fuel_nav($params = array())
  152. {
  153. $CI =& get_instance();
  154. return $CI->fuel->navigation->render($params);
  155. }
  156. }
  157. // --------------------------------------------------------------------
  158. if ( ! function_exists('fuel_page'))
  159. {
  160. /**
  161. * Generates a page using the Fuel_page class
  162. *
  163. * @access public
  164. * @param string
  165. * @param array
  166. * @param array
  167. * @return string
  168. */
  169. function fuel_page($location, $vars = array(), $params = array())
  170. {
  171. $CI =& get_instance();
  172. return $CI->fuel->pages->render($location, $vars, $params, TRUE);
  173. }
  174. }
  175. // --------------------------------------------------------------------
  176. if ( ! function_exists('fuel_form'))
  177. {
  178. /**
  179. * Creates a form using form builder
  180. *
  181. * @access public
  182. * @param mixed
  183. * @param array
  184. * @param array
  185. * @return string
  186. */
  187. function fuel_form($fields, $values = array(), $params = array())
  188. {
  189. $CI =& get_instance();
  190. // if a string is provided instead of array, we will assume it is a model
  191. if (is_string($fields))
  192. {
  193. $model = $fields;
  194. if (substr($model, strlen($model) - 6) != '_model')
  195. {
  196. $model = $model . '_model';
  197. }
  198. $CI->load->model($model);
  199. // check if the model has a form_fields method on it first
  200. if ( ! method_exists('form_fields', $CI->$model))
  201. {
  202. return '';
  203. }
  204. $fields = $CI->$model->form_fields();
  205. }
  206. $CI->load->library('form_builder', $params);
  207. $CI->form_builder->set_fields($fields);
  208. $CI->form_builder->set_field_values($values);
  209. return $CI->form_builder->render();
  210. }
  211. }
  212. // --------------------------------------------------------------------
  213. if ( ! function_exists('fuel_model'))
  214. {
  215. /**
  216. * Loads a module model and creates a variable in the view that you can use to merge data.
  217. *
  218. * The <dfn>params</dfn> parameter is an associative array that can have the following values:
  219. *
  220. * <ul>
  221. * <li><strong>find</strong> - the find method to use on the module model. Options are "one", "key", "all" or any method name on the model that begins with "find_" (excluding "find_" from the value)</li>
  222. * <li><strong>select</strong> - the select condition to filter the results of the find query</li>
  223. * <li><strong>where</strong> - the where condition to be used in the find query</li>
  224. * <li><strong>order</strong> - order the data results and sort them </li>
  225. * <li><strong>limit</strong> - limit the number of data results returned</li>
  226. * <li><strong>offset</strong> - offset the data results</li>
  227. * <li><strong>return_method</strong> - the return method to use which can be an object or an array</li>
  228. * <li><strong>assoc_key</strong> - the field to be used as an associative key for the data results</li>
  229. * <li><strong>var</strong> - the variable name to assign the data returned from the module model query</li>
  230. * <li><strong>module</strong> - specifies the module folder name to find the model</li>
  231. * </ul>
  232. * @access public
  233. * @param string
  234. * @param mixed
  235. * @param mixed
  236. * @return mixed
  237. */
  238. function fuel_model($module, $params = array(), $where = array())
  239. {
  240. $CI =& get_instance();
  241. $module = $CI->fuel->modules->get($module, FALSE);
  242. if ($module)
  243. {
  244. return $module->find($params, $where);
  245. }
  246. return FALSE;
  247. }
  248. }
  249. // --------------------------------------------------------------------
  250. if ( ! function_exists('fuel_set_var'))
  251. {
  252. /**
  253. * Sets a variable for all views to use (including layouts) no matter what view it is declared in.
  254. *
  255. * Using fuel_set_var in a layout field in the admin, will have no affect (e.g. {fuel_set_var('layout', 'my_layout')}).
  256. *
  257. * @access public
  258. * @param string
  259. * @param array
  260. * @return void
  261. */
  262. function fuel_set_var($key, $val = NULL)
  263. {
  264. $CI =& get_instance();
  265. if (strtoupper($CI->fuel->config('double_parse')) == 'AUTO')
  266. {
  267. $CI->fuel->set_config('double_parse', TRUE);
  268. }
  269. if (is_array($key))
  270. {
  271. $CI->load->vars($key);
  272. }
  273. else if (is_string($key))
  274. {
  275. $vars[$key] = $val;
  276. $CI->load->vars($vars);
  277. }
  278. }
  279. }
  280. // --------------------------------------------------------------------
  281. if ( ! function_exists('fuel_var_append'))
  282. {
  283. /**
  284. * Appends a value to an array variable for all views to use no matter what view it is declared in.
  285. *
  286. * <code>
  287. * // EXAMPLE HEADER FILE
  288. * ...
  289. * &lt;?php echo css(&#x27;main&#x27;); ?&gt;
  290. * &lt;?php echo css($css); ?&gt;
  291. *
  292. * &lt;?php echo js(&#x27;jquery, main&#x27;); ?&gt;
  293. * &lt;?php echo js($js); ?&gt;
  294. * ...
  295. *
  296. * // Then in your view file
  297. * ...
  298. * &lt;php
  299. * fuel_var_append('css', 'my_css_file.css');
  300. * fuel_var_append('js', 'my_js_file.js');
  301. * ?&gt;
  302. * <h1>About our company</h1>
  303. * ...
  304. * </code>
  305. * @access public
  306. * @param string
  307. * @param mixed
  308. * @return void
  309. */
  310. function fuel_var_append($key, $value)
  311. {
  312. $CI =& get_instance();
  313. $vars = $CI->load->get_vars();
  314. if (isset($vars[$key]) AND is_array($vars[$key]))
  315. {
  316. if (is_array($value))
  317. {
  318. $vars[$key] = array_merge($vars[$key], $value);
  319. }
  320. else
  321. {
  322. array_push($vars[$key], $value);
  323. }
  324. fuel_set_var($key, $vars[$key]);
  325. }
  326. }
  327. }
  328. // --------------------------------------------------------------------
  329. if ( ! function_exists('fuel_var'))
  330. {
  331. /**
  332. * Returns a variable and allows for a default value.
  333. * Also creates inline editing marker.
  334. * The <dfn>default</dfn> parameter will be used if the variable does not exist.
  335. * The <dfn>edit_module</dfn> parameter specifies the module to include for inline editing.
  336. * The <dfn>evaluate</dfn> parameter specifies whether to evaluate any php in the variables.
  337. *
  338. * <p class="important">You should not use this function inside of another function because you may get unexepected results. This is
  339. * because it returns inline editing markers that later get parsed out by FUEL. For example:</p>
  340. *
  341. * <code>
  342. * // NO
  343. * &lt;a href="&lt;?=site_url(fuel_var('my_url'))?&gt;"&gt;my link&lt;/a&gt;
  344. *
  345. * // YES
  346. * &lt;?=fuel_edit('my_url', 'Edit Link')?&gt; &lt;a href="&lt;?=site_url($my_url)?&gt;"&gt;my link&lt;/a&gt;
  347. * </code>
  348. * @access public
  349. * @param string
  350. * @param string
  351. * @param string
  352. * @param boolean
  353. * @return string
  354. */
  355. function fuel_var($key, $default = '', $edit_module = 'pagevariables', $evaluate = FALSE)
  356. {
  357. $CI =& get_instance();
  358. $CI->load->helper('inflector');
  359. $key_arr = explode('|', $key);
  360. $key = $key_arr[0];
  361. if (isset($GLOBALS[$key]))
  362. {
  363. $val = $GLOBALS[$key];
  364. }
  365. else if ($CI->load->get_var($key))
  366. {
  367. $val = $CI->load->get_var($key);
  368. }
  369. else
  370. {
  371. $val = $default;
  372. }
  373. if (is_string($val) AND $evaluate)
  374. {
  375. $val = eval_string($val);
  376. }
  377. else if (is_array($val) AND $evaluate)
  378. {
  379. if (isset($key_arr[1]))
  380. {
  381. if (isset($val[$key_arr[1]]))
  382. {
  383. $val = $val[$key_arr[1]];
  384. }
  385. else
  386. {
  387. $val = $default;
  388. }
  389. }
  390. else
  391. {
  392. foreach ($val as $k => $v)
  393. {
  394. $val[$k] = eval_string($v);
  395. }
  396. }
  397. }
  398. if ($edit_module === TRUE) $edit_module = 'pagevariables';
  399. if ( ! empty($edit_module) AND $CI->fuel->pages->mode() != 'views' AND ! defined('FUELIFY') OR (defined('FUELIFY') AND FUELIFY))
  400. {
  401. $marker = fuel_edit($key, humanize($key), $edit_module);
  402. }
  403. else
  404. {
  405. $marker = '';
  406. }
  407. if (is_string($val))
  408. {
  409. return $marker . $val;
  410. }
  411. else
  412. {
  413. if ( ! empty($marker))
  414. {
  415. // used to help with javascript positioning
  416. $marker = '<span>' . $marker . '</span>';
  417. }
  418. return $marker;
  419. }
  420. }
  421. }
  422. // --------------------------------------------------------------------
  423. if ( ! function_exists('fuel_edit'))
  424. {
  425. /**
  426. * Sets a variable marker (pencil icon) in a page which can be used for inline editing.
  427. *
  428. * The <dfn>id</dfn> parameter is the unique id that will be used to query the module. You can also pass an id value
  429. * and a field like so <dfn>id|field</dfn>. This will display only a certain field instead of the entire module form.
  430. * Alternatively, you can now also just pass the entire object and it will generate the id, label, module and published values automatically.
  431. * The <dfn>is_published</dfn> parameter specifies whether to indicate with the pencil icon that the item is active/published
  432. * The <dfn>label</dfn> parameter specifies the label to display next to the pencil icon.
  433. * The <dfn>xOffset</dfn> and <dfn>yOffset</dfn> are pixel values to offset the pencil icon.
  434. *
  435. * @access public
  436. * @param mixed
  437. * @param string
  438. * @param string
  439. * @param boolean
  440. * @param int
  441. * @param int
  442. * @return string
  443. */
  444. function fuel_edit($id, $label = NULL, $module = 'pagevariables', $is_published = TRUE, $xoffset = NULL, $yoffset = NULL)
  445. {
  446. $CI =& get_instance();
  447. $page = $CI->fuel->pages->active();
  448. $permission = $module;
  449. if (empty($page))
  450. {
  451. $page = $CI->fuel->pages->create();
  452. }
  453. if ( ! empty($id) AND ( ! defined('FUELIFY') OR defined('FUELIFY') AND FUELIFY !== FALSE))
  454. {
  455. if (is_object($id) AND is_a($id, 'Data_record') AND isset($id->id))
  456. {
  457. $ref_id = $id->id;
  458. if (empty($module) OR $module == 'pagevariables')
  459. {
  460. $module = $id->parent_model()->table_name();
  461. $tables = array_flip($id->parent_model()->tables());
  462. if (isset($tables[$module]))
  463. {
  464. $module = $tables[$module];
  465. }
  466. unset($tables);
  467. }
  468. if (empty($label))
  469. {
  470. $label = lang('action_edit') . ': ';
  471. if (isset($id->title))
  472. {
  473. $label .= $id->title;
  474. }
  475. else if ($id->name)
  476. {
  477. $label .= $id->name;
  478. }
  479. }
  480. if (isset($id->published))
  481. {
  482. $is_published = is_true_val($id->published);
  483. }
  484. else if (isset($id->active))
  485. {
  486. $is_published = is_true_val($id->active);
  487. }
  488. }
  489. else
  490. {
  491. $ref_id = $id;
  492. }
  493. $mod = $CI->fuel->modules->get($module, FALSE);
  494. if ( ! empty($mod))
  495. {
  496. $module = $mod->info('module_uri');
  497. $permission = $mod->info('permission');
  498. }
  499. $marker['id'] = $ref_id;
  500. $marker['label'] = $label;
  501. $marker['module'] = $module;
  502. $marker['permission'] = $permission;
  503. $marker['published'] = $is_published;
  504. $marker['xoffset'] = $xoffset;
  505. $marker['yoffset'] = $yoffset;
  506. $key = $page->add_marker($marker);
  507. return '<!--' . $key . '-->';
  508. }
  509. return '';
  510. }
  511. }
  512. // --------------------------------------------------------------------
  513. if ( ! function_exists('fuel_cache_id'))
  514. {
  515. /**
  516. * Creates the cache ID for the fuel page based on the URI.
  517. *
  518. * If no <dfn>location</dfn> value is passed, it will default to the current <a href="<?=user_guide_url('my_url_helper')?>">uri_path</a>.
  519. *
  520. * @access public
  521. * @param string
  522. * @return string
  523. */
  524. function fuel_cache_id($location = NULL)
  525. {
  526. $CI =& get_instance();
  527. return $CI->fuel->cache->create_id($location);
  528. }
  529. }
  530. // --------------------------------------------------------------------
  531. if ( ! function_exists('fuel_url'))
  532. {
  533. /**
  534. * Creates the admin URL for FUEL (e.g. http://localhost/MY_PROJECT/fuel/admin)
  535. *
  536. * @access public
  537. * @param string
  538. * @param boolean
  539. * @return string
  540. */
  541. function fuel_url($uri = '', $query_string = FALSE)
  542. {
  543. $CI =& get_instance();
  544. $uri = fuel_uri($uri, $query_string);
  545. return site_url($uri, NULL, FALSE);
  546. }
  547. }
  548. // --------------------------------------------------------------------
  549. if ( ! function_exists('fuel_uri'))
  550. {
  551. /**
  552. * Returns the FUEL admin URI path
  553. *
  554. * @access public
  555. * @param string
  556. * @param boolean
  557. * @return string
  558. */
  559. function fuel_uri($uri = '', $query_string = FALSE)
  560. {
  561. $CI =& get_instance();
  562. if (is_bool($query_string) AND $query_string !== FALSE)
  563. {
  564. $query_string = $_GET;
  565. }
  566. $q = '';
  567. if ( ! empty($query_string))
  568. {
  569. if (is_array($query_string))
  570. {
  571. $q_str = http_build_query($query_string);
  572. if ( ! empty($q_str))
  573. {
  574. $q = '?' . $q_str;
  575. }
  576. }
  577. else if (is_string($query_string))
  578. {
  579. $q = (strncmp($query_string, '?', 1) !== 0) ? '?' . $query_string : $query_string;
  580. }
  581. }
  582. return $CI->fuel->config('fuel_path') . $uri . $q;
  583. }
  584. }
  585. // --------------------------------------------------------------------
  586. if ( ! function_exists('fuel_uri_segment'))
  587. {
  588. /**
  589. * Returns the uri segment based on the FUEL admin path
  590. *
  591. * @access public
  592. * @param int
  593. * @param boolean
  594. * @return string
  595. */
  596. function fuel_uri_segment($seg_index = 0, $rerouted = FALSE)
  597. {
  598. $CI =& get_instance();
  599. if ($rerouted)
  600. {
  601. return $CI->uri->rsegment(fuel_uri_index($seg_index));
  602. }
  603. else
  604. {
  605. return $CI->uri->segment(fuel_uri_index($seg_index));
  606. }
  607. }
  608. }
  609. // --------------------------------------------------------------------
  610. if ( ! function_exists('fuel_uri_index'))
  611. {
  612. /**
  613. * Returns the uri index number based on the FUEL admin path
  614. *
  615. * @access public
  616. * @param int
  617. * @return int
  618. */
  619. function fuel_uri_index($seg_index = 0)
  620. {
  621. $CI =& get_instance();
  622. $fuel_path = $CI->fuel->config('fuel_path');
  623. $start_index = count(explode('/', $fuel_path)) - 1;
  624. return $start_index + $seg_index;
  625. }
  626. }
  627. // --------------------------------------------------------------------
  628. if ( ! function_exists('fuel_uri_string'))
  629. {
  630. /**
  631. * Returns the uri string based on the FUEL admin path
  632. *
  633. * @access public
  634. * @param int
  635. * @param int
  636. * @param boolean
  637. * @return string
  638. */
  639. function fuel_uri_string($from = 0, $to = NULL, $rerouted = FALSE)
  640. {
  641. $CI =& get_instance();
  642. $fuel_index = fuel_uri_index($from);
  643. if ($rerouted)
  644. {
  645. $segs = $CI->uri->rsegment_array($fuel_index);
  646. }
  647. else
  648. {
  649. $segs = $CI->uri->segment_array($fuel_index);
  650. }
  651. $from = fuel_uri_index($from);
  652. if (isset($to))
  653. {
  654. $to = fuel_uri_index($to);
  655. if ($from < $to)
  656. {
  657. $to = $from;
  658. }
  659. }
  660. else
  661. {
  662. $to = sizeof($segs);
  663. }
  664. $segs = array_slice($segs, $from, $to);
  665. $uri = implode('/', $segs);
  666. return $uri;
  667. }
  668. }
  669. // --------------------------------------------------------------------
  670. if ( ! function_exists('is_fuelified'))
  671. {
  672. /**
  673. * Check to see if you are logged in and can use inline editing
  674. *
  675. * @access public
  676. * @return boolean
  677. */
  678. function is_fuelified()
  679. {
  680. $CI =& get_instance();
  681. return $CI->fuel->auth->is_fuelified();
  682. }
  683. }
  684. // --------------------------------------------------------------------
  685. if ( ! function_exists('in_fuel_admin'))
  686. {
  687. /**
  688. * Check to see if you are in the FUEL admin
  689. *
  690. * @access public
  691. * @return boolean
  692. */
  693. function in_fuel_admin()
  694. {
  695. return (defined('FUEL_ADMIN') AND FUEL_ADMIN === TRUE);
  696. }
  697. }
  698. // --------------------------------------------------------------------
  699. if ( ! function_exists('fuel_user_lang'))
  700. {
  701. /**
  702. * Returns the user language of the person logged in... used for inline editing
  703. *
  704. * @access public
  705. * @return string
  706. */
  707. function fuel_user_lang()
  708. {
  709. $CI =& get_instance();
  710. return $CI->fuel->auth->user_lang();
  711. }
  712. }
  713. // --------------------------------------------------------------------
  714. if ( ! function_exists('fuel_settings'))
  715. {
  716. /**
  717. * Returns the setting(s) for a particular module
  718. *
  719. * @access public
  720. * @param string Module name
  721. * @param string Settings key (optional)
  722. * @return mixed
  723. */
  724. function fuel_settings($module, $key = '')
  725. {
  726. $CI =& get_instance();
  727. return $CI->fuel->settings->get($module, $key);
  728. }
  729. }
  730. /* End of file fuel_helper.php */
  731. /* Location: ./modules/fuel/helpers/fuel_helper.php */