コード例 #1
0
 /**
  * @param array $data Parameters:
  *                    - viewid (int)
  *                    - commentid (int)
  */
 public function __construct($data, $cron = false)
 {
     parent::__construct($data, $cron);
     $comment = new ArtefactTypeComment($this->commentid);
     $this->overridemessagecontents = true;
     if ($onartefact = $comment->get('onartefact')) {
         // feedback on artefact
         $userid = null;
         require_once get_config('docroot') . 'artefact/lib.php';
         $artefactinstance = artefact_instance_from_id($onartefact);
         if ($artefactinstance->feedback_notify_owner()) {
             $userid = $artefactinstance->get('owner');
             $groupid = $artefactinstance->get('group');
             $institutionid = $artefactinstance->get('institution');
         }
         if (empty($this->url)) {
             $this->url = 'artefact/artefact.php?artefact=' . $onartefact . '&view=' . $this->viewid;
         }
     } else {
         // feedback on view.
         $onview = $comment->get('onview');
         if (!($viewrecord = get_record('view', 'id', $onview))) {
             throw new ViewNotFoundException(get_string('viewnotfound', 'error', $onview));
         }
         $userid = $viewrecord->owner;
         $groupid = $viewrecord->group;
         $institutionid = $viewrecord->institution;
         if (empty($this->url)) {
             $this->url = 'view/view.php?id=' . $onview;
         }
     }
     // Now fetch the users that will need to get notified about this event
     // depending on whether the page has an owner, group, or institution id set.
     if (!empty($userid)) {
         $this->users = activity_get_users($this->get_id(), array($userid));
     } else {
         if (!empty($groupid)) {
             require_once get_config('docroot') . 'lib/group.php';
             $this->users = get_records_sql_array("SELECT u.* from {usr} u, {group_member} m, {group} g\n                                                       WHERE g.id = m.group AND m.member = u.id AND m.group = ?\n                                                       AND (g.feedbacknotify = " . GROUP_ROLES_ALL . "\n                                                           OR (g.feedbacknotify = " . GROUP_ROLES_NONMEMBER . " AND (m.role = 'tutor' OR m.role = 'admin'))\n                                                           OR (g.feedbacknotify = " . GROUP_ROLES_ADMIN . " AND m.role = 'admin')\n                                                       )", array($groupid));
         } else {
             if (!empty($institutionid)) {
                 require_once get_config('libroot') . 'institution.php';
                 $institution = new Institution($institutionid);
                 $admins = $institution->institution_and_site_admins();
                 $this->users = get_records_sql_array("SELECT * FROM {usr} WHERE id IN (" . implode(',', $admins) . ")", array());
             }
         }
     }
     if (empty($this->users)) {
         // no one to notify - possibe if group 'feedbacknotify' is set to 0
         return;
     }
     $title = $onartefact ? $artefactinstance->get('title') : $viewrecord->title;
     $this->urltext = $title;
     $body = $comment->get('description');
     $posttime = strftime(get_string('strftimedaydatetime'), $comment->get('ctime'));
     // Internal
     $this->message = strip_tags(str_shorten_html($body, 200, true));
     // Seen as things like emaildigest base the message on $this->message
     // we need to set the language for the $removedbyline here based on first user.
     $user = $this->users[0];
     $lang = empty($user->lang) || $user->lang == 'default' ? get_config('lang') : $user->lang;
     // Comment deleted notification
     if ($deletedby = $comment->get('deletedby')) {
         $this->strings = (object) array('subject' => (object) array('key' => 'commentdeletednotificationsubject', 'section' => 'artefact.comment', 'args' => array($title)));
         $deletedmessage = ArtefactTypeComment::deleted_messages();
         $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.comment');
         $this->message = $removedbyline . ":\n" . $this->message;
         foreach ($this->users as $key => $user) {
             if (empty($user->lang) || $user->lang == 'default') {
                 // check to see if we need to show institution language
                 $instlang = get_user_institution_language($user->id);
                 $lang = empty($instlang) || $instlang == 'default' ? get_config('lang') : $instlang;
             } else {
                 $lang = $user->lang;
             }
             // For email we can send the message in the user's preferred language
             $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.comment');
             $this->users[$key]->htmlmessage = get_string_from_language($lang, 'feedbackdeletedhtml', 'artefact.comment', hsc($title), $removedbyline, clean_html($body), get_config('wwwroot') . $this->url, hsc($title));
             $this->users[$key]->emailmessage = get_string_from_language($lang, 'feedbackdeletedtext', 'artefact.comment', $title, $removedbyline, trim(html2text($body)), $title, get_config('wwwroot') . $this->url);
         }
         return;
     }
     $this->strings = (object) array('subject' => (object) array('key' => 'newfeedbacknotificationsubject', 'section' => 'artefact.comment', 'args' => array($title)));
     $this->url .= '&showcomment=' . $comment->get('id');
     // Email
     $author = $comment->get('author');
     foreach ($this->users as $key => $user) {
         $authorname = empty($author) ? $comment->get('authorname') : display_name($author, $user);
         if (empty($user->lang) || $user->lang == 'default') {
             // check to see if we need to show institution language
             $instlang = get_user_institution_language($user->id);
             $lang = empty($instlang) || $instlang == 'default' ? get_config('lang') : $instlang;
         } else {
             $lang = $user->lang;
         }
         $this->users[$key]->htmlmessage = get_string_from_language($lang, 'feedbacknotificationhtml', 'artefact.comment', hsc($authorname), hsc($title), $posttime, clean_html($body), get_config('wwwroot') . $this->url);
         $this->users[$key]->emailmessage = get_string_from_language($lang, 'feedbacknotificationtext', 'artefact.comment', $authorname, $title, $posttime, trim(html2text($body)), get_config('wwwroot') . $this->url);
     }
 }
コード例 #2
0
 * @package    mahara
 * @subpackage artefact-comment
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */
define('INTERNAL', 1);
define('MENUITEM', 'myportfolio');
require dirname(dirname(dirname(__FILE__))) . '/init.php';
define('TITLE', get_string('editcomment', 'artefact.comment'));
safe_require('artefact', 'comment');
$id = param_integer('id');
$viewid = param_integer('view');
$comment = new ArtefactTypeComment($id);
if ($USER->get('id') != $comment->get('author')) {
    throw new AccessDeniedException(get_string('canteditnotauthor', 'artefact.comment'));
}
$onview = $comment->get('onview');
if ($onview && $onview != $viewid) {
    throw new NotFoundException(get_string('commentnotinview', 'artefact.comment', $id, $viewid));
}
$maxage = (int) get_config_plugin('artefact', 'comment', 'commenteditabletime');
$editableafter = time() - 60 * $maxage;
$goto = $comment->get_view_url($viewid, false);
if ($comment->get('ctime') < $editableafter) {
    $SESSION->add_error_msg(get_string('cantedittooold', 'artefact.comment', $maxage));
    redirect($goto);
}
$lastcomment = ArtefactTypeComment::last_public_comment($viewid, $comment->get('onartefact'));
if (!$comment->get('private') && $id != $lastcomment->id) {
コード例 #3
0
 /**
  * Creates a comment from the given entry
  *
  * @param SimpleXMLElement $entry    The entry to create the comment from
  * @param PluginImportLeap $importer The importer
  * @return array A list of artefact IDs created, to be used with the artefact mapping.
  */
 private static function create_comment(SimpleXMLElement $entry, PluginImportLeap $importer)
 {
     $createdartefacts = array();
     $comment = new ArtefactTypeComment();
     $comment->set('title', (string) $entry->title);
     $description = PluginImportLeap::get_entry_content($entry, $importer);
     $type = isset($entry->content['type']) ? (string) $entry->content['type'] : 'text';
     if ($type == 'text') {
         $description = format_whitespace($description);
     }
     $comment->set('description', $description);
     if ($published = strtotime((string) $entry->published)) {
         $comment->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $comment->set('mtime', $updated);
     }
     $private = PluginImportLeap::is_correct_category_scheme($entry, $importer, 'audience', 'Private');
     $comment->set('private', (int) $private);
     $comment->set('owner', $importer->get('usr'));
     if (isset($entry->author->name) && strlen($entry->author->name)) {
         $comment->set('authorname', $entry->author->name);
     } else {
         $comment->set('author', $importer->get('usr'));
     }
     if (empty(self::$tempview)) {
         self::create_temporary_view($importer->get('usr'));
     }
     $comment->set('onview', self::$tempview);
     $comment->set('tags', PluginImportLeap::get_entry_tags($entry));
     $comment->commit();
     array_unshift($createdartefacts, $comment->get('id'));
     return $createdartefacts;
 }
コード例 #4
0
 /**
  * @param array $data Parameters:
  *                    - viewid (int)
  *                    - commentid (int)
  */
 public function __construct($data, $cron = false)
 {
     parent::__construct($data, $cron);
     $comment = new ArtefactTypeComment($this->commentid);
     $this->overridemessagecontents = true;
     if ($onartefact = $comment->get('onartefact')) {
         // feedback on artefact
         $userid = null;
         require_once get_config('docroot') . 'artefact/lib.php';
         $artefactinstance = artefact_instance_from_id($onartefact);
         if ($artefactinstance->feedback_notify_owner()) {
             $userid = $artefactinstance->get('owner');
         }
         if (empty($this->url)) {
             $this->url = get_config('wwwroot') . 'view/artefact.php?artefact=' . $onartefact . '&view=' . $this->viewid;
         }
     } else {
         // feedback on view.
         $onview = $comment->get('onview');
         if (!($viewrecord = get_record('view', 'id', $onview))) {
             throw new ViewNotFoundException(get_string('viewnotfound', 'error', $onview));
         }
         $userid = $viewrecord->owner;
         if (empty($this->url)) {
             $this->url = get_config('wwwroot') . 'view/view.php?id=' . $onview;
         }
     }
     if (empty($userid)) {
         return;
     }
     $this->users = activity_get_users($this->get_id(), array($userid));
     $title = $onartefact ? $artefactinstance->get('title') : $viewrecord->title;
     $this->urltext = $title;
     $body = $comment->get('description');
     $posttime = strftime(get_string('strftimedaydatetime'), $comment->get('ctime'));
     $user = $this->users[0];
     $lang = empty($user->lang) || $user->lang == 'default' ? get_config('lang') : $user->lang;
     // Internal
     $this->message = strip_tags(str_shorten_html($body, 200, true));
     // Comment deleted notification
     if ($deletedby = $comment->get('deletedby')) {
         $this->strings = (object) array('subject' => (object) array('key' => 'commentdeletednotificationsubject', 'section' => 'artefact.comment', 'args' => array($title)));
         $deletedmessage = ArtefactTypeComment::deleted_messages();
         $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.comment');
         $this->message = $removedbyline . ":\n" . $this->message;
         // Email
         $this->users[0]->htmlmessage = get_string_from_language($lang, 'feedbackdeletedhtml', 'artefact.comment', $title, $removedbyline, $body, $this->url, $title);
         $this->users[0]->emailmessage = get_string_from_language($lang, 'feedbackdeletedtext', 'artefact.comment', $title, $removedbyline, trim(html2text($body)), $title, $this->url);
         return;
     }
     $this->strings = (object) array('subject' => (object) array('key' => 'newfeedbacknotificationsubject', 'section' => 'artefact.comment', 'args' => array($title)));
     $this->url .= '&showcomment=' . $comment->get('id');
     // Email
     $author = $comment->get('author');
     $authorname = empty($author) ? $comment->get('authorname') : display_name($author, $user);
     $this->users[0]->htmlmessage = get_string_from_language($lang, 'feedbacknotificationhtml', 'artefact.comment', $authorname, $title, $posttime, $body, $this->url);
     $this->users[0]->emailmessage = get_string_from_language($lang, 'feedbacknotificationtext', 'artefact.comment', $authorname, $title, $posttime, trim(html2text($body)), $this->url);
 }
コード例 #5
0
 /**
  * Fix comments to point to the right view.  Probably more
  * appropriate in setup_relationships.  To do that we would have
  * to change that call to happen after views are created.
  */
 public static function setup_view_relationships_from_request(PluginImportLeap $importer)
 {
     if ($entry_requests = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ?', array($importer->get('importertransport')->get('importid'), 'comment'))) {
         foreach ($entry_requests as $entry_request) {
             $commentids = unserialize($entry_request->artefactmapping);
             $comment = new ArtefactTypeComment($commentids[0]);
             if ($comment->get('onartefact')) {
                 continue;
             }
             $entry = $importer->get_entry_by_id($entry_request->entryid);
             $referentid = self::get_referent_entryid($entry, $importer);
             if ($viewid = $importer->get_viewid_imported_by_entryid($referentid)) {
                 $comment->set('onview', $viewid);
                 $comment->commit();
             } else {
                 // Nothing to link this comment to, so leave it in the temporary view.
                 self::$savetempview = true;
             }
         }
     }
 }
コード例 #6
0
 * @package    mahara
 * @subpackage artefact-comment
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
 *
 */
define('INTERNAL', 1);
define('MENUITEM', 'myportfolio');
require dirname(dirname(dirname(__FILE__))) . '/init.php';
define('TITLE', get_string('editcomment', 'artefact.comment'));
safe_require('artefact', 'comment');
$id = param_integer('id');
$viewid = param_integer('view');
$comment = new ArtefactTypeComment($id);
if ($USER->get('id') != $comment->get('author')) {
    throw new AccessDeniedException(get_string('canteditnotauthor', 'artefact.comment'));
}
$onview = $comment->get('onview');
if ($onview && $onview != $viewid) {
    throw new NotFoundException(get_string('commentnotinview', 'artefact.comment', $id, $viewid));
}
$maxage = (int) get_config_plugin('artefact', 'comment', 'commenteditabletime');
$editableafter = time() - 60 * $maxage;
$goto = $comment->get_view_url($viewid, false);
if ($comment->get('ctime') < $editableafter) {
    $SESSION->add_error_msg(get_string('cantedittooold', 'artefact.comment', $maxage));
    redirect($goto);
}
$lastcomment = ArtefactTypeComment::last_public_comment($viewid, $comment->get('onartefact'));
if (!$comment->get('private') && $id != $lastcomment->id) {