Copyright 2003-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (GPL). If you did not receive this file, see http://www.horde.org/licenses/gpl.
Автор: Marko Djukic (marko@oblo.com)
Автор: Duck (duck@obala.net)
Пример #1
0
 /**
  * Allows other Horde apps to post messages.
  *
  * In most apps we use the same code to make comments possible. This function
  * does most of that. Allow comments to be added to any app. The app itself
  * should check if the agora api is present, determine a key and call this
  * function before app::menu is called (before any output has started. At the
  * end of its output it can print the array returned to show the comments.
  *
  * @access private
  *
  * @param string $scope          The application which is posting this message.
  * @param string $key            Unique key from the object (picture etc we're
  *                               viewing. It will be used as the forum name.
  * @param string $callback       A callback method of the specified application
  *                               that gets called to make sure that posting to
  *                               this forum is allowed.
  * @param boolean $body          Show the comment bodies in the thread view or
  *                               not.
  * @param string $base_url       Base URL the edit/delete/reply links should
  *                               point to.
  * @param string $url            If specified, the form gets submitted to this
  *                               URL instead of the current page.
  * @param array $variables       A hash with all variables of a submitted form
  *                               generated by this method.
  * @param string $template_file  Template file to use.
  *
  * @return mixed array  Returns either the rendered Horde_Form for comments
  *                      and threads for posting/viewing a message or PEAR
  *                      objects on error.
  */
 public function doComments($scope, $key, $callback, $bodies = true, $base_url = null, $url = null, $variables = null, $template_file = false)
 {
     if (is_null($base_url)) {
         $base_url = Horde::selfUrl(true);
     }
     list($forum_id, $message_id) = Agora::getAgoraId();
     $params = array();
     if ($message_id) {
         $params['message_id'] = $message_id;
     }
     if ($parent = Horde_Util::getFormData('message_parent_id')) {
         $params['message_parent_id'] = $parent;
     }
     // See if we're editing.
     if (isset($params['message_id'])) {
         $params['title'] = _("Edit a comment");
     } else {
         $params['title'] = _("Add a comment");
         $params['message_id'] = null;
     }
     if (Horde_Util::getFormData('delete') === null) {
         $comments = $this->postMessage($scope, $key, $callback, $params, $url, $variables);
     } else {
         $comments = $this->removeMessage($scope, $key, $callback, $params, $url, $variables);
     }
     if ($comments instanceof PEAR_Error) {
         return $comments;
     }
     include AGORA_BASE . '/lib/Comments.php';
     $threads = Agora_ViewComments::render($key, $scope, $base_url, $template_file);
     if ($threads instanceof PEAR_Error) {
         $threads = $threads->getMessage();
     }
     if ($comments instanceof PEAR_Error) {
         $comments = $comments->getMessage();
     }
     return array('threads' => $threads, 'comments' => $comments);
 }