All pastes #97326 Raw Edit

Stuff

public html v1 · immutable
#97326 ·published 2006-07-23 16:18 UTC
rendered paste body
<?phpif(!defined('IN_SUBDREAMER'))  die('Hacking attempt!');// get the value of $p2_action$p2_action = isset($_POST['p2_action']) ? $_POST['p2_action'] : (isset($_GET['p2_action']) ? $_GET['p2_action'] : 'displaynews');// get plugin language$p2_language = GetLanguage(2);// article bitfield settings$p2_articlebitfield = array('useglobalsettings'       => 1,                            'displayonline'           => 2,                            'displaytitle'            => 4,                            'displayauthor'           => 8,                            'displaycreateddate'      => 16,                            'displayupdateddate'      => 32,                            'displayprintarticlelink' => 64,                            'displayemailarticlelink' => 128,                            'displaydescription'      => 256,                            'displaysmilies'          => 512,                            'displaycomments'         => 1024);// ############################### SEND ARTICLE ################################function p2_SendEmail($articleid){  global $DB, $categoryid, $sdurl, $p2_language;  $useremail    = $_POST['p2_emailfrom'];  $emailto      = $_POST['p2_emailto'];  $emailcomment = $_POST['p2_emailcomment'];  // obtain emails  $getemails = str_replace(',', ' ', $emailto);                  // get rid of commas  $getemails = eregi_replace("[[:space:]]+", " ", $getemails);   // get rid of extra spaces  $getemails = trim($getemails);                                 // then trim  $emails    = explode(" ", $getemails);  // setup some vars  $invalidemails = 0;  // check if emails are real  for($i = 0; $i < count($emails); $i++)  {    if(!ereg("^([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $emails[$i]))      $invalidemails = 1;  }  if($invalidemails == 1)    $errors[] = $p2_language['invalid_email'];  else  {    // check user email    if(!ereg("^([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $useremail))      $errors[] = $p2_language['invalid_email'];  }  // check if article exists/online  if(!$article = $DB->query_first("SELECT * FROM " . TABLE_PREFIX . "p2_news WHERE articleid = '$articleid'                                   AND categoryid = '$categoryid' AND (settings & 2) AND (datestart = 0 OR datestart < '" . time() . "')                                   AND (dateend   = 0 OR dateend   > '" . time() . "')") )  {    echo $p2_language['article_offline'];    return 0;  }  // send email if no errors  if(!isset($errors))  {    // email headers    $headers  = "MIME-Version: 1.0\r \n";    $headers .= "Content-type: text/plain; charset=iso-8859-1\r \n";    $headers .= "From: \"$useremail\" <$useremail>\r \n";    $headers .= "Reply-To: \"$useremail\" <$useremail>\r \n";    // email subject    $subject = $article['title'];    // email main message    $message = $sdurl . "index.php?categoryid=" . $categoryid . "&p2_articleid=$articleid \r \n \r \n $emailcomment";    for($i = 0; $i < count($emails); $i++)    {      if(@mail($emails[$i], $subject, $message, $headers))      {        $messagesent = 1;      }    }    if($messagesent == 1)    {      echo $p2_language['email_sent'] . '<br />' . $article['title'] . '<br /><br />           <a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_articleid=' . $articleid) . '">' . $p2_language['go_back'] . '<a>';    }    else    {      echo $p2_language['email_not_sent'];    }  }  else  {    foreach($errors as $key=>$value)    {      echo $value . '<br /><br />';    }    p2_EmailArticle($articleid);  }}// ############################ EMAIL ARTICLE FORM #############################function p2_EmailArticle($articleid){  global $DB, $categoryid, $inputsize, $p2_language;  // check if article exists/online  if(!$article = $DB->query_first("SELECT * FROM " . TABLE_PREFIX . "p2_news WHERE articleid = '$articleid'                                   AND categoryid = '$categoryid' AND (settings & 2) AND (datestart = 0 OR datestart < '" . time() . "')                                   AND (dateend   = 0 OR dateend   > '" . time() . "')") )  {    echo $p2_language['article_offline'];    return 0;  }  echo '<b>' . $article['title'] . '</b><br /><br />        ' . $p2_language['enter_recipient_email'] . '<br />        <form method="post" action="' . RewriteLink('index.php?categoryid=' . $categoryid. '&p2_articleid=' . $articleid . '&p2_action=sendemail') . '">        <input type="text" name="p2_emailto" value="' . $_POST['p2_emailto'] . '" size="'.$inputsize.'" /><br />        ' . $p2_language['separate_with_commas'] . '<br /><br />        ' . $p2_language['enter_your_email'] . '<br />        <input type="text" name="p2_emailfrom" size="'.$inputsize.'" value="' . $_POST['p2_emailfrom'] . '" /><br /><br />        ' . $p2_language['enter_comment'] . '<br />        <textarea name="p2_emailcomment" cols="'.$inputsize.'" rows="5">' . $_POST['p2_emailcomment'] . '</textarea><br /><br />        <input type="submit" value="' . strip_tags($p2_language['send_email']) . '" />        </form>';}// ######################### INSERT ARTICLE INTO DB  ###########################function p2_InsertArticle(){  global $DB, $categoryid, $p2_language;  $author      = $_POST['p2_author'];  $title       = $_POST['p2_title'];  $description = $_POST['p2_description'];  $article     = $_POST['p2_article'];  if(strlen($author) == 0)  {    $errors .= $p2_language['enter_name'] . '<br />';  }  if(strlen($title) == 0)  {    $errors .= $p2_language['enter_title'] . '<br />';  }  if(strlen($article) == 0)  {    $errors .= $p2_language['enter_article'] . '<br />';  }  // if no errors insert news, else print error and show submit form  if(!isset($errors))  {    $DB->query("INSERT INTO " . TABLE_PREFIX . "p2_news (categoryid, settings, datecreated, author, title, description, article)                VALUES ($categoryid, 1, '" . time() . "', '$author', '$title', '$description', '$article')");    echo $p2_language['article_submitted'];    $getemail = $DB->query_first("SELECT value FROM " . TABLE_PREFIX . "pluginsettings WHERE pluginid = '3' AND title = 'Article Notification'");    $email    = $getemail['value'];    if(strlen($email) > 0)    {      // obtain emails      $getemails = str_replace(',', ' ', $email);                    // get rid of commas      $getemails = eregi_replace("[[:space:]]+", " ", $getemails);   // get rid of extra spaces      $getemails = trim($getemails);                                 // then trim      $emails    = explode(" ", $getemails);      $fullname = 'Article Plugin';      $subject  = 'New article submitted to your website!';      $message  = 'A new article has been submitted to your website.';      $headers  = "MIME-Version: 1.0\r \n";      $headers .= "Content-type: text/plain; charset=iso-8859-1\r \n";      $headers .= "From: \"$fullname\" <$email>\r \n";      $headers .= "Reply-To: \"$fullname\" <$email>\r \n";      for($i = 0; $i < count($emails); $i++)      {        @mail($emails[$i], $subject, $message, $headers);      }    }  }  else  {    echo '<b>' . $errors . '</b><br /><br />';    p2_SubmitArticle($author, $title, $description, $article);  }}// ########################### SUBMIT ARTICLE FORM  ############################function p2_SubmitArticle($author, $title, $description, $article){  global $categoryid, $userinfo, $inputsize, $p2_language;  echo '<form method="post" action="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_action=insertarticle') . '">        <table width="100%" border="0" cellpadding="0" cellspacing="0">';  if($userinfo['loggedin'])  {    echo '<input type="hidden" name="p2_author" value="' . $userinfo['username'] . '" />';  }  else  {    echo '<tr>            <td width="25%" valign="top">' . $p2_language['author'] . '</td>            <td width="75%" valign="top" style="padding-left: 8px; padding-bottom: 6px;">              <input type="text" name="p2_author" value="'.$author.'" size="'.$inputsize.'" maxlength="64" />            </td>          </tr>';  }  echo '<tr>          <td width="25%" valign="top">' . $p2_language['title'] . '</td>          <td width="75%" valign="top" style="padding-left: 8px; padding-bottom: 6px;">            <input type="text" name="p2_title" value="'.$title.'" size="'.$inputsize.'" maxlength="128">          </td>        </tr>        <tr>          <td width="25%" valign="top">' . $p2_language['description'] . '</td>          <td width="75%" valign="top" style="padding-left: 8px; padding-bottom: 6px;">            <textarea name="p2_description" cols="'.$inputsize.'" rows="5">'.$description.'</textarea>          </td>        </tr>        <tr>          <td width="25%" valign="top">' . $p2_language['article'] . '</td>          <td width="75%" valign="top" style="padding-left: 8px; padding-bottom: 6px;">            <textarea name="p2_article" cols="'.$inputsize.'" rows="25">'.$article.'</textarea>          </td>        </tr>        <tr>          <td width="25%" valign="top"></td>          <td width="75%" valign="top" style="padding-left: 8px; padding-bottom: 6px;">            <input type="hidden" name="p2_action" value="insertarticle" />            <input type="submit" value="' . strip_tags($p2_language['submit_article']) . '" />          </td>        </tr>        </table>        </form>';}// ############################## DISPLAY ARTICLE ##############################function p2_DisplayArticle($article){  global $DB, $sdurl, $categoryid, $userinfo, $p2_articlebitfield, $p2_language;  // check which page of the article we are on  // this variable needs to be created before displaying the article becuase it's used  // in the description printing area  $currentpage = (isset($_GET['p2_page']) AND ereg("^[0-9]+$", $_GET['p2_page'])) ? $_GET['p2_page'] : 1;  // to prevent blank lines from showing, create a variable that will determine if weed need to break  $displaylinebreaks = false;  // display title?  if($article['settings'] & $p2_articlebitfield['displaytitle'])  {    echo '<b><u>' . $article['title'] . '</u></b>&nbsp;';    $displaylinebreaks = true;  }  // display author?  if($article['settings'] & $p2_articlebitfield['displayauthor'])  {    echo $p2_language['by'] . ' ' . $article['author'] . '<br />';    $displaylinebreaks = true;  }  // display published date?  if($article['settings'] & $p2_articlebitfield['displaycreateddate'])  {    echo $p2_language['published'] . ' ' . iif($article['datestart'] != 0, DisplayDate($article['datestart']), DisplayDate($article['datecreated'])) . '';    $displaylinebreaks = true;  }  // display updated date?  if( ($article['settings'] & $p2_articlebitfield['displayupdateddate']) AND ($article['dateupdated'] != 0) )  {    echo $p2_language['updated'] . ' ' . DisplayDate($article['dateupdated']) . '';    $displaylinebreaks = true;  }  // display print article link?  if($article['settings'] & $p2_articlebitfield['displayprintarticlelink'])  {    echo '<img src="' . $sdurl . 'plugins/p2_news/print.gif" /> <a href="' . $sdurl . 'plugins/p2_news/printarticle.php?p2_articleid=' . $article['articleid'] . '" target="_blank">' . $p2_language['print'] . '</a>&nbsp;&nbsp;&nbsp;' . iif(!($article['settings'] & $p2_articlebitfield['displayemailarticlelink']), '<br />');    $displaylinebreaks = true;  }  // display email article link?  if($article['settings'] & $p2_articlebitfield['displayemailarticlelink'])  {    echo '<img src="' . $sdurl . 'plugins/p2_news/email.gif" /> <a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_articleid=' . $article['articleid'] . '&p2_action=emailarticle') . '">' . $p2_language['email'] . '</a><br />';    $displaylinebreaks = true;  }  if($displaylinebreaks)  {    echo '<br />';  }  // display description?  if(strlen($article['description']))  {    if(!isset($_GET['p2_articleid']))    {      echo iif($article['settings'] & $p2_articlebitfield['displaysmilies'], AddSmilies($article['description']), $article['description']);    }    else if( ($article['settings'] & $p2_articlebitfield['displaydescription']) AND $currentpage == 1)    {      echo iif($article['settings'] & $p2_articlebitfield['displaysmilies'], AddSmilies($article['description']), $article['description']);    }  }  // display article?  if(!strlen($article['description']) OR isset($_GET['p2_articleid']))  {    if(strlen($article['article']))    {      // find out how many pages are in this article      $articlepages = preg_split('/{(pagebreak)\s*(.*?)}/i', $article['article']);      // a few more checks...      if($currentpage == 0 OR $currentpage > count($articlepages))      {        $currentpage = 1;      }      // add smilies to article?      if($article['settings'] & $p2_articlebitfield['displaysmilies'])      {        $articlepages[$currentpage - 1] = AddSmilies($articlepages[$currentpage - 1]);      }      // this preg_replace code was created by shoz: phpfreaks.com/forums/index.php?showuser=14845      echo preg_replace('#(\A[\s]*<br[^>]*>[\s]*|'                                      // remove <br/> at beginning of the string                        .'<br[^>]*>\s*(?=(?:\{pagebreak\}))|'                           // remove <br/> before {pagebreak}                        .'(?<=(?:\{pagebreak\}))\s*<br[^>]*>|'                          // remove <br/> after {pagebreak}                        .'<br[^>]*>[\s]*\Z)#is', '', $articlepages[$currentpage - 1]);  // remove <br/> at end of string      if(count($articlepages) > 1)      {        echo '<br /><br />              <center>';        // display previous page link?        if($currentpage > 1)        {          echo '<a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_articleid=' . $article['articleid'] . '&p2_page=' . ($currentpage - 1)) . '">' . $p2_language['previous_page'] . '</a> | ';        }        echo $p2_language['page'] . ' ' . $currentpage . ' ' . $p2_language['of'] . ' ' . count($articlepages);        if(count($articlepages) > $currentpage)        {          echo ' | <a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_articleid=' . $article['articleid'] . '&p2_page=' . ($currentpage + 1)) . '">' . $p2_language['next_page'] . '</a>';        }        echo '</center>';      }    }  }  else  {    // display link to article    echo '<a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_articleid=' . $article['articleid']) . '">' . $p2_language['read_more'] . '</a>&nbsp;-&nbsp;';  }  // display submit news link?  if(in_array(2, $userinfo['pluginsubmitids']))  {    echo '<a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_action=submitarticle') . '">' . $p2_language['submit_article'] . '</a>';  }  // display user comments?  if($article['settings'] & $p2_articlebitfield['displaycomments'])  {    echo iif(in_array(2, $userinfo['pluginsubmitids']), ' - ', '<br /><br />');    // if p2_start is set, then it has already been confirmed to be an int (checked below)    Comments(2, $article['articleid'], 'index.php?categoryid=' . $categoryid . iif(isset($_GET['p2_start']), '&p2_start=' . $_GET['p2_start']) . '&p2_articleid=' . $article['articleid']);  }}// ############################### DISPLAY NEWS  ###############################function p2_DisplayNews(){  global $DB, $categoryid, $p2_articlebitfield, $p2_language;  // get global article settings  $getsettings = $DB->query("SELECT description, value FROM " . TABLE_PREFIX . "pluginsettings WHERE pluginid = 2");  for($i = 0; $setting = $DB->fetch_array($getsettings); $i++)  {    $settings[$setting['description']] = $setting['value'];  }  // create global settings  $globalsettings = 0;  $globalsettings += $settings['Display Title']                      == 1 ? 4    : 0;  $globalsettings += $settings['Display Author']                     == 1 ? 8    : 0;  $globalsettings += $settings['Display Creation Date']              == 1 ? 16   : 0;  $globalsettings += $settings['Display Updated Date']               == 1 ? 32   : 0;  $globalsettings += $settings['Display Print Article Link']         == 1 ? 64   : 0;  $globalsettings += $settings['Display Email Article Link']         == 1 ? 128  : 0;  $globalsettings += $settings['Display Description Inside Article'] == 1 ? 256  : 0;  $globalsettings += $settings['Display Smilie Images']              == 1 ? 512  : 0;  $globalsettings += $settings['Display User Comments']              == 1 ? 1024 : 0;  unset($settings);  // display specific article?  if(isset($_GET['p2_articleid']))  {    if($article = $DB->query_first("SELECT * FROM " . TABLE_PREFIX . "p2_news WHERE articleid = '" . $_GET['p2_articleid'] . "'                                    AND categoryid = '$categoryid' AND (settings & 2) AND (datestart = 0 OR datestart < '" . time() . "')                                    AND (dateend   = 0 OR dateend   > '" . time() . "')") )    {      // use global settings for this article?      if($article['settings'] & $p2_articlebitfield['useglobalsettings'])      {        $article['settings'] = $globalsettings;      }      // display the article      p2_DisplayArticle($article);      // update the views      $DB->query("UPDATE " . TABLE_PREFIX . "p2_news SET views=views+1 WHERE articleid = '" . $_GET['p2_articleid'] . "'");    }    else    {      echo $p2_language['article_offline'];      return;    }  }  else  {    // display all articles    // find the limit start    $start = (isset($_GET['p2_start']) AND ereg("^[0-9]+$", $_GET['p2_start'])) ? $_GET['p2_start'] : 0;    // get category settings, if none then resort to default    if($categorysettings = $DB->query_first("SELECT * FROM " . TABLE_PREFIX . "p2_settings WHERE categoryid = '$categoryid'"))    {      $limit         = $categorysettings['maxarticles'];      $order         = $categorysettings['sorting'];      $multiplepages = $categorysettings['multiplepages'];    }    else    {      $limit         = 10;      $order         = 'articleid DESC';      $multiplepages = 1;    }    $getarticles = $DB->query("SELECT * FROM " . TABLE_PREFIX . "p2_news WHERE categoryid = '$categoryid' AND (settings & 2)                               AND (datestart = 0 OR datestart < '" . time() . "')                               AND (dateend   = 0 OR dateend   > '" . time() . "')                               ORDER BY " . $order . " LIMIT $start, " . ($limit + 1) . "");    $rows = $DB->get_num_rows($getarticles);    for($i = 0; $i < $rows AND $i < $limit; $i++)    {      $article = $DB->fetch_array($getarticles);      // use global settings for this article?      if($article['settings'] & $p2_articlebitfield['useglobalsettings'])      {        $article['settings'] = $globalsettings;      }      // display article      p2_DisplayArticle($article);      // display break      if( (($i + 1) < $rows) AND (($i + 1) < $limit) )      {        echo '<br /><br /><hr><br />';      }    }    // display multiple pages?    if($multiplepages)    {      if($start > 0 OR $rows > $limit)      {        echo '<br /><br /><hr /><br />              <table width="100%" cellpadding="0" cellspacing="0" border="0">              <tr>';        if($start > 0)        {          echo '<td><a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_start=' . ($start - $limit)) . '">' . $p2_language['previous'] . '</a></td>';        }        if($rows > $limit)        {          echo '<td align="right"><a href="' . RewriteLink('index.php?categoryid=' . $categoryid . '&p2_start=' . ($start + $limit)) . '">' . $p2_language['next'] . '</a></td>';        }        echo '</tr></table>';      }    }  }}// ######################### START CALLING FUNCTIONS  ##########################// $p2_action is created at the top of this page// first do a security check on articleid:if(isset($_GET['p2_articleid']) AND !ereg("^[0-9]+$", $_GET['p2_articleid'])){  unset($_GET['p2_articleid']);}if($p2_action == 'insertarticle' AND in_array(2, $userinfo['pluginsubmitids'])){  p2_InsertArticle();}else if($p2_action == 'submitarticle' AND in_array(2, $userinfo['pluginsubmitids'])){  p2_SubmitArticle(NULL, NULL, NULL, NULL);}else if(isset($_GET['p2_articleid']) AND $p2_action == 'emailarticle'){  p2_EmailArticle($_GET['p2_articleid']);}else if(isset($_GET['p2_articleid']) AND $p2_action == 'sendemail'){  p2_SendEmail($_GET['p2_articleid']);}else{  p2_DisplayNews();}// ############################## UNSET VARIABLES ##############################unset($p2_language);?>