Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/blocks/tags/block_tags.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class block_tags extends block_base {
00004     function init() {
00005         $this->title = get_string('pluginname', 'block_tags');
00006         // the cron function goes through all users, so only do daily
00007         // (this creates rss feeds for personal course tags)
00008         // removed until rsslib supports dc/cc
00009         // $this->cron = 60*60*24;
00010     }
00011 
00012     function instance_allow_multiple() {
00013         return true;
00014     }
00015 
00016     function has_config() {
00017         return true;
00018     }
00019 
00020     function applicable_formats() {
00021         return array('all' => true);
00022     }
00023 
00024     function instance_allow_config() {
00025         return true;
00026     }
00027 
00028     function specialization() {
00029 
00030         // load userdefined title and make sure it's never empty
00031         if (empty($this->config->title)) {
00032             $this->title = get_string('pluginname','block_tags');
00033         } else {
00034             $this->title = $this->config->title;
00035         }
00036     }
00037 
00038     function get_content() {
00039 
00040         global $CFG, $COURSE, $SITE, $USER, $SCRIPT, $OUTPUT;
00041 
00042         if (empty($CFG->usetags)) {
00043             $this->content->text = '';
00044             if ($this->page->user_is_editing()) {
00045                 $this->content->text = get_string('disabledtags', 'block_tags');
00046             }
00047             return $this->content;
00048         }
00049 
00050         if (!isset($this->config)) {
00051             $this->config = new stdClass();
00052         }
00053 
00054         if (empty($this->config->numberoftags)) {
00055             $this->config->numberoftags = 80;
00056         }
00057 
00058         if ($this->content !== NULL) {
00059             return $this->content;
00060         }
00061 
00062         if (empty($this->instance)) {
00063             $this->content = '';
00064             return $this->content;
00065         }
00066 
00067         $this->content = new stdClass;
00068         $this->content->footer = '';
00069 
00071 
00072         require_once($CFG->dirroot.'/tag/locallib.php');
00073 
00074         if (empty($CFG->block_tags_showcoursetags) or !$CFG->block_tags_showcoursetags) {
00075 
00076             $this->content->text = tag_print_cloud($this->config->numberoftags, true);
00077 
00078         // start of show course tags section
00079         } else {
00080 
00081             require_once($CFG->dirroot.'/tag/coursetagslib.php');
00082 
00083             // Permissions and page awareness
00084             $systemcontext = get_context_instance(CONTEXT_SYSTEM);
00085             $loggedin = isloggedin() && !isguestuser();
00086             $coursepage = $canedit = false;
00087             $coursepage = (isset($this->page->course->id) && $this->page->course->id != SITEID);
00088             $mymoodlepage = ($SCRIPT == '/my/index.php') ? true : false;
00089             $sitepage = (isset($this->page->course->id) && $this->page->course->id == SITEID && !$mymoodlepage);
00090             $coursecontext = get_context_instance(CONTEXT_COURSE, $this->page->course->id);
00091             if ($coursepage) {
00092                 $canedit =  has_capability('moodle/tag:create', $systemcontext);
00093             }
00094 
00095             // Check rss feed - temporarily removed until Dublin Core tags added
00096             // provides a feed of users course tags for each unit they have tagged
00097             //$rssfeed = '';
00098             //if (file_exists($CFG->dataroot.'/'.SITEID.'/usertagsrss/'.$USER->id.'/user_unit_tags_rss.xml')) {
00099             //    $rssfeed = '/file.php/'.SITEID.'/usertagsrss/'.$USER->id.'/user_unit_tags_rss.xml';
00100             //}
00101 
00102             // Language strings
00103             $tagslang = 'block_tags';
00104 
00105             // DB hits to get groups of marked up tags (if available)
00106             //TODO check whether time limited personal tags are required
00107             $numoftags = $this->config->numberoftags;
00108             $sort = 'name';
00109             $coursetagdivs = array();
00110             $alltags = $officialtags = $coursetags = $commtags = $mytags = $courseflag = '';
00111             if ($sitepage or $coursepage) {
00112                 $alltags = coursetag_print_cloud(coursetag_get_all_tags($sort, $this->config->numberoftags), true);
00113                 $officialtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', $numoftags, $sort), true);
00114                 $commtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', $numoftags, $sort), true);
00115                 if ($loggedin) {
00116                     $mytags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', $numoftags, $sort), true);
00117                 }
00118             }
00119             if ($coursepage) {
00120                 $coursetags = coursetag_print_cloud(coursetag_get_tags($this->page->course->id, 0, '', $numoftags, $sort), true);
00121                 if (!$coursetags) $coursetags = get_string('notagsyet', $tagslang);
00122                 $courseflag = '&amp;courseid='.$this->page->course->id;
00123             }
00124             if ($mymoodlepage) {
00125                 $mytags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id, 'default', $numoftags, $sort), true);
00126                 $officialtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'official', $numoftags, $sort), true);
00127                 $commtags = coursetag_print_cloud(coursetag_get_tags(0, 0, 'default', $numoftags, $sort), true);
00128             }
00129 
00130             // Prepare the divs and javascript that displays the groups of tags (and which is displayed first)
00131             $moretags = $CFG->wwwroot.'/tag/coursetags_more.php';
00132             $moretagstitle = get_string('moretags', $tagslang);
00133             $moretagsstring = get_string('more', $tagslang);
00134             $displayblock = 'style="display:block"';
00135             $displaynone = 'style="display:none"'; //only one div created below will be displayed at a time
00136             if ($alltags) {
00137                 if ($sitepage) {
00138                     $display = $displayblock;
00139                 } else {
00140                     $display = $displaynone;
00141                 }
00142                 $alltagscontent = '
00143                     <div id="f_alltags" '.$display.'>'.
00144                         get_string("alltags", $tagslang).
00145                         '<div class="coursetag_list">'.$alltags.'</div>
00146                         <div class="coursetag_morelink">
00147                             <a href="'.$moretags.'?show=all'.$courseflag.'" title="'.$moretagstitle.'">'.$moretagsstring.'</a>
00148                         </div>
00149                     </div>';
00150                 $coursetagdivs[] = 'f_alltags';
00151             }
00152             if ($mytags) {
00153                 if ($mymoodlepage) {
00154                     $display = $displayblock;
00155                 } else {
00156                     $display = $displaynone;
00157                 }
00158                 $mytagscontent = '
00159                     <div id="f_mytags" '.$display.'>';
00160                         /*if ($rssfeed) { // - temporarily removed
00161                             $mytagscontent .= link_to_popup_window(
00162                                 $rssfeed, $name='popup',
00163                                 '<img src="'.$CFG->wwwroot.'/pix/rss.gif" alt="User Unit Tags RSS" /> My Unit Tags RSS',
00164                                 $height=600, $width=800,
00165                                 $title='My Unit Tags RSS', $options='menubar=1,scrollbars,resizable', $return=true).'<br />';
00166                         }*/
00167                 $mytagscontent .=
00168                         get_string('mytags', $tagslang).
00169                         '<div class="coursetag_list">'.$mytags.'</div>
00170                         <div class="coursetag_morelink">
00171                             <a href="'.$moretags.'?show=my'.$courseflag.'" title="'.$moretagstitle.'">'.$moretagsstring.'</a>
00172                         </div>
00173                     </div>';
00174                 $coursetagdivs[] = 'f_mytags';
00175             }
00176             if ($officialtags) {
00177                 if ($mytags or $alltags) {
00178                     $display = $displaynone;
00179                 } else {
00180                     $display = $displayblock;
00181                 }
00182                 $officialtagscontent = '
00183                     <div id="f_officialtags" '.$display.'>'.
00184                         get_string('officialtags', $tagslang).
00185                         '<div class="coursetag_list">'.$officialtags.'</div>
00186                         <div class="coursetag_morelink">
00187                             <a href="'.$moretags.'?show=official'.$courseflag.'" title="'.$moretagstitle.'">'.$moretagsstring.'</a>
00188                         </div>
00189                     </div>';
00190                 $coursetagdivs[] = 'f_officialtags';
00191             }
00192             if ($coursetags) {
00193                 if ($coursepage) {
00194                     $display = $displayblock;
00195                 } else {
00196                     $display = $displaynone;
00197                 }
00198                 $coursetagscontent = '
00199                     <div id="f_coursetags" '.$display.'>'.
00200                         get_string('coursetags', $tagslang).
00201                         '<div class="coursetag_list">'.$coursetags.'</div>
00202                         <div class="coursetag_morelink">
00203                             <a href="'.$moretags.'?show=course'.$courseflag.'" title="'.$moretagstitle.'">'.$moretagsstring.'</a>
00204                         </div>
00205                     </div>';
00206                 $coursetagdivs[] = 'f_coursetags';
00207             }
00208             if ($commtags) {
00209                 $commtagscontent = '
00210                     <div id="f_commtags" '.$displaynone.'>'.
00211                         get_string('communitytags', $tagslang).
00212                         '<div class="coursetag_list">'.$commtags.'</div>
00213                         <div class="coursetag_morelink">
00214                             <a href="'.$moretags.'?show=community'.$courseflag.'" title="'.$moretagstitle.'">'.$moretagsstring.'</a>
00215                         </div>
00216                     </div>';
00217                 $coursetagdivs[] .= 'f_commtags';
00218             }
00219             // Tidy up the end of a javascript array and add javascript
00220             coursetag_get_jscript($coursetagdivs);
00221 
00222             // Add the divs (containing the tags) to the block's content
00223             if ($alltags) { $this->content->text .= $alltagscontent; }
00224             if ($mytags) { $this->content->text .= $mytagscontent; }
00225             if ($officialtags) { $this->content->text .= $officialtagscontent; }
00226             if ($coursetags) { $this->content->text .= $coursetagscontent; }
00227             if ($commtags) { $this->content->text .= $commtagscontent; }
00228 
00229             // add the input form section (allowing a user to tag the current course) and navigation, or loggin message
00230             if ($loggedin) {
00231                 // only show the input form on course pages for those allowed (or not barred)
00232                 if ($coursepage && $canedit) {
00233                     //$this->content->footer .= coursetag_get_jscript();
00234                     $tagthisunit = get_string('tagthisunit', $tagslang);
00235                     $buttonadd = get_string('add', $tagslang);
00236                     $arrowtitle = get_string('arrowtitle', $tagslang);
00237                     $sesskey = sesskey();
00238                     $arrowright = $OUTPUT->pix_url('t/arrow_left');
00239                     $this->content->footer .= <<<EOT
00240                         <hr />
00241                         <form action="{$CFG->wwwroot}/tag/coursetags_add.php" method="post" id="coursetag"
00242                                 onsubmit="return ctags_checkinput(this.coursetag_new_tag.value)">
00243                             <div style="display: none;">
00244                                 <input type="hidden" name="returnurl" value="{$this->page->url}" />
00245                                 <input type="hidden" name="entryid" value="$COURSE->id" />
00246                                 <input type="hidden" name="userid" value="$USER->id" />
00247                                 <input type="hidden" name="sesskey" value="$sesskey" />
00248                             </div>
00249                             <div><label for="coursetag_new_tag">$tagthisunit</label></div>
00250                             <div class="coursetag_form_wrapper">
00251                             <div class="coursetag_form_positioner">
00252                                 <div class="coursetag_form_input1">
00253                                     <input type="text" name="coursetag_sug_keyword" class="coursetag_form_input1a" disabled="disabled" />
00254                                 </div>
00255                                 <div class="coursetag_form_input2">
00256                                     <input type="text" name="coursetag_new_tag" id="coursetag_new_tag" class="coursetag_form_input2a"
00257                                         onfocus="ctags_getKeywords()" onkeyup="ctags_getKeywords()" maxlength="50" />
00258                                 </div>
00259                                 <div class="coursetag_form_input3" id="coursetag_sug_btn">
00260                                     <a title="$arrowtitle">
00261                                         <img src="$arrowright" width="10" height="10" alt="enter" onclick="ctags_setKeywords()" />
00262                                     </a>
00263                                 </div>
00264                             </div>
00265                             <div style="display: inline;">
00266                                 <button type="submit">$buttonadd</button>
00267                             </div>
00268                             </div>
00269                         </form>
00270 EOT;
00271                     // add the edit link
00272                     $this->content->footer .= '
00273                         <div>
00274                         <a href="'.$CFG->wwwroot.'/tag/coursetags_edit.php?courseid='.$this->page->course->id.'"
00275                         title="'.get_string('edittags', $tagslang).'">'.get_string('edittags', $tagslang).'</a>
00276                         </div>';
00277                 }
00278 
00279                 // Navigation elements at the bottom of the block
00280                 // show the alternative displays options if available
00281                 $elementid = 'coursetagslinks_'.$this->instance->id;
00282                 if ($mytags or $officialtags or $commtags or $coursetags) {
00283                     $this->content->footer .= '<div id="'.$elementid.'"></div>';
00284                 }
00285                 // This section sets the order of the links
00286                 $coursetagslinks = array();
00287                 if ($mytags) {
00288                     $coursetagslinks['my'] = array('title'=>get_string('mytags2', $tagslang),
00289                                                     'onclick'=>'f_mytags',
00290                                                     'text'=>get_string('mytags1', $tagslang));
00291                 }
00292                 // because alltags is always present, only show link if there is something else as well
00293                 if ($alltags and ($mytags or $officialtags or $commtags or $coursetags)) {
00294                     $coursetagslinks['all'] = array('title'=>get_string('alltags2', $tagslang),
00295                                                     'onclick'=>'f_alltags',
00296                                                     'text'=>get_string('alltags1', $tagslang));
00297                 }
00298                 if ($officialtags) {
00299                     $coursetagslinks['off'] = array('title'=>get_string('officialtags2', $tagslang),
00300                                                     'onclick'=>'f_officialtags',
00301                                                     'text'=>get_string('officialtags1', $tagslang));
00302                 }
00303                 //if ($commtags) {
00304                 //    $coursetagslinks['com'] = array('title'=>get_string('communitytags2', $tagslang),
00305                 //                                    'onclick'=>'f_commtags',
00306                 //                                    'text'=>get_string('communitytags1', $tagslang));
00307                 //}
00308                 if ($coursetags) {
00309                     $coursetagslinks['crs'] = array('title'=>get_string('coursetags2', $tagslang),
00310                                                     'onclick'=>'f_coursetags',
00311                                                     'text'=>get_string('coursetags1', $tagslang));
00312                 }
00313                 coursetag_get_jscript_links($elementid, $coursetagslinks);
00314 
00315             } else {
00316                 //if not logged in
00317                 $this->content->footer = '<hr />'.get_string('please', $tagslang).'
00318                     <a href="'.get_login_url().'">'.get_string('login', $tagslang).'
00319                         </a> '.get_string('tagunits', $tagslang);
00320             }
00321         }
00322         // end of show course tags section
00323 
00324         return $this->content;
00325     }
00326 }
00327 
 All Data Structures Namespaces Files Functions Variables Enumerations