]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14679 towards blocks conversion
authorskodak <skodak>
Mon, 2 Jun 2008 20:15:51 +0000 (20:15 +0000)
committerskodak <skodak>
Mon, 2 Jun 2008 20:15:51 +0000 (20:15 +0000)
14 files changed:
blocks/glossary_random/block_glossary_random.php
blocks/html/block_html.php
blocks/mentees/block_mentees.php
blocks/messages/block_messages.php
blocks/mnet_hosts/block_mnet_hosts.php
blocks/moodleblock.class.php
blocks/online_users/block_online_users.php
blocks/quiz_results/block_quiz_results.php
blocks/quiz_results/config_instance.html
blocks/rss_client/block_rss_client.php
blocks/rss_client/block_rss_client_action.php
blocks/rss_client/config_instance.html
blocks/search/config_global.html
blocks/section_links/block_section_links.php

index 6fa57e51a25a14a3ca044984ff7c00c1e74caec0..0923d2d74b1872267ac96451704f5f6b3c46ae2d 100644 (file)
@@ -13,7 +13,7 @@ class block_glossary_random extends block_base {
     }
 
     function specialization() {
-        global $CFG, $COURSE;
+        global $CFG, $COURSE, $DB;
         $this->course = $COURSE;
 
         // load userdefined title and make sure it's never empty
@@ -35,8 +35,8 @@ class block_glossary_random extends block_base {
         if (time() > $this->config->nexttime) {
 
             // place glossary concept and definition in $pref->cache
-            if (!$numberofentries = count_records('glossary_entries','glossaryid',$this->config->glossary,
-                                                  'approved',1)) {
+            if (!$numberofentries = $DB->count_records('glossary_entries',
+                                                       array('glossaryid'=>$this->config->glossary, 'approved'=>1))) {
                 $this->config->cache = get_string('noentriesyet','block_glossary_random');
                 $this->instance_config_commit();
             }
@@ -72,11 +72,10 @@ class block_glossary_random extends block_base {
                     break;
             }
 
-            if ($entry = get_records_sql('  SELECT concept, definition, format '.
-                                         '    FROM '.$CFG->prefix.'glossary_entries'.
-                                         '   WHERE glossaryid = '.$this->config->glossary.
-                                         '     AND approved = 1 '.
-                                         'ORDER BY timemodified '.$SORT, $limitfrom, $limitnum)) {
+            if ($entry = $DB->get_records_sql("SELECT concept, definition, format
+                                                 FROM {glossary_entries}
+                                                WHERE glossaryid = ? AND approved = 1
+                                             ORDER BY timemodified $SORT", array($this->config->glossary), $limitfrom, $limitnum)) {
 
                 $entry = reset($entry);
 
@@ -153,7 +152,7 @@ class block_glossary_random extends block_base {
     }
 
     function get_content() {
-        global $USER, $CFG, $COURSE;
+        global $USER, $CFG, $COURSE, $DB;
 
         if (empty($this->config->glossary)) {
             $this->content->text   = get_string('notyetconfigured','block_glossary_random');
@@ -166,7 +165,7 @@ class block_glossary_random extends block_base {
         if ($this->course->id == $COURSE->id) {
             $course = $COURSE;
         } else {
-            $course = get_record('course', 'id', $this->course->id); 
+            $course = $DB->get_record('course', array('id'=>$this->course->id)); 
         }
 
         require_once($CFG->dirroot.'/course/lib.php');
index e894deae2f788a22ecbf941350a0783e4edda747..2086c49f11c3b6874a8e23ecda2f485ca3d9b2a3 100755 (executable)
@@ -65,16 +65,16 @@ class block_html extends block_base {
      * @return boolean
      **/
     function decode_content_links_caller($restore) {
-        global $CFG;
+        global $CFG, $DB;
 
-        if ($restored_blocks = get_records_select("backup_ids","table_name = 'block_instance' AND backup_code = $restore->backup_unique_code AND new_id > 0", "", "new_id")) {
+        if ($restored_blocks = $DB->get_records_select("backup_ids", "table_name = 'block_instance' AND backup_code = ? AND new_id > 0", array($restore->backup_unique_code), "", "new_id")) {
             $restored_blocks = implode(',', array_keys($restored_blocks));
             $sql = "SELECT bi.*
-                      FROM {$CFG->prefix}block_instance bi
-                           JOIN {$CFG->prefix}block b ON b.id = bi.blockid
+                      FROM {block_instance} bi
+                           JOIN {block} b ON b.id = bi.blockid
                      WHERE b.name = 'html' AND bi.id IN ($restored_blocks)"; 
 
-            if ($instances = get_records_sql($sql)) {
+            if ($instances = $DB->get_records_sql($sql)) {
                 foreach ($instances as $instance) {
                     $blockobject = block_instance('html', $instance);
                     $blockobject->config->text = restore_decode_absolute_links($blockobject->config->text);
index 87a85e40cfaf9c2c0f2f9680c05ca18d37b87ca8..cf645fe4e1a5f523ad0dbc1de10cfbe03d4fdd2a 100755 (executable)
@@ -20,21 +20,19 @@ class block_mentees extends block_base {
     }
 
     function get_content() {
-        
-        global $CFG, $USER;
+        global $CFG, $USER, $DB;
+
         if ($this->content !== NULL) {
             return $this->content;
         }
 
         // get all the mentees, i.e. users you have a direct assignment to
-        if ($usercontexts = get_records_sql("SELECT c.instanceid, c.instanceid, u.firstname, u.lastname
-                                         FROM {$CFG->prefix}role_assignments ra,
-                                              {$CFG->prefix}context c,
-                                              {$CFG->prefix}user u
-                                         WHERE ra.userid = $USER->id
-                                         AND   ra.contextid = c.id
-                                         AND   c.instanceid = u.id
-                                         AND   c.contextlevel = ".CONTEXT_USER)) {
+        if ($usercontexts = $DB->get_records_sql("SELECT c.instanceid, c.instanceid, u.firstname, u.lastname
+                                                    FROM {role_assignments} ra, {context} c, {user} u
+                                                   WHERE ra.userid = ?
+                                                         AND ra.contextid = c.id
+                                                         AND c.instanceid = u.id
+                                                         AND c.contextlevel = ".CONTEXT_USER, array($USER->id))) {
                                            
             $this->content->text = '<ul>';
             foreach ($usercontexts as $usercontext) {
index f152df17d72954b847f896c8080efb4bbdaa3df0..f86833cc101f503af9a5de3787e971aefcbc9c29 100644 (file)
@@ -7,7 +7,7 @@ class block_messages extends block_base {
     }
 
     function get_content() {
-        global $USER, $CFG;
+        global $USER, $CFG, $DB;
 
         if (!$CFG->messaging) {
             return ''; 
@@ -27,13 +27,11 @@ class block_messages extends block_base {
 
         $this->content->footer = '<a href="'.$CFG->wwwroot.'/message/index.php" onclick="this.target=\'message\'; return openpopup(\'/message/index.php\', \'message\', \'menubar=0,location=0,scrollbars,status,resizable,width=400,height=500\', 0);">'.get_string('messages', 'message').'</a>...';
 
-        $users = get_records_sql("SELECT m.useridfrom as id, COUNT(m.useridfrom) as count,
-                                         u.firstname, u.lastname, u.picture, u.imagealt, u.lastaccess
-                                       FROM {$CFG->prefix}user u, 
-                                            {$CFG->prefix}message m 
-                                       WHERE m.useridto = '$USER->id' 
-                                         AND u.id = m.useridfrom
-                                    GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess,u.imagealt");
+        $users = $DB->get_records_sql("SELECT m.useridfrom AS id, COUNT(m.useridfrom) AS count,
+                                              u.firstname, u.lastname, u.picture, u.imagealt, u.lastaccess
+                                         FROM {user} u, {message} m 
+                                        WHERE m.useridto = ? AND u.id = m.useridfrom
+                                     GROUP BY m.useridfrom, u.firstname,u.lastname,u.picture,u.lastaccess,u.imagealt", array($USER->id));
 
 
         //Now, we have in users, the list of users to show
index fba97048bba29eae3f693356efdfa409f9ee571a..8167d044f16e58dc9cf04aaab08736163b387ba7 100644 (file)
@@ -19,7 +19,7 @@ class block_mnet_hosts extends block_list {
     }
 
     function get_content() {
-        global $THEME, $CFG, $USER;
+        global $THEME, $CFG, $USER, $DB;
 
         // only for logged in users!
         if (!isloggedin() || isguest()) {
@@ -50,14 +50,14 @@ class block_mnet_hosts extends block_list {
                  a.name as application,
                  a.display_name
              FROM 
-                 {$CFG->prefix}mnet_host h,
-                 {$CFG->prefix}mnet_application a,
-                 {$CFG->prefix}mnet_host2service h2s_IDP,
-                 {$CFG->prefix}mnet_service s_IDP,
-                 {$CFG->prefix}mnet_host2service h2s_SP,
-                 {$CFG->prefix}mnet_service s_SP
+                 {mnet_host} h,
+                 {mnet_application} a,
+                 {mnet_host2service} h2s_IDP,
+                 {mnet_service} s_IDP,
+                 {mnet_host2service} h2s_SP,
+                 {mnet_service} s_SP
              WHERE
-                 h.id != '{$CFG->mnet_localhost_id}' AND
+                 h.id <> ? AND
                  h.id = h2s_IDP.hostid AND
                  h.applicationid = a.id AND
                  h2s_IDP.serviceid = s_IDP.id AND
@@ -71,7 +71,7 @@ class block_mnet_hosts extends block_list {
                  a.display_name,
                  h.name";
 
-        $hosts = get_records_sql($sql);
+        $hosts = $DB->get_records_sql($sql, array($CFG->mnet_localhost_id));
 
         $this->content = new stdClass;
         $this->content->items = array();
index 0dc65c64cab4a9c60f040399a43af448f46dcfc5..d8ea5fe50dbcbfbbac647040ae1b9b8c1ea353fa 100644 (file)
@@ -704,12 +704,12 @@ class block_base {
      * @todo finish documenting this function
      */
     function instance_config_print() {
+        global $CFG, $DB;
         // Default behavior: print the config_instance.html file
         // You don't need to override this if you're satisfied with the above
         if (!$this->instance_allow_multiple() && !$this->instance_allow_config()) {
             return false;
         }
-        global $CFG;
 
         if (is_file($CFG->dirroot .'/blocks/'. $this->name() .'/config_instance.html')) {
             print_simple_box_start('center', '', '', 5, 'blockconfiginstance');
index b872f57dc2c02f7a00d9dd8af1e3bddb4207074d..135d5874fec6615e51f3e33cea4afb1f312d7028 100644 (file)
@@ -14,7 +14,7 @@ class block_online_users extends block_base {
     function has_config() {return true;}
 
     function get_content() {
-        global $USER, $CFG, $COURSE;
+        global $USER, $CFG, $COURSE, $DB;
 
         if ($this->content !== NULL) {
             return $this->content;
@@ -47,42 +47,39 @@ class block_online_users extends block_base {
 
         $groupmembers = "";
         $groupselect = "";
+        $params = array();
 
         //Add this to the SQL to show only group users
         if ($currentgroup !== NULL) {
-            $groupmembers = ",  {$CFG->prefix}groups_members gm ";
-            $groupselect = " AND u.id = gm.userid AND gm.groupid = '$currentgroup'";
+            $groupmembers = ", {groups_members} gm";
+            $groupselect = "AND u.id = gm.userid AND gm.groupid = :currentgroup";
+            $params['currentgroup'] = $currentgroup;
         }
 
         if ($COURSE->id == SITEID) {  // Site-level
-            $select = "SELECT u.id, u.username, u.firstname, u.lastname, u.picture, max(u.lastaccess) as lastaccess ";
-            $from = "FROM {$CFG->prefix}user u 
-                          $groupmembers ";
-            $where = "WHERE u.lastaccess > $timefrom
-                      $groupselect ";
-            $order = "ORDER BY lastaccess DESC ";
+            $sql = "SELECT u.id, u.username, u.firstname, u.lastname, u.picture, MAX(u.lastaccess) AS lastaccess
+                      FROM {user} u $groupmembers
+                     WHERE u.lastaccess > $timefrom
+                           $groupselect
+                  GROUP BY u.id, u.username, u.firstname, u.lastname, u.picture
+                  ORDER BY lastaccess DESC ";
             
         } else { // Course-level
-            $courseselect = "AND ul.courseid = '".$COURSE->id."'";
-            $select = "SELECT u.id, u.username, u.firstname, u.lastname, u.picture, max(ul.timeaccess) as lastaccess ";
-            $from = "FROM {$CFG->prefix}user_lastaccess ul,
-                          {$CFG->prefix}user u
-                          $groupmembers ";
-            $where =  "WHERE ul.timeaccess > $timefrom
-                       AND u.id = ul.userid
-                       AND ul.courseid = $COURSE->id
-                       $groupselect ";
-            $order = "ORDER BY lastaccess DESC ";
+            $sql = "SELECT u.id, u.username, u.firstname, u.lastname, u.picture, MAX(ul.timeaccess) AS lastaccess
+                      FROM {user_lastaccess} ul, {user} u $groupmembers
+                     WHERE ul.timeaccess > $timefrom
+                           AND u.id = ul.userid
+                           AND ul.courseid = :courseid
+                           $groupselect
+                  GROUP BY u.id, u.username, u.firstname, u.lastname, u.picture
+                  ORDER BY lastaccess DESC";
+            $params['courseid'] = $COURSE->id;
         }
         
-        $groupby = "GROUP BY u.id, u.username, u.firstname, u.lastname, u.picture ";
-        
-        $SQL = $select . $from . $where . $groupby . $order;
-
         $users = array();        
         $pcontext = get_related_contexts_string($context);
     
-        if ($pusers = get_records_sql($SQL, 0, 50)) {   // We'll just take the most recent 50 maximum
+        if ($pusers = $DB->get_records_sql($sql, $params, 0, 50)) {   // We'll just take the most recent 50 maximum
             $hidden = false;
 
             if (!has_capability('moodle/role:viewhiddenassigns', $context)) {
@@ -92,10 +89,10 @@ class block_online_users extends block_base {
                 $userids = array_keys($pusers);
                 $userids = implode(',', $userids);
                 $sql = "SELECT userid
-                          FROM {$CFG->prefix}role_assignments
+                          FROM {role_assignments}
                          WHERE userid IN ($userids) AND contextid $pcontext AND hidden = 1
                       GROUP BY userid";
-                $hidden = get_records_sql($sql);
+                $hidden = $DB->get_records_sql($sql);
             }
 
             foreach ($pusers as $puser) {
index 0f4a99b7b6eaf68508239ee87b0f699a2b84e429..4dc9da970fa961cd4b6d378cb1be7e7a2e13122d 100644 (file)
@@ -42,9 +42,9 @@ class block_quiz_results extends block_base {
             $quizid    = $this->instance->pageid;
 
             // A trick to take advantage of instance config and save queries
-            if(empty($this->config->courseid)) {
-                $modrecord = get_record('modules', 'name', 'quiz');
-                $cmrecord  = get_record('course_modules', 'module', $modrecord->id, 'instance', $quizid);
+            if (empty($this->config->courseid)) {
+                $modrecord = $DB->get_record('modules', array('name'=>'quiz'));
+                $cmrecord  = $DB->get_record('course_modules', array('module'=>$modrecord->id, 'instance'=>$quizid));
                 $this->config->courseid = intval($cmrecord->course);
                 $this->instance_config_commit();
             }
@@ -54,22 +54,22 @@ class block_quiz_results extends block_base {
         $context = get_context_instance(CONTEXT_COURSE, $courseid);
 
 
-        if(empty($quizid)) {
+        if (empty($quizid)) {
             $this->content->text = get_string('error_emptyquizid', 'block_quiz_results');
             return $this->content;
         }
 
         // Get the quiz record
-        $quiz = get_record('quiz', 'id', $quizid);
-        if(empty($quiz)) {
+        $quiz = $DB->get_record('quiz', array('id'=>$quizid));
+        if (empty($quiz)) {
             $this->content->text = get_string('error_emptyquizrecord', 'block_quiz_results');
             return $this->content;
         }
 
         // Get the grades for this quiz
-        $grades = get_records('quiz_grades', 'quiz', $quizid, 'grade, timemodified DESC');
+        $grades = $DB->get_records('quiz_grades', array('quiz'=>$quizid), 'grade, timemodified DESC');
 
-        if(empty($grades)) {
+        if (empty($grades)) {
             // No grades, sorry
             // The block will hide itself in this case
             return $this->content;
@@ -88,8 +88,8 @@ class block_quiz_results extends block_base {
 
         // If the block is configured to operate in group mode, or if the name display format
         // is other than "fullname", then we need to retrieve the full course record
-        if(!empty($this->config->usegroups) || $nameformat != B_QUIZRESULTS_NAME_FORMAT_FULL) {
-            $course = get_record_select('course', 'id = '.$courseid, 'groupmode, groupmodeforce, student');
+        if (!empty($this->config->usegroups) || $nameformat != B_QUIZRESULTS_NAME_FORMAT_FULL) {
+            $course = $DB->get_record('course', array('id'=>$courseid), 'groupmode, groupmodeforce, student');
         }
 
         if(!empty($this->config->usegroups)) {
@@ -98,13 +98,13 @@ class block_quiz_results extends block_base {
                 $groupmode = $course->groupmode;
             }
             else {
-                $module = get_record_sql('SELECT cm.groupmode FROM '.$CFG->prefix.'modules m LEFT JOIN '.$CFG->prefix.'course_modules cm ON m.id = cm.module WHERE m.name = \'quiz\' AND cm.instance = '.$quizid);
+                $module = $DB->get_record_sql('SELECT cm.groupmode FROM {modules} m LEFT JOIN {course_modules} cm ON m.id = cm.module WHERE m.name = \'quiz\' AND cm.instance = ?', array($quizid));
                 $groupmode = $module->groupmode;
             }
             // The actual groupmode for the quiz is now known to be $groupmode
         }
 
-        if(has_capability('moodle/site:accessallgroups', $context) && $groupmode == SEPARATEGROUPS) {
+        if (has_capability('moodle/site:accessallgroups', $context) && $groupmode == SEPARATEGROUPS) {
             // We 'll make an exception in this case
             $groupmode = VISIBLEGROUPS;
         }
@@ -127,9 +127,9 @@ class block_quiz_results extends block_base {
             }
 
             // Now find which groups these users belong in
-            $groupofuser = get_records_sql(
-            'SELECT m.userid, m.groupid, g.name FROM '.$CFG->prefix.'groups g LEFT JOIN '.$CFG->prefix.'groups_members m ON g.id = m.groupid '.
-            'WHERE g.courseid = '.$courseid.' AND m.userid IN ('.implode(',', $userids).')'
+            $groupofuser = $DB->get_records_sql(
+            'SELECT m.userid, m.groupid, g.name FROM {groups} g LEFT JOIN {groups_members} m ON g.id = m.groupid '.
+            'WHERE g.courseid = ? AND m.userid IN ('.implode(',', $userids).')', array($courseid)
             );
 
             $groupgrades = array();
index d7b6be2d9bb67a1968e4c59f3c51f21a86c3e4d7..ac4c324c3c2461b9ad48cccce022d13fd0881bee 100644 (file)
@@ -6,7 +6,7 @@
     </td>
     <td>
         <?php
-            $quizzes = get_records('quiz', 'course', $this->instance->pageid, '', 'id, name');
+            $quizzes = $DB->get_records('quiz', array('course'=>$this->instance->pageid), '', 'id, name');
             if(empty($quizzes)) {
                 echo '<strong>'.get_string('config_no_quizzes_in_course', 'block_quiz_results').'</strong>';
                 echo '<p><input type="hidden" name="quizid" value="0" /></p>';
index c4f7527c85642d3bd637ddd24dfb5268f490a444..5247495ba5196a137acf83d5ac9b92f8e4823136 100644 (file)
      * @return string|NULL
      */
     function get_rss_by_id($rssid, $display_description, $shownumentries, $showtitle=false) {
-        global $CFG;
+        global $CFG, $DB;
         $returnstring = '';
         $now = time();
         require_once($CFG->libdir .'/rsslib.php');
             define('MAGPIE_OUTPUT_ENCODING', 'utf-8');  // see bug 3107
         }
 
-        $rss_record = get_record('block_rss_client', 'id', $rssid);
+        $rss_record = $DB->get_record('block_rss_client', array('id'=>$rssid));
         if (isset($rss_record) && isset($rss_record->id)) {
             // By capturing the output from fetch_rss this way
             // error messages do not display and clutter up the moodle interface
 
     // cron function, used to refresh all the RSS feeds from Moodle cron
     function cron() {
-
-        global $CFG;
+        global $CFG, $DB;
 
     /// We are going to measure execution times
         $starttime =  microtime();
         }
 
     /// Fetch all site feeds.
-        $rs = get_recordset('block_rss_client');
+        $rs = $DB->get_recordset('block_rss_client');
         $counter = 0;
         mtrace('');
-        while  ($rec = rs_fetch_next_record($rs)) {
+        foreach ($rs as $rec) {
             mtrace('    ' . $rec->url . ' ', '');
         /// Fetch the rss feed, using standard magpie caching
         /// so feeds will be renewed only if cache has expired
             }
             $counter ++;
         }
-        rs_close($rs);
+        $rs->close();
 
     /// Show times
         mtrace($counter . ' feeds refreshed (took ' . microtime_diff($starttime, microtime()) . ' seconds)');
index bfe3aa5eef508ca018df468304cc1f06713eb8fe..7a35173dbcfc892cbf595f7346d50e873fa37d16 100644 (file)
@@ -15,7 +15,6 @@ require_once($CFG->libdir .'/rsslib.php');
 require_once(MAGPIE_DIR .'rss_fetch.inc');
 
 require_login();
-global $USER;
 
 
 if (isset($_SERVER['HTTP_REFERER'])) {
@@ -59,7 +58,7 @@ if (!defined('MAGPIE_OUTPUT_ENCODING')) {
 if (!empty($id)) {
     // we get the complete $course object here because print_header assumes this is
     // a complete object (needed for proper course theme settings)
-    if ($course = get_record('course', 'id', $id)) {
+    if ($course = $DB->get_record('course', array('id'=>$id))) {
         $context = get_context_instance(CONTEXT_COURSE, $id);
     }
 } else {
@@ -86,7 +85,7 @@ if ( !isset($act) ) {
 }
 
 if ( isset($rssid) ) {
-    $rss_record = get_record('block_rss_client', 'id', $rssid);
+    $rss_record = $DB->get_record('block_rss_client', array('id'=>$rssid));
 }
 
 
@@ -130,18 +129,18 @@ if ($act == 'updfeed') {
         $dataobject->preferredtitle = '';
         $dataobject->shared = 0;
     } else {
-        $dataobject->description = addslashes($rss->channel['description']);
-        $dataobject->title = addslashes($rss->channel['title']);
-        $dataobject->preferredtitle = addslashes($preferredtitle);
+        $dataobject->description = $rss->channel['description'];
+        $dataobject->title = $rss->channel['title'];
+        $dataobject->preferredtitle = $preferredtitle;
         if ($shared == 1 && $canaddsharedfeeds) {
             $dataobject->shared = 1;
         } else {
             $dataobject->shared = 0;
         }
     }
-    $dataobject->url = addslashes($url);
+    $dataobject->url = $url;
 
-    if (!update_record('block_rss_client', $dataobject)) {
+    if (!$DB->update_record('block_rss_client', $dataobject)) {
         print_error('updatersserror', 'error', '', $rssid);
     }
 
@@ -164,8 +163,8 @@ if ($act == 'updfeed') {
     $dataobject->userid = $USER->id;
     $dataobject->description = '';
     $dataobject->title = '';
-    $dataobject->url = addslashes($url);
-    $dataobject->preferredtitle = addslashes($preferredtitle);
+    $dataobject->url = $url;
+    $dataobject->preferredtitle = $preferredtitle;
 
     if ($shared == 1 && $canaddsharedfeeds) {
         $dataobject->shared = 1;
@@ -173,7 +172,7 @@ if ($act == 'updfeed') {
         $dataobject->shared = 0;
     }
 
-    $rssid = insert_record('block_rss_client', $dataobject);
+    $rssid = $DB->insert_record('block_rss_client', $dataobject);
     if (!$rssid) {
         print_error('updatersserror', 'error', '', $url);
     }
@@ -195,12 +194,12 @@ if ($act == 'updfeed') {
 
         $dataobject->id = $rssid;
         if (!empty($rss->channel['description'])) {
-            $dataobject->description = addslashes($rss->channel['description']);
+            $dataobject->description = $rss->channel['description'];
         }
         if (!empty($rss->channel['title'])) {
-            $dataobject->title = addslashes($rss->channel['title']);
+            $dataobject->title = $rss->channel['title'];
         }
-        if (!update_record('block_rss_client', $dataobject)) {
+        if (!$DB->update_record('block_rss_client', $dataobject)) {
             print_error('updatersserror', 'error', '', $rssid);
         }
         $message .= '<br />'. get_string('feedadded', 'block_rss_client');
@@ -212,12 +211,12 @@ if ($act == 'updfeed') {
 */
 } else if ( isset($rss_record) && $act == 'rssedit' ) {
 
-    $preferredtitle = stripslashes_safe($rss_record->preferredtitle);
+    $preferredtitle = $rss_record->preferredtitle;
     if (empty($preferredtitle)) {
-        $preferredtitle = stripslashes_safe($rss_record->title);
+        $preferredtitle = $rss_record->title;
     }
-    $url = stripslashes_safe($rss_record->url);
-    $shared = stripslashes_safe($rss_record->shared);
+    $url = $rss_record->url;
+    $shared = $rss_record->shared;
     rss_display_feeds($id, $USER->id, $rssid, $context);
     rss_print_form($act, $url, $rssid, $preferredtitle, $shared, $id, $context);
 
@@ -236,7 +235,7 @@ if ($act == 'updfeed') {
     }
 
     // echo "DEBUG: act = delfeed"; //debug
-    delete_records('block_rss_client', 'id', $rssid);
+    $DB->delete_records('block_rss_client', array('id'=>$rssid));
 
     redirect($referrer, get_string('feeddeleted', 'block_rss_client') );
 
index 543e575c4fa7e281e29d6311a1d979778e99b0cd..4375b8ca3dff4ccb03f0daf0aa28071fcca044dc 100644 (file)
@@ -78,12 +78,12 @@ print_box_start();
             }
             global $USER;
 
-            if ($rssfeeds = get_records_select('block_rss_client', 'userid = '.$USER->id.' OR shared = 1')) {
+            if ($rssfeeds = $DB->get_records_select('block_rss_client', 'userid = ? OR shared = 1', array($USER->id))) {
                 foreach($rssfeeds as $rssfeed) {
                     if (!empty($rssfeed->preferredtitle)) {
-                        $feedtitle = stripslashes_safe($rssfeed->preferredtitle);
+                        $feedtitle = $rssfeed->preferredtitle;
                     } else {
-                        $feedtitle = stripslashes_safe($rssfeed->title);
+                        $feedtitle = $rssfeed->title;
                     }
                     $checked = '';
                     if (in_array($rssfeed->id, $selectedarray)) {
index be8041c74c270c53215add86fc95d1ac046ec126..dd694c207a9e34b4fb46aa91e5bdb60e3a06fc49 100644 (file)
@@ -1,5 +1,15 @@
+<?php
+
+/**
+* Requires and includes
+*/
+include_once $CFG->dirroot."/search/lib.php";
+
+$defaultfiletypes = "PDF,TXT,HTML,PPT,XML,DOC,HTM";
+
+?>
 <div style="text-align:center;">
-<table cellspacing="5">
+<table cellspacing="5" width="90%">
     <tr>
         <td valign="top" align="right">
             <b><?php print_string('configsearchtext', 'block_search') ?>:</b>
         </td>
         <td valign="top" align="left">
           <input id="block_search_filetypes" type="text" name="block_search_filetypes" value="<?php 
-            if(isset($CFG->block_search_filetypes)) {
-                p($CFG->block_search_filetypes);
-            } else {
-                p("PDF,TXT,HTML,PPT,XML,DOC,HTM");
-            } ?>"/><br/><br/>
+            if(!isset($CFG->block_search_filetypes)) {
+                $CFG->block_search_filetypes = $defaultfiletypes;
+            } 
+            p($CFG->block_search_filetypes);
+            ?>" />
+            <br/><br/>
         </td>
     </tr>
     <tr>
           <br/><br/>
         </td>
     </tr>
+    <tr>
+        <td valign="top" align="right">
+            <b><?php print_string('configlimitindexbody', 'block_search') ?>:</b>
+        </td>
+        <td valign="top" align="left">
+            <input id="block_search_limit_index_body" type="text" size="8" name="block_search_limit_index_body" value="<?php 
+            if(isset($CFG->block_search_limit_index_body)) {
+                p($CFG->block_search_limit_index_body);
+            } else {
+                p('');
+            } ?>"/> <?php print_string('bytes', 'block_search') ?><br/><br/>
+        </td>
+    </tr>
+</table>
+
+<fieldset name="">
+<legend align="top"><?php print_string('pdfhandling', 'block_search') ?></legend> 
+<table cellspacing="5" width="90%">
     <tr>
         <td valign="top" align="right">
             <b><?php print_string('configpdftotextcmd', 'block_search') ?>:</b>
             } ?>"/><br/><br/>
         </td>
     </tr>
+</table>
+</fieldset>
+
+<fieldset name="">
+<legend align="top"><?php print_string('wordhandling', 'block_search') ?></legend> 
+<table cellspacing="5" width="90%">
     <tr>
         <td valign="top" align="right">
             <b><?php print_string('configwordtotextcmd', 'block_search') ?>:</b>
             } ?>"/><br/><br/>
         </td>
     </tr>
+</table>
+</fieldset>
+
+<?php 
+$types = split(',', $CFG->block_search_filetypes);
+if (!empty($types)){
+    foreach($types as $type) {
+        $utype = strtoupper($type);
+        $type = strtolower($type);
+        $type = trim($type);
+        if (preg_match("/\\b$type\\b/i", $defaultfiletypes)) continue;
+?>
+<fieldset name="">
+<legend align="top"><?php echo get_string('handlingfor', 'block_search').' '.$utype ?></legend> 
+<table cellspacing="5" width="90%">
     <tr>
         <td valign="top" align="right">
-            <b><?php print_string('configlimitindexbody', 'block_search') ?>:</b>
+            <b><?php print_string('configtypetotxtcmd', 'block_search') ?>:</b>
         </td>
         <td valign="top" align="left">
-            <input id="block_search_limit_index_body" type="text" size="8" name="block_search_limit_index_body" value="<?php 
-            if(isset($CFG->block_search_limit_index_body)) {
-                p($CFG->block_search_limit_index_body);
-            } else {
-                p('');
-            } ?>"/> <?php print_string('bytes', 'block_search') ?><br/><br/>
+            <input id="block_search_<?php p($type) ?>_to_text_cmd" type="text" size="60" name="block_search_<?php p($type) ?>_to_text_cmd" value="<?php 
+            $propname = "block_search_{$type}_to_text_cmd";
+            if(isset($CFG->$propname)) {
+                p($CFG->$propname);
+            } 
+            ?>"/>
+            <br/><br/>
+        </td>
+    </tr>
+    <tr>
+        <td valign="top" align="right">
+            <b><?php print_string('configtypetotxtenv', 'block_search') ?>:</b>
+        </td>
+        <td valign="top" align="left">
+            <input id="block_search_<?php p($type) ?>_to_text_env" type="text" size="60" name="block_search_<?php p($type) ?>_to_text_env" value="<?php 
+            $propname = "block_search_{$type}_to_text_env";
+            if(isset($CFG->$propname)) {
+                echo stripslashes($CFG->$propname);
+            } ?>"/><br/><br/>
         </td>
     </tr>
+</table>
+</fieldset>
+<?php
+    }
+}
+?>
+
+<fieldset name="">
+<legend align="top"><?php echo get_string('searchdiscovery', 'block_search') ?></legend> 
+<table>
+    <tr>
+        <td>
+            <pre>
+            <?php
+            $searchnames = search_collect_searchables(true);
+            list($searchable_list, $params) = $DB->get_in_or_equal($searchnames);
+            ?>
+            </pre>
+        </td>
+    </tr>
+</table>
+</fieldset>
+
+<fieldset name="">
+<legend align="top"><?php echo get_string('modulessearchswitches', 'block_search') ?></legend> 
+<table cellspacing="5" width="90%">
+    <tr valign="top">
+        <td align="left">
+<?php
+$i = 0;
+$found_searchable_modules = 0;
+if ($modules = $DB->get_records_select('modules', "name $searchable_list", $params, 'name', 'id,name')){
+    foreach($modules as $module){
+        $i++;
+        $keyname = "search_in_{$module->name}";
+        $checkedup = (!isset($CFG->$keyname) || $CFG->$keyname) ? 'checked="checked"' : '' ;
+        $checkeddown = !(!isset($CFG->$keyname) || $CFG->$keyname) ? 'checked="checked"' : '' ;
+        echo "<input type=\"radio\" name=\"search_in_{$module->name}\" value=\"0\" {$checkeddown} /> " . get_string('no');
+        echo " - <input type=\"radio\" name=\"search_in_{$module->name}\" value=\"1\" {$checkedup} /> " . get_string('yes');
+        echo " - ".get_string('modulename', $module->name).'<br/>';
+        if ($i % 20 == 0){
+            echo "</td><td align=\"left\">";
+        }
+        $found_searchable_modules = 1;
+    }
+} 
+if (!$found_searchable_modules) {
+    print_string('nosearchablemodules', 'block_search');
+}  
+?>
+
+        </td>
+    </tr>
+</table>
+</fieldset>
+
+<fieldset name="">
+<legend align="top"><?php echo get_string('blockssearchswitches', 'block_search') ?></legend> 
+<table cellspacing="5" width="90%">
+    <tr valign="top">
+        <td align="left">
+<?php
+$i = 0;
+$found_searchable_blocks = 0;
+if ($blocks = $DB->get_records_select('block', "name $searchable_list", $params, 'name', 'id,name')){
+    foreach($blocks as $block){
+        $i++;
+        $keyname = "search_in_{$block->name}";
+        $checked = (!isset($CFG->$keyname) || $CFG->$keyname) ? 'checked="checked"' : '' ;
+        echo "<input type=\"checkbox\" name=\"search_in_{$block->name}\" value=\"1\" {$checked} />";
+        
+        // multiple fallback strategy to get the name of the block
+        $blocklabel = get_string('blockname', 'block_'.$block->name);
+        if ($blocklabel == '[[blockname]]') $blocklabel = get_string($block->name, 'block_'.$block->name);
+        if ($blocklabel == "[[{$block->name}]]") $blocklabel = "<span class=\"dimmed_text\">$block->name</span>";
+        echo " - ".$blocklabel.'<br/>';
+        if ($i % 20 == 0){
+            echo "</td><td align=\"left\">";
+        }
+        $found_searchable_blocks = 1;
+    }
+}    
+if (!$found_searchable_blocks) {
+    print_string('nosearchableblocks', 'block_search');
+}  
+?>
+
+        </td>
+    </tr>
+</table>
+</fieldset>
+
+<table cellspacing="5" width="90%">
     <tr>
         <td valign="top" align="right" colspan="2">
             <input type="submit" value="<?php print_string('savechanges'); ?>" />
index c41b93d35a00c99ce31d7610a57c1ed1f3c1ff57..36870a89fcced350af42bec334cb42f6e63ecc3f 100644 (file)
@@ -47,7 +47,7 @@ class block_section_links extends block_base {
         if ($this->instance->pageid == $COURSE->id) {
             $course = $COURSE;
         } else {
-            $course = get_record('course', array('id'=>$this->instance->pageid));
+            $course = $DB->get_record('course', array('id'=>$this->instance->pageid));
         }
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
 
@@ -79,12 +79,12 @@ class block_section_links extends block_base {
         }
 
         $sql = "SELECT section, visible
-                  FROM {$CFG->prefix}course_sections
-                 WHERE course = $course->id AND
+                  FROM {course_sections}
+                 WHERE course = ? AND
                        section < ".($course->numsections+1)."
               ORDER BY section";
 
-        if ($sections = get_records_sql($sql)) {
+        if ($sections = $DB->get_records_sql($sql, array($course->id))) {
             $text = '<ol class="inline-list">';
             for ($i = $inc; $i <= $course->numsections; $i += $inc) {
                 if (!isset($sections[$i])) {