Advertisement
Guest User

Pixmicat! mod_pushpost Special Edition for 7th

a guest
Mar 5th, 2013
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 21.09 KB | None | 0 0
  1. <?php
  2. class mod_pushpost extends ModuleHelper {
  3.         // 推文判斷起始標籤
  4.         private $PUSHPOST_SEPARATOR = '[MOD_PUSHPOST_USE]';
  5.         // 討論串最多顯示之推文筆數 (超過則自動隱藏,全部隱藏:0)
  6.         private $PUSHPOST_DEF = 10;
  7.         // 表情
  8.         private $PUSH_EMOTIONS = array("","(゚∀゚)","(´∀`)","(*´∀`)","(*゚∇゚)","(*´д`)","(*゚ー゚)","(゚3゚)","(´ー`)","(・_ゝ・)","(´,_ゝ`)","(´_ゝ`)","(・ー・)","(・∀・)","(ゝ∀・)",
  9.                         "(〃∀〃)","(*゚∀゚*)","(゚∀。)","(`д´)","(`ε´)","(`ヮ´)","σ`∀´)","゚∀゚)σ","゚∀゚)ノ","(╬゚д゚)","(|||゚д゚)","(´゚д゚`)","(゚д゚)","Σ(゚д゚)","(;゚д゚)","(;´д`)",
  10.                         "(д)゚゚","(☉д⊙)","(((゚д゚)))","(`・´)","(´д`)","(-д-)","(&gt;д&lt;)","(つд⊂)","・゚(ノд`゚)","(TдT)","(*´ω`*)","(・ω・)","(`・ω・)","(´・ω)","(`・ω)",
  11.                         "(´・ω・`)","(`・ω・´)","(・_っ・)","(^_っ^)","(`_っ´)","(`ー´)","(´_っ`)","(´ρ`)","(゚ω゚)","(o゚ω゚o)","(^ω^)","(・ิ㉨・ิ)","(。◕∀◕。)","ヾ(´ε`ヾ)","(ノ・ω・)ノ",
  12.                         "(ノ゚∀゚)ノ","(σ゚д゚)σ","(σ゚∀゚)σ","|д`)","|ー`)","|д゚)","|∀゚)","ヽ(●´∀`●)ノ","(゚д゚≡゚д゚)","。・゚・(つд`゚)・゚・","_,._","゚Å゚)","⊂彡☆))д`)","⊂彡☆))д´)",
  13.                         "⊂彡☆))∀`)","(´∀((☆ミつ");
  14.         //發言
  15.          private $GESTURES = array("","<","。o0","ノシ","彡","o彡゚","ゝ","ㄏ","ノ","ノ゛","ノ","ノミ","ツ","っ","っ゛","つ","つ゛","o","凸","/","y","y━・~","y-~","≡3","~♪","♬","❤",
  16.                         "~♥","σ","ノ彡┴─┴","⌒*","⌒☆","⌒★","≡☆");
  17.          
  18.         public function __construct($PMS) {
  19.                 parent::__construct($PMS);
  20.                
  21.                 $this->loadLanguage(); // 載入語言檔
  22.         }
  23.  
  24.         /* Get the name of module */
  25.         public function getModuleName() {
  26.                 return $this->moduleNameBuilder('文章推文機制+整合K島V板表情符號');
  27.         }
  28.  
  29.         /* Get the module version infomation */
  30.         public function getModuleVersionInfo() {
  31.                 return '7th.Release.SP(v130305)';
  32.         }
  33.  
  34.         /**
  35.         * 生成識別ID
  36.         *
  37.         * @return string 長度8識別ID
  38.          */
  39.         private function getID() {
  40.                 return substr(crypt(md5(getREMOTE_ADDR().IDSEED.gmdate('Ymd', time() + TIME_ZONE * 3600)), 'id'), -8);
  41.         }
  42.  
  43.         public function autoHookHead(&$txt, $isReply) {
  44.                 $txt .= '<style type="text/css">.pushpost { background-color: #fff; font-size: 0.8em; padding: 10px; }</style>
  45. <script type="text/javascript">
  46. // <![CDATA[
  47. var lastpushpost=0;
  48. function mod_pushpostShow(pid){
  49.        $g("mod_pushpostID").value = pid;
  50.        $g("mod_pushpostName").value = getCookie("namec");
  51.        $("div#mod_pushpostBOX").insertBefore($("div#r"+pid+" .quote"));
  52.  
  53.        if(lastpushpost!=pid) {
  54.                $("div#mod_pushpostBOX").show();
  55.        } else
  56.                $("div#mod_pushpostBOX").toggle();
  57.        lastpushpost = pid;
  58.        return false;
  59. }
  60. function mod_pushpostKeyPress(e){if(e.which==13){e.preventDefault();mod_pushpostSend();}}
  61. function mod_pushpostSend(){
  62.        var o0 = $g("mod_pushpostID"), o1 = $g("mod_pushpostName"), o2 = $g("mod_pushpostComm"), o3 = $g("mod_pushpostSmb"), pp = $("div#r"+o0.value+" .quote"), o4 = $("#push_emotion option:selected").val(), o5 = $("#gesture option:selected").val();
  63.        if(o2.value===""){ alert("'.$this->_T('nocomment').'"); return false; }
  64.        o1.disabled = o2.disabled = o3.disabled = true;
  65.        $.ajax({
  66.                url: "'.str_replace('&amp;', '&', $this->getModulePageURL()).'&no="+o0.value,
  67.                type: "POST",
  68.                data: {ajaxmode: true, name: o1.value, push_emotion: o4, gesture: o5, comm: o2.value},
  69.                success: function(rv){
  70.                        if(rv.substr(0, 4)!=="+OK "){ alert(rv); o3.disabled = false; return false; }
  71.                        rv = rv.substr(4);
  72.                        (pp.find(".pushpost").length===0)
  73.                                ? pp.append("<div class=\'pushpost\'>"+rv+"</div>")
  74.                                : pp.children(".pushpost").append("<br />"+rv);
  75.                        o0.value = o1.value = o2.value = o4 = o5 = ""; o1.disabled = o2.disabled = o3.disabled = false;
  76.                        $("div#mod_pushpostBOX").hide();
  77.                },
  78.                error: function(){ alert("Network error."); o1.disabled = o2.disabled = o3.disabled = false; }
  79.        });
  80. }
  81. // ]]>
  82. </script>';
  83.         }
  84.  
  85.         public function autoHookFoot(&$foot) {
  86.                 $ecnt=count($this->PUSH_EMOTIONS);
  87.                 $gcnt=count($this->GESTURES);
  88.                 for($i=0;$i<$ecnt;$i++) {
  89.                         $emot.="<option>".$this->PUSH_EMOTIONS[$i]."</option>\n";
  90.                 }
  91.                 for($i=0;$i<$gcnt;$i++) {
  92.                         $gest.="<option>".$this->GESTURES[$i]."</option>\n";
  93.                 }
  94.                 $foot .= '
  95. <div id="mod_pushpostBOX" style="display:none">
  96. <input type="hidden" id="mod_pushpostID" />'.$this->_T('pushpost').' <ul>
  97. <li>'._T('form_name').' <input type="text" id="mod_pushpostName" maxlength="20" onkeypress="mod_pushpostKeyPress(event)" /></li>
  98. <li>'._T('form_comment').
  99. '<select id="push_emotion" style="text-align:right;line-height:1.7em" class="push_area">'.$emot.'</select>'.
  100. '<select id="gesture" class="push_area" style="line-height:1.7em">'.$gest.'</select>'.
  101. '<input type="text" id="mod_pushpostComm" size="50" maxlength="50" onkeypress="mod_pushpostKeyPress(event)" /><input type="button" id="mod_pushpostSmb" value="'._T('form_submit_btn').'" onclick="mod_pushpostSend()" /></li></ul>
  102. </div>
  103. ';
  104.         }
  105.  
  106.         public function autoHookThreadPost(&$arrLabels, $post, $isReply) {
  107.                 $PIO = PMCLibrary::getPIOInstance();
  108.                 $pushcount = '';
  109.                 if ($post['status'] != '') {
  110.                         $f = $PIO->getPostStatus($post['status']);
  111.                         $pushcount = $f->value('mppCnt'); // 被推次數
  112.                 }
  113.                 $arrLabels['{$QUOTEBTN}'] .= '&nbsp;<a href="'.
  114.                         $this->getModulePageURL(array('no'=> $post['no'])).
  115.                         '" onclick="return mod_pushpostShow('.$post['no'].')">'.
  116.                         $pushcount.$this->_T('pushbutton').'</a>';
  117.                if (strpos($arrLabels['{$COM}'], $this->PUSHPOST_SEPARATOR.'<br />') !== false) {
  118.                         // 回應模式
  119.                         if ($isReply || $pushcount <= $this->PUSHPOST_DEF) {
  120.                                  $arrLabels['{$COM}'] = str_replace($this->PUSHPOST_SEPARATOR.
  121.                                  '<br />', '<div class="pushpost">', $arrLabels['{$COM}']).
  122.                                  '</div>';
  123.                         } else {
  124.                         // 頁面瀏覽
  125.                                  // 定位符號位置
  126.                                 $delimiter = strpos($arrLabels['{$COM}'], $this->PUSHPOST_SEPARATOR.'<br />');
  127.                                 if ($this->PUSHPOST_DEF > 0) {
  128.                                         $push_array = explode('<br />', substr($arrLabels['{$COM}'], $delimiter + strlen($this->PUSHPOST_SEPARATOR.'<br />')));
  129.                                         $pushs = '<div class="pushpost">……<br />'.implode('<br />', array_slice($push_array, 0 - $this->PUSHPOST_DEF)).'</div>';
  130.                                 } else {
  131.                                         $pushs = '';
  132.                                 }
  133.                                 $arrLabels['{$COM}'] = substr($arrLabels['{$COM}'], 0, $delimiter).$pushs;
  134.                                 $arrLabels['{$WARN_BEKILL}'] .= '<span class="warn_txt2">'.$this->_T('omitted').'<br /></span>'."\n";
  135.                         }
  136.                 }
  137.         }
  138.  
  139.         public function autoHookThreadReply(&$arrLabels, $post, $isReply) {
  140.                 $this->autoHookThreadPost($arrLabels, $post, $isReply);
  141.         }
  142.  
  143.         public function autoHookRegistBegin(&$name, &$email, &$sub, &$com, $upfileInfo, $accessInfo, $isReply) {
  144.                 // 登入權限允許標籤留存不轉換 (後端登入修改文章後推文仍有效)
  145.                 if (adminAuthenticate('check')) return;
  146.                
  147.                 // 防止手動插入標籤
  148.                 if (strpos($com, $this->PUSHPOST_SEPARATOR."\r\n") !== false) {
  149.                         $com = str_replace($this->PUSHPOST_SEPARATOR."\r\n", "\r\n", $com);
  150.                 }
  151.         }
  152.  
  153.         public function autoHookAdminList(&$modFunc, $post, $isres) {
  154.                 $modFunc .= '[<a href="'.$this->getModulePageURL(
  155.                                         array(
  156.                                               'action' => 'del',
  157.                                               'no' => $post[no]
  158.                                        
  159.                                         )
  160.                           ).'">刪推</a>]';           
  161.         }
  162.  
  163.         public function ModulePage() {
  164.                 $PIO = PMCLibrary::getPIOInstance();
  165.                
  166.                 if (!isset($_GET['no'])) die('[Error] not enough parameter.');
  167.                 if (isset($_GET['action'])) {
  168.                         if (adminAuthenticate('check')) {
  169.                                 $pushcount = ''; $puststart=0;
  170.                                 $post = $PIO->fetchPosts($_GET['no']);
  171.                                 if (!count($post)) die('[Error] Post does not exist.'); // 被推之文章不存在
  172.                                 extract($post[0]);
  173.  
  174.                                 if ($status != ''){
  175.                                         $f = $PIO->getPostStatus($status);
  176.                                         $pushcount = $f->value('mppCnt'); // 被推次數
  177.                                 }
  178.  
  179.                                 if (($puststart=strpos($com, $this->PUSHPOST_SEPARATOR.'<br />'))===false) die('[Error] No pushpost.');
  180.  
  181.                                 $ocom = substr($com,0,$puststart);
  182.                                 $pushpost = explode('<br />',substr($com,$puststart+strlen($this->PUSHPOST_SEPARATOR.'<br />')));
  183.                                 $com = $ocom;
  184.  
  185.                                 if ($_GET['action'] == 'del') { // list
  186.                                         $p_count = 1;
  187.                                         $com .= '<div class="pushpost">';
  188.                                         foreach($pushpost as $p) {
  189.                                                 $com .= '<input type="checkbox" name="'.($p_count++).'" value="delete" />'.$p.'<br />';
  190.                                         }      
  191.                                         $com .= '</div>';
  192.  
  193.                                         $dat = '';
  194.                                         head($dat);
  195.                                         $dat .= '<div class="bar_reply">'.$this->_T('deletepush').'</div>';
  196.                                         $dat .= '<form action="'.$this->getModulePageURL(
  197.                                                 array(
  198.                                                        'action'=>'delpush',
  199.                                                        'no' => $_GET['no']
  200.                                                       )
  201.                                                  ).'" method="post">';
  202.                                         $dat .= PMCLibrary::getPTEInstance()->ParseBlock('SEARCHRESULT',
  203.                                                 array(
  204.                                                         '{$NO}'=>$no, '{$SUB}'=>$sub, '{$NAME}'=>$name,
  205.                                                         '{$NOW}'=>$now, '{$COM}'=>$com, '{$CATEGORY}'=>$category,
  206.                                                         '{$NAME_TEXT}'=>_T('post_name'), '{$CATEGORY_TEXT}'=>_T('post_category')
  207.                                                 )
  208.                                         );                                         
  209.                                         echo $dat, '<input type="submit" value="'._T('del_btn').'" /></form></body></html>';
  210.                                         return;
  211.                                 } else if($_GET['action'] == 'delpush') { // delete
  212.                                         $delno = array();
  213.                                         reset($_POST);
  214.                                         while ($item = each($_POST)) {
  215.                                                 if ($item[1]=='delete' && $item[0] != 'func')
  216.                                                         array_push($delno, $item[0]);
  217.                                         }
  218.                                         if (count($delno)) {
  219.                                                 foreach($delno as $d) {
  220.                                                         if(isset($pushpost[$d-1])) unset($pushpost[$d-1]);
  221.                                                 }
  222.                                         }                                              
  223.                                         $pushcount = count($pushpost);
  224.                                         if ($pushcount) {
  225.                                                 $f->update('mppCnt', $pushcount); // 更新推文次數
  226.                                                 $com = $ocom.$this->PUSHPOST_SEPARATOR.'<br />'.implode('<br />', $pushpost);
  227.                                         } else {
  228.                                                 $f->remove('mppCnt'); // 刪除推文次數
  229.                                                 $com = $ocom;
  230.                                         }
  231.  
  232.                                         $PIO->updatePost($_GET['no'], array('com' => $com, 'status' => $f->toString())); // 更新推文
  233.                                         $PIO->dbCommit();
  234.  
  235.                                         header('HTTP/1.1 302 Moved Temporarily');
  236.                                         header('Location: '.fullURL().PHP_SELF.'?page_num=0');
  237.                                         return;
  238.                                 } else die('[Error] unknown action.');
  239.                         } else die('[Error] unauthenticated action.');
  240.                 }
  241.                 // 非 AJAX 推文,產出表單供填寫
  242.                 if (!isset($_POST['comm'])) {
  243.                         echo $this->printStaticForm(intval($_GET['no']));
  244.                 } else {
  245.                 // 處理推文
  246.                          // 傳送方法不正確
  247.                          if ($_SERVER['REQUEST_METHOD'] != 'POST') {
  248.                                  die(_T('regist_notpost'));
  249.                          }       
  250.  
  251.                         // 查IP
  252.                         $baninfo = '';
  253.                         $ip = getREMOTE_ADDR();
  254.                         $host = gethostbyaddr($ip);
  255.                         if (BanIPHostDNSBLCheck($ip, $host, $baninfo)) {
  256.                                 die(_T('regist_ipfiltered', $baninfo));
  257.                         }      
  258.  
  259.                         $name = CleanStr($_POST['name']);
  260.                         $comm = CleanStr($_POST['comm']);
  261.                         $push_emotion = CleanStr($_POST['push_emotion']);
  262.                         $gesture = CleanStr($_POST['gesture']);
  263.                         if (strlen($name) > 30) die($this->_T('maxlength')); // 名稱太長
  264.                         if (strlen($comm) > 160) die($this->_T('maxlength')); // 太多字
  265.                         if (strlen($comm) == 0) die($this->_T('nocomment')); // 沒打字
  266.                         $name = str_replace(
  267.                                 array(_T('trip_pre'), _T('admin'), _T('deletor')),
  268.                                 array(_T('trip_pre_fake'), '"'._T('admin').'"', '"'._T('deletor').'"'),
  269.                                 $name
  270.                         );
  271.                         // 生成ID, Trip 等識別資訊
  272.                         $pushID = $this->getID();                      
  273.                         $pushtime = gmdate('y/m/d H:i', time() + intval(TIME_ZONE) * 3600);
  274.                         if (preg_match('/(.*?)[##](.*)/u', $name, $regs)) {
  275.                                 $cap = strtr($regs[2], array('&amp;'=>'&'));
  276.                                 $salt = strtr(preg_replace('/[^\.-z]/', '.', substr($cap.'H.', 1, 2)), ':;<=>?@[\\]^_`', 'ABCDEFGabcdef');
  277.                                 $name = $regs[1]._T('trip_pre').substr(crypt($cap, $salt), -10);
  278.                         }
  279.                         if (!$name || preg_match("/^[ | |]*$/", $name)) {
  280.                                 if (ALLOW_NONAME) $name = DEFAULT_NONAME;
  281.                                 else die(_T('regist_withoutname')); // 不接受匿名
  282.                         }
  283.                         if (ALLOW_NONAME == 2) { // 強制砍名
  284.                                 $name = preg_match('/(\\'._T('trip_pre').'.{10})/', $name, $matches) ? $matches[1].':' : DEFAULT_NONAME.':';
  285.                         } else {
  286.                                 $name .= ':';
  287.                         }
  288.                         $pushpost = "{$name} {$push_emotion}{$gesture}{$comm} ({$pushID} {$pushtime})"; // 推文主體
  289.  
  290.                         $post = $PIO->fetchPosts($_GET['no']);
  291.                         if (!count($post)) die('[Error] Post does not exist.'); // 被推之文章不存在
  292.  
  293.                         $parentNo = $post[0]['resto'] ? $post[0]['resto'] : $post[0]['no'];
  294.                         $threads = array_flip($PIO->fetchThreadList());
  295.                         $threadPage = floor($threads[$parentNo] / PAGE_DEF);
  296.  
  297.                         $p = ($parentNo==$post[0]['no']) ? $post : $PIO->fetchPosts($parentNo); // 取出首篇
  298.                         $flgh = $PIO->getPostStatus($p[0]['status']);
  299.                         if ($flgh->exists('TS')) die('[Error] '._T('regist_threadlocked')); // 首篇禁止回應/同時表示禁止推文
  300.  
  301.                         $post[0]['com'] .= ((strpos($post[0]['com'], $this->PUSHPOST_SEPARATOR.'<br />')===false) ? '<br />'.$this->PUSHPOST_SEPARATOR : '').'<br /> '.$pushpost;
  302.                         $flgh2 = $PIO->getPostStatus($post[0]['status']);
  303.                         $flgh2->plus('mppCnt'); // 推文次數+1
  304.                         $PIO->updatePost($_GET['no'], array('com'=>$post[0]['com'], 'status'=>$flgh2->toString())); // 更新推文
  305.                         $PIO->dbCommit();
  306.                        
  307.                        // mod_audit logcat
  308.                        $this->callCHP('mod_audit_logcat',
  309.                                 array(sprintf('[%s] No.%d %s (%s)',
  310.                                         __CLASS__,
  311.                                         $_GET['no'],
  312.                                         $comm,
  313.                                         $pushID)
  314.                                 )
  315.                         );
  316.                        
  317.                         if (STATIC_HTML_UNTIL == -1 || $threadPage <= STATIC_HTML_UNTIL) {
  318.                                 // 僅更新討論串出現那頁
  319.                                 updatelog(0, $threadPage, true);
  320.                         }      
  321.                         deleteCache(array($parentNo)); // 刪除討論串舊快取
  322.  
  323.                         if (isset($_POST['ajaxmode'])) {
  324.                                 echo '+OK ', $pushpost;
  325.                         } else {
  326.                                 header('HTTP/1.1 302 Moved Temporarily');
  327.                                 header('Location: '.fullURL().PHP_SELF2.'?'.time());
  328.                         }
  329.                 }
  330.         }
  331.  
  332.         /**
  333.          * 產出靜態推文表單
  334.          *
  335.          * @param  int $targetPost 推文對象文章編號
  336.          * @return string             表單頁面 HTML
  337.          */
  338.         private function printStaticForm($targetPost) {
  339.                 $PIO = PMCLibrary::getPIOInstance();
  340.                 $PTE = PMCLibrary::getPTEInstance();
  341.                
  342.                 $post = $PIO->fetchPosts($targetPost);
  343.                 if (!count($post)) die('[Error] Post does not exist.');
  344.  
  345.                 $dat = $PTE->ParseBlock('HEADER', array('{$TITLE}'=>TITLE, '{$RESTO}'=>''));
  346.                 $dat .= '</head><body id="main">';
  347.                 $dat .= '<form action="'.$this->getModulePageURL(array('no' => $targetPost)).'" method="post">
  348. '.$this->_T('pushpost').' <ul><li>'._T('form_name').' <input type="text" name="name" maxlength="20" /></li><li>'._T('form_comment').' <input type="text" name="comm"
  349. size="50" maxlength="50" /><input type="submit" value="'._T('form_submit_btn').'" /></li></ul>             
  350. </form>';
  351.                 $dat .= '</body></html>';
  352.                 return $dat;
  353.         }      
  354.         /**
  355.          * 動態加入語言資源
  356.          */
  357.         private function loadLanguage() {
  358.                 $lang = array(
  359.                         'zh_TW' => array(
  360.                                 'nocomment' => '請輸入內文',
  361.                                 'pushpost' => '[推文]',
  362.                                 'pushbutton' => '推',
  363.                                 'maxlength' => '你話太多了',
  364.                                 'omitted' => '有部分推文被省略。要閱讀全部推文請按下回應連結。',
  365.                                 'deletepush' => '刪除推文模式'
  366.                         ),
  367.                         'ja_JP' => array(
  368.                                 'nocomment' => '何か書いて下さい',
  369.                                 'pushpost' => '[推文]',
  370.                                 'pushbutton' => '推',
  371.                                 'maxlength' => 'コメントが長すぎます',
  372.                                 'omitted' => '推文省略。全て読むには返信ボタンを押してください。',
  373.                                 'deletepush' => '削除推文モード'
  374.                         ),
  375.                         'en_US' => array(
  376.                                 'nocomment' => 'Please type your comment.',
  377.                                 'pushpost' => '[Push this post]',
  378.                                 'pushbutton' => 'PUSH',
  379.                                 'maxlength' => 'You typed too many words',
  380.                                 'omitted' => 'Some pushs omitted. Click Reply to view.',
  381.                                 'deletepush' => 'Delete Push Post Mode'
  382.                             )  
  383.                 );
  384.                 $this->attachLanguage($lang, 'en_US');     
  385.         }      
  386. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement