function savePluginsAction() { $translate = DevblocksPlatform::getTranslationService(); $worker = CerberusApplication::getActiveWorker(); if (!$worker || !$worker->is_superuser) { echo $translate->_('common.access_denied'); return; } if (DEMO_MODE) { DevblocksPlatform::setHttpResponse(new DevblocksHttpResponse(array('config', 'plugins'))); return; } @($plugins_enabled = DevblocksPlatform::importGPC($_REQUEST['plugins_enabled'], 'array')); $pluginStack = DevblocksPlatform::getPluginRegistry(); if (is_array($plugins_enabled)) { foreach ($plugins_enabled as $plugin_id) { $plugin = $pluginStack[$plugin_id]; $plugin->setEnabled(true); unset($pluginStack[$plugin_id]); } } // [JAS]: Clear unchecked plugins foreach ($pluginStack as $plugin) { // [JAS]: We can't force disable core here [TODO] Improve if ($plugin->id == 'cerberusweb.core') { continue; } $plugin->setEnabled(false); } DevblocksPlatform::clearCache(); // Run any enabled plugin patches // [TODO] Should the platform do this automatically on enable in order? $patchMgr = DevblocksPlatform::getPatchService(); $patches = DevblocksPlatform::getExtensions("devblocks.patch.container", false, true); if (is_array($patches)) { foreach ($patches as $patch_manifest) { /* @var $patch_manifest DevblocksExtensionManifest */ $container = $patch_manifest->createInstance(); /* @var $container DevblocksPatchContainerExtension */ $patchMgr->registerPatchContainer($container); } } if (!$patchMgr->run()) { // fail die("Failed updating plugins."); // [TODO] Make this more graceful } // Reload plugin translations DAO_Translation::reloadPluginStrings(); DevblocksPlatform::redirect(new DevblocksHttpResponse(array('config', 'plugins'))); }
/** * @param $instance Model_CommunityTool */ public function configure(Model_CommunityTool $instance) { $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = dirname(dirname(__FILE__)) . '/templates/'; $tpl->assign('config_path', $tpl_path); // Locales $default_locale = DAO_CommunityToolProperty::get($instance->code, self::PARAM_DEFAULT_LOCALE, 'en_US'); $tpl->assign('default_locale', $default_locale); $locales = DAO_Translation::getDefinedLangCodes(); $tpl->assign('locales', $locales); // Personalization $page_title = DAO_CommunityToolProperty::get($instance->code, self::PARAM_PAGE_TITLE, 'Support Center'); $tpl->assign('page_title', $page_title); // Login Handlers $login_handlers = DevblocksPlatform::getExtensions('usermeet.login.authenticator'); uasort($login_handlers, create_function('$a, $b', "return strcasecmp(\$a->name,\$b->name);\n")); $tpl->assign('login_handlers', $login_handlers); $login_handler = DAO_CommunityToolProperty::get($instance->code, self::PARAM_LOGIN_HANDLER, ''); $tpl->assign('login_handler', $login_handler); // Modules @($visible_modules = unserialize(DAO_CommunityToolProperty::get($instance->code, self::PARAM_VISIBLE_MODULES, ''))); $tpl->assign('visible_modules', $visible_modules); $all_modules = DevblocksPlatform::getExtensions('usermeet.sc.controller', true, true); $modules = array(); // Sort the enabled modules first, in order. if (is_array($visible_modules)) { foreach ($visible_modules as $module_id => $visibility) { if (!isset($all_modules[$module_id])) { continue; } $module = $all_modules[$module_id]; $modules[$module_id] = $module; unset($all_modules[$module_id]); } } // Append the unused modules if (is_array($all_modules)) { foreach ($all_modules as $module_id => $module) { $modules[$module_id] = $module; $modules = array_merge($modules, $all_modules); } } $tpl->assign('modules', $modules); $tpl->display("file:{$tpl_path}portal/sc/config/index.tpl"); }
function handleRequest(DevblocksHttpRequest $request) { @set_time_limit(0); // no timelimit (when possible) $translate = DevblocksPlatform::getTranslationService(); $stack = $request->path; array_shift($stack); // update $cache = DevblocksPlatform::getCacheService(); /* @var $cache _DevblocksCacheManager */ switch (array_shift($stack)) { case 'locked': if (!DevblocksPlatform::versionConsistencyCheck()) { $url = DevblocksPlatform::getUrlService(); echo "<h1>Feg - Fax Email Gateway 1.x</h1>"; echo "The application is currently waiting for an administrator to finish upgrading. " . "Please wait a few minutes and then " . sprintf("<a href='%s'>try again</a>.<br><br>", $url->write('c=update&a=locked')); echo sprintf("If you're an admin you may <a href='%s'>finish the upgrade</a>.", $url->write('c=update')); } else { DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login'))); } break; default: $path = APP_TEMP_PATH . DIRECTORY_SEPARATOR; $file = $path . 'feg_update_lock'; $settings = DevblocksPlatform::getPluginSettingsService(); $authorized_ips_str = $settings->get('feg.core', FegSettings::AUTHORIZED_IPS); $authorized_ips = DevblocksPlatform::parseCrlfString($authorized_ips_str); $authorized_ip_defaults = DevblocksPlatform::parseCsvString(AUTHORIZED_IPS_DEFAULTS); $authorized_ips = array_merge($authorized_ips, $authorized_ip_defaults); // Is this IP authorized? $pass = false; foreach ($authorized_ips as $ip) { if (substr($ip, 0, strlen($ip)) == substr($_SERVER['REMOTE_ADDR'], 0, strlen($ip))) { $pass = true; break; } } if (!$pass) { echo vsprintf($translate->_('update.ip_unauthorized'), $_SERVER['REMOTE_ADDR']); return; } // Check requirements $errors = FegApplication::checkRequirements(); if (!empty($errors)) { echo $translate->_('update.correct_errors'); echo "<ul style='color:red;'>"; foreach ($errors as $error) { echo "<li>" . $error . "</li>"; } echo "</ul>"; exit; } try { // If authorized, lock and attempt update if (!file_exists($file) || @filectime($file) + 600 < time()) { // 10 min lock // Log everybody out since we're touching the database $session = DevblocksPlatform::getSessionService(); $session->clearAll(); // Lock file touch($file); // Recursive patch FegApplication::update(); // Clean up @unlink($file); $cache = DevblocksPlatform::getCacheService(); $cache->save(APP_BUILD, "devblocks_app_build"); // Clear all caches $cache->clean(); DevblocksPlatform::getClassLoaderService()->destroy(); // Clear compiled templates $tpl = DevblocksPlatform::getTemplateService(); $tpl->utility->clearCompiledTemplate(); $tpl->cache->clearAll(); // Reload plugin translations DAO_Translation::reloadPluginStrings(); // Redirect DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login'))); } else { echo $translate->_('update.locked_another'); } } catch (Exception $e) { unlink($file); die($e->getMessage()); } } exit; }
function saveTabPluginsAction() { $translate = DevblocksPlatform::getTranslationService(); $worker = FegApplication::getActiveWorker(); if (!$worker || !$worker->is_superuser) { echo $translate->_('common.access_denied'); return; } $pluginStack = DevblocksPlatform::getPluginRegistry(); @($plugins_enabled = DevblocksPlatform::importGPC($_REQUEST['plugins_enabled'])); if (is_array($pluginStack)) { foreach ($pluginStack as $plugin) { /* @var $plugin DevblocksPluginManifest */ switch ($plugin->id) { case 'devblocks.core': case 'feg.core': case 'feg.auditlog': $plugin->setEnabled(true); break; default: if (null !== $plugins_enabled && false !== array_search($plugin->id, $plugins_enabled)) { $plugin->setEnabled(true); } else { $plugin->setEnabled(false); } break; } } } try { FegApplication::update(); } catch (Exception $e) { // [TODO] ... } DevblocksPlatform::clearCache(); // Reload plugin translations DAO_Translation::reloadPluginStrings(); DevblocksPlatform::redirect(new DevblocksHttpResponse(array('setup', 'plugins'))); }
function handleRequest(DevblocksHttpRequest $request) { @set_time_limit(0); // no timelimit (when possible) $translate = DevblocksPlatform::getTranslationService(); $stack = $request->path; array_shift($stack); // update $cache = DevblocksPlatform::getCacheService(); /* @var $cache _DevblocksCacheManager */ $settings = DevblocksPlatform::getPluginSettingsService(); switch (array_shift($stack)) { case 'locked': if (!DevblocksPlatform::versionConsistencyCheck()) { $url = DevblocksPlatform::getUrlService(); echo "<h1>Cerberus Helpdesk 5.x</h1>"; echo "The helpdesk is currently waiting for an administrator to finish upgrading. " . "Please wait a few minutes and then " . sprintf("<a href='%s'>try again</a>.<br><br>", $url->write('c=update&a=locked')); echo sprintf("If you're an admin you may <a href='%s'>finish the upgrade</a>.", $url->write('c=update')); } else { DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login'))); } break; default: $path = APP_TEMP_PATH . DIRECTORY_SEPARATOR; $file = $path . 'c4update_lock'; $authorized_ips_str = $settings->get('cerberusweb.core', CerberusSettings::AUTHORIZED_IPS); $authorized_ips = DevblocksPlatform::parseCrlfString($authorized_ips_str); $authorized_ip_defaults = DevblocksPlatform::parseCsvString(AUTHORIZED_IPS_DEFAULTS); $authorized_ips = array_merge($authorized_ips, $authorized_ip_defaults); // Is this IP authorized? $pass = false; foreach ($authorized_ips as $ip) { if (substr($ip, 0, strlen($ip)) == substr($_SERVER['REMOTE_ADDR'], 0, strlen($ip))) { $pass = true; break; } } if (!$pass) { echo vsprintf($translate->_('update.ip_unauthorized'), $_SERVER['REMOTE_ADDR']); return; } // Check requirements $errors = CerberusApplication::checkRequirements(); if (!empty($errors)) { echo $translate->_('update.correct_errors'); echo "<ul style='color:red;'>"; foreach ($errors as $error) { echo "<li>" . $error . "</li>"; } echo "</ul>"; exit; } // If authorized, lock and attempt update if (!file_exists($file) || @filectime($file) + 600 < time()) { // 10 min lock touch($file); //echo "Running plugin patches...<br>"; if (DevblocksPlatform::runPluginPatches('core.patches')) { @unlink($file); // [JAS]: Clear all caches $cache->clean(); DevblocksPlatform::getClassLoaderService()->destroy(); // Clear compiled templates $tpl = DevblocksPlatform::getTemplateService(); $tpl->clear_compiled_tpl(); // Reload plugin translations DAO_Translation::reloadPluginStrings(); DevblocksPlatform::redirect(new DevblocksHttpResponse(array('login'))); } else { @unlink($file); echo "Failure!"; // [TODO] Needs elaboration } break; } else { echo $translate->_('update.locked_another'); } } exit; }
/** * @return _DevblocksTranslationManager */ static function getTranslationService() { static $languages = array(); $locale = DevblocksPlatform::getLocale(); // Registry if (isset($languages[$locale])) { return $languages[$locale]; } $cache = self::getCacheService(); if (null === ($map = $cache->load(self::CACHE_TAG_TRANSLATIONS . '_' . $locale))) { /* @var $cache _DevblocksCacheManager */ $map = array(); $map_en = DAO_Translation::getMapByLang('en_US'); if (0 != strcasecmp('en_US', $locale)) { $map_loc = DAO_Translation::getMapByLang($locale); } // Loop through the English string objects if (is_array($map_en)) { foreach ($map_en as $string_id => $obj_string_en) { $string = ''; // If we have a locale to check if (isset($map_loc) && is_array($map_loc)) { @($obj_string_loc = $map_loc[$string_id]); @($string = !empty($obj_string_loc->string_override) ? $obj_string_loc->string_override : $obj_string_loc->string_default); } // If we didn't hit, load the English default if (empty($string)) { @($string = !empty($obj_string_en->string_override) ? $obj_string_en->string_override : $obj_string_en->string_default); } // If we found any match if (!empty($string)) { $map[$string_id] = $string; } } } unset($obj_string_en); unset($obj_string_loc); unset($map_en); unset($map_loc); // Cache with tag (tag allows easy clean for multiple langs at once) $cache->save($map, self::CACHE_TAG_TRANSLATIONS . '_' . $locale); } $translate = _DevblocksTranslationManager::getInstance(); $translate->addLocale($locale, $map); $translate->setLocale($locale); $languages[$locale] = $translate; return $translate; }
case 'devblocks.core': case 'feg.core': case 'feg.auditlog': $plugin->setEnabled(true); break; default: $plugin->setEnabled(false); break; } } } // Platform + App try { FegApplication::update(); // Reload plugin translations DAO_Translation::reloadPluginStrings(); // Success $tpl->assign('step', STEP_CONTACT); $tpl->display('steps/redirect.tpl'); exit; // [TODO] Verify the database } catch (Exception $e) { $tpl->assign('error', $e->getMessage()); $tpl->assign('template', 'steps/step_init_db.tpl'); exit; } } else { // upgrade / patch /* * [TODO] We should probably only forward to upgrade when we know * the proper tables were installed. We may be repeating an install
static function importTmxFile($filename) { $db = DevblocksPlatform::getDatabaseService(); if (!file_exists($filename)) { return; } /* * [JAS] [TODO] This could be inefficient when reading a lot * of TMX sources, but it could also be inefficient always * keeping it in memory after using it once. I'm going to err * on the side of a little extra DB work for the few times it's * called. */ $hash = array(); foreach (DAO_Translation::getWhere() as $s) { /* @var $s Model_TranslationDefault */ $hash[$s->lang_code . '_' . $s->string_id] = $s; } if (false == @($xml = simplexml_load_file($filename))) { /* @var $xml SimpleXMLElement */ return; } $namespaces = $xml->getNamespaces(true); foreach ($xml->body->tu as $tu) { /* @var $tu SimpleXMLElement */ $msgid = strtolower((string) $tu['tuid']); foreach ($tu->tuv as $tuv) { /* @var $tuv SimpleXMLElement */ $attribs = $tuv->attributes($namespaces['xml']); $lang = (string) $attribs['lang']; $string = (string) $tuv->seg[0]; // [TODO] Handle multiple segs? @($hash_obj = $hash[$lang . '_' . $msgid]); /* @var $hash_obj Model_Translation */ // If not found in the DB if (empty($hash_obj)) { $fields = array(DAO_Translation::STRING_ID => $msgid, DAO_Translation::LANG_CODE => $lang, DAO_Translation::STRING_DEFAULT => $string); $id = DAO_Translation::create($fields); // Add to our hash to prevent dupes $new = new Model_Translation(); $new->id = $id; $new->string_id = $msgid; $new->lang_code = $lang; $new->string_default = $string; $new->string_override = ''; $hash[$lang . '_' . $msgid] = $new; // If exists in DB and the string has changed } elseif (!empty($hash_obj) && 0 != strcasecmp($string, $hash_obj->string_default)) { $fields = array(DAO_Translation::STRING_DEFAULT => $string); DAO_Translation::update($hash_obj->id, $fields); } } } unset($xml); }
function showGeneralAction() { $date_service = DevblocksPlatform::getDateService(); $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = $this->_TPL_PATH; $tpl->assign('path', $tpl_path); $worker = CerberusApplication::getActiveWorker(); $tpl->assign('worker', $worker); $tour_enabled = intval(DAO_WorkerPref::get($worker->id, 'assist_mode', 1)); $tpl->assign('assist_mode', $tour_enabled); $keyboard_shortcuts = intval(DAO_WorkerPref::get($worker->id, 'keyboard_shortcuts', 1)); $tpl->assign('keyboard_shortcuts', $keyboard_shortcuts); $mail_inline_comments = DAO_WorkerPref::get($worker->id, 'mail_inline_comments', 1); $tpl->assign('mail_inline_comments', $mail_inline_comments); $mail_always_show_all = DAO_WorkerPref::get($worker->id, 'mail_always_show_all', 0); $tpl->assign('mail_always_show_all', $mail_always_show_all); $addresses = DAO_AddressToWorker::getByWorker($worker->id); $tpl->assign('addresses', $addresses); // Timezones $tpl->assign('timezones', $date_service->getTimezones()); @($server_timezone = date_default_timezone_get()); $tpl->assign('server_timezone', $server_timezone); // Languages $langs = DAO_Translation::getDefinedLangCodes(); $tpl->assign('langs', $langs); $tpl->assign('selected_language', DAO_WorkerPref::get($worker->id, 'locale', 'en_US')); $tpl->display('file:' . $tpl_path . 'preferences/modules/general.tpl'); }
function saveViewAction() { @($row_ids = DevblocksPlatform::importGPC($_REQUEST['row_ids'], 'array', array())); @($translations = DevblocksPlatform::importGPC($_REQUEST['translations'], 'array', array())); // Save the form strings if (is_array($row_ids)) { foreach ($row_ids as $idx => $row_id) { $fields = array(DAO_Translation::STRING_OVERRIDE => $translations[$idx]); DAO_Translation::update($row_id, $fields); } } self::_clearCache(); DevblocksPlatform::redirect(new DevblocksHttpResponse(array('setup', 'translations'))); }
function showTabGeneralAction() { $date_service = DevblocksPlatform::getDateService(); $tpl = DevblocksPlatform::getTemplateService(); $tpl_path = $this->_TPL_PATH; $tpl->assign('path', $tpl_path); $worker = PortSensorApplication::getActiveWorker(); $tpl->assign('worker', $worker); $assist_mode = intval(DAO_WorkerPref::get($worker->id, 'assist_mode', 1)); $tpl->assign('assist_mode', $assist_mode); $keyboard_shortcuts = intval(DAO_WorkerPref::get($worker->id, 'keyboard_shortcuts', 1)); $tpl->assign('keyboard_shortcuts', $keyboard_shortcuts); // Timezones $tpl->assign('timezones', $date_service->getTimezones()); @($server_timezone = date_default_timezone_get()); $tpl->assign('server_timezone', $server_timezone); // Languages $langs = DAO_Translation::getDefinedLangCodes(); $tpl->assign('langs', $langs); $tpl->assign('selected_language', DAO_WorkerPref::get($worker->id, 'locale', 'en_US')); $tpl->display('file:' . $tpl_path . 'preferences/tabs/general.tpl'); }