PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/inc/post.php

http://0byte.googlecode.com/
PHP | 190 lines | 159 code | 4 blank | 27 comment | 75 complexity | f648d4393571310213b710b459ea1382 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. * THIS FILE DEPRECATED AND IN FUTURE WILL BE REPLACED BY post.rewrited.php
  4. *
  5. * This file is part of 0byte.
  6. *
  7. * 0byte is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 2 of the License.
  10. *
  11. * 0byte is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * See <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. $inser='';
  20. if (request::get_get('pg',0)) {
  21. $inser.=request::get_get('pg',0)."/";
  22. }
  23. if (request::get_get('blog',0)) {
  24. $inser.="blog/".request::get_get('blog',0)."/";
  25. }
  26. $blck="&& blck != 1";
  27. if ($usr->lvl>=$rlvl) {
  28. $blck="";
  29. } else if ($loged) {
  30. $blck='&& (`blck` != 1 || `auth` = "'.$usr->login.'")';
  31. }
  32. if (request::get_get('count',0)) {
  33. $count=request::get_get('count',0);
  34. } else {
  35. $count=10;
  36. }
  37. $favourite=request::get_get('favourite',0);
  38. $pg=request::get_get('pg','');
  39. $draft=request::get_get('draft',0);
  40. $frm=request::get_get("frm",0,0);
  41. if (sizeof($_GET)==0 || ($frm>0 && strlen($pg)<2 && !request::get_get('like',0) && !$favourite && !$draft && !request::get_get('tag',0)
  42. && !request::get_get('auth',0) && !request::get_get('blog',0) && !request::get_get('fnd',0))) {
  43. $sql_get="(SELECT * FROM `post` WHERE `top`=1 ORDER BY `id` DESC) UNION (SELECT * FROM `post` WHERE ratep-ratem >= $to_main $blck && ( `lock` = 0 || ".get_special()." ) ORDER BY id DESC) ORDER BY `top` DESC , `id` DESC";
  44. }
  45. else
  46. if ($loged && $draft) {
  47. $inser.='draft/';
  48. $sql_get="SELECT * FROM `draft` WHERE auth = '".$usr->login."' ORDER BY id DESC ";
  49. echo render_template(TPL_POST_LIST.'/draft.tpl.php', null);
  50. } else if ($loged && $favourite) {
  51. $inser.='favourite/';
  52. $sql_get="SELECT * FROM `favourite`,`post` WHERE `favourite`.`pid`=`post`.`id` && `favourite`.`who` = '".$usr->login."' ORDER BY `post`.`id` DESC";
  53. echo render_template(TPL_POST_LIST.'/favourite.tpl.php', null);
  54. } else if (request::get_get('like',0)>0) {
  55. $tags=db_result(db_query('SELECT `tag` FROM `post` WHERE `id` = %d',request::get_get('like',0)));
  56. $tags_arr=split(",", $tags);
  57. $query="SELECT *, ";
  58. $where=null;
  59. foreach ($tags_arr as $tag) {
  60. $query.="IF(`tag` LIKE '%".mysql_escape_string(trim($tag))."%',1,0)+";
  61. $where.="`tag` LIKE '%".mysql_escape_string(trim($tag))."%' || ";
  62. }
  63. $query=substr($query, 0, strlen($query)-1);
  64. $where=substr($where, 0, strlen($where)-4);
  65. $query.=" AS `rel` FROM `post` WHERE ".$where." ORDER BY `rel` DESC";
  66. $sql_get=$query;
  67. $inser.='like/'.request::get_get('like',0);
  68. }
  69. else
  70. if (request::get_get('tag',0)) {
  71. $sql_get="SELECT * FROM `post` WHERE tag LIKE '%".mysql_escape_string(request::get_get('tag')).",%' ||
  72. tag LIKE '%, ".mysql_escape_string(request::get_get('tag'))."%'
  73. || LOWER(tag) = LOWER('".mysql_escape_string(request::get_get('tag'))."')
  74. || tag = '".mysql_escape_string(request::get_get('tag'))."' || tag LIKE '%,".mysql_escape_string(request::get_get('tag'))."%' $blck ORDER BY id DESC";
  75. $inser.="tag/".htmlspecialchars(request::get_get('tag'))."/";
  76. echo render_template(TPL_POST_LIST.'/tag.tpl.php', array('text'=>htmlspecialchars(request::get_get('tag'))));
  77. } else if (request::get_get('pg','null')==='pers') {
  78. $sql_get="SELECT * FROM `post` WHERE blog = 'own' $blck && ( `lock` = 0 || ".get_special()." ) ORDER BY id DESC ";
  79. } else {
  80. if (request::get_get('auth',0)) {
  81. $sql_get="SELECT * FROM `post` WHERE auth = '".mysql_escape_string(request::get_get('auth'))."' $blck ORDER BY id DESC ";
  82. $inser.="auth/".request::get_get('auth')."/";
  83. $au=1;
  84. } else if (request::get_get('blog',0)) {
  85. $sql_get="SELECT * FROM `post` WHERE blogid = '".intval(request::get_get('blog'))."' $blck ORDER BY id DESC ";
  86. $bl=1;
  87. } else {
  88. $sql_get="SELECT * FROM `post` WHERE blog != 'own' $blck ORDER BY id DESC ";
  89. }
  90. }
  91. if (request::get_get('fnd',0)) {
  92. $fnd=trim(str_replace(" ", "%", request::get_get('fnd')));
  93. $sql_get="SELECT * FROM `post` WHERE ( title LIKE '%".mysql_escape_string($fnd)."%' || text LIKE '%".mysql_escape_string($fnd)."%' || ftext LIKE '%".mysql_escape_string($fnd)."%' || tag LIKE '%".mysql_escape_string($fnd)."%' ) $blck ORDER BY id DESC";
  94. echo render_template(TPL_POST_LIST.'/find.tpl.php', array("text"=>htmlspecialchars(request::get_get('fnd'))));
  95. }
  96. if (request::get_get('pg',0)!=0 && request::get_get('pg',0)=='lenta' && $loged==1) {
  97. $sql_get = 'SELECT * FROM `post` WHERE `blck` = 0 && `auth` != "'.$usr->login.'" && '.get_special().' ORDER BY `id` DESC';
  98. }
  99. $result=db_query($sql_get);
  100. $i=0;
  101. $k=0;
  102. $cur=$_SERVER['REQUEST_URI'];
  103. $cur=str_replace("&","*amp",$cur);
  104. $cur=str_replace("?","*qw",$cur);
  105. $kol=db_num_rows($result);
  106. $result=db_query($sql_get." LIMIT ".$frm." , ".$count);
  107. if ($kol<1 && request::get_get('blog',0)==0) {
  108. if (request::get_get('fnd',0)!=0) {
  109. echo render_error("?????? ?? ???????!");
  110. } else {
  111. redirect($dir.'error/not_found');
  112. }
  113. } else {
  114. if (isset($bl) && $bl==1 && !in_array(request::get_get('blog'), $special_blogs)) {
  115. // $sql_get="SELECT * FROM `blogs` WHERE id = '".intval($_GET['blog'])."' ";
  116. // $resul=mysql_query($sql_get,$sql);
  117. // $rowa = mysql_fetch_assoc($resul);
  118. $rowa= db_fetch_assoc(db_query("SELECT * FROM `blogs` WHERE id = %d ",request::get_get('blog')));
  119. $blg=new blog;
  120. $blg->make($rowa);
  121. // $sql_get="SELECT * FROM `inblog` WHERE blogid = '".intval($_GET['blog'])."' && name =
  122. // '".$usr->login."'";
  123. // $res=mysql_query($sql_get,$sql);
  124. // $ro = mysql_fetch_assoc($res);
  125. $ro=db_fetch_assoc(db_query("SELECT * FROM `inblog` WHERE blogid = %d && name = %s",request::get_get('blog'),$usr->login));
  126. $avatar=0;
  127. $avatar_url=null;
  128. if (strlen($blg->av)>0) {
  129. $avatar=1;
  130. $avatar_url="res.php?t=bl&img=".$blg->av;
  131. }
  132. $in_blog=1;
  133. if ($ro['name']==$usr->login && $ro['out']==0 ) {
  134. $in_blog=0;
  135. }
  136. $owner=1;
  137. if ($blg->owner==$usr->login || $loged==0) {
  138. $owner=0;
  139. }
  140. echo render_template(TPL_POST_LIST.'/blog.tpl.php', array('avatar'=>$avatar,
  141. 'avatar_url'=>$avatar_url,'name'=>$blg->name,'about'=>$blg->about,
  142. 'in_blog'=>$in_blog,'inblog_url'=>"twork.php?wt=mergeblog&amp;id=".$blg->id,
  143. 'owner'=>$owner,'rate'=>$blg->rate(),'ratep_url'=>"twork.php?wt=rateblog&amp;id=".$blg->id."&amp;rate=p&amp;from=".$cur,
  144. 'ratem_url'=>"twork.php?wt=rateblog&amp;id=".$blg->id."&amp;rate=m&amp;from=".$cur));
  145. if ($kol<1) {
  146. echo render_error("???? ????!");
  147. }
  148. } else {
  149. if (@$au==1) {
  150. $alien=new user;
  151. $alien->find(request::get_get('auth'),'av, ratep, ratem',1);
  152. $avatar=0;
  153. $avatar_url=null;
  154. if (strlen($alien->av)>2) {
  155. $avatar=1;
  156. $avatar_url="res.php?t=av&img=".$alien->av;
  157. }
  158. echo render_template(TPL_POST_LIST.'/user.tpl.php', array('avatar'=>$avatar,
  159. 'avatar_url'=>$avatar_url,'name'=>$alien->login,'rate'=>$alien->rate(),
  160. 'ratep_url'=>"twork.php?wt=rateuser&name=".$alien->login."&rate=p&from=".$cur,
  161. 'ratem_url'=>"twork.php?wt=rateuser&name=".$alien->login."&rate=m&from=".$cur));
  162. }
  163. }
  164. while ($row = db_fetch_assoc($result)) {
  165. // if (isset($_GET['hl']) && $_GET['hl']==$row['id']) {
  166. // echo "<a id='hl'></a>";
  167. // }
  168. $posts[$k]=post_echo($row,0,$draft);
  169. if ($posts[$k]->visible) {
  170. if ($posts[$k]->tp==1 || ($posts[$k]->tp!=3 && $posts[$k]->havecut()==1)) {
  171. $full=1;
  172. } else {
  173. $full=0;
  174. }
  175. echo render_template(TPL_POST_LIST.'/bottom.tpl.php', array('show_full'=>$full,
  176. 'id'=>$posts[$k]->id,'comments'=>klist($posts[$k]->id),
  177. 'ratep_url'=>"twork.php?wt=ratepost&amp;id=".$posts[$k]->id."&amp;rate=p&amp;from=".$cur,
  178. 'ratem_url'=>"twork.php?wt=ratepost&amp;id=".$posts[$k]->id."&amp;rate=m&amp;from=".$cur,
  179. 'rate'=>$posts[$k]->rate(),'draft'=>$draft,'rate_num'=>($posts[$k]->ratep+$posts[$k]->ratem)%100));
  180. }
  181. $k++;
  182. }
  183. }
  184. $fnd=request::get_get('fnd',null);
  185. echo render_paginator($inser, $count, $kol, request::get_get('frm',0), '/'.$fnd);
  186. ?>