public static function render_instance(BlockInstance $instance, $editing = false) { global $USER, $THEME; $configdata = $instance->get('configdata'); $desiredtypes = array(); foreach ($configdata as $k => $v) { if (!empty($v) && $k != 'maxitems') { $type = preg_replace('/[^a-z]+/', '', $k); $desiredtypes[$type] = $type; } } if ($USER->get('admin') && !empty($desiredtypes['adminmessages'])) { unset($desiredtypes['adminmessages']); $desiredtypes += get_column('activity_type', 'name', 'admin', 1); } $maxitems = isset($configdata['maxitems']) ? $configdata['maxitems'] : 5; // check if multirecipientnotification plugin is active or if we proceed here if (record_exists('module_installed', 'name', 'multirecipientnotification', 'active', '1') && safe_require_plugin('module', 'multirecipientnotification')) { global $USER; $userid = $USER->get('id'); $activitylist = activityblocklistin(join(',', $desiredtypes), $maxitems); $records = $activitylist->records; $showmore = $activitylist->count > $maxitems; // use a different template $smartytemplate = 'blocktype:inbox:inboxmr.tpl'; } else { $records = array(); if ($desiredtypes) { $sql = "\n SELECT n.id, n.subject, n.message, n.url, n.urltext, n.read, t.name AS type\n FROM {notification_internal_activity} n JOIN {activity_type} t ON n.type = t.id\n WHERE n.usr = ?\n AND t.name IN (" . join(',', array_map('db_quote', $desiredtypes)) . ")\n ORDER BY n.ctime DESC\n LIMIT ?;"; $records = get_records_sql_array($sql, array($USER->get('id'), $maxitems + 1)); } // Hack to decide whether to show the More... link if ($showmore = count($records) > $maxitems) { unset($records[$maxitems]); } if ($records) { foreach ($records as &$r) { $r->message = format_notification_whitespace($r->message, $r->type); } } $smartytemplate = 'blocktype:inbox:inbox.tpl'; } if ($records) { require_once 'activity.php'; foreach ($records as &$r) { $section = empty($r->plugintype) ? 'activity' : "{$r->plugintype}.{$r->pluginname}"; $r->strtype = get_string('type' . $r->type, $section); } } $smarty = smarty_core(); if ($showmore) { $smarty->assign('morelink', self::get_link($instance) . '?type=' . implode(',', $desiredtypes)); } $smarty->assign('blockid', 'blockinstance_' . $instance->get('id')); $smarty->assign('items', $records); return $smarty->fetch($smartytemplate); }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; $userid = $instance->get_view()->get('owner'); if (!$userid) { // 'My Friends' doesn't make sense for group/site views return ''; } $smarty = smarty_core(); $records = get_records_sql_array('SELECT usr1, usr2 FROM {usr_friend} JOIN {usr} u1 ON (u1.id = usr1 AND u1.deleted = 0) JOIN {usr} u2 ON (u2.id = usr2 AND u2.deleted = 0) WHERE usr1 = ? OR usr2 = ? ORDER BY ' . db_random() . ' LIMIT ?', array($userid, $userid, MAXFRIENDDISPLAY)); // get the friends into a 4x4 array if ($records) { $friends = array(); for ($i = 0; $i < 4; $i++) { if (isset($records[4 * $i])) { $friends[$i] = array(); for ($j = 4 * $i; $j < ($i + 1) * 4; $j++) { if (isset($records[$j])) { if ($records[$j]->usr1 == $userid) { $friends[$i][] = $records[$j]->usr2; } else { $friends[$i][] = $records[$j]->usr1; } } } } } } else { $friends = false; } $smarty->assign('friends', $friends); // If the user has no friends, try and display something useful, such // as a 'request friendship' button $loggedinid = $USER->get('id'); $is_friend = is_friend($userid, $loggedinid); if ($is_friend) { $relationship = 'existingfriend'; } else { if (record_exists('usr_friend_request', 'requester', $loggedinid, 'owner', $userid)) { $relationship = 'requestedfriendship'; } else { $relationship = 'none'; $friendscontrol = get_account_preference($userid, 'friendscontrol'); if ($friendscontrol == 'auto') { $newfriendform = pieform(array('name' => 'myfriends_addfriend', 'successcallback' => 'addfriend_submit', 'autofocus' => false, 'renderer' => 'div', 'elements' => array('add' => array('type' => 'submit', 'value' => get_string('addtomyfriends', 'group')), 'id' => array('type' => 'hidden', 'value' => $userid)))); $smarty->assign('newfriendform', $newfriendform); } $smarty->assign('friendscontrol', $friendscontrol); } } $smarty->assign('relationship', $relationship); $smarty->assign_by_ref('USER', $USER); $smarty->assign('USERID', $userid); return $smarty->fetch('blocktype:myfriends:myfriends.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); $result = ''; if (!empty($configdata['artefactids'])) { $artefactids = implode(', ', array_map('db_quote', $configdata['artefactids'])); if (!($mostrecent = get_records_sql_array('SELECT a.title, ' . db_format_tsfield('a.ctime', 'ctime') . ', p.title AS parenttitle, a.id, a.parent FROM {artefact} a JOIN {artefact} p ON a.parent = p.id WHERE a.artefacttype = \'blogpost\' AND a.parent IN ( ' . $artefactids . ' ) AND a.owner = (SELECT owner from {view} WHERE id = ?) ORDER BY a.ctime DESC LIMIT 10', array($instance->get('view'))))) { $mostrecent = array(); } // format the dates foreach ($mostrecent as &$data) { $data->displaydate = format_date($data->ctime); } $smarty = smarty_core(); $smarty->assign('mostrecent', $mostrecent); $smarty->assign('view', $instance->get('view')); $result = $smarty->fetch('blocktype:recentposts:recentposts.tpl'); } return $result; }
public static function render_instance(BlockInstance $instance, $editing = false) { safe_require('artefact', 'survey'); //require_once(dirname(dirname(dirname(__FILE__))) . '/dwoo/function.survey_name.php'); $configdata = $instance->get('configdata'); // this will make sure to unserialize it for us $survey = isset($configdata['survey']) ? $configdata['survey'] : ''; $userid = isset($configdata['userid']) ? $configdata['userid'] : ''; //$showresponses = (isset($configdata['showresponses']) ? $configdata['showresponses'] : false); //$showresults = (isset($configdata['showresults']) ? $configdata['showresults'] : true); $showchart = isset($configdata['showchart']) ? $configdata['showchart'] : true; $palette = isset($configdata['palette']) ? $configdata['palette'] : 'default'; $legend = isset($configdata['legend']) ? $configdata['legend'] : 'key'; $fonttype = isset($configdata['fonttype']) ? $configdata['fonttype'] : 'sans'; $fontsize = isset($configdata['fontsize']) ? $configdata['fontsize'] : 10; $height = isset($configdata['height']) ? $configdata['height'] : 250; $width = isset($configdata['width']) ? $configdata['width'] : 400; $artefactids = get_records_sql_array("SELECT\ta.id\n\t\t\tFROM {artefact} a\n\t\t\tWHERE a.artefacttype = 'survey' AND a.title = ? AND a.owner = ?\n\t\t\tORDER BY a.ctime DESC, a.mtime DESC", array($survey, $userid)); $data = array(); $first = true; foreach ($artefactids as $artefactid) { if ($first) { $alpha = 30; } else { $alpha = 10; } $data[] = array('id' => $artefactid->id, 'palette' => $palette, 'legend' => $legend, 'fonttype' => $fonttype, 'fontsize' => $fontsize, 'height' => $height, 'width' => $width, 'alpha' => $alpha); $first = false; } $smarty = smarty_core(); //$smarty->addPlugin('survey_name', 'Dwoo_Plugin_survey_name'); $smarty->assign('CHART', $showchart ? true : false); $smarty->assign('data', $data); return $smarty->fetch('blocktype:surveyhistory:surveyhistory.tpl'); }
function xmldb_blocktype_externalvideo_upgrade($oldversion = 0) { if ($oldversion < 2014030500) { $urlpattern = '#\\b(https?://)prezi\\.com/bin/preziloader\\.swf\\?prezi_id=([a-z0-9]+)\\b#'; $matches = array(); $sql = "SELECT id, configdata FROM {block_instance} WHERE blocktype='externalvideo'"; $records = get_records_sql_array($sql, array()); if ($records) { foreach ($records as $r) { $configdata = unserialize($r->configdata); if (isset($configdata['html'])) { preg_match($urlpattern, $configdata['html'], $matches); } else { if (isset($configdata['videoid'])) { preg_match($urlpattern, $configdata['videoid'], $matches); } } if (count($matches) >= 3) { $newurl = $matches[1] . 'prezi.com/embed/' . $matches[2]; $width = !empty($configdata['width']) ? $configdata['width'] : 0; $height = !empty($configdata['height']) ? $configdata['height'] : 0; $configdata['html'] = $configdata['videoid'] = PluginBlocktypeExternalvideo::iframe_code($newurl, $width, $height); set_field('block_instance', 'configdata', serialize($configdata), 'id', $r->id); } } } ensure_record_exists('iframe_source_icon', (object) array('name' => 'Prezi', 'domain' => 'prezi.com'), (object) array('name' => 'Prezi', 'domain' => 'prezi.com')); ensure_record_exists('iframe_source', (object) array('prefix' => 'prezi.com/embed/', 'name' => 'Prezi'), (object) array('prefix' => 'prezi.com/embed/', 'name' => 'Prezi')); update_safe_iframe_regex(); } return true; }
public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $smarty = smarty_core(); $filter = param_alpha('filter', 'all'); $offset = param_integer('offset', 0); $limit = 1000; //get list online friend $result_friend_online_id = get_onlinefriends($limit, $offset); $str_eselma_online = implode(',', $result_friend_online_id['data']); if ($str_eselma_online) { $query_result_friend_online = "\n SELECT *\n FROM {usr}\n WHERE id in ({$str_eselma_online})\n "; $result_friend_online = get_records_sql_array($query_result_friend_online); } //get list offline friend $result_friend_offline_id = get_offlinefriends($limit, $offset); $str_eselma_offline = implode(',', $result_friend_offline_id['data']); if ($str_eselma_offline) { $query_result_friend_offline = "\n SELECT *\n FROM {usr}\n WHERE id in ({$str_eselma_offline})\n "; $result_friend_offline = get_records_sql_array($query_result_friend_offline); } $smarty->assign('eselma_get_online', $result_friend_online); $smarty->assign('eselma_get_offline', $result_friend_offline); $smarty->assign('lastminutes', floor(get_config('accessidletimeout') / 60)); $smarty->assign('eselma_count_online', $result_friend_online_id['count']); $smarty->assign('eselma_count_offline', $result_friend_offline_id['count']); return $smarty->fetch('blocktype:eselmaonoff:content.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); $type = isset($configdata['displaytype']) ? $configdata['displaytype'] : 'texticon'; $showicon = $type == 'icononly' || $type == 'texticon' ? true : false; $showtext = $type == 'textonly' || $type == 'texticon' ? true : false; $owner = $instance->get('view_obj')->get('owner'); // Whether to include email button if (isset($configdata['displayemail']) && $configdata['displayemail']) { $email = get_field('artefact_internal_profile_email', 'email', 'principal', 1, 'owner', $owner); } else { $email = false; } if (!isset($configdata['artefactids']) || empty($configdata['artefactids'])) { // When we first come into this block, it will have // no social profiles configured yet. $configdata['artefactids'] = array(0); } // Include selected social profiles $sql = 'SELECT title, description, note FROM {artefact} WHERE id IN (' . join(',', $configdata['artefactids']) . ') AND owner = ? AND artefacttype = ? ORDER BY description ASC'; if (!($data = get_records_sql_array($sql, array($owner, 'socialprofile')))) { $data = array(); } safe_require('artefact', 'internal'); $data = ArtefactTypeSocialprofile::get_profile_icons($data); $smarty = smarty_core(); $smarty->assign('showicon', $showicon); $smarty->assign('showtext', $showtext); $smarty->assign('profiles', $data); $smarty->assign('email', $email); return $smarty->fetch('blocktype:socialprofile:content.tpl'); }
function mahara_group_get_groups($client) { $function = 'mahara_group_get_groups'; $dbgroups = get_records_sql_array('SELECT * FROM {group} WHERE institution = ? AND shortname = ? AND deleted = 0', array('mahara', 'mytestgroup1')); $params = array(); $groups = $client->call($function, $params); $this->assertEquals(count($groups), count($groups)); }
/** * Get all view access records relevant at the data of the indexing */ public static function view_access_records($viewid) { $records = get_records_sql_array(' SELECT va.view AS view_id, va.accesstype, va.group, va.role, va.usr, va.institution FROM {view_access} va WHERE va.view = ? AND (startdate IS NULL OR startdate < current_timestamp) AND (stopdate IS NULL OR stopdate > current_timestamp)', array($viewid)); return $records; }
function search_functions($request, $limit, $offset) { $data = array('count' => 0, 'data' => false); $sql = "SELECT * FROM {external_functions} WHERE name LIKE ?"; $values = array('%' . $request . '%'); if ($results = get_records_sql_array($sql, $values, $offset, $limit)) { $data['count'] = sizeof(get_records_sql_array($sql, $values)); $data['data'] = (array) $results; } return $data; }
/** * Get all view access records relevant at the data of the indexing */ public static function collection_access_records($id) { $records = get_records_sql_array(' SELECT vac.view AS view_id, vac.accesstype, vac.group, vac.role, vac.usr, vac.institution FROM {view_access} vac INNER JOIN {collection_view} vcol ON vac.view = vcol.view WHERE vcol.collection = ? AND (vac.startdate IS NULL OR vac.startdate < current_timestamp) AND (vac.stopdate IS NULL OR vac.stopdate > current_timestamp)', array($id)); return $records; }
function xmldb_interaction_forum_upgrade($oldversion = 0) { if ($oldversion < 2009062300) { foreach (array('topic', 'forum') as $type) { log_debug("Subscription upgrade for {$type}s"); // Add missing primary key to the subscription tables // Step 1: remove duplicates if ($dupes = get_records_sql_array(' SELECT "user", ' . $type . ', COUNT(*) FROM {interaction_forum_subscription_' . $type . '} GROUP BY "user", ' . $type . ' HAVING COUNT(*) > 1', array())) { // We found duplicate subscriptions to a topic/forum foreach ($dupes as $dupe) { log_debug("interaction.forum: Removing duplicate {$type} subscription for {$dupe->user}"); delete_records('interaction_forum_subscription_' . $type, 'user', $dupe->user, $type, $dupe->{$type}); insert_record('interaction_forum_subscription_' . $type, (object) array('user' => $dupe->user, $type => $dupe->{$type})); } } // Step 2: add the actual key $table = new XMLDBTable('interaction_forum_subscription_' . $type); $key = new XMLDBKey('primary'); $key->setAttributes(XMLDB_KEY_PRIMARY, array('user', $type)); add_key($table, $key); // Add a 'key' column, used for unsubscriptions $field = new XMLDBField('key'); $field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, null); add_field($table, $field); $key = new XMLDBKey('keyuk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('key')); add_key($table, $key); // Populate the key column if ($records = get_records_array('interaction_forum_subscription_' . $type, '', '', '', '"user", ' . $type)) { foreach ($records as $where) { $new = (object) array('user' => $where->user, $type => $where->{$type}, 'key' => dechex(mt_rand())); update_record('interaction_forum_subscription_' . $type, $new, $where); } } // Now make the key column not null $field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, XMLDB_NOTNULL); change_field_notnull($table, $field); } } if ($oldversion < 2009081700) { if (!get_record('interaction_config', 'plugin', 'forum', 'field', 'postdelay')) { insert_record('interaction_config', (object) array('plugin' => 'forum', 'field' => 'postdelay', 'value' => 30)); } } if ($oldversion < 2009081800) { $subscription = (object) array('plugin' => 'forum', 'event' => 'creategroup', 'callfunction' => 'create_default_forum'); ensure_record_exists('interaction_event_subscription', $subscription, $subscription); } return true; }
public static function render_instance(BlockInstance $instance, $editing = false) { $userid = $instance->get_view()->get('owner'); if (!$userid) { return ''; } $smarty = smarty_core(); // Get viewable views $views = array(); if ($allviews = get_records_select_array('view', "\"owner\" = ? AND type NOT IN ('profile', 'dashboard')", array($userid))) { foreach ($allviews as $view) { if (can_view_view($view->id)) { $views[$view->id] = $view; $view->artefacts = array(); } } } if ($views) { $viewidlist = implode(', ', array_map(create_function('$a', 'return (int)$a->id;'), $views)); $artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin FROM {view_artefact} va INNER JOIN {artefact} a ON va.artefact = a.id INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name WHERE va.view IN (' . $viewidlist . ') GROUP BY 1, 2, 3, 4, 5 ORDER BY a.title, va.artefact', ''); if ($artefacts) { foreach ($artefacts as $artefactrec) { safe_require('artefact', $artefactrec->plugin); // Perhaps I shouldn't have to construct the entire // artefact object to render the name properly. $classname = generate_artefact_class_name($artefactrec->artefacttype); $artefactobj = new $classname(0, array('title' => $artefactrec->title)); $artefactobj->set('dirty', false); if (!$artefactobj->in_view_list()) { continue; } $artname = $artefactobj->display_title(30); if (strlen($artname)) { $views[$artefactrec->view]->artefacts[] = array('id' => $artefactrec->artefact, 'title' => $artname); } } } $tags = get_records_select_array('view_tag', 'view IN (' . $viewidlist . ')'); if ($tags) { foreach ($tags as &$tag) { $views[$tag->view]->tags[] = $tag->tag; } } } $smarty->assign('VIEWS', $views); return $smarty->fetch('blocktype:myviews:myviews.tpl'); }
function delete_all_notifications_submit() { global $USER, $SESSION; $userid = $USER->get('id'); $type = param_variable('type', 'all'); $typesql = ''; if ($type != 'all') { // Treat as comma-separated list of activity type names $types = explode(',', preg_replace('/[^a-z,]+/', '', $type)); if ($types) { $typesql = ' at.name IN (' . join(',', array_map('db_quote', $types)) . ')'; if (in_array('adminmessages', $types)) { $typesql = '(' . $typesql . ' OR at.admin = 1)'; } $typesql = ' AND ' . $typesql; } } $from = "\n FROM {notification_internal_activity} a\n JOIN {activity_type} at ON a.type = at.id\n WHERE a.usr = ? {$typesql}"; $values = array($userid); db_begin(); $count = 0; $records = get_records_sql_array('SELECT a.id ' . $from, $values); if ($records) { $count = sizeof($records); $ids = array(); foreach ($records as $row) { $ids[] = $row->id; } // Remove parent pointers to messages we're about to delete execute_sql(' UPDATE {notification_internal_activity} SET parent = NULL WHERE parent IN ( ' . join(',', array_map('db_quote', $ids)) . ' )'); // delete execute_sql(' DELETE FROM {notification_internal_activity} WHERE id IN ( ' . join(',', array_map('db_quote', $ids)) . ' )'); // The update_unread_delete db trigger on notification_internal_activity // will update the unread column on the usr table. } db_commit(); $SESSION->add_ok_msg(get_string('deletednotifications1', 'activity', $count)); safe_require('module', 'multirecipientnotification'); if (PluginModuleMultirecipientnotification::is_active()) { redirect(get_config('wwwroot') . 'module/multirecipientnotification/inbox.php?type=' . $type); } else { redirect(get_config('wwwroot') . 'account/activity/index.php?type=' . $type); } }
function xmldb_blocktype_textbox_upgrade($oldversion = 0) { if ($oldversion < 2011082200) { // Convert all textbox html content to artefacts $tbcount = count_records('block_instance', 'blocktype', 'textbox'); $sql = ' SELECT b.id, b.title, b.configdata, b.view, v.owner, v.group, v.institution, v.ctime, v.mtime, v.atime FROM {block_instance} b JOIN {view} v ON b.view = v.id WHERE b.id > ? AND b.blocktype = ? ORDER BY b.id'; $done = 0; $lastid = 0; if (is_mysql()) { $mp = mysql_get_variable('max_allowed_packet'); $limit = $mp && is_numeric($mp) && $mp > 1048576 ? $mp / 8192 : 100; } else { $limit = 5000; } while ($records = get_records_sql_array($sql, array($lastid, 'textbox'), 0, $limit)) { // Create the new artefacts $values = array(); foreach ($records as $r) { $configdata = unserialize($r->configdata); array_push($values, 'html', $r->ctime, $r->mtime, $r->atime, $r->title, isset($configdata['text']) ? $configdata['text'] : '', $r->owner, $r->group, $r->institution, $r->owner > 0 ? $r->owner : null, $r->owner > 0 ? null : '?', $r->id); // Dumping the block id in the note column makes it easier to update block_instance later } $insertsql = "\n INSERT INTO {artefact}\n (artefacttype, ctime, mtime, atime, title, description, owner, \"group\", institution, author, authorname, note)\n VALUES "; $insertsql .= join(',', array_fill(0, count($records), '(?,?,?,?,?,?,?,?,?,?,?,?)')); execute_sql($insertsql, $values); // Update block_instance configdata to point at the new artefacts if (is_postgres()) { execute_sql("\n UPDATE {block_instance}\n SET configdata = 'a:1:{s:10:\"artefactid\";i:' || a.id::text || ';}'\n FROM (\n SELECT id, note FROM {artefact} WHERE artefacttype = 'html' AND note IS NOT NULL\n ) a\n WHERE blocktype = 'textbox' AND {block_instance}.id::text = a.note"); // Update view_artefact table execute_sql("\n INSERT INTO {view_artefact} (view, block, artefact)\n SELECT b.view, b.id, a.id\n FROM {block_instance} b, {artefact} a\n WHERE b.blocktype = 'textbox' AND a.artefacttype = 'html' AND a.note IS NOT NULL AND CAST(b.id AS TEXT) = a.note", array()); } else { if (is_mysql()) { execute_sql("\n UPDATE {block_instance}, {artefact}\n SET {block_instance}.configdata = CONCAT('a:1:{s:10:\"artefactid\";i:', {artefact}.id, ';}')\n WHERE\n {artefact}.artefacttype = 'html'\n AND {artefact}.note IS NOT NULL\n AND {block_instance}.blocktype = 'textbox'\n AND {block_instance}.id = {artefact}.note"); // Update view_artefact table execute_sql("\n INSERT INTO {view_artefact} (view, block, artefact)\n SELECT b.view, b.id, a.id\n FROM {block_instance} b, {artefact} a\n WHERE b.blocktype = 'textbox' AND a.artefacttype = 'html' AND a.note IS NOT NULL AND b.id = a.note", array()); } } // Remove the dodgy block id in the note column execute_sql("UPDATE {artefact} SET note = NULL WHERE artefacttype = 'html' AND note IS NOT NULL"); $done += count($records); log_debug("Upgrading textbox blocks: {$done}/{$tbcount}"); $last = end($records); $lastid = $last->id; } } return true; }
public static function setup_links(&$links, $viewids, $artefactids) { $viewlist = join(',', array_map('intval', $viewids)); $artefactlist = join(',', array_map('intval', $artefactids)); // Get the annotations that are on these views. $records = get_records_select_array('artefact_annotation', "view IN ({$viewlist})", array(), '', 'annotation,view'); if ($records) { foreach ($records as &$r) { // view is reflected_on_by annotation (at the current moment). if (!isset($links->viewartefact[$r->view][$r->annotation])) { $links->viewartefact[$r->view][$r->annotation] = array(); } $links->viewartefact[$r->view][$r->annotation][] = 'reflected_on_by'; // annotation reflects_on view (at the current moment). if (!isset($links->artefactview[$r->annotation][$r->view])) { $links->artefactview[$r->annotation][$r->view] = array(); } $links->artefactview[$r->annotation][$r->view][] = 'reflects_on'; // Get the embedded images in the annotation. $sql = "SELECT fileid\n FROM {artefact_file_embedded}\n WHERE resourceid = ?"; if ($files = get_records_sql_array($sql, array($r->annotation))) { foreach ($files as $file) { $links->attachments[$r->annotation][$file->fileid] = 1; } } // Get the feedback on the annotation. $sql = "SELECT f.artefact as feedback\n FROM {artefact_annotation_feedback} f\n WHERE f.onannotation = ?\n AND f.deletedby IS NULL\n ORDER BY f.artefact DESC"; if ($annotationfeedback = get_records_sql_array($sql, array($r->annotation))) { foreach ($annotationfeedback as $f) { // feedback reflects_on annotation. if (!isset($links->artefactartefact[$f->feedback][$r->annotation])) { $links->artefactartefact[$f->feedback][$r->annotation] = array(); } $links->artefactartefact[$f->feedback][$r->annotation][] = 'reflects_on'; // annotation is reflected_on_by feedback. if (!isset($links->artefactartefact[$r->annotation][$f->feedback])) { $links->artefactartefact[$r->annotation][$f->feedback] = array(); } $links->artefactartefact[$r->annotation][$f->feedback][] = 'reflected_on_by'; // Get the embedded images in the annotation feedback. $sql = "SELECT *\n FROM {artefact_file_embedded}\n WHERE resourceid = ?"; if ($files = get_records_sql_array($sql, array($f->feedback))) { foreach ($files as $file) { $links->attachments[$f->feedback][$file->fileid] = 1; } } } } } } }
public static function render_instance(BlockInstance $instance, $editing = false) { $configdata = $instance->get('configdata'); $result = ''; $limit = isset($configdata['count']) ? (int) $configdata['count'] : 10; if (!empty($configdata['artefactids'])) { $before = 'TRUE'; if ($instance->get_view()->is_submitted()) { if ($submittedtime = $instance->get_view()->get('submittedtime')) { // Don't display posts added after the submitted date. $before = "a.ctime < '{$submittedtime}'"; } } $artefactids = implode(', ', array_map('db_quote', $configdata['artefactids'])); if (!($mostrecent = get_records_sql_array('SELECT a.title, ' . db_format_tsfield('a.ctime', 'ctime') . ', p.title AS parenttitle, a.id, a.parent FROM {artefact} a JOIN {artefact} p ON a.parent = p.id JOIN {artefact_blog_blogpost} ab ON (ab.blogpost = a.id AND ab.published = 1) WHERE a.artefacttype = \'blogpost\' AND a.parent IN ( ' . $artefactids . ' ) AND a.owner = (SELECT "owner" from {view} WHERE id = ?) AND ' . $before . ' ORDER BY a.ctime DESC, a.id DESC LIMIT ' . $limit, array($instance->get('view'))))) { $mostrecent = array(); } // format the dates foreach ($mostrecent as &$data) { $data->displaydate = format_date($data->ctime); } $smarty = smarty_core(); $smarty->assign('mostrecent', $mostrecent); $smarty->assign('view', $instance->get('view')); $smarty->assign('blockid', $instance->get('id')); $smarty->assign('editing', $editing); if ($editing) { // Get id and title of configued blogs $recentpostconfigdata = $instance->get('configdata'); $wherestm = ' WHERE id IN (' . join(',', array_fill(0, count($recentpostconfigdata['artefactids']), '?')) . ')'; if (!($selectedblogs = get_records_sql_array('SELECT id, title FROM {artefact}' . $wherestm, $recentpostconfigdata['artefactids']))) { $selectedblogs = array(); } $smarty->assign('blogs', $selectedblogs); } $result = $smarty->fetch('blocktype:recentposts:recentposts.tpl'); } return $result; }
function get_accessible_surveys() { // Get names of all the survey responses (from other users) that are accessible to our user... global $USER; $results = get_records_sql_array("SELECT\ta.title\n\t\tFROM {artefact} a\n\t\tLEFT JOIN {artefact_access_usr} aau ON (aau.artefact = a.id)\n\t\tWHERE aau.usr = ?", array($USER->get('id'))); // Prepare our accessible surveys array so we can use it as options in drop-down select box... $survey_types = array('empty' => get_string('selectsurvey', 'artefact.survey')); if ($results) { // There can be (and often will be) duplicates of survey names: // two/more users can complete the same survey, but the responses will appear as different artefacts. // // We use/simulate mathematical concept of Set, which can contain only one instance of the same thing (survey in our case). // // We achieve that by checking if the current survey name is already contained in our accessible surveys array. // If not, we add the name of taht survey to our accessible surveys array $accessible_surveys = array(); foreach ($results as $result) { if (!in_array($result->title, $accessible_surveys)) { $accessible_surveys[] = $result->title; } } foreach ($accessible_surveys as $filename) { $LANGUAGE = ArtefactTypeSurvey::get_default_lang($filename); $xmlDoc = new DOMDocument('1.0', 'UTF-8'); $ch = curl_init(get_config('wwwroot') . 'artefact/survey/surveys/' . $filename); # Return http response in string curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $loaded = $xmlDoc->loadXML(curl_exec($ch)); if ($loaded) { $surveyname = $xmlDoc->getElementsByTagName('survey')->item(0)->getAttribute('name'); if (isset($surveyname) && $surveyname == substr($filename, 0, -4)) { $title = $xmlDoc->getElementsByTagName('title')->item(0)->getAttribute($LANGUAGE); $survey_types = array_merge($survey_types, array($filename => $title)); } else { $message = get_string('surveynameerror', 'artefact.survey', $filename); $_SESSION['messages'][] = array('type' => 'error', 'msg' => $message); } } else { $message = get_string('surveyerror', 'artefact.survey', $filename); $_SESSION['messages'][] = array('type' => 'error', 'msg' => $message); } } } return $survey_types; }
/** * Given a query string and limits, return an array of matching users using the * search plugin defined in config.php * * @param string The query string * @param integer How many results to return * @param integer What result to start at (0 == first result) * @return array A data structure containing results looking like ... * $results = array( * count => integer, // total number of results * limit => integer, // how many results are returned * offset => integer, // starting from which result * results => array( // the result records * array( * id => integer, * username => string, * institution => string, * firstname => string, * lastname => string, * preferredname => string, * email => string, * ), * array( * id => integer, * username => string, * institution => string, * firstname => string, * lastname => string, * preferredname => string, * email => string, * ), * array(...), * ), * ); */ function search_user($query_string, $limit, $offset = 0, $data = array()) { $plugin = get_config('searchplugin'); safe_require('search', $plugin); safe_require('artefact', 'internal'); $publicfields = array_keys(ArtefactTypeProfile::get_public_fields()); if (empty($publicfields)) { $publicfields = array('preferredname'); } $fieldlist = "('" . join("','", $publicfields) . "')"; $results = call_static_method(generate_class_name('search', $plugin), 'search_user', $query_string, $limit, $offset, $data); if ($results['data']) { $userlist = '(' . join(',', array_map(create_function('$u', 'return (int)$u[\'id\'];'), $results['data'])) . ')'; $public_fields = get_records_sql_array(' SELECT u.id, a.artefacttype, a.title FROM {usr} u LEFT JOIN {artefact} a ON u.id=a.owner AND a.artefacttype IN ' . $fieldlist . ' WHERE u.id IN ' . $userlist . ' ORDER BY u.firstname, u.lastname, u.id, a.artefacttype', array()); $public_fields_byuser = array(); if (!empty($public_fields)) { foreach ($public_fields as $field) { // This will be null if the user does not have a field marked public if ($field->artefacttype !== null) { $public_fields_byuser[$field->id][$field->artefacttype] = $field->title; } } } foreach ($results['data'] as &$result) { $result['name'] = display_name($result); if (isset($public_fields_byuser[$result['id']])) { foreach ($public_fields_byuser[$result['id']] as $field => $value) { $result[$field] = $value; } } if (isset($result['country'])) { $result['country'] = get_string('country.' . $result['country']); } } } return $results; }
function mahara_user_get_users($client) { error_log('getting all users'); $function = 'mahara_user_get_users'; $dbusers = get_records_sql_array('SELECT u.id AS id FROM {usr} u INNER JOIN {auth_instance} ai ON u.authinstance = ai.id WHERE u.deleted = 0 AND ai.institution = \'mahara\'', array()); $userids = array(); foreach ($dbusers as $dbuser) { if ($dbuser->id == 0) { continue; } $userids[] = $dbuser->id; } $params = array(); $users = $client->call($function, $params); $this->assertEquals(count($users), count($userids)); }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; $configdata = $instance->get('configdata'); $instance_id = $instance->get('id'); $showinstance = isset($configdata["showinstance"]) ? (bool) $configdata["showinstance"] : True; $loggedinid = $USER->get('id'); $viewowner = get_field('view', 'owner', 'id', $instance->get('view')); if ($loggedinid && $loggedinid == $viewowner) { $ownprofile = true; } else { $ownprofile = false; } //Get information of user $query_user_info = "\n SELECT *\n FROM {artefact}\n WHERE owner = ? AND artefacttype in ('address', 'mobilenumber', 'email')"; $result_user_info = get_records_sql_array($query_user_info, array($viewowner)); foreach ($result_user_info as $result) { if ($result->artefacttype == "email") { $eselma_email = $result->title; } else { if ($result->artefacttype == "mobilenumber") { $eselma_mobilenumber = $result->title; } else { if ($result->artefacttype == "address") { $eselma_address = $result->title; } } } } //Get user's social media $query_social_media = "\n SELECT title, description, note FROM {artefact}\n WHERE owner = ? AND artefacttype = 'socialprofile'\n ORDER BY description ASC"; $data = get_records_sql_array($query_social_media, array($viewowner)); $smarty = smarty_core(); $smarty->assign('showinstance', $showinstance); $smarty->assign('instance_id', $instance_id); $smarty->assign('socialprofiles', $data); $smarty->assign('ownprofile', $ownprofile); $smarty->assign('eselma_address', $eselma_address); $smarty->assign('eselma_mobilenumber', $eselma_mobilenumber); $smarty->assign('eselma_email', $eselma_email); return $smarty->fetch('blocktype:eselmaprofileinfo:content.tpl'); }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; $loggedinid = $USER->get('id'); $viewowner = get_field('view', 'owner', 'id', $instance->get('view')); if ($loggedinid && $loggedinid == $viewowner) { $ownprofile = true; } else { $ownprofile = false; } $query_user = "******"; $result_user = get_records_sql_array($query_user, array($viewowner)); foreach ($result_user as $result) { if ($result->artefacttype == 'firstname') { $eselma_firstname = $result->title; } else { if ($result->artefacttype == 'lastname') { $eselma_lastname = $result->title; } else { if ($result->artefacttype == 'studentid') { $eselma_studentid = $result->title; } else { if ($result->artefacttype == 'preferredname') { $eselma_preferredname = $result->title; } else { if ($result->artefacttype == 'introduction') { $eselma_introduction = $result->title; } } } } } } $smarty = smarty_core(); $smarty->assign('ownprofile', $ownprofile); $smarty->assign('eselma_firstname', $eselma_firstname); $smarty->assign('eselma_lastname', $eselma_lastname); $smarty->assign('eselma_studentid', $eselma_studentid); $smarty->assign('eselma_preferredname', $eselma_preferredname); $smarty->assign('eselma_introduction', $eselma_introduction); return $smarty->fetch('blocktype:eselmaaboutme:content.tpl'); }
public static function instance_config_form(BlockInstance $instance) { $configdata = $instance->get('configdata'); $view = $instance->get_view(); $groupid = $view->get('group'); $institutionid = $view->get('institution'); $userid = $view->get('owner'); $urlparams['new'] = 1; if (!empty($groupid)) { $where = 'c.group = ?'; $values = array($groupid); $urlparams['group'] = $groupid; } else { if (!empty($institutionid)) { $where = 'c.institution = ?'; $values = array($institutionid); $urlparams['institution'] = $institutionid; } else { $where = 'c.owner = ?'; $values = array($userid); } } ($collections = get_records_sql_array("\n SELECT c.id, c.name\n FROM {collection} c\n WHERE " . $where . "\n ORDER BY c.name, c.ctime ASC", $values)) || ($collections = array()); $default = false; $options = array(); if (!empty($collections)) { foreach ($collections as $collection) { if (!$default) { // need to have an initially selected item $default = $collection->id; } $options[$collection->id] = $collection->name; } return array('collection' => array('type' => 'select', 'title' => get_string('collection', 'blocktype.navigation'), 'rules' => array('required' => true), 'options' => $options, 'defaultvalue' => !empty($configdata['collection']) ? $configdata['collection'] : $default)); } else { $baseurl = get_config('wwwroot') . 'collection/edit.php'; if ($urlparams) { $baseurl .= '?' . http_build_query($urlparams); } return array('nocollections' => array('type' => 'html', 'title' => get_string('collection', 'blocktype.navigation'), 'description' => get_string('nocollections1', 'blocktype.navigation', $baseurl), 'value' => '')); } }
public static function instance_config_form($instance) { $configdata = $instance->get('configdata'); $userid = $instance->get_view()->get('owner'); ($collections = get_records_sql_array("\n SELECT c.id, c.name\n FROM {collection} c\n WHERE c.owner = ?\n ORDER BY c.name, c.ctime ASC", array($userid))) || ($collections = array()); $default = false; $options = array(); if (!empty($collections)) { foreach ($collections as $collection) { if (!$default) { // need to have an initially selected item $default = $collection->id; } $options[$collection->id] = $collection->name; } return array('collection' => array('type' => 'select', 'title' => get_string('collection', 'blocktype.navigation'), 'rules' => array('required' => true), 'options' => $options, 'defaultvalue' => !empty($configdata['collection']) ? $configdata['collection'] : $default)); } else { return array('nocollections' => array('type' => 'html', 'title' => get_string('collection', 'blocktype.navigation'), 'description' => get_string('nocollections', 'blocktype.navigation', get_config('wwwroot')), 'value' => '')); } }
/** * Detect the proper auth instance based on received user information. * * @param \auth_oidc\jwt $idtoken JWT ID Token. * @return int|null The auth instance ID if found, or null if none found. */ protected function detect_auth_instance($idtoken) { // Get auth instance. $sql = 'SELECT ai.id as instanceid, i.priority as institutionpriority FROM {auth_instance} ai JOIN {institution} i ON i.name = ai.institution WHERE ai.authname = \'oidc\' ORDER BY i.priority DESC, ai.priority ASC'; $instances = get_records_sql_array($sql); $catchalls = array(); $instanceid = null; foreach ($instances as $instance) { $reqattr = get_config_plugin_instance('auth', $instance->instanceid, 'institutionattribute'); $reqval = get_config_plugin_instance('auth', $instance->instanceid, 'institutionvalue'); if (empty($reqattr) || empty($reqval)) { $catchalls[$instance->institutionpriority][] = $instance; } else { // Check if we received specified attribute. $userattrval = $idtoken->claim($reqattr); if (!empty($userattrval)) { // Match value. if (preg_match('#' . trim($reqval) . '#', $userattrval)) { $instanceid = $instance->instanceid; break; } } } } // If no match on attribute, get the instance id of the first catchall by priority. if (empty($instanceid)) { foreach ($catchalls as $priority => $instances) { foreach ($instances as $instance) { $instanceid = $instance->instanceid; break; } break; } } return $instanceid; }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; $configdata = $instance->get('configdata'); $desiredtypes = array(); foreach ($configdata as $k => $v) { if (!empty($v) && $k != 'maxitems') { $type = preg_replace('/[^a-z]+/', '', $k); $desiredtypes[$type] = $type; } } if ($USER->get('admin') && !empty($desiredtypes['adminmessages'])) { unset($desiredtypes['adminmessages']); $desiredtypes += get_column('activity_type', 'name', 'admin', 1); } $maxitems = isset($configdata['maxitems']) ? $configdata['maxitems'] : 5; $records = array(); if ($desiredtypes) { $sql = "\n SELECT n.id, n.subject, n.message, n.url, n.urltext, n.read, t.name AS type\n FROM {notification_internal_activity} n JOIN {activity_type} t ON n.type = t.id\n WHERE n.usr = ?\n AND t.name IN (" . join(',', array_map('db_quote', $desiredtypes)) . ")\n ORDER BY n.ctime DESC\n LIMIT ?;"; $records = get_records_sql_array($sql, array($USER->get('id'), $maxitems + 1)); } // Hack to decide whether to show the More... link if ($showmore = count($records) > $maxitems) { unset($records[$maxitems]); } if ($records) { require_once 'activity.php'; foreach ($records as &$r) { $r->message = format_notification_whitespace($r->message, $r->type); } } $smarty = smarty_core(); if ($showmore) { $smarty->assign('desiredtypes', implode(',', $desiredtypes)); } $smarty->assign('blockid', 'blockinstance_' . $instance->get('id')); $smarty->assign('items', $records); return $smarty->fetch('blocktype:inbox:inbox.tpl'); }
public static function instance_config_form($group, $instance = null) { if (isset($instance)) { $instanceconfig = get_records_assoc('interaction_forum_instance_config', 'forum', $instance->get('id'), '', 'field,value'); $autosubscribe = isset($instanceconfig['autosubscribe']) ? $instanceconfig['autosubscribe']->value : false; $weight = isset($instanceconfig['weight']) ? $instanceconfig['weight']->value : null; $createtopicusers = isset($instanceconfig['createtopicusers']) ? $instanceconfig['createtopicusers']->value : null; $closetopics = !empty($instanceconfig['closetopics']); $indentmode = isset($instanceconfig['indentmode']) ? $instanceconfig['indentmode']->value : null; $maxindent = isset($instanceconfig['maxindent']) ? $instanceconfig['maxindent']->value : null; $moderators = get_column_sql('SELECT fm.user FROM {interaction_forum_moderator} fm JOIN {usr} u ON (fm.user = u.id AND u.deleted = 0) WHERE fm.forum = ?', array($instance->get('id'))); } if ($instance === null) { $exclude = ''; } else { $exclude = 'AND i.id != ' . db_quote($instance->get('id')); } $existing = get_records_sql_array(' SELECT i.id, i.title, c.value AS weight FROM {interaction_instance} i INNER JOIN {interaction_forum_instance_config} c ON (i.id = c.forum AND c.field = \'weight\') WHERE i.group = ? AND i.deleted != 1 ' . $exclude . ' ORDER BY c.value', array($group->id)); if ($existing) { foreach ($existing as &$item) { $item = (array) $item; } } else { $existing = array(); } return array('indentmode' => array('type' => 'select', 'title' => get_string('indentmode', 'interaction.forum'), 'options' => array('full_indent' => get_string('indentfullindent', 'interaction.forum'), 'max_indent' => get_string('indentmaxindent', 'interaction.forum'), 'no_indent' => get_string('indentflatindent', 'interaction.forum')), 'description' => get_string('indentmodedescription', 'interaction.forum'), 'defaultvalue' => isset($indentmode) ? $indentmode : 'full_indent', 'rules' => array('required' => true)), 'maxindent' => array('type' => 'text', 'title' => get_string('maxindent', 'interaction.forum'), 'size' => 2, 'defaultvalue' => isset($maxindent) ? $maxindent : 10, 'class' => isset($indentmode) && $indentmode == 'max_indent' ? '' : 'hidden', 'rules' => array('integer' => true, 'minvalue' => 1, 'maxvalue' => 100)), 'fieldset' => array('type' => 'fieldset', 'collapsible' => true, 'collapsed' => true, 'legend' => get_string('settings'), 'elements' => array('autosubscribe' => array('type' => 'select', 'title' => get_string('autosubscribeusers', 'interaction.forum'), 'options' => array(true => get_string('yes'), false => get_string('no')), 'description' => get_string('autosubscribeusersdescription', 'interaction.forum'), 'defaultvalue' => isset($autosubscribe) ? $autosubscribe : false, 'rules' => array('required' => true), 'help' => true), 'weight' => array('type' => 'weight', 'title' => get_string('Order', 'interaction.forum'), 'description' => get_string('orderdescription', 'interaction.forum'), 'defaultvalue' => isset($weight) ? $weight : count($existing), 'rules' => array('required' => true), 'existing' => $existing, 'ignore' => count($existing) == 0), 'moderator' => array('type' => 'userlist', 'title' => get_string('Moderators', 'interaction.forum'), 'description' => get_string('moderatorsdescription', 'interaction.forum'), 'defaultvalue' => isset($moderators) ? $moderators : null, 'group' => $group->id, 'includeadmins' => false, 'filter' => false, 'lefttitle' => get_string('potentialmoderators', 'interaction.forum'), 'righttitle' => get_string('currentmoderators', 'interaction.forum')), 'createtopicusers' => array('type' => 'select', 'title' => get_string('whocancreatetopics', 'interaction.forum'), 'options' => array('members' => get_string('allgroupmembers', 'group'), 'moderators' => get_string('moderatorsandgroupadminsonly', 'interaction.forum')), 'description' => get_string('createtopicusersdescription', 'interaction.forum'), 'defaultvalue' => isset($createtopicusers) && $createtopicusers == 'moderators' ? 'moderators' : 'members', 'rules' => array('required' => true)), 'closetopics' => array('type' => 'checkbox', 'title' => get_string('closetopics', 'interaction.forum'), 'description' => get_string('closetopicsdescription', 'interaction.forum'), 'defaultvalue' => !empty($closetopics))))); }
function xmldb_blocktype_groupviews_upgrade($oldversion = 0) { if ($oldversion < 2015090300) { $sql = "SELECT id, configdata FROM {block_instance} WHERE blocktype='groupviews'"; $records = get_records_sql_array($sql, array()); if ($records) { log_debug("Processing 'Group pages' blocks so they continue to display full list of pages/collections"); $count = 0; $limit = 500; $total = count($records); foreach ($records as $r) { $configdata = unserialize($r->configdata); $updateconfig = false; // Do we need to update the setting for shared views if (!isset($configdata['showsharedviews']) || $configdata['showsharedviews'] == 1) { $updateconfig = true; $configdata['showsharedviews'] = 2; } // Do we need to update the setting for shared collections if (!isset($configdata['showsharedcollections']) || $configdata['showsharedcollections'] == 1) { $updateconfig = true; $configdata['showsharedcollections'] = 2; } if ($updateconfig) { set_field('block_instance', 'configdata', serialize($configdata), 'id', $r->id); } $count++; if ($count % $limit == 0 || $count == $total) { log_debug("{$count}/{$total}"); set_time_limit(30); } } } } return true; }
* @package mahara * @subpackage core * @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. * */ define('INTERNAL', 1); define('JSON', 1); require dirname(dirname(dirname(__FILE__))) . '/init.php'; $result = get_records_sql_array('SELECT a.id, a.title, a.note, (u.profileicon = a.id) AS isdefault, COUNT (DISTINCT aa.artefact) AS attachcount, COUNT(DISTINCT va.view) AS viewcount, COUNT(DISTINCT s.id) AS skincount FROM {artefact} a LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id LEFT OUTER JOIN {artefact_attachment} aa ON aa.attachment = a.id LEFT OUTER JOIN {skin} s ON (s.bodybgimg = a.id OR s.viewbgimg = a.id) LEFT OUTER JOIN {usr} u ON (u.id = a.owner) WHERE artefacttype = \'profileicon\' AND a.owner = ? GROUP BY a.id, a.title, a.note, isdefault ORDER BY a.id', array($USER->get('id'))); $lastrow = array('id' => 0, 'isdefault' => 't', 'title' => get_string('standardavatartitle', 'artefact.file'), 'note' => get_string('standardavatarnote', 'artefact.file')); $usersdefaulticon = record_exists_select('usr', 'profileicon IS NULL AND id = ?', array($USER->get('id'))); if (!$usersdefaulticon) { $lastrow['isdefault'] = 'f'; } if (!$result) { $result = array(); } $result[] = $lastrow; $data['error'] = false;
function xmldb_artefact_file_upgrade($oldversion = 0) { $status = true; if ($oldversion < 2007010900) { $table = new XMLDBTable('artefact_file_files'); $field = new XMLDBField('adminfiles'); $field->setAttributes(XMLDB_TYPE_INTEGER, 1, false, true, false, null, null, 0); add_field($table, $field); set_field('artefact_file_files', 'adminfiles', 0); // Put all folders into artefact_file_files $folders = get_column_sql("\n SELECT a.id\n FROM {artefact} a\n LEFT OUTER JOIN {artefact_file_files} f ON a.id = f.artefact\n WHERE a.artefacttype = 'folder' AND f.artefact IS NULL"); if ($folders) { foreach ($folders as $folderid) { $data = (object) array('artefact' => $folderid, 'adminfiles' => 0); insert_record('artefact_file_files', $data); } } } if ($oldversion < 2007011800) { // Make sure the default quota is set set_config_plugin('artefact', 'file', 'defaultquota', 10485760); } if ($oldversion < 2007011801) { // Create image table $table = new XMLDBTable('artefact_file_image'); $table->addFieldInfo('artefact', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $table->addFieldInfo('width', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL); $table->addFieldInfo('height', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null); $table->addKeyInfo('artefactfk', XMLDB_KEY_FOREIGN, array('artefact'), 'artefact', array('id')); $status = $status && create_table($table); $images = get_column('artefact', 'id', 'artefacttype', 'image'); log_debug(count($images)); require_once get_config('docroot') . 'artefact/lib.php'; foreach ($images as $imageid) { $image = artefact_instance_from_id($imageid); $path = $image->get_path(); $image->set('dirty', false); $data = new StdClass(); $data->artefact = $imageid; if (file_exists($path)) { list($data->width, $data->height) = getimagesize($path); } if (empty($data->width) || empty($data->height)) { $data->width = 0; $data->height = 0; } insert_record('artefact_file_image', $data); } } if ($oldversion < 2007013100) { // Add new tables for file/mime types $table = new XMLDBTable('artefact_file_file_types'); $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL); $table->addFieldInfo('enabled', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1); $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('description')); create_table($table); $table = new XMLDBTable('artefact_file_mime_types'); $table->addFieldInfo('mimetype', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL); $table->addFieldInfo('description', XMLDB_TYPE_TEXT, 128, null, XMLDB_NOTNULL); $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('mimetype')); $table->addKeyInfo('descriptionfk', XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description')); create_table($table); safe_require('artefact', 'file'); PluginArtefactFile::resync_filetype_list(); } if ($oldversion < 2007021400) { $table = new XMLDBTable('artefact_file_files'); $field = new XMLDBField('oldextension'); $field->setAttributes(XMLDB_TYPE_TEXT); add_field($table, $field); } if ($oldversion < 2007042500) { // migrate everything we had to change to make mysql happy execute_sql("ALTER TABLE {artefact_file_file_types} ALTER COLUMN description TYPE varchar(32)"); execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN mimetype TYPE varchar(128)"); execute_sql("ALTER TABLE {artefact_file_mime_types} ALTER COLUMN description TYPE varchar(32)"); } if ($oldversion < 2008091100) { $table = new XMLDBTable('artefact_file_files'); $field = new XMLDBField('fileid'); $field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null); add_field($table, $field); execute_sql("UPDATE {artefact_file_files} SET fileid = artefact WHERE NOT size IS NULL"); } if ($oldversion < 2008101602) { $table = new XMLDBTable('artefact_file_files'); $field = new XMLDBField('filetype'); $field->setAttributes(XMLDB_TYPE_TEXT); add_field($table, $field); // Guess mime type for existing files $fileartefacts = get_records_sql_array(' SELECT a.artefacttype, f.artefact, f.oldextension, f.fileid FROM {artefact} a, {artefact_file_files} f WHERE a.id = f.artefact ', array()); require_once get_config('libroot') . 'file.php'; if ($fileartefacts) { foreach ($fileartefacts as $a) { $type = null; if ($a->artefacttype == 'image') { $size = getimagesize(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid); $type = $size['mime']; } else { if ($a->artefacttype == 'profileicon') { $size = getimagesize(get_config('dataroot') . 'artefact/file/profileicons/originals/' . $a->fileid % 256 . '/' . $a->fileid); $type = $size['mime']; } else { if ($a->artefacttype == 'file') { $type = get_mime_type(get_config('dataroot') . 'artefact/file/originals/' . $a->fileid % 256 . '/' . $a->fileid); } } } if ($type) { set_field('artefact_file_files', 'filetype', $type, 'artefact', $a->artefact); } } } delete_records('config', 'field', 'pathtofile'); } if ($oldversion < 2008101701) { if ($data = get_config_plugin('blocktype', 'internalmedia', 'enabledtypes')) { $olddata = unserialize($data); $newdata = array(); foreach ($olddata as $d) { if ($d == 'mov') { $newdata[] = 'quicktime'; } else { if ($d == 'mp4') { $newdata[] = 'mp4_video'; } else { if ($d != 'mpg') { $newdata[] = $d; } } } } set_config_plugin('blocktype', 'internalmedia', 'enabledtypes', serialize($newdata)); } } if ($oldversion < 2009021200) { $table = new XMLDBTable('artefact_file_mime_types'); $key = new XMLDBKey('artefilemimetype_des_fk'); $key->setAttributes(XMLDB_KEY_FOREIGN, array('description'), 'artefact_file_file_types', array('description')); drop_key($table, $key); $table = new XMLDBTable('artefact_file_file_types'); drop_table($table); PluginArtefactFile::resync_filetype_list(); } if ($oldversion < 2009021301) { // IE has been uploading jpegs with the image/pjpeg mimetype, // which is not recognised as an image by the download script. // Fix all existing jpegs in the db: set_field('artefact_file_files', 'filetype', 'image/jpeg', 'filetype', 'image/pjpeg'); // This won't happen again because we now read the contents of the // uploaded file to detect image artefacts, and overwrite the mime // type declared by the browser if we see an image. } if ($oldversion < 2009033000) { if (!get_record('artefact_config', 'plugin', 'file', 'field', 'uploadagreement')) { insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'uploadagreement', 'value' => 1)); insert_record('artefact_config', (object) array('plugin' => 'file', 'field' => 'usecustomagreement', 'value' => 1)); } } return $status; }