コード例 #1
0
ファイル: article.co.php プロジェクト: noikiy/dophin
 /**
  * 显示文章信息
  */
 public function detail()
 {
     if (!empty($_GET['url'])) {
         $start = strrpos($_GET['url'], '/');
         if (false === $start) {
             $start = -1;
         }
         if (false === strpos($_GET['url'], '.html')) {
             $str = substr($_GET['url'], $start + 1);
         } else {
             $str = substr($_GET['url'], $start + 1, -5);
         }
         $_GET['id'] = $id = UMath::idDecrypt($str);
     }
     if (empty($_GET['id']) || !ctype_digit($_GET['id'])) {
         $this->header404();
         exit;
     } else {
         $id = $_GET['id'];
     }
     $mo = new Model_Article();
     if (!$detail) {
         $this->header404();
         exit;
     }
     // 有跳转链接,直接跳转到目标网址
     if ($detail['redirect']) {
         header('Location:' . $detail['redirect']);
         exit;
     }
     if ($detail['html_file']) {
         if (!empty($_GET['make_html']) && is_file($htmlFile = $mo->getHtmlFile($id, $detail['html_file']))) {
             $htmlUrl = str_replace(WEB_PATH, '/', $htmlFile);
             header('Location:' . $htmlUrl);
             exit;
         } else {
             $_GET['make_html'] = true;
         }
     } else {
         $_GET['make_html'] = true;
         $detail['html_file'] = UMath::idCrypt($id);
         $data = array('id' => $id, 'html_file' => $detail['html_file']);
         $mo->save($data);
     }
     $this->detail = $detail;
     $_GET['make_html'] = true;
     $_GET['html_display'] = false;
     $_GET['html_file'] = $mo->getHtmlFile($id, $detail['html_file']);
     $htmlUrl = str_replace(WEB_PATH, '/', $_GET['html_file']);
     $this->display();
     header('Location:' . $htmlUrl);
     return false;
 }
コード例 #2
0
ファイル: String.class.php プロジェクト: noikiy/dophin
 /**
  * 解密一个字符串为ID数字
  * @param string $str
  * @return string
  */
 public static function idDeCrypt($str)
 {
     $key = self::idCryptKey();
     $keyLen = strlen($key);
     $id = '';
     $strLen = strlen($str);
     if ($keyLen < $strLen) {
         $key .= substr($key, 0, $strLen - $keyLen + 1);
     }
     $ki = 0;
     if ($GLOBALS['_id_crypt_slice_pos']) {
         $pos = $GLOBALS['_id_crypt_slice_pos'];
         $idLen = UMath::any2dec(substr($str, $pos, 1));
         $str = substr($str, $pos + 1) . substr($str, 0, $pos);
     } else {
         $pos = floor((strlen($str) - 1) / 2);
         $idLen = UMath::any2dec(substr($str, $pos, 1));
         $str = substr($str, 0, $pos) . substr($str, $pos + 1);
     }
     for ($i = 0; $i < $strLen; $i++, $ki++) {
         $val = UMath::any2dec($str[$i]);
         $kVal = UMath::any2dec($key[$ki]);
         if ($val < $kVal) {
             if (isset($str[$i + 1])) {
                 $val = UMath::any2dec($str[$i] . $str[$i + 1]);
             } else {
                 $val = UMath::any2dec($str[$i]);
             }
             $i++;
         }
         $tmp = $val - $kVal;
         if (strlen($id) == $idLen) {
             break;
         }
         $id .= $tmp;
     }
     return $id;
 }