コード例 #1
0
 private function _sendSerialize($data)
 {
     $sAdapter = new Zend_Serializer_Adapter_PhpSerialize();
     $serializer = Zend_Serializer::factory($sAdapter);
     $serialized = $serializer->serialize($data);
     $this->getResponse()->setHeader('Content-type', 'text/plain');
     $this->getResponse()->setBody($serialized);
 }
コード例 #2
0
ファイル: DatabaseObject.php プロジェクト: bsa-git/zf-myblog
 /**
  * Constructor
  *
  * @param array $config
  */
 public function __construct(array $config = array())
 {
     parent::__construct($config);
     $this->_db = $config['db'];
     $this->_table = $config['name'];
     $this->_idField = $config['primary'];
     $front = Zend_Controller_Front::getInstance();
     $this->_request = $front->getRequest();
     $this->_config = Zend_Registry::get('config');
     // Получим обьект сериализатора
     $this->_serializer = Zend_Serializer::factory('PhpSerialize');
     // Получим обьекты для логирования
     $this->_logMsg = Zend_Registry::get('Zend_Log');
     $this->_logStat = Zend_Registry::get('Zend_LogStat');
     $this->_logEx = Zend_Registry::get('Zend_LogEx');
 }
コード例 #3
0
ファイル: SysBox.php プロジェクト: bsa-git/zf-myblog
 /**
  * Send mail
  * 
  * @param array $aMailParams 
  * @return void 
  */
 static function sendMail(array $aMailParams)
 {
     $to_email = $aMailParams['to']['email'];
     $to_name = $aMailParams['to']['name'];
     $mail_subject = $aMailParams['subject'];
     //--------------------------
     try {
         //Получим данные конфигурации почты
         $config = Zend_Registry::get('config');
         //Отправим сообщение по почте
         $tr = new Zend_Mail_Transport_Smtp($config['email']['smtp'], array('port' => 25));
         Zend_Mail::setDefaultTransport($tr);
         $mail = new Zend_Mail($config['email']['charset']);
         $mail->setSubject($aMailParams['subject']);
         $mail->setBodyText($aMailParams['body']);
         if (!$aMailParams['from']) {
             $aMailParams['from'] = $config['email']['from'];
         }
         $headerAddresses = array_intersect_key($aMailParams, self::$_methodMapHeaders);
         if (count($headerAddresses)) {
             foreach ($headerAddresses as $header => $address) {
                 $method = self::$_methodMapHeaders[$header];
                 if (is_array($address) && isset($address['name']) && !is_numeric($address['name'])) {
                     $params = array($address['email'], $address['name']);
                 } else {
                     if (is_array($address) && isset($address['email'])) {
                         $params = array($address['email']);
                     } else {
                         $params = array($address);
                     }
                 }
                 call_user_func_array(array($mail, $method), $params);
             }
         }
         $mail->send();
         // Запомним в логе сообщений
         $message = "Params of email: to-\"{$to_email}\"; name-\"{$to_name}\"; subject-\"{$mail_subject}\";";
         $logMsg = Zend_Registry::get('Zend_Log');
         $logMsg->mail_ok($message);
         // Запомним в логе статистики
         $logStat = Zend_Registry::get('Zend_LogStat');
         $serializer = Zend_Serializer::factory('PhpSerialize');
         $serialized = $serializer->serialize(array('to_email' => $to_email, 'to_name' => $to_name, 'subject' => $mail_subject));
         $logStat->mail_ok($serialized);
     } catch (Exception $e) {
         // Ошибка передачи почты
         // Запомним в логе сообщений
         $message = "Params of email: to-\"{$to_email}\"; name-\"{$to_name}\"; subject-\"{$mail_subject}\";";
         $message .= "\n\n" . $e->getMessage();
         $logMsg = Zend_Registry::get('Zend_Log');
         $logMsg->mail_err($message);
         // Запомним в логе ошибок
         $logEx = Zend_Registry::get('Zend_LogEx');
         $message .= "\n\n" . $e->getTraceAsString();
         $logEx->err($message);
         throw $e;
     }
 }
コード例 #4
0
ファイル: SerializerTest.php プロジェクト: jsnshrmn/Suma
 public function testFactoryOnADummyClassAdapter()
 {
     $this->setExpectedException('Zend_Serializer_Exception', 'must implement Zend_Serializer_Adapter_AdapterInterface');
     Zend_Serializer::setAdapterLoader(new Zend_Loader_PluginLoader(array('Zend_Serializer_Adapter' => dirname(__FILE__) . '/_files')));
     Zend_Serializer::factory('dummy');
 }
コード例 #5
0
 public function setOption($name, $value)
 {
     switch ($name) {
         case 'server':
             // explode list of server urls by ","
             if (!is_array($value)) {
                 $value = explode(',', $value);
                 // if array key "host" exists -> this is an only one server configuration
             } elseif (isset($value['host'])) {
                 $value = array($value);
             }
             $serverList = array();
             foreach ($value as $k => $server) {
                 $serverArr = array();
                 // detect host:port given as array key
                 if (is_string($k)) {
                     $hostArr = explode(':', $k);
                     $serverArr['host'] = $hostArr[0];
                     if (isset($hostArr[1])) {
                         $serverArr['port'] = $hostArr[1];
                     }
                 }
                 // parse server url
                 if (is_string($server)) {
                     $serverUrlArr = @parse_url($server);
                     if (!$serverUrl) {
                         throw new Zend_Cache_Exception('Invalid server url given: ' . $server);
                     }
                     $serverArr['host'] = $serverUrl['host'];
                     if (isset($serverUrl['port'])) {
                         $serverArr['port'] = $serverUrl['port'];
                     }
                     if (isset($serverUrl['query'])) {
                         $queryArr = array();
                         parse_str($serverUrl['query'], $queryArr);
                         $serverArr += $queryArr;
                     }
                 }
                 $normalizedServerOpts = $this->_normalizeServerOptions($serverArr);
                 $serverKey = $normalizedServerOpts['host'] . ':' . $normalizedServerOpts['port'];
                 $serverList[$serverKey] = $normalizedServerOpts;
             }
             $value = $serverList;
             if ($this->_memcached) {
                 // TODO: check if a simple parameter change is enough or only a new server was added.
                 $this->_memcached = null;
             }
             break;
         case 'persistent':
             if ($value) {
                 $value = self::DEFAULT_PERSISTENT_ID;
             } else {
                 $value = false;
             }
             // -> no break -> handle by persistent_id
         // -> no break -> handle by persistent_id
         case 'persistent_id':
             if (!$value) {
                 $value = false;
             } else {
                 $value = (string) $value;
             }
             if ($value !== $this->_options['persistent_id']) {
                 $this->_memcached = null;
             }
             break;
         case 'distribution':
             $value = (int) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_DISTRIBUTION, $value);
             }
             break;
         case 'libketama_compatible':
             $value = (bool) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, $value);
             }
             break;
         case 'buffer_writes':
             $value = (bool) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_BUFFER_WRITES, $value);
             }
             break;
         case 'binary_protocol':
             $value = (bool) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, $value);
             }
             break;
         case 'no_block':
             $value = (bool) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_NO_BLOCK, $value);
             }
             break;
         case 'tcp_nodelay':
             $value = (bool) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_TCP_NODELAY, $value);
             }
             break;
         case 'socket_send_size':
             $value = (int) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_SOCKET_SEND_SIZE, $value);
             }
             break;
         case 'socket_recv_size':
             $value = (int) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_SOCKET_RECV_SIZE, $value);
             }
             break;
         case 'compression':
             $value = (bool) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_COMPRESSION, $value);
             }
             break;
         case 'serializer':
             if (is_int($value)) {
                 $this->_serializerObject = null;
                 if ($this->_memcached) {
                     $this->_memcached->setOption(Memcached::OPT_SERIALIZER, $value);
                 }
             } else {
                 if (!$value instanceof Zend_Serializer_Adapter_AdapterInterface) {
                     require_once 'Zend/Serializer.php';
                     $value = Zend_Serializer::factory($value);
                 }
                 $this->_serializerObject = $value;
                 if ($this->_memcached) {
                     $this->_memcached->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_PHP);
                 }
             }
             break;
         case 'hash_algo':
             $value = (int) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_HASH, $value);
             }
             break;
         case 'connect_timeout':
             $value = (double) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_CONNECT_TIMEOUT, $value * 1000);
             }
             break;
         case 'retry_timeout':
             $value = (int) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_RETRY_TIMEOUT, $value);
             }
             break;
         case 'send_timeout':
             $value = (double) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_SEND_TIMEOUT, $value * 1000);
             }
             break;
         case 'recv_timeout':
             $value = (double) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_RECV_TIMEOUT, $value * 1000);
             }
             break;
         case 'poll_timeout':
             $value = (double) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_POLL_TIMEOUT, $value * 1000);
             }
             break;
         case 'cache_dns_lookups':
             $value = (bool) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_CACHE_LOOKUPS, $value);
             }
             break;
         case 'server_failure_limit':
             $value = (int) $value;
             if ($this->_memcached) {
                 $this->_memcached->setOption(Memcached::OPT_SERVER_FAILURE_LIMIT, $value);
             }
             break;
     }
     parent::setOption($name, $value);
 }
コード例 #6
0
ファイル: BaseController.php プロジェクト: bsa-git/zf-myblog
 /**
  * Initialization controller
  */
 function init()
 {
     //Начало времени выполнения диспечеризации
     $this->_startTimeDispatch = microtime(1);
     $request = $this->getRequest();
     $params = $request->getParams();
     // Get cofig
     $config = Zend_Registry::get('config');
     //$request->
     //Получим адаптер базы данных
     $this->db = Zend_Registry::get('db');
     //Зарегистрируем плагин FlashMessenger
     $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
     //$this->initView();
     // Создадим обьект breadcrumbs и добавим начальную точку отсчета
     $this->_breadcrumbs = new Default_Plugin_Breadcrumbs();
     if ($params['module'] == 'default') {
         $this->_breadcrumbs->addStep($this->Translate('Главная'), $this->getUrl(null, 'index'));
     } elseif ($params['module'] == 'admin') {
         $this->_breadcrumbs->addStep($this->Translate('Администрирование'), $this->getUrl(null, 'index'));
     } elseif ($params['module'] == 'hr') {
         $this->_breadcrumbs->addStep($this->Translate('Персонал'), $this->getUrl(null, 'index'));
     }
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $this->view->authenticated = true;
         $this->_authenticated = true;
         $this->_identity = $auth->getIdentity();
         $this->view->identity = $this->_identity;
         $this->_isAdmin = $this->_identity->user_type == 'administrator';
         $this->view->isAdmin = $this->_isAdmin;
         $this->_isEditor = $this->_identity->user_type == 'editor';
         $this->view->isEditor = $this->_isEditor;
         $this->_isMember = $this->_identity->user_type == 'member';
         $this->view->isMember = $this->_isMember;
         $this->_isCommentator = $this->_identity->user_type == 'commentator';
         $this->view->isCommentator = $this->_isCommentator;
     } else {
         $this->_authenticated = false;
         $this->view->authenticated = false;
         $this->_isGuest = true;
         $this->view->isGuest = true;
     }
     // Получим url_mvc
     $this->_url_mvc = Default_Plugin_SysBox::getRouterURL();
     $this->view->url_mvc = $this->_url_mvc;
     // Получим обьект сессии
     $this->_sessZendAuth = Zend_Registry::get("Zend_Auth");
     // Получим обьект userAgent
     $bootstrap = $this->getInvokeArg('bootstrap');
     $this->_userAgent = $bootstrap->getResource('useragent');
     $this->view->userAgent = $this->_userAgent;
     // Определим текущий броузер
     $this->_isIE = Default_Plugin_SysBox::isIE();
     $this->view->isIE = $this->_isIE;
     $this->_browser = Default_Plugin_SysBox::getBrowser();
     $this->view->browser = $this->_browser;
     $this->_isCompatibleBrowser = Default_Plugin_SysBox::checkBrowser($config['user']['incompatible_browsers']);
     $this->view->isCompatibleBrowser = $this->_isCompatibleBrowser;
     $this->_isForbiddenBrowser = !Default_Plugin_SysBox::checkBrowser($config['user']['forbidden_browsers']);
     $this->view->isForbiddenBrowser = $this->_isForbiddenBrowser;
     //Создадим обьект Redirector
     $this->_redirector = $this->_helper->getHelper('Redirector');
     // Получим обьект сериализатора
     $this->_serializer = Zend_Serializer::factory('PhpSerialize');
     // Получим обьекты для логирования
     $this->_logMsg = Zend_Registry::get('Zend_Log');
     $this->_logStat = Zend_Registry::get('Zend_LogStat');
     $this->_logEx = Zend_Registry::get('Zend_LogEx');
     // Получим доступные модули для приложения
     $strModules = trim($config['user']['modules']['enable']);
     $strModules = str_replace(' ', '', $strModules);
     $strModules = strtolower($strModules);
     $modules = explode(';', $strModules);
     $this->_modules = $modules;
     $this->view->modules = $modules;
     // Пользовательские параметры
     $Zend_Auth = Zend_Registry::get('Zend_Auth');
     $this->view->scheme = $Zend_Auth->user_scheme;
     $this->view->user_main_name = trim($config['user']['main']['name']);
     $this->view->logo_url = trim($config['user']['main']['logo_url']);
     // Check forbidden browser
     if ($this->_isForbiddenBrowser) {
         Default_Plugin_Error::catchException(new Zend_Exception($this->Translate('Данная версия браузера запрещена к использованию! Установите более новую версию браузера.'), 403));
     }
 }
コード例 #7
0
ファイル: Log.php プロジェクト: bsa-git/zf-myblog
 /**
  * Write data to log
  *
  * @param  Zend_Controller_Request_Abstract $request
  * @return void
  */
 static function toLog($request)
 {
     //return;
     $params = $request->getParams();
     $serializer = Zend_Serializer::factory('PhpSerialize');
     $db = Zend_Registry::get('db');
     $logStat = Zend_Registry::get('Zend_LogStat');
     $auth = Zend_Auth::getInstance();
     $user_url = $_SERVER['REMOTE_ADDR'];
     //------------------
     // Получим адрес в виде: module/controller/action
     $module = $request->getModuleName();
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     $url_action = "{$module}/{$controller}/{$action}";
     $arrLogURL = array('default/user/view', 'default/user/videos');
     // Определим данные для сохранения в лог
     foreach ($arrLogURL as $urlLog) {
         switch ($urlLog) {
             case 'default/user/view':
                 // Открыть сообщение
                 if ($url_action == $urlLog) {
                     $urlPost = trim($request->getUserParam('url'));
                     $username = trim($request->getUserParam('username'));
                     $arrStat = array('author' => $username, 'post_url' => $urlPost, 'user_url' => $user_url);
                     if ($auth->hasIdentity()) {
                         $identity = $auth->getIdentity();
                         $arrStat['user'] = $identity->username;
                     }
                     $serialized = $serializer->serialize($arrStat);
                     $logStat->post_open($serialized);
                 }
                 break;
             case 'default/user/videos':
                 // Открыть сообщение
                 if ($url_action == $urlLog && $params['type_action'] == 'play') {
                     $clip_id = $params['clip_id'];
                     $arrStat = array('clip_id' => $clip_id, 'user_url' => $user_url);
                     if ($auth->hasIdentity()) {
                         $identity = $auth->getIdentity();
                         $arrStat['user'] = $identity->username;
                     }
                     $serialized = $serializer->serialize($arrStat);
                     $logStat->video_play($serialized);
                 }
                 break;
             default:
                 break;
         }
     }
 }
コード例 #8
0
ファイル: User.php プロジェクト: bsa-git/zf-myblog
 /**
  * Error login 
  * 
  * @param string $username
  * @param int $code 
  */
 public static function LoginFailure($username, $code = '')
 {
     switch ($code) {
         case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
             $reason = 'Unknown username';
             break;
         case Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS:
             $reason = 'Multiple users found with this username';
             break;
         case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
             $reason = 'Invalid password';
             break;
         case Zend_Auth_Result::FAILURE_UNCATEGORIZED:
             $reason = 'Invalid uncategorized';
             break;
         default:
             $reason = '';
     }
     $message = sprintf('Failed login attempt from url="%s"; user="******"', $_SERVER['REMOTE_ADDR'], $username);
     if (strlen($reason) > 0) {
         $message .= sprintf(' (%s)', $reason);
     }
     // Запомним в логе сообщений
     $logMsg = Zend_Registry::get('Zend_Log');
     $logMsg->login_err($message);
     // Запомним в логе статистики
     $serializer = Zend_Serializer::factory('PhpSerialize');
     $serialized = $serializer->serialize(array('url' => $_SERVER['REMOTE_ADDR'], 'user' => $username, 'reason' => $reason));
     $logStat = Zend_Registry::get('Zend_LogStat');
     $logStat->login_err($serialized);
 }