function smarty_function_get_tag_summary($params, $smarty)
{
    $db = Zend_Registry::get('db');
    $user_id = (int) $params['user_id'];
    $summary = Default_Model_DbTable_BlogPost::GetTagSummary($db, $user_id);
    if (isset($params['assign']) && strlen($params['assign']) > 0) {
        $smarty->assign($params['assign'], $summary);
    }
}
function smarty_function_get_monthly_blog_summary($params, $smarty)
{
    $options = array();
    if (isset($params['user_id'])) {
        $options['user_id'] = (int) $params['user_id'];
    }
    if (isset($params['liveOnly']) && $params['liveOnly']) {
        $options['status'] = Default_Model_DbTable_BlogPost::STATUS_LIVE;
    }
    if (isset($params['public_only'])) {
        $options['public_only'] = (int) $params['public_only'];
    }
    if (isset($params['actuals'])) {
        $options['actuals'] = array(1);
    }
    $db = Zend_Registry::get('db');
    $summary = Default_Model_DbTable_BlogPost::GetMonthlySummary($db, $options);
    if (isset($params['assign']) && strlen($params['assign']) > 0) {
        $smarty->assign($params['assign'], $summary);
    }
}
Beispiel #3
0
 /**
  * Initialization form
  */
 public function init()
 {
     parent::init();
     //---------------- Форма ----------------
     // Указываем action формы
     $urlAction = $this->getUrl('edit', 'blogmanager');
     $urlAction .= '?id=' . $this->post->getId();
     $this->setAction($urlAction);
     //Зададим метод передачи данных
     $this->setMethod('post');
     // Задаем атрибут class для формы
     $this->setAttrib('class', 'myfrm');
     $this->setAttrib('id', 'blogpost-form');
     //------------ Добавим краткое название блога --------------
     $elTitle = new Zend_Form_Element_Text('title', array('label' => 'Название', 'maxlength' => '255', 'size' => '60', 'required' => true, 'validators' => array(array('StringLength', true, array(0, 255))), 'filters' => array(array('StringTrim'), array('StripTags'))));
     //Установим название, если блог существует
     $this->addElement($elTitle);
     if ($this->post->profile->title) {
         $this->setDefault('title', $this->post->profile->title);
     }
     //---------------- Дата создания записи в блоге ----------------
     // Элемент "Дата создания". Элемент содержит нестандартный декоратор - javascript календарь
     $elDatePost = new Zend_Form_Element_Text('ts_created', array('label' => 'Дата создания', 'maxlength' => '10', 'required' => true, 'validators' => array(array('Date', true, array('locale' => $this->_language))), 'filters' => array('StringTrim')));
     // Удаляем все существующие декораторы, назначенные по умолчанию
     $elDatePost->clearDecorators();
     // Назначаем новые, включая наш декоратор Calendar
     // Это необходимо для того что бы изображение календаря размещалось сразу за полем ввода
     $elDatePost->addDecorator('ViewHelper')->addDecorator('Calendar')->addDecorator('Errors')->addDecorator('HtmlTag', array('tag' => 'dd'))->addDecorator('Label', array('tag' => 'dt'));
     $this->addElement($elDatePost);
     //Установим дату по умолчанию
     //        $tsCreated = $this->post->ts_created;
     $locale = Default_Plugin_SysBox::getTranslateLocale();
     $format = Default_Plugin_SimpleDate::get_format_display_date($locale);
     $sd = new Default_Plugin_SimpleDate($this->post->ts_created);
     $this->setDefault('ts_created', $sd->to_display_date($format));
     //---------- Добавим элемент описания сообщения в блоге ------------
     //$this->addElement('textarea', 'content', array(
     $elDescription = new Zend_Form_Element_Textarea('ckeditor_description', array('label' => $this->Translate('Краткое описание сообщения') . ':', 'required' => false, 'validators' => array(), 'filters' => array('Sanitize')));
     $this->addElement($elDescription);
     //Установим краткое описание сообщения, если оно существует
     if ($this->post->profile->description) {
         $this->setDefault('ckeditor_description', $this->post->profile->description);
     }
     //---------- Добавим элемент содержания блога ------------
     //$this->addElement('textarea', 'content', array(
     $elContent = new Zend_Form_Element_Textarea('ckeditor_content', array('label' => $this->Translate('Ваше сообщение') . ':', 'required' => true, 'filters' => array('Sanitize')));
     $this->addElement($elContent);
     //Установим содержания блога, если оно существует
     if ($this->post->profile->content) {
         $this->setDefault('ckeditor_content', $this->post->profile->content);
     }
     //-------- Добавим кнопки --------------
     //Установим значение кнопки сохранить
     $this->addElement('submit', 'save', array('ignore' => true, 'label' => 'Сохранить'));
     $this->getElement('save')->setAttrib('class', 'btn btn-primary');
     //Перезапишем стандартные декораторы, для размещения двух кнопок рядом
     $this->getElement('save')->setDecorators(array('ViewHelper'));
     //Установим значение кнопки закрыть
     $this->addElement('submit', 'close', array('ignore' => true, 'label' => 'Закрыть'));
     $this->getElement('close')->setAttrib('class', 'btn');
     //Перезапишем стандартные декораторы, для размещения двух кнопок рядом
     $this->getElement('close')->setDecorators(array('ViewHelper'));
     //---------------- Группа данные блога ----------------
     // Группируем элементы
     // Группа полей связанных с авторизационными данными
     $this->addDisplayGroup(array('title', 'ts_created', 'ckeditor_description', 'ckeditor_content', 'save', 'close'), 'blogDataGroup', array('legend' => 'Подробная информация'));
 }
Beispiel #4
0
 /**
  * Action - feed 
  * actions with news user tape 
  * you can get all the news 
  * and the user can receive news only on a separate tag
  *
  * Access to the action is possible in the following paths:
  * router pattern - user/all/feed/:tag/* or controller/:action/*
  *
  * - /user/all/feed/reports
  * or
  * - /index/feed
  *
  * @return void
  */
 public function feedAction()
 {
     //Получим параметр метки
     $tag = trim($this->_request->getUserParam('tag'));
     // first retrieve all recent posts
     $options = array('status' => Default_Model_DbTable_BlogPost::STATUS_LIVE, 'limit' => 10, 'order' => 'p.ts_created desc', 'public_only' => true);
     if ($tag) {
         $options['tag'] = $tag;
     }
     $recentPosts = Default_Model_DbTable_BlogPost::GetPosts($this->db, $options);
     // base URL for generated links
     if ($this->getRequest()->getServer('HTTPS') == 'on') {
         $domain = 'https://';
     } else {
         $domain = 'http://';
     }
     $domain .= $this->getRequest()->getServer('HTTP_HOST');
     // url for web feed
     if ($tag) {
         $url = $this->getCustomUrl(array('tag' => $tag), 'feed_tag_all');
     } else {
         $url = $this->getUrl('feed');
     }
     $feedData = array('link' => $domain . $url, 'charset' => 'UTF-8', 'entries' => array());
     if ($tag) {
         $tagLabel = Default_Model_DbTable_BlogPost::getLabelForTag($this->db, $tag);
         $title = $this->Translate('Сообщения авторов') . ' ' . $this->Translate('для метки') . ' - ' . $tagLabel;
     } else {
         $title = $this->Translate('Сообщения всех авторов');
     }
     $feedData['title'] = $title;
     // determine which users' posts were retrieved
     $user_ids = array();
     foreach ($recentPosts as $post) {
         $user_ids[$post->user_id] = $post->user_id;
     }
     // load the user records
     if (count($user_ids) > 0) {
         $options = array('user_id' => $user_ids);
         $users = Default_Model_DbTable_User::GetUsers($this->db, $options);
     } else {
         $users = array();
     }
     // build feed entries based on returned posts
     foreach ($recentPosts as $post) {
         $user = $users[$post->user_id];
         $url = $this->getCustomUrl(array('username' => $user->username, 'url' => $post->url), 'post');
         $entry = array('title' => $post->profile->title, 'link' => $domain . $url, 'description' => $post->getTeaser(200), 'lastUpdate' => $post->ts_created, 'category' => array());
         // attach tags to each entry
         foreach ($post->getTags() as $tag) {
             $entry['category'][] = array('term' => $tag);
         }
         $feedData['entries'][] = $entry;
     }
     // create feed based on created data
     $feed = Zend_Feed::importArray($feedData, 'atom');
     // disable auto-rendering since we're outputting an image
     $this->_helper->viewRenderer->setNoRender();
     // output the feed to the browser
     $feed->send();
 }
Beispiel #5
0
 /**
  * Get the values of a field in a table
  *
  * @param array $options
  *
  * @return array
  */
 public function getValuesForCol($options = NULL)
 {
     // Обращение идет к таблице "users"
     if ($options['joinTableForSort'] == 'admin.users') {
         $options['joinTableForSort'] = '';
         $rows = Default_Model_DbTable_User::GetValuesForCol($this->db, $options);
         return $rows;
     }
     // Обращение идет к таблице "users_profile"
     if ($options['joinTableForSort'] == 'admin.users_profile') {
         $options['joinTableForSort'] = 'users_profile';
         $rows = Default_Model_DbTable_User::GetValuesForCol($this->db, $options);
         return $rows;
     }
     // Обращение идет к таблице "blog_post" или присоединенным таблицам:
     // blog_post_profile; blog_post_tags; blog_post_images; blog_post_locations
     $rows = Default_Model_DbTable_BlogPost::GetValuesForCol($this->db, $options);
     return $rows;
 }
Beispiel #6
0
 /**
  * Action - optimize
  * optimize the search index
  *
  * Access to the action is possible in the following paths:
  * - /search/optimize
  * @return void
  */
 public function optimizeAction()
 {
     $result = TRUE;
     $err_msg = '';
     $json = array();
     //-------------------
     try {
         // Задержка условная
         sleep(3);
         $indexFullpath = Default_Model_DbTable_BlogPost::getIndexFullpath();
         // Откроем поисковый индекс
         $index = Zend_Search_Lucene::open($indexFullpath);
         // Оптимизация индекса
         $index->optimize();
         $message = array('<em>' . $this->Translate("Оптимизация поискового индекса") . '!</em>', $this->Translate("Оптимизация поискового индекса завершилась успешно") . '.');
         if ($this->_isAjaxRequest) {
             $json['class_message'] = 'information';
             $json['messages'] = $message;
             $json['$result'] = $result;
         }
     } catch (Exception $ex) {
         $err_msg = $ex->getMessage();
         $message = array('<em>' . $this->Translate("Ошибка оптимизации поискового индекса") . '!</em>', $err_msg);
         if ($this->_isAjaxRequest) {
             $json['class_message'] = 'warning';
             $json['messages'] = $message;
             $json['$result'] = $result;
         } else {
             $logger = Zend_Registry::get('Zend_Log');
             $logger->warn('Error optimizing search index: ' . $ex->getMessage());
             $result = FALSE;
         }
     }
     if ($this->_isAjaxRequest) {
         $this->sendJson($json);
     } else {
         $this->view->result = $result;
         if ($result) {
             $this->view->class_message = 'information';
         } else {
             $this->view->err_msg = $err_msg;
             $this->view->class_message = 'warning';
         }
         $this->view->message = $message;
         $this->_breadcrumbs->addStep($this->Translate('Оптимизация поискового индекса'));
     }
 }
Beispiel #7
0
 /**
  * Load row table
  *
  * @param array $row
  * @param int $id
  *
  * @return bool
  */
 public function loadRowTable($row, $id)
 {
     $result = parent::loadRowTable($row, $id);
     if ($result) {
         // Загрузим все записи пользователя
         $options = array('user_id' => array($id));
         $row->posts = Default_Model_DbTable_BlogPost::GetPosts($this->db, $options);
     }
     return $result;
 }
 /**
  * Action - getlocations
  * get geographic coordinates
  *
  * Access to the action is possible in the following paths:
  * - /blogmanager/getlocations?user_id=1234&post_id=2345
  *
  * @return void
  */
 public function getlocationsAction()
 {
     $request = $this->getRequest();
     $post_id = $request->getPost('post_id');
     $user_id = $request->getPost('user_id');
     $ret = array('post_id' => 0);
     $post = new Default_Model_DbTable_BlogPost($this->db);
     if ($post->loadForUser($user_id, $post_id)) {
         $ret['post_id'] = $post->getId();
         $ret['locations'] = array();
         foreach ($post->locations as $location) {
             $location_id = $location->getId();
             $details_url = $this->getUrl('details', 'blogmanager') . "?post_id={$post_id}&location_id={$location_id}";
             $ret['locations'][] = array('location_id' => $location_id, 'latitude' => $location->latitude, 'longitude' => $location->longitude, 'description' => $location->description, 'content' => $location->content, 'correction' => $location->correction, 'details' => $location->details ? $details_url : '');
         }
     }
     $this->sendJson($ret);
 }
Beispiel #9
0
 /**
  * Action - images
  * obtain images via ajax request
  *
  * Access to the action is possible in the following paths:
  * router pattern - user/:username/post/:post_id/images/*
  * 
  * - /user/user1/post/27/images
  *
  * @return void
  */
 public function imagesAction()
 {
     if ($this->_isAjaxRequest) {
         $jsons = array();
         try {
             $request = $this->getRequest();
             $username = trim($request->getUserParam('username'));
             $post_id = (int) $request->getUserParam('post_id');
             $params = $request->getParams();
             $_from = (int) $params['from'];
             $_to = (int) $params['to'];
             // Получим сообщение
             $posts = Default_Model_DbTable_BlogPost::GetPosts($this->db, array('post_id' => array($post_id)));
             if ($posts) {
                 $images = $posts[$post_id]->images;
                 $images = array_values($images);
                 $indexMax = count($images) - 1;
                 // Создадим обьект шаблона
                 $templater = Default_Plugin_SysBox::createViewSmarty();
                 //Установим параметры шаблона
                 $templater->images = $images;
                 $templater->username = $username;
                 $templater->_from = $_from;
                 $templater->_to = $_to;
                 // Получим результат шаблона
                 $html = $templater->render('user/images.tpl');
                 $jsons['html'] = $html;
                 $more = $indexMax > $_to;
                 $jsons['more'] = $more;
                 if ($_to > $indexMax) {
                     $_to = $indexMax;
                 }
                 $jsons['to'] = $_to;
                 $jsons['from'] = $_from;
             }
             $this->sendJson($jsons);
         } catch (Exception $exc) {
             $jsons = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка получения изображений') . '</em>', Default_Plugin_SysBox::getMessageError($exc)));
             $this->sendJson($jsons);
             return;
         }
     }
 }