PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Admin/Common/common.php

http://nblog-thinkphp.googlecode.com/
PHP | 857 lines | 550 code | 67 blank | 240 comment | 106 complexity | 401eccfedffd392663e197f3e6317189 MD5 | raw file
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ?????
  4. // +----------------------------------------------------------------------
  5. // | @link ( http://www.yurnero.net )
  6. // +----------------------------------------------------------------------
  7. // | @copyright
  8. // +----------------------------------------------------------------------
  9. // | @licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  10. // +----------------------------------------------------------------------
  11. // | @author Haijun Wu <nicholasinlove@126.com>
  12. // +----------------------------------------------------------------------
  13. // | $Id: common.php 115 2011-05-11 09:06:41Z nicholasinlove1986@gmail.com $
  14. // +----------------------------------------------------------------------
  15. if (!defined('IN_BLOG')) {
  16. die('Hacking attempt');
  17. }
  18. require_cache (ROOT_PATH.'Includes/common.inc.php');
  19. /**
  20. * ????????
  21. *
  22. * @access public
  23. * @param string $log_info ????
  24. * @param string $log_script ??
  25. * @return void
  26. */
  27. function set_log($log_info,$log_script = __ACTION__) {
  28. $user_id = $_SESSION[C('USER_AUTH_KEY')];
  29. $log_ip = get_client_ip();
  30. $log_time = time();
  31. $log = M('AdminLog');
  32. $data = array();
  33. $data['user_id'] = $user_id;
  34. $data['log_time'] = $log_time;
  35. $data['log_info'] = $log_info;
  36. $data['log_script'] = $log_script;
  37. $data['log_ip'] = $log_ip;
  38. $log->add($data);
  39. }
  40. /**
  41. * ???????????(from ecshop
  42. *
  43. * @access public
  44. * @param string $file_path ????
  45. * @param bool $rename_prv ??????????????rename()?????
  46. *
  47. * @return int ?????????{0 <= x <= 15}??????????????????????
  48. * ??????????????????????
  49. * ???rename()????????????????????????????????
  50. */
  51. function file_mode_info($file_path) {
  52. /* ?????????????????? */
  53. if (!file_exists($file_path)) {
  54. return false;
  55. }
  56. $mark = 0;
  57. if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
  58. /* ???? */
  59. $test_file = $file_path . '/cf_test.txt';
  60. /* ????? */
  61. if (is_dir($file_path)) {
  62. /* ???????? */
  63. $dir = @opendir($file_path);
  64. if ($dir === false) {
  65. return $mark; //???????????????????????????
  66. }
  67. if (@readdir($dir) !== false) {
  68. $mark ^= 1; //???? 001?????? 000
  69. }
  70. @closedir($dir);
  71. /* ???????? */
  72. $fp = @fopen($test_file, 'wb');
  73. if ($fp === false) {
  74. return $mark; //???????????????????
  75. }
  76. if (@fwrite($fp, 'directory access testing.') !== false) {
  77. $mark ^= 2; //??????011???????? 010
  78. }
  79. @fclose($fp);
  80. @unlink($test_file);
  81. /* ????????? */
  82. $fp = @fopen($test_file, 'ab+');
  83. if ($fp === false) {
  84. return $mark;
  85. }
  86. if (@fwrite($fp, "modify test.\r\n") !== false) {
  87. $mark ^= 4;
  88. }
  89. @fclose($fp);
  90. /* ??????????rename()????? */
  91. if (@rename($test_file, $test_file) !== false) {
  92. $mark ^= 8;
  93. }
  94. @unlink($test_file);
  95. } elseif (is_file($file_path)) {
  96. /* ?????? */
  97. $fp = @fopen($file_path, 'rb');
  98. if ($fp) {
  99. $mark ^= 1; //?? 001
  100. }
  101. @fclose($fp);
  102. /* ?????? */
  103. $fp = @fopen($file_path, 'ab+');
  104. if ($fp && @fwrite($fp, '') !== false) {
  105. $mark ^= 6; //??????? 111?????????011...
  106. }
  107. @fclose($fp);
  108. /* ??????????rename()????? */
  109. if (@rename($test_file, $test_file) !== false) {
  110. $mark ^= 8;
  111. }
  112. }
  113. } else {
  114. if (@is_readable($file_path)) {
  115. $mark ^= 1;
  116. }
  117. if (@is_writable($file_path)) {
  118. $mark ^= 14;
  119. }
  120. }
  121. return $mark;
  122. }
  123. /**
  124. * ?????????
  125. *
  126. * @return string $str ????
  127. */
  128. function get_random_name() {
  129. $str = date('Ymd');
  130. for ($i = 0; $i < 6; $i++) {
  131. $str .= chr(mt_rand(97, 122));
  132. }
  133. return $str;
  134. }
  135. /**
  136. * ????????????(from ecshop
  137. *
  138. * @access public
  139. * @param string $val ??????
  140. *
  141. * @return int $val
  142. */
  143. function return_bytes($val) {
  144. $val = trim($val);
  145. $last = strtolower($val{strlen($val)-1});
  146. switch($last) {
  147. case 'g':
  148. $val *= 1024;
  149. case 'm':
  150. $val *= 1024;
  151. case 'k':
  152. $val *= 1024;
  153. }
  154. return $val;
  155. }
  156. /**
  157. * ??????????(from ecshop
  158. *
  159. * @access public
  160. * @param
  161. *
  162. * @return void
  163. */
  164. function num_bitunit($num) {
  165. $bitunit = array(' B',' KB',' MB',' GB');
  166. for ($key = 0, $count = count($bitunit); $key < $count; $key++) {
  167. if ($num >= pow(2, 10 * $key) - 1) {// 1024B ???? 1KB
  168. $num_bitunit_str = (ceil($num / pow(2, 10 * $key) * 100) / 100) . " $bitunit[$key]";
  169. }
  170. }
  171. return $num_bitunit_str;
  172. }
  173. /**
  174. * ????????'--'(from ecshop
  175. *
  176. * @access public
  177. * @param
  178. * @return void
  179. */
  180. function remove_comment($var) {
  181. return (substr($var, 0, 2) != '--');
  182. }
  183. /**
  184. * ????????(from ecshop
  185. *
  186. * @access public
  187. * @param mix $ext ?????? ?????
  188. * @return void
  189. */
  190. function clear_compiled_files($ext = '') {
  191. return clear_tpl_files(false, $ext);
  192. }
  193. /**
  194. * ??????(from ecshop
  195. *
  196. * @access public
  197. * @param mix $ext ?????? ?????
  198. * @return void
  199. */
  200. function clear_cache_files($ext = '') {
  201. return clear_tpl_files(true, $ext);
  202. }
  203. /**
  204. * ???????????(from ecshop
  205. *
  206. * @access public
  207. * @param mix $ext ???????
  208. * @return void
  209. */
  210. function clear_all_files($ext = '') {
  211. return clear_tpl_files(false, $ext) + clear_tpl_files(true, $ext);
  212. }
  213. /**
  214. * ????????????????(from ecshop
  215. *
  216. * @access public
  217. * @param bool $is_cache ??????????????
  218. * @param string $ext ??????????????
  219. *
  220. * @return int ?????????
  221. */
  222. function clear_tpl_files($is_cache = true, $ext = '') {
  223. $dirs = array();
  224. //????
  225. $tmp_dir = ROOT_PATH . STATIC_CACHES_DIR;
  226. $compiled_dir = ROOT_PATH . 'Blog/Runtime/Cache/';
  227. $compiled_admin_dir = ROOT_PATH . 'Admin/Runtime/Cache/';
  228. if ($is_cache) {
  229. $dirs[] = $tmp_dir;
  230. } else {
  231. $dirs[] = $compiled_dir;
  232. $dirs[] = $compiled_admin_dir;
  233. }
  234. $str_len = strlen($ext);
  235. $count = 0;
  236. foreach ($dirs as $dir) {
  237. $folder = @opendir($dir);
  238. if ($folder === false) {
  239. continue;
  240. }
  241. while ($file = readdir($folder)) {
  242. if ($file == '.' || $file == '..' || $file == 'index.htm' || $file == 'index.html' || $file == 'index.php') {
  243. continue;
  244. }
  245. if (is_file($dir . $file)) {
  246. /* ????????????? */
  247. $pos = ($is_cache) ? strrpos($file, '_') : strrpos($file, '.');
  248. if ($str_len > 0 && $pos !== false) {
  249. $ext_str = substr($file, 0, $pos);
  250. if ($ext_str == $ext) {
  251. if (@unlink($dir . $file)) {
  252. $count++;
  253. }
  254. }
  255. } else {
  256. if (@unlink($dir . $file)) {
  257. $count++;
  258. }
  259. }
  260. }
  261. }
  262. closedir($folder);
  263. }
  264. return $count;
  265. }
  266. /**
  267. * ?????????
  268. *
  269. * @access public
  270. * @param string $str ???
  271. *
  272. * @return bool
  273. *
  274. */
  275. function is_gb($str) {
  276. if (strlen($str)>=2) {
  277. $str=strtok($str,"");
  278. if ((ord($str[0])<161)||(ord($str[0])>247)) {
  279. return false;
  280. } else {
  281. if ((ord($str[1])<161)||(ord($str[1])>254)) {
  282. return false;
  283. } else {
  284. return true;
  285. }
  286. }
  287. } else {
  288. return false;
  289. }
  290. }
  291. /**
  292. * ????????(??)
  293. *
  294. * @access public
  295. * @return void
  296. */
  297. function create_static_caches() {
  298. $path = ROOT_PATH . STATIC_CACHES_DIR;
  299. //??
  300. if (!file_exists($path.'calendar_static.php')) {
  301. $cal = $path.'calendar_static.php';
  302. import("@.ORG.Calendar");
  303. $y = Calendar::local_date('Y');
  304. $m = Calendar::local_date('m');
  305. $date = new Calendar($y,$m);
  306. $start_time = local_mktime(0,0,0,$m,1,$y);
  307. $end_time = local_mktime(0,0,0,$date->nextMonth,1,$date->nextYear);
  308. $num = get_posts_from_date($start_time,$end_time);
  309. $html = $date->outPut($num);
  310. if($fp = @fopen($cal, 'wb')) {
  311. $cachedata = "\$html = unserialize('".addcslashes(serialize($html), '\\\'')."');";
  312. @fwrite($fp, "<?php\n//nblog cache file\n//Created on " . date('Y-m-d H:i:s',time()) . "\n\nif (!defined('IN_BLOG')) exit('Hacking attempt');\n\n\$expiration='".(time() + 600)."';\r\n".$cachedata."\r\n?>");
  313. @fclose($fp);
  314. @chmod($cal, 0777);
  315. }
  316. }
  317. //????
  318. if (!file_exists($path.'category_static.php')) {
  319. $cat = D('Category');
  320. $data = $cat->getCatArray();
  321. f_static_cache('category_static',$data ,$path);
  322. }
  323. //?????????????????????????
  324. if (!file_exists($path.'cat_option_static.php')) {
  325. $cat = D('Category');
  326. $data = f_static_cache('category_static','',$path);
  327. $data = $cat->getCatOptions($data,$cat_id);
  328. f_static_cache('cat_option_static',$data ,$path);
  329. }
  330. //?????????,?????????,?????????
  331. if (!file_exists($path.'category_isshow_static.php')) {
  332. $cat = D('Category');
  333. $data = $cat->getCatList(0,0,0,false,false);
  334. foreach ($data as $key =>$v) {
  335. foreach ($v as $k=>$c){
  336. if($k!='category_id'&&$k!='category_url'&&$k!='category_title'&&$k!='posts_num'&&$k!='level') {
  337. unset($data[$key][$k]);
  338. }
  339. }
  340. }
  341. f_static_cache('category_isshow_static',$data ,$path);
  342. }
  343. //????
  344. if (!file_exists($path.'links_static.php')) {
  345. $links = M('Links');
  346. $map = array();
  347. $map['link_status'] = 1;
  348. $map['link_visible'] = 1;
  349. $data = $links->field('link_url,link_name,link_description')->where($map)->order('link_sort asc')->limit(C('links_num'))->findAll();
  350. f_static_cache('links_static',$data ,$path);
  351. }
  352. //????
  353. if (!file_exists($path.'comment_static.php')) {
  354. $com = M('Comment');
  355. $map = array();
  356. $map[C('DB_PREFIX').'comment.comment_status'] = 1;
  357. $map[C('DB_PREFIX').'comment.comment_visible'] = 1;
  358. $map[C('DB_PREFIX').'comment.comment_type'] = array('neq',2);
  359. $map[C('DB_PREFIX').'posts.posts_status'] = 1;
  360. if (C('remark')) {
  361. $map[C('DB_PREFIX').'comment.comment_remark'] = 1;
  362. }
  363. $data = $com->where($map)->field(C('DB_PREFIX').'comment.comment_id,'.C('DB_PREFIX').'comment.posts_id,'.C('DB_PREFIX').'posts.posts_title,'.C('DB_PREFIX').'posts.posts_url,'.C('DB_PREFIX').'comment.comment_content,'.C('DB_PREFIX').'comment.comment_author,'.C('DB_PREFIX').'comment.comment_email,'.C('DB_PREFIX').'comment.comment_url')->join(C('DB_PREFIX').'posts ON '.C('DB_PREFIX').'posts.posts_id = '.C('DB_PREFIX').'comment.posts_id')->order('comment_id desc')->limit(C('recent_comments_num'))->findAll();
  364. foreach ($data as $k=>$v) {
  365. //$data[$k]['comment_short_content'] = msubstr(htmlspecialchars(addslashes($v['comment_content'])),0,C('recent_comments_limit'));
  366. $comment_excerpt = preg_replace('/(\r\n)|(\n)/', '', $v['comment_content']); // ?????
  367. $comment_excerpt = rc_remove_blockquotes($comment_excerpt); // ???? blockquote ??
  368. $comment_excerpt = preg_replace('/\<(.+?)\>/', '', $comment_excerpt); // ??????
  369. $data[$k]['comment_short_content'] = msubstr($comment_excerpt, 0, C('recent_comments_limit'));
  370. $data[$k]['comment_ellipsis'] = (strpos($data[$k]['comment_short_content'],"...")) ? 1 : 0 ;
  371. $data[$k]['comment_email'] = get_gravatar($data[$k]['comment_email'], $s = 80, $d = C('avatar_default'), $r = C('avatar_rating'));
  372. }
  373. f_static_cache('comment_static',$data ,$path);
  374. }
  375. //???? ?????????
  376. if (!file_exists($path.'posts_static.php')) {
  377. $posts = M('Posts');
  378. $map = array();
  379. $map['posts_status'] = 1;
  380. $map['posts_draft'] = 1;
  381. $map['posts_type'] = 1;
  382. $data = $posts->where($map)->field('posts_date, count(posts_id) as num')->order('posts_date desc')->group('posts_date')->select();
  383. $newarr = array();
  384. foreach ($data as $key => $v) {
  385. $newarr[$v['posts_date']] = $v['num'];
  386. }
  387. f_static_cache('posts_static',$newarr ,$path);
  388. }
  389. //??
  390. if (!file_exists($path.'tag_static.php')) {
  391. $tag = D('Tag');
  392. $data = $tag->getTagArray();
  393. foreach ($data as $key =>$v) {
  394. foreach ($v as $k=>$c){
  395. if($k=='tag_addtime') {
  396. unset($data[$key][$k]);
  397. }
  398. }
  399. }
  400. f_static_cache('tag_static',$data ,$path);
  401. }
  402. //????
  403. if (!file_exists($path.'statistics_static.php')) {
  404. $posts = M('Posts');
  405. $com = M('Comment');
  406. $cat = M('Category');
  407. $tag = M('Tag');
  408. $tb = M('Trackback');
  409. $link = M('Links');
  410. //??
  411. $posts_map = array();
  412. $posts_map['posts_status'] = 1;
  413. $posts_map['posts_draft'] = 1;
  414. $posts_map['posts_type'] = 1;
  415. $posts_num = $posts->where($posts_map)->count();
  416. //??
  417. $comment_sql = '';
  418. $comment_sql .= ' comment_status = 1 and comment_visible = 1 and comment_type <> 2 ';
  419. if (C('remark')) {
  420. $comment_sql .= ' and comment_remark = 1 ';
  421. }
  422. $comment_num = $com->where($comment_sql)->count();
  423. //??
  424. $guestbook_map = array();
  425. //$guestbook_map['comment_status'] = 1;
  426. $guestbook_map['comment_visible'] = 1;
  427. $guestbook_map['comment_type'] = 2;
  428. /*if (C('remark')) {
  429. $comment_map['comment_remark'] = 1;
  430. }*/
  431. $guestbook_num = $com->where($guestbook_map)->count();
  432. //??
  433. $category_num = $cat->where('category_isshow = 1')->count();
  434. //??
  435. $tag_num = $tag->count();
  436. //??
  437. $real_list = array();
  438. $folder = opendir(ROOT_PATH . UPLOAD_DIR);
  439. while ($file = readdir($folder)) {
  440. if ((strpos($file,'.doc') || strpos($file,'.pdf') || strpos($file,'.rar') || strpos($file,'.zip'))!== false) {
  441. $real_list[] = $file;
  442. }
  443. }
  444. $attachment_num = count($real_list);
  445. //????
  446. $tb_map = array();
  447. $tb_map['tb_visible'] = 1;
  448. $trackback_num = $tb->where($tb_map)->count();
  449. //???
  450. $today_num = C('today_pv');
  451. $total_num = C('total_pv');
  452. $statistics_addtime = gmtime();
  453. //????
  454. $link_map = array();
  455. $link_map['link_status'] = 1;
  456. $link_map['link_visible'] = 1;
  457. $link_num = $link->where($link_map)->count();
  458. $data = array(
  459. 'posts_num' => !empty($posts_num) ? intval($posts_num) : 0,
  460. 'comment_num' => !empty($comment_num) ? intval($comment_num) : 0,
  461. 'guestbook_num' => !empty($guestbook_num) ? intval($guestbook_num) : 0,
  462. 'category_num' => !empty($category_num) ? intval($category_num) : 0,
  463. 'tag_num' => !empty($tag_num) ? intval($tag_num) : 0,
  464. 'attachment_num' => !empty($attachment_num) ? intval($attachment_num) : 0,
  465. 'trackback_num' => !empty($trackback_num) ? intval($trackback_num) : 0,
  466. 'link_num' => !empty($link_num) ? intval($link_num) : 0,
  467. 'today_num' => !empty($today_num) ? intval($today_num) : 0,
  468. 'total_num' => !empty($total_num) ? intval($total_num) : 0,
  469. 'statistics_addtime' => $statistics_addtime,
  470. );
  471. f_static_cache('statistics_static',$data ,$path);
  472. }
  473. }
  474. /**
  475. * ???????
  476. *
  477. * @access private
  478. * @param string $template_name ???
  479. * @return array
  480. */
  481. function get_template_info($template_name) {
  482. $file_dir = "./".TEMPLATE_DIR . $template_name;
  483. $arr = array();
  484. $info = array();
  485. $ext = array('png', 'gif', 'jpg', 'jpeg');
  486. $info['code'] = $template_name;
  487. $info['screenshot'] = '';
  488. foreach ($ext as $val) {
  489. if (file_exists($file_dir . "/screenshot.$val")) {
  490. $info['screenshot'] = $file_dir . "/screenshot.$val";
  491. }
  492. }
  493. if (file_exists($file_dir.'/info.txt') && !empty($template_name)) {
  494. $arr = @file($file_dir.'/info.txt');
  495. $template_name_ = explode(': ', $arr[0]);
  496. $template_uri = explode(': ', $arr[1]);
  497. $template_desc = explode(': ', $arr[2]);
  498. $template_version = explode(': ', $arr[3]);
  499. $template_author = explode(': ', $arr[4]);
  500. $template_author_uri = explode(': ', $arr[5]);
  501. $template_tag = explode(': ', $arr[6]);
  502. $info['name'] = isset($template_name[1]) ? trim($template_name_[1]) : '';
  503. $info['uri'] = isset($template_uri[1]) ? trim($template_uri[1]) : '';
  504. $info['desc'] = isset($template_desc[1]) ? trim($template_desc[1]) : '';
  505. $info['version'] = isset($template_version[1]) ? trim($template_version[1]) : '';
  506. $info['author'] = isset($template_author[1]) ? trim($template_author[1]) : '';
  507. $info['author_uri'] = isset($template_author_uri[1]) ? trim($template_author_uri[1]) : '';
  508. $info['tag'] = isset($template_tag[1]) ? trim($template_tag[1]) : '';
  509. $info['templatedir'] = trim($file_dir);
  510. } else {
  511. $info['name'] = '';
  512. $info['uri'] = '';
  513. $info['desc'] = '';
  514. $info['version'] = '';
  515. $info['author'] = '';
  516. $info['author_uri'] = '';
  517. $info['tag'] = '';
  518. $info['templatedir'] = trim($file_dir);
  519. }
  520. return $info;
  521. }
  522. /**
  523. * ?????
  524. *
  525. * @access public
  526. * @param string $n ?????
  527. * @return string $name ????
  528. */
  529. function get_uid($n) {
  530. $name = NULL;
  531. for ($j=0;$j<$n;$j++) {
  532. srand((double)microtime()*1000000);
  533. $randname=rand(!$j ? 1: 0,9);
  534. $name.=$randname;
  535. }
  536. return $name;
  537. $name = NULL;
  538. }
  539. /**
  540. * ??????
  541. *
  542. * @access public
  543. * @param string $n ?????
  544. * @return array
  545. */
  546. function random_size($n) {
  547. /* ???????? */
  548. $arr = array('0.8em', '0.9em', '1.0em', '1.1em', '1.2em', '1.3em');
  549. if ($n > 6) {
  550. $n = $n % 6;
  551. }
  552. return $arr[$n];
  553. }
  554. /**
  555. * ?????????,?????????????
  556. *
  557. * @param string $key
  558. * @param string $value
  559. * @return boolearn
  560. */
  561. function add_action($key,$value,$order=10) {
  562. global $filter;
  563. $filter[$key][$order]=$value;
  564. }
  565. /**
  566. * ??????????
  567. *
  568. * @param string $key
  569. */
  570. function do_action($key) {
  571. global $filter;
  572. ksort($filter[$key]);
  573. foreach ($filter[$key] as $function) {
  574. call_user_func($function);
  575. }
  576. }
  577. /**
  578. * ??????
  579. *
  580. * @access public
  581. * @param integer $id ?????
  582. * @return array
  583. */
  584. function get_vote($id = '') {
  585. $v = M('Vote');
  586. $vo = M('VoteOption');
  587. $db = M();
  588. /* ??????????? */
  589. if (empty($id)) {
  590. $timestamp = gmtime();
  591. $vote = $v->field('*,rand() as rnd')->where("vote_visible = 1 AND vote_status = 1 AND
  592. vote_starttime <= '$timestamp' AND vote_endtime >= '$timestamp'")->order('rnd desc')->limit(1)->find();
  593. } else {
  594. $vote = $v->where("vote_visible = 1 AND vote_status = 1 AND vote_id = '$id'")->find();
  595. }
  596. if ($vote !== false && !empty($vote)) {
  597. /* ?????ID,?????? */
  598. $sql_option = 'SELECT v.*, o.* ' . 'FROM ' . C('DB_PREFIX'). 'vote AS v, ' .C('DB_PREFIX') . 'vote_option AS o ' .
  599. "WHERE o.vote_id = v.vote_id AND o.vote_id = '$vote[vote_id]' order by option_sort asc";
  600. $res = $db->query($sql_option);
  601. /* ??? */
  602. $option_num = $vo->where("vote_id = ".$vote['vote_id'])->sum('option_count');
  603. $arr = array();
  604. $count = 100;
  605. foreach ($res as $idx => $row) {
  606. if ($option_num > 0 && $idx == count($res) - 1) {
  607. $percent = $count;
  608. } else {
  609. $percent = ($row['vote_count'] > 0 && $option_num > 0) ? round(($row['option_count'] / $option_num) * 100) : 0;
  610. $count -= $percent;
  611. }
  612. if($percent < 0) {
  613. $percent = 0;
  614. }
  615. $arr[$row['vote_id']]['options'][$row['option_id']]['percent'] = $percent;
  616. $arr[$row['vote_id']]['vote_id'] = $row['vote_id'];
  617. $arr[$row['vote_id']]['vote_name'] = htmlspecialchars(stripslashes($row['vote_name']));
  618. $arr[$row['vote_id']]['vote_type'] = $row['vote_type'];
  619. $arr[$row['vote_id']]['vote_filterip'] = $row['vote_filterip'];
  620. $arr[$row['vote_id']]['vote_view'] = $row['vote_view'];
  621. $arr[$row['vote_id']]['vote_count'] = $row['vote_count'];
  622. $arr[$row['vote_id']]['options'][$row['option_id']]['option_id'] = $row['option_id'];
  623. $arr[$row['vote_id']]['options'][$row['option_id']]['option_name'] = $row['option_name'];
  624. $arr[$row['vote_id']]['options'][$row['option_id']]['option_url'] = $row['option_url'];
  625. $arr[$row['vote_id']]['options'][$row['option_id']]['option_count'] = $row['option_count'];
  626. $arr[$row['vote_id']]['options'][$row['option_id']]['option_sort'] = $row['option_sort'];
  627. $arr[$row['vote_id']]['options'][$row['option_id']]['option_color'] = get_uid(1); //????
  628. $arr[$row['vote_id']]['options'][$row['option_id']]['option_width'] = ($percent == 0) ? 1 : round($percent);//?????
  629. if($arr[$row['vote_id']]['options'][$row['option_id']]['option_width'] == 100) {
  630. $arr[$row['vote_id']]['options'][$row['option_id']]['option_width'] = 99;
  631. }
  632. }
  633. $vote['vote_id'] = (!empty($vote['vote_id'])) ? $vote['vote_id'] : '';
  634. $ret = array('id' => $vote['vote_id'], 'content' => $arr);
  635. return $ret;
  636. }
  637. }
  638. /**
  639. * ??ip
  640. */
  641. function split_ip($str) {
  642. $str = str_replace("\n",",",$str);
  643. $str = str_replace("\r",",",$str);
  644. $str = str_replace(",,",",",$str);
  645. $str = explode(",",$str);
  646. return $str;
  647. }
  648. function base64_url_encode($input) {
  649. return strtr(base64_encode($input), '+/=', '-_,');
  650. }
  651. function base64_url_decode($input) {
  652. return base64_decode(strtr($input, '-_,', '+/='));
  653. }
  654. /**
  655. * ?$_POST?$_GET?$_COOKIE?$_REQUEST????????
  656. *
  657. * @access public
  658. * @param string $text ???????
  659. * @return string
  660. */
  661. function get_var(&$string) {
  662. if (is_string($string) ) {
  663. $string = Input::getVar($string);
  664. } elseif (is_array($string)){
  665. foreach ($string as $key => $val) {
  666. $string[$key] = get_var($val);
  667. }
  668. } elseif (is_object($string)) {
  669. $vars = get_object_vars($string);
  670. foreach ($vars as $key => $val) {
  671. $string->$key = get_var($val);
  672. }
  673. }
  674. return $string;
  675. }
  676. /**
  677. * ????????????????
  678. *
  679. */
  680. /*import("@.ORG.Input");
  681. if (get_magic_quotes_gpc()) {
  682. $_GET = get_var($_GET);
  683. $_POST = get_var($_POST);
  684. $_COOKIE = get_var($_COOKIE);
  685. $_REQUEST = get_var($_REQUEST);
  686. }*/
  687. /**
  688. * ????????????????
  689. *
  690. * @access public
  691. * @return void
  692. */
  693. function all_stripslashes() {
  694. if (get_magic_quotes_gpc()) {
  695. $_GET = stripslashes_deep($_GET);
  696. $_POST = stripslashes_deep($_POST);
  697. $_COOKIE = stripslashes_deep($_COOKIE);
  698. $_REQUEST = stripslashes_deep($_REQUEST);
  699. }
  700. }
  701. /**
  702. * Remove all blockquote nodes.
  703. */
  704. function rc_remove_blockquotes($str) {
  705. $start_pattern = '<blockquote';
  706. $end_pattern = '</blockquote>';
  707. // The number of blockquote nodes.
  708. $quote_count = substr_count(strtolower($str), $start_pattern);
  709. // If there are 0 blockquote nodes, do nothing.
  710. if ($quote_count <= 0) {
  711. return $str;
  712. // If there is 1 blockquote node, remove it.
  713. } else if($quote_count == 1) {
  714. $all_pattern = '/(\<blockquote(.*?)\>)(.*)(\<\/blockquote\>)/i';
  715. return preg_replace($all_pattern, '', $str);
  716. }
  717. // If there are more than 1 backquote nodes, pick the first ending tag.
  718. $end = strpos(strtolower($str), $end_pattern);
  719. // Loop all the blockquotes.
  720. while ($end) {
  721. // Get substring before first ending tag, and pick the last starting tag.
  722. $str_before_end = substr($str, 0, $end);
  723. $start = strrpos(strtolower($str_before_end), $start_pattern);
  724. // Replace blockquote node to separate.
  725. $sep = ' ';
  726. $str = substr_replace($str, $sep, $start, $end + strlen($end_pattern) - $start);
  727. // Pick next ending tag.
  728. $end = strpos(strtolower($str), $end_pattern);
  729. }
  730. return $str;
  731. }
  732. /**
  733. * ????
  734. *
  735. * @param: $email[string] ???????
  736. * @param: $subject[string] ????
  737. * @param: $content[string] ????
  738. * @param: $type[int] 0 ????? 1 HTML??
  739. *
  740. * @return boolean
  741. */
  742. function send_mail($email, $subject, $content, $type = 1) {
  743. /**
  744. * ??mail??????
  745. */
  746. if (C('mail_service') == 0 && function_exists('mail')) {
  747. /* ??????? */
  748. $content_type = ($type == 0) ? 'Content-Type: text/plain; charset=utf-8' : 'Content-Type: text/html; charset=utf-8';
  749. $headers = array();
  750. $headers[] = 'From: "' . '=?UTF8?B?' . base64_encode(C('blog_name')) . '?='.'" <' . C('smtp_mail') . '>';
  751. $headers[] = $content_type . '; format=flowed';
  752. $res = @mail($email, '=?UTF8?B?' . base64_encode($subject) . '?=', $content, implode("\r\n", $headers));
  753. if (!$res) {
  754. return false;
  755. } else {
  756. return true;
  757. }
  758. } else {
  759. /**
  760. * ??smtp??????
  761. */
  762. import('@.ORG.Phpmailer');
  763. $mail = new PHPMailer();
  764. $mail->IsSMTP();
  765. $mail->Username = C('smtp_user');
  766. $mail->Password = C('smtp_pass');
  767. $mail->From = C('smtp_mail');
  768. $mail->Host = C('smtp_host');
  769. $mail->Port = C('smtp_port');
  770. $mail->Mailer = "smtp";
  771. $mail->FromName = C('blog_name');
  772. ($type == 0) ? $mail->IsHTML(false) : $mail->IsHTML(true);
  773. $mail->SMTPAuth = true;
  774. $mail->CharSet = "utf-8";
  775. $mail->Encoding = "base64";
  776. $mail->Subject = $subject;
  777. $mail->AddAddress("$email", "");
  778. $mail->Body = $body;
  779. if (!$mail->Send()) {
  780. return false;
  781. continue;
  782. } else {
  783. return true;
  784. }
  785. // Clear all addresses and attachments for next loop
  786. $mail->ClearAddresses();
  787. $mail->ClearAttachments();
  788. }
  789. }
  790. ?>