public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $configdata = $instance->get('configdata'); $result = ''; if (isset($configdata['artefactids']) && is_array($configdata['artefactids'])) { foreach ($configdata['artefactids'] as $artefactid) { try { $artefact = $instance->get_artefact_instance($artefactid); } catch (ArtefactNotFoundException $e) { continue; } $icondata = array('id' => $artefactid, 'viewid' => $instance->get('view')); $detailsurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefactid . '&view=' . $instance->get('view'); if ($artefact instanceof ArtefactTypeProfileIcon) { require_once 'file.php'; $downloadurl = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $artefactid; $size = filesize(get_dataroot_image_path('artefact/file/profileicons/', $artefactid)); } else { if ($artefact instanceof ArtefactTypeFile) { $downloadurl = get_config('wwwroot') . 'artefact/file/download.php?file=' . $artefactid . '&view=' . $icondata['viewid']; $size = $artefact->get('size'); } } $result .= '<div title="' . hsc($artefact->get('title')) . '">'; $result .= '<div class="fl"><a href="' . hsc($downloadurl) . '">'; $result .= '<img src="' . hsc(call_static_method(generate_artefact_class_name($artefact->get('artefacttype')), 'get_icon', $icondata)) . '" alt=""></a></div>'; $result .= '<div style="margin-left: 30px;">'; $result .= '<h4><a href="' . hsc($detailsurl) . '">' . str_shorten_text($artefact->get('title'), 20) . '</a></h4>'; $description = $artefact->get('description'); if ($description) { $result .= '<p style="margin: 0;"><strong>' . hsc($description) . '</strong></p>'; } $result .= '' . display_size($size) . ' | ' . strftime(get_string('strftimedaydate'), $artefact->get('ctime')); $result .= '</div>'; $result .= '</div>'; } } return $result; }
/** * Puts all profile icons in the static/profileicons/ directory */ private function populate_profileicons() { $profileiconsdir = $this->exporter->get('exportdir') . '/' . $this->exporter->get('rootdir') . '/static/profileicons/'; $removekeys = array(); foreach ($this->artefactdata as $artefactid => $artefact) { if ($artefact->get('artefacttype') == 'profileicon') { $removekeys[] = $artefactid; if (!copy($artefact->get_path(), $profileiconsdir . PluginExportHtml::sanitise_path($artefact->get('title')))) { throw new SystemException("Unable to copy profile icon {$artefactid} into export"); } // Make sure we grab a nicely resized version too $maxdimension = 200; $resizedpath = get_dataroot_image_path('artefact/file/profileicons/', $artefactid, $maxdimension); if (!copy($resizedpath, $profileiconsdir . $maxdimension . 'px-' . PluginExportHtml::sanitise_path($artefact->get('title')))) { throw new SystemException("Unable to copy resized profile icon {$maxdimension}px-{$artefact->get('title')} into export"); } } } foreach ($removekeys as $key) { unset($this->artefactdata[$key]); } }
/** * Callback to replace links to thumb.php to point to the correct file in * the HTML export */ private function replace_thumbnail_link($matches) { if (isset($matches[3])) { $type = $matches[2]; $parts = preg_split('/(&|&|%26)/', $matches[3]); array_shift($parts); foreach ($parts as $part) { list($key, $value) = explode('=', $part); $options[$key] = $value; } if (!isset($options['id'])) { return ''; } switch ($type) { case 'profileicon': // Convert the user ID to a profile icon ID if (!($options['id'] = get_field_sql('SELECT profileicon FROM {usr} WHERE id = ?', array($options['id'])))) { // No profile icon, get the default one list($size, $prefix) = $this->get_size_from_options($options); if ($from = get_dataroot_image_path('artefact/file/profileicons/no_userphoto/' . get_config('theme'), 0, $size)) { $to = '/static/profileicons/0-' . $prefix . 'no_userphoto.png'; $this->htmlexportcopyproxy->add($from, $to); } return $this->basepath . $to; } case 'profileiconbyid': try { $icon = artefact_instance_from_id($options['id']); } catch (ArtefactNotFoundException $e) { return ''; } if ($icon->get_plugin_name() != 'file') { return ''; } return $this->get_export_path_for_file($icon, $options, '/static/profileicons/'); default: return ''; } } return ''; }
function fetch_user_image($username) { global $REMOTEWWWROOT; list($user, $authinstance) = find_remote_user($username, $REMOTEWWWROOT); if (!$user) { return false; } $ic = $user->profileicon; if (!empty($ic)) { $filename = get_config('dataroot') . 'artefact/file/profileicons/' . $user->profileicon % 256 . '/' . $user->profileicon; $return = array(); try { $fi = file_get_contents($filename); } catch (Exception $e) { // meh } $return['f1'] = base64_encode($fi); require_once 'file.php'; $im = get_dataroot_image_path('artefact/file/profileicons', $user->profileicon, 100); $fi = file_get_contents($im); $return['f2'] = base64_encode($fi); return $return; } else { // no icon } }
public function get_path($data = array()) { require_once 'file.php'; $result = get_dataroot_image_path('artefact/file/profileicons/', $this->fileid, $data); return $result; }
// Move the file into the correct place. $directory = get_config('dataroot') . 'artefact/file/profileicons/no_userphoto/' . $THEME->basename . '/originals/0/'; check_dir_exists($directory); copy($nouserphotopic, $directory . '0'); // Now we can try and get the image in the correct size if ($path = get_dataroot_image_path('artefact/file/profileicons/no_userphoto/' . $THEME->basename, 0, $size)) { header('Content-type: ' . 'image/png'); readfile_exit($path); } } // Emergency fallback header('Content-type: ' . 'image/png'); readfile_exit($THEME->get_path('images/no_userphoto.png')); case 'logobyid': $filedata = get_record('artefact_file_files', 'artefact', param_integer('id')); if ($path = get_dataroot_image_path('artefact/file/profileicons', $filedata->fileid, get_imagesize_parameters())) { if ($filedata->filetype) { header('Content-type: ' . $filedata->filetype); if (!get_config('nocache')) { $maxage = 604800; header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $maxage) . ' GMT'); header('Cache-Control: max-age=' . $maxage); header('Pragma: public'); } readfile_exit($path); } } // Nothing found, use the site logo. header('Content-type: ' . 'image/png'); readfile_exit($THEME->get_path('images/site-logo.png')); case 'blocktype':
// below at the other get_config('theme') call! if ($path = get_dataroot_image_path('artefact/file/profileicons/no_userphoto/' . get_config('theme'), 0, $size)) { header('Content-type: ' . 'image/png'); readfile($path); exit; } // If we couldn't find the no user photo picture, we put it into // dataroot if we can $nouserphotopic = theme_get_path('images/no_userphoto.png'); if ($nouserphotopic) { // Move the file into the correct place. $directory = get_config('dataroot') . 'artefact/file/profileicons/no_userphoto/' . get_config('theme') . '/originals/0/'; check_dir_exists($directory); copy($nouserphotopic, $directory . '0'); // Now we can try and get the image in the correct size if ($path = get_dataroot_image_path('artefact/file/profileicons/no_userphoto/' . get_config('theme'), 0, $size)) { header('Content-type: ' . 'image/png'); readfile($path); exit; } } // Emergency fallback header('Content-type: ' . 'image/png'); readfile(theme_get_path('images/no_userphoto.png')); exit; break; case 'blocktype': $bt = param_alpha('bt'); // blocktype $ap = param_alpha('ap', null); // artefact plugin (optional)
/** * Puts all profile icons in the static/profileicons/ directory */ private function populate_profileicons() { global $SESSION; $profileiconsdir = $this->exporter->get('exportdir') . '/' . $this->exporter->get('rootdir') . '/static/profileicons/'; $removekeys = array(); foreach ($this->artefactdata as $artefactid => $artefact) { if ($artefact->get('artefacttype') == 'profileicon') { $removekeys[] = $artefactid; if (!($profileiconpath = $artefact->get_path())) { $SESSION->add_error_msg(get_string('nonexistentprofileicon', 'export', $artefact->get('title'))); } else { if (!copy($profileiconpath, $profileiconsdir . PluginExportHtml::sanitise_path($artefact->get('title')))) { $SESSION->add_error_msg(get_string('unabletocopyprofileicon', 'export', $artefact->get('title'))); } } // Make sure we grab a nicely resized version too $maxdimension = 200; if (!($resizedpath = get_dataroot_image_path('artefact/file/profileicons/', $artefactid, $maxdimension))) { $SESSION->add_error_msg(get_string('nonexistentresizedprofileicon', 'export', $maxdimension . 'px-' . $artefact->get('title'))); } else { if (!copy($resizedpath, $profileiconsdir . $maxdimension . 'px-' . PluginExportHtml::sanitise_path($artefact->get('title')))) { $SESSION->add_error_msg(get_string('unabletocopyresizedprofileicon', 'export', $maxdimension . 'px-' . $artefact->get('title'))); } } } } }