📄 blog.lib.php
字号:
<?php/**=============================================================================== Dokeos - elearning and course management software Copyright (c) 2004-2008 Dokeos SPRL Copyright (c) Keppens Toon For a full list of contributors, see "credits.txt". The full license can be read in "license.txt". This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the GNU General Public License for more details. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium Mail: info@dokeos.com=============================================================================== Functions in this API file:===============================================================================*//** * Blog class * Contains several functions dealing with displaying, * editing,... of a blog * * @version 1.0 * @package dokeos.blogs * @author Toon Keppens <toon@vi-host.net> * */class Blog{ /** * Get the title of a blog * @author Toon Keppens * * @param Integer $blog_id * * @return String Blog Title */ function get_blog_title($blog_id) { if(is_numeric($blog_id)) { // init $tbl_blogs = Database::get_course_table(TABLE_BLOGS); $sql = " SELECT `blog_name` FROM " . $tbl_blogs . " WHERE `blog_id` = " . mysql_real_escape_string((int)$blog_id); $result = api_sql_query($sql, __FILE__, __LINE__); $blog = mysql_fetch_array($result); return stripslashes($blog['blog_name']); } } /** * Get the description of a blog * @author Toon Keppens * * @param Integer $blog_id * * @return String Blog description */ function get_blog_subtitle($blog_id) { // init $tbl_blogs = Database::get_course_table(TABLE_BLOGS); $sql = "SELECT blog_subtitle FROM $tbl_blogs WHERE blog_id ='".mysql_real_escape_string((int)$blog_id)."'"; $result = api_sql_query($sql, __FILE__, __LINE__); $blog = mysql_fetch_array($result); return stripslashes($blog['blog_subtitle']); } /** * Get the users of a blog * @author Toon Keppens * * @param Integer $blog_id * * @return Array Returns an array with [userid]=>[username] */ function get_blog_users($blog_id) { // Database table definitions $tbl_users = Database::get_main_table(TABLE_MAIN_USER); $tbl_blogs = Database::get_course_table(TABLE_BLOGS); $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); // Get blog members $sql = " SELECT user.user_id, user.firstname, user.lastname FROM " . $tbl_blogs_rel_user . " blogs_rel_user INNER JOIN " . $tbl_users . " user ON blogs_rel_user.user_id = user.user_id WHERE blogs_rel_user.blog_id = '" . mysql_real_escape_string((int)$blog_id)."'"; $result = api_sql_query($sql, __FILE__, __LINE__); $blog_members = array (); while($user = mysql_fetch_array($result)) { $blog_members[$user['user_id']] = $user['lastname']." " . $user['firstname']; } return $blog_members; } /** * Creates a new blog in the given course * @author Toon Keppens * * @param Integer $course_id Id * @param String $title * @param Text $description * * @return void */ function create_blog($title, $subtitle) { global $_user; // Tabel definitions $tbl_blogs = Database::get_course_table(TABLE_BLOGS); $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); // Create the blog $sql = "INSERT INTO $tbl_blogs (`blog_name`, `blog_subtitle`, `date_creation`, `visibility` ) VALUES ('".mysql_real_escape_string($title)."', '".mysql_real_escape_string($subtitle)."', NOW(), '1');"; api_sql_query($sql, __FILE__, __LINE__); $this_blog_id = Database::get_last_insert_id(); // Make first post. :) $sql = "INSERT INTO $tbl_blogs_posts (`title`, `full_text`, `date_creation`, `blog_id`, `author_id` ) VALUES ('".get_lang("Welcome")."', '" . get_lang('FirstPostText')."', NOW(), '".mysql_real_escape_string((int)$this_blog_id)."', '".mysql_real_escape_string((int)$_user['user_id'])."');"; api_sql_query($sql, __FILE__, __LINE__); // Put it on course homepage $sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('".mysql_real_escape_string($title)."','blog/blog.php?blog_id=".(int)$this_blog_id."','blog.gif','1','0','pastillegris.gif',0)"; api_sql_query($sql, __FILE__, __LINE__); // Subscribe the teacher to this blog Blog::set_user_subscribed((int)$this_blog_id,(int)$_user['user_id']); return void; } /** * Update title and subtitle of a blog in the given course * @author Toon Keppens * * @param Integer $course_id Id * @param String $title * @param Text $description * * @return void */ function edit_blog($blog_id, $title, $subtitle) { global $_user; // Table definitions $tbl_blogs = Database::get_course_table(TABLE_BLOGS); $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); // Update the blog $sql = "UPDATE $tbl_blogs SET blog_name = '".mysql_real_escape_string($title)."', blog_subtitle = '".mysql_real_escape_string($subtitle)."' WHERE blog_id ='".mysql_real_escape_string((int)$blog_id)."' LIMIT 1"; api_sql_query($sql, __FILE__, __LINE__); $this_blog_id = Database::get_last_insert_id(); // Update course homepage link $sql = "UPDATE $tbl_tool SET name = '".mysql_real_escape_string($title)."' WHERE link = 'blog/blog.php?blog_id=".mysql_real_escape_string((int)$blog_id)."' LIMIT 1"; api_sql_query($sql, __FILE__, __LINE__); return void; } /** * Deletes a blog and it's posts from the course database * @author Toon Keppens * * @param Integer $blog_id * * @return void */ function delete_blog($blog_id) { // Init $tbl_blogs = Database::get_course_table(TABLE_BLOGS); $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); $tbl_blogs_comment = Database::get_course_table(TABLE_BLOGS_COMMENTS); $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS); $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); $tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING); $tbl_blogs_attachment = Database::get_course_table(TABLE_BLOGS_ATTACHMENT); // Delete posts from DB and the attachments delete_all_blog_attachment($blog_id); //Delete comments $sql = "DELETE FROM $tbl_blogs_comment WHERE blog_id ='".(int)$blog_id."'"; api_sql_query($sql, __FILE__, __LINE__); // Delete posts $sql = "DELETE FROM $tbl_blogs_posts WHERE blog_id ='".(int)$blog_id."'"; api_sql_query($sql, __FILE__, __LINE__); // Delete tasks $sql = "DELETE FROM $tbl_blogs_tasks WHERE blog_id ='".(int)$blog_id."'"; api_sql_query($sql, __FILE__, __LINE__); // Delete ratings $sql = "DELETE FROM $tbl_blogs_rating WHERE blog_id ='".(int)$blog_id."'"; api_sql_query($sql, __FILE__, __LINE__); // Delete blog $sql ="DELETE FROM $tbl_blogs WHERE blog_id ='".(int)$blog_id."'"; api_sql_query($sql, __FILE__, __LINE__); // Delete from course homepage $sql = "DELETE FROM $tbl_tool WHERE link = 'blog/blog.php?blog_id=".(int)$blog_id."'"; api_sql_query($sql, __FILE__, __LINE__); return void; } /** * Creates a new post in a given blog * @author Toon Keppens * * @param String $title * @param String $full_text * @param Integer $blog_id * * @return void */ function create_post($title, $full_text, $file_comment, $blog_id) { global $_user; global $_course; global $blog_table_attachment; $upload_ok=true; $has_attachment=false; if(!empty($_FILES['user_upload']['name'])) { require_once('fileUpload.lib.php'); $upload_ok = process_uploaded_file($_FILES['user_upload']); $has_attachment=true; } if($upload_ok) { // Table Definitions $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS); // Create the post $sql = "INSERT INTO " . $tbl_blogs_posts." (`title`, `full_text`, `date_creation`, `blog_id`, `author_id` ) VALUES ('".Database::escape_string($title)."', '".Database::escape_string($full_text)."', NOW(), '".(int)$blog_id."', '".(int)$_user['user_id']."');"; api_sql_query($sql, __FILE__, __LINE__); $last_post_id=Database::insert_id(); if ($has_attachment) { $courseDir = $_course['path'].'/upload/blog'; $sys_course_path = api_get_path(SYS_COURSE_PATH); $updir = $sys_course_path.$courseDir; // Try to add an extension to the file if it hasn't one $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']); // user's file name $file_name =$_FILES['user_upload']['name']; if (!filter_extension($new_file_name)) { Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension')); } else { $new_file_name = uniqid(''); $new_path=$updir.'/'.$new_file_name; $result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path); $comment=Database::escape_string($file_comment); // Storing the attachments if any if ($result) { $sql='INSERT INTO '.$blog_table_attachment.'(filename,comment, path, post_id,size, blog_id,comment_id) '. "VALUES ( '".Database::escape_string($file_name)."', '".Database::escape_string($comment)."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".$_FILES['user_upload']['size']."', '".$blog_id."', '0' )"; $result=api_sql_query($sql, __LINE__, __FILE__); $message.=' / '.get_lang('AttachmentUpload'); } } } } else { Display::display_error_message(get_lang('UplNoFileUploaded')); } return void; } /** * Edits a post in a given blog * @author Toon Keppens * * @param Integer $blog_id * @param String $title * @param String $full_text * @param Integer $blog_id * * @return void */ function edit_post($post_id, $title, $full_text, $blog_id) { // Init $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -