Skip to content

Commit

Permalink
MDL-13404 - Merge from 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
scyrma committed Feb 22, 2008
1 parent 52a6dc1 commit db32b05
Show file tree
Hide file tree
Showing 25 changed files with 811 additions and 1,583 deletions.
2 changes: 1 addition & 1 deletion backup/backuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ function backup_user_info ($bf,$preferences) {

//Check if we have user tags to backup
if (!empty($CFG->usetags)) {
if ($tags = get_item_tags('user', $user->id)) { //This return them ordered by default
if ($tags = tag_get_tags(array('type'=>'user', 'id'=>$user->id))) { //This return them ordered by default
//Start USER_TAGS tag
fwrite ($bf,start_tag("USER_TAGS",4,true));
//Write user tags fields
Expand Down
2 changes: 1 addition & 1 deletion blocks/blog_tags/block_blog_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function get_content() {
$this->content->text .= '<li><a href="'.$link.'" '.
'class="'.$tag->class.'" '.
'title="'.get_string('numberofentries','blog',$tag->ct).'">'.
$tag->name.'</a></li> ';
tag_display_name($tag) .'</a></li> ';
}
$this->content->text .= "\n</ul>\n";

Expand Down
17 changes: 14 additions & 3 deletions blocks/tag_flickr/block_tag_flickr.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,23 @@ function get_content() {
return $this->content;
}

$tagid = optional_param('id', 0, PARAM_INT); // tag id
$tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility
$tag = optional_param('tag', '', PARAM_TAG); // tag

if ($tag) {
$tag_object = tag_get_id($tag, TAG_RETURN_OBJECT);
} elseif (!$tag && $tagid) {
$tag_object = tag_get_tag_by_id($tagid);
} else {
// can't display the block if no tag was submitted!
// todo: something useful here.
error('Missing tag parameter');
}

//include related tags in the photo query ?
$tags_csv = tag_display_name(tag_by_id($tagid));
$tags_csv = html_entity_decode(tag_display_name($tag_object));
if (!empty($this->config->includerelatedtags)) {
$tags_csv .= ',' . tag_names_csv( get_item_tags('tag',$tagid));
$tags_csv .= ',' . tag_get_related_tags_csv(tag_get_related_tags(array('type'=>'tag','id'=>$tag_object->id)), TAG_RETURN_TEXT);
}
$tags_csv = urlencode($tags_csv);

Expand Down
59 changes: 43 additions & 16 deletions blocks/tag_youtube/block_tag_youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,29 @@ function get_videos_by_playlist(){

function get_videos_by_tag(){

$tagid = optional_param('id', 0, PARAM_INT); // tag id
$tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility
$tag = optional_param('tag', '', PARAM_TAG); // tag

if ($tag) {
$tag_object = tag_get_id($tag, TAG_RETURN_OBJECT);
} elseif (!$tag && $tagid) {
$tag_object = tag_get_tag_by_id($tagid);
} else {
// can't display the block if no tag was submitted!
// todo: something useful here.
error('Missing tag parameter');
}

$query_tag = tag_display_name(tag_by_id($tagid));
$query_tag = html_entity_decode(tag_display_name($tag_object));
$query_tag = urlencode($query_tag);

$numberofvideos = DEFAULT_NUMBER_OF_VIDEOS;
if( !empty($this->config->numberofvideos)) {
if ( !empty($this->config->numberofvideos) ) {
$numberofvideos = $this->config->numberofvideos;
}

$request = 'http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag';
$request .= '&dev_id=' . YOUTUBE_DEV_KEY;
$request .= '&dev_id='. YOUTUBE_DEV_KEY;
$request .= "&tag={$query_tag}";
$request .= "&page=1";
$request .= "&per_page={$numberofvideos}";
Expand All @@ -99,9 +110,20 @@ function get_videos_by_tag(){

function get_videos_by_tag_and_category(){

$tagid = optional_param('id', 0, PARAM_INT); // tag id
$tagid = optional_param('id', 0, PARAM_INT); // tag id - for backware compatibility
$tag = optional_param('tag', '', PARAM_TAG); // tag

if ($tag) {
$tag_object = tag_get_id($tag, TAG_RETURN_OBJECT);
} elseif (!$tag && $tagid) {
$tag_object = tag_get_tag_by_id($tagid);
} else {
// can't display the block if no tag was submitted!
// todo: something useful here.
error('Missing tag parameter');
}

$query_tag = tag_display_name(tag_by_id($tagid));
$query_tag = html_entity_decode(tag_display_name($tag_object));
$query_tag = urlencode($query_tag);

$numberofvideos = DEFAULT_NUMBER_OF_VIDEOS;
Expand Down Expand Up @@ -158,18 +180,23 @@ function render_video_list($xmlobj){
$text .= '<ul class="yt-video-entry unlist img-text">';
$videos = $xmlobj['ut_response']['video_list']['video'];

foreach($videos as $video){
$text .= '<li>';
$text .= '<div class="clearfix">';
$text .= '<a href="'. s($video['url']) . '">';
$text .= '<img alt="" class="youtube-thumb" src="'. $video['thumbnail_url'] .'" /></a>';
$text .= '</div><span><a href="'. s($video['url']) . '">'.s($video['title']).'</a></span>';
$text .= '<div>';
$text .= format_time($video['length_seconds']);
$text .= "</div></li>\n";
if (is_array($videos) ) {
foreach($videos as $video){
$text .= '<li>';
$text .= '<div class="clearfix">';
$text .= '<a href="'. s($video['url']) . '">';
$text .= '<img alt="" class="youtube-thumb" src="'. $video['thumbnail_url'] .'" /></a>';
$text .= '</div><span><a href="'. s($video['url']) . '">'.s($video['title']).'</a></span>';
$text .= '<div>';
$text .= format_time($video['length_seconds']);
$text .= "</div></li>\n";
}
} else {
// if youtube is offline, or for whatever reason the previous
// call doesn't work...
//add_to_log(SITEID, 'blocks/tag_youtube', 'problem in getting videos off youtube');
}
$text .= "</ul><div class=\"clearer\"></div>\n";

return $text;
}
}
Expand Down
4 changes: 2 additions & 2 deletions blocks/tags/block_tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ function get_content() {

/// Get a list of tags

require_once($CFG->dirroot.'/tag/lib.php');
require_once($CFG->dirroot.'/tag/taglib.php');

$this->content->text = print_tag_cloud(popular_tags_count($this->config->numberoftags), false, 170, 70, true);
$this->content->text = tag_print_cloud($this->config->numberoftags, false, 170, 70, true);

return $this->content;
}
Expand Down
57 changes: 16 additions & 41 deletions blog/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,12 @@
$post->action = $action;
$strformheading = get_string('updateentrywithid', 'blog');

if ($itemptags = get_item_tags('post', $post->id, 'ti.ordering ASC', 'id,rawname', '', '', 'default')) {
if ($ptags = records_to_menu($itemptags, 'id','rawname')) {
$post->ptags = implode(', ', $ptags);
} else {
$post->ptags = '';
}
if ($itemptags = html_entity_decode(tag_get_tags_csv(array('type'=>'post', 'id'=>$post->id), TAG_RETURN_TEXT, 'default'))) {
$post->ptags = $itemptags;
}

if ($itemotags = get_item_tags('post', $post->id, 'ti.ordering ASC', 'id,rawname', '', '', 'official')) {
if ($otags = records_to_menu($itemotags, 'id','rawname')) {
$post->otags = array_keys($otags);
}
if ($itemotags = tag_get_tags_array(array('type'=>'post', 'id'=>$post->id), 'official')) {
$post->otags = array_keys($itemotags);
}
break;
default :
Expand Down Expand Up @@ -231,7 +225,7 @@ function do_delete($post) {

$status = delete_records('post', 'id', $post->id);
//$status = delete_records('blog_tag_instance', 'entryid', $post->id) and $status;
untag_an_item('post', $post->id);
tag_set('post', $post->id, array());

blog_delete_old_attachments($post);

Expand Down Expand Up @@ -293,7 +287,7 @@ function do_edit($post, $blogeditform) {

//delete_records('blog_tag_instance', 'entryid', $post->id);
//delete_records('tag_instance', 'itemid', $post->id, 'itemtype', 'blog');
untag_an_item('post', $post->id);
//untag_an_item('post', $post->id);
// add them back
add_tags_info($post->id);

Expand All @@ -309,38 +303,19 @@ function do_edit($post, $blogeditform) {
* @param int postid - id of the blog
*/
function add_tags_info($postid) {

global $USER;

$post = get_record('post', 'id', $postid);

/// Attach official tags

$tags = array();
if ($otags = optional_param('otags', '', PARAM_INT)) {
foreach ($otags as $otag) {
$tag->tagid = $otag;
//insert_record('blog_tag_instance', $tag);
tag_an_item('post', $postid, $otag, 'official');
foreach ($otags as $tagid) {
// TODO : make this use the tag name in the form
$tag = tag_get_tag_by_id($tagid);
$tags[] = $tag->name;
}
}

/// Attach Personal Tags
if ($ptags = optional_param('ptags', '', PARAM_NOTAGS)) {
$ptags = explode(',', $ptags);
foreach ($ptags as $ptag) {
$ptag = trim($ptag);
// check for existence
// it does not matter whether it is an offical tag or personal tag
// we do not want to have 1 copy of offical tag and 1 copy of personal tag (for the same tag)
if ($ctag = tag_by_name($ptag)) {
tag_an_item('post', $postid, $ctag->id);
} else { // create a personal tag
if ($tagid = tag_create($ptag)) {
if ($tagid = array_shift($tagid)) {
tag_an_item('post', $postid, $tagid);
}
}
}
}
}
$manual_tags = optional_param('ptags', '', PARAM_NOTAGS);
$tags = array_merge($tags, explode(',', $manual_tags));

tag_set('post', $postid, $tags);
}
?>
28 changes: 4 additions & 24 deletions blog/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function definition() {


if (!empty($CFG->usetags)) {
$mform->addElement('header', 'tagshdr', get_string('tags', 'blog'));
$mform->createElement('select', 'otags', get_string('otags','blog'));
$mform->addElement('header', 'tagshdr', get_string('tags', 'tag'));
$mform->createElement('select', 'otags', get_string('otags','tag'));

$js_escape = array(
"\r" => '\r',
Expand All @@ -46,28 +46,11 @@ function definition() {
'\\' => '\\\\'
);

$otagsselEl =& $mform->addElement('select', 'otags', get_string('otags', 'blog'), array(), 'size="5"');
$otagsselEl =& $mform->addElement('select', 'otags', get_string('otags', 'tag'), array(), 'size="5"');
$otagsselEl->setMultiple(true);
$this->otags_select_setup();

if (has_capability('moodle/blog:manageofficialtags', $sitecontext)){
$deleteotagsmsg = strtr(get_string('deleteotagswarn', 'blog'), $js_escape);
$mform->registerNoSubmitButton('deleteotags');
$mform->addElement('submit', 'deleteotags', get_string('delete'),
array('onclick'=>"return confirm('$deleteotagsmsg');"));
$mform->disabledIf('deleteotags', 'otags[]', 'noitemselected');
$mform->setAdvanced('deleteotags');

$mform->registerNoSubmitButton('addotags');
$otagsgrp = array();
$otagsgrp[] =& $mform->createElement('text', 'otagsadd', get_string('addotags', 'blog'));
$otagsgrp[] =& $mform->createElement('submit', 'addotags', get_string('add'));
$mform->addGroup($otagsgrp, 'otagsgrp', get_string('addotags','blog'), array(' '), false);
$mform->setType('otagsadd', PARAM_NOTAGS);
$mform->setAdvanced('otagsgrp');
}

$mform->addElement('textarea', 'ptags', get_string('ptags', 'blog'), array('cols'=>'40', 'rows'=>'5'));
$mform->addElement('textarea', 'ptags', get_string('ptags', 'tag'), array('cols'=>'40', 'rows'=>'5'));
$mform->setType('ptagsadd', PARAM_NOTAGS);
}

Expand Down Expand Up @@ -99,9 +82,6 @@ function otags_select_setup(){
}
if ($otags = get_records_sql_menu('SELECT id, name from '.$CFG->prefix.'tag WHERE tagtype=\'official\' ORDER by name ASC')){
$otagsselect->loadArray($otags);
} else {
// removing this causes errors
//$mform->removeElement('otags');
}
}

Expand Down
7 changes: 2 additions & 5 deletions blog/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@

if (!empty($tagid)) {
$taginstance = get_record('tag', 'id', $tagid);
} else {
$tagid = '';
if (!empty($tag)) {
$taginstance = tag_id($tag);
}
} elseif (!empty($tag)) {
$taginstance = tag_id($tag);
}

/// navigations
Expand Down
4 changes: 2 additions & 2 deletions blog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

$id = optional_param('id', 0, PARAM_INT);
$start = optional_param('formstart', 0, PARAM_INT);
$userid = optional_param('userid',0,PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
$tag = optional_param('tag', '', PARAM_NOTAGS);
$tagid = optional_param('tagid', 0, PARAM_INT);
$postid = optional_param('postid',0,PARAM_INT);
$postid = optional_param('postid', 0, PARAM_INT);
$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
$filterselect = optional_param('filterselect', 0, PARAM_INT);

Expand Down
17 changes: 3 additions & 14 deletions blog/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,22 +222,11 @@ function blog_print_entry($blogEntry, $viewtype='full', $filtertype='', $filters
echo $attachedimages;
/// Links to tags

/*
if ($blogtags = get_records_sql('SELECT t.* FROM '.$CFG->prefix.'tags t, '.$CFG->prefix.'blog_tag_instance ti
WHERE t.id = ti.tagid
AND ti.entryid = '.$blogEntry->id)) {
*/
if (!empty($CFG->usetags) && ($blogtags = get_item_tags('post', $blogEntry->id))) {
if ( !empty($CFG->usetags) && ($blogtags = tag_get_tags_csv(array('type'=>'post', 'id'=>$blogEntry->id))) ) {
echo '<div class="tags">';
if ($blogtags) {
print_string('tags');
echo ': ';
foreach ($blogtags as $key => $blogtag) {
//$taglist[] = '<a href="index.php?filtertype='.$filtertype.'&amp;filterselect='.$filterselect.'&amp;tagid='.$blogtag->id.'">'.tag_display_name($blogtag).'</a>'; // Blog tag only
$taglist[] = '<a href="'.$CFG->wwwroot.'/tag/index.php?id='.$blogtag->id.'">'.tag_display_name($blogtag).'</a>'; // General tag link
}
echo implode(', ', $taglist);
}
print(get_string('tags', 'tag') .': '. $blogtags);
}
echo '</div>';
}

Expand Down
4 changes: 0 additions & 4 deletions lang/en_utf8/blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@


$string['addnewentry'] = 'Add a new entry';
$string['addotags'] = 'Add official tags';
$string['addptags'] = 'Add user-defined tags';
$string['backupblogshelp'] = 'If enabled then blogs will be included in SITE automated backups';
$string['blockmenutitle'] = 'Blog Menu';
$string['blocktagstitle'] = 'Blog Tags';
Expand Down Expand Up @@ -35,10 +33,8 @@
$string['notallowedtoedit'] = 'You are not allowed to edit this entry';
$string['numberofentries'] = 'Entries: $a';
$string['numberoftags'] = 'Number of tags to display';
$string['otags'] = 'Official tags';
$string['pagesize'] = 'Number of blog entries per Page';
$string['personalblogs'] = 'Users can only see their own blog';
$string['ptags'] = 'User defined tags (Comma separated)';
$string['publishto'] = 'Publish to';
$string['publishtonoone'] = 'Yourself (draft)';
$string['publishtosite'] = 'Anyone on this site';
Expand Down
4 changes: 4 additions & 0 deletions lang/en_utf8/tag.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

$string['addedotag'] = '\"$a\" was added as an official tag.';
$string['addotags'] = 'Add official tags';
$string['addtagtomyinterests'] = 'Add \"$a\" to my interests';
$string['blocktagstitle'] = 'Tags';
$string['count'] = 'Count';
Expand All @@ -20,6 +22,8 @@
$string['newname'] = 'New tag name';
$string['noresultsfor'] = 'No results for \"$a\"';
$string['owner'] = 'Owner';
$string['otags'] = 'Official tags';
$string['ptags'] = 'User defined tags (Comma separated)';
$string['relatedtags'] = 'Related tags';
$string['responsiblewillbenotified'] = 'The person responsible will be notified';
$string['resetflag'] = 'Reset flag';
Expand Down
Loading

0 comments on commit db32b05

Please sign in to comment.