/** * Convert a Mahara plugin template file path into a normal template file path with extra search paths. * * @param string $pluginfile The plugintype, name, and name of file, e.g. "blocktype:clippy:index.tpl" * @param int $cacheTime Not used. * @param int $cacheId Not used. * @param int $compileId Not used. * @param array $includePath The paths to look in. * @throws MaharaException */ public function __construct($file, $cacheTime = null, $cacheId = null, $compileId = null, $includePath = null) { global $THEME; $parts = explode(':', $file, 3); if (count($parts) !== 3) { throw new SystemException("Invalid template path \"{$file}\""); } // Keep the original string for logging purposes $dwooref = $file; list($plugintype, $pluginname, $file) = $parts; // Since we use $plugintype as part of a file path, we should whitelist it $plugintype = strtolower($plugintype); if (!in_array($plugintype, plugin_types())) { throw new SystemException("Invalid plugintype in Dwoo template \"{$dwooref}\""); } // Get the relative path for this particular plugin require_once get_config('docroot') . $plugintype . '/lib.php'; $pluginpath = call_static_method(generate_class_name($plugintype), 'get_theme_path', $pluginname); // Because this is a plugin template file, we don't want to include any accidental matches against // core template files with the same name. $includePath = array(); // First look for a local override. $includePath[] = get_config('docroot') . "local/theme/{$pluginpath}/templates"; // Then look for files in a custom theme foreach ($THEME->inheritance as $theme) { $includePath[] = get_config('docroot') . "theme/{$theme}/{$pluginpath}/templates"; } // Lastly look for files in the plugin itself foreach ($THEME->inheritance as $theme) { $includePath[] = get_config('docroot') . "{$pluginpath}/theme/{$theme}/templates"; // For legacy purposes also look for the template file loose under the theme directory. $includePath[] = get_config('docroot') . "{$pluginpath}/theme/{$theme}"; } // Now, we instantiate this as a standard Dwoo_Template_File class. // We're passing in $file, which is the relative path to the file, and // $includePath, which is an array of directories to search for $file in. // We let Dwoo figure out which one actually has it. parent::__construct($file, null, null, null, $includePath); }
/** * Releases a submission to a remote host. * @param int $id A view or collection id * @param mixed $assessmentdata Assessment data from the remote host, for this assignment * @param string $teacherusername The username of the teacher who is releasing the assignment * @param boolean $iscollection Whether the $id is a view or a collection */ function release_submitted_view($id, $assessmentdata, $teacherusername, $iscollection = false) { global $REMOTEWWWROOT, $USER; list($teacher, $authinstance) = find_remote_user($teacherusername, $REMOTEWWWROOT); require_once 'view.php'; db_begin(); if ($iscollection) { require_once 'collection.php'; $collection = new Collection($id); $collection->release($teacher); } else { $view = new View($id); View::_db_release(array($id), $view->get('owner')); } // Provide each artefact plugin the opportunity to handle the remote submission release foreach (plugins_installed('artefact') as $plugin) { safe_require('artefact', $plugin->name); $classname = generate_class_name('artefact', $plugin->name); if (is_callable($classname . '::view_release_external_data')) { call_static_method($classname, 'view_release_external_data', $id, $assessmentdata, $teacher ? $teacher->id : 0, $iscollection); } } // Release the view for editing db_commit(); }
function get_search_plugins() { $searchpluginoptions = array(); if ($searchplugins = plugins_installed('search')) { foreach ($searchplugins as $plugin) { safe_require_plugin('search', $plugin->name, 'lib.php'); if (!call_static_method(generate_class_name('search', $plugin->name), 'is_available_for_site_setting')) { continue; } $searchpluginoptions[$plugin->name] = $plugin->name; $config_path = get_config('docroot') . 'search/' . $plugin->name . '/version.php'; if (is_readable($config_path)) { $config = new stdClass(); require_once $config_path; if (isset($config->name)) { $searchpluginoptions[$plugin->name] = $config->name; } } } } return $searchpluginoptions; }
/** * Builds data for the artefact chooser. * * This builds three pieces of information: * * - HTML containing table rows * - Pagination HTML and Javascript * - The total number of artefacts found * - Artefact fields to return */ public static function build_artefactchooser_data($data, $group = null, $institution = null) { global $USER; // If lazyload is set, immediately return an empty resultset // In the case of forms using lazyload, lazyload is set to false by subsequent requests via ajax, // for example in views/artefactchooser.json.php, at which time the full resultset is returned. if (isset($data['lazyload']) && $data['lazyload']) { $result = ''; $pagination = build_pagination(array('id' => $data['name'] . '_pagination', 'class' => 'ac-pagination', 'url' => View::make_base_url() . (param_boolean('s') ? '&s=1' : ''), 'count' => 0, 'limit' => 0, 'offset' => 0, 'datatable' => $data['name'] . '_data', 'jsonscript' => 'view/artefactchooser.json.php', 'firsttext' => '', 'previoustext' => '', 'nexttext' => '', 'lasttext' => '', 'numbersincludefirstlast' => false, 'extradata' => array('value' => $data['defaultvalue'], 'blocktype' => $data['blocktype'], 'group' => $group, 'institution' => $institution))); return array($result, $pagination, 0, 0, array()); } $search = ''; if (!empty($data['search']) && param_boolean('s')) { $search = param_variable('search', ''); // Maybe later, depending on performance - don't search if there's // not enough characters. Prompts should be added to the UI too. //if (strlen($search) < 3) { // $search = ''; //} } $data['search'] = $search; $data['offset'] -= $data['offset'] % $data['limit']; safe_require('blocktype', $data['blocktype']); $blocktypeclass = generate_class_name('blocktype', $data['blocktype']); $data['sortorder'] = array(array('fieldname' => 'title', 'order' => 'ASC')); if (method_exists($blocktypeclass, 'artefactchooser_get_sort_order')) { $data['sortorder'] = call_static_method($blocktypeclass, 'artefactchooser_get_sort_order'); } list($artefacts, $totalartefacts) = self::get_artefactchooser_artefacts($data, $USER, $group, $institution); $selectone = $data['selectone']; $value = $data['defaultvalue']; $elementname = $data['name']; $template = $data['template']; $returnfields = isset($data['returnfields']) ? $data['returnfields'] : null; $returnartefacts = array(); $result = ''; if ($artefacts) { if (!empty($data['ownerinfo'])) { require_once get_config('docroot') . 'artefact/lib.php'; $userid = $group || $institution ? null : $USER->get('id'); foreach (artefact_get_owner_info(array_keys($artefacts)) as $k => $v) { if ($artefacts[$k]->owner !== $userid || $artefacts[$k]->group !== $group || $artefacts[$k]->institution !== $institution) { $artefacts[$k]->ownername = $v->name; $artefacts[$k]->ownerurl = $v->url; } } } foreach ($artefacts as &$artefact) { safe_require('artefact', get_field('artefact_installed_type', 'plugin', 'name', $artefact->artefacttype)); if (method_exists($blocktypeclass, 'artefactchooser_get_element_data')) { $artefact = call_static_method($blocktypeclass, 'artefactchooser_get_element_data', $artefact); } // Build the radio button or checkbox for the artefact $formcontrols = ''; if ($selectone) { $formcontrols .= '<input type="radio" class="radio" id="' . hsc($elementname . '_' . $artefact->id) . '" name="' . hsc($elementname) . '" value="' . hsc($artefact->id) . '"'; if ($value == $artefact->id) { $formcontrols .= ' checked="checked"'; } $formcontrols .= '>'; } else { $formcontrols .= '<input type="checkbox" id="' . hsc($elementname . '_' . $artefact->id) . '" name="' . hsc($elementname) . '[' . hsc($artefact->id) . ']"'; if ($value && in_array($artefact->id, $value)) { $formcontrols .= ' checked="checked"'; } $formcontrols .= ' class="artefactid-checkbox checkbox">'; $formcontrols .= '<input type="hidden" name="' . hsc($elementname) . '_onpage[]" value="' . hsc($artefact->id) . '" class="artefactid-onpage">'; } $smarty = smarty_core(); $smarty->assign('artefact', $artefact); $smarty->assign('elementname', $elementname); $smarty->assign('formcontrols', $formcontrols); $result .= $smarty->fetch($template) . "\n"; if ($returnfields) { $returnartefacts[$artefact->id] = array(); foreach ($returnfields as $f) { if ($f == 'safedescription') { $returnartefacts[$artefact->id]['safedescription'] = clean_html($artefact->description); continue; } if ($f == 'attachments') { // Check if the artefact has attachments - we need to update the instance config form // to have those attachments selected. $attachment_ids = get_column('artefact_attachment', 'attachment', 'artefact', $artefact->id); $returnartefacts[$artefact->id]['attachments'] = $attachment_ids; continue; } $returnartefacts[$artefact->id][$f] = $artefact->{$f}; } } } if ($returnfields && !empty($data['getblocks'])) { // Get ids of the blocks containing these artefacts $blocks = get_records_select_array('view_artefact', 'artefact IN (' . join(',', array_fill(0, count($artefacts), '?')) . ')', array_keys($artefacts)); if (!empty($blocks)) { // For each artefact, attach a list of block ids of all the blocks // that contain it. foreach ($blocks as $block) { if (empty($returnartefacts[$block->artefact]['blocks'])) { $returnartefacts[$block->artefact]['blocks'] = array(); } $returnartefacts[$block->artefact]['blocks'][] = $block->block; } } } } $pagination = build_pagination(array('id' => $elementname . '_pagination', 'class' => 'ac-pagination', 'url' => View::make_base_url() . (param_boolean('s') ? '&s=1' : ''), 'count' => $totalartefacts, 'limit' => $data['limit'], 'offset' => $data['offset'], 'datatable' => $elementname . '_data', 'jsonscript' => 'view/artefactchooser.json.php', 'firsttext' => '', 'previoustext' => '', 'nexttext' => '', 'lasttext' => '', 'numbersincludefirstlast' => false, 'extradata' => array('value' => $value, 'blocktype' => $data['blocktype'], 'group' => $group, 'institution' => $institution))); return array($result, $pagination, $totalartefacts, $data['offset'], $returnartefacts); }
function install_blocktype_viewtypes_for_plugin($blocktype) { safe_require('blocktype', $blocktype); $blocktype = blocktype_namespaced_to_single($blocktype); db_begin(); delete_records('blocktype_installed_viewtype', 'blocktype', $blocktype); if ($viewtypes = call_static_method(generate_class_name('blocktype', $blocktype), 'get_viewtypes')) { foreach ($viewtypes as $vt) { insert_record('blocktype_installed_viewtype', (object) array('blocktype' => $blocktype, 'viewtype' => $vt)); } } db_commit(); }
/** * Dealing with things to count in progressbar that are not true artefacts * and therefore are not countable by adding up how many instances exist in * the artefact table. Or if you want to count an artefact differently. * For example: Social -> Make a friend * * @param string $plugin name of artefact plugin * @param array $onlythese (optional) An array of items from artefact_get_progressbar_items, indicating which to include * @return array of objects each containing artefacttype, completed * (where completed represents the number completed) */ function artefact_get_progressbar_metaartefacts($plugin, $onlythese = false) { $results = array(); $classname = generate_class_name('artefact', $plugin); // Check the artefacttypes to see if they have a special metaartefact count $names = call_static_method($classname, 'get_artefact_types'); foreach ($names as $name) { if (!array_key_exists($name, $onlythese)) { continue; } $is_metaartefact = call_static_method('ArtefactType' . ucfirst($name), 'is_metaartefact'); if ($is_metaartefact) { $meta = call_user_func($classname . '::progressbar_metaartefact_count', $name); if (is_object($meta)) { array_push($results, $meta); } } } // Also check the special artefacts if (is_array($specials = call_static_method($classname, 'progressbar_additional_items'))) { foreach ($specials as $special) { if (!array_key_exists($special->name, $onlythese)) { continue; } if (empty($special->is_metaartefact)) { // check to see if it can have mataartefact count $special->is_metaartefact = call_static_method('ArtefactType' . ucfirst($special->name), 'is_metaartefact'); } if (!empty($special->is_metaartefact)) { // Now check if they have a special metaartefact count $meta = call_user_func($classname . '::progressbar_metaartefact_count', $special->name); if (is_object($meta)) { array_push($results, $meta); } } } } return $results; }
/** * Builds the pieform for the search field in the page header */ function header_search_form() { $plugin = get_config('searchplugin'); safe_require('search', $plugin); return call_static_method(generate_class_name('search', $plugin), 'header_search_form'); }
$enable = param_integer('enable', 0); $disable = param_integer('disable', 0); if ($disable && !call_static_method(generate_class_name($plugintype, $pluginname), 'can_be_disabled')) { throw new UserException("Plugin {$plugintype} {$pluginname} cannot be disabled"); } if ($enable || $disable) { require_once get_config('libroot') . 'upgrade.php'; clear_menu_cache(); activate_plugin_form($plugintype, get_record($plugintype . '_installed', 'name', $pluginname)); } if ($plugintype == 'artefact') { $type = param_alpha('type'); $classname = generate_artefact_class_name($type); } else { $type = ''; $classname = generate_class_name($plugintype, $pluginname); } if (!call_static_method($classname, 'has_config')) { throw new InvalidArgumentException("{$classname} doesn't have config options available"); } $form = call_static_method($classname, 'get_config_options'); $form['plugintype'] = $plugintype; $form['pluginname'] = $pluginname; $form['name'] = 'pluginconfig'; $form['class'] = 'panel panel-body'; $form['pluginconfigform'] = true; $form['jsform'] = true; $form['successcallback'] = 'pluginconfig_submit'; $form['validatecallback'] = 'pluginconfig_validate'; $form['elements']['plugintype'] = array('type' => 'hidden', 'value' => $plugintype); $form['elements']['pluginname'] = array('type' => 'hidden', 'value' => $pluginname);
public static function class_from_format($format) { $format = trim($format); if ($format == 'files') { $format = 'file'; } safe_require('import', $format); return generate_class_name('import', $format); }
function get_portfolio_items_by_tag($tag, $owner, $limit, $offset, $sort = 'name', $type = null, $returntags = true) { // For now, can only be used to search a user's portfolio if (empty($owner->id) || empty($owner->type)) { throw new SystemException('get_views_and_artefacts_by_tag: invalid owner'); } if ($owner->type != 'user') { throw new SystemException('get_views_and_artefacts_by_tag only implemented for users'); } $types = get_portfolio_types_from_param($type); $plugin = 'internal'; safe_require('search', $plugin); $result = call_static_method(generate_class_name('search', $plugin), 'portfolio_search_by_tag', $tag, $owner, $limit, $offset, $sort, $types, $returntags); $result->filter = $result->type = $type ? $type : 'all'; return $result; }
$count = 0; db_begin(); try { foreach ($_GET as $k => $v) { if (preg_match('/^delete\\-(\\d+)$/', $k, $m)) { delete_records('notification_internal_activity', 'id', $m[1], 'usr', $USER->get('id')); $count++; } } } catch (Exception $e) { db_rollback(); json_reply('local', get_string('failedtodeletenotifications', 'activity') . ': ' . $e->getMessage()); } db_commit(); safe_require('notification', 'internal'); json_reply(false, array('message' => get_string('deletednotifications', 'activity', $count), 'count' => $count, 'newunreadcount' => call_static_method(generate_class_name('notification', 'internal'), 'unread_count', $USER->get('id')))); } } // normal processing $type = param_alphanum('type', 'all'); $limit = param_integer('limit', 10); $offset = param_integer('offset', 0); $userid = $USER->get('id'); if ($type == 'all') { $count = count_records('notification_internal_activity', 'usr', $userid); $sql = 'SELECT a.*, at.name AS type,at.plugintype, at.pluginname FROM {notification_internal_activity} a JOIN {activity_type} at ON a.type = at.id WHERE a.usr = ? ORDER BY ctime DESC'; $records = get_records_sql_array($sql, array($userid), $offset, $limit); } else { if ($type == 'adminmessages' && $USER->get('admin')) {
/** * Submit plugin institution form values. * * @param Pieform $form * @param array $values * @param Institution $institution * @return bool is page need to be refreshed */ function plugin_institution_prefs_submit(Pieform $form, $values, Institution $institution) { $elements = array(); $installed = plugin_all_installed(); foreach ($installed as $i) { if (!safe_require_plugin($i->plugintype, $i->name)) { continue; } call_static_method(generate_class_name($i->plugintype, $i->name), 'institutionprefs_submit', $form, $values, $institution); } }
/** * Builds data for the artefact chooser. * * This builds three pieces of information: * * - HTML containing table rows * - Pagination HTML and Javascript * - The total number of artefacts found */ public static function build_artefactchooser_data($data, $group = null, $institution = null) { global $USER; $search = ''; if (!empty($data['search']) && param_boolean('s')) { $search = param_variable('search', ''); // Maybe later, depending on performance - don't search if there's // not enough characters. Prompts should be added to the UI too. //if (strlen($search) < 3) { // $search = ''; //} } $data['search'] = $search; $data['offset'] -= $data['offset'] % $data['limit']; safe_require('blocktype', $data['blocktype']); $blocktypeclass = generate_class_name('blocktype', $data['blocktype']); $data['sortorder'] = array(array('fieldname' => 'title', 'order' => 'ASC')); if (method_exists($blocktypeclass, 'artefactchooser_get_sort_order')) { $data['sortorder'] = call_static_method($blocktypeclass, 'artefactchooser_get_sort_order'); } list($artefacts, $totalartefacts) = self::get_artefactchooser_artefacts($data, $USER, $group, $institution); $selectone = $data['selectone']; $value = $data['defaultvalue']; $elementname = $data['name']; $template = $data['template']; $result = ''; if ($artefacts) { foreach ($artefacts as &$artefact) { safe_require('artefact', get_field('artefact_installed_type', 'plugin', 'name', $artefact->artefacttype)); if (method_exists($blocktypeclass, 'artefactchooser_get_element_data')) { $artefact = call_static_method($blocktypeclass, 'artefactchooser_get_element_data', $artefact); } // Build the radio button or checkbox for the artefact $formcontrols = ''; if ($selectone) { $formcontrols .= '<input type="radio" class="radio" id="' . hsc($elementname . '_' . $artefact->id) . '" name="' . hsc($elementname) . '" value="' . hsc($artefact->id) . '"'; if ($value == $artefact->id) { $formcontrols .= ' checked="checked"'; } $formcontrols .= '>'; } else { $formcontrols .= '<input type="checkbox" id="' . hsc($elementname . '_' . $artefact->id) . '" name="' . hsc($elementname) . '[' . hsc($artefact->id) . ']"'; if ($value && in_array($artefact->id, $value)) { $formcontrols .= ' checked="checked"'; } $formcontrols .= ' class="artefactid-checkbox checkbox">'; $formcontrols .= '<input type="hidden" name="' . hsc($elementname) . '_onpage[]" value="' . hsc($artefact->id) . '" class="artefactid-onpage">'; } $smarty = smarty_core(); $smarty->assign('artefact', $artefact); $smarty->assign('elementname', $elementname); $smarty->assign('formcontrols', $formcontrols); $result .= $smarty->fetch($template) . "\n"; } } $pagination = build_pagination(array('id' => $elementname . '_pagination', 'class' => 'ac-pagination', 'url' => View::make_base_url() . (param_boolean('s') ? '&s=1' : ''), 'count' => $totalartefacts, 'limit' => $data['limit'], 'offset' => $data['offset'], 'datatable' => $elementname . '_data', 'jsonscript' => 'view/artefactchooser.json.php', 'firsttext' => '', 'previoustext' => '', 'nexttext' => '', 'lasttext' => '', 'numbersincludefirstlast' => false, 'extradata' => array('value' => $value, 'blocktype' => $data['blocktype'], 'group' => $group, 'institution' => $institution))); return array($result, $pagination, $totalartefacts, $data['offset']); }
if ($ids) { set_field_select('notification_internal_activity', 'read', 1, 'id IN (' . join(',', $ids) . ') AND usr = ?', array($USER->get('id'))); } $message = get_string('markedasread', 'activity'); } else { if ($delete) { $ids = array(); foreach ($_GET as $k => $v) { if (preg_match('/^delete\\-(\\d+)$/', $k, $m)) { $ids[] = $m[1]; } } if ($ids) { $strids = join(',', $ids); $userid = $USER->get('id'); db_begin(); // Remove parent pointers to messages we're about to delete // Use temp table in subselect for Mysql compat. execute_sql("\n UPDATE {notification_internal_activity}\n SET parent = NULL\n WHERE parent IN (\n SELECT id\n FROM (\n SELECT id FROM {notification_internal_activity} WHERE id IN ({$strids}) AND usr = ?\n ) AS temp\n )", array($userid)); delete_records_select('notification_internal_activity', "id IN ({$strids}) AND usr = ?", array($userid)); db_commit(); } $message = get_string('deletednotifications', 'activity', count($ids)); } } $newhtml = activitylist_html($type, $limit, $offset); if ($message) { safe_require('notification', 'internal'); $newhtml['newunreadcount'] = call_static_method(generate_class_name('notification', 'internal'), 'unread_count', $USER->get('id')); } json_reply(false, (object) array('message' => $message, 'data' => $newhtml));
/** * This method is called late in the import process, after views, collections, and artefacts have been set up, to give collections the opportunity * to rewrite any references they have to old view, collection, or artefact IDs. * * Blocktypes that use this API should define an "import_rewrite_blockinstance_relationships_leap" method. */ private function rewrite_blockinstance_relationships() { foreach ($this->viewids as $entryid => $viewid) { $records = get_records_array('block_instance', 'view', $viewid, 'view, id'); if ($records) { foreach ($records as $blockrec) { // Let blocktype plugin rewrite relationships now that all views and collections are set up safe_require('blocktype', $blockrec->blocktype); $classname = generate_class_name('blocktype', $blockrec->blocktype); $method = 'import_rewrite_blockinstance_relationships_leap'; $blockinstance['config'] = call_static_method($classname, $method, $blockrec->id, $this); } } } }
/** * Returns a datastructure describing the tabs that appear on a group page * * @param object $group Database record of group to get tabs for * @return array */ function group_get_menu_tabs() { static $menu; $group = group_current_group(); if (!$group) { return null; } $role = group_user_access($group->id); $menu = array('info' => array('path' => 'groups/info', 'url' => group_homepage_url($group, false), 'title' => get_string('About', 'group'), 'weight' => 20)); if (group_can_list_members($group, $role)) { $menu['members'] = array('path' => 'groups/members', 'url' => 'group/members.php?id=' . $group->id, 'title' => get_string('Members', 'group'), 'weight' => 30); } if ($interactionplugins = plugins_installed('interaction')) { foreach ($interactionplugins as $plugin) { safe_require('interaction', $plugin->name); $plugin_menu = call_static_method(generate_class_name('interaction', $plugin->name), 'group_menu_items', $group); $menu = array_merge($menu, $plugin_menu); } } $menu['views'] = array('path' => 'groups/views', 'url' => 'view/groupviews.php?group=' . $group->id, 'title' => get_string('Views', 'group'), 'weight' => 50); $menu['collections'] = array('path' => 'groups/collections', 'url' => 'collection/index.php?group=' . $group->id, 'title' => get_string('Collections', 'group'), 'weight' => 60); if (group_role_can_edit_views($group, $role)) { $menu['share'] = array('path' => 'groups/share', 'url' => 'group/shareviews.php?group=' . $group->id, 'title' => get_string('share', 'view'), 'weight' => 70); } if ($role) { safe_require('grouptype', $group->grouptype); $artefactplugins = call_static_method('GroupType' . $group->grouptype, 'get_group_artefact_plugins'); if ($plugins = plugins_installed('artefact')) { foreach ($plugins as &$plugin) { if (!in_array($plugin->name, $artefactplugins)) { continue; } safe_require('artefact', $plugin->name); $plugin_menu = call_static_method(generate_class_name('artefact', $plugin->name), 'group_tabs', $group->id); $menu = array_merge($menu, $plugin_menu); } } } if (group_role_can_access_report($group, $role)) { $menu['report'] = array('path' => 'groups/report', 'url' => 'group/report.php?group=' . $group->id, 'title' => get_string('report', 'group'), 'weight' => 70); } if (defined('MENUITEM')) { $key = substr(MENUITEM, strlen('groups/')); if ($key && isset($menu[$key])) { $menu[$key]['selected'] = true; } } return $menu; }
/** * Cronjob to recalculate how much quota each user is using and update it as * appropriate. * * This gives a backstop for the possibility that there is a bug elsewhere that * has caused the quota count to get out of sync */ function recalculate_quota() { $plugins = plugins_installed('artefact', true); $userquotas = array(); $groupquotas = array(); foreach ($plugins as $plugin) { safe_require('artefact', $plugin->name); $classname = generate_class_name('artefact', $plugin->name); if (is_callable($classname . '::recalculate_quota')) { $pluginuserquotas = call_static_method($classname, 'recalculate_quota'); foreach ($pluginuserquotas as $userid => $usage) { if (!isset($userquotas[$userid])) { $userquotas[$userid] = $usage; } else { $userquotas[$userid] += $usage; } } } if (is_callable($classname . '::recalculate_group_quota')) { $plugingroupquotas = call_static_method($classname, 'recalculate_group_quota'); foreach ($plugingroupquotas as $groupid => $usage) { if (!isset($groupquotas[$groupid])) { $groupquotas[$groupid] = $usage; } else { $groupquotas[$groupid] += $usage; } } } } foreach ($userquotas as $user => $quota) { $data = (object) array('quotaused' => $quota); $where = (object) array('id' => $user); update_record('usr', $data, $where); } foreach ($groupquotas as $group => $quota) { $data = (object) array('quotaused' => $quota); $where = (object) array('id' => $group); update_record('group', $data, $where); } }
/** * helper function to return the appropriate class name from an import format * this will try and resolve inconsistencies (eg file/files, leap/leap2a etc * and also pull in the class definition for you */ public static function class_from_format($format) { $format = trim($format); $corr = array('files' => 'file', 'leap2a' => 'leap'); foreach ($corr as $bad => $good) { if ($format == $bad) { $format = $good; break; } } safe_require('import', $format); return generate_class_name('import', $format); }
/** * creates the information for the interaction_sideblock * * @param int $groupid the group the sideblock is for * @param boolean (optional) $membership whether the user is a member * @return array containing indices 'name', 'weight', 'data' */ function interaction_sideblock($groupid, $membership = true) { $interactiontypes = array_flip(array_map(create_function('$a', 'return $a->name;'), plugins_installed('interaction'))); if (!($interactions = get_records_select_array('interaction_instance', '"group" = ? AND deleted = ?', array($groupid, 0), 'plugin, ctime', 'id, plugin, title'))) { $interactions = array(); } foreach ($interactions as $i) { if (!is_array($interactiontypes[$i->plugin])) { $interactiontypes[$i->plugin] = array(); } $interactiontypes[$i->plugin][] = $i; } // Sort them according to how the plugin wants them sorted if ($interactiontypes) { foreach ($interactiontypes as $plugin => &$interactions) { safe_require('interaction', $plugin); $classname = generate_class_name('interaction', $plugin); if (method_exists($classname, 'sideblock_sort')) { $interactions = call_static_method($classname, 'sideblock_sort', $interactions); } } } $data = array('group' => $groupid, 'interactiontypes' => $interactiontypes, 'membership' => $membership); // Add a sideblock for group interactions return array('name' => 'groupinteractions', 'weight' => -5, 'data' => $data); }
function release_submitted_view($viewid, $assessmentdata, $teacherusername) { global $REMOTEWWWROOT, $USER; require_once 'view.php'; $view = new View($viewid); list($teacher, $authinstance) = find_remote_user($teacherusername, $REMOTEWWWROOT); db_begin(); foreach (plugins_installed('artefact') as $plugin) { safe_require('artefact', $plugin->name); $classname = generate_class_name('artefact', $plugin->name); if (is_callable($classname . '::view_release_external_data')) { call_static_method($classname, 'view_release_external_data', $view, $assessmentdata, $teacher ? $teacher->id : 0); } } // Release the view for editing $view->set('submittedhost', null); $view->set('submittedtime', null); $view->commit(); db_commit(); }
if (!is_dir(get_config('docroot') . $plugin . '/' . $dir)) { continue; } if (array_key_exists($dir, $plugins[$plugin]['installed'])) { $installed = true; } // if we're already installed keep going // if we're an artefact plugin, we have to check for blocktypes. if ($plugin != 'artefact' && !empty($installed)) { continue; } if (empty($installed)) { $plugins[$plugin]['notinstalled'][$dir] = array(); try { validate_plugin($plugin, $dir); $classname = generate_class_name($plugin, $dir); $classname::sanity_check(); } catch (InstallationException $e) { $plugins[$plugin]['notinstalled'][$dir]['notinstallable'] = $e->GetMessage(); } } if ($plugin == 'artefact' && table_exists(new XMLDBTable('blocktype_installed'))) { // go check it for blocks as well $btlocation = get_config('docroot') . $plugin . '/' . $dir . '/blocktype'; if (!is_dir($btlocation)) { continue; } $btdirhandle = opendir($btlocation); while (false !== ($btdir = readdir($btdirhandle))) { if (strpos($btdir, '.') === 0) { continue;
require_once 'group.php'; $id = param_integer('id', 0); if (!empty($id)) { $instance = interaction_instance_from_id($id); $plugin = $instance->get('plugin'); $groupid = (int) $instance->get('group'); define('TITLE', get_string('edittitle', 'interaction.' . $plugin)); } else { $instance = null; $plugin = param_alphanum('plugin'); $groupid = param_integer('group'); define('TITLE', get_string('addtitle', 'interaction.' . $plugin)); } define('GROUP', $groupid); $group = group_current_group(); safe_require('interaction', $plugin); $membership = group_user_access($groupid); if ($membership != 'admin') { throw new AccessDeniedException(get_string('notallowedtoeditinteractions', 'group')); } $returnto = param_alpha('returnto', 'view'); $elements = array_merge(PluginInteraction::instance_config_base_form($plugin, $group, $instance), call_static_method(generate_class_name('interaction', $plugin), 'instance_config_form', $group, $instance), array('submit' => array('type' => 'submitcancel', 'value' => array(get_string('save'), get_string('cancel')), 'goto' => get_config('wwwroot') . 'interaction/' . $plugin . (isset($instance) && $returnto != 'index' ? '/view.php?id=' . $instance->get('id') : '/index.php?group=' . $groupid)))); $js = call_static_method(generate_class_name('interaction', $plugin), 'instance_config_js', $group, $instance); // save, validate and cancelhandlers are in interaction/lib.php $form = pieform(array('name' => 'edit_interaction', 'plugintype' => 'interaction', 'pluginname' => $plugin, 'elements' => $elements)); $smarty = smarty(array('tablerenderer')); $smarty->assign('form', $form); $smarty->assign('INLINEJAVASCRIPT', $js); $smarty->assign('heading', $group->name); $smarty->assign('subheading', TITLE); $smarty->display('interaction/edit.tpl');
function right_nav() { global $USER, $THEME; safe_require('notification', 'internal'); $unread = call_static_method(generate_class_name('notification', 'internal'), 'unread_count', $USER->get('id')); $menu = array(array('path' => 'settings', 'wwwroot' => get_config('httpswwwroot'), 'url' => 'account/', 'title' => get_string('settings'), 'icon' => $THEME->get_url('images/settings.png'), 'alt' => get_string('settings'), 'weight' => 10), array('path' => 'inbox', 'url' => 'account/activity', 'icon' => $THEME->get_url('images/email.gif'), 'alt' => get_string('inbox'), 'count' => $unread, 'countclass' => 'unreadmessagecount', 'weight' => 20), array('path' => 'settings/account', 'url' => 'account/', 'title' => get_string('account'), 'weight' => 10), array('path' => 'settings/notifications', 'url' => 'account/activity/preferences/', 'title' => get_string('notifications'), 'weight' => 30), array('path' => 'settings/institutions', 'url' => 'account/institutions.php', 'title' => get_string('institutionmembership'), 'weight' => 40)); $menu_structure = find_menu_children($menu, ''); return $menu_structure; }
function siteoptions_submit(Pieform $form, $values) { $fields = array('sitename', 'lang', 'theme', 'dropdownmenu', 'defaultaccountlifetime', 'defaultregistrationexpirylifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn', 'defaultaccountlifetimeupdate', 'allowpublicviews', 'allowpublicprofiles', 'allowanonymouspages', 'generatesitemap', 'registration_sendweeklyupdates', 'mathjax', 'institutionexpirynotification', 'institutionautosuspend', 'requireregistrationconfirm', 'showselfsearchsideblock', 'nousernames', 'searchplugin', 'showtagssideblock', 'tagssideblockmaxtags', 'country', 'viewmicroheaders', 'userscanchooseviewthemes', 'remoteavatars', 'userscanhiderealnames', 'antispam', 'spamhaus', 'surbl', 'anonymouscomments', 'recaptchaonregisterform', 'recaptchapublickey', 'recaptchaprivatekey', 'loggedinprofileviewaccess', 'disableexternalresources', 'proxyaddress', 'proxyauthmodel', 'proxyauthcredentials', 'smtphosts', 'smtpport', 'smtpuser', 'smtppass', 'smtpsecure', 'noreplyaddress', 'homepageinfo', 'showprogressbar', 'showonlineuserssideblock', 'onlineuserssideblockmaxusers', 'registerterms', 'licensemetadata', 'licenseallowcustom', 'allowmobileuploads', 'creategroups', 'createpublicgroups', 'allowgroupcategories', 'wysiwyg', 'staffreports', 'staffstats', 'userscandisabledevicedetection', 'watchlistnotification_delay', 'masqueradingreasonrequired', 'masqueradingnotified', 'searchuserspublic', 'eventloglevel', 'eventlogexpiry', 'sitefilesaccess', 'exporttoqueue', 'defaultmultipleblogs'); $count = 0; $where_sql = " WHERE admin = 0 AND id != 0"; // if default account lifetime expiry has no end date if (empty($values['defaultaccountlifetime'])) { if ($values['defaultaccountlifetimeupdate'] == 'all') { // need to remove user expiry db_begin(); $count = count_records_sql("SELECT COUNT(*) FROM {usr} {$where_sql}"); execute_sql("UPDATE {usr} SET expiry = NULL {$where_sql}"); db_commit(); } else { // make the 'some' option the same as 'none' as it is meaningless to // update existing users without expiry date to having 'no end date' $values['defaultaccountlifetimeupdate'] = 'none'; } } else { // fetch all the users that are not siteadmins $user_expiry = mktime(0, 0, 0, date('n'), date('j'), date('Y')) + (int) $values['defaultaccountlifetime']; if ($values['defaultaccountlifetimeupdate'] == 'some') { // and the user's expiry is not set $where_sql .= " AND expiry IS NULL"; $count = count_records_sql("SELECT COUNT(*) FROM {usr} {$where_sql}"); db_begin(); execute_sql("UPDATE {usr} SET expiry = ? {$where_sql}", array(format_date($user_expiry))); db_commit(); } else { if ($values['defaultaccountlifetimeupdate'] == 'all') { // and the user's expiry is set db_begin(); $count = count_records_sql("SELECT COUNT(*) FROM {usr} {$where_sql}"); execute_sql("UPDATE {usr} SET expiry = ? {$where_sql}", array(format_date($user_expiry))); db_commit(); } } } // if public views are disabled, sitemap generation must also be disabled. if ($values['allowpublicviews'] == false) { $values['generatesitemap'] = false; } else { // Ensure allowpublicprofiles is set as well $values['allowpublicprofiles'] = 1; } $oldsearchplugin = get_config('searchplugin'); $oldlanguage = get_config('lang'); $oldtheme = get_config('theme'); foreach ($fields as $field) { if (!set_config($field, $values[$field])) { siteoptions_fail($form, $field); } } if ($oldlanguage != $values['lang']) { safe_require('artefact', 'file'); ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']); } save_notification_settings($values, null, true); if ($oldsearchplugin != $values['searchplugin']) { // Call the old search plugin's sitewide cleanup method safe_require('search', $oldsearchplugin); call_static_method(generate_class_name('search', $oldsearchplugin), 'cleanup_sitewide'); // Call the new search plugin's sitewide initialize method safe_require('search', $values['searchplugin']); $initialize = call_static_method(generate_class_name('search', $values['searchplugin']), 'initialize_sitewide'); if (!$initialize) { $form->reply(PIEFORM_ERR, array('message' => get_string('searchconfigerror1', 'admin', $values['searchplugin']), 'goto' => '/admin/site/options.php')); } } // Call the new search plugin's can connect safe_require('search', $values['searchplugin']); $connect = call_static_method(generate_class_name('search', $values['searchplugin']), 'can_connect'); if (!$connect) { $form->reply(PIEFORM_ERR, array('message' => get_string('searchconfigerror1', 'admin', $values['searchplugin']), 'goto' => '/admin/site/options.php')); } // submitted sessionlifetime is in minutes; db entry session_timeout is in seconds if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) { siteoptions_fail($form, 'sessionlifetime'); } // Submitted value is on/off; database entry should be 1/0 foreach (array('viruschecking', 'usersallowedmultipleinstitutions') as $checkbox) { if (!set_config($checkbox, (int) ($values[$checkbox] == 'on'))) { siteoptions_fail($form, $checkbox); } } if ($values['viruschecking'] == 'on') { $pathtoclam = escapeshellcmd(trim(get_config('pathtoclam'))); if (!$pathtoclam) { $form->reply(PIEFORM_ERR, array('message' => get_string('clamnotset', 'mahara', $pathtoclam), 'goto' => '/admin/site/options.php')); } else { if (!file_exists($pathtoclam) && !is_executable($pathtoclam)) { $form->reply(PIEFORM_ERR, array('message' => get_string('clamlost', 'mahara', $pathtoclam), 'goto' => '/admin/site/options.php')); } } } if (get_config('recaptchaonregisterform') && !(get_config('recaptchapublickey') && get_config('recaptchaprivatekey'))) { $form->reply(PIEFORM_ERR, array('message' => get_string('recaptchakeysmissing1', 'admin'), 'goto' => '/admin/site/options.php')); } // Need to clear the cached menus in case site config changes effect them. clear_menu_cache(); $message = get_string('siteoptionsset', 'admin'); if ($oldtheme != $values['theme']) { global $USER; $message .= ' ' . get_string('usersseenewthemeonlogin', 'admin'); $USER->reset_institutions(); } if ($count) { $message .= ' ' . get_string('numberusersupdated', 'admin', $count); } $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => '/admin/site/options.php')); }
* @param string $status A human-readable string describing the current step */ function export_iframe_progress_handler($percent, $status) { print_iframe_progress_handler($percent, $status); flush(); } // Bail if we don't have enough data to do an export if (!isset($exportdata['format']) || !isset($exportdata['what']) || !isset($exportdata['views'])) { export_iframe_die(get_string('unabletogenerateexport', 'export')); exit; } safe_require('export', $exportdata['format']); $user = new User(); $user->find_by_id($USER->get('id')); $class = generate_class_name('export', $exportdata['format']); switch ($exportdata['what']) { case 'all': $exporter = new $class($user, PluginExport::EXPORT_ALL_VIEWS, PluginExport::EXPORT_ALL_ARTEFACTS, 'export_iframe_progress_handler'); break; case 'views': $exporter = new $class($user, $exportdata['views'], PluginExport::EXPORT_ARTEFACTS_FOR_VIEWS, 'export_iframe_progress_handler'); break; case 'collections': $exporter = new $class($user, $exportdata['views'], PluginExport::EXPORT_COLLECTIONS, 'export_iframe_progress_handler'); break; default: export_iframe_die(get_string('unabletoexportportfoliousingoptions', 'export')); } $exporter->includefeedback = $exportdata['includefeedback']; // Get an estimate of how big the unzipped export file would be
function artefact_get_types_from_filter($filter) { static $contenttype_artefacttype = null; if (is_null($contenttype_artefacttype)) { $contenttype_artefacttype = array(); foreach (require_artefact_plugins() as $plugin) { $classname = generate_class_name('artefact', $plugin->name); if (!is_callable($classname . '::get_artefact_type_content_types')) { continue; } $artefacttypetypes = call_static_method($classname, 'get_artefact_type_content_types'); foreach ($artefacttypetypes as $artefacttype => $contenttypes) { if (!empty($contenttypes)) { foreach ($contenttypes as $ct) { $contenttype_artefacttype[$ct][] = $artefacttype; } } } } } if (empty($contenttype_artefacttype[$filter])) { return null; } return $contenttype_artefacttype[$filter]; }
public function notify_user($user) { $changes = new stdClass(); $userdata = $this->to_stdclass(); // some stuff gets overridden by user specific stuff if (!empty($user->url)) { $userdata->url = $user->url; } if (empty($user->lang) || $user->lang == 'default') { $user->lang = get_config('lang'); } if (empty($user->method)) { // If method is not set then either the user has selected 'none' or their setting has not been set (so use default). if ($record = get_record('usr_activity_preference', 'usr', $user->id, 'activity', $this->get_id())) { $user->method = $record->method; if (empty($user->method)) { // The user specified 'none' as their notification type. return; } } else { $user->method = $this->get_default_method(); if (empty($user->method)) { // The default notification type is 'none' for this activity type. return; } } } // always do internal foreach (PluginNotificationInternal::$userdata as &$p) { $function = 'get_' . $p; $userdata->{$p} = $this->{$function}($user); } $userdata->internalid = PluginNotificationInternal::notify_user($user, $userdata); if ($this->update_url($userdata->internalid)) { $changes->url = $userdata->url = $this->url; } if ($user->method != 'internal' || isset($changes->url)) { // OVERWRITE 1: replacement, changed from: //$changes->read = (int) ($user->method != 'internal'); $changes->read = 0; // END OVERWRITE 1 $changes->id = $userdata->internalid; update_record('notification_internal_activity', $changes); } if ($user->method != 'internal') { $method = $user->method; safe_require('notification', $method); $notificationclass = generate_class_name('notification', $method); $classvars = get_class_vars($notificationclass); if (!empty($classvars['userdata'])) { foreach ($classvars['userdata'] as &$p) { $function = 'get_' . $p; if (!isset($userdata->{$p}) && method_exists($this, $function)) { $userdata->{$p} = $this->{$function}($user); } } } try { call_static_method($notificationclass, 'notify_user', $user, $userdata); } catch (MaharaException $e) { static $badnotification = false; static $adminnotified = array(); // We don't mind other notification methods failing, as it'll // go into the activity log as 'unread' $changes->read = 0; update_record('notification_internal_activity', $changes); if (!$badnotification && !($e instanceof EmailDisabledException || $e instanceof InvalidEmailException)) { // Admins should probably know about the error, but to avoid sending too many similar notifications, // save an initial prefix of the message being sent and throw away subsequent exceptions with the // same prefix. To cut down on spam, it's worth missing out on a few similar messages. $k = substr($e, 0, 60); if (!isset($adminnotified[$k])) { $message = (object) array('users' => get_column('usr', 'id', 'admin', 1), 'subject' => get_string('adminnotificationerror', 'activity'), 'message' => $e); $adminnotified[$k] = 1; $badnotification = true; activity_occurred('maharamessage', $message); $badnotification = false; } } } } // The user's unread message count does not need to be updated from $changes->read // because of the db trigger on notification_internal_activity. }
/** * Submit plugin account form values. * * @param Pieform $form * @param array $values * @return bool is page need to be refreshed */ function plugin_account_prefs_submit(Pieform $form, $values) { $reload = false; $elements = array(); $installed = plugin_all_installed(); foreach ($installed as $i) { if (!safe_require_plugin($i->plugintype, $i->name)) { continue; } $reload = call_static_method(generate_class_name($i->plugintype, $i->name), 'accountprefs_submit', $form, $values) || $reload; } return $reload; }
foreach ($jobs as $job) { if (!cron_lock($job, $start, $plugintype)) { continue; } // If some other cron instance ran the job while we were messing around, // skip it. $nextrun = get_field_sql(' SELECT ' . db_format_tsfield('nextrun') . ' FROM {' . $table . '} WHERE plugin = ? AND callfunction = ?', array($job->plugin, $job->callfunction)); if ($nextrun != $job->nextrun) { log_info("Too late to run {$plugintype} {$job->plugin} {$job->callfunction}; skipping."); cron_free($job, $start, $plugintype); continue; } $classname = generate_class_name($plugintype, $job->plugin); log_info("Running {$classname}::" . $job->callfunction); safe_require($plugintype, $job->plugin, 'lib.php', 'require_once'); try { call_static_method($classname, $job->callfunction); } catch (Exception $e) { log_message($e->getMessage(), LOG_LEVEL_WARN, true, true, $e->getFile(), $e->getLine(), $e->getTrace()); $output = $e instanceof MaharaException ? $e->render_exception() : $e->getMessage(); echo "{$output}\n"; // Don't call handle_exception; try to update next run time and free the lock } $nextrun = cron_next_run_time($start, (array) $job); // update next run time set_field($plugintype . '_cron', 'nextrun', db_format_timestamp($nextrun), 'plugin', $job->plugin, 'callfunction', $job->callfunction); cron_free($job, $start, $plugintype); $now = $fake ? time() - ($realstart - $start) : time();
public function get_data($key, $id) { if (!isset($this->temp[$key][$id])) { $blocktypeclass = generate_class_name('blocktype', $this->get('blocktype')); if (!isset($this->temp[$key])) { $this->temp[$key] = array(); } $this->temp[$key][$id] = call_static_method($blocktypeclass, 'get_instance_' . $key, $id); } return $this->temp[$key][$id]; }