示例#1
0
 public function vxGeoHome($geo)
 {
     $Geo = new Geo($geo, $this->Geo->map);
     $geo_real = mysql_real_escape_string($Geo->geo->geo, $this->db);
     $geo_md5 = md5($geo);
     $geos_all_children = $Geo->vxGetRecursiveChildrenArray('', true);
     $geos_all_children_sql = implode(',', $geos_all_children);
     echo '<div id="main">';
     echo '<div class="blank" align="left">';
     _v_ico_map();
     echo ' <a href="/">' . Vocabulary::site_name . '</a> &gt; ' . Vocabulary::term_region . ' &gt; ' . $Geo->geo->name->cn . ' <span class="tip_i"><small>portal</small></span></div>';
     echo '<div class="blank" align="left">';
     if ($this->User->vxIsLogin()) {
         if ($this->User->usr_geo == $Geo->geo->geo) {
             echo '<span class="text_large">' . _vo_ico_silk('world') . ' ' . $Geo->geo->name->cn . '</span><span class="tip_i"> ... 这是我的当前所在地';
             echo ' / <a href="/user/move.vx" class="t">修改我的所在地</a>';
         } else {
             echo '<span class="text_large">' . _vo_ico_silk('world') . ' ' . $Geo->geo->name->cn . '</span><span class="tip_i"> ... <a href="/geo/' . $this->User->usr_geo . '" class="t">返回' . $this->Geo->map['name'][$this->User->usr_geo] . '</a> / <a href="/user/move.vx" class="t">修改我的所在地</a>';
         }
         if ($geo_count_going = $this->cs->get('babel_geo_going_' . $geo_md5)) {
             $geo_count_going = intval($geo_count_going);
         } else {
             $sql = "SELECT COUNT(*) FROM babel_geo_going WHERE ggg_geo = '{$geo_real}'";
             $rs = mysql_query($sql, $this->db);
             $geo_count_going = mysql_result($rs, 0, 0);
             mysql_free_result($rs);
             $this->cs->save(strval($geo_count_going), 'babel_geo_going_' . $geo_md5);
         }
         $sql = "SELECT ggg_id FROM babel_geo_going WHERE ggg_geo = '{$Geo->geo->geo}' AND ggg_uid = {$this->User->usr_id}";
         $rs = mysql_query($sql);
         if (mysql_num_rows($rs) == 1) {
             $geo_flag_going = true;
         } else {
             $geo_flag_going = false;
         }
         mysql_free_result($rs);
         echo ' ... <a href="/who/going/' . urlencode($Geo->geo->geo) . '" class="o">目前有 ' . $geo_count_going . ' 人想去' . $Geo->geo->name->cn . '</a> / ';
         if ($geo_flag_going) {
             echo '<a href="/revert/going/' . $Geo->geo->geo . '" class="t">我不想去' . $Geo->geo->name->cn . '</a>';
         } else {
             echo '<a href="/set/going/' . $Geo->geo->geo . '" class="t">我想去' . $Geo->geo->name->cn . '</a>';
         }
         if ($geo_count_been = $this->cs->get('babel_geo_visited_' . $geo_md5)) {
             $geo_count_been = intval($geo_count_been);
         } else {
             $sql = "SELECT COUNT(*) FROM babel_geo_been WHERE gbn_geo = '{$geo_real}'";
             $rs = mysql_query($sql, $this->db);
             $geo_count_been = mysql_result($rs, 0, 0);
             mysql_free_result($rs);
             $this->cs->save(strval($geo_count_been), 'babel_geo_visited_' . $geo_md5);
         }
         $sql = "SELECT gbn_id FROM babel_geo_been WHERE gbn_geo = '{$Geo->geo->geo}' AND gbn_uid = {$this->User->usr_id}";
         $rs = mysql_query($sql);
         if (mysql_num_rows($rs) == 1) {
             $geo_flag_been = true;
         } else {
             $geo_flag_been = false;
         }
         mysql_free_result($rs);
         echo ' ... <a href="/who/visited/' . urlencode($Geo->geo->geo) . '" class="o">目前有 ' . $geo_count_been . ' 人去过' . $Geo->geo->name->cn . '</a> / ';
         if ($geo_flag_been) {
             echo '<a href="/revert/been/' . $Geo->geo->geo . '" class="t">我没有去过' . $Geo->geo->name->cn . '</a>';
         } else {
             echo '<a href="/set/been/' . $Geo->geo->geo . '" class="t">我去过' . $Geo->geo->name->cn . '</a>';
         }
         echo '</span>';
         if (isset($_SESSION['babel_geo_message'])) {
             if ($_SESSION['babel_geo_message'] != '') {
                 _v_hr();
                 echo '<div class="notify">' . $_SESSION['babel_geo_message'] . '</div>';
                 $_SESSION['babel_geo_message'] = '';
             }
         }
     } else {
         echo '<span class="text_large">' . _vo_ico_silk('world') . ' ' . $Geo->geo->name->cn . '</span>';
     }
     _v_hr();
     if ($geo_route = $this->cs->get('babel_geo_route_' . $geo_md5)) {
         $geo_route = unserialize($geo_route);
     } else {
         $geo_route = $Geo->vxGetRoute($geo);
         $this->cs->save(serialize($geo_route), 'babel_geo_route_' . $geo_md5);
     }
     echo '<div class="geo_home_middle" style="margin-bottom: 5px;" ><img src="/img/gt.gif" align="absmiddle" /> ';
     $i = 0;
     foreach ($geo_route as $g => $g_name) {
         $i++;
         if ($i == 1) {
             if ($g == $geo) {
                 echo $g_name;
             } else {
                 echo '<a href="/geo/' . $g . '" class="o">' . $g_name . '</a>';
             }
         } else {
             if ($g == $geo) {
                 echo ' &gt; ' . $g_name;
             } else {
                 echo ' &gt; <a href="/geo/' . $g . '" class="o">' . $g_name . '</a>';
             }
         }
     }
     if ($Geo->geo->description->cn != '') {
         echo '<div class="geo_home_desc">';
         echo $Geo->geo->description->cn;
         _v_d_e();
     }
     _v_d_e();
     /* Start: geos_children */
     if ($geos_children = $this->cl->load('babel_geo_children_' . $geo_md5)) {
         $geos_children = unserialize($geos_children);
     } else {
         $geos_children = $this->Geo->vxGetChildrenArray($geo);
         $this->cl->save(serialize($geos_children), 'babel_geo_children_' . $geo_md5);
     }
     if (count($geos_children) > 0) {
         $len_total = 0;
         foreach ($geos_children as $elem) {
             $len_total = $len_total + mb_strlen($elem, 'UTF-8');
         }
         $len_avg = floor($len_total / count($geos_children));
         $br = calc_geo_break($len_avg);
         _v_hr();
         if ($o = $this->cl->load('babel_geo_children_' . $geo_md5 . '_o')) {
             echo $o;
         } else {
             $o = '';
             $o .= '<div class="geo_home_bar"><img src="/img/icons/silk/world_go.png" align="absmiddle" /> 下属于' . $Geo->geo->name->cn . '的区域</div>';
             $o .= '<div class="geo_home_content">';
             $o .= '<blockquote>';
             $i = 0;
             foreach ($geos_children as $g => $g_name) {
                 $i++;
                 $css_color = rand_color();
                 $o .= '<a href="/geo/' . $g . '" class="var" style="color: ' . $css_color . ';">' . $g_name . '</a>&nbsp; ';
                 if ($i % $br == 0) {
                     $o .= '<br />';
                 }
             }
             $o .= '</blockquote>';
             $o .= '</div>';
             echo $o;
             $this->cl->save($o, 'babel_geo_children_' . $geo_md5 . '_o');
         }
     }
     /* End: array geos_children */
     /* Start: array geos_parallel */
     if ($geos_parallel = $this->cl->load('babel_geo_parallel_' . $geo_md5)) {
         $geos_parallel = unserialize($geos_parallel);
     } else {
         $geos_parallel = $this->Geo->vxGetParallelArray($geo);
         $this->cl->save(serialize($geos_parallel), 'babel_geo_parallel_' . $geo_md5);
     }
     if (count($geos_parallel) > 0) {
         $len_total = 0;
         foreach ($geos_parallel as $elem) {
             $len_total = $len_total + mb_strlen($elem, 'UTF-8');
         }
         $len_avg = floor($len_total / count($geos_parallel));
         $br = calc_geo_break($len_avg);
         _v_hr();
         if ($o = $this->cl->load('babel_geo_parallel_' . $geo_md5 . '_o')) {
             echo $o;
         } else {
             $o = '';
             $o .= '<div class="geo_home_bar"><img src="/img/icons/silk/world_link.png" align="absmiddle" /> 与' . $Geo->geo->name->cn . '平行的区域</div>';
             $o .= '<div class="geo_home_content">';
             $o .= '<blockquote>';
             $i = 0;
             foreach ($geos_parallel as $g => $g_name) {
                 $i++;
                 $css_color = rand_color();
                 $o .= '<a href="/geo/' . $g . '" class="var" style="color: ' . $css_color . ';">' . $g_name . '</a>&nbsp; ';
                 if ($i % $br == 0) {
                     $o .= '<br />';
                 }
             }
             $o .= '</blockquote>';
             $o .= '</div>';
             echo $o;
             $this->cl->save($o, 'babel_geo_parallel_' . $geo_md5 . '_o');
         }
     }
     /* End: array geos_parallel */
     if ($_SESSION['babel_ua']['GECKO_DETECTED'] || $_SESSION['babel_ua']['KHTML_DETECTED'] || $_SESSION['babel_ua']['OPERA_DETECTED']) {
         $hack_width = 'width="100%" ';
     } else {
         $hack_width = 'width="99%" ';
     }
     echo '<table cellpadding="0" cellspacing="0" border="0" ' . $hack_width . '>';
     echo '<tr>';
     echo '<td width="60%" align="left" valign="top" style="border-right: 1px solid #EEE; border-top: 1px solid #EEE; border-bottom: 1px solid #EEE;">';
     echo '<div class="geo_home_bar_top"><img src="/img/icons/silk/award_star_gold_2.png" align="absmiddle" /> 同区域最新活跃主题<span class="tip_i"> ... <img src="/img/icons/silk/feed.png" align="absmiddle" alt="RSS" /> <a href="/feed/geo/' . $Geo->geo->geo . '">RSS 种子输出</a></span></div>';
     echo '<div class="geo_home_content">';
     if ($Topics = $this->cs->get('babel_geo_topics_latest_' . $geo_md5)) {
         $Topics = unserialize($Topics);
     } else {
         $sql = "SELECT usr_id, usr_nick, usr_portrait, usr_gender, tpc_id, tpc_uid, tpc_title, tpc_content, tpc_hits FROM babel_topic, babel_user WHERE tpc_uid = usr_id AND usr_id IN (SELECT usr_id FROM babel_user WHERE usr_geo IN ({$geos_all_children_sql})) AND tpc_flag IN (0, 2) AND tpc_pid NOT IN " . BABEL_NODES_POINTLESS . " ORDER BY tpc_lasttouched DESC LIMIT 25";
         $rs = mysql_query($sql, $this->db);
         $Topics = array();
         while ($Topic = mysql_fetch_object($rs)) {
             $Topics[$Topic->tpc_id] = $Topic;
         }
         $this->cs->save(serialize($Topics), 'babel_geo_topics_latest_' . $geo_md5);
     }
     $i = 0;
     $authors = array();
     foreach ($Topics as $Topic) {
         $i++;
         if (!array_key_exists($Topic->usr_id, $authors)) {
             $authors[$Topic->usr_id] = rand_color();
         }
         if ($i > 1) {
             if ($i % 2 == 0) {
                 $css_class = 'geo_home_entry_even';
             } else {
                 $css_class = 'geo_home_entry_odd';
             }
         } else {
             $css_class = 'geo_home_entry_odd';
         }
         $img_p = $Topic->usr_portrait ? CDN_IMG . 'p/' . $Topic->usr_portrait . '_n.jpg' : CDN_IMG . 'p_' . $Topic->usr_gender . '_n.gif';
         echo '<div class="' . $css_class . '"><img src="' . $img_p . '" class="portrait" align="absmiddle" border="0" /> <a href="/topic/view/' . $Topic->tpc_id . '.html">' . make_plaintext($Topic->tpc_title) . '</a> <span class="tip_i">...</span> <a href="/u/' . urlencode($Topic->usr_nick) . '" style="color: ' . $authors[$Topic->usr_id] . '" class="var">' . make_plaintext($Topic->usr_nick) . '</a></div>';
     }
     _v_d_e();
     echo '</td>';
     echo '<td width="40%" align="left" valign="top" style="border-top: 1px solid #EEE; border-bottom: 1px solid #EEE;">';
     echo '<div class="geo_home_bar_top"><img src="/img/icons/silk/award_star_gold_1.png" align="absmiddle" /> 本月同区域最热主题</div>';
     echo '<div class="geo_home_content">';
     if ($Topics = $this->cs->get('babel_geo_topics_hot_' . $geo_md5)) {
         $Topics = unserialize($Topics);
     } else {
         $now = getdate(time());
         $start = mktime(0, 0, 0, $now['mon'], 1, $now['year']);
         $sql = "SELECT tpc_id, tpc_title, tpc_hits, tpc_posts FROM babel_topic WHERE tpc_uid IN (SELECT usr_id FROM babel_user WHERE usr_geo IN ({$geos_all_children_sql})) AND tpc_created > {$start} AND tpc_flag IN (0, 2) AND tpc_pid NOT IN " . BABEL_NODES_POINTLESS . " ORDER BY tpc_hits DESC, tpc_lasttouched DESC LIMIT 10";
         $rs = mysql_query($sql, $this->db);
         $Topics = array();
         while ($Topic = mysql_fetch_object($rs)) {
             $Topics[$Topic->tpc_id] = $Topic;
         }
         $this->cs->save(serialize($Topics), 'babel_geo_topics_hot_' . $geo_md5);
     }
     $i = 0;
     foreach ($Topics as $Topic) {
         $i++;
         if ($i > 1) {
             if ($i % 2 == 0) {
                 $css_class = 'geo_home_entry_even';
             } else {
                 $css_class = 'geo_home_entry_odd';
             }
         } else {
             $css_class = 'geo_home_entry_odd';
         }
         echo '<div class="' . $css_class . '"><small class="fade">' . $i . '.</small> ' . '<a href="/topic/view/' . $Topic->tpc_id . '.html">' . make_plaintext($Topic->tpc_title) . '</a> <span class="tip_i"><small> ... ' . $Topic->tpc_hits . '/' . $Topic->tpc_posts . '</small></span>';
         _v_d_e();
     }
     echo '</div>';
     _v_hr();
     if ($geo_count = $this->cs->get('babel_geo_settle_count_' . $geo_md5)) {
         $geo_count = intval($geo_count);
     } else {
         $sql = "SELECT COUNT(*) FROM babel_user WHERE usr_geo IN ({$geos_all_children_sql})";
         $rs = mysql_query($sql, $this->db);
         $geo_count = intval(mysql_result($rs, 0, 0));
         mysql_free_result($rs);
         $this->cs->save(strval($geo_count), 'babel_geo_settle_count_' . $geo_md5);
     }
     echo '<div class="geo_home_bar"><img src="/img/icons/silk/group.png" align="absmiddle" /> 在' . $Geo->geo->name->cn . '的会员<span class="tip_i"> ... 共 ' . $geo_count . ' 人</span></div>';
     $sql = "SELECT usr_id, usr_gender, usr_portrait, usr_nick FROM babel_user WHERE usr_geo IN ({$geos_all_children_sql}) ORDER BY usr_created DESC LIMIT 10";
     $rs = mysql_query($sql, $this->db);
     if (mysql_num_rows($rs) > 0) {
         echo '<div class="geo_home_content"><div class="geo_home_entry_odd" align="left">';
     }
     while ($User = mysql_fetch_object($rs)) {
         $img_p = $User->usr_portrait ? CDN_IMG . 'p/' . $User->usr_portrait . '_n.jpg' : CDN_IMG . 'p_' . $User->usr_gender . '_n.gif';
         echo '<a href="/u/' . urlencode($User->usr_nick) . '"><img src="' . $img_p . '" alt="' . make_single_return($User->usr_nick) . '" class="psmall" align="absmiddle" border="0" /></a> ';
     }
     if ($geo_count > 10) {
         echo '<span class="tip_i"> ... <small><a href="/who/settle/' . $Geo->geo->geo . '" class="o">more</a> &gt;</small></span></div>';
     } else {
         if (mysql_num_rows($rs) > 0) {
             _v_d_e();
         }
     }
     mysql_free_result($rs);
     _v_d_e();
     if ($this->User->vxIsLogin()) {
         if ($friends = $this->cs->get('babel_user_friends_geo_' . $geo_md5 . '_' . $this->User->usr_id)) {
             $friends = unserialize($friends);
         } else {
             $sql = "SELECT usr_id, usr_gender, usr_portrait, usr_nick FROM babel_user WHERE usr_geo IN ({$geos_all_children_sql}) AND usr_id IN (SELECT frd_fid FROM babel_friend WHERE frd_uid = {$this->User->usr_id}) ORDER BY usr_created DESC";
             $rs = mysql_query($sql, $this->db);
             $friends = array();
             while ($Friend = mysql_fetch_object($rs)) {
                 $friends[$Friend->usr_id] = $Friend;
             }
             mysql_free_result($rs);
             $this->cs->save(serialize($friends), 'babel_user_friends_geo_' . $geo_md5 . '_' . $this->User->usr_id);
         }
         $friends_count = count($friends);
         _v_hr();
         echo '<div class="geo_home_bar"><img src="/img/icons/silk/heart.png" align="absmiddle" /> 我在' . $Geo->geo->name->cn . '的好友<span class="tip_i"> ... 共 ' . $friends_count . ' 人</span></div>';
         echo '<div class="geo_home_content">';
         $i = 0;
         $gap = 13;
         foreach ($friends as $Friend) {
             $i++;
             if ($i == 1) {
                 echo '<div class="geo_home_entry_odd" align="left">';
             }
             if ($i > $gap && ($i - 1) % $gap == 0) {
                 if (($i - 1) / $gap % 2 == 0) {
                     echo '<div class="geo_home_entry_odd" align="left">';
                 } else {
                     echo '<div class="geo_home_entry_even" align="left">';
                 }
             }
             $img_p = $Friend->usr_portrait ? CDN_IMG . 'p/' . $Friend->usr_portrait . '_n.jpg' : CDN_IMG . 'p_' . $Friend->usr_gender . '_n.gif';
             echo '<a href="/u/' . urlencode($Friend->usr_nick) . '"><img src="' . $img_p . '" alt="' . make_single_return($Friend->usr_nick) . '" class="psmall" align="absmiddle" border="0" /></a> ';
             if ($i > $gap - 1 && $i % $gap == 0) {
                 echo '</div>';
             }
         }
         _v_d_e();
         _v_hr();
         echo '<div class="geo_home_bar">';
         _v_ico_silk('clock');
         echo ' ' . $Geo->geo->name->cn . '的人们在做什么?';
         _v_d_e();
         echo '<div class="geo_home_content">';
         $sql = 'SELECT usr_id, usr_nick, usr_gender, usr_portrait, ing_id, ing_doing, ing_created FROM babel_user, babel_ing_update WHERE ing_uid = usr_id AND usr_geo IN (' . $geos_all_children_sql . ') ORDER BY ing_created DESC LIMIT 10';
         $rs = mysql_query($sql);
         $i = 0;
         while ($_ing = mysql_fetch_array($rs)) {
             $i++;
             if ($i % 2 == 0) {
                 $css_class = 'even';
             } else {
                 $css_class = 'odd';
             }
             $img_p = $_ing['usr_portrait'] ? CDN_IMG . 'p/' . $_ing['usr_portrait'] . '_n.jpg' : CDN_IMG . 'p_' . $_ing['usr_gender'] . '_n.gif';
             echo '<div class="geo_home_entry_' . $css_class . '"><img src="' . $img_p . '" align="absmiddle" alt="' . make_single_return($_ing['usr_nick']) . '" class="portrait" /> <a href="/ing-' . $_ing['ing_id'] . '.html">' . format_ubb($_ing['ing_doing']) . '</a><span class="tip_i"> ... <a href="/u/' . urlencode($_ing['usr_nick']) . '" style="color: ' . rand_color() . '" class="var">' . make_plaintext($_ing['usr_nick']) . '</a></span></div>';
         }
         mysql_free_result($rs);
         _v_d_e();
     }
     _v_d_e();
     echo '</td>';
     echo '</tr>';
     echo '</table>';
     echo '<div class="geo_home_middle" style="margin-bottom: 5px;" ><img src="/img/gt.gif" align="absmiddle" /> ';
     $i = 0;
     foreach ($geo_route as $g => $g_name) {
         $i++;
         if ($i == 1) {
             if ($g == $geo) {
                 echo $g_name;
             } else {
                 echo '<a href="/geo/' . $g . '" class="o">' . $g_name . '</a>';
             }
         } else {
             if ($g == $geo) {
                 echo ' &gt; ' . $g_name;
             } else {
                 echo ' &gt; <a href="/geo/' . $g . '" class="o">' . $g_name . '</a>';
             }
         }
     }
     _v_d_e();
     /* To be implemented: Geo related sites
     		_v_hr();
     		echo('<div class="geo_home_bar"><img src="/img/gt.gif" align="absmiddle" /> ' . $Geo->geo->name->cn . '的相关网站</div>');
     		*/
     _v_d_e();
     echo '</div>';
 }