Project Babel

Made by V2EX | software for internet'); } /* S Node class */ class Node { public $db; public $nod_id; public $nod_pid; public $nod_uid; public $nod_sid; public $nod_level; public $nod_name; public $nod_title; public $nod_title_en_us; public $nod_title_de_de; public $nod_title_zh_cn; public $nod_title_i18n; public $nod_description; public $nod_header; public $nod_footer; public $nod_topics; public $nod_favs; public $nod_created; public $nod_lastupdated; public $usr_id; public $usr_nick; public function __construct($node_id, $db) { $this->db =& $db; $sql = "SELECT nod_id, nod_pid, nod_uid, nod_sid, nod_level, nod_name, nod_title, nod_title_en_us, nod_title_de_de, nod_title_zh_cn, nod_description, nod_header, nod_footer, nod_topics, nod_favs, nod_created, nod_lastupdated, usr_id, usr_nick FROM babel_node, babel_user WHERE nod_uid = usr_id AND nod_id = {$node_id}"; $rs = mysql_query($sql, $this->db); $O = mysql_fetch_object($rs); mysql_free_result($rs); $this->nod_id = $O->nod_id; $this->nod_pid = $O->nod_pid; $this->nod_uid = $O->nod_uid; $this->nod_sid = $O->nod_sid; $this->nod_level = $O->nod_level; $this->nod_name = $O->nod_name; $this->nod_title = $O->nod_title; $this->nod_title_en_us = $O->nod_title_en_us; $this->nod_title_de_de = $O->nod_title_de_de; $this->nod_title_zh_cn = $O->nod_title_zh_cn; $this->nod_title_i18n = $O->nod_title; switch (BABEL_LANG) { default: case 'en_us': if ($this->nod_title_en_us != '') { $this->nod_title_i18n = $this->nod_title_en_us; } break; case 'zh_cn': if ($this->nod_title_zh_cn != '') { $this->nod_title_i18n = $this->nod_title_zh_cn; } break; case 'de_de': if ($this->nod_title_de_de != '') { $this->nod_title_i18n = $this->nod_title_de_de; } break; } $this->nod_description = $O->nod_description; $this->nod_header = $O->nod_header; $this->nod_footer = $O->nod_footer; $this->nod_topics = $O->nod_topics; $this->nod_favs = $O->nod_favs; $this->nod_created = $O->nod_created; $this->nod_lastupdated = $O->nod_lastupdated; $this->usr_id = $O->usr_id; $this->usr_nick = $O->usr_nick; $O = null; } public function __destruct() { } public function vxGetNodeInfo($node_id) { $sql = "SELECT nod_id, nod_name, nod_title, nod_title_en_us, nod_title_de_de, nod_title_zh_cn FROM babel_node WHERE nod_id = {$node_id}"; $rs = mysql_query($sql, $this->db); $Node = mysql_fetch_object($rs); mysql_free_result($rs); $Node->nod_title_i18n = $Node->nod_title; switch (BABEL_LANG) { default: case 'en_us': if ($Node->nod_title_en_us != '') { $Node->nod_title_i18n = $Node->nod_title_en_us; } break; case 'zh_cn': if ($Node->nod_title_zh_cn != '') { $Node->nod_title_i18n = $Node->nod_title_zh_cn; } break; case 'de_de': if ($Node->nod_title_de_de != '') { $Node->nod_title_i18n = $Node->nod_title_de_de; } break; } return $Node; } public function vxUpdateTopics($board_id = '') { if ($board_id == '') { $board_id = $this->nod_id; } $_t = time(); $sql = "SELECT COUNT(tpc_id) FROM babel_topic WHERE tpc_pid = {$board_id}"; $rs = mysql_query($sql, $this->db); $nod_topics = mysql_result($rs, 0, 0); mysql_free_result($rs); $sql = "UPDATE babel_node SET nod_topics = {$nod_topics}, nod_lastupdated = {$_t} WHERE nod_id = {$board_id} LIMIT 1"; mysql_query($sql, $this->db); if (mysql_affected_rows($this->db) == 1) { return true; } else { return false; } } public function vxUpdateFavs($board_id = '') { if ($board_id == '') { $board_id = $this->nod_id; } $sql = "SELECT COUNT(fav_id) FROM babel_favorite WHERE fav_res = '{$board_id}' AND fav_type = 1"; $rs = mysql_query($sql, $this->db); $nod_favs = mysql_result($rs, 0, 0); mysql_free_result($rs); $sql = "UPDATE babel_node SET nod_favs = {$nod_favs} WHERE nod_id = {$board_id} LIMIT 1"; mysql_query($sql, $this->db); if (mysql_affected_rows($this->db) == 1) { return true; } else { return false; } } public function vxGetNodeChildren($section_id = '') { if ($section_id == '') { $section_id = $this->nod_id; } $sql = "SELECT nod_id, nod_name, nod_title FROM babel_node WHERE nod_pid = {$section_id} ORDER BY nod_topics DESC"; $rs = mysql_query($sql, $this->db); if (mysql_num_rows($rs) > 0) { return $rs; } else { return false; } } public function vxDrawChannels($board_id = '', $exclude = 0) { echo (''); if ($board_id == '') { $board_id = $this->nod_id; } $sql = "SELECT chl_id, chl_title, chl_url FROM babel_channel WHERE chl_pid = {$board_id} ORDER BY chl_title"; $rs = mysql_query($sql, $this->db); $count = mysql_num_rows($rs); if ($count > 0) { switch (BABEL_LANG) { case 'en_us': default: echo($exclude != 0 ? ' ... ' . $count . ' more channels
':' ... ' . $count . ' related channels
'); break; case 'zh_cn': echo($exclude != 0 ? ',' . $count . ' 个其他相关频道
':',' . $count . ' 个相关频道'); break; } _v_hr(); echo('
'); while ($Channel = mysql_fetch_object($rs)) { if (trim($Channel->chl_title) == '') { $Channel->chl_title = $Channel->chl_url; } if ($Channel->chl_id == $exclude) { echo('' . make_plaintext($Channel->chl_title) . ' '); } else { $css_color = rand_color(); echo('' . make_plaintext($Channel->chl_title) . ' '); } } mysql_free_result($rs); echo('
'); return true; } else { echo(''); mysql_free_result($rs); return false; } } public function vxDrawAlsoFav($c, $i18n_label) { $board_id = $this->nod_id; if ($o = $c->load('babel_node_fav_also_' . $board_id)) { } else { $sql = "SELECT fav_uid FROM babel_favorite WHERE fav_res = {$board_id} AND fav_type = 1"; $rs = mysql_query($sql); $_users = array(); while ($_user = mysql_fetch_array($rs)) { $_users[] = $_user['fav_uid']; } mysql_free_result($rs); $_nodes = array(); $o = ''; if (count($_users) > 0) { foreach ($_users as $usr_id) { $sql = "SELECT fav_res FROM babel_favorite WHERE fav_uid = {$usr_id} AND fav_type = 1"; $rs = mysql_query($sql); if (mysql_num_rows($rs) > 0) { while ($_node = mysql_fetch_array($rs)) { if (array_key_exists(intval($_node['fav_res']), $_nodes)) { $_nodes[$_node['fav_res']]++; } else { $_nodes[$_node['fav_res']] = 1; } } } mysql_free_result($rs); } } if (count($_nodes) > 0) { arsort($_nodes); $_nodes_keys = array_keys($_nodes); $sql = "SELECT nod_id, nod_title, nod_name FROM babel_node WHERE nod_id IN (" . implode(',', $_nodes_keys) . ")"; $rs = mysql_query($sql); if (mysql_num_rows($rs) > 0) { while ($_node = mysql_fetch_array($rs)) { $_nodes_names[$_node['nod_id']] = $_node['nod_name']; $_nodes_titles[$_node['nod_id']] = $_node['nod_title']; } $o .= _vo_hr(); $o .= '' . _vo_ico_silk('star') . ' ' . $i18n_label . ' ... '; $i = 0; if (count($_nodes_keys) > 7) { $max = 8; } else { $max = count($_nodes_keys); } while ($i < $max) { $css_color = rand_color(); $o .= '' . make_plaintext($_nodes_titles[$_nodes_keys[$i]]) . ' (' . $_nodes[$_nodes_keys[$i]] . ') '; $i++; } } else { $o = ''; } mysql_free_result($rs); } else { $o = ''; } $c->save($o, 'babel_node_fav_also_' . $board_id); } echo $o; } public function vxDrawStock($c) { if (!BABEL_FEATURE_NODE_STOCK) { return false; } else { if ($o = $c->load('babel_node_stock_' . $this->nod_id)) { if ($o == '') { return false; } else { echo $o; return true; } } else { $special = false; $fix = ''; if (preg_match('/^6([0-9]{5})$/', $this->nod_name) || $this->nod_name == 'sh000001') { $special = 'sh'; if ($this->nod_name == 'sh000001') { $this->nod_name = '000001'; $fix = '+' . urlencode('-深发展'); } } if ((preg_match('/^0([0-9]{5})$/', $this->nod_name) || $this->nod_name == '399001' || preg_match('/^3([0-9]{5})$/', $this->nod_name)) && $special == false) { $special = 'sz'; } $o = ''; if ($special == 'sh' || $special == 'sz') { $o .= ''; $o .= ' '; $o .= ''; $news = fetch_rss('http://news.google.com/news?hl=zh-CN&ned=cn&q=' . $this->nod_name . '+%7C+' . urlencode($this->nod_title) . $fix . '&ie=UTF-8&output=rss'); $blogs = fetch_rss('http://blogsearch.google.com/blogsearch_feeds?hl=en&q=' . $this->nod_name . '+%7C+' . urlencode($this->nod_title) . $fix . '&ie=utf-8&num=10&output=rss'); $tn = fetch_rss('http://feeds.technorati.com/search/' . $this->nod_name); $o .= ''; $o .= ''; $o .= ' '; $o .= $this->nod_header . ' 行情图表 | Google Blog Search results for ' . $this->nod_title . ' | 新闻资讯 | Technorati results for ' . $this->nod_title . ''; $o .= _vo_hr(); $o .= '
回到顶部
'; $o .= _vo_ico_silk('chart_line'); $o .= ' ' . $this->nod_header . ' 的行情图表
'; $o .= '
'; $o .= ''; $o .= ''; $o .= '图表切换 分时行情 | 5 分钟 K 线 | 日 K 线 | 周 K 线 | 月 K 线 | RSI | MACD | KDJ | MIKE
'; $o .= '
'; $o .= _vo_hr(); $o .= '
回到顶部
'; $o .= _vo_ico_silk('comments'); $o .= ' 来自 Google Blog Search 的关于 ' . $this->nod_header . ' 的最新消息
'; $i = 0; foreach ($blogs->items as $blog) { $i++; $css_class = $i % 2 == 0 ? 'even' : 'odd'; $d = str_replace('', '', $blog['description']); $d = str_replace('', '', $d); $t = str_replace('', '', $blog['title']); $t = str_replace('', '', $t); $o .= '
'; $o .= ''; $o .= _vo_ico_silk('bullet_blue'); $o .= ' ' . $t . ''; $o .= $d; $o .= '
'; unset($blog); } $o .= _vo_hr(); $o .= '
回到顶部
'; $o .= _vo_ico_silk('world'); $o .= ' 来自互联网的关于 ' . $this->nod_header . ' 的最新资讯
'; $i = 0; foreach ($news->items as $item) { $i++; $css_class = $i % 2 == 0 ? 'even' : 'odd'; $n = str_replace('
', '
', $item['description']); $n = str_replace('' . $this->nod_title . '', $this->nod_title, $n); $n = str_replace('' . $this->nod_title . $this->nod_name . '', $this->nod_title . $this->nod_name, $n); $n = str_replace('' . $this->nod_name . $this->nod_title . '', $this->nod_name . $this->nod_title, $n); $n = str_replace('' . $this->nod_name . '', $this->nod_name, $n); $n = preg_replace('/([^<]+)<\/a>
/', '' . _vo_ico_silk('bullet_black') . '
$2',$n); $n = str_replace(' ', '', $n); $o .= '
' . $n . '
'; unset($item); } $o .= _vo_hr(); $o .= '
回到顶部
'; $o .= _vo_ico_silk('comments'); $o .= ' 来自 Technorati 的关于 ' . $this->nod_header . ' 的最新消息
'; $i = 0; foreach ($tn->items as $blog) { $i++; $css_class = $i % 2 == 0 ? 'even' : 'odd'; $d = str_replace('

Posted in', $d); $t = $blog['title']; $o .= '
'; $o .= ''; $o .= _vo_ico_silk('bullet_blue'); $o .= ' ' . $t . ''; $o .= $d; $o .= '
'; unset($blog); } $o .= _vo_hr(); $o .= '各大财经网站关于 ' . $this->nod_title . ' (' . $this->nod_name . ') 的相关信息 '; $o .= '新浪 | '; $o .= '和讯 | '; $o .= '东方财富网 | '; $o .= '证券之星 | '; $o .= '金融界'; $o .= ''; $o .= _vo_hr(); $o .= '回到顶部'; $o .= ''; $o .= ''; echo $o; $c->save($o, 'babel_node_stock_' . $this->nod_id); return true; } else { $c->save($o, 'babel_node_stock_' . $this->nod_id); return false; } } } } private function vxTrimKijijiTitle($title) { if (mb_ereg_match('最新的客齐集广告', $title)) { mb_ereg('最新的客齐集广告 所在地:(.+) 分类:(.+)', $title, $m); return $m[2]; } else { return $title; } } } /* E Node class */ ?>