Beispiel #1
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     $configdata = $instance->get('configdata');
     $result = '';
     $artefactid = isset($configdata['artefactid']) ? $configdata['artefactid'] : null;
     if ($artefactid) {
         require_once get_config('docroot') . 'artefact/lib.php';
         $artefact = $instance->get_artefact_instance($artefactid);
         $configdata['hidetitle'] = true;
         $configdata['countcomments'] = true;
         $configdata['viewid'] = $instance->get('view');
         $configdata['blockid'] = $instance->get('id');
         $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:blogpost:blogpost.tpl');
 }
Beispiel #2
0
 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');
 }
Beispiel #3
0
 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');
 }
Beispiel #4
0
 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');
 }
Beispiel #5
0
 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');
 }
Beispiel #6
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     $configdata = $instance->get('configdata');
     if (!empty($configdata['artefactid'])) {
         safe_require('artefact', 'file');
         safe_require('artefact', 'comment');
         $artefact = $instance->get_artefact_instance($configdata['artefactid']);
         $viewid = $instance->get('view');
         $text = ArtefactTypeFolder::append_view_url($artefact->get('note'), $viewid);
         $information = ArtefactTypeFolder::append_view_url($artefact->get('description'), $viewid);
         $literature = $configdata['literature'];
         $smarty = smarty_core();
         $smarty->assign('text', $text);
         $smarty->assign('information', $information);
         $smarty->assign('literature', $literature);
         $attachments = $artefact->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($viewid) ? $viewid : 0);
                 $attachment->downloadpath = get_config('wwwroot') . 'artefact/file/download.php?file=' . $attachment->id;
                 if (isset($viewid)) {
                     $attachment->downloadpath .= '&view=' . $viewid;
                 }
             }
             $smarty->assign('attachments', $attachments);
             $smarty->assign('count', count($attachments));
         }
         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->assign('commentcount', $commentcount);
         $smarty->assign('comments', $comments);
         $smarty->assign('blockid', $instance->get('id'));
         return $smarty->fetch('blocktype:eselmagraduation:content.tpl');
     }
     return '';
 }
Beispiel #7
0
 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');
 }
Beispiel #8
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     global $USER;
     $configdata = $instance->get('configdata');
     $view = $instance->get('view');
     $full = isset($configdata['full']) ? $configdata['full'] : false;
     $results = array();
     $smarty = smarty_core();
     $smarty->assign('view', $view);
     $viewownerdisplay = null;
     // Display all posts, from all blogs, owned by this user
     $tagsin = $tagsout = array();
     $results = self::get_blog_posts_in_block($instance, $tagsin, $tagsout);
     if ($tagsin || $tagsout) {
         $smarty->assign('blockid', $instance->get('id'));
         $smarty->assign('editing', $editing);
         if ($editing) {
             // Get list of blogs owned by this user to create the "Add new post" shortcut while editing
             $viewowner = $instance->get_view()->get('owner');
             if (!$viewowner || !($blogs = get_records_select_array('artefact', 'artefacttype = \'blog\' AND owner = ?', array($viewowner), 'title ASC', 'id, title'))) {
                 $blogs = array();
             }
             $smarty->assign('tagselect', implode(', ', $tagsin));
             $smarty->assign('blogs', $blogs);
         }
         // if posts are not found with the selected tag, notify the user
         if (!$results) {
             $smarty->assign('badtag', implode(', ', $tagsin));
             $smarty->assign('badnotag', implode(', ', $tagsout));
             return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl');
         }
         // update the view_artefact table so journal entries are accessible when this is the only block on the page
         // referencing this journal
         $dataobject = array('view' => $view, 'block' => $instance->get('id'));
         require_once get_config('docroot') . 'lib/view.php';
         $viewobj = new View($view);
         require_once get_config('docroot') . 'artefact/lib.php';
         safe_require('artefact', 'blog');
         safe_require('artefact', 'comment');
         foreach ($results as $result) {
             $dataobject["artefact"] = $result->parent;
             $result->postedbyon = get_string('postedbyon', 'artefact.blog', display_default_name($result->owner), format_date(strtotime($result->ctime)));
             $result->displaydate = format_date(strtotime($result->ctime));
             $artefact = new ArtefactTypeBlogpost($result->id);
             // get comments for this post
             $result->commentcount = count_records_select('artefact_comment_comment', "onartefact = {$result->id} AND private = 0 AND deletedby IS NULL");
             $allowcomments = $artefact->get('allowcomments');
             if (empty($result->commentcount) && empty($allowcomments)) {
                 $result->commentcount = null;
             }
             list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $viewobj, null, false);
             $result->comments = $comments;
             // get all tags for this post
             $taglist = get_records_array('artefact_tag', 'artefact', $result->id, "tag DESC");
             foreach ($taglist as $t) {
                 $result->taglist[] = $t->tag;
             }
             if ($full) {
                 $rendered = $artefact->render_self(array('viewid' => $view, 'details' => true, 'blockid' => $instance->get('id')));
                 $result->html = $rendered['html'];
                 if (!empty($rendered['javascript'])) {
                     $result->html .= '<script type="application/javascript">' . $rendered['javascript'] . '</script>';
                 }
             }
         }
         // check if the user viewing the page is the owner of the selected tag
         $owner = $results[0]->owner;
         if ($USER->id != $owner) {
             $viewownerdisplay = get_user_for_display($owner);
         }
         $smarty->assign('tagsin', $tagsin);
         $smarty->assign('tagsout', $tagsout);
     } else {
         if (!self::get_chooseable_tags()) {
             // error if block configuration fails
             $smarty->assign('configerror', get_string('notagsavailableerror', 'blocktype.blog/taggedposts'));
             return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl');
         } else {
             // error if block configuration fails
             $smarty->assign('configerror', get_string('configerror', 'blocktype.blog/taggedposts'));
             return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl');
         }
     }
     // add any needed links to the tags
     $tagstr = $tagomitstr = '';
     foreach ($tagsin as $key => $tag) {
         if ($key > 0) {
             $tagstr .= ', ';
         }
         $tagstr .= $viewownerdisplay ? '"' . $tag . '"' : '"<a href="' . get_config('wwwroot') . 'tags.php?tag=' . $tag . '&sort=name&type=text">' . $tag . '</a>"';
     }
     if (!empty($tagsout)) {
         foreach ($tagsout as $key => $tag) {
             if ($key > 0) {
                 $tagomitstr .= ', ';
             }
             $tagomitstr .= $viewownerdisplay ? '"' . $tag . '"' : '"<a href="' . get_config('wwwroot') . 'tags.php?tag=' . $tag . '&sort=name&type=text">' . $tag . '</a>"';
         }
     }
     $blockheading = get_string('blockheadingtags', 'blocktype.blog/taggedposts', count($tagsin), $tagstr);
     $blockheading .= !empty($tagomitstr) ? get_string('blockheadingtagsomit', 'blocktype.blog/taggedposts', count($tagsout), $tagomitstr) : '';
     $blockheading .= $viewownerdisplay ? ' ' . get_string('by', 'artefact.blog') . ' <a href="' . profile_url($viewownerdisplay) . '">' . display_name($viewownerdisplay) . '</a>' : '';
     $smarty->assign('full', $full);
     $smarty->assign('results', $results);
     $smarty->assign('blockheading', $blockheading);
     return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl');
 }
Beispiel #9
0
 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;
     $width = floor($width);
     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('&amp;', '&', $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 = 'https://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>' . '&nbsp;' . get_string('by', 'blocktype.file/gallery') . '&nbsp;' . '<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) {
                 // Determine the scaling for the fitting the image in the square of $width size
                 // Calculate the bigger, width vs height, to work out the ratio
                 $configwidth = $width - (get_config_plugin('blocktype', 'gallery', 'photoframe') ? 8 : 0);
                 // $width - photo frame padding
                 $imagewidth = $image->get('width');
                 $imageheight = $image->get('height');
                 if ($imagewidth > $imageheight) {
                     $ratio = $imagewidth / $configwidth;
                 } else {
                     $ratio = $imageheight / $configwidth;
                 }
                 $ratiowidth = floor($imagewidth / $ratio);
                 $ratioheight = floor($imageheight / $ratio);
                 // All image dimensions need to be bigger than 15px
                 // see function imagesize_data_to_internal_form()
                 $ratiowidth = $ratiowidth < 16 ? 16 : $ratiowidth;
                 $ratioheight = $ratioheight < 16 ? 16 : $ratioheight;
                 $topoffset = floor(($configwidth - $ratioheight) / 2);
                 $src .= '&size=' . $ratiowidth . 'x' . $ratioheight;
                 $height = $ratioheight;
             } 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, 'width' => !empty($ratiowidth) ? $ratiowidth : null, 'title' => $image->get('description'), 'slimbox2' => $slimbox2attr, 'squaredimensions' => $width, 'squaretop' => !empty($topoffset) ? $topoffset : null);
         }
     }
     $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);
     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);
     if (!empty($configdata['artefactid'])) {
         $artefact = $instance->get_artefact_instance($configdata['artefactid']);
         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->assign('commentcount', $commentcount);
         $smarty->assign('comments', $comments);
     }
     return $smarty->fetch('blocktype:gallery:' . $template . '.tpl');
 }
Beispiel #10
0
 /**
  * This function returns a list of posts in a given blog.
  *
  * @param integer
  * @param integer
  * @param integer
  * @param array
  */
 public static function get_posts($id, $limit, $offset, $viewoptions = null)
 {
     $results = array('limit' => $limit, 'offset' => $offset);
     // If viewoptions is null, we're getting posts for the my blogs area,
     // and we should get all posts & show drafts first.  Otherwise it's a
     // blog in a view, and we should only get published posts.
     $from = "\n            FROM {artefact} a LEFT JOIN {artefact_blog_blogpost} bp ON a.id = bp.blogpost\n            WHERE a.artefacttype = 'blogpost' AND a.parent = ?";
     if (!is_null($viewoptions)) {
         if (isset($viewoptions['before'])) {
             $from .= " AND a.ctime < '{$viewoptions['before']}'";
         }
         $from .= ' AND bp.published = 1';
     }
     $results['count'] = count_records_sql('SELECT COUNT(*) ' . $from, array($id));
     $data = get_records_sql_assoc('
         SELECT
             a.id, a.title, a.description, a.author, a.authorname, ' . db_format_tsfield('a.ctime', 'ctime') . ', ' . db_format_tsfield('a.mtime', 'mtime') . ',
             a.locked, bp.published, a.allowcomments ' . $from . '
         ORDER BY bp.published ASC, a.ctime DESC, a.id DESC', array($id), $offset, $limit);
     if (!$data) {
         $results['data'] = array();
         return $results;
     }
     // Get the attached files.
     $postids = array_map(create_function('$a', 'return $a->id;'), $data);
     $files = ArtefactType::attachments_from_id_list($postids);
     if ($files) {
         safe_require('artefact', 'file');
         foreach ($files as &$file) {
             $params = array('id' => $file->attachment);
             if (!empty($viewoptions['viewid'])) {
                 $params['viewid'] = $viewoptions['viewid'];
             }
             $file->icon = call_static_method(generate_artefact_class_name($file->artefacttype), 'get_icon', $params);
             $data[$file->artefact]->files[] = $file;
         }
     }
     if ($tags = ArtefactType::tags_from_id_list($postids)) {
         foreach ($tags as &$at) {
             $data[$at->artefact]->tags[] = $at->tag;
         }
     }
     foreach ($data as &$post) {
         // Format dates properly
         if (is_null($viewoptions)) {
             // My Blogs area: create forms for changing post status & deleting posts.
             $post->changepoststatus = ArtefactTypeBlogpost::changepoststatus_form($post->id, $post->published);
             $post->delete = ArtefactTypeBlogpost::delete_form($post->id, $post->title);
         } else {
             $by = $post->author ? display_default_name($post->author) : $post->authorname;
             $post->postedby = get_string('postedbyon', 'artefact.blog', $by, format_date($post->ctime));
             // Get comment counts
             if (!empty($viewoptions['countcomments'])) {
                 safe_require('artefact', 'comment');
                 require_once get_config('docroot') . 'lib/view.php';
                 $view = new View($viewoptions['viewid']);
                 $artefact = artefact_instance_from_id($post->id);
                 list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, null, false);
                 $post->commentcount = $commentcount;
                 $post->comments = $comments;
             }
         }
         $post->ctime = format_date($post->ctime, 'strftimedaydatetime');
         $post->mtime = format_date($post->mtime);
         // Ensure images in the post have the right viewid associated with them
         if (!empty($viewoptions['viewid'])) {
             safe_require('artefact', 'file');
             $post->description = ArtefactTypeFolder::append_view_url($post->description, $viewoptions['viewid']);
         }
     }
     $results['data'] = array_values($data);
     return $results;
 }