示例#1
0
 /**
  * Post a thread.
  *
  * @param  int      $boardID
  * @access public
  * @return void
  */
 public function post($boardID = 0)
 {
     $this->loadModel('forum');
     if ($this->app->user->account == 'guest') {
         die(js::locate($this->createLink('user', 'login', "referer=" . helper::safe64Encode($this->app->getURI()))));
     }
     /* Get the board. */
     $board = $this->loadModel('tree')->getById($boardID);
     /* Checking the board exist or not. */
     if (!$board) {
         die(js::error($this->lang->forum->notExist) . js::locate('back'));
     }
     /* Checking current user can post to the board or not. */
     if (!$this->forum->canPost($board)) {
         die(js::error($this->lang->forum->readonly) . js::locate('back'));
     }
     /* Set editor for current user. */
     $this->thread->setEditor($board->id, 'post');
     /* User posted a thread, try to save it to database. */
     if ($_POST) {
         $captchaConfig = isset($this->config->site->captcha) ? $this->config->site->captcha : 'auto';
         $needCaptcha = false;
         if ($captchaConfig == 'auto' and $this->loadModel('guarder')->isEvil($this->post->{$this->session->contentInput})) {
             $needCaptcha = true;
         }
         if ($captchaConfig == 'open') {
             $needCaptcha = true;
         }
         if ($captchaConfig == 'close') {
             $needCaptcha = false;
         }
         /* If no captcha but is garbage, return the error info. */
         $captchaInput = $this->session->captchaInput;
         if ($this->post->{$captchaInput} === false and $needCaptcha) {
             $this->send(array('result' => 'fail', 'reason' => 'needChecking', 'captcha' => $this->loadModel('guarder')->create4Thread()));
         }
         $result = $this->thread->post($boardID);
         $this->send($result);
     }
     $titleInput = helper::createRandomStr(6, $skip = 'A-Z');
     $contentInput = helper::createRandomStr(7, $skip = 'A-Z');
     $this->session->set('titleInput', $titleInput);
     $this->session->set('contentInput', $contentInput);
     $this->config->thread->require->post = "{$this->session->titleInput}, {$this->session->contentInput}";
     $this->config->thread->editor->post = array('id' => $this->session->contentInput, 'tools' => 'simple');
     $this->view->title = $board->name . $this->lang->minus . $this->lang->thread->post;
     $this->view->board = $board;
     $this->view->canManage = $this->thread->canManage($boardID);
     $this->view->titleInput = $titleInput;
     $this->view->contentInput = $contentInput;
     $this->view->board = $board;
     $this->view->mobileURL = helper::createLink('thread', 'post', "boardID={$boardID}", '', 'mhtml');
     $this->view->desktopURL = helper::createLink('thread', 'post', "boardID={$boardID}", '', 'html');
     $this->display();
 }
示例#2
0
    /**
     * Create guarder for message reply.
     * 
     * @access public
     * @return string
     */
    public function create4MessageReply()
    {
        $guarder = $this->createCaptcha();
        $input = helper::createRandomStr(8, $skip = 'A-Z');
        $this->session->set('captchaInput', $input);
        shuffle($this->config->guarder->captchaTags);
        $htmlTag = current($this->config->guarder->captchaTags);
        list($leftTag, $rightTag) = explode('|', $htmlTag);
        $equal = empty($this->config->guarder->captchas) ? "</td><td class='text-lg text-center w-40px'> {$this->lang->guarder->equal} </td><td>" : '';
        return <<<EOT
<th>{$this->lang->guarder->captcha}</th>
<td>
  <table class='captcha'>
    <tr class='text-middle'>
      <td class='text-lg w-110px'>{$leftTag}{$guarder}{$rightTag}
      {$equal}
      <input type='text'  name='{$input}' id='{$input}' class='w-100px inline-block form-control text-center' placeholder='{$this->lang->guarder->placeholder}'/> &nbsp;</td>
    </tr>
  </table>
</td>
EOT;
    }
示例#3
0
 /**
  * Verify administrator through ok file.
  *
  * @access public
  * @return array
  */
 public function verifyAdmin()
 {
     if ($this->session->okFileName == false or $this->session->okFileName == '') {
         $this->session->set('okFileName', helper::createRandomStr(4, $skip = '0-9A-Z') . '.txt');
         $this->session->set('okFileContent', helper::createRandomStr(4, $skip = '0-9A-Z'));
     }
     $okFile = $this->app->getTmpRoot() . $this->session->okFileName;
     if (file_exists($okFile) and trim(file_get_contents($okFile)) != $this->session->okFileContent or !$this->session->okFileContent) {
         @unlink($okFile);
         $this->session->set('okFileName', helper::createRandomStr(4, $skip = '0-9A-Z') . '.txt');
         $this->session->set('okFileContent', helper::createRandomStr(4, $skip = '0-9A-Z'));
         $okFile = $this->app->getTmpRoot() . $this->session->okFileName;
     }
     if (!file_exists($okFile) or trim(file_get_contents($okFile)) != $this->session->okFileContent) {
         return array('result' => 'fail', 'name' => $okFile, 'content' => $this->session->okFileContent);
     }
     $this->session->set('verify', 'pass');
     $this->session->set('okFileName', '');
     return array('result' => 'success');
 }
示例#4
0
 /**
  * Create hook file.
  * 
  * @param  string    $template 
  * @param  string    $theme 
  * @param  string    $code 
  * @access public
  * @return bool
  */
 public function createHookFile($template, $theme, $code)
 {
     $hookFile = $this->directories->encryptLessPath . helper::createRandomStr(6, $skip = '0-9A-Z') . ".php";
     $params = $this->getCustomParams($template, $theme);
     $params = var_export($params, true);
     $params = str_replace("{$template}/{$theme}/", "{$template}/_THEME_CODEFIX_/", $params);
     foreach ($this->config->css as $item => $value) {
         $value = str_replace("{$template}/{$theme}/", "{$template}/_THEME_CODEFIX_/", $value);
     }
     foreach ($this->config->js as $item => $value) {
         $value = str_replace("{$template}/{$theme}/", "{$template}/_THEME_CODEFIX_/", $value);
     }
     $cssCodes = serialize($this->config->css);
     $jsCodes = serialize($this->config->js);
     $cssCode = var_export($cssCodes, true);
     $jsCodes = var_export($jsCodes, true);
     $code = "<?php\nif(!function_exists('get_THEME_CODEFIX_CSS'))\n{\n    function get_THEME_CODEFIX_CSS()\n    {\n        \$css = unserialize({$cssCode});\n        return \$css;\n    }\n}\nif(!function_exists('get_THEME_CODEFIX_JS'))\n{\n    function get_THEME_CODEFIX_JS()\n    {\n        \$js = unserialize({$jsCodes});\n        return \$js;\n    }\n}\nif(!function_exists('get_THEME_CODEFIX_params'))\n{\n    function get_THEME_CODEFIX_params()\n    {\n        return {$params};\n    }\n}\n";
     return file_put_contents($hookFile, $code);
 }
示例#5
0
 /**
  * Create hook file.
  * 
  * @param  string    $template 
  * @param  string    $theme 
  * @param  string    $code 
  * @access public
  * @return bool
  */
 public function createHookFile($template, $theme, $code)
 {
     if (!is_dir($hookPath)) {
         mkdir($hookPath, 0777, true);
     }
     $hookFile = $this->directories->encryptLessPath . helper::createRandomStr(6, $skip = '0-9A-Z') . ".php";
     $params = $this->getCustomParams($template, $theme);
     $css = var_export($params['css'], true);
     $js = var_export($params['js'], true);
     unset($params['css']);
     unset($params['js']);
     $params = var_export($params, true);
     $css = str_replace("{$template}/{$theme}/", "{$template}/_THEME_CODEFIX_/", $css);
     $js = str_replace("{$template}/{$theme}/", "{$template}/_THEME_CODEFIX_/", $js);
     $params = str_replace("{$template}/{$theme}/", "{$template}/_THEME_CODEFIX_/", $params);
     $code = "<?php\nif(!function_exists('get_THEME_CODEFIX_CSS'))\n{\n    function get_THEME_CODEFIX_CSS()\n    {\n        return {$css};\n    }\n}\nif(!function_exists('get_THEME_CODEFIX_JS'))\n{\n    function get_THEME_CODEFIX_JS()\n    {\n        return {$js};\n    }\n}\nif(!function_exists('get_THEME_CODEFIX_params'))\n{\n    function get_THEME_CODEFIX_params()\n    {\n        return {$params};\n    }\n}\n";
     return file_put_contents($hookFile, $code);
 }
示例#6
0
 /**
  * Verfy administrator through ok file.
  * 
  * @access public
  * @return array
  */
 public function verfyAdmin()
 {
     if ($this->session->okFileName == false or $this->session->okFileName == '') {
         $this->session->set('okFileName', helper::createRandomStr(4, $skip = '0-9A-Z') . '.txt');
     }
     $okFile = $this->app->getTmpRoot() . $this->session->okFileName;
     if (file_exists($okFile) and time() - filemtime($okFile) > 3600) {
         @unlink($okFile);
         $this->session->set('okFileName', helper::createRandomStr(4, $skip = '0-9A-Z') . '.txt');
         $okFile = $this->app->getTmpRoot() . $this->session->okFileName;
     }
     if (!file_exists($okFile) or time() - filemtime($okFile) > 3600) {
         return array('result' => 'fail', 'okFile' => $okFile);
     }
     return array('result' => 'success');
 }