diff --git a/blog/lib.php b/blog/lib.php index 50db382d42e..40f48ee538e 100755 --- a/blog/lib.php +++ b/blog/lib.php @@ -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, ' ', ' '); - - $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='', $return=false) { - - $returnstring = "\n".'
'."\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 + * 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_rss_content($str) { - $str = superhtmlentities($str); - $content = "\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