PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/system/expressionengine/libraries/Cp.php

https://bitbucket.org/tdevonshire/hoolux
PHP | 994 lines | 533 code | 177 blank | 284 comment | 58 complexity | efdf22f6f363d59d105f95868444eca2 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2012, EllisLab, Inc.
  8. * @license http://ellislab.com/expressionengine/user-guide/license.html
  9. * @link http://ellislab.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine CP Class
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Core
  19. * @category Core
  20. * @author EllisLab Dev Team
  21. * @link http://ellislab.com
  22. */
  23. class Cp {
  24. var $cp_theme = '';
  25. var $cp_theme_url = ''; // base URL to the CP theme folder
  26. var $xid_ttl = 14400;
  27. var $installed_modules = FALSE;
  28. var $its_all_in_your_head = array();
  29. var $footer_item = array();
  30. var $requests = array();
  31. var $loaded = array();
  32. var $js_files = array(
  33. 'ui' => array(),
  34. 'plugin' => array(),
  35. 'file' => array(),
  36. 'package' => array(),
  37. 'fp_module' => array()
  38. );
  39. /**
  40. * Constructor
  41. *
  42. */
  43. function __construct()
  44. {
  45. $this->EE =& get_instance();
  46. if ($this->EE->router->fetch_class() == 'ee')
  47. {
  48. show_error("The CP library is only available on Control Panel requests.");
  49. }
  50. // Cannot set these in the installer
  51. if ( ! defined('EE_APPPATH'))
  52. {
  53. $this->cp_theme = ( ! $this->EE->session->userdata('cp_theme')) ? $this->EE->config->item('cp_theme') : $this->EE->session->userdata('cp_theme');
  54. $this->cp_theme_url = $this->EE->config->slash_item('theme_folder_url').'cp_themes/'.$this->cp_theme.'/';
  55. $this->EE->load->vars(array(
  56. 'cp_theme_url' => $this->cp_theme_url
  57. ));
  58. }
  59. // Make sure all requests to iframe the CP are denied
  60. $this->EE->output->set_header('X-Frame-Options: SameOrigin');
  61. }
  62. // --------------------------------------------------------------------
  63. /**
  64. * Set Certain Default Control Panel View Variables
  65. *
  66. * @access public
  67. * @return void
  68. */
  69. function set_default_view_variables()
  70. {
  71. $js_folder = ($this->EE->config->item('use_compressed_js') == 'n') ? 'src' : 'compressed';
  72. $langfile = substr($this->EE->router->class, 0, strcspn($this->EE->router->class, '_'));
  73. // Javascript Path Constants
  74. define('PATH_JQUERY', PATH_THEMES.'javascript/'.$js_folder.'/jquery/');
  75. define('PATH_JAVASCRIPT', PATH_THEMES.'javascript/'.$js_folder.'/');
  76. define('JS_FOLDER', $js_folder);
  77. $this->EE->load->library('menu');
  78. $this->EE->load->library('accessories');
  79. $this->EE->load->library('javascript', array('autoload' => FALSE));
  80. $this->EE->load->model('member_model'); // for screen_name, quicklinks
  81. $this->EE->lang->loadfile($langfile);
  82. // Success/failure messages
  83. $cp_messages = array();
  84. foreach(array('message_success', 'message_notice', 'message_error', 'message_failure') as $flash_key)
  85. {
  86. if ($message = $this->EE->session->flashdata($flash_key))
  87. {
  88. $flash_key = ($flash_key == 'message_failure') ? 'error' : substr($flash_key, 8);
  89. $cp_messages[$flash_key] = $message;
  90. }
  91. }
  92. $cp_table_template = array(
  93. 'table_open' => '<table class="mainTable" border="0" cellspacing="0" cellpadding="0">'
  94. );
  95. $cp_pad_table_template = array(
  96. 'table_open' => '<table class="mainTable padTable" border="0" cellspacing="0" cellpadding="0">'
  97. );
  98. $user_q = $this->EE->member_model->get_member_data(
  99. $this->EE->session->userdata('member_id'),
  100. array(
  101. 'screen_name', 'notepad', 'quick_links',
  102. 'avatar_filename', 'avatar_width', 'avatar_height'
  103. )
  104. );
  105. $notepad_content = ($user_q->row('notepad')) ? $user_q->row('notepad') : '';
  106. // Global view variables
  107. $vars = array(
  108. 'cp_page_onload' => '',
  109. 'cp_page_title' => '',
  110. 'cp_breadcrumbs' => array(),
  111. 'cp_right_nav' => array(),
  112. 'cp_messages' => $cp_messages,
  113. 'cp_notepad_content' => $notepad_content,
  114. 'cp_table_template' => $cp_table_template,
  115. 'cp_pad_table_template' => $cp_pad_table_template,
  116. 'cp_theme_url' => $this->cp_theme_url,
  117. 'cp_current_site_label' => $this->EE->config->item('site_name'),
  118. 'cp_screen_name' => $user_q->row('screen_name'),
  119. 'cp_avatar_path' => $user_q->row('avatar_filename') ? $this->EE->config->slash_item('avatar_url').$user_q->row('avatar_filename') : '',
  120. 'cp_avatar_width' => $user_q->row('avatar_filename') ? $user_q->row('avatar_width') : '',
  121. 'cp_avatar_height' => $user_q->row('avatar_filename') ? $user_q->row('avatar_height') : '',
  122. 'cp_quicklinks' => $this->_get_quicklinks($user_q->row('quick_links')),
  123. 'EE_view_disable' => FALSE,
  124. 'is_super_admin' => ($this->EE->session->userdata['group_id'] == 1) ? TRUE : FALSE, // for conditional use in view files
  125. // Menu
  126. 'cp_menu_items' => $this->EE->menu->generate_menu(),
  127. 'cp_accessories' => $this->EE->accessories->generate_accessories(),
  128. // Sidebar state (overwritten below if needed)
  129. 'sidebar_state' => '',
  130. 'maincontent_state' => '',
  131. );
  132. // global table data
  133. $this->EE->session->set_cache('table', 'cp_template', $cp_table_template);
  134. $this->EE->session->set_cache('table', 'cp_pad_template', $cp_pad_table_template);
  135. if (isset($this->EE->table))
  136. {
  137. // @todo We have a code order issue with accessories.
  138. // If an accessory changed the table template (this happens
  139. // a lot due to differences in design), we set up the CP
  140. // template. Otherwise this is set in the table lib constructor.
  141. $this->EE->table->set_template($cp_table_template);
  142. }
  143. // we need these paths again in my account, so we'll keep track of them
  144. // kind of hacky, but before it was accessing _ci_cache_vars, which is worse
  145. $this->EE->session->set_cache('cp_sidebar', 'cp_avatar_path', $vars['cp_avatar_path'])
  146. ->set_cache('cp_sidebar', 'cp_avatar_width', $vars['cp_avatar_width'])
  147. ->set_cache('cp_sidebar', 'cp_avatar_height', $vars['cp_avatar_height']);
  148. $css_paths = array(
  149. PATH_CP_THEME.$this->cp_theme.'/',
  150. PATH_CP_THEME.'default/'
  151. );
  152. if ($this->cp_theme !== 'default')
  153. {
  154. array_shift($css_paths);
  155. }
  156. foreach ($css_paths as $a_path)
  157. {
  158. $file = $a_path.'css/advanced.css';
  159. if (file_exists($file))
  160. {
  161. break;
  162. }
  163. }
  164. $vars['advanced_css_mtime'] = (file_exists($file)) ? filemtime($file) : FALSE;
  165. if ($this->EE->router->method != 'index')
  166. {
  167. $this->set_breadcrumb(BASE.AMP.'C='.$this->EE->router->class, lang($this->EE->router->class));
  168. }
  169. if ($this->EE->session->userdata('show_sidebar') == 'n')
  170. {
  171. $vars['sidebar_state'] = ' style="display:none"';
  172. $vars['maincontent_state'] = ' style="width:100%; display:block"';
  173. }
  174. // The base javascript variables that will be available globally through EE.varname
  175. // this really could be made easier - ideally it would show up right below the main
  176. // jQuery script tag - before the plugins, so that it has access to jQuery.
  177. // If you use it in your js, please uniquely identify your variables - or create
  178. // another object literal:
  179. // Bad: EE.test = "foo";
  180. // Good: EE.unique_foo = "bar"; EE.unique = { foo : "bar"};
  181. $js_lang_keys = array(
  182. 'logout_confirm' => lang('logout_confirm'),
  183. 'logout' => lang('logout'),
  184. 'search' => lang('search'),
  185. 'session_timeout' => lang('session_timeout')
  186. );
  187. /* -------------------------------------------
  188. /* Hidden Configuration Variable
  189. /* - login_reminder => y/n to turn the CP Login Reminder On or Off. Default is 'y'
  190. /* -------------------------------------------*/
  191. if ($this->EE->config->item('login_reminder') != 'n')
  192. {
  193. $js_lang_keys['session_expiring'] = lang('session_expiring');
  194. $js_lang_keys['username'] = lang('username');
  195. $js_lang_keys['password'] = lang('password');
  196. $js_lang_keys['login'] = lang('login');
  197. $this->EE->javascript->set_global(array(
  198. 'SESS_TIMEOUT' => $this->EE->session->cpan_session_len * 1000,
  199. 'XID_TIMEOUT' => $this->xid_ttl * 1000,
  200. 'SESS_TYPE' => $this->EE->config->item('admin_session_type')
  201. ));
  202. }
  203. $this->EE->javascript->set_global(array(
  204. 'BASE' => str_replace(AMP, '&', BASE),
  205. 'XID' => XID_SECURE_HASH,
  206. 'PATH_CP_GBL_IMG' => PATH_CP_GBL_IMG,
  207. 'CP_SIDEBAR_STATE' => $this->EE->session->userdata('show_sidebar'),
  208. //'flashdata' => $this->EE->session->flashdata,
  209. 'username' => $this->EE->session->userdata('username'),
  210. 'router_class' => $this->EE->router->class, // advanced css
  211. 'lang' => $js_lang_keys,
  212. 'THEME_URL' => $this->cp_theme_url
  213. ));
  214. // Combo-load the javascript files we need for every request
  215. $js_scripts = array(
  216. 'effect' => 'core',
  217. 'ui' => array('core', 'widget', 'mouse', 'position', 'sortable', 'dialog'),
  218. 'plugin' => array('ee_focus', 'ee_interact.event', 'ee_notice', 'ee_txtarea', 'tablesorter', 'ee_toggle_all'),
  219. 'file' => 'cp/global_start'
  220. );
  221. if ($this->cp_theme != 'mobile')
  222. {
  223. $js_scripts['plugin'][] = 'ee_navigation';
  224. }
  225. $this->add_js_script($js_scripts);
  226. $this->_seal_combo_loader();
  227. $this->EE->load->vars($vars);
  228. $this->EE->javascript->compile();
  229. }
  230. // --------------------------------------------------------------------
  231. /**
  232. * Mask URL.
  233. *
  234. * To be used to create url's that "mask" the real location of the
  235. * users control panel. Eg: http://example.com/index.php?URL=http://example2.com
  236. *
  237. * @access public
  238. * @param string URL
  239. * @return string Masked URL
  240. */
  241. function masked_url($url)
  242. {
  243. return $this->EE->functions->fetch_site_index(0,0).QUERY_MARKER.'URL='.urlencode($url);
  244. }
  245. // --------------------------------------------------------------------
  246. /**
  247. * Add JS Script
  248. *
  249. * Adds a javascript file to the javascript combo loader
  250. *
  251. * @access public
  252. * @param array - associative array of
  253. */
  254. function add_js_script($script = array(), $in_footer = TRUE)
  255. {
  256. if ( ! is_array($script))
  257. {
  258. if (is_bool($in_footer))
  259. {
  260. return FALSE;
  261. }
  262. $script = array($script => $in_footer);
  263. $in_footer = TRUE;
  264. }
  265. if ( ! $in_footer)
  266. {
  267. return $this->its_all_in_your_head = array_merge($this->its_all_in_your_head, $script);
  268. }
  269. foreach ($script as $type => $file)
  270. {
  271. if ( ! is_array($file))
  272. {
  273. $file = array($file);
  274. }
  275. if (array_key_exists($type, $this->js_files))
  276. {
  277. $this->js_files[$type] = array_merge($this->js_files[$type], $file);
  278. }
  279. else
  280. {
  281. $this->js_files[$type] = $file;
  282. }
  283. }
  284. return $this->js_files;
  285. }
  286. // --------------------------------------------------------------------
  287. /**
  288. * Render Footer Javascript
  289. *
  290. * @access public
  291. * @return string
  292. */
  293. function render_footer_js()
  294. {
  295. // add global end file
  296. $this->_seal_combo_loader();
  297. $this->add_js_script('file', 'cp/global_end');
  298. $str = '';
  299. $requests = $this->_seal_combo_loader();
  300. foreach($requests as $req)
  301. {
  302. $str .= '<script type="text/javascript" charset="utf-8" src="'.BASE.AMP.'C=javascript'.AMP.'M=combo_load'.$req.'"></script>';
  303. }
  304. if ($this->EE->extensions->active_hook('cp_js_end') === TRUE)
  305. {
  306. $str .= '<script type="text/javascript" src="'.BASE.AMP.'C=javascript'.AMP.'M=load'.AMP.'file=ext_scripts"></script>';
  307. }
  308. return $str;
  309. }
  310. // --------------------------------------------------------------------
  311. /**
  312. * Seal the current combo loader and reopen a new one.
  313. *
  314. * @access private
  315. * @return array
  316. */
  317. function _seal_combo_loader()
  318. {
  319. $str = '';
  320. $mtimes = array();
  321. $this->js_files = array_map('array_unique', $this->js_files);
  322. foreach ($this->js_files as $type => $files)
  323. {
  324. if (isset($this->loaded[$type]))
  325. {
  326. $files = array_diff($files, $this->loaded[$type]);
  327. }
  328. if (count($files))
  329. {
  330. $mtimes[] = $this->_get_js_mtime($type, $files);
  331. $str .= AMP.$type.'='.implode(',', $files);
  332. }
  333. }
  334. if ($str)
  335. {
  336. $this->loaded = array_merge_recursive($this->loaded, $this->js_files);
  337. $this->js_files = array(
  338. 'ui' => array(),
  339. 'plugin' => array(),
  340. 'file' => array(),
  341. 'package' => array(),
  342. 'fp_module' => array()
  343. );
  344. $this->requests[] = $str.AMP.'v='.max($mtimes);
  345. }
  346. return $this->requests;
  347. }
  348. // --------------------------------------------------------------------
  349. /**
  350. * Get last modification time of a js file.
  351. * Returns highest if passed an array.
  352. *
  353. * @access private
  354. * @param string
  355. * @param mixed
  356. * @return int
  357. */
  358. function _get_js_mtime($type, $name)
  359. {
  360. if (is_array($name))
  361. {
  362. $mtimes = array();
  363. foreach($name as $file)
  364. {
  365. $mtimes[] = $this->_get_js_mtime($type, $file);
  366. }
  367. return max($mtimes);
  368. }
  369. $folder = $this->EE->config->item('use_compressed_js') == 'n' ? 'src' : 'compressed';
  370. switch($type)
  371. {
  372. case 'ui': $file = PATH_THEMES.'javascript/'.$folder.'/jquery/ui/jquery.ui.'.$name.'.js';
  373. break;
  374. case 'plugin': $file = PATH_THEMES.'javascript/'.$folder.'/jquery/plugins/'.$name.'.js';
  375. break;
  376. case 'file': $file = PATH_THEMES.'javascript/'.$folder.'/'.$name.'.js';
  377. break;
  378. case 'package': $file = PATH_THIRD.$name.'/javascript/'.$name.'.js';
  379. break;
  380. case 'fp_module': $file = PATH_MOD.$name.'/javascript/'.$name.'.js';
  381. break;
  382. default:
  383. return 0;
  384. }
  385. return file_exists($file) ? filemtime($file) : 0;
  386. }
  387. // --------------------------------------------------------------------
  388. /**
  389. * Set the right navigation
  390. *
  391. * @access public
  392. * @param array
  393. * @param string
  394. * @return int
  395. */
  396. function set_right_nav($nav = array())
  397. {
  398. $this->EE->load->vars('cp_right_nav', array_reverse($nav));
  399. }
  400. // --------------------------------------------------------------------
  401. /**
  402. * Set the right navigation
  403. *
  404. * @access public
  405. * @param array
  406. * @param string
  407. * @return int
  408. */
  409. function set_action_nav($nav = array())
  410. {
  411. $this->EE->load->vars('cp_action_nav', array_reverse($nav));
  412. }
  413. // --------------------------------------------------------------------
  414. /**
  415. * Updates saved publish layouts
  416. *
  417. * @access public
  418. * @param array
  419. * @return bool
  420. */
  421. function delete_layout_tabs($tabs = array(), $namespace = '', $channel_id = array())
  422. {
  423. $this->EE->load->library('layout');
  424. return $this->EE->layout->delete_layout_tabs($tabs, $namespace, $channel_id);
  425. }
  426. // --------------------------------------------------------------------
  427. /**
  428. * Deprecated Add new tabs and associated fields to saved publish layouts
  429. *
  430. * @access public
  431. * @param array
  432. * @return bool
  433. */
  434. function add_layout_tabs($tabs = array(), $namespace = '', $channel_id = array())
  435. {
  436. $this->EE->load->library('logger');
  437. $this->EE->logger->deprecated(NULL, 'Layout::add_layout_tabs()');
  438. $this->EE->load->library('layout');
  439. $this->EE->layout->add_layout_tabs($tabs, $namespace, $channel_id);
  440. }
  441. // --------------------------------------------------------------------
  442. /**
  443. * Deprecated Adds new fields to the saved publish layouts, creating the default tab if required
  444. *
  445. * @access public
  446. * @param array
  447. * @param int
  448. * @return bool
  449. */
  450. function add_layout_fields($tabs = array(), $channel_id = array())
  451. {
  452. $this->EE->load->library('logger');
  453. $this->EE->logger->deprecated(NULL, 'Layout::add_layout_fields()');
  454. $this->EE->load->library('layout');
  455. return $this->EE->layout->add_layout_fields($tabs, $channel_id);
  456. }
  457. // --------------------------------------------------------------------
  458. /**
  459. * Deprecated Deletes fields from the saved publish layouts
  460. *
  461. * @access public
  462. * @param array or string
  463. * @param int
  464. * @return bool
  465. */
  466. function delete_layout_fields($tabs, $channel_id = array())
  467. {
  468. $this->EE->load->library('layout');
  469. return $this->EE->layout->delete_layout_fields($tabs, $channel_id);
  470. }
  471. // --------------------------------------------------------------------
  472. /**
  473. * URL to the current page unless POST data exists - in which case it
  474. * goes to the root controller. To use the result, prefix it with BASE.AMP
  475. *
  476. * @access public
  477. * @return string
  478. */
  479. function get_safe_refresh()
  480. {
  481. static $url = '';
  482. if ( ! $url)
  483. {
  484. $go_to_c = (count($_POST) > 0);
  485. $page = '';
  486. foreach($_GET as $key => $val)
  487. {
  488. if ($key == 'S' OR $key == 'D' OR ($go_to_c && $key != 'C'))
  489. {
  490. continue;
  491. }
  492. $page .= $key.'='.$val.AMP;
  493. }
  494. if (strlen($page) > 4 && substr($page, -5) == AMP)
  495. {
  496. $page = substr($page, 0, -5);
  497. }
  498. $url = $page;
  499. }
  500. return $url;
  501. }
  502. // --------------------------------------------------------------------
  503. /**
  504. * Get Quicklinks
  505. *
  506. * Does a lookup for quick links. Based on the URL we determine if it is external or not
  507. *
  508. * @access private
  509. * @return array
  510. */
  511. function _get_quicklinks($quick_links)
  512. {
  513. $i = 1;
  514. $quicklinks = array();
  515. if (count($quick_links) != 0 && $quick_links != '')
  516. {
  517. foreach (explode("\n", $quick_links) as $row)
  518. {
  519. $x = explode('|', $row);
  520. $quicklinks[$i]['title'] = (isset($x[0])) ? $x[0] : '';
  521. $quicklinks[$i]['link'] = (isset($x[1])) ? $x[1] : '';
  522. $quicklinks[$i]['order'] = (isset($x[2])) ? $x[2] : '';
  523. $i++;
  524. }
  525. }
  526. $quick_links = $quicklinks;
  527. $len = strlen($this->EE->config->item('cp_url'));
  528. $link = array();
  529. $count = 0;
  530. foreach ($quick_links as $ql)
  531. {
  532. if (strncmp($ql['link'], $this->EE->config->item('cp_url'), $len) == 0)
  533. {
  534. $l = str_replace($this->EE->config->item('cp_url'), '', $ql['link']);
  535. $l = preg_replace('/\?S=[a-zA-Z0-9]+&D=cp&/', '', $l);
  536. $link[$count] = array(
  537. 'link' => BASE.AMP.$l,
  538. 'title' => $ql['title'],
  539. 'external' => FALSE
  540. );
  541. }
  542. else
  543. {
  544. $link[$count] = array(
  545. 'link' => $ql['link'],
  546. 'title' => $ql['title'],
  547. 'external' => TRUE
  548. );
  549. }
  550. $count++;
  551. }
  552. return $link;
  553. }
  554. // --------------------------------------------------------------------
  555. /**
  556. * Abstracted Way to Add a Page Variable
  557. *
  558. * @access public
  559. * @return void
  560. */
  561. function set_variable($name, $value)
  562. {
  563. $this->EE->load->vars(array($name => $value));
  564. }
  565. // --------------------------------------------------------------------
  566. /**
  567. * Abstracted Way to Add a Breadcrumb Links
  568. *
  569. * @access public
  570. * @return void
  571. */
  572. function set_breadcrumb($link, $title)
  573. {
  574. static $_crumbs = array();
  575. $_crumbs[$link] = $title;
  576. $this->EE->load->vars(array('cp_breadcrumbs' => $_crumbs));
  577. }
  578. // --------------------------------------------------------------------
  579. /**
  580. * Validate and Enable Secure Forms for the Control Panel
  581. *
  582. * @access public
  583. * @return void
  584. */
  585. function secure_forms()
  586. {
  587. $hash = '';
  588. if ($this->EE->config->item('secure_forms') == 'y')
  589. {
  590. if (count($_POST) > 0)
  591. {
  592. if ( ! isset($_POST['XID'])
  593. OR ! $this->EE->security->secure_forms_check($_POST['XID']))
  594. {
  595. $this->EE->functions->redirect(BASE);
  596. }
  597. unset($_POST['XID']);
  598. }
  599. $hash = $this->EE->security->generate_xid();
  600. }
  601. define('XID_SECURE_HASH', $hash);
  602. }
  603. // --------------------------------------------------------------------
  604. /**
  605. * Fetch CP Themes
  606. *
  607. * Fetch control panel themes
  608. *
  609. * @access public
  610. * @param string
  611. * @return string
  612. */
  613. function fetch_cp_themes()
  614. {
  615. $this->EE->load->model('admin_model');
  616. return $this->EE->admin_model->get_cp_theme_list();
  617. }
  618. // --------------------------------------------------------------------
  619. /**
  620. * Load Package JS
  621. *
  622. * Load a javascript file from a package
  623. *
  624. * @access public
  625. * @param string
  626. * @return void
  627. */
  628. function load_package_js($file)
  629. {
  630. $current_top_path = $this->EE->load->first_package_path();
  631. $package = trim(str_replace(array(PATH_THIRD, 'views'), '', $current_top_path), '/');
  632. $this->EE->jquery->plugin(BASE.AMP.'C=javascript'.AMP.'M=load'.AMP.'package='.$package.AMP.'file='.$file, TRUE);
  633. }
  634. // --------------------------------------------------------------------
  635. /**
  636. * Load Package CSS
  637. *
  638. * Load a stylesheet from a package
  639. *
  640. * @access public
  641. * @param string
  642. * @return void
  643. */
  644. function load_package_css($file)
  645. {
  646. $current_top_path = $this->EE->load->first_package_path();
  647. $package = trim(str_replace(array(PATH_THIRD, 'views'), '', $current_top_path), '/');
  648. $url = BASE.AMP.'C=css'.AMP.'M=third_party'.AMP.'package='.$package.AMP.'file='.$file;
  649. $this->add_to_head('<link type="text/css" rel="stylesheet" href="'.$url.'" />');
  650. }
  651. // --------------------------------------------------------------------
  652. /**
  653. * Add Header Data
  654. *
  655. * Add any string to the <head> tag
  656. *
  657. * @access public
  658. * @param string
  659. * @return string
  660. */
  661. function add_to_head($data)
  662. {
  663. $this->its_all_in_your_head[] = $data;
  664. }
  665. // --------------------------------------------------------------------
  666. /**
  667. * Add Footer Data
  668. *
  669. * Add any string above the </body> tag
  670. *
  671. * @access public
  672. * @param string
  673. * @return string
  674. */
  675. function add_to_foot($data)
  676. {
  677. $this->footer_item[] = $data;
  678. }
  679. // --------------------------------------------------------------------
  680. /**
  681. * Allowed Group
  682. *
  683. * Member access validation
  684. *
  685. * @access public
  686. * @param string
  687. * @return bool
  688. */
  689. function allowed_group()
  690. {
  691. $which = func_get_args();
  692. if ( ! count($which))
  693. {
  694. return FALSE;
  695. }
  696. // Super Admins always have access
  697. if ($this->EE->session->userdata('group_id') == 1)
  698. {
  699. return TRUE;
  700. }
  701. foreach ($which as $w)
  702. {
  703. $k = $this->EE->session->userdata($w);
  704. if ( ! $k OR $k !== 'y')
  705. {
  706. return FALSE;
  707. }
  708. }
  709. return TRUE;
  710. }
  711. // --------------------------------------------------------------------
  712. /**
  713. * Is Module Installed?
  714. *
  715. * Returns array of installed modules.
  716. *
  717. * @access public
  718. * @return array
  719. */
  720. function get_installed_modules()
  721. {
  722. if ( ! is_array($this->installed_modules))
  723. {
  724. $this->installed_modules = array();
  725. $this->EE->db->select('LOWER(module_name) AS name');
  726. $this->EE->db->order_by('module_name');
  727. $query = $this->EE->db->get('modules');
  728. if ($query->num_rows())
  729. {
  730. foreach($query->result_array() as $row)
  731. {
  732. $this->installed_modules[$row['name']] = $row['name'];
  733. }
  734. }
  735. }
  736. return $this->installed_modules;
  737. }
  738. // --------------------------------------------------------------------
  739. /**
  740. * Invalid Custom Field Names
  741. *
  742. * Tracks "reserved" words to avoid variable name collision
  743. *
  744. * @access public
  745. * @return array
  746. */
  747. function invalid_custom_field_names()
  748. {
  749. static $invalid_fields = array();
  750. if ( ! empty($invalid_fields))
  751. {
  752. return $invalid_fields;
  753. }
  754. $channel_vars = array(
  755. 'aol_im', 'author', 'author_id', 'avatar_image_height',
  756. 'avatar_image_width', 'avatar_url', 'bday_d', 'bday_m',
  757. 'bday_y', 'bio', 'comment_auto_path',
  758. 'comment_entry_id_auto_path',
  759. 'comment_total', 'comment_url_title_path', 'count',
  760. 'edit_date', 'email', 'entry_date', 'entry_id',
  761. 'entry_id_path', 'expiration_date', 'forum_topic_id',
  762. 'gmt_edit_date', 'gmt_entry_date', 'icq', 'interests',
  763. 'ip_address', 'location', 'member_search_path', 'month',
  764. 'msn_im', 'occupation', 'permalink', 'photo_image_height',
  765. 'photo_image_width', 'photo_url', 'profile_path',
  766. 'recent_comment_date', 'relative_date', 'relative_url',
  767. 'screen_name', 'signature', 'signature_image_height',
  768. 'signature_image_url', 'signature_image_width', 'status',
  769. 'switch', 'title', 'title_permalink', 'total_results',
  770. 'trimmed_url', 'url', 'url_as_email_as_link', 'url_or_email',
  771. 'url_or_email_as_author', 'url_title', 'url_title_path',
  772. 'username', 'channel', 'channel_id', 'yahoo_im', 'year'
  773. );
  774. $global_vars = array(
  775. 'app_version', 'captcha', 'charset', 'current_time',
  776. 'debug_mode', 'elapsed_time', 'email', 'embed', 'encode',
  777. 'group_description', 'group_id', 'gzip_mode', 'hits',
  778. 'homepage', 'ip_address', 'ip_hostname', 'lang', 'location',
  779. 'member_group', 'member_id', 'member_profile_link', 'path',
  780. 'private_messages', 'screen_name', 'site_index', 'site_name',
  781. 'site_url', 'stylesheet', 'total_comments', 'total_entries',
  782. 'total_forum_posts', 'total_forum_topics', 'total_queries',
  783. 'username', 'webmaster_email', 'version'
  784. );
  785. $orderby_vars = array(
  786. 'comment_total', 'date', 'edit_date', 'expiration_date',
  787. 'most_recent_comment', 'random', 'screen_name', 'title',
  788. 'url_title', 'username', 'view_count_four', 'view_count_one',
  789. 'view_count_three', 'view_count_two'
  790. );
  791. $invalid_fields = array_unique(array_merge($channel_vars, $global_vars, $orderby_vars));
  792. return $invalid_fields;
  793. }
  794. // --------------------------------------------------------------------
  795. /**
  796. * Fetch Action IDs
  797. *
  798. * @access public
  799. * @param string
  800. * @param string
  801. * @return mixed
  802. */
  803. function fetch_action_id($class, $method)
  804. {
  805. $this->EE->db->select('action_id');
  806. $this->EE->db->where('class', $class);
  807. $this->EE->db->where('method', $method);
  808. $query = $this->EE->db->get('actions');
  809. if ($query->num_rows() == 0)
  810. {
  811. return FALSE;
  812. }
  813. return $query->row('action_id');
  814. }
  815. }
  816. /* End of file Cp.php */
  817. /* Location: ./system/expressionengine/libraries/Cp.php */