PageRenderTime 61ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/index.php

http://nanote.googlecode.com/
PHP | 2445 lines | 2025 code | 288 blank | 132 comment | 352 complexity | 658c32630e345e1bbab4318d9a0b612a MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // Nanote - simple flat-file blog script
  3. // Š Zorg <ekumena@gmail.com>, 2007-2011
  4. ERROR_REPORTING(E_ALL);
  5. //date_default_timezone_set('Europe/Moscow');
  6. // ????????? ?????
  7. $domain = @str_replace(array('www.','-'), array('','_'), strtolower($_SERVER['HTTP_HOST']));
  8. $_POST['datadir'] = 'data/'.$domain;
  9. // ????????? ??????
  10. if(!is_dir($_POST['datadir']))
  11. {
  12. mkdir($_POST['datadir']);
  13. chmod($_POST['datadir'], 0777);
  14. $_install = array('.panel', '.pages', '.login', '.blocks', '.cats', '.error404', '1254942727');
  15. foreach($_install as $_c)
  16. {
  17. copy('data/'.$_c, $_POST['datadir'].'/'.$_c);
  18. chmod($_POST['datadir'].'/'.$_c, 0777);
  19. }
  20. }
  21. // ???????? ?????????? ????????
  22. $_glob = unserialize(file_get_contents('data/.settings.blank.global'));
  23. if(file_exists($_POST['datadir'].'/.settings.global'))
  24. {
  25. $_glob = unserialize(file_get_contents($_POST['datadir'].'/.settings.global')) + $_glob;
  26. }
  27. // ??????????? ?????????????
  28. $_s['url'] = '';
  29. // ????????? ????????? ???????
  30. foreach($_glob as $k=>$v)
  31. {
  32. $j = substr($k,0,2);
  33. if($j=='_l') $_l[substr($k,2)] = $v;
  34. if($j=='_s') $_s[substr($k,2)] = $v;
  35. if($j=='_d') $_d[substr($k,2)] = $v;
  36. }
  37. // ????????? ??????
  38. session_start();
  39. // ???? ?????????? ????????
  40. if($_SERVER['REQUEST_METHOD']=='POST' && isset($_POST['sett']) && (isset($_SESSION['adm']) || !trim($_s['pass']))) {
  41. // ? ??????? ??????? ???????
  42. unset($_s['curl']);
  43. unset($_d['curl']);
  44. unset($_s['d']);
  45. unset($_s['pglk']);
  46. unset($_s['slf']);
  47. unset($_s['title']);
  48. unset($_s['plname']);
  49. unset($_s['lang']);
  50. unset($_s['sav_dir']);
  51. unset($_s['ver']);
  52. if(trim($_POST['_spass'])) $_POST['_spass'] = md5($_POST['_spass']);
  53. else $_POST['_spass'] = $_glob['_spass'];
  54. foreach($_POST as $k=>$v)
  55. {
  56. // ????????
  57. if(stristr($k, 'plugins_'))
  58. {
  59. $_glob['plugins'][str_replace('plugins_', '', $k)] = $v;
  60. }
  61. else $_glob[$k] = stripslashes(str_replace(array("\r", "\n"), array('',"\n"), $v));
  62. }
  63. //$_loc['catid'][727] = array('goodcat', '??????? ?????????', 'template', '1-?????????? ? ?????? ?????????', '1-?????????? ? ?????', '1-? ?????????', '1-? rss', '??????');
  64. //$_loc[cat][id] = array(727, 353);
  65. // ?????? ????????
  66. if(isset($_glob['plugins']))
  67. {
  68. foreach($_glob['plugins'] as $pk=>$pv)
  69. {
  70. $_glob['plugins'][$pk] = isset($_POST['plugins_'.$pk]) ? 1 : 0;
  71. }
  72. }
  73. fsave($_POST['datadir'].'/.settings.global', 'w+', serialize($_glob));
  74. // ???????? ????????? ?????????
  75. if(!file_exists($_POST['datadir'].'/.settings.local'))
  76. {
  77. copy('data/.settings.blank.local', $_POST['datadir'].'/.settings.local');
  78. chmod($_POST['datadir'].'/.settings.local', 0777);
  79. }
  80. // ????????? ?????????
  81. header('Location: '.$_SERVER['HTTP_REFERER']);
  82. }
  83. // ???????? ????????? ????????
  84. // ???????? ?????????? ????????
  85. $lfile = file_exists($_POST['datadir'].'/.settings.local') ? $_POST['datadir'].'/.settings.local' : 'data/.settings.blank.local';
  86. $_loc = unserialize(file_get_contents($lfile));
  87. $_v = $_GET + $_POST;
  88. $_c = $_COOKIE;
  89. //
  90. $_v['ver'] = 0.389;
  91. // ???????? ??????
  92. if(isset($_FILES['nefis']['name']))
  93. {
  94. for ($i=0; $i<sizeof($_FILES['nefis']['name']); $i++)
  95. {
  96. if(trim($_FILES['nefis']['tmp_name'][$i]))
  97. {
  98. $name = strtolower(basename($_FILES['nefis']['name'][$i]));
  99. @copy($_FILES['nefis']['tmp_name'][$i], 'files/'.$name);
  100. $_upfiles[] = $name;
  101. }
  102. }
  103. }
  104. // null
  105. $_v['pg'] = $_s['d'] = $pst['title'] = $_s['pglk'] = $_intpl['inheader']= $_intpl['infooter'] = '';
  106. // ??????????? ?? magic quotes ??-????????
  107. if(get_magic_quotes_gpc())
  108. {
  109. foreach($_v as $k=>$v)
  110. {
  111. @$_v[$k] = stripslashes($v);
  112. }
  113. }
  114. // ????????? ?????? (todo: ????? ???????)
  115. $_error[1] = '?? ?? ?????? ???????????? ??? ??????.';
  116. $_error[2] = '???????? ??????????? ???.';
  117. $_error[3] = '??????? ??????????? ???.';
  118. $_error[4] = '? ????????? ???????????? ?????.';
  119. $_error[5] = '????????? ?????? ?????????? :)';
  120. $_error[6] = '?????? ?? ????? ????????? :(';
  121. $_error[7] = '???????? ?????? ???? ?????? 3 ???????? ? ???????? ?? ?????? ?? ?????!';
  122. $_success[1] = '??????????? ???????????!';
  123. $_success[2] = '?????? ????????? Nanote.';
  124. $_success[3] = '????? ????????? ??????? ????????.';
  125. $_title[1] = $_s['bname'].' - ?????';
  126. $_title[2] = $_s['bname'].' - ????????';
  127. // ?????? ??? ??????? sitemap
  128. $_urls['sitemap'] = explode("\n", $_s['urlsitemaptx']);
  129. // ?????? ?????
  130. $_urls['ping'] = explode("\n", $_s['urlpingtx']);
  131. // ??????? .htaccess ? ?????????? - ??? ????????
  132. if(is_file('.htaccess')) $_s['curl'] = 1;
  133. // ????????? ?????????? ????????
  134. $_s['slf'] = $_SERVER['PHP_SELF'];
  135. $_lk['rsslink'] = rsslink();
  136. // ??????? ?????????? base url
  137. if(!trim($_s['url'])) $_s['url'] = 'http://'.$_SERVER['HTTP_HOST'] . str_replace('index.php','',$_s['slf']);
  138. $s = $_SERVER['QUERY_STRING'];
  139. $e = explode('/', $s);
  140. if(isset($e[1]) && is_dir($_SERVER['DOCUMENT_ROOT'].'/'.$e[1]))
  141. {
  142. $s = str_replace($e[1].'/','',$s);
  143. }
  144. if(substr($s, (strlen($s)-1), 1)=='/') $s = substr($s, 0, (strlen($s)-1));
  145. $rq = explode($_s['px'], substr($s,1));
  146. // ???, ?????? ?????, ??????! :)
  147. if(isset($rq) && isset($_loc['alias'][$rq[0]]))
  148. {
  149. $rq[1] = $_loc['alias'][$rq[0]];
  150. $rq[0] = 'p';
  151. $direct = 1;
  152. }
  153. // ??? ?? ?????? ?????? ?????, ? ???? ????????? ??????
  154. if(isset($_loc['customurl'][$_SERVER['QUERY_STRING']]) || isset($_loc['customurl'][substr($_SERVER['QUERY_STRING'],1)]))
  155. {
  156. $rq[0] = 'p';
  157. $rq[1] = isset($_loc['customurl'][$_SERVER['QUERY_STRING']]) ? $_loc['customurl'][$_SERVER['QUERY_STRING']] : $_loc['customurl'][substr($_SERVER['QUERY_STRING'],1)];
  158. $direct = 1;
  159. }
  160. // ?????? ?????? (?????? ?? ????? ?????)
  161. if(isset($rq) && !isset($direct))
  162. {
  163. if(isset($rq[3]) && is_numeric($rq[2]) && is_numeric($rq[1]) && is_numeric($rq[0]))
  164. {
  165. $e = explode(':',$rq[3]);
  166. $rq[1] = mktime($e[0],$e[1],$e[2],$rq[1],$rq[2],$rq[0]);
  167. $rq[0] = 'p';
  168. }
  169. else if(isset($rq[2]) && isset($_loc['alias'][$rq[2]]))
  170. {
  171. $rq[0] = 'p'; $rq[1] = $_loc['alias'][$rq[2]];
  172. }
  173. else if((isset($rq[1]) && is_numeric($rq[1]) && strlen($rq[1]) == 2 && $rq[0] != 's') || strlen($rq[0]) == 4)
  174. {
  175. if(isset($rq[2]) && !is_numeric($rq[2]) && !isset($_loc['alias'][$rq[2]]))
  176. {
  177. $_v['pg'] = '.error404';
  178. }
  179. else
  180. {
  181. $y=(isset($rq[0]) ? $rq[0] : date('Y'));
  182. $m=(isset($rq[1]) ? $rq[1] : 12);
  183. $dim=days_in_month($m, $y);
  184. $mon = (isset($rq[1]) ? $rq[1] : 1);
  185. $day1 = (isset($rq[2]) ? $rq[2] : 1);
  186. // ?????? ????????? ?????? ? ?????? ???
  187. $_metatitle = $_title[1].' '.implode('-',$rq);
  188. $_intpl['inheader'] .= '<meta name="robots" content="noindex,follow,noodp,noydir" />'."\n";
  189. $_s['t_start'] = mktime(0, 0, 1, $mon, $day1, (int) $y) + ($_s['tmset'] * 3600);
  190. $day2 = (isset($rq[2]) ? $rq[2] : $dim);
  191. $_s['t_end'] = mktime(23, 59, 59, $m, $day2, (int) $y) + ($_s['tmset'] * 3600);
  192. }
  193. unset($rq);
  194. }
  195. }
  196. // ?????? ??????????
  197. if(!trim($_s['pass']))
  198. {
  199. $rq[0] = 'pg';
  200. $rq[1] = '.panel';
  201. // javascript-???????????
  202. @$_s['pglk'] .=
  203. '<script>
  204. var notify_msg = "' . $_success[2] . '";
  205. </script>';
  206. }
  207. // ?????? ???????
  208. $et = explode('-tpl-', $main_template = file_get_contents($_s['tpd'].'/index.php'));
  209. $se = sizeof($et);
  210. for($i=0;$i<$se;$i++)
  211. {
  212. if($i%2)
  213. {
  214. $bn = explode('/-',$et[$i]);
  215. $_tplin[substr($bn[1],0,strlen($bn[1]))] = $bn[0];
  216. }
  217. }
  218. if(isset($_v['ppp'])) $_s['ppp']=$_v['ppp'];
  219. else if(@trim($rq[0]))
  220. {
  221. if($rq[0]=='s')
  222. {
  223. $_v['sp'] = $rq[1];
  224. if(isset($rq[2]))
  225. {
  226. $_v['sw'] = urldecode($rq[2]);
  227. $_v['act']='sw';
  228. }
  229. // ?????? ????????? ? ?????? ???
  230. $_metatitle = $_title[2].' '.ceil($_v['sp']/$_s['ppp']+1).' '.@$rq[2];
  231. $_intpl['inheader'] .= '<meta name="robots" content="noindex,follow,noodp,noydir" />'."\n";
  232. }
  233. else if($rq[0]=='ep') { $_v['act']=$rq[0]; $_v['pg']=@$rq[1]; }
  234. else if($rq[0]=='bk') { $_v['act']=$rq[0]; $_v['p']=@$rq[1]; }
  235. else if($rq[0]=='p') $_v['p']=$rq[1];
  236. else if($rq[0]=='sw') { $_v['sw']=urldecode($rq[1]); $_v['act']='sw'; }
  237. else if($rq[0]=='pg') $_v['pg']=str_replace('-','_',$rq[1]);
  238. else if($rq[0]=='unban') $_v['act']='unban';
  239. else if(isset($rq[1]) && trim($rq[1])) { $_v['act']=$rq[0]; $_v['p']=$rq[1]; }
  240. else $_v['act']=$rq[0];
  241. }
  242. function fsave($f,$m,$t) {
  243. $fh = fopen($f, $m);
  244. flock($fh, LOCK_EX);
  245. fwrite($fh, $t);
  246. flock($fh, LOCK_UN);
  247. fclose($fh);
  248. @chmod($f, 0777);
  249. }
  250. function _get($s, $a, $b) {
  251. $z = strpos ($s, $a);
  252. if ($z !== false) {
  253. $z += strlen ($a);
  254. $y = strpos ($s, $b);
  255. if ($y !== false) return substr ($s, $z, $y - $z);
  256. }
  257. return false;
  258. }
  259. function getposts() {
  260. global $_loc, $_s;
  261. $d = dir($_POST['datadir']);
  262. while (false !== ($en = $d->read()))
  263. {
  264. // ???????? ??? ?????, ??? ??????
  265. if(is_numeric($en))
  266. {
  267. // ????????? ?? ?????? ?? (????????) ? ?? ?????????? ?? ??????????
  268. $allow = ((!@$_loc['draft'][$en] && $en < time()) || isset($_SESSION['adm'])) ? 1 : 0;
  269. if($allow)
  270. {
  271. // ???? ????????? ?? ???????
  272. if(isset($_s['t_start']) && isset($_s['t_end']))
  273. {
  274. if(($en >= $_s['t_start']) && ($en <= $_s['t_end'])) $psts[] = $en;
  275. }
  276. else $psts[] = $en;
  277. }
  278. }
  279. }
  280. $d->close();
  281. if(isset($psts)) return $psts;
  282. else return false;
  283. }
  284. function posttemplates() {
  285. global $_loc, $_s;
  286. $d = dir($_s['tpd']);
  287. while (false !== ($et = $d->read()))
  288. {
  289. if (stristr($et, 'post-') && (!stristr($et, 'default') && !stristr($et, 'full')))
  290. {
  291. $posttpl[$et] = str_replace('.php', '', $et);
  292. }
  293. }
  294. return $posttpl;
  295. }
  296. // ???????????? ????????? ??????
  297. function wordsrate($text, $size=6)
  298. {
  299. $text = str_replace(array('.',"\n"), ' ', $text);
  300. $text = preg_replace('| +|', ' ', clean(strip_tags($text)));
  301. $words = explode(' ', $text);
  302. $num = 0;
  303. $cword = array();
  304. foreach($words as $word)
  305. {
  306. $len = function_exists('mb_strlen') ? mb_strlen($word, 'UTF-8') : strlen($word);
  307. if($len > 4)
  308. {
  309. $num++;
  310. $cword[] = function_exists('mb_strtolower') ? mb_strtolower($word, 'UTF-8') : strtolower($word);
  311. if($num>$size) break;
  312. }
  313. }
  314. return $cword;
  315. }
  316. /**
  317. * Description of Image_Processor
  318. *
  319. * @author mrak, http://pnk.pp.ua
  320. */
  321. class Image_Processor {
  322. protected $contentType = null;
  323. protected $img = null;
  324. protected $tmpname = null;
  325. protected function getMime($fileName) {
  326. return mime_content_type($fileName);
  327. }
  328. public function __construct($fileName) {
  329. // ???? ???? ? ??? ????????
  330. if (file_exists('files/'.$fileName))
  331. {
  332. $fileName = 'files/'.$fileName;
  333. }
  334. else
  335. {
  336. // ???????? ???????? ????????? ???????????
  337. $tmpexp = explode('/', $fileName);
  338. $this->tmpname = 'files/'.$tmpexp[sizeof($tmpexp)-1];
  339. copy($fileName, $this->tmpname);
  340. $fileName = $this->tmpname;
  341. }
  342. if (is_readable($fileName)) {
  343. if(stristr($fileName,'png')) $this->contentType = 'image/png';
  344. if(stristr($fileName,'jpg') || stristr($fileName,'jpeg')) $this->contentType = 'image/jpeg';
  345. if(stristr($fileName,'gif')) $this->contentType = 'image/gif';
  346. switch ($this->contentType) {
  347. case 'image/png':
  348. $img = imagecreatefrompng($fileName);
  349. break;
  350. case 'image/jpeg':
  351. $img = imagecreatefromjpeg($fileName);
  352. break;
  353. case 'image/gif':
  354. $img = imagecreatefromgif($fileName);
  355. break;
  356. default:
  357. throw new Exception('Wrong content type "' . $this->contentType . '"');
  358. break;
  359. }
  360. if (!is_resource($img)) {
  361. throw new Exception('Could not read image');
  362. }
  363. $this->img = $img;
  364. } else {
  365. throw new Exception('Cannot read file "' . $fileName . '"');
  366. }
  367. }
  368. public function resample($newwidth, $newheight, $newFileName) {
  369. global $_s, $_upfiles;
  370. // ??? ???????? ???? ???? ?????????
  371. if (!file_exists('files/'.$newFileName))
  372. {
  373. $tmpexp = explode('/', $newFileName);
  374. $newFileName = $tmpexp[sizeof($tmpexp)-1];
  375. }
  376. if($this->tmpname != null && !$_s['grubimg'])
  377. {
  378. unlink($this->tmpname);
  379. }
  380. else
  381. {
  382. $_upfiles[] = str_replace(array('/','files'), '', $this->tmpname);
  383. }
  384. $height = imagesy($this->img);
  385. $width = imagesx($this->img);
  386. $k = min($newheight / $height, $newwidth / $width);
  387. if ($k >= 1) {
  388. $k = 1;
  389. }
  390. $newwidth = $k * $width;
  391. $newheight = $k * $height;
  392. $thumb = imagecreatetruecolor($newwidth, $newheight);
  393. imagecopyresampled($thumb, $this->img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  394. // ???????? ????? ?????????
  395. $rname = 'files/thumb_'.$newFileName;
  396. switch ($this->contentType) {
  397. case 'image/png':
  398. imagepng($thumb, $rname);
  399. break;
  400. case 'image/jpeg':
  401. imagepng($thumb, $rname);
  402. break;
  403. case 'image/gif':
  404. imagepng($thumb, $rname);
  405. break;
  406. default:
  407. throw new Exception('DEATH');
  408. break;
  409. }
  410. }
  411. }
  412. // ?????? rss (???????? ?? ?????????? ?????)
  413. function imp_rss($r)
  414. {
  415. if(@$f = file_get_contents($r))
  416. {
  417. $ex=explode('<item>',$f);
  418. for($i=1; $i<sizeof($ex); $i++)
  419. {
  420. $_rss['title'] = _get($ex[$i],'<title>','</title>');
  421. $_rss['text'] = _get($ex[$i],'<description>','</description>');
  422. $_rss['time'] = strtotime(_get($ex[$i],'<pubDate>','</pubDate>'));
  423. foreach($_rss as $k=>$v) $_rss[$k] = str_replace(array('<![CDATA[',']]>'),'',$v);
  424. $_rss['text'] = strtr($_rss['text'], array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
  425. fsave($_POST['datadir'].'/'.$_rss['time'],'w+',$_rss['title']."\n".str_replace(array("\r","\n"),'',$_rss['text'])."\n[comments]\n");
  426. }
  427. return '????? ????????????? ['.(sizeof($ex)-1).'] ???????.';
  428. } else return '????? ??????????';
  429. }
  430. function _curl($url, $time, $nobody=true, $ref=false) {
  431. if(function_exists('curl_init') && $ch = curl_init())
  432. {
  433. curl_setopt($ch, CURLOPT_URL, $url);
  434. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
  435. if($nobody) curl_setopt($ch, CURLOPT_HEADER, false);
  436. if($nobody) curl_setopt($ch, CURLOPT_NOBODY, true);
  437. if($ref) curl_setopt($ch, CURLOPT_REFERER, $ref);
  438. curl_setopt($ch, CURLOPT_TIMEOUT, $time);
  439. curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
  440. curl_exec($ch);
  441. curl_close($ch);
  442. return true;
  443. }
  444. else return false;
  445. }
  446. function ping($url, $blogname, $blogurl) {
  447. global $_s;
  448. $blogname = $blogname ? $blogname : $_s['bname'];
  449. $tb_send='<?xml version="1.0"?>
  450. <methodCall>
  451. <methodName>weblogUpdates.ping</methodName>
  452. <params>
  453. <param>
  454. <value>'.$blogname.'</value>
  455. </param>
  456. <param>
  457. <value>'.$blogurl.'</value>
  458. </param>
  459. </params>
  460. </methodCall>';
  461. @$host = explode('/', str_replace('http://', '', $url), 2);
  462. $tb_sock = fsockopen($host[0], 80);
  463. fputs($tb_sock, "POST /" . @$host[1] . " HTTP/1.1\r\n");
  464. fputs($tb_sock, "User-Agent: Nanote\r\n");
  465. fputs($tb_sock, "Host: " . $host[0] . "\r\n");
  466. fputs($tb_sock, "Content-Type: text/xml\r\n");
  467. fputs($tb_sock, "Content-length: " . strlen($tb_send) . "\r\n");
  468. fputs($tb_sock, "Connection: close\r\n\r\n");
  469. fputs($tb_sock, $tb_send);
  470. while (!feof($tb_sock))
  471. {
  472. @$response .= fgets($tb_sock, 128);
  473. }
  474. fclose($tb_sock);
  475. strpos($response, '<error>0</error>') ? $return = true : $return = $response;
  476. return $return;
  477. }
  478. function days_in_month($a_month, $a_year) {
  479. return date('t', strtotime($a_year . '-' . $a_month . '-01'));
  480. }
  481. function rus2lat($str) {
  482. // ???????? ?????????????? ???? ?? ??????? ??? WP RusToLat, ????? Andrey Serebryakov
  483. $iso = array(
  484. "?"=>"YE","?"=>"I","?"=>"G","?"=>"i","?"=>"","?"=>"ye","?"=>"g",
  485. "?"=>"A","?"=>"B","?"=>"V","?"=>"G","?"=>"D",
  486. "?"=>"E","?"=>"YO","?"=>"ZH","?"=>"I",
  487. "?"=>"Z","?"=>"I","?"=>"J","?"=>"K","?"=>"L",
  488. "?"=>"M","?"=>"N","?"=>"O","?"=>"P","?"=>"R",
  489. "?"=>"S","?"=>"T","?"=>"U","?"=>"F","?"=>"X",
  490. "?"=>"C","?"=>"CH","?"=>"SH","?"=>"SHH","?"=>"'",
  491. "?"=>"Y","?"=>"","?"=>"E","?"=>"YU","?"=>"YA",
  492. "?"=>"a","?"=>"b","?"=>"v","?"=>"g","?"=>"d",
  493. "?"=>"e","?"=>"yo","?"=>"zh","?"=>"i",
  494. "?"=>"z","?"=>"i","?"=>"j","?"=>"k","?"=>"l",
  495. "?"=>"m","?"=>"n","?"=>"o","?"=>"p","?"=>"r",
  496. "?"=>"s","?"=>"t","?"=>"u","?"=>"f","?"=>"x",
  497. "?"=>"c","?"=>"ch","?"=>"sh","?"=>"shh","?"=>"",
  498. "?"=>"y","?"=>"","?"=>"e","?"=>"yu","?"=>"ya",
  499. "Ť"=>"","ť"=>"","—"=>"",' '=>'_','"'=>'','@'=>'',
  500. '^'=>'','|'=>'','.'=>'','<'=>'','>'=>'','…'=>''
  501. );
  502. return strtolower(strtr($str,$iso));
  503. }
  504. function resizeimg($arNextMatch)
  505. {
  506. global $_s;
  507. $img = $arNextMatch[0];
  508. preg_match("/src=\"(.*)\/(.*?)\"/i", $img, $arMatch);
  509. $pefix = $arMatch[1];
  510. $src = $arMatch[2];
  511. // ????????? ?? ???????????
  512. if (!file_exists('files/'.$src))
  513. {
  514. $src = $pefix . '/' . $src;
  515. }
  516. $imgProc = new Image_Processor($src);
  517. $imgProc->resample($_s['thumbsize'], $_s['thumbsize'], $src);
  518. if($_s['grubimg'])
  519. {
  520. $tmpexp = explode('/', $src);
  521. $arNextMatch[0] = str_replace($src, '/files/'.$tmpexp[sizeof($tmpexp)-1], $arNextMatch[0]);
  522. }
  523. return $arNextMatch[0];
  524. }
  525. function replacethumbs($arNextMatch)
  526. {
  527. global $_s;
  528. $img = $arNextMatch[0];
  529. preg_match("/src=\"(.*)\/(.*?)\"/i", $img, $arMatch);
  530. preg_match("/src=\"(.*)\.(.*?)\"/i", $img, $flMatch);
  531. $pefix = $arMatch[1];
  532. $src = $arMatch[2];
  533. $tmpexp = explode('/', $src);
  534. $filename = $tmpexp[sizeof($tmpexp)-1];
  535. $img = str_replace($pefix.'/', '', $img);
  536. $img = str_replace($src, $_s['url'].'files/thumb_'.$src, $img);
  537. if(!stristr($pefix,'http')) $link = $_s['imgtpl'] ? imglk($_s['url'].'files/'.$src) : $_s['url'].'files/'.$src;
  538. else $link = $_s['imgtpl'] ? imglk($flMatch[1].'.'.$flMatch[2]) : $flMatch[1].'.'.$flMatch[2];
  539. if(file_exists('files/'.$filename)) $link = $_s['imgtpl'] ? imglk($_s['url'].'files/'.$src) : $_s['url'].'files/'.$src;
  540. return '<a href="'.$link.'" rel="nofollow" class="fullsizeimg">'.$img.'</a>';
  541. }
  542. function plk($p) {
  543. global $_s, $_loc;
  544. $x = isset($_s['curl']) ? '' : '?/';
  545. if(isset($_loc['customurl'][$p])) { $l = $_loc['customurl'][$p]; }
  546. else if(isset($_loc['alias'][$p])) $l = date('Y/m/',$p).$_loc['alias'][$p];
  547. else $l = date('Y/m/d/H:i:s',$p).'';
  548. return $_s['url'].$x.$l;
  549. }
  550. function pgk($p) {
  551. global $_s;
  552. return isset($_s['curl']) ? $_s['url'].'pg/'.$p : $_s['url'].'?/pg/'.$p;
  553. }
  554. function alk($p,$a=false) {
  555. global $_s, $_v;
  556. $a = $a ? '/'.$a : '';
  557. return isset($_s['curl']) ? $_s['url'].$p.$a : $_s['url'].'?/'.$p.$a;
  558. }
  559. function slk($p, $sw=false) {
  560. global $_s, $_v;
  561. $a = isset($_v['sw']) ? '/'.$_v['sw'] : '';
  562. return isset($_s['curl']) ? $_s['url'].'s/'.$p.$a : $_s['url'].'?/s/'.$p.$a;
  563. }
  564. function swlk($p) {
  565. global $_s;
  566. $a = isset($_v['s']) ? '/s/'.$_v['s'] : '';
  567. return isset($_s['curl']) ? $_s['url'].'sw/'.$p.$a : $_s['url'].'?/sw/'.$p.$a;
  568. }
  569. function dtlk($p) {
  570. global $_s;
  571. return isset($_s['curl']) ? $_s['url'].$p : $_s['url'].'?/'.$p;
  572. }
  573. function ctlk($p) {
  574. global $_s, $_loc;
  575. $alias = $_loc['catid'][$p][0];
  576. return isset($_s['curl']) ? $_s['url'].'t/'.$p : $_s['url'].'?/t/'.$p;
  577. }
  578. function uslk($p, $mail) {
  579. global $_s;
  580. return $_s['url'].'?unsubscribe='.$p.'&mail='.$mail;
  581. }
  582. function rsslink() {
  583. global $_s;
  584. return alk($_s['rsstpl']);
  585. }
  586. function imglk($img) {
  587. global $_s;
  588. return $_SERVER['PHP_SELF'].'?fullsize='.$img;
  589. }
  590. // ????????? ?????? ?? ?????
  591. function datelinks($time, $sufx = '-', $hours = false)
  592. {
  593. // ???? = ?????? ?? ?????
  594. $d = date('d', $time);
  595. $m = date('m', $time);
  596. $y = date('Y', $time);
  597. $Hi = date('H:i', $time);
  598. $_hi = $hours ? ' '.$Hi : '';
  599. // ?????????? ?????? ?? ?????
  600. return '<a href="' . dtlk($y.'/'.$m.'/'.$d) . '" rel="nofollow">' . $d .
  601. '</a>'.$sufx.'<a href="' . dtlk($y.'/'.$m) . '" rel="nofollow">' . $m .
  602. '</a>'.$sufx.'<a href="' . dtlk($y) . '" rel="nofollow">' . $y . '</a> '.$_hi;
  603. }
  604. function cd($f) {
  605. return 'onClick="return confirm(\'??????????? ???????? ['.htmlspecialchars($f).']\')"';
  606. }
  607. function postdata($from, $move = false)
  608. {
  609. global $_loc;
  610. if(isset($_loc['alias'][$from]))
  611. {
  612. if($move) $_loc['alias'][$_loc['alias'][$from]] = $move;
  613. unset($_loc['alias'][$_loc['alias'][$from]]);
  614. }
  615. if(isset($_loc['alias'][$from]))
  616. {
  617. if($move) $_loc['alias'][$move] = $_loc['alias'][$from];
  618. unset($_loc['alias'][$from]);
  619. }
  620. if(isset($_loc['customurl'][$from]))
  621. {
  622. if($move)
  623. {
  624. $_loc['customurl'][$_loc['customurl'][$from]] = $move;
  625. $_loc['customurl'][$move] = $_loc['customurl'][$from];
  626. }
  627. unset($_loc['customurl'][$_loc['customurl'][$from]]);
  628. unset($_loc['customurl'][$from]);
  629. }
  630. if(isset($_loc['subs'][$from]))
  631. {
  632. if($move) $_loc['subs'][$move] = $_loc['subs'][$from];
  633. unset($_loc['subs'][$from]);
  634. }
  635. if(isset($_loc['seelog'][$from]))
  636. {
  637. if($move) $_loc['seelog'][$move] = $_loc['seelog'][$from];
  638. unset($_loc['seelog'][$from]);
  639. }
  640. if(isset($_loc['template'][$from]))
  641. {
  642. if($move) $_loc['template'][$move] = $_loc['template'][$from];
  643. unset($_loc['template'][$from]);
  644. }
  645. if(isset($_loc['draft'][$from]))
  646. {
  647. if($move) $_loc['draft'][$move] = $_loc['draft'][$from];
  648. unset($_loc['draft'][$from]);
  649. }
  650. if(isset($_loc['comments'][$from]))
  651. {
  652. if($move) $_loc['comments'][$move] = $_loc['comments'][$from];
  653. unset($_loc['comments'][$from]);
  654. }
  655. if(isset($_loc['cat'][$from]))
  656. {
  657. if($move) $_loc['cat'][$move] = $_loc['cat'][$from];
  658. unset($_loc['cat'][$from]);
  659. }
  660. }
  661. function savepost($title = false, $text = false)
  662. {
  663. global $_loc, $_s, $_v, $_l, $_lk, $plugins, $pst, $extra_options, $_urls, $_upfiles;
  664. // ??????????
  665. if($text)
  666. {
  667. $_v['title'] = $title;
  668. $_v['text'] = $text;
  669. }
  670. if (!isset($_v['title']) || !isset($_v['text']))
  671. {
  672. // ?????? ????
  673. @$extra_options = $_loc['fields'][$_loc['template'][$_v['p']]];
  674. if (isset($_v['p']))
  675. {
  676. $pst = ptinfo($_v['p']);
  677. $pst['text'] = htmlspecialchars(str_replace(array("\r", "\n"), array('',"\n"), $pst['text']), ENT_QUOTES);
  678. // ???????? ?????????
  679. if(isset($plugins['template.form-post']))
  680. {
  681. rsort($plugins['template.form-post']);
  682. foreach($plugins['template.form-post'] as $func)
  683. {
  684. if(function_exists($func)) $func();
  685. }
  686. }
  687. include $_s['tpd'].'/form-post.php';
  688. exit();
  689. }
  690. else
  691. {
  692. // ???????? ?????????
  693. if(isset($plugins['template.form-post']))
  694. {
  695. rsort($plugins['template.form-post']);
  696. foreach($plugins['template.form-post'] as $func)
  697. {
  698. if(function_exists($func)) $func();
  699. }
  700. }
  701. include $_s['tpd'].'/form-post.php';
  702. exit();
  703. }
  704. }
  705. else
  706. {
  707. if(!@trim($_v['p']))
  708. {
  709. $_v['p'] = time();
  710. $_new = true;
  711. }
  712. @$newdate = strtotime($_v['dated']);
  713. if(!isset($_new) && $newdate && $newdate != $_v['p'])
  714. {
  715. postdata($_v['p']);
  716. @unlink($_POST['datadir'].'/'.$_v['p']);
  717. $_v['p'] = $newdate;
  718. }
  719. if(isset($_new) && $newdate && $newdate > time())
  720. {
  721. $_v['p'] = $newdate;
  722. }
  723. if(trim($_v['title']))
  724. {
  725. $lat = str_replace('_','-',rus2lat(clean($_v['title'])));
  726. // ?????? ?? ????????????? url (???????? ?????????? ??????????)
  727. $num = 2;
  728. while(isset($_loc['alias'][$lat.'-'.$num])) $num++;
  729. $lat = isset($_loc['alias'][$lat]) ? $lat . '-' . $num : $lat;
  730. $_loc['alias'][$lat] = $_v['p'];
  731. $_loc['alias'][$_v['p']] = $lat;
  732. }
  733. // ???????? url
  734. if(@trim($_v['alias']))
  735. {
  736. if(isset($_loc['customurl'][$_v['p']]))
  737. {
  738. unset($_loc['customurl'][$_loc['customurl'][$_v['p']]]);
  739. unset($_loc['customurl'][$_v['p']]);
  740. }
  741. $_loc['customurl'][$_v['alias']] = $_v['p'];
  742. $_loc['customurl'][$_v['p']] = $_v['alias'];
  743. }
  744. // ??????????? ???/????
  745. if(isset($_v['comments'])) $_loc['comments'][$_v['p']] = 1;
  746. else $_loc['comments'][$_v['p']] = 0;
  747. // ?????? ??????
  748. $_loc['template'][$_v['p']] = isset($_v['template']) ? $_v['template'] : '';
  749. // ????????
  750. $_loc['draft'][$_v['p']] = isset($_v['draft']) ? 1 : 0;
  751. // ?????????(?)
  752. $_loc['cat'][$_v['p']] = array(explode(',', $_v['category']));
  753. // ????????? ????
  754. foreach($_v as $ke=>$va)
  755. {
  756. if(strstr($ke, 'input_'))
  757. {
  758. @$_loc[$ke][$_v['p']] = $va;
  759. }
  760. }
  761. // ??????
  762. if($_s['thumbson'])
  763. {
  764. $_v['text'] = preg_replace_callback("/<img(.*?)>/i", "resizeimg", $_v['text']);
  765. }
  766. // ???????? ?????????
  767. if(isset($plugins['post.save']))
  768. {
  769. rsort($plugins['post.save']);
  770. foreach($plugins['post.save'] as $func)
  771. {
  772. if(function_exists($func)) $func();
  773. }
  774. }
  775. // ????????????? ?????
  776. if(isset($_upfiles))
  777. {
  778. foreach($_upfiles as $vf) $_atfiles[$_v['p']][] = $vf;
  779. }
  780. @fsave($_POST['datadir'].'/'.$_v['p'],'w+',$_v['title']."\n".trim($_v['text']).(trim($_v['comm']) ? "[comments]\n" : '[comments]').trim($_v['comm'])."\n");
  781. @fsave($_POST['datadir'].'/.settings.local', 'w+', serialize($_loc));
  782. // ???? ???? ????? ????????????? ?????
  783. if(isset($_atfiles))
  784. {
  785. if(is_file($_POST['datadir'].'/.se.files'))
  786. {
  787. $allfiles = unserialize(file_get_contents($_POST['datadir'].'/.se.files'));
  788. }
  789. $newfiles = isset($allfiles) ? ($_atfiles + $allfiles) : $_atfiles;
  790. @fsave($_POST['datadir'].'/.se.files', 'w+', serialize($newfiles));
  791. }
  792. // ????? ??????, ping, ?????? sitemap
  793. if(isset($_new))
  794. {
  795. if(isset($_urls['sitemap']) && trim($_urls['sitemap'][0]))
  796. {
  797. foreach($_urls['sitemap'] as $sp)
  798. {
  799. _curl(trim($sp).urlencode(alk('sitemap.xml')), 10);
  800. }
  801. }
  802. if(isset($_urls['ping']) && trim($_urls['ping'][0]))
  803. {
  804. foreach($_urls['ping'] as $pn)
  805. {
  806. ping(trim($pn), $_v['title'], $_lk['rsslink']);
  807. }
  808. }
  809. }
  810. if(!$text)
  811. {
  812. header('Location: '.plk($_v['p']));
  813. }
  814. else
  815. {
  816. return $_v['p'];
  817. }
  818. }
  819. }
  820. function ptinfo($ide)
  821. {
  822. global $_s, $_v, $_l, $_glob, $plugins, $_loc, $anons;
  823. $pst['ed']='';
  824. // ????????? ?? ?????? ?? (????????) ? ?? ?????????? ?? ??????????
  825. $allow = ((!@$_loc['draft'][$ide] && $ide < time()) || isset($_SESSION['adm'])) ? 1 : 0;
  826. if(!isset($ide) || !trim($ide) || !file_exists($_POST['datadir'].'/'.$ide) || !$allow) return 0;
  827. // ?????????
  828. if(isset($_loc['cat'][$ide]))
  829. {
  830. $pst['cats'] = $_loc['cat'][$ide];
  831. } else $pst['cats'] = '';
  832. // ????????, ?????? ??????
  833. if(@$_loc['draft'][$ide] && !$_SESSION['adm']) return 0;
  834. $inon = explode('[comments]',$dt = file_get_contents($_POST['datadir'].'/'.$ide));
  835. @list($pst['title'], $pst['raw']) = explode("\n", $dt, 2);
  836. @list($pst['title'], $pst['text']) = explode("\n", $inon[0], 2);
  837. $pst['fulltext'] = $pst['text'];
  838. $pst['id'] = $ide;
  839. $pst['timestamp'] = $ide + $_s['tmset'] * 3600;
  840. $tx = explode("\n", $pst['text']);
  841. $pst['link'] = plk($ide);
  842. if(@$_v['act'] != 'ed')
  843. {
  844. // ???????????? ??????????? :j
  845. // $pst['text'] = '<p>'.str_replace("\r\n\r\n", '</p><p>', trim($pst['text'])).'</p>';
  846. // ?????? ?????????
  847. $pst['title'] = trim($pst['title']) ? trim($pst['title']) : $_l['nosubj'];
  848. // ?????? ?? ?????????
  849. if($_s['thumbson'])
  850. {
  851. $pst['text'] = preg_replace_callback("/<img(.*?)>/i", "replacethumbs", $pst['text']);
  852. }
  853. // ?????????? ? ??????
  854. if(trim($_s['replacetx']))
  855. {
  856. $replace = explode("\n", $_s['replacetx']);
  857. foreach ($replace as $v)
  858. {
  859. if(trim($v))
  860. {
  861. $ex = explode('=>', trim($v));
  862. $from = trim($ex[0]);
  863. $to = trim($ex[1]);
  864. if(!is_array($pst))
  865. {
  866. foreach($pst as $ptkey => $ptval) $to = str_replace('%'.$ptkey.'%', $ptval, $to);
  867. }
  868. $pst['text'] = preg_replace('/'.$from.'/ui', $to, $pst['text']);
  869. }
  870. }
  871. }
  872. }
  873. if(!isset($_v['p']))
  874. {
  875. // ????? ?????? ?????? (cut), ?????????
  876. if($s = strpos($pst['text'], $_s['cut']))
  877. {
  878. $srt = substr($pst['text'], 0, $s);
  879. }
  880. // ?????????? ???? ?????? ???? ???????? ??????
  881. else if((sizeof($tx)>2) && $_s['autocut'])
  882. {
  883. $srt = $tx[0];
  884. }
  885. if(isset($srt))
  886. {
  887. $pst['text'] = $srt.str_replace(array('%link%','%title%'), array($pst['link'], $pst['title']), $_l['more']);
  888. }
  889. }
  890. $pst['date'] = date('d-m-Y, H:i', $ide + $_s['tmset'] * 3600);
  891. // ?????????? ?????? ?? ?????
  892. $pst['datelink'] = datelinks($ide + $_s['tmset'] * 3600, '-', true);
  893. @$pst['commts'] = explode("\n", $inon[1]);
  894. //???????? ????????????, ??????? ?????? ????????
  895. $comment_num = $pst['comtnhd'] = 0;
  896. if(!isset($_SESSION['adm']))
  897. {
  898. foreach($pst['commts'] as $v)
  899. {
  900. if(!stristr($v, '@@'.$_s['aname'])) $comment_num++;
  901. else $pst['comtnhd']++;
  902. }
  903. }
  904. else
  905. {
  906. $comment_num = sizeof($pst['commts']);
  907. }
  908. @$pst['comtn'] = $comment_num;
  909. if(isset($_SESSION['adm']))
  910. {
  911. $pst['ed']='<div class="edpanel"><a id="ed" href='.alk('ed',$pst['id']).' title="?????????????">E</a> <a id="de" title="???????" href='.alk('de',$pst['id']).' '.cd($pst['title']).'>X</a></div>';
  912. }
  913. $pst['template'] = @$_loc['template'][$pst['id']] ? $_loc['template'][$pst['id']] : $_s['tpp'];
  914. $pst['template'] = isset($_s['post.tpl.hold']) ? $_s['post.tpl.hold'] : $pst['template'];
  915. // ???????? ?????????
  916. if(isset($plugins['post.get.'.$pst['id']]))
  917. {
  918. rsort($plugins['post.get.'.$pst['id']]);
  919. foreach($plugins['post.get.'.$pst['id']] as $func)
  920. {
  921. if(function_exists($func)) $pst = $func($pst);
  922. }
  923. }
  924. // ???????? ?????????
  925. if(isset($plugins['post.get']))
  926. {
  927. rsort($plugins['post.get']);
  928. foreach($plugins['post.get'] as $func)
  929. {
  930. if(function_exists($func)) $pst = $func($pst);
  931. }
  932. }
  933. if($_s['autometa'])
  934. {
  935. $anons['title'] = $pst['title'];
  936. $anons['text'] = $pst['text'];
  937. }
  938. return $pst;
  939. }
  940. function pginfo($f) {
  941. global $_s, $plugins;
  942. $d['ed'] = $d['comtn'] = '';
  943. $f = str_replace('-', '_', $f);
  944. $fname = str_replace($_POST['datadir'].'/', '', $f);
  945. if(strstr($f, '.se') || !$fc = @file_get_contents($f)) return false;
  946. $e1 = explode('</'.$_s['pgt'].'>',$fc);
  947. $e2 = explode('<'.$_s['pgt'].'>',$e1[0]);
  948. $d['title'] = isset($e2[1]) ? $e2[1] : $fname;
  949. $d['text'] = isset($e1[1]) ? $e1[1] : $fc;
  950. $d['link'] = pgk(str_replace('_', '-', $fname));
  951. $d['timestamp'] = filemtime($f) + $_s['tmset'] * 3600;
  952. $d['date'] = date('d-m-Y', $d['timestamp']);
  953. $d['datexml'] = date('Y-m-d', $d['timestamp']);
  954. $d['template'] = $_s['tpp'];
  955. // ???????? ?????????
  956. if(isset($plugins['page.get']))
  957. {
  958. rsort($plugins['post.get']);
  959. foreach($plugins['page.get'] as $func)
  960. {
  961. if(function_exists($func)) $d = $func($d);
  962. }
  963. }
  964. return $d;
  965. }
  966. function catslist($cats=false, $td='<a href="%link%" rel="nofollow">%name%</a>', $i=',') {
  967. global $_s, $_l, $_v, $_loc;
  968. if(is_array($cats))
  969. {
  970. foreach($cats as $v)
  971. {
  972. if(isset($_loc['catid'][$v[0]]))
  973. {
  974. $pst['cats_links'][] = str_replace(array('%link%', '%name%'), array(ctlk($v[0]), $_loc['catid'][$v[0]][1]), $td);
  975. }
  976. }
  977. if(isset($pst['cats_links'])) return implode($i, $pst['cats_links']);
  978. }
  979. return '';
  980. }
  981. function catlist($td='<a href="%link%" rel="nofollow">%name%</a>', $i='<br>') {
  982. global $_s, $_l, $_v, $_loc;
  983. if(isset($_loc['catid']))
  984. {
  985. foreach($_loc['catid'] as $k=>$v)
  986. {
  987. $_cats[] = str_replace(array('%link%', '%name%'), array(ctlk($k), $v[1]), $td);
  988. }
  989. if(isset($_cats)) return implode($i, $_cats);
  990. }
  991. return '';
  992. }
  993. function pglist($c=0, $td=0) {
  994. global $_s, $_l, $_v;
  995. $d = dir($_POST['datadir']);
  996. while (false !== ($et = $d->read()))
  997. {
  998. if (!is_numeric($et))
  999. {
  1000. // ???? ?? ????????? ? ?? ??????????, ?? ??????? ????????
  1001. if(substr($et,0,1) != '.' && !is_dir($_POST['datadir'].'/'.$et) && $et != $_s['index']) $docs[filemtime($_POST['datadir'].'/'.$et)] = $et;
  1002. // ???????? ????????-??????????
  1003. else if(substr($et,0,2) == '._') include_once($_POST['datadir'].'/'.$et);
  1004. }
  1005. }
  1006. $out=false;
  1007. if(isset($docs))
  1008. {
  1009. krsort($docs);
  1010. $dn=0;
  1011. foreach($docs as $et)
  1012. {
  1013. if(!$c) $c = sizeof($docs);
  1014. if($dn<$c)
  1015. {
  1016. $doc = pginfo($_POST['datadir'].'/'.$et);
  1017. $dc = $td ? $td : $_l['pglist'];
  1018. // ????????? ??????
  1019. if($doc)
  1020. {
  1021. foreach($doc as $k=>$v) $dc = str_replace('%'.$k.'%', $v, $dc);
  1022. $dn++;
  1023. $out .= $dc;
  1024. }
  1025. }
  1026. }
  1027. }
  1028. $d->close();
  1029. return $out;
  1030. }
  1031. // ????? ??????
  1032. function blocks($place) {
  1033. global $_s, $_l, $_lk, $_loc, $_tplin, $plugins;
  1034. // ???? ???? ?????? ??????????
  1035. if(isset($_loc['block'][$place]))
  1036. {
  1037. $blocks = $_loc['block'][$place];
  1038. $template = $_tplin[$place . '-block'];
  1039. ksort($blocks);
  1040. foreach($blocks as $k=>$v)
  1041. {
  1042. $prepare = str_replace('%title%', $v[0], $template);
  1043. $prepare = str_replace('%content%', $v[1], $prepare);
  1044. // ???????? ?????????
  1045. if(isset($plugins['block.get']))
  1046. {
  1047. rsort($plugins['block.get']);
  1048. foreach($plugins['block.get'] as $func)
  1049. {
  1050. if(function_exists($func)) $prepare = $func($prepare);
  1051. }
  1052. }
  1053. // ???????? ?????????
  1054. if(isset($plugins['block.get.'.$place.'_'.$k]))
  1055. {
  1056. rsort($plugins['block.get.'.$place.'_'.$k]);
  1057. foreach($plugins['block.get.'.$place.'_'.$k] as $func)
  1058. {
  1059. if(function_exists($func)) $prepare = $func($prepare);
  1060. }
  1061. }
  1062. // ?? ?????? ??????? ??????? ??? ?????????? (?? ???????: ??? ?????? ?????)
  1063. if(strstr($prepare, '%pglist%'))
  1064. {
  1065. $prepare = str_replace('%pglist%', pglist(8), $prepare);
  1066. }
  1067. if(strstr($prepare, '%cmtlist%'))
  1068. {
  1069. $prepare = str_replace('%cmtlist%', cmtlist(8), $prepare);
  1070. }
  1071. if(strstr($prepare, '%catlist%'))
  1072. {
  1073. $prepare = str_replace('%catlist%', catlist(), $prepare);
  1074. }
  1075. // ?????? ????????? ??????????
  1076. foreach($_s as $sk=>$sv) $prepare = str_replace('%'.$sk.'%', $sv, $prepare);
  1077. // ?????? ??????
  1078. foreach($_lk as $lk=>$lv) $prepare = str_replace('%'.$lk.'%', $lv, $prepare);
  1079. // ??????? ??????
  1080. if(isset($_SESSION['adm'])) $prepare = str_replace(array('<!--is_admin-', '-is_admin-->'), '', $prepare);
  1081. // ???? ?????: ???? ??????????????
  1082. $prepare = isset($_SESSION['adm']) ? str_replace('%edit%', '<div class="edpanel"><a id="ed" href='.alk('bk', $place.'_'.$k).' title="?????????????">E</a> <a id="de" title="???????" href='.alk('de', $place.'_'.$k).' '.cd($v[0]).'>X</a></div>', $prepare) : str_replace('%edit%', '', $prepare);
  1083. // ???????? ?????????
  1084. if(isset($plugins['block.output']))
  1085. {
  1086. rsort($plugins['block.output']);
  1087. foreach($plugins['block.output'] as $func)
  1088. {
  1089. if(function_exists($func)) $prepare = $func($prepare);
  1090. }
  1091. }
  1092. echo $prepare;
  1093. }
  1094. }
  1095. }
  1096. // ?????? ????????? ?????????? (?? ?????????? ??????, ?? ????????????!)
  1097. function cmtlist($c=0, $td=0, $lm=0) {
  1098. global $_s, $_l, $_loc;
  1099. $d = dir($_POST['datadir']);
  1100. while (false !== ($et = $d->read()))
  1101. {
  1102. if (substr($et,0,1) != '.' && is_numeric($et))
  1103. {
  1104. // ????????? ?? ?????? ?? (????????)
  1105. $allow = (!@$_loc['draft'][$et] || isset($_SESSION['adm'])) ? 1 : 0;
  1106. if($allow)
  1107. {
  1108. $cmts[filemtime($_POST['datadir'].'/'.$et)] = $et;
  1109. }
  1110. }
  1111. }
  1112. $d->close();
  1113. if(isset($cmts))
  1114. {
  1115. krsort($cmts);
  1116. $out=false;
  1117. $dn=0;
  1118. foreach($cmts as $et)
  1119. {
  1120. if(!$c) $c=10;
  1121. $cmt = ptinfo($et);
  1122. if(($cmt['comtn']-2)>0 && $dn<$c)
  1123. {
  1124. list($cmt['nick'], $cmt['ip'], $cmt['date'], $cmt['text']) = explode('ť', $cmt['commts'][($cmt['comtn']-2)]);
  1125. $cmt['cmtlink'] = $cmt['link'].'#cmt-'.($cmt['comtn']-2);
  1126. $e = explode('<',$cmt['text']);
  1127. $cmt['text'] = strip_tags($e[0]);
  1128. $s = strpos($cmt['nick'], '@');
  1129. if($s) $cmt['nick'] = substr($cmt['nick'],0,$s);
  1130. $cmt['nick'] = (@trim($cmt['nick']) ? $cmt['nick'] : $_l['anonym']);
  1131. $dc = $td ? $td : $_l['cmtlist'];
  1132. foreach($cmt as $k=>$v) @$dc = str_replace('%'.$k.'%',$v,$dc);
  1133. $dn++;
  1134. $out .= $dc;
  1135. }
  1136. }
  1137. }
  1138. if(isset($out)) return $out;
  1139. else return false;
  1140. }
  1141. // ??????????/????????? ??????
  1142. function ptnext($p) {
  1143. global $_s, $_l;
  1144. $allp = getposts();
  1145. rsort($allp);
  1146. $s = sizeof($allp);
  1147. $nx['p']['sub'] = $nx['p']['lnk'] = $nx['n']['sub'] = $nx['n']['lnk'] = '';
  1148. for($i=0;$i<$s;$i++)
  1149. {
  1150. if($allp[$i] == $p)
  1151. {
  1152. if(@$n = ptinfo($allp[$i+1]))
  1153. {
  1154. $nx['p']['sub'] = $n['title'];
  1155. $nx['p']['lnk'] = $n['link'];
  1156. }
  1157. if(@$p = ptinfo($allp[$i-1]))
  1158. {
  1159. $nx['n']['sub'] = $p['title'];
  1160. $nx['n']['lnk'] = $p['link'];
  1161. }
  1162. return @$nx;
  1163. }
  1164. }
  1165. }
  1166. function clean($t) {
  1167. return str_replace(array('"','<','>','\"','$','(','(','*','+','%','$','#',':','[',']','&','!','?','~','=','+','?',':',';','{','}','`','/','\\',"\r","\n",',',')','\'','- ',' -'),'',$t);
  1168. }
  1169. // ????????? ????????
  1170. function retex($t) {
  1171. return preg_replace('#\B(@[_?-???-??0-9a-zA-Z]+)#u', '<a href="'.swlk('\\1').'" rel="nofollow">\\1</a>',$t);
  1172. }
  1173. // ????????? ????????? nick
  1174. if(@trim($_v['nick']))
  1175. {
  1176. setcookie('nnk', $_v['nick'], time() + 604800);
  1177. }
  1178. // ?????? ??????????, ????????? ??????
  1179. if (isset($_v['passwd']) && md5($_v['passwd']) == $_s['pass'])
  1180. {
  1181. $_SESSION['adm'] = 1;
  1182. }
  1183. // ????????, ?????????????? ???????????
  1184. if(isset($_v['fullsize']))
  1185. {
  1186. if(is_file($_POST['datadir'].'/.se.files'))
  1187. {
  1188. $allfiles = unserialize(file_get_contents($_POST['datadir'].'/.se.files'));
  1189. }
  1190. $_intpl['inheader'] .= '<meta name="robots" content="noindex,follow,noodp,noydir" />'."\n";
  1191. $tmpexp = explode('/', $_v['fullsize']);
  1192. $filename = $tmpexp[sizeof($tmpexp)-1];
  1193. $_s['title'] = @$pst['title'] ? $pst['title'] : $filename;
  1194. include $_s['tpd'].'/image-fullsize.php';
  1195. exit();
  1196. }
  1197. // ?????????? ??? ?????? ??????????
  1198. if(isset($_v['majax']))
  1199. {
  1200. header("Content-type: text/javascript");
  1201. if($_v['majax'] == 'makethumbs')
  1202. {
  1203. $psts = getposts();
  1204. $total = 0;
  1205. if($psts && $pz = sizeof($psts))
  1206. {
  1207. rsort($psts);
  1208. for ($i=0; $i<sizeof($psts); $i++)
  1209. {
  1210. $pst = ptinfo($psts[$i]);
  1211. $images = explode('src', $pst['text']);
  1212. // ??????
  1213. if($_s['thumbson'])
  1214. {
  1215. $pst['raw'] = preg_replace_callback("/<img(.*?)>/i", "resizeimg", $pst['raw']);
  1216. }
  1217. $total += sizeof($images)-1;
  1218. }
  1219. }
  1220. $_msg = '??????????? '.$total.' ????????.';
  1221. }
  1222. if($_v['majax'] == 'checkup')
  1223. {
  1224. if(!@$f = file_get_contents('http://code.google.com/feeds/p/nanote/downloads/basic'))
  1225. {
  1226. $_msg = '?? ??????? ???????????.';
  1227. }
  1228. else
  1229. {
  1230. $ex = explode('<entry>', $f);
  1231. foreach($ex as $entry)
  1232. {
  1233. $id = explode('<id>', $entry);
  1234. if(strstr($id[1], 'nanote-v-'))
  1235. {
  1236. $vers = _get($id[1], 'nanote-v-', '.zip');
  1237. $desc = trim(_get($id[1], '<content type="html">', '</content>'));
  1238. $dex = explode("\n\n", str_replace('&lt;pre&gt;','',$desc));
  1239. $info_link = trim(_get($id[1], '<link rel="alternate" type="text/html" href="', '" />'));
  1240. $download_link = 'http://nanote.googlecode.com/files/nanote-v-'.$vers.'.zip';
  1241. break;
  1242. }
  1243. }
  1244. $_msg = '?? ??????????? ??????? ?????????? ??????? <b>' . $_v['ver'] . '</b>';
  1245. if($_v['ver']<$vers)
  1246. {
  1247. @$_msg = '???????? ?????? <b>' . $vers . '</b> : <a href="'.$link.'">???????</a><hr>' . trim($dex[0]);
  1248. }
  1249. if($_v['ver']>$vers)
  1250. {
  1251. $_msg = '?? ??????????? ????????????????? ??????? <b><a href="http://nanote.googlecode.com/svn/trunk/">' . $_v['ver'] . '</a></b> (?????????? - <a href="'.$info_link.'">'.$vers.'</a>)';
  1252. }
  1253. }
  1254. }
  1255. if($_v['majax'] == 'doping')
  1256. {
  1257. $pingsuccess = 0;
  1258. if(isset($_urls['ping']))
  1259. {
  1260. foreach($_urls['ping'] as $pn)
  1261. {
  1262. if(ping(trim($pn), $_s['bname'], $_lk['rsslink']))
  1263. {
  1264. $pingsuccess++;
  1265. }
  1266. }
  1267. }
  1268. $_msg = '??????? ???????????? '.$pingsuccess.' ????????.';
  1269. }
  1270. if($_v['majax'] == 'addsitemap')
  1271. {
  1272. $sitemapsuccess = 0;
  1273. if(isset($_urls['sitemap']))
  1274. {
  1275. foreach($_urls['sitemap'] as $sp)
  1276. {
  1277. $sp = str_replace('%url%', urlencode(alk('sitemap.xml')), trim($sp));
  1278. if(_curl($sp, 10))
  1279. {
  1280. $sitemapsuccess++;
  1281. }
  1282. }
  1283. }
  1284. $_msg = '?????????? '.$sitemapsuccess.' ??????????? ? sitemap.';
  1285. }
  1286. exit('document.getElementById(\''.$_v['majax'].'\').innerHTML = \''.$_msg.'\'; ');
  1287. }
  1288. // ???????
  1289. if(isset($_v['unsubscribe']))
  1290. {
  1291. if(in_array($_v['mail'], $_loc['subs'][$_v['unsubscribe']]))
  1292. {
  1293. $key = array_search($_v['mail'], $_loc['subs'][$_v['unsubscribe']]);
  1294. unset($_loc['subs'][$_v['unsubscribe']][$key]);
  1295. if(@fsave($_POST['datadir'].'/.settings.local', 'w+', serialize($_loc)))
  1296. {
  1297. header('Location: '.$_s['url']);
  1298. }
  1299. }
  1300. }
  1301. // ????????? ??-?????????
  1302. $_s['title'] = $_s['bname'];
  1303. if(isset($_glob['plugins']))
  1304. {
  1305. foreach($_glob['plugins'] as $plugin => $status)
  1306. {
  1307. if($status) include('plugins/'.$plugin);
  1308. }
  1309. }
  1310. // ???????? ?????????
  1311. if(isset($plugins['main']))
  1312. {
  1313. rsort($plugins['main']);
  1314. foreach($plugins['main'] as $func)
  1315. {
  1316. if(function_exists($func)) $func();
  1317. }
  1318. }
  1319. // actions
  1320. if(isset($_v['act']))
  1321. {
  1322. if(isset($plugins['action.'.$_v['act']]))
  1323. {
  1324. foreach($plugins['action.'.$_v['act']] as $func)
  1325. {
  1326. if(function_exists($func)) $func();
  1327. }
  1328. }
  1329. // ????????????? rss
  1330. if(strstr($_v['act'], 'rss'))
  1331. {
  1332. header('Content-type: application/xml');
  1333. echo "<?xml version=\"1.0\" encoding=\"".$_s['enc']."\"?>\n<rss version=\"2.0\">\n<channel>\n<title>".$_s['bname']."</title>\n<link>".$_s['url']."</link>\n<description></description>\n<language>ru</language>\n";
  1334. $_s['post.tpl.hold'] = $_v['act'];
  1335. unset($_v['act']);
  1336. blog();
  1337. echo "\n</channel>\n</rss>";
  1338. exit();
  1339. }
  1340. switch($_v['act']) {
  1341. case 't':
  1342. $_v['act'] = $_v['pg'] = $_v['p'] = null;
  1343. $tags = explode(',', $rq[1]);
  1344. $_v['sw'] = $_v['act'] = null;
  1345. // ?????? ????? ?????/?????????
  1346. for ($i=0; $i<sizeof($tags); $i++) $tnames[] = $_loc['catid'][$tags[$i]][1];
  1347. foreach ($_loc['cat'] as $k=>$v)
  1348. {
  1349. foreach($v[0] as $incat)
  1350. {
  1351. if(in_array($incat, $tags))
  1352. {
  1353. // ????????? ?? ?????? ?? (????????)
  1354. $allow = ((!@$_loc['draft'][$k] && $k < time()) || isset($_SESSION['adm'])) ? 1 : 0;
  1355. $psts[] = $k;
  1356. }
  1357. }
  1358. }
  1359. // javascript ??????????? ? ????????? ??????????
  1360. @$_s['pglk'] .=
  1361. '<script>
  1362. var search = \''.$_v['sw'].'\';
  1363. var searchtpl = \'' . $_l['search'] . '\';
  1364. var notify_msg = "??????? ' . sizeof($psts) . ' ???????.";
  1365. </script>';
  1366. // ?????? ????????? ? ?????? ???
  1367. $_s['title'] = $_s['bname'].' - '.implode(', ', $tnames);
  1368. $_intpl['inheader'] .= '<meta name="robots" content="noindex,follow,noodp,noydir" />'."\n";
  1369. include $_s['tpd'].'/index.php';
  1370. exit();
  1371. break;
  1372. case 'ban':
  1373. $ip = trim($_v['p']);
  1374. if(strstr($_s['stop_word_ip'], $ip))
  1375. {
  1376. $_glob['_sstop_word_ip'] = str_replace(array(','.$ip, $ip), '', $_s['stop_word_ip']);
  1377. }
  1378. else
  1379. {
  1380. $_glob['_sstop_word_ip'] = $_s['stop_word_ip'].','.$ip;
  1381. }
  1382. fsave($_POST['datadir'].'/.settings.global','w+',serialize($_glob));
  1383. header('Location: '.$_SERVER['HTTP_REFERER']);
  1384. break;
  1385. case 'lgout':
  1386. if ($_SESSION['adm'])
  1387. {
  1388. unset($_SESSION['adm']);
  1389. header('Location: '.$_s['url']);
  1390. }
  1391. break;
  1392. case 'comm':
  1393. if(isset($_v['p']) && is_numeric($_v['p']) && file_exists($_POST['datadir'].'/'.$_v['p']))
  1394. {
  1395. if ($_s['cmton'] || isset($_SESSION['adm']))
  1396. {
  1397. $postinfo = ptinfo($_v['p']);
  1398. //
  1399. for ($i=1; $i<($postinfo['comtn']-1)+$postinfo['comtnhd']; $i++)
  1400. {
  1401. list($cmt['nick'], $cmt['ip'], $cmt['date'], $cmt['text']) = explode('ť', $postinfo['commts'][$i]);
  1402. $md5[] = md5(trim($cmt['text']));
  1403. }
  1404. //
  1405. if (@trim($_v['text']))
  1406. {
  1407. $exw = explode(',', $_s['stop_word_ip']);
  1408. $txt = substr(trim($_v['text']), 0, 4096);
  1409. @$nick = substr(clean(strip_tags($_v['nick'])), 0, 69);
  1410. $_v['ip'] = getenv('REMOTE_ADDR');
  1411. if(isset($_SESSION['adm']))
  1412. {
  1413. $nick = $_s['aname'];
  1414. }
  1415. else if(stristr($nick, $_s['aname']))
  1416. {
  1417. $_s['err'] = 1;
  1418. }
  1419. $txt = str_replace(array("\r", "\n",'ť'), array("", "\r", '&raquo;'), $txt);
  1420. // capcha
  1421. if(!isset($_SESSION['adm']) && $_s['cmtspam']!=0)
  1422. {
  1423. // ??????? ?????????
  1424. if($_s['cmtspam'] == 2)
  1425. {
  1426. $uniq = md5($_s['pass'] + $_v['p']);
  1427. if (!trim($_v[$uniq]) || trim($_v['text'.$_v['p']]))
  1428. {
  1429. $_s['err'] = 2;
  1430. }
  1431. }
  1432. // ?????? ????????
  1433. if($_s['cmtspam'] == 1)
  1434. {
  1435. if (isset($_v['answer']) && $_v['answer'])
  1436. {
  1437. $answer = preg_replace('/[^a-z0-9]+/i', '', $_v['answer']);
  1438. if (implode(file('http://captchator.com/captcha/check_answer/'.session_id().'/'.$answer)) != '1')
  1439. {
  1440. $_s['err'] = 2;
  1441. }
  1442. } else $_s['err'] = 3;
  1443. }
  1444. }
  1445. if(!isset($_SESSION['adm']))
  1446. {
  1447. $txt = str_replace(array('<', '>'), array('&lt;', '&gt;'), $txt);
  1448. $txt = str_replace('"', '&quot;', $txt);
  1449. }
  1450. $txt = str_replace("\r", "\n", $txt);
  1451. $txt = str_replace("\n", ' <br /> ', $txt);
  1452. // ????????
  1453. if(isset($md5) && in_array(md5(trim($txt)), $md5))
  1454. {
  1455. $_s['err'] = 6;
  1456. }
  1457. // ???????? ?? ????-?????
  1458. foreach($exw as $v)
  1459. {
  1460. if($v = trim($v) && (stristr($txt.' '.$nick,$v) || strstr($_v['ip'],$v)))
  1461. {
  1462. $_s['err'] = 4;
  1463. }
  1464. }
  1465. $mfrom = strstr($nick, '@') ? $nick : "noreply-$_s[email]";
  1466. if((!isset($_s['err']) && $_loc['comments'][$_v['p']]) || isset($_SESSION['adm']))
  1467. {
  1468. // ???????? ?????????
  1469. if(isset($plugins['comment.save']))
  1470. {
  1471. rsort($plugins['comment.save']);
  1472. foreach($plugins['comment.save'] as $func)
  1473. {
  1474. if(function_exists($func)) $func();
  1475. }
  1476. }
  1477. fsave($_POST['datadir'].'/'.$_v['p'], 'a+',$nick.'ť'.$_v['ip'].'ť'.date('d-m-y, H:i', time() + $_s['tmset'] * 3600).'ť'.$txt."\n");
  1478. // email-??????????? ??????
  1479. if($_s['email'] && !isset($_SESSION['adm']))
  1480. {
  1481. mail($_s['email'], 'comment '.$nick,
  1482. $nick." (".$_v['ip'].")\n---\n".$_v['text']."\n---\n".plk($_v['p']),
  1483. 'Content-Type: text/plain; charset='.$_s['enc']."\nFrom: ".$nick."<$mfrom>\r\n"
  1484. );
  1485. }
  1486. // email-??????????? ?????????????
  1487. if(isset($_loc['subs'][$_v['p']]) && !isset($_SESSION['adm']))
  1488. {
  1489. @$partnick = explode('@', $nick);
  1490. foreach($_loc['subs'][$_v['p']] as $mail)
  1491. {
  1492. if($mail != $nick)
  1493. {
  1494. mail($mail, 'comment '.$partnick[0],
  1495. $partnick[0]."\n---\n".$_v['text']."\n---\n??????: ".plk($_v['p'])."\n??????????: ".uslk($_v['p'], $mail),
  1496. 'Content-Type: text/plain; charset='.$_s['enc']."\nFrom: ".$partnick[0]."<noreply-".$_s['email'].">\r\n"
  1497. );
  1498. }
  1499. }
  1500. }
  1501. $_s['succ'] = 1;
  1502. $_v['text'] = '';
  1503. }
  1504. } else $_s['err'] = 5;
  1505. // ???????????
  1506. $notify_msg = isset($_s['err']) ? $_error[$_s['err']] : $_success[$_s['succ']];
  1507. // ???????? ?? email-???????????
  1508. if((isset($nick) && strstr($nick, '@')) && !isset($_SESSION['adm']) && @!in_array($nick, $_loc['subs'][$_v['p']]))
  1509. {
  1510. $_loc['subs'][$_v['p']][] = $nick;
  1511. @fsave($_POST['datadir'].'/.settings.local', 'w+', serialize($_loc));
  1512. }
  1513. // javascript-???????????
  1514. @$_s['pglk'] .=
  1515. '<script>
  1516. var notify_msg = "' . $notify_msg . '";
  1517. </script>';
  1518. }
  1519. }
  1520. break;
  1521. case 'de':
  1522. if(isset($_SESSION['adm']))
  1523. {
  1524. // ?????? ?????: left_1 : left - place, 1 - sort
  1525. if(strstr($_v['p'], '_')) $xpos = explode('_', $_v['p']);
  1526. // ???????? ?????
  1527. if(isset($xpos) && isset($_loc['block'][$xpos[0]]))
  1528. {
  1529. array_splice($_loc['block'][$xpos[0]], $xpos[1], 1);
  1530. fsave($_POST['datadir'].'/.settings.local', 'w+', serialize($_loc));
  1531. // ???????? ??????/????????
  1532. }
  1533. else if($xpos[0] == 'cat' && isset($_loc['catid'][$xpos[1]]))
  1534. {
  1535. unset($_loc['catid'][$xpos[1]]);
  1536. fsave($_POST['datadir'].'/.settings.local', 'w+', serialize($_loc));
  1537. header('Location: '.$_SERVER['HTTP_REFERER']);
  1538. }
  1539. else
  1540. {
  1541. //exit();
  1542. @unlink($_POST['datadir'].'/'.$_v['p']);
  1543. postdata($_v['p']);
  1544. fsave($_POST['datadir'].'/.settings.local', 'w+', serialize($_loc));
  1545. }
  1546. header('Location: '.$_s['url']);
  1547. }
  1548. break;
  1549. case 'ep':
  1550. if(isset($_SESSION['adm']))
  1551. {
  1552. if (@trim($n = $_v['title']) && @trim($t = $_v['text']))
  1553. {
  1554. if($_v['p'])
  1555. {
  1556. $n = $_v['p'];
  1557. $t = '<'.$_s['pgt'].'>'.$_v['title'].'</'.$_s['pgt'].'>'.$t;
  1558. }
  1559. else
  1560. {
  1561. $t = '<'.$_s['pgt'].'>'.$n.'</'.$_s['pgt'].'>'.$t;
  1562. $n = rus2lat($n);//date('dMY_hmi');
  1563. }
  1564. // ???????? ?????????
  1565. if(isset($plugins['page.save']))
  1566. {
  1567. rsort($plugins['page.save']);
  1568. foreach($plugins['page.save'] as $func)
  1569. {
  1570. if(function_exists($func)) $func();
  1571. }
  1572. }
  1573. @fsave($_POST['datadir'].'/'.$n, 'w+', $t);
  1574. header('Location: '.pgk($n));
  1575. }
  1576. else
  1577. {
  1578. if(isset($_v['pg']) && trim($_v['pg']))
  1579. {
  1580. @$po = str_replace(array("\r", "\n"), array("", "\r"), htmlspecialchars(file_get_contents($_POST['datadir'].'/'.@$_v['pg']), ENT_QUOTES));
  1581. @$pst['text'] = str_replace("\r", "\n", $po);
  1582. $px = 1;
  1583. }
  1584. @$pst['title'] = $_v['p'] = $_v['pg'];
  1585. if(isset($px))
  1586. {
  1587. $pst = pginfo($_POST['datadir'].'/'.$_v['p']);
  1588. }
  1589. // ???????? ?????????
  1590. if(isset($plugins['template.form-post']))
  1591. {
  1592. rsort($plugins['t…

Large files files are truncated, but you can click here to view the full file