arefd2010
جمعه 17 بهمن 1393, 23:25 عصر
باسلام خدمت دوستان گرامی
لطفا نظر خودتون رو در باره این سایت در میان بذارید. البته باید این رو اضافه کنم که هنوز کامل نیست...
توی این سایت از پی اچ پی سی اس اس / 3 جاوا اسکریپت جی کوئری استفاده کردم
و همه کد هاشو خودم نوشتم.
و اینکه یک بلاگ چه قسمت هایی باید داشته باشه؟
http://blog.arefdailami.ir
نمونه کد هایی که بنده نوشتم:
<?php require_once("/home/arefdail/public_html/blog/includes/constants.php");
?>
<?php
function mysql_prep( $value ) {
$link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS,DB_NAME);
if (mysqli_connect_errno()) {
printf ("Connection Faild: " , mysql_connect_error());
exit();
}
$magic_quotes_active = get_magic_quotes_gpc();
$new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
if( $new_enough_php ) { // PHP v4.3.0 or higher
// undo any magic quote effects so mysql_real_escape_string can do the work
if( $magic_quotes_active ) { $value = stripslashes( $value ); }
//$value = mysqli_real_escape_string($link , $value );
$value = mysqli_real_escape_string($link , $value);
} else { // before PHP v4.3.0
// if magic quotes aren't already on then add slashes manually
if( !$magic_quotes_active ) { $value = addslashes( $value ); }
// if magic quotes are active, then the slashes already exist
}
return $value;
}
function redirect_to($location) {
if ($location != NULL ) {
header("Location: {$location}");
exit();
}
}
function confirm_query($result_set){
if (!$result_set) {
die("Database query faild: " . mysql_error());
}
}
function show_post($opt){
global $link;
global $result_set;
if (isset($_GET['pid'])) {
$page_id = $_GET['pid'];
}
if (isset($_GET['action'])) {$action = $_GET['action'];} else {$action = "";}
$query = "SELECT posts.PostTitle , posts.PostDate ,posts.PostID, postsdetails.PostText,postsdetails.categoryID , users.UserName FROM posts
INNER JOIN
postsdetails
ON posts.PostID = postsdetails.PostID
INNER JOIN
users
ON posts.OwnerID = users.UserID ";
if (isset($page_id)) {
$query .= "WHERE posts.PostID='$page_id'";
}
mysql_prep($query);
$result_set = mysqli_query($link , $query);
confirm_query($result_set);
$output = "";
switch ($action) {
case 'viewcategory':
$cid = $_GET['cid'];
$GLOBALS['cid'] = $cid;
while ($Post = $result_set->fetch_assoc()) {
if ($Post['categoryID'] == $cid) {
$output .= '<div class="post"><div class="postheader"><span class="title"><a href="?action=viewpost&pid=' . $Post["PostID"] . '">' . $Post['PostTitle'] . '</a></span>';
$output .= '<span class="author">'. "نوشته ی " . $Post['UserName'] . '</span>';
$output .= ' در تاریخ: ' . $Post['PostDate'] . '</div>' ;
$i = strpos($Post['PostText'] , '<em hidden></em>');
$output .= substr($Post['PostText'], 0 , $i) .'</div>' ;
$output .="<a href=\"?action=viewpost&pid={$Post['PostID']}\">بیشتر بخوانید</a>";
//$url = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"];
//$url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : "";
//$url .= $_SERVER["REQUEST_URI"];
}
}echo $output;
break;
case 'viewpost':
while ($Post = $result_set->fetch_assoc()) {
$output .= '<div class="post"><div class="postheader"><span class="title"><a href="?action=viewpost&pid=' . $Post["PostID"] . '">' . $Post['PostTitle'] . '</a></span>';
$output .= " " . "نوشته ی " .'<span class="author">' . $Post['UserName'] . '</span>';
$output .= ' در تاریخ: ' . $Post['PostDate'] . '</div>' ;
$output .= $Post['PostText'];
$output .= '</div>';
echo $output;
$GLOBALS['username'] = $Post['UserName'];
$GLOBALS['cid'] = $Post['categoryID'];
require_once ('./comments/index.php');
$_SESSION['posttitle'] = $Post['PostTitle'];
}
break;
case 'newpost':
include('/newpost.php');
break;
default:
$output = "";
while ($Post = $result_set->fetch_assoc()) {
$output .= '<div class="post"><div class="postheader"><span class="title"><a href="?action=viewpost&pid=' . $Post["PostID"] . '">' . $Post['PostTitle'] . '</a></span>';
$output .= " " . "نوشته ی " .'<span class="author">' . $Post['UserName'] . '</span>';
$output .= ' در تاریخ: ' . $Post['PostDate'] . '</div>' ;
$i = strpos($Post['PostText'] , '<em hidden></em>');
$output .= substr($Post['PostText'], 0 , $i).'</div>';
$output .="<a href=\"?action=viewpost&pid={$Post['PostID']}\">بیشتر بخوانید</a>";
}
echo $output;
break;
}
}
function showPostsByUser() {
global $link;
if (isset($_GET['action']) && isset($_GET['pid'])) {
$query = "SELECT * FROM `posts`
INNER JOIN `users`
ON users.UserID = posts.OwnerID";
$result_set = mysqli_query($link , $query);
confirm_query ($result_set);
while ($row = $result_set->fetch_assoc()) {
if ($GLOBALS['username'] == $row['UserName']) {
echo '<h3><a href="?action=viewpost&pid=' . $row['PostID'] . '">' . $row['PostTitle'] . '</a><h3>';
}
}
}
}
function showPostsByCategory(){
global $link;
if (isset($_GET['action']) || isset($GLOBALS['cid']) || isset($_GET['pid'])) {
$query = "SELECT * FROM `postsdetails`
INNER JOIN `posts`
ON postsdetails.PostID = posts.PostID
WHERE postsdetails.categoryID = " . $GLOBALS['cid'];
$result_set = mysqli_query($link , $query);
confirm_query ($result_set);
while ($row = $result_set->fetch_assoc()) {
echo '<h3><a href="?action=viewpost&pid=' . $row['PostID'] . '">' . $row['PostTitle'] . '</a><h3>';
}
}
}
function showAllCategories() {
global $link;
$query = "SELECT * FROM `categories`";
$result_set = mysqli_query($link , $query);
confirm_query($result_set);
while ($category = $result_set->fetch_assoc()) {
echo '<h3><a href="?action=viewcategory&cid=' . $category['categoryID'] . '">' . $category['categoryTitle'] . '</a><h3>';
}
}
?>
لطفا نظر خودتون رو در باره این سایت در میان بذارید. البته باید این رو اضافه کنم که هنوز کامل نیست...
توی این سایت از پی اچ پی سی اس اس / 3 جاوا اسکریپت جی کوئری استفاده کردم
و همه کد هاشو خودم نوشتم.
و اینکه یک بلاگ چه قسمت هایی باید داشته باشه؟
http://blog.arefdailami.ir
نمونه کد هایی که بنده نوشتم:
<?php require_once("/home/arefdail/public_html/blog/includes/constants.php");
?>
<?php
function mysql_prep( $value ) {
$link = mysqli_connect(DB_SERVER, DB_USER, DB_PASS,DB_NAME);
if (mysqli_connect_errno()) {
printf ("Connection Faild: " , mysql_connect_error());
exit();
}
$magic_quotes_active = get_magic_quotes_gpc();
$new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
if( $new_enough_php ) { // PHP v4.3.0 or higher
// undo any magic quote effects so mysql_real_escape_string can do the work
if( $magic_quotes_active ) { $value = stripslashes( $value ); }
//$value = mysqli_real_escape_string($link , $value );
$value = mysqli_real_escape_string($link , $value);
} else { // before PHP v4.3.0
// if magic quotes aren't already on then add slashes manually
if( !$magic_quotes_active ) { $value = addslashes( $value ); }
// if magic quotes are active, then the slashes already exist
}
return $value;
}
function redirect_to($location) {
if ($location != NULL ) {
header("Location: {$location}");
exit();
}
}
function confirm_query($result_set){
if (!$result_set) {
die("Database query faild: " . mysql_error());
}
}
function show_post($opt){
global $link;
global $result_set;
if (isset($_GET['pid'])) {
$page_id = $_GET['pid'];
}
if (isset($_GET['action'])) {$action = $_GET['action'];} else {$action = "";}
$query = "SELECT posts.PostTitle , posts.PostDate ,posts.PostID, postsdetails.PostText,postsdetails.categoryID , users.UserName FROM posts
INNER JOIN
postsdetails
ON posts.PostID = postsdetails.PostID
INNER JOIN
users
ON posts.OwnerID = users.UserID ";
if (isset($page_id)) {
$query .= "WHERE posts.PostID='$page_id'";
}
mysql_prep($query);
$result_set = mysqli_query($link , $query);
confirm_query($result_set);
$output = "";
switch ($action) {
case 'viewcategory':
$cid = $_GET['cid'];
$GLOBALS['cid'] = $cid;
while ($Post = $result_set->fetch_assoc()) {
if ($Post['categoryID'] == $cid) {
$output .= '<div class="post"><div class="postheader"><span class="title"><a href="?action=viewpost&pid=' . $Post["PostID"] . '">' . $Post['PostTitle'] . '</a></span>';
$output .= '<span class="author">'. "نوشته ی " . $Post['UserName'] . '</span>';
$output .= ' در تاریخ: ' . $Post['PostDate'] . '</div>' ;
$i = strpos($Post['PostText'] , '<em hidden></em>');
$output .= substr($Post['PostText'], 0 , $i) .'</div>' ;
$output .="<a href=\"?action=viewpost&pid={$Post['PostID']}\">بیشتر بخوانید</a>";
//$url = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] : 'https://'.$_SERVER["SERVER_NAME"];
//$url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : "";
//$url .= $_SERVER["REQUEST_URI"];
}
}echo $output;
break;
case 'viewpost':
while ($Post = $result_set->fetch_assoc()) {
$output .= '<div class="post"><div class="postheader"><span class="title"><a href="?action=viewpost&pid=' . $Post["PostID"] . '">' . $Post['PostTitle'] . '</a></span>';
$output .= " " . "نوشته ی " .'<span class="author">' . $Post['UserName'] . '</span>';
$output .= ' در تاریخ: ' . $Post['PostDate'] . '</div>' ;
$output .= $Post['PostText'];
$output .= '</div>';
echo $output;
$GLOBALS['username'] = $Post['UserName'];
$GLOBALS['cid'] = $Post['categoryID'];
require_once ('./comments/index.php');
$_SESSION['posttitle'] = $Post['PostTitle'];
}
break;
case 'newpost':
include('/newpost.php');
break;
default:
$output = "";
while ($Post = $result_set->fetch_assoc()) {
$output .= '<div class="post"><div class="postheader"><span class="title"><a href="?action=viewpost&pid=' . $Post["PostID"] . '">' . $Post['PostTitle'] . '</a></span>';
$output .= " " . "نوشته ی " .'<span class="author">' . $Post['UserName'] . '</span>';
$output .= ' در تاریخ: ' . $Post['PostDate'] . '</div>' ;
$i = strpos($Post['PostText'] , '<em hidden></em>');
$output .= substr($Post['PostText'], 0 , $i).'</div>';
$output .="<a href=\"?action=viewpost&pid={$Post['PostID']}\">بیشتر بخوانید</a>";
}
echo $output;
break;
}
}
function showPostsByUser() {
global $link;
if (isset($_GET['action']) && isset($_GET['pid'])) {
$query = "SELECT * FROM `posts`
INNER JOIN `users`
ON users.UserID = posts.OwnerID";
$result_set = mysqli_query($link , $query);
confirm_query ($result_set);
while ($row = $result_set->fetch_assoc()) {
if ($GLOBALS['username'] == $row['UserName']) {
echo '<h3><a href="?action=viewpost&pid=' . $row['PostID'] . '">' . $row['PostTitle'] . '</a><h3>';
}
}
}
}
function showPostsByCategory(){
global $link;
if (isset($_GET['action']) || isset($GLOBALS['cid']) || isset($_GET['pid'])) {
$query = "SELECT * FROM `postsdetails`
INNER JOIN `posts`
ON postsdetails.PostID = posts.PostID
WHERE postsdetails.categoryID = " . $GLOBALS['cid'];
$result_set = mysqli_query($link , $query);
confirm_query ($result_set);
while ($row = $result_set->fetch_assoc()) {
echo '<h3><a href="?action=viewpost&pid=' . $row['PostID'] . '">' . $row['PostTitle'] . '</a><h3>';
}
}
}
function showAllCategories() {
global $link;
$query = "SELECT * FROM `categories`";
$result_set = mysqli_query($link , $query);
confirm_query($result_set);
while ($category = $result_set->fetch_assoc()) {
echo '<h3><a href="?action=viewcategory&cid=' . $category['categoryID'] . '">' . $category['categoryTitle'] . '</a><h3>';
}
}
?>