Beispiel #1
0
 public static function preConfigure()
 {
     $app = Mindy::app();
     $tpl = $app->template;
     $tpl->addHelper('t', function ($text, $category, $params = []) {
         if ($category !== 'app' && !strpos($category, '.')) {
             $category .= '.main';
         }
         $findCategory = explode('.', $category);
         $moduleNameRaw = ucfirst($findCategory[0]);
         if (Mindy::app()->hasModule($moduleNameRaw)) {
             $module = Mindy::app()->getModule($moduleNameRaw);
             $moduleName = get_class($module) . '.' . $findCategory[1];
             return Mindy::t($moduleName, $text, $params);
         } else {
             return $text;
         }
     });
     $tpl->addHelper('convert_base64', ['\\Modules\\Mail\\Helper\\MailHelper', 'convertToBase64']);
     $tpl->addHelper('ucfirst', ['\\Mindy\\Helper\\Text', 'mbUcfirst']);
     $tpl->addHelper('debug_panel', ['\\Modules\\Core\\Components\\DebugPanel', 'render']);
     $tpl->addHelper('param', ['\\Modules\\Core\\Components\\ParamsHelper', 'get']);
     $tpl->addHelper('humanizeDateTime', ['\\Modules\\Core\\Components\\Humanize', 'humanizeDateTime']);
     $tpl->addHelper('locale', function () use($app) {
         return $app->locale;
     });
     $tpl->addHelper('humanizeSize', ['\\Modules\\Core\\Components\\Humanize', 'humanizeSize']);
     $tpl->addHelper('humanizePrice', ['\\Modules\\Core\\Components\\Humanize', 'numToStr']);
     $tpl->addHelper('limit', ['\\Mindy\\Helper\\Text', 'limit']);
     $tpl->addHelper('strtotime', 'strtotime');
     $tpl->addHelper('time', 'time');
     $tpl->addHelper('is_file', 'is_file');
     $tpl->addHelper('d', 'd');
     $tpl->addHelper('locale_date', function ($timestamp, $format = 'd MMMM yyyy') {
         return Translate::getInstance()->getDateFormatter()->format($format, $timestamp);
     });
     $tpl->addHelper('method_exists', function ($obj, $name) {
         return method_exists($obj, $name);
     });
     $tpl->addHelper('user_actions', function ($by = 10) {
         return UserLog::objects()->limit($by)->order(['-created_at'])->all();
     });
     $signal = $app->signal;
     $signal->handler('\\Mindy\\Orm\\Model', 'afterSave', [self::className(), 'afterSaveModel']);
     $signal->handler('\\Mindy\\Orm\\Model', 'afterDelete', [self::className(), 'afterDeleteModel']);
 }
 /**
  * Generates a salt that can be used to generate a password hash.
  *
  * The PHP {@link http://php.net/manual/en/function.crypt.php crypt()} built-in function
  * requires, for the Blowfish hash algorithm, a salt string in a specific format:
  *  "$2a$" (in which the "a" may be replaced by "x" or "y" see PHP manual for details),
  *  a two digit cost parameter,
  *  "$",
  *  22 characters from the alphabet "./0-9A-Za-z".
  *
  * @param int $cost Cost parameter used by the Blowfish hash algorithm.
  * @return string the random salt value.
  * @throws Exception in case of invalid cost number
  */
 public static function generateSalt($cost = 13)
 {
     if (!is_numeric($cost)) {
         throw new Exception(Mindy::t('base', '{class}::$cost must be a number.', array('{class}' => __CLASS__)));
     }
     $cost = (int) $cost;
     if ($cost < 4 || $cost > 31) {
         throw new Exception(Mindy::t('base', '{class}::$cost must be between 4 and 31.', array('{class}' => __CLASS__)));
     }
     if (($random = Mindy::app()->getSecurityManager()->generateRandomString(22, true)) === false) {
         if (($random = Mindy::app()->getSecurityManager()->generateRandomString(22, false)) === false) {
             throw new Exception(Mindy::t('base', 'Unable to generate random string.'));
         }
     }
     return sprintf('$2a$%02d$', $cost) . strtr($random, array('_' => '.', '~' => '/'));
 }
 public function __callInternal($name, $parameters)
 {
     if ($this->_m !== null) {
         foreach ($this->_m as $object) {
             if ($object->getEnabled() && method_exists($object, $name)) {
                 return call_user_func_array(array($object, $name), $parameters);
             }
         }
     }
     if (class_exists('Closure', false) && ($this->canGetProperty($name) || property_exists($this, $name)) && $this->{$name} instanceof Closure) {
         return call_user_func_array($this->{$name}, $parameters);
     }
     throw new Exception(Mindy::t('base', '{class} and its behaviors do not have a method or closure named "{name}".', ['{class}' => get_class($this), '{name}' => $name]));
 }
Beispiel #4
0
 /**
  * @return array Права доступа массивом для использования в формах вида id => name
  */
 public function getPermIdArray()
 {
     $permissions = [];
     foreach ($this->_permissions as $code => $data) {
         if ($data['module'] === null && Mindy::app()->hasModule($data['module'])) {
             $name = Mindy::t(ucfirst($data['module']) . "Module.main", $data['name']);
         } else {
             if (empty($data['name'])) {
                 $name = $code;
             } else {
                 $name = $data['name'];
             }
         }
         $permissions[$data['id']] = $name;
     }
     return $permissions;
 }