Example #1
0
function delete_blog_submit(Pieform $form, $values)
{
    global $SESSION;
    $blog = new ArtefactTypeBlog($values['delete']);
    $blog->check_permission();
    if ($blog->get('locked')) {
        $SESSION->add_error_msg(get_string('submittedforassessment', 'view'));
    } else {
        $blog->delete();
        $SESSION->add_ok_msg(get_string('blogdeleted', 'artefact.blog'));
    }
    redirect('/artefact/blog/index.php');
}
Example #2
0
/**
 * This function is called to update the blog details.
 */
function editblog_submit(Pieform $form, $values)
{
    global $USER;
    if ($data = $form->get_element('institution')) {
        ArtefactTypeBlog::edit_blog($USER, $values);
        redirect('/artefact/blog/view/index.php?id=' . $values['id'] . '&institution=' . $data['value']);
    } else {
        ArtefactTypeBlog::edit_blog($USER, $values);
        redirect('/artefact/blog/view/index.php?id=' . $values['id']);
    }
}
Example #3
0
/**
 * This function gets called to submit the new blog.
 *
 * @param array
 */
function newblog_submit(Pieform $form, $values)
{
    global $USER;
    $data = $form->get_element('institution');
    if ($data['value'] != false) {
        ArtefactTypeBlog::new_blog(null, $values);
        redirect('/artefact/blog/index.php?institution=' . $data['value']);
    } else {
        ArtefactTypeBlog::new_blog($USER, $values);
        redirect('/artefact/blog/index.php');
    }
}
Example #4
0
function delete_blog_submit(Pieform $form, $values)
{
    global $SESSION;
    require_once 'embeddedimage.php';
    $blog = new ArtefactTypeBlog($values['delete']);
    $blog->check_permission();
    $institution = $blog->get('institution');
    $group = $blog->get('group');
    if ($blog->get('locked')) {
        $SESSION->add_error_msg(get_string('submittedforassessment', 'view'));
    } else {
        $blog->delete();
        $SESSION->add_ok_msg(get_string('blogdeleted', 'artefact.blog'));
    }
    if ($institution) {
        redirect('/artefact/blog/index.php?institution=' . $institution);
    } else {
        if ($group) {
            redirect('/artefact/blog/index.php?group=' . $group);
        }
    }
    redirect('/artefact/blog/index.php');
}
Example #5
0
/**
 * This function is called to update the blog details.
 */
function editblog_submit(Pieform $form, $values)
{
    global $USER;
    ArtefactTypeBlog::edit_blog($USER, $values);
    $institution = $form->get_element('institution');
    $group = $form->get_element('group');
    if (!empty($institution['value'])) {
        redirect('/artefact/blog/view/index.php?id=' . $values['id'] . '&institution=' . $institution['value']);
    } else {
        if (!empty($group['value'])) {
            redirect('/artefact/blog/view/index.php?id=' . $values['id'] . '&group=' . $group['value']);
        } else {
            redirect('/artefact/blog/view/index.php?id=' . $values['id']);
        }
    }
}
 * Copyright (C) 2006-2009 Catalyst IT Ltd and others; see:
 *                         http://wiki.mahara.org/Contributors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    mahara
 * @subpackage artefact-blog
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
 *
 */
define('INTERNAL', 1);
define('JSON', 1);
require dirname(dirname(dirname(__FILE__))) . '/init.php';
safe_require('artefact', 'blog');
$blogs = (object) array('offset' => param_integer('offset', 0), 'limit' => param_integer('limit', 10));
list($blogs->count, $blogs->data) = ArtefactTypeBlog::get_blog_list($blogs->limit, $blogs->offset);
ArtefactTypeBlog::build_blog_list_html($blogs);
json_reply(false, array('data' => $blogs));
require_once get_config('libroot') . 'pieforms/pieform.php';
if ($publish = param_integer('publish', null)) {
    ArtefactTypeBlogpost::publish_form($publish);
}
if ($delete = param_integer('delete', null)) {
    ArtefactTypeBlogpost::delete_form($delete);
}
$id = param_integer('id', null);
if (is_null($id)) {
    if (!($records = get_records_select_array('artefact', "artefacttype = 'blog' AND \"owner\" = ?", array($USER->get('id')), 'id ASC'))) {
        throw new ParameterException();
    }
    $id = $records[0]->id;
    $blog = new ArtefactTypeBlog($id, $records[0]);
} else {
    $blog = new ArtefactTypeBlog($id);
}
$blog->check_permission();
$limit = param_integer('limit', 5);
$offset = param_integer('offset', 0);
$posts = ArtefactTypeBlogPost::get_posts($id, $limit, $offset);
$template = 'artefact:blog:posts.tpl';
$pagination = array('baseurl' => get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $id, 'id' => 'blogpost_pagination', 'jsonscript' => 'artefact/blog/view/index.json.php', 'datatable' => 'postlist');
ArtefactTypeBlogPost::render_posts($posts, $template, array(), $pagination);
$strpublished = json_encode(get_string('published', 'artefact.blog'));
$js = <<<EOF
function publish_success(form, data) {
    removeElement('publish_' + data.id);
    \$('poststatus' + data.id).innerHTML = {$strpublished};
}
function delete_success(form, data) {
Example #8
0
 * @package    mahara
 * @subpackage artefact-blog
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
 *
 */
define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/blogs');
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'blog');
define('SECTION_PAGE', 'view');
require dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php';
define('TITLE', get_string('viewblog', 'artefact.blog'));
safe_require('artefact', 'blog');
$id = param_integer('id');
$blog = new ArtefactTypeBlog($id);
$blog->check_permission();
// This javascript is used to generate a list of blog posts.
$js = '';
if ($blog->count_children()) {
    $js = (require 'index.js.php');
}
$images = array('themepaths' => array('images/file.gif', 'images/image.gif'));
$smarty = smarty(array('tablerenderer'), array(), array(), $images);
$smarty->assign_by_ref('blog', $blog);
$smarty->assign_by_ref('editform', $form);
$smarty->assign_by_ref('INLINEJAVASCRIPT', $js);
$smarty->assign('heading', get_string('viewblog', 'artefact.blog') . ' - ' . $blog->get('title'));
$smarty->assign('strnopostsaddone', get_string('nopostsaddone', 'artefact.blog', '<a href="' . get_config('wwwroot') . 'artefact/blog/post.php?blog=' . $blog->get('id') . '">', '</a>'));
$smarty->display('artefact:blog:view.tpl');
$institution = param_alphanum('institution', 0);
$blogid = param_alphanum('blogid', 0);
$fileid = param_alphanum('selected', null);
$changebrowsetab = param_integer('imgbrowserconf_artefactid_changeowner', 0);
// Folder value is 0 when returning to Home folder
$changefolder = param_exists('imgbrowserconf_artefactid_changefolder') ? true : false;
$uploadimg = param_integer('imgbrowserconf_artefactid_upload', 0);
$formsubmit = param_exists('action_submitimage') ? true : false;
$formcancel = param_exists('cancel_action_submitimage') ? true : false;
if ($forumpostid && !$groupid) {
    $sql = "SELECT g.id\n                FROM {group} g\n                INNER JOIN {interaction_instance} ii ON ii.group = g.id\n                INNER JOIN {interaction_forum_topic} ift ON ift.forum = ii.id\n                INNER JOIN {interaction_forum_post} ifp ON ifp.topic = ift.id\n                WHERE ifp.id = ?\n                AND ifp.deleted = 0";
    $groupid = get_field_sql($sql, array($forumpostid));
}
if ($blogid) {
    safe_require('artefact', 'blog');
    $blogobj = new ArtefactTypeBlog($blogid);
    $institution = $blogobj->get('institution');
    $institution = !empty($institution) ? $institution : 0;
    $groupid = $blogobj->get('group');
    $groupid = !empty($groupid) ? $groupid : 0;
}
// Create new image browser
if ($change) {
    $ib = new ImageBrowser(array('view' => $viewid, 'post' => $forumpostid, 'group' => $groupid, 'institution' => $institution, 'selected' => $fileid));
    try {
        $returndata = $ib->render_image_browser();
        json_reply(false, array('data' => $returndata));
    } catch (Exception $e) {
        json_reply(true, $e->getMessage());
    }
}
function requiredfields_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    if (isset($values['password1'])) {
        $authobj = AuthFactory::create($USER->authinstance);
        // This method should exist, because if it did not then the change
        // password form would not have been shown.
        if ($password = $authobj->change_password($USER, $values['password1'])) {
            $SESSION->add_ok_msg(get_string('passwordsaved'));
        } else {
            throw new SystemException('Attempt by "' . $USER->get('username') . '@' . $USER->get('institution') . 'to change their password failed');
        }
    }
    if (isset($values['username'])) {
        $SESSION->set('resetusername', false);
        if ($values['username'] != $USER->get('username')) {
            $USER->username = $values['username'];
            $USER->commit();
            $otherfield = true;
        }
    }
    if (isset($values['state'])) {
        $current_app_name = explode(".", $_SERVER["HTTP_HOST"]);
        $current_app_short_name = $current_app_name[0];
        $current_app_short_name = str_replace("http://", "", $current_app_short_name);
        $current_app_short_name = str_replace("https://", "", $current_app_short_name);
        Doctrine_Query::create()->update('GcrUsers')->set('state', '?', $values['state'])->set('country', '?', $values['country'])->where('platform_short_name = ?', $current_app_short_name)->andWhere('user_id = ?', $USER->get('id'))->execute();
    }
    if (isset($values['socialprofile_hidden']) && $values['socialprofile_hidden']) {
        // Socialprofile fields. Save them on their own as they are a fieldset.
        set_profile_field($USER->get('id'), 'socialprofile', $values);
        $otherfield = true;
    }
    foreach ($values as $field => $value) {
        if (in_array($field, array('submit', 'sesskey', 'password1', 'password2', 'username', 'socialprofile_service', 'socialprofile_profiletype', 'socialprofile_profileurl', 'socialprofile_hidden', 'state', 'country'))) {
            continue;
        }
        if ($field == 'email') {
            $email = $values['email'];
            // Need to update the admin email on installation
            if ($USER->get('admin')) {
                $oldemail = get_field('usr', 'email', 'id', $USER->get('id'));
                if ($oldemail == '*****@*****.**') {
                    // we are dealing with the dummy email that is set on install
                    update_record('usr', array('email' => $email), array('id' => $USER->get('id')));
                    update_record('artefact_internal_profile_email', array('email' => $email), array('owner' => $USER->get('id')));
                }
            }
            // Check if a validation email has been sent, if not send one
            if (!record_exists('artefact_internal_profile_email', 'owner', $USER->get('id'))) {
                $key = get_random_key();
                $key_url = get_config('wwwroot') . 'artefact/internal/validate.php?email=' . rawurlencode($email) . '&key=' . $key;
                $key_url_decline = $key_url . '&decline=1';
                try {
                    $sitename = get_config('sitename');
                    email_user((object) array('id' => $USER->get('id'), 'username' => $USER->get('username'), 'firstname' => $USER->get('firstname'), 'lastname' => $USER->get('lastname'), 'preferredname' => $USER->get('preferredname'), 'admin' => $USER->get('admin'), 'staff' => $USER->get('staff'), 'email' => $email), null, get_string('emailvalidation_subject', 'artefact.internal'), get_string('emailvalidation_body1', 'artefact.internal', $USER->get('firstname'), $email, $sitename, $key_url, $sitename, $key_url_decline));
                } catch (EmailException $e) {
                    $SESSION->add_error_msg($email);
                }
                insert_record('artefact_internal_profile_email', (object) array('owner' => $USER->get('id'), 'email' => $email, 'verified' => 0, 'principal' => 1, 'key' => $key, 'expiry' => db_format_timestamp(time() + 86400)));
                $SESSION->add_ok_msg(get_string('validationemailsent', 'artefact.internal'));
            }
        } else {
            set_profile_field($USER->get('id'), $field, $value);
            $otherfield = true;
        }
    }
    if (isset($otherfield)) {
        $SESSION->add_ok_msg(get_string('requiredfieldsset', 'auth'));
    }
    // Update the title of user's first blog if first and/or last name have been changed
    $updatedfields = array_keys($values);
    if (in_array('firstname', $updatedfields) || in_array('lastname', $updatedfields)) {
        safe_require('artefact', 'blog');
        $userblogs = get_records_select_array('artefact', 'artefacttype = \'blog\' AND owner = ?', array($USER->get('id')));
        if ($userblogs && count($userblogs) == 1) {
            $defaultblog = new ArtefactTypeBlog($userblogs[0]->id);
            $defaultblog->set('title', get_string('defaultblogtitle', 'artefact.blog', display_name($USER, null, true)));
            $defaultblog->commit();
        }
    }
    redirect();
}
Example #11
0
        $institutionname = $institution;
        if (!$USER->get('admin')) {
            throw new AccessDeniedException();
        }
        $title = get_string('siteblogs', 'artefact.blog');
    } else {
        $s = institution_selector_for_page($institution, get_config('wwwroot') . 'artefact/blog/view/index.php');
        $institutionname = $s['institution'];
        if (!($USER->get('admin') || $USER->is_institutional_admin())) {
            throw new AccessDeniedException();
        }
        $title = get_string('institutionblogs', 'artefact.blog');
    }
} else {
    if ($id) {
        $blogobj = new ArtefactTypeBlog($id);
        $institution = $institutionname = $blogobj->get('institution');
        if ($institution != 'mahara') {
            $s = institution_selector_for_page($institution, get_config('wwwroot') . 'artefact/blog/view/index.php');
        }
    }
}
PluginArtefactBlog::set_blog_nav($institution, $institutionname);
if ($institutionname === false) {
    $smarty = smarty();
    $smarty->display('admin/users/noinstitutions.tpl');
    exit;
}
if ($changepoststatus = param_integer('changepoststatus', null)) {
    ArtefactTypeBlogpost::changepoststatus_form($changepoststatus);
}
Example #12
0
 /**
  * During the copying of a view, we might be allowed to copy
  * blogposts but not the containing blog.  We need to create a new
  * blog to hold the copied posts.
  */
 public function default_parent_for_copy(&$view, &$template, $artefactstoignore)
 {
     static $blogid;
     if (!empty($blogid)) {
         return $blogid;
     }
     $blogname = get_string('viewposts', 'artefact.blog', $view->get('id'));
     $data = (object) array('title' => $blogname, 'description' => get_string('postscopiedfromview', 'artefact.blog', $template->get('title')), 'owner' => $view->get('owner'), 'group' => $view->get('group'), 'institution' => $view->get('institution'));
     $blog = new ArtefactTypeBlog(0, $data);
     $blog->commit();
     $blogid = $blog->get('id');
     return $blogid;
 }
/**
 * This function is called to update the blog details.
 */
function editblog_submit(Pieform $form, $values)
{
    global $USER;
    ArtefactTypeBlog::edit_blog($USER, $values);
    redirect('/artefact/blog/view/?id=' . $values['id']);
}
Example #14
0
        $title = get_string('siteblogs', 'artefact.blog');
    } else {
        $s = institution_selector_for_page($institution, get_config('wwwroot') . 'artefact/blog/view/index.php');
        $institutionname = $s['institution'];
        if (!($USER->get('admin') || $USER->is_institutional_admin())) {
            throw new AccessDeniedException();
        }
        $title = get_string('institutionblogs', 'artefact.blog');
    }
} else {
    if ($groupid = param_alphanum('group', null)) {
        $group = get_record('group', 'id', $groupid, 'deleted', 0);
        $title = get_string('groupblogs', 'artefact.blog', $group->name);
    } else {
        if ($id) {
            $blogobj = new ArtefactTypeBlog($id);
            $institution = $institutionname = $blogobj->get('institution');
            $groupid = $blogobj->get('group');
            if ($groupid) {
                $group = get_record('group', 'id', $groupid, 'deleted', 0);
            }
            $title = get_string('viewbloggroup', 'artefact.blog', $blogobj->get('title'));
            if ($institution && $institution != 'mahara') {
                $s = institution_selector_for_page($institution, get_config('wwwroot') . 'artefact/blog/view/index.php');
            }
        }
    }
}
PluginArtefactBlog::set_blog_nav($institution, $institutionname, $groupid);
if ($institutionname === false) {
    $smarty = smarty();
Example #15
0
}
// OK - let's add tags
$tags_arr = array();
$tagsort = param_alpha('ts', null) != 'freq' ? 'alpha' : 'freq';
foreach (get_my_tags(null, false, $tagsort) as $tag) {
    $tags_arr[] = array("id" => $tag->tag, "tag" => $tag->tag);
}
if (count($tags_arr) > 0) {
    $json['tags'] = $tags_arr;
}
// OK - let's add journals (and journal posts)
$blogs_arr = array();
$blogs = (object) array('offset' => param_integer('offset', 0), 'limit' => param_integer('limit', 10));
$blogposts_arr = array();
$blogposts = array();
list($blogs->count, $blogs->data) = ArtefactTypeBlog::get_blog_list($blogs->limit, $blogs->offset);
foreach ($blogs->data as $blog) {
    if (!$blog->locked) {
        $blogs_arr[] = array("id" => $blog->id, "blog" => $blog->title);
        $blogposts = ArtefactTypeBlogpost::get_posts($blog->id, $blogs->limit, $blogs->offset, null);
        foreach ($blogposts['data'] as $blogpost) {
            if (!$blogpost->locked) {
                $blogposts_arr[] = array("id" => $blogpost->id, "blogpost" => $blogpost->title);
            }
        }
    }
}
if (count($blogs_arr) > 0) {
    $json['blogs'] = $blogs_arr;
}
if (count($blogposts_arr) > 0) {
Example #16
0
 public static function instance_config_form(BlockInstance $instance)
 {
     global $USER;
     safe_require('artefact', 'blog');
     $configdata = $instance->get('configdata');
     if (!empty($configdata['artefactid'])) {
         $blog = $instance->get_artefact_instance($configdata['artefactid']);
     }
     $elements = array();
     // If the blog post in this block is owned by the owner of the View,
     // then the block can be configured. Otherwise, the blog post was
     // copied in from another View. We won't confuse users by asking them to
     // choose a blog post to put in this block, when the one that is
     // currently in it isn't choosable.
     $institution = $instance->get('view_obj')->get('institution');
     $group = $instance->get('view_obj')->get('group');
     if (empty($configdata['artefactid']) || ArtefactTypeBlog::can_edit_blog($blog, $institution, $group)) {
         $sql = "SELECT a.id FROM {artefact} a\n                    INNER JOIN {artefact_blog_blogpost} p ON p.blogpost = a.id\n                    WHERE p.published = 1";
         if ($institution) {
             $sql .= " AND a.institution = ?";
             $where = array($institution);
         } else {
             if ($group) {
                 $sql .= " AND a.group = ?";
                 $where = array($group);
             } else {
                 $sql .= " AND a.owner = ?";
                 $where = array($USER->get('id'));
             }
         }
         $publishedposts = get_column_sql($sql, $where);
         $elements[] = self::artefactchooser_element(isset($configdata['artefactid']) ? $configdata['artefactid'] : null, $publishedposts);
         $elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'blogpost');
     } else {
         $elements[] = array('type' => 'html', 'name' => 'notice', 'value' => '<div class="metadata">' . get_string('blogcopiedfromanotherview', 'artefact.blog', get_string('blogpost', 'artefact.blog')) . '</div>');
     }
     return $elements;
 }
Example #17
0
 public static function instance_config_form(BlockInstance $instance)
 {
     global $USER;
     safe_require('artefact', 'blog');
     $configdata = $instance->get('configdata');
     require_once get_config('libroot') . 'view.php';
     $view = new View($instance->get('view'));
     $institution = $view->get('institution');
     $group = $view->get('group');
     if (!empty($configdata['artefactid'])) {
         $blog = $instance->get_artefact_instance($configdata['artefactid']);
     }
     $elements = array();
     // If the blog in this block is owned by the owner of the View, then
     // the block can be configured. Otherwise, the blog was copied in from
     // another View. We won't confuse users by asking them to choose a blog
     // to put in this block, when the one that is currently in it isn't
     // choosable.
     //
     // Note: the owner check will have to change when we do group/site
     // blogs
     if (empty($configdata['artefactid']) || ArtefactTypeBlog::can_edit_blog($blog, $institution, $group)) {
         $where = array('blog');
         $sql = "SELECT a.id FROM {artefact} a\n                    WHERE a.artefacttype = ?";
         if ($institution) {
             $sql .= " AND a.institution = ?";
             $where[] = $institution;
         } else {
             if ($group) {
                 $sql .= " AND a.group = ?";
                 $where[] = $group;
             } else {
                 $sql .= " AND a.owner = ?";
                 $where[] = $USER->get('id');
             }
         }
         $blogids = get_column_sql($sql, $where);
         $elements[] = self::artefactchooser_element(isset($configdata['artefactid']) ? $configdata['artefactid'] : null, $blogids);
         $elements['count'] = array('type' => 'text', 'title' => get_string('postsperpage', 'blocktype.blog/blog'), 'defaultvalue' => isset($configdata['count']) ? $configdata['count'] : 5, 'size' => 3);
         $elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'blog');
     } else {
         $elements[] = array('type' => 'html', 'name' => 'notice', 'value' => '<div class="metadata">' . get_string('blogcopiedfromanotherview', 'artefact.blog', get_string('Blog', 'artefact.blog')) . '</div>');
     }
     return $elements;
 }
Example #18
0
 /**
  * Creates a catch-all blog if one doesn't exist already
  *
  * @param PluginImportLeap $importer The importer
  * @return int The artefact ID of the catch-all blog
  */
 private static function ensure_catchall_blog(PluginImportLeap $importer)
 {
     static $blogid = null;
     if (is_null($blogid)) {
         $time = time();
         // TODO maybe the importer will get a time field to record time of import
         $blog = new ArtefactTypeBlog();
         $title = $importer->get('xml')->xpath('//a:feed/a:title');
         $blog->set('title', get_string('dataimportedfrom', 'artefact.blog', (string) $title[0]));
         $blog->set('description', get_string('entriesimportedfromleapexport', 'artefact.blog'));
         $blog->set('owner', $importer->get('usr'));
         $blog->set('ctime', $time);
         $blog->set('mtime', $time);
         $blog->commit();
         $blogid = $blog->get('id');
     }
     return $blogid;
 }
Example #19
0
function editpost_submit(Pieform $form, $values)
{
    global $USER, $SESSION, $blogpost, $blog;
    require_once 'embeddedimage.php';
    db_begin();
    $postobj = new ArtefactTypeBlogPost($blogpost, null);
    $postobj->set('title', $values['title']);
    $postobj->set('description', $values['description']);
    $postobj->set('tags', $values['tags']);
    if (get_config('licensemetadata')) {
        $postobj->set('license', $values['license']);
        $postobj->set('licensor', $values['licensor']);
        $postobj->set('licensorurl', $values['licensorurl']);
    }
    $postobj->set('published', !$values['draft']);
    $postobj->set('allowcomments', (int) $values['allowcomments']);
    if (!$blogpost) {
        $postobj->set('parent', $blog);
        $blogobj = new ArtefactTypeBlog($blog);
        if ($blogobj->get('institution')) {
            $postobj->set('institution', $blogobj->get('institution'));
        } else {
            if ($blogobj->get('group')) {
                $postobj->set('group', $blogobj->get('group'));
            } else {
                $postobj->set('owner', $USER->id);
            }
        }
    }
    $postobj->commit();
    $blogpost = $postobj->get('id');
    // Need to wait until post is saved in case we are a new blogpost before we can sort out embedded images as we need an id
    $postobj->set('description', EmbeddedImage::prepare_embedded_images($values['description'], 'blogpost', $postobj->get('id')));
    // Attachments
    $old = $postobj->attachment_id_list();
    // $new = is_array($values['filebrowser']['selected']) ? $values['filebrowser']['selected'] : array();
    $new = is_array($values['filebrowser']) ? $values['filebrowser'] : array();
    // only allow the attaching of files that exist and are editable by user
    foreach ($new as $key => $fileid) {
        $file = artefact_instance_from_id($fileid);
        if (!$file instanceof ArtefactTypeFile || !$USER->can_publish_artefact($file)) {
            unset($new[$key]);
        }
    }
    if (!empty($new) || !empty($old)) {
        foreach ($old as $o) {
            if (!in_array($o, $new)) {
                try {
                    $postobj->detach($o);
                } catch (ArtefactNotFoundException $e) {
                }
            }
        }
        foreach ($new as $n) {
            if (!in_array($n, $old)) {
                try {
                    $postobj->attach($n);
                } catch (ArtefactNotFoundException $e) {
                }
            }
        }
    }
    db_commit();
    $result = array('error' => false, 'message' => get_string('blogpostsaved', 'artefact.blog'), 'goto' => get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $blog);
    if ($form->submitted_by_js()) {
        // Redirect back to the blog page from within the iframe
        $SESSION->add_ok_msg($result['message']);
        $form->json_reply(PIEFORM_OK, $result, false);
    }
    $form->reply(PIEFORM_OK, $result);
}
Example #20
0
 /**
  * During the copying of a view, we might be allowed to copy
  * blogposts but not the containing blog.  We need to create a new
  * blog to hold the copied posts.
  */
 public function default_parent_for_copy(&$view, &$template, $artefactstoignore)
 {
     static $blogids;
     global $USER, $SESSION;
     $viewid = $view->get('id');
     if (isset($blogids[$viewid])) {
         return $blogids[$viewid];
     }
     $blogname = get_string('viewposts', 'artefact.blog', $viewid);
     $data = (object) array('title' => $blogname, 'description' => get_string('postscopiedfromview', 'artefact.blog', $template->get('title')), 'owner' => $view->get('owner'), 'group' => $view->get('group'), 'institution' => $view->get('institution'));
     $blog = new ArtefactTypeBlog(0, $data);
     $blog->commit();
     $blogids[$viewid] = $blog->get('id');
     if (!empty($data->group) || !empty($data->institution)) {
         $SESSION->add_ok_msg(get_string('copiedblogpoststonewjournal', 'collection'));
     } else {
         try {
             $user = get_user($view->get('owner'));
             set_account_preference($user->id, 'multipleblogs', 1);
             $SESSION->add_ok_msg(get_string('copiedblogpoststonewjournal', 'collection'));
         } catch (Exception $e) {
             $SESSION->add_error_msg(get_string('unabletosetmultipleblogs', 'error', $user->username, $viewid, get_config('wwwroot') . 'account/index.php'), false);
         }
         try {
             $USER->accountprefs = load_account_preferences($user->id);
         } catch (Exception $e) {
             $SESSION->add_error_msg(get_string('pleaseloginforjournals', 'error'));
         }
     }
     return $blogids[$viewid];
 }
Example #21
0
/**
 * This function gets called to submit the new blog.
 *
 * @param array
 */
function newblog_submit(Pieform $form, $values)
{
    global $USER;
    ArtefactTypeBlog::new_blog($USER, $values);
    redirect('/artefact/blog/');
}
Example #22
0
 *
 * @package    mahara
 * @subpackage artefact-blog
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
 *
 */
define('INTERNAL', 1);
define('JSON', 1);
require dirname(dirname(dirname(__FILE__))) . '/init.php';
safe_require('artefact', 'blog');
$action = param_variable('action', 'list');
$id = param_variable('id', null);
json_headers();
if ($action == 'list') {
    $limit = param_integer('limit', ArtefactTypeBlog::pagination);
    $offset = param_integer('offset', 0);
    list($count, $data) = ArtefactTypeBlog::get_blog_list($USER, $limit, $offset);
    echo json_encode(array('count' => $count, 'limit' => $limit, 'offset' => $offset, 'data' => $data));
} else {
    if ($action == 'delete') {
        $blog = artefact_instance_from_id($id);
        if ($blog instanceof ArtefactTypeBlog) {
            $blog->check_permission();
            $blog->delete();
            json_reply(false, get_string('blogdeleted', 'artefact.blog'));
        }
        throw new ArtefactNotFoundException(get_string('blogdoesnotexist', 'artefact.blog'));
    }
}