当前位置: 首页>>代码示例>>PHP>>正文


PHP artefact_instance_from_id函数代码示例

本文整理汇总了PHP中artefact_instance_from_id函数的典型用法代码示例。如果您正苦于以下问题:PHP artefact_instance_from_id函数的具体用法?PHP artefact_instance_from_id怎么用?PHP artefact_instance_from_id使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了artefact_instance_from_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render_instance

 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');
 }
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:29,代码来源:lib.php

示例2: render_instance

 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');
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:33,代码来源:lib.php

示例3: render_instance

 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');
 }
开发者ID:swjbakker,项目名称:mahara-artefact_cpds,代码行数:32,代码来源:lib.php

示例4: render_instance

 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');
 }
开发者ID:Br3nda,项目名称:mahara,代码行数:35,代码来源:lib.php

示例5: assign_smarty_vars

 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);
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:56,代码来源:lib.php

示例6: get_instance_title

 /**
  * 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 '';
 }
开发者ID:Br3nda,项目名称:mahara,代码行数:14,代码来源:lib.php

示例7: render_instance

 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');
 }
开发者ID:sarahjcotton,项目名称:mahara,代码行数:55,代码来源:lib.php

示例8: add_links

 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');
     }
 }
开发者ID:Br3nda,项目名称:mahara,代码行数:12,代码来源:lib.php

示例9: add_links

 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');
     }
 }
开发者ID:Br3nda,项目名称:mahara,代码行数:12,代码来源:lib.php

示例10: import_submit

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' => 'imported@example.org');
    $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', 'imported@example.org', '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;
}
开发者ID:Br3nda,项目名称:mahara,代码行数:47,代码来源:index.php

示例11: dump_export_data

 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");
     }
 }
开发者ID:Br3nda,项目名称:mahara,代码行数:21,代码来源:lib.php

示例12: editgoalsandskills_submit

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);
}
开发者ID:rboyatt,项目名称:mahara,代码行数:46,代码来源:editgoalsandskills.php

示例13: editpost_submit

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);
}
开发者ID:sarahjcotton,项目名称:mahara,代码行数:71,代码来源:post.php

示例14: render_self

 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' => '');
 }
开发者ID:sarahjcotton,项目名称:mahara,代码行数:29,代码来源:lib.php

示例15: prepare_embedded_images

 /**
  * 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;
     }
//.........这里部分代码省略.........
开发者ID:sarahjcotton,项目名称:mahara,代码行数:101,代码来源:embeddedimage.php


注:本文中的artefact_instance_from_id函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。