Example #1
0
function group_get_groupinfo_data($group)
{
    safe_require('artefact', 'file');
    safe_require('interaction', 'forum');
    $group->admins = group_get_admins(array($group->id));
    $group->settingsdescription = group_display_settings($group);
    if (get_config('allowgroupcategories')) {
        $group->categorytitle = $group->category ? get_field('group_category', 'title', 'id', $group->category) : '';
    }
    if (group_can_list_members($group, group_user_access($group->id))) {
        $group->membercount = count_records('group_member', 'group', $group->id);
    }
    $group->viewcount = count_records('view', 'group', $group->id);
    $group->filecounts = ArtefactTypeFileBase::count_user_files(null, $group->id, null);
    $group->forumcounts = PluginInteractionForum::count_group_forums($group->id);
    $group->topiccounts = PluginInteractionForum::count_group_topics($group->id);
    $group->postcounts = PluginInteractionForum::count_group_posts($group->id);
    return $group;
}
         set_field_select('interaction_forum_topic', 'sticky', 0, 'id IN (' . implode(',', $checked) . ')', array());
         $SESSION->add_ok_msg(get_string('topicunstickysuccess', 'interaction.forum'));
     } else {
         if ($moderator && $type == 'closed') {
             set_field_select('interaction_forum_topic', 'closed', 1, 'id IN (' . implode(',', $checked) . ')', array());
             $SESSION->add_ok_msg(get_string('topicclosedsuccess', 'interaction.forum'));
         } else {
             if ($moderator && $type == 'open') {
                 set_field_select('interaction_forum_topic', 'closed', 0, 'id IN (' . implode(',', $checked) . ')', array());
                 $SESSION->add_ok_msg(get_string('topicopenedsuccess', 'interaction.forum'));
             } else {
                 if ($type == 'subscribe' && !$forum->subscribed) {
                     db_begin();
                     foreach ($checked as $key => $value) {
                         if (!record_exists('interaction_forum_subscription_topic', 'user', $USER->get('id'), 'topic', $value)) {
                             insert_record('interaction_forum_subscription_topic', (object) array('user' => $USER->get('id'), 'topic' => $value, 'key' => PluginInteractionForum::generate_unsubscribe_key()));
                         }
                     }
                     db_commit();
                     $SESSION->add_ok_msg(get_string('topicsubscribesuccess', 'interaction.forum'));
                 } else {
                     if ($type == 'unsubscribe' && !$forum->subscribed) {
                         delete_records_sql('DELETE FROM {interaction_forum_subscription_topic}
         WHERE topic IN (' . implode(',', $checked) . ') AND "user" = ?', array($USER->get('id')));
                         $SESSION->add_ok_msg(get_string('topicunsubscribesuccess', 'interaction.forum'));
                     }
                 }
             }
         }
     }
 }
Example #3
0
function subscribe_topic_submit(Pieform $form, $values)
{
    global $USER;
    if ($values['type'] == 'subscribe') {
        insert_record('interaction_forum_subscription_topic', (object) array('topic' => $values['topic'], 'user' => $USER->get('id'), 'key' => PluginInteractionForum::generate_unsubscribe_key()));
    } else {
        delete_records('interaction_forum_subscription_topic', 'topic', $values['topic'], 'user', $USER->get('id'));
    }
    redirect('/interaction/forum/topic.php?id=' . $values['topic']);
}
function addpost_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    $parentid = param_integer('parent');
    $postid = insert_record('interaction_forum_post', (object) array('topic' => $values['topic'], 'poster' => $USER->get('id'), 'parent' => $parentid, 'subject' => $values['subject'], 'body' => $values['body'], 'ctime' => db_format_timestamp(time())), 'id', true);
    $delay = get_config_plugin('interaction', 'forum', 'postdelay');
    if (!is_null($delay) && $delay == 0) {
        PluginInteractionForum::interaction_forum_new_post(array($postid));
    }
    $SESSION->add_ok_msg(get_string('addpostsuccess', 'interaction.forum'));
    redirect('/interaction/forum/topic.php?id=' . $values['topic'] . '#post' . $postid);
}
Example #5
0
 public static function prepare_post_body($body, $postid)
 {
     self::$replacement_postid = $postid;
     return preg_replace_callback('#(?<=[\'"])' . get_config('wwwroot') . 'artefact/file/download\\.php\\?(file=\\d+(?:(?:&amp;|&)(?:[a-z]+=[x0-9]+)+)*)#', array('self', 'replace_download_link'), $body);
 }
Example #6
0
function edittopic_submit(Pieform $form, $values)
{
    global $SESSION, $USER, $topic;
    $topicid = param_integer('id');
    $returnto = param_alpha('returnto', 'topic');
    $groupid = get_field_sql("SELECT DISTINCT i.group FROM {interaction_instance} i\n                              INNER JOIN {interaction_forum_topic} t ON i.id = t.forum\n                              WHERE t.id =?", array($topicid));
    db_begin();
    // check the post content actually changed
    // otherwise topic could have been set as sticky/closed
    $postchanged = $values['subject'] != $topic->subject || $values['body'] != $topic->body;
    if ($postchanged) {
        $newbody = EmbeddedImage::prepare_embedded_images($values['body'], 'topic', $topicid, $groupid);
        update_record('interaction_forum_post', array('subject' => $values['subject'], 'body' => PluginInteractionForum::prepare_post_body($newbody, $values['post'])), array('id' => $values['post']));
    }
    if ($values['editrecord'] && $postchanged) {
        insert_record('interaction_forum_edit', (object) array('user' => $USER->get('id'), 'post' => $values['post'], 'ctime' => db_format_timestamp(time())));
    }
    if (isset($values['sticky'])) {
        update_record('interaction_forum_topic', array('sticky' => isset($values['sticky']) && $values['sticky'] == 1 ? 1 : 0, 'closed' => isset($values['closed']) && $values['closed'] == 1 ? 1 : 0), array('id' => $topicid));
    }
    db_commit();
    $SESSION->add_ok_msg(get_string('edittopicsuccess', 'interaction.forum'));
    if ($returnto == 'view') {
        redirect('/interaction/forum/view.php?id=' . $topic->forum);
    } else {
        redirect('/interaction/forum/topic.php?id=' . $topicid);
    }
}
        // they can view it
        $fileinloggedinmenu = $file->get('institution') == 'mahara';
        // check if users are allowed to access files in subfolders
        if (!get_config('sitefilesaccess')) {
            $fileinloggedinmenu = $fileinloggedinmenu && $file->get('parent') == null;
        }
        $fileinloggedinmenu = $fileinloggedinmenu && $USER->is_logged_in();
        $fileinloggedinmenu = $fileinloggedinmenu && record_exists('site_menu', 'file', $fileid, 'public', 0);
        if (!$fileinloggedinmenu) {
            // Alternatively, if you own the file or you are an admin, it should always work
            if (!$USER->can_view_artefact($file)) {
                // Check for images sitting in visible forum posts
                $visibleinpost = false;
                if ($postid && $file instanceof ArtefactTypeImage) {
                    safe_require('interaction', 'forum');
                    $visibleinpost = PluginInteractionForum::can_see_attached_file($file, $postid);
                }
                if (!$visibleinpost) {
                    throw new AccessDeniedException(get_string('accessdenied', 'error'));
                }
            }
        }
    }
}
$path = $file->get_path($size);
$title = $file->download_title();
if ($contenttype = $file->override_content_type()) {
    $options['overridecontenttype'] = $contenttype;
}
$options['owner'] = $file->get('owner');
serve_file($path, $title, $file->get('filetype'), $options);
 /**
  * When a user joins a group, subscribe them automatically to all forums 
  * that should be subscribable
  *
  * @param array $eventdata
  */
 public static function user_joined_group($event, $gm)
 {
     if ($forumids = get_column_sql("\n            SELECT ii.id\n            FROM {group} g\n            LEFT JOIN {interaction_instance} ii ON g.id = ii.group\n            LEFT JOIN {interaction_forum_instance_config} ific ON ific.forum = ii.id\n            WHERE \"group\" = ? AND ific.field = 'autosubscribe' and ific.value = '1'", array($gm['group']))) {
         db_begin();
         foreach ($forumids as $forumid) {
             insert_record('interaction_forum_subscription_forum', (object) array('forum' => $forumid, 'user' => $gm['member'], 'key' => PluginInteractionForum::generate_unsubscribe_key()));
         }
         db_commit();
     }
 }
Example #9
0
function addpost_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    require_once 'embeddedimage.php';
    $parentid = param_integer('parent');
    $post = (object) array('topic' => $values['topic'], 'poster' => $USER->get('id'), 'parent' => $parentid, 'subject' => $values['subject'], 'body' => $values['body'], 'ctime' => db_format_timestamp(time()));
    $sendnow = isset($values['sendnow']) && $values['sendnow'] ? 1 : 0;
    // See if the same content has been submitted in the last 5 seconds. If so, don't add this post.
    $oldpost = get_record_select('interaction_forum_post', 'topic = ? AND poster = ? AND parent = ? AND subject = ? AND body = ? AND ctime > ?', array($post->topic, $post->poster, $post->parent, $post->subject, $post->body, db_format_timestamp(time() - 5)), 'id');
    if ($oldpost) {
        redirect(get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'] . '&post=' . $oldpost->id);
    }
    $postrec = new stdClass();
    $postid = $postrec->id = insert_record('interaction_forum_post', $post, 'id', true);
    $postrec->path = get_field('interaction_forum_post', 'path', 'id', $parentid) . '/' . sprintf('%010d', $postrec->id);
    update_record('interaction_forum_post', $postrec);
    // Rewrite the post id into links in the body
    $groupid = get_groupid_from_postid($postid);
    $newbody = EmbeddedImage::prepare_embedded_images($post->body, 'post', $postid, $groupid);
    $newbody = PluginInteractionForum::prepare_post_body($newbody, $postid);
    if (!empty($newbody) && $newbody != $post->body) {
        set_field('interaction_forum_post', 'body', $newbody, 'id', $postid);
    }
    if ($sendnow == 0) {
        $delay = get_config_plugin('interaction', 'forum', 'postdelay');
    } else {
        $delay = 0;
    }
    if (!is_null($delay) && $delay == 0) {
        PluginInteractionForum::interaction_forum_new_post(array($postid));
    }
    $SESSION->add_ok_msg(get_string('addpostsuccess', 'interaction.forum'));
    if (is_using_probation() && $post->parent) {
        $parentposter = get_field('interaction_forum_post', 'poster', 'id', $post->parent);
        vouch_for_probationary_user($parentposter);
    }
    redirect(get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'] . '&post=' . $postid);
}
 /**
  * Generate sitemap(s) and an index
  *
  * @return bool
  */
 public function generate()
 {
     // check that the sitemaps directory exists and create it if it doesn't
     check_dir_exists($this->directory, true);
     // this is used by PluginInteractionForum::get_active_topics
     $USER = new User();
     // create a new sitemap
     $this->create_sitemap();
     // get a list of public groups
     $publicgroups = get_records_select_array('group', 'public = 1 AND deleted = 0');
     if (!empty($publicgroups)) {
         foreach ($publicgroups as $group) {
             if (isset($group->mtime) && $this->check_date($group->mtime)) {
                 // each group gets a url entry
                 $groupurl = group_homepage_url($group);
                 $groupurl = utf8_encode(htmlspecialchars($groupurl, ENT_QUOTES, 'UTF-8'));
                 $grouplastmod = format_date(strtotime($group->mtime), 'strftimew3cdate');
                 $this->add_url($groupurl, $grouplastmod);
             }
             // build a list of forums in each public group
             $forums = get_forum_list($group->id);
             $forumids = array();
             foreach ($forums as $forum) {
                 $forumids[] = $forum->id;
             }
             // active topics within the specified forums (public only)
             $activetopics = PluginInteractionForum::get_active_topics(0, 0, 0, $forumids);
             foreach ($activetopics['data'] as $topic) {
                 if (isset($topic->mtime) && $this->check_date($topic->mtime) || isset($topic->ctime) && $this->check_date($topic->ctime)) {
                     $forumurl = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $topic->id;
                     $forumurl = utf8_encode(htmlspecialchars($forumurl, ENT_QUOTES, 'UTF-8'));
                     // mtime will be set if the last post has been edited
                     if (isset($topic->mtime) && strtotime($topic->mtime) !== FALSE) {
                         $forumlastmod = format_date(strtotime($topic->mtime), 'strftimew3cdate');
                     } else {
                         $forumlastmod = format_date(strtotime($topic->ctime), 'strftimew3cdate');
                     }
                     $this->add_url($forumurl, $forumlastmod);
                 }
             }
         }
     }
     // views shared with the public
     // grouphomepage type views are handled above
     $types = array('portfolio');
     $views = View::view_search(null, null, null, null, null, 0, true, null, $types);
     if (!empty($views->data)) {
         foreach ($views->data as $view) {
             if (isset($view['mtime']) && $this->check_date($view['mtime'])) {
                 $viewurl = utf8_encode(htmlspecialchars($view['fullurl'], ENT_QUOTES, 'UTF-8'));
                 $viewlastmod = format_date(strtotime($view['mtime']), 'strftimew3cdate');
                 $this->add_url($viewurl, $viewlastmod);
             }
         }
     }
     // add the urlset and print the xml out
     // only if the urlset has any children
     if ($this->currenturlset->hasChildNodes()) {
         $this->save_sitemap(true);
     }
     return true;
 }
Example #11
0
/**
 *
 * @package    mahara
 * @subpackage core
 * @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', 'groups/topics');
require dirname(dirname(__FILE__)) . '/init.php';
require_once 'pieforms/pieform.php';
safe_require('interaction', 'forum');
require_once 'group.php';
define('TITLE', get_string('Topics', 'interaction.forum'));
if (!$USER->is_logged_in()) {
    throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$category = param_integer('category', 0);
$data = PluginInteractionForum::get_active_topics($limit, $offset, $category);
$pagination = build_pagination(array('id' => 'topics_pagination', 'url' => get_config('wwwroot') . 'group/topics.php' . ($category ? '?category=' . (int) $category : ''), 'jsonscript' => 'json/topics.php', 'datatable' => 'topiclist', 'count' => $data['count'], 'limit' => $limit, 'offset' => $offset));
$smarty = smarty(array('paginator'));
$smarty->assign_by_ref('topics', $data['data']);
$smarty->assign_by_ref('pagination', $pagination['html']);
$smarty->assign('INLINEJAVASCRIPT', 'addLoadEvent(function() { p = ' . $pagination['javascript'] . '});');
$smarty->assign('PAGEHEADING', TITLE);
$smarty->display('group/topics.tpl');
Example #12
0
/**
 * creates the group sideblock
 */
function group_sideblock()
{
    require_once 'group.php';
    $data['group'] = group_current_group();
    if (!$data['group']) {
        return null;
    }
    $data['menu'] = group_get_menu_tabs();
    // @todo either: remove this if interactions become group
    // artefacts, or: do this in interaction/lib.php if we leave them
    // as interactions
    $data['forums'] = get_records_select_array('interaction_instance', '"group" = ? AND deleted = ? AND plugin = ?', array(GROUP, 0, 'forum'), 'ctime', 'id, plugin, title');
    if (!$data['forums']) {
        $data['forums'] = array();
    } else {
        safe_require('interaction', 'forum');
        $data['forums'] = PluginInteractionForum::sideblock_sort($data['forums']);
    }
    return $data;
}
function addtopic_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    $forumid = param_integer('forum');
    db_begin();
    $topicid = insert_record('interaction_forum_topic', (object) array('forum' => $forumid, 'sticky' => isset($values['sticky']) && $values['sticky'] ? 1 : 0, 'closed' => isset($values['closed']) && $values['closed'] ? 1 : 0), 'id', true);
    $postid = insert_record('interaction_forum_post', (object) array('topic' => $topicid, 'poster' => $USER->get('id'), 'subject' => $values['subject'], 'body' => $values['body'], 'ctime' => db_format_timestamp(time())), 'id', true);
    if (!record_exists('interaction_forum_subscription_forum', 'user', $USER->get('id'), 'forum', $forumid)) {
        insert_record('interaction_forum_subscription_topic', (object) array('user' => $USER->get('id'), 'topic' => $topicid, 'key' => PluginInteractionForum::generate_unsubscribe_key()));
    }
    db_commit();
    $delay = get_config_plugin('interaction', 'forum', 'postdelay');
    if (!is_null($delay) && $delay == 0) {
        PluginInteractionForum::interaction_forum_new_post(array($postid));
    }
    $SESSION->add_ok_msg(get_string('addtopicsuccess', 'interaction.forum'));
    redirect('/interaction/forum/topic.php?id=' . $topicid);
}