public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $configdata = $instance->get('configdata'); $viewid = $instance->get('view'); $wwwroot = get_config('wwwroot'); $files = array(); if (isset($configdata['artefactids']) && is_array($configdata['artefactids'])) { foreach ($configdata['artefactids'] as $artefactid) { try { $artefact = $instance->get_artefact_instance($artefactid); } catch (ArtefactNotFoundException $e) { continue; } $file = array('id' => $artefactid, 'title' => $artefact->get('title'), 'description' => $artefact->get('description'), 'size' => $artefact->get('size'), 'ctime' => $artefact->get('ctime'), 'artefacttype' => $artefact->get('artefacttype'), 'iconsrc' => call_static_method(generate_artefact_class_name($artefact->get('artefacttype')), 'get_icon', array('id' => $artefactid, 'viewid' => $viewid)), 'downloadurl' => $wwwroot); if ($artefact instanceof ArtefactTypeProfileIcon) { $file['downloadurl'] .= 'thumb.php?type=profileiconbyid&id=' . $artefactid; } else { if ($artefact instanceof ArtefactTypeFile) { $file['downloadurl'] .= 'artefact/file/download.php?file=' . $artefactid . '&view=' . $viewid; } } $file['is_image'] = $artefact instanceof ArtefactTypeImage ? true : false; $files[] = $file; } } $smarty = smarty_core(); $smarty->assign('viewid', $instance->get('view')); $smarty->assign('files', $files); return $smarty->fetch('blocktype:filedownload:filedownload.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $smarty = smarty_core(); //$configdata = $instance->get('configdata'); //$configdata['viewid'] = $instance->get('view'); // Get data about the resume fields the user has $return = ''; if ($artefacts = get_records_sql_array(' SELECT va.artefact, a.artefacttype FROM {view_artefact} va INNER JOIN {artefact} a ON (va.artefact = a.id) WHERE va.view = ? AND va.block = ?', array($instance->get('view'), $instance->get('id')))) { foreach ($artefacts as $artefact) { $resumefield = $instance->get_artefact_instance($artefact->artefact); $rendered = $resumefield->render_self(array('viewid' => $instance->get('view'))); $result = $rendered['html']; if (!empty($rendered['javascript'])) { $result .= '<script type="text/javascript">' . $rendered['javascript'] . '</script>'; } $smarty->assign($artefact->artefacttype, $result); } } return $smarty->fetch('blocktype:entireresume:content.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { safe_require('artefact', 'survey'); //require_once(dirname(dirname(dirname(__FILE__))) . '/dwoo/function.survey_name.php'); $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us if (!isset($configdata['artefactid'])) { return ''; } $id = $configdata['artefactid']; $survey = $instance->get_artefact_instance($id); $showresponses = isset($configdata['showresponses']) ? $configdata['showresponses'] : false; $showresults = isset($configdata['showresults']) ? $configdata['showresults'] : true; $showchart = isset($configdata['showchart']) ? $configdata['showchart'] : true; $palette = isset($configdata['palette']) ? $configdata['palette'] : 'default'; $legend = isset($configdata['legend']) ? $configdata['legend'] : 'key'; $fonttype = isset($configdata['fonttype']) ? $configdata['fonttype'] : 'sans'; $fontsize = isset($configdata['fontsize']) ? $configdata['fontsize'] : 10; $height = isset($configdata['height']) ? $configdata['height'] : 250; $width = isset($configdata['width']) ? $configdata['width'] : 400; $smarty = smarty_core(); //$smarty->addPlugin('survey_name', 'Dwoo_Plugin_survey_name'); $smarty->assign('RESPONSES', $showresponses ? true : false); $smarty->assign('responseshtml', ArtefactTypeSurvey::build_user_responses_output_html($survey->get('title'), unserialize($survey->get('description')))); $smarty->assign('RESULTS', $showresults ? true : false); $smarty->assign('resultshtml', ArtefactTypeSurvey::build_user_responses_summary_html($survey->get('title'), unserialize($survey->get('description')))); $smarty->assign('CHART', $showchart ? true : false); $smarty->assign('charturl', get_config('wwwroot') . 'artefact/survey/chart.php?id=' . $id . '&width=' . $width . '&height=' . $height . '&palette=' . $palette . '&legend=' . $legend . '&fonttype=' . $fonttype . '&fontsize=' . $fontsize); return $smarty->fetch('blocktype:survey:survey.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $configdata = $instance->get('configdata'); $configdata['viewid'] = $instance->get('view'); $configdata['simpledisplay'] = true; // This can be either an image or profileicon. They both implement // render_self $result = ''; $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null; if ($artefactid) { $artefact = $instance->get_artefact_instance($artefactid); $result = $artefact->render_self($configdata); $result = $result['html']; require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($configdata['viewid']); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); } $smarty = smarty_core(); if ($artefactid) { $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); } $smarty->assign('html', $result); return $smarty->fetch('blocktype:folder:folder.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us if (!isset($configdata['artefactid'])) { return ''; } $id = $configdata['artefactid']; $image = $instance->get_artefact_instance($id); $wwwroot = get_config('wwwroot'); $viewid = $instance->get('view'); if ($image instanceof ArtefactTypeProfileIcon) { $src = $wwwroot . 'thumb.php?type=profileiconbyid&id=' . $id; $description = $image->get('title'); } else { $src = $wwwroot . 'artefact/file/download.php?file=' . $id . '&view=' . $viewid; $description = $image->get('description'); } if (!empty($configdata['width'])) { $src .= '&maxwidth=' . $configdata['width']; } require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($viewid); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($image, $view, $instance->get('id'), true, $editing); $smarty = smarty_core(); $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); $smarty->assign('url', $wwwroot . 'artefact/artefact.php?artefact=' . $id . '&view=' . $viewid); $smarty->assign('src', $src); $smarty->assign('description', $description); $smarty->assign('showdescription', !empty($configdata['showdescription']) && !empty($description)); return $smarty->fetch('blocktype:image:image.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us $configdata['viewid'] = $instance->get('view'); $result = ''; $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null; if ($artefactid) { $artefact = $instance->get_artefact_instance($artefactid); if (!file_exists($artefact->get_path())) { return; } $result = clean_html(file_get_contents($artefact->get_path())); require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($configdata['viewid']); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); } $smarty = smarty_core(); if ($artefactid) { $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); } $smarty->assign('html', $result); return $smarty->fetch('blocktype:html:html.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us $configdata['viewid'] = $instance->get('view'); // This can be either an image or profileicon. They both implement // render_self $result = ''; if (isset($configdata['artefactid'])) { $image = $instance->get_artefact_instance($configdata['artefactid']); if ($image instanceof ArtefactTypeProfileIcon) { $src = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $configdata['artefactid']; $description = $image->get('title'); } else { $src = get_config('wwwroot') . 'artefact/file/download.php?file=' . $configdata['artefactid']; $src .= '&view=' . $instance->get('view'); $description = $image->get('description'); } if (!empty($configdata['width'])) { $src .= '&maxwidth=' . $configdata['width']; } $result = '<div class="center"><div>'; $result .= '<a href="' . get_config('wwwroot') . 'view/artefact.php?artefact=' . $configdata['artefactid'] . '&view=' . $instance->get('view') . '"><img src="' . hsc($src) . '" alt="' . hsc($description) . '"></a>'; $result .= '</div>'; $description = is_a($image, 'ArtefacttypeImage') ? $image->get('description') : $image->get('title'); if (!empty($configdata['showdescription']) && $description) { $result .= '<p>' . hsc($description) . '</p>'; } $result .= '</div>'; } return $result; }
/** * 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'])) { return $bi->get_artefact_instance($configdata['artefactid'])->get('title'); } return ''; }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; require_once get_config('docroot') . 'lib/view.php'; $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us $configdata['viewid'] = $instance->get('view'); $view = new View($configdata['viewid']); $group = $view->get('group'); $result = ''; $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null; if ($artefactid) { $artefact = $instance->get_artefact_instance($configdata['artefactid']); if (!file_exists($artefact->get_path())) { return ''; } $urlbase = get_config('wwwroot'); // edit view doesn't use subdomains, neither do groups if (get_config('cleanurls') && get_config('cleanurlusersubdomains') && !$editing && empty($group)) { $viewauthor = new User(); $viewauthor->find_by_id($view->get('owner')); $viewauthorurlid = $viewauthor->get('urlid'); if ($urlallowed = !is_null($viewauthorurlid) && strlen($viewauthorurlid)) { $urlbase = profile_url($viewauthor) . '/'; } } // Send the current language to the pdf viewer $language = current_language(); $language = str_replace('_', '-', substr($language, 0, substr_count($language, '_') > 0 ? 5 : 2)); if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) { // In case the language file exists as a string with both lower and upper case, eg fr_FR we test for this $language = substr($language, 0, 2) . '-' . strtoupper(substr($language, 0, 2)); if (!file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) { // In case we fail to find a language of 5 chars, eg pt_BR (Portugese, Brazil) we try the 'parent' pt (Portugese) $language = substr($language, 0, 2); if ($language != 'en' && !file_exists(get_config('docroot') . 'artefact/file/blocktype/pdf/js/pdfjs/web/locale/' . $language . '/viewer.properties')) { $language = 'en-GB'; } } } $result = '<iframe src="' . $urlbase . 'artefact/file/blocktype/pdf/viewer.php?editing=' . $editing . '&ingroup=' . !empty($group) . '&file=' . $artefactid . '&lang=' . $language . '&view=' . $instance->get('view') . '" width="100%" height="500" frameborder="0"></iframe>'; require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($configdata['viewid']); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); } $smarty = smarty_core(); if ($artefactid) { $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); } $smarty->assign('html', $result); return $smarty->fetch('blocktype:pdf:pdfrender.tpl'); }
/** * Returns a list of artefact IDs that are in this blockinstance. * * Normally this would just include the blogpost ID itself (children such * as attachments don't need to be included here, they're handled by the * artefact parent cache). But people might just link to artefacts without * using the attachment facility. There's nothing wrong with them doing * that, so if they do we should scrape the post looking for such links and * include those artefacts as being part of this blockinstance. * * @return array List of artefact IDs that are 'in' this blogpost - all * the blogpost ID plus links to other artefacts that are * part of the blogpost text. Note that proper artefact * children, such as blog post attachments, aren't included - * the artefact parent cache is used for them * @see PluginBlocktypeBlog::get_artefacts() */ public static function get_artefacts(BlockInstance $instance) { $configdata = $instance->get('configdata'); $artefacts = array(); if (isset($configdata['artefactid'])) { $artefacts[] = $configdata['artefactid']; // Add all artefacts found in the blogpost text $blogpost = $instance->get_artefact_instance($configdata['artefactid']); $artefacts = array_unique(array_merge($artefacts, $blogpost->get_referenced_artefacts_from_postbody())); } return $artefacts; }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us $configdata['viewid'] = $instance->get('view'); if (isset($configdata['artefactid'])) { $pdf = $instance->get_artefact_instance($configdata['artefactid']); if (!file_exists($pdf->get_path())) { return ''; } return '<iframe src="' . get_config('wwwroot') . 'artefact/file/blocktype/pdf/viewer.php?file=' . $configdata['artefactid'] . '&view=' . $instance->get('view') . '" width="100%" height="500" frameborder="0"></iframe>'; } return ''; }
public static function render_instance(BlockInstance $instance, $editing = false) { // Check if XSLT extension is loaded properly, because we will need it... // The XSL extension implements the XSL standard, performing XSLT transformations using the libxslt library. $xslext = extension_loaded('xsl'); if (!$xslext) { $missingextensions = array(); !$xslext && ($missingextensions[] = 'xsl'); $errormsg = '<p>' . get_string('europassextensionmissing', 'artefact.europass') . '</p>'; $errormsg .= '<ul>'; foreach ($missingextensions as $extension) { $errormsg .= '<li><a href="http://www.php.net/' . $extension . '">' . $extension . '</a></li>'; } $errormsg .= '</ul>'; return $errormsg; exit; } require_once get_config('docroot') . 'artefact/lib.php'; $smarty = smarty_core(); $configdata = $instance->get('configdata'); $configdata['viewid'] = $instance->get('view'); // Get data about the resume field in this blockinstance if (!empty($configdata['artefactid'])) { $europassfield = $instance->get_artefact_instance($configdata['artefactid']); if ($europassfield->get('artefacttype') != 'application') { $rendered = $europassfield->render_self($configdata); $result = $rendered['html']; if (!empty($rendered['javascript'])) { $result .= '<script type="text/javascript">' . $rendered['javascript'] . '</script>'; } } else { require_once get_config('docroot') . 'artefact/europass/lib/locale.php'; $personalinformation = null; try { $personalinformation = artefact_instance_from_type('personalinformation'); } catch (Exception $e) { } if (!empty($personalinformation)) { $gender = $personalinformation->get_composite('gender'); } else { $gender = null; } $occupation = get_occupation($europassfield->get('description'), get_config('lang'), $gender); $result = $occupation['label']; } return $result; } return ''; }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us $configdata['viewid'] = $instance->get('view'); $result = ''; if (isset($configdata['artefactid'])) { $html = $instance->get_artefact_instance($configdata['artefactid']); if (!file_exists($html->get_path())) { return; } $result = clean_html(file_get_contents($html->get_path())); } return $result; }
public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $configdata = $instance->get('configdata'); $configdata['viewid'] = $instance->get('view'); $configdata['simpledisplay'] = true; // This can be either an image or profileicon. They both implement // render_self $result = ''; if (isset($configdata['artefactid'])) { $folder = $instance->get_artefact_instance($configdata['artefactid']); $result = $folder->render_self($configdata); $result = $result['html']; } return $result; }
public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $smarty = smarty_core(); $configdata = $instance->get('configdata'); $configdata['viewid'] = $instance->get('view'); // Get data about the resume field in this blockinstance if (!empty($configdata['artefactid'])) { $resumefield = $instance->get_artefact_instance($configdata['artefactid']); $rendered = $resumefield->render_self($configdata); $result = $rendered['html']; if (!empty($rendered['javascript'])) { $result .= '<script type="text/javascript">' . $rendered['javascript'] . '</script>'; } return $result; } return ''; }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); if (empty($configdata['artefactid'])) { return ''; } $result = self::get_js_source(); require_once get_config('docroot') . 'artefact/lib.php'; $artefact = $instance->get_artefact_instance($configdata['artefactid']); $width = !empty($configdata['width']) ? hsc($configdata['width']) : '300'; $height = !empty($configdata['height']) ? hsc($configdata['height']) : '300'; $mimetype = $artefact->get('filetype'); $mimetypefiletypes = self::get_allowed_mimetype_filetypes(); if (!isset($mimetypefiletypes[$mimetype])) { return get_string('typeremoved', 'blocktype.file/internalmedia'); } $callbacks = self::get_all_filetype_players(); $result .= '<div class="mediaplayer-container center"><div class="mediaplayer">' . call_static_method('PluginBlocktypeInternalmedia', $callbacks[$mimetypefiletypes[$mimetype]], $artefact, $instance, $width, $height) . '</div></div>'; return $result; }
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; }
public static function render_instance(BlockInstance $instance, $editing = false) { // Check if XSLT extension is loaded properly, because we will need it... // The XSL extension implements the XSL standard, performing XSLT transformations using the libxslt library. $xslext = extension_loaded('xsl'); if (!$xslext) { $missingextensions = array(); !$xslext && ($missingextensions[] = 'xsl'); $errormsg = '<p>' . get_string('europassextensionmissing', 'artefact.europass') . '</p>'; $errormsg .= '<ul>'; foreach ($missingextensions as $extension) { $errormsg .= '<li><a href="http://www.php.net/' . $extension . '">' . $extension . '</a></li>'; } $errormsg .= '</ul>'; return $errormsg; exit; } require_once get_config('docroot') . 'artefact/lib.php'; $smarty = smarty_core(); $configdata = $instance->get('configdata'); $configdata['viewid'] = $instance->get('view'); // Get data about the language field in this blockinstance if (!empty($configdata['artefactid'])) { $mylanguages = $instance->get_artefact_instance($configdata['artefactid']); $rendered = $mylanguages->render_self($configdata); $result = $rendered['html']; if (!empty($rendered['javascript'])) { $result .= '<script type="text/javascript">' . $rendered['javascript'] . '</script>'; } // If we are displaying otherlanguage table, then add link to CEF level definitions... if ($mylanguages->get('artefacttype') == 'otherlanguage') { $l = substr(set_default_locale(get_config('lang')), 0, 2); $result .= '<a href="http://europass.cedefop.europa.eu/LanguageSelfAssessmentGrid/' . $l . '" target="_blank">' . get_string('language-foreign-CEF-level', 'artefact.europass') . '</a>'; } return $result; } return ''; }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); $viewid = $instance->get('view'); $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null; if (empty($artefactid)) { return ''; } $result = self::get_js_source(); require_once get_config('docroot') . 'artefact/lib.php'; $artefact = $instance->get_artefact_instance($artefactid); $defaultwidth = get_config_plugin('blocktype', 'internalmedia', 'width') ? get_config_plugin('blocktype', 'internalmedia', 'width') : 300; $defaultheight = get_config_plugin('blocktype', 'internalmedia', 'height') ? get_config_plugin('blocktype', 'internalmedia', 'height') : 300; $width = !empty($configdata['width']) ? hsc($configdata['width']) : $defaultwidth; $height = !empty($configdata['height']) ? hsc($configdata['height']) : $defaultheight; $mimetype = $artefact->get('filetype'); $mimetypefiletypes = self::get_allowed_mimetype_filetypes(); if (!isset($mimetypefiletypes[$mimetype])) { return get_string('typeremoved', 'blocktype.file/internalmedia'); } $callbacks = self::get_all_filetype_players(); $result .= '<div class="mediaplayer-container center"><div class="mediaplayer">' . call_static_method('PluginBlocktypeInternalmedia', $callbacks[$mimetypefiletypes[$mimetype]], $artefact, $instance, $width, $height) . '</div></div>'; if ($artefactid) { require_once get_config('docroot') . 'artefact/comment/lib.php'; require_once get_config('docroot') . 'lib/view.php'; $view = new View($viewid); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, $instance->get('id'), true, $editing); } $smarty = smarty_core(); if ($artefactid) { $smarty->assign('commentcount', $commentcount); $smarty->assign('comments', $comments); } $smarty->assign('html', $result); return $smarty->fetch('blocktype:internalmedia:internalmedia.tpl'); }
public static function instance_config_form(BlockInstance $instance) { global $USER; safe_require('artefact', 'blog'); $configdata = $instance->get('configdata'); if (!empty($configdata['artefactid'])) { $blog = $instance->get_artefact_instance($configdata['artefactid']); } $elements = array(); // If the blog post in this block is owned by the owner of the View, // then the block can be configured. Otherwise, the blog post was // copied in from another View. We won't confuse users by asking them to // choose a blog post to put in this block, when the one that is // currently in it isn't choosable. // // Note: the owner check will have to change when we do group/site // blogs if (empty($configdata['artefactid']) || $blog->get('owner') == $USER->get('id')) { $publishedposts = get_column_sql(' SELECT a.id FROM {artefact} a INNER JOIN {artefact_blog_blogpost} p ON p.blogpost = a.id WHERE p.published = 1 AND a.owner= ?', array($USER->get('id'))); $elements[] = self::artefactchooser_element(isset($configdata['artefactid']) ? $configdata['artefactid'] : null, $publishedposts); $elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'blogpost'); } else { $elements[] = array('type' => 'html', 'name' => 'notice', 'value' => '<div class="metadata">' . get_string('blogcopiedfromanotherview', 'artefact.blog', get_string('blogpost', 'artefact.blog')) . '</div>'); } return $elements; }
/** * is called by the cron-job to process the notifications stored into * watchlist_queue. */ function watchlist_process_notifications() { $delayMin = get_config('watchlistnotification_delay'); $comparetime = time() - $delayMin * 60; $sql = "SELECT usr, view, MAX(changed_on) AS time\n FROM {watchlist_queue}\n GROUP BY usr, view"; $results = get_records_sql_array($sql, array()); if (false === $results) { return; } foreach ($results as $viewuserdaterow) { if ($viewuserdaterow->time > date('Y-m-d H:i:s', $comparetime)) { continue; } // don't send a notification if only blockinstances are referenced // that were deleted (block exists but corresponding // block_instance doesn't) $sendnotification = false; $blockinstance_ids = get_column('watchlist_queue', 'block', 'usr', $viewuserdaterow->usr, 'view', $viewuserdaterow->view); if (is_array($blockinstance_ids)) { $blockinstance_ids = array_unique($blockinstance_ids); } $viewuserdaterow->blocktitles = array(); // need to check if view has an owner, group or institution $view = get_record('view', 'id', $viewuserdaterow->view); if (empty($view->owner) && empty($view->group) && empty($view->institution)) { continue; } // ignore root pages, owner = 0, this account is not meant to produce content if (isset($view->owner) && empty($view->owner)) { continue; } foreach ($blockinstance_ids as $blockinstance_id) { if (empty($blockinstance_id)) { // if no blockinstance is given, assume that the form itself // was changed, e.g. the theme, or a block was removed $sendnotification = true; continue; } require_once get_config('docroot') . 'blocktype/lib.php'; try { $block = new BlockInstance($blockinstance_id); } catch (BlockInstanceNotFoundException $exc) { // maybe the block was deleted continue; } $blocktype = $block->get('blocktype'); $title = ''; // try to get title rendered by plugin-class safe_require('blocktype', $blocktype); if (class_exists(generate_class_name('blocktype', $blocktype))) { $title = $block->get_title(); } else { log_warn('class for blocktype could not be loaded: ' . $blocktype); $title = $block->get('title'); } // if no title was given to the blockinstance, try to get one // from the artefact if (empty($title)) { $configdata = $block->get('configdata'); if (array_key_exists('artefactid', $configdata)) { try { $artefact = $block->get_artefact_instance($configdata['artefactid']); $title = $artefact->get('title'); } catch (Exception $exc) { log_warn('couldn\'t identify title of blockinstance ' . $block->get('id') . $exc->getMessage()); } } } // still no title, maybe the default-name for the blocktype if (empty($title)) { $title = get_string('title', 'blocktype.' . $blocktype); } // no title could be retrieved, so let's tell the user at least // what type of block was changed if (empty($title)) { $title = '[' . $blocktype . '] (' . get_string('nonamegiven', 'activity') . ')'; } $viewuserdaterow->blocktitles[] = $title; $sendnotification = true; } // only send notification if there is something to talk about (don't // send notification for example when new blockelement was aborted) if ($sendnotification) { try { $watchlistnotification = new ActivityTypeWatchlistnotification($viewuserdaterow, false); $watchlistnotification->notify_users(); } catch (ViewNotFoundException $exc) { // Seems like the view has been deleted, don't do anything } catch (SystemException $exc) { // if the view that was changed doesn't have an owner } } delete_records('watchlist_queue', 'usr', $viewuserdaterow->usr, 'view', $viewuserdaterow->view); } }
public static function instance_config_form(BlockInstance $instance) { global $USER; $instance->set('artefactplugin', 'annotation'); // Get the saved configs in the artefact $configdata = $instance->get('configdata'); if (!($height = get_config('blockeditorheight'))) { $cfheight = param_integer('cfheight', 0); $height = $cfheight ? $cfheight * 0.7 : 150; } // Default annotation text. $text = ''; $tags = ''; $artefactid = ''; $readonly = false; $textreadonly = false; $view = $instance->get_view(); if (!empty($configdata['artefactid'])) { $artefactid = $configdata['artefactid']; try { $artefact = $instance->get_artefact_instance($artefactid); // Get the annotation record -> to get the artefact it's linked to. $annotation = new ArtefactTypeAnnotation($artefactid); // Get the total annotation feedback inserted so far by anyone. $totalannotationfeedback = ArtefactTypeAnnotationfeedback::count_annotation_feedback($artefactid, array($view->get('id')), array($annotation->get('artefact'))); $readonly = $artefact->get('owner') !== $view->get('owner') || $artefact->get('group') !== $view->get('group') || $artefact->get('institution') !== $view->get('institution') || $artefact->get('locked') || !$USER->can_edit_artefact($artefact); if (isset($totalannotationfeedback[$view->get('id')])) { $textreadonly = $totalannotationfeedback[$view->get('id')]->total > 0; } $text = $artefact->get('description'); $tags = $artefact->get('tags'); } catch (ArtefactNotFoundException $e) { unset($artefactid); } } $elements = array('text' => array('type' => $textreadonly ? 'html' : 'wysiwyg', 'class' => '', 'title' => get_string('Annotation', 'artefact.annotation'), 'width' => '100%', 'height' => $height . 'px', 'defaultvalue' => $text, 'rules' => array('maxlength' => 65536)), 'annotationreadonlymsg' => array('type' => 'html', 'class' => 'message info' . ($textreadonly ? '' : ' hidden'), 'value' => get_string('annotationreadonlymessage', 'blocktype.annotation/annotation'), 'help' => true), 'allowfeedback' => array('type' => 'switchbox', 'title' => get_string('allowannotationfeedback', 'artefact.annotation'), 'defaultvalue' => !empty($artefact) ? $artefact->get('allowcomments') : 1), 'tags' => array('type' => 'tags', 'class' => $readonly ? 'hidden' : '', 'width' => '100%', 'title' => get_string('tags'), 'description' => get_string('tagsdescprofile'), 'defaultvalue' => $tags), 'tagsreadonly' => array('type' => 'html', 'class' => $readonly ? '' : 'hidden', 'width' => '100%', 'title' => get_string('tags'), 'value' => '<div id="instconf_tagsreadonly_display">' . (is_array($tags) ? hsc(join(', ', $tags)) : '') . '</div>')); if ($textreadonly) { // The annotation is displayed as html, need to populate its value. $elements['text']['value'] = $text; } return $elements; }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us $configdata['viewid'] = $instance->get('view'); $style = isset($configdata['style']) ? intval($configdata['style']) : 2; $copyright = null; // Needed to set Panoramio copyright later... $width = !empty($configdata['width']) ? $configdata['width'] : 75; switch ($style) { case 0: // thumbnails $template = 'thumbnails'; break; case 1: // slideshow $template = 'slideshow'; $width = !empty($configdata['width']) ? $configdata['width'] : 400; break; case 2: // square thumbnails $template = 'squarethumbs'; break; } $images = array(); $slimbox2 = get_config_plugin('blocktype', 'gallery', 'useslimbox2'); if ($slimbox2) { $slimbox2attr = 'lightbox_' . $instance->get('id'); } else { $slimbox2attr = null; } // if we're trying to embed external gallery (thumbnails or slideshow) if (isset($configdata['select']) && $configdata['select'] == 2) { $gallery = self::make_gallery_url($configdata['external']); if (empty($gallery)) { return get_string('externalnotsupported', 'blocktype.file/gallery'); } $url = isset($gallery['url']) ? hsc($gallery['url']) : null; $type = isset($gallery['type']) ? hsc($gallery['type']) : null; $var1 = isset($gallery['var1']) ? hsc($gallery['var1']) : null; $var2 = isset($gallery['var2']) ? hsc($gallery['var2']) : null; switch ($type) { case 'widget': /***************************** Roy Tanck's FLICKR WIDGET for Flickr RSS & Picasa RSS http://www.roytanck.com/get-my-flickr-widget/ *****************************/ $widget_sizes = array(100, 200, 300); $width = self::find_nearest($widget_sizes, $width); $images = urlencode(str_replace('&', '&', $url)); $template = 'imagecloud'; break; case 'picasa': // Slideshow if ($style == 1) { $picasa_show_sizes = array(144, 288, 400, 600, 800); $width = self::find_nearest($picasa_show_sizes, $width); $height = round($width * 0.75); $images = array('user' => $var1, 'gallery' => $var2); $template = 'picasashow'; } else { $picasa_thumbnails = array(32, 48, 64, 72, 104, 144, 150, 160); $width = self::find_nearest($picasa_thumbnails, $width); // If the Thumbnails should be Square... if ($style == 2) { $small = 's' . $width . '-c'; $URL = 'http://picasaweb.google.com/data/feed/api/user/' . $var1 . '/album/' . $var2 . '?kind=photo&thumbsize=' . $width . 'c'; } else { $small = 's' . $width; $URL = 'http://picasaweb.google.com/data/feed/api/user/' . $var1 . '/album/' . $var2 . '?kind=photo&thumbsize=' . $width; } $big = 's' . get_config_plugin('blocktype', 'gallery', 'previewwidth'); $xmlDoc = new DOMDocument('1.0', 'UTF-8'); $config = array(CURLOPT_URL => $URL, CURLOPT_RETURNTRANSFER => true); $result = mahara_http_request($config); $xmlDoc->loadXML($result->data); $photos = $xmlDoc->getElementsByTagNameNS('http://search.yahoo.com/mrss/', 'group'); foreach ($photos as $photo) { $children = $photo->cloneNode(true); $thumb = $children->getElementsByTagNameNS('http://search.yahoo.com/mrss/', 'thumbnail')->item(0)->getAttribute('url'); $description = null; if (isset($children->getElementsByTagNameNS('http://search.yahoo.com/mrss/', 'description')->item(0)->firstChild->nodeValue)) { $description = $children->getElementsByTagNameNS('http://search.yahoo.com/mrss/', 'description')->item(0)->firstChild->nodeValue; } $images[] = array('link' => str_replace($small, $big, $thumb), 'source' => $thumb, 'title' => $description, 'slimbox2' => $slimbox2attr); } } break; case 'flickr': // Slideshow if ($style == 1) { $flickr_show_sizes = array(400, 500, 700, 800); $width = self::find_nearest($flickr_show_sizes, $width); $height = round($width * 0.75); $images = array('user' => $var1, 'gallery' => $var2); $template = 'flickrshow'; } else { $width = 75; // Currently only thumbnail size, that Flickr supports $api_key = get_config_plugin('blocktype', 'gallery', 'flickrapikey'); $URL = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&extras=url_sq,url_t&photoset_id=' . $var2 . '&api_key=' . $api_key; $xmlDoc = new DOMDocument('1.0', 'UTF-8'); $config = array(CURLOPT_URL => $URL, CURLOPT_RETURNTRANSFER => true); $result = mahara_http_request($config); $xmlDoc->loadXML($result->data); $photos = $xmlDoc->getElementsByTagName('photo'); foreach ($photos as $photo) { // If the Thumbnails should be Square... if ($style == 2) { $thumb = $photo->getAttribute('url_sq'); $link = str_replace('_s.jpg', '_b.jpg', $thumb); } else { $thumb = $photo->getAttribute('url_t'); $link = str_replace('_t.jpg', '_b.jpg', $thumb); } $description = $photo->getAttribute('title'); $images[] = array('link' => $link, 'source' => $thumb, 'title' => $description, 'slimbox2' => $slimbox2attr); } } break; case 'panoramio': // Slideshow if ($style == 1) { $height = round($width * 0.75); $images = array('user' => $var1); $template = 'panoramioshow'; } else { $copyright = get_string('panoramiocopyright', 'blocktype.file/gallery'); $URL = 'http://www.panoramio.com/map/get_panoramas.php?set=' . $var1 . '&from=0&to=50&size=original&mapfilter=true'; $config = array(CURLOPT_URL => $URL, CURLOPT_RETURNTRANSFER => true); $result = mahara_http_request($config); $data = json_decode($result->data, true); foreach ($data['photos'] as $photo) { $link = str_replace('/original/', '/large/', $photo['photo_file_url']); // If the Thumbnails should be Square... if ($style == 2) { $thumb = str_replace('/original/', '/square/', $photo['photo_file_url']); $width = 60; // Currently only square thumbnail size, that Panoramio supports } else { $thumb = str_replace('/original/', '/thumbnail/', $photo['photo_file_url']); } $title = !empty($photo['photo_title']) ? $photo['photo_title'] : get_string('Photo', 'blocktype.file/gallery'); $description = '<a href="' . $photo['photo_url'] . '" target="_blank">' . $title . '</a>' . ' ' . get_string('by', 'blocktype.file/gallery') . ' ' . '<a href="' . $photo['owner_url'] . '" target="_blank">' . $photo['owner_name'] . '</a>'; $images[] = array('link' => $link, 'source' => $thumb, 'title' => $description, 'slimbox2' => $slimbox2attr); } } break; case 'photobucket': // Slideshow if ($style == 1) { $height = round($width * 0.75); $images = array('url' => $url, 'user' => $var1, 'album' => $var2); $template = 'photobucketshow'; } else { $consumer_key = get_config_plugin('blocktype', 'gallery', 'pbapikey'); // PhotoBucket API key $consumer_secret = get_config_plugin('blocktype', 'gallery', 'pbapiprivatekey'); //PhotoBucket API private key $oauth_signature_method = 'HMAC-SHA1'; $oauth_version = '1.0'; $oauth_timestamp = time(); $mt = microtime(); $rand = mt_rand(); $oauth_nonce = md5($mt . $rand); $method = 'GET'; $albumname = $var1 . '/' . $var2; $api_url = 'http://api.photobucket.com/album/' . urlencode($albumname); $params = null; $paramstring = 'oauth_consumer_key=' . $consumer_key . '&oauth_nonce=' . $oauth_nonce . '&oauth_signature_method=' . $oauth_signature_method . '&oauth_timestamp=' . $oauth_timestamp . '&oauth_version=' . $oauth_version; $base = urlencode($method) . '&' . urlencode($api_url) . '&' . urlencode($paramstring); $oauth_signature = base64_encode(hash_hmac('sha1', $base, $consumer_secret . '&', true)); $URL = $api_url . '?' . $paramstring . '&oauth_signature=' . urlencode($oauth_signature); $xmlDoc = new DOMDocument('1.0', 'UTF-8'); $config = array(CURLOPT_URL => $URL, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true); $result = mahara_http_request($config); $xmlDoc->loadXML($result->data); $xmlDoc2 = new DOMDocument('1.0', 'UTF-8'); $config2 = array(CURLOPT_URL => $xmlDoc->getElementsByTagName('url')->item(0)->firstChild->nodeValue, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true); $result2 = mahara_http_request($config2); $xmlDoc2->loadXML($result->data); $photos = $xmlDoc2->getElementsByTagName('media'); foreach ($photos as $photo) { $children = $photo->cloneNode(true); $link = $children->getElementsByTagName('url')->item(0)->firstChild->nodeValue; $thumb = $children->getElementsByTagName('thumb')->item(0)->firstChild->nodeValue; $description = null; if (isset($children->getElementsByTagName('description')->item(0)->firstChild->nodeValue)) { $description = $children->getElementsByTagName('description')->item(0)->firstChild->nodeValue; } $images[] = array('link' => $link, 'source' => $thumb, 'title' => $description, 'slimbox2' => $slimbox2attr); } } break; case 'windowslive': // Slideshow if ($style == 1) { $images = array('url' => $url, 'user' => $var1, 'album' => $var2); $template = 'windowsliveshow'; } else { $config = array(CURLOPT_URL => str_replace(' ', '%20', $url), CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true); $result = mahara_http_request($config); $data = $result->data; // Extract data about images and thumbs from HTML source - hack! preg_match_all("#previewImageUrl: '([a-zA-Z0-9\\_\\-\\.\\\\/]+)'#", $data, $photos); preg_match_all("#thumbnailImageUrl: '([a-zA-Z0-9\\_\\-\\.\\\\/]+)'#", $data, $thumbs); for ($i = 0; $i < sizeof($photos[1]); $i++) { $images[] = array('link' => str_replace(array('\\x3a', '\\x2f', '\\x25', '\\x3fpsid\\x3d1'), array(':', '/', '%', ''), $photos[1][$i]), 'source' => str_replace(array('\\x3a', '\\x2f', '\\x25', '\\x3fpsid\\x3d1'), array(':', '/', '%', ''), $thumbs[1][$i]), 'title' => null, 'slimbox2' => $slimbox2attr); } } break; } } else { safe_require('artefact', 'file'); $artefactids = array(); if (isset($configdata['select']) && $configdata['select'] == 1 && is_array($configdata['artefactids'])) { $artefactids = $configdata['artefactids']; } else { if (!empty($configdata['artefactid'])) { // Get descendents of this folder. $artefactids = artefact_get_descendants(array(intval($configdata['artefactid']))); } } // This can be either an image or profileicon. They both implement // render_self foreach ($artefactids as $artefactid) { $image = $instance->get_artefact_instance($artefactid); if ($image instanceof ArtefactTypeProfileIcon) { $src = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $artefactid; $description = $image->get('title'); } else { if ($image instanceof ArtefactTypeImage) { $src = get_config('wwwroot') . 'artefact/file/download.php?file=' . $artefactid; $src .= '&view=' . $instance->get('view'); $description = $image->get('description'); } else { continue; } } if ($slimbox2) { $link = $src . '&maxwidth=' . get_config_plugin('blocktype', 'gallery', 'previewwidth'); } else { $link = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $artefactid . '&view=' . $instance->get('view'); } // If the Thumbnails are Square or not... if ($style == 2) { $src .= '&size=' . $width . 'x' . $width; $height = $width; } else { $src .= '&maxwidth=' . $width; $imgwidth = $image->get('width'); $imgheight = $image->get('height'); $height = $imgwidth > $width ? intval($width / $imgwidth * $imgheight) : $imgheight; } $images[] = array('link' => $link, 'source' => $src, 'height' => $height, 'title' => $image->get('description'), 'slimbox2' => $slimbox2attr); } } $smarty = smarty_core(); $smarty->assign('instanceid', $instance->get('id')); $smarty->assign('count', count($images)); $smarty->assign('images', $images); $smarty->assign('showdescription', !empty($configdata['showdescription']) ? $configdata['showdescription'] : false); $smarty->assign('width', $width); $smarty->assign('captionwidth', get_config_plugin('blocktype', 'gallery', 'photoframe') ? $width + 8 : $width); if (isset($height)) { $smarty->assign('height', $height); } if (isset($needsapikey)) { $smarty->assign('needsapikey', $needsapikey); } $smarty->assign('frame', get_config_plugin('blocktype', 'gallery', 'photoframe')); $smarty->assign('copyright', $copyright); return $smarty->fetch('blocktype:gallery:' . $template . '.tpl'); }
/** * Set the text property of the block config so that exports can be imported * into older versions. * * @param BlockInstance $bi The blockinstance to export the config for. * @return array The config for the blockinstance */ public static function export_blockinstance_config_leap(BlockInstance $bi) { $configdata = $bi->get('configdata'); $result = array(); $text = ''; $license = ''; $licensor = ''; $licensorurl = ''; $tags = ''; if (!empty($configdata['artefactid'])) { $result['artefactid'] = json_encode(array($configdata['artefactid'])); $note = $bi->get_artefact_instance($configdata['artefactid']); $text = $note->get('description'); $tags = $note->get('tags'); $license = $note->get('license'); $licensor = $note->get('licensor'); $licensorurl = $note->get('licensorurl'); } $result['text'] = json_encode(array($text)); $result['tags'] = json_encode(array($tags)); $result['license '] = json_encode(array($license)); $result['licensor'] = json_encode(array($licensor)); $result['licensorurl'] = json_encode(array($licensorurl)); return $result; }
/** * Set the text property of the block config so that exports can be imported * into older versions. * * @param BlockInstance $bi The blockinstance to export the config for. * @return array The config for the blockinstance */ public static function export_blockinstance_config_leap(BlockInstance $bi) { $configdata = $bi->get('configdata'); $result = array(); $text = ''; $information = ''; if (!empty($configdata['artefactid'])) { $result['artefactid'] = json_encode(array($configdata['artefactid'])); $note = $bi->get_artefact_instance($configdata['artefactid']); $text = $note->get('note'); $information = $note->get('description'); } $result['text'] = json_encode(array($text)); $result['information'] = json_encode(array($information)); return $result; }
/** * Returns a list of artefact IDs that are in this blockinstance. * * {@internal{Because links to artefacts within blogposts don't count * as making those artefacts 'children' of the blog post, we have to add * them directly to the blog.}} * * @return array List of artefact IDs that are 'in' this blog - all * blogposts in it plus all links to other artefacts that are * part of the blogpost text. Note that proper artefact * children, such as blog post attachments, aren't included - * the artefact parent cache is used for them * @see PluginBlocktypeBlogPost::get_artefacts() */ public static function get_artefacts(BlockInstance $instance) { $configdata = $instance->get('configdata'); $artefacts = array(); if (isset($configdata['artefactid'])) { $artefacts[] = $configdata['artefactid']; // Artefacts that are linked to directly in blog post text aren't // strictly children of blog posts, which means that // artefact_in_view won't understand that they are "within the // blog". We have to help it here directly by working out what // artefacts are linked to in all of this blog's blog posts. $blog = $instance->get_artefact_instance($configdata['artefactid']); if ($blogposts = $blog->get_children_instances()) { foreach ($blogposts as $blogpost) { if ($blogpost->get('published')) { $artefacts[] = $blogpost->get('id'); $artefacts = array_merge($artefacts, $blogpost->get_referenced_artefacts_from_postbody()); } } $artefacts = array_unique($artefacts); } } return $artefacts; }
public static function instance_config_form(BlockInstance $instance) { global $USER; safe_require('artefact', 'blog'); $configdata = $instance->get('configdata'); if (!empty($configdata['artefactid'])) { $blog = $instance->get_artefact_instance($configdata['artefactid']); } $elements = array(); // If the blog post in this block is owned by the owner of the View, // then the block can be configured. Otherwise, the blog post was // copied in from another View. We won't confuse users by asking them to // choose a blog post to put in this block, when the one that is // currently in it isn't choosable. $institution = $instance->get('view_obj')->get('institution'); $group = $instance->get('view_obj')->get('group'); if (empty($configdata['artefactid']) || ArtefactTypeBlog::can_edit_blog($blog, $institution, $group)) { $sql = "SELECT a.id FROM {artefact} a\n INNER JOIN {artefact_blog_blogpost} p ON p.blogpost = a.id\n WHERE p.published = 1"; if ($institution) { $sql .= " AND a.institution = ?"; $where = array($institution); } else { if ($group) { $sql .= " AND a.group = ?"; $where = array($group); } else { $sql .= " AND a.owner = ?"; $where = array($USER->get('id')); } } $publishedposts = get_column_sql($sql, $where); $elements[] = self::artefactchooser_element(isset($configdata['artefactid']) ? $configdata['artefactid'] : null, $publishedposts); $elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'blogpost'); } else { $elements[] = array('type' => 'html', 'name' => 'notice', 'value' => '<div class="metadata">' . get_string('blogcopiedfromanotherview', 'artefact.blog', get_string('blogpost', 'artefact.blog')) . '</div>'); } return $elements; }