public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $configdata = $instance->get('configdata'); $configdata['viewid'] = $instance->get('view'); $configdata['simpledisplay'] = true; // This can be either an image or profileicon. They both implement // render_self $result = ''; $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null; if ($artefactid) { $artefact = $instance->get_artefact_instance($artefactid); $result = $artefact->render_self($configdata); $result = $result['html']; require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($configdata['viewid']); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); } $smarty = smarty_core(); if ($artefactid) { $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); } $smarty->assign('html', $result); return $smarty->fetch('blocktype:folder:folder.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); $result = ''; $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null; if ($artefactid) { require_once get_config('docroot') . 'artefact/lib.php'; $artefact = $instance->get_artefact_instance($artefactid); $configdata['hidetitle'] = true; $configdata['countcomments'] = true; $configdata['viewid'] = $instance->get('view'); $configdata['blockid'] = $instance->get('id'); $result = $artefact->render_self($configdata); $result = $result['html']; require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($configdata['viewid']); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); } $smarty = smarty_core(); if ($artefactid) { $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); } $smarty->assign('html', $result); return $smarty->fetch('blocktype:blogpost:blogpost.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us $configdata['viewid'] = $instance->get('view'); $result = ''; $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null; if ($artefactid) { $artefact = $instance->get_artefact_instance($artefactid); if (!file_exists($artefact->get_path())) { return; } $result = clean_html(file_get_contents($artefact->get_path())); require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($configdata['viewid']); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); } $smarty = smarty_core(); if ($artefactid) { $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); } $smarty->assign('html', $result); return $smarty->fetch('blocktype:html:html.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us if (!isset($configdata['artefactid'])) { return ''; } $id = $configdata['artefactid']; $image = $instance->get_artefact_instance($id); $wwwroot = get_config('wwwroot'); $viewid = $instance->get('view'); if ($image instanceof ArtefactTypeProfileIcon) { $src = $wwwroot . 'thumb.php?type=profileiconbyid&id=' . $id; $description = $image->get('title'); } else { $src = $wwwroot . 'artefact/file/download.php?file=' . $id . '&view=' . $viewid; $description = $image->get('description'); } if (!empty($configdata['width'])) { $src .= '&maxwidth=' . $configdata['width']; } require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($viewid); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($image, $view, $instance->get('id'), true, $editing); $smarty = smarty_core(); $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); $smarty->assign('url', $wwwroot . 'artefact/artefact.php?artefact=' . $id . '&view=' . $viewid); $smarty->assign('src', $src); $smarty->assign('description', $description); $smarty->assign('showdescription', !empty($configdata['showdescription']) && !empty($description)); return $smarty->fetch('blocktype:image:image.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; require_once get_config('docroot') . 'lib/view.php'; $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us $configdata['viewid'] = $instance->get('view'); $view = new View($configdata['viewid']); $group = $view->get('group'); $result = ''; $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null; if ($artefactid) { $artefact = $instance->get_artefact_instance($configdata['artefactid']); if (!file_exists($artefact->get_path())) { return ''; } $urlbase = get_config('wwwroot'); // edit view doesn't use subdomains, neither do groups if (get_config('cleanurls') && get_config('cleanurlusersubdomains') && !$editing && empty($group)) { $viewauthor = new User(); $viewauthor->find_by_id($view->get('owner')); $viewauthorurlid = $viewauthor->get('urlid'); if ($urlallowed = !is_null($viewauthorurlid) && strlen($viewauthorurlid)) { $urlbase = profile_url($viewauthor) . '/'; } } // Send the current language to the pdf viewer $language = current_language(); $language = str_replace('_', '-', substr($language, 0, substr_count($language, '_') > 0 ? 5 : 2)); if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) { // In case the language file exists as a string with both lower and upper case, eg fr_FR we test for this $language = substr($language, 0, 2) . '-' . strtoupper(substr($language, 0, 2)); if (!file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) { // In case we fail to find a language of 5 chars, eg pt_BR (Portugese, Brazil) we try the 'parent' pt (Portugese) $language = substr($language, 0, 2); if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) { $language = 'en-GB'; } } } $result = '<iframe src="' . $urlbase . 'artefact/file/blocktype/pdf/viewer.php?editing=' . $editing . '&ingroup=' . !empty($group) . '&file=' . $artefactid . '&lang=' . $language . '&view=' . $instance->get('view') . '" width="100%" height="500" frameborder="0"></iframe>'; require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($configdata['viewid']); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); } $smarty = smarty_core(); if ($artefactid) { $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); } $smarty->assign('html', $result); return $smarty->fetch('blocktype:pdf:pdfrender.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; if ($editing) { $smarty = smarty_core(); $smarty->assign('editing', get_string('ineditordescription1', 'blocktype.comment/comment')); $html = $smarty->fetch('blocktype:comment:comment.tpl'); return $html; } // Feedback list pagination requires limit/offset params $limit = param_integer('limit', 10); $offset = param_integer('offset', 0); $showcomment = param_integer('showcomment', null); // Create the "make feedback private form" now if it's been submitted if (param_variable('make_public_submit', null)) { pieform(ArtefactTypeComment::make_public_form(param_integer('comment'))); } else { if (param_variable('delete_comment_submit_x', null)) { pieform(ArtefactTypeComment::delete_comment_form(param_integer('comment'))); } } $view = new View($instance->get('view')); $submittedgroup = (int) $view->get('submittedgroup'); if ($USER->is_logged_in() && $submittedgroup && group_user_can_assess_submitted_views($submittedgroup, $USER->get('id'))) { $releaseform = true; } else { $releaseform = false; } // If the view has comments turned off, tutors can still leave // comments if the view is submitted to their group. if (!empty($releaseform) || $view->user_comments_allowed($USER)) { $addfeedbackpopup = true; } safe_require('artefact', 'comment'); $commentoptions = ArtefactTypeComment::get_comment_options(); $commentoptions->limit = $limit; $commentoptions->offset = $offset; $commentoptions->showcomment = $showcomment; $commentoptions->view = $instance->get_view(); $feedback = ArtefactTypeComment::get_comments($commentoptions); $smarty = smarty_core(); $smarty->assign('feedback', $feedback); if (isset($addfeedbackpopup)) { $smarty->assign('enablecomments', 1); $smarty->assign('addfeedbackpopup', $addfeedbackpopup); } $html = $smarty->fetch('blocktype:comment:comment.tpl'); return $html; }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); if (!empty($configdata['artefactid'])) { safe_require('artefact', 'file'); safe_require('artefact', 'comment'); $artefact = $instance->get_artefact_instance($configdata['artefactid']); $viewid = $instance->get('view'); $text = ArtefactTypeFolder::append_view_url($artefact->get('note'), $viewid); $information = ArtefactTypeFolder::append_view_url($artefact->get('description'), $viewid); $literature = $configdata['literature']; $smarty = smarty_core(); $smarty->assign('text', $text); $smarty->assign('information', $information); $smarty->assign('literature', $literature); $attachments = $artefact->get_attachments(); if ($attachments) { require_once get_config('docroot') . 'artefact/lib.php'; foreach ($attachments as &$attachment) { $f = artefact_instance_from_id($attachment->id); $attachment->size = $f->describe_size(); $attachment->iconpath = $f->get_icon(array('id' => $attachment->id, 'viewid' => isset($options['viewid']) ? $options['viewid'] : 0)); $attachment->viewpath = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($viewid) ? $viewid : 0); $attachment->downloadpath = get_config('wwwroot') . 'artefact/file/download.php?file=' . $attachment->id; if (isset($viewid)) { $attachment->downloadpath .= '&view=' . $viewid; } } $smarty->assign('attachments', $attachments); $smarty->assign('count', count($attachments)); } require_once get_config('docroot') . 'lib/view.php'; $view = new View($viewid); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); $smarty->assign('blockid', $instance->get('id')); return $smarty->fetch('blocktype:eselmagraduation:content.tpl'); } return ''; }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); if (!empty($configdata['artefactid'])) { safe_require('artefact', 'file'); safe_require('artefact', 'comment'); $artefact = $instance->get_artefact_instance($configdata['artefactid']); $viewid = $instance->get('view'); $text = ArtefactTypeFolder::append_view_url($artefact->get('description'), $viewid); $smarty = smarty_core(); $smarty->assign('text', $text); $attachments = $artefact->get_attachments(); if ($attachments) { require_once get_config('docroot') . 'artefact/lib.php'; foreach ($attachments as &$attachment) { $f = artefact_instance_from_id($attachment->id); $attachment->size = $f->describe_size(); $attachment->iconpath = $f->get_icon(array('id' => $attachment->id, 'viewid' => isset($options['viewid']) ? $options['viewid'] : 0)); $attachment->viewpath = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $attachment->id . '&view=' . (isset($viewid) ? $viewid : 0); $attachment->downloadpath = get_config('wwwroot') . 'artefact/file/download.php?file=' . $attachment->id; if (isset($viewid)) { $attachment->downloadpath .= '&view=' . $viewid; } } $smarty->assign('attachments', $attachments); $smarty->assign('count', count($attachments)); } if ($artefact->get('allowcomments')) { $commentcount = ArtefactTypeComment::count_comments(null, array($configdata['artefactid'])); $commentcount = isset($commentcount[$configdata['artefactid']]) ? $commentcount[$configdata['artefactid']]->comments : 0; $artefacturl = get_config('wwwroot') . 'artefact/artefact.php?view=' . $viewid . '&artefact=' . $configdata['artefactid']; $smarty->assign('artefacturl', $artefacturl); $smarty->assign('commentcount', $commentcount); } return $smarty->fetch('blocktype:textbox:content.tpl'); } return ''; }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); $viewid = $instance->get('view'); $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null; if (empty($artefactid)) { return ''; } $result = self::get_js_source(); require_once get_config('docroot') . 'artefact/lib.php'; $artefact = $instance->get_artefact_instance($artefactid); $defaultwidth = get_config_plugin('blocktype', 'internalmedia', 'width') ? get_config_plugin('blocktype', 'internalmedia', 'width') : 300; $defaultheight = get_config_plugin('blocktype', 'internalmedia', 'height') ? get_config_plugin('blocktype', 'internalmedia', 'height') : 300; $width = !empty($configdata['width']) ? hsc($configdata['width']) : $defaultwidth; $height = !empty($configdata['height']) ? hsc($configdata['height']) : $defaultheight; $mimetype = $artefact->get('filetype'); $mimetypefiletypes = self::get_allowed_mimetype_filetypes(); if (!isset($mimetypefiletypes[$mimetype])) { return get_string('typeremoved', 'blocktype.file/internalmedia'); } $callbacks = self::get_all_filetype_players(); $result .= '<div class="mediaplayer-container center"><div class="mediaplayer">' . call_static_method('PluginBlocktypeInternalmedia', $callbacks[$mimetypefiletypes[$mimetype]], $artefact, $instance, $width, $height) . '</div></div>'; if ($artefactid) { require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($viewid); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); } $smarty = smarty_core(); if ($artefactid) { $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); } $smarty->assign('html', $result); return $smarty->fetch('blocktype:internalmedia:internalmedia.tpl'); }
* * @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'));
/** * 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; }
$data['ecommenters'] = $extcommenters; $data['mcomments'] = $membercomments; $data['ecomments'] = $extcomments; $data['comments'] = $commenters; $data['baseurl'] = $needsubdomain ? $view->get_url(true) : $wwwroot . $view->get_url(false); } if (in_array($sort, array('title', 'sharedby', 'mcomments', 'ecomments'))) { sorttablebycolumn($sharedviews, $sort, $direction); } $sharedviews = array_slice($sharedviews, $offset, $limit); list($searchform, $groupviews, $unusedpagination) = View::views_by_owner($group->id); $groupviews = $groupviews->data; $groupviewscount = count($groupviews); foreach ($groupviews as &$data) { $view = new View($data['id']); $comments = ArtefactTypeComment::get_comments(0, 0, null, $view); $extcommenters = 0; $membercommenters = 0; $extcomments = 0; $membercomments = 0; $commenters = array(); foreach ($comments->data as $c) { if (empty($c->author)) { if (!isset($commenters[$c->authorname])) { $commenters[$c->authorname] = array(); } $commenters[$c->authorname]['commenter'] = $c->authorname; $commenters[$c->authorname]['count'] = isset($commenters[$c->authorname]['count']) ? $commenters[$c->authorname]['count'] + 1 : 1; if ($commenters[$c->authorname]['count'] == 1) { $extcommenters++; }
/** * @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); }
* @copyright For copyright information on Mahara, please see the README file distributed with this software. * */ define('INTERNAL', 1); define('PUBLIC', 1); define('JSON', 1); require dirname(dirname(dirname(__FILE__))) . '/init.php'; require_once get_config('libroot') . 'view.php'; require_once get_config('libroot') . 'pieforms/pieform.php'; safe_require('artefact', 'comment'); $extradata = json_decode(param_variable('extradata')); if (!can_view_view($extradata->view)) { json_reply('local', get_string('noaccesstoview', 'view')); } if (!empty($extradata->artefact) && !artefact_in_view($extradata->artefact, $extradata->view)) { json_reply('local', get_string('accessdenied', 'error')); } $limit = param_integer('limit', 10); $offset = param_integer('offset'); $artefact = null; if (!empty($extradata->artefact)) { $artefact = artefact_instance_from_id($extradata->artefact); } $view = new View($extradata->view); $commentoptions = ArtefactTypeComment::get_comment_options(); $commentoptions->limit = $limit; $commentoptions->offset = $offset; $commentoptions->view = $view; $commentoptions->artefact = $artefact; $data = ArtefactTypeComment::get_comments($commentoptions); json_reply(false, array('data' => $data));
public function delete() { safe_require('artefact', 'comment'); db_begin(); ArtefactTypeComment::delete_view_comments($this->id); delete_records('view_access', 'view', $this->id); delete_records('view_autocreate_grouptype', 'view', $this->id); delete_records('view_tag', 'view', $this->id); delete_records('view_visit', 'view', $this->id); delete_records('collection_view', 'view', $this->id); delete_records('usr_watchlist_view', 'view', $this->id); if ($blockinstanceids = get_column('block_instance', 'id', 'view', $this->id)) { require_once get_config('docroot') . 'blocktype/lib.php'; foreach ($blockinstanceids as $id) { $bi = new BlockInstance($id); $bi->delete(); } } handle_event('deleteview', $this->id); delete_records('view_rows_columns', 'view', $this->id); delete_records('view', 'id', $this->id); if (!empty($this->owner) && $this->is_submitted()) { // There should be no way to delete a submitted view, // but unlock its artefacts just in case. ArtefactType::update_locked($this->owner); } require_once 'embeddedimage.php'; EmbeddedImage::delete_embedded_images('description', $this->id); $this->deleted = true; db_commit(); }
array_unshift($artefactpath, array('url' => get_config('wwwroot') . 'view/artefact.php?artefact=' . $parent . '&view=' . $viewid, 'title' => $parentobj->display_title())); } $parent = $parentobj->get('parent'); } $artefactpath[] = array('url' => '', 'title' => $artefact->display_title()); // Feedback $feedback = ArtefactTypeComment::get_comments($limit, $offset, $showcomment, $view, $artefact); $javascript = <<<EOF var viewid = {$viewid}; addLoadEvent(function () { paginator = {$feedback->pagination_js} }); EOF; if ($artefact->get('allowcomments')) { $anonfeedback = !$USER->is_logged_in() && view_has_token($viewid, get_cookie('viewaccess:' . $viewid)); $addfeedbackform = pieform(ArtefactTypeComment::add_comment_form(false, $artefact->get('approvecomments'))); } $objectionform = pieform(objection_form()); if ($notrudeform = $view->notrude_form()) { $notrudeform = pieform($notrudeform); } $viewbeingwatched = (int) record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid); $headers = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'); $hasfeed = false; $feedlink = ''; // add a link to the ATOM feed in the header if the view is public if ($artefact->get('artefacttype') == 'blog' && $view->is_public()) { $hasfeed = true; $feedlink = get_config('wwwroot') . 'artefact/blog/atom.php?artefact=' . $artefactid . '&view=' . $viewid; $headers[] = '<link rel="alternate" type="application/atom+xml" href="' . $feedlink . '" />'; }
} // If the view has comments turned off, tutors can still leave // comments if the view is submitted to their group. if (!empty($releaseform) || ($commenttype = $view->user_comments_allowed($USER))) { $defaultprivate = !empty($releaseform); $moderate = isset($commenttype) && $commenttype === 'private'; $addfeedbackform = pieform(ArtefactTypeComment::add_comment_form($defaultprivate, $moderate)); } if ($USER->is_logged_in()) { $objectionform = pieform(objection_form()); if ($notrudeform = $view->notrude_form()) { $notrudeform = pieform($notrudeform); } } $viewbeingwatched = (int) record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid); $feedback = ArtefactTypeComment::get_comments($limit, $offset, $showcomment, $view); // Set up theme $viewtheme = $view->get('theme'); if ($viewtheme && $THEME->basename != $viewtheme) { $THEME = new Theme($viewtheme); } $stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">'); $can_edit = $USER->can_edit_view($view) && !$submittedgroup && !$view->is_submitted(); $smarty = smarty(array('paginator', 'viewmenu', 'artefact/resume/resumeshowhide.js'), $stylesheets, array(), array('stylesheets' => array('style/views.css'), 'sidebars' => false)); $javascript = <<<EOF var viewid = {$viewid}; addLoadEvent(function () { paginator = {$feedback->pagination_js} }); EOF; // collection top navigation
function institution_view_stats_table($limit, $offset, &$institutiondata) { global $USER; if ($institutiondata['views'] != 0) { $count = count_records_select('view', 'id IN (' . join(',', array_fill(0, $institutiondata['views'], '?')) . ') AND type != ?', array_merge($institutiondata['viewids'], array('dashboard'))); } else { $count = 0; } $pagination = build_pagination(array('id' => 'stats_pagination', 'url' => get_config('wwwroot') . 'admin/users/statistics.php?institution=' . $institutiondata['name'] . '&type=views', 'jsonscript' => 'admin/users/statistics.json.php', 'datatable' => 'statistics_table', 'count' => $count, 'limit' => $limit, 'offset' => $offset, 'extradata' => array('institution' => $institutiondata['name']), 'setlimit' => true)); $result = array('count' => $count, 'tablerows' => '', 'pagination' => $pagination['html'], 'pagination_js' => $pagination['javascript']); if ($count < 1) { return $result; } $viewdata = get_records_sql_assoc("SELECT\n v.id, v.title, v.owner, v.group, v.institution, v.visits, v.type, v.ownerformat, v.urlid\n FROM {view} v\n WHERE v.id IN (" . join(',', array_fill(0, $institutiondata['views'], '?')) . ") AND v.type != ?\n ORDER BY v.visits DESC, v.title, v.id", array_merge($institutiondata['viewids'], array('dashboard')), $offset, $limit); require_once 'view.php'; require_once 'group.php'; View::get_extra_view_info($viewdata, false, false); safe_require('artefact', 'comment'); $comments = ArtefactTypeComment::count_comments(array_keys($viewdata)); foreach ($viewdata as &$v) { $v = (object) $v; if ($v->owner) { $v->ownername = display_name($v->user); $v->ownerurl = profile_url($v->user); } else { $v->ownername = $v->sharedby; if ($v->group) { $v->ownerurl = group_homepage_url($v->groupdata); } else { if ($v->institution && $v->institution != 'mahara') { $v->ownerurl = get_config('wwwroot') . 'institution/index.php?institution=' . $v->institution; } } } $v->comments = isset($comments[$v->id]) ? (int) $comments[$v->id]->comments : 0; } $csvfields = array('title', 'displaytitle', 'fullurl', 'owner', 'group', 'institution', 'ownername', 'ownerurl', 'visits', 'type', 'comments'); $USER->set_download_file(generate_csv($viewdata, $csvfields), 'viewstatistics.csv', 'text/csv'); $result['csv'] = true; $smarty = smarty_core(); $smarty->assign('data', $viewdata); $smarty->assign('offset', $offset); $result['tablerows'] = $smarty->fetch('admin/viewstats.tpl'); return $result; }
/** * 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; } } } }
function institution_submit(Pieform $form, $values) { global $SESSION, $institution, $add, $instancearray, $USER, $authinstances, $customthemedefaults; db_begin(); // Update the basic institution record... if ($add) { $newinstitution = new Institution(); $newinstitution->initialise($values['name'], $values['displayname']); $institution = $newinstitution->name; } else { $newinstitution = new Institution($institution); $newinstitution->displayname = $values['displayname']; $oldinstitution = get_record('institution', 'name', $institution); // Clear out any cached menus for this institution clear_menu_cache($institution); } $newinstitution->showonlineusers = !isset($values['showonlineusers']) ? 2 : $values['showonlineusers']; if (get_config('usersuniquebyusername')) { // Registering absolutely not allowed when this setting is on, it's a // security risk. See the documentation for the usersuniquebyusername // setting for more information $newinstitution->registerallowed = 0; } else { $newinstitution->registerallowed = $values['registerallowed'] ? 1 : 0; $newinstitution->registerconfirm = $values['registerconfirm'] ? 1 : 0; } if (!empty($values['lang'])) { if ($values['lang'] == 'sitedefault') { $newinstitution->lang = null; } else { $newinstitution->lang = $values['lang']; } } $newinstitution->theme = empty($values['theme']) || $values['theme'] == 'sitedefault' ? null : $values['theme']; $newinstitution->dropdownmenu = !empty($values['dropdownmenu']) ? 1 : 0; $newinstitution->skins = !empty($values['skins']) ? 1 : 0; require_once get_config('docroot') . 'artefact/comment/lib.php'; $commentoptions = ArtefactTypeComment::get_comment_options(); $newinstitution->commentsortorder = empty($values['commentsortorder']) ? $commentoptions->sort : $values['commentsortorder']; $newinstitution->commentthreaded = !empty($values['commentthreaded']) ? 1 : 0; if ($newinstitution->theme == 'custom') { if (!empty($oldinstitution->style)) { $styleid = $oldinstitution->style; delete_records('style_property', 'style', $styleid); } else { $record = (object) array('title' => get_string('customstylesforinstitution', 'admin', $newinstitution->displayname)); $styleid = insert_record('style', $record, 'id', true); } $properties = array(); $record = (object) array('style' => $styleid); foreach (array_keys($customthemedefaults) as $name) { $record->field = $name; $record->value = $values[$name]; insert_record('style_property', $record); $properties[$name] = $values[$name]; } // Cache the css $smarty = smarty_core(); $smarty->assign('data', $properties); set_field('style', 'css', $smarty->fetch('customcss.tpl'), 'id', $styleid); $newinstitution->style = $styleid; } else { $newinstitution->style = null; } if (get_config('licensemetadata')) { $newinstitution->licensemandatory = !empty($values['licensemandatory']) ? 1 : 0; $newinstitution->licensedefault = isset($values['licensedefault']) ? $values['licensedefault'] : ''; } if (!empty($values['resetcustom']) && !empty($oldinstitution->style)) { $newinstitution->style = null; } if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) { if (!empty($values['updateuserquotas']) && !empty($values['defaultquota'])) { execute_sql("UPDATE {usr} SET quota = ? WHERE id IN (SELECT usr FROM {usr_institution} WHERE institution = ?)", array($values['defaultquota'], $institution)); // get all the users from the institution and make sure that they are still below // their quota threshold if ($users = get_records_sql_array('SELECT * FROM {usr} u LEFT JOIN {usr_institution} ui ON u.id = ui.usr AND ui.institution = ?', array($institution))) { $quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit'); if ($quotanotifylimit <= 0 || $quotanotifylimit >= 100) { $quotanotifylimit = 100; } foreach ($users as $user) { $user->quota = $values['defaultquota']; // check if the user has gone over the quota notify limit $user->quotausedpercent = $user->quotaused / $user->quota * 100; $overlimit = false; if ($quotanotifylimit <= $user->quotausedpercent) { $overlimit = true; } $notified = get_field('usr_account_preference', 'value', 'field', 'quota_exceeded_notified', 'usr', $user->id); if ($overlimit && '1' !== $notified) { require_once get_config('docroot') . 'artefact/file/lib.php'; ArtefactTypeFile::notify_users_threshold_exceeded(array($user), false); // no need to email admin as we can alert them right now $SESSION->add_error_msg(get_string('useroverquotathreshold', 'artefact.file', display_name($user))); } else { if ($notified && !$overlimit) { set_account_preference($user->id, 'quota_exceeded_notified', false); } } } } } $newinstitution->defaultquota = empty($values['defaultquota']) ? get_config_plugin('artefact', 'file', 'defaultquota') : $values['defaultquota']; } if ($institution != 'mahara') { $newinstitution->defaultmembershipperiod = $values['defaultmembershipperiod'] ? intval($values['defaultmembershipperiod']) : null; if ($USER->get('admin')) { $newinstitution->maxuseraccounts = $values['maxuseraccounts'] ? intval($values['maxuseraccounts']) : null; $newinstitution->expiry = db_format_timestamp($values['expiry']); } } $newinstitution->allowinstitutionpublicviews = isset($values['allowinstitutionpublicviews']) && $values['allowinstitutionpublicviews'] ? 1 : 0; // TODO: Move handling of authentication instances within the Institution class as well? if (!empty($values['authplugin'])) { $allinstances = array_merge($values['authplugin']['instancearray'], $values['authplugin']['deletearray']); if (array_diff($allinstances, $instancearray)) { throw new ConfigException('Attempt to delete or update another institution\'s auth instance'); } if (array_diff($instancearray, $allinstances)) { throw new ConfigException('One of your instances is unaccounted for in this transaction'); } foreach ($values['authplugin']['instancearray'] as $priority => $instanceid) { if (in_array($instanceid, $values['authplugin']['deletearray'])) { // Should never happen: throw new SystemException('Attempt to update AND delete an auth instance'); } $record = new StdClass(); $record->priority = $priority; $record->id = $instanceid; update_record('auth_instance', $record, array('id' => $instanceid)); } foreach ($values['authplugin']['deletearray'] as $instanceid) { // If this authinstance is the only xmlrpc authinstance that references a host, delete the host record. $hostwwwroot = null; foreach ($authinstances as $ai) { if ($ai->id == $instanceid && $ai->authname == 'xmlrpc') { $hostwwwroot = get_field_sql("SELECT \"value\" FROM {auth_instance_config} WHERE \"instance\" = ? AND field = 'wwwroot'", array($instanceid)); if ($hostwwwroot && count_records_select('auth_instance_config', "field = 'wwwroot' AND \"value\" = ?", array($hostwwwroot)) == 1) { // Unfortunately, it's possible that this host record could belong to a different institution, // so specify the institution here. delete_records('host', 'wwwroot', $hostwwwroot, 'institution', $institution); // We really need to fix this, either by removing the institution from the host table, or refusing to allow the // institution to be changed in the host record when another institution's authinstance is still pointing at it. } break; } } delete_records('auth_remote_user', 'authinstance', $instanceid); delete_records('auth_instance_config', 'instance', $instanceid); delete_records('auth_instance', 'id', $instanceid); // Make it no longer be the parent authority to any auth instances delete_records('auth_instance_config', 'field', 'parent', 'value', $instanceid); } } // Store plugin settings. plugin_institution_prefs_submit($form, $values, $newinstitution); // Save the changes to the DB $newinstitution->commit(); if ($add) { // Automatically create an internal authentication authinstance $authinstance = (object) array('instancename' => 'internal', 'priority' => 0, 'institution' => $newinstitution->name, 'authname' => 'internal'); insert_record('auth_instance', $authinstance); // We need to add the default lines to the site_content table for this institution // We also need to set the institution to be using default static pages to begin with // so that using custom institution pages is an opt-in situation $pages = site_content_pages(); $now = db_format_timestamp(time()); foreach ($pages as $name) { $page = new stdClass(); $page->name = $name; $page->ctime = $now; $page->mtime = $now; $page->content = get_string($page->name . 'defaultcontent', 'install', get_string('staticpageconfiginstitution', 'install')); $page->institution = $newinstitution->name; insert_record('site_content', $page); $institutionconfig = new stdClass(); $institutionconfig->institution = $newinstitution->name; $institutionconfig->field = 'sitepages_' . $name; $institutionconfig->value = 'mahara'; insert_record('institution_config', $institutionconfig); } } if (is_null($newinstitution->style) && !empty($oldinstitution->style)) { delete_records('style_property', 'style', $oldinstitution->style); delete_records('style', 'id', $oldinstitution->style); } // Set the logo after updating the institution, because the institution // needs to exist before it can own the logo artefact. if (!empty($values['logo'])) { safe_require('artefact', 'file'); // Entry in artefact table $data = (object) array('institution' => $institution, 'title' => 'logo', 'description' => 'Institution logo', 'note' => $values['logo']['name'], 'size' => $values['logo']['size']); $imageinfo = getimagesize($values['logo']['tmp_name']); $data->width = $imageinfo[0]; $data->height = $imageinfo[1]; $data->filetype = $imageinfo['mime']; $artefact = new ArtefactTypeProfileIcon(0, $data); if (preg_match("/\\.([^\\.]+)\$/", $values['logo']['name'], $saved)) { $artefact->set('oldextension', $saved[1]); } $artefact->commit(); $id = $artefact->get('id'); // Move the file into the correct place. $directory = get_config('dataroot') . 'artefact/file/profileicons/originals/' . $id % 256 . '/'; check_dir_exists($directory); move_uploaded_file($values['logo']['tmp_name'], $directory . $id); // Delete the old logo if (!empty($oldinstitution->logo)) { $oldlogo = new ArtefactTypeProfileIcon($oldinstitution->logo); $oldlogo->delete(); } set_field('institution', 'logo', $id, 'name', $institution); } if (!empty($values['deletelogo'])) { execute_sql("UPDATE {institution} SET logo = NULL WHERE name = ?", array($institution)); } delete_records('institution_locked_profile_field', 'name', $institution); foreach (ArtefactTypeProfile::get_all_fields() as $field => $type) { if ($values[$field]) { $profilefield = new StdClass(); $profilefield->name = $institution; $profilefield->profilefield = $field; insert_record('institution_locked_profile_field', $profilefield); } } db_commit(); if ($add) { if (!$newinstitution->registerallowed) { // If registration is not allowed, then an authinstance will not // have been created, and thus cause the institution page to add // its own error message on the next page load $SESSION->add_ok_msg(get_string('institutionaddedsuccessfully2', 'admin')); } $nexturl = '/admin/users/institutions.php?i=' . urlencode($institution); } else { $message = get_string('institutionupdatedsuccessfully', 'admin'); if (isset($values['theme'])) { $changedtheme = $oldinstitution->theme != $values['theme'] && (!empty($oldinstitution->theme) || $values['theme'] != 'sitedefault'); if ($changedtheme || $values['theme'] == 'custom') { $message .= ' ' . get_string('usersseenewthemeonlogin', 'admin'); } $USER->reset_institutions(); } $SESSION->add_ok_msg($message); $nexturl = '/admin/users/institutions.php'; } redirect($nexturl); }
/** * Dumps all views into the HTML export */ private function dump_view_export_data() { safe_require('artefact', 'comment'); $progressstart = 55; $progressend = 75; $i = 0; $viewcount = count($this->views); $rootpath = $this->exportingoneview ? './' : '../../'; $smarty = $this->get_smarty($rootpath); foreach ($this->views as $viewid => $view) { $this->notify_progress_callback(intval($progressstart + ++$i / $viewcount * ($progressend - $progressstart)), get_string('exportingviewsprogress', 'export', $i, $viewcount)); $smarty->assign('page_heading', $view->get('title')); $smarty->assign('viewdescription', $view->get('description')); if ($this->exportingoneview) { $smarty->assign('nobreadcrumbs', true); $directory = $this->exportdir . '/' . $this->rootdir; } else { $smarty->assign('breadcrumbs', array(array('text' => get_string('Views', 'view')), array('text' => $view->get('title'), 'path' => 'index.html'))); $directory = $this->exportdir . '/' . $this->rootdir . '/views/' . self::text_to_filename($view->get('title')); if (is_dir($directory)) { throw new SystemException(get_string('duplicatepagetitle', 'export.html')); } if (!check_dir_exists($directory)) { throw new SystemException("Could not create directory for view {$viewid}"); } } // Collection menu data if (isset($this->viewcollection[$viewid]) && $this->viewexportmode == PluginExport::EXPORT_COLLECTIONS) { $smarty->assign_by_ref('collectionname', $this->collections[$this->viewcollection[$viewid]]->get('name')); $smarty->assign_by_ref('collectionmenu', $this->collection_menu($this->viewcollection[$viewid])); $smarty->assign('viewid', $viewid); } $outputfilter = new HtmlExportOutputFilter($rootpath, $this); // Include comments if ($this->includefeedback) { $commentoptions = ArtefactTypeComment::get_comment_options(); $commentoptions->view = $view; $commentoptions->limit = 0; $commentoptions->export = true; if ($feedback = ArtefactTypeComment::get_comments($commentoptions)) { $feedback->tablerows = $outputfilter->filter($feedback->tablerows); } $smarty->assign('feedback', $feedback); } $smarty->assign('view', $outputfilter->filter($view->build_rows(false, true))); $content = $smarty->fetch('export:html:view.tpl'); if (!file_put_contents("{$directory}/index.html", $content)) { throw new SystemException("Could not write view page for view {$viewid}"); } } }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; $configdata = $instance->get('configdata'); $view = $instance->get('view'); $full = isset($configdata['full']) ? $configdata['full'] : false; $results = array(); $smarty = smarty_core(); $smarty->assign('view', $view); $viewownerdisplay = null; // Display all posts, from all blogs, owned by this user $tagsin = $tagsout = array(); $results = self::get_blog_posts_in_block($instance, $tagsin, $tagsout); if ($tagsin || $tagsout) { $smarty->assign('blockid', $instance->get('id')); $smarty->assign('editing', $editing); if ($editing) { // Get list of blogs owned by this user to create the "Add new post" shortcut while editing $viewowner = $instance->get_view()->get('owner'); if (!$viewowner || !($blogs = get_records_select_array('artefact', 'artefacttype = \'blog\' AND owner = ?', array($viewowner), 'title ASC', 'id, title'))) { $blogs = array(); } $smarty->assign('tagselect', implode(', ', $tagsin)); $smarty->assign('blogs', $blogs); } // if posts are not found with the selected tag, notify the user if (!$results) { $smarty->assign('badtag', implode(', ', $tagsin)); $smarty->assign('badnotag', implode(', ', $tagsout)); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); } // update the view_artefact table so journal entries are accessible when this is the only block on the page // referencing this journal $dataobject = array('view' => $view, 'block' => $instance->get('id')); require_once get_config('docroot') . 'lib/view.php'; $viewobj = new View($view); require_once get_config('docroot') . 'artefact/lib.php'; safe_require('artefact', 'blog'); safe_require('artefact', 'comment'); foreach ($results as $result) { $dataobject["artefact"] = $result->parent; $result->postedbyon = get_string('postedbyon', 'artefact.blog', display_default_name($result->owner), format_date(strtotime($result->ctime))); $result->displaydate = format_date(strtotime($result->ctime)); $artefact = new ArtefactTypeBlogpost($result->id); // get comments for this post $result->commentcount = count_records_select('artefact_comment_comment', "onartefact = {$result->id} AND private = 0 AND deletedby IS NULL"); $allowcomments = $artefact->get('allowcomments'); if (empty($result->commentcount) && empty($allowcomments)) { $result->commentcount = null; } list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $viewobj, null, false); $result->comments = $comments; // get all tags for this post $taglist = get_records_array('artefact_tag', 'artefact', $result->id, "tag DESC"); foreach ($taglist as $t) { $result->taglist[] = $t->tag; } if ($full) { $rendered = $artefact->render_self(array('viewid' => $view, 'details' => true, 'blockid' => $instance->get('id'))); $result->html = $rendered['html']; if (!empty($rendered['javascript'])) { $result->html .= '<script type="application/javascript">' . $rendered['javascript'] . '</script>'; } } } // check if the user viewing the page is the owner of the selected tag $owner = $results[0]->owner; if ($USER->id != $owner) { $viewownerdisplay = get_user_for_display($owner); } $smarty->assign('tagsin', $tagsin); $smarty->assign('tagsout', $tagsout); } else { if (!self::get_chooseable_tags()) { // error if block configuration fails $smarty->assign('configerror', get_string('notagsavailableerror', 'blocktype.blog/taggedposts')); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); } else { // error if block configuration fails $smarty->assign('configerror', get_string('configerror', 'blocktype.blog/taggedposts')); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); } } // add any needed links to the tags $tagstr = $tagomitstr = ''; foreach ($tagsin as $key => $tag) { if ($key > 0) { $tagstr .= ', '; } $tagstr .= $viewownerdisplay ? '"' . $tag . '"' : '"<a href="' . get_config('wwwroot') . 'tags.php?tag=' . $tag . '&sort=name&type=text">' . $tag . '</a>"'; } if (!empty($tagsout)) { foreach ($tagsout as $key => $tag) { if ($key > 0) { $tagomitstr .= ', '; } $tagomitstr .= $viewownerdisplay ? '"' . $tag . '"' : '"<a href="' . get_config('wwwroot') . 'tags.php?tag=' . $tag . '&sort=name&type=text">' . $tag . '</a>"'; } } $blockheading = get_string('blockheadingtags', 'blocktype.blog/taggedposts', count($tagsin), $tagstr); $blockheading .= !empty($tagomitstr) ? get_string('blockheadingtagsomit', 'blocktype.blog/taggedposts', count($tagsout), $tagomitstr) : ''; $blockheading .= $viewownerdisplay ? ' ' . get_string('by', 'artefact.blog') . ' <a href="' . profile_url($viewownerdisplay) . '">' . display_name($viewownerdisplay) . '</a>' : ''; $smarty->assign('full', $full); $smarty->assign('results', $results); $smarty->assign('blockheading', $blockheading); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); }
/** * This function returns a list of posts in a given blog. * * @param integer * @param integer * @param integer * @param array */ public static function get_posts($id, $limit, $offset, $viewoptions = null) { $results = array('limit' => $limit, 'offset' => $offset); // If viewoptions is null, we're getting posts for the my blogs area, // and we should get all posts & show drafts first. Otherwise it's a // blog in a view, and we should only get published posts. $from = "\n FROM {artefact} a LEFT JOIN {artefact_blog_blogpost} bp ON a.id = bp.blogpost\n WHERE a.artefacttype = 'blogpost' AND a.parent = ?"; if (!is_null($viewoptions)) { if (isset($viewoptions['before'])) { $from .= " AND a.ctime < '{$viewoptions['before']}'"; } $from .= ' AND bp.published = 1'; } $results['count'] = count_records_sql('SELECT COUNT(*) ' . $from, array($id)); $data = get_records_sql_assoc(' SELECT a.id, a.title, a.description, a.author, a.authorname, ' . db_format_tsfield('a.ctime', 'ctime') . ', ' . db_format_tsfield('a.mtime', 'mtime') . ', a.locked, bp.published, a.allowcomments ' . $from . ' ORDER BY bp.published ASC, a.ctime DESC, a.id DESC', array($id), $offset, $limit); if (!$data) { $results['data'] = array(); return $results; } // Get the attached files. $postids = array_map(create_function('$a', 'return $a->id;'), $data); $files = ArtefactType::attachments_from_id_list($postids); if ($files) { safe_require('artefact', 'file'); foreach ($files as &$file) { $params = array('id' => $file->attachment); if (!empty($viewoptions['viewid'])) { $params['viewid'] = $viewoptions['viewid']; } $file->icon = call_static_method(generate_artefact_class_name($file->artefacttype), 'get_icon', $params); $data[$file->artefact]->files[] = $file; } } if ($tags = ArtefactType::tags_from_id_list($postids)) { foreach ($tags as &$at) { $data[$at->artefact]->tags[] = $at->tag; } } foreach ($data as &$post) { // Format dates properly if (is_null($viewoptions)) { // My Blogs area: create forms for changing post status & deleting posts. $post->changepoststatus = ArtefactTypeBlogpost::changepoststatus_form($post->id, $post->published); $post->delete = ArtefactTypeBlogpost::delete_form($post->id, $post->title); } else { $by = $post->author ? display_default_name($post->author) : $post->authorname; $post->postedby = get_string('postedbyon', 'artefact.blog', $by, format_date($post->ctime)); // Get comment counts if (!empty($viewoptions['countcomments'])) { safe_require('artefact', 'comment'); require_once get_config('docroot') . 'lib/view.php'; $view = new View($viewoptions['viewid']); $artefact = artefact_instance_from_id($post->id); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, null, false); $post->commentcount = $commentcount; $post->comments = $comments; } } $post->ctime = format_date($post->ctime, 'strftimedaydatetime'); $post->mtime = format_date($post->mtime); // Ensure images in the post have the right viewid associated with them if (!empty($viewoptions['viewid'])) { safe_require('artefact', 'file'); $post->description = ArtefactTypeFolder::append_view_url($post->description, $viewoptions['viewid']); } } $results['data'] = array_values($data); return $results; }
$moderate = isset($commenttype) && $commenttype === 'private'; $addfeedbackform = pieform(ArtefactTypeComment::add_comment_form($defaultprivate, $moderate)); } if ($USER->is_logged_in()) { $objectionform = pieform(objection_form()); if ($notrudeform = notrude_form()) { $notrudeform = pieform($notrudeform); } } $viewbeingwatched = (int) record_exists('usr_watchlist_view', 'usr', $USER->get('id'), 'view', $viewid); $commentoptions = ArtefactTypeComment::get_comment_options(); $commentoptions->limit = $limit; $commentoptions->offset = $offset; $commentoptions->showcomment = $showcomment; $commentoptions->view = $view; $feedback = ArtefactTypeComment::get_comments($commentoptions); // Set up theme $viewtheme = $view->get('theme'); if ($viewtheme && $THEME->basename != $viewtheme) { $THEME = new Theme($viewtheme); } $headers = array(); $headers[] = '<link rel="stylesheet" type="text/css" href="' . append_version_number(get_config('wwwroot') . 'js/jquery/jquery-ui/css/ui-lightness/jquery-ui-1.10.2.min.css') . '">'; $headers = array_merge($headers, $view->get_all_blocktype_css()); // Set up skin, if the page has one $viewskin = $view->get('skin'); $issiteview = $view->get('institution') == 'mahara'; if ($viewskin && get_config('skins') && can_use_skins($owner, false, $issiteview) && (!isset($THEME->skins) || $THEME->skins !== false)) { $skin = array('skinid' => $viewskin, 'viewid' => $view->get('id')); $skindata = unserialize(get_field('skin', 'viewskin', 'id', $viewskin)); } else {
/** * @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); } }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us $configdata['viewid'] = $instance->get('view'); $style = isset($configdata['style']) ? intval($configdata['style']) : 2; $copyright = null; // Needed to set Panoramio copyright later... $width = !empty($configdata['width']) ? $configdata['width'] : 75; $width = floor($width); switch ($style) { case 0: // thumbnails $template = 'thumbnails'; break; case 1: // slideshow $template = 'slideshow'; $width = !empty($configdata['width']) ? $configdata['width'] : 400; break; case 2: // square thumbnails $template = 'squarethumbs'; break; } $images = array(); $slimbox2 = get_config_plugin('blocktype', 'gallery', 'useslimbox2'); if ($slimbox2) { $slimbox2attr = 'lightbox_' . $instance->get('id'); } else { $slimbox2attr = null; } // if we're trying to embed external gallery (thumbnails or slideshow) if (isset($configdata['select']) && $configdata['select'] == 2) { $gallery = self::make_gallery_url($configdata['external']); if (empty($gallery)) { return get_string('externalnotsupported', 'blocktype.file/gallery'); } $url = isset($gallery['url']) ? hsc($gallery['url']) : null; $type = isset($gallery['type']) ? hsc($gallery['type']) : null; $var1 = isset($gallery['var1']) ? hsc($gallery['var1']) : null; $var2 = isset($gallery['var2']) ? hsc($gallery['var2']) : null; switch ($type) { case 'widget': /***************************** Roy Tanck's FLICKR WIDGET for Flickr RSS & Picasa RSS http://www.roytanck.com/get-my-flickr-widget/ *****************************/ $widget_sizes = array(100, 200, 300); $width = self::find_nearest($widget_sizes, $width); $images = urlencode(str_replace('&', '&', $url)); $template = 'imagecloud'; break; case 'picasa': // Slideshow if ($style == 1) { $picasa_show_sizes = array(144, 288, 400, 600, 800); $width = self::find_nearest($picasa_show_sizes, $width); $height = round($width * 0.75); $images = array('user' => $var1, 'gallery' => $var2); $template = 'picasashow'; } else { $picasa_thumbnails = array(32, 48, 64, 72, 104, 144, 150, 160); $width = self::find_nearest($picasa_thumbnails, $width); // If the Thumbnails should be Square... if ($style == 2) { $small = 's' . $width . '-c'; $URL = 'http://picasaweb.google.com/data/feed/api/user/' . $var1 . '/album/' . $var2 . '?kind=photo&thumbsize=' . $width . 'c'; } else { $small = 's' . $width; $URL = 'http://picasaweb.google.com/data/feed/api/user/' . $var1 . '/album/' . $var2 . '?kind=photo&thumbsize=' . $width; } $big = 's' . get_config_plugin('blocktype', 'gallery', 'previewwidth'); $xmlDoc = new DOMDocument('1.0', 'UTF-8'); $config = array(CURLOPT_URL => $URL, CURLOPT_RETURNTRANSFER => true); $result = mahara_http_request($config); $xmlDoc->loadXML($result->data); $photos = $xmlDoc->getElementsByTagNameNS('http://search.yahoo.com/mrss/', 'group'); foreach ($photos as $photo) { $children = $photo->cloneNode(true); $thumb = $children->getElementsByTagNameNS('http://search.yahoo.com/mrss/', 'thumbnail')->item(0)->getAttribute('url'); $description = null; if (isset($children->getElementsByTagNameNS('http://search.yahoo.com/mrss/', 'description')->item(0)->firstChild->nodeValue)) { $description = $children->getElementsByTagNameNS('http://search.yahoo.com/mrss/', 'description')->item(0)->firstChild->nodeValue; } $images[] = array('link' => str_replace($small, $big, $thumb), 'source' => $thumb, 'title' => $description, 'slimbox2' => $slimbox2attr); } } break; case 'flickr': // Slideshow if ($style == 1) { $flickr_show_sizes = array(400, 500, 700, 800); $width = self::find_nearest($flickr_show_sizes, $width); $height = round($width * 0.75); $images = array('user' => $var1, 'gallery' => $var2); $template = 'flickrshow'; } else { $width = 75; // Currently only thumbnail size, that Flickr supports $api_key = get_config_plugin('blocktype', 'gallery', 'flickrapikey'); $URL = 'https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&extras=url_sq,url_t&photoset_id=' . $var2 . '&api_key=' . $api_key; $xmlDoc = new DOMDocument('1.0', 'UTF-8'); $config = array(CURLOPT_URL => $URL, CURLOPT_RETURNTRANSFER => true); $result = mahara_http_request($config); $xmlDoc->loadXML($result->data); $photos = $xmlDoc->getElementsByTagName('photo'); foreach ($photos as $photo) { // If the Thumbnails should be Square... if ($style == 2) { $thumb = $photo->getAttribute('url_sq'); $link = str_replace('_s.jpg', '_b.jpg', $thumb); } else { $thumb = $photo->getAttribute('url_t'); $link = str_replace('_t.jpg', '_b.jpg', $thumb); } $description = $photo->getAttribute('title'); $images[] = array('link' => $link, 'source' => $thumb, 'title' => $description, 'slimbox2' => $slimbox2attr); } } break; case 'panoramio': // Slideshow if ($style == 1) { $height = round($width * 0.75); $images = array('user' => $var1); $template = 'panoramioshow'; } else { $copyright = get_string('panoramiocopyright', 'blocktype.file/gallery'); $URL = 'http://www.panoramio.com/map/get_panoramas.php?set=' . $var1 . '&from=0&to=50&size=original&mapfilter=true'; $config = array(CURLOPT_URL => $URL, CURLOPT_RETURNTRANSFER => true); $result = mahara_http_request($config); $data = json_decode($result->data, true); foreach ($data['photos'] as $photo) { $link = str_replace('/original/', '/large/', $photo['photo_file_url']); // If the Thumbnails should be Square... if ($style == 2) { $thumb = str_replace('/original/', '/square/', $photo['photo_file_url']); $width = 60; // Currently only square thumbnail size, that Panoramio supports } else { $thumb = str_replace('/original/', '/thumbnail/', $photo['photo_file_url']); } $title = !empty($photo['photo_title']) ? $photo['photo_title'] : get_string('Photo', 'blocktype.file/gallery'); $description = '<a href="' . $photo['photo_url'] . '" target="_blank">' . $title . '</a>' . ' ' . get_string('by', 'blocktype.file/gallery') . ' ' . '<a href="' . $photo['owner_url'] . '" target="_blank">' . $photo['owner_name'] . '</a>'; $images[] = array('link' => $link, 'source' => $thumb, 'title' => $description, 'slimbox2' => $slimbox2attr); } } break; case 'photobucket': // Slideshow if ($style == 1) { $height = round($width * 0.75); $images = array('url' => $url, 'user' => $var1, 'album' => $var2); $template = 'photobucketshow'; } else { $consumer_key = get_config_plugin('blocktype', 'gallery', 'pbapikey'); // PhotoBucket API key $consumer_secret = get_config_plugin('blocktype', 'gallery', 'pbapiprivatekey'); //PhotoBucket API private key $oauth_signature_method = 'HMAC-SHA1'; $oauth_version = '1.0'; $oauth_timestamp = time(); $mt = microtime(); $rand = mt_rand(); $oauth_nonce = md5($mt . $rand); $method = 'GET'; $albumname = $var1 . '/' . $var2; $api_url = 'http://api.photobucket.com/album/' . urlencode($albumname); $params = null; $paramstring = 'oauth_consumer_key=' . $consumer_key . '&oauth_nonce=' . $oauth_nonce . '&oauth_signature_method=' . $oauth_signature_method . '&oauth_timestamp=' . $oauth_timestamp . '&oauth_version=' . $oauth_version; $base = urlencode($method) . '&' . urlencode($api_url) . '&' . urlencode($paramstring); $oauth_signature = base64_encode(hash_hmac('sha1', $base, $consumer_secret . '&', true)); $URL = $api_url . '?' . $paramstring . '&oauth_signature=' . urlencode($oauth_signature); $xmlDoc = new DOMDocument('1.0', 'UTF-8'); $config = array(CURLOPT_URL => $URL, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true); $result = mahara_http_request($config); $xmlDoc->loadXML($result->data); $xmlDoc2 = new DOMDocument('1.0', 'UTF-8'); $config2 = array(CURLOPT_URL => $xmlDoc->getElementsByTagName('url')->item(0)->firstChild->nodeValue, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true); $result2 = mahara_http_request($config2); $xmlDoc2->loadXML($result->data); $photos = $xmlDoc2->getElementsByTagName('media'); foreach ($photos as $photo) { $children = $photo->cloneNode(true); $link = $children->getElementsByTagName('url')->item(0)->firstChild->nodeValue; $thumb = $children->getElementsByTagName('thumb')->item(0)->firstChild->nodeValue; $description = null; if (isset($children->getElementsByTagName('description')->item(0)->firstChild->nodeValue)) { $description = $children->getElementsByTagName('description')->item(0)->firstChild->nodeValue; } $images[] = array('link' => $link, 'source' => $thumb, 'title' => $description, 'slimbox2' => $slimbox2attr); } } break; case 'windowslive': // Slideshow if ($style == 1) { $images = array('url' => $url, 'user' => $var1, 'album' => $var2); $template = 'windowsliveshow'; } else { $config = array(CURLOPT_URL => str_replace(' ', '%20', $url), CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true); $result = mahara_http_request($config); $data = $result->data; // Extract data about images and thumbs from HTML source - hack! preg_match_all("#previewImageUrl: '([a-zA-Z0-9\\_\\-\\.\\\\/]+)'#", $data, $photos); preg_match_all("#thumbnailImageUrl: '([a-zA-Z0-9\\_\\-\\.\\\\/]+)'#", $data, $thumbs); for ($i = 0; $i < sizeof($photos[1]); $i++) { $images[] = array('link' => str_replace(array('\\x3a', '\\x2f', '\\x25', '\\x3fpsid\\x3d1'), array(':', '/', '%', ''), $photos[1][$i]), 'source' => str_replace(array('\\x3a', '\\x2f', '\\x25', '\\x3fpsid\\x3d1'), array(':', '/', '%', ''), $thumbs[1][$i]), 'title' => null, 'slimbox2' => $slimbox2attr); } } break; } } else { safe_require('artefact', 'file'); $artefactids = array(); if (isset($configdata['select']) && $configdata['select'] == 1 && is_array($configdata['artefactids'])) { $artefactids = $configdata['artefactids']; } else { if (!empty($configdata['artefactid'])) { // Get descendents of this folder. $artefactids = artefact_get_descendants(array(intval($configdata['artefactid']))); } } // This can be either an image or profileicon. They both implement // render_self foreach ($artefactids as $artefactid) { $image = $instance->get_artefact_instance($artefactid); if ($image instanceof ArtefactTypeProfileIcon) { $src = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $artefactid; $description = $image->get('title'); } else { if ($image instanceof ArtefactTypeImage) { $src = get_config('wwwroot') . 'artefact/file/download.php?file=' . $artefactid; $src .= '&view=' . $instance->get('view'); $description = $image->get('description'); } else { continue; } } if ($slimbox2) { $link = $src . '&maxwidth=' . get_config_plugin('blocktype', 'gallery', 'previewwidth'); } else { $link = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $artefactid . '&view=' . $instance->get('view'); } // If the Thumbnails are Square or not... if ($style == 2) { // Determine the scaling for the fitting the image in the square of $width size // Calculate the bigger, width vs height, to work out the ratio $configwidth = $width - (get_config_plugin('blocktype', 'gallery', 'photoframe') ? 8 : 0); // $width - photo frame padding $imagewidth = $image->get('width'); $imageheight = $image->get('height'); if ($imagewidth > $imageheight) { $ratio = $imagewidth / $configwidth; } else { $ratio = $imageheight / $configwidth; } $ratiowidth = floor($imagewidth / $ratio); $ratioheight = floor($imageheight / $ratio); // All image dimensions need to be bigger than 15px // see function imagesize_data_to_internal_form() $ratiowidth = $ratiowidth < 16 ? 16 : $ratiowidth; $ratioheight = $ratioheight < 16 ? 16 : $ratioheight; $topoffset = floor(($configwidth - $ratioheight) / 2); $src .= '&size=' . $ratiowidth . 'x' . $ratioheight; $height = $ratioheight; } else { $src .= '&maxwidth=' . $width; $imgwidth = $image->get('width'); $imgheight = $image->get('height'); $height = $imgwidth > $width ? intval($width / $imgwidth * $imgheight) : $imgheight; } $images[] = array('link' => $link, 'source' => $src, 'height' => $height, 'width' => !empty($ratiowidth) ? $ratiowidth : null, 'title' => $image->get('description'), 'slimbox2' => $slimbox2attr, 'squaredimensions' => $width, 'squaretop' => !empty($topoffset) ? $topoffset : null); } } $smarty = smarty_core(); $smarty->assign('instanceid', $instance->get('id')); $smarty->assign('count', count($images)); $smarty->assign('images', $images); $smarty->assign('showdescription', !empty($configdata['showdescription']) ? $configdata['showdescription'] : false); $smarty->assign('width', $width); if (isset($height)) { $smarty->assign('height', $height); } if (isset($needsapikey)) { $smarty->assign('needsapikey', $needsapikey); } $smarty->assign('frame', get_config_plugin('blocktype', 'gallery', 'photoframe')); $smarty->assign('copyright', $copyright); if (!empty($configdata['artefactid'])) { $artefact = $instance->get_artefact_instance($configdata['artefactid']); require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($configdata['viewid']); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); } return $smarty->fetch('blocktype:gallery:' . $template . '.tpl'); }
/** * Does a bulk_delete on a list of artefacts, grouping artefacts of * the same type. * * Currently only tested for folders and their contents. */ public static function delete_by_artefacttype($artefactids) { if (empty($artefactids)) { return; } db_begin(); artefact_watchlist_notification($artefactids); // Delete comments first safe_require('artefact', 'comment'); ArtefactTypeComment::delete_comments_onartefacts($artefactids); $records = get_records_select_assoc('artefact', 'id IN (' . join(',', array_map('intval', $artefactids)) . ')', null, 'artefacttype', 'id,parent,artefacttype,container'); $containers = array(); $leaves = array(); foreach ($records as $r) { if ($r->container) { $containers[$r->artefacttype][] = (int) $r->id; } else { $leaves[$r->artefacttype][] = $r->id; } } // Delete non-containers grouped by artefacttype foreach ($leaves as $artefacttype => $ids) { $classname = generate_artefact_class_name($artefacttype); call_static_method($classname, 'bulk_delete', $ids); } // Delete containers grouped by artefacttype foreach ($containers as $artefacttype => $ids) { $classname = generate_artefact_class_name($artefacttype); if (is_mysql()) { set_field_select('artefact', 'parent', null, 'id IN (' . join(',', $ids) . ')', array()); } call_static_method($classname, 'bulk_delete', $ids); } handle_event('deleteartefacts', $artefactids); db_commit(); }
// If the view is a group view check that the $USER can view it $author = $file->get('author'); $group = $file->get('group'); if (!empty($author) && !empty($group)) { if ($USER->can_view_artefact($file)) { $artefactok = true; } } // The user may be trying to download a file that's not in the view, but which has // been attached to public feedback on the view if ($commentid = param_integer('comment', null)) { if (!record_exists('artefact_attachment', 'artefact', $commentid, 'attachment', $fileid)) { throw new AccessDeniedException(''); } safe_require('artefact', 'comment'); $comment = new ArtefactTypeComment($commentid); if (!$comment->viewable_in($viewid)) { throw new AccessDeniedException(''); } } else { if ($artefactok == false) { throw new AccessDeniedException(''); } } if (!can_view_view($viewid)) { throw new AccessDeniedException(''); } if (!$file instanceof ArtefactTypeFile) { throw new NotFoundException(); } } else {
/** * * @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('PUBLIC', 1); define('JSON', 1); require dirname(dirname(dirname(__FILE__))) . '/init.php'; require_once get_config('libroot') . 'view.php'; require_once get_config('libroot') . 'pieforms/pieform.php'; safe_require('artefact', 'comment'); $extradata = json_decode(param_variable('extradata')); if (!can_view_view($extradata->view)) { json_reply('local', get_string('noaccesstoview', 'view')); } if (!empty($extradata->artefact) && !artefact_in_view($extradata->artefact, $extradata->view)) { json_reply('local', get_string('accessdenied', 'error')); } $limit = param_integer('limit', 10); $offset = param_integer('offset'); if (!empty($extradata->artefact)) { $artefact = artefact_instance_from_id($extradata->artefact); } $view = new View($extradata->view); $data = ArtefactTypeComment::get_comments($limit, $offset, null, $view, $artefact); json_reply(false, array('data' => $data));
function view_stats_table($limit, $offset) { $count = count_records_select('view', '(owner != 0 OR owner IS NULL) AND type != ?', array('dashboard')); $pagination = build_pagination(array('id' => 'stats_pagination', 'url' => get_config('wwwroot') . 'admin/statistics.php?type=views', 'jsonscript' => 'admin/statistics.json.php', 'datatable' => 'statistics_table', 'count' => $count, 'limit' => $limit, 'offset' => $offset)); $result = array('count' => $count, 'tablerows' => '', 'pagination' => $pagination['html'], 'pagination_js' => $pagination['javascript']); if ($count < 1) { return $result; } $viewdata = get_records_sql_assoc("SELECT\n v.id, v.title, v.owner, v.group, v.institution, v.visits,\n u.id AS userid, u.firstname, u.lastname,\n g.id AS groupid, g.name AS groupname,\n i.displayname AS institutionname\n FROM {view} v\n LEFT JOIN {usr} u ON v.owner = u.id\n LEFT JOIN {group} g ON v.group = g.id\n LEFT JOIN {institution} i ON v.institution = i.name\n WHERE (v.owner != 0 OR \"owner\" IS NULL) AND v.type != ?\n ORDER BY v.visits DESC, v.title, v.id", array('dashboard'), $offset, $limit); safe_require('artefact', 'comment'); $comments = ArtefactTypeComment::count_comments(array_keys($viewdata)); foreach ($viewdata as &$v) { if ($v->owner) { $v->ownername = display_name($v->owner); $v->ownerurl = 'user/view.php?id=' . $v->userid; } else { if ($v->group) { $v->ownername = $v->groupname; $v->ownerurl = 'group/view.php?id=' . $v->groupid; } else { if ($v->institution == 'mahara') { $v->ownername = get_config('sitename'); } else { if ($v->institution) { $v->ownername = $v->institutionname; } } } } $v->comments = isset($comments[$v->id]) ? (int) $comments[$v->id]->comments : 0; } $smarty = smarty_core(); $smarty->assign('data', $viewdata); $smarty->assign('offset', $offset); $result['tablerows'] = $smarty->fetch('admin/viewstats.tpl'); return $result; }