コード例 #1
0
ファイル: id.php プロジェクト: Bren2010/BlueElephant
 /**
  * Dissect information from an id.
  * 
  * Used to dissect keys from an id that can be used to find it in a 
  * database.
  * 
  * @param string $hash The id being used.
  * @param string $type The type of id being used.
  * 
  * @return array Array of data that can be used in a query for the 
  * original content.
  */
 protected static function dissectKeys($hash, $type)
 {
     switch ($type) {
         case 'news':
             $sections = explode('/', $hash);
             $toReturn = array();
             $ambiguity = 60;
             // Minimum of 60 seconds.
             $toReturn['year'] = $sections[0];
             if (empty($sections[2])) {
                 // No unique address
                 $ambiguity = 2678400;
                 // A month in seconds.
                 $toReturn['day'] = 1;
                 $toReturn['hour'] = 0;
                 $toReturn['minute'] = 0;
             } else {
                 $toReturn['day'] = substr($sections[2], 0, 2);
                 $toReturn['hour'] = substr($sections[2], 2, 2);
                 $toReturn['minute'] = substr($sections[2], 4, 2);
             }
             if (empty($sections[1])) {
                 // Months
                 $ambiguity = 31556926;
                 // A year in seconds.
                 $toReturn['month'] = 1;
             } else {
                 $toReturn['month'] = $sections[1];
             }
             $toReturn['ambiguity'] = $ambiguity;
             $toReturn['date'] = mktime((int) $toReturn['hour'], (int) $toReturn['minute'], 0, (int) $toReturn['month'], (int) $toReturn['day'], (int) $toReturn['year']);
             //echo $toReturn['date'];
             //die;
             return $toReturn;
             break;
         case 'bug':
             $toReturn = array();
             $data = explode('-', $hash);
             $toReturn['time'] = base_convert($data[0], 36, 10);
             return $toReturn;
             break;
         case 'user':
             return array('username' => $hash);
             break;
         case 'article':
             return Id::dissetKeys($hash, 'news');
             break;
     }
     return false;
 }