これはクラス自体です。
<?php
include_once('mysql.php');
/**
*
* @author Borro <borro@bk.ru>
* @version 0.1a
*
*/
class Article{
/**
* , MySQL
*
* @var MySQL
*/
private $mysql;
/**
*
*
* @param MySQL $mysql
*/
public function __construct($mysql)
{
$this->mysql = $mysql;
}
/**
*
*
* @param string $title
* @param string $text
* @param string $author
* @param string $description
* @param string $keywords
* @param string $notitle
* @return int
*/
public function AddArticle($title, $text, $author, $description, $keywords, $notitle)
{
if ($title != '') {
$title = mysql_escape_string(htmlspecialchars($title));
}
else {
throw new Exception(" ", 201);
}
if ($text != '') {
$text = mysql_escape_string(trim($text));
}
else {
throw new Exception(" ", 202);
}
if ($author != '') {
$author = mysql_escape_string(trim($author));
}
else {
throw new Exception(" ", 203);
}
$description = mysql_escape_string(strip_tags(trim($description)));
$keywords = mysql_escape_string(strip_tags(trim($keywords)));
$notitle = mysql_escape_string($notitle);
$t = $this->mysql->query("INSERT INTO `articles` (title, text, author, description, keywords, make_date, notitle) VALUE('$title', '$text', '$author', '$description', '$keywords', NOW(), '$notitle')");
if ($t == false) {
throw new Exception(mysql_error(), mysql_errno());
}
return $this->mysql->insert_id();
}
/**
*
*
* @param int $id
* @return array
*/
public function ViewArticle($id)
{
$id = intval($id);
$this->mysql->query("SELECT * FROM `articles` WHERE id = $id");
return $this->mysql->fetch_array();
}
/**
*
*
* @return array
*/
public function ViewAllArticles()
{
$this->mysql->query("SELECT * FROM `articles` ORDER BY `edit_date` DESC");
return $this->mysql->result2assoc_array();
}
/**
*
*
* @param int $id
* @param string $title
* @param string $text
* @param string $author
* @param string $description
* @param string $keywords
* @param string $notitle
* @return int
*/
public function EditArticles($id, $title, $text, $author, $description, $keywords, $notitle)
{
if ($id != '') {
$id = intval($id);
}
else {
throw new Exception(" ID", 200);
}
if ($title != '') {
$title = mysql_escape_string(htmlspecialchars($title));
}
else {
throw new Exception(" ", 201);
}
if ($text != '') {
$text = mysql_escape_string(trim($text));
}
else {
throw new Exception(" ", 202);
}
if ($author != '') {
$author = mysql_escape_string(trim($author));
}
else {
throw new Exception(" ", 203);
}
$description = mysql_escape_string(strip_tags(trim($description)));
$keywords = mysql_escape_string(strip_tags(trim($keywords)));
$notitle = mysql_escape_string($notitle);
$this->mysql->query("UPDATE `articles` SET title ='$title', text ='$text', author ='$author', description = '$description', keywords ='$keywords', notitle = '$notitle' WHERE id = $id");
return $id;
}
/**
*
*
* @param int $id
* @return bool
*/
public function DeleteArticle($id)
{
$id = intval($id);
$t = $this->mysql->query("DELETE FROM `articles` WHERE id=$id");
return true;
}
}
?>
ユーザー向けの実装:
<?php
include_once('config.php');
include_once('class/article.php');
$article = new Article($mysql);
include_once('sbl_top.php');
switch (@$_GET['action']) {
case 'view':
$art = $article->ViewArticle($_GET['id']);
if ($art['notitle']=='yes') {
echo $art['text'];
}
else {
echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} ";
}
break;
default:
$array = $article->ViewAllArticles();
echo " : <a href='{$_SERVER['SCRIPT_NAME']}?action=view&id={$art['id']}' style='color:black'>{$art['title']} "
." : ".trim($text[0])."... ";
}
}
echo "
include_once('config.php'); include_once('class/article.php'); $article = new Article($mysql); include_once('sbl_top.php'); switch (@$_GET['action']) { case 'view': $art = $article->ViewArticle($_GET['id']); if ($art['notitle']=='yes') { echo $art['text']; } else { echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} "; } break; default: $array = $article->ViewAllArticles(); echo " : <a href='{$_SERVER['SCRIPT_NAME']}?action=view&id={$art['id']}' style='color:black'>{$art['title']} " ." : ".trim($text[0])."... "; } } echo " |
<?php
|
<?php
|
<?php
|
<?php
include_once('config.php');
include_once('class/article.php');
$article = new Article($mysql);
include_once('sbl_top.php');
switch (@$_GET['action']) {
case 'view':
$art = $article->ViewArticle($_GET['id']);
if ($art['notitle']=='yes') {
echo $art['text'];
}
else {
echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} ";
}
break;
default:
$array = $article->ViewAllArticles();
echo " : <a href='{$_SERVER['SCRIPT_NAME']}?action=view&id={$art['id']}' style='color:black'>{$art['title']} "
." : ".trim($text[0])."... ";
}
}
echo "
<?php
| <?php
|
<?php
include_once('config.php');
include_once('class/article.php');
$article = new Article($mysql);
include_once('sbl_top.php');
switch (@$_GET['action']) {
case 'view':
$art = $article->ViewArticle($_GET['id']);
if ($art['notitle']=='yes') {
echo $art['text'];
}
else {
echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} ";
}
break;
default:
$array = $article->ViewAllArticles();
echo " : <a href='{$_SERVER['SCRIPT_NAME']}?action=view&id={$art['id']}' style='color:black'>{$art['title']} "
." : ".trim($text[0])."... ";
}
}
echo "
<?php
include_once('config.php');
include_once('class/article.php');
$article = new Article($mysql);
include_once('sbl_top.php');
switch (@$_GET['action']) {
case 'view':
$art = $article->ViewArticle($_GET['id']);
if ($art['notitle']=='yes') {
echo $art['text'];
}
else {
echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} ";
}
break;
default:
$array = $article->ViewAllArticles();
echo " : <a href='{$_SERVER['SCRIPT_NAME']}?action=view&id={$art['id']}' style='color:black'>{$art['title']} "
." : ".trim($text[0])."... ";
}
}
echo "
<?php
include_once('config.php');
include_once('class/article.php');
$article = new Article($mysql);
include_once('sbl_top.php');
switch (@$_GET['action']) {
case 'view':
$art = $article->ViewArticle($_GET['id']);
if ($art['notitle']=='yes') {
echo $art['text'];
}
else {
echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} ";
}
break;
default:
$array = $article->ViewAllArticles();
echo " : <a href='{$_SERVER['SCRIPT_NAME']}?action=view&id={$art['id']}' style='color:black'>{$art['title']} "
." : ".trim($text[0])."... ";
}
}
echo "
<?php
include_once('config.php');
include_once('class/article.php');
$article = new Article($mysql);
include_once('sbl_top.php');
switch (@$_GET['action']) {
case 'view':
$art = $article->ViewArticle($_GET['id']);
if ($art['notitle']=='yes') {
echo $art['text'];
}
else {
echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} ";
}
break;
default:
$array = $article->ViewAllArticles();
echo " : <a href='{$_SERVER['SCRIPT_NAME']}?action=view&id={$art['id']}' style='color:black'>{$art['title']} "
." : ".trim($text[0])."... ";
}
}
echo "
<?php
include_once('config.php');
include_once('class/article.php');
$article = new Article($mysql);
include_once('sbl_top.php');
switch (@$_GET['action']) {
case 'view':
$art = $article->ViewArticle($_GET['id']);
if ($art['notitle']=='yes') {
echo $art['text'];
}
else {
echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} ";
}
break;
default:
$array = $article->ViewAllArticles();
echo " : <a href='{$_SERVER['SCRIPT_NAME']}?action=view&id={$art['id']}' style='color:black'>{$art['title']} "
." : ".trim($text[0])."... ";
}
}
echo "
";
休憩;
}
include_once( 'sbl_bottom.php');
?>
管理者向けの実装:
<?php
include_once('sbl_top.php');
include_once('../class/article.php');
$article = new Article($mysql);
include_once('../fckeditor/fckeditor.php');
switch (@$_GET['action']) {
case 'view':
$art = $article->ViewArticle($_GET['id']);
if ($art['notitle']=='yes') {
echo $art['text'];
}
else {
echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} ";
}
echo "<a href='{$_SERVER['SCRIPT_NAME']}?action=delete&id[]={$art['id']}' style='color:red'>
include_once('sbl_top.php'); include_once('../class/article.php'); $article = new Article($mysql); include_once('../fckeditor/fckeditor.php'); switch (@$_GET['action']) { case 'view': $art = $article->ViewArticle($_GET['id']); if ($art['notitle']=='yes') { echo $art['text']; } else { echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} "; } echo "<a href='{$_SERVER['SCRIPT_NAME']}?action=delete&id[]={$art['id']}' style='color:red'> |
<?php
|
<?php
|
<?php
|
<?php
include_once('sbl_top.php');
include_once('../class/article.php');
$article = new Article($mysql);
include_once('../fckeditor/fckeditor.php');
switch (@$_GET['action']) {
case 'view':
$art = $article->ViewArticle($_GET['id']);
if ($art['notitle']=='yes') {
echo $art['text'];
}
else {
echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} ";
}
echo "<a href='{$_SERVER['SCRIPT_NAME']}?action=delete&id[]={$art['id']}' style='color:red'>
<?php
include_once('sbl_top.php');
include_once('../class/article.php');
$article = new Article($mysql);
include_once('../fckeditor/fckeditor.php');
switch (@$_GET['action']) {
case 'view':
$art = $article->ViewArticle($_GET['id']);
if ($art['notitle']=='yes') {
echo $art['text'];
}
else {
echo " {$art['title']} ".$art['text']." : {$art['author']} : {$art['make_date']} : {$art['edit_date']} ";
}
echo "<a href='{$_SERVER['SCRIPT_NAME']}?action=delete&id[]={$art['id']}' style='color:red'>
"
。 "<ahref='{$_SERVER['SCRIPT_NAME'-03►?action=vedit&id={$art['id'-03>style = 'color:orange'>記事の編集";
休憩;
ケース「新規」:
$ oFCKeditor =新しいFCKeditor( 'text');
$ oFCKeditor-> BasePath = "../fckeditor/";
$ oFCKeditor-> Value = "Enter Text";
echo "<form action = '{$ _ SERVER [' SCRIPT_NAME ']}?action = add' method = 'POST'>"
」
タイトル:ページとして保存 |