PageRenderTime 56ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/mc/rt_missioncontrol_j15/lib/rtcore.class.php

https://github.com/bhar1red/anahita
PHP | 581 lines | 387 code | 127 blank | 67 comment | 87 complexity | 303ab57837b2e503562a42cf44cd864d MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version � 1.5.2 June 9, 2011
  4. * @author � �RocketTheme http://www.rockettheme.com
  5. * @copyright Copyright (C) 2007 - 2011 RocketTheme, LLC
  6. * @license � http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  7. */
  8. // no direct access
  9. defined('_JEXEC') or die('Restricted index access');
  10. define('_COOKIENAME', 'mc-redirect');
  11. class RTCore
  12. {
  13. var $document;
  14. var $language;
  15. var $session;
  16. var $basePath;
  17. var $adminPath;
  18. var $baseUrl;
  19. var $currentUrl;
  20. var $templateUrl;
  21. var $templateUrlAbsolute;
  22. var $templatePath;
  23. var $templateName;
  24. var $user;
  25. var $toolbar;
  26. var $toolbar_output;
  27. var $help;
  28. var $actions;
  29. var $first;
  30. var $bodytags;
  31. var $updateUrl;
  32. var $updateSlug;
  33. var $params;
  34. var $browser;
  35. var $_browser_params = array();
  36. function __construct()
  37. {
  38. require_once('rtbrowser.class.php');
  39. $this->checkRedirect();
  40. $this->browser = new RTBrowser();
  41. // some more init
  42. $this->basePath = JPATH_ROOT;
  43. $this->adminPath = $this->basePath . DS . 'administrator';
  44. $this->templateName = $this->_getCurrentAdminTemplate();
  45. $this->templatePath = $this->adminPath . DS . 'templates' . DS . $this->templateName;
  46. $this->templateUrl = $this->baseUrl . 'templates/' . $this->templateName;
  47. $this->templateUrlAbsolute = JURI::root(true) . '/administrator/' .$this->templateUrl;
  48. // Set the main class vars to match the call
  49. JHTML::_('behavior.mootools');
  50. $doc =& JFactory::getDocument();
  51. $this->document = $doc;
  52. $this->user =& JFactory::getUser();
  53. $this->language = $doc->language;
  54. $this->direction = $doc->direction;
  55. $this->session =& JFactory::getSession();
  56. $this->baseUrl = JURI::root(true) . "/";
  57. $uri = JURI::getInstance();
  58. $this->currentUrl = $uri->toString();
  59. $this->params = $this->getTemplateParams();
  60. // init and store toolbar
  61. }
  62. function initRenderer()
  63. {
  64. $this->_initToolbar();
  65. $this->toolbar_output = $this->toolbar->render('toolbar');
  66. $this->_injectClasses();
  67. }
  68. function getTemplateParams() {
  69. include_once('rtparameter.php');
  70. if (file_exists($this->templatePath.DS.'params.ini'))
  71. $paramsdata = file_get_contents($this->templatePath.DS.'params.ini');
  72. else
  73. $paramsdata = null;
  74. $paramsdefs = $this->templatePath.DS.'templateDetails.xml';
  75. $params = new RTParameter( $paramsdata, $paramsdefs );
  76. return $params;
  77. }
  78. /* ------ Stylesheet Funcitons ----------- */
  79. function addStyle($filename = '')
  80. {
  81. if (is_array($filename)) return RTCore::addStyles($filename);
  82. return $this->_parseBrowserFromName($filename, 'css');
  83. }
  84. function addStyles($styles = array())
  85. {
  86. foreach ($styles as $style) RTCore::addStyle($style);
  87. }
  88. function addInlineStyle($css = '')
  89. {
  90. $doc =& $this->document;
  91. return $doc->addStyleDeclaration($css);
  92. }
  93. /* ------ Script Funcitons ----------- */
  94. function addScript($filename = '')
  95. {
  96. if (is_array($filename)) return RTCore::addScripts($filename);
  97. return $this->_parseBrowserFromName(RTCore::getMooScriptVersion($filename), 'js');
  98. }
  99. function addScripts($scripts = array())
  100. {
  101. foreach ($scripts as $script) RTCore::addScript($script);
  102. }
  103. function addInlineScript($js = '')
  104. {
  105. $doc =& $this->document;
  106. return $doc->addScriptDeclaration($js);
  107. }
  108. function getMooScriptVersion($filename) {
  109. global $moo_override;
  110. if (true || JPluginHelper::isEnabled('system', 'mtupgrade') || $moo_override) {
  111. return str_replace('.js','-mt1.2.js',$filename);
  112. } else {
  113. return $filename;
  114. }
  115. }
  116. function addOverrideStyles()
  117. {
  118. global $option;
  119. $override = 'override.css.php';
  120. $override_file = $this->templatePath . DS . 'overrides' . DS . $option . DS . $override;
  121. $override_url = $this->templateUrl . '/overrides/' . $option . '/' . $override;
  122. jimport('joomla.filesystem.file');
  123. if (JFile::exists($override_file)) {
  124. $this->document->addStylesheet($override_url);
  125. }
  126. }
  127. function processAjax()
  128. {
  129. if (JRequest::getString('process') == 'ajax' && JRequest::getString('model')) {
  130. $model = $this->getAjaxModel(JRequest::getString('model'));
  131. if ($model === false) die();
  132. include_once($model);
  133. exit;
  134. } else {
  135. return true;
  136. }
  137. return false;
  138. }
  139. function getAjaxModel($model_name)
  140. {
  141. $model_path = $this->templatePath . DS . 'ajax-models' . DS . $model_name . '.php';
  142. if (file_exists($model_path)) {
  143. return $model_path;
  144. } else {
  145. return false;
  146. }
  147. }
  148. function checkRedirect()
  149. {
  150. global $mainframe;
  151. $redirect = Jrequest::getVar(_COOKIENAME, '', 'COOKIE');
  152. if (isset($redirect) && $redirect != '') {
  153. setcookie(_COOKIENAME, '', time() - 3600);
  154. // $messages =& $mainframe->getMessageQueue();
  155. // if (strpos($redirect, 'com_login')===false
  156. // && empty($messages)
  157. // && strtolower(JRequest::getString('process')) != 'ajax')
  158. // $mainframe->redirect($redirect);
  159. }
  160. }
  161. function storeRedirect()
  162. {
  163. setcookie(_COOKIENAME, $this->_getCurrentPageURL());
  164. }
  165. function _injectClasses()
  166. {
  167. global $option;
  168. $task = JRequest::getString('task');
  169. $view = JRequest::getString('view');
  170. $buffer =& $this->document->_buffer['component'][''];
  171. $filter = "";
  172. jimport('joomla.filesystem.file');
  173. $override_replace = $this->templatePath . DS . 'overrides' . DS . $option . DS . 'injections-replace.php';
  174. $override_post = $this->templatePath . DS . 'overrides' . DS . $option . DS . 'injections-post.php';
  175. //use phpQuery
  176. if (!class_exists('phpQuery')) {
  177. require_once(dirname(__FILE__) . "/phpQuery.php");
  178. }
  179. // include any post pq injections for component
  180. if (JFile::exists($override_replace)) {
  181. include($override_replace);
  182. } else {
  183. $pq = phpQuery::newDocument($buffer);
  184. // add filter-table class for filter
  185. pq('form[name=adminForm] td:contains("Filter") > input[type=text]')->parents('table')->addClass('mc-filter-table');
  186. // add legend-table class for legend
  187. pq('form[name=adminForm] td:contains("toggle state")')->parents('table')->addClass('mc-legend-table');
  188. // add list table class for main list
  189. pq('table.adminlist ')->addClass('mc-list-table');
  190. // special cases
  191. pq('table.adminlist')->prev('table')->addClass('mc-filter-table');
  192. // edit forms
  193. pq('form[name=adminForm] fieldset.adminform:first')->parents('form[name=adminForm])')->wrapInner('<div class="mc-form-frame" />');
  194. pq('div.col:last')->addClass('mc-last-column');
  195. pq('form[name=adminForm] table.adminform table:not(".mc-filter-table")')->wrapAll('<div class="mc-form-frame mc-padding" />');
  196. pq('form[name=adminForm] > table.admintable,form[name=adminForm] > table.adminform')->wrapAll('<div class="mc-form-frame mc-padding" />');
  197. pq('table.mc-filter-table')->parent('div.mc-form-frame')->removeClass('mc-form-frame');
  198. pq('input#position.combobox')->wrapAll('<div class="mc-position-relative" />');
  199. //resize input fields
  200. //$inputfield = pq('form[name=adminForm]')->find(':input[size]');
  201. /* $size = intval($inputfield->attr('size') * 0.6);
  202. $inputfield->attr('size',$size);*/
  203. //$inputfield = pq('form[name=adminForm] table:not(".adminlist")')->find(':input[size], textarea[cols]');
  204. $inputfield = pq('form[name=adminForm] table:not(".adminlist")')->find(':input[size]');
  205. //$int = 1;
  206. foreach ($inputfield->elements as $obj) {
  207. //echo $int++.' ';
  208. $obj = pq($obj);
  209. //$width = $obj->attr('size') ? 'size' : 'cols';
  210. $width = 'size';
  211. //var_dump('before', (int) $obj->attr($width));
  212. $size = round((int)$obj->attr($width) * 0.6);
  213. //var_dump('after', $obj->attr($width) * 0.6, '---');
  214. $obj->attr($width, $size);
  215. }
  216. ;
  217. // generic first/last classes
  218. pq('form[name=adminForm] table:first,table.noshow table.mc-list-table')->addClass('mc-first-table');
  219. pq('form[name=adminForm] table.mc-first-table')->next('table')->addClass('mc-second-table');
  220. pq('form[name=adminForm] table.mc-first-table tr:first td:first,form[name=adminForm] table.mc-first-table tr:first th:first')->addClass('mc-first-cell');
  221. pq('form[name=adminForm] table.mc-first-table tr:first td:last,form[name=adminForm] table.mc-first-table tr:first th:last')->addClass('mc-last-cell');
  222. // non-list tables
  223. //$filter = pq('form[name=adminForm] table.adminform');
  224. //$filter->parents('table')->removeClass('mc-first-table')->addClass('mc-nolist-table');
  225. //$filter = pq('form[name=adminForm] fieldset table.admintable')->removeClass('mc-first-table');
  226. //save image
  227. // include any post pq injections for component
  228. if (JFile::exists($override_post)) {
  229. include($override_post);
  230. }
  231. $buffer = $pq->getDocument()->htmlOuter();
  232. }
  233. //$buffer = "...".$buffer;
  234. }
  235. function _initToolbar()
  236. {
  237. jimport('joomla.html.toolbar');
  238. require_once('rttoolbar.class.php');
  239. if ( KService::has('com:controller.toolbar') ) {
  240. $toolbar = KService::get('com:controller.toolbar');
  241. JFactory::getDocument()->setBuffer($toolbar->getTitle(), 'modules', 'title');
  242. $bar = JToolBar::getInstance('toolbar');
  243. foreach($toolbar->getCommands() as $command)
  244. {
  245. if (!$command->attribs->href ) {
  246. $command->attribs->href = '#';
  247. }
  248. $command->attribs->class = implode(" ", (array)KConfig::unbox($command->attribs->class));
  249. $command->attribs->class .= ' toolbar';
  250. $html = '<li>';
  251. $html .= ' <a '.KHelperArray::toString($command->attribs).'>';
  252. $html .= ' <span class="'.$command->icon.'" title="'.JText::_($command->title).'"></span>';
  253. $html .= JText::_($command->label);
  254. $html .= ' </a>';
  255. $html .= '</li>';
  256. $bar->appendButton('custom', $html,$command->id);
  257. }
  258. } else
  259. $bar = JToolBar::getInstance('toolbar');
  260. $toolbar = $bar;
  261. $newbar = array();
  262. $newhelp = array();
  263. $actions = array();
  264. $first = array();
  265. foreach ($toolbar->_bar as $button) {
  266. if (strtolower($button[0]) == 'help') {
  267. // $newhelp[] = $button;
  268. } elseif (strtolower($button[1]) == 'unarchive' or
  269. strtolower($button[1]) == 'archive' or
  270. strtolower($button[1]) == 'publish' or
  271. strtolower($button[1]) == 'unpublish' or
  272. strtolower($button[1]) == 'move' or
  273. strtolower($button[1]) == 'copy' or
  274. strtolower($button[1]) == 'trash') {
  275. $actions[] = $button;
  276. } else if (strtolower($button[1]) == 'new' or
  277. strtolower($button[1]) == 'apply' or
  278. strtolower($button[1]) == 'save') {
  279. $first[] = $button;
  280. } else {
  281. $newbar[] = $button;
  282. }
  283. }
  284. //create new toolbar object
  285. $toolbar = new RTToolbar('toolbar');
  286. //$toolbar->_buttonPath[0] = $this->basePath.DS.'libraries'.DS.'joomla'.DS.'html'.DS.'toolbar'.DS.'button';
  287. $toolbar->_bar = $newbar;
  288. $toolbar->_buttonPath = $bar->_buttonPath;
  289. $toolbar->_actions = $actions;
  290. $toolbar->_first = $first;
  291. $this->toolbar = $toolbar;
  292. $this->actions = $actions;
  293. $this->first = $first;
  294. //new help button
  295. $helpbar = new RTToolbar('help');
  296. //$helpbar->_buttonPath[0] = $this->basePath.DS.'libraries'.DS.'joomla'.DS.'html'.DS.'toolbar'.DS.'button';
  297. $helpbar->_bar = $newhelp;
  298. $this->help = $helpbar;
  299. }
  300. function _addListItem($item, $class = null, $link = null, $badge=null)
  301. {
  302. if ($item == '___') {$item = '';$class="divider";}
  303. if ($link != null) $item = '<a href="' . $link . '">' . $item . '</a>';
  304. if ($badge) $item .= $badge;
  305. if ($class == null) return $item;
  306. $chunk = array();
  307. $chunk[0] = $item;
  308. $chunk[1] = $class;
  309. return $chunk;
  310. }
  311. function _listify($list, $class = null)
  312. {
  313. if (isset($class)) $output = '<ul class="' . $class . '">';
  314. else $output = '<ul>';
  315. foreach ($list as $item) {
  316. if (is_array($item)) {
  317. $value = $item[0];
  318. $iclass = $item[1];
  319. } else {
  320. $value = $item;
  321. $iclass = null;
  322. }
  323. if (isset($iclass)) $output .= '<li class="' . $iclass . '">' . $value . '</li>';
  324. else $output .= '<li>' . $value . '</li>';
  325. }
  326. $output .= '</ul>';
  327. return $output;
  328. }
  329. /**
  330. * Get either a Gravatar URL or complete image tag for a specified email address.
  331. *
  332. * @param string $email The email address
  333. * @param string $s Size in pixels, defaults to 80px [ 1 - 512 ]
  334. * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
  335. * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
  336. * @param boole $img True to return a complete IMG tag False for just the URL
  337. * @param array $atts Optional, additional key/value attributes to include in the IMG tag
  338. * @return String containing either just a URL or a complete image tag
  339. * @source http://gravatar.com/site/implement/images/php/
  340. */
  341. function _getGravatar($email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array())
  342. {
  343. // Added to setect whether to use HTTP or HTTPS:
  344. $mode = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
  345. $url = $mode.'://www.gravatar.com/avatar/';
  346. $url .= md5(strtolower(trim($email)));
  347. $url .= "?s=$s&d=$d&r=$r";
  348. if ($img) {
  349. $url = '<img src="' . $url . '"';
  350. foreach ($atts as $key => $val)
  351. $url .= ' ' . $key . '="' . $val . '"';
  352. $url .= ' />';
  353. }
  354. return $url;
  355. }
  356. function _parseBrowserFromName($filename, $type = 'css')
  357. {
  358. $ext = substr($filename, strrpos($filename, '.'));
  359. $filename = substr($filename, 0, strrpos($filename, '.'));
  360. if (!preg_match("/^http(s?):/", $filename)) $filename = $this->templateUrl . '/' . $type . '/' . $filename;
  361. else return true;
  362. $checks = $this->browser->_checks;
  363. // Add RTL if enabled
  364. if ($this->document->direction == 'rtl') $checks[] = '-rtl';
  365. foreach ($checks as $check) {
  366. if (file_exists($this->adminPath . DS . $filename . $check . $ext)) {
  367. if ($type == 'js') $this->document->addScript($filename . $check . $ext);
  368. else $this->document->addStylesheet($filename . $check . $ext);
  369. }
  370. }
  371. return true;
  372. }
  373. function _getTools()
  374. {
  375. $user = & JFactory::getUser();
  376. // cache some acl checks
  377. $canConfig = $user->authorize('com_config', 'manage');
  378. $canCheckin = $user->authorize('com_checkin', 'manage');
  379. if ($canConfig || $canCheckin || $canMassMail) {
  380. $tools = array();
  381. if ($canCheckin) {
  382. //$tools[] = $this->_addListItem(JText::_('Global Checkin'), 'checkin', 'index.php?option=com_checkin');
  383. //$tools[] = $this->_addListItem('___');
  384. }
  385. $tools[] = $this->_addListItem(JText::_('Cache Manager'), 'config', 'index.php?option=com_cache');
  386. $tools[] = $this->_addListItem(JText::_('Purge Expired Cache'), 'config', 'index.php?option=com_cache&task=purgeadmin');
  387. $tools[] = $this->_addListItem('___');
  388. return $this->_listify($tools, 'mc-dropdown');
  389. }
  390. return false;
  391. }
  392. /**
  393. * @return
  394. */
  395. function _getTemplateName()
  396. {
  397. $cid = JRequest::getVar('cid');
  398. if (is_array($cid))
  399. return $cid[0];
  400. else
  401. return null;
  402. }
  403. function _getAdminTemplate()
  404. {
  405. global $mainframe, $option;
  406. $template = null;
  407. $task = JRequest::getCmd('task');
  408. $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int'));
  409. if ($option == 'com_templates' && $task == 'edit' && $client->id == 1 && array_key_exists('cid', $_REQUEST)) {
  410. $template = $_REQUEST['cid'][0];
  411. }
  412. else {
  413. $template = $mainframe->getTemplate();
  414. }
  415. return $template;
  416. }
  417. function _getCurrentAdminTemplate()
  418. {
  419. $db =& JFactory::getDBO();
  420. $db->setQuery('select template from #__templates_menu where client_id = 1');
  421. $template = $db->loadResult();
  422. return $template;
  423. }
  424. function _getCurrentSiteTemplate()
  425. {
  426. $db =& JFactory::getDBO();
  427. $db->setQuery('select template from #__templates_menu where client_id = 0');
  428. $template = $db->loadResult();
  429. return $template;
  430. }
  431. function _isGantrySiteTemplate()
  432. {
  433. $libPath = $this->basePath . DS . 'templates' . DS . $this->_getCurrentSiteTemplate() . DS . 'lib' . DS . 'gantry' . DS . 'gantry.php';
  434. if (file_exists($libPath)) return true;
  435. else return false;
  436. }
  437. function _isGantryTemplate()
  438. {
  439. $cid = JRequest::getVar('cid');
  440. if (is_array($cid)) {
  441. $libPath = $this->basePath . DS . 'templates' . DS . $cid[0] . DS . 'lib' . DS . 'gantry' . DS . 'gantry.php';
  442. if (file_exists($libPath)) return true;
  443. }
  444. return false;
  445. }
  446. function _getCurrentPageURL()
  447. {
  448. $isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on");
  449. $port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443")));
  450. $port = ($port) ? ':' . $_SERVER["SERVER_PORT"] : '';
  451. $url = ($isHTTPS ? 'https://' : 'http://') . $_SERVER["SERVER_NAME"] . $port . $_SERVER["REQUEST_URI"];
  452. return $url;
  453. }
  454. }