添加了按标签浏览页面

This commit is contained in:
Li Jianxuan 2014-03-13 09:11:52 +00:00
parent df96f114f6
commit e87c60c651
3 changed files with 63 additions and 48 deletions

View File

@ -65,9 +65,10 @@ return array(
'tag' => array( 'tag' => array(
'type' => 'Segment', 'type' => 'Segment',
'options' => array( 'options' => array(
'route' => '/tag[/:tag]', 'route' => '/tag[/keytype/[:keytype]][/:tag]',
'constraints' => array( 'constraints' => array(
'tag' => ".*", 'tag' => ".*",
'keytype' => '.*'
), ),
'defaults' => array( 'defaults' => array(
'module' => 'Metadata', 'module' => 'Metadata',

View File

@ -68,10 +68,18 @@ class IndexController extends AbstractActionController
public function tagAction() public function tagAction()
{ {
$tag = $this->params()->fromRoute('tag'); $tag = $this->params()->fromRoute('tag');
$keytype = $this->params()->fromRoute('keytype');
if(preg_match("/\'/",$tag)) if(preg_match("/\'/",$tag))
view::Post($this,"参数错误",-1); view::Post($this,"参数错误",-1);
if(!empty($keytype))
{
$tags = new \Westdc\Metadata\Tags;
$this->ViewModel->setVariable('keywords',$tags->getAllTagsAndCount($keytype));
return $this->ViewModel;
}
if(empty($tag)) if(empty($tag))
{ {
$tags = new \Westdc\Metadata\Tags; $tags = new \Westdc\Metadata\Tags;

View File

@ -1,48 +1,54 @@
<?php <?php
namespace Sookon\Helpers; namespace Sookon\Helpers;
// 三段 // 三段
// 一段是微秒 一段是地址 一段是随机数 // 一段是微秒 一段是地址 一段是随机数
class Uuid class Uuid
{ {
private $valueBeforeMD5; private $valueBeforeMD5;
private $valueAfterMD5; private $valueAfterMD5;
function __construct() function __construct()
{ {
$address = $this->getLocalHost(); $this->update();
$this->valueBeforeMD5 = $address.':'.$this->currentTimeMillis().':'.$this->nextLong(); }
$this->valueAfterMD5 = md5($this->valueBeforeMD5);
} public function update()
function toString() {
{ $address = $this->getLocalHost();
$raw = strtoupper($this->valueAfterMD5); $this->valueBeforeMD5 = $address.':'.$this->currentTimeMillis().':'.$this->nextLong();
return substr($raw,0,8).'-'.substr($raw,8,4).'-'.substr($raw,12,4).'-'.substr($raw,16,4).'-'.substr($raw,20); $this->valueAfterMD5 = md5($this->valueBeforeMD5);
} }
private function nextLong() public function toString()
{ {
$tmp = rand(0,1)?'-':''; $raw = strtoupper($this->valueAfterMD5);
return $tmp.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(100, 999).rand(100, 999); return substr($raw,0,8).'-'.substr($raw,8,4).'-'.substr($raw,12,4).'-'.substr($raw,16,4).'-'.substr($raw,20);
} }
private function currentTimeMillis()
{ private function nextLong()
list($usec, $sec) = explode(" ",microtime()); {
return $sec.substr($usec, 2, 3); $tmp = rand(0,1)?'-':'';
} return $tmp.rand(1000, 9999).rand(1000, 9999).rand(1000, 9999).rand(100, 999).rand(100, 999);
private function getLocalHost() }
{ private function currentTimeMillis()
$address = isset($_ENV["COMPUTERNAME"]) ? $_ENV["COMPUTERNAME"]."/":"".'/'; {
$address.= $_SERVER["SERVER_ADDR"]; list($usec, $sec) = explode(" ",microtime());
return strtolower($address); return $sec.substr($usec, 2, 3);
} }
private function getLocalHost()
static function test($uuid) {
{ $address = isset($_ENV["COMPUTERNAME"]) ? $_ENV["COMPUTERNAME"]."/":"".'/';
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid)) $address.= $_SERVER["SERVER_ADDR"];
{ return strtolower($address);
return false; }
}else{
return true; static function test($uuid)
} {
} if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
return false;
}else{
return true;
}
}
} }