/** * 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; }
function delete_comment_submit(Pieform $form, $values) { global $SESSION, $USER, $view; $comment = new ArtefactTypeComment((int) $values['comment']); if ($USER->get('id') == $comment->get('author')) { $deletedby = 'author'; } else { if ($USER->can_edit_view($view)) { $deletedby = 'owner'; } else { if ($USER->get('admin')) { $deletedby = 'admin'; } } } $viewid = $view->get('id'); if ($artefact = $comment->get('onartefact')) { $url = 'artefact/artefact.php?view=' . $viewid . '&artefact=' . $artefact; } else { $url = $view->get_url(false); } db_begin(); $comment->set('deletedby', $deletedby); $comment->commit(); if ($deletedby != 'author') { // Notify author if ($artefact) { $title = get_field('artefact', 'title', 'id', $artefact); } else { $title = get_field('view', 'title', 'id', $comment->get('onview')); } $title = hsc($title); $data = (object) array('subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'commentdeletednotificationsubject', 'section' => 'artefact.comment', 'args' => array($title)), 'message' => (object) array('key' => 'commentdeletedauthornotification', 'section' => 'artefact.comment', 'args' => array($title, html2text($comment->get('description')))), 'urltext' => (object) array('key' => $artefact ? 'artefact' : 'view')), 'users' => array($comment->get('author')), 'url' => $url); activity_occurred('maharamessage', $data); } if ($deletedby != 'owner' && $comment->get('owner') != $USER->get('id')) { // Notify owner $data = (object) array('commentid' => $comment->get('id'), 'viewid' => $view->get('id')); activity_occurred('feedback', $data, 'artefact', 'comment'); } db_commit(); $SESSION->add_ok_msg(get_string('commentremoved', 'artefact.comment')); redirect(get_config('wwwroot') . $url); }
/** * 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; } } } }