From 7dd764b856c4b071f7d19abb86ee68586c99eb8a Mon Sep 17 00:00:00 2001 From: Jenny Gray Date: Thu, 20 Sep 2012 09:12:11 +0100 Subject: [PATCH] MDL-15471 course tagging improvements --- blocks/tags/block_tags.php | 332 +++++++++-------------------- blocks/tags/edit_form.php | 5 +- blocks/tags/lang/en/block_tags.php | 18 +- blocks/tags/settings.php | 15 +- blocks/tags/version.php | 2 +- lang/en/role.php | 1 + lib/db/access.php | 11 + lib/db/install.xml | 4 +- lib/db/upgrade.php | 16 +- tag/coursetags_edit.php | 2 +- tag/coursetags_more.php | 30 +-- tag/coursetagslib.php | 309 +-------------------------- tag/locallib.php | 30 ++- tag/search.php | 2 +- tag/tag.js | 4 - version.php | 2 +- 16 files changed, 191 insertions(+), 592 deletions(-) diff --git a/blocks/tags/block_tags.php b/blocks/tags/block_tags.php index 0e429f393431e..8a0529188eaaa 100644 --- a/blocks/tags/block_tags.php +++ b/blocks/tags/block_tags.php @@ -1,43 +1,54 @@ . + class block_tags extends block_base { - function init() { + public function init() { $this->title = get_string('pluginname', 'block_tags'); - // the cron function goes through all users, so only do daily - // (this creates rss feeds for personal course tags) - // removed until rsslib supports dc/cc - // $this->cron = 60*60*24; } - function instance_allow_multiple() { + public function instance_allow_multiple() { return true; } - function has_config() { + public function has_config() { return true; } - function applicable_formats() { + public function applicable_formats() { return array('all' => true); } - function instance_allow_config() { + public function instance_allow_config() { return true; } - function specialization() { + public function specialization() { - // load userdefined title and make sure it's never empty + // Load userdefined title and make sure it's never empty. if (empty($this->config->title)) { - $this->title = get_string('pluginname','block_tags'); + $this->title = get_string('pluginname', 'block_tags'); } else { $this->title = $this->config->title; } } - function get_content() { + public function get_content() { - global $CFG, $COURSE, $SITE, $USER, $SCRIPT, $OUTPUT; + global $CFG, $COURSE, $USER, $SCRIPT, $OUTPUT; if (empty($CFG->usetags)) { $this->content = new stdClass(); @@ -56,6 +67,10 @@ function get_content() { $this->config->numberoftags = 80; } + if (empty($this->config->tagtype)) { + $this->config->tagtype = ''; + } + if ($this->content !== NULL) { return $this->content; } @@ -68,260 +83,111 @@ function get_content() { $this->content = new stdClass; $this->content->footer = ''; - /// Get a list of tags + // Get a list of tags. require_once($CFG->dirroot.'/tag/locallib.php'); if (empty($CFG->block_tags_showcoursetags) or !$CFG->block_tags_showcoursetags) { - $this->content->text = tag_print_cloud($this->config->numberoftags, true); + $this->content->text = tag_print_cloud(null, $this->config->numberoftags, true); - // start of show course tags section } else { - + // Start of show course tags section. require_once($CFG->dirroot.'/tag/coursetagslib.php'); - // Permissions and page awareness - $systemcontext = context_system::instance(); - $loggedin = isloggedin() && !isguestuser(); - $coursepage = $canedit = false; - $coursepage = (isset($this->page->course->id) && $this->page->course->id != SITEID); - $mymoodlepage = ($SCRIPT == '/my/index.php') ? true : false; - $sitepage = (isset($this->page->course->id) && $this->page->course->id == SITEID && !$mymoodlepage); - if ($coursepage) { - $canedit = has_capability('moodle/tag:create', $systemcontext); - } - - // Check rss feed - temporarily removed until Dublin Core tags added - // provides a feed of users course tags for each unit they have tagged - //$rssfeed = ''; - //if (file_exists($CFG->dataroot.'/'.SITEID.'/usertagsrss/'.$USER->id.'/user_unit_tags_rss.xml')) { - // $rssfeed = '/file.php/'.SITEID.'/usertagsrss/'.$USER->id.'/user_unit_tags_rss.xml'; - //} - - // Language strings - $tagslang = 'block_tags'; - - // DB hits to get groups of marked up tags (if available) - //TODO check whether time limited personal tags are required - $numoftags = $this->config->numberoftags; - $sort = 'name'; - $coursetagdivs = array(); - $alltags = $officialtags = $coursetags = $commtags = $mytags = $courseflag = ''; - if ($sitepage or $coursepage) { - $alltags = coursetag_print_cloud(coursetag_get_all_tags($sort, $this->config->numberoftags), true); - $officialtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', $numoftags, $sort), true); - $commtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', $numoftags, $sort), true); - if ($loggedin) { - $mytags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', $numoftags, $sort), true); + // Page awareness. + $tagtype = 'all'; + if ($SCRIPT == '/my/index.php') { + $tagtype = 'my'; + } else if (isset($this->page->course->id)) { + if ($this->page->course->id != SITEID) { + $tagtype = 'course'; } } - if ($coursepage) { - $coursetags = coursetag_print_cloud(coursetag_get_tags($this->page->course->id, 0, '', $numoftags, $sort), true); - if (!$coursetags) $coursetags = get_string('notagsyet', $tagslang); - $courseflag = '&courseid='.$this->page->course->id; - } - if ($mymoodlepage) { - $mytags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', $numoftags, $sort), true); - $officialtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', $numoftags, $sort), true); - $commtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', $numoftags, $sort), true); - } - // Prepare the divs and javascript that displays the groups of tags (and which is displayed first) - $moretags = $CFG->wwwroot.'/tag/coursetags_more.php'; - $moretagstitle = get_string('moretags', $tagslang); - $moretagsstring = get_string('more', $tagslang); - $displayblock = 'style="display:block"'; - $displaynone = 'style="display:none"'; //only one div created below will be displayed at a time - if ($alltags) { - if ($sitepage) { - $display = $displayblock; - } else { - $display = $displaynone; - } - $alltagscontent = ' -
'. - get_string("alltags", $tagslang). - '
'.$alltags.'
- -
'; - $coursetagdivs[] = 'f_alltags'; - } - if ($mytags) { - if ($mymoodlepage) { - $display = $displayblock; - } else { - $display = $displaynone; - } - $mytagscontent = ' -
'; - /*if ($rssfeed) { // - temporarily removed - $mytagscontent .= link_to_popup_window( - $rssfeed, $name='popup', - 'User Unit Tags RSS My Unit Tags RSS', - $height=600, $width=800, - $title='My Unit Tags RSS', $options='menubar=1,scrollbars,resizable', $return=true).'
'; - }*/ - $mytagscontent .= - get_string('mytags', $tagslang). - '
'.$mytags.'
- -
'; - $coursetagdivs[] = 'f_mytags'; - } - if ($officialtags) { - if ($mytags or $alltags) { - $display = $displaynone; - } else { - $display = $displayblock; - } - $officialtagscontent = ' -
'. - get_string('officialtags', $tagslang). - '
'.$officialtags.'
- -
'; - $coursetagdivs[] = 'f_officialtags'; + // DB hits to get groups of marked up tags (if available). + // TODO check whether time limited personal tags are required. + $content = ''; + $moretags = new moodle_url('/tag/coursetags_more.php', array('show'=>$tagtype)); + if ($tagtype == 'all') { + $tags = coursetag_get_tags(0, 0, $this->config->tagtype, $this->config->numberoftags, 'name'); + } else if ($tagtype=='course') { + $tags = coursetag_get_tags($this->page->course->id, 0, $this->config->tagtype, $this->config->numberoftags, 'name'); + $moretags->param('courseid', $this->page->course->id); + } else if ($tagtype=='my') { + $tags = coursetag_get_tags(0, $USER->id, $this->config->tagtype, $this->config->numberoftags, 'name'); } - if ($coursetags) { - if ($coursepage) { - $display = $displayblock; - } else { - $display = $displaynone; - } - $coursetagscontent = ' -
'. - get_string('coursetags', $tagslang). - '
'.$coursetags.'
- -
'; - $coursetagdivs[] = 'f_coursetags'; + $tagcloud = tag_print_cloud($tags, 150, true); + if (!$tagcloud) { + $tagcloud = get_string('notagsyet', 'block_tags'); } - if ($commtags) { - $commtagscontent = ' -
'. - get_string('communitytags', $tagslang). - '
'.$commtags.'
- -
'; - $coursetagdivs[] .= 'f_commtags'; - } - // Tidy up the end of a javascript array and add javascript - coursetag_get_jscript($coursetagdivs); - // Add the divs (containing the tags) to the block's content - if ($alltags) { $this->content->text .= $alltagscontent; } - if ($mytags) { $this->content->text .= $mytagscontent; } - if ($officialtags) { $this->content->text .= $officialtagscontent; } - if ($coursetags) { $this->content->text .= $coursetagscontent; } - if ($commtags) { $this->content->text .= $commtagscontent; } - // add the input form section (allowing a user to tag the current course) and navigation, or loggin message - if ($loggedin) { - // only show the input form on course pages for those allowed (or not barred) - if ($coursepage && $canedit) { - //$this->content->footer .= coursetag_get_jscript(); - $tagthisunit = get_string('tagthisunit', $tagslang); - $buttonadd = get_string('add', $tagslang); - $arrowtitle = get_string('arrowtitle', $tagslang); + // Prepare the divs that display the groups of tags. + $content = get_string($tagtype."tags", 'block_tags'). + '
'.$tagcloud.'
+ '; + // Add javascript. + coursetag_get_jscript(); + + // Add the divs (containing the tags) to the block's content. + $this->content->text .= $content; + + // Add the input form section (allowing a user to tag the current course) and navigation, or login message. + if (isloggedin() && !isguestuser()) { + // Only show the input form on course pages for those allowed (or not barred). + if ($tagtype == 'course' && + has_capability('moodle/tag:create', context_course::instance($this->page->course->id))) { + $buttonadd = get_string('add', 'block_tags'); + $arrowtitle = get_string('arrowtitle', 'block_tags'); + $edit_tags = get_string('edittags', 'block_tags'); $sesskey = sesskey(); $arrowright = $OUTPUT->pix_url('t/arrow_left'); + $redirect = $this->page->url->out(); $this->content->footer .= <<
- -
-
-
-
-
- - +
-
- +
+
+
+ +
+
+ +
+
+ + enter + +
-
- - enter - +
+ + $edit_tags
-
- -
-
EOT; - // add the edit link - $this->content->footer .= ' - '; - } - - // Navigation elements at the bottom of the block - // show the alternative displays options if available - $elementid = 'coursetagslinks_'.$this->instance->id; - if ($mytags or $officialtags or $commtags or $coursetags) { - $this->content->footer .= '
'; - } - // This section sets the order of the links - $coursetagslinks = array(); - if ($mytags) { - $coursetagslinks['my'] = array('title'=>get_string('mytags2', $tagslang), - 'onclick'=>'f_mytags', - 'text'=>get_string('mytags1', $tagslang)); - } - // because alltags is always present, only show link if there is something else as well - if ($alltags and ($mytags or $officialtags or $commtags or $coursetags)) { - $coursetagslinks['all'] = array('title'=>get_string('alltags2', $tagslang), - 'onclick'=>'f_alltags', - 'text'=>get_string('alltags1', $tagslang)); } - if ($officialtags) { - $coursetagslinks['off'] = array('title'=>get_string('officialtags2', $tagslang), - 'onclick'=>'f_officialtags', - 'text'=>get_string('officialtags1', $tagslang)); - } - //if ($commtags) { - // $coursetagslinks['com'] = array('title'=>get_string('communitytags2', $tagslang), - // 'onclick'=>'f_commtags', - // 'text'=>get_string('communitytags1', $tagslang)); - //} - if ($coursetags) { - $coursetagslinks['crs'] = array('title'=>get_string('coursetags2', $tagslang), - 'onclick'=>'f_coursetags', - 'text'=>get_string('coursetags1', $tagslang)); - } - coursetag_get_jscript_links($elementid, $coursetagslinks); - } else { - //if not logged in - $this->content->footer = '
'.get_string('please', $tagslang).' - '.get_string('login', $tagslang).' - '.get_string('tagunits', $tagslang); + // If not logged in. + $this->content->footer = '
'.get_string('please', 'block_tags').' + '.get_string('login', 'block_tags').' + '.get_string('tagunits', 'block_tags'); } } - // end of show course tags section + // End of show course tags section. return $this->content; } -} - +} \ No newline at end of file diff --git a/blocks/tags/edit_form.php b/blocks/tags/edit_form.php index ea7f3cb9cb369..bc5c26522b9b1 100644 --- a/blocks/tags/edit_form.php +++ b/blocks/tags/edit_form.php @@ -1,5 +1,4 @@ addElement('select', 'config_numberoftags', get_string('numberoftags', 'blog'), $numberoftags); $mform->setDefault('config_numberoftags', 80); + + $defaults = array('default'=>'default', 'official'=>'official', ''=>'both'); + $mform->addElement('select', 'config_tagtype', get_string('defaultdisplay', 'block_tags'), $defaults); + $mform->setDefault('config_tagtype', ''); } } diff --git a/blocks/tags/lang/en/block_tags.php b/blocks/tags/lang/en/block_tags.php index 0643b911d664e..67098167ab5f5 100644 --- a/blocks/tags/lang/en/block_tags.php +++ b/blocks/tags/lang/en/block_tags.php @@ -1,5 +1,4 @@ . defined('MOODLE_INTERNAL') || die; @@ -6,4 +20,3 @@ $settings->add(new admin_setting_configcheckbox('block_tags_showcoursetags', get_string('showcoursetags', 'block_tags'), get_string('showcoursetagsdef', 'block_tags'), 0)); } - diff --git a/blocks/tags/version.php b/blocks/tags/version.php index 3885368054af8..d4b93d125a520 100644 --- a/blocks/tags/version.php +++ b/blocks/tags/version.php @@ -25,6 +25,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2012061700; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2012082800; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2012061700; // Requires this Moodle version $plugin->component = 'block_tags'; // Full name of the plugin (used for diagnostics) diff --git a/lang/en/role.php b/lang/en/role.php index 2e05346e335d7..d1fc04b24c036 100644 --- a/lang/en/role.php +++ b/lang/en/role.php @@ -353,6 +353,7 @@ $string['tag:edit'] = 'Edit existing tags'; $string['tag:editblocks'] = 'Edit blocks in tags pages'; $string['tag:manage'] = 'Manage all tags'; +$string['tag:flag'] = 'Flag tags as innappropriate'; $string['thisusersroles'] = 'This user\'s role assignments'; $string['unassignarole'] = 'Unassign role {$a}'; $string['unassignerror'] = 'Error while unassigning the role {$a->role} from user {$a->user}.'; diff --git a/lib/db/access.php b/lib/db/access.php index ebf6021347ee5..5ee80e527cd35 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -1669,6 +1669,17 @@ ) ), + 'moodle/tag:flag' => array( + 'riskbitmask' => RISK_SPAM, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'archetypes' => array( + 'manager' => CAP_ALLOW, + 'user' => CAP_ALLOW + ) + ), + 'moodle/tag:editblocks' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, diff --git a/lib/db/install.xml b/lib/db/install.xml index bcd5920cdf278..2dd1403a59256 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -2019,8 +2019,8 @@ - - + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 4fc23fc1b38e6..2a55f52c0ab7f 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1206,5 +1206,19 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2012090700.01); } + if ($oldversion < 2012092000.00) { + // Define index idname (unique) to be added to tag + $table = new xmldb_table('tag'); + $index = new xmldb_index('idname', XMLDB_INDEX_UNIQUE, array('id', 'name')); + + // Conditionally launch add index idname + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + // Main savepoint reached + upgrade_main_savepoint(true, 2012092000.01); + } + return true; -} +} \ No newline at end of file diff --git a/tag/coursetags_edit.php b/tag/coursetags_edit.php index 53e6be651866b..39f637f57c5b6 100644 --- a/tag/coursetags_edit.php +++ b/tag/coursetags_edit.php @@ -96,7 +96,7 @@ $title = get_string('edittitle', $tagslang); echo $OUTPUT->heading($title, 2, 'mdl-align'); - $mytags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default'), true); + $mytags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default'), 150, true); $outstr = '
diff --git a/tag/coursetags_more.php b/tag/coursetags_more.php index 61c3ccd333115..da4d25e2fabd3 100644 --- a/tag/coursetags_more.php +++ b/tag/coursetags_more.php @@ -105,44 +105,44 @@ if ($show == 'course' and $courseid) { if ($sort == 'popularity') { - $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'popularity'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'popularity'), 150, true); } else if ($sort == 'date') { - $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'timemodified'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'timemodified'), 150, true); } else { - $tags = coursetag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags($courseid, 0, '', 0, 'name'), 150, true); } // My tags } else if ($show == 'my' and $loggedin) { if ($sort == 'popularity') { - $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'popularity'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'popularity'), 150, true); } else if ($sort == 'date') { - $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'timemodified'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'timemodified'), 150, true); } else { - $tags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'name'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', 0, 'name'), 150, true); } // Official course tags } else if ($show == 'official') { if ($sort == 'popularity') { - $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'popularity'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'popularity'), 150, true); } else if ($sort == 'date') { - $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'timemodified'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'timemodified'), 150, true); } else { - $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'name'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'official', 0, 'name'), 150, true); } // Community (official and personal together) also called user tags } else if ($show == 'community') { if ($sort == 'popularity') { - $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'popularity'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'popularity'), 150, true); } else if ($sort == 'date') { - $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'timemodified'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'timemodified'), 150, true); } else { - $tags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'name'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_tags(0, 0, 'default', 0, 'name'), 150, true); } // All tags for courses and blogs and any thing else tagged - the fallback default ($show == all) @@ -150,11 +150,11 @@ $subtitle = $showalltags; if ($sort == 'popularity') { - $tags = coursetag_print_cloud(coursetag_get_all_tags('popularity'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_all_tags('popularity'), 150, true); } else if ($sort == 'date') { - $tags = coursetag_print_cloud(coursetag_get_all_tags('timemodified'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_all_tags('timemodified'), 150, true); } else { - $tags = coursetag_print_cloud(coursetag_get_all_tags('name'), true, 200, 90); + $tags = tag_print_cloud(coursetag_get_all_tags('name'), 150, true); } } diff --git a/tag/coursetagslib.php b/tag/coursetagslib.php index 7d36b473642a4..bde390df00941 100644 --- a/tag/coursetagslib.php +++ b/tag/coursetagslib.php @@ -24,6 +24,7 @@ */ require_once $CFG->dirroot.'/tag/lib.php'; +require_once $CFG->dirroot.'/tag/locallib.php'; /** * Returns an ordered array of tags associated with visible courses @@ -186,110 +187,26 @@ function coursetag_sort($a, $b) { if (is_numeric($a->$tagsort)) { return ($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort > $b->$tagsort) ? 1 : -1; - } elseif (is_string($a->$tagsort)) { + } else if (is_string($a->$tagsort)) { return strcmp($a->$tagsort, $b->$tagsort); } else { return 0; } } -/** - * Prints a tag cloud - * - * @package core_tag - * @category tag - * @param array $tagcloud array of tag objects (fields: id, name, rawname, count and flag) - * @param mixed $return if true return html string - * @param int $max_size maximum text size, in percentage - * @param int $min_size minimum text size, in percentage - */ -function coursetag_print_cloud($tagcloud, $return=false, $max_size=180, $min_size=80) { - - global $CFG; - - if (empty($tagcloud)) { - return; - } - - ksort($tagcloud); - - $count = array(); - foreach ($tagcloud as $key => $value) { - if(!empty($value->count)) { - $count[$key] = log10($value->count); - } else { - $count[$key] = 0; - } - } - - $max = max($count); - $min = min($count); - - $spread = $max - $min; - if (0 == $spread) { // we don't want to divide by zero - $spread = 1; - } - - $step = ($max_size - $min_size)/($spread); - - $systemcontext = context_system::instance(); - $can_manage_tags = has_capability('moodle/tag:manage', $systemcontext); - - //prints the tag cloud - $output = '
    '; - foreach ($tagcloud as $key => $tag) { - - $size = $min_size + ((log10($tag->count) - $min) * $step); - $size = ceil($size); - - $style = 'style="font-size: '.$size.'%"'; - - if ($tag->count > 1) { - $title = 'title="'.s(get_string('thingstaggedwith','tag', $tag)).'"'; - } else { - $title = 'title="'.s(get_string('thingtaggedwith','tag', $tag)).'"'; - } - - $href = 'href="'.$CFG->wwwroot.'/tag/index.php?id='.$tag->id.'"'; - - //highlight tags that have been flagged as inappropriate for those who can manage them - $tagname = tag_display_name($tag); - if ($tag->flag > 0 && $can_manage_tags) { - $tagname = '' . tag_display_name($tag) . ''; - } - - $tag_link = '
  • '.$tagname.'
  • '; - - $output .= $tag_link; - - } - $output .= '
'."\n"; - - if ($return) { - return $output; - } else { - echo $output; - } -} - /** * Returns javascript for use in tags block and supporting pages * * @package core_tag * @category tag - * @param string $coursetagdivs comma separated divs ids * @return null */ -function coursetag_get_jscript($coursetagdivs = '') { +function coursetag_get_jscript() { global $CFG, $DB, $PAGE; $PAGE->requires->js('/tag/tag.js'); $PAGE->requires->strings_for_js(array('jserror1', 'jserror2'), 'block_tags'); - if ($coursetagdivs) { - $PAGE->requires->js_function_call('set_course_tag_divs', $coursetagdivs); - } - if ($coursetags = $DB->get_records('tag', null, 'name ASC', 'name, id')) { foreach ($coursetags as $key => $value) { $PAGE->requires->js_function_call('set_course_tag', array($key)); @@ -359,7 +276,7 @@ function coursetag_store_keywords($tags, $courseid, $userid=0, $tagtype='officia global $CFG; if (is_array($tags) and !empty($tags)) { - foreach($tags as $tag) { + foreach ($tags as $tag) { $tag = trim($tag); if (strlen($tag) > 0) { //tag_set_add('course', $courseid, $tag, $userid); //deletes official tags @@ -494,221 +411,3 @@ function coursetag_delete_course_tags($courseid, $showfeedback=false) { } } -/* - * Function called by cron to create/update users rss feeds - * - * @return true - * - * Function removed. - * rsslib.php needs updating to accept Dublin Core tags (dc/cc) input before this can work. - */ -/* -function coursetag_rss_feeds() { - - global $CFG, $DB; - require_once($CFG->dirroot.'/lib/dmllib.php'); - require_once($CFG->dirroot.'/lib/rsslib.php'); - - $status = true; - mtrace(' Preparing to update all user unit tags RSS feeds'); - if (empty($CFG->enablerssfeeds)) { - mtrace(' RSS DISABLED (admin variables - enablerssfeeds)'); - } else { - - // Load all the categories for use later on - $categories = $DB->get_records('course_categories'); - - // get list of users who have tagged a unit - $sql = " - SELECT DISTINCT u.id as userid, u.username, u.firstname, u.lastname, u.email - FROM {user} u, {course} c, {tag_instance} cti, {tag} t - WHERE c.id = cti.itemid - AND u.id = cti.tiuserid - AND t.id = cti.tagid - AND t.tagtype = 'personal' - AND u.confirmed = 1 - AND u.deleted = 0 - ORDER BY userid"; - if ($users = $DB->get_records_sql($sql)) { - - $items = array(); //contains rss data items for each user - foreach ($users as $user) { - - // loop through each user, getting the data (tags for courses) - $sql = " - SELECT cti.id, c.id as courseid, c.fullname, c.shortname, c.category, t.rawname, cti.timemodified - FROM {course} c, {tag_instance} cti, {tag} t - WHERE c.id = cti.itemid - AND cti.tiuserid = :userid{$user->userid} - AND cti.tagid = t.id - AND t.tagtype = 'personal' - ORDER BY courseid"; - if ($usertags = $DB->get_records_sql($sql, array('userid' => $user->userid))) { - $latest_date = 0; //latest date any tag was created by a user - $c = 0; //course identifier - - foreach ($usertags as $usertag) { - if ($usertag->courseid != $c) { - $c = $usertag->courseid; - $items[$c] = new stdClass(); - $items[$c]->title = $usertag->fullname . '(' . $usertag->shortname . ')'; - $items[$c]->link = $CFG->wwwroot . '/course/view.php?name=' . $usertag->shortname; - $items[$c]->description = ''; //needs to be blank - $items[$c]->category = $categories[$usertag->category]->name; - $items[$c]->subject[] = $usertag->rawname; - $items[$c]->pubdate = $usertag->timemodified; - $items[$c]->tag = true; - } else { - $items[$c]->subject[] .= $usertag->rawname; - } - // Check and set the latest modified date. - $latest_date = $usertag->timemodified > $latest_date ? $usertag->timemodified : $latest_date; - } - - // Setup some vars for use while creating the file - $path = $CFG->dataroot.'/1/usertagsrss/'.$user->userid; - $file_name = 'user_unit_tags_rss.xml'; - $title = get_string('rsstitle', 'tag', ucwords(strtolower($user->firstname.' '.$user->lastname))); - $desc = get_string('rssdesc', 'tag'); - // check that the path exists - if (!file_exists($path)) { - mtrace(' Creating folder '.$path); - check_dir_exists($path, TRUE, TRUE); - } - - // create or update the feed for the user - // this functionality can be copied into seperate lib as in next two lines - //require_once($CFG->dirroot.'/local/ocilib.php'); - //oci_create_rss_feed( $path, $file_name, $latest_date, $items, $title, $desc, $dc=true, $cc=false); - - // Set path to RSS file - $full_path = "$save_path/$file_name"; - - mtrace(" Preparing to update RSS feed for $file_name"); - - // First let's make sure there is work to do by checking the time the file was last modified, - // if a course was update after the file was mofified - if (file_exists($full_path)) { - if ($lastmodified = filemtime($full_path)) { - mtrace(" XML File $file_name Created on ".date( "D, j M Y G:i:s T", $lastmodified )); - mtrace(' Lastest course modification on '.date( "D, j M Y G:i:s T", $latest_date )); - if ($latest_date > $lastmodified) { - mtrace(" XML File $file_name needs updating"); - $changes = true; - } else { - mtrace(" XML File $file_name doesn't need updating"); - $changes = false; - } - } - } else { - mtrace(" XML File $file_name needs updating"); - $changes = true; - } - - if ($changes) { - // Now we know something has changed, write the new file - - if (!empty($items)) { - // First set rss feeds common headers - $header = rss_standard_header(strip_tags(format_string($title,true)), - $CFG->wwwroot, - $desc, - true, true); - // Now all the rss items - if (!empty($header)) { - $articles = rss_add_items($items,$dc,$cc); - } - // Now all rss feeds common footers - if (!empty($header) && !empty($articles)) { - $footer = rss_standard_footer(); - } - // Now, if everything is ok, concatenate it - if (!empty($header) && !empty($articles) && !empty($footer)) { - $result = $header.$articles.$footer; - } else { - $result = false; - } - } else { - $result = false; - } - - // Save the XML contents to file - if (!empty($result)) { - $rss_file = fopen($full_path, "w"); - if ($rss_file) { - $status = fwrite ($rss_file, $result); - fclose($rss_file); - } else { - $status = false; - } - } - - // Output result - if (empty($result)) { - // There was nothing to put into the XML file. Delete it! - if( is_file($full_path) ) { - mtrace(" There were no items for XML File $file_name. Deleting XML File"); - unlink($full_path); - mtrace(" $full_path -> (deleted)"); - } else { - mtrace(" There were no items for the XML File $file_name and no file to delete. Ignore."); - } - } else { - if (!empty($status)) { - mtrace(" $full_path -> OK"); - } else { - mtrace(" $full_path -> FAILED"); - } - } - } - //end of oci_create_rss_feed() - } - } - } - } - - return $status; -} - */ - -/* - * Get official keywords for the in header.html - * use: echo ''; - * - * @param int $courseid - * @return string - * - * Function removed but fully working - * This function is potentially useful to anyone wanting to improve search results for course pages. - * The idea is to add official tags (not personal tags to prevent their deletion) to all - * courses (facility not added yet) which will be automatically added to the page header to boost - * search engine specificity/ratings. - */ -/* -function coursetag_get_official_keywords($courseid, $asarray=false) { - global $CFG; - $returnstr = ''; - $sql = "SELECT t.id, name, rawname - FROM {tag} t, {tag_instance} ti - WHERE ti.itemid = :courseid - AND ti.itemtype = 'course' - AND t.tagtype = 'official' - AND ti.tagid = t.id - ORDER BY name ASC"; - if ($tags = $DB->get_records_sql($sql, array('courseid' => $courseid))) { - if ($asarray) { - return $tags; - } - foreach ($tags as $tag) { - if( empty($CFG->keeptagnamecase) ) { - $name = textlib::strtotitle($tag->name); - } else { - $name = $tag->rawname; - } - $returnstr .= $name.', '; - } - $returnstr = rtrim($returnstr, ', '); - } - return $returnstr; -} -*/ diff --git a/tag/locallib.php b/tag/locallib.php index 095bbda04a2b9..92abe5dae3cbb 100644 --- a/tag/locallib.php +++ b/tag/locallib.php @@ -32,21 +32,29 @@ * @package core_tag * @access public * @category tag - * @param int $nr_of_tags Limit for the number of tags to return/display + * @param array $tagset Array of tags to display + * @param int $nr_of_tags Limit for the number of tags to return/display, used if $tagset is null * @param bool $return if true the function will return the generated tag cloud instead of displaying it. * @return string|null a HTML string or null if this function does the output */ -function tag_print_cloud($nr_of_tags=150, $return=false) { +//TODO question for integrator - for contrib work would it be best to add $tagset at the end of the parameter list +// not the beginning? I put it at the beginning because it sits better as alternative to $nr_of_tags there +function tag_print_cloud($tagset=null, $nr_of_tags=150, $return=false) { global $CFG, $DB; $can_manage_tags = has_capability('moodle/tag:manage', context_system::instance()); - if ( !$tagsincloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag - FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid - WHERE ti.itemtype <> \'tag\' - GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.tagtype - ORDER BY count DESC, tg.name ASC', null, 0, $nr_of_tags) ) { - $tagsincloud = array(); + if (is_null($tagset)) { + // No tag set received, so fetch tags from database + if ( !$tagsincloud = $DB->get_records_sql('SELECT tg.rawname, tg.id, tg.name, tg.tagtype, COUNT(ti.id) AS count, tg.flag + FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid + WHERE ti.itemtype <> \'tag\' + GROUP BY tg.id, tg.rawname, tg.name, tg.flag, tg.tagtype + ORDER BY count DESC, tg.name ASC', null, 0, $nr_of_tags) ) { + $tagsincloud = array(); + } + } else { + $tagsincloud = $tagset; } $tagkeys = array_keys($tagsincloud); @@ -200,8 +208,10 @@ function tag_print_management_box($tag_object, $return=false) { $links[] = ''. get_string('addtagtomyinterests', 'tag', $tagname) .''; } - // flag as inappropriate link - $links[] = ''. get_string('flagasinappropriate', 'tag', rawurlencode($tagname)) .''; + // Flag as inappropriate link. Only people with moodle/tag:flag capability. + if (has_capability('moodle/tag:flag', $systemcontext)) { + $links[] = ''. get_string('flagasinappropriate', 'tag', rawurlencode($tagname)) .''; + } // Edit tag: Only people with moodle/tag:edit capability who either have it as an interest or can manage tags if (has_capability('moodle/tag:edit', $systemcontext) || diff --git a/tag/search.php b/tag/search.php index 422d4e1bc7ca0..b399bac2d1279 100644 --- a/tag/search.php +++ b/tag/search.php @@ -72,7 +72,7 @@ echo '

'; echo $OUTPUT->box_start('generalbox', 'big-tag-cloud-box'); -tag_print_cloud(150); +tag_print_cloud(null, 150); echo $OUTPUT->box_end(); echo $OUTPUT->footer(); diff --git a/tag/tag.js b/tag/tag.js index 5cab660389dce..85fc306266bfd 100644 --- a/tag/tag.js +++ b/tag/tag.js @@ -45,10 +45,6 @@ function ctags_checkinput(val) { } } -function set_course_tag_divs(ctagdivs) { - window.coursetagdivs = ctagdivs; -} - function set_course_tag(key) { window.coursetag_tags[window.coursetag_tags.length] = key; } diff --git a/version.php b/version.php index a79542418841c..593815a66c97f 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012092000.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012092000.01; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes