return true;
}
- /**
- * get_formatted_entry_link
- *
- * @return string Permalink URL wrapped in an HTML link
- */
- function get_formatted_entry_link() {
-
- // removed the word 'permalink' and replaced with 'Read More' to
- // further eliminate jargon from moodle blog
- // Daryl Hawes note: must localize this line now
- $str = '<a href="'. $this->get_entryurl() .'">Read More</a>';
- return $str;
-
- }
-
- /*
- * get_simple_entry_link - Just the link, with no extra html.
- *
- * @return string Returns just a URL with no HTML.
- * (Daryl Hawes note: this function moved to class.Blogentry from lib.php)
- */
- function get_simple_entry_link() {
-
- $str = htmlspecialchars( $this->get_entryurl() );
- return $str;
-
- }
-
- /**
- * get_blog_this_URL added by Daryl Hawes for moodle integration
- *
- * @param bool $showImage If true then the return string is an HTML image tag
- * If false then the return string is an HTML text link
- * @uses $CFG
- * @return string An HTML image tag or text link depending upon $showImage argument
- */
- function get_blog_this_URL($showImage=false) {
- $str = '';
- global $CFG;
- //ensure user is logged in and that they have a blog to edit
- if ( !isguest() && blog_isLoggedIn() ) {
- $blogThisString = '';
- if ($showImage) {
- $blogThisString = '<img src="'. $CFG->pixpath .'/blog/blog.gif" alt="'. get_string('blogthis', 'blog');
- $blogThisString .= '!" title="'. get_string('blogthis', 'blog') .'!" border="0" align="middle" />';
- } else {
- $blogThisString = get_string('blogthis', 'blog');
- }
- if (!$showImage) {
- $str .= '(';
- }
- $str .= '<a href="'. $this->get_entryblogthisurl() .'">'. $blogThisString .'</a>';
- if (!$showImage) {
- $str .= ')';
- }
- }
- return $str;
- }
-
- /**
- * get_formatted_edit_URL added by Daryl Hawes for moodle integration
- * An empty string is returned if the user is a guest, the user is not logged in,
- * or the user is not currently editing their blog page (turn editing on button)
- * we will only show edit link if the entry is in draft status or the user is an admin
- * note: teacher should not be allowed to edit or delete - only demote back to draft
- *
- * @param bool $showImage If false a text link is printed. If true a linked edit icon is printed.
- * @uses $USER
- * @uses $CFG
- * @todo get_formatted_delete_URL and get_formatted_edit_URL should be merged into a single function
- */
- function get_formatted_edit_URL($showImage=false) {
- global $USER, $CFG;
- $str = '';
-
- if ( !isguest() && blog_isLoggedIn() && blog_isediting() && blog_is_blog_admin($this->entryuserid)
- && (!$CFG->blog_enable_moderation || isadmin() || $blogEntry->entryPublishState == 'draft') ) {
- $str = '<div class="blogedit">';
-
- //check if user is in blog's acl
- //instead of creating a new BlogInfo object might a BlogInfo pointer in BlogEntry constructor be better? Does php have singleton objects? if not then a bloginfo reference as an argument to the constructor of BlogEntry would be a good idea. (The only problem here is in pages with multiple bloginfo objects represented - aggregate pages.)
- $bloginfo = new BlogInfo($this->entryuserid);
- //if so then show them an edit link
- if (blog_user_has_rights($bloginfo)) {
- $editString = '';
- if ($showImage) {
- $editString = '<img src="'. $CFG->pixpath .'/t/edit.gif" alt="'. get_string('edit');
- $editString .= '" title="'. get_string('edit') .'" align="absmiddle" height="16" width="16" border="0" />';
- } else {
- $editString = get_string('edit');
- }
- if (!$showImage) {
- $str .= '(';
- }
- $str .= '<a title="'. get_string('edit') .'" href="'. $this->get_entryediturl() .'">'. $editString .'</a>';
- if (!$showImage) {
- $str .= ')';
- }
- }
- $str .= '</div>';
- unset($blogInfo); //clean up after ourselves
- }
- return $str;
- }
-
- /**
- * get_formatted_delete_URL added by Daryl Hawes for moodle integration
- * An empty string is returned if the user is a guest, the user is not logged in,
- * or the user is not currently editing their blog page (turn editing on button)
- * we will only show edit link if the entry is in draft status or the user is an admin
- * note: teacher should not be allowed to edit or delete - only demote back to draft
- *
- * @uses $USER
- * @uses $CFG
- * @param bool $showImage If false a text link is printed. If true a linked delete icon is printed.
- * @todo get_formatted_delete_URL and get_formatted_edit_URL should be merged into a single function
- */
- function get_formatted_delete_URL($showImage=false) {
- global $USER, $CFG;
- $str = '';
-
- if ( !isguest() && blog_isLoggedIn() && blog_isediting() && blog_is_blog_admin($this->entryuserid)
- && (!$CFG->blog_enable_moderation || isadmin() || $blogEntry->entryPublishState == 'draft') ) {
-
- $str = '<div class="blogdelete">';
-
- //check if user is in blog's acl
- //instead of creating a new BlogInfo object might a BlogInfo pointer in BlogEntry constructor be better? Does php have singleton objects? if not then a bloginfo reference as an argument to the constructor of BlogEntry would be a good idea.
- $bloginfo =& new BlogInfo($this->entryuserid);
- //if so then show them an edit link
- if (blog_user_has_rights($bloginfo)) {
- $deleteString = '';
- if ($showImage) {
- $deleteString = '<img src="'. $CFG->pixpath .'/t/delete.gif" alt="'. get_string('delete');
- $deleteString .= '" title="'. get_string('delete') .'" align="absmiddle" border="0" />';
- } else {
- $deleteString = get_string('delete');
- }
- if (!$showImage) {
- $str .= '(';
- }
- $str .= '<a title="'. get_string('delete') .'" href="'. $this->get_entrydeleteurl() .'">'. $deleteString .'</a>';
- if (!$showImage) {
- $str .= ')';
- }
- }
- $str .= '</div>';
- unset($blogInfo); //clean up after ourselves
- }
- return $str;
- }
-
/**
* get_formatted_entry_body
* getter for ->entryBody.
return $CFG->wwwroot .'/blog/archive.php?userid='. $this->entryuserid .'&postid='. $this->entryId;
}
- /**
- * The url of the news feed containing this item. Uses global admin config to determin what feed type to point to.
- * @return string
- */
- function get_entryfeedurl() {
- global $CFG;
- return $CFG->wwwroot .'/blog/rss.php?userid='. $this->entryuserid;
- }
-
- /**
- *
- * @return string
- */
- function get_entryediturl() {
- global $CFG;
- return $CFG->wwwroot .'/blog/edit.php?userid='. $this->entryuserid .'&editid='. $this->entryId;
- }
-
-
- /**
- *
- * @return string
- */
- function get_entrydeleteurl() {
- global $CFG;
- return 'javascript:del(\''. $CFG->wwwroot .'/blog/\', '. $this->entryId .', '. $this->entryuserid .')';
- }
-
- /**
- *
- * @return string
- */
- function get_entryblogthisurl() {
- global $CFG;
- return $CFG->wwwroot .'/blog/blogthis.php?userid='. $this->entryuserid .'&act=use&postid='. $this->entryId;
- }
/**
* BlogEntry setters do not save to the database.
return false;
}
- /**
- * BlogEntry setters do not save to the database.
- * To save changes call the BlogEntry->save() function when ready.
- *
- * @param int $courseid The course by id that this entry should be associated with.
- */
- function set_courseid($courseid) {
- $this->entryCourseId = $courseid;
- }
-
- /**
- * BlogEntry setters do not save to the database.
- * To save changes call the BlogEntry->save() function when ready.
- *
- * @param int $groupid The groupid that this entry should be associated with.
- */
- function set_groupid($groupid) {
- $this->entryGroupId = $groupid;
- }
-
- /**
- * BlogEntry setters do not save to the database.
- * To save changes call the BlogEntry->save() function when ready.
- *
- * @param array $catids An array of category ids to associate this entry with.
- */
- function set_categoryids($catids) {
- $this->entryCategoryIds = $catids;
-
- if (!empty($this->entryCategoryIds)) {
- if (!is_array($this->entryCategoryIds)) {
- $this->entryCategoryIds = array($this->entryCategoryIds);
- }
- $this->entryCategoryIds = array_unique($this->entryCategoryIds);
- }
-
- // now populate the entryCategories array
- if (!empty($this->entryCategoryIds)) {
- foreach ($this->entryCategoryIds as $categoryid) {
- if (! $currcat = get_record('blog_categories', 'id', $categoryid)) {
- print 'Could not find category id '. $categoryid ."\n";
- $this->entryCategories[$categoryid] = '';
- } else {
- $this->entryCategories[$categoryid] = $currcat->catname;
- }
- }
- }
- }
/**
* This function will determine if the user is logged in and
if ( ! $uid == '' && ! isguest() ) {
return true;
}
- } else if ($this->entryPublishState == 'course') {
- //there is a courseid and the user is a member of that course
- if ( isset($this->entryCourseId) && (isteacher($this->entryCourseId, $uid) || isstudent($this->entryCourseId, $uid) ) ) {
- return true;
- }
- } else if ($this->entryPublishState == 'teacher') {
- if ( isset($this->entryCourseId) && isteacher($this->entryCourseId, $uid) ) {
- return true;
- }
- } else if ($this->entryPublishState == 'group') {
- if ( isset($this->entryGroupId) && ismember($this->entryGroupId, $uid) ) {
- return true;
- }
- }
+ }
//nothing qualified - the user requesting access is not allowed to view this entry!
return false;
$this->blogtitle = &$this->blogInfo->blogtitle;
$this->blogtagline = &$this->blogInfo->blogtagline;
- $this->blogtheme = $this->blogInfo->get_blog_theme();
}
if (!is_numeric($courseid) || $courseid == 0 || $courseid == 1) {
//still no entries - they must all be filtered away or there simply are none. return null.
return NULL;
}
-
- /**
- *
- */
- function get_bloginfo() {
- //returns blog entries based on current filters as stored by but not created by this class
- if (!empty($this->blogInfo) ) {
- return $this->blogInfo;
- }
- return NULL;
- }
/**
* Using the member variables build a where clause and sql statment
return $this->filtered_entries;
}
- /**
- * get_where_clause
- *
- * This function will take all of this BlogFilter's instance variables and
- * calculate the proper sql string needed to fetch the appropriate entries.
- * fields are referred to as e.* in the post table
- * and c.* if they are in the blog_categories_entries table
- *
- * @return string The where clause for searching using this filter's settings
- */
- function get_where_clause() {
- $hascats = false;
- $where = '';
- if ( !empty($this->categoryid) ) {
- $hascats = true;
- }
-
- if ($this->is_userid_valid()) {
- $where .= 'e.userid='. $this->userid;
- }
- if ($this->is_courseid_valid()) {
- if ($where != '') {
- $where .= ' AND ';
- }
- $where .= 'e.courseid='. $this->courseid;
- }
-
- if ($this->is_userid_valid() && $this->is_postid_valid()) {
- // a blog and a specific entry in that blog were specified. our mission is clear
- if ($where != '') {
- $where .= ' AND ';
- }
- $where .= 'e.id='. $this->postid .' ';
- } else {
- // we do not have a specific post id, so get all posts that match additional criteria if present
- if ($hascats) {
- if ($where != '') {
- $where .= ' AND ';
- }
- // where the discovered post id matches the categories_entries table entryid and the catid matches
- $where .= ' e.id = c.entryid AND c.categoryid='. $this->categoryid;
-
- }
- }
-
- if ( !empty($this->tstart) && !empty($this->tend) ) {
- if ($where != '') {
- $where .= ' AND ';
- }
- $where .= 'e.lastmodified >= '. $this->tstart .' AND e.lastmodified <= '. $this->tend;
- }
-
- //http://www.techonthenet.com/sql/like.htm
- $keywords = $this->keywords;
- if (!empty($keywords) && count($keywords) > 0) {
- if (!empty($keywords['body'])) {
- if ($where != '') {
- $where .= ' AND ';
- }
- $where .= "(e.body LIKE '%". $keywords['body'] ."%' OR e.extendedbody LIKE '%". $keywords['body'] ."%') ";
- }
- if (!empty($keywords['body'])) {
- if ($where != '') {
- $where .= ' AND ';
- }
- $where .= "(e.title LIKE '%". $keywords['title'] ."%') ";
- }
- }
- return $where;
- }
-
- /**
- * get the count of entries in db without applying full filtering
- */
- function get_entry_count($where='', $hascats=false) {
- global $CFG;
- $sql = 'post e';
- if ($hascats) {
- $sql .= ', '. $CFG->prefix .'blog_categories_entries c ';
- }
- if (empty($where)) {
- $where = $this->get_where_clause();
- }
- return count_records_select($sql, $where);
- }
-
/**
* get the count of viewable entries, easiest way is to count fetch_entries
* this is used for print_paging_bar
*/
function get_filtered_entry_count() {
global $CFG;
-
+ //might need to use a count_records_sql.
$entries = $this->get_filtered_entries();
return count($entries);
}
$link .= $linktext . '</a>';
return $link;
}
-
+
/**
* The unused param is defined as either
* <code>
$unused = array($unused);
}
if (!in_array('startmonth', $unused)) {
- $getargs .= '&m=' . $this->startmonth;
+ $getargs .= '&m=' . $this->startmonth;
}
if (!in_array('startday', $unused)) {
$getargs .= '&d=' . $this->startday;
}
return $getargs;
}
-
- function is_userid_valid() {
- if (is_numeric($this->userid) && $this->userid != 0 && $this->userid != '') {
- return true;
- }
- return false;
- }
-
- function is_groupid_valid() {
- if (is_numeric($this->groupid) && $this->groupid != 0 && $this->groupid != '') {
- return true;
- }
- return false;
- }
-
- function is_courseid_valid() {
- if (is_numeric($this->courseid) && $this->courseid != 0 && $this->courseid != '') {
- return true;
- }
- return false;
- }
-
- function is_postid_valid() {
- if (is_numeric($this->postid) && $this->postid != 0 && $this->postid != '') {
- return true;
- }
- return false;
- }
-
- /**
- * get_member_list
- *
- * @param string $sort
- * @param int $limitnum
- * @return object containing records with ->id and ->title of member blogs
- */
- function get_member_list($sort='', $limitnum='') {
- global $CFG;
- if (!empty($this->memberlist)) {
- return $this->memberlist;
- }
-
- //temporarily change $this->fetchstart to unlimit the entries from db and fetch
- $oldstart = $this->fetchstart;
- $this->fetchstart = '';
- $entries = $this->fetch_entries();
- $this->fetchstart = $oldstart;
-
- $records = array();
- $bids = array();
- foreach ($entries as $entry) {
- if (!in_array($entry->entryuserid, $bids)) {
- $bids[$entry->entryuserid] = $entry->entryuserid;
- }
- }
-
- foreach ($bids as $bid) {
- $thisrecord->id = $bid;
- $thisrecord->title = get_user_preferences('blogtitle', $CFG->blog_default_title, $bid);
- $records[] = $thisrecord;
- }
- $this->memberlist = $records;
- return $records;
- }
} //end class BlogFilter
?>
$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="extendedbody" />';
$returnstring .= "\n".'<input type="hidden" name="comm" />';
$returnstring .= "\n".'<input type="hidden" name="tem" />';
$returnstring .= "\n".'<input type="hidden" name="userid" value="'. $userid .'" />';
$template['body'] = $blogEntry->get_formatted_entry_body();
$template['countofextendedbody'] = 0;
- if ($template['extendedbody'] = $blogEntry->get_formatted_entry_extended_body()) {
- $template['extendedbody'] = $blogEntry->get_formatted_entry_extended_body();
- $template['countofextendedbody'] = count_words($template->extendedbody);
- } else {
- $template['extendedbody'] = '';
- }
-
- if ($viewtype=='full' && !empty($template['extendedbody'])) {
- $template['body'] .= '<hr width="80%" />' . $template['extendedbody'];
- } else if ( !empty($template->extendedbody) && $template->countofextendedbody != 0) {
- $template['body'] .= '<br /> <a href="'. $blogEntry->get_entryurl() .'">'. get_string('moreelipses', 'blog') .' ('. $template['countofextendedbody'] .' words)</a>';
- }
-
$template['title'] = '<a name="'. $blogEntry->entryId .'"></a>';
//enclose the title in nolink tags so that moodle formatting doesn't autolink the text
$template['title'] .= '<span class="nolink">'. stripslashes_safe($blogEntry->entryTitle);
$template['title'] .= '</span>';
// add editing controls if allowed
- $template['editbuttons'] = $blogEntry->get_formatted_edit_URL(true);
- $template['editbuttons'] .= $blogEntry->get_formatted_delete_URL(true);
$template['courseid'] = $blogEntry->entryCourseId;
$template['userid'] = $blogEntry->entryuserid;
$template['authorviewurl'] = $CFG->wwwroot .'/user/view.php?course=1&id='. $template['userid'];