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 (RivetyCore_Registry::get('enable_localization') == '1' && !is_null($module_name) && trim($module_name) != "" && !is_null($key) && trim($key) != "") { $locale_code = RivetyCore_Translate::cleanZendLocaleCode($locale_code); // TODO: account for core rivety module $path_to_csv = RivetyCore_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 (RivetyCore_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; }
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://', RivetyCore_Registry::get('site_url').$out_url); } else { // TODO - add other cases, such as absolute and relative URLs } return $out_url; }
function smarty_block_t($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'] && RivetyCore_Registry::get('enable_admin_localization') == '0') { $do_translation = false; } if ($params['replace']) { return RivetyCore_Translate::translate($tpl_vars['locale_code'], "default", $content, $params['replace'], $do_translation); } else { return RivetyCore_Translate::translate($tpl_vars['locale_code'], "default", $content, null, $do_translation); } } } }
function extract($source) { // TODO - should remove this default value $rivety_id = RivetyCore_Registry::get('yahoo_api_rivety_id'); $curl_handle = curl_init(); $keywords = null; $all_keywords = null; $filter = new RivetyCore_FilterTags(); $noisewords = RivetyCore_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=".$rivety_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 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->_rivety_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 (RivetyCore_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("/"); } } // $nav_items }
function init() { parent::init(); $this->view->isAdminController = true; $template_path = $this->_theme_locations['admin']['current_theme']['path'] . "/tpl_controllers/" . $this->getRequest()->getModuleName(); $this->view->setScriptPath($template_path); $this->view->base_path = substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], "/")); $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']."/tpl_common"; $this->view->admin_theme_controller_path = $this->_theme_locations['admin']['current_theme']['path'].'/tpl_controllers/'.$this->getRequest()->getControllerName(); $this->view->admin_theme_module_path = $this->_theme_locations['admin']['current_theme']['path'].'/tpl_controllers'; $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']."/tpl_common"; $this->view->default_admin_theme_controller_path = $this->_theme_locations['admin']['default_theme']['path'].'/tpl_controllers/'.$this->getRequest()->getControllerName(); $this->view->default_admin_theme_module_path = $this->_theme_locations['admin']['default_theme']['path'].'/tpl_controllers'; $request = $this->getRequest(); if ($request->has('dev') && $request->dev == true) $this->view->isDeveloper = true; $this->view->current_path = $this->_theme_locations['admin']['current_theme']['path'] . "/tpl_controllers/" . $this->getRequest()->getControllerName(); $roles_table = new Roles(); $locale_table = new Locales(); if ($this->_identity->isAdmin) { $bypass = array(); $globalRoles = explode(",", RivetyCore_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 (@RivetyCore_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 RivetyCore_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->_rivety_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; } } }
{ $front->registerPlugin(new AclPlugin); $params = array('front_controller' => $front); $RivetyCore_plugin->doAction('bootstrap', $params); // ACTION HOOK } else { $front->registerPlugin(new InstallPlugin); } $router = new Zend_Controller_Router_Rewrite(); $front->setRouter($router); if ($isInstalled) { if (RivetyCore_Registry::get('enable_localization') == '1') { $router->addRoute('default', new Zend_Controller_Router_Route(":locale/:module/:controller/:action/*", array('locale' => '', 'module' => "default", 'controller' => "index", 'action' => "index",))); } else { $router->addRoute('default', new Zend_Controller_Router_Route(":module/:controller/:action/*", array('module' => "default", 'controller' => "index", 'action' => "index",))); } if (file_exists($routes_file)) { $routes = new Zend_Config_Ini($routes_file, 'default'); $router->addConfig($routes, 'routes'); } $RivetyCore_plugin->doAction('bootstrap_routes', array('router' => $router)); // ACTION HOOK }
protected function _checkConfirmationUrl($email, $code) { $salt = RivetyCore_Registry::get('salt'); $test = $email . $salt; return (md5($test) == $code); }
function setcookieAction() { // TODO maybe? - prevent people from viewing this page if localization is not enabled $request = new RivetyCore_Request($this->getRequest()); if ($request->has("code") && $request->code != "") { $locale_code = $request->code; $time = RivetyCore_Registry::get('locale_cache_lifetime'); if (RivetyCore_Translate::validateLocaleCode($locale_code)) { setcookie("locale_code", $locale_code, time() + $time , "/"); if ($request->has("return_url")) { $url_filter = new RivetyCore_Url_Filter(); header("Location: ".$url_filter->filter($request->return_url, array('locale_code' => $locale_code))); } else { header("Location: /".$locale_code); } } } else { $this->_redirect("/default/locale/choose/"); } }
function sendEmail($subject, $to_address, $template, $params = null, $to_name = null, $isHtml = false) { $useAuth = RivetyCore_Registry::get('smtp_use_auth'); if (array_key_exists('from_email', $params)) { $site_from_email = $params['from_email']; } else { $site_from_email = RivetyCore_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 = RivetyCore_Registry::get('site_from'); } $smtp = RivetyCore_Registry::get('smtp_server'); $username = RivetyCore_Registry::get('smtp_username'); $password = RivetyCore_Registry::get('smtp_password'); $ssl = RivetyCore_Registry::get('smtp_ssl_type'); //tls $smtp_port = RivetyCore_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(RivetyCore_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) { RivetyCore_Log::report('email: could not send', $e, Zend_Log::ERR); } }
function testdataAction() { $request = new RivetyCore_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) { $tmp_user[$key] = $value; // if ($key != "avatar") { // } } $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."; RivetyCore_Registry::set('test_data_path', $request->data_path); $this->view->data_path = RivetyCore_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 preDispatch(Zend_Controller_Request_Abstract $request) { $frontController = Zend_Controller_Front :: getInstance(); $auth = Zend_Auth :: getInstance(); $roles_table = new Roles(); $appNamespace = new Zend_Session_Namespace('RivetyCore_Temp'); if (Zend_Registry :: isRegistered('acl')) { $acl = Zend_Registry :: get('acl'); } else { $acl = new RivetyCore_Acl($auth); Zend_Registry::set('acl', $acl); } // determine role if ($auth->hasIdentity()) { $user = Zend_Auth :: getInstance()->getIdentity(); $users_roles_table = new UsersRoles(); $users_roles_db = $users_roles_table->fetchAll($users_roles_table->select()->where("username = ?", $user->username)); $user_roles = array(); if (count($users_roles_db) > 0) { foreach ($users_roles_db as $role) { $user_roles[] = $role->role_id; $user_roles = array_merge($user_roles, $roles_table->getAllAncestors($role->role_id)); } } $user_roles = array_unique($user_roles); $user_is_guest = false; $defaultNamespace = new Zend_Session_Namespace('Zend_Auth'); // REFRESH THE SESSION EXPIRATION $defaultNamespace->setExpirationSeconds((int)RivetyCore_Registry::get('session_timeout')); } else { $user_roles = array($roles_table->getIdByShortname("guest")); $user_is_guest = true; } $requested = $request->getModuleName() . "-" . ucfirst(strtolower($request->getControllerName())) . "-" . $request->getActionName(); $url = $frontController->getBaseUrl() . "/"; if (!$acl->has($requested)) { // this doesn't exist, throw to 404 $request->setModuleName('default'); $request->setControllerName('auth'); $request->setActionName('missing'); } else { $isAllowed = array(); foreach ($user_roles as $user_role) { $isAllowed[$user_role] = $acl->isAllowed($user_role, $requested); // if ($acl->isAllowed($user_role, $requested)) // { // $isAllowed[$user_role] = true; // } // else // { // $isAllowed[$user_role] = false; // } } if (!in_array(true, $isAllowed)) { if ($user_is_guest) { $url .= $request->getModuleName() . "/"; $url .= $request->getControllerName() . "/"; $url .= $request->getActionName() . "/"; $params = $request->getParams(); while ($param = current($params)) { if (key($params) != "module" && key($params) != "controller" && key($params) != "action") $url .= key($params) . '/' . $param . "/"; next($params); } if (substr($url,strlen($url) - 1, 1) == "/") { $url = substr($url, 0, strlen($url) - 1); } // place requested url in the session, unless this is the login controller if ($request->getControllerName() != "auth") { $request->setParam('ourl', base64_encode($url)); // $appNamespace->requestedUrl = $url; } $blockedActions = RivetyCore_Registry::get('disable_login_redirect'); if (!empty($blockedActions)) $blockedActions = explode(',', $blockedActions); $mca = $request->getModuleName() . "_" . $request->getControllerName() . "_" . $request->getActionName(); if (is_array($blockedActions) && in_array($mca, $blockedActions)) { // forward to the 401 Unauthorized page $request->setModuleName('default'); $request->setControllerName('auth'); $request->setActionName('unauthorized'); } else { // forward to the login script $request->setModuleName('default'); $request->setControllerName('auth'); $request->setActionName('login'); } } else { $admin = "default-Admin-index"; $isAdmin = array(); foreach($user_roles as $user_role) { $isAdmin[$user_role] = $acl->isAllowed($user_role, $admin); // if ($acl->isAllowed($user_role, $admin)) // { // $isAdmin[$user_role] = true; // } // else // { // $isAdmin[$user_role] = false; // } } if (!in_array(true, $isAdmin)) { $request->setModuleName('default'); $request->setControllerName('auth'); $request->setActionName('denied'); } else { $request->setModuleName('default'); $request->setControllerName('admin'); $request->setActionName('index'); } } } } }
public function write($id, $value) { $sessions_table = new Sessions(); $lifetime = (int)RivetyCore_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); RivetyCore_Log::info("Session handler: updated session " .$id); } else { $id = $sessions_table->insert($data); RivetyCore_Log::info("Session handler: updating session " .$id); } }
public function listAction() { $request = new RivetyCore_Request($this->getRequest()); $base_path = RivetyCore_Registry::get('upload_path') . "/rivetycommon"; if (!$request->has("folder") || empty($request->folder)) die("error - folder is empty or doesn't exist"); $photos = array(); $dir = new DirectoryIterator($base_path . "/" . $request->folder); foreach ($dir as $file_info) { $extension = pathinfo($file_info, PATHINFO_EXTENSION); if (!$file_info->isDir() && !$file_info->isDot() && in_array(strtolower($extension), $this->_allowed_extensions)) { $photos[] = $file_info->__toString(); } } natsort($photos); $photos = array_values($photos); if ($this->format == 'json') die(Zend_Json::encode($photos)); }
function loginredirectAction() { if ($this->_identity->isAdmin) $this->_redirect(RivetyCore_Registry::get('login_redirect_admins')); else $this->_redirect(RivetyCore_Registry::get('login_redirect_non_admins')); }