function indexAction() { $params = array('locale_code' => $this->locale_code, 'request' => $this->getRequest()); if ($this->_auth->hasIdentity()) { $params['is_admin'] = $this->_identity->isAdmin; } else { $params['is_admin'] = false; } $additional = $this->_Bolts_plugin->doFilter($this->_mca, $params); // FILTER HOOK foreach ($additional as $key => $value) { $this->view->{$key} = $value; } // $this->view->welcome = $this->_T("Welcome!"); // TODO - find out if there is a valid cookie // then redirect to that locale // or redirect to the default locale // ONLY if localization is enabled // if localization is enabled and the URI does not contain a locale code // and there is not a valid locale cookie // redirect to a URI that contains the default locale code if (Bolts_Registry::get('enable_localization') == '1') { $locales_table = new Locales(); $locale_codes = $locales_table->getLocaleCodes(true); $uri_parts = explode("/", trim($this->_uri, "/")); if (count($uri_parts) > 0 && !in_array($uri_parts[0], $locale_codes)) { // redirect method will automatically add the correct locale code to the URI $this->_redirect("/"); } } }
public function stripssl($out_url, array $params = null) { if (stripos($out_url, "/") === 0) { if ($params) { $out_url = $this->filter($out_url, $params); } $out_url = str_replace('https://', 'http://', Bolts_Registry::get('site_url') . $out_url); } else { // TODO - add other cases, such as absolute and relative URLs } return $out_url; }
static function translate($locale_code, $module_name, $key, $replace = null, $do_translation = true) { // DON'T EVER LEAVE THIS UNCOMMENTED // ob_clean(); // can be useful for debugging since using dd() will dump out into the existing markup and be hard to see // but this clears out all the other markup so the debug data can be seen clearly $translation = $key; if ($do_translation) { if (Bolts_Registry::get('enable_localization') == '1' && !is_null($module_name) && trim($module_name) != "" && !is_null($key) && trim($key) != "") { $locale_code = Bolts_Translate::cleanZendLocaleCode($locale_code); $path_to_csv = Bolts_Registry::get('basepath') . "/modules/" . $module_name . "/languages/" . $locale_code . ".csv"; if (file_exists($path_to_csv)) { try { $translate = new Zend_Translate("csv", $path_to_csv, $locale_code, array('delimiter' => ",")); $translation = $translate->_($key); // this next bit will populate the locale file with untranslated terms // so it's easier for someone to go through and translate them if (Bolts_Registry::get('auto_populate_language_files') == '1') { if (!$translate->isTranslated($key, true, $locale_code)) { $key_no_quotes = str_replace('"', '"', $key); $str = '"' . $key_no_quotes . '","' . $key_no_quotes . '"' . "\n"; file_put_contents($path_to_csv, $str, FILE_APPEND); } } } catch (Exception $e) { $translation = $key; } } else { // create the file file_put_contents($path_to_csv, $key . ',' . $key); } } } $output = ""; if (is_null($replace)) { // no replace, no sprintf $output = $translation; } else { if (is_array($replace)) { if (count($replace) > 1) { // there are multiple indices, use vsprintf $output = vsprintf($translation, $replace); } else { // there's only one index, use the cheaper sprintf instead $output = sprintf($translation, $replace[0]); } } else { // $replace is not an array, so try using it straight $output = sprintf($translation, $replace); } } return $output; }
function smarty_block_translate($params, $content, $smarty, $repeat) { $tpl_vars = $smarty->_tpl_vars; // only output on the closing tag if (!$repeat) { if (isset($content)) { $do_translation = true; if ($smarty->_tpl_vars['isAdminController'] && Bolts_Registry::get('enable_admin_localization', 'default') == '0') { $do_translation = false; } if ($params['replace']) { return Bolts_Translate::translate($tpl_vars['locale_code'], "default", $content, $params['replace'], $do_translation); } else { return Bolts_Translate::translate($tpl_vars['locale_code'], "default", $content, null, $do_translation); } } } }
function setcookieAction() { // TODO maybe? - prevent people from viewing this page if localization is not enabled $request = new Bolts_Request($this->getRequest()); if ($request->has("code") && $request->code != "") { $locale_code = $request->code; $time = Bolts_Registry::get('locale_cache_lifetime'); if (Bolts_Translate::validateLocaleCode($locale_code)) { setcookie("locale_code", $locale_code, time() + $time, "/"); if ($request->has("return_url")) { $url_filter = new Bolts_Url_Filter(); header("Location: " . $url_filter->filter($request->return_url, array('locale_code' => $locale_code))); } else { header("Location: /" . $locale_code); } } } else { $this->_redirect("/bolts/locale/choose/"); } }
function extract($source) { // TODO - should remove this default value $Bolts_id = Bolts_Registry::get('yahoo_api_Bolts_id'); $curl_handle = curl_init(); $keywords = null; $all_keywords = null; $filter = new Bolts_FilterTags(); $noisewords = Bolts_NoiseWords::getAll(); $url = "http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction"; curl_setopt($curl_handle, CURLOPT_URL, $url); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "appid=" . $Bolts_id . "&output=php&context=" . urlencode($source)); $buffer = curl_exec($curl_handle); curl_close($curl_handle); $results = unserialize($buffer); if (is_array($results['ResultSet'])) { if (!is_array($results['ResultSet']['Result'])) { $all_keywords = array($results['ResultSet']['Result']); } else { $all_keywords = $results['ResultSet']['Result']; } } $keywords = array(); if (is_array($all_keywords)) { foreach ($all_keywords as $keyword) { // this is probably overkill, but in case I ever need to check for other things, I'm okay. $errors = 0; if (in_array($keyword, $noisewords)) { $errors++; } if ($errors == 0) { $keywords[] = $filter->filter($keyword); } } } return $keywords; }
function testdataAction() { $request = new Bolts_Request($this->getRequest()); if ($this->getRequest()->isPost()) { $errors = array(); $data_path = $request->data_path; $data_file = $data_path . "/users.dat"; $image_dir = $data_path . "/images"; $users_table = new Users(); $users_roles_table = new UsersRoles(); if ($request->has("email_domain")) { $email_domain = $request->email_domain; } else { $email_domain = "nowhere.com"; } if (!file_exists($data_file)) { $errors[] = $this->_T("Data file missing. Check path."); } else { $users = unserialize(file_get_contents($data_file)); if (!is_array($users)) { $errors[] = $this->_T("Data file is corrupt or something."); } } if (count($errors) == 0) { $old_users = $users_table->fetchAll(); foreach ($old_users as $old_user) { if ($users_table->getMetaData($old_user->username, "is_test_user") == "true") { $where = $users_table->getAdapter()->quoteInto("username = ?", $old_user->username); $users_table->delete($where); $users_roles_table->delete($where); } } $count = 0; foreach ($users as $user) { $tmp_user = array(); foreach ($user as $key => $value) { if ($key != "avatar") { $tmp_user[$key] = $value; } } $tmp_user['email'] = strtolower($tmp_user['username'] . "@" . $email_domain); $tmp_user['password'] = "******"; $destination_path = $users_table->getAvatarPath($user['username']); $destination_filename = $users_table->getAvatarPath($user['username'], true); if (!is_dir($destination_path)) { mkdir($destination_path, 0777, true); } if (file_exists($destination_filename)) { unlink($destination_filename); } $source_image = $image_dir . "/" . $user['avatar']; copy($source_image, $destination_filename); $role_data = array("username" => $tmp_user['username'], "role_id" => $tmp_user['role_id']); $users_roles_table->insert($role_data); unset($tmp_user['role_id']); $users_table->insert($tmp_user); $users_table->setMetaData($tmp_user['username'], "is_test_user", "true"); $save_users[] = $user; $count++; } $this->view->success = "User data loaded. Created " . $count . " users."; Bolts_Registry::set('test_data_path', $request->data_path); $this->view->data_path = Bolts_Registry::get('test_data_path'); $this->view->email_domain = $email_domain; } else { $this->view->errors = $errors; $this->view->data_path = Zend_Registry::get('basepath') . "/tmp/testdata"; $this->view->email_domain = $request->email_domain; } } else { $this->view->data_path = Zend_Registry::get('basepath') . "/tmp/testdata"; $this->view->email_domain = "nowhere.com"; $this->view->notice = $this->_T("Warning: If you are reinstalling the test data, the old test data will be overwritten. Users created outside the test data should not be affected."); } }
public function write($id, $value) { $sessions_table = new Sessions(); $lifetime = (int) Bolts_Registry::get('session_timeout'); $expiration = time() + $lifetime; $data = array('id' => $id, 'value' => $value, 'expiration' => $expiration); $where = $sessions_table->getAdapter()->quoteInto('id = ?', $id); if ($sessions_table->getCountByWhereClause($where) > 0) { $sessions_table->update($data, $where); } else { $id = $sessions_table->insert($data); } }
function getAvatarPath($username, $include_filename = false) { $path = Bolts_Registry::get('upload_path') . "/" . $username . "/original"; $params['path'] = $path; $params['filename'] = Bolts_Registry::get('avatar_filename'); $params = $this->_Bolts_plugin->doFilter("bolts_users_table_avatar_path", $params); if ($include_filename) { return $params['path'] . "/" . $params['filename']; } else { return $params['path']; } }
function init() { $params = array('username' => null); $modules_table = new Modules("core"); $roles_table = new Roles(); $enabled_modules = $modules_table->getEnabledModules(); foreach ($enabled_modules as $enabled_module) { $this->view->{"module_" . $enabled_module} = true; } if (!empty($_SERVER['HTTPS'])) { $this->view->is_ssl = true; $this->_is_ssl = true; } else { $this->view->is_ssl = false; $this->_is_ssl = false; } $this->_uri = $_SERVER['REQUEST_URI']; $this->_host_id = Zend_Registry::get('host_id'); $this->view->host_id = $this->_host_id; $this->view->session_id = Zend_Session::getId(); $this->view->site_url = Bolts_Registry::get('site_url'); $this->view->site_name = Bolts_Registry::get('site_name'); $this->registry = Zend_Registry::getInstance(); $this->session = new Zend_Session_Namespace('Default'); $this->_mca = $this->_request->getModuleName() . "_" . $this->_request->getControllerName() . "_" . $this->_request->getActionName(); $this->view->mca = str_replace("_", "-", $this->_mca); $this->view->controller_name = $this->_request->getControllerName(); $this->module_name = $this->_request->getModuleName(); $this->view->module_name = $this->_request->getModuleName(); $this->view->action_name = $this->_request->getActionName(); $this->_auth = Zend_Auth::getInstance(); if ($this->_auth->hasIdentity()) { $this->_identity = $this->_auth->getIdentity(); $this->view->isLoggedIn = true; $params['username'] = $this->_identity->username; $users_table = new Users(); $loggedInUser = $users_table->fetchByUsername($this->_identity->username); if (!is_null($loggedInUser)) { $this->_loggedInUser = $loggedInUser; $this->view->loggedInUser = $loggedInUser->toArray(); } $this->view->loggedInUsername = $this->_identity->username; $this->view->loggedInFullName = $this->_identity->full_name; $loggedInRoleIds = $roles_table->getRoleIdsByUsername($this->_identity->username); $this->view->loggedInRoleIds = $loggedInRoleIds; foreach ($loggedInRoleIds as $role_id) { $role = $roles_table->fetchRow('id = ' . $role_id); if ((bool) $role->isadmin) { $this->view->isAdmin = true; $this->_identity->isAdmin = true; } } } else { $this->_identity = null; $this->view->isLoggedIn = false; } $appNamespace = new Zend_Session_Namespace('Bolts_Temp'); $this->view->last_login = $appNamespace->last_login; $this->_Bolts_plugin = Bolts_Plugin::getInstance(); $this->_theme_locations = Zend_Registry::get('theme_locations'); // Theme filter block: Allow plugin's to alter the current theme based on request, locale, etc. $theme_params = array('request' => $this->_request, 'admin' => array('current_theme' => $this->_theme_locations['admin']['current_theme']), 'frontend' => array('current_theme' => $this->_theme_locations['frontend']['current_theme'])); $theme_params = $this->_Bolts_plugin->doFilter('current_themes', $theme_params); // FILTER HOOK if (file_exists($theme_params['admin']['current_theme']['path'])) { $this->_theme_locations['admin']['current_theme'] = $theme_params['admin']['current_theme']; } if (file_exists($theme_params['frontend']['current_theme']['path'])) { $this->_theme_locations['frontend']['current_theme'] = $theme_params['frontend']['current_theme']; $template_path = $this->_theme_locations['frontend']['current_theme']['path'] . "/modules/" . $this->getRequest()->getModuleName(); $this->view->setScriptPath($template_path); } // Theme filter block: End. $this->view->theme_path = $this->_theme_locations['frontend']['current_theme']['path']; $this->view->theme_url = $this->_theme_locations['frontend']['current_theme']['url']; $this->view->theme_global_path = $this->_theme_locations['frontend']['current_theme']['path'] . "/global"; $this->view->theme_global = $this->view->theme_global_path; $this->view->theme_controller_path = $this->_theme_locations['frontend']['current_theme']['path'] . '/modules/' . $this->getRequest()->getModuleName() . "/" . $this->getRequest()->getControllerName(); $this->view->theme_module_path = $this->_theme_locations['frontend']['current_theme']['path'] . '/modules/' . $this->getRequest()->getModuleName(); $this->view->default_theme_path = $this->_theme_locations['frontend']['default_theme']['path']; $this->view->default_theme_url = $this->_theme_locations['frontend']['default_theme']['url']; $this->view->default_theme_global_path = $this->_theme_locations['frontend']['default_theme']['path'] . "/global"; $this->view->default_theme_controller_path = $this->_theme_locations['frontend']['default_theme']['path'] . '/modules/' . $this->getRequest()->getModuleName() . "/" . $this->getRequest()->getControllerName(); $this->view->default_theme_module_path = $this->_theme_locations['frontend']['default_theme']['path'] . '/modules/' . $this->getRequest()->getModuleName(); Bolts_Log::report("Current path " . $this->_mca, null, Zend_Log::INFO); $this->view->isAdminController = false; $this->view->title_prefix = Bolts_Registry::get('title_prefix'); $locale_is_valid = true; $default_locale_code = str_replace('_', '-', trim(strtolower(Bolts_Registry::get('default_locale')))); $this->locale_code = $default_locale_code; if (Bolts_Registry::get('enable_localization') == '1') { // to set the locale code, look in the URL, not in the cookie // the only thing that should check the cookie is the home page and optionally the locale chooser page $locales_table = new Locales(); $db_locales_full = $locales_table->getLocaleCodesArray(true); $db_locales = array_keys($db_locales_full); // Get the locales allowed in the config $allowed_locales = explode(',', Bolts_Registry::get('allowed_locales')); if (!empty($allowed_locales) && (bool) array_filter($allowed_locales)) { $allowed_locales = array_map('trim', $allowed_locales); $allowed_locales = array_map('strtolower', $allowed_locales); $allowed_locales = str_replace('_', '-', $allowed_locales); } else { throw new Exception('Localization is enabled, but no locales are set in `allowed_locales`'); } // Load the allowed locales into Smarty for the admin drop down $all_locales = array(); foreach ($db_locales_full as $code => $name) { if (in_array($code, $allowed_locales)) { $all_locales[$code] = $name; } } $this->view->locale_codes = $all_locales; // Get the locales allowed on the frontend in the config $live_locales = explode(',', Bolts_Registry::get('live_locales')); if (!empty($live_locales) && (bool) array_filter($live_locales)) { $live_locales = array_map('trim', $live_locales); $live_locales = array_map('strtolower', $live_locales); $live_locales = str_replace('_', '-', $live_locales); $this->live_locales = $live_locales; } else { throw new Exception('Localization is enabled, but no locales are set in `live_locales`'); } if ($this->_request->has('locale') && $this->_request->locale != '') { $locale_code = $this->_request->get('locale'); if ($locale_code !== $default_locale_code) { if (ereg("^..-.{2,5}", $locale_code) !== false) { // Get the locales out of the database if (!in_array($locale_code, $db_locales) || !in_array($locale_code, $allowed_locales)) { $locale_is_valid = false; } if ($this->view->isAdmin !== true) { if (!in_array($locale_code, $this->live_locales)) { $locale_is_valid = false; } } } else { $locale_is_valid = false; } } if ($locale_is_valid) { $store_locales = explode(',', Bolts_Registry::get('store_enabled_locales')); if (!empty($store_locales) && (bool) array_filter($store_locales)) { $store_locales = array_map('trim', $store_locales); $store_locales = array_map('strtolower', $store_locales); $store_locales = str_replace('_', '-', $store_locales); if (!in_array($locale_code, $store_locales)) { $this->view->store_enabled = false; } else { $this->view->store_enabled = true; } } else { $this->view->store_enabled = false; } } $locale_params = array('request' => $this->_request, 'locale_code' => $locale_code, 'locale_is_valid' => $locale_is_valid); $locale_params = $this->_Bolts_plugin->doFilter('validate_locale', $locale_params); // FILTER HOOK $locale_code = $locale_params['locale_code']; $locale_is_valid = $locale_params['locale_is_valid']; if ($locale_is_valid == true) { // The locale is good. $this->locale_code = $locale_code; $this->default_locale_code = $default_locale_code; $this->view->locale_code = $locale_code; $this->view->default_locale_code = $default_locale_code; $this->view->request_locale = $locale_code; $this->view->default_locale_code = $default_locale_code; } else { if (strtolower($locale_code) !== $locale_code) { // The locale is probably just upper case. Try lower case. $this->locale_code = strtolower($locale_code); $url = str_replace("/{$locale_code}/", '/', $_SERVER['REDIRECT_URL']); // See Apache Quirks: http://framework.zend.com/manual/en/zend.controller.request.html $this->_redirect($url, array('code' => 301)); } else { // This locale is just bad. $this->locale_code = $default_locale_code; $this->view->locale_code = $default_locale_code; // Checking hasIdentity() here would be incorrect, as guests do not have identities, but may have access to this action if (@Bolts_ResourceCheck::isAllowed("choose", "default", $this->_identity->username, 'Locale')) { $this->_redirect("/bolts/locale/choose/"); } else { if (empty($this->_request->locale)) { $this->_redirect("/", array('code' => 301)); } else { $this->_redirect("/bolts/auth/missing/"); } } } } } elseif ($this->_mca == "default_index_index" && isset($_COOKIE['locale_code'])) { $this->_redirect("/" . $_COOKIE['locale_code'] . "/", array(), false); } else { // Checking hasIdentity() here would be incorrect, as guests do not have identities, but may have access to this action if (@Bolts_ResourceCheck::isAllowed("choose", "default", $this->_identity->username, 'Locale')) { $this->_redirect($default_locale_code . "/bolts/locale/choose/"); } else { $this->_redirect($default_locale_code . "/bolts/auth/missing/"); } } } $this->view->custom_metadata = Bolts_Registry::get('custom_metadata'); $language = substr($this->locale_code, 0, strpos($this->locale_code, '-')); // TODO - these should not be hardcoded here switch ($language) { case 'de': $this->view->format_date = "%e. %b. %Y, %l:%M Uhr"; $this->view->format_datetime = "%A, %e. %B %Y um %l:%M:%S%p Uhr"; $this->view->format_datetime_small = "%e %b %Y, %l:%M%p"; break; case 'fr': $this->view->format_date = "%e %b %Y, %l:%M:%S"; $this->view->format_datetime = "%A %e %B %Y à %l:%M:%S%p"; $this->view->format_datetime_small = "%e %b %Y, %l:%M%p"; break; default: $this->view->format_date = Bolts_Registry::get('format_date'); $this->view->format_datetime = Bolts_Registry::get('format_datetime'); $this->view->format_datetime_small = Bolts_Registry::get('format_datetime_small'); break; } $this->view->current_year = date("Y"); // SAVED FOR FUTURE USE - changing the language pack based on locale // $locale_table = new Locales(); // $locale_data = $locale_table->fetchByLocaleCode($this->view->locale_code); // if (count($locale_data) > 0) { // $this->locale_data = $locale_data['0']; // $this->view->locale_data = $this->locale_data; // $lan_pk = $this->locale_data['language_code'].'_'.$this->locale_data['country_code'].'.UTF-8'; // setlocale(LC_ALL, $lan_pk); // setlocale(LC_NUMERIC, 'en_US.UTF-8'); // setlocale(LC_COLLATE, 'en_US.UTF-8'); // } // this is a way to force the browser to reload some scripts if (Bolts_Registry::get('uncache_css_js_version')) { $this->view->uncache_version = "?v=" . Bolts_Registry::get('uncache_css_js_version'); } if (Bolts_Registry::get('uncache_flash_version')) { $this->view->uncache_flash = "?v=" . Bolts_Registry::get('uncache_flash_version'); } // Set the content type to UTF-8 header('Content-type: text/html; charset=UTF-8'); // get navigation items from database or cache // check for role of identity, if we don't have one, use guest. // TODO - move this to the place where role is determined, there should only be one place if ($this->_auth->hasIdentity()) { $tmp_ids = $loggedInRoleIds; $this->my_roles = $roles_table->fetchRolesByUsername($this->_identity->username)->toArray(); $username = $this->_identity->username; $this->view->username = $username; } else { $tmp_ids = array($roles_table->getIdByShortname("guest")); $this->my_roles = array(0 => array("id" => "1", "shortname" => "guest", "description" => "Guest", "is_admin" => "0", "isguest" => "1", "isdefault" => "0")); } $this->view->my_roles = $this->my_roles; // find the parent roles, add the parent role IDs to the nav_role_ids for inheritance. $nav_parent_role_ids = array(); foreach ($tmp_ids as $nav_role) { $nav_parent_role_ids = array_merge($nav_parent_role_ids, $roles_table->getAllAncestors($nav_role)); } $nav_role_ids = array(); $nav_role_ids = array_merge($nav_parent_role_ids, $tmp_ids); $unique_ids = array_unique($nav_role_ids); sort($unique_ids); $nav_table = new Navigation($unique_ids, $this->locale_code); $cache_name = 'navigation_' . $this->locale_code . '-' . md5(implode($unique_ids, "-")); // MD5 The Unique IDs to shorten the cache name $cache_tags = array('navigation', $this->locale_code); $nav_items_temp = false; if (Bolts_Registry::get('enable_navigation_cache') == '1') { $nav_items_temp = Bolts_Cache::load($cache_name); } if ($nav_items_temp === false || !isset($nav_items_temp)) { $nav_items_temp = array(); foreach ($unique_ids as $nav_role_id) { $nav_items_temp = array_merge($nav_items_temp, $nav_table->getNavTree($nav_role_id)); } if (Bolts_Registry::get('enable_navigation_cache') == '1') { Bolts_Cache::save($nav_items_temp, $cache_name, $cache_tags); } } $navparams = array('nav_items' => $nav_items_temp, 'request' => $this->_request, 'locale_code' => $this->locale_code); $navparams = $this->_Bolts_plugin->doFilter('controller_nav', $navparams); // FILTER HOOK $this->view->nav_items = $navparams['nav_items']; // TODO - Rich fix this // // VIEW STATES // if (!$this->session->view_states) { // $this->session->view_states = array(); // } // // TODO - allow use of regular expressions such as /auth/* // $last_visited_pages_filter = explode('|', Bolts_Registry::get('last_visited_pages_filter')); // if (!in_array($this->_uri, $last_visited_pages_filter)) { // $this->session->view_states['last_visited'] = $this->_uri; // } // $this->view->view_states = $this->session->view_states; // CONTROLLER INIT HOOK $params['request'] = $this->_request; $params['locale_code'] = $this->locale_code; $params['session'] = $this->session; $additional = $this->_Bolts_plugin->doFilter('controller_init', $params); // FILTER HOOK unset($additional['request']); // we don't want to send the request to the view if (isset($additional['filter_redirect'])) { $this->_redirect($additional['filter_redirect']); } foreach ($additional as $key => $value) { $this->view->{$key} = $value; } }
function init() { parent::init(); $template_path = $this->_theme_locations['admin']['current_theme']['path'] . "/modules/" . $this->getRequest()->getModuleName(); $this->view->setScriptPath($template_path); $this->view->isAdminController = true; $this->view->admin_theme_path = $this->_theme_locations['admin']['current_theme']['path']; $this->view->admin_theme_url = $this->_theme_locations['admin']['current_theme']['url']; $this->view->admin_theme_global_path = $this->_theme_locations['admin']['current_theme']['path'] . "/global"; $this->view->admin_theme_controller_path = $this->_theme_locations['admin']['current_theme']['path'] . '/modules/' . $this->getRequest()->getModuleName() . "/" . $this->getRequest()->getControllerName(); $this->view->admin_theme_module_path = $this->_theme_locations['admin']['current_theme']['path'] . '/modules/' . $this->getRequest()->getModuleName(); $this->view->default_admin_theme_path = $this->_theme_locations['admin']['default_theme']['path']; $this->view->default_admin_theme_url = $this->_theme_locations['admin']['default_theme']['url']; $this->view->default_admin_theme_global_path = $this->_theme_locations['admin']['default_theme']['path'] . "/global"; $this->view->default_admin_theme_controller_path = $this->_theme_locations['admin']['default_theme']['path'] . '/modules/' . $this->getRequest()->getModuleName() . "/" . $this->getRequest()->getControllerName(); $this->view->default_admin_theme_module_path = $this->_theme_locations['admin']['default_theme']['path'] . '/modules/' . $this->getRequest()->getModuleName(); $request = $this->getRequest(); if ($request->has('dev') && $request->dev == true) { $this->view->isDeveloper = true; } $this->view->current_path = $template_path . "/" . $this->getRequest()->getControllerName(); $roles_table = new Roles(); $locale_table = new Locales(); if ($this->_identity->isAdmin) { $bypass = array(); $globalRoles = explode(",", Bolts_Registry::get('global_role_shortnames')); $inherited_roles = array(); foreach ($this->my_roles as $role => $value) { $ids = $roles_table->getAllAncestors($value['id']); $inherited_roles = array_merge($inherited_roles, $ids, array($value['id'])); $all_shortnames = array(array("id" => $value['id'], "shortname" => $value['shortname'])); foreach ($ids as $bp) { $all_shortnames[] = array("id" => $bp, "shortname" => $roles_table->getShortnameById($bp)); } $all_locales = $locale_table->getLocaleCodesArray(true); foreach ($all_shortnames as $sn) { if (array_key_exists(strtolower(substr($sn['shortname'], -5)), $all_locales) && strtolower(substr($sn['shortname'], -5)) == strtolower($this->locale_code)) { $bypass[] = $sn['id']; // if current locale, get other locale restricted roles for that locale for navigation } if (strtolower(substr($sn['shortname'], -6)) == "global" || in_array($sn['shortname'], $globalRoles) || in_array($sn['id'], $globalRoles)) { $bypass[] = $sn['id']; } } } $inherited_roles = array_unique($inherited_roles); sort($inherited_roles); $this->view->all_roles = array_unique($inherited_roles); $bypass = array_unique($bypass); sort($bypass); $this->view->bypass = $bypass; if (@Bolts_ResourceCheck::isAllowed("locale_specific_admin_role", "default", $this->_identity->username)) { $this->_bumpRegionalAccess($bypass); } // This variable is set in $this->_bumpRegionalAccess() if (isset($this->restricted_role_id) && count($this->restricted_role_id) > 0) { $restr = array(); foreach ($this->restricted_role_id as $role) { $restr[] = $role['id']; } $tmp_ids = array_unique($restr); $nav_parent_role_ids = array(); foreach ($tmp_ids as $nav_role) { $nav_parent_role_ids = array_merge($nav_parent_role_ids, $roles_table->getAllAncestors($nav_role)); } $nav_role_ids = array_merge($nav_parent_role_ids, $tmp_ids, $bypass); $unique_ids = array_unique($nav_role_ids); $nav_table = new Navigation($unique_ids, $this->locale_code); $cache = new Bolts_Cache(); $cache_name = 'navigation_admin_' . $this->locale_code . '-' . md5(implode($unique_ids, "-")); // MD5 The Unique IDs to shorten the cache name $cache_tags = array('navigation', 'admin_navigation', $this->locale_code); $nav_items_temp = $cache->load($cache_name); if ($nav_items_temp === false || !isset($nav_items_temp)) { $nav_items_temp = array(); foreach ($unique_ids as $nav_role_id) { $nav_items_temp = array_merge($nav_items_temp, $nav_table->getNavTree($nav_role_id)); } $cache->save($nav_items_temp, $cache_name, $cache_tags); } $navparams = array('nav_items' => $nav_items_temp, 'request' => $this->_request, 'locale_code' => $this->locale_code); $navparams = $this->_Bolts_plugin->doFilter('controller_nav', $navparams); // FILTER HOOK $this->view->nav_items = $navparams['nav_items']; $this->view->access = $this->restricted_role_id; } else { $access = array(); $roles = $inherited_roles; foreach ($roles as $role) { $in = $this->_checkMatch($role); if (count($in) > 0) { foreach ($in as $i) { $access[] = array("id" => $i, "shortname" => $roles_table->getShortnameById($i)); } } } $this->view->access = $access; } } }
protected function _checkConfirmationUrl($email, $code) { $salt = Bolts_Registry::get('salt'); $test = $email . $salt; if (md5($test) == $code) { return true; } else { return false; } }
function sendEmail($subject, $to_address, $template, $params = null, $to_name = null, $isHtml = false) { $useAuth = Bolts_Registry::get('smtp_use_auth'); if (array_key_exists('from_email', $params)) { $site_from_email = $params['from_email']; } else { $site_from_email = Bolts_Registry::get('site_from_email'); } // TODO - shouldn't this be from_name instead of from_email ? if (array_key_exists('from_name', $params)) { $site_from = $params['from_name']; } else { $site_from = Bolts_Registry::get('site_from'); } $smtp = Bolts_Registry::get('smtp_server'); $username = Bolts_Registry::get('smtp_username'); $password = Bolts_Registry::get('smtp_password'); $ssl = Bolts_Registry::get('smtp_ssl_type'); //tls $smtp_port = Bolts_Registry::get('smtp_port'); $config = array(); if ($useAuth == 1) { $config = array('auth' => 'login', 'username' => $username, 'password' => $password, 'ssl' => $ssl, 'port' => (int) $smtp_port); } try { $mailTransport = new Zend_Mail_Transport_Smtp($smtp, $config); // defines gmail smtp infrastructure as default for any email message originated by Zend_Mail. Zend_Mail::setDefaultTransport($mailTransport); $mail = new Zend_Mail(); foreach ($params as $key => $value) { $this->_smarty->assign($key, $value); } $message = $this->_smarty->fetch($template); if ($isHtml) { $mail->setBodyHtml($message); } else { $mail->setBodyText($message); } $mail->setFrom($site_from_email, $site_from); if (!is_null($to_name) && trim($to_name) != '') { $mail->addTo($to_address, $to_name); } else { $mail->addTo($to_address); } $mail->setSubject($subject); $mail->setReturnPath(Bolts_Registry::get('site_from_email')); $id_part = substr($site_from_email, strpos('@', $site_from_email)); $message_id = md5(uniqid()) . $id_part; //$mail->addHeader('Message-Id', $message_id); $mail->send(); } catch (Exception $e) { Bolts_Log::report('email: could not send', $e, Zend_Log::ERR); } }
$front->throwExceptions(true); $front->setParam('noViewRenderer', false); $view_renderer = new Zend_Controller_Action_Helper_ViewRenderer($view); $view_renderer->setNoController(true)->setViewBasePathSpec($theme_locations['frontend']['current_theme']['path'] . '/modules/:module')->setViewScriptPathSpec(':controller/:action.:suffix')->setViewScriptPathNoControllerSpec(':action.:suffix')->setViewSuffix('tpl'); Zend_Controller_Action_HelperBroker::addHelper($view_renderer); if ($isInstalled) { $front->registerPlugin(new AclPlugin()); $Bolts_plugin->doAction('bootstrap', array('front_controller' => $front)); // ACTION HOOK } else { $front->registerPlugin(new InstallPlugin()); } $router = new Zend_Controller_Router_Rewrite(); $front->setRouter($router); if ($isInstalled) { if (Bolts_Registry::get('enable_localization') == '1') { $router->addRoute('default', new Zend_Controller_Router_Route(":locale/:module/:controller/:action/*", array('locale' => '', 'module' => "bolts", 'controller' => "index", 'action' => "index"))); } else { $router->addRoute('default', new Zend_Controller_Router_Route(":module/:controller/:action/*", array('module' => "bolts", 'controller' => "index", 'action' => "index"))); } if (file_exists($routes_file)) { $routes = new Zend_Config_Ini($routes_file, 'default'); $router->addConfig($routes, 'routes'); } $Bolts_plugin->doAction('bootstrap_routes', array('router' => $router)); // ACTION HOOK } if ($ZZZZ_dump_include_path) { $include_paths = explode(":", get_include_path()); die(var_dump($include_paths, true)); }
function loginredirectAction() { if ($this->_identity->isAdmin) { $this->_redirect(Bolts_Registry::get('login_redirect_admins')); } else { $this->_redirect(Bolts_Registry::get('login_redirect_non_admins')); } }