⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blog.lib.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:
		{			Blog::display_new_comment_form($blog_id, $post_id, $blog_post['title']);		}	}	/**	 * Adds rating to a certain post or comment	 * @author Toon Keppens	 *	 * @param String $type	 * @param Integer $blog_id	 * @param Integer $item_id	 * @param Integer $rating	 *	 * @return Boolean success	 */	function add_rating($type, $blog_id, $item_id, $rating)	{		global $_user;		// Init		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);		// Check if the user has already rated this post/comment		$sql = "SELECT rating_id FROM $tbl_blogs_rating					WHERE blog_id = '".(int)$blog_id."'					AND item_id = '".(int)$item_id."'					AND rating_type = '".mysql_real_escape_string($type)."'					AND user_id = '".(int)$_user['user_id']."'";		$result = api_sql_query($sql, __FILE__, __LINE__);		if(mysql_num_rows($result) == 0) // Add rating		{			$sql = "INSERT INTO $tbl_blogs_rating ( `blog_id`, `rating_type`, `item_id`, `user_id`, `rating` )						VALUES ('".(int)$blog_id."', '".mysql_real_escape_string($type)."', '".(int)$item_id."', '".(int)$_user['user_id']."', '".mysql_real_escape_string($rating)."')";			$result = api_sql_query($sql, __FILE__, __LINE__);			return true;		}		else // Return		{			return false;		}	}	function display_rating($type, $blog_id, $item_id)	{		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);		// Calculate rating		$sql = "SELECT AVG(rating) as rating FROM $tbl_blogs_rating WHERE blog_id = '".(int)$blog_id."' AND item_id = '".(int)$item_id."' AND rating_type = '".mysql_real_escape_string($type)."' ";		$result = api_sql_query($sql, __FILE__, __LINE__);		$result = mysql_fetch_array($result);		return round($result['rating'], 2);	}	/**	 * Shows the rating form if not already rated by that user	 * @author Toon Keppens	 *	 * @param String $type	 * @param Integer $blog_id	 * @param Integer $item_id	 *	 */	function display_rating_form($type, $blog_id, $post_id, $comment_id = NULL)	{		global $_user;		// Init		$tbl_blogs_rating = Database::get_course_table(TABLE_BLOGS_RATING);		if($type == 'post')		{			// Check if the user has already rated this post			$sql = "SELECT rating_id FROM $tbl_blogs_rating					WHERE blog_id = '".(int)$blog_id."'					AND item_id = '".(int)$post_id."'					AND rating_type = '".mysql_real_escape_string($type)."'					AND user_id = '".(int)$_user['user_id']."'";			$result = api_sql_query($sql, __FILE__, __LINE__);			if(mysql_num_rows($result) == 0) // Add rating			{				return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $post_id . '" name="frm_rating_' . $type . '_' . $post_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $post_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /></form>';			}			else // Return			{				return '';			}		}		if($type = 'comment')		{			// Check if the user has already rated this comment			$sql = "SELECT rating_id FROM $tbl_blogs_rating					WHERE blog_id = '".(int)$blog_id ."'					AND item_id = '".(int)$comment_id."'					AND rating_type = '".mysql_real_escape_string($type)."'					AND user_id = '".(int)$_user['user_id']."'";			$result = api_sql_query($sql, __FILE__, __LINE__);			if(mysql_num_rows($result) == 0) // Add rating			{				return ' - ' . get_lang('RateThis') . ': <form method="get" action="blog.php" style="display: inline" id="frm_rating_' . $type . '_' . $comment_id . '" name="frm_rating_' . $type . '_' . $comment_id . '"><select name="rating" onchange="document.forms[\'frm_rating_' . $type . '_' . $comment_id . '\'].submit()"><option value="">-</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select><input type="hidden" name="action" value="view_post" /><input type="hidden" name="type" value="' . $type . '" /><input type="hidden" name="do" value="rate" /><input type="hidden" name="blog_id" value="' . $blog_id . '" /><input type="hidden" name="post_id" value="' . $post_id . '" /><input type="hidden" name="comment_id" value="' . $comment_id . '" /></form>';			}			else // Return			{				return '';			}		}	}	/**	 * This functions gets all replys to a post, threaded.	 *	 * @param Integer $current	 * @param Integer $current_level	 * @param Integer $blog_id	 * @param Integer $post_id	 */	function get_threaded_comments($current = 0, $current_level = 0, $blog_id, $post_id, $task_id = 0)	{		// Init		$tbl_blogs_comments = Database::get_course_table(TABLE_BLOGS_COMMENTS);		$tbl_users = Database::get_main_table(TABLE_MAIN_USER);		$tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);		global $charset,$dateFormatLong;		// Select top level comments		$next_level = $current_level + 1;		$sql = "SELECT comments.*, user.lastname, user.firstname, task.color					FROM $tbl_blogs_comments comments						INNER JOIN $tbl_users user ON comments.author_id = user.user_id						LEFT JOIN $tbl_blogs_tasks task ON comments.task_id = task.task_id					WHERE parent_comment_id = $current						AND comments.blog_id = '".(int)$blog_id."'						AND comments.post_id = '".(int)$post_id."'";		$result = api_sql_query($sql, __FILE__, __LINE__);		while($comment = mysql_fetch_array($result))		{			// Select the children recursivly			$tmp = "SELECT comments.*, user.lastname, user.firstname FROM $tbl_blogs_comments comments					INNER JOIN $tbl_users user ON comments.author_id = user.user_id					WHERE comment_id = $current					AND blog_id = '".(int)$blog_id."'					AND post_id = '".(int)$post_id."'";			$tmp = api_sql_query($tmp, __FILE__, __LINE__);			$tmp = mysql_fetch_array($tmp);			$parent_cat = $tmp['parent_comment_id'];			$border_color = '';			// Prepare data			$comment_text = make_clickable(stripslashes($comment['comment']));			$blog_comment_date = ucfirst(format_locale_date($dateFormatLong,strtotime($comment['date_creation'])));			$blog_comment_time = date('H:i',strtotime($comment['date_creation']));			$blog_comment_actions = "";			if(api_is_allowed('BLOG_' . $blog_id, 'article_comments_delete', $task_id)) { $blog_comment_actions .= '<a href="blog.php?action=view_post&amp;blog_id=' . $blog_id . '&amp;post_id=' . $post_id . '&amp;do=delete_comment&amp;comment_id=' . $comment['comment_id'] . '&amp;task_id=' . $task_id . '" title="' . get_lang('DeleteThisComment') . '" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)). '\')) return false;"><img src="../img/delete.gif" border="0" /></a>'; }			if(api_is_allowed('BLOG_' . $blog_id, 'article_comments_rate')) { $rating_select = Blog::display_rating_form('comment', $blog_id, $post_id, $comment['comment_id']); }			if(!is_null($comment['task_id']))			{				$border_color = ' border-left: 3px solid #' . $comment['color'];			}						$comment_text=stripslashes($comment_text);			// Output...			$margin = $current_level * 30;			echo '<div class="blogpost_comment" style="margin-left: ' . $margin . 'px;' . $border_color . '">';				echo '<span class="blogpost_comment_title"><a href="#add_comment" onclick="document.getElementById(\'comment_parent_id\').value=\'' . $comment['comment_id'] . '\'; document.getElementById(\'comment_title\').value=\'Re: '.addslashes($comment['title']) . '\'" title="' . get_lang('ReplyToThisComment') . '" >'.stripslashes($comment['title']) . '</a></span>';				echo '<span class="blogpost_comment_date">' . $blog_comment_date . ' (' . $blog_comment_time . ')</span>';				echo '<span class="blogpost_text">' . $comment_text . '</span>';								$file_name_array=get_blog_attachment($blog_id,$post_id, $comment['comment_id']);				if (!empty($file_name_array))				{													echo '<br /><br />';					echo Display::return_icon('attachment.gif',get_lang('Attachment'));					echo '<a href="download.php?file=';							echo $file_name_array['path'];						echo ' "> '.$file_name_array['filename'].' </a>';						echo '<span class="attachment_comment">';						echo $file_name_array['comment'];					echo '</span><br />';												}												echo '<span class="blogpost_comment_info">' . get_lang('Author') . ': ' . $comment['lastname'] . ' ' . $comment['firstname'] . ' - ' . get_lang('Rating') . ': '.Blog::display_rating('comment', $blog_id, $comment['comment_id']) . $rating_select . '</span>';				echo '<span class="blogpost_actions">' . $blog_comment_actions . '</span>';			echo '</div>';			// Go further down the tree.			Blog::get_threaded_comments( $comment['comment_id'], $next_level, $blog_id, $post_id);		}	}	/**	 * Displays the form to create a new post	 * @author Toon Keppens	 *	 * @param Integer $blog_id	 */	function display_form_new_post($blog_id)	{		if(api_is_allowed('BLOG_' . $blog_id, 'article_add'))		{			echo '<script type="text/javascript">					function FCKeditor_OnComplete( editorInstance )					{					  editorInstance.Events.AttachEvent( \'OnSelectionChange\', check_for_title ) ;					}					function check_for_title()					{						// This functions shows that you can interact directly with the editor area						// DOM. In this way you have the freedom to do anything you want with it.						// Get the editor instance that we want to interact with.						var oEditor = FCKeditorAPI.GetInstance(\'post_full_text\') ;						// Get the Editor Area DOM (Document object).						var oDOM = oEditor.EditorDocument ;						var iLength ;						var contentText ;						var contentTextArray;						var bestandsnaamNieuw = "";						var bestandsnaamOud = "";						// The are two diffent ways to get the text (without HTML markups).						// It is browser specific.						if( document.all )		// If Internet Explorer.						{							contentText = oDOM.body.innerText ;						}						else					// If Gecko.						{							var r = oDOM.createRange() ;							r.selectNodeContents( oDOM.body ) ;							contentText = r.toString() ;						}						// Compose title if there is none						contentTextArray = contentText.split(\' \') ;						var x=0;						for(x=0; (x<5 && x<contentTextArray.length); x++)						{							if(x < 4)							{								bestandsnaamNieuw += contentTextArray[x] + \' \';							}							else							{								bestandsnaamNieuw += contentTextArray[x] + \'...\';							}						}						if(document.getElementById(\'post_title_edited\').value == "false")						{							document.getElementById(\'post_title\').value = bestandsnaamNieuw;						}					}					function trim(s) {					 while(s.substring(0,1) == \' \') {					  s = s.substring(1,s.length);					 }					 while(s.substring(s.length-1,s.length) == \' \') {					  s = s.substring(0,s.length-1);					 }					 return s;					}					function check_if_still_empty()					{						if(trim(document.getElementById(\'post_title\').value) != "")						{							document.getElementById(\'post_title_edited\').value = "true";						}					}			</script>';			echo '<form name="add_post" enctype="multipart/form-data"  method="post" action="blog.php?blog_id=' . $blog_id . '">				 <span class="blogpost_title">' . get_lang('NewPost') . '</span> 						<table width="100%" border="0" cellspacing="2" cellpadding="0">							<tr>						   <td width="80" valign="top">' . get_lang('Title') . ':&nbsp;&nbsp;</td>						   <td><input name="post_title" id="post_title" type="text" size="60" onblur="check_if_still_empty()" />' .						   		'<input type="hidden" name="post_title_edited" id="post_title_edited" value="false" /><br /><br /></td>							</tr>							<tr>						   <td valign="top">' . get_lang('PostFullText') . ':&nbsp;&nbsp;</td>						   <td>';									$oFCKeditor = new FCKeditor('post_full_text') ;									$oFCKeditor->BasePath	= api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;									$oFCKeditor->Height		= '350';									$oFCKeditor->Width		= '98%';									$oFCKeditor->Value		= isset($_POST['post_full_text'])?stripslashes($_POST['post_full_text']):'';									$oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";									$oFCKeditor->Config['IMUploadPath'] = "upload/blog/";									$oFCKeditor->ToolbarSet = "Blog";									$TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE);									$sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".mysql_real_escape_string($_SESSION["_course"]["language"])."'";									$result_sql=api_sql_query($sql);									$isocode_language=mysql_result($result_sql,0,0);									$oFCKeditor->Config['DefaultLanguage'] = $isocode_language;									$oFCKeditor->Create() ;			echo '			 <br /></td>							</tr> 							<tr><td><b>'.get_lang('AddAnAttachment').'</b><br /><br /></td></tr>								<tr><td width="80" valign="top">' . ucwords(get_lang('FileName') ). ':&nbsp;&nbsp;</td>						    <td><input type="file" name="user_upload"/></td><br></tr>						    						    <tr><td width="80" valign="top">' . get_lang('FileComment'). ':&nbsp;&nbsp;</td>						    <td><br /><textarea name="post_file_comment" cols="34" /></textarea></td></tr>							<tr>								<td >&nbsp;</td>								<td>								 <input type="hidden" name="action" value="" />								 <input type="hidden" name="new_post_submit" value="true" />								 <input type="submit" name="Submit" value="' . get_lang('Ok') . '" />								</td>							</tr>						</table>					</form>';		}		else		{			api_not_allowed();		}	}	/**	 * Displays the form to edit a post	 * @author Toon Keppens	 *	 * @param Integer $blog_id

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -