Просмотр файла edittext.php

Размер файла: 11.46Kb
<?php
require('includes/header.php');
require('includes/utils.php');
require('includes/db.php');
require('includes/auth.php');

if(isset($_POST['action']))
{
   $banners = mysql_query('SELECT banner FROM users WHERE login = "' . $login . '"');
   list($banner) = mysql_fetch_array($banners);

if(preg_match('/[^\w\.]/', $_GET['page']))
{
?>
<wml>
<card id="error" title="error" ontimer="main.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>"><timer value="15"/>
<p align="center">
Неправильное имя страницы
</p>
</card>
</wml>
<?php
   exit;
}

   $contents = file("$login/" . addslashes($_GET['page']));
   for($i = 0; $i < count($contents); $i++)
   {
      if($banner == 'top' && $i == 6)
      {
      }
      else
      {
         $contents2[] = $contents[$i];
      }
      if(trim($contents[$i]) == '<p align="center">' || trim($contents[$i]) == '<p align="left">' || trim($contents[$i]) == '<p align="right">')
      {
         if($banner == 'top')
            $contents2[] = get_random_link();
      }

      if((isset($contents[$i+1]) && trim($contents[$i+1]) == '</p>') || (isset($contents[$i+2]) && trim($contents[$i+2]) == '</card>'))
      {
         if($banner == 'bottom')
         {
            array_pop($contents2);
            $contents2[] = get_random_link();
         }
      }

      if($i == $_GET['i'])
      {
         if($i == 5 && $_POST['location'] == 'rewrite' && $_POST['action'] != 'left' && $_POST['action'] != 'center' && $_POST['action'] != 'right')
         {
?>
<wml>
<card id="added" title="added" ontimer="edit.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_GET['page']; ?>"><timer value="15"/>
<p>
В этой строке Вы можете использовать только выравнивание текста<br/>
</p>
</card>
</wml>
<?php
            exit;
         }

         $_POST['text'] = str_replace('&', '&amp;', $_POST['text']);
         $_POST['text'] = str_replace('$', '$$', $_POST['text']);
         if($_POST['strip'] == 'yes')
            $_POST['text'] = strip_tags($_POST['text']);

         if($_POST['text'] == '' && ($_POST['action'] != 'left' && $_POST['action'] != 'center' && $_POST['action'] != 'right'))
         {
?>
<wml>
<card id="added" title="added" ontimer="edit.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_GET['page']; ?>"><timer value="15"/>
<p>
Вы не ввели текст<br/>
</p>
</card>
</wml>
<?php
            exit;
         }

         switch($_POST['action'])
         {
            case 'link':
               $new_line = '<a href="' . $_POST['link'] . '">' . $_POST['text'] . "</a>\n";
               break;
            case 'linkb':
               $new_line = '<b><a href="' . $_POST['link'] . '">' . $_POST['text'] . "</a></b>\n";
               break;
            case 'linki':
               $new_line = '<i><a href="' . $_POST['link'] . '">' . $_POST['text'] . "</a></i>\n";
               break;
            case 'links':
               $new_line = '<small><a href="' . $_POST['link'] . '">' . $_POST['text'] . "</a></small>\n";
               break;
            case 'linku':
               $new_line = '<u><a href="' . $_POST['link'] . '">' . $_POST['text'] . "</a></u>\n";
               break;
            case 'text':
               $new_line = $_POST['text'] . "\n";
               break;
            case 'textb':
               $new_line = '<b>' . $_POST['text'] . "</b>\n";
               break;
            case 'texti':
               $new_line = '<i>' . $_POST['text'] . "</i>\n";
               break;
            case 'texts':
               $new_line = '<small>' . $_POST['text'] . "</small>\n";
               break;
            case 'textu':
               $new_line = '<u>' . $_POST['text'] . "</u>\n";
               break;
            case 'picture':
               $new_line = '<img src="' . $_POST['picture'] . '" alt="' . $_POST['text'] . '"/>' . "\n";
               break;
            case 'urlpict':
               $new_line = '<a href="' . $_POST['link'] . '"><img src="' . $_POST['picture'] . '" alt="' . $_POST['text'] . '"/></a>' . "\n";
               break;
            case 'br':
               $new_line = '<br/>' . "\n";
               break;
            case 'left':
               if($_GET['i'] == 5)
                  $new_line = '<p align="left">' . "\n";
               else
                  $new_line = '</p><p align="left">' . "\n";
               break;
            case 'center':
               if($_GET['i'] == 5)
                  $new_line = '<p align="center">' . "\n";
               else
                  $new_line = '</p><p align="center">' . "\n";
               break;
           case 'right':
               if($_GET['i'] == 5)
                  $new_line = '<p align="right">' . "\n";
               else
                  $new_line = '</p><p align="right">' . "\n";
               break;
            default:
               $new_line = '';
         }

         if($_POST['abr'] == 'yes')
            $new_line .= "\n<br/>\n";

         if($_POST['location'] == 'below')
         {
            // adding new line
            $contents2[] = $new_line;
         }
         if($_POST['location'] == 'rewrite')
         {
            // adding new line
            if($_GET['i'] == 5)
            {
               $adv_link = array_pop($contents2);
               array_pop($contents2);
               $contents2[] = $new_line;
               //$contents2[] = $adv_link;
            }
            else
            {
               array_pop($contents2);
               $contents2[] = $new_line;
            }
         }
         if($_POST['location'] == 'above')
         {
            // adding new line
            $curr_row = array_pop($contents2);
            $contents2[] = $new_line;
            array_push($contents2, $curr_row);
         }
      }
   }
   $fp = fopen("$login/" . addslashes($_GET['page']), 'wb');
   fputs($fp, join('', $contents2));
   fclose($fp);
?>
<wml>
<card id="added" title="added" ontimer="edit.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_GET['page']; ?>"><timer value="15"/>
<p>
Строка изменена<br/>
</p>
</card>
</wml>
<?php
   exit;
}

if(!isset($_GET['page']))
   $_GET['page'] = 'index.wml';

if(preg_match('/[^\w\.]/', $_GET['page']))
{
?>
<wml>
<card id="error" title="error" ontimer="main.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>"><timer value="15"/>
<p align="center">
Неправильное имя страницы
</p>
</card>
</wml>
<?php
   exit;
}

if(isset($_GET['action']) && $_GET['action'] == 'del')
{
   if($_GET['i'] != 5) // строка с первым <p align ...
   {
      $contents = file("$login/" . addslashes($_GET['page']));
      $contents2 = array();
      for($i = 0; $i < count($contents); $i++)
      {
         if($i != $_GET['i'])
            $contents2[] = $contents[$i];
      }
      $fp = fopen("$login/" . addslashes($_GET['page']), 'w');
      fputs($fp, join('', $contents2));
      fclose($fp);
      $message = 'Текст удален';
   }
   else
   {
      $message = 'Данную строку нельзя удалить';
   }
?>
<wml>
<card id="added" title="added" ontimer="edit.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_GET['page']; ?>&amp;"><timer value="15"/>
<p>
<?php echo $message; ?><br/>
</p>
</card>
</wml>
<?php
   exit;
}

$contents = file("$login/" . addslashes($_GET['page']));

?>
<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<card id="Edit" title="Pe&#x0434;a&#x043A;&#x0442;op">
<p>
<?php echo htmlspecialchars($contents[(int)$_GET['i']]);//echo htmlentities($contents[(int)$_GET['i']]); ?><br/>
<a href="edittext.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_GET['page']; ?>&amp;i=<?php echo $_GET['i']; ?>&amp;action=del">&#x0423;&#x0434;a&#x043B;&#x0438;&#x0442;&#x044C;</a><br/>
*********<br/>
<br/>
Te&#x043A;c&#x0442;:<br/>
<input name="text" emptyok="true" value="" title="text"/><br/>
URL:<br/>
<input name="link" emptyok="true" maxlength="150" value="http://" title="link"/><br/>
&#x041A;ap&#x0442;&#x0438;&#x043D;&#x043A;a:<br/>
<input name="picture" emptyok="true" maxlength="150" value="http://" title="picture"/><br/>
Co&#x0437;&#x0434;a&#x0442;&#x044C; &#x043A;a&#x043A;:<br/>
<select name="action">
<option value="link">&#x041B;&#x0438;&#x043D;&#x043A;</option>
<option value="linkb">Жирный линк</option>
<option value="linki">Курсивный линк</option>
<option value="linku">Подчеркнутый линк</option>
<option value="links">Малый линк</option>
<option value="text">Te&#x043A;c&#x0442;</option>
<option value="textb">Жирный текст</option>
<option value="texti">РљСѓСЂСЃРёРІ</option>
<option value="textu">Подчеркнутый</option>
<option value="texts">Малый текст</option>
<option value="picture">&#x041A;ap&#x0442;&#x0438;&#x043D;&#x043A;a</option>
<option value="urlpict">&#x041B;&#x0438;&#x043D;&#x043A; &#x0432; &#x043A;ap&#x0442;&#x0438;&#x043D;&#x043A;e</option>
<option value="br">&lt;br/&gt;</option>
<option value="left">align=left</option>
<option value="center">align=center</option>
<option value="right">align=right</option>
</select><br/>
A&#x0432;&#x0442;o&lt;br/&gt;:<br/>
<select name="abr">
<option value="yes">&#x0414;a</option>
<option value="no">&#x041D;e&#x0442;</option>
</select><br/>
Pac&#x043F;o&#x043B;o&#x0436;e&#x043D;&#x0438;e:<br/>
<select name="location">
<option value="below">H&#x0438;&#x0436;&#x0435;</option>
<option value="rewrite">&#x041F;epe&#x0437;a&#x043F;&#x0438;c&#x044C;</option>
<option value="above">&#x0412;&#x044B;&#x0448;e</option>
</select><br/>
Резать теги:<br/>
<select name="strip">
<option value="yes">Да</option>
<option value="no">Нет</option>
</select><br/>
<anchor title="go">OK<go href="edittext.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_GET['page']; ?>&amp;i=<?php echo $_GET['i']; ?>" method="post">
<postfield name="action" value="$(action)"/>
<postfield name="location" value="$(location)"/>
<postfield name="abr" value="$(abr)"/>
<postfield name="text" value="$(text)"/>
<postfield name="link" value="$(link)"/>
<postfield name="picture" value="$(picture)"/>
<postfield name="strip" value="$(strip)"/>
</go></anchor><br/>
<br/>
<a href="buttons.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_GET['page']; ?>">Co&#x0444;&#x0442;-&#x043A;&#x043B;a&#x0432;&#x0438;&#x0448;&#x0438;</a><br/>
<a href="edittitle.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_GET['page']; ?>&amp;i=<?php echo $_GET['id']; ?>&amp;cp=go">Co&#x0437;&#x0434;a&#x0442;&#x044C; c&#x0442;pa&#x043D;&#x0438;&#x0446;&#x0443; &#x0438;&#x043B;&#x0438; &#x0438;&#x0437;&#x043C;e&#x043D;&#x0438;&#x0442;&#x044C; &#x0437;a&#x0433;o&#x043B;o&#x0432;o&#x043A;</a><br/>
*********<br/>
<a href="edit.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>&amp;page=<?php echo $_GET['page']; ?>">Ha c&#x0442;pa&#x043D;&#x0438;&#x0446;&#x0443;</a><br/>
<a href="main.php?id=<?php echo $id; ?>&amp;p=<?php echo $login; ?>">Меню</a><br/>
&#x0438;&#x043C;&#x044F;:<?php echo $_GET['page']; ?>, Pa&#x0437;&#x043C;ep:<?php echo filesize($login . '/' . $_GET['page']); ?> byte
</p>
</card>
</wml>