Show DevBest NewSys - News Management

Status
Not open for further replies.

Weasel

👄 I'd intercept me
Nov 25, 2011
4,132
2,456
PHP:
<?php
ob_start();
require_once('../inc/config.php');
session_start();

if (!$_SESSION['username'])
{
    header("Location: index.php");
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo SITENAME ?> - Admin Panel</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/facebox.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="tiny/tiny_mce.js"></script>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/facebox.js" type="text/javascript"></script>
<script type="text/javascript">

    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox({
        loadingImage : 'img/loading.gif',
        closeImage   : 'img/closelabel.png'
      })
    })
  
  </script>
<script type="text/javascript">
    tinyMCE.init({
        mode : "textareas",
        theme : "simple"
    });
</script>
<SCRIPT LANGUAGE="JavaScript">
      function confirmAction() {
        return confirm("Do you really want to remove this article?")
      }
  
</SCRIPT>
</head>

<body>
<div class="logo"><?php echo SITENAME ?> - Create Article <div class="right"> You are logged in as <?php echo $_SESSION['username'] ?></div></div>
<div class="container">
    <div class="main_col">
<?php
$submit = $_POST['submit'];
$remove = $_POST['remove'];
$news_content = $_POST['newscontent'];
$news_title = mysql_real_escape_string($_POST['newstitle']);
$news_author = mysql_real_escape_string($_POST['newsauthor']);
$news_date = date("y-m-d");

if ($submit)
{
    $namecheck = mysql_query("SELECT news_title FROM articles WHERE news_title='$news_title'");
    $count = mysql_num_rows($namecheck);
  
    if ($count!=0)
    {
        die ('<div class="red" style="margin-bottom: 0;">Article <strong>'.$news_title.'</strong> already exists!</div>
        <meta http-equiv="REFRESH" content="2;url=index">
        ');
    }
  
    if ($news_title&&$news_content&&$news_author)
    {
        $news_content = preg_replace("@\[img\](.*\.(gif|png|jpg))\[\/img\]@si",
                        "<img src=\"$1\" border=\"0\" />", $news_content);
        $news_content = preg_replace('~\[youtube]https://www.youtube.com/watch\?v=(.*)\[/youtube]~Uis',
        '<iframe width="560" height="315" src="//www.youtube.com/embed/\\1" frameborder="0" allowfullscreen></iframe>', $news_content);
      
        $query = mysql_query(
            "    INSERT INTO articles
                VALUES('','$news_title','$news_content','$news_date','$news_author')
            ");
      
        echo "<div class='green'>You have posted <strong>$news_title</strong> !</div>";
    }
    else
    {
        echo '<div class="red">You must fill in all fields!</div>';
    }
}

?>

<form action="" method="POST">

    Article Title :
    <br />
    <input name="newstitle" type="text" class="userpass" />
    <br /><br />
    Article Author :
    <br />
    <input name="newsauthor" type="text" class="userpass" value="<?php echo $_SESSION['username'] ?>" />
    <br /><br />
    Article Content :
    <br />
    <textarea id="elm1" name="newscontent" rows="7" cols="30" style="width: 100%"></textarea>
    <br />
    <input name="submit" type="submit" class="button" value="Post News" />
    <a href="viewarticle"><input name="edit" type="button" class="button" value="Edit Article" /></a>
  
</form>

  </div>
  <div class="left_col">
    <?php $amount_get = mysql_query("SELECT * FROM `articles` "); $articles = mysql_num_rows($amount_get); ?>
    <?php $amount_get = mysql_query("SELECT * FROM `users` "); $users = mysql_num_rows($amount_get); ?>
    <?php $amount_get = mysql_query("SELECT * FROM `comment` "); $comments = mysql_num_rows($amount_get); ?>
  
    <div class="link"><a href="index">Homepage</a></div>
    <div class="icon"><img src="img/navi/home.gif" /></div>
    <div class="link"><a href="addarticle">Create Article (<?php echo $articles ?>)</a></div>
    <div class="icon"><img src="img/navi/article.gif" /></div>
    <div class="link"><a href="adduser">Add User (<?php echo $users ?>)</a></div>
    <div class="icon"><img src="img/navi/user.gif" /></div>
    <div class="link"><a href="comments">Comments (<?php echo $comments ?>)</a></div>
    <div class="icon"><img src="img/navi/comment.gif" /></div>
  
  </div>
</div>
<div class="footer">&copy; Copyright <?php echo SITENAME ?> 2012. <div class="right"><a href="index">Home</a> - <a href="addarticle">Create Article</a> - <a href="logout" rel="facebox">Logout</a></div></div>
</body>
</html>

Images can be included if they end on .png, .gif or .jpg
I'm not really a RegEx pro, so the YouTube part was a bit tricky for me.

Make sure it is like this:


https:// and only the /watch?v=videoid

The above code needs to be replaced within addarticle.php in the admin directory.

Code:
[img]http://devbest.com/logo-fancy.png[/img]
[youtube]https://www.youtube.com/watch?v=BU1eNNxL-wk[/youtube]
 
Status
Not open for further replies.

Users who are viewing this thread

Top