/** * Try to autoload class definitions before failing. * This makes the Campsite class definition file inclusion optional. * * @param string $p_className */ function __autoload($p_className) { global $ADMIN, $ADMIN_DIR; require_once $GLOBALS['g_campsiteDir'] . '/classes/CampPlugin.php'; static $classDirectories = array('classes', 'classes/Extension', 'template_engine/classes', 'template_engine/metaclasses'); if (!is_string($p_className)) { return; } foreach ($classDirectories as $dirName) { $fileName = $GLOBALS['g_campsiteDir'] . "/{$dirName}/{$p_className}.php"; if (file_exists($fileName)) { require_once $fileName; return; } } $basePaths = array(); foreach (CampPlugin::GetEnabled() as $CampPlugin) { $basePaths[] = $CampPlugin->getBasePath(); } foreach ($basePaths as $basePath) { foreach ($classDirectories as $dirName) { $fileName = $GLOBALS['g_campsiteDir'] . "/{$basePath}/{$dirName}/{$p_className}.php"; if (file_exists($fileName)) { require_once $fileName; return; } } } }
/** * Get plugins plugins dir * * @return array */ private static function getPluginsPluginsDir() { $dirs = array(); foreach (CampPlugin::GetEnabled() as $CampPlugin) { $dirs[] = CS_PATH_SITE . "/{$CampPlugin->getBasePath()}/smarty_camp_plugins"; } return $dirs; }
/** * Legacy admin bootstrap */ protected function _initNewscoop() { global $ADMIN_DIR, $ADMIN, $g_user, $prefix, $Campsite; defined('WWW_DIR') || define('WWW_DIR', realpath(APPLICATION_PATH . '/../')); defined('LIBS_DIR') || define('LIBS_DIR', WWW_DIR . '/admin-files/libs'); $GLOBALS['g_campsiteDir'] = WWW_DIR; require_once $GLOBALS['g_campsiteDir'] . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'campsite_constants.php'; require_once CS_PATH_CONFIG . DIR_SEP . 'install_conf.php'; // goes to install process if configuration files does not exist yet if (!file_exists(CS_PATH_CONFIG . DIR_SEP . 'configuration.php') || !file_exists(CS_PATH_CONFIG . DIR_SEP . 'database_conf.php')) { header('Location: ' . $Campsite['SUBDIR'] . '/install/'); exit; } require_once CS_PATH_CONFIG . DIR_SEP . 'database_conf.php'; require_once CS_PATH_SITE . DIR_SEP . 'include' . DIR_SEP . 'campsite_init.php'; require_once CS_PATH_SITE . DIR_SEP . 'classes' . DIR_SEP . 'CampTemplateCache.php'; // detect extended login/logout files $prefix = file_exists(CS_PATH_SITE . DIR_SEP . 'admin-files' . DIR_SEP . 'ext_login.php') ? '/ext_' : '/'; require_once CS_PATH_SITE . DIR_SEP . $ADMIN_DIR . DIR_SEP . 'camp_html.php'; require_once CS_PATH_CLASSES . DIR_SEP . 'SecurityToken.php'; // load if possible before setting camp_report_bug error handler // to prevent error messages include_once 'HTML/QuickForm.php'; include_once 'HTML/QuickForm/RuleRegistry.php'; include_once 'HTML/QuickForm/group.php'; if (!defined('IN_PHPUNIT') && !getenv('PLZSTOPTHISERRORHANDLERBIZNIS')) { set_error_handler(function ($p_number, $p_string, $p_file, $p_line) { if (($p_number & error_reporting()) === 0) { return; // respect php settings } global $ADMIN_DIR, $Campsite; require_once $Campsite['HTML_DIR'] . "/{$ADMIN_DIR}/bugreporter/bug_handler_main.php"; camp_bug_handler_main($p_number, $p_string, $p_file, $p_line); }, E_ALL); } camp_load_translation_strings("api"); $plugins = CampPlugin::GetEnabled(true); foreach ($plugins as $plugin) { camp_load_translation_strings("plugin_" . $plugin->getName()); } // Load common translation strings camp_load_translation_strings('globals'); require_once APPLICATION_PATH . "/../{$ADMIN_DIR}/init_content.php"; if (file_exists($Campsite['HTML_DIR'] . '/reset_cache')) { CampCache::singleton()->clear('user'); unlink($GLOBALS['g_campsiteDir'] . '/reset_cache'); } }
private function __construct() { parent::Smarty(); $config = CampSite::GetConfigInstance(); $this->debugging = $config->getSetting('smarty.debugging'); $this->force_compile = $config->getSetting('smarty.force_compile'); $this->compile_check = $config->getSetting('smarty.compile_check'); $this->use_sub_dirs = $config->getSetting('smarty.use_subdirs'); // cache settings $cacheHandler = SystemPref::Get('TemplateCacheHandler'); if ($cacheHandler) { $this->caching = 1; $this->cache_handler_func = "TemplateCacheHandler_$cacheHandler::handler"; require_once CS_PATH_SITE.DIR_SEP.'classes'.DIR_SEP.'cache'.DIR_SEP."TemplateCacheHandler_$cacheHandler.php"; } else { $this->caching = 0; } // define dynamic uncached block require_once CS_PATH_SMARTY.DIR_SEP.'campsite_plugins/block.dynamic.php'; $this->register_block('dynamic', 'smarty_block_dynamic', false); // define render function require_once CS_PATH_SMARTY.DIR_SEP.'campsite_plugins/function.render.php'; $this->register_function('render', 'smarty_function_render', false); $this->left_delimiter = $config->getSetting('smarty.left_delimeter'); $this->right_delimiter = $config->getSetting('smarty.right_delimeter'); $this->cache_dir = CS_PATH_SITE.DIR_SEP.'cache'; $this->config_dir = CS_PATH_SMARTY.DIR_SEP.'configs'; $plugin_smarty_camp_plugin_paths = array(); foreach (CampPlugin::GetEnabled() as $CampPlugin) { $plugin_smarty_camp_plugin_paths[] = CS_PATH_SITE.DIR_SEP.$CampPlugin->getBasePath().DIR_SEP.'smarty_camp_plugins'; } $this->plugins_dir = array_merge(array(CS_PATH_SMARTY.DIR_SEP.'campsite_plugins', CS_PATH_SMARTY.DIR_SEP.'plugins'), $plugin_smarty_camp_plugin_paths); $this->template_dir = CS_PATH_TEMPLATES; $this->compile_dir = CS_PATH_SITE.DIR_SEP.'templates_cache'; } // fn __constructor
/** * Forward to legacy controller if controller/action not found */ public function preDispatch() { $errors = $this->_getParam('error_handler'); if (!$errors) { return; } $request = $this->getRequest(); $adminControllerFile = __DIR__ . '/../..' . str_replace('/admin', '/admin-files', $request->getPathInfo()); if (file_exists($adminControllerFile)) { $this->_forward('index', 'legacy', 'admin', array()); return; } foreach (\CampPlugin::GetEnabled() as $CampPlugin) { $adminControllerFile = dirname(APPLICATION_PATH) . '/' . $CampPlugin->getBasePath() . str_replace('/admin', '/admin-files', $request->getPathInfo()); if (file_exists($adminControllerFile)) { $this->_forward('index', 'legacy', 'admin', array()); return; } } }
/** * Creates an object of the given type. Returns the created object. * * @param string $p_objectType * @return object */ private function createObject($p_objectType) { $p_objectType = CampContext::TranslateProperty($p_objectType); $classFullPath = $GLOBALS['g_campsiteDir'] . '/template_engine/metaclasses/' . CampContext::ObjectType($p_objectType) . '.php'; if (file_exists($classFullPath)) { require_once $classFullPath; } elseif (class_exists(CampContext::$m_objectTypes[$p_objectType]['class'])) { $className = CampContext::ObjectType($p_objectType); } else { $pluginImplementsClassFullPath = false; foreach (CampPlugin::GetEnabled() as $CampPlugin) { $pluginClassFullPath = $GLOBALS['g_campsiteDir'] . '/' . $CampPlugin->getBasePath() . '/template_engine/metaclasses/' . CampContext::ObjectType($p_objectType) . '.php'; if (file_exists($pluginClassFullPath)) { $pluginImplementsClassFullPath = $pluginClassFullPath; } } if ($pluginImplementsClassFullPath) { require_once $pluginImplementsClassFullPath; } else { throw new InvalidObjectException($p_objectType); } } $className = CampContext::ObjectType($p_objectType); $this->m_objects[$p_objectType] = new $className(); return $this->m_objects[$p_objectType]; }
// If its not a PHP file, assume its a directory. if ($extension != '.php') { // If its a directory if (($call_script != '') && ($call_script[strlen($call_script)-1] != '/') ) { $call_script .= '/'; } $call_script .= 'index.php'; } $needs_menu = ! (in_array($call_script, $no_menu_scripts) || Input::Get('p_no_menu', 'boolean', false, true)); // Verify the file exists $path_name = $Campsite['HTML_DIR'] . "/$ADMIN_DIR/$call_script"; if (!file_exists($path_name)) { foreach (CampPlugin::GetEnabled() as $CampPlugin) { $plugin_path_name = $Campsite['HTML_DIR'].'/'.$CampPlugin->getBasePath()."/$ADMIN_DIR/$call_script"; if (file_exists($plugin_path_name)) { $path_name = $plugin_path_name; break; } } if (!file_exists($path_name)) { header("HTTP/1.1 404 Not found"); exit; } } // Clean up the global namespace before we call the script unset($access); unset($extension);
/** * Searches for classes that process actions. Returns an array of * action names. * * @return array */ public static function ReadAvailableActions() { if (is_array(MetaAction::$m_availableActions)) { return MetaAction::$m_availableActions; } if (self::FetchActionsFromCache()) { return self::$m_availableActions; } require_once('File/Find.php'); $actions = array(); $basePaths = array('.'); foreach (CampPlugin::GetEnabled() as $CampPlugin) { $basePaths[] = $CampPlugin->getBasePath(); } foreach ($basePaths as $basePath) { $directoryPath = $GLOBALS['g_campsiteDir'].'/'.$basePath.'/template_engine/metaclasses'; $actionIncludeFiles = File_Find::search('/^MetaAction[^.]*\.php$/', $directoryPath, 'perl', false); foreach ($actionIncludeFiles as $includeFile) { if (preg_match('/MetaAction([^.]+)\.php/', $includeFile, $matches) == 0 || strtolower($matches[1]) == 'request') { continue; } require_once($includeFile); $actionName = $matches[1]; if (class_exists('MetaAction'.$actionName)) { $actions[self::TranslateProperty($actionName)] = array('name'=>$actionName, 'file'=>"$directoryPath/MetaAction$actionName.php"); } } } self::$m_availableActions = $actions; self::StoreActionsInCache(); return self::$m_availableActions; }
/** * Get plugins plugins dir. * * @return array */ public static function getPluginsPluginsDir() { $pluginsManager = \Zend_Registry::get('container')->getService('newscoop.plugins.manager'); $availablePlugins = $pluginsManager->getInstalledPlugins(); $dirs = array(); foreach ($availablePlugins as $plugin) { $pluginPath = explode('\\', $plugin); $directoryPath = realpath(__DIR__ . '/../../plugins/' . $pluginPath[0] . '/' . $pluginPath[1] . '/Resources/smartyPlugins'); if ($directoryPath) { $dirs[] = $directoryPath; } } //legacy plugins foreach (CampPlugin::GetEnabled() as $CampPlugin) { $dirs[] = CS_PATH_SITE . "/{$CampPlugin->getBasePath()}/smarty_camp_plugins"; } //comunity ticker $dirs[] = __DIR__ . '/../../src/Newscoop/CommunityTickerBundle/Resources/smartyPlugins'; return $dirs; }
public function preparePluginsMenu($menu) { $translator = $this->container->get('translator'); $rootMenu = false; $pluginInfos = \CampPlugin::GetPluginsInfo(true); if ($this->user->hasPermission('plugin_manager')) { $rootMenu = true; } foreach ($pluginInfos as $info) { if (isset($info['menu']['permission']) && $this->user->hasPermission($info['menu']['permission'])) { $rootMenu = true; } elseif (isset($info['menu']['sub']) && is_array($info['menu']['sub'])) { foreach ($info['menu']['sub'] as $menuInfo) { if ($this->user->hasPermission($menuInfo['permission'])) { $rootMenu = true; } } } } $menu->addChild($translator->trans('Plugins'), array('uri' => '#'))->setAttribute('dropdown', true)->setLinkAttribute('data-toggle', 'dropdown'); if (!$rootMenu) { $menu[$translator->trans('Plugins')]->setDisplay(false); return; } if ($this->user->hasPermission('plugin_manager')) { $this->addChild($menu[$translator->trans('Plugins')], $translator->trans('Manage Plugins'), array('uri' => $this->container->get('router')->generate('newscoop_newscoop_plugins_index'))); } $enabled = \CampPlugin::GetEnabled(); $enabledIds = array(); foreach ($enabled as $plugin) { $enabledIds[] = $plugin->getName(); } foreach ($pluginInfos as $info) { if (in_array($info['name'], $enabledIds)) { $parentMenu = false; if (isset($info['menu']['permission']) && $this->user->hasPermission($info['menu']['permission'])) { $parentMenu = true; } elseif (isset($info['menu']['sub']) && is_array($info['menu']['sub'])) { foreach ($info['menu']['sub'] as $menuInfo) { if ($this->user->hasPermission($menuInfo['permission'])) { $parentMenu = true; } } } if ($parentMenu && isset($info['menu'])) { $uri = '#'; if (isset($info['menu']['path'])) { $uri = $this->generateZendRoute('admin') . '/' . $info['menu']['path']; } $this->addChild($menu[$translator->trans('Plugins')], $translator->trans($info['menu']['label']), array('uri' => $uri))->setLinkAttribute('data-toggle', 'rightdrop'); } if (isset($info['menu']['sub']) && is_array($info['menu']['sub'])) { foreach ($info['menu']['sub'] as $menuInfo) { if ($this->user->hasPermission($menuInfo['permission'])) { $uri = '#'; if (isset($menuInfo['path'])) { $uri = $this->generateZendRoute('admin') . '/' . $menuInfo['path']; } $this->addChild($menu[$translator->trans('Plugins')][$translator->trans($info['menu']['label'])], $translator->trans($menuInfo['label']), array('uri' => $uri)); } } } } } return $menu; }
$redirector->gotoSimple('manage.php', 'plugins', 'admin'); } if (Input::Get('upload_package')) { $file = $_FILES['package']; if ($Plugin = CampPlugin::extractPackage($file['tmp_name'], $log)) { $success = getGS('The plugin $1 was sucessfully installed.', $Plugin->getName()); } else { $error = $log; } //$Plugin->enable(); } if (Input::Get('p_uninstall')) { $Plugin = new CampPlugin(Input::Get('p_plugin', 'string')); $Plugin->uninstall(); } $plugins = CampPlugin::GetEnabled(true); foreach ($plugins as $plugin) { camp_load_translation_strings("plugin_" . $plugin->getName()); } if (count($infos = CampPlugin::GetPluginsInfo()) > 0) { // check if update was needed CampPlugin::GetPluginsInfo(false, true); if ($needsUpdate = CampPlugin::GetNeedsUpdate()) { camp_html_add_msg(getGS("Some plugins have to be updated. Please press the save button.")); } } else { camp_html_add_msg(getGS("You have no installed plugins.")); } $crumbs = array(); $crumbs[] = array(getGS("Plugins"), ""); $crumbs[] = array(getGS("Manage"), "");
public function indexAction() { global $controller, $Campsite, $ADMIN_DIR, $ADMIN, $g_user, $g_ado_db, $prefix; $controller = $this; $no_menu_scripts = array($prefix . 'login.php', $prefix . 'logout.php', '/issues/preview.php', '/issues/empty.php', '/ad_popup.php', '/articles/preview.php', '/articles/autopublish.php', '/articles/autopublish_do_add.php', '/articles/images/popup.php', '/articles/images/view.php', '/articles/topics/popup.php', '/articles/files/popup.php', '/articles/empty.php', '/articles/post.php', '/comments/ban.php', '/comments/do_ban.php', '/imagearchive/do_add.php', '/users/authors_ajax/detail.php', '/users/authors_ajax/grid.php', $prefix . 'password_recovery.php', $prefix . 'password_check_token.php', '/articles/locations/popup.php', '/articles/locations/preview.php', '/articles/locations/search.php', '/articles/locations/filter.php', '/articles/context_box/popup.php', '/articles/multidate/popup.php', '/media-archive/edit-attachment.php', '/media-archive/edit.php'); CampPlugin::ExtendNoMenuScripts($no_menu_scripts); $request_uri = $_SERVER['REQUEST_URI']; $call_script = substr($request_uri, strlen("/{$ADMIN}")); // Remove any GET parameters if (($question_mark = strpos($call_script, '?')) !== false) { $call_script = substr($call_script, 0, $question_mark); } // Remove all attempts to get at other parts of the file system $call_script = str_replace('/../', '/', $call_script); $GLOBALS['call_script'] = $call_script; // detect extended login/logout files if ($call_script == '/login.php') { $call_script = $prefix . 'login.php'; } $extension = ''; if (($extension_start = strrpos($call_script, '.')) !== false) { $extension = strtolower(substr($call_script, $extension_start)); } if ($extension == '.php' || $extension == '') { // If its not a PHP file, assume its a directory. if ($extension != '.php') { // If its a directory if ($call_script != '' && $call_script[strlen($call_script) - 1] != '/') { $call_script .= '/'; } $call_script .= 'index.php'; } $this->view->legacy = true; $needs_menu = !(in_array($call_script, $no_menu_scripts) || Input::Get('p_no_menu', 'boolean', false, true)); if (!$needs_menu) { $this->_helper->layout->disableLayout(); } // Verify the file exists $path_name = $Campsite['HTML_DIR'] . "/{$ADMIN_DIR}/{$call_script}"; if (!file_exists($path_name)) { foreach (CampPlugin::GetEnabled() as $CampPlugin) { $plugin_path_name = dirname(APPLICATION_PATH) . '/' . $CampPlugin->getBasePath() . "/{$ADMIN_DIR}/{$call_script}"; if (file_exists($plugin_path_name)) { $path_name = $plugin_path_name; // possible plugin include paths $include_paths = array('/classes', '/template_engine/classes', '/template_engine/metaclasses'); // set include paths for plugin foreach ($include_paths as $path) { $path = dirname(APPLICATION_PATH) . '/' . $CampPlugin->getBasePath() . $path; if (file_exists($path)) { set_include_path(implode(PATH_SEPARATOR, array(realpath($path), get_include_path()))); } } break; } } if (!file_exists($path_name)) { header("HTTP/1.1 404 Not found"); echo '<html><head><title>404 Not Found</title></head><body>'; echo '<h1>Not Found</h1>'; echo '<p>The requested URL ', $_SERVER['REQUEST_URI'], ' was not found on this server.</p>'; echo '</body></html>'; exit; } } // render view require_once $path_name; return; } elseif (file_exists($Campsite['HTML_DIR'] . "/{$ADMIN_DIR}/{$call_script}")) { readfile($Campsite['HTML_DIR'] . "/{$ADMIN_DIR}/{$call_script}"); exit; } header("HTTP/1.1 404 Not found"); exit; }