public function translate($message, $count = NULL) { $case = $this->detectCase($message); $args = func_get_args(); if (is_string($count)) { if (isset($args[2]) && is_numeric($args[2])) { $count = $args[2]; } } $counter = $count; if (is_numeric($count)) { $counter = $this->inflexion($count); } $node = String::lower($message . $counter); if (isset($this->dict[$node])) { $message = $this->dict[$node]; } else { $message = implode(' ', explode('_', $message)); } if (count($args) > 1) { array_shift($args); $message = vsprintf($message, $args); } if ($case == 'default') { return $message; } elseif ($case == 'firstUpper') { return ucfirst($message); } else { return call_user_func(array('String', $case), $message); } }
public function authenticate(array $credentials) { $email = $credentials['username']; $password = $credentials['password']; $role = String::lower($credentials['extra']); switch ($role) { case 'student': $student = new Student(); $student->email = $email; $student->password = $password; $student = StudentRegistry::verifyStudent($student); $student->courses = StudentRegistry::getStudentCourses($student); foreach ($student->courses as $course) { $student->allowed_courses[] = (int) $course->id; } $identity = new Identity($student->id, $role, $student); $identity->student = $student; break; case 'teacher': $teacher = new Teacher(); $teacher->email = $email; $teacher->password = $password; $teacher = TeacherRegistry::verifyTeacher($teacher); $teacher->courses = TeacherRegistry::getTeacherCourses($teacher); $identity = new Identity($teacher->id, $role, $teacher); $identity->teacher = $teacher; break; case 'admin': $identity = new Identity('admin', $role); break; } return $identity; // vrátíme identitu }
private function gatherActions() { $service = Environment::getService('Nette\\Loaders\\RobotLoader'); $class_list = $service->list; $actions = array(); foreach ($class_list as $class => $file) { //zachtime annotation exception lebo nette si generuje nejake annotation claasy do robotloodera try { $r = new ReflectionClass($class); if ($r->isSubclassOf('Admin_SecurePresenter') && $r->getName() != 'BaseModulePresenter') { $methods = $r->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { if (String::lower($method->class) == $class) { if (strpos($method->getName(), 'action') !== false || strpos($method->getName(), 'handle') !== false) { $actions[$class][] = $method->getName(); } } } } } catch (ReflectionException $e) { } } $actions = array_merge($actions, Environment::getApplication()->getModulesPermissions()); $model = new UsersModuleModel(); $model->saveActions($actions); return $actions; }
public function save($values) { $this->_prepare(); $values['email'] = String::lower($values['name'] . '.' . $values['surname'] . '@st.fm.uniba.sk'); if (!isset($values['id'])) { $values['password'] = String::lower($values['name'] . $values['surname']); } if (isset($values['id'])) { $id = $values['id']; unset($values['id']); db::update(':table:', $values)->where('id = %i', $id)->execute(); } else { $sql = 'INSERT INTO [:table:]'; $result = db::query($sql, $values); } }
private function checkAuthorization() { $presenter = String::lower($this->getReflection()->getName()); $user = Environment::getUser(); $user->setAuthorizationHandler(MokujiServiceLocator::getService('UserAuthorizator')); //if(Environment::getServiceLocator()->hasService('UserAuthorizator')) $user->setAuthorizationHandler(Environment::getService('UserAuthorizator')); //else $user->setAuthorizationHandler(new Admin_UserModel()); if ($this->formatActionMethod($this->action) == 'actiondeny') { return; } if ($user->isAllowed($presenter, $this->formatActionMethod($this->action)) === true) { if ($user->isAllowed($presenter, $this->formatSignalMethod($this->signal)) === false) { throw new AuthenticationException('This action is not allowed'); } } else { throw new AuthenticationException('This action is not allowed'); } }
public function __call($method_name, $args) { $method_name = '_' . $method_name; $tags = array('tags' => array('Models' . $this->getReflection()->getName())); if ($this->reflection->hasMethod($method_name)) { $method = $this->reflection->getMethod($method_name); if ($method->getAnnotation('cache') == 'update' || $method->getAnnotation('cache') == 'insert' || strpos(String::lower($method_name), 'update') > 0 || strpos(String::lower($method_name), 'insert') > 0 || strpos(String::lower($method_name), 'delete') > 0 || strpos(String::lower($method_name), 'edit') > 0 || strpos(String::lower($method_name), 'save') > 0 || strpos(String::lower($method_name), 'create') > 0) { fd('cache cleaned'); if (!empty($args)) { $method->invokeArgs($this, $args); } else { $this->{$method_name}(); } //WORKAROUND $cache_folder = Environment::getVariable('tempDir') . '/c-' . $this->cache->namespace; if (file_exists($cache_folder)) { $files = glob($cache_folder . '/*'); if ($files != false) { foreach ($files as $file) { if (file_exists($file)) { unlink($file); } } } } //$this->cache->clean(); } else { if (!empty($args)) { $ckey = sha1($method_name . serialize($args)); if (!isset($this->cache[$ckey])) { $this->cache->save($ckey, $method->invokeArgs($this, $args)); } } else { $ckey = sha1($method_name); if (!isset($this->cache[$ckey])) { $this->cache->save($ckey, $this->{$method_name}()); } } return $this->cache[$ckey]; } } }
public function isAllowed($role = self::ALL, $resource = self::ALL, $privilege = self::ALL) { if ($privilege == 'actionDeny') { return true; } $data = Environment::getUser()->getIdentity()->permissions; if (isset($data[String::lower($resource)])) { if ($privilege == null) { return true; } foreach ($data[String::lower($resource)] as $user_privilege) { if (String::lower($privilege) == String::lower($user_privilege)) { return true; } } return false; } else { return false; } }
<?php /** * $Horde: horde/services/help/index.php,v 2.72 2004/02/14 01:36:27 chuck Exp $ * * Copyright 1999-2004 Jon Parise <*****@*****.**> * * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. */ @define('HORDE_BASE', dirname(__FILE__) . '/../..'); require_once HORDE_BASE . '/lib/base.php'; require_once HORDE_LIBS . 'Horde/Help.php'; $title = _("Help"); $show = String::lower(Util::getFormData('show', 'index')); $module = String::lower(basename(Util::getFormData('module', 'horde'))); $topic = Util::getFormData('topic'); if ($module == 'admin') { $fileroot = $registry->getParam('fileroot'); $help_file = $fileroot . "/admin/locale/{$language}/help.xml"; $help_file_fallback = $fileroot . '/admin/locale/en_US/help.xml'; } else { $fileroot = $registry->getParam('fileroot', $module); $help_file = $fileroot . "/locale/{$language}/help.xml"; $help_file_fallback = $fileroot . '/locale/en_US/help.xml'; } if ($show == 'index') { require HORDE_TEMPLATES . '/help/index.inc'; } else { require HORDE_TEMPLATES . '/common-header.inc'; if ($show == 'menu') {
protected function checkAction() { if (($action = $this->Url['action']) === false) { $change = ($action = $this->defaultAction) !== null; } $tmp = array(); foreach ($this->abstractClasses as $class) { $tmp = array_merge($tmp, get_class_methods($class)); } $tmp = array_diff(get_class_methods($this), get_class_methods(__CLASS__), $tmp, $this->disabledActions); foreach ($tmp as $method) { $methods[String::lower($method)] = $method; } if (isset($methods[String::lower($action)])) { $this->Url->setVar('action', $methods[String::lower($action)]); } else { if ($this->defaultActionForUnknown && !empty($this->defaultAction)) { $change = $this->Url['action'] = $this->defaultAction; } else { self::error404(); } } if (!empty($change) && $this->reloadForDefaultAction) { $this->redirect($this->Url['controller'] . '/' . $this->Url['action']); } }
public static function inIArray($needle, array $haystack) { return in_array(String::lower($needle), array_map(array('String', 'lower'), $haystack)); }
/** * Helper for usort, compares labels alphabetically * Compares translations of labels if a translator is set * @param NavigationNode $item1 * @param NavigationNode $item2 * @return int */ public function compareLabel(NavigationNode $item1, NavigationNode $item2) { $translator = $this->getBuilder()->getTranslator(); if ($translator instanceof ITranslator) { $label1 = $translator->translate($item1->label); $label2 = $translator->translate($item2->label); } else { $label1 = $item1->label; $label2 = $item2->label; } $sortable = array(String::lower((string) $label1), String::lower((string) $label2)); if ($sortable[0] == $sortable[1]) { return 0; } $sorted = $sortable; sort($sorted); return $sorted[0] == $sortable[0] ? -1 : 1; }
/** * hides action * @param string $action * @return DibiDatagrid_ActionColumn */ public function hideAction($action) { $action = String::lower($action); $this->removeComponent($this->getComponent($action)); return $this; }
public function makeAutologin($password, $uname) { if ($this->isLogged() && $this->autolog) { $pref = Config::read('cookie.prefix'); $c_id = $pref . Config::read('modules.Session.User.Autologin.cookie.uid'); $c_key = $pref . Config::read('modules.Session.User.Autologin.cookie.key'); $lifetime = Config::read('modules.Session.User.Autologin.lifetime'); if (Config::read('security.check.uagent')) { $uagent = $this->Session->read('config.uagent'); } else { $uagent = null; } $info = array($password, String::lower($uname), $uagent); $hash = Security::hash('sha1', $info); Misc::makeCookie($pref . 'rand', $hash[0], $lifetime); Misc::makeCookie($c_key, $hash[1], $lifetime); Misc::makeCookie($c_id, $this->uid, $lifetime); } }
/** * Determines if a browser accepts a given MIME type. * * @access private * * @param string $mimetype The MIME type to check. * * @return boolean True if the browser accepts the MIME type. */ function _acceptMIMEType($mimetype) { if (strstr('*/*', $this->_accept)) { return true; } if (strstr($this->_accept, String::lower($mimetype))) { return true; } /* image/jpeg and image/pjpeg *appear* to be the same entity, but mozilla don't seem to want to accept the latter. For our purposes, we will treat them the same. */ if ($this->isBrowser('mozilla') && String::lower($mimetype) == 'image/pjpeg' && strstr($this->_accept, 'image/jpeg')) { return true; } return false; }
/** * The content to go in this block. * * @return string The content */ function _content() { if (!@(include_once 'Services/Weather.php')) { Horde::logMessage('The weather.com block will not work without Services_Weather from PEAR. Run pear install Services_Weather.', __FILE__, __LINE__, PEAR_LOG_ERR); return _("The weather.com block is not available."); } global $conf; $cacheDir = Horde::getTempDir(); $html = ''; if (empty($this->_params['location'])) { return _("No location is set."); } $weatherDotCom =& Services_Weather::service("WeatherDotCom"); $weatherDotCom->setAccountData(isset($conf['weatherdotcom']['partner_id']) ? $conf['weatherdotcom']['partner_id'] : '', isset($conf['weatherdotcom']['license_key']) ? $conf['weatherdotcom']['license_key'] : ''); if (!$cacheDir) { return PEAR::raiseError(_("No temporary directory available for cache."), 'horde.error'); } else { $weatherDotCom->setCache("file", array("cache_dir" => $cacheDir . '/')); } $weatherDotCom->setDateTimeFormat("m.d.Y", "H:i"); $weatherDotCom->setUnitsFormat($this->_params['units']); $units = $weatherDotCom->getUnitsFormat(); // If the user entered a zip code for the location, no need to // search (weather.com accepts zip codes as location IDs). // The location ID should already have been validated in // getParams. $search = preg_match('/\\b(?:\\d{5}(-\\d{5})?)|(?:[A-Z]{4}\\d{4})\\b/', $this->_params['location'], $matches) ? $matches[0] : $weatherDotCom->searchLocation($this->_params['location']); if (is_a($search, 'PEAR_Error')) { return $search->getmessage(); } if (is_array($search)) { // Several locations returned due to imprecise location parameter $html = _("Several locations possible with the parameter: "); $html .= $this->_params['location']; $html .= "<br/><ul>"; foreach ($search as $id_weather => $real_location) { $html .= "<li>{$real_location} ({$id_weather})</li>\n"; } $html .= "</ul>"; return $html; } $location = $weatherDotCom->getLocation($search); if (is_a($location, 'PEAR_Error')) { return $location->getmessage(); } $weather = $weatherDotCom->getWeather($search); if (is_a($weather, 'PEAR_Error')) { return $weather->getmessage(); } $forecast = $weatherDotCom->getForecast($search, $this->_params['days']); if (is_a($forecast, 'PEAR_Error')) { return $forecast->getmessage(); } // Location and local time. $html .= "<table width=100%><tr><td class=control>"; $html .= '<b>' . $location['name'] . '</b>' . ' local time ' . $location['time']; $html .= "</b></td></tr></table>"; // Sunrise/sunset. $html .= '<b>' . _("Sunrise: ") . '</b>' . Horde::img('block/sunrise/sunrise.gif', _("Sunrise")) . $location['sunrise']; $html .= ' <b>' . _("Sunset: ") . '</b>' . Horde::img('block/sunrise/sunset.gif', _("Sunset")) . $location['sunset']; // Temperature. $html .= '<br /><b>' . _("Temperature: ") . '</b>'; $html .= $weather['temperature'] . '°' . String::upper($units['temp']); // Dew point. $html .= ' <b>' . _("Dew point: ") . '</b>'; $html .= $weather['dewPoint'] . '°' . String::upper($units['temp']); // Feels like temperature. $html .= ' <b>' . _("Feels like: ") . '</b>'; $html .= $weather['feltTemperature'] . '°' . String::upper($units['temp']); // Pressure and trend. $html .= '<br /><b>' . _("Pressure: ") . '</b>'; $html .= number_format($weather['pressure'], 2) . ' ' . $units['pres']; $html .= _(" and ") . $weather['pressureTrend']; // Wind. $html .= '<br /><b>' . _("Wind: ") . '</b>'; if ($weather['windDirection'] == 'VAR') { $html .= _("Variable"); } elseif ($weather['windDirection'] == 'CALM') { $html .= _("Calm"); } else { $html .= _("From the ") . $weather['windDirection']; $html .= ' (' . $weather['windDegrees'] . ')'; } $html .= _(" at ") . $weather['wind'] . ' ' . $units['wind']; // Humidity. $html .= '<br /><b>' . _("Humidity: ") . '</b>'; $html .= $weather['humidity'] . '%'; // Visibility. $html .= ' <b>' . _("Visibility: ") . '</b>'; $html .= $weather['visibility'] . (is_numeric($weather['visibility']) ? ' ' . $units['vis'] : ''); // UV index. $html .= ' <b>' . _("U.V. index: ") . '</b>'; $html .= $weather['uvIndex'] . ' - ' . $weather['uvText']; // Current condition. $html .= '<br /><b>' . _("Current condition: ") . '</b>' . Horde::img('block/weatherdotcom/32x32/' . $weather['conditionIcon'] . '.png', _(String::lower($weather['condition'])), 'align="middle"'); $html .= ' ' . $weather['condition']; // Do the forecast now. $html .= '<table border="0" width="100%" align="center"><tr>'; $html .= '<tr><td class="control" colspan="' . $this->_params['days'] * 2 . '"><center><b>' . $this->_params['days'] . '-day forecast</b></center></td></tr><tr>'; $futureDays = 0; foreach ($forecast['days'] as $which => $day) { $html .= '<td colspan="2" align="center">'; // Day name. $html .= '<b>'; if ($which == 0) { $html .= _("Today"); } elseif ($which == 1) { $html .= _("Tomorrow"); } else { $html .= strftime('%A', mktime(0, 0, 0, date('m'), date('d') + $futureDays, date('Y'))); } $html .= '</b><br />'; $futureDays++; // High/low temp. If after 2 p.m. local time, the "day" // forecast is no longer valid. if ($which > 0 || $which == 0 && strtotime($location['time']) < strtotime('14:00')) { $html .= '<span style="color:red">' . $day['tempertureHigh'] . '°' . String::upper($units['temp']) . '</span>/'; } $html .= '<span style="color:blue">' . $day['temperatureLow'] . '°' . String::upper($units['temp']) . '</span>'; $html .= '</td>'; } $html .= '</tr><tr>'; $elementWidth = 100 / ($this->_params['days'] * 2); foreach ($forecast['days'] as $which => $day) { // Day forecast. $html .= '<td align="center" valign="top" width="' . $elementWidth . '%">'; if ($which > 0 || $which == 0 && strtotime($location['time']) < strtotime('14:00')) { $html .= '<b><i>Day</i></b><br />'; $html .= Horde::img('block/weatherdotcom/23x23/' . $day['day']['conditionIcon'] . '.png', $day['day']['condition']); $html .= '<br />' . $day['day']['condition']; } else { $html .= ' '; } $html .= '</td>'; // Night forecast. $html .= '<td align="center" valign="top" width="' . $elementWidth . '%">'; $html .= '<b><i>Night</i></b><br />'; $html .= Horde::img('block/weatherdotcom/23x23/' . $day['night']['conditionIcon'] . '.png', $day['night']['condition']); $html .= '<br />' . $day['night']['condition']; $html .= '</td>'; } $html .= '</tr></table>'; // Display a bar at the bottom of the block with the required // attribution to weather.com and the logo, both linked to // weather.com with the partner ID. $html .= '<table width=100%><tr>'; $html .= '<td align=right class=control>'; $html .= 'Weather data provided by '; $html .= Horde::link('http://www.weather.com/?prod=xoap&par=' . $weatherDotCom->_partnerID, 'weather.com', '', '_blank', '', 'weather.com'); $html .= '<i>weather.com</i>® '; $html .= Horde::img('block/weatherdotcom/32x32/TWClogo_32px.png', 'weather.com logo'); $html .= '</a></td></tr></table>'; return $html; }