示例#1
0
文件: Room.php 项目: xety/marsbot
 /**
  * Get the ID by the room name or the name by the ID.
  *
  * @param string|int $name The name/id of the room.
  *
  * @return false|bool
  */
 public static function getRoomInfo($name)
 {
     if (is_numeric($name)) {
         $url = 'http://xat.com/xat' . $name;
     } else {
         $url = 'http://xat.com/' . $name;
     }
     $http = new Http();
     $response = $http->get($url);
     $roomId = Text::getBetween($response->getBody(), '<a href="http://xat.com/web_gear/chat/embed.php?id=', '&GroupName=');
     $roomName = Text::getBetween($response->getBody(), '&GroupName=', '"');
     $title = Text::getBetween($response->getBody(), '<title>', '</title>');
     $title = explode(' ', $title);
     if (!is_numeric($roomId) || $title[0] === 'xat') {
         return false;
     } else {
         Configure::write('Room.id', $roomId);
         Configure::write('Room.name', $roomName);
         $config = ['id' => $roomId, 'name' => $roomName];
         return $config;
     }
 }
示例#2
0
文件: Hash.php 项目: xety/marsbot
 /**
  * Remove data matching $path from the $data array.
  * You can use `{n}` and `{s}` to remove multiple elements
  * from $data.
  *
  * @param array $data The data to operate on.
  * @param string $path A path expression to use to remove.
  * @return array The modified array.
  */
 public static function remove(array $data, $path)
 {
     $noTokens = strpos($path, '[') === false;
     $noExpansion = strpos($path, '{') === false;
     if ($noExpansion && $noTokens && strpos($path, '.') === false) {
         unset($data[$path]);
         return $data;
     }
     $tokens = $noTokens ? explode('.', $path) : Text::tokenize($path, '.', '[', ']');
     if ($noExpansion && $noTokens) {
         return static::_simpleOp('remove', $data, $tokens);
     }
     $token = array_shift($tokens);
     $nextPath = implode('.', $tokens);
     list($token, $conditions) = self::_splitConditions($token);
     foreach ($data as $k => $v) {
         $match = static::_matchToken($k, $token);
         if ($match && is_array($v)) {
             if ($conditions && static::_matches($v, $conditions)) {
                 unset($data[$k]);
                 continue;
             }
             $data[$k] = static::remove($v, $nextPath);
             if (empty($data[$k])) {
                 unset($data[$k]);
             }
         } elseif ($match && empty($nextPath)) {
             unset($data[$k]);
         }
     }
     return $data;
 }