Subrion - open source content management system
Copyright (C) 2016 Intelliants, LLC
This file is part of Subrion.
Subrion is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Subrion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Subrion. If not, see .
public static function output($output) { $escapedScriptPath = str_replace('/', '\\/', preg_quote(IA_HOME)); $matches = array(); $filteredContent = strip_tags($output); preg_match('#Parse error\\: (.+) in ' . $escapedScriptPath . '(.+?) on line (\\d+)#i', $filteredContent, $matches); if (empty($matches)) { preg_match('#Fatal error\\: (.+) in ' . $escapedScriptPath . '(.+?) on line (\\d+)#i', $filteredContent, $matches); if (empty($matches)) { return false; // return false in order to output the original string } } self::$_halt = true; iaDebug::debug(self::error(0, $matches[1], $matches[2], $matches[3], true), null, 'error'); return ''; }
function smarty_function_ia_hooker($params, &$smarty) { if (!isset($params['name'])) { return; } $name = $params['name']; iaDebug::debug('smarty', $name, 'hooks'); iaSystem::renderTime('smarty', $name); $iaCore = iaCore::instance(); $hooks = $iaCore->getHooks(); if (!array_key_exists($name, $hooks) || empty($hooks[$name])) { return; } foreach ($hooks[$name] as $hook) { $hook['type'] = in_array($hook['type'], array('php', 'html', 'plain', 'smarty')) ? $hook['type'] : 'php'; if (empty($hook['pages']) || in_array($iaCore->iaView->name(), $hook['pages'])) { if ($hook['filename']) { switch ($hook['type']) { case 'php': if (file_exists(IA_HOME . $hook['filename'])) { include IA_HOME . $hook['filename']; } break; case 'smarty': echo $smarty->fetch(IA_HOME . $hook['filename']); } } else { switch ($hook['type']) { case 'php': eval($hook['code']); break; case 'smarty': echo $smarty->fetch('eval:' . $hook['code']); break; case 'html': echo $hook['code']; break; case 'plain': echo iaSanitize::html($hook['code']); } } } } }
protected function _debugTimer() { $count = count(iaSystem::$timer) - 1; $totalTime = 0; $text = ''; $last[0] = $last[1] = iaSystem::$timer[0]['time']; $start = iaSystem::$timer[0]['time']; $end = iaSystem::$timer[$count]['time']; $totalRealTime = number_format($end[1] + $end[0] - ($start[1] + $start[0]), 5, '.', ''); for ($i = 0; $i < $count; $i++) { $memoryUsed = (int) iaSystem::$timer[$i]['bytes']; $memoryInPrevIteration = $i ? (int) iaSystem::$timer[$i - 1]['bytes'] : 0; $start = (double) $last[0][1] + (double) $last[0][0]; $end = iaSystem::$timer[$i]['time'][1] + iaSystem::$timer[$i]['time'][0]; $times = number_format((double) $end - $start, 5, '.', ''); $perc = ceil(($memoryUsed - $memoryInPrevIteration) * 100 / $memoryUsed); if ($times > 0.0001) { $last[0] = $last[1] = iaSystem::$timer[$i]['time']; $totalTime += $times; $text .= '<tr><td class="iterator" rowspan="2">' . $i . '.</td> <td rowspan="2" class="noborder"> <i>' . iaSystem::$timer[$i]['description'] . '</i> <br /> ' . ($perc >= 5 ? '<font color="orange"><i>memory up:</i></font> ' . $perc . '%' : '') . '</td> <td><b>Rendering time:</b></td> <td>' . ($times > 0.01 ? '<font color="red">' . $times * 1000 . '</font>' : $times * 1000) . ' ms (' . $totalTime . ' s)</td> </tr> <tr> <td width="100"><b>Memory usage:</b></td> <td width="150">' . iaSystem::byteView($memoryUsed) . ' (' . number_format($memoryUsed, 0, '', ' ') . ')</td> </tr>'; } } $search = array('START', 'END'); $replace = array('<b class="d_green">START</b>', '<b class="d_red">END</b>'); $text = str_replace($search, $replace, '<b>Real time render:</b> ' . $totalRealTime . '<br /> <b>Math time render:</b> ' . $totalTime . '<br /> <b>Memory usage:</b> ' . iaSystem::byteView($memoryUsed) . '(' . number_format($memoryUsed, 0, '', ' ') . 'b) <table>' . $text . '</table>'); echo $text; return '[Time: ' . $totalRealTime . '] [Mem.: ' . iaSystem::byteView($memoryUsed) . ']'; }
if (count($chunks) > 2) { if (!in_array($chunks[1], array('co', 'com', 'net', 'org', 'gov', 'ltd', 'ac', 'edu'))) { $domain = implode('.', array($chunks[1], $chunks[0])); if ($chunks[2] != 'www') { $domain = implode('.', array($chunks[2], $chunks[1], $chunks[0])); } } } $domain = '.' . $domain; } ini_set('session.gc_maxlifetime', 1800); // 30 minutes //session_set_cookie_params(1800, '/', $domain, false, true); session_name('INTELLI_' . substr(md5(IA_HOME), 0, 10)); session_start(); setcookie(session_name(), session_id(), time() + 1800); require_once IA_CLASSES . 'ia.system.php'; require_once IA_INCLUDES . 'function.php'; if (function_exists('spl_autoload_register')) { spl_autoload_register(array('iaSystem', 'autoload')); } iaSystem::renderTime('start'); if (INTELLI_DEBUG) { register_shutdown_function(array('iaSystem', 'shutdown')); ob_start(array('iaSystem', 'output')); } else { error_reporting(0); } set_error_handler(array('iaSystem', 'error')); iaSystem::renderTime('Core started'); iaCore::instance()->init();
public function ia_template($resourceName, $useCustom = true) { if ($useCustom) { $default = $resourceName; $templateName = $this->iaCore->iaView->theme; if (defined('IA_CURRENT_PACKAGE')) { if (iaCore::ACCESS_ADMIN == $this->iaCore->getAccessType()) { if (is_file(IA_PACKAGE_TEMPLATE_ADMIN . $resourceName)) { $resourceName = IA_PACKAGE_TEMPLATE_ADMIN . $resourceName; } } elseif (is_file(IA_FRONT_TEMPLATES . $templateName . IA_DS . 'packages' . IA_DS . IA_CURRENT_PACKAGE . IA_DS . $resourceName)) { $resourceName = IA_FRONT_TEMPLATES . $templateName . IA_DS . 'packages' . IA_DS . IA_CURRENT_PACKAGE . IA_DS . $resourceName; } elseif (is_file(IA_PACKAGE_TEMPLATE_COMMON . $resourceName)) { $resourceName = IA_PACKAGE_TEMPLATE_COMMON . $resourceName; } } elseif (defined('IA_CURRENT_PLUGIN')) { if (iaCore::ACCESS_FRONT == $this->iaCore->getAccessType() && is_file(IA_FRONT_TEMPLATES . $templateName . IA_DS . 'plugins' . IA_DS . IA_CURRENT_PLUGIN . IA_DS . $resourceName)) { $resourceName = IA_FRONT_TEMPLATES . $templateName . IA_DS . 'plugins' . IA_DS . IA_CURRENT_PLUGIN . IA_DS . $resourceName; } else { $resourceName = IA_PLUGIN_TEMPLATE . $resourceName; } } $resourceName = $resourceName == $default ? IA_TEMPLATES . $templateName . IA_DS . $resourceName : $resourceName; is_file($resourceName) || ($resourceName = IA_TEMPLATES . $templateName . IA_DS . $default); is_file($resourceName) || ($resourceName = IA_TEMPLATES . 'common' . IA_DS . $default); } else { $resourceName = $this->template_dir . $resourceName; } if (!$this->templateExists($resourceName)) { if (INTELLI_DEBUG || INTELLI_QDEBUG) { trigger_error('Unable to find the following resource: <b>' . $resourceName . '</b>', E_USER_ERROR); } else { echo '<div style="font-weight: bold; color: #f00; margin: 20px 0;">File Missing: ' . $resourceName . '</div>'; } } iaSystem::renderTime('after check file ' . $resourceName); return $resourceName; }
public static function ia_block_view($params, Smarty_Internal_Template &$smarty) { $block = $params['block']; switch ($block['type']) { case 'menu': if ($block['contents']) { $smarty->assign('menu', $block); $result = $smarty->fetch($block['tpl']); } break; case 'smarty': $smarty->assign('block', $block); if ($block['external']) { $filename = explode(':', $block['filename']); $template = iaCore::instance()->get('tmpl'); switch (count($filename)) { case 1: $templateFile = sprintf("%stemplates/%s/%s", IA_HOME, $template, $filename[0]); $templateFile = file_exists($templateFile) ? $templateFile : sprintf('%s/templates/common/%s', IA_HOME, $filename[0]); break; case 2: $templateFile = sprintf('%stemplates/%s/packages/%s/%s', IA_HOME, $template, $filename[0], $filename[1]); $templateFile = file_exists($templateFile) ? $templateFile : sprintf('%spackages/%s/templates/common/%s', IA_HOME, $filename[0], $filename[1]); break; default: $templateFile = sprintf("%stemplates/%s/plugins/%s/%s", IA_HOME, $template, $filename[1], $filename[2]); $templateFile = file_exists($templateFile) ? $templateFile : sprintf('%splugins/%s/templates/front/%s', IA_HOME, $filename[1], $filename[2]); } $source = @file_get_contents($templateFile); if (false === $source) { trigger_error('Unable to locate the block template: <b>' . $block['filename'] . '</b>'); } } else { $source = $block['contents']; } $result = $smarty->fetch('eval:' . $source); break; case 'php': if (!$block['external']) { if (iaSystem::phpSyntaxCheck($block['contents'])) { $iaCore = iaCore::instance(); // predefine this variable to be used in the code below $result = eval($block['contents']); } else { iaDebug::debug(array('name' => $block['name'], 'code' => '<textarea style="width:80%;height:100px;">' . $block['contents'] . '</textarea>'), '<b style="color:red;">PHP syntax error in the block "' . $block['name'] . '"</b>', 'error'); } } else { $result = (include_once $block['filename']); } break; case 'html': $result = $block['contents']; break; case 'plain': $result = htmlspecialchars($block['contents']); } return empty($result) ? '' : $result; }
protected function _runPhpCode($code) { if (iaSystem::phpSyntaxCheck($code)) { $iaCore =& $this->iaCore; $iaDb =& $this->iaDb; eval($code); } }
public static function loadCoreClass($name, $type = 'admin') { if (!class_exists('iaCore')) { define('IA_INCLUDES', IA_HOME . 'includes' . IA_DS); define('IA_SMARTY', IA_INCLUDES . 'smarty' . IA_DS); define('IA_CLASSES', IA_INCLUDES . 'classes' . IA_DS); define('IA_PACKAGES', IA_HOME . 'packages' . IA_DS); define('IA_PLUGINS', IA_HOME . 'plugins' . IA_DS); define('IA_TMP', IA_HOME . 'tmp' . IA_DS); define('IA_CACHEDIR', IA_TMP . 'cache' . IA_DS); if (file_exists(IA_INCLUDES . 'config.inc.php')) { include_once IA_INCLUDES . 'config.inc.php'; } else { define('INTELLI_CONNECT', 'mysql'); define('INTELLI_DBHOST', self::getPost('dbhost', 'localhost')); define('INTELLI_DBPORT', self::getPost('dbport', 3306)); define('INTELLI_DBUSER', self::getPost('dbuser')); define('INTELLI_DBPASS', self::getPost('dbpwd')); define('INTELLI_DBNAME', self::getPost('dbname')); define('INTELLI_DBPREFIX', self::getPost('prefix', '', false)); define('INTELLI_DEBUG', false); } set_include_path(IA_CLASSES); require_once 'ia.system.php'; if (function_exists('spl_autoload_register') && function_exists('spl_autoload_unregister')) { spl_autoload_register(array('iaSystem', 'autoload')); } require_once IA_INCLUDES . 'function.php'; require_once 'ia.interfaces.php'; $iaCore = iaCore::instance(); iaSystem::setDebugMode(); $iaCore->factory(array('sanitize', 'validate')); $iaCore->iaDb = $iaCore->factory('db'); $iaCore->factory('language'); $iaCore->iaView = $iaCore->factory('view'); $iaCore->iaCache = $iaCore->factory('cache'); $config = array('baseurl', 'timezone'); $config = $iaCore->iaDb->keyvalue(array('name', 'value'), "`name` IN ('" . implode("','", $config) . "')", iaCore::getConfigTable()); $iaCore->languages = array('en' => 'English'); $iaCore->iaView->language = 'en'; date_default_timezone_set($config['timezone']); define('IA_CLEAR_URL', $config['baseurl']); define('IA_URL', IA_CLEAR_URL); define('IA_FRONT_TEMPLATES', IA_HOME . 'templates' . IA_DS); define('IA_TEMPLATES', IA_FRONT_TEMPLATES); } return iaCore::instance()->factory($name, $type); }
public function factoryPlugin($plugin, $type = self::FRONT, $name = null) { if (empty($name)) { $name = $plugin; } $class = self::CLASSNAME_PREFIX . ucfirst(strtolower($name)); if (!isset($this->_classInstances[$class])) { $fileSize = $this->loadClass($type, $name, $plugin); if (false === $fileSize) { return false; } iaDebug::debug('<b>plugin:</b> ia.' . $type . '.' . $name . ' (' . iaSystem::byteView($fileSize) . ')', 'Initialized Classes List', 'info'); $this->_classInstances[$class] = new $class(); $this->_classInstances[$class]->init(); } return $this->_classInstances[$class]; }
private function _checkForUpdates() { $url = sprintf(iaUtil::REMOTE_TOOLS_URL . 'get/updates/%s/', IA_VERSION); $content = iaUtil::getPageContent($url); if (!$content) { return; } $content = iaUtil::jsonDecode($content); if (is_array($content) && $content) { $messages = array(); foreach ($content as $entry) { switch ($entry['type']) { case self::UPDATE_TYPE_INFO: $messages[] = array($entry['id'], $entry['message']); break; case self::UPDATE_TYPE_PATCH: $version = explode('.', $entry['version']); if (count($version) > 3) { if ($this->_iaCore->get('auto_apply_critical_upgrades')) { $result = iaSystem::forceUpgrade($entry['version']); if (is_bool($result) && $result) { $this->_iaCore->factory('cache')->clearGlobalCache(); $message = iaLanguage::getf('script_upgraded', array('version' => $entry['version'])); $this->_iaCore->iaView->setMessages($message, iaView::SUCCESS); iaUtil::go_to(IA_SELF); } else { iaDebug::debug($result, 'Forced upgrade to the version ' . $entry['version']); } } } else { $url = sprintf('%sinstall/upgrade/check/%s/', IA_CLEAR_URL, $entry['version']); $this->_iaCore->iaView->setMessages(iaLanguage::getf('upgrade_available', array('url' => $url, 'version' => $entry['version'])), iaView::SYSTEM); } } } $this->_iaCore->iaView->assign('updatesInfo', $messages); } }
public static function ia_block_view($params, Smarty_Internal_Template &$smarty) { $block = $params['block']; switch ($block['type']) { case 'menu': if ($block['contents']) { $smarty->assign('menu', $block); $result = $smarty->fetch($block['tpl']); } break; case 'smarty': $smarty->assign('block', $block); $result = $smarty->fetch($block['external'] ? $block['filename'] : 'eval:' . $block['contents']); break; case 'php': if (!$block['external']) { if (iaSystem::phpSyntaxCheck($block['contents'])) { $iaCore = iaCore::instance(); // predefine this variable to be used in the code below $result = eval($block['contents']); } else { iaDebug::debug(array('name' => $block['name'], 'code' => '<textarea style="width:80%;height:100px;">' . $block['contents'] . '</textarea>'), '<b style="color:red;">PHP syntax error in the block "' . $block['name'] . '"</b>', 'error'); } } else { $result = (include_once $block['filename']); } break; case 'html': $result = $block['contents']; break; case 'plain': $result = htmlspecialchars($block['contents']); } return empty($result) ? '' : $result; }
protected function _indexPage(&$iaView) { $iaView->display('index'); $iaCore =& $this->_iaCore; $iaDb =& $this->_iaDb; if (isset($_GET['reset']) || isset($_GET['save'])) { $data = isset($_GET['list']) ? $_GET['list'] : ''; if ($iaDb->update(array('admin_columns' => $data), iaDb::convertIds(iaUsers::getIdentity()->id), null, iaUsers::getTable())) { iaUsers::reloadIdentity(); } $iaView->setMessages(iaLanguage::get('saved'), iaView::SUCCESS); iaUtil::go_to(IA_SELF); } $disabledWidgets = iaUsers::getIdentity()->admin_columns; $disabledWidgets = empty($disabledWidgets) ? array() : explode(',', trim($disabledWidgets, ',')); $iaView->assign('disabled_widgets', $disabledWidgets); $customizationMode = isset($_GET['customize']) && empty($_GET['customize']); if ($customizationMode) { $iaView->setMessages(iaLanguage::get('customization_mode_alert')); $iaView->assign('customization_mode', true); } // populate statistics $iaItem = $iaCore->factory('item'); $itemsList = $iaItem->getPackageItems(); $validSizes = array('small', 'medium', 'package'); $iaCore->startHook('adminDashboardStatistics', array('items' => &$itemsList)); natcasesort($itemsList); $statistics = array(); foreach ($validSizes as $size) { $statistics[$size] = array(); } foreach ($itemsList as $itemName => $pluginType) { $itemName = substr($itemName, 0, -1); switch ($pluginType) { case 'core': $classInstance = $iaCore->factory('member' == $itemName ? 'users' : $itemName); break; case 'plugin': $array = explode(':', $itemName); $itemName = isset($array[1]) ? $array[1] : $itemName; $classInstance = $iaCore->factoryPlugin($array[0], iaCore::ADMIN, isset($array[1]) ? $array[1] : null); break; default: $classInstance = $iaCore->factoryPackage($itemName, $pluginType, iaCore::ADMIN); } if (!$customizationMode && in_array($itemName, $disabledWidgets)) { continue; } if ($classInstance) { if (method_exists($classInstance, self::STATISTICS_GETTER_METHOD)) { if ($classInstance->dashboardStatistics) { $data = $classInstance->{self::STATISTICS_GETTER_METHOD}(); isset($data['icon']) || ($data['icon'] = $itemName); isset($data['caption']) || ($data['caption'] = $itemName); $data['caption'] = iaLanguage::get($data['caption'], $data['caption']); $widgetFormat = isset($data['_format']) && in_array($data['_format'], $validSizes) ? $data['_format'] : $validSizes[0]; $statistics[$widgetFormat][$itemName] = $data; } } } } $iaView->assign('statistics', $statistics); // if (($customizationMode || !in_array('changelog', $disabledWidgets)) && $iaCore->get('display_changelog') && is_file(IA_HOME . 'changelog.txt')) { $index = 0; $log = array(); $titles = array(); $lines = file(IA_HOME . 'changelog.txt'); foreach ($lines as $line_num => $line) { $line = trim($line); if ($line) { if ($line[0] == '>') { $index++; $log[$index] = array('title' => trim($line, '<> '), 'added' => '', 'modified' => '', 'bugfixes' => '', 'other' => ''); $titles[trim($line, '<> ')] = $index; } elseif ($index > 0) { switch ($line[0]) { case '+': $class = 'added'; break; case '-': $class = 'bugfixes'; break; case '*': $class = 'modified'; break; default: $class = 'other'; } $issue = preg_replace('/#(\\d+)/', '<a href="http://dev.subrion.org/issues/$1" target="_blank">#$1</a>', ltrim($line, '+-* ')); $log[$index][$class] .= '<li>' . $issue . '</li>'; } } } unset($log[0]); ksort($titles); $titles = array_reverse($titles); $iaView->assign('changelog_titles', $titles); $iaView->assign('changelog', $log); } // twitter widget if ($customizationMode || !in_array('twitter', $disabledWidgets)) { $data = iaUtil::getPageContent('http://tools.intelliants.com/timeline/'); $iaView->assign('timeline', iaUtil::jsonDecode($data)); } if ($customizationMode || !in_array('recent-activity', $disabledWidgets)) { $data = $iaCore->factory('log')->get(); $iaView->assign('activity_log', $data); } if ($customizationMode || !in_array('website-visits', $disabledWidgets)) { $data = $iaCore->factory('users')->getVisitorsInfo(); $iaView->assign('online_members', $data); } if ($iaCore->get('check_for_updates')) { if ($content = iaUtil::getPageContent(iaUtil::REMOTE_TOOLS_URL . 'get/patch/')) { $content = iaUtil::jsonDecode($content); if (is_array($content) && $content) { foreach ($content as $versionFrom => $versionTo) { if (version_compare($versionFrom, IA_VERSION) === 0 && version_compare($versionTo, IA_VERSION)) { $version = explode('.', $versionTo); if (count($version) > 3) { if ($iaCore->get('auto_apply_critical_upgrades')) { $result = iaSystem::forceUpgrade($versionTo); if (is_bool($result) && $result) { $iaCore->factory('cache')->clearGlobalCache(); $message = iaLanguage::getf('script_upgraded', array('version' => $versionTo)); $iaView->setMessages($message, iaView::SUCCESS); iaUtil::go_to(IA_SELF); } else { iaDebug::debug($result, 'Forced upgrade to the version ' . $versionTo); } } } else { $url = sprintf('%sinstall/upgrade/check/%s/', IA_CLEAR_URL, $versionTo); $iaView->setMessages(iaLanguage::getf('upgrade_available', array('url' => $url, 'version' => $versionTo)), iaView::SYSTEM); } } } } } } }