public function errorAction()
 {
     $this->_helper->_layout->setLayout('layout_errors');
     $this->_helper->viewRenderer->setNoRender(true);
     // default application error
     $this->getResponse()->setHttpResponseCode(500);
     $this->view->message = $this->view->translate('Application error');
     // log errors
     $logtext = "\n------------------------------------------------------------\n";
     $errors = $this->_getParam('error_handler');
     if (isset($errors->type)) {
         switch ($errors->type) {
             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
             case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                 // 404 error -- controller or action not found
                 $this->getResponse()->setHttpResponseCode(404);
                 $this->view->message = $this->view->translate('Error 404 - Page not found');
                 break;
         }
     }
     $logtext .= $this->view->message;
     $logtext .= "\n";
     if (isset($errors->exception)) {
         $logtext .= isset($errors->exception->information) ? $errors->exception->information : '';
         $logtext .= "\n";
         $logtext .= $errors->exception->getMessage();
         $logtext .= "\n";
         $logtext .= $errors->exception->getTraceAsString();
     }
     // conditionally display exceptions
     if (APPLICATION_ENV != 'production' && isset($errors->exception) && $this->getResponse()->getHttpResponseCode() != 404) {
         $this->view->exception = $errors->exception;
     }
     if (APPLICATION_ENV != 'production' && isset($errors->request) && $this->getResponse()->getHttpResponseCode() != 404) {
         $this->view->request = $errors->request;
     }
     if (isset($errors->request)) {
         $logtext .= var_export($errors->request->getParams(), true);
         $logtext .= "\n";
     } else {
         $this->view->request = '';
     }
     // log errors but not 404s
     if ($this->getResponse()->getHttpResponseCode() != 404) {
         Application_Plugin_Common::log($logtext);
     }
 }
Пример #2
0
 /**
  * Add notification
  */
 public function pushNotification(array $to_users, $notification_type, $resource_type, $resource_id, $set_as_new = true)
 {
     // prevent self-notify
     if (Zend_Auth::getInstance()->hasIdentity() && in_array(Zend_Auth::getInstance()->getIdentity()->id, $to_users)) {
         $key = array_search(Zend_Auth::getInstance()->getIdentity()->id, $to_users);
         unset($to_users[$key]);
     }
     if (!empty($to_users)) {
         foreach ($to_users as $user_id) {
             $data = array('type' => $notification_type, 'to_user' => (int) $user_id, 'resource_type' => $resource_type, 'resource_id' => $resource_id, 'is_new' => $set_as_new ? 1 : 0, 'email_sent' => 0, 'created_on' => Application_Plugin_Common::now());
             try {
                 $result = $this->insert($data);
             } catch (Zend_Db_Exception $e) {
                 Application_Plugin_Common::log($e->getMessage());
             }
         }
     }
     return;
 }
Пример #3
0
 /**
  * Follow User
  */
 public function followUser($user_id, $follow_id)
 {
     if ($this->areFriends($user_id, $follow_id) || $this->isFollowing($follow_id, $user_id)) {
         return false;
     }
     $data = array('user_id' => $user_id, 'follow_id' => $follow_id, 'created_on' => Application_Plugin_Common::now());
     try {
         $ret = $this->insert($data);
     } catch (Zend_Db_Exception $e) {
         Application_Plugin_Common::log($e->getMessage());
     }
     if ($ret === null) {
         return false;
     }
     return true;
 }
Пример #4
0
        if ($protocol == 'https://') {
            $oembedURL .= '&scheme=https';
        }
        $client = new Zend_Http_Client($oembedURL, array('timeout' => 5));
        try {
            $response = $client->request();
            if ($response->isSuccessful()) {
                // return html with iframe
                $ret = $response->getBody();
                $rich_content = array('type' => 'youtube', 'data' => $ret);
                // update meta
                $post['meta'] = array('rich_content' => json_encode($rich_content));
                return;
            }
        } catch (Zend_Http_Client_Adapter_Exception $e) {
            Application_Plugin_Common::log(array($e->getMessage()));
        }
    }, $content);
});
$this->attach('hook_data_postcontent', 10, function (&$post) {
    // fix rich data
    if (isset($post['rich_content_json'])) {
        $rich_content = json_decode($post['rich_content_json']);
        if ($rich_content->type == 'youtube' && !empty($rich_content->data)) {
            $youtube_data = json_decode($rich_content->data);
            // add autoplay to src
            $youtube_data->html = preg_replace('#\\<iframe(.*?)\\ssrc\\=\\"(.*?)\\"(.*?)\\>#i', '<iframe$1 src="$2&autoplay=1"$3>', $youtube_data->html);
            $play_url = htmlentities(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? str_replace("http://", "https://", $youtube_data->html) : $youtube_data->html);
            $youtube_html = '
			<div class="youtube-video-box">
			<div>
Пример #5
0
 /**
  * Finds a view script from the available directories.
  *
  * @param string $name The base name of the script.
  * @return void
  */
 protected function _script($name)
 {
     if ($this->isLfiProtectionOn() && preg_match('#\\.\\.[\\\\/]#', $name)) {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('Requested scripts may not include parent directory traversal ("../", "..\\" notation)');
         $e->setView($this);
         throw $e;
     }
     if (0 == count($this->_path['script'])) {
         require_once 'Zend/View/Exception.php';
         $e = new Zend_View_Exception('no view script directory set; unable to determine location for view script');
         $e->setView($this);
         throw $e;
     }
     /* original
        foreach ($this->_path['script'] as $dir) {
            if (is_readable($dir . $name)) {
                return $dir . $name;
            }
        }
        */
     // alcalbg: layout conflict detector
     $count = 0;
     $ret = $ret_log = false;
     foreach ($this->_path['script'] as $dir) {
         if (is_readable($dir . $name)) {
             if ($ret === false) {
                 $ret = $dir . $name;
             }
             $ret_log = $dir . $name;
             ++$count;
         }
     }
     if ($count > 2) {
         foreach ($this->_path['script'] as $dir) {
             if ($dir . $name != $ret_log && is_readable($dir . $name)) {
                 $message = 'Possible layout conflict: ' . $dir . $name;
                 Application_Plugin_Common::log($message);
             }
         }
     }
     if ($ret) {
         return $ret;
     }
     // alcalbg: end
     require_once 'Zend/View/Exception.php';
     $message = "script '{$name}' not found in path (" . implode(PATH_SEPARATOR, $this->_path['script']) . ")";
     $e = new Zend_View_Exception($message);
     $e->setView($this);
     throw $e;
 }
Пример #6
0
 /**
  * Init main Cache mechanism
  */
 protected function _initCache()
 {
     if (!defined('CACHE_PATH')) {
         die("Error: Cache directory not defined, check index.php file.");
     }
     if ($this->_appConfig->cache_frontend_options) {
         $frontendOptions = json_decode($this->_appConfig->cache_frontend_options, true);
     } else {
         $frontendOptions = array('automatic_serialization' => true, 'lifetime' => 600);
     }
     $backend_fallback = 'File';
     $backendOptions_fallback = array('cache_dir' => CACHE_PATH);
     if ($this->_appConfig->cache_backend) {
         $backend = $this->_appConfig->cache_backend;
         $backendOptions = json_decode($this->_appConfig->cache_backend_options, true);
     } else {
         $backend = $backend_fallback;
         $backendOptions = $backendOptions_fallback;
     }
     try {
         $cache = Zend_Cache::factory('Core', $backend, $frontendOptions, $backendOptions);
     } catch (Zend_Exception $e) {
         $message = 'ERROR: Cannot start cache - ' . $e->getMessage();
         Application_Plugin_Common::log($message);
         // fallback cache
         try {
             $cache = Zend_Cache::factory('Core', $backend_fallback, $frontendOptions, $backendOptions_fallback);
         } catch (Zend_Exception $e) {
             $message = 'ERROR: Cannot start fallback cache - ' . $e->getMessage();
             Application_Plugin_Common::log($message);
             die($message);
         }
     }
     // Set the cache to be used with all table objects
     Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
     // Save all-purpose cache to the registry
     Zend_Registry::set('cache', $cache);
 }
Пример #7
0
 /**
  * Create new page - add defaults & save
  */
 public function createNewPage(Application_Model_Profiles_Row $profile)
 {
     $profile->type = 'page';
     $profile->avatar = 'default/pages.jpg';
     $profile->cover = 'default/' . rand(1, 3) . '.jpg';
     $profile->is_hidden = 0;
     try {
         $created_id = $profile->save();
     } catch (Zend_Db_Exception $e) {
         Application_Plugin_Common::log($e->getMessage());
     }
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $ProfilesMeta->metaUpdate('date_created', Application_Plugin_Common::now(), $created_id);
     $user_id = Zend_Auth::getInstance()->getIdentity()->id;
     return $profile;
 }
Пример #8
0
 /**
  * Send email
  *
  * TODO: add language specific template based on recepient default language
  */
 public static function sendEmail($to, $subject, $body, $show_errors = false)
 {
     if (Zend_Registry::get('config')->get('mail_adapter') == 'smtp') {
         $smtp_config = array('ssl' => Zend_Registry::get('config')->get('mail_security'), 'port' => Zend_Registry::get('config')->get('mail_port'), 'auth' => Zend_Registry::get('config')->get('mail_login'), 'username' => Zend_Registry::get('config')->get('mail_username'), 'password' => Zend_Registry::get('config')->get('mail_password'));
         $tr = new Zend_Mail_Transport_Smtp(Zend_Registry::get('config')->get('mail_host'), $smtp_config);
     } else {
         $tr = new Zend_Mail_Transport_Sendmail();
     }
     Zend_Mail::setDefaultTransport($tr);
     $mail = new Zend_Mail('utf8');
     $mail->setBodyHtml($body);
     $mail->setFrom(Zend_Registry::get('config')->get('mail_from'), Zend_Registry::get('config')->get('mail_from_name'));
     $mail->addTo($to);
     $mail->setSubject($subject);
     try {
         $mail->send($tr);
     } catch (Zend_Mail_Exception $e) {
         if (method_exists($tr, 'getConnection') && method_exists($tr->getConnection(), 'getLog')) {
             Application_Plugin_Common::log(array($e->getMessage(), $tr->getConnection()->getLog()));
         } else {
             Application_Plugin_Common::log(array($e->getMessage(), 'error sending mail'));
         }
         if ($show_errors) {
             Application_Plugin_Alerts::error(Zend_Registry::get('Zend_Translate')->translate('Something went wrong, email was not sent.'), 'off');
         }
         return false;
     }
     return true;
 }