protected function actionProxy($params) { $feed = $params['feed']; if ($feed != '' && strpos($feed, 'http') === 0) { header('Content-Type: text/xml'); if (function_exists('curl_init')) { $httpclient = new \GO\Base\Util\HttpClient(); $xml = $httpclient->request($feed); } else { if (!\GO\Base\Fs\File::checkPathInput($feed)) { throw new \Exception("Invalid request"); } $xml = @file_get_contents($feed); } if ($xml) { //fix relative images preg_match('/(.*:\\/\\/[^\\/]+)\\//', $feed, $matches); $baseUrl = $matches[1]; $xml = str_replace('src="/', 'src="' . $baseUrl . '/', $xml); $xml = str_replace('src="/', 'src="' . $baseUrl . '/', $xml); $xml = str_replace('href="/', 'href="' . $baseUrl . '/', $xml); $xml = str_replace('href="/', 'href="' . $baseUrl . '/', $xml); $xml = str_replace('<content:encoded>', '<content>', $xml); $xml = str_replace('</content:encoded>', '</content>', $xml); $xml = str_replace('</dc:creator>', '</author>', $xml); echo str_replace('<dc:creator', '<author', $xml); } } }
protected function actionDescription($params) { $response = array(); $response['title'] = ''; $response['description'] = ''; if (function_exists('curl_init')) { try { $c = new \GO\Base\Util\HttpClient(); $c->setCurlOption(CURLOPT_CONNECTTIMEOUT, 2); $c->setCurlOption(CURLOPT_TIMEOUT, 5); $c->setCurlOption(CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); $html = $c->request($params['url']); //go_debug($html); $html = str_replace("\r", '', $html); $html = str_replace("\n", ' ', $html); $html = preg_replace("'</[\\s]*([\\w]*)[\\s]*>'", "</\$1>", $html); preg_match('/<head>(.*)<\\/head>/i', $html, $match); if (isset($match[1])) { $html = $match[1]; //go_debug($html); preg_match('/charset=([^"\'>]*)/i', $c->getContentType(), $match); if (isset($match[1])) { $charset = strtolower(trim($match[1])); if ($charset != 'utf-8') { $html = \GO\Base\Util\String::to_utf8($html, $charset); } } preg_match_all('/<meta[^>]*>/i', $html, $matches); $description = ''; foreach ($matches[0] as $match) { if (stripos($match, 'description')) { $name_pos = stripos($match, 'content'); if ($name_pos) { $description = substr($match, $name_pos + 7, -1); $description = trim($description, '="\'/ '); break; } } } //replace double spaces $response['description'] = preg_replace('/\\s+/', ' ', $description); preg_match('/<title>(.*)<\\/title>/i', $html, $match); $response['title'] = $match ? preg_replace('/\\s+/', ' ', trim($match[1])) : ''; } } catch (\Exception $e) { } try { $contents = $c->request($params['url'] . '/favicon.ico'); if (!empty($contents) && $c->getHttpCode() != 404) { $relpath = 'public/bookmarks/'; $path = \GO::config()->file_storage_path . $relpath; if (!is_dir($path)) { mkdir($path, 0755, true); } $filename = str_replace('.', '_', preg_replace('/^https?:\\/\\//', '', $_POST['url'])) . '.ico'; $filename = rtrim(str_replace('/', '_', $filename), '_ '); //var_dump($filename); file_put_contents($path . $filename, $contents); $response['logo'] = $relpath . $filename; } } catch (\Exception $e) { $response['logo'] = ''; } } $response['title'] = \GO\Base\Util\String::cut_string($response['title'], 64, true, ""); $response['description'] = \GO\Base\Util\String::cut_string($response['description'], 255, true, ""); return $response; }