Пример #1
0
 function addRoles($parent_role = null)
 {
     $roles_table = new Roles();
     //dd($roles_table->fetchImmediateChildren(2)->toArray());
     // we start this recursive funtion by looking for roles with no parent.
     if (is_null($parent_role)) {
         $roles = $roles_table->fetchParentless();
     } else {
         $roles = $roles_table->fetchImmediateChildren($parent_role);
         //dd($roles->toArray());
     }
     foreach ($roles as $role) {
         // Add the role and specifiy that as the parent. On the first pass, this is null.
         if (!$this->hasRole($role->id)) {
             Bolts_Log::info("Adding role " . $role->shortname);
             $this->addRole(new Zend_Acl_Role($role->id), $parent_role);
         }
         if (count($roles_table->fetchImmediateChildren($role->id)) > 0) {
             $this->addRoles($role->id);
         }
     }
 }
Пример #2
0
 /**
  * Unregister's a logger
  *
  * @static 
  * @access public
  * @param string $loggerName Logical name of the logger
  */
 public static function unregisterLogger($loggerName)
 {
     if (!in_array($loggerName, array_keys(self::$instances))) {
         return false;
     }
     unset(self::$instances[$loggerName]);
     if (self::getDefaultLoggerName() == $loggerName) {
         self::$defaultLogger = null;
     }
 }
Пример #3
0
 function setup($module_id)
 {
     $basepath = Zend_Registry::get("basepath");
     $module_dir = $basepath . "/" . $this->module_dir;
     $full_dir = $module_dir . "/" . $module_id;
     $subdirs = array("models", "plugins", "controllers", "lib");
     $tmp_include_path = "";
     try {
         $module_cfg = $this->parseIni($module_id);
         if (is_dir($full_dir)) {
             foreach ($subdirs as $subdir) {
                 $includable_dir = $full_dir . "/" . $subdir;
                 if (is_dir($includable_dir)) {
                     $tmp_include_path .= PATH_SEPARATOR . $includable_dir;
                 }
             }
             set_include_path(get_include_path() . $tmp_include_path);
         }
         $this->upgradeDatabase($module_id);
         $this->setDefaultConfig($module_id);
         $ap = Bolts_Plugin::getInstance();
         if (count($module_cfg['plugins']) > 0) {
             foreach ($module_cfg['plugins'] as $hook => $plugin) {
                 $hook_type = substr($hook, 0, strpos($hook, "."));
                 $hook_name = substr($hook, strpos($hook, ".") + 1);
                 $callback_class = substr($plugin, 0, strpos($plugin, "::"));
                 $callback_method = substr($plugin, strpos($plugin, "::") + 2);
                 if ($hook_type == "filter") {
                     $ap->addFilter($hook_name, $callback_class, $callback_method, 10);
                 }
                 if ($hook_type == "action") {
                     $ap->addAction($hook_name, $callback_class, $callback_method, 10);
                 }
             }
         }
     } catch (Exception $e) {
         Bolts_Log::report("Could not set up " . $module_id, $e, Zend_Log::ERR);
         // $where = $this->getAdapter()->quoteInto("id = ?", $module_id);
         // $this->delete($where);
     }
 }
Пример #4
0
 function editAction()
 {
     $errors = array();
     $users_table = new Users();
     $users_roles_table = new UsersRoles();
     $request = new Bolts_Request($this->getRequest());
     $countries_table = new Countries();
     $this->view->countries = $countries_table->getCountriesArray('Choose a country...');
     $roles_table = new Roles();
     $roles = $roles_table->fetchAll(NULL, "shortname ASC");
     $arRoles = array();
     foreach ($roles as $role) {
         if (!strpos($role->shortname, "-base")) {
             $arRoles[$role->id] = $role->description;
         }
     }
     $this->view->roles = $arRoles;
     $is_new = true;
     $user = array();
     if ($request->has('username')) {
         $obUser = $users_table->fetchByUsername($request->username);
         if (!is_null($obUser)) {
             $is_new = false;
             $user_roles = $users_roles_table->fetchAll($users_roles_table->select()->where("username = ?", $obUser->username));
             if (count($user_roles) > 0) {
                 $tmp_selected = array();
                 foreach ($user_roles as $user_role) {
                     $tmp_selected[] = $user_role->role_id;
                 }
                 $this->view->selected_roles = $tmp_selected;
             }
             $user = $obUser->toArray();
         }
     }
     $this->view->is_new = $is_new;
     if ($is_new) {
         // defaults for form fields
         $user['username'] = "";
         $user['full_name'] = "";
         $user['aboutme'] = "";
     }
     $pre_render = $this->_Bolts_plugin->doFilter($this->_mca . "_pre_render", array('user' => $user, 'request' => $this->_request));
     // FILTER HOOK
     $user = $pre_render['user'];
     foreach ($pre_render as $key => $value) {
         if ($key != "user") {
             $this->view->{$key} = $value;
         }
     }
     // $tags = unserialize($user['tags']);
     if ($this->getRequest()->isPost()) {
         $errors = array();
         $request->stripTags(array('full_name', 'email', 'newpassword', 'confirm'));
         // $request->stripTags(array('full_name', 'email', 'newpassword', 'confirm', 'aboutme'));
         $user['username'] = $request->username;
         $user['email'] = $request->email;
         $user['password'] = $request->newpassword;
         $user['confirm'] = $request->confirm;
         $user['full_name'] = $request->full_name;
         $user['birthday'] = $birthday = strtotime($request->Birthday_Day . $request->Birthday_Month . $request->Birthday_Year);
         $user['gender'] = $request->gender;
         $user['country_code'] = $request->country_code;
         $user['aboutme'] = $request->aboutme;
         // validate username
         $username_validator = new Zend_Validate();
         $username_validator->addValidator(new Zend_Validate_StringLength(1, Bolts_Registry::get('username_length')));
         $username_validator->addValidator(new Zend_Validate_Alnum());
         if (!$username_validator->isValid($user['username'])) {
             $show_username = "******" . $user['username'] . "'";
             if (trim($user['username']) == "") {
                 $show_username = "******" . $this->_T("empty") . "]";
             }
             $errors[] = $this->_T("%s isn't a valid username. (Between %d and %d characters, only letters and numbers)", array($show_username, 1, Bolts_Registry::get('username_length')));
         }
         if ($is_new) {
             $user_where = $users_table->getAdapter()->quoteInto('username = ?', $user['username']);
             if ($users_table->getCountByWhereClause($user_where) > 0) {
                 $errors[] = $this->_T("The username '%s' is already in use", $user['username']);
             }
         }
         // validate email
         if (!Bolts_Validate::checkEmail($user['email'])) {
             $errors[] = $this->_T("Email is not valid");
         }
         // check to see if email is in use already by someone else
         if ($users_table->isEmailInUse($user['email'], $user['username'])) {
             $errors[] = $this->_T("Email already in use");
         }
         // if password isn't blank, validate it
         if ($user['password'] != "") {
             if (!Bolts_Validate::checkLength($user['password'], 6, Bolts_Registry::get('password_length'))) {
                 $errors[] = $this->_T("Password must be between 6 and 32 characters");
             }
             // if password is set, make sure it matches confirm
             if ($user['password'] != $user['confirm']) {
                 $errors[] = $this->_T("Passwords don't match");
             }
         }
         // convert birthday_ts to mysql date
         $birthday = date("Y-m-d H:i:s", $user['birthday']);
         $params = array('request' => $request, 'user' => $user, 'errors' => $errors);
         // upload new avatar image if present
         if (array_key_exists('filedata', $_FILES)) {
             if ($_FILES['filedata']['tmp_name'] != '') {
                 $destination_path = Bolts_Registry::get('upload_path') . "/" . $user['username'] . "/original";
                 if (!is_dir($destination_path)) {
                     mkdir($destination_path, 0777, true);
                     Bolts_Log::report("Creating user folder at " . $destination_path, null, Zend_Log::DEBUG);
                 }
                 if (file_exists($destination_path . "/avatar")) {
                     unlink($destination_path . "/avatar");
                     Bolts_Log::report("Deleted existing user avatar from " . $destination_path, null, Zend_Log::DEBUG);
                 } else {
                     Bolts_Log::report("User avatar did not exist in " . $destination_path, null, Zend_Log::DEBUG);
                 }
                 move_uploaded_file($_FILES['filedata']['tmp_name'], $destination_path . "/avatar");
                 Users::clearUserCache($user['username']);
                 Bolts_Log::report("User avatar uploaded to " . $destination_path, null, Zend_Log::DEBUG);
                 $params['user']['hasnewfile'] = true;
             } else {
                 $params['user']['hasnewfile'] = false;
             }
         }
         $additional = $this->_Bolts_plugin->doFilter($this->_mca . "_pre_save", $params);
         // FILTER HOOK
         $errors = $additional['errors'];
         $user = $additional['user'];
         $users_roles_table->delete($users_roles_table->getAdapter()->quoteInto("username = ?", $user['username']));
         foreach ($request->role_ids as $role_id) {
             $role_data = array("username" => $user['username'], "role_id" => $role_id);
             $users_roles_table->insert($role_data);
         }
         if (count($errors) == 0) {
             /**********  Commented out due to Plug-in compatibility issues. 
             			$data = array(
             				'email' => $user['email'],
             				'birthday' => $birthday,
             				'aboutme' => nl2br($user['aboutme']),
             				'gender' => $user['gender'],
             				'full_name' => $user['full_name'],
             				'country_code' => $user['country_code'],
             				'last_modified_on' => date(DB_DATETIME_FORMAT),
             			);
             			**********/
             $user['birthday'] = $birthday;
             $user['aboutme'] = nl2br($user['aboutme']);
             $user['last_modified_on'] = date(DB_DATETIME_FORMAT);
             // This is a hold-over value from the form.
             unset($user['confirm']);
             if ($user['password'] != "") {
                 #$data['password'] = $user['password'];
             } else {
                 unset($user['password']);
             }
             if ($is_new) {
                 // TODO - stuff?  really?
                 $stuff = array('request' => $request, 'user' => $user, 'errors' => $errors);
                 $additional1 = $this->_Bolts_plugin->doFilter($this->_mca, $stuff);
                 // FILTER HOOK
                 $errors = $additional1['errors'];
                 $user = $additional1['user'];
                 $data['username'] = $user['username'];
                 #$data['created_on'] = date(DB_DATETIME_FORMAT);
                 $user['created_on'] = date(DB_DATETIME_FORMAT);
                 $users_table->insert($user);
                 $this->view->success = "Profile created.";
             } else {
                 $where = $users_table->getAdapter()->quoteInto('username = ?', $user['username']);
                 #$users_table->update($data, $where);
                 $users_table->update($user, $where);
                 $this->view->success = "Profile updated.";
             }
         } else {
             $this->view->errors = $errors;
         }
     }
     $this->view->end_year = -Bolts_Registry::get('minimum_registration_age');
     $this->view->genders = Bolts_Common::getGenderArray();
     $user['aboutme'] = Bolts_Common::br2nl($user['aboutme']);
     $this->view->user = $user;
 }
Пример #5
0
 function indexAction()
 {
     $modules_table = new Modules("nuts");
     $request = new Bolts_Request($this->getRequest());
     if ($request->has("id") and $request->has("perform")) {
         switch ($request->perform) {
             case "enable":
                 if (!$modules_table->isEnabled($request->id)) {
                     if ($modules_table->enable($request->id)) {
                         if (!is_null($modules_table->success)) {
                             $this->view->success = $modules_table->success;
                         } else {
                             $this->view->success = "Module \"" . $request->id . "\" enabled.";
                         }
                     }
                 } else {
                     $this->view->notice = "Module \"" . $request->id . "\" is already enabled.";
                 }
                 break;
             case "disable":
                 if ($modules_table->isEnabled($request->id)) {
                     if ($modules_table->disable($request->id)) {
                         if (!is_null($modules_table->success)) {
                             $this->view->success = $modules_table->success;
                         } else {
                             $this->view->success = "Module \"" . $request->id . "\" disabled.";
                         }
                     }
                 } else {
                     $this->view->notice = "Module \"" . $request->id . "\" is already disabled.";
                 }
                 break;
             case "install":
                 if (!$modules_table->exists($request->id)) {
                     if ($modules_table->install($request->id)) {
                         if (!is_null($modules_table->success)) {
                             $this->view->success = $modules_table->success;
                         } else {
                             $this->view->success = "Module \"" . $request->id . "\" installed.";
                         }
                     }
                 } else {
                     $this->view->notice = "Module \"" . $request->id . "\" is already installed.";
                 }
                 break;
             case "uninstall":
                 if ($modules_table->exists($request->id)) {
                     if ($modules_table->disable($request->id)) {
                         if ($modules_table->uninstall($request->id)) {
                             if (!is_null($modules_table->success)) {
                                 $this->view->success = $modules_table->success;
                             } else {
                                 $this->view->success = "Module \"" . $request->id . "\" disabled and uninstalled.";
                             }
                         }
                     }
                 } else {
                     $this->view->notice = "Module \"" . $request->id . "\" is not installed.";
                 }
                 break;
         }
         if (count($modules_table->errors) > 0) {
             $this->view->errors = $modules_table->errors;
         }
         if (!is_null($modules_table->notice)) {
             $this->view->notice = $modules_table->notice;
         }
     }
     $basepath = Zend_Registry::get('basepath');
     $module_dir = $basepath . "/nuts";
     $o_module_dir = dir($module_dir);
     $available_modules = array();
     while (false !== ($entry = $o_module_dir->read())) {
         if (substr($entry, 0, 1) != ".") {
             if ($entry != "default") {
                 $full_dir = $module_dir . "/" . $entry;
                 if (file_exists($full_dir . "/module.ini") and !$modules_table->exists($entry)) {
                     $tmp_module = $modules_table->parseIni($entry);
                     $tmp_module['id'] = $entry;
                     $tmp_module['available'] = true;
                     $available_modules[] = $tmp_module;
                 }
             }
         }
     }
     $o_module_dir->close();
     $tmp_modules = array();
     $modules = $modules_table->fetchAll(null, "id");
     if (count($modules) > 0) {
         $tmp_modules = array();
         foreach ($modules as $module) {
             $module = $module->toArray();
             try {
                 $config = $modules_table->parseIni($module['id']);
                 foreach ($config as $key => $val) {
                     $module[$key] = $val;
                 }
                 $module['available'] = false;
                 $tmp_modules[] = $module;
             } catch (Exception $e) {
                 Bolts_Log::report("Could not set up " . $module, $e, Zend_Log::ERR);
             }
         }
     }
     $this->view->modules = array_merge($tmp_modules, $available_modules);
 }
Пример #6
0
 static function doAction($hook, $params)
 {
     Bolts_Log::report("Bolts_Plugin: Action hook fired - " . $hook, null, Zend_Log::INFO);
     Bolts_Log::report("Bolts_Plugin: Action hook fired - " . $hook . " - params: ", $params);
     $plugins = Zend_Registry::get('plugin_actions');
     if (array_key_exists($hook, $plugins)) {
         $priority = array();
         $functions = array();
         foreach ($plugins[$hook] as $key => $function) {
             $priority[$key] = $function['priority'];
             $functions[$key] = $function;
         }
         array_multisort($priority, SORT_ASC, $functions, SORT_ASC, $plugins[$hook]);
         Bolts_Log::report("Bolts_Plugin: Action priority arrays for " . $hook, array('priority' => $priority, 'functions' => $functions, 'plugins-' . $hook => $plugins[$hook]), Zend_Log::DEBUG);
         foreach ($plugins[$hook] as $action) {
             $class_name = $action['class_name'];
             $function_name = $action['function_name'];
             $class = new $class_name();
             Bolts_Log::report("Bolts_Plugin: Action " . $hook . " is calling " . $class_name . "::" . $function_name, null, Zend_Log::INFO);
             $class->{$function_name}($params);
         }
     }
 }
Пример #7
0
 function go($action, $params, $url = null)
 {
     $params['Action'] = $action;
     if (!$url) {
         $url = $this->_server;
     }
     $params['AWSAccessKeyId'] = $this->_key;
     $params['SignatureVersion'] = 1;
     $params['Timestamp'] = gmdate("Y-m-d\\TH:i:s\\Z");
     $params['Version'] = "2008-01-01";
     uksort($params, "strnatcasecmp");
     $toSign = "";
     foreach ($params as $key => $val) {
         $toSign .= $key . $val;
     }
     $sha1 = $this->hasher($toSign);
     $sig = $this->base64($sha1);
     $params['Signature'] = $sig;
     Bolts_Log::report('sqs go params', $params, Zend_Log::INFO);
     $output = Bolts_Url::get($url, $params);
     $xmlstr = $output['output'];
     Bolts_Log::report("output from sqs", $output, Zend_Log::DEBUG);
     try {
         $xml = new SimpleXMLElement($xmlstr);
         if ($output['http_code'] == 200 and !isset($xml->Errors)) {
             Bolts_Log::report("xml from sqs", $xml, Zend_Log::DEBUG);
             return $xml;
         } else {
             return false;
         }
     } catch (Exception $ex) {
         return false;
     }
 }
Пример #8
0
 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;
     }
 }
Пример #9
0
 function editAction()
 {
     if ($this->_user->username != $this->_identity->username) {
         $this->_forward('default', 'auth', 'missing');
         return;
     } else {
         $countries_table = new Countries();
         $this->view->countries = $countries_table->getCountriesArray('Choose a country...');
         $user = $this->_user->toArray();
         $params = array('user' => $user, 'request' => $this->_request, 'session' => $this->session);
         $pre_render = $this->_Bolts_plugin->doFilter($this->_mca . "_pre_render", $params);
         // FILTER HOOK
         $user = $pre_render['user'];
         foreach ($pre_render as $key => $value) {
             if ($key != "user") {
                 $this->view->{$key} = $value;
             }
         }
         //$tags = unserialize($user->tags);
         if ($this->getRequest()->isPost()) {
             $errors = array();
             $request = new Bolts_Request($this->getRequest());
             $request->stripTags(array('email', 'newpassword', 'confirm', 'aboutme'));
             $user['username'] = $this->_identity->username;
             $user['email'] = $request->email;
             $user['full_name'] = $request->full_name;
             $user['password'] = $request->newpassword;
             $user['confirm'] = $request->confirm;
             $user['birthday'] = $birthday = strtotime($request->Birthday_Day . $request->Birthday_Month . $request->Birthday_Year);
             //$user['tags'] = $tag_array = Bolts_Common::makeTagArray($request->tags);
             $user['gender'] = $request->gender;
             $user['country_code'] = $request->country_code;
             $user['aboutme'] = $request->aboutme;
             // validate email
             if (!Bolts_Validate::checkEmail($user['email'])) {
                 $errors[] = $this->_T("Email is not valid");
             }
             // check to see if email is in use already by someone else
             if ($this->_users_table->isEmailInUse($user['email'], $user['username'])) {
                 $errors[] = $this->_T("Email already in use");
             }
             // if password isn't blank, validate it
             if ($user['password'] != "") {
                 if (!Bolts_Validate::checkLength($user['password'], 6, Bolts_Registry::get('password_length'))) {
                     $errors[] = $this->_T("Password must be between %d and %d characters", array(6, Bolts_Registry::get('password_length')));
                 }
                 // if password is set, make sure it matches confirm
                 if ($user['password'] != $user['confirm']) {
                     $errors[] = $this->_T("Passwords don't match");
                 }
             }
             if (!Bolts_Validate::checkLength($user['aboutme'], 0, Bolts_Registry::get('user_about_me_length'))) {
                 $errors[] = $this->_T("About me must be less than %d characters.", Bolts_Registry::get('user_about_me_length'));
             }
             // convert birthday_ts to mysql date
             $birthday = date("Y-m-d H:i:s", $user['birthday']);
             $params = array('request' => $this->getRequest(), 'user' => $user, 'errors' => $errors);
             // upload new avatar image if present
             if (array_key_exists('filedata', $_FILES)) {
                 if ($_FILES['filedata']['tmp_name'] != '') {
                     $users_table = new Users();
                     $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);
                         Bolts_Log::report("Creating user folder at " . $destination_path, null, Zend_Log::DEBUG);
                     }
                     if (file_exists($destination_filename)) {
                         unlink($destination_filename);
                         Bolts_Log::report("Deleted existing user avatar from " . $destination_path, null, Zend_Log::DEBUG);
                     } else {
                         Bolts_Log::report("User avatar did not exist in " . $destination_path, null, Zend_Log::DEBUG);
                     }
                     move_uploaded_file($_FILES['filedata']['tmp_name'], $destination_filename);
                     Users::clearUserCache($user['username']);
                     Bolts_Log::report("User avatar uploaded to " . $destination_path, null, Zend_Log::DEBUG);
                     $params['user']['hasnewfile'] = true;
                 } else {
                     $params['user']['hasnewfile'] = false;
                 }
             }
             $additional = $this->_Bolts_plugin->doFilter($this->_mca . "_pre_save", $params);
             // FILTER HOOK
             $errors = $additional['errors'];
             $user = $additional['user'];
             if (strlen($user['full_name']) < 1) {
                 $user['full_name'] = $this->_T("Unidentified User");
             }
             if (count($errors) == 0) {
                 $data = array('email' => $user['email'], 'full_name' => $user['full_name'], 'birthday' => $birthday, 'aboutme' => nl2br($user['aboutme']), 'gender' => $user['gender'], 'country_code' => $user['country_code'], 'last_modified_on' => date(DB_DATETIME_FORMAT));
                 if ($user['password'] != "") {
                     $data['password'] = $user['password'];
                 }
                 $where = $this->_users_table->getAdapter()->quoteInto('username = ?', $this->_username);
                 $this->_users_table->update($data, $where);
                 $this->_Bolts_plugin->doAction('default_user_edit_post_save', array('username' => $this->_username));
                 // ACTION HOOK
                 $this->view->success = $this->_T("Profile Updated.");
             } else {
                 $this->view->errors = $errors;
             }
         }
         //$this->view->tags = Bolts_Common::makeTagString($tags);
         $this->view->end_year = -Bolts_Registry::get('minimum_registration_age');
         // multiply min age by number of seconds in a year
         $this->view->genders = Bolts_Common::getGenderArray();
         $user['aboutme'] = Bolts_Common::br2nl(stripslashes($user['aboutme']));
         $this->view->user = $user;
     }
 }
Пример #10
0
 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);
     }
 }
Пример #11
0
        Bolts_Log::report("Database error", $ex, Zend_Log::EMERG);
        header("Location: /errordocuments/error_DB.html");
    }
} catch (Exception $ex) {
    if (!empty($config) && canDebug($ip, $config)) {
        d($ex->getMessage());
        dd($ex);
    } else {
        $ex_type = trim(substr($ex->getMessage(), 0, strpos($ex->getMessage(), " ")));
        switch ($ex_type) {
            case "MISSING_LIBS":
                header("Location: /errordocuments/error_LIBS.html");
                break;
            case "CANT_WRITE":
                header("Location: /errordocuments/error_CANTWRITE.html");
                break;
            case "DIR_MISSING":
                header("Location: /errordocuments/error_DIRMISSING.html");
                break;
            default:
                if ($isInstalled) {
                    header("Location: /errordocuments/error_500.html");
                    Bolts_Log::report("Frontcontroller Error", $ex, Zend_Log::EMERG);
                } else {
                    d($ex->getMessage());
                    dd($ex);
                }
                break;
        }
    }
}
Пример #12
0
 }
 if (is_null(@$config['application']['host_id'])) {
     $host_id = null;
 } else {
     $host_id = $config['application']['host_id'];
 }
 $log_filename = $config['application']['log_filename'];
 Zend_Registry::set('basepath', $basepath);
 Zend_Registry::set('config_file', $config_file);
 Zend_Registry::set('host_id', $host_id);
 // create logger
 $writer = new Zend_Log_Writer_Stream($log_filename);
 $filter = new Zend_Log_Filter_Priority($log_level);
 $writer->addFilter($filter);
 Bolts_Log::registerLogger('default', $writer, true);
 Bolts_Log::report("Log Started", null, Zend_Log::INFO);
 // Create Plugin Manager
 $Bolts_plugin = Bolts_Plugin::getInstance();
 // define constants
 $constants = new Constants();
 set_include_path(get_include_path() . PATH_SEPARATOR . $config['application']['addtl_includes']);
 $databases = new Zend_Config_Ini($config_file, 'databases');
 $dbAdapters = array();
 foreach ($databases->db as $config_name => $db) {
     $dbAdapters[$config_name] = Zend_Db::factory($db->adapter, $db->config->toArray());
     if ((bool) $db->config->default) {
         Zend_Db_Table::setDefaultAdapter($dbAdapters[$config_name]);
     }
 }
 // Store the adapter for use anywhere in our app
 $registry = Zend_Registry::getInstance();