Ejemplo n.º 1
0
function delete_blog_submit(Pieform $form, $values)
{
    global $SESSION;
    require_once 'embeddedimage.php';
    $blog = new ArtefactTypeBlog($values['delete']);
    $blog->check_permission();
    if ($blog->get('locked')) {
        $SESSION->add_error_msg(get_string('submittedforassessment', 'view'));
    } else {
        $blog->delete();
        EmbeddedImage::delete_embedded_images('blog', $blog->get('id'));
        $SESSION->add_ok_msg(get_string('blogdeleted', 'artefact.blog'));
    }
    redirect('/artefact/blog/index.php');
}
Ejemplo n.º 2
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');
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
        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);
}
if ($delete = param_integer('delete', null)) {
Ejemplo n.º 5
0
$js = <<<EOF
function publish_success(form, data) {
    removeElement('publish_' + data.id);
    \$('poststatus' + data.id).innerHTML = {$strpublished};
}
function delete_success(form, data) {
    addElementClass('postdetails_' + data.id, 'hidden');
    if (\$('postfiles_' + data.id)) {
        addElementClass('postfiles_' + data.id, 'hidden');
    }
    addElementClass('postdescription_' + data.id, 'hidden');
    addElementClass('posttitle_' + data.id, 'hidden');
}
EOF;
$smarty = smarty(array('paginator'));
$smarty->assign('PAGEHEADING', $blog->get('title'));
$smarty->assign('INLINEJAVASCRIPT', $js);
if (!$USER->get_account_preference('multipleblogs') && count_records('artefact', 'artefacttype', 'blog', 'owner', $USER->get('id')) == 1) {
    $smarty->assign('enablemultipleblogstext', 1);
}
$smarty->assign_by_ref('blog', $blog);
$smarty->assign_by_ref('posts', $posts);
$smarty->display('artefact:blog:view.tpl');
exit;
function publish_submit(Pieform $form, $values)
{
    $blogpost = new ArtefactTypeBlogPost((int) $values['publish']);
    $blogpost->check_permission();
    $blogpost->publish();
    $form->reply(PIEFORM_OK, array('message' => get_string('blogpostpublished', 'artefact.blog'), 'goto' => get_config('wwwroot') . 'artefact/blog/view/?id=' . $blogpost->get('parent'), 'id' => $values['publish']));
}
Ejemplo n.º 6
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];
 }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
0
define('INTERNAL', 1);
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'blog');
define('SECTION_PAGE', 'settings');
require dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php';
define('TITLE', get_string('blogsettings', 'artefact.blog'));
require_once 'pieforms/pieform.php';
require_once 'license.php';
safe_require('artefact', 'blog');
if (!PluginArtefactBlog::is_active()) {
    throw new AccessDeniedException(get_string('plugindisableduser', 'mahara', get_string('blog', 'artefact.blog')));
}
$id = param_integer('id');
$blog = new ArtefactTypeBlog($id);
$institution = $institutionname = $groupid = null;
if ($blog->get('institution')) {
    $institution = true;
    $institutionname = $blog->get('institution');
} else {
    if ($blog->get('group')) {
        $groupid = $blog->get('group');
    }
}
PluginArtefactBlog::set_blog_nav($institution, $institutionname, $groupid);
$blog->check_permission(true);
if ($blog->get('locked')) {
    throw new AccessDeniedException(get_string('submittedforassessment', 'view'));
}
$form = pieform(array('name' => 'editblog', 'method' => 'post', 'action' => '', 'plugintype' => 'artefact', 'pluginname' => 'blog', 'elements' => array('id' => array('type' => 'hidden', 'value' => $id), 'institution' => array('type' => 'hidden', 'value' => $institutionname ? $institutionname : 0), 'group' => array('type' => 'hidden', 'value' => $groupid ? $groupid : 0), 'title' => array('type' => 'text', 'title' => get_string('blogtitle', 'artefact.blog'), 'description' => get_string('blogtitledesc', 'artefact.blog'), 'rules' => array('required' => true), 'defaultvalue' => $blog->get('title')), 'description' => array('type' => 'wysiwyg', 'rows' => 10, 'cols' => 70, 'title' => get_string('blogdesc', 'artefact.blog'), 'description' => get_string('blogdescdesc', 'artefact.blog'), 'rules' => array('maxlength' => 65536, 'required' => false), 'defaultvalue' => $blog->get('description')), 'tags' => array('defaultvalue' => $blog->get('tags'), 'type' => 'tags', 'title' => get_string('tags'), 'description' => get_string('tagsdescprofile'), 'help' => true), 'license' => license_form_el_basic($blog), 'licensing_advanced' => license_form_el_advanced($blog), 'submit' => array('type' => 'submitcancel', 'class' => 'btn-primary', 'value' => array(get_string('savesettings', 'artefact.blog'), get_string('cancel', 'artefact.blog'))))));
$smarty = smarty();
if (!$institutionname && !$groupid) {
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
0
 * @copyright  (C) 2006-2009 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', 'settings');
require dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php';
define('TITLE', get_string('blogsettings', 'artefact.blog'));
require_once 'pieforms/pieform.php';
safe_require('artefact', 'blog');
$id = param_integer('id');
$blog = new ArtefactTypeBlog($id);
$blog->check_permission();
if ($blog->get('locked')) {
    throw new AccessDeniedException(get_string('submittedforassessment', 'view'));
}
$form = pieform(array('name' => 'editblog', 'method' => 'post', 'action' => '', 'plugintype' => 'artefact', 'pluginname' => 'blog', 'elements' => array('id' => array('type' => 'hidden', 'value' => $id), 'title' => array('type' => 'text', 'title' => get_string('blogtitle', 'artefact.blog'), 'description' => get_string('blogtitledesc', 'artefact.blog'), 'rules' => array('required' => true), 'defaultvalue' => $blog->get('title')), 'description' => array('type' => 'wysiwyg', 'rows' => 10, 'cols' => 70, 'title' => get_string('blogdesc', 'artefact.blog'), 'description' => get_string('blogdescdesc', 'artefact.blog'), 'rules' => array('required' => false), 'defaultvalue' => $blog->get('description')), 'tags' => array('defaultvalue' => $blog->get('tags'), 'type' => 'tags', 'title' => get_string('tags'), 'description' => get_string('tagsdescprofile'), 'help' => true), 'submit' => array('type' => 'submitcancel', 'value' => array(get_string('savesettings', 'artefact.blog'), get_string('cancel', 'artefact.blog'))))));
$smarty = smarty();
if (!$USER->get_account_preference('multipleblogs') && count_records('artefact', 'artefacttype', 'blog', 'owner', $USER->get('id')) == 1) {
    $smarty->assign('enablemultipleblogstext', 1);
}
$smarty->assign_by_ref('editform', $form);
$smarty->assign_by_ref('blog', $blog);
$smarty->assign('PAGEHEADING', TITLE);
$smarty->display('artefact:blog:settings.tpl');
exit;
/**
 * This function is called to update the blog details.
 */
Ejemplo n.º 11
0
    } 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();
    $smarty->display('admin/users/noinstitutions.tpl');
Ejemplo n.º 12
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());
    }
}
// If an image browser was already created and updated somehow, rebuild or submit the form now