]> git.mjollnir.org Git - moodle.git/commitdiff
some cleaning, not very clean yet
authortoyomoyo <toyomoyo>
Mon, 13 Mar 2006 06:05:44 +0000 (06:05 +0000)
committertoyomoyo <toyomoyo>
Mon, 13 Mar 2006 06:05:44 +0000 (06:05 +0000)
blog/class.BlogEntry.php
blog/edit.html
blog/edit.php
blog/header.php
blog/index.php
blog/lib.php
blog/preferences.html
blog/preferences.php
blog/set_session_vars.php
blog/tags.html
blog/tags.php

index 0322385ff78fa80c74c0a92b84adb97985b26fed..133a07030287398313ebc080cd5b1bda61aaef63 100755 (executable)
@@ -170,71 +170,6 @@ class BlogEntry {
         }
         return true;
     }
-    
-    /**
-     * get_formatted_karma_link
-     *
-     * @return string If allowed a link to set karma for this entry will be returned
-     * @uses $USER
-     * @uses $CFG
-     */
-    function get_formatted_karma_link() {
-        global $USER, $CFG;
-        $str = '';
-        if (!empty($CFG->blog_ratename)) {
-            $str .= $CFG->blog_ratename .': ';
-        }
-        $str .= $this->entryKarma;
-        if ( !isguest() && blog_isLoggedIn()) {
-            $str .= ' ( <a href="'. $CFG->wwwroot .'/blog/karma.php?op=add&amp;userid='. $this->entryuserid .'&amp;postid='. $this->entryId .'">+</a> / <a href="'. $CFG->wwwroot .'/blog/karma.php?op=sub&amp;userid='. $this->entryuserid .'&amp;postid='. $this->entryId .'">-</a> )';
-        }
-        return $str;
-    }
-
-    /**
-     * get_formatted_category_link
-     *
-     * @return string unordered list of categories this entry is associated with
-     * @uses $CFG
-     */
-    function get_formatted_category_link() {
-        global $CFG;
-        $returnstring = '<span class="post-category">';
-        
-        if (!empty($this->entryCategoryIds)) {
-            $count = count($this->entryCategoryIds);
-            foreach ($this->entryCategoryIds as $categoryid) {
-                $returnstring .= '<a href="'. $CFG->wwwroot .'/blog/index.php?user='. $this->entryuserid .'&amp;categoryid='. $categoryid .'">'. $this->entryCategories[$categoryid] .'</a>';
-                $count--;
-                if ($count != 0) {
-                    $returnstring .= ',&nbsp;';
-                }
-                $returnstring .= "\n";
-            }
-        }
-
-        return $returnstring.'</span>' . "\n";
-    }
-    
-    
-    /**
-     * get_formatted_course_link
-     *
-     * @return string Returns and unordered list of courses that this entry is associated with
-     * @uses $CFG
-     */
-    function get_formatted_course_link() {
-        global $CFG;
-        $returnstring = '<span class="post-course">';
-        $courseid = $this->entryCourseId;
-        if ( !empty($courseid) && !($courseid == 0 || $courseid == '' || ! is_numeric($courseid) )) {
-            if ($course = get_record('course', 'id', $courseid, '', '', '', '', 'fullname')) {
-                $returnstring .= '<a href="'. $CFG->wwwroot .'/course/view.php?id='. $courseid .'">'. $course->fullname .'</a>' . "\n";
-            }
-        }
-    
-        return $returnstring.'</span>' . "\n";
-    }
 
     /**
      * get_formatted_entry_link
@@ -263,7 +198,7 @@ class BlogEntry {
         return $str;
     
     }
-    
+
     /**
      * get_blog_this_URL added by Daryl Hawes for moodle integration
      *
@@ -284,12 +219,12 @@ class BlogEntry {
             } else {
                 $blogThisString = get_string('blogthis', 'blog');
             }
-            if (!$showImage) { 
-                $str .= '('; 
+            if (!$showImage) {
+                $str .= '(';
             }
             $str .= '<a href="'. $this->get_entryblogthisurl() .'">'. $blogThisString .'</a>';
-            if (!$showImage) { 
-                $str .= ')'; 
+            if (!$showImage) {
+                $str .= ')';
             }
         }
         return $str;
@@ -404,7 +339,7 @@ class BlogEntry {
         }
         return stripslashes_safe($this->entryBody);
     }
-    
+
     /**
      * get_unformatted_entry_body
      * getter for ->entryBody
index aaee0c7b67085f7675c7df8b69d74ab61b9e6d63..09f2c347903879cd322154a599dce66ea960fbc0 100755 (executable)
@@ -6,7 +6,7 @@
     }
 
     // find all the tags this post uses
-    if (isset($post->id)) {
+    if (isset($post->postid)) {
         if ($tagsused = get_records('blog_tag_instance', 'entryid', $post->postid)) {
             foreach ($tagsused as $usedtag) {
                 $usedtags[] = $usedtag -> tagid;
 ?>
 
 
-
 <!-- the following form is based on moodle/mod/forum/post.html -->
 
 <form name="entry" method="post" action="<?php echo $CFG->wwwroot;?>/blog/edit.php" id="entry" <?php echo $onsubmit; ?> enctype="multipart/form-data">
-
+<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
 <input type="hidden" name="realcourse" value="0" />
 <input type="hidden" name="realgroup" value="0" />
 
@@ -78,7 +77,6 @@
     </select>
     </td>
 
-
     <td>
     <select name="ptags[]" multiple="multiple" size="8">
     <?php
@@ -95,7 +93,6 @@
     </td>
 </tr>
 
-
 <tr>
     <td>
     <?php
     </small></small>
     </td>
 </tr>
-
-    <?php
-    if ($CFG->blog_enable_trackback_out || $CFG->blog_enable_pingback_out) {
-        print '<tr valign="top">';
-        print '<td align="right"><strong>';
-        print_string('advancedoptions', 'blog');
-        print '</strong></td><td align="left">';
-        
-
-         if ($CFG->blog_enable_pingback_out) {
-             print '<input type="checkbox" name="sendpingbacks" value="1" id="sendpingpacks" /><small><small>';      
-             print_string('sendpingback', 'blog');     
-             helpbutton('pingback', get_string('helppingback', 'blog'), 'blog');
-             print '</small></small><br />';       
-         }
-
-          if ($CFG->blog_enable_trackback_out) {
-              print '<input type="checkbox" name="sendtrackbacks" value="1" id="sendtrackbacks" /><small><small>';  
-              print_string('sendtrackback', 'blog');
-              helpbutton('trackback', get_string('helptrackback', 'blog'), 'blog');
-              print '</small></small><br />';
-          }
-
-        print '</td></tr>';
-    }
-    ?>
 <tr>
     <td align="center" colspan="3">
         <input type="hidden" name="editform" value="1" id="editform" />
index f3e9a268b9d2c4f07229d23820558cc8806688e1..94c4e0c16b5dfe104b5150bce56dc862f7f997b7 100755 (executable)
@@ -16,10 +16,8 @@ if (isguest()) {
     error(get_string('noguestpost', 'forum'), $referrer);
 }
 
-optional_variable($userid, 0);
-optional_variable($editid, '');
-optional_variable($sendpingbacks, 0);
-optional_variable($sendtrackbacks, 0);
+$userid = optional_param('userid', 0);
+$editid = optional_param('editid', '');
 
 global $USER, $CFG;
 
@@ -41,14 +39,6 @@ $pageNavigation = 'edit';
 
 include($CFG->dirroot .'/blog/header.php');
 
-if (!empty($course)) {
-    $courseid = $course->id;
-} else if (!isadmin() && $CFG->blog_enable_moderation) {
-    // the user is not an admin, blog moderation is on and there is no course association
-    //Daryl Hawes note: possible bug here if editing a personal post that existed before blog moderation was enabled for the site.
-    error('Blog moderation is enabled. Your entries must be associated with a course.');
-}
-
 //print_object($PAGE->bloginfo); //debug
 
 //check if user is in blog's acl
@@ -79,9 +69,9 @@ if ($usehtmleditor = can_use_richtext_editor()) {
     $onsubmit = '';
 }
 
-if ($post = data_submitted( get_referer() ) ) {
+if (($post = data_submitted( get_referer() )) && confirm_sesskey()) {
     if (!empty($post->editform)) { //make sure we're processing the edit form here
-        //print_object($post); //debug
+        print_object($post); //debug
 
         ///these varaibles needs to be changed because of the javascript hack
         ///post->courseid
@@ -95,9 +85,9 @@ if ($post = data_submitted( get_referer() ) ) {
             $post->error = get_string('emptymessage', 'forum');
         }
         if ($post->act == 'save') {
-            do_save($post, $PAGE->bloginfo, $sendpingbacks, $sendtrackbacks);
+            do_save($post, $PAGE->bloginfo);
         } else if ($post->act == 'update') {
-            do_update($post, $PAGE->bloginfo, $sendpingbacks, $sendtrackbacks);
+            do_update($post, $PAGE->bloginfo);
         } else if ($post->act == 'del') {
             require_variable($postid);
             do_delete($PAGE->bloginfo, $postid);
@@ -141,7 +131,9 @@ if ($editid != '') {  // User is editing a post
 }
 
 if (isset($post->postid) && ($post->postid != -1) ) {
-    $formHeading = get_string('updateentrywithid', 'blog', $post->postid);
+
+    $formHeading = get_string('updateentrywithid', 'blog');
+
 } else {
     $formHeading = get_string('addnewentry', 'blog');
 }
@@ -202,7 +194,7 @@ function do_delete(&$bloginfo_arg, $postid) {
 * @param object $post argument is a reference to the post object which is used to store information for the form
 * @param object $bloginfo_arg argument is reference to a blogInfo object.
 */
-function do_save(&$post, &$bloginfo_arg, $sendpingbacks, $sendtrackbacks) {
+function do_save(&$post, &$bloginfo_arg) {
     global $USER, $CFG;
 //    echo 'Debug: Post object in do_save function of edit.php<br />'; //debug
 //    print_object($post); //debug
@@ -265,7 +257,7 @@ function do_save(&$post, &$bloginfo_arg, $sendpingbacks, $sendtrackbacks) {
             add_to_log($site->id, 'blog', 'add', 'archive.php?userid='. $bloginfo_arg->userid .'&postid='. $entryID, 'created new blog entry with entry id# '. $entryID);
         }
         //to debug this save function comment out the following redirect code
-        if ($courseid == 1 || $courseid == 0 || $courseid == '') {
+        if ($courseid == SITEID || $courseid == 0 || $courseid == '') {
             redirect($CFG->wwwroot .'/blog/index.php?userid='. $bloginfo_arg->userid);
         } else {
             redirect($CFG->wwwroot .'/course/view.php?id='. $courseid);
@@ -278,7 +270,7 @@ function do_save(&$post, &$bloginfo_arg, $sendpingbacks, $sendtrackbacks) {
  * @param . $bloginfo_arg argument is reference to a blogInfo object.
  * @todo complete documenting this function. enable trackback and pingback between entries on the same server
  */
-function do_update(&$post, &$bloginfo, $sendpingbacks, $sendtrackbacks) {
+function do_update(&$post, &$bloginfo) {
 
     global $CFG, $USER;
     
index ffadacc182f6e2aaa9d816172b5fe020b8f72e9d..6afb2492d40f0ece92897166c1f6b859eb65b51b 100755 (executable)
@@ -8,26 +8,22 @@ require_once($CFG->dirroot .'/blog/blogpage.php');
 require_once($CFG->libdir .'/blocklib.php');
 require_once($CFG->dirroot .'/course/lib.php');
 
-optional_param('blockaction');
-optional_param('instanceid', 0, PARAM_INT);
-optional_param('blockid',    0, PARAM_INT);
-optional_param('groupid',    0, PARAM_INT);
-optional_param('userid',     0, PARAM_INT);
-
-optional_variable($categoryid, '');
-optional_variable($groupid, '');
-optional_variable($pageTitle, '');
-optional_variable($pageHeading, ''/*$site->fullname*/);
-optional_variable($pageFocus, '');
-optional_variable($pageMeta, '');
-optional_variable($pageNavigation, '');
+$blockaction = optional_param('blockaction');
+$instanceid = optional_param('instanceid', 0, PARAM_INT);
+$blockid = optional_param('blockid',    0, PARAM_INT);
+$groupid = optional_param('groupid',    0, PARAM_INT);
+$userid = optional_param('userid',     0, PARAM_INT);
+
+$pageTitle = optional_param('pageTitle');
+$pageHeading = optional_param('pageHeading'/*$site->fullname*/);
+$pageFocus = optional_param('pageFocus');
+$pageMeta = optional_param('pageMeta');
+$pageNavigation = optional_param('pageNavigation');
 
 if (!isset($courseid)) {
     $courseid = optional_param('courseid', SITEID, PARAM_INT);
 }
 
-//header('X-Pingback: '. $CFG->wwwroot .'/blog/api.php'."\n");
-
 if (!$site = get_site()) {
     redirect($CFG->wwwroot.'/index.php');
 }
@@ -44,14 +40,6 @@ if ($courseid != SITEID) {
     require_login($course->id);
 }
 
-// ensure that if a group is specified that the user is in fact a member of that group
-/*
-if ($groupid) {
-    if (!ismember($groupid) && !isteacher($course->id)) {
-        error('You are not a member of the specified group. Group with id#('. $groupid .')');
-    }
-}*/
-
 // Bounds for block widths within this page
 define('BLOCK_L_MIN_WIDTH', 160);
 define('BLOCK_L_MAX_WIDTH', 210);
@@ -86,6 +74,11 @@ if (!isset($filtertype)) {
     $filterselect = $USER->id;
 }
 
+/// navigations
+/// site blogs - sitefullname -> blogs -> (?tag)
+/// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
+/// group blogs - sitefullname -> course fullname ->group ->(?tag)
+/// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
 $blogstring = get_string('blogs','blog');
 $tagstring = get_string('tag','blog');
 
@@ -178,20 +171,14 @@ switch ($filtertype) {
     break;
 }
 
-
-/// site blogs - sitefullname -> blogs -> (?tag)
-/// course blogs - sitefullname -> course fullname ->blogs ->(?tag)
-/// group blogs - sitefullname -> course fullname ->group ->(?tag)
-/// user blogs - sitefullname -> (?coursefullname) -> participants -> blogs -> (?tag)
-
 $editing = false;
 if ($PAGE->user_allowed_editing()) {
     $editing = $PAGE->user_is_editing();
 }
 
 // Calculate the preferred width for left, right and center (both center positions will use the same)
-optional_variable($preferred_width_left,  blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]));
-optional_variable($preferred_width_right, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]));
+$preferred_width_left = optional_param('preferred_width_left',  blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]));
+$preferred_width_right = optional_param('preferred_width_right', blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]));
 $preferred_width_left = min($preferred_width_left, BLOCK_L_MAX_WIDTH);
 $preferred_width_left = max($preferred_width_left, BLOCK_L_MIN_WIDTH);
 $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH);
index e3460546f0a7b360abb200c4ab2edc53b138739e..750c8a83fec9def3d5eaf0a24f995b24f6b8edd4 100755 (executable)
@@ -17,20 +17,21 @@ require_once($CFG->libdir .'/blocklib.php');
 
 $id = optional_param('id');
 $limit = optional_param('limit');
-optional_variable($formstart, 'none');
-optional_variable($m, ''); //month
-optional_variable($y, ''); //year
-optional_variable($d, ''); //day
-optional_variable($limit, 'none');
-optional_variable($formstart, 'none');
+$formstart = optional_param('formstart', 'none');
+$m = optional_param('m', ''); //month
+$y = optional_param('y', ''); //year
+$d = optional_param('d', ''); //day
+$limit = optional_param('limit', 'none');
+$formstart = optional_param('formstart', 'none');
 
 $userid = optional_param('userid',0,PARAM_INT);
 $groupid = optional_param('groupid',0,PARAM_INT);
 $courseid = optional_param('courseid',0,PARAM_INT);
 $tag = optional_param('tag');
 $tagid = optional_param('tagid');
-$filtertype = optional_param('filtertype','',PARAM_ALPHA);
-$filterselect = optional_param('filterselect','',PARAM_NOTAGS);
+
+$filtertype = optional_param('filtertype', '', PARAM_ALPHA);
+$filterselect = optional_param('filterselect', 0, PARAM_INT);
 
 /// overwrite filter code here
 /// the the following code does the rights checkings?
@@ -95,14 +96,14 @@ if ($filtertype) {
 
 switch ($filtertype) {
     case 'site':
-        if ($CFG->bloglevel < 4) {
+        if ($CFG->bloglevel < BLOG_SITE_LEVEL) {
             error ('site blogs is not enabled');
-        } else if ($CFG->bloglevel < 5) {
+        } else if ($CFG->bloglevel < BLOG_GLOBAL_LEVEL) {
             require_login();
         }
     break;
     case 'course':
-        if ($CFG->bloglevel < 3) {
+        if ($CFG->bloglevel < BLOG_COURSE_LEVEL) {
             error ('course blogs is not enabled');
         }
 
@@ -112,7 +113,7 @@ switch ($filtertype) {
         /// check if viewer is student
     break;
     case 'group':
-        if ($CFG->bloglevel < 2) {
+        if ($CFG->bloglevel < BLOG_GROUP_LEVEL) {
             error ('group blogs is not enabled');
         }
         if (!isteacheredit($course) and (groupmode($course) == SEPARATEGROUPS)) {
@@ -123,7 +124,7 @@ switch ($filtertype) {
         /// check if user is editting teacher, or if spg, is member
     break;
     case 'user':
-        if ($CFG->bloglevel < 1) {
+        if ($CFG->bloglevel < BLOG_USER_LEVEL) {
             error ('Blogs is not enabled');
         }
         $canview = 0;    //bad start
@@ -146,7 +147,7 @@ switch ($filtertype) {
                 }
             }
         }
-        if (!$canview && $CFG->bloglevel < 4) {
+        if (!$canview && $CFG->bloglevel < BLOG_SITE_LEVEL) {
             error ('you can not view this user\'s blogs');
         }
         /// check to see if the viewer is sharing no_group, visible group course.
index 73fce314dce86a7a9d144797b0a2f375528ada03..06ba4be105c2276b7a019715db3546e82c9b23ea 100755 (executable)
@@ -10,6 +10,13 @@ require_once($CFG->libdir .'/blocklib.php');
 require_once($CFG->libdir .'/pagelib.php');
 require_once($CFG->dirroot .'/blog/blogpage.php');
 
+/* blog access level constant declaration */
+define ('BLOG_USER_LEVEL', 1);
+define ('BLOG_GROUP_LEVEL', 2);
+define ('BLOG_COURSE_LEVEL', 3);
+define ('BLOG_SITE_LEVEL', 4);
+define ('BLOG_GLOBAL_LEVEL', 5);
+
 /**
  * Definition of blogcourse page type (blog page with course id present).
  */
@@ -649,7 +656,7 @@ function blog_print_html_formatted_entries(&$blogFilter, $filtertype, $filtersel
 
             if (blog_isLoggedIn()) {
                 $morelink = '<br />&nbsp;&nbsp;';
-                $morelink .= $blogFilter->get_complete_link('<a href="'. $CFG->wwwroot .'/blog/edit.php', get_string('addentries', 'blog'))."\n";
+                $morelink .= $blogFilter->get_complete_link('<a href="'. $CFG->wwwroot .'/blog/edit.php', get_string('addnewentry', 'blog'))."\n";
                 
             }
         }
@@ -663,7 +670,7 @@ function blog_print_html_formatted_entries(&$blogFilter, $filtertype, $filtersel
         //yu: testing code
         if (blog_isLoggedIn()) {
         //the user's blog is enabled and they are viewing their own blog
-            $morelink .= $blogFilter->get_complete_link($CFG->wwwroot .'/blog/edit.php', get_string('addentries', 'blog'));
+            $morelink .= $blogFilter->get_complete_link($CFG->wwwroot .'/blog/edit.php', get_string('addnewentry', 'blog'));
         }
 
         print $morelink.'<br />'."\n";
@@ -683,7 +690,7 @@ function blog_print_html_formatted_entries(&$blogFilter, $filtertype, $filtersel
     
     if (blog_isLoggedIn()) {
         //the user's blog is enabled and they are viewing their own blog
-        $output .= $blogFilter->get_complete_link($CFG->wwwroot .'/blog/edit.php', get_string('addentries', 'blog'));
+        $output .= $blogFilter->get_complete_link($CFG->wwwroot .'/blog/edit.php', get_string('addnewentry', 'blog'));
     }
     print $output;
     unset($blogFilter->filtered_entries);
index 68d8369af3c07f8975cb633ed9b27c332b4bf12c..7904d7036f296e2f8879877da03a1b367a74b08b 100755 (executable)
@@ -6,15 +6,6 @@
 <form method="post" action="preferences.php" name="entry" id="entry">
 
 <table cellpadding="9" cellspacing="0">
-<tr valign="top">
-    <td><?php print_string('title', 'blog');?>:</td>
-    <td><input type="text" size="20" maxlength="32" name="blogtitle" value="<?php echo $bloginfo->get_blog_title();?>" /></td>
-</tr>
-<tr>
-    <td><?php print_string('tagline', 'blog');?>:</td>
-    <td><input type="text" size="32" maxlength="128" name="blogtagline" value="<?php echo $bloginfo->get_blog_tagline();?>" /></td>
-</tr>
-
 <tr>
     <td><?php print_string('pagesize', 'blog');?>:</td>
     <td><input type="text" size="32" maxlength="128" name="pagesize" value="<?php echo get_user_preferences('blogpagesize',8);?>" />
 <?php } ?>
 <tr>
     <td colspan="2" align="center">
-
-    <input type="hidden" name="format" value="1" />
-    <input type="hidden" name="etitle" value="This is a preview of this template" />
-    <input type="hidden" name="body" value="Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure d" />
-
        <input type="submit" value="<?php print_string("savechanges") ?>" /></td>
 </tr>
 </table>
index ac72d491052a0437e821343e464ea2ab74bf2885..72012a6305c9215f35dc5a48c31adbf15ef62127 100755 (executable)
 
     //ensure that the logged in user is not using the guest account
     if (isguest()) {
-        error(get_string('noguestpost', 'forum'), $referrer);
+        error(get_string('noguestpost', 'blog'), $referrer);
     }
     
     if (!blog_isLoggedIn() ) {
-        error(get_string('noguestpost', 'forum'), $referrer);
+        error(get_string('noguestpost', 'blog'), $referrer);
     }
     $userid = $USER->id;
     $bloginfo =& new BlogInfo($userid);
 
        if ($post = data_submitted()) {
         print_header();
-        if (!isset($post->blogtitle) || !isset($post->blogtagline) ) {
-            error(get_string('settingsupdatederror', 'blog'), $referrer);
-        }
 
-        if (! $bloginfo->set_blog_title($post->blogtitle)) {
-            error(get_string('settingsupdatederror', 'blog'), $referrer );
-        }
-
-        if (! $bloginfo->set_blog_tagline($post->blogtagline)) {
-            error(get_string('settingsupdatederror', 'blog'), $referrer );
-        }
-    
-        if (isset($post->theme)) {
-            if (! $bloginfo->set_blog_theme($post->theme)) {
-                error(get_string('settingsupdatederror', 'blog'), $referrer );
-            }
-        }
-        
         set_user_preference('blogpagesize', optional_param('pagesize'));
         
         redirect($referrer, get_string('changessaved'), 1);
@@ -56,7 +39,7 @@
     $site = get_site();
     $pageMeta = '<script language="javascript" type="text/javascript" src="'. $CFG->wwwroot .'/blog/blog.js"></script>' . "\n";
 
-    $strpreferences = get_string('preferences', 'calendar');
+    $strpreferences = get_string('preferences','blog');
 
     $navigation = '<a href="'. $bloginfo->get_blog_url() .'">'. $bloginfo->get_blog_title() . '</a> -> '. $strpreferences;
 
index f0315a8b9c6b610284778450c36ec768492cfc81..8af24efecd6de0931e1ef4ff5e6491c3031363c3 100644 (file)
@@ -4,19 +4,19 @@
     require_once('../config.php');
     require_once('lib.php');
 
-    require_variable($_GET['referrer']);
-    require_variable($_GET['var']);
-    optional_variable($_GET['value']);
-    optional_variable($_GET['userid']);
-    optional_variable($_GET['courseid']);
-    optional_variable($_GET['categoryid']);
-    optional_variable($_GET['d']);
-    optional_variable($_GET['m']);
-    optional_variable($_GET['y']);
+    $referrer = required_param('referrer');
+    $var = required_param('var');
+    $value = optional_param('value');
+    $userid = optional_param('userid');
+    $courseid = optional_param('courseid');
+    $d = optional_param('d');
+    $m = optional_param('m');
+    $y = optional_param('y');
+    $id = optional_param('id');
 
-    switch($_GET['var']) {
+    switch($var) {
         case 'setcourse':
-            $id = intval($_GET['id']);
+            $id = intval($id);
             if($id == 0) {
                 $SESSION->cal_courses_shown = array();
                 calendar_set_referring_course(0);
@@ -47,4 +47,4 @@
         break;
     }
     redirect($referrer);
-?>
\ No newline at end of file
+?>
index 62ffb064b15343e670004ee4c3d7611ba1f54b93..78ae29c8f9c7ea47d151bf2df43e4e456ad7de29 100755 (executable)
@@ -1,16 +1,17 @@
 <?php
-print_heading(get_string('tagsmanagement','blog'));
+print_heading(get_string('tagmanagement','blog'));
 ?>
 
 <table>
     <tr>
-        <td width="50%">Official Tags</td>
-        <td width="50%">User Defined Tags</td>
+        <td width="50%"><?php print_string('otags','blog');?></td>
+        <td width="50%"><?php print_string('ptags','blog');?></td>
     </tr>
     
     <tr>
         <td>
             <form action="tags.php" method="POST">
+            <input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
             <?php if (isadmin()){ ?>
             <select name="tags[]" multiple="multiple" size="8">
             <?php
@@ -22,7 +23,7 @@ print_heading(get_string('tagsmanagement','blog'));
             </select>
             <input type="hidden" name="mode" value="delete" />
             <br />
-            <input type="submit" value="delete" />
+            <input type="submit" value="<?php print_string('delete');?>" />
             <?php }
                 else {
                     $otags = get_records_sql('SELECT * from '.$CFG->prefix.'tags WHERE type=\'official\' ORDER by text ASC');
@@ -36,6 +37,7 @@ print_heading(get_string('tagsmanagement','blog'));
         
         <td>
             <form action="tags.php" method="POST">
+            <input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
             <select name="tags[]" multiple="multiple" size="8">
             <?php
                 $ptags1 = get_records_sql('SELECT * from '.$CFG->prefix.'tags WHERE type=\'personal\' AND userid = '.$USER->id.' ORDER by text ASC');
@@ -48,7 +50,7 @@ print_heading(get_string('tagsmanagement','blog'));
             </select>
             <input type="hidden" name="mode" value="delete" />
             <br />
-            <input type="submit" value="delete" />
+            <input type="submit" value="<?php print_string('delete');?>" />
             </form>
         </td>
     </tr>
@@ -57,9 +59,10 @@ print_heading(get_string('tagsmanagement','blog'));
         <td>
             <?php if (isadmin()) { ?>
             <form action="tags.php" method="POST">
-            Add Official:<br/>
+            <input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
+            <?php print_string('addotags','blog');?>:<br/>
             <input type="text" name="otag" />
-            <input type="submit" value="add" />
+            <input type="submit" value="<?php print_string('add');?>" />
             <input type="hidden" name="mode" value="addofficial" />
             </form>
             <?php }?>
@@ -67,9 +70,10 @@ print_heading(get_string('tagsmanagement','blog'));
         
         <td>
             <form action="tags.php" method="POST">
-            Add Personal:<br/>
+            <input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
+            <?php print_string('addptags','blog');?><br/>
             <input type="text" name="ptag" />
-            <input type="submit" value="add" />
+            <input type="submit" value="<?php print_string('add');?>" />
             <input type="hidden" name="mode" value="addpersonal" />
             </form>
         </td>
@@ -78,5 +82,5 @@ print_heading(get_string('tagsmanagement','blog'));
 </table>
 
 <p align="center">
-    <a href="#" onclick="window.close()">close this window</a>
+    <a href="#" onclick="window.close()"><?php print_string('closewindow');?></a>
 </p>
index e539b9a49e0918d81ba6fb507b454a8d25edc685..8be4d8f459be70f32807bcfe7ed23a16828f93b0 100755 (executable)
@@ -7,6 +7,11 @@ $mode = optional_param('mode','',PARAM_ALPHA);
 
 switch ($mode) {
     case 'addofficial':
+    
+        if (!isadmin() || !confirm_sesskey()) {
+            die('you can not add official tags');
+        }
+        
         if (($otag = optional_param('otag')) && (!get_record('tags','text',$otag))) {
             $tag->userid = $USER->id;
             $tag->text = $otag;
@@ -24,7 +29,11 @@ switch ($mode) {
 
     break;
     
-    case 'addpersonal':
+    case 'addpersonal':    /// everyone can add
+        if (!confirm_sesskey() || isguest() || !isset($USER->id)) {
+            error ('you can not add tags');
+        }
+        
         if (($ptag = optional_param('ptag')) && (!get_record('tags','text',$ptag))) {
             $tag->userid = $USER->id;
             $tag->text = $ptag;
@@ -43,6 +52,10 @@ switch ($mode) {
     break;
     
     case 'delete':
+        if (!confirm_sesskey()) {
+            error('you can not delete tags');
+        }
+        
         $tags = optional_param('tags');
         print_object($tags);
         foreach ($tags as $tag) {
@@ -54,6 +67,7 @@ switch ($mode) {
                 continue;
             }
             
+            /// Only admin can delete tags that are referenced
             if (!isadmin() && get_records('blog_tag_instance','tagid', $tag)) {
                 notify('tag is used by other users, can not delete!');
                 continue;
@@ -62,7 +76,7 @@ switch ($mode) {
             delete_records('tags','id',$tag);
             delete_records('blog_tag_instance', 'tagid', $tag);
 
-            //remove parent window option
+            /// remove parent window option via javascript
             echo '<script>
             var i=0;
             while (i < window.opener.document.entry[\'otags[]\'].length) {