]> git.mjollnir.org Git - moodle.git/commitdiff
many functions removed, might have broken a few things
authortoyomoyo <toyomoyo>
Wed, 15 Mar 2006 04:15:09 +0000 (04:15 +0000)
committertoyomoyo <toyomoyo>
Wed, 15 Mar 2006 04:15:09 +0000 (04:15 +0000)
blog/lib.php
blog/preferences.html

index 50db382d42e638f5fd59ed7d544f63c981d6676a..40f48ee538ed5407cb34f799862af77ec8f0bd03 100755 (executable)
@@ -73,38 +73,6 @@ if (empty($CFG->blog_default_fetch_num_entries) ) {
     $CFG->blog_default_fetch_num_entries = 8;
 }
 
-/**
- * blog_user_bloginfo
- *
- * returns a blogInfo object if the user has a blog in the acl table
- * This function stores the currently logged in user's bloginfo object
- * statically - do not release/unset the returned object.
- * added by Daryl Hawes for moodle integration
- * $userid - if no userid specified it will attempt to use the logged in user's id
- */
-function blog_user_bloginfo($userid='') {
-//Daryl Hawes note: not sure that this attempt at optimization is correct
-//    static $bloginfosingleton; //store the logged in user's bloginfo in a static var
-
-    if ($userid == '') {
-        global $USER;
-        if (!isset($USER) || !isset($USER->id)) {
-            return;
-        }
-        $userid = $USER->id;
-    }
-    
-/*    if (isset($USER) && $USER->id == $uid && !empty($bloginfosingleton)) {
-        return $bloginfosingleton;
-    }*/
-
-    $thisbloginfo = new BlogInfo($userid);
-/*        if (isset($USER) && $USER->id == $userid) {
-            $bloginfosingleton = $thisbloginfo;
-        }*/
-    return $thisbloginfo;
-}
-
 /**
  * Verify that a user is logged in based on the session
  * @return bool True if user has a valid login session
@@ -117,116 +85,6 @@ function blog_isLoggedIn() {
     return 0;
 }
 
-/**
- * This function upgrades the blog's tables as needed.
- * It's called from moodle/admin/index.php
- */
-function blog_upgrade_blog_db($continueto) {
-
-    global $CFG, $db;
-
-    require_once($CFG->dirroot.'/blog/version.php');  // Get code versions
-
-    if (empty($CFG->blog_version)) { // Blog has never been installed.
-        $strdatabaseupgrades = get_string('databaseupgrades');
-        print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades,
-                     '', '', false, '&nbsp;', '&nbsp;');
-
-        $db->debug=true;
-        if (modify_database($CFG->dirroot .'/blog/db/'. $CFG->dbtype .'.sql')) {
-            $db->debug = false;
-            if (set_config('blog_version', $blog_version)) {
-                notify(get_string('databasesuccess'), 'green');
-                notify(get_string('databaseupgradeblog', 'blog', $blog_version));
-
-                /// Added by Daryl Hawes - since blog has to be installed the first time before blog's blocks, and on first install creating default blocks when none exist is a bad idea, just reset blocks for blog index here
-                require_once($CFG->libdir .'/pagelib.php');
-                require_once($CFG->dirroot .'/blog/blogpage.php');                
-                page_map_class(PAGE_BLOG_VIEW, 'page_blog');    
-                // Now, create our page object.
-                $page = page_create_object(PAGE_BLOG_VIEW, 0);
-                // Add default blocks to the new page type
-                blocks_repopulate_page($page);
-                
-                print_continue($continueto);
-                exit;
-            } else {
-                error('Upgrade of blogging system failed! (Could not update version in config table)');
-            }
-        } else {
-            error('blog tables could NOT be set up successfully!');
-        }
-    }
-
-
-    if ($blog_version > $CFG->blog_version) {       // Upgrade tables
-        $strdatabaseupgrades = get_string('databaseupgrades');
-        print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades);
-
-        require_once($CFG->dirroot. '/blog/db/'. $CFG->dbtype .'.php');
-
-        $db->debug=true;
-        if (blog_upgrade($CFG->blog_version)) {
-            $db->debug=false;
-            if (set_config('blog_version', $blog_version)) {
-                notify(get_string('databasesuccess'), 'green');
-                notify(get_string('databaseupgradeblocks', '', $blog_version));
-                print_continue($continueto);
-                exit;
-            } else {
-                error('Upgrade of blogging system failed! (Could not update version in config table)');
-            }
-        } else {
-            $db->debug=false;
-            error('Upgrade failed!  See blog/version.php');
-        }
-
-    } else if ($blog_version < $CFG->blog_version) {
-        notify('WARNING!!!  The blog code you are using is OLDER than the version that made these databases! ('. $version .' < '. $CFG->blog_version .')');
-    }
-}
-
-/**
- * course_has_blog_entries
- *   Given a course id return true if there are blog entries from any user related to that course
- * $courseid - the id for the course
- * Daryl Hawes note: When forum entries start using post table this function will no longer behave as expected
- * Since non blog posts will be associated with this course. Perhaps moduleid or another field could be wrangled 
- * into identifying the type of post?
- */
-function blog_course_has_blog_entries($courseid) {
-    $entries = get_records('post', 'courseid', $courseid);
-    if (! empty($entries) ) {
-        return true;
-    }
-    return false;
-}
-
-/**
- * Output a hidden html form used by text entry pages that require preview.php's functionality
- */
-function blog_print_preview_form($userid=0, $categoryelement='<input type="hidden" name="categoryid[]">', $return=false) {
-
-    $returnstring = "\n".'<div id="prev" style="visibility:hidden;z-index:-1;position:absolute;display:none;">';
-    $returnstring .= "\n".'<form name="prev" action="preview.php" method="post" target="preview">';
-    $returnstring .= "\n".'<input type="hidden" name="etitle" />';
-    $returnstring .= "\n".'<input type="hidden" name="body" />';
-    $returnstring .= "\n".'<input type="hidden" name="comm" />';
-    $returnstring .= "\n".'<input type="hidden" name="tem" />';
-    $returnstring .= "\n".'<input type="hidden" name="userid" value="'. $userid .'" />';
-
-//    $returnstring .= '<input type="hidden" name="categoryid[]" value="'. $categoryid .'" />';
-    $returnstring .= "\n". $categoryelement;
-    $returnstring .= "\n".'<input type="hidden" name="format" />';
-    $returnstring .= "\n".'</form>';
-    $returnstring .= "\n".'</div>'."\n";
-    
-    if ($return) {
-        return $returnstring; //return the form as a string if requested
-    }
-    print $returnstring; //else just print the string and exit the function
-}
-
 /**
  * blog_user_has_rights - returns true if user is the blog's owner or a moodle admin.
  *
@@ -291,203 +149,31 @@ function blog_isediting() {
 }
 
 /**
- * Turns a php string into a string ready for insert into an rss xml feed
- */
-function blog_rss_content($str) {
-    $str = superhtmlentities($str);
-    $content = "<![CDATA[$str]]>\n";
-
-    return $content;
-}
-
-/**
- * function found when searching on problem of smart quotes
- * posted at http://daynah.php-princess.net/index.php?p=94
- */
-function superhtmlentities($text) {
-  $entities = array(128 => 'euro', 130 => 'sbquo', 
-  131 => 'fnof', 132 => 'bdquo', 133 => 'hellip', 
-  134 => 'dagger', 135 => 'Dagger', 136 => 'circ', 
-  137 => 'permil', 138 => 'Scaron', 139 => 'lsaquo', 
-  140 => 'OElig', 145 => 'lsquo', 146 => 'rsquo', 
-  147 => 'ldquo', 148 => 'rdquo', 149 => 'bull', 
-  150 => 'ndash', 151 => 'mdash', 152 => 'tilde', 
-  153 => 'trade', 154 => 'scaron', 155 => 'rsaquo', 
-  156 => 'oelig', 159 => 'Yuml');
-
-  $new_text = '';
-  for($i = 0; $i < strlen($text); $i++) {
-    $num = ord($text{$i});
-    if (array_key_exists($num, $entities)) {
-        $new_text .= '&\\'.$entities[$num].';';
-    } else if ($num < 127 || $num > 159) {
-        $new_text .= $text{$i};
-    }
-  }
-  return htmlentities($new_text);
-}
-
-/**
- * blog_get_recent_entries_byrange
- * not in blogInfo because entries being searched 
- * can be found in any number of blogs rather than just one.
- *
- * Returns specified range of entries since a given time.
- *
- * In using this function be aware for your where clause that the tables being 
- * read are post (e) and blog_categories_entries (c) and the returned values
- * will be e.*
- *
- * @param int $limit .
- * @param int $start .
- * @param string $where .
- * @param string $orderby .
- * @param bool $includeCategories .
- *
- * @return BlogEntries 
- */
-function blog_get_recent_entries_byrange($limit, $start, $where='', $orderby='lastmodified DESC', $includeCategories=false) {
-    global $CFG;
-
-//    echo 'Debug: where clause in blog_get_recent_entries_byrange: $where<br />'; //debug
-
-    if ($includeCategories) {
-        $records = get_records_select('post e, '. $CFG->prefix .'blog_categories_entries c', $where, $orderby, '*', $start, $limit);
-    } else {
-        $records = get_records_select('post', $where, $orderby, '*', $start, $limit);
-    }
-//    print_object($records); //debug
-
-    if (empty($records)) {
-        return array();
-    } else {
-        $blogEntries = array();
-        foreach($records as $record) {
-            $blogEntry = new BlogEntry($record);
-            //ensure that the user has rights to view this entry
-            if ($blogEntry->user_can_view() ) {
-                $blogEntries[] = $blogEntry;
-            }
-        }
-        return $blogEntries;
-    }
-}
-
-/**
- * returns a unix time stamp from year month and day
- * used to get start and end dates for comparing against timestamps in databases
- */
-function blog_get_month_time($y, $m, $d, $firstday=true) {
-
-    if ( !empty($y) && !empty($m) && !empty($d)) {
-        $time = mktime(0, 0, 0, $m, $d, $y);
-    } else if ( !empty($y) && !empty($m) ) {
-        $day = blog_mk_getLastDayofMonth($m, $y);
-        if ($firstday) {
-            $day = 1;
-        }
-        $time = mktime(0, 0, 0, $m, $day, $y);
-    } else {
-        $time = '';
-    }
-    return $time;
-}
-
-/**
- * attempting to create a method useful for a popup form on the index
- * page that will allow a user to filter entries based upon date
+ * blog_user_bloginfo
  *
- * This function will return a list, in order, formatted as "MM-YYYY" for each year and month
- * in which this blog has entries.
- * @param BlogFilter $blogFilter - a BlogFilter object with the current filter settings for this page
- */
-function blog_get_year_month_of_viewable_entries(&$blogFilter) {
-    global $_SERVER;
-    
-    $entries = $blogFilter->get_filtered_entries();
-    $datearray = array();
-    $datearray['m=&amp;y='] = 'All Dates';
-    
-    if ( !empty($entries) ) {
-        foreach ($entries as $entry) {
-            if ( $entry->user_can_view() ) {
-//                print_object($entry); //debug
-                //user is allowed to see this entry, so return its year/month information
-                $date = $entry->entryLastModified;
-                $truncDate = date("F Y", $date); // this will return January 2004 for the date.
-                $curmonth = date("m", $date); // this will return January 2004 for the date.
-                $curyear = date("Y", $date); // this will return January 2004 for the date.
-                $index = 'm='. $curmonth .'&amp;y='. $curyear;
-                $datearray[$index] = $truncDate;
-            }
-        }
-    }
-//    print_object($datearray); //debug
-        
-    if (is_numeric($blogFilter->startmonth) && is_numeric($blogFilter->startyear)) {
-        $selected = 'm='. $blogFilter->startmonth .'&amp;y='. $blogFilter->startyear;
-    } else {
-        $selected = '';
-    }
-    $unused = array('startmonth', 'startyear');
-    $getvars = $blogFilter->get_getvars($unused);
-    //attach a random number to the popup function's form name
-    //becuase there may be multiple instances of this form on each page
-    $self = basename($_SERVER['PHP_SELF']); 
-    $form = popup_form($self . $getvars .'&amp;', $datearray, 'blog_date_selection'. mt_rand(), $selected, '', '', '', true);
-    return str_replace('<form', '<form style="display: inline;"', $form);
-}
-
-/**
- * pretty close to a direct copy of calendar/view.php calendar_course_filter_selector function
+ * returns a blogInfo object if the user has a blog in the acl table
+ * This function stores the currently logged in user's bloginfo object
+ * statically - do not release/unset the returned object.
+ * added by Daryl Hawes for moodle integration
+ * $userid - if no userid specified it will attempt to use the logged in user's id
  */
-function blog_course_filter_selector(&$blogFilter) {
-    global $USER, $_SERVER;
-    
-    $getvars = $blogFilter->get_getvars('courseid');
-
-    if ( !isset($USER) || !isset($USER->id) ) {
-        return;
-    }
-
-    if (isguest($USER->id)) {
-        return '';
-    }
-    
-    if (isadmin($USER->id)) {
-        $courses = get_courses('all', 'c.shortname');
-        
-    } else {
-        $courses = get_my_courses($USER->id, 'shortname');
-    }
-    
-    unset($courses[1]);
-    
-    $courseoptions[1] = get_string('fulllistofcourses');
-    foreach ($courses as $course) {
-        // Verify that there are actually blog entries for this course before showing it as a selection.
-        if ($entries = count_records('post', 'courseid', $course->id)) {
-            $courseoptions[$course->id] = $course->shortname;
+function blog_user_bloginfo($userid='') {
+//Daryl Hawes note: not sure that this attempt at optimization is correct
+//    static $bloginfosingleton; //store the logged in user's bloginfo in a static var
+    global $USER;
+    if ($userid == '') {
+        global $USER;
+        if (!isset($USER) || !isset($USER->id)) {
+            return;
         }
+        $userid = $USER->id;
     }
 
-    //if there were no courses added then simply return
-    if (count($courseoptions) == 1) {
-        return;
-    }
-    
-    if (is_numeric($blogFilter->courseid)) {
-        $selected = $blogFilter->courseid;
-    } else {
-        $selected = '';
-    }
-    //attach a random number to the popup function's form name
-    //because there may be multiple instances of this form on each page
-    $self = basename($_SERVER['PHP_SELF']); 
-    $form = popup_form($self . $getvars .'&amp;courseid=',
-                       $courseoptions, 'blog_course_selection'. mt_rand(), $selected, '', '', '', true);
-    
-    return str_replace('<form', '<form style="display: inline;"', $form);
+    $thisbloginfo = new BlogInfo($userid);
+/*        if (isset($USER) && $USER->id == $userid) {
+            $bloginfosingleton = $thisbloginfo;
+        }*/
+    return $thisbloginfo;
 }
 
 /**
@@ -567,27 +253,6 @@ function blog_member_list(&$blogFilter, &$memberrecords, $format=1, $return=true
     return;
 }
 
-/**
- * @param int courseid the selected course in popup
- */
-function blog_get_course_selection_popup($courseid='') {
-    global $USER;
-    if ( !isset($USER) || !isset($USER->id) ) {
-        return;
-    }
-    if ( isadmin() ) {
-        $courses = get_courses(); //show admin users all courses
-    } else {
-        $courses = get_my_courses($USER->id) ; //get_my_courses is in datalib.php
-    }
-    //print_object($courses); //debug
-    $courseoptions = array();
-    foreach ($courses as $course) {
-        $courseoptions[$course->id] = $course->shortname;
-    }
-    return choose_from_menu($courseoptions, 'course_selection', $courseid, '', '', '0', true);
-}
-
 /**
  *  This function is in lib and not in BlogInfo because entries being searched
  *   might be found in any number of blogs rather than just one.
@@ -623,7 +288,6 @@ function blog_print_html_formatted_entries(&$blogFilter, $filtertype, $filtersel
         }
     }
 
-
     $morelink = '<br />&nbsp;&nbsp;';
     // show personal or general heading block as applicable
     echo '<div class="headingblock header blog">';
@@ -660,13 +324,7 @@ function blog_print_html_formatted_entries(&$blogFilter, $filtertype, $filtersel
                 
             }
         }
-/*
-        if (blog_isLoggedIn() && blog_isediting() ) {
-            //Daryl Hawes note: localize this submit button!
-            print '<div align="center"><input type="submit" value="Save these publish settings" id="batchpublish" name="batchpublish" /></div>'."\n";
-            print '</form>'."\n";
-        }
-*/
+
         //yu: testing code
         if (blog_isLoggedIn()) {
         //the user's blog is enabled and they are viewing their own blog
@@ -686,7 +344,6 @@ function blog_print_html_formatted_entries(&$blogFilter, $filtertype, $filtersel
     }
 
     $output = '<br /><center>'. get_string('noentriesyet', 'blog') .'</center><br />';
-    $userbloginfo = blog_user_bloginfo();
     
     if (blog_isLoggedIn()) {
         //the user's blog is enabled and they are viewing their own blog
@@ -696,33 +353,6 @@ function blog_print_html_formatted_entries(&$blogFilter, $filtertype, $filtersel
     unset($blogFilter->filtered_entries);
 }
 
-/**
- * What text should be displayed claiming ownership to the current blog entries?
- * @uses $PAGE
- * @return string
- */
-function blog_get_title_text() {
-    global $PAGE; //hackish
-
-    if (isset($PAGE) && isset($PAGE->bloginfo)) {
-        $blogInfo = &$PAGE->bloginfo;
-        $title = $blogInfo->get_blog_title();
-        if($title != '') {
-            $displaytitle = $title;
-            $tagline = $blogInfo->get_blog_tagline();
-            if ($tagline != '') {
-                $displaytitle .= ' - '. $tagline;
-            }
-        }
-    }
-    if (isset($displaytitle)) {
-        return $displaytitle;
-    } else {
-        // Daryl Hawes - better wording would be good here, localize this line once the wording is selected.
-        return 'Combined Blog '. get_string('entries', 'blog') .'<br />';
-    }
-}
-
 /**
  * blog_get_moodle_pix_path
  *
@@ -877,11 +507,7 @@ function blog_applicable_publish_states($courseid='') {
             $options['course'] = get_string('publishtocourse', 'blog', $course->shortname);
         }
     }
-    /*
-     //groups not supported quite yet - pseudocode:
-     if (isset($post->groupid) && $post->groupid != '') {
-         $options['group'] = 'Fellow group members and teachers can view';
-     }*/
+
     if (!$CFG->blog_enable_moderation || isadmin() || (is_numeric($courseid) && isteacher($courseid)) ) {
         // only admins and teachers can see site and public options when moderation is enabled
         $options['site'] = get_string('publishtosite', 'blog');
@@ -890,532 +516,4 @@ function blog_applicable_publish_states($courseid='') {
     return $options;
 }
 
-/**
- * blog_get_entries_by_category - not in blogInfo because entries being searched 
- *   can be found in any number of blogs rather than just one.
- * catids can be an array of category ids or a single category id
- * defined as either
- * $catids = array(1, 2, 3, 4, 5);
- * or
- * $catids = 2;
- *
- * Used by rss.php
- */
-function blog_get_entries_by_category($catids, $courseid=0, $limit=8, $start=0) {
-    $catsearch = ' e.id=c.entryid AND '; //only gets categories whose postid matches entries retrieved
-    if (blog_array_count($catids) > 0) {
-        $count = 0;
-        foreach ($catids as $catid) {
-            $catsearch .= 'c.categoryid='. $catid .' ';
-            $count += 1;
-            if (count($catids) != $count) {
-                $catsearch .= 'OR ';
-            }
-        } 
-    } else {
-        $catsearch .= 'c.categoryid='. $catids;
-    }
-    $wherecourse = '';
-    if (is_numeric($courseid) && $courseid != 0 && $courseid != 1) {
-        $wherecourse = ' AND e.courseid='. $courseid;
-    }
-    $where = $catsearch.$wherecourse;
-//    echo 'Debug: where clause for blog_get_entries_by_category: '. $where; //debug
-    return blog_get_recent_entries_byrange($limit, $start, $where, '', true);
-}
-
-/**
- * builds calendar with links to filter entries by date
- * modified by Daryl Hawes to build links even when no userid is specified
- * and to return the html as a string if desired
- */
-function blog_draw_calendar(&$blogFilter, $return=false)
-{
-    global $CFG;
-//    print_object($blogFilter);
-
-    if (!empty($blogFilter->startmonth)) {
-        $m = $blogFilter->startmonth;
-    } else {
-        $m = date('n', mktime());
-        $blogFilter->startmonth = $m;
-    }
-    if (!empty($blogFilter->startyear)) {
-        $y = $blogFilter->startyear;
-    } else {
-        $y = date('Y', mktime());
-        $blogFilter->startyear = $y;
-    }
-    $userid = $blogFilter->userid;
-    
-    //create a string to represent a URL argument with userid info. If no userid then string is empty.
-    $useridString = '&amp;userid='. $userid;
-    if ($userid == 0 || $userid == '') {
-        $useridString = '';
-    }
-
-   // calculate the weekday the first of the month is on
-   $tmpd = getdate(mktime(0, 0, 0, $m, 1, $y));
-   $monthname = $tmpd['month'];
-   $firstwday= $tmpd['wday'];
-   $today = date('Ymd', mktime());
-
-   $lastday = blog_mk_getLastDayofMonth($m, $y);
-
-   //determine next and previous month
-   if (($m - 1) < 1) { $pm = 12; } else { $pm = $m - 1; }
-   if (($m + 1) > 12) { $nm = 1; } else { $nm = $m + 1; }
-
-   if (strlen($pm) == 1) { $pm = '0'. $pm; };
-   if (strlen($nm) == 1) { $nm = '0'. $nm; };
-
-   $returnstring = "\n".'<table class="generaltable"><tr>'."\n";
-   $returnstring .= '<td style="text-align: left; width: 12%;">'."\n";
-
-   $currentyear = $y;
-   $currentmonth = $m;
-
-   if (($m - 1) < 1) {
-       $blogFilter->startyear = $y - 1;
-   } else {
-       $blogFilter->startyear = $y;
-   }
-
-   $blogFilter->startmonth = $pm;
-   $self = basename($_SERVER['PHP_SELF']); 
-   $returnstring .= $blogFilter->get_complete_link( $self, '&lt;&lt;' , array('startday'))."\n";
-
-   $blogFilter->startyear = $currentyear;
-   $blogFilter->startmonth = $currentmonth;
-
-   $returnstring .= '</td><td style="text-align: center;">'."\n";
-//   $returnstring .= $blogFilter->get_complete_link($CFG->wwwroot .'/blog/archive.php', $monthname .' '. $y, array('startday'));
-   $returnstring .= $blogFilter->get_complete_link($self, $monthname .' '. $y, array('startday'));
-
-   if (($m + 1) > 12) {
-       $blogFilter->startyear = $blogFilter->startyear + 1;
-   } else {
-        $blogFilter->startyear = $y;
-   }
-
-   $blogFilter->startmonth = $nm;
-   $returnstring .= '</td><td style="text-align: right; width: 12%;">'."\n";
-   $returnstring .= $blogFilter->get_complete_link( $self, '&gt;&gt;', array('startday'))."\n";
-   $returnstring .= '</td></tr>'."\n";
-
-   $blogFilter->startyear = $currentyear;
-   $blogFilter->startmonth = $currentmonth;
-
-   $returnstring .= '<tr><td colspan="3">'."\n";
-   $returnstring .= '<table class="calendarmini"><thead>'."\n";
-   $returnstring .= '<tr><td width="19" align="center" class="calday">'. get_string('calsun', 'blog') .'</td>'."\n";
-   $returnstring .= '<td width="19" align="center" class="calday">'. get_string('calmon', 'blog') .'</td>'."\n";
-   $returnstring .= '<td width="19" align="center" class="calday">'. get_string('caltue', 'blog') .'</td>'."\n";
-   $returnstring .= '<td width="19" align="center" class="calday">'. get_string('calwed', 'blog') .'</td>'."\n";
-    $returnstring .= '<td width="19" align="center" class="calday">'. get_string('calthu', 'blog') .'</td>'."\n";
-    $returnstring .= '<td width="19" align="center" class="calday">'. get_string('calfri', 'blog') .'</td>'."\n";
-    $returnstring .= '<td width="19" align="center" class="calday">'. get_string('calsat', 'blog') .'</td></tr></thead><tbody>'."\n";
-
-    $d = 1;
-    $wday = $firstwday;
-    $firstweek = true;
-
-    // loop through all the days of the month
-    while ( $d <= $lastday)
-    {
-        // set up blank days for first week
-        if ($firstweek) {
-        $returnstring .= '<tr>'."\n";
-        for ($i=1; $i <= $firstwday; $i++) {
-            $returnstring .= '<td>&nbsp;</td>'."\n";
-        }
-        $firstweek = false;
-        }
-
-       // Sunday start week with <tr>
-       if ($wday==0) {
-           $returnstring .= '<tr>'."\n";
-        }
-
-       $mo = $m;
-       if ($mo < 10) {
-           if (!preg_match("/0\d/", $mo)) {
-                $mo = '0'. $mo;
-           }
-       }
-
-        // Look for blog entries for this day
-       $tstart = blog_get_month_time($y, $m, $d, true);
-       $tend = blog_get_month_time($y, $m, $d + 1, false);
-       $where = " lastmodified >= $tstart AND lastmodified <= $tend ";
-
-        if ($userid != 0 && $userid != '') {
-            $where .= ' AND author = '. $userid .' ';
-        }
-
-      $count = count_records_select('post', $where);
-
-//echo 'Where clause: '. $where .' | count:'. $count. '<br />'."\n"; //debug
-        $da = $d;
-        if($da < 10) {
-            if(!preg_match("/0\d/", $da)) {
-                $da = "0". $da;
-            }
-        }        
-      // check for event
-      $showdate = $y . $mo . $da;
-
-      $returnstring .= '<td align=center';
-      if ($showdate == $today) {
-           $returnstring .= ' class="cal_today"';
-      }
-      if ($wday == 6 || $wday == 0) { 
-          $returnstring .= ' class="cal_weekend"';
-      }
-      $returnstring .= '>'."\n";
-
-      // if entries are found, output link to that day's entries
-      if ($count > 0) {
-          $blogFilter->startday = $d;
-          $returnstring .= $blogFilter->get_complete_link($CFG->wwwroot .'/blog/index.php', $d);
-      } else {
-           $returnstring .= $d."\n";
-      }
-      $returnstring .= '</td>'."\n";
-
-      // Saturday end week with </tr>
-      if ($wday == 6) { 
-          $returnstring .= '</tr>'."\n"; 
-      }
-      $wday++;
-      $wday = $wday % 7;
-      $d++;
-    }
-
-    if ($wday != 0) {
-        for($i = $wday; $i < 7; $i++) {
-            $returnstring .= '<td>&nbsp;</td>'."\n";
-        }
-        $returnstring .= '</tr>'."\n";
-    }
-    
-    $returnstring .= '</table>'."\n";
-
-    $returnstring .= '</td></tr></tbody></table>'."\n";
-
-    if ($return) {
-        return $returnstring;
-    }
-    print $returnstring;
-// end blog_draw_calendar function
-}
-
-/**
- * get the last day of the month
- */
-function blog_mk_getLastDayofMonth($mon, $year)
-{
-    for ($tday=28; $tday <= 31; $tday++)
-    {
-        $tdate = getdate(mktime(0, 0, 0, $mon, $tday, $year));
-        if ($tdate['mon'] != $mon)
-            { break; }
-
-    }
-    $tday--;
-
-    return $tday;
-}
-
-/**
- * blog_safeHTML
- *   Clean up user input (currently unused, moodle's format_text() is preferable)
- */
-function blog_safeHTML($html, $tags = 'b|br|i|u|ul|ol|li|p|a|blockquote|em|strong') {
-// removes all tags that are considered unsafe
-// Adapted from a function posted in the comments about the strip_tags()
-// function on the php.net web site.
-//
-// This function is not perfect! It can be bypassed!
-// Remove any nulls from the input
-    $html = preg_replace('/\0/', '', $html);
-    // convert the ampersands to null characters (to save for later)
-    $html = preg_replace('/&/', '\0', $html);
-  
-    // convert the sharp brackets to their html code and escape special characters such as "
-    $html=htmlspecialchars($html);
-   
-    // restore the tags that are considered safe
-    if ($tags) {
-        // Fix start tags
-        $html = preg_replace("/&lt;(($tags).*?)&gt;/i", '<$1>', $html);
-        // Fix end tags
-        $html = preg_replace("/&lt;\/($tags)&gt;/i", '</$1>', $html);
-        // Fix quotes
-        $html = preg_replace("/&quot;/", '"', $html);
-        $html = addslashes($html);
-        // Don't allow, e.g. <a href="javascript:evil_code">
-        $html = preg_replace("/<($tags)([^>]*)>/ie", "'<$1' . stripslashes_safe(str_replace('javascript', 'hackerscript', '$2')) .'>'", $html);
-        // Don't allow, e.g. <img src="foo.gif" onmouseover="evil_javascript">
-        $html = preg_replace("/<($tags)([^>]*)>/ie", "'<$1' . stripslashes_safe(str_replace(' on', ' off', '$2')) .'>'", $html);
-        $html = stripslashes_safe($html);
-                                                                            
-    }
-                                                                                                     
-    // restore the ampersands
-    $html = preg_replace('/\0/', '&', $html);
-          
-    return($html);
-} // safeHTML
-
-// I don't like how the PHP count() function returns 1 if
-// you pass it a scalar. So this is my custom function that
-// will return 0 if the argument isn't an array.
-function blog_array_count($arr) {
-    if (!is_array($arr)) {
-        return 0;
-    }
-    
-    return count($arr);
-}
-
-/**
-* check_dir_exists
- *   Function to check if a directory exists
- *    and, optionally, create it
- *    copied from moodle/backup/lib.php
- */
-if (! function_exists('check_dir_exists')) {
-    function check_dir_exists($dir, $create=false) {
-        
-        global $CFG; 
-        
-        $status = true;
-        if (!is_dir($dir)) {
-            if (!$create) {
-                $status = false;
-            } else {
-                umask(0000);
-                $status = mkdir ($dir, $CFG->directorypermissions);
-            }
-        }
-        return $status;
-    }
-}
-
-/////////////// Time and Date display functions ///////////////
-
-/*
- * Returns the current time as a readable date string
- * using moodle's chosen full date display format from admin configuration.
- */
-function blog_now() {
-    $strftimedaydatetime = get_string('strftimedaydatetime');
-    $date = userdate(time(), $strftimedaydatetime);
-    return $date;
-}
-
-/**
-* UNIX timestamp to a readable format.
- * using moodle's chosen date format from admin configuration.
- */
-function blog_format_date($datetime) {
-    $strftimedate = get_string('strftimedate');
-    $date = userdate($datetime, $strftimedate);
-    return $date;
-}
-
-/**
-* converts unix timestamp to just a date
- * using moodle's chosen short date format from admin configuration.
- */
-function blog_short_date($datetime) {
-    $strftimedateshort = get_string('strftimedateshort');
-    $date = userdate($datetime, $strftimedateshort);
-    return $date;     
-}
-
-/**
-* converts unix timestamp to just a date
- * using moodle's chosen time format from admin configuration.
- */
-function blog_short_time($datetime) {
-    $strftimetime = get_string('strftimetime');
-    $time = userdate($datetime, $strftimedateshort);
-    return $time;
-}
-
-/////////////// Trackback functions ///////////////
-
-// Note: trackback specification
-// http://www.movabletype.org/docs/mttrackback.html
-
-
-/**
- * generate rdf for trackback autodiscovery
- */
-function blog_get_trackback_rdf_string($blogEntry) {
-    
-    global $CFG;
-    $userid = $blogEntry->entryuserid;
-    $entryid = $blogEntry->entryId;
-    $blogInfo = new BlogInfo($userid);
-    
-//    echo 'in blog_get_trackback_rdf_string blogEntry:<br />'."\n"; //debug
-//    print_object($blogEntry); //debug
-    
-    $rdf = "\n".'<!-- //RDF for trackback autodiscovery
-<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-         xmlns:dc="http://purl.org/dc/elements/1.1/"
-         xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
-<rdf:Description
-    rdf:about="'. htmlentities($CFG->wwwroot .'/blog/archive.php?userid='. $userid .'&amp;postid='. $entryid) .'"
-    dc:identifier="'. htmlentities($CFG->wwwroot .'/blog/archive.php?userid='. $userid .'&amp;postid='. $entryid) .'"
-    dc:title="'. $blogInfo->blogtitle .'" 
-    trackback:ping="';
-    if ($CFG->slasharguments) {
-               $rdf .= $CFG->wwwroot .'/blog/tb.php/'. $entryid;
-    } else {
-        $rdf .= $CFG->wwwroot .'/blog/tb.php?file=/'. $entryid;
-    }
-    $rdf .='" />
-</rdf:RDF>
--->'."\n";
-    unset($blogInfo); //clean up after ourselves
-    return $rdf;    
-}
-
-
-/**
- * Return a list of trackbacks for a particular id
- */
-function blog_list_trackbacks($postid) {
-    global $db, $CFG;
-
-    //Daryl Hawes note: convert this sql statement to a moodle function call
-    $sql = 'SELECT * FROM '. $CFG->prefix .'blog_trackback WHERE entryid = '. $postid;
-    $res = $db->Execute($sql);
-
-    //iterate results
-    $list = array();
-    while( !$res->EOF && isset($res->fields) ) {
-        $list[] = $res->fields;
-        $res->MoveNext();
-    }
-
-    return $list;
-}
-
-
-/////////////////////// CATEGORY MANAGEMENT ////////////////////////////////////
-
-
-
-  
-/**
- *called by blog_category_list
- * @return string  html links for each category
- */
-function blog_get_html_display_for_categories(&$blogFilter, $shownumentries, &$records, $showseparators, $title, $section) {
-    global $CFG, $editing;
-    $returnstring ='';
-    if ($showseparators) {
-        //first show a separator if requested
-        $returnstring .= $title .'<br />'."\n";
-    }
-    $editallowed = false;
-
-    if ($editing) {
-        $isteacher = false;
-        if (isset($blogFilter->courseid)) {
-            $isteacher = isteacher($blogFilter->courseid);
-        }
-        if ( isadmin() ) {
-            // admin is allowed to edit any categories on the site
-            $editallowed = true;
-        } else if ( ($section == 'course' || $section == 'group') && $isteacher ) {
-            // teacher of course can modify course categories and group categories
-            $editallowed = true;
-        } else if ($section == 'personal' && blog_is_blog_admin($blogFilter->userid) ) {
-            // user can modify their own blog categories
-            $editallowed = true;
-        }
-    }
-
-    if (!isset($records) ) {
-        return;
-    }
-    
-    foreach($records as $record) {
-        $catcount = '';
-        $categoryid = $record->id;
-        $categoryname = $record->catname;
-        if ($shownumentries) {
-            $tempfilter =& new BlogFilter('', $categoryid);
-            $catcount = ' (';
-            $catcount .= $tempfilter->get_filtered_entry_count();
-            $catcount .= ')';
-        }
-        $blogFilter->categoryid = $categoryid;
-        $returnstring .= $blogFilter->get_complete_link($CFG->wwwroot .'/blog/index.php', stripslashes_safe($categoryname) . $catcount);
-        if ($editallowed) {
-            // note that only the 'act' and 'categoryid' vars are needed here because the me() function includes the 
-            // existing query string
-            $returnstring .= '&nbsp;<a href="'. me() .'&amp;act=editcategory&amp;categoryid='. $categoryid .'">';
-            $returnstring .= '<img src="'. $CFG->pixpath .'/t/edit.gif" alt="'. get_string('edit');
-            $returnstring .= '" title="'. get_string('edit') .'" align="absmiddle" height="16" width="16" border="0" /></a>'."\n";
-            if ($categoryid != 1) { //do not remove "General" sitewide category
-                $returnstring .= '&nbsp;<a href="'. $CFG->wwwroot .'/blog/admin.php?act=delcategory&amp;categoryid='. $categoryid;
-                $returnstring .= '&amp;userid='. $blogFilter->userid .'&amp;courseid='. $blogFilter->courseid .'&amp;groupid='. $blogFilter->groupid .'" onClick="return confirm(\''. get_string('confirmcategorydelete', 'blog') .'\');">';
-                $returnstring .= '<img src="'. $CFG->pixpath .'/t/delete.gif" ALT="'. get_string('delete');
-$returnstring .= '" title="'. get_string('delete') .'" align="absmiddle" border="0" /></a>'."\n";
-            }
-        }
-        $returnstring .= '<br />'."\n";
-    }
-    return $returnstring;
-}
-
-/**
- *
- */
-function blog_get_popup_display_for_categories(&$blogFilter, $format, $shownumentries, &$records) {
-    global $CFG;
-
-    if (!isset($records) ) {
-        return;
-    }
-    $returnstring = '';
-    
-    foreach ($records as $record) {
-        if ($format == 2) {
-            $value = $CFG->wwwroot .'/blog/index.php?categoryid='. $record->id;
-            $value .= '&amp;userid='. $blogFilter->userid .'&amp;courseid='. $blogFilter->courseid .'&amp;groupid='. $blogFilter->groupid;
-        } else {
-            $value = $record->id;
-        }
-        
-        $returnstring .= '<option value="'. $value .'"';
-        if ($record->id == $blogFilter->categoryid) {
-            $returnstring .= ' selected';
-        }
-        $catcount = '';
-        $categoryid = $record->id;
-        $categoryname = $record->catname;
-        if ($shownumentries) {
-            $tempfilter =& new BlogFilter('', $categoryid);
-            $tempfilter->userid = $blogFilter->userid;
-            $catcount = ' (';
-            //if we had an array of blogentry objects we could avoid a database call
-            //and instead simply ask the blogentry objects to tell us which apply
-            $catcount .= $tempfilter->get_filtered_entry_count();
-            $catcount .= ')';
-        }
-        $returnstring .= '>' ."\n". stripslashes_safe($categoryname) . $catcount ."\n";
-        $returnstring .= '</option>';
-    }
-    return $returnstring;
-}
 ?>
index 6cbee778427acc5600cb943af40c98a6eda4b411..da0323c7edab846148b9279bdf726ac3b43a95b9 100755 (executable)
@@ -1,8 +1,3 @@
-<?php
-    // print out the extra form element needed to support post previews
-    blog_print_preview_form($bloginfo->userid);
-?>
-
 <form method="post" action="preferences.php" name="entry" id="entry">
 <input type="hidden" name="referrer" value="<?php echo $referrer; ?>" />
 <table cellpadding="9" cellspacing="0">