function Dwoo_Plugin_flickr(Dwoo $dwoo, $tags, $assign = 'flickrPhotos', $count = 5, $tagmode = 'all') { $cacheKey = sprintf('flickr?tagmode=%s&tags=%s', urlencode($tagmode), urlencode($tags)); if (!($flickrData = apc_fetch($cacheKey))) { $feedURL = sprintf('http://api.flickr.com/services/feeds/photos_public.gne?format=php_serial&tagmode=%s&tags=%s', urlencode($tagmode), urlencode($tags)); $flickrData = @unserialize(@file_get_contents($feedURL)); apc_store($cacheKey, $flickrData, 600); } if (!empty($flickrData['items'])) { $dwoo->assignInScope(array_slice($flickrData['items'], 0, $count), $assign); } else { $dwoo->assignInScope(array(), $assign); } return ''; }
/** * Dwoo {str} function plugin * * Type: function<br> * Name: str<br> * Date: June 22, 2006<br> * Purpose: Fetch internationalized strings * @author Catalyst IT Ltd * @version 1.0 * @return Internationalized string */ function Dwoo_Plugin_str(Dwoo $dwoo, $tag, $section = 'mahara', $args = null, $arg1 = null, $arg2 = null, $arg3 = null, $assign = null) { static $dictionary; $params = array($tag, $section); if ($args) { if (!is_array($args)) { $args = array($args); } $params = array_merge($params, $args); } else { if (isset($arg1)) { foreach (array('arg1', 'arg2', 'arg3') as $k) { if (isset(${$k})) { $params[] = ${$k}; } } } } $ret = call_user_func_array('get_string', $params); // If there is an 'assign' parameter, place it into that instead. if (!empty($assign)) { $dwoo->assignInScope($ret, $assign); return; } return $ret; }
/** * Reads a file * <pre> * * file : path or URI of the file to read (however reading from another website is not recommended for performance reasons) * * assign : if set, the file will be saved in this variable instead of being output * </pre> * This software is provided 'as-is', without any express or implied warranty. * In no event will the authors be held liable for any damages arising from the use of this software. * * @author Jordi Boggiano <*****@*****.**> * @copyright Copyright (c) 2008, Jordi Boggiano * @license http://dwoo.org/LICENSE Modified BSD License * @link http://dwoo.org/ * @version 1.1.0 * @date 2009-07-18 * @package Dwoo */ function Dwoo_Plugin_fetch(Dwoo $dwoo, $file, $assign = null) { if ($file === '') { return; } if ($policy = $dwoo->getSecurityPolicy()) { while (true) { if (preg_match('{^([a-z]+?)://}i', $file)) { return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING); } $file = realpath($file); $dirs = $policy->getAllowedDirectories(); foreach ($dirs as $dir => $dummy) { if (strpos($file, $dir) === 0) { break 2; } } return $dwoo->triggerError('The security policy prevents you to read <em>' . $file . '</em>', E_USER_WARNING); } } $file = str_replace(array("\t", "\n", "\r"), array('\\t', '\\n', '\\r'), $file); $out = file_get_contents($file); if ($assign === null) { return $out; } $dwoo->assignInScope($out, $assign); }
/** * Dwoo {contextualhelp} function plugin * * Type: function<br> * Date: June 22, 2006<br> * Purpose: Provide inline contextual help for arbitrary sections * @author Catalyst IT Ltd * @version 1.0 * @return HTML snippet for help icon */ function Dwoo_Plugin_contextualhelp(Dwoo $dwoo, $plugintype, $pluginname, $form = null, $element = null, $section = null, $assign = null) { $ret = call_user_func_array('get_help_icon', array($plugintype, $pluginname, $form, $element, null, $section)); // If there is an 'assign' parameter, place it into that instead. if ($assign) { $dwoo->assignInScope($ret, $assign); return; } return $ret; }
/** * * @package mahara * @subpackage dwoo * @author Catalyst IT Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later * @copyright For copyright information on Mahara, please see the README file distributed with this software. * */ function Dwoo_Plugin_loadgroupquota(Dwoo $dwoo) { $group = group_current_group(); $quota = $group->quota; $quotaused = $group->quotaused; if ($quota >= 1048576) { $quota_message = get_string('quotausagegroup', 'mahara', sprintf('%0.1fMB', $group->quotaused / 1048576), sprintf('%0.1fMB', $quota / 1048567)); } else { if ($quota >= 1024) { $quota_message = get_string('quotausagegroup', 'mahara', sprintf('%0.1fKB', $group->quotaused / 1024), sprintf('%0.1fKB', $quota / 1024)); } else { $quota_message = get_string('quotausagegroup', 'mahara', sprintf('%d bytes', $group->quotaused), sprintf('%d bytes', $quota)); } } $dwoo->assignInScope($quota_message, 'GROUPQUOTA_MESSAGE'); if ($quota == 0) { $dwoo->assignInScope(100, 'GROUPQUOTA_PERCENTAGE'); } else { $dwoo->assignInScope(round($quotaused / $quota * 100), 'GROUPQUOTA_PERCENTAGE'); } }
/** * Evaluates the given string as if it was a template * * Although this plugin is kind of optimized and will * not recompile your string each time, it is still not * a good practice to use it. If you want to have templates * stored in a database or something you should probably use * the Dwoo_Template_String class or make another class that * extends it * <pre> * * var : the string to use as a template * * assign : if set, the output of the template will be saved in this variable instead of being output * </pre> * This software is provided 'as-is', without any express or implied warranty. * In no event will the authors be held liable for any damages arising from the use of this software. * * @author Jordi Boggiano <*****@*****.**> * @copyright Copyright (c) 2008, Jordi Boggiano * @license http://dwoo.org/LICENSE Modified BSD License * @link http://dwoo.org/ * @version 1.0.0 * @date 2008-10-23 * @package Dwoo */ function Dwoo_Plugin_eval(Dwoo $dwoo, $var, $assign = null) { if ($var == '') { return; } $tpl = new Dwoo_Template_String($var); $out = $dwoo->get($tpl, $dwoo->readVar('_parent')); if ($assign !== null) { $dwoo->assignInScope($out, $assign); } else { return $out; } }
/** * Dwoo {loadquota} function plugin * * Type: function<br> * Name: loadquota<br> * Date: June 22, 2006<br> * Purpose: Set quota related variables for the quota template * @author Catalyst IT Ltd * @version 1.0 * @return Nothing */ function Dwoo_Plugin_loadquota(Dwoo $dwoo) { global $USER; if (!$USER->is_logged_in()) { return; } $quota = $USER->get('quota'); $quotaused = $USER->get('quotaused'); if ($quota >= 1048576) { $quota_message = get_string('quotausage', 'mahara', sprintf('%0.1fMB', $USER->get('quotaused') / 1048576), sprintf('%0.1fMB', $quota / 1048567)); } else { if ($quota >= 1024) { $quota_message = get_string('quotausage', 'mahara', sprintf('%0.1fKB', $USER->get('quotaused') / 1024), sprintf('%0.1fKB', $quota / 1024)); } else { $quota_message = get_string('quotausage', 'mahara', sprintf('%d bytes', $USER->get('quotaused')), sprintf('%d bytes', $quota)); } } $dwoo->assignInScope($quota_message, 'QUOTA_MESSAGE'); if ($quota == 0) { $dwoo->assignInScope(100, 'QUOTA_PERCENTAGE'); } else { $dwoo->assignInScope(round($quotaused / $quota * 100), 'QUOTA_PERCENTAGE'); } }
function Dwoo_Plugin_facebook(Dwoo $dwoo, $page, $assign = 'fbFeed', $limit = 5, $since = false, $cacheTime = 60, $acessToken = '207886205923030|XNMhiHAb8MQp6KmSSIzfd3QH560') { $url = 'https://graph.facebook.com/' . urlencode($page) . '/feed?access_token=' . urlencode($acessToken); $cacheKey = 'fbFeed:' . $page; if ($limit) { $url .= '&limit=' . urlencode($limit); $cacheKey .= ';limit:' . $limit; } if ($since) { $url .= '&since=' . urlencode($since); $cacheKey .= ';since:' . $since; } if (false === ($result = Cache::fetch($cacheKey))) { $data = file_get_contents($url); $result = $data ? json_decode($data, true) : null; Cache::store($cacheKey, $result, $cacheTime); } if (!empty($result['data']) && is_array($result['data'])) { $dwoo->assignInScope($result['data'], $assign); } else { $dwoo->assignInScope(array(), $assign); } return ''; }
/** * Inserts another template into the current one * <pre> * * file : the resource name of the template * * cache_time : cache length in seconds * * cache_id : cache identifier for the included template * * compile_id : compilation identifier for the included template * * data : data to feed into the included template, it can be any array and will default to $_root (the current data) * * assign : if set, the output of the included template will be saved in this variable instead of being output * * rest : any additional parameter/value provided will be added to the data array * </pre> * This software is provided 'as-is', without any express or implied warranty. * In no event will the authors be held liable for any damages arising from the use of this software. * * @author Jordi Boggiano <*****@*****.**> * @copyright Copyright (c) 2008, Jordi Boggiano * @license http://dwoo.org/LICENSE Modified BSD License * @link http://dwoo.org/ * @version 1.1.0 * @date 2009-07-18 * @package Dwoo */ function Dwoo_Plugin_include(Dwoo $dwoo, $file, $cache_time = null, $cache_id = null, $compile_id = null, $data = '_root', $assign = null, array $rest = array()) { if ($file === '') { return; } if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) { // resource:identifier given, extract them $resource = $m[1]; $identifier = $m[2]; } else { // get the current template's resource $resource = $dwoo->getTemplate()->getResourceName(); $identifier = $file; } try { if (!is_numeric($cache_time)) { $cache_time = null; } $include = $dwoo->templateFactory($resource, $identifier, $cache_time, $cache_id, $compile_id); } catch (Dwoo_Security_Exception $e) { return $dwoo->triggerError('Include : Security restriction : ' . $e->getMessage(), E_USER_WARNING); } catch (Dwoo_Exception $e) { return $dwoo->triggerError('Include : ' . $e->getMessage(), E_USER_WARNING); } if ($include === null) { return $dwoo->triggerError('Include : Resource "' . $resource . ':' . $identifier . '" not found.', E_USER_WARNING); } elseif ($include === false) { return $dwoo->triggerError('Include : Resource "' . $resource . '" does not support includes.', E_USER_WARNING); } if ($dwoo->isArray($data)) { $vars = $data; } elseif ($dwoo->isArray($cache_time)) { $vars = $cache_time; } else { $vars = $dwoo->readVar($data); } if (count($rest)) { $vars = $rest + $vars; } $out = $dwoo->get($include, $vars); if ($assign !== null) { $dwoo->assignInScope($out, $assign); } else { return $out; } }
/** * Dwoo {mahara_pagelinks} function pluging * * appends an 'offset=n' parameter to the url to get the url for a different page * @param integer $limit number of items per page * @param integer $offset offset of first data item on this page * @param integer $count total number of items * @param string $url where to get results from * @param string $assign the template var to assign the result to * @return string * * THIS IS DEPRECATED. Pagination is done differently almost everywhere else * (e.g. find friends). One place this is being used is the admin user search. * Hopefully that can be converted away soon. */ function Dwoo_Plugin_mahara_pagelinks(Dwoo $dwoo, $offset, $limit, $count, $url, $assign = '') { $params = array('offset' => $offset, 'limit' => $limit, 'count' => $count, 'url' => $url, 'assign' => $assign); $id = substr(md5(microtime()), 0, 4); $output = '<div class="pagination" id="' . $id . '">'; $params['offsetname'] = isset($params['offsetname']) ? $params['offsetname'] : 'offset'; $params['offset'] = param_integer($params['offsetname'], 0); $params['firsttext'] = isset($params['firsttext']) ? $params['firsttext'] : get_string('first'); $params['previoustext'] = isset($params['previoustext']) ? $params['previoustext'] : get_string('previous'); $params['nexttext'] = isset($params['nexttext']) ? $params['nexttext'] : get_string('next'); $params['lasttext'] = isset($params['lasttext']) ? $params['lasttext'] : get_string('last'); if (!isset($params['numbersincludefirstlast'])) { $params['numbersincludefirstlast'] = true; } if (!isset($params['numbersincludeprevnext'])) { $params['numbersincludeprevnext'] = true; } if ($params['limit'] <= $params['count']) { $pages = ceil($params['count'] / $params['limit']); $page = $params['offset'] / $params['limit']; $last = $pages - 1; $next = min($last, $page + 1); $prev = max(0, $page - 1); // Build a list of what pagenumbers will be put between the previous/next links $pagenumbers = array(); if ($params['numbersincludefirstlast']) { $pagenumbers[] = 0; } if ($params['numbersincludeprevnext']) { $pagenumbers[] = $prev; } $pagenumbers[] = $page; if ($params['numbersincludeprevnext']) { $pagenumbers[] = $next; } if ($params['numbersincludefirstlast']) { $pagenumbers[] = $last; } $pagenumbers = array_unique($pagenumbers); // Build the first/previous links $isfirst = $page == 0; $output .= mahara_pagelink('first', $params['url'], 0, '« ' . $params['firsttext'], get_string('firstpage'), $isfirst, $params['offsetname']); $output .= mahara_pagelink('prev', $params['url'], $params['limit'] * $prev, '← ' . $params['previoustext'], get_string('prevpage'), $isfirst, $params['offsetname']); // Build the pagenumbers in the middle foreach ($pagenumbers as $k => $i) { if ($k != 0 && $prevpagenum < $i - 1) { $output .= '…'; } if ($i == $page) { $output .= '<span class="selected">' . ($i + 1) . '</span>'; } else { $output .= mahara_pagelink('', $params['url'], $params['limit'] * $i, $i + 1, '', false, $params['offsetname']); } $prevpagenum = $i; } // Build the next/last links $islast = $page == $last; $output .= mahara_pagelink('next', $params['url'], $params['limit'] * $next, $params['nexttext'] . ' →', get_string('nextpage'), $islast, $params['offsetname']); $output .= mahara_pagelink('last', $params['url'], $params['limit'] * $last, $params['lasttext'] . ' »', get_string('lastpage'), $islast, $params['offsetname']); } if (isset($params['json_script']) && isset($params['datatable'])) { $paginator_js = hsc(get_config('wwwroot') . 'js/paginator.js'); $datatable = json_encode($params['datatable']); $json_script = json_encode($params['json_script']); $output .= <<<EOF <script type="text/javascript" src="{$paginator_js}"></script> <script type="text/javascript"> new Paginator("{$id}", {$datatable}, {$json_script}); </script> EOF; } // Close the container div $output .= '</div>'; if (!empty($params['assign'])) { $dwoo->assignInScope($output, $params['assign']); return; } return $output; }