public static function get_treasures($alias = null) { if ($alias !== null) { $site = \Model_Site::find_by_alias($alias); if (!$site instanceof \Model_Site) { die('abon'); } $sites[] = $site; } else { $sites = \Model_Site::find('all'); } $treasures = array(); foreach ($sites as $site) { $captures = array(array('url' => $site->url)); $patterns = explode('@@@@', $site->pattern); foreach ($patterns as $pattern) { $_captures = array(); foreach ($captures as $capture) { $url = $capture['url']; $html = @file_get_contents($url); if (preg_match_all('@' . $pattern . '@', $html, $matches)) { foreach ($matches[1] as $match) { if (strpos($match, 'http') !== 0) { $info = parse_url($url); $info['scheme'] .= ':/'; if (!isset($info['path'])) { $info['path'] = '/'; } if ($info['path'] === '/') { $match = preg_replace('@../@', '', $match); $info['path'] = $match; } if (isset($info['port'])) { $info['host'] .= ':'; } $match = join('/', $info); } // Url is starting 'http' if (!empty($site->account)) { // Put account information in url $account = $site->account . ':' . $site->password . '@'; $match = preg_replace('@^(https?://)(.*)$@', '$1' . $account . '$2', $match); } $_capture = array('url' => $match); if ($site->is_camouflage_referer) { $_capture['referer'] = $url; } $_captures[] = $_capture; } } else { // Match error } } $captures = $_captures; } $treasures[$site->alias] = $captures; } return $treasures; }
public function action_delete($id = null) { if ($site = Model_Site::find($id)) { $site->delete(); Session::set_flash('success', e('Deleted site #' . $id)); } else { Session::set_flash('error', e('Could not delete site #' . $id)); } Response::redirect('admin/site'); }