📜 ⬆️ ⬇️

Principles of creating a portal with easy integration of design in PHP (source)

This topic is related to the topic Principles of creating a portal with easy integration of design in PHP

This is the class itself:

<?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;
}
}
?>

Implementation for users:

<?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 "
<?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 "
<?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 "
";
break;
}
include_once ('sbl_bottom.php');
?>

Implementation for admin:

<?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'>

<?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'>
<?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'>
<?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'>
'
""
break;
case 'new':
$ oFCKeditor = new FCKeditor ('text');
$ oFCKeditor-> BasePath = "../fckeditor/";
$ oFCKeditor-> Value = "Enter text";
echo "<form action = '{$ _ SERVER [' SCRIPT_NAME ']}? action = add' method = 'POST'>"
. "
Title: Save As Page Article

')

Source: https://habr.com/ru/post/22340/


All Articles