示例#1
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     require_once get_config('docroot') . 'artefact/lib.php';
     $smarty = smarty_core();
     $configdata = $instance->get('configdata');
     $data = array();
     // add in the selected email address
     if (!empty($configdata['email'])) {
         $configdata['artefactids'][] = $configdata['email'];
     }
     // Get data about the profile fields in this blockinstance
     if (!empty($configdata['artefactids'])) {
         $viewowner = get_field('view', 'owner', 'id', $instance->get('view'));
         foreach ($configdata['artefactids'] as $id) {
             try {
                 $artefact = artefact_instance_from_id($id);
                 if (is_a($artefact, 'ArtefactTypeProfile') && $artefact->get('owner') == $viewowner) {
                     $rendered = $artefact->render_self(array('link' => true));
                     $data[$artefact->get('artefacttype')] = $rendered['html'];
                 }
             } catch (ArtefactNotFoundException $e) {
                 log_debug('Artefact not found when rendering contactinfo block instance. ' . 'There might be a bug with deleting artefacts of this type? ' . 'Original error follows:');
                 log_debug($e->getMessage());
             }
         }
     }
     $smarty->assign('profileinfo', $data);
     return $smarty->fetch('blocktype:contactinfo:content.tpl');
 }
示例#2
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     global $exporter;
     require_once get_config('docroot') . 'artefact/lib.php';
     safe_require('artefact', 'plans');
     $configdata = $instance->get('configdata');
     $smarty = smarty_core();
     if (isset($configdata['artefactid'])) {
         $plan = artefact_instance_from_id($configdata['artefactid']);
         $tasks = ArtefactTypeTask::get_tasks($configdata['artefactid']);
         $template = 'artefact:plans:taskrows.tpl';
         $blockid = $instance->get('id');
         if ($exporter) {
             $pagination = false;
         } else {
             $baseurl = $instance->get_view()->get_url();
             $baseurl .= (false === strpos($baseurl, '?') ? '?' : '&') . 'block=' . $blockid;
             $pagination = array('baseurl' => $baseurl, 'id' => 'block' . $blockid . '_pagination', 'datatable' => 'tasktable_' . $blockid, 'jsonscript' => 'artefact/plans/viewtasks.json.php');
         }
         ArtefactTypeTask::render_tasks($tasks, $template, $configdata, $pagination);
         if ($exporter && $tasks['count'] > $tasks['limit']) {
             $artefacturl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $configdata['artefactid'] . '&view=' . $instance->get('view');
             $tasks['pagination'] = '<a href="' . $artefacturl . '">' . get_string('alltasks', 'artefact.plans') . '</a>';
         }
         $smarty->assign('owner', $plan->get('owner'));
         $smarty->assign('tags', $plan->get('tags'));
         $smarty->assign('tasks', $tasks);
     } else {
         $smarty->assign('noplans', 'blocktype.plans/plans');
     }
     $smarty->assign('blockid', $instance->get('id'));
     return $smarty->fetch('blocktype:plans:content.tpl');
 }
示例#3
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     global $exporter;
     require_once get_config('docroot') . 'artefact/lib.php';
     safe_require('artefact', 'cpds');
     $configdata = $instance->get('configdata');
     $smarty = smarty_core();
     if (isset($configdata['artefactid'])) {
         $cpd = artefact_instance_from_id($configdata['artefactid']);
         $activities = ArtefactTypeActivity::get_activities($configdata['artefactid']);
         $template = 'artefact:cpds:activityrows.tpl';
         $blockid = $instance->get('id');
         if ($exporter) {
             $pagination = false;
         } else {
             $pagination = array('baseurl' => $instance->get_view()->get_url() . '&block=' . $blockid, 'id' => 'block' . $blockid . '_pagination', 'datatable' => 'activitytable_' . $blockid, 'jsonscript' => 'artefact/cpds/viewactivities.json.php');
         }
         ArtefactTypeActivity::render_activities($activities, $template, $configdata, $pagination);
         if ($exporter && $activities['count'] > $activities['limit']) {
             $artefacturl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $configdata['artefactid'] . '&amp;view=' . $instance->get('view');
             $activities['pagination'] = '<a href="' . $artefacturl . '">' . get_string('allactivities', 'artefact.cpds') . '</a>';
         }
         $smarty->assign('description', $cpd->get('description'));
         $smarty->assign('activities', $activities);
         $smarty->assign('owner', $cpd->get('owner'));
         $smarty->assign('tags', $cpd->get('tags'));
     } else {
         $smarty->assign('nocpds', 'blocktype.cpds/cpds');
     }
     $smarty->assign('blockid', $instance->get('id'));
     return $smarty->fetch('blocktype:cpds:content.tpl');
 }
示例#4
0
文件: lib.php 项目: Br3nda/mahara
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     require_once get_config('docroot') . 'artefact/lib.php';
     $smarty = smarty_core();
     $configdata = $instance->get('configdata');
     $data = array();
     // add in the selected email address
     if (!empty($configdata['email'])) {
         $configdata['artefactids'][] = $configdata['email'];
     }
     // Get data about the profile fields in this blockinstance
     if (!empty($configdata['artefactids'])) {
         $viewowner = get_field('view', 'owner', 'id', $instance->get('view'));
         foreach ($configdata['artefactids'] as $id) {
             $artefact = artefact_instance_from_id($id);
             if ($artefact->get('owner') == $viewowner) {
                 $rendered = $artefact->render_self(array('link' => true));
                 $data[$artefact->get('artefacttype')] = $rendered['html'];
             }
         }
     }
     // Work out the path to the thumbnail for the profile image
     if (!empty($configdata['profileicon'])) {
         $downloadpath = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $configdata['profileicon'];
         $downloadpath .= '&maxwidth=80';
         $smarty->assign('profileiconpath', $downloadpath);
     }
     // Override the introduction text if the user has any for this
     // particular blockinstance
     if (!empty($configdata['introtext'])) {
         $data['introduction'] = $configdata['introtext'];
     }
     $smarty->assign('profileinfo', $data);
     return $smarty->fetch('blocktype:profileinfo:content.tpl');
 }
示例#5
0
 public function assign_smarty_vars()
 {
     $user = $this->get('exporter')->get('user');
     $userid = $user->get('id');
     $updated = get_record_sql('select ' . db_format_tsfield('max(mtime)', 'mtime') . ' from {artefact} a join {artefact_installed_type} t on a.artefacttype = t.name where t.plugin = \'internal\'');
     $this->smarty->assign('artefacttype', 'internal');
     $this->smarty->assign('artefactplugin', 'internal');
     $this->smarty->assign('title', display_name($user, $user));
     $this->smarty->assign('updated', PluginExportLeap::format_rfc3339_date($updated->mtime));
     // If this ID is changed, you'll have to change it in author.tpl too
     $this->smarty->assign('id', 'portfolio:artefactinternal');
     $this->smarty->assign('leaptype', $this->get_leap_type());
     $persondata = array();
     $spacialdata = array();
     usort($this->artefacts, array($this, 'artefact_sort'));
     foreach ($this->artefacts as $a) {
         if (!($data = $this->data_mapping($a))) {
             if ($a->get('artefacttype') == 'introduction') {
                 $this->smarty->assign('contenttype', 'html');
                 $this->smarty->assign('content', clean_html($a->get('title')));
             }
             continue;
         }
         $value = $a->render_self(array());
         $value = $value['html'];
         // TODO fix this when we non-js stuff
         $data = array_merge(array('value' => $value, 'artefacttype' => $a->get('artefacttype'), 'artefactplugin' => 'internal'), $data);
         if (array_key_exists('spacial', $data)) {
             $spacialdata[] = (object) $data;
         } else {
             $label = get_string($a->get('artefacttype'), 'artefact.internal');
             if ($a->get('artefacttype') == 'socialprofile') {
                 $label = $a->get('description');
             }
             $data = array_merge($data, array('label' => $label));
             $persondata[] = (object) $data;
         }
     }
     if ($extras = $this->exporter->get('extrapersondata')) {
         $persondata = array_merge($persondata, $extras);
     }
     $this->smarty->assign('persondata', $persondata);
     $this->smarty->assign('spacialdata', $spacialdata);
     // Grab profile icons and link to them, making sure the default is first
     if ($icons = get_column_sql("SELECT id\n            FROM {artefact}\n            WHERE artefacttype = 'profileicon'\n            AND \"owner\" = ?\n            ORDER BY id = (\n                SELECT profileicon FROM {usr} WHERE id = ?\n            ) DESC, id", array($userid, $userid))) {
         foreach ($icons as $icon) {
             $icon = artefact_instance_from_id($icon);
             $this->add_artefact_link($icon, 'related');
         }
         $this->smarty->assign('links', $this->links);
     }
     if (!($categories = $this->get_categories())) {
         $categories = array();
     }
     $this->smarty->assign('categories', $categories);
 }
示例#6
0
文件: lib.php 项目: Br3nda/mahara
 /**
  * Optional method. If exists, allows this class to decide the title for 
  * all blockinstances of this type
  */
 public static function get_instance_title(BlockInstance $bi)
 {
     $configdata = $bi->get('configdata');
     if (!empty($configdata['artefactid'])) {
         require_once get_config('docroot') . 'artefact/lib.php';
         $folder = artefact_instance_from_id($configdata['artefactid']);
         return $folder->get('title');
     }
     return '';
 }
示例#7
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     require_once get_config('docroot') . 'artefact/lib.php';
     $smarty = smarty_core();
     $configdata = $instance->get('configdata');
     $data = array();
     $data['socialprofiles'] = array();
     // add in the selected email address
     if (!empty($configdata['email'])) {
         $configdata['artefactids'][] = $configdata['email'];
     }
     $viewowner = get_field('view', 'owner', 'id', $instance->get('view'));
     // Get data about the profile fields in this blockinstance
     if (!empty($configdata['artefactids'])) {
         foreach ($configdata['artefactids'] as $id) {
             try {
                 $artefact = artefact_instance_from_id($id);
                 if (is_a($artefact, 'ArtefactTypeProfile') && $artefact->get('owner') == $viewowner) {
                     $rendered = $artefact->render_self(array('link' => true));
                     $artefacttype = $artefact->get('artefacttype');
                     if ($artefacttype == 'socialprofile') {
                         if (get_record('blocktype_installed', 'active', 1, 'name', 'socialprofile', 'artefactplugin', 'internal')) {
                             $data['socialprofiles'][] = array('link' => ArtefactTypeSocialprofile::get_profile_link($artefact->get('title'), $artefact->get('note')), 'title' => $artefact->get('title'), 'description' => $artefact->get('description'), 'note' => $artefact->get('note'));
                         }
                     } else {
                         $data[$artefacttype] = $rendered['html'];
                     }
                 }
             } catch (ArtefactNotFoundException $e) {
                 log_debug('Artefact not found when rendering a block instance. ' . 'There might be a bug with deleting artefacts of this type? ' . 'Original error follows:');
                 log_debug($e->getMessage());
             }
         }
         // Sort social profiles alphabetically (in ASC order)
         $description = array();
         foreach ($data['socialprofiles'] as $key => $row) {
             $description[$key] = $row['description'];
         }
         array_multisort($description, SORT_ASC, $data['socialprofiles']);
     }
     // Work out the path to the thumbnail for the profile image
     if (!empty($configdata['profileicon'])) {
         $downloadpath = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $configdata['profileicon'];
         $downloadpath .= '&maxwidth=80';
         $smarty->assign('profileiconpath', $downloadpath);
         $smarty->assign('profileiconalt', get_string('profileimagetext', 'mahara', display_default_name(get_user($viewowner))));
     }
     // Override the introduction text if the user has any for this
     // particular blockinstance
     if (!empty($configdata['introtext'])) {
         $data['introduction'] = $configdata['introtext'];
     }
     $smarty->assign('profileinfo', $data);
     return $smarty->fetch('blocktype:profileinfo:content.tpl');
 }
示例#8
0
文件: lib.php 项目: Br3nda/mahara
 public function add_links()
 {
     parent::add_links();
     // add on attachments
     if (!($attachments = $this->artefact->attachment_id_list())) {
         return;
     }
     foreach ($attachments as $attachment) {
         $f = artefact_instance_from_id($attachment);
         $this->add_artefact_link($f, 'has_attachment');
     }
 }
示例#9
0
文件: lib.php 项目: Br3nda/mahara
 public function add_links()
 {
     parent::add_links();
     // check for blog posts this file may be attached to
     if (!($posts = get_records_array('artefact_attachment', 'attachment', $this->artefact->get('id')))) {
         return;
     }
     foreach ($posts as $p) {
         $post = artefact_instance_from_id($p->artefact);
         $this->add_artefact_link($post, 'is_attachment_of');
     }
 }
示例#10
0
文件: index.php 项目: Br3nda/mahara
function import_submit(Pieform $form, $values)
{
    global $SESSION;
    $date = time();
    $nicedate = date('Y/m/d h:i:s', $date);
    $uploaddir = get_config('dataroot') . 'import/test-' . $date . '/';
    $filename = $uploaddir . $values['file']['name'];
    check_dir_exists($uploaddir);
    move_uploaded_file($values['file']['tmp_name'], $filename);
    if ($values['file']['type'] == 'application/zip') {
        // Unzip here
        $command = sprintf('%s %s %s %s', escapeshellcmd(get_config('pathtounzip')), escapeshellarg($filename), get_config('unzipdirarg'), escapeshellarg($uploaddir));
        $output = array();
        exec($command, $output, $returnvar);
        if ($returnvar != 0) {
            $SESSION->add_error_msg('Unable to unzip the file');
            redirect('/import/');
        }
        $filename = $uploaddir . 'leap2a.xml';
        if (!is_file($filename)) {
            $SESSION->add_error_msg('No leap2a.xml file detected - please check your export file again');
            redirect('/import/');
        }
    }
    // Create dummy user
    $user = (object) array('username' => 'import_' . $date, 'password' => 'import1', 'firstname' => 'Imported', 'lastname' => 'User (' . $nicedate . ')', 'email' => '*****@*****.**');
    $userid = create_user($user);
    // And we're good to go
    echo '<pre>';
    $filename = substr($filename, strlen(get_config('dataroot')));
    require_once dirname(dirname(__FILE__)) . '/import/lib.php';
    safe_require('import', 'leap');
    db_begin();
    $importer = PluginImport::create_importer(null, (object) array('token' => '', 'usr' => $userid, 'queue' => (int) (!PluginImport::import_immediately_allowed()), 'ready' => 0, 'expirytime' => db_format_timestamp(time() + 60 * 60 * 24), 'format' => 'leap', 'data' => array('filename' => $filename), 'loglevel' => PluginImportLeap::LOG_LEVEL_VERBOSE, 'logtargets' => LOG_TARGET_STDOUT, 'profile' => true));
    $importer->process();
    // Now done, delete the temporary e-mail address if there's a new one
    // A bit sucky, presumes only one email in the import
    $email = artefact_instance_from_id(get_field('artefact', 'id', 'title', '*****@*****.**', 'artefacttype', 'email', 'owner', $userid));
    $email->delete();
    execute_sql('UPDATE {artefact_internal_profile_email} SET principal = 1 WHERE "owner" = ?', array($userid));
    db_commit();
    echo "\n\n";
    echo 'Done. You can <a href="' . get_config('wwwroot') . '/admin/users/changeuser.php?id=' . $userid . '">change to this user</a> to inspect the result, ';
    echo 'or <a href="' . get_config('wwwroot') . 'import/">try importing again</a>';
    echo '</pre>';
    exit;
}
示例#11
0
文件: lib.php 项目: Br3nda/mahara
 public function dump_export_data()
 {
     if ($this->exporter->get('viewexportmode') == PluginExport::EXPORT_LIST_OF_VIEWS && $this->exporter->get('artefactexportmode') == PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS) {
         // Dont' care about resume in this case
         return;
     }
     $smarty = $this->exporter->get_smarty('../../', 'resume');
     $smarty->assign('page_heading', get_string('resumeofuser', 'artefact.resume', full_name($this->exporter->get('user'))));
     $smarty->assign('breadcrumbs', array(array('text' => get_string('resume', 'artefact.resume'), 'path' => 'index.html')));
     if ($artefacts = get_column_sql("SELECT id\n            FROM {artefact}\n            WHERE owner = ?\n            AND artefacttype IN\n            (SELECT name FROM {artefact_installed_type} WHERE plugin = 'resume')", array($this->exporter->get('user')->get('id')))) {
         foreach ($artefacts as $id) {
             $artefact = artefact_instance_from_id($id);
             $rendered = $artefact->render_self(array());
             $smarty->assign($artefact->get('artefacttype'), $rendered['html']);
         }
     }
     $content = $smarty->fetch('export:html/resume:index.tpl');
     if (false === file_put_contents($this->fileroot . 'index.html', $content)) {
         throw new SystemException("Unable to create index.html for resume");
     }
 }
示例#12
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     require_once get_config('docroot') . 'artefact/lib.php';
     $smarty = smarty_core();
     $configdata = $instance->get('configdata');
     $data = array();
     // add in the selected email address
     if (!empty($configdata['email'])) {
         $configdata['artefactids'][] = $configdata['email'];
     }
     // Get data about the profile fields in this blockinstance
     if (!empty($configdata['artefactids'])) {
         $viewowner = get_field('view', 'owner', 'id', $instance->get('view'));
         foreach ($configdata['artefactids'] as $id) {
             try {
                 $artefact = artefact_instance_from_id($id);
                 if (is_a($artefact, 'ArtefactTypeProfile') && $artefact->get('owner') == $viewowner) {
                     $rendered = $artefact->render_self(array('link' => true));
                     $data[$artefact->get('artefacttype')] = $rendered['html'];
                 }
             } catch (ArtefactNotFoundException $e) {
                 log_debug('Artefact not found when rendering a block instance. ' . 'There might be a bug with deleting artefacts of this type? ' . 'Original error follows:');
                 log_debug($e->getMessage());
             }
         }
     }
     // Work out the path to the thumbnail for the profile image
     if (!empty($configdata['profileicon'])) {
         $downloadpath = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $configdata['profileicon'];
         $downloadpath .= '&maxwidth=80';
         $smarty->assign('profileiconpath', $downloadpath);
     }
     // Override the introduction text if the user has any for this
     // particular blockinstance
     if (!empty($configdata['introtext'])) {
         $data['introduction'] = $configdata['introtext'];
     }
     $smarty->assign('profileinfo', $data);
     return $smarty->fetch('blocktype:profileinfo:content.tpl');
 }
示例#13
0
文件: lib.php 项目: Br3nda/mahara
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     require_once get_config('docroot') . 'artefact/lib.php';
     $smarty = smarty_core();
     $configdata = $instance->get('configdata');
     $data = array();
     // add in the selected email address
     if (!empty($configdata['email'])) {
         $configdata['artefactids'][] = $configdata['email'];
     }
     // Get data about the profile fields in this blockinstance
     if (!empty($configdata['artefactids'])) {
         $viewowner = get_field('view', 'owner', 'id', $instance->get('view'));
         foreach ($configdata['artefactids'] as $id) {
             $artefact = artefact_instance_from_id($id);
             if ($artefact->get('owner') == $viewowner) {
                 $rendered = $artefact->render_self(array('link' => true));
                 $data[$artefact->get('artefacttype')] = $rendered['html'];
             }
         }
     }
     $smarty->assign('profileinfo', $data);
     return $smarty->fetch('blocktype:contactinfo:content.tpl');
 }
示例#14
0
function editgoalsandskills_submit(Pieform $form, array $values)
{
    global $SESSION, $artefact, $USER;
    require_once 'embeddedimage.php';
    $newdescription = EmbeddedImage::prepare_embedded_images($values['description'], $values['artefacttype'], $USER->get('id'));
    db_begin();
    $artefact->set('title', get_string($values['artefacttype'], 'artefact.resume'));
    $artefact->set('description', $newdescription);
    $artefact->commit();
    // Attachments
    $old = $artefact->attachment_id_list();
    $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 {
                    $artefact->detach($o);
                } catch (ArtefactNotFoundException $e) {
                }
            }
        }
        foreach ($new as $n) {
            if (!in_array($n, $old)) {
                try {
                    $artefact->attach($n);
                } catch (ArtefactNotFoundException $e) {
                }
            }
        }
    }
    db_commit();
    $result = array('error' => false, 'message' => get_string('goalandskillsaved', 'artefact.resume'), 'goto' => get_config('wwwroot') . 'artefact/resume/goalsandskills.php');
    if ($form->submitted_by_js()) {
        // Redirect back to the resume goals and skills page from within the iframe
        $SESSION->add_ok_msg($result['message']);
        $form->json_reply(PIEFORM_OK, $result, false);
    }
    $form->reply(PIEFORM_OK, $result);
}
示例#15
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);
}
示例#16
0
 public function render_self($options)
 {
     $smarty = smarty_core();
     $smarty->assign('title', $this->get('title'));
     $smarty->assign('owner', $this->get('owner'));
     $smarty->assign('tags', $this->get('tags'));
     $smarty->assign('description', $this->get('description'));
     if (!empty($options['details']) and get_config('licensemetadata')) {
         $smarty->assign('license', render_license($this));
     } else {
         $smarty->assign('license', false);
     }
     $attachments = $this->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($options['viewid']) ? $options['viewid'] : 0);
             $attachment->downloadpath = get_config('wwwroot') . 'artefact/file/download.php?file=' . $attachment->id;
             if (isset($options['viewid'])) {
                 $attachment->downloadpath .= '&view=' . $options['viewid'];
             }
         }
         $smarty->assign('attachments', $attachments);
     }
     return array('html' => $smarty->fetch('artefact.tpl'), 'javascript' => '');
 }
示例#17
0
 /**
  * Format HTML content in a WYSIWYG text box to correctly serve an embedded image
  * which was added via the TinyMCE imagebrowser plugin.
  * Add a database reference to the embedded image if required, to set viewing permissions for it
  *
  * @param string $fieldvalue The HTML source of the text body added to the TinyMCE text editor
  * @param string $resourcetype The type of resource which the TinyMCE editor is used in, e.g. 'forum', 'topic', 'post' for forum text boxes
  * @param int $resourceid The id of the resourcetype
  * @param int $groupid The id of the group the resource is in if applicable
  * @return string The updated $fieldvalue
  */
 public static function prepare_embedded_images($fieldvalue, $resourcetype, $resourceid, $groupid = NULL)
 {
     if (empty($fieldvalue) || empty($resourcetype) || empty($resourceid)) {
         return $fieldvalue;
     }
     global $USER;
     $dom = new DOMDocument();
     $dom->encoding = 'utf-8';
     $oldval = libxml_use_internal_errors(true);
     $success = $dom->loadHTML(utf8_decode($fieldvalue));
     libxml_use_internal_errors($oldval);
     if ($success) {
         $publicimages = array();
         $xpath = new DOMXPath($dom);
         $srcstart = get_config('wwwroot') . 'artefact/file/download.php?';
         $query = '//img[starts-with(@src,"' . $srcstart . '")]';
         $images = $xpath->query($query);
         if (!$images->length) {
             self::remove_embedded_images($resourcetype, $resourceid);
             return $fieldvalue;
         }
         foreach ($images as $image) {
             // is this user allowed to publish this image?
             $imgsrc = $image->getAttribute('src');
             $searchpattern = '`file=(\\d+)`';
             $foundmatch = preg_match_all($searchpattern, $imgsrc, $matches);
             if ($foundmatch) {
                 foreach ($matches[1] as $imgid) {
                     $file = artefact_instance_from_id($imgid);
                     if (!$file instanceof ArtefactTypeImage || !$USER->can_publish_artefact($file)) {
                         return $fieldvalue;
                     } else {
                         $publicimages[] = $imgid;
                         $imgispublic = get_field('artefact_file_embedded', 'id', 'fileid', $imgid, 'resourcetype', $resourcetype, 'resourceid', $resourceid);
                         // add to embedded_images table for public access, specifiying context
                         if (!$imgispublic) {
                             insert_record('artefact_file_embedded', (object) array('fileid' => $imgid, 'resourcetype' => $resourcetype, 'resourceid' => $resourceid));
                         }
                     }
                 }
             }
             // rewrite to include group value and resource value
             // if user has group access, he or she will have access to view forum-based content
             $imgnode = $dom->createElement("img");
             $imgnode->setAttribute('width', $image->getAttribute('width'));
             $imgnode->setAttribute('height', $image->getAttribute('height'));
             $imgnode->setAttribute('style', $image->getAttribute('style'));
             $imgnode->setAttribute('alt', $image->getAttribute('alt'));
             if (!empty($groupid)) {
                 $searchpattern = '`group=(\\d+)`';
                 $foundmatch = preg_match_all($searchpattern, $imgsrc, $matches);
                 if (!$foundmatch) {
                     $imgsrc = $imgsrc . '&group=' . $groupid;
                     $imgnode->setAttribute('src', $imgsrc);
                 } else {
                     // check that the group value hasn't been spoofed
                     foreach ($matches[1] as $index => $grpid) {
                         if ($matches[1][$index] != $groupid) {
                             $imgsrc = str_replace('group=' . $matches[1][$index], 'group=' . $groupid, $imgsrc);
                         }
                     }
                     $imgnode->setAttribute('src', $imgsrc);
                 }
             }
             $searchpattern = '`' . $resourcetype . '=(\\d+)`';
             $foundmatch = preg_match_all($searchpattern, $imgsrc, $matches);
             if (!$foundmatch) {
                 $imgnode->setAttribute('src', $imgsrc . '&' . $resourcetype . '=' . $resourceid);
             } else {
                 // check that the resourceid hasn't been spoofed
                 foreach ($matches[1] as $index => $rsrcid) {
                     if ($matches[1][$index] != $resourceid) {
                         $imgsrc = str_replace($resourcetype . '=' . $matches[1][$index], $resourcetype . '=' . $resourceid, $imgsrc);
                     }
                 }
                 $imgnode->setAttribute('src', $imgsrc);
             }
             $image->parentNode->replaceChild($imgnode, $image);
         }
         self::remove_embedded_images($resourcetype, $resourceid, $publicimages);
         // we only want the fragments inside the body tag created by new DOMDocument
         $childnodes = $dom->getElementsByTagName('body')->item(0)->childNodes;
         $dummydom = new DOMDocument();
         foreach ($childnodes as $child) {
             $dummydom->appendChild($dummydom->importNode($child, true));
         }
         $fieldvalue = html_entity_decode($dummydom->saveHTML(), ENT_QUOTES, 'UTF-8');
         return $fieldvalue;
     }
 }
示例#18
0
/**
 * Deletes a user
 *
 * This function ensures that a user is deleted according to how Mahara wants a 
 * deleted user to be. You can call it multiple times on the same user without 
 * harm.
 *
 * @param int $userid The ID of the user to delete
 */
function delete_user($userid)
{
    db_begin();
    // We want to append 'deleted.timestamp' to some unique fields in the usr
    // table, so they can be reused by new accounts
    $fieldstomunge = array('username', 'email');
    $datasuffix = '.deleted.' . time();
    $user = get_record('usr', 'id', $userid, null, null, null, null, implode(', ', $fieldstomunge));
    $deleterec = new StdClass();
    $deleterec->id = $userid;
    $deleterec->deleted = 1;
    foreach ($fieldstomunge as $field) {
        if (!preg_match('/\\.deleted\\.\\d+$/', $user->{$field})) {
            $deleterec->{$field} = $user->{$field} . $datasuffix;
        }
    }
    // Set authinstance to default internal, otherwise the old authinstance can be blocked from deletion
    // by deleted users.
    $authinst = get_field('auth_instance', 'id', 'institution', 'mahara', 'authname', 'internal');
    if ($authinst) {
        $deleterec->authinstance = $authinst;
    }
    update_record('usr', $deleterec);
    // Remove user from any groups they're in, invited to or want to be in
    $groupids = get_column('group_member', '"group"', 'member', $userid);
    if ($groupids) {
        require_once get_config('libroot') . 'group.php';
        foreach ($groupids as $groupid) {
            group_remove_user($groupid, $userid, true);
        }
    }
    delete_records('group_member_request', 'member', $userid);
    delete_records('group_member_invite', 'member', $userid);
    // Remove any friend relationships the user is in
    execute_sql('DELETE FROM {usr_friend}
        WHERE usr1 = ?
        OR usr2 = ?', array($userid, $userid));
    execute_sql('DELETE FROM {usr_friend_request}
        WHERE owner = ?
        OR requester = ?', array($userid, $userid));
    delete_records('artefact_access_usr', 'usr', $userid);
    delete_records('auth_remote_user', 'localusr', $userid);
    delete_records('import_queue', 'usr', $userid);
    delete_records('usr_account_preference', 'usr', $userid);
    delete_records('usr_activity_preference', 'usr', $userid);
    delete_records('usr_infectedupload', 'usr', $userid);
    delete_records('usr_institution', 'usr', $userid);
    delete_records('usr_institution_request', 'usr', $userid);
    delete_records('usr_password_request', 'usr', $userid);
    delete_records('usr_watchlist_view', 'usr', $userid);
    delete_records('view_access', 'usr', $userid);
    // Remove the user's views & artefacts
    $viewids = get_column('view', 'id', 'owner', $userid);
    if ($viewids) {
        require_once get_config('libroot') . 'view.php';
        foreach ($viewids as $viewid) {
            $view = new View($viewid);
            $view->delete();
        }
    }
    $artefactids = get_column('artefact', 'id', 'owner', $userid);
    // @todo: test all artefact bulk_delete stuff, then replace the one-by-one
    // artefact deletion below with ArtefactType::delete_by_artefacttype($artefactids);
    if ($artefactids) {
        foreach ($artefactids as $artefactid) {
            try {
                $a = artefact_instance_from_id($artefactid);
                $a->delete();
            } catch (ArtefactNotFoundException $e) {
                // Awesome, it's already gone.
            }
        }
    }
    db_commit();
    handle_event('deleteuser', $userid);
}
示例#19
0
文件: lib.php 项目: Br3nda/mahara
 /**
  * Creates a file artefact based on the given entry.
  *
  * @param SimpleXMLElement $entry The entry to base the file's data on
  * @param PluginImport $importer  The importer
  * @param int $parent             The ID of the parent artefact for this file
  * @throws ImportException If the given entry is not detected as being a file
  * @return ArtefactTypeFile The file artefact created
  */
 public static function create_file(SimpleXMLElement $entry, PluginImport $importer, $parent = null)
 {
     if (!self::is_file($entry, $importer)) {
         throw new ImportException($importer, "create_file(): Cannot create a file artefact from an entry we don't recognise as a file");
     }
     // TODO: make sure there's no arbitrary file inclusion
     // TODO: the src attribute must be an IRI, according to the ATOM spec.
     // This means that it could have UTF8 characters in it, and the PHP
     // documentation doesn't sound hopeful that urldecode will work with
     // UTF8 characters
     $pathname = urldecode((string) $entry->content['src']);
     // TODO: might want to make it easier to get at the directory where the import files are
     $data = $importer->get('data');
     $dir = dirname($data['filename']);
     // Note: this data is passed (eventually) to ArtefactType->__construct,
     // which calls strtotime on the dates for us
     $data = (object) array('title' => (string) $entry->title, 'owner' => $importer->get('usr'), 'filetype' => (string) $entry->content['type']);
     if (isset($entry->summary)) {
         $data->description = (string) $entry->summary;
     }
     if ($published = strtotime((string) $entry->published)) {
         $data->ctime = (string) $entry->published;
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $data->mtime = (string) $entry->updated;
     }
     if ($parent) {
         $data->parent = $parent;
     }
     $pathname = $dir . DIRECTORY_SEPARATOR . $pathname;
     // This API sucks, but that's not my problem
     if (!($id = ArtefactTypeFile::save_file($pathname, $data, $importer->get('usrobj')))) {
         throw new ImportException($importer, 'TODO: get_string: was unable to import file');
     }
     // Work out if the file was really a profile icon
     $isprofileicon = false;
     $match = $entry->xpath('mahara:artefactplugin[@mahara:plugin="file" and @mahara:type="profileicon"]');
     if (count($match) == 1) {
         $isprofileicon = true;
     }
     $artefact = artefact_instance_from_id($id);
     // Work around that save_file doesn't let us set the mtime
     $artefact->set('mtime', strtotime((string) $entry->updated));
     if ($isprofileicon) {
         $artefact->set('artefacttype', 'profileicon');
         $artefact->set('parent', null);
         // Sadly the process for creating a profile icon is a bit dumb. To
         // be honest, it shouldn't even be a separate artefact type
         $basedir = get_config('dataroot') . 'artefact/file/';
         $olddir = 'originals/' . $id % 256 . '/';
         $newdir = 'profileicons/originals/' . $id % 256 . '/';
         check_dir_exists($basedir . $newdir);
         if (!rename($basedir . $olddir . $id, $basedir . $newdir . $id)) {
             throw new ImportException($importer, 'TODO: get_string: was unable to move profile icon');
         }
         // Unconditionally set as default, even if there is more than one
         $importer->get('usrobj')->profileicon = $id;
         $importer->get('usrobj')->commit();
     }
     $artefact->commit();
     return $artefact;
 }
示例#20
0
 public static function instance_config_validate($form, $values)
 {
     global $USER;
     if (!empty($values['images'])) {
         foreach ($values['images'] as $id) {
             $image = new ArtefactTypeImage($id);
             if (!$image instanceof ArtefactTypeImage || !$USER->can_view_artefact($image)) {
                 $result['message'] = get_string('unrecoverableerror', 'error');
                 $form->set_error(null, $result['message']);
                 $form->reply(PIEFORM_ERR, $result);
             }
         }
     }
     if (!empty($values['folder'])) {
         $folder = artefact_instance_from_id($values['folder']);
         if (!$folder instanceof ArtefactTypeFolder || !$USER->can_view_artefact($folder)) {
             $result['message'] = get_string('unrecoverableerror', 'error');
             $form->set_error(null, $result['message']);
             $form->reply(PIEFORM_ERR, $result);
         }
     }
 }
示例#21
0
文件: lib.php 项目: rboyatt/mahara
 /**
  * @param array $data Parameters:
  *                    - viewid (int)
  *                    - annotationid (int)
  */
 public function __construct($data, $cron = false)
 {
     parent::__construct($data, $cron);
     $annotation = new ArtefactTypeAnnotation($this->annotationid);
     $annotationfeedback = new ArtefactTypeAnnotationfeedback($this->annotationfeedbackid);
     $this->overridemessagecontents = true;
     if ($onartefact = $annotation->get('artefact')) {
         // 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 {
         if ($onview = $annotation->get('view')) {
             // Feedback on view.
             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;
             }
         } else {
             // Something is wrong.
             throw new ViewNotFoundException(get_string('invalidannotationfeedbacklinkerror', 'artefact.annotation'));
         }
     }
     // 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';
             $sql = "SELECT u.*\n                    FROM {usr} u, {group_member} m, {group} g\n                    WHERE g.id = m.group\n                    AND m.member = u.id\n                    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                        )";
             $this->users = get_records_sql_array($sql, 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 = $annotationfeedback->get('description');
     $posttime = strftime(get_string('strftimedaydatetime'), $annotationfeedback->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 = $annotationfeedback->get('deletedby')) {
         $this->strings = (object) array('subject' => (object) array('key' => 'annotationfeedbackdeletednotificationsubject', 'section' => 'artefact.annotation', 'args' => array($title)));
         $deletedmessage = ArtefactTypeAnnotationfeedback::deleted_by_types_description();
         $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.annotation');
         $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.annotation');
             $this->users[$key]->htmlmessage = get_string_from_language($lang, 'annotationfeedbackdeletedhtml', 'artefact.annotation', hsc($title), $removedbyline, clean_html($body), get_config('wwwroot') . $this->url, hsc($title));
             $this->users[$key]->emailmessage = get_string_from_language($lang, 'annotationfeedbackdeletedtext', 'artefact.annotation', $title, $removedbyline, trim(html2text(htmlspecialchars($body))), $title, get_config('wwwroot') . $this->url);
         }
         return;
     }
     $this->strings = (object) array('subject' => (object) array('key' => 'newannotationfeedbacknotificationsubject', 'section' => 'artefact.annotation', 'args' => array($title)));
     $this->url .= '&showcomment=' . $annotationfeedback->get('id');
     // Email
     $author = $annotationfeedback->get('author');
     foreach ($this->users as $key => $user) {
         $authorname = empty($author) ? $annotationfeedback->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, 'annotationfeedbacknotificationhtml', 'artefact.annotation', hsc($authorname), hsc($title), $posttime, clean_html($body), get_config('wwwroot') . $this->url);
         $this->users[$key]->emailmessage = get_string_from_language($lang, 'annotationfeedbacknotificationtext', 'artefact.annotation', $authorname, $title, $posttime, trim(html2text(htmlspecialchars($body))), get_config('wwwroot') . $this->url);
     }
 }
示例#22
0
 /**
  * @param array $data Parameters:
  *                    - message (string)
  *                    - view (int)
  *                    - artefact (int) (optional)
  *                    - reporter (int)
  *                    - ctime (int) (optional)
  */
 function __construct($data, $cron = false)
 {
     parent::__construct($data, $cron);
     require_once 'view.php';
     $this->view = new View($this->view);
     if (!empty($this->artefact)) {
         require_once get_config('docroot') . 'artefact/lib.php';
         $this->artefact = artefact_instance_from_id($this->artefact);
     }
     if ($owner = $this->view->get('owner')) {
         // Notify institutional admins of the view owner
         if ($institutions = get_column('usr_institution', 'institution', 'usr', $owner)) {
             $this->users = activity_get_users($this->get_id(), null, null, null, $institutions);
         }
     }
     if (empty($this->artefact)) {
         $this->url = $this->view->get_url(false);
     } else {
         $this->url = 'artefact/artefact.php?artefact=' . $this->artefact->get('id') . '&view=' . $this->view->get('id');
     }
     if (empty($this->strings->subject)) {
         $this->overridemessagecontents = true;
         $viewtitle = $this->view->get('title');
         $this->strings = new stdClass();
         if (empty($this->artefact)) {
             $this->strings->subject = (object) array('key' => 'objectionablecontentview', 'section' => 'activity', 'args' => array($viewtitle, display_default_name($this->reporter)));
         } else {
             $title = $this->artefact->get('title');
             $this->strings->subject = (object) array('key' => 'objectionablecontentviewartefact', 'section' => 'activity', 'args' => array($viewtitle, $title, display_default_name($this->reporter)));
         }
     }
 }
示例#23
0
文件: upgrade.php 项目: Br3nda/mahara
function xmldb_artefact_file_upgrade($oldversion = 0)
{
    $status = true;
    if ($oldversion < 2007010900) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('adminfiles');
        $field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, null, null, 0);
        add_field($table, $field);
        set_field('artefact_file_files', 'adminfiles', 0);
        // Put all folders into artefact_file_files
        $folders = get_column_sql("\n            SELECT a.id\n            FROM {artefact} a\n            LEFT OUTER JOIN {artefact_file_files} f ON a.id = f.artefact\n            WHERE a.artefacttype = 'folder' AND f.artefact IS NULL");
        if ($folders) {
            foreach ($folders as $folderid) {
                $data = (object) array('artefact' => $folderid, 'adminfiles' => 0);
                insert_record('artefact_file_files', $data);
            }
        }
    }
    if ($oldversion < 2007011800) {
        // Make sure the default quota is set
        set_config_plugin('artefact', 'file', 'defaultquota', 10485760);
    }
    if ($oldversion < 2007011801) {
        // Create image table
        $table = new XMLDBTable('artefact_file_image');
        $table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $table->addFieldInfo('width', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $table->addFieldInfo('height', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null);
        $table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id'));
        $status = $status && create_table($table);
        $images = get_column('artefact', 'id', 'artefacttype', 'image');
        log_debug(count($images));
        require_once get_config('docroot') . 'artefact/lib.php';
        foreach ($images as $imageid) {
            $image = artefact_instance_from_id($imageid);
            $path = $image->get_path();
            $image->set('dirty', false);
            $data = new StdClass();
            $data->artefact = $imageid;
            if (file_exists($path)) {
                list($data->width, $data->height) = getimagesize($path);
            }
            if (empty($data->width) || empty($data->height)) {
                $data->width = 0;
                $data->height = 0;
            }
            insert_record('artefact_file_image', $data);
        }
    }
    if ($oldversion < 2007013100) {
        // Add new tables for file/mime types
        $table = new XMLDBTable('artefact_file_file_types');
        $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('description'));
        create_table($table);
        $table = new XMLDBTable('artefact_file_mime_types');
        $table->addFieldInfo('mimetype', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('mimetype'));
        $table->addKeyInfo('descriptionfk', XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
        create_table($table);
        safe_require('artefact', 'file');
        PluginArtefactFile::resync_filetype_list();
    }
    if ($oldversion < 2007021400) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('oldextension');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);
    }
    if ($oldversion < 2007042500) {
        // migrate everything we had to change to  make mysql happy
        execute_sql("ALTER TABLE {artefact_file_file_types} ALTER COLUMN description TYPE varchar(32)");
        execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN mimetype TYPE varchar(128)");
        execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN description TYPE varchar(32)");
    }
    if ($oldversion < 2008091100) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('fileid');
        $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null);
        add_field($table, $field);
        execute_sql("UPDATE {artefact_file_files} SET fileid = artefact WHERE NOT size IS NULL");
    }
    if ($oldversion < 2008101602) {
        $table = new XMLDBTable('artefact_file_files');
        $field = new XMLDBField('filetype');
        $field->setAttributes(XMLDB_TYPE_TEXT);
        add_field($table, $field);
        // Guess mime type for existing files
        $fileartefacts = get_records_sql_array('
            SELECT
                a.artefacttype, f.artefact, f.oldextension, f.fileid
            FROM
                {artefact} a,
                {artefact_file_files} f
            WHERE
                a.id = f.artefact
        ', array());
        require_once get_config('libroot') . 'file.php';
        if ($fileartefacts) {
            foreach ($fileartefacts as $a) {
                $type = null;
                if ($a->artefacttype == 'image') {
                    $size = getimagesize(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                    $type = $size['mime'];
                } else {
                    if ($a->artefacttype == 'profileicon') {
                        $size = getimagesize(get_config('dataroot') . 'artefact/file/profileicons/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                        $type = $size['mime'];
                    } else {
                        if ($a->artefacttype == 'file') {
                            $type = get_mime_type(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid);
                        }
                    }
                }
                if ($type) {
                    set_field('artefact_file_files', 'filetype', $type, 'artefact', $a->artefact);
                }
            }
        }
        delete_records('config', 'field', 'pathtofile');
    }
    if ($oldversion < 2008101701) {
        if ($data = get_config_plugin('blocktype', 'internalmedia', 'enabledtypes')) {
            $olddata = unserialize($data);
            $newdata = array();
            foreach ($olddata as $d) {
                if ($d == 'mov') {
                    $newdata[] = 'quicktime';
                } else {
                    if ($d == 'mp4') {
                        $newdata[] = 'mp4_video';
                    } else {
                        if ($d != 'mpg') {
                            $newdata[] = $d;
                        }
                    }
                }
            }
            set_config_plugin('blocktype', 'internalmedia', 'enabledtypes', serialize($newdata));
        }
    }
    if ($oldversion < 2009021200) {
        $table = new XMLDBTable('artefact_file_mime_types');
        $key = new XMLDBKey('artefilemimetype_des_fk');
        $key->setAttributes(XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description'));
        drop_key($table, $key);
        $table = new XMLDBTable('artefact_file_file_types');
        drop_table($table);
        PluginArtefactFile::resync_filetype_list();
    }
    if ($oldversion < 2009021301) {
        // IE has been uploading jpegs with the image/pjpeg mimetype,
        // which is not recognised as an image by the download script.
        // Fix all existing jpegs in the db:
        set_field('artefact_file_files', 'filetype', 'image/jpeg', 'filetype', 'image/pjpeg');
        // This won't happen again because we now read the contents of the
        // uploaded file to detect image artefacts, and overwrite the mime
        // type declared by the browser if we see an image.
    }
    if ($oldversion < 2009033000) {
        if (!get_record('artefact_config', 'plugin', 'file', 'field', 'uploadagreement')) {
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'uploadagreement', 'value' => 1));
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'usecustomagreement', 'value' => 1));
        }
    }
    return $status;
}
示例#24
0
function xmldb_artefact_file_upgrade($oldversion = 0)
{
    $status = true;
    if ($oldversion < 2009033000) {
        if (!get_record('artefact_config', 'plugin', 'file', 'field', 'uploadagreement')) {
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'uploadagreement', 'value' => 1));
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'usecustomagreement', 'value' => 1));
        }
    }
    if ($oldversion < 2009091700) {
        execute_sql("DELETE FROM {artefact_file_files} WHERE artefact IN (SELECT id FROM {artefact} WHERE artefacttype = 'folder')");
    }
    if ($oldversion < 2009091701) {
        $table = new XMLDBTable('artefact_file_files');
        $key = new XMLDBKey('artefactpk');
        $key->setAttributes(XMLDB_KEY_PRIMARY, array('artefact'));
        add_key($table, $key);
        $table = new XMLDBTable('artefact_file_image');
        $key = new XMLDBKey('artefactpk');
        $key->setAttributes(XMLDB_KEY_PRIMARY, array('artefact'));
        add_key($table, $key);
    }
    if ($oldversion < 2009092300) {
        insert_record('artefact_installed_type', (object) array('plugin' => 'file', 'name' => 'archive'));
        // update old files
        if (function_exists('zip_open')) {
            $files = get_records_select_array('artefact_file_files', "filetype IN ('application/zip', 'application/x-zip')");
            if ($files) {
                $checked = array();
                foreach ($files as $file) {
                    $path = get_config('dataroot') . 'artefact/file/originals/' . $file->fileid % 256 . '/' . $file->fileid;
                    $zip = zip_open($path);
                    if (is_resource($zip)) {
                        $checked[] = $file->artefact;
                        zip_close($zip);
                    }
                }
                if (!empty($checked)) {
                    set_field_select('artefact', 'artefacttype', 'archive', "artefacttype = 'file' AND id IN (" . join(',', $checked) . ')', array());
                }
            }
        }
    }
    if ($oldversion < 2010012702) {
        if ($records = get_records_sql_array("SELECT * FROM {artefact_file_files} WHERE filetype='application/octet-stream'", array())) {
            require_once 'file.php';
            foreach ($records as &$r) {
                $path = get_config('dataroot') . 'artefact/file/originals/' . $r->fileid % 256 . '/' . $r->fileid;
                set_field('artefact_file_files', 'filetype', file_mime_type($path), 'fileid', $r->fileid, 'artefact', $r->artefact);
            }
        }
    }
    if ($oldversion < 2011052500) {
        // Set default quota to 50MB
        set_config_plugin('artefact', 'file', 'defaultgroupquota', 52428800);
    }
    if ($oldversion < 2011070700) {
        // Create an images folder for everyone with a profile icon
        $imagesdir = get_string('imagesdir', 'artefact.file');
        $imagesdirdesc = get_string('imagesdirdesc', 'artefact.file');
        execute_sql("\n            INSERT INTO {artefact} (artefacttype, container, owner, ctime, mtime, atime, title, description, author)\n            SELECT 'folder', 1, owner, current_timestamp, current_timestamp, current_timestamp, ?, ?, owner\n            FROM {artefact} WHERE owner IS NOT NULL AND artefacttype = 'profileicon'\n            GROUP BY owner", array($imagesdir, $imagesdirdesc));
        // Put profileicons into the images folder and update the description
        $profileicondesc = get_string('uploadedprofileicon', 'artefact.file');
        if (is_postgres()) {
            execute_sql("\n                UPDATE {artefact}\n                SET parent = f.folderid, description = ?\n                FROM (\n                    SELECT owner, MAX(id) AS folderid\n                    FROM {artefact}\n                    WHERE artefacttype = 'folder' AND title = ? AND description = ?\n                    GROUP BY owner\n                ) f\n                WHERE artefacttype = 'profileicon' AND {artefact}.owner = f.owner", array($profileicondesc, $imagesdir, $imagesdirdesc));
        } else {
            execute_sql("\n                UPDATE {artefact}, (\n                    SELECT owner, MAX(id) AS folderid\n                    FROM {artefact}\n                    WHERE artefacttype = 'folder' AND title = ? AND description = ?\n                    GROUP BY owner\n                ) f\n                SET parent = f.folderid, description = ?\n                WHERE artefacttype = 'profileicon' AND {artefact}.owner = f.owner", array($imagesdir, $imagesdirdesc, $profileicondesc));
        }
    }
    if ($oldversion < 2011082200) {
        // video file type
        if (!get_record('artefact_installed_type', 'plugin', 'file', 'name', 'video')) {
            insert_record('artefact_installed_type', (object) array('plugin' => 'file', 'name' => 'video'));
        }
        // update existing records
        $videotypes = get_records_sql_array('
            SELECT DISTINCT description
            FROM {artefact_file_mime_types}
            WHERE mimetype ' . db_ilike() . ' \'%video%\'', array());
        if ($videotypes) {
            $mimetypes = array();
            foreach ($videotypes as $type) {
                $mimetypes[] = $type->description;
            }
            $files = get_records_sql_array('
                SELECT *
                FROM {artefact_file_files}
                WHERE filetype IN (
                    SELECT mimetype
                    FROM {artefact_file_mime_types}
                    WHERE description IN (' . join(',', array_map('db_quote', array_values($mimetypes))) . ')
                )', array());
            if ($files) {
                $checked = array();
                foreach ($files as $file) {
                    $checked[] = $file->artefact;
                }
                if (!empty($checked)) {
                    set_field_select('artefact', 'artefacttype', 'video', "artefacttype = 'file' AND id IN (" . join(',', $checked) . ')', array());
                }
            }
        }
        // audio file type
        if (!get_record('artefact_installed_type', 'plugin', 'file', 'name', 'audio')) {
            insert_record('artefact_installed_type', (object) array('plugin' => 'file', 'name' => 'audio'));
        }
        // update existing records
        $audiotypes = get_records_sql_array('
            SELECT DISTINCT description
            FROM {artefact_file_mime_types}
            WHERE mimetype ' . db_ilike() . ' \'%audio%\'', array());
        if ($audiotypes) {
            $mimetypes = array();
            foreach ($audiotypes as $type) {
                $mimetypes[] = $type->description;
            }
            $files = get_records_sql_array('
                SELECT *
                FROM {artefact_file_files}
                WHERE filetype IN (
                    SELECT mimetype
                    FROM {artefact_file_mime_types}
                    WHERE description IN (' . join(',', array_map('db_quote', array_values($mimetypes))) . ')
                 )', array());
            if ($files) {
                $checked = array();
                foreach ($files as $file) {
                    $checked[] = $file->artefact;
                }
                if (!empty($checked)) {
                    set_field_select('artefact', 'artefacttype', 'audio', "artefacttype = 'file' AND id IN (" . join(',', $checked) . ')', array());
                }
            }
        }
    }
    if ($oldversion < 2012050400) {
        if (!get_record('artefact_config', 'plugin', 'file', 'field', 'resizeonuploadenable')) {
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploadenable', 'value' => 0));
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploaduseroption', 'value' => 0));
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploadmaxheight', 'value' => get_config('imagemaxheight')));
            insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'resizeonuploadmaxwidth', 'value' => get_config('imagemaxwidth')));
        }
    }
    if ($oldversion < 2012092400) {
        $basepath = get_config('dataroot') . "artefact/file/originals/";
        try {
            check_dir_exists($basepath, true);
        } catch (Exception $e) {
            throw new SystemException("Failed to create " . $basepath);
        }
        $baseiter = new DirectoryIterator($basepath);
        foreach ($baseiter as $dir) {
            if ($dir->isDot()) {
                continue;
            }
            $dirpath = $dir->getPath() . '/' . $dir->getFilename();
            $fileiter = new DirectoryIterator($dirpath);
            foreach ($fileiter as $file) {
                if ($file->isDot()) {
                    continue;
                }
                if (!$file->isFile()) {
                    log_error("Something was wrong about the dataroot in artefact/file/originals/{$dir}. Unexpected folder {$file}");
                    continue;
                }
                chmod($file->getPathname(), $file->getPerms() & 0666);
            }
        }
    }
    if ($oldversion < 2013031200) {
        // Update MIME types for Microsoft video files: avi, asf, wm, and wmv
        update_record('artefact_file_mime_types', (object) array('mimetype' => 'video/x-ms-asf', 'description' => 'asf'), (object) array('mimetype' => 'video/x-ms-asf'));
        update_record('artefact_file_mime_types', (object) array('mimetype' => 'video/x-ms-wm', 'description' => 'wm'), (object) array('mimetype' => 'video/x-ms-wm'));
        update_record('artefact_file_mime_types', (object) array('mimetype' => 'video/x-ms-wmv', 'description' => 'wmv'), (object) array('mimetype' => 'video/x-ms-wmv'));
    }
    if ($oldversion < 2014040800) {
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'audio/aac'), (object) array('mimetype' => 'audio/aac', 'description' => 'aac'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/msaccess'), (object) array('mimetype' => 'application/msaccess', 'description' => 'accdb'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'shockwave/director'), (object) array('mimetype' => 'shockwave/director', 'description' => 'cct'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-csh'), (object) array('mimetype' => 'application/x-csh', 'description' => 'cs'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/css'), (object) array('mimetype' => 'text/css', 'description' => 'css'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/csv'), (object) array('mimetype' => 'text/csv', 'description' => 'csv'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'video/x-dv'), (object) array('mimetype' => 'video/x-dv', 'description' => 'dv'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'description' => 'docx'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-word.document.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-word.document.macroEnabled.12', 'description' => 'docm'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 'description' => 'dotx'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-word.template.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-word.template.macroEnabled.12', 'description' => 'dotm'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-director'), (object) array('mimetype' => 'application/x-director', 'description' => 'dcr'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/epub+zip'), (object) array('mimetype' => 'application/epub+zip', 'description' => 'epub'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-smarttech-notebook'), (object) array('mimetype' => 'application/x-smarttech-notebook', 'description' => 'gallery'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/mac-binhex40'), (object) array('mimetype' => 'application/mac-binhex40', 'description' => 'hqx'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/x-component'), (object) array('mimetype' => 'text/x-component', 'description' => 'htc'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/xhtml+xml'), (object) array('mimetype' => 'application/xhtml+xml', 'description' => 'xhtml'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'image/vnd.microsoft.icon'), (object) array('mimetype' => 'image/vnd.microsoft.icon', 'description' => 'ico'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/calendar'), (object) array('mimetype' => 'text/calendar', 'description' => 'ics'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/inspiration'), (object) array('mimetype' => 'application/inspiration', 'description' => 'isf'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/inspiration.template'), (object) array('mimetype' => 'application/inspiration.template', 'description' => 'ist'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/java-archive'), (object) array('mimetype' => 'application/java-archive', 'description' => 'jar'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-java-jnlp-file'), (object) array('mimetype' => 'application/x-java-jnlp-file', 'description' => 'jnlp'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.moodle.backup'), (object) array('mimetype' => 'application/vnd.moodle.backup', 'description' => 'mbz'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-msaccess'), (object) array('mimetype' => 'application/x-msaccess', 'description' => 'mdb'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'message/rfc822'), (object) array('mimetype' => 'message/rfc822', 'description' => 'mht'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.moodle.profiling'), (object) array('mimetype' => 'application/vnd.moodle.profiling', 'description' => 'mpr'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.oasis.opendocument.graphics-template'), (object) array('mimetype' => 'application/vnd.oasis.opendocument.graphics-template', 'description' => 'otg'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.oasis.opendocument.presentation-template'), (object) array('mimetype' => 'application/vnd.oasis.opendocument.presentation-template', 'description' => 'otp'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.oasis.opendocument.spreadsheet-template'), (object) array('mimetype' => 'application/vnd.oasis.opendocument.spreadsheet-template', 'description' => 'ots'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'audio/ogg'), (object) array('mimetype' => 'audio/ogg', 'description' => 'oga'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'video/ogg'), (object) array('mimetype' => 'video/ogg', 'description' => 'ogv'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'image/pict'), (object) array('mimetype' => 'image/pict', 'description' => 'pct'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'description' => 'pptx'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', 'description' => 'pptm'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.template'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.template', 'description' => 'potx'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-powerpoint.template.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', 'description' => 'potm'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', 'description' => 'ppam'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', 'description' => 'ppsx'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', 'description' => 'ppsm'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'audio/x-realaudio-plugin'), (object) array('mimetype' => 'audio/x-realaudio-plugin', 'description' => 'ra'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'audio/x-pn-realaudio-plugin'), (object) array('mimetype' => 'audio/x-pn-realaudio-plugin', 'description' => 'ram'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.rn-realmedia-vbr'), (object) array('mimetype' => 'application/vnd.rn-realmedia-vbr', 'description' => 'rmvb'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/richtext'), (object) array('mimetype' => 'text/richtext', 'description' => 'rtx'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-stuffit'), (object) array('mimetype' => 'application/x-stuffit', 'description' => 'sit'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/smil'), (object) array('mimetype' => 'application/smil', 'description' => 'smi'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'image/svg+xml'), (object) array('mimetype' => 'image/svg+xml', 'description' => 'svg'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.writer'), (object) array('mimetype' => 'application/vnd.sun.xml.writer', 'description' => 'sxw'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.writer.template'), (object) array('mimetype' => 'application/vnd.sun.xml.writer.template', 'description' => 'stw'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.calc'), (object) array('mimetype' => 'application/vnd.sun.xml.calc', 'description' => 'sxc'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.calc.template'), (object) array('mimetype' => 'application/vnd.sun.xml.calc.template', 'description' => 'stc'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.draw'), (object) array('mimetype' => 'application/vnd.sun.xml.draw', 'description' => 'sxd'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.draw.template'), (object) array('mimetype' => 'application/vnd.sun.xml.draw.template', 'description' => 'std'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.impress'), (object) array('mimetype' => 'application/vnd.sun.xml.impress', 'description' => 'sxi'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.impress.template'), (object) array('mimetype' => 'application/vnd.sun.xml.impress.template', 'description' => 'sti'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.writer.global'), (object) array('mimetype' => 'application/vnd.sun.xml.writer.global', 'description' => 'sxg'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.sun.xml.math'), (object) array('mimetype' => 'application/vnd.sun.xml.math', 'description' => 'sxm'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'image/tiff'), (object) array('mimetype' => 'image/tiff', 'description' => 'tif'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-tex'), (object) array('mimetype' => 'application/x-tex', 'description' => 'tex'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/x-texinfo'), (object) array('mimetype' => 'application/x-texinfo', 'description' => 'texi'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'text/tab-separated-values'), (object) array('mimetype' => 'text/tab-separated-values', 'description' => 'tsv'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'video/webm'), (object) array('mimetype' => 'video/webm', 'description' => 'webm'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-excel'), (object) array('mimetype' => 'application/vnd.ms-excel', 'description' => 'xls'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'description' => 'xlsx'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-excel.sheet.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-excel.sheet.macroEnabled.12', 'description' => 'xlsm'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'), (object) array('mimetype' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', 'description' => 'xltx'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-excel.template.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-excel.template.macroEnabled.12', 'description' => 'xltm'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', 'description' => 'xlsb'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/vnd.ms-excel.addin.macroEnabled.12'), (object) array('mimetype' => 'application/vnd.ms-excel.addin.macroEnabled.12', 'description' => 'xlam'));
        ensure_record_exists('artefact_file_mime_types', (object) array('mimetype' => 'application/xml'), (object) array('mimetype' => 'application/xml', 'description' => 'xml'));
    }
    if ($oldversion < 2014051200) {
        require_once get_config('docroot') . '/lib/file.php';
        $mimetypes = get_records_assoc('artefact_file_mime_types', '', '', '', 'description,mimetype');
        // Re-examine only those files where their current identified mimetype is
        // different from how we would identify their mimetype based on file extension
        $rs = get_recordset_sql('
            select a.id, aff.oldextension, aff.filetype
            from
                {artefact} a
                inner join {artefact_file_files} aff
                    on a.id = aff.artefact
            where a.artefacttype = \'archive\'
                and not exists (
                    select 1 from {artefact_file_mime_types} afmt
                    where afmt.description = aff.oldextension
                    and afmt.mimetype = aff.filetype
                )
            order by a.id
        ');
        $total = 0;
        $done = 0;
        while ($zf = $rs->FetchRow()) {
            if ($done % 100 == 0) {
                log_debug('Verifying filetypes: ' . $done . '/' . $rs->RecordCount());
            }
            $done++;
            $file = artefact_instance_from_id($zf['id']);
            $path = $file->get_path();
            // Check what our improved file detection system thinks it is
            $guess = file_mime_type($path, 'foo.' . $zf['oldextension']);
            if ($guess != 'application/octet-stream') {
                $data = new stdClass();
                $data->filetype = $data->guess = $guess;
                foreach (array('video', 'audio', 'archive') as $artefacttype) {
                    $classname = 'ArtefactType' . ucfirst($artefacttype);
                    if (call_user_func_array(array($classname, 'is_valid_file'), array($file->get_path(), &$data))) {
                        set_field('artefact', 'artefacttype', $artefacttype, 'id', $zf['id']);
                        set_field('artefact_file_files', 'filetype', $data->filetype, 'artefact', $zf['id']);
                        continue 2;
                    }
                }
                // It wasn't any of those special ones, so just make it a normal file artefact
                set_field('artefact', 'artefacttype', 'file', 'id', $zf['id']);
                set_field('artefact_file_files', 'filetype', $data->filetype, 'artefact', $zf['id']);
            }
        }
        log_debug('Verifying filetypes: ' . $done . '/' . $rs->RecordCount());
        $rs->Close();
    }
    if ($oldversion < 2014060900) {
        $events = array((object) array('plugin' => 'file', 'event' => 'saveartefact', 'callfunction' => 'eventlistener_savedeleteartefact'), (object) array('plugin' => 'file', 'event' => 'deleteartefact', 'callfunction' => 'eventlistener_savedeleteartefact'), (object) array('plugin' => 'file', 'event' => 'deleteartefacts', 'callfunction' => 'eventlistener_savedeleteartefact'), (object) array('plugin' => 'file', 'event' => 'updateuser', 'callfunction' => 'eventlistener_savedeleteartefact'));
        foreach ($events as $event) {
            ensure_record_exists('artefact_event_subscription', $event, $event);
        }
        PluginArtefactFile::set_quota_triggers();
    }
    if ($oldversion < 2014061000) {
        // Remove the not needed quota notify on update config trigger from previous update
        if (is_postgres()) {
            $sql = 'DROP TRIGGER IF EXISTS {unmark_quota_exeed_notified_on_update_setting_trigger} ON {artefact_config};';
        } else {
            $sql = 'DROP TRIGGER IF EXISTS {unmark_quota_exeed_notified_on_update_setting_trigger};';
        }
        execute_sql($sql);
    }
    if ($oldversion < 2014111200) {
        // Create embedded images table
        $table = new XMLDBTable('artefact_file_embedded');
        $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE);
        $table->addFieldInfo('fileid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
        $table->addFieldInfo('resourcetype', XMLDB_TYPE_CHAR, '100', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $table->addFieldInfo('resourceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL);
        $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
        $table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('fileid'), 'artefact', array('id'));
        $status = $status && create_table($table);
    }
    if ($oldversion < 2015101900) {
        log_debug('Need to consolidate "textbox" and "editnote" embedded resource types as they are in fact the same thing');
        if ($records = get_records_sql_array('SELECT * FROM {artefact_file_embedded} WHERE resourcetype IN (?, ?)', array('editnote', 'textbox'))) {
            $newrecords = array();
            // Turn the results into something easier to check against
            foreach ($records as $k => $v) {
                $newrecords[$v->resourcetype . '_' . $v->resourceid . '_' . $v->fileid] = $v;
            }
            foreach ($newrecords as $nk => $nv) {
                // need to sort out the 'editnote' options
                if (preg_match('/^editnote_(.*)$/', $nk, $match)) {
                    // Check to see if there is a corresponding 'textbox' one - if not we need to make one
                    if (!array_key_exists('textbox_' . $match[1], $newrecords)) {
                        insert_record('artefact_file_embedded', (object) array('fileid' => $nv->fileid, 'resourcetype' => 'textbox', 'resourceid' => $nv->resourceid));
                    }
                    // now delete the 'editnote' one
                    delete_records('artefact_file_embedded', 'id', $nv->id);
                }
            }
        }
    }
    return $status;
}
示例#25
0
    $extradata->blockid = $blockid;
}
if (empty($extradata->view) || empty($extradata->annotation) || empty($extradata->blockid)) {
    json_reply('local', get_string('annotationinformationerror', 'artefact.annotation'));
}
if (!can_view_view($extradata->view)) {
    json_reply('local', get_string('noaccesstoview', 'view'));
}
if (!artefact_in_view($extradata->annotation, $extradata->view)) {
    json_reply('local', get_string('accessdenied', 'error'));
}
if (!empty($extradata->artefact) && !artefact_in_view($extradata->artefact, $extradata->view)) {
    json_reply('local', get_string('accessdenied', 'error'));
}
if ($ispagination) {
    // This is not really working yet. Need to do more work on artefact/artefact.php
    $options = ArtefactTypeAnnotationfeedback::get_annotation_feedback_options();
    $options->limit = $limit;
    $options->offset = $offset;
    $options->view = $extradata->view;
    $options->annotation = $extradata->annotation;
    $options->artefact = $extradata->artefact;
    $options->block = $extradata->blockid;
    $annotationfeedback = ArtefactTypeAnnotationfeedback::get_annotation_feedback($options);
    json_reply(false, array('data' => $annotationfeedback));
} else {
    $view = new View($extradata->view);
    $annotationartefact = artefact_instance_from_id($extradata->annotation);
    list($feedbackcount, $annotationfeedback) = ArtefactTypeAnnotationfeedback::get_annotation_feedback_for_view($annotationartefact, $view, $extradata->blockid);
    json_reply(false, array('data' => $annotationfeedback));
}
示例#26
0
 /**
  * Given a filesystem directory and the id of an artefact, fill the 
  * filesystem directory with the files and folders that Mahara considers 
  * are inside the artefact.
  *
  * This method is recursive, creating the file/directory structure for all 
  * directories under the one passed.
  *
  * This method also creates index.htmls in each directory created.
  *
  * @param string $filesystemdirectory The file system directory to populate
  * @param int    $level               How deep the directory is
  * @param int    $parentid            The folder to start from - can be null
  */
 private function populate_filedir($filesystemdirectory, $level, $parentid)
 {
     foreach ($this->artefactdata as $artefactid => $artefact) {
         if ($artefact->get('parent') == $parentid) {
             if ($artefact->get('artefacttype') == 'folder') {
                 $directory = $filesystemdirectory . PluginExportHtml::sanitise_path($artefact->get('title')) . '/';
                 check_dir_exists($directory);
                 $this->create_index_for_directory($directory, $level + 1, $artefact);
                 $this->populate_filedir($directory, $level + 1, $artefactid);
             } else {
                 $artefact = artefact_instance_from_id($artefactid);
                 if (!copy($artefact->get_path(), $filesystemdirectory . PluginExportHtml::sanitise_path($artefact->get('title')))) {
                     throw new SystemException("Unable to copy artefact {$artefactid}'s file");
                 }
             }
         }
     }
 }
示例#27
0
function pieform_element_filebrowser_move(Pieform $form, $element, $data)
{
    global $USER;
    $artefactid = $data['artefact'];
    // Artefact being moved
    $newparentid = $data['newparent'];
    // Folder to move it to
    try {
        $artefact = artefact_instance_from_id($artefactid);
    } catch (ArtefactNotFoundException $e) {
        $result = array('error' => true, 'message' => get_string('movingfailed', 'artefact.file'), 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $data['folder']));
        return $result;
    }
    if (!$USER->can_edit_artefact($artefact)) {
        return array('error' => true, 'message' => get_string('movefailednotowner', 'artefact.file'));
    }
    if (!in_array($artefact->get('artefacttype'), PluginArtefactFile::get_artefact_types())) {
        return array('error' => true, 'message' => get_string('movefailednotfileartefact', 'artefact.file'));
    }
    if ($newparentid > 0) {
        if ($newparentid == $artefactid) {
            return array('error' => true, 'message' => get_string('movefaileddestinationinartefact', 'artefact.file'));
        }
        if ($newparentid == $artefact->get('parent')) {
            return array('error' => false, 'message' => get_string('filealreadyindestination', 'artefact.file'));
        }
        try {
            $newparent = artefact_instance_from_id($newparentid);
        } catch (ArtefactNotFoundException $e) {
            $parentfolder = $element['folder'] ? $element['folder'] : null;
            $result = array('error' => true, 'message' => get_string('movingfailed', 'artefact.file'), 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $data['folder']));
            return $result;
        }
        if (!$USER->can_edit_artefact($newparent)) {
            return array('error' => true, 'message' => get_string('movefailednotowner', 'artefact.file'));
        } else {
            if ($newparent->get('locked')) {
                return array('error' => true, 'message' => get_string('cannoteditfoldersubmitted', 'artefact.file'));
            }
        }
        $group = $artefact->get('group');
        if ($group && $group !== $newparent->get('group')) {
            return array('error' => true, 'message' => get_string('movefailednotowner', 'artefact.file'));
        }
        if ($newparent->get('artefacttype') != 'folder') {
            return array('error' => true, 'message' => get_string('movefaileddestinationnotfolder', 'artefact.file'));
        }
        $nextparentid = $newparent->get('parent');
        while (!empty($nextparentid)) {
            if ($nextparentid != $artefactid) {
                $ancestor = artefact_instance_from_id($nextparentid);
                $nextparentid = $ancestor->get('parent');
            } else {
                return array('error' => true, 'message' => get_string('movefaileddestinationinartefact', 'artefact.file'));
            }
        }
    } else {
        // $newparentid === 0
        if ($artefact->get('parent') == null) {
            return array('error' => false, 'message' => get_string('filealreadyindestination', 'artefact.file'));
        }
        $group = $artefact->get('group');
        if ($group) {
            if (!pieform_element_filebrowser_edit_group_folder($group, 0)) {
                return array('error' => true, 'message' => get_string('movefailednotowner', 'artefact.file'));
            }
        }
        $newparentid = null;
    }
    if ($oldparentid = $artefact->get('parent')) {
        $oldparent = artefact_instance_from_id($oldparentid);
        if ($oldparent->get('locked')) {
            return array('error' => true, 'message' => get_string('cannotremovefromsubmittedfolder', 'artefact.file'));
        }
    }
    if ($artefact->move($newparentid)) {
        return array('error' => false, 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $data['folder']));
    }
    return array('error' => true, 'message' => get_string('movefailed', 'artefact.file'));
}
示例#28
0
文件: lib.php 项目: banterweb/mahara
 public static function instance_config_save($values, $instance)
 {
     global $USER;
     require_once 'embeddedimage.php';
     $data = array();
     $view = $instance->get_view();
     foreach (array('owner', 'group', 'institution') as $f) {
         $data[$f] = $view->get($f);
     }
     if (empty($values['artefactid']) || $values['makecopy']) {
         // The artefact title will be the same as the block title when the
         // artefact is first created, or, if there's no block title, generate
         // 'Note (1)', 'Note (2)', etc.  After that, the artefact title can't
         // be edited inside the block, but can be changed in the Notes area.
         if (empty($values['title'])) {
             $title = artefact_new_title(get_string('Note', 'artefact.internal'), 'html', $data['owner'], $data['group'], $data['institution']);
         } else {
             $title = $values['title'];
         }
         $artefact = new ArtefactTypeHtml(0, $data);
         $artefact->set('title', $title);
         $artefact->set('description', $values['text']);
         if (get_config('licensemetadata')) {
             $artefact->set('license', $values['license']);
             $artefact->set('licensor', $values['licensor']);
             $artefact->set('licensorurl', $values['licensorurl']);
         }
         $artefact->set('allowcomments', !empty($values['allowcomments']) ? $values['allowcomments'] : 0);
         $artefact->set('tags', $values['tags']);
     } else {
         $artefact = new ArtefactTypeHtml((int) $values['artefactid']);
         if (!$USER->can_publish_artefact($artefact)) {
             throw new AccessDeniedException(get_string('nopublishpermissiononartefact', 'mahara', hsc($artefact->get('title'))));
         }
         // Stop users from editing textbox artefacts whose owner is not the same as the
         // view owner, even if they would normally be allowed to edit the artefact.
         // It's too confusing.  Textbox artefacts with other owners *can* be included in
         // the view read-only, provided the artefact has the correct republish
         // permission.
         if ($artefact->get('owner') === $data['owner'] && $artefact->get('group') === $data['group'] && $artefact->get('institution') === $data['institution'] && !$artefact->get('locked') && $USER->can_edit_artefact($artefact)) {
             $newdescription = EmbeddedImage::prepare_embedded_images($values['text'], 'textbox', (int) $values['artefactid'], $view->get('group'));
             $artefact->set('description', $newdescription);
             if (get_config('licensemetadata')) {
                 $artefact->set('license', $values['license']);
                 $artefact->set('licensor', $values['licensor']);
                 $artefact->set('licensorurl', $values['licensorurl']);
             }
             $artefact->set('tags', $values['tags']);
             $artefact->set('allowcomments', !empty($values['allowcomments']) ? 1 : 0);
         }
     }
     $artefact->commit();
     $newdescription = EmbeddedImage::prepare_embedded_images($values['text'], 'textbox', $artefact->get('id'), $view->get('group'));
     if ($newdescription !== $values['text']) {
         $updatedartefact = new stdClass();
         $updatedartefact->id = $artefact->get('id');
         $updatedartefact->description = $newdescription;
         update_record('artefact', $updatedartefact, 'id');
     }
     // Add attachments, if there are any...
     $old = $artefact->attachment_id_list();
     $new = is_array($values['artefactids']) ? $values['artefactids'] : 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 {
                     $artefact->detach($o);
                 } catch (ArtefactNotFoundException $e) {
                 }
             }
         }
         foreach ($new as $n) {
             if (!in_array($n, $old)) {
                 try {
                     $artefact->attach($n);
                 } catch (ArtefactNotFoundException $e) {
                 }
             }
         }
     }
     $values['artefactid'] = $artefact->get('id');
     $instance->save_artefact_instance($artefact);
     unset($values['text']);
     unset($values['otherblocksmsg']);
     unset($values['readonlymsg']);
     unset($values['textreadonly']);
     unset($values['makecopy']);
     unset($values['chooseartefact']);
     unset($values['managenotes']);
     unset($values['allowcomments']);
     // Pass back a list of any other blocks that need to be rendered
     // due to this change.
     $values['_redrawblocks'] = array_unique(get_column('view_artefact', 'block', 'artefact', $values['artefactid'], 'view', $instance->get('view')));
     return $values;
 }
示例#29
0
 public function get_summary()
 {
     $smarty = $this->exporter->get_smarty();
     $outputfilter = new HtmlExportOutputFilter('.', $this->exporter);
     $smarty->assign('introduction', $outputfilter->filter(get_profile_field($this->exporter->get('user')->get('id'), 'introduction')));
     $smarty->assign('profileviewexported', $this->profileviewexported);
     $iconid = $this->exporter->get('user')->get('profileicon');
     if ($iconid) {
         $icon = artefact_instance_from_id($iconid);
         $smarty->assign('icon', '<img src="static/profileicons/200px-' . PluginExportHtml::sanitise_path($icon->get('title')) . '" alt="Profile Picture">');
     }
     return array('description' => $smarty->fetch('export:html/internal:summary.tpl'));
 }
示例#30
0
 /**
  * Copy the description of the view template
  * and its embedded image artefacts
  *
  * @param View $template the view template
  * @param array &$artefactcopies the artefact mapping
  * @return string updated description
  */
 private function copy_description(View $template, array &$artefactcopies)
 {
     $new_description = $template->get('description');
     if (!empty($new_description) && strpos($new_description, 'artefact/file/download.php?file=') !== false) {
         // Get all possible embedded artefacts
         $artefactids = array_unique(artefact_get_references_in_html($new_description));
         // Copy these image artefacts
         foreach ($artefactids as $aid) {
             try {
                 $a = artefact_instance_from_id($aid);
             } catch (Exception $e) {
                 continue;
             }
             if ($a instanceof ArtefactTypeImage) {
                 $artefactcopies[$aid] = (object) array('oldid' => $aid, 'oldparent' => $a->get('parent'));
                 $artefactcopies[$aid]->newid = $a->copy_for_new_owner($this->get('owner'), $this->get('group'), $this->get('institution'));
             }
         }
         // Update the image urls in the description
         if (!empty($artefactcopies)) {
             $regexp = array();
             $replacetext = array();
             foreach ($artefactcopies as $oldaid => $newobj) {
                 // Change the old image id to the new one
                 $regexp[] = '#<img([^>]+)src=("|\\")' . preg_quote(get_config('wwwroot') . 'artefact/file/download.php?file=' . $oldaid) . '(&|&amp;)embedded=1([^"]*)"#';
                 $replacetext[] = '<img$1src="' . get_config('wwwroot') . 'artefact/file/download.php?file=' . $newobj->newid . '&embedded=1"';
             }
             $new_description = preg_replace($regexp, $replacetext, $new_description);
         }
     }
     return $new_description;
 }