942,528 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 440
  • PHP RSS
Apr 2nd, 2010
0

Problem wih PHP BBcode

Expand Post »
hi all
I have CMS system with Mysql storage. in this system there are options to add news title, news subject, news theme and image upload features.
i would like to add PHP bbcode options to the theme section of this
code. for ex i need to write smth bold in news body section
here is my CMS
admin.page
PHP Syntax (Toggle Plain Text)
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Bismillah</title>
  7. <script type="text/JavaScript">
  8. <!--
  9. function MM_jumpMenu(targ,selObj,restore){ //v3.0
  10. eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  11. if (restore) selObj.selectedIndex=0;
  12. }
  13. //-->
  14. </script>
  15. </head>
  16.  
  17. <body>
  18. <p>
  19. <?
  20. include("connect.php");
  21.  
  22. include ("image_set.php");
  23. ?>
  24.  
  25. </p>
  26. <p style="font-size:24pt; color:#FF0000;">Xeber elave ele</p>
  27.  
  28. <hr />
  29. Mesajlar :&nbsp;
  30. <?
  31.  
  32. $no=$_POST[no];
  33. $title=$_POST[title];
  34. $subject=$_POST[subject];
  35. $description=$_POST[description];
  36. $aktive=$_POST[aktive];
  37. $search=$_POST[search];
  38. $show=$_POST[show];
  39. $category=$_POST[category];
  40. // image ayarlari burada
  41. $small_image="news_little"; //
  42. $big_image="news_big"; // chmod 777
  43. $big_image_width=640;
  44. $big_image_height=480;
  45. $little_image_width=200;
  46. $little_image_height=150;
  47. //if ($image)
  48. ?>
  49. <? if ($_POST[del])
  50. {// del dugmesine badeldiysa
  51. $query=mysql_query("select * from news where no='$no'");
  52. while($row=mysql_fetch_row($query))
  53. /
  54. { @unlink($row[4]);
  55. @unlink($row[5]);
  56. }
  57. if (mysql_query("delete from news where no='$no'")) echo "image deleted";
  58. else echo "not deleted";
  59. }
  60. ?>
  61. <?
  62. if ($_POST[edit])
  63. {
  64.  
  65. $query=mysql_query("select * from news where no='$no'");
  66. while($row=mysql_fetch_row($query))
  67. {
  68. $no2=$row[0];
  69. $title2=$row[1];
  70. $subject2=$row[2];
  71. $description2=$row[3];
  72. $littleimage2=$row[4];
  73. $image2=$row[5];
  74. $aktive2=$row[7];
  75. }
  76. }
  77. ?>
  78. <? if($_POST["add"])
  79. {
  80. if(strlen($_FILES["image"]["name"])>4)
  81. {
  82.  
  83.  
  84. $find=$_FILES["image"] ;
  85. $to_be_finded = array('з','З','э','Э','р','Р','ь','ц','Ю','ю','Ц','Ь',',',' ','(',')','[',']');
  86. $to_be_changed = array('c','C','i','I','g','G','u','o','S','s','O','U','','_','','','','');
  87. $_FILES["image"]=str_replace($to_be_finded, $to_be_changed, $find);
  88. $image = "$big_image/".$_FILES["image"]["name"];
  89. move_uploaded_file($_FILES["image"]["tmp_name"],$image);
  90. $littleimage = "$small_image/".$_FILES["image"]["name"];
  91. move_uploaded_file($_FILES["image"]["tmp_name"],$littleimage);
  92.  
  93. $icerik = resample($image,$little_image_en,$little_image_boy);
  94. $folder = fopen ($littleimage,"w+");
  95. fwrite($folder,$icerik);
  96. fclose($folder);
  97.  
  98.  
  99. $icerik = resample($image,$big_image_en,$big_image_boy);
  100. $folder = fopen ($image,"w+");
  101. fwrite($folder,$icerik);
  102. fclose($folder);
  103.  
  104. }
  105.  
  106.  
  107. if (!$no)
  108. {
  109.  
  110. if (mysql_query("insert into news values ('','$title','$subject','$description','$littleimage','$image','$aktive', '$category')"))
  111. {echo " cahnged"; $image="";$littleimage="";}
  112. else echo "not changed!";
  113.  
  114. }
  115. else
  116. {
  117. if ($image) $imageek="image='$image',littleimage='$littleimage'";
  118. if (mysql_query("update news set title='$title',subject='$subject',description='$description',aktive='$aktive'$imageek where no='$no'"))
  119. {echo "news added"; $image="";$littleimage="";}
  120. else echo "news not added";
  121. }
  122. }
  123. ?>
  124. <hr />
  125.  
  126. <form id="form1" name="form1" method="post" action="">
  127. available news:
  128. <label>
  129. <select name="no" id="no">
  130. <?
  131. $query=mysql_query("select * from news order by no desc");
  132. while($row=mysql_fetch_row($query))
  133. {
  134. echo "<option value='$row[0]'>$row[1]</option>";
  135. }
  136. ?>
  137.  
  138. </select>
  139.  
  140.  
  141.  
  142.  
  143.  
  144. <label>
  145. <input name="edit" type="submit" id="edit" value="Dьzenle" />
  146. </label>
  147. <label>
  148. <input name="del" type="submit" id="del" value="Sil" />
  149. </label>
  150. <label></label>
  151. </form>
  152. <hr />
  153.  
  154. <form id="form2" name="form2" method="post" action="" enctype="multipart/form-data">
  155. <table width="250" border="1" cellspacing="5" cellpadding="0">
  156. <tr>
  157. <td width="80">no
  158. <input name="no" type="hidden" value="<? echo $no2; ?>" /></td>
  159.  
  160. <td width="100"><label></label> </td>
  161. </tr>
  162. <tr>
  163. <td>Image
  164. <? if($littleimage2)
  165.  
  166. {echo "<img src=$littleimage2 align=right><br />";
  167. //echo "<input name='littleimage' type='hidden' id='littleimage' value='$littleimage2' />";
  168. }
  169. ?>
  170. </td>
  171. <td> <label>
  172. <input name="image" type="file" id="image" />
  173. </label></td>
  174. </tr>
  175. <tr>
  176. <td>Title</td>
  177. <td><input name="title" type="text" id="title" value="<? echo $title2;?>" size="50" /></td>
  178. </tr>
  179. <tr>
  180. <td>Subject</td>
  181. <td><input name="subject" type="text" id="subject" value="<? echo $subject2;?>" size="50" /></td>
  182. </tr>
  183. <tr>
  184. <td>description</td>
  185. <td><label>
  186. <textarea name="description" cols="80" rows="5" id="is"><? echo $description2;?></textarea>
  187. </label></td>
  188. </tr>
  189. <tr>
  190. <td>Aktiv</td>
  191. <td><label>
  192. <input <?php if ($aktive2=="aktive") {echo "checked=\"checked\"";} ?> name="aktive" type="radio" value="aktive" checked="checked" />
  193. aktivate
  194. <input <?php if ($aktive2=="pasif") {echo "checked=\"checked\"";} ?> name="aktive" type="radio" value="pasif" />
  195. do it passive</label></td>
  196. </tr>
  197. <tr>
  198. <td><select name="category">
  199. <option value=default>birini sec</option>
  200. <option value="PHP">PHP</option>
  201. <option value="JavaScript">JavaScript</option>
  202. <option value="CSS">CSS</option>
  203. <option value="Photoshop">Photoshop</option>
  204. <option value="HTML">HTML</option>
  205. </select>
  206.  
  207.  
  208. </td>
  209. <td><input name="add" type="submit" id="add" value="daxil et" />
  210. <label>
  211. <input name="search" type="submit" id="axtar" value="Axtar" />
  212. <input name="show" type="submit" id="show" value="Butun xeberleri show" />
  213. </label></td>
  214. </tr>
  215. </table>
  216. </form>
  217.  
  218. <p>&nbsp;</p>
  219. <?
  220. if (($search) || ($show))
  221. {
  222. if ($search)
  223. {
  224. if ($title) $query=mysql_query("select * from news where title like '%$title%'");
  225. if ($subject) $query=mysql_query("select * from news where subject like '%$subject%'");
  226. if ($description) $query=mysql_query("select * from news where description like '%$description%'");
  227. }
  228. if ($show)
  229. {
  230. $query=mysql_query("select * from news order by no desc");
  231. }
  232. echo "<table border=1>
  233. <tr>
  234. <td>Dьzenle</td>
  235. <td>Sil</td>
  236. <td>No</td>
  237. <td>title</td>
  238. <td>subject</td>
  239. <td>description</td>
  240. <td>littleimage</td>
  241. <td>aktive</td>
  242. </tr>";
  243. while($row=mysql_fetch_row($query))
  244. {echo "
  245. <tr><form action=\"\" method=\"post\"><input name=\"no\" type=\"hidden\" value=\"$row[0]\">
  246.  
  247. <td><input name=\"edit\" type=\"submit\" value=\"deyish\"> </td>
  248. <td><input name=\"del\" type=\"submit\" value=\"Sil\"></td>
  249.  
  250. <td>$row[0]&nbsp;</td>
  251. <td>$row[1]&nbsp;</td>
  252. <td>$row[2]&nbsp;</td>
  253. <td>$row[3]&nbsp;</td>
  254. <td><img src=$row[4]>&nbsp;</td>
  255. <td>$row[6]</td>
  256. </form> </tr>";
  257. }
  258. echo "</table>";
  259. }
  260. ?>
  261. <?php
  262. echo "<a href=\"http://aziko.6te.net\">go the main page</a>";
  263. ?>
  264. </body>
  265. </html>

and image_set.php

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. function resample($image,$max_width,$max_height)
  3. {
  4.  
  5.  
  6. ob_start();
  7.  
  8.  
  9. $im = getimagesize($image);
  10. $width = $im[0];
  11. $height = $im[1];
  12.  
  13.  
  14. $x_ratio = $max_width / $width;
  15. $y_ratio = $max_height / $height;
  16.  
  17. if (($width <= $max_width) and ($height <= $max_height)){
  18. $son_width = $width;
  19. $son_height = $height;
  20. }
  21. else if (($x_aratio * $height) < $max_height){
  22. $son_width = $max_width;
  23. $son_height = ceil($x_ratio * $height);
  24. }
  25. else {
  26. $son_width = ceil($y_ratio * $width);
  27. $son_height = $max_height;
  28. }
  29.  
  30.  
  31. $old = imagecreatefromjpeg($image);
  32. $new = imagecreatetruecolor($son_width,$son_height);
  33.  
  34.  
  35. imagecopyresampled(
  36. $new,$eski,0,0,0,0,
  37. $son_width,$son_height,$width,$height);
  38.  
  39.  
  40. imagejpeg($new,null,-1);
  41. $icerik = ob_get_contents();
  42.  
  43.  
  44. ob_widthd_clean();
  45. imagedestroy($old);
  46. imagedestroy($new);
  47.  
  48. return $icerik;
  49.  
  50. }
  51. ?>
and finally
index.php
PHP Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Dahi Tasarim . CoM</title>
  6. <style type="text/css">
  7. <!--
  8. a:link {
  9. color: #0066FF;
  10. text-decoration: underline;
  11. }
  12. a:visited {
  13. text-decoration: underline;
  14. color: #0033CC;
  15. }
  16. a:hover {
  17. text-decoration: none;
  18. color: #FFFFFF;
  19. }
  20. a:active {
  21. text-decoration: underline;
  22. }
  23. -->
  24. </style></head>
  25.  
  26. <body><center>
  27.  
  28. <? // baglan php yi yukluyoruz
  29. include("connect.php");
  30. define('MAX_PAGE1', 4);
  31. define('MAX_PAGE2', 1);
  32. /
  33. $no=$_GET["no"];
  34.  
  35. $page = $_GET["page"];
  36. $start1 = MAX_PAGE1 * ($page - 1);
  37. $max2 = MAX_PAGE2;
  38. list($total) = mysql_fetch_row($rs1);
  39. $page_amount = ceil($total / MAX_PAGE1);
  40. if (0 == $page){
  41. $page = 1;
  42. }
  43. $start = MAX_PAGE1 * ($page - 1);
  44. $max1 = MAX_PAGE1;
  45. $rs1 = mysql_query("SELECT COUNT(aktive) FROM news") or die("Count query error!");
  46. if (!$no && !$page)
  47. {$query=mysql_query("select * from news where aktive='aktive' order by no desc limit 1");
  48. }
  49. if ($page && !$no) {
  50. $query = mysql_query("SELECT * FROM news where aktive='aktive' ORDER BY no DESC LIMIT $start, $max2") or die("Employee query error!");
  51. }
  52. if ($no)/
  53. {$query=mysql_query("select * from news where no='$no'");
  54. }
  55. while($row=mysql_fetch_row($query))
  56. {
  57. $title=$row[1];
  58. $subject=$row[2];
  59. $theme=$row[3];
  60. $littleimage=$row[4];
  61. $bigimage=$row[5];
  62. $theme=str_replace ("\n","<br />",$theme);
  63.  
  64. }
  65. ?>
  66. <table border="1" cellpadding="10" cellspacing="10" bordercolor="#666666" bgcolor="#CCCCCC">
  67. <tr>
  68. <td width="500" valign="top" bgcolor="#FFCC00" name="bigimage">
  69. <?php if ( !empty( $bigimage ) ): ?>
  70. <img alt="" src="<?=$bigimage; ?>">
  71. <?php else: ?>
  72. <img alt="No image" src="/yukle/news_buyuk/noimage.jpeg">
  73. <?php endif; ?>
  74. <div class="indent1">
  75. <h1><?=$title; ?> <span></span></h1>
  76. <p><?=$theme; ?></p></td>
  77. <td width="170" valign="top" bgcolor="#FF9900">
  78. <?
  79.  
  80.  
  81. define('MAX_PAGE', 4);
  82. $db = mysql_connect("localhost", "username", "password") or die("Couldn't connect to db!");
  83. mysql_select_db("username") or die("Couldn't select db!");
  84. $rs = mysql_query("SELECT COUNT(aktive) FROM news") or die("Count query error!");
  85. list($total) = mysql_fetch_row($rs);
  86. $page_amount = ceil($total / MAX_PAGE);
  87. $page = intval(@$_GET["page"]);
  88. if (0 == $page){
  89. $page = 1;
  90. }
  91. $start = MAX_PAGE * ($page - 1);
  92. $max = MAX_PAGE;
  93. $rs = mysql_query("SELECT no, littleimage, subject, description, title FROM news where aktive='aktive' ORDER BY no
  94. DESC LIMIT $start, $max") or die("Employee query error!");
  95. ?>
  96. <?php
  97.  
  98. while($row1=mysql_fetch_row($rs))
  99. {
  100. $no=$row1[0];
  101. $subject=$row1[2];
  102. $description=$row1[3];
  103. $littleimage=$row1[1];
  104. $title=$row1[4];
  105. ?>
  106. <?php
  107. if(file_exists($littleimage)){
  108. echo "<p><a href='index.php?page=$page&no=$no'>
  109. <img alt='' src='$littleimage' />
  110. <br><span>$title</span></a><br />$subject
  111. </p>";
  112. }
  113. else
  114. {
  115. echo "<p><a href='index.php?page=$page&no=$no'>
  116. <img alt='' src='/yukle/news_buyuk/noimage.jpeg' />
  117. <br><span>$title</span></a><br />$subject
  118. </p>";
  119. }
  120. }
  121.  
  122. ?>
  123. </td></tr>
  124. <tr>
  125. <td colspan="2" bgcolor="#669933" align="left"><ul>
  126. <?
  127. $query=mysql_query("select * from news where aktive='aktive' order by no desc limit 0,20");
  128. // newslerin sadece titlelarini ekranda gosterip link verecegiz
  129. while($row=mysql_fetch_row($query))
  130. {
  131. $no=$row[0];
  132. $title=$row[1];
  133. echo "<li> <a href=index.php?no=$no>$title</a></li>";
  134. }
  135. ?>
  136. </ul></td></tr>
  137. </table>
  138. <table border="0" cellpadding="5" align="center">
  139. <tr><td>Istedigin pageye get:</td>
  140. <?php
  141. for ($i = 1; $i < $page_amount; $i++) {
  142. $txt = $i;
  143. if ($page != $i)
  144. $txt = "<a href=\"" . $_SERVER["PHP_SELF"] . "?page=$i\">$txt</a>";
  145. ?>
  146. <td align="center"><?= $txt ?></td>
  147. <?php
  148. }
  149. ?>
  150. </tr>
  151. </table></center>
  152. <hr>
  153. </div>
  154. <?
  155. if ($query) mysql_free_result($query);
  156. if ($rs) mysql_free_result($rs);
  157. if ($connect) mysql_close($connect);
  158. ?>
  159. </body>
  160. </html>
Similar Threads
Reputation Points: 11
Solved Threads: 2
Posting Whiz in Training
azegurb is offline Offline
244 posts
since Sep 2009
Apr 3rd, 2010
0
Re: Problem wih PHP BBcode
If you want somebody to embed bbcode for you then I don't think many people will offer unless you put some effort into it. I have read that there is a bbcode library or alternatively if that library isn't available on your webhost then you can use the recourse hungry regex.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,003 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP Refresh?
Next Thread in PHP Forum Timeline: I need some help with the array returned by preg_match_all





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC