Full-Text RSS 2.9.5
17
UPDATING.txt
@ -13,10 +13,19 @@ To update your copy of Full-Text RSS to ensure feeds continue to be processed as
|
||||
|
||||
5. Enter a URL in the form field to test the updated code
|
||||
|
||||
6. If you'd configured the last version, copy custom_config.php from your old version to the new folder.
|
||||
6. If you'd configured the last version, copy custom_config.php from your old version to the new installation.
|
||||
|
||||
7. Test the new copy again to make sure the config values are now applied to the new version.
|
||||
7. If you'd added custom site config files (in site_config/custom/), copy those over to the new installation.
|
||||
|
||||
8. Now simply rename the folder with your old copy to 'full-text-rss-old' and then rename the folder with the new copy to 'full-text-rss' (or whatever name you'd given the original folder).
|
||||
8. Test the new copy again to make sure the config values are now applied to the new version.
|
||||
|
||||
That's all that's needed. Your feeds should continue to work as they did before. Let us know if you have any trouble: fivefilters@fivefilters.org.
|
||||
9. Now simply rename the folder with your old copy to 'full-text-rss-old' and then rename the folder with the new copy to 'full-text-rss' (or whatever name you'd given the original folder).
|
||||
|
||||
That's all that's needed. Your feeds should continue to work as they did before. Let us know if you have any trouble: help@fivefilters.org.
|
||||
|
||||
Updating Site Patterns
|
||||
======================
|
||||
|
||||
Site patterns are used by Full-Text RSS to improve extraction for certain sites. These are simple text files which are updated more frequently than the Full-Text RSS software itself.
|
||||
|
||||
To make sure your copy of Full-Text RSS is using the latest site patterns, We've created a simple tool to help you get the latest copy of these site patterns from FiveFilters.org. To use it, access the admin/ folder in your browser and follow the instructions.
|
43
admin/index.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// Admin page for Full-Text RSS
|
||||
// Author: Keyvan Minoukadeh
|
||||
// Copyright (c) 2012 Keyvan Minoukadeh
|
||||
// License: AGPLv3
|
||||
// Date: 2012-04-29
|
||||
// More info: http://fivefilters.org/content-only/
|
||||
// Help: http://help.fivefilters.org
|
||||
|
||||
/*
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Usage
|
||||
// -----
|
||||
// Access this file in your browser
|
||||
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
ini_set("display_errors", 1);
|
||||
@set_time_limit(120);
|
||||
|
||||
////////////////////////////////
|
||||
// Load config file
|
||||
////////////////////////////////
|
||||
require_once('../config.php');
|
||||
require_once('require_login.php');
|
||||
require_once('template.php');
|
||||
tpl_header('Admin');
|
||||
|
||||
?>
|
||||
<p>The admin pages are intended to help you manage your copy of Full-Text RSS more easily.</p>
|
||||
<p>We currently offer an experimental <a href="update.php">update tool</a> which you can use to update your site patterns.</p>
|
38
admin/login.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once(dirname(dirname(__FILE__)).'/config.php');
|
||||
if (!isset($options->admin_credentials) || $options->admin_credentials['username'] == '' || $options->admin_credentials['password'] == '') {
|
||||
die('<h2>Admin privileges required</h2><p>This page requires admin privileges but Full-Text RSS has not been configured with admin credentials.</p><p>If you are the administrator, please edit your <tt>custom_config.php</tt> file and enter the credentials in the appropriate section. When you\'ve done that, this page will prompt you for your admin credentials.</p>');
|
||||
}
|
||||
|
||||
$name = @$_POST['username'];
|
||||
$pass = @$_POST['pass'];
|
||||
$invalid_login = false;
|
||||
|
||||
if ($name || $pass) {
|
||||
if ($name == $options->admin_credentials['username'] && $pass == $options->admin_credentials['password']) {
|
||||
// Authentication successful - set session
|
||||
$_SESSION['auth'] = 1;
|
||||
if (isset($_POST['redirect']) && preg_match('/^[0-9a-z]+$/', $_POST['redirect'])) {
|
||||
header('Location: '.$_POST['redirect'].'.php');
|
||||
} else {
|
||||
header('Location: index.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
$invalid_login = true;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>Login</title></head>
|
||||
<body>
|
||||
<?php if ($invalid_login) echo '<p><strong>Invalid login, please try again.</strong> If you can\'t remember your admin credentials, open your <tt>custom_config.php</tt> and you\'ll find them in there.</p>'; ?>
|
||||
<form method="post" action="login.php">
|
||||
<?php if (isset($_GET['redirect'])) echo '<input type="hidden" name="redirect" value="'.htmlspecialchars($_GET['redirect']).'" />'; ?>
|
||||
<label>Username: <input type="text" name="username" value="<?php echo @$_POST['username']; ?>" /></label>
|
||||
<label>Password: <input type="password" name="pass" /></label>
|
||||
<input type="submit" name="submit" value="Log In" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
95
admin/require_login.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// Require login for admin access
|
||||
// Author: Keyvan Minoukadeh
|
||||
// Copyright (c) 2012 Keyvan Minoukadeh
|
||||
// License: AGPLv3
|
||||
// Date: 2012-04-16
|
||||
// More info: http://fivefilters.org/content-only/
|
||||
// Help: http://help.fivefilters.org
|
||||
|
||||
/*
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Usage
|
||||
// -----
|
||||
// This file is included on pages which require admin privileges - e.g. updating the software.
|
||||
// The username is 'admin' by default and the password should be set in the custom_config.php file.
|
||||
session_start();
|
||||
require_once(dirname(dirname(__FILE__)).'/config.php');
|
||||
|
||||
$realm = 'Restricted area';
|
||||
|
||||
if (isset($_GET['logout'])) $_SESSION['auth'] = 0;
|
||||
|
||||
if (!isset($_SESSION['auth']) || $_SESSION['auth'] != 1) {
|
||||
if (isset($admin_page)) {
|
||||
header('Location: login.php?redirect='.$admin_page);
|
||||
} else {
|
||||
header('Location: login.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/* HTTP DIGEST authentication - doesn't work without server tweaks in FastCGI environments
|
||||
|
||||
//user => password
|
||||
$users = array($options->admin_credentials['username'] => $options->admin_credentials['password']);
|
||||
|
||||
if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
|
||||
header('HTTP/1.1 401 Unauthorized');
|
||||
header('WWW-Authenticate: Digest realm="'.$realm.
|
||||
'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');
|
||||
|
||||
die('If you can\'t remember your admin credentials, open your custom_config.php and you\'ll find them in there.');
|
||||
}
|
||||
|
||||
|
||||
// analyze the PHP_AUTH_DIGEST variable
|
||||
if (!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) ||
|
||||
!isset($users[$data['username']]))
|
||||
die('Wrong credentials!');
|
||||
|
||||
|
||||
// generate the valid response
|
||||
$A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
|
||||
$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
|
||||
$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
|
||||
|
||||
if ($data['response'] != $valid_response)
|
||||
die('Wrong credentials!');
|
||||
|
||||
// ok, valid username & password
|
||||
// echo 'Thanks! You are now logged in.';
|
||||
unset($realm, $users, $data, $A1, $A2, $valid_response);
|
||||
|
||||
// function to parse the http auth header
|
||||
function http_digest_parse($txt)
|
||||
{
|
||||
// protect against missing data
|
||||
$needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
|
||||
$data = array();
|
||||
$keys = implode('|', array_keys($needed_parts));
|
||||
|
||||
preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
|
||||
|
||||
foreach ($matches as $m) {
|
||||
$data[$m[1]] = $m[3] ? $m[3] : $m[4];
|
||||
unset($needed_parts[$m[1]]);
|
||||
}
|
||||
|
||||
return $needed_parts ? false : $data;
|
||||
}
|
||||
*/
|
||||
?>
|
52
admin/template.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
ob_start();
|
||||
function tpl_header($title='Full-Text RSS Admin Area') {
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><?php echo $title; ?></title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="robots" content="noindex, nofollow" />
|
||||
<link rel="stylesheet" href="../css/bootstrap.min.css" type="text/css" media="screen" />
|
||||
<script type="text/javascript" src="../js/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="../js/bootstrap-tooltip.js"></script>
|
||||
<script type="text/javascript" src="../js/bootstrap-popover.js"></script>
|
||||
<script type="text/javascript" src="../js/bootstrap-tab.js"></script>
|
||||
<style>
|
||||
html, body { background-color: #eee; }
|
||||
body { margin: 0; line-height: 1.4em; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; }
|
||||
label, input, select, textarea { font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; }
|
||||
.actions { padding-left: 220px; }
|
||||
.popover .inner { width: 200px; }
|
||||
#main-container { width: 800px; padding-bottom: 60px; }
|
||||
.page-header { padding-bottom: 0; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container" id="main-container">
|
||||
<div class="navbar">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="brand" href="../">Full-Text RSS</a>
|
||||
<ul class="nav">
|
||||
<li class="active"><a href="update.php">Update site patterns</a></li>
|
||||
<li><a href="index.php?logout">Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="page-header"><h1><?php echo $title; ?></h1></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function tpl_footer() {
|
||||
?>
|
||||
|
||||
</div> <!-- close container -->
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
}
|
||||
|
||||
register_shutdown_function('tpl_footer');
|
191
admin/update.php
Normal file
@ -0,0 +1,191 @@
|
||||
<?php
|
||||
// Update site config files for Full-Text RSS
|
||||
// Author: Keyvan Minoukadeh
|
||||
// Copyright (c) 2012 Keyvan Minoukadeh
|
||||
// License: AGPLv3
|
||||
// Date: 2012-04-13
|
||||
// More info: http://fivefilters.org/content-only/
|
||||
// Help: http://help.fivefilters.org
|
||||
|
||||
/*
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Usage
|
||||
// -----
|
||||
// Access this file in your browser and follow the instructions to update your site config files.
|
||||
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
ini_set("display_errors", 1);
|
||||
@set_time_limit(120);
|
||||
|
||||
////////////////////////////////
|
||||
// Load config file
|
||||
////////////////////////////////
|
||||
require_once('../config.php');
|
||||
$admin_page = 'update';
|
||||
require_once('require_login.php');
|
||||
require_once('template.php');
|
||||
tpl_header('Update site patterns');
|
||||
|
||||
$version = include('../site_config/standard/version.php');
|
||||
|
||||
/////////////////////////////////
|
||||
// Check for valid update key
|
||||
/////////////////////////////////
|
||||
if (!isset($_REQUEST['key']) || trim($_REQUEST['key']) == '') {
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
header('Location: update.php');
|
||||
exit;
|
||||
}
|
||||
$auto = true;
|
||||
$no_auto_reasons = array();
|
||||
if (!class_exists('ZipArchive')) {
|
||||
$auto = false;
|
||||
$no_auto_reasons[] = 'zip support (PHP\'s <a href="http://php.net/manual/en/zip.requirements.php">ZipArchive</a> class) is missing';
|
||||
}
|
||||
if (!is_writable('../site_config')) {
|
||||
$auto = false;
|
||||
$no_auto_reasons[] = 'your <tt>site_config/</tt> folder is not writable - change permissions to 777 and try again.</p>';
|
||||
}
|
||||
if (!file_exists('../site_config/standard/version.php')) {
|
||||
die('Could not determine current version of your site pattern files (site_config/standard/version.php). Make sure you\'re using at least version 2.9.5 of Full-Text RSS.');
|
||||
}
|
||||
if (!@$options->registration_key) {
|
||||
$input_field = '<label for="key">Registration key</label><input type="password" name="key" id="key" />';
|
||||
} else {
|
||||
$reg_key = preg_replace('/[^a-z0-9-]/i', '', $options->registration_key);
|
||||
$input_field = '<input type="hidden" name="key" value="'.$reg_key.'" />';
|
||||
}
|
||||
?>
|
||||
<p>You have Full-Text RSS <strong><?php echo _FF_FTR_VERSION; ?></strong>
|
||||
(Site Patterns version: <strong><?php echo (isset($version) ? $version : 'Unknown'); ?></strong>)
|
||||
</p>
|
||||
<p>To see if you have the latest versions, <a href="http://fivefilters.org/content-only/latest_version.php?version=<?php echo urlencode(_FF_FTR_VERSION).'&site_config='.urlencode(@$version); ?>">check for updates</a>.</p>
|
||||
<?php
|
||||
$reg_key_info = '<h3>Registration key</h3><p>This update tool requires a registration key issued by FiveFilters.org. You do not need a registration key to use Full-Text RSS, and none of the regular funtionality is affected if you do not have one. The update tool is simply a convenience service we offer our customers.</p>';
|
||||
if ($auto) {
|
||||
echo '<p>This update tool will attempt to fetch the latest site patterns from FiveFilters.org and update yours.</p>';
|
||||
echo '<p><strong>Important: </strong>if you\'ve modified or added your own config files in the <tt>site_config/standard/</tt> folder, please move them to <tt>site_config/custom/</tt> — the update process will attempt to replace everything in <tt>site_config/standard/</tt> with our updated version.</p>';
|
||||
echo $reg_key_info;
|
||||
if (!isset($reg_key)) {
|
||||
echo '<p>Your registration key should be your PayPal or Avangate transaction ID. If you don\'t have a registration key, you will get one sent to you automatically when you <a href="http://fivefilters.org/content-only/">purchase Full-Text RSS</a> from FiveFilters.org.</p>';
|
||||
}
|
||||
echo '<form method="post" action="update.php" class="well">',$input_field,' <input type="submit" value="Update now" /></form>';
|
||||
} else {
|
||||
echo '<div class="notice">';
|
||||
echo '<p>We cannot automatically update your site pattern files because:</p>';
|
||||
echo '<ul>';
|
||||
foreach ($no_auto_reasons as $reason) {
|
||||
echo '<li>',$reason,'</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
echo '<p>You can still manually update by downloading the zip file and replacing everything in your <tt>site_config/standard/</tt> folder with the contents of the zip file.</p>';
|
||||
echo '</div>';
|
||||
echo $reg_key_info;
|
||||
if (!isset($reg_key)) {
|
||||
echo '<p>Enter your registration key below to download the latest version of the site config files from FiveFilters.org</p>';
|
||||
echo '<p>Your registration key should be your PayPal or Avangate transaction ID.</p>';
|
||||
}
|
||||
echo '<form method="post" class="well" action="http://fivefilters.org/content-only/update/get_site_config.php">',$input_field,' <input type="submit" value="Download site patterns" /></form>';
|
||||
}
|
||||
echo '<h3>Help</h3>';
|
||||
echo '<p>If you have any trouble, please contact us via our <a href="http://help.fivefilters.org">support site</a>.</p>';
|
||||
exit;
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
// Check for updates
|
||||
//////////////////////////////////
|
||||
$ff_version = (float)@file_get_contents('http://fivefilters.org/content-only/site_config/standard/version.txt');
|
||||
if (version_compare($version, $ff_version) != -1) {
|
||||
die('Your site config files are up to date! If you have trouble extracting from a particular site, please email us: help@fivefilters.org');
|
||||
} else {
|
||||
println("Updated site patterns are available at FiveFilters.org (version $ff_version)...");
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
// Prepare
|
||||
//////////////////////////////////
|
||||
$latest_remote = 'http://fivefilters.org/content-only/update/get_site_config.php?key='.urlencode($_REQUEST['key']);
|
||||
$tmp_latest_local = '../site_config/latest_site_config.zip';
|
||||
$tmp_latest_local_dir = '../site_config/standard_latest';
|
||||
$tmp_old_local_dir = '../site_config/standard_old';
|
||||
if (file_exists($tmp_latest_local)) unlink($tmp_latest_local);
|
||||
if (file_exists($tmp_latest_local_dir)) rrmdir($tmp_latest_local_dir);
|
||||
if (file_exists($tmp_old_local_dir)) {
|
||||
rrmdir($tmp_old_local_dir);
|
||||
}
|
||||
$standard_local_dir = '../site_config/standard/';
|
||||
//@copy($latest_remote, $tmp_latest_local);
|
||||
//copy() does not appear to fill $http_response_header in certain environments
|
||||
@file_put_contents($tmp_latest_local, @file_get_contents($latest_remote));
|
||||
$headers = implode("\n", $http_response_header);
|
||||
//var_dump($headers); exit;
|
||||
if (strpos($headers, 'HTTP/1.1 403') !== false) {
|
||||
println("Invalid registration key supplied");
|
||||
exit;
|
||||
} elseif (strpos($headers, 'HTTP/1.1 200') === false) {
|
||||
println("Sorry, something went wrong. We're looking into it. Please contact us if the problem persists.");
|
||||
exit;
|
||||
}
|
||||
if (class_exists('ZipArchive') && file_exists($tmp_latest_local)) {
|
||||
println("Downloaded latest copy of the site pattern files to $tmp_latest_local");
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($tmp_latest_local) === TRUE) {
|
||||
$zip->extractTo($tmp_latest_local_dir);
|
||||
$zip->close();
|
||||
@unlink($tmp_latest_local);
|
||||
if (file_exists($tmp_latest_local_dir)) {
|
||||
println("Unzipped contents to $tmp_latest_local_dir");
|
||||
if (!file_exists($tmp_latest_local_dir.'/version.php')) {
|
||||
println("There was a problem extracting the latest site patterns archive - your current site patterns remain untouched.");
|
||||
println("Please <a href=\"$latest_remote\">update manually</a>.");
|
||||
exit;
|
||||
}
|
||||
rename($standard_local_dir, $tmp_old_local_dir);
|
||||
if (file_exists($tmp_old_local_dir)) println("Renamed $standard_local_dir to $tmp_old_local_dir");
|
||||
rename($tmp_latest_local_dir, $standard_local_dir);
|
||||
if (file_exists($standard_local_dir)) println("Renamed $tmp_latest_local_dir to $standard_local_dir");
|
||||
println("<strong style=\"color: darkgreen;\">All done!</strong> Your old site config files are in $tmp_old_local_dir — these will be removed next time you go through the update process.");
|
||||
} else {
|
||||
if (file_exists($tmp_latest_local)) @unlink($tmp_latest_local);
|
||||
println("Failed to unzip to $tmp_latest_local_dir - your current site patterns remain untouched");
|
||||
}
|
||||
} else {
|
||||
if (file_exists($tmp_latest_local)) @unlink($tmp_latest_local);
|
||||
println("Failed to extract from $tmp_latest_local - your current site patterns remain untouched");
|
||||
}
|
||||
} else {
|
||||
println("Could not download the latest site config files. Please <a href=\"$latest_remote\">update manually</a> - your current site patterns remain untouched.");
|
||||
}
|
||||
|
||||
function println($txt) {
|
||||
echo $txt,"<br />\n";
|
||||
ob_end_flush();
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
|
||||
function rrmdir($dir) {
|
||||
foreach(glob($dir . '/{*.txt,*.php,.*.txt,.*.php}', GLOB_BRACE|GLOB_NOSORT) as $file) {
|
||||
if(is_dir($file)) {
|
||||
rrmdir($file);
|
||||
} else {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
rmdir($dir);
|
||||
}
|
||||
?>
|
@ -2,6 +2,35 @@ FiveFilters.org: Full-Text RSS
|
||||
http://fivefilters.org/content-only/
|
||||
CHANGELOG
|
||||
------------------------------------
|
||||
2.9.5 (2012-04-29)
|
||||
- Language detection using Text_LanguageDetect or PHP-CLD (dc:language field in output and $options->detect_language in config)
|
||||
- New site patterns added and old ones updated
|
||||
- Experimental tool for simpler site pattern updates (access admin/ folder)
|
||||
- Plus other fixes/improvements
|
||||
|
||||
2.9.1 (2011-11-02)
|
||||
- Fix: Character encoding issue affecting some non-English articles (makefulltextfeed.php and SimplePie/Misc.php changed)
|
||||
|
||||
2.9 (2011-11-01)
|
||||
- New site patterns added and old ones updated
|
||||
- New config option: require_key - restrict access to those with password/key
|
||||
- New config option: rewrite_url - URL rewrite rules to be applied before HTTP request
|
||||
- New site config options to extract author(s) and publication date (matches included in feed item as <dc:creator> and <pubDate>)
|
||||
- New site config option: replace_string([string to find]): [replacement string]
|
||||
- New site identification method: site fingerprints (HTML fragments linked to site config)
|
||||
- Update check now also checks for new site patterns
|
||||
- Effective URL (URL after redirects/rewrites) now included in feed item as <dc:identifier>
|
||||
- Prevent indexing of generated feeds by search engines
|
||||
- Enclosure support (enclosures preserved as <media:content> elements)
|
||||
- Better handling of non-HTML content types
|
||||
- Sending custom User-Agent HTTP header for matching sites now supported
|
||||
- CSS extraction deprecated in favour of site patterns (still works, but form field removed and feature may disappear in 3.0)
|
||||
- Fix: Improved character-encoding detection
|
||||
- Fix: URL parsing issues for certain URLs (SimplePie updated)
|
||||
- Fix: Author and other Dublin Core (<dc:..>) elements now appear in JSON output
|
||||
- Fix: Minor fixes for PHP Readability
|
||||
- Plus other minor fixes/improvements
|
||||
|
||||
2.8 (2011-05-30)
|
||||
- Tidy no longer stripping HTML5 elements
|
||||
- JSON output (pass &format=json in querystring)
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
// Full-Text RSS: Clear Cache
|
||||
// Author: Keyvan Minoukadeh
|
||||
// Copyright (c) 2010 Keyvan Minoukadeh
|
||||
// Copyright (c) 2012 Keyvan Minoukadeh
|
||||
// License: AGPLv3
|
||||
|
||||
/*
|
||||
@ -61,7 +61,7 @@ $frontendOptions = array(
|
||||
'write_control' => false,
|
||||
'automatic_cleaning_factor' => 0,
|
||||
'ignore_user_abort' => false
|
||||
);
|
||||
);
|
||||
$backendOptions = array(
|
||||
'cache_dir' => $options->cache_dir.'/http-responses/',
|
||||
'file_locking' => false,
|
||||
|
221
config.php
@ -12,7 +12,7 @@
|
||||
// .....................................................
|
||||
|
||||
// Create config object
|
||||
$options = new stdClass();
|
||||
if (!isset($options)) $options = new stdClass();
|
||||
|
||||
// Enable service
|
||||
// ----------------------
|
||||
@ -21,14 +21,18 @@ $options = new stdClass();
|
||||
// be told that the service is disabled.
|
||||
$options->enabled = true;
|
||||
|
||||
// Default entries (without API key)
|
||||
// Default entries (without access key)
|
||||
// ----------------------
|
||||
// The number of feed items to process when no API key is supplied.
|
||||
// The number of feed items to process when no API key is supplied
|
||||
// and no &max=x value is supplied in the querystring.
|
||||
$options->default_entries = 5;
|
||||
|
||||
// Max entries (without API key)
|
||||
// Max entries (without access key)
|
||||
// ----------------------
|
||||
// The maximum number of feed items to process when no API key is supplied.
|
||||
// The maximum number of feed items to process when no access key is supplied.
|
||||
// This limits the user-supplied &max=x value. For example, if the user
|
||||
// asks for 20 items to be processed (&max=20), if max_entries is set to
|
||||
// 10, only 10 will be processed.
|
||||
$options->max_entries = 10;
|
||||
|
||||
// Rewrite relative URLs
|
||||
@ -48,16 +52,6 @@ $options->rewrite_relative_urls = true;
|
||||
// User decides: 'user' (this option will appear on the form)
|
||||
$options->exclude_items_on_fail = 'user';
|
||||
|
||||
// Extraction pattern
|
||||
// ---------------------------------
|
||||
// Specify what should get extracted
|
||||
// Possible values:
|
||||
// Auto detect: 'auto'
|
||||
// Custom: css string (e.g. 'div#content')
|
||||
// Element within auto-detected block: 'auto ' + css string (e.g. 'auto p')
|
||||
// User decides: 'user' (default, this option will appear on the form)
|
||||
$options->extraction_pattern = 'user';
|
||||
|
||||
// Enable caching
|
||||
// ----------------------
|
||||
// Enable this if you'd like to cache results
|
||||
@ -71,22 +65,69 @@ $options->caching = false;
|
||||
// Only used if caching is true
|
||||
$options->cache_dir = dirname(__FILE__).'/cache';
|
||||
|
||||
// Message to prepend (without API key)
|
||||
// Message to prepend (without access key)
|
||||
// ----------------------
|
||||
// HTML to insert at the beginning of each feed item when no API key is supplied.
|
||||
// HTML to insert at the beginning of each feed item when no access key is supplied.
|
||||
// Substitution tags:
|
||||
// {url} - Feed item URL
|
||||
// {effective-url} - Feed item URL after we've followed all redirects
|
||||
$options->message_to_prepend = '';
|
||||
|
||||
// Message to append (without API key)
|
||||
// Message to append (without access key)
|
||||
// ----------------------
|
||||
// HTML to insert at the end of each feed item when no API key is supplied.
|
||||
// HTML to insert at the end of each feed item when no access key is supplied.
|
||||
// Substitution tags:
|
||||
// {url} - Feed item URL
|
||||
// {effective-url} - Feed item URL after we've followed all redirects
|
||||
$options->message_to_append = '';
|
||||
|
||||
// Error message when content extraction fails (without access key)
|
||||
// ----------------------
|
||||
$options->error_message = '[unable to retrieve full-text content]';
|
||||
|
||||
// Keep enclosure in feed items
|
||||
// If enabled, we will try to preserve enclosures if present.
|
||||
// ----------------------
|
||||
$options->keep_enclosures = true;
|
||||
|
||||
// Detect language
|
||||
// ---------------
|
||||
// Should we try and find/guess the language of the article being processed?
|
||||
// Values will be placed inside the <dc:language> element inside each <item> element
|
||||
// Possible values:
|
||||
// * Ignore language: 0
|
||||
// * Use article/feed metadata (e.g. HTML lang attribute): 1 (default)
|
||||
// * As above, but guess if not present: 2
|
||||
// * Always guess: 3
|
||||
// * User decides: 'user' (value of 0-3 can be passed in querystring: e.g. &l=2)
|
||||
$options->detect_language = 1;
|
||||
|
||||
// Registration key
|
||||
// ---------------
|
||||
// The registration key is optional. It is not required to use Full-Text RSS,
|
||||
// and does not affect the normal operation of Full-Text RSS. It is currently
|
||||
// only used on admin pages which help you update site patterns with the
|
||||
// latest version offered by FiveFilters.org. For these admin-related
|
||||
// tasks to complete, we will require a valid registration key.
|
||||
// If you would like one, you can purchase the latest version of Full-Text RSS
|
||||
// at http://fivefilters.org/content-only/
|
||||
// Your registration key will automatically be sent in the confirmation email.
|
||||
// Once you have it, simply copy and paste it here.
|
||||
$options->registration_key = '';
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/// RESTRICT ACCESS /////////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// Admin credentials
|
||||
// ----------------------
|
||||
// Certain pages/actions, e.g. updating site patterns with our online tool, will require admin credentials.
|
||||
// To use these pages, enter a password here and you'll be prompted for it when you try to access those pages.
|
||||
// If no password or username is set, pages requiring admin privelages will be inaccessible.
|
||||
// The default username is 'admin'.
|
||||
// Example: $options->admin_credentials = array('username'=>'admin', 'password'=>'my-secret-password');
|
||||
$options->admin_credentials = array('username'=>'admin', 'password'=>'');
|
||||
|
||||
// URLs to allow
|
||||
// ----------------------
|
||||
// List of URLs (or parts of a URL) which the service will accept.
|
||||
@ -102,14 +143,109 @@ $options->allowed_urls = array();
|
||||
// Note: this list is ignored if allowed_urls is not empty
|
||||
$options->blocked_urls = array();
|
||||
|
||||
// Error message when content extraction fails (without API key)
|
||||
// Key holder(s) only?
|
||||
// ----------------------
|
||||
$options->error_message = '[unable to retrieve full-text content]';
|
||||
// Set this to true if you want to restrict access only to
|
||||
// those with a key (see below to specify key(s)).
|
||||
// If set to true, no feed is produced unless a valid
|
||||
// key is provided.
|
||||
$options->key_required = false;
|
||||
|
||||
// Access keys (password protected access)
|
||||
// ------------------------------------
|
||||
// NOTE: You do not need an API key from fivefilters.org to run your own
|
||||
// copy of the code. This is here if you'd like to restrict access to
|
||||
// _your_ copy.
|
||||
// Keys let you group users - those with a key and those without - and
|
||||
// restrict access to the service to those without a key.
|
||||
// If you want everyone to access the service in the same way, you can
|
||||
// leave the array below empty and ignore the access key options further down.
|
||||
// The options further down let you control how the service should behave
|
||||
// in each mode.
|
||||
// Note: Explicitly including the index number (1 and 2 in the examples below)
|
||||
// is highly recommended (when generating feeds, we encode the key and
|
||||
// refer to it by index number and hash).
|
||||
$options->api_keys = array();
|
||||
// Example:
|
||||
// $options->api_keys[1] = 'secret-key-1';
|
||||
// $options->api_keys[2] = 'secret-key-2';
|
||||
|
||||
// Default entries (with access key)
|
||||
// ----------------------
|
||||
// The number of feed items to process when a valid access key is supplied.
|
||||
$options->default_entries_with_key = 5;
|
||||
|
||||
// Max entries (with access key)
|
||||
// ----------------------
|
||||
// The maximum number of feed items to process when a valid access key is supplied.
|
||||
$options->max_entries_with_key = 10;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/// ADVANCED OPTIONS ////////////////////////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// Fingerprints
|
||||
// ----------------------
|
||||
// key is fingerprint (fragment to find in HTML)
|
||||
// value is host name to use for site config lookup if fingerprint matches
|
||||
$options->fingerprints = array(
|
||||
// Posterous
|
||||
'<meta name="generator" content="Posterous"' => array('hostname'=>'fingerprint.posterous.com', 'head'=>true),
|
||||
// Blogger
|
||||
'<meta content=\'blogger\' name=\'generator\'' => array('hostname'=>'fingerprint.blogspot.com', 'head'=>true),
|
||||
'<meta name="generator" content="Blogger"' => array('hostname'=>'fingerprint.blogspot.com', 'head'=>true),
|
||||
// WordPress (hosted)
|
||||
// '<meta name="generator" content="WordPress.com"' => array('hostname'=>'fingerprint.wordpress.com', 'head'=>true),
|
||||
// WordPress (self-hosted and hosted)
|
||||
'<meta name="generator" content="WordPress' => array('hostname'=>'fingerprint.wordpress.com', 'head'=>true)
|
||||
);
|
||||
|
||||
// User Agent strings - mapping domain names
|
||||
// ----------------------
|
||||
// e.g. $options->user_agents = array('example.org' => 'PHP/5.2');
|
||||
$options->user_agents = array( 'lifehacker.com' => 'PHP/5.2',
|
||||
'gawker.com' => 'PHP/5.2',
|
||||
'deadspin.com' => 'PHP/5.2',
|
||||
'kotaku.com' => 'PHP/5.2',
|
||||
'jezebel.com' => 'PHP/5.2',
|
||||
'io9.com' => 'PHP/5.2',
|
||||
'jalopnik.com' => 'PHP/5.2',
|
||||
'gizmodo.com' => 'PHP/5.2',
|
||||
'.wikipedia.org' => 'Mozilla/5.2'
|
||||
);
|
||||
|
||||
// URL Rewriting
|
||||
// ----------------------
|
||||
// Currently allows simple string replace of URLs.
|
||||
// Useful for rewriting certain URLs to point to a single page
|
||||
// or HTML view. Although using the single_page_link site config
|
||||
// instruction is the preferred way to do this, sometimes, as
|
||||
// with Google Docs URLs, it's not possible.
|
||||
// Note: this might move to the site config file at some point.
|
||||
$options->rewrite_url = array(
|
||||
// Rewrite public Google Docs URLs to point to HTML view:
|
||||
// if a URL contains docs.google.com, replace /Doc? with /View?
|
||||
'docs.google.com' => array('/Doc?' => '/View?'),
|
||||
'tnr.com' => array('tnr.com/article/' => 'tnr.com/print/article/'),
|
||||
'.m.wikipedia.org' => array('.m.wikipedia.org' => '.wikipedia.org')
|
||||
);
|
||||
|
||||
// Content-Type exceptions
|
||||
// -----------------------
|
||||
// We currently treat everything as HTML.
|
||||
// Here you can define different actions if
|
||||
// Content-Type returned by server matches.
|
||||
// MIME type as key, action as value.
|
||||
// Valid actions:
|
||||
// * 'exclude' - exclude this item from the result
|
||||
// * 'link' - create HTML link to the item
|
||||
$options->content_type_exc = array(
|
||||
'application/pdf' => array('action'=>'link', 'name'=>'PDF'),
|
||||
'image' => array('action'=>'link', 'name'=>'Image'),
|
||||
'audio' => array('action'=>'link', 'name'=>'Audio'),
|
||||
'video' => array('action'=>'link', 'name'=>'Video')
|
||||
);
|
||||
|
||||
// Alternative Full-Text RSS service URL
|
||||
// ----------------------
|
||||
// This option is to offer very simple load distribution for the service.
|
||||
@ -133,17 +269,29 @@ $options->cache_directory_level = 0;
|
||||
// -------------
|
||||
// 0 = script will not clean cache (rename cachecleanup.php and use it for scheduled (e.g. cron) cache cleanup)
|
||||
// 1 = clean cache everytime the script runs (not recommended)
|
||||
// 100 = (roughly) clean cache once out of every 100 script runs
|
||||
// x = (roughly) clean cache once out of every x script runs
|
||||
// 100 = clean cache roughly once every 100 script runs
|
||||
// x = clean cache roughly once every x script runs
|
||||
// ...you get the idea :)
|
||||
$options->cache_cleanup = 100;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
/// DEPRECATED OPTIONS
|
||||
/// THESE OPTIONS WILL CHANGE IN VERSION 3.0
|
||||
/// THESE OPTIONS MIGHT CHANGE IN VERSION 3.0
|
||||
/// WE RECOMMEND YOU DO NOT USE THEM
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
// Extraction pattern (deprecated)
|
||||
// Site configuration files offer a better,
|
||||
// more flexible solution - please use those instead.
|
||||
// ---------------------------------
|
||||
// Specify what should get extracted
|
||||
// Possible values:
|
||||
// Auto detect: 'auto'
|
||||
// Custom: css string (e.g. 'div#content')
|
||||
// Element within auto-detected block: 'auto ' + css string (e.g. 'auto p')
|
||||
// User decides: 'user' (same as 'auto' but CSS selector can be passed in query, e.g. &what=.content)
|
||||
$options->extraction_pattern = 'user';
|
||||
|
||||
// Restrict service (deprecated)
|
||||
// -----------------------------
|
||||
// Set this to true if you'd like certain features
|
||||
@ -153,29 +301,6 @@ $options->cache_cleanup = 100;
|
||||
// * Cache time (20 minutes for non-key holders if set to true)
|
||||
$options->restrict = false;
|
||||
|
||||
// API keys (deprecated)
|
||||
// ----------------------
|
||||
// NOTE: You do not need an API key from fivefilters.org to run your own
|
||||
// copy of the code. This is here if you'd like to offer others an API key
|
||||
// to access _your_ copy.
|
||||
// Keys let you group users - those with a key and those without - and
|
||||
// restrict access to the service to those without a key.
|
||||
// If you want everyone to access the service in the same way, you can
|
||||
// leave the array below empty and ignore the API key options further down.
|
||||
// The options further down in this file will allow you to specify
|
||||
// how the service should behave in each mode.
|
||||
$options->api_keys = array();
|
||||
|
||||
// Default entries (with API key) (deprecated)
|
||||
// ----------------------
|
||||
// The number of feed items to process when a valid API key is supplied.
|
||||
$options->default_entries_with_key = 5;
|
||||
|
||||
// Max entries (with API key) (deprecated)
|
||||
// ----------------------
|
||||
// The maximum number of feed items to process when a valid API key is supplied.
|
||||
$options->max_entries_with_key = 10;
|
||||
|
||||
// Message to prepend (with API key) (deprecated)
|
||||
// ----------------------
|
||||
// HTML to insert at the beginning of each feed item when a valid API key is supplied.
|
||||
@ -194,7 +319,7 @@ $options->error_message_with_key = '[unable to retrieve full-text content]';
|
||||
/// DO NOT CHANGE ANYTHING BELOW THIS ///////////
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
if (!defined('_FF_FTR_VERSION')) define('_FF_FTR_VERSION', '2.8');
|
||||
if (!defined('_FF_FTR_VERSION')) define('_FF_FTR_VERSION', '2.9.5');
|
||||
|
||||
if ((basename(__FILE__) == 'config.php') && (file_exists(dirname(__FILE__).'/custom_config.php'))) {
|
||||
require_once(dirname(__FILE__).'/custom_config.php');
|
||||
|
9
css/bootstrap.min.css
vendored
Normal file
@ -1,92 +0,0 @@
|
||||
/*Defaults Styling*/
|
||||
body {font:12px/17px Arial, Helvetica, sans-serif; color:#333; background:#ccc; padding:40px 20px 20px 20px;}
|
||||
fieldset {background:#f2f2e6; padding:10px; border:1px solid #fff; border-color:#fff #666661 #666661 #fff; margin-bottom:36px; width:600px;}
|
||||
input, textarea, select {font:12px/12px Arial, Helvetica, sans-serif; padding:0;}
|
||||
fieldset.action {background:#9da2a6; border-color:#e5e5e5 #797c80 #797c80 #e5e5e5; margin-top:-20px;}
|
||||
legend {background:#bfbf30; color:#fff; font:17px/21px Calibri, Arial, Helvetica, sans-serif; padding:0 10px; margin:-26px 0 0 -11px; font-weight:bold; border:1px solid #fff; border-color:#e5e5c3 #505014 #505014 #e5e5c3;}
|
||||
label {font-size:11px; font-weight:bold; color:#666;}
|
||||
label.opt {font-weight:normal;}
|
||||
dl {clear:both;}
|
||||
dt {float:left; text-align:right; width:100px; line-height:25px; margin:0 10px 10px 0;}
|
||||
dd {float:left; width:465px; line-height:25px; margin:0 0 10px 0;}
|
||||
#footer {font-size:11px;}
|
||||
|
||||
#container {width:700px; margin:0 auto;}
|
||||
|
||||
/*##########################################
|
||||
Script: Niceforms 2.0
|
||||
Theme: StandardBlue
|
||||
Author: Lucian Slatineanu
|
||||
URL: http://www.emblematiq.com/
|
||||
##########################################*/
|
||||
|
||||
/*Text inputs*/
|
||||
.NFText {border:none; vertical-align:middle; font:12px/15px Arial, Helvetica, sans-serif; background:none;}
|
||||
.NFTextCenter {height:15px; background:url(../images/niceforms/input.png) repeat-x 0 0; padding:3px 0; margin:0; float:left; line-height:15px;}
|
||||
.NFTextLeft, .NFTextRight {width:7px; height:21px; vertical-align:middle; float:left;}
|
||||
.NFTextLeft {background:url(../images/niceforms/input-left.png) no-repeat 0 0;}
|
||||
.NFTextRight {background:url(../images/niceforms/input-right.png) no-repeat 0 0;}
|
||||
/*Radio*/
|
||||
.NFRadio {cursor:pointer; position:absolute; display:block; width:13px; height:13px; border:1px solid transparent; background:url(../images/niceforms/radio.png) no-repeat 0 0; z-index:2;}
|
||||
/*Checkbox*/
|
||||
.NFCheck {cursor:pointer; position:absolute; width:12px; height:12px; border:1px solid transparent; background:url(../images/niceforms/checkbox.png) no-repeat 0 0; z-index:2;}
|
||||
/*Buttons*/
|
||||
.NFButton {width:auto; height:26px; color:#fff; padding:0 2px; background:url(../images/niceforms/button.png) repeat-x 0 0; cursor:pointer; border:none; font:10px/26px Tahoma, Arial, Helvetica, sans-serif; font-weight:bold; text-transform:uppercase; letter-spacing:1px; vertical-align:middle;}
|
||||
.NFButtonLeft, .NFButtonRight {width:6px; height:26px; vertical-align:middle;}
|
||||
.NFButtonLeft {background:url(../images/niceforms/button-left.png) no-repeat 0 0;}
|
||||
.NFButtonRight {background:url(../images/niceforms/button-right.png) no-repeat 0 0;}
|
||||
/*Textareas*/
|
||||
.NFTextarea {border:none; background:none; font:12px/12px Arial, Helvetica, sans-serif; margin:0;}
|
||||
.NFTextareaTop, .NFTextareaBottom {height:5px; clear:both; float:none; padding-right:10px;}
|
||||
.NFTextareaTop {background:url(../images/niceforms/textarea-tr.png) no-repeat 100% 0;}
|
||||
.NFTextareaBottom {background:url(../images/niceforms/textarea-br.png) no-repeat 100% 0; margin-bottom:5px;}
|
||||
.NFTextareaTopLeft, .NFTextareaBottomLeft {width:5px; height:5px;}
|
||||
.NFTextareaTopLeft {background:#f2f2e6 url(../images/niceforms/textarea-tl.png) no-repeat 0 0;}
|
||||
.NFTextareaBottomLeft {background:#f2f2e6 url(../images/niceforms/textarea-bl.png) no-repeat 0 0;}
|
||||
.NFTextareaLeft, .NFTextareaRight, .NFTextareaLeftH, .NFTextareaRightH {float:left; padding-bottom:5px;}
|
||||
.NFTextareaLeft, .NFTextareaLeftH {width:5px;}
|
||||
.NFTextareaLeft {background:url(../images/niceforms/textarea-l-off.png) repeat-y 0 0;}
|
||||
.NFTextareaLeftH {background:url(../images/niceforms/textarea-l-over.png) repeat-y 0 0;}
|
||||
.NFTextareaRight, .NFTextareaRightH {padding-right:5px; padding-bottom:0;}
|
||||
.NFTextareaRight {background:url(../images/niceforms/textarea-r-off.png) repeat-y 100% 0;}
|
||||
.NFTextareaRightH {background:url(../images/niceforms/textarea-r-over.png) repeat-y 100% 100%;}
|
||||
/*Files*/
|
||||
.NFFileButton {padding-bottom:0; vertical-align:bottom; cursor:pointer; background:url(../images/niceforms/file.png) no-repeat 0 0; width:60px; height:21px;}
|
||||
.NFFile {position:relative; margin-bottom:5px;}
|
||||
.NFFile input.NFhidden {position:relative; filter:alpha(opacity=0); opacity:0; z-index:2; cursor:pointer; text-align:left;}
|
||||
.NFFileNew {position:absolute; top:0px; left:0px; z-index:1;}
|
||||
/*Selects*/
|
||||
.NFSelect {height:21px; position:absolute; border:1px solid transparent;}
|
||||
.NFSelectLeft {float:left; width:3px; height:21px; background:url(../images/niceforms/select-left.png) no-repeat 0 0; vertical-align:middle;}
|
||||
.NFSelectRight {height:21px; width:auto; background:url(../images/niceforms/select-right.png) no-repeat 100% 0; cursor:pointer; font:12px/21px Arial, Helvetica, sans-serif; color:#fff; padding-left:3px; margin-left:3px;}
|
||||
.NFSelectTarget {position:absolute; background:none; margin-left:-13px; margin-top:18px; z-index:3; left:0; top:0; padding-bottom:13px;}
|
||||
.NFSelectOptions {position:relative; background:#707175; margin-left:16px; margin-top:0; list-style:none; padding:4px 0; color:#fff; font:11px/13px Arial, Helvetica, sans-serif; z-index:4; max-height:200px; overflow-y:auto; overflow-x:hidden; left:0; top:0;}
|
||||
.NFSelectOptions li {padding-bottom:1px;}
|
||||
.NFSelectOptions a {display:block; text-decoration:none; color:#fff; padding:2px 3px; background:none;}
|
||||
.NFSelectOptions a.NFOptionActive {background:#464646;}
|
||||
.NFSelectOptions a:hover {background:#333;}
|
||||
/*Multiple Selects*/
|
||||
.NFMultiSelect {border:0; background:none; margin:0;}
|
||||
.NFMultiSelectTop, .NFMultiSelectBottom {height:5px; clear:both; float:none; padding-right:10px;}
|
||||
.NFMultiSelectTop {background:url(../images/niceforms/textarea-tr.png) no-repeat 100% 0;}
|
||||
.NFMultiSelectBottom {background:url(../images/niceforms/textarea-br.png) no-repeat 100% 0; margin-bottom:5px;}
|
||||
.NFMultiSelectTopLeft, .NFMultiSelectBottomLeft {width:5px; height:5px;}
|
||||
.NFMultiSelectTopLeft {background:#f2f2e6 url(../images/niceforms/textarea-tl.png) no-repeat 0 0;}
|
||||
.NFMultiSelectBottomLeft {background:#f2f2e6 url(../images/niceforms/textarea-bl.png) no-repeat 0 0;}
|
||||
.NFMultiSelectLeft, .NFMultiSelectRight, .NFMultiSelectLeftH, .NFMultiSelectRightH {float:left; padding-bottom:5px;}
|
||||
.NFMultiSelectLeft, .NFMultiSelectLeftH {width:5px;}
|
||||
.NFMultiSelectLeft {background:url(../images/niceforms/textarea-l-off.png) repeat-y 0 0;}
|
||||
.NFMultiSelectLeftH {background:url(../images/niceforms/textarea-l-over.png) repeat-y 0 0;}
|
||||
.NFMultiSelectRight, .NFMultiSelectRightH {padding-right:5px; padding-bottom:0;}
|
||||
.NFMultiSelectRight {background:url(../images/niceforms/textarea-r-off.png) repeat-y 100% 0;}
|
||||
.NFMultiSelectRightH {background:url(../images/niceforms/textarea-r-over.png) repeat-y 100% 0;}
|
||||
|
||||
/*Focused*/
|
||||
.NFfocused {border:1px dotted #666;}
|
||||
/*Hovered*/
|
||||
.NFh {background-position:0 100%;}
|
||||
.NFhr {background-position:100% 100%;}
|
||||
/*Hidden*/
|
||||
.NFhidden {opacity:0; z-index:-1; position:relative;}
|
||||
/*Safari*/
|
||||
select, input, textarea, button {outline:none; resize:none;}
|
@ -13,7 +13,7 @@ SimplePie.org. We have kept most of their checks intact as we use SimplePie in o
|
||||
http://github.com/simplepie/simplepie/tree/master/compatibility_test/
|
||||
*/
|
||||
|
||||
$app_name = 'Full-Text RSS 2.8';
|
||||
$app_name = 'Full-Text RSS 2.9';
|
||||
|
||||
$php_ok = (function_exists('version_compare') && version_compare(phpversion(), '5.2.0', '>='));
|
||||
$pcre_ok = extension_loaded('pcre');
|
||||
@ -39,7 +39,7 @@ if (extension_loaded('xmlreader')) {
|
||||
|
||||
header('Content-type: text/html; charset=UTF-8');
|
||||
|
||||
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
||||
?><!DOCTYPE html>
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
Before Width: | Height: | Size: 110 B |
Before Width: | Height: | Size: 661 B |
Before Width: | Height: | Size: 711 B |
Before Width: | Height: | Size: 247 B |
Before Width: | Height: | Size: 701 B |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 578 B |
Before Width: | Height: | Size: 581 B |
Before Width: | Height: | Size: 260 B |
Before Width: | Height: | Size: 1013 B |
Before Width: | Height: | Size: 263 B |
Before Width: | Height: | Size: 869 B |
Before Width: | Height: | Size: 265 B |
Before Width: | Height: | Size: 488 B |
Before Width: | Height: | Size: 168 B |
Before Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 266 B |
Before Width: | Height: | Size: 270 B |
Before Width: | Height: | Size: 269 B |
Before Width: | Height: | Size: 488 B |
285
index.php
@ -16,141 +16,228 @@ if (!defined('_FF_FTR_INDEX')) {
|
||||
<title>Full-Text RSS Feeds | from fivefilters.org</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="robots" content="noindex, follow" />
|
||||
<script type="text/javascript" src="niceforms.js"></script>
|
||||
<link rel="stylesheet" href="css/niceforms-default.css" type="text/css" media="screen" />
|
||||
<script type="text/javascript" src="js/niceforms.js"></script>
|
||||
<!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>-->
|
||||
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
|
||||
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" media="screen" />
|
||||
<script type="text/javascript" src="js/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="js/bootstrap-tooltip.js"></script>
|
||||
<script type="text/javascript" src="js/bootstrap-popover.js"></script>
|
||||
<script type="text/javascript" src="js/bootstrap-tab.js"></script>
|
||||
<script type="text/javascript">
|
||||
var baseUrl = 'http://'+window.location.host+window.location.pathname.replace(/(\/index\.php|\/)$/, '');
|
||||
$(document).ready(function() {
|
||||
// remove http scheme from urls before submitting
|
||||
$('#form').submit(function() {
|
||||
$('#url').val($('#url').val().replace(/^http:\/\//i, ''));
|
||||
return true;
|
||||
});
|
||||
// popovers
|
||||
$('#url').popover({offset: 10, placement: 'left', trigger: 'focus', html: true});
|
||||
$('#key').popover({offset: 10, placement: 'left', trigger: 'focus', html: true});
|
||||
$('#max').popover({offset: 10, placement: 'left', trigger: 'focus', html: true});
|
||||
$('#links').popover({offset: 10, placement: 'left', trigger: 'focus', html: true});
|
||||
$('#exc').popover({offset: 10, placement: 'left', trigger: 'focus', html: true});
|
||||
// tooltips
|
||||
$('a[rel=tooltip]').tooltip();
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
html, body { background-color: #eee; }
|
||||
body { margin: 0; line-height: 1.4em; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; }
|
||||
label, input, select, textarea { font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; }
|
||||
li { color: #404040; }
|
||||
li.active a { font-weight: bold; color: #666 !important; }
|
||||
form .controls { margin-left: 220px !important; }
|
||||
label { width: 200px !important; }
|
||||
fieldset legend { padding-left: 220px; line-height: 20px !important;}
|
||||
.form-actions { padding-left: 220px !important; }
|
||||
.popover-inner { width: 205px; }
|
||||
h1 { margin-bottom: 18px; }
|
||||
</style>
|
||||
</head>
|
||||
<body style="background-color: #eee; margin: 0; line-height: 1.4em;">
|
||||
<div id="container">
|
||||
<h1 style="padding-bottom: 30px;">Full-Text RSS <?php echo _FF_FTR_VERSION; ?> <span style="font-size: .7em; font-weight: normal;">— from <a href="http://fivefilters.org">FiveFilters.org</a></span></h1>
|
||||
<form method="get" action="makefulltextfeed.php" id="form" class="niceform">
|
||||
<body>
|
||||
<div class="container" style="width: 800px; padding-bottom: 60px;">
|
||||
<h1 style="padding-top: 5px;">Full-Text RSS <?php echo _FF_FTR_VERSION; ?> <span style="font-size: .7em; font-weight: normal;">— from <a href="http://fivefilters.org">FiveFilters.org</a></span></h1>
|
||||
<form method="get" action="makefulltextfeed.php" id="form" class="form-horizontal">
|
||||
<fieldset>
|
||||
<legend>Create full-text feed from feed or webpage URL</legend>
|
||||
<dl>
|
||||
<dt><label for="url">Enter URL:</label></dt>
|
||||
<dd><input type="text" id="url" name="url" style="width: 450px;" /></dd>
|
||||
</dl>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="url">Enter URL</label>
|
||||
<div class="controls"><input type="text" id="url" name="url" style="width: 450px;" title="URL" data-content="Typically this is a URL for a partial feed which we transform into a full-text feed. But it can also be a standard web page URL, in which case we'll extract its content and return it in a 1-item feed." /></div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Options</legend>
|
||||
<!--
|
||||
<?php if ($options->extraction_pattern == 'user') { ?>
|
||||
<dl>
|
||||
<dt><label for="what">Extraction pattern:</label></dt>
|
||||
<dd><input type="text" id="what" name="what" value="auto" style="width: 250px;" /></dd>
|
||||
</dl>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="what">Extraction pattern:</label>
|
||||
<div class="controls"><input type="text" id="what" name="what" value="auto" style="width: 250px;" /></div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
-->
|
||||
<?php if (isset($options->api_keys) && !empty($options->api_keys)) { ?>
|
||||
<dl>
|
||||
<dt><label for="key">API key:</label></dt>
|
||||
<dd><input type="text" id="key" name="key" style="width: 250px;" /></dd>
|
||||
</dl>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="key">Access key</label>
|
||||
<div class="controls">
|
||||
<input type="text" id="key" name="key" class="input-medium" <?php if ($options->key_required) echo 'required'; ?> title="Access Key" data-content="<?php echo ($options->key_required) ? 'An access key is required to generate a feed' : 'If you have an access key, enter it here.'; ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<dl>
|
||||
<dt><label for="max">Max items:</label></dt>
|
||||
<dd><select name="max" id="max">
|
||||
<?php for ($i = 1; $i <= $options->max_entries; $i++) {
|
||||
printf("<option value=\"%s\"%s>%s</option>\n", $i, ($i==$options->default_entries) ? ' selected="selected"' : '', $i);
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl>
|
||||
<dt><label for="links">Links:</label></dt>
|
||||
<dd><select name="links">
|
||||
<option value="preserve" selected="selected">preserve</option>
|
||||
<option value="footnotes">add to footnotes</option>
|
||||
<option value="remove">remove</option>
|
||||
</select></label></dd>
|
||||
</dl>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="max">Max items</label>
|
||||
<div class="controls">
|
||||
<?php
|
||||
// echo '<select name="max" id="max" class="input-medium">'
|
||||
// for ($i = 1; $i <= $options->max_entries; $i++) {
|
||||
// printf("<option value=\"%s\"%s>%s</option>\n", $i, ($i==$options->default_entries) ? ' selected="selected"' : '', $i);
|
||||
// }
|
||||
// echo '</select>';
|
||||
if (!empty($options->api_keys)) {
|
||||
$msg = 'Limit: '.$options->max_entries.' (with key: '.$options->max_entries_with_key.')';
|
||||
$msg_more = 'If you need more items, change <tt>max_entries</tt> (and <tt>max_entries_with_key</tt>) in config.';
|
||||
} else {
|
||||
$msg = 'Limit: '.$options->max_entries;
|
||||
$msg_more = 'If you need more items, change <tt>max_entries</tt> in config.';
|
||||
}
|
||||
?>
|
||||
<input type="text" name="max" id="max" class="input-mini" value="<?php echo $options->default_entries; ?>" title="Feed item limit" data-content="Set the maximum number of feed items we should process. The smaller the number, the faster the new feed is produced.<br /><br />If your URL refers to a standard web page, this will have no effect: you will only get 1 item.<br /><br /> <?php echo $msg_more; ?>" />
|
||||
<span class="help-inline" style="color: #888;"><?php echo $msg; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="links">Links</label>
|
||||
<div class="controls">
|
||||
<select name="links" id="links" class="input-medium" title="Link handling" data-content="By default, links within the content are preserved. Change this field if you'd like links removed, or included as footnotes.">
|
||||
<option value="preserve" selected="selected">preserve</option>
|
||||
<option value="footnotes">add to footnotes</option>
|
||||
<option value="remove">remove</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($options->exclude_items_on_fail == 'user') { ?>
|
||||
<dl>
|
||||
<dt><label for="exc">If extraction fails:</label></dt>
|
||||
<dd><select name="exc">
|
||||
<option value="" selected="selected">keep item in feed</option>
|
||||
<option value="1">remove item from feed</option>
|
||||
</select></label></dd>
|
||||
</dl>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="exc">If extraction fails</label>
|
||||
<div class="controls">
|
||||
<select name="exc" id="exc" title="Item handling when extraction fails" data-content="If extraction fails, we can remove the item from the feed or keep it in.<br /><br />Keeping the item will keep the title, URL and original description (if any) found in the feed. In addition, we insert a message before the original description notifying you that extraction failed.">
|
||||
<option value="" selected="selected">keep item in feed</option>
|
||||
<option value="1">remove item from feed</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="json">JSON output</label>
|
||||
<div class="controls">
|
||||
<input type="checkbox" name="format" value="json" id="json" style="margin-top: 7px;" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
<fieldset class="action" style="background: transparent; border: none; margin-bottom: 20px; padding: 0;">
|
||||
<input type="submit" id="sudbmit" name="submit" value="Create Feed" />
|
||||
</fieldset>
|
||||
<div class="form-actions">
|
||||
<input type="submit" id="sudbmit" name="submit" value="Create Feed" class="btn btn-primary" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<hr />
|
||||
|
||||
<h2>For the site owner</h2>
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#start" data-toggle="tab">Getting Started</a></li>
|
||||
<li><a href="#general" data-toggle="tab">General Info</a></li>
|
||||
<li><a href="#updates" data-toggle="tab">Updates</a></li>
|
||||
<li><a href="#license" data-toggle="tab">License</a></li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
|
||||
<!-- GETTING STARTED TAB -->
|
||||
|
||||
<div class="active tab-pane" id="start">
|
||||
|
||||
<h3>Thank you!</h3>
|
||||
|
||||
<p>Thanks for downloading and setting up Full-Text RSS from FiveFilters.org. The software runs on most web hosting environments, but to make sure everything works as it should, please follow the steps below.</p>
|
||||
|
||||
<h3>Quick Start</h3>
|
||||
<ol>
|
||||
<li><a href="ftr_compatibility_test.php">Check server compatibility</a> to make sure this server meets the requirements</li>
|
||||
<li>Enter a feed or article URL in the form above and click 'Create Feed' <a href="http://help.fivefilters.org/customer/portal/articles/223127-suggested-feeds-and-articles" rel="tooltip" title="Need suggestions? We've got a number of feeds and articles you can try" class="label">?</a></li>
|
||||
<li>If the generated full-text feed looks okay, copy the URL from your browser's address bar and use it in your news reader or application</li>
|
||||
<li><strong>That's it!</strong> (Although see below if you'd like to customise further.)</li>
|
||||
</ol>
|
||||
|
||||
<p>Thanks for downloading and setting this up. If you haven't done so already, <a href="ftr_compatibility_test.php">check server compatibility</a>
|
||||
to see if your environment will support this application. Full-Text RSS runs on most shared web hosting environments.</p>
|
||||
<h3>Configure</h3>
|
||||
<p>In addition to the options above, Full-Text RSS can be configured to better suit your needs. Features include:</p>
|
||||
<p>In addition to the options above, Full-Text RSS comes with a configuration file which allows you to control how the application works. <a href="http://help.fivefilters.org/customer/portal/articles/223410-configure">Find out more.</a></p>
|
||||
<p>Features include:</p>
|
||||
<ul>
|
||||
<li>Site patterns for better control over extraction (<a href="site_config/README.txt">more info</a>)</li>
|
||||
<li>Restrict access to a pre-defined set of URLs or block certain URLs</li>
|
||||
<li>Site patterns for better control over extraction (<a href="http://help.fivefilters.org/customer/portal/articles/223153-site-patterns">more info</a>)</li>
|
||||
<li>Restrict access to those with an access key and/or to a pre-defined set of URLs</li>
|
||||
<li>Restrict the maximum number of feed items to be processed</li>
|
||||
<li>JSON output</li>
|
||||
<li>Prepend or append an HTML fragment to each feed item processed</li>
|
||||
<li>Caching</li>
|
||||
</ul>
|
||||
<p>Please refer to the <a href="http://fivefilters.org/content-only/guide/user_guide_2.8.pdf">user guide</a> for more information.</p>
|
||||
<p><?php if (!file_exists('custom_config.php')) { ?>To change the configuration, save a copy of <tt>config.php</tt> as <tt>custom_config.php</tt> and make any changes you like to it.<?php } else { ?>To change the configuration, edit <tt>custom_config.php</tt> and make any changes you like.<?php } ?></p>
|
||||
|
||||
<p>If everything works fine, feel free to modify this page by saving it as <tt>custom_index.php</tt> and change it to whatever you like.</p>
|
||||
<h3>Customise this page</h3>
|
||||
<p>If everything works fine, feel free to modify this page by following the steps below:</p>
|
||||
<ol>
|
||||
<li>Save a copy of <tt>index.php</tt> as <tt>custom_index.php</tt></li>
|
||||
<li>Edit <tt>custom_index.php</tt></li>
|
||||
</ol>
|
||||
<p>Next time you load this page, it will automatically load custom_index.php instead.</p>
|
||||
|
||||
<h3>Sharing is caring</h3>
|
||||
If you plan to offer this service to others through your hosted copy, please keep a download link so users can grab a copy of the code if they
|
||||
want it (you can either offer the download yourself, or link to the download page on fivefilters.org to support us).
|
||||
That's one requirement of the <a href="http://www.gnu.org/licenses/agpl-3.0.html" title="AGPLv3">license</a>.</p>
|
||||
<p>Thanks! :)</p>
|
||||
|
||||
<h3 id="donate">Updates</h3>
|
||||
<p>To see if you're running the latest version, <a href="http://fivefilters.org/content-only/latest_version.php?version=<?php echo urlencode(_FF_FTR_VERSION); ?>">check for updates</a>.</p>
|
||||
<h3 id="support">Support</h3>
|
||||
<p>Check our <a href="http://help.fivefilters.org">help centre</a> if you need help. You can also email us at <a href="mailto:help@fivefilters.org">help@fivefilters.org</a>.</p>
|
||||
|
||||
<h3 id="donate">Support</h3>
|
||||
<p>We have a <a href="https://member.fivefilters.org/f/">public forum</a> which anyone can use to discuss any issues, post questions and find answers (it's free to join and post).</p>
|
||||
<p>We provide a little more information in the section below, but if you need help with anything, you can also email us at <a href="mailto:fivefilters@fivefilters.org">fivefilters@fivefilters.org</a>.</p>
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
<!-- GENERAL TAB -->
|
||||
|
||||
<h2>For everyone</h2>
|
||||
<div id="general" class="tab-pane">
|
||||
|
||||
<h3>About</h3>
|
||||
<p>This is a free software project to help people extract content from web pages. It can extract content from a standard HTML page and return a 1-item feed or it can transform an existing feed into a full-text feed. It is being developed as part of the <a href="http://fivefilters.org">Five Filters</a> project to promote independent, non-corporate media.</p>
|
||||
|
||||
<p>This is a free software project to enable article extraction from web pages. It can extract content from a standard HTML page and return a 1-item feed or it can transform an existing feed into a full-text feed. It is being developed as part of the <a href="http://fivefilters.org">Five Filters</a> project to promote independent, non-corporate media.</p>
|
||||
|
||||
<h3>Bookmarklet</h3>
|
||||
<p>To easily transform partial-feeds you encounter (or convert any content on a page into a 1-item feed), drag the link below to your browser's bookmarks toolbar.
|
||||
<p>Rather than copying and pasting URLs into this form, you can add the bookmarklet on this page to your browser. Simply drag the link below to your browser's bookmarks toolbar.
|
||||
Then whenever you'd like a full-text feed, click the bookmarklet.</p>
|
||||
<p>Drag this:
|
||||
<script type="text/javascript">
|
||||
document.write('<a style="cursor: move;" onclick="alert(\'drag to bookmarks toolbar\'); return false;" href="javascript:location.href=\''+baseUrl+'/makefulltextfeed.php?url=\'+encodeURIComponent(document.location.href);">Full-Text RSS</a>');
|
||||
document.write('<a class="btn info" style="cursor: move;" onclick="alert(\'drag to bookmarks toolbar\'); return false;" href="javascript:location.href=\''+baseUrl+'/makefulltextfeed.php?url=\'+encodeURIComponent(document.location.href);">Full-Text RSS</a>');
|
||||
</script>
|
||||
<p>Note: This uses the default options and does not include your access key (if configured).</p>
|
||||
|
||||
<h3 id="api">API</h3>
|
||||
<h3>Free Software</h3>
|
||||
<p>Note: 'Free' as in 'free speech' (see the <a href="https://www.gnu.org/philosophy/free-sw.html">free software definition</a>)</p>
|
||||
|
||||
<p>If you're the owner of this site and you plan to offer this service to others through your hosted copy, please keep a download link so users can grab a copy of the code if they
|
||||
want it (you can either offer a free download yourself, or link to the purchase option on fivefilters.org to support us).</p>
|
||||
|
||||
<p>For full details, please refer to the <a href="http://www.gnu.org/licenses/agpl-3.0.html" title="AGPLv3">license</a>.</p>
|
||||
|
||||
<p>If you're not the owner of this site (ie. you're not hosting this yourself), you do not have to rely on an external service if you don't want to. You can <a href="http://fivefilters.org/content-only/#download">download your own copy</a> of Full-Text RSS under the AGPL license.</p>
|
||||
|
||||
<h3 id="api">URL Construction</h3>
|
||||
<p>To extract content from a web page or to transform an existing partial feed to full text, pass the URL (<a href="http://meyerweb.com/eric/tools/dencoder/">encoded</a>) in the querystring to the following URL:</p>
|
||||
<ul>
|
||||
<li style="font-family: monospace;"><script type="text/javascript">document.write(baseUrl);</script>/makefulltextfeed.php?url=<strong>[url]</strong></li>
|
||||
</ul>
|
||||
|
||||
<p>All the parameters in the form above can be passed in this way. Examine the URL in the addressbar after you click 'Create Feed' to see the values.</p>
|
||||
<p>All the parameters in the form above can be passed in this way. Examine the URL in the address bar after you click 'Create Feed' to see the values.</p>
|
||||
|
||||
<p>Note: If you're not hosting this yourself, you do not have to rely on an external API if you don't want to — this is a free software (open source)
|
||||
project licensed under the AGPL. You're free to <a href="http://fivefilters.org/content-only/#download">download your own copy</a>.</p>
|
||||
|
||||
<h3>Source Code and Technologies</h3>
|
||||
<p><p>The application uses <a href="http://en.wikipedia.org/wiki/PHP">PHP</a>, <a href="http://www.keyvan.net/2010/08/php-readability/">PHP Readability</a>, <a href="http://simplepie.org/">SimplePie</a>, <a href="http://www.ajaxray.com/blog/2008/03/08/php-universal-feed-generator-supports-rss-10-rss-20-and-atom/">FeedWriter</a>, Humble HTTP Agent. Depending on your configuration, these optional components may also be used: <a href="http://framework.zend.com/manual/en/zend.cache.introduction.html">Zend Cache</a>, <a href="http://framework.zend.com/manual/en/zend.dom.query.html">Zend DOM Query</a>, <a href="http://code.google.com/p/rolling-curl/">Rolling Curl</a> and <a href="http://hg.gsnedders.com/iri/">IRI</a>. Readability is the magic piece of code that tries to identify and extract the content block from any given web page.</p>
|
||||
<h3>Software Components</h3>
|
||||
<p>Full-Text RSS is written in PHP and relies on the following <strong>primary</strong> components:</p>
|
||||
<ul>
|
||||
<li><a href="http://www.keyvan.net/2010/08/php-readability/">PHP Readability</a></li>
|
||||
<li><a href="http://simplepie.org/">SimplePie</a></li>
|
||||
<li>FeedWriter</li>
|
||||
<li>Humble HTTP Agent</li>
|
||||
</ul>
|
||||
<p>Depending on your configuration, these <strong>secondary</strong> components may also be used:</p>
|
||||
<ul>
|
||||
<li><a href="http://framework.zend.com/manual/en/zend.cache.introduction.html">Zend Cache</a></li>
|
||||
<li><a href="http://framework.zend.com/manual/en/zend.dom.query.html">Zend DOM Query</a></li>
|
||||
<li><a href="http://code.google.com/p/rolling-curl/">Rolling Curl</a></li>
|
||||
<li><a href="http://pear.php.net/package/Text_LanguageDetect">Text_LanguageDetect</a> or <a href="https://github.com/lstrojny/php-cld">PHP-CLD</a> if available</li>
|
||||
</ul>
|
||||
|
||||
<h3>System Requirements</h3>
|
||||
|
||||
@ -158,20 +245,40 @@ if (!defined('_FF_FTR_INDEX')) {
|
||||
The code has been tested on Windows and Linux using the Apache web server. If you're a Windows user, you can try it on your own machine using <a href="http://www.wampserver.com/en/index.php">WampServer</a>. It has also been reported as working under IIS, but we have not tested this ourselves.</p>
|
||||
|
||||
<h3 id="download">Download</h3>
|
||||
<p>Download from <a href="http://fivefilters.org/content-only/#download">fivefilters.org</a> - old versions are available in the code repository.</p>
|
||||
<p>Download from <a href="http://fivefilters.org/content-only/#download">fivefilters.org</a> — old versions are available in our <a href="http://code.fivefilters.org">code repository</a>.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<h3>License</h3>
|
||||
<p><a href="http://en.wikipedia.org/wiki/Affero_General_Public_License" style="border-bottom: none;"><img src="images/agplv3.png" alt="AGPL logo" /></a><br />This web application is licensed under the <a href="http://en.wikipedia.org/wiki/Affero_General_Public_License">AGPL version 3</a> — which basically means if you use the code to offer the same or similar service for your users, you are also required to share the code with your users so they can examine the code and run it for themselves. (<a href="http://www.clipperz.com/users/marco/blog/2008/05/30/freedom_and_privacy_cloud_call_action">More on why this is important.</a>)</p>
|
||||
<p>The libraries used by the application are licensed as follows...</p>
|
||||
<!-- UPDATES TAB -->
|
||||
<div id="updates" class="tab-pane">
|
||||
<?php
|
||||
$site_config_version_file = dirname(__FILE__).'/site_config/standard/version.php';
|
||||
if (file_exists($site_config_version_file)) {
|
||||
$site_config_version = include($site_config_version_file);
|
||||
}
|
||||
?>
|
||||
<p>Your version of Full-Text RSS: <strong><?php echo _FF_FTR_VERSION; ?></strong><br />
|
||||
Your version of Site Patterns: <strong><?php echo (isset($site_config_version) ? $site_config_version : 'Unknown'); ?></strong>
|
||||
</p>
|
||||
<p>To see if you have the latest versions, and to update your site patterns, please try our <a href="admin/update.php">update tool</a>.</p>
|
||||
<p>If you've purchased this from FiveFilters.org, you'll receive notification when we release a new version or update the site patterns.</p>
|
||||
</div>
|
||||
|
||||
<!-- LICENSE TAB -->
|
||||
<div id="license" class="tab-pane">
|
||||
<p><a href="http://en.wikipedia.org/wiki/Affero_General_Public_License" style="border-bottom: none;"><img src="images/agplv3.png" alt="AGPL logo" /></a></p>
|
||||
<p>Full-Text RSS is licensed under the <a href="http://en.wikipedia.org/wiki/Affero_General_Public_License">AGPL version 3</a> — which basically means if you use the code to offer the same or similar service for your users, you are also required to share the code with your users so they can examine the code and run it for themselves. (<a href="http://www.clipperz.com/users/marco/blog/2008/05/30/freedom_and_privacy_cloud_call_action">More on why this is important.</a>)</p>
|
||||
<p>The software components used by the application are licensed as follows...</p>
|
||||
<ul>
|
||||
<li>PHP Readability: <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License v2</a></li>
|
||||
<li>SimplePie: <a href="http://en.wikipedia.org/wiki/BSD_license">BSD</a></li>
|
||||
<li>FeedWriter: <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html">GPL v2</a></li>
|
||||
<li>Humble HTTP Agent: <a href="http://en.wikipedia.org/wiki/Affero_General_Public_License">AGPL v3</a></li>
|
||||
<li>Zend: <a href="http://framework.zend.com/license/new-bsd">New BSD</a></li>
|
||||
<li>IRI: <a href="http://en.wikipedia.org/wiki/BSD_license">BSD</a></li>
|
||||
<li>Rolling Curl: <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License v2</a></li>
|
||||
<li>Rolling Curl: <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License v2</a></li>
|
||||
<li>Text_LanguageDetect: <a href="http://en.wikipedia.org/wiki/BSD_license">BSD</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
98
js/bootstrap-popover.js
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
/* ===========================================================
|
||||
* bootstrap-popover.js v2.0.3
|
||||
* http://twitter.github.com/bootstrap/javascript.html#popovers
|
||||
* ===========================================================
|
||||
* Copyright 2012 Twitter, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* =========================================================== */
|
||||
|
||||
|
||||
!function ($) {
|
||||
|
||||
"use strict"; // jshint ;_;
|
||||
|
||||
|
||||
/* POPOVER PUBLIC CLASS DEFINITION
|
||||
* =============================== */
|
||||
|
||||
var Popover = function ( element, options ) {
|
||||
this.init('popover', element, options)
|
||||
}
|
||||
|
||||
|
||||
/* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
|
||||
========================================== */
|
||||
|
||||
Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
|
||||
|
||||
constructor: Popover
|
||||
|
||||
, setContent: function () {
|
||||
var $tip = this.tip()
|
||||
, title = this.getTitle()
|
||||
, content = this.getContent()
|
||||
|
||||
$tip.find('.popover-title')[this.isHTML(title) ? 'html' : 'text'](title)
|
||||
$tip.find('.popover-content > *')[this.isHTML(content) ? 'html' : 'text'](content)
|
||||
|
||||
$tip.removeClass('fade top bottom left right in')
|
||||
}
|
||||
|
||||
, hasContent: function () {
|
||||
return this.getTitle() || this.getContent()
|
||||
}
|
||||
|
||||
, getContent: function () {
|
||||
var content
|
||||
, $e = this.$element
|
||||
, o = this.options
|
||||
|
||||
content = $e.attr('data-content')
|
||||
|| (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
, tip: function () {
|
||||
if (!this.$tip) {
|
||||
this.$tip = $(this.options.template)
|
||||
}
|
||||
return this.$tip
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
/* POPOVER PLUGIN DEFINITION
|
||||
* ======================= */
|
||||
|
||||
$.fn.popover = function (option) {
|
||||
return this.each(function () {
|
||||
var $this = $(this)
|
||||
, data = $this.data('popover')
|
||||
, options = typeof option == 'object' && option
|
||||
if (!data) $this.data('popover', (data = new Popover(this, options)))
|
||||
if (typeof option == 'string') data[option]()
|
||||
})
|
||||
}
|
||||
|
||||
$.fn.popover.Constructor = Popover
|
||||
|
||||
$.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
|
||||
placement: 'right'
|
||||
, content: ''
|
||||
, template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
|
||||
})
|
||||
|
||||
}(window.jQuery);
|
135
js/bootstrap-tab.js
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
/* ========================================================
|
||||
* bootstrap-tab.js v2.0.3
|
||||
* http://twitter.github.com/bootstrap/javascript.html#tabs
|
||||
* ========================================================
|
||||
* Copyright 2012 Twitter, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ======================================================== */
|
||||
|
||||
|
||||
!function ($) {
|
||||
|
||||
"use strict"; // jshint ;_;
|
||||
|
||||
|
||||
/* TAB CLASS DEFINITION
|
||||
* ==================== */
|
||||
|
||||
var Tab = function ( element ) {
|
||||
this.element = $(element)
|
||||
}
|
||||
|
||||
Tab.prototype = {
|
||||
|
||||
constructor: Tab
|
||||
|
||||
, show: function () {
|
||||
var $this = this.element
|
||||
, $ul = $this.closest('ul:not(.dropdown-menu)')
|
||||
, selector = $this.attr('data-target')
|
||||
, previous
|
||||
, $target
|
||||
, e
|
||||
|
||||
if (!selector) {
|
||||
selector = $this.attr('href')
|
||||
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
|
||||
}
|
||||
|
||||
if ( $this.parent('li').hasClass('active') ) return
|
||||
|
||||
previous = $ul.find('.active a').last()[0]
|
||||
|
||||
e = $.Event('show', {
|
||||
relatedTarget: previous
|
||||
})
|
||||
|
||||
$this.trigger(e)
|
||||
|
||||
if (e.isDefaultPrevented()) return
|
||||
|
||||
$target = $(selector)
|
||||
|
||||
this.activate($this.parent('li'), $ul)
|
||||
this.activate($target, $target.parent(), function () {
|
||||
$this.trigger({
|
||||
type: 'shown'
|
||||
, relatedTarget: previous
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
, activate: function ( element, container, callback) {
|
||||
var $active = container.find('> .active')
|
||||
, transition = callback
|
||||
&& $.support.transition
|
||||
&& $active.hasClass('fade')
|
||||
|
||||
function next() {
|
||||
$active
|
||||
.removeClass('active')
|
||||
.find('> .dropdown-menu > .active')
|
||||
.removeClass('active')
|
||||
|
||||
element.addClass('active')
|
||||
|
||||
if (transition) {
|
||||
element[0].offsetWidth // reflow for transition
|
||||
element.addClass('in')
|
||||
} else {
|
||||
element.removeClass('fade')
|
||||
}
|
||||
|
||||
if ( element.parent('.dropdown-menu') ) {
|
||||
element.closest('li.dropdown').addClass('active')
|
||||
}
|
||||
|
||||
callback && callback()
|
||||
}
|
||||
|
||||
transition ?
|
||||
$active.one($.support.transition.end, next) :
|
||||
next()
|
||||
|
||||
$active.removeClass('in')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* TAB PLUGIN DEFINITION
|
||||
* ===================== */
|
||||
|
||||
$.fn.tab = function ( option ) {
|
||||
return this.each(function () {
|
||||
var $this = $(this)
|
||||
, data = $this.data('tab')
|
||||
if (!data) $this.data('tab', (data = new Tab(this)))
|
||||
if (typeof option == 'string') data[option]()
|
||||
})
|
||||
}
|
||||
|
||||
$.fn.tab.Constructor = Tab
|
||||
|
||||
|
||||
/* TAB DATA-API
|
||||
* ============ */
|
||||
|
||||
$(function () {
|
||||
$('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
|
||||
e.preventDefault()
|
||||
$(this).tab('show')
|
||||
})
|
||||
})
|
||||
|
||||
}(window.jQuery);
|
275
js/bootstrap-tooltip.js
vendored
Normal file
@ -0,0 +1,275 @@
|
||||
/* ===========================================================
|
||||
* bootstrap-tooltip.js v2.0.3
|
||||
* http://twitter.github.com/bootstrap/javascript.html#tooltips
|
||||
* Inspired by the original jQuery.tipsy by Jason Frame
|
||||
* ===========================================================
|
||||
* Copyright 2012 Twitter, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ========================================================== */
|
||||
|
||||
|
||||
!function ($) {
|
||||
|
||||
"use strict"; // jshint ;_;
|
||||
|
||||
|
||||
/* TOOLTIP PUBLIC CLASS DEFINITION
|
||||
* =============================== */
|
||||
|
||||
var Tooltip = function (element, options) {
|
||||
this.init('tooltip', element, options)
|
||||
}
|
||||
|
||||
Tooltip.prototype = {
|
||||
|
||||
constructor: Tooltip
|
||||
|
||||
, init: function (type, element, options) {
|
||||
var eventIn
|
||||
, eventOut
|
||||
|
||||
this.type = type
|
||||
this.$element = $(element)
|
||||
this.options = this.getOptions(options)
|
||||
this.enabled = true
|
||||
|
||||
if (this.options.trigger != 'manual') {
|
||||
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
|
||||
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
|
||||
this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this))
|
||||
this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this))
|
||||
}
|
||||
|
||||
this.options.selector ?
|
||||
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
|
||||
this.fixTitle()
|
||||
}
|
||||
|
||||
, getOptions: function (options) {
|
||||
options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data())
|
||||
|
||||
if (options.delay && typeof options.delay == 'number') {
|
||||
options.delay = {
|
||||
show: options.delay
|
||||
, hide: options.delay
|
||||
}
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
, enter: function (e) {
|
||||
var self = $(e.currentTarget)[this.type](this._options).data(this.type)
|
||||
|
||||
if (!self.options.delay || !self.options.delay.show) return self.show()
|
||||
|
||||
clearTimeout(this.timeout)
|
||||
self.hoverState = 'in'
|
||||
this.timeout = setTimeout(function() {
|
||||
if (self.hoverState == 'in') self.show()
|
||||
}, self.options.delay.show)
|
||||
}
|
||||
|
||||
, leave: function (e) {
|
||||
var self = $(e.currentTarget)[this.type](this._options).data(this.type)
|
||||
|
||||
if (!self.options.delay || !self.options.delay.hide) return self.hide()
|
||||
|
||||
clearTimeout(this.timeout)
|
||||
self.hoverState = 'out'
|
||||
this.timeout = setTimeout(function() {
|
||||
if (self.hoverState == 'out') self.hide()
|
||||
}, self.options.delay.hide)
|
||||
}
|
||||
|
||||
, show: function () {
|
||||
var $tip
|
||||
, inside
|
||||
, pos
|
||||
, actualWidth
|
||||
, actualHeight
|
||||
, placement
|
||||
, tp
|
||||
|
||||
if (this.hasContent() && this.enabled) {
|
||||
$tip = this.tip()
|
||||
this.setContent()
|
||||
|
||||
if (this.options.animation) {
|
||||
$tip.addClass('fade')
|
||||
}
|
||||
|
||||
placement = typeof this.options.placement == 'function' ?
|
||||
this.options.placement.call(this, $tip[0], this.$element[0]) :
|
||||
this.options.placement
|
||||
|
||||
inside = /in/.test(placement)
|
||||
|
||||
$tip
|
||||
.remove()
|
||||
.css({ top: 0, left: 0, display: 'block' })
|
||||
.appendTo(inside ? this.$element : document.body)
|
||||
|
||||
pos = this.getPosition(inside)
|
||||
|
||||
actualWidth = $tip[0].offsetWidth
|
||||
actualHeight = $tip[0].offsetHeight
|
||||
|
||||
switch (inside ? placement.split(' ')[1] : placement) {
|
||||
case 'bottom':
|
||||
tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
|
||||
break
|
||||
case 'top':
|
||||
tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
|
||||
break
|
||||
case 'left':
|
||||
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
|
||||
break
|
||||
case 'right':
|
||||
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
|
||||
break
|
||||
}
|
||||
|
||||
$tip
|
||||
.css(tp)
|
||||
.addClass(placement)
|
||||
.addClass('in')
|
||||
}
|
||||
}
|
||||
|
||||
, isHTML: function(text) {
|
||||
// html string detection logic adapted from jQuery
|
||||
return typeof text != 'string'
|
||||
|| ( text.charAt(0) === "<"
|
||||
&& text.charAt( text.length - 1 ) === ">"
|
||||
&& text.length >= 3
|
||||
) || /^(?:[^<]*<[\w\W]+>[^>]*$)/.exec(text)
|
||||
}
|
||||
|
||||
, setContent: function () {
|
||||
var $tip = this.tip()
|
||||
, title = this.getTitle()
|
||||
|
||||
$tip.find('.tooltip-inner')[this.isHTML(title) ? 'html' : 'text'](title)
|
||||
$tip.removeClass('fade in top bottom left right')
|
||||
}
|
||||
|
||||
, hide: function () {
|
||||
var that = this
|
||||
, $tip = this.tip()
|
||||
|
||||
$tip.removeClass('in')
|
||||
|
||||
function removeWithAnimation() {
|
||||
var timeout = setTimeout(function () {
|
||||
$tip.off($.support.transition.end).remove()
|
||||
}, 500)
|
||||
|
||||
$tip.one($.support.transition.end, function () {
|
||||
clearTimeout(timeout)
|
||||
$tip.remove()
|
||||
})
|
||||
}
|
||||
|
||||
$.support.transition && this.$tip.hasClass('fade') ?
|
||||
removeWithAnimation() :
|
||||
$tip.remove()
|
||||
}
|
||||
|
||||
, fixTitle: function () {
|
||||
var $e = this.$element
|
||||
if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
|
||||
$e.attr('data-original-title', $e.attr('title') || '').removeAttr('title')
|
||||
}
|
||||
}
|
||||
|
||||
, hasContent: function () {
|
||||
return this.getTitle()
|
||||
}
|
||||
|
||||
, getPosition: function (inside) {
|
||||
return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), {
|
||||
width: this.$element[0].offsetWidth
|
||||
, height: this.$element[0].offsetHeight
|
||||
})
|
||||
}
|
||||
|
||||
, getTitle: function () {
|
||||
var title
|
||||
, $e = this.$element
|
||||
, o = this.options
|
||||
|
||||
title = $e.attr('data-original-title')
|
||||
|| (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
|
||||
|
||||
return title
|
||||
}
|
||||
|
||||
, tip: function () {
|
||||
return this.$tip = this.$tip || $(this.options.template)
|
||||
}
|
||||
|
||||
, validate: function () {
|
||||
if (!this.$element[0].parentNode) {
|
||||
this.hide()
|
||||
this.$element = null
|
||||
this.options = null
|
||||
}
|
||||
}
|
||||
|
||||
, enable: function () {
|
||||
this.enabled = true
|
||||
}
|
||||
|
||||
, disable: function () {
|
||||
this.enabled = false
|
||||
}
|
||||
|
||||
, toggleEnabled: function () {
|
||||
this.enabled = !this.enabled
|
||||
}
|
||||
|
||||
, toggle: function () {
|
||||
this[this.tip().hasClass('in') ? 'hide' : 'show']()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* TOOLTIP PLUGIN DEFINITION
|
||||
* ========================= */
|
||||
|
||||
$.fn.tooltip = function ( option ) {
|
||||
return this.each(function () {
|
||||
var $this = $(this)
|
||||
, data = $this.data('tooltip')
|
||||
, options = typeof option == 'object' && option
|
||||
if (!data) $this.data('tooltip', (data = new Tooltip(this, options)))
|
||||
if (typeof option == 'string') data[option]()
|
||||
})
|
||||
}
|
||||
|
||||
$.fn.tooltip.Constructor = Tooltip
|
||||
|
||||
$.fn.tooltip.defaults = {
|
||||
animation: true
|
||||
, placement: 'top'
|
||||
, selector: false
|
||||
, template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
|
||||
, trigger: 'hover'
|
||||
, title: ''
|
||||
, delay: 0
|
||||
}
|
||||
|
||||
}(window.jQuery);
|
167
js/jquery-1.4.4.min.js
vendored
@ -1,167 +0,0 @@
|
||||
/*!
|
||||
* jQuery JavaScript Library v1.4.4
|
||||
* http://jquery.com/
|
||||
*
|
||||
* Copyright 2010, John Resig
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
* http://jquery.org/license
|
||||
*
|
||||
* Includes Sizzle.js
|
||||
* http://sizzlejs.com/
|
||||
* Copyright 2010, The Dojo Foundation
|
||||
* Released under the MIT, BSD, and GPL Licenses.
|
||||
*
|
||||
* Date: Thu Nov 11 19:04:53 2010 -0500
|
||||
*/
|
||||
(function(E,B){function ka(a,b,d){if(d===B&&a.nodeType===1){d=a.getAttribute("data-"+b);if(typeof d==="string"){try{d=d==="true"?true:d==="false"?false:d==="null"?null:!c.isNaN(d)?parseFloat(d):Ja.test(d)?c.parseJSON(d):d}catch(e){}c.data(a,b,d)}else d=B}return d}function U(){return false}function ca(){return true}function la(a,b,d){d[0].type=a;return c.event.handle.apply(b,d)}function Ka(a){var b,d,e,f,h,l,k,o,x,r,A,C=[];f=[];h=c.data(this,this.nodeType?"events":"__events__");if(typeof h==="function")h=
|
||||
h.events;if(!(a.liveFired===this||!h||!h.live||a.button&&a.type==="click")){if(a.namespace)A=RegExp("(^|\\.)"+a.namespace.split(".").join("\\.(?:.*\\.)?")+"(\\.|$)");a.liveFired=this;var J=h.live.slice(0);for(k=0;k<J.length;k++){h=J[k];h.origType.replace(X,"")===a.type?f.push(h.selector):J.splice(k--,1)}f=c(a.target).closest(f,a.currentTarget);o=0;for(x=f.length;o<x;o++){r=f[o];for(k=0;k<J.length;k++){h=J[k];if(r.selector===h.selector&&(!A||A.test(h.namespace))){l=r.elem;e=null;if(h.preType==="mouseenter"||
|
||||
h.preType==="mouseleave"){a.type=h.preType;e=c(a.relatedTarget).closest(h.selector)[0]}if(!e||e!==l)C.push({elem:l,handleObj:h,level:r.level})}}}o=0;for(x=C.length;o<x;o++){f=C[o];if(d&&f.level>d)break;a.currentTarget=f.elem;a.data=f.handleObj.data;a.handleObj=f.handleObj;A=f.handleObj.origHandler.apply(f.elem,arguments);if(A===false||a.isPropagationStopped()){d=f.level;if(A===false)b=false;if(a.isImmediatePropagationStopped())break}}return b}}function Y(a,b){return(a&&a!=="*"?a+".":"")+b.replace(La,
|
||||
"`").replace(Ma,"&")}function ma(a,b,d){if(c.isFunction(b))return c.grep(a,function(f,h){return!!b.call(f,h,f)===d});else if(b.nodeType)return c.grep(a,function(f){return f===b===d});else if(typeof b==="string"){var e=c.grep(a,function(f){return f.nodeType===1});if(Na.test(b))return c.filter(b,e,!d);else b=c.filter(b,e)}return c.grep(a,function(f){return c.inArray(f,b)>=0===d})}function na(a,b){var d=0;b.each(function(){if(this.nodeName===(a[d]&&a[d].nodeName)){var e=c.data(a[d++]),f=c.data(this,
|
||||
e);if(e=e&&e.events){delete f.handle;f.events={};for(var h in e)for(var l in e[h])c.event.add(this,h,e[h][l],e[h][l].data)}}})}function Oa(a,b){b.src?c.ajax({url:b.src,async:false,dataType:"script"}):c.globalEval(b.text||b.textContent||b.innerHTML||"");b.parentNode&&b.parentNode.removeChild(b)}function oa(a,b,d){var e=b==="width"?a.offsetWidth:a.offsetHeight;if(d==="border")return e;c.each(b==="width"?Pa:Qa,function(){d||(e-=parseFloat(c.css(a,"padding"+this))||0);if(d==="margin")e+=parseFloat(c.css(a,
|
||||
"margin"+this))||0;else e-=parseFloat(c.css(a,"border"+this+"Width"))||0});return e}function da(a,b,d,e){if(c.isArray(b)&&b.length)c.each(b,function(f,h){d||Ra.test(a)?e(a,h):da(a+"["+(typeof h==="object"||c.isArray(h)?f:"")+"]",h,d,e)});else if(!d&&b!=null&&typeof b==="object")c.isEmptyObject(b)?e(a,""):c.each(b,function(f,h){da(a+"["+f+"]",h,d,e)});else e(a,b)}function S(a,b){var d={};c.each(pa.concat.apply([],pa.slice(0,b)),function(){d[this]=a});return d}function qa(a){if(!ea[a]){var b=c("<"+
|
||||
a+">").appendTo("body"),d=b.css("display");b.remove();if(d==="none"||d==="")d="block";ea[a]=d}return ea[a]}function fa(a){return c.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:false}var t=E.document,c=function(){function a(){if(!b.isReady){try{t.documentElement.doScroll("left")}catch(j){setTimeout(a,1);return}b.ready()}}var b=function(j,s){return new b.fn.init(j,s)},d=E.jQuery,e=E.$,f,h=/^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,l=/\S/,k=/^\s+/,o=/\s+$/,x=/\W/,r=/\d/,A=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,
|
||||
C=/^[\],:{}\s]*$/,J=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,w=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,I=/(?:^|:|,)(?:\s*\[)+/g,L=/(webkit)[ \/]([\w.]+)/,g=/(opera)(?:.*version)?[ \/]([\w.]+)/,i=/(msie) ([\w.]+)/,n=/(mozilla)(?:.*? rv:([\w.]+))?/,m=navigator.userAgent,p=false,q=[],u,y=Object.prototype.toString,F=Object.prototype.hasOwnProperty,M=Array.prototype.push,N=Array.prototype.slice,O=String.prototype.trim,D=Array.prototype.indexOf,R={};b.fn=b.prototype={init:function(j,
|
||||
s){var v,z,H;if(!j)return this;if(j.nodeType){this.context=this[0]=j;this.length=1;return this}if(j==="body"&&!s&&t.body){this.context=t;this[0]=t.body;this.selector="body";this.length=1;return this}if(typeof j==="string")if((v=h.exec(j))&&(v[1]||!s))if(v[1]){H=s?s.ownerDocument||s:t;if(z=A.exec(j))if(b.isPlainObject(s)){j=[t.createElement(z[1])];b.fn.attr.call(j,s,true)}else j=[H.createElement(z[1])];else{z=b.buildFragment([v[1]],[H]);j=(z.cacheable?z.fragment.cloneNode(true):z.fragment).childNodes}return b.merge(this,
|
||||
j)}else{if((z=t.getElementById(v[2]))&&z.parentNode){if(z.id!==v[2])return f.find(j);this.length=1;this[0]=z}this.context=t;this.selector=j;return this}else if(!s&&!x.test(j)){this.selector=j;this.context=t;j=t.getElementsByTagName(j);return b.merge(this,j)}else return!s||s.jquery?(s||f).find(j):b(s).find(j);else if(b.isFunction(j))return f.ready(j);if(j.selector!==B){this.selector=j.selector;this.context=j.context}return b.makeArray(j,this)},selector:"",jquery:"1.4.4",length:0,size:function(){return this.length},
|
||||
toArray:function(){return N.call(this,0)},get:function(j){return j==null?this.toArray():j<0?this.slice(j)[0]:this[j]},pushStack:function(j,s,v){var z=b();b.isArray(j)?M.apply(z,j):b.merge(z,j);z.prevObject=this;z.context=this.context;if(s==="find")z.selector=this.selector+(this.selector?" ":"")+v;else if(s)z.selector=this.selector+"."+s+"("+v+")";return z},each:function(j,s){return b.each(this,j,s)},ready:function(j){b.bindReady();if(b.isReady)j.call(t,b);else q&&q.push(j);return this},eq:function(j){return j===
|
||||
-1?this.slice(j):this.slice(j,+j+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(N.apply(this,arguments),"slice",N.call(arguments).join(","))},map:function(j){return this.pushStack(b.map(this,function(s,v){return j.call(s,v,s)}))},end:function(){return this.prevObject||b(null)},push:M,sort:[].sort,splice:[].splice};b.fn.init.prototype=b.fn;b.extend=b.fn.extend=function(){var j,s,v,z,H,G=arguments[0]||{},K=1,Q=arguments.length,ga=false;
|
||||
if(typeof G==="boolean"){ga=G;G=arguments[1]||{};K=2}if(typeof G!=="object"&&!b.isFunction(G))G={};if(Q===K){G=this;--K}for(;K<Q;K++)if((j=arguments[K])!=null)for(s in j){v=G[s];z=j[s];if(G!==z)if(ga&&z&&(b.isPlainObject(z)||(H=b.isArray(z)))){if(H){H=false;v=v&&b.isArray(v)?v:[]}else v=v&&b.isPlainObject(v)?v:{};G[s]=b.extend(ga,v,z)}else if(z!==B)G[s]=z}return G};b.extend({noConflict:function(j){E.$=e;if(j)E.jQuery=d;return b},isReady:false,readyWait:1,ready:function(j){j===true&&b.readyWait--;
|
||||
if(!b.readyWait||j!==true&&!b.isReady){if(!t.body)return setTimeout(b.ready,1);b.isReady=true;if(!(j!==true&&--b.readyWait>0))if(q){var s=0,v=q;for(q=null;j=v[s++];)j.call(t,b);b.fn.trigger&&b(t).trigger("ready").unbind("ready")}}},bindReady:function(){if(!p){p=true;if(t.readyState==="complete")return setTimeout(b.ready,1);if(t.addEventListener){t.addEventListener("DOMContentLoaded",u,false);E.addEventListener("load",b.ready,false)}else if(t.attachEvent){t.attachEvent("onreadystatechange",u);E.attachEvent("onload",
|
||||
b.ready);var j=false;try{j=E.frameElement==null}catch(s){}t.documentElement.doScroll&&j&&a()}}},isFunction:function(j){return b.type(j)==="function"},isArray:Array.isArray||function(j){return b.type(j)==="array"},isWindow:function(j){return j&&typeof j==="object"&&"setInterval"in j},isNaN:function(j){return j==null||!r.test(j)||isNaN(j)},type:function(j){return j==null?String(j):R[y.call(j)]||"object"},isPlainObject:function(j){if(!j||b.type(j)!=="object"||j.nodeType||b.isWindow(j))return false;if(j.constructor&&
|
||||
!F.call(j,"constructor")&&!F.call(j.constructor.prototype,"isPrototypeOf"))return false;for(var s in j);return s===B||F.call(j,s)},isEmptyObject:function(j){for(var s in j)return false;return true},error:function(j){throw j;},parseJSON:function(j){if(typeof j!=="string"||!j)return null;j=b.trim(j);if(C.test(j.replace(J,"@").replace(w,"]").replace(I,"")))return E.JSON&&E.JSON.parse?E.JSON.parse(j):(new Function("return "+j))();else b.error("Invalid JSON: "+j)},noop:function(){},globalEval:function(j){if(j&&
|
||||
l.test(j)){var s=t.getElementsByTagName("head")[0]||t.documentElement,v=t.createElement("script");v.type="text/javascript";if(b.support.scriptEval)v.appendChild(t.createTextNode(j));else v.text=j;s.insertBefore(v,s.firstChild);s.removeChild(v)}},nodeName:function(j,s){return j.nodeName&&j.nodeName.toUpperCase()===s.toUpperCase()},each:function(j,s,v){var z,H=0,G=j.length,K=G===B||b.isFunction(j);if(v)if(K)for(z in j){if(s.apply(j[z],v)===false)break}else for(;H<G;){if(s.apply(j[H++],v)===false)break}else if(K)for(z in j){if(s.call(j[z],
|
||||
z,j[z])===false)break}else for(v=j[0];H<G&&s.call(v,H,v)!==false;v=j[++H]);return j},trim:O?function(j){return j==null?"":O.call(j)}:function(j){return j==null?"":j.toString().replace(k,"").replace(o,"")},makeArray:function(j,s){var v=s||[];if(j!=null){var z=b.type(j);j.length==null||z==="string"||z==="function"||z==="regexp"||b.isWindow(j)?M.call(v,j):b.merge(v,j)}return v},inArray:function(j,s){if(s.indexOf)return s.indexOf(j);for(var v=0,z=s.length;v<z;v++)if(s[v]===j)return v;return-1},merge:function(j,
|
||||
s){var v=j.length,z=0;if(typeof s.length==="number")for(var H=s.length;z<H;z++)j[v++]=s[z];else for(;s[z]!==B;)j[v++]=s[z++];j.length=v;return j},grep:function(j,s,v){var z=[],H;v=!!v;for(var G=0,K=j.length;G<K;G++){H=!!s(j[G],G);v!==H&&z.push(j[G])}return z},map:function(j,s,v){for(var z=[],H,G=0,K=j.length;G<K;G++){H=s(j[G],G,v);if(H!=null)z[z.length]=H}return z.concat.apply([],z)},guid:1,proxy:function(j,s,v){if(arguments.length===2)if(typeof s==="string"){v=j;j=v[s];s=B}else if(s&&!b.isFunction(s)){v=
|
||||
s;s=B}if(!s&&j)s=function(){return j.apply(v||this,arguments)};if(j)s.guid=j.guid=j.guid||s.guid||b.guid++;return s},access:function(j,s,v,z,H,G){var K=j.length;if(typeof s==="object"){for(var Q in s)b.access(j,Q,s[Q],z,H,v);return j}if(v!==B){z=!G&&z&&b.isFunction(v);for(Q=0;Q<K;Q++)H(j[Q],s,z?v.call(j[Q],Q,H(j[Q],s)):v,G);return j}return K?H(j[0],s):B},now:function(){return(new Date).getTime()},uaMatch:function(j){j=j.toLowerCase();j=L.exec(j)||g.exec(j)||i.exec(j)||j.indexOf("compatible")<0&&n.exec(j)||
|
||||
[];return{browser:j[1]||"",version:j[2]||"0"}},browser:{}});b.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(j,s){R["[object "+s+"]"]=s.toLowerCase()});m=b.uaMatch(m);if(m.browser){b.browser[m.browser]=true;b.browser.version=m.version}if(b.browser.webkit)b.browser.safari=true;if(D)b.inArray=function(j,s){return D.call(s,j)};if(!/\s/.test("\u00a0")){k=/^[\s\xA0]+/;o=/[\s\xA0]+$/}f=b(t);if(t.addEventListener)u=function(){t.removeEventListener("DOMContentLoaded",u,
|
||||
false);b.ready()};else if(t.attachEvent)u=function(){if(t.readyState==="complete"){t.detachEvent("onreadystatechange",u);b.ready()}};return E.jQuery=E.$=b}();(function(){c.support={};var a=t.documentElement,b=t.createElement("script"),d=t.createElement("div"),e="script"+c.now();d.style.display="none";d.innerHTML=" <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";var f=d.getElementsByTagName("*"),h=d.getElementsByTagName("a")[0],l=t.createElement("select"),
|
||||
k=l.appendChild(t.createElement("option"));if(!(!f||!f.length||!h)){c.support={leadingWhitespace:d.firstChild.nodeType===3,tbody:!d.getElementsByTagName("tbody").length,htmlSerialize:!!d.getElementsByTagName("link").length,style:/red/.test(h.getAttribute("style")),hrefNormalized:h.getAttribute("href")==="/a",opacity:/^0.55$/.test(h.style.opacity),cssFloat:!!h.style.cssFloat,checkOn:d.getElementsByTagName("input")[0].value==="on",optSelected:k.selected,deleteExpando:true,optDisabled:false,checkClone:false,
|
||||
scriptEval:false,noCloneEvent:true,boxModel:null,inlineBlockNeedsLayout:false,shrinkWrapBlocks:false,reliableHiddenOffsets:true};l.disabled=true;c.support.optDisabled=!k.disabled;b.type="text/javascript";try{b.appendChild(t.createTextNode("window."+e+"=1;"))}catch(o){}a.insertBefore(b,a.firstChild);if(E[e]){c.support.scriptEval=true;delete E[e]}try{delete b.test}catch(x){c.support.deleteExpando=false}a.removeChild(b);if(d.attachEvent&&d.fireEvent){d.attachEvent("onclick",function r(){c.support.noCloneEvent=
|
||||
false;d.detachEvent("onclick",r)});d.cloneNode(true).fireEvent("onclick")}d=t.createElement("div");d.innerHTML="<input type='radio' name='radiotest' checked='checked'/>";a=t.createDocumentFragment();a.appendChild(d.firstChild);c.support.checkClone=a.cloneNode(true).cloneNode(true).lastChild.checked;c(function(){var r=t.createElement("div");r.style.width=r.style.paddingLeft="1px";t.body.appendChild(r);c.boxModel=c.support.boxModel=r.offsetWidth===2;if("zoom"in r.style){r.style.display="inline";r.style.zoom=
|
||||
1;c.support.inlineBlockNeedsLayout=r.offsetWidth===2;r.style.display="";r.innerHTML="<div style='width:4px;'></div>";c.support.shrinkWrapBlocks=r.offsetWidth!==2}r.innerHTML="<table><tr><td style='padding:0;display:none'></td><td>t</td></tr></table>";var A=r.getElementsByTagName("td");c.support.reliableHiddenOffsets=A[0].offsetHeight===0;A[0].style.display="";A[1].style.display="none";c.support.reliableHiddenOffsets=c.support.reliableHiddenOffsets&&A[0].offsetHeight===0;r.innerHTML="";t.body.removeChild(r).style.display=
|
||||
"none"});a=function(r){var A=t.createElement("div");r="on"+r;var C=r in A;if(!C){A.setAttribute(r,"return;");C=typeof A[r]==="function"}return C};c.support.submitBubbles=a("submit");c.support.changeBubbles=a("change");a=b=d=f=h=null}})();var ra={},Ja=/^(?:\{.*\}|\[.*\])$/;c.extend({cache:{},uuid:0,expando:"jQuery"+c.now(),noData:{embed:true,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:true},data:function(a,b,d){if(c.acceptData(a)){a=a==E?ra:a;var e=a.nodeType,f=e?a[c.expando]:null,h=
|
||||
c.cache;if(!(e&&!f&&typeof b==="string"&&d===B)){if(e)f||(a[c.expando]=f=++c.uuid);else h=a;if(typeof b==="object")if(e)h[f]=c.extend(h[f],b);else c.extend(h,b);else if(e&&!h[f])h[f]={};a=e?h[f]:h;if(d!==B)a[b]=d;return typeof b==="string"?a[b]:a}}},removeData:function(a,b){if(c.acceptData(a)){a=a==E?ra:a;var d=a.nodeType,e=d?a[c.expando]:a,f=c.cache,h=d?f[e]:e;if(b){if(h){delete h[b];d&&c.isEmptyObject(h)&&c.removeData(a)}}else if(d&&c.support.deleteExpando)delete a[c.expando];else if(a.removeAttribute)a.removeAttribute(c.expando);
|
||||
else if(d)delete f[e];else for(var l in a)delete a[l]}},acceptData:function(a){if(a.nodeName){var b=c.noData[a.nodeName.toLowerCase()];if(b)return!(b===true||a.getAttribute("classid")!==b)}return true}});c.fn.extend({data:function(a,b){var d=null;if(typeof a==="undefined"){if(this.length){var e=this[0].attributes,f;d=c.data(this[0]);for(var h=0,l=e.length;h<l;h++){f=e[h].name;if(f.indexOf("data-")===0){f=f.substr(5);ka(this[0],f,d[f])}}}return d}else if(typeof a==="object")return this.each(function(){c.data(this,
|
||||
a)});var k=a.split(".");k[1]=k[1]?"."+k[1]:"";if(b===B){d=this.triggerHandler("getData"+k[1]+"!",[k[0]]);if(d===B&&this.length){d=c.data(this[0],a);d=ka(this[0],a,d)}return d===B&&k[1]?this.data(k[0]):d}else return this.each(function(){var o=c(this),x=[k[0],b];o.triggerHandler("setData"+k[1]+"!",x);c.data(this,a,b);o.triggerHandler("changeData"+k[1]+"!",x)})},removeData:function(a){return this.each(function(){c.removeData(this,a)})}});c.extend({queue:function(a,b,d){if(a){b=(b||"fx")+"queue";var e=
|
||||
c.data(a,b);if(!d)return e||[];if(!e||c.isArray(d))e=c.data(a,b,c.makeArray(d));else e.push(d);return e}},dequeue:function(a,b){b=b||"fx";var d=c.queue(a,b),e=d.shift();if(e==="inprogress")e=d.shift();if(e){b==="fx"&&d.unshift("inprogress");e.call(a,function(){c.dequeue(a,b)})}}});c.fn.extend({queue:function(a,b){if(typeof a!=="string"){b=a;a="fx"}if(b===B)return c.queue(this[0],a);return this.each(function(){var d=c.queue(this,a,b);a==="fx"&&d[0]!=="inprogress"&&c.dequeue(this,a)})},dequeue:function(a){return this.each(function(){c.dequeue(this,
|
||||
a)})},delay:function(a,b){a=c.fx?c.fx.speeds[a]||a:a;b=b||"fx";return this.queue(b,function(){var d=this;setTimeout(function(){c.dequeue(d,b)},a)})},clearQueue:function(a){return this.queue(a||"fx",[])}});var sa=/[\n\t]/g,ha=/\s+/,Sa=/\r/g,Ta=/^(?:href|src|style)$/,Ua=/^(?:button|input)$/i,Va=/^(?:button|input|object|select|textarea)$/i,Wa=/^a(?:rea)?$/i,ta=/^(?:radio|checkbox)$/i;c.props={"for":"htmlFor","class":"className",readonly:"readOnly",maxlength:"maxLength",cellspacing:"cellSpacing",rowspan:"rowSpan",
|
||||
colspan:"colSpan",tabindex:"tabIndex",usemap:"useMap",frameborder:"frameBorder"};c.fn.extend({attr:function(a,b){return c.access(this,a,b,true,c.attr)},removeAttr:function(a){return this.each(function(){c.attr(this,a,"");this.nodeType===1&&this.removeAttribute(a)})},addClass:function(a){if(c.isFunction(a))return this.each(function(x){var r=c(this);r.addClass(a.call(this,x,r.attr("class")))});if(a&&typeof a==="string")for(var b=(a||"").split(ha),d=0,e=this.length;d<e;d++){var f=this[d];if(f.nodeType===
|
||||
1)if(f.className){for(var h=" "+f.className+" ",l=f.className,k=0,o=b.length;k<o;k++)if(h.indexOf(" "+b[k]+" ")<0)l+=" "+b[k];f.className=c.trim(l)}else f.className=a}return this},removeClass:function(a){if(c.isFunction(a))return this.each(function(o){var x=c(this);x.removeClass(a.call(this,o,x.attr("class")))});if(a&&typeof a==="string"||a===B)for(var b=(a||"").split(ha),d=0,e=this.length;d<e;d++){var f=this[d];if(f.nodeType===1&&f.className)if(a){for(var h=(" "+f.className+" ").replace(sa," "),
|
||||
l=0,k=b.length;l<k;l++)h=h.replace(" "+b[l]+" "," ");f.className=c.trim(h)}else f.className=""}return this},toggleClass:function(a,b){var d=typeof a,e=typeof b==="boolean";if(c.isFunction(a))return this.each(function(f){var h=c(this);h.toggleClass(a.call(this,f,h.attr("class"),b),b)});return this.each(function(){if(d==="string")for(var f,h=0,l=c(this),k=b,o=a.split(ha);f=o[h++];){k=e?k:!l.hasClass(f);l[k?"addClass":"removeClass"](f)}else if(d==="undefined"||d==="boolean"){this.className&&c.data(this,
|
||||
"__className__",this.className);this.className=this.className||a===false?"":c.data(this,"__className__")||""}})},hasClass:function(a){a=" "+a+" ";for(var b=0,d=this.length;b<d;b++)if((" "+this[b].className+" ").replace(sa," ").indexOf(a)>-1)return true;return false},val:function(a){if(!arguments.length){var b=this[0];if(b){if(c.nodeName(b,"option")){var d=b.attributes.value;return!d||d.specified?b.value:b.text}if(c.nodeName(b,"select")){var e=b.selectedIndex;d=[];var f=b.options;b=b.type==="select-one";
|
||||
if(e<0)return null;var h=b?e:0;for(e=b?e+1:f.length;h<e;h++){var l=f[h];if(l.selected&&(c.support.optDisabled?!l.disabled:l.getAttribute("disabled")===null)&&(!l.parentNode.disabled||!c.nodeName(l.parentNode,"optgroup"))){a=c(l).val();if(b)return a;d.push(a)}}return d}if(ta.test(b.type)&&!c.support.checkOn)return b.getAttribute("value")===null?"on":b.value;return(b.value||"").replace(Sa,"")}return B}var k=c.isFunction(a);return this.each(function(o){var x=c(this),r=a;if(this.nodeType===1){if(k)r=
|
||||
a.call(this,o,x.val());if(r==null)r="";else if(typeof r==="number")r+="";else if(c.isArray(r))r=c.map(r,function(C){return C==null?"":C+""});if(c.isArray(r)&&ta.test(this.type))this.checked=c.inArray(x.val(),r)>=0;else if(c.nodeName(this,"select")){var A=c.makeArray(r);c("option",this).each(function(){this.selected=c.inArray(c(this).val(),A)>=0});if(!A.length)this.selectedIndex=-1}else this.value=r}})}});c.extend({attrFn:{val:true,css:true,html:true,text:true,data:true,width:true,height:true,offset:true},
|
||||
attr:function(a,b,d,e){if(!a||a.nodeType===3||a.nodeType===8)return B;if(e&&b in c.attrFn)return c(a)[b](d);e=a.nodeType!==1||!c.isXMLDoc(a);var f=d!==B;b=e&&c.props[b]||b;var h=Ta.test(b);if((b in a||a[b]!==B)&&e&&!h){if(f){b==="type"&&Ua.test(a.nodeName)&&a.parentNode&&c.error("type property can't be changed");if(d===null)a.nodeType===1&&a.removeAttribute(b);else a[b]=d}if(c.nodeName(a,"form")&&a.getAttributeNode(b))return a.getAttributeNode(b).nodeValue;if(b==="tabIndex")return(b=a.getAttributeNode("tabIndex"))&&
|
||||
b.specified?b.value:Va.test(a.nodeName)||Wa.test(a.nodeName)&&a.href?0:B;return a[b]}if(!c.support.style&&e&&b==="style"){if(f)a.style.cssText=""+d;return a.style.cssText}f&&a.setAttribute(b,""+d);if(!a.attributes[b]&&a.hasAttribute&&!a.hasAttribute(b))return B;a=!c.support.hrefNormalized&&e&&h?a.getAttribute(b,2):a.getAttribute(b);return a===null?B:a}});var X=/\.(.*)$/,ia=/^(?:textarea|input|select)$/i,La=/\./g,Ma=/ /g,Xa=/[^\w\s.|`]/g,Ya=function(a){return a.replace(Xa,"\\$&")},ua={focusin:0,focusout:0};
|
||||
c.event={add:function(a,b,d,e){if(!(a.nodeType===3||a.nodeType===8)){if(c.isWindow(a)&&a!==E&&!a.frameElement)a=E;if(d===false)d=U;else if(!d)return;var f,h;if(d.handler){f=d;d=f.handler}if(!d.guid)d.guid=c.guid++;if(h=c.data(a)){var l=a.nodeType?"events":"__events__",k=h[l],o=h.handle;if(typeof k==="function"){o=k.handle;k=k.events}else if(!k){a.nodeType||(h[l]=h=function(){});h.events=k={}}if(!o)h.handle=o=function(){return typeof c!=="undefined"&&!c.event.triggered?c.event.handle.apply(o.elem,
|
||||
arguments):B};o.elem=a;b=b.split(" ");for(var x=0,r;l=b[x++];){h=f?c.extend({},f):{handler:d,data:e};if(l.indexOf(".")>-1){r=l.split(".");l=r.shift();h.namespace=r.slice(0).sort().join(".")}else{r=[];h.namespace=""}h.type=l;if(!h.guid)h.guid=d.guid;var A=k[l],C=c.event.special[l]||{};if(!A){A=k[l]=[];if(!C.setup||C.setup.call(a,e,r,o)===false)if(a.addEventListener)a.addEventListener(l,o,false);else a.attachEvent&&a.attachEvent("on"+l,o)}if(C.add){C.add.call(a,h);if(!h.handler.guid)h.handler.guid=
|
||||
d.guid}A.push(h);c.event.global[l]=true}a=null}}},global:{},remove:function(a,b,d,e){if(!(a.nodeType===3||a.nodeType===8)){if(d===false)d=U;var f,h,l=0,k,o,x,r,A,C,J=a.nodeType?"events":"__events__",w=c.data(a),I=w&&w[J];if(w&&I){if(typeof I==="function"){w=I;I=I.events}if(b&&b.type){d=b.handler;b=b.type}if(!b||typeof b==="string"&&b.charAt(0)==="."){b=b||"";for(f in I)c.event.remove(a,f+b)}else{for(b=b.split(" ");f=b[l++];){r=f;k=f.indexOf(".")<0;o=[];if(!k){o=f.split(".");f=o.shift();x=RegExp("(^|\\.)"+
|
||||
c.map(o.slice(0).sort(),Ya).join("\\.(?:.*\\.)?")+"(\\.|$)")}if(A=I[f])if(d){r=c.event.special[f]||{};for(h=e||0;h<A.length;h++){C=A[h];if(d.guid===C.guid){if(k||x.test(C.namespace)){e==null&&A.splice(h--,1);r.remove&&r.remove.call(a,C)}if(e!=null)break}}if(A.length===0||e!=null&&A.length===1){if(!r.teardown||r.teardown.call(a,o)===false)c.removeEvent(a,f,w.handle);delete I[f]}}else for(h=0;h<A.length;h++){C=A[h];if(k||x.test(C.namespace)){c.event.remove(a,r,C.handler,h);A.splice(h--,1)}}}if(c.isEmptyObject(I)){if(b=
|
||||
w.handle)b.elem=null;delete w.events;delete w.handle;if(typeof w==="function")c.removeData(a,J);else c.isEmptyObject(w)&&c.removeData(a)}}}}},trigger:function(a,b,d,e){var f=a.type||a;if(!e){a=typeof a==="object"?a[c.expando]?a:c.extend(c.Event(f),a):c.Event(f);if(f.indexOf("!")>=0){a.type=f=f.slice(0,-1);a.exclusive=true}if(!d){a.stopPropagation();c.event.global[f]&&c.each(c.cache,function(){this.events&&this.events[f]&&c.event.trigger(a,b,this.handle.elem)})}if(!d||d.nodeType===3||d.nodeType===
|
||||
8)return B;a.result=B;a.target=d;b=c.makeArray(b);b.unshift(a)}a.currentTarget=d;(e=d.nodeType?c.data(d,"handle"):(c.data(d,"__events__")||{}).handle)&&e.apply(d,b);e=d.parentNode||d.ownerDocument;try{if(!(d&&d.nodeName&&c.noData[d.nodeName.toLowerCase()]))if(d["on"+f]&&d["on"+f].apply(d,b)===false){a.result=false;a.preventDefault()}}catch(h){}if(!a.isPropagationStopped()&&e)c.event.trigger(a,b,e,true);else if(!a.isDefaultPrevented()){var l;e=a.target;var k=f.replace(X,""),o=c.nodeName(e,"a")&&k===
|
||||
"click",x=c.event.special[k]||{};if((!x._default||x._default.call(d,a)===false)&&!o&&!(e&&e.nodeName&&c.noData[e.nodeName.toLowerCase()])){try{if(e[k]){if(l=e["on"+k])e["on"+k]=null;c.event.triggered=true;e[k]()}}catch(r){}if(l)e["on"+k]=l;c.event.triggered=false}}},handle:function(a){var b,d,e,f;d=[];var h=c.makeArray(arguments);a=h[0]=c.event.fix(a||E.event);a.currentTarget=this;b=a.type.indexOf(".")<0&&!a.exclusive;if(!b){e=a.type.split(".");a.type=e.shift();d=e.slice(0).sort();e=RegExp("(^|\\.)"+
|
||||
d.join("\\.(?:.*\\.)?")+"(\\.|$)")}a.namespace=a.namespace||d.join(".");f=c.data(this,this.nodeType?"events":"__events__");if(typeof f==="function")f=f.events;d=(f||{})[a.type];if(f&&d){d=d.slice(0);f=0;for(var l=d.length;f<l;f++){var k=d[f];if(b||e.test(k.namespace)){a.handler=k.handler;a.data=k.data;a.handleObj=k;k=k.handler.apply(this,h);if(k!==B){a.result=k;if(k===false){a.preventDefault();a.stopPropagation()}}if(a.isImmediatePropagationStopped())break}}}return a.result},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),
|
||||
fix:function(a){if(a[c.expando])return a;var b=a;a=c.Event(b);for(var d=this.props.length,e;d;){e=this.props[--d];a[e]=b[e]}if(!a.target)a.target=a.srcElement||t;if(a.target.nodeType===3)a.target=a.target.parentNode;if(!a.relatedTarget&&a.fromElement)a.relatedTarget=a.fromElement===a.target?a.toElement:a.fromElement;if(a.pageX==null&&a.clientX!=null){b=t.documentElement;d=t.body;a.pageX=a.clientX+(b&&b.scrollLeft||d&&d.scrollLeft||0)-(b&&b.clientLeft||d&&d.clientLeft||0);a.pageY=a.clientY+(b&&b.scrollTop||
|
||||
d&&d.scrollTop||0)-(b&&b.clientTop||d&&d.clientTop||0)}if(a.which==null&&(a.charCode!=null||a.keyCode!=null))a.which=a.charCode!=null?a.charCode:a.keyCode;if(!a.metaKey&&a.ctrlKey)a.metaKey=a.ctrlKey;if(!a.which&&a.button!==B)a.which=a.button&1?1:a.button&2?3:a.button&4?2:0;return a},guid:1E8,proxy:c.proxy,special:{ready:{setup:c.bindReady,teardown:c.noop},live:{add:function(a){c.event.add(this,Y(a.origType,a.selector),c.extend({},a,{handler:Ka,guid:a.handler.guid}))},remove:function(a){c.event.remove(this,
|
||||
Y(a.origType,a.selector),a)}},beforeunload:{setup:function(a,b,d){if(c.isWindow(this))this.onbeforeunload=d},teardown:function(a,b){if(this.onbeforeunload===b)this.onbeforeunload=null}}}};c.removeEvent=t.removeEventListener?function(a,b,d){a.removeEventListener&&a.removeEventListener(b,d,false)}:function(a,b,d){a.detachEvent&&a.detachEvent("on"+b,d)};c.Event=function(a){if(!this.preventDefault)return new c.Event(a);if(a&&a.type){this.originalEvent=a;this.type=a.type}else this.type=a;this.timeStamp=
|
||||
c.now();this[c.expando]=true};c.Event.prototype={preventDefault:function(){this.isDefaultPrevented=ca;var a=this.originalEvent;if(a)if(a.preventDefault)a.preventDefault();else a.returnValue=false},stopPropagation:function(){this.isPropagationStopped=ca;var a=this.originalEvent;if(a){a.stopPropagation&&a.stopPropagation();a.cancelBubble=true}},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=ca;this.stopPropagation()},isDefaultPrevented:U,isPropagationStopped:U,isImmediatePropagationStopped:U};
|
||||
var va=function(a){var b=a.relatedTarget;try{for(;b&&b!==this;)b=b.parentNode;if(b!==this){a.type=a.data;c.event.handle.apply(this,arguments)}}catch(d){}},wa=function(a){a.type=a.data;c.event.handle.apply(this,arguments)};c.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){c.event.special[a]={setup:function(d){c.event.add(this,b,d&&d.selector?wa:va,a)},teardown:function(d){c.event.remove(this,b,d&&d.selector?wa:va)}}});if(!c.support.submitBubbles)c.event.special.submit={setup:function(){if(this.nodeName.toLowerCase()!==
|
||||
"form"){c.event.add(this,"click.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="submit"||d==="image")&&c(b).closest("form").length){a.liveFired=B;return la("submit",this,arguments)}});c.event.add(this,"keypress.specialSubmit",function(a){var b=a.target,d=b.type;if((d==="text"||d==="password")&&c(b).closest("form").length&&a.keyCode===13){a.liveFired=B;return la("submit",this,arguments)}})}else return false},teardown:function(){c.event.remove(this,".specialSubmit")}};if(!c.support.changeBubbles){var V,
|
||||
xa=function(a){var b=a.type,d=a.value;if(b==="radio"||b==="checkbox")d=a.checked;else if(b==="select-multiple")d=a.selectedIndex>-1?c.map(a.options,function(e){return e.selected}).join("-"):"";else if(a.nodeName.toLowerCase()==="select")d=a.selectedIndex;return d},Z=function(a,b){var d=a.target,e,f;if(!(!ia.test(d.nodeName)||d.readOnly)){e=c.data(d,"_change_data");f=xa(d);if(a.type!=="focusout"||d.type!=="radio")c.data(d,"_change_data",f);if(!(e===B||f===e))if(e!=null||f){a.type="change";a.liveFired=
|
||||
B;return c.event.trigger(a,b,d)}}};c.event.special.change={filters:{focusout:Z,beforedeactivate:Z,click:function(a){var b=a.target,d=b.type;if(d==="radio"||d==="checkbox"||b.nodeName.toLowerCase()==="select")return Z.call(this,a)},keydown:function(a){var b=a.target,d=b.type;if(a.keyCode===13&&b.nodeName.toLowerCase()!=="textarea"||a.keyCode===32&&(d==="checkbox"||d==="radio")||d==="select-multiple")return Z.call(this,a)},beforeactivate:function(a){a=a.target;c.data(a,"_change_data",xa(a))}},setup:function(){if(this.type===
|
||||
"file")return false;for(var a in V)c.event.add(this,a+".specialChange",V[a]);return ia.test(this.nodeName)},teardown:function(){c.event.remove(this,".specialChange");return ia.test(this.nodeName)}};V=c.event.special.change.filters;V.focus=V.beforeactivate}t.addEventListener&&c.each({focus:"focusin",blur:"focusout"},function(a,b){function d(e){e=c.event.fix(e);e.type=b;return c.event.trigger(e,null,e.target)}c.event.special[b]={setup:function(){ua[b]++===0&&t.addEventListener(a,d,true)},teardown:function(){--ua[b]===
|
||||
0&&t.removeEventListener(a,d,true)}}});c.each(["bind","one"],function(a,b){c.fn[b]=function(d,e,f){if(typeof d==="object"){for(var h in d)this[b](h,e,d[h],f);return this}if(c.isFunction(e)||e===false){f=e;e=B}var l=b==="one"?c.proxy(f,function(o){c(this).unbind(o,l);return f.apply(this,arguments)}):f;if(d==="unload"&&b!=="one")this.one(d,e,f);else{h=0;for(var k=this.length;h<k;h++)c.event.add(this[h],d,l,e)}return this}});c.fn.extend({unbind:function(a,b){if(typeof a==="object"&&!a.preventDefault)for(var d in a)this.unbind(d,
|
||||
a[d]);else{d=0;for(var e=this.length;d<e;d++)c.event.remove(this[d],a,b)}return this},delegate:function(a,b,d,e){return this.live(b,d,e,a)},undelegate:function(a,b,d){return arguments.length===0?this.unbind("live"):this.die(b,null,d,a)},trigger:function(a,b){return this.each(function(){c.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0]){var d=c.Event(a);d.preventDefault();d.stopPropagation();c.event.trigger(d,b,this[0]);return d.result}},toggle:function(a){for(var b=arguments,d=
|
||||
1;d<b.length;)c.proxy(a,b[d++]);return this.click(c.proxy(a,function(e){var f=(c.data(this,"lastToggle"+a.guid)||0)%d;c.data(this,"lastToggle"+a.guid,f+1);e.preventDefault();return b[f].apply(this,arguments)||false}))},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}});var ya={focus:"focusin",blur:"focusout",mouseenter:"mouseover",mouseleave:"mouseout"};c.each(["live","die"],function(a,b){c.fn[b]=function(d,e,f,h){var l,k=0,o,x,r=h||this.selector;h=h?this:c(this.context);if(typeof d===
|
||||
"object"&&!d.preventDefault){for(l in d)h[b](l,e,d[l],r);return this}if(c.isFunction(e)){f=e;e=B}for(d=(d||"").split(" ");(l=d[k++])!=null;){o=X.exec(l);x="";if(o){x=o[0];l=l.replace(X,"")}if(l==="hover")d.push("mouseenter"+x,"mouseleave"+x);else{o=l;if(l==="focus"||l==="blur"){d.push(ya[l]+x);l+=x}else l=(ya[l]||l)+x;if(b==="live"){x=0;for(var A=h.length;x<A;x++)c.event.add(h[x],"live."+Y(l,r),{data:e,selector:r,handler:f,origType:l,origHandler:f,preType:o})}else h.unbind("live."+Y(l,r),f)}}return this}});
|
||||
c.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error".split(" "),function(a,b){c.fn[b]=function(d,e){if(e==null){e=d;d=null}return arguments.length>0?this.bind(b,d,e):this.trigger(b)};if(c.attrFn)c.attrFn[b]=true});E.attachEvent&&!E.addEventListener&&c(E).bind("unload",function(){for(var a in c.cache)if(c.cache[a].handle)try{c.event.remove(c.cache[a].handle.elem)}catch(b){}});
|
||||
(function(){function a(g,i,n,m,p,q){p=0;for(var u=m.length;p<u;p++){var y=m[p];if(y){var F=false;for(y=y[g];y;){if(y.sizcache===n){F=m[y.sizset];break}if(y.nodeType===1&&!q){y.sizcache=n;y.sizset=p}if(y.nodeName.toLowerCase()===i){F=y;break}y=y[g]}m[p]=F}}}function b(g,i,n,m,p,q){p=0;for(var u=m.length;p<u;p++){var y=m[p];if(y){var F=false;for(y=y[g];y;){if(y.sizcache===n){F=m[y.sizset];break}if(y.nodeType===1){if(!q){y.sizcache=n;y.sizset=p}if(typeof i!=="string"){if(y===i){F=true;break}}else if(k.filter(i,
|
||||
[y]).length>0){F=y;break}}y=y[g]}m[p]=F}}}var d=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,e=0,f=Object.prototype.toString,h=false,l=true;[0,0].sort(function(){l=false;return 0});var k=function(g,i,n,m){n=n||[];var p=i=i||t;if(i.nodeType!==1&&i.nodeType!==9)return[];if(!g||typeof g!=="string")return n;var q,u,y,F,M,N=true,O=k.isXML(i),D=[],R=g;do{d.exec("");if(q=d.exec(R)){R=q[3];D.push(q[1]);if(q[2]){F=q[3];
|
||||
break}}}while(q);if(D.length>1&&x.exec(g))if(D.length===2&&o.relative[D[0]])u=L(D[0]+D[1],i);else for(u=o.relative[D[0]]?[i]:k(D.shift(),i);D.length;){g=D.shift();if(o.relative[g])g+=D.shift();u=L(g,u)}else{if(!m&&D.length>1&&i.nodeType===9&&!O&&o.match.ID.test(D[0])&&!o.match.ID.test(D[D.length-1])){q=k.find(D.shift(),i,O);i=q.expr?k.filter(q.expr,q.set)[0]:q.set[0]}if(i){q=m?{expr:D.pop(),set:C(m)}:k.find(D.pop(),D.length===1&&(D[0]==="~"||D[0]==="+")&&i.parentNode?i.parentNode:i,O);u=q.expr?k.filter(q.expr,
|
||||
q.set):q.set;if(D.length>0)y=C(u);else N=false;for(;D.length;){q=M=D.pop();if(o.relative[M])q=D.pop();else M="";if(q==null)q=i;o.relative[M](y,q,O)}}else y=[]}y||(y=u);y||k.error(M||g);if(f.call(y)==="[object Array]")if(N)if(i&&i.nodeType===1)for(g=0;y[g]!=null;g++){if(y[g]&&(y[g]===true||y[g].nodeType===1&&k.contains(i,y[g])))n.push(u[g])}else for(g=0;y[g]!=null;g++)y[g]&&y[g].nodeType===1&&n.push(u[g]);else n.push.apply(n,y);else C(y,n);if(F){k(F,p,n,m);k.uniqueSort(n)}return n};k.uniqueSort=function(g){if(w){h=
|
||||
l;g.sort(w);if(h)for(var i=1;i<g.length;i++)g[i]===g[i-1]&&g.splice(i--,1)}return g};k.matches=function(g,i){return k(g,null,null,i)};k.matchesSelector=function(g,i){return k(i,null,null,[g]).length>0};k.find=function(g,i,n){var m;if(!g)return[];for(var p=0,q=o.order.length;p<q;p++){var u,y=o.order[p];if(u=o.leftMatch[y].exec(g)){var F=u[1];u.splice(1,1);if(F.substr(F.length-1)!=="\\"){u[1]=(u[1]||"").replace(/\\/g,"");m=o.find[y](u,i,n);if(m!=null){g=g.replace(o.match[y],"");break}}}}m||(m=i.getElementsByTagName("*"));
|
||||
return{set:m,expr:g}};k.filter=function(g,i,n,m){for(var p,q,u=g,y=[],F=i,M=i&&i[0]&&k.isXML(i[0]);g&&i.length;){for(var N in o.filter)if((p=o.leftMatch[N].exec(g))!=null&&p[2]){var O,D,R=o.filter[N];D=p[1];q=false;p.splice(1,1);if(D.substr(D.length-1)!=="\\"){if(F===y)y=[];if(o.preFilter[N])if(p=o.preFilter[N](p,F,n,y,m,M)){if(p===true)continue}else q=O=true;if(p)for(var j=0;(D=F[j])!=null;j++)if(D){O=R(D,p,j,F);var s=m^!!O;if(n&&O!=null)if(s)q=true;else F[j]=false;else if(s){y.push(D);q=true}}if(O!==
|
||||
B){n||(F=y);g=g.replace(o.match[N],"");if(!q)return[];break}}}if(g===u)if(q==null)k.error(g);else break;u=g}return F};k.error=function(g){throw"Syntax error, unrecognized expression: "+g;};var o=k.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\((even|odd|[\dn+\-]*)\))?/,
|
||||
POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(g){return g.getAttribute("href")}},relative:{"+":function(g,i){var n=typeof i==="string",m=n&&!/\W/.test(i);n=n&&!m;if(m)i=i.toLowerCase();m=0;for(var p=g.length,q;m<p;m++)if(q=g[m]){for(;(q=q.previousSibling)&&q.nodeType!==1;);g[m]=n||q&&q.nodeName.toLowerCase()===
|
||||
i?q||false:q===i}n&&k.filter(i,g,true)},">":function(g,i){var n,m=typeof i==="string",p=0,q=g.length;if(m&&!/\W/.test(i))for(i=i.toLowerCase();p<q;p++){if(n=g[p]){n=n.parentNode;g[p]=n.nodeName.toLowerCase()===i?n:false}}else{for(;p<q;p++)if(n=g[p])g[p]=m?n.parentNode:n.parentNode===i;m&&k.filter(i,g,true)}},"":function(g,i,n){var m,p=e++,q=b;if(typeof i==="string"&&!/\W/.test(i)){m=i=i.toLowerCase();q=a}q("parentNode",i,p,g,m,n)},"~":function(g,i,n){var m,p=e++,q=b;if(typeof i==="string"&&!/\W/.test(i)){m=
|
||||
i=i.toLowerCase();q=a}q("previousSibling",i,p,g,m,n)}},find:{ID:function(g,i,n){if(typeof i.getElementById!=="undefined"&&!n)return(g=i.getElementById(g[1]))&&g.parentNode?[g]:[]},NAME:function(g,i){if(typeof i.getElementsByName!=="undefined"){for(var n=[],m=i.getElementsByName(g[1]),p=0,q=m.length;p<q;p++)m[p].getAttribute("name")===g[1]&&n.push(m[p]);return n.length===0?null:n}},TAG:function(g,i){return i.getElementsByTagName(g[1])}},preFilter:{CLASS:function(g,i,n,m,p,q){g=" "+g[1].replace(/\\/g,
|
||||
"")+" ";if(q)return g;q=0;for(var u;(u=i[q])!=null;q++)if(u)if(p^(u.className&&(" "+u.className+" ").replace(/[\t\n]/g," ").indexOf(g)>=0))n||m.push(u);else if(n)i[q]=false;return false},ID:function(g){return g[1].replace(/\\/g,"")},TAG:function(g){return g[1].toLowerCase()},CHILD:function(g){if(g[1]==="nth"){var i=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(g[2]==="even"&&"2n"||g[2]==="odd"&&"2n+1"||!/\D/.test(g[2])&&"0n+"+g[2]||g[2]);g[2]=i[1]+(i[2]||1)-0;g[3]=i[3]-0}g[0]=e++;return g},ATTR:function(g,i,n,
|
||||
m,p,q){i=g[1].replace(/\\/g,"");if(!q&&o.attrMap[i])g[1]=o.attrMap[i];if(g[2]==="~=")g[4]=" "+g[4]+" ";return g},PSEUDO:function(g,i,n,m,p){if(g[1]==="not")if((d.exec(g[3])||"").length>1||/^\w/.test(g[3]))g[3]=k(g[3],null,null,i);else{g=k.filter(g[3],i,n,true^p);n||m.push.apply(m,g);return false}else if(o.match.POS.test(g[0])||o.match.CHILD.test(g[0]))return true;return g},POS:function(g){g.unshift(true);return g}},filters:{enabled:function(g){return g.disabled===false&&g.type!=="hidden"},disabled:function(g){return g.disabled===
|
||||
true},checked:function(g){return g.checked===true},selected:function(g){return g.selected===true},parent:function(g){return!!g.firstChild},empty:function(g){return!g.firstChild},has:function(g,i,n){return!!k(n[3],g).length},header:function(g){return/h\d/i.test(g.nodeName)},text:function(g){return"text"===g.type},radio:function(g){return"radio"===g.type},checkbox:function(g){return"checkbox"===g.type},file:function(g){return"file"===g.type},password:function(g){return"password"===g.type},submit:function(g){return"submit"===
|
||||
g.type},image:function(g){return"image"===g.type},reset:function(g){return"reset"===g.type},button:function(g){return"button"===g.type||g.nodeName.toLowerCase()==="button"},input:function(g){return/input|select|textarea|button/i.test(g.nodeName)}},setFilters:{first:function(g,i){return i===0},last:function(g,i,n,m){return i===m.length-1},even:function(g,i){return i%2===0},odd:function(g,i){return i%2===1},lt:function(g,i,n){return i<n[3]-0},gt:function(g,i,n){return i>n[3]-0},nth:function(g,i,n){return n[3]-
|
||||
0===i},eq:function(g,i,n){return n[3]-0===i}},filter:{PSEUDO:function(g,i,n,m){var p=i[1],q=o.filters[p];if(q)return q(g,n,i,m);else if(p==="contains")return(g.textContent||g.innerText||k.getText([g])||"").indexOf(i[3])>=0;else if(p==="not"){i=i[3];n=0;for(m=i.length;n<m;n++)if(i[n]===g)return false;return true}else k.error("Syntax error, unrecognized expression: "+p)},CHILD:function(g,i){var n=i[1],m=g;switch(n){case "only":case "first":for(;m=m.previousSibling;)if(m.nodeType===1)return false;if(n===
|
||||
"first")return true;m=g;case "last":for(;m=m.nextSibling;)if(m.nodeType===1)return false;return true;case "nth":n=i[2];var p=i[3];if(n===1&&p===0)return true;var q=i[0],u=g.parentNode;if(u&&(u.sizcache!==q||!g.nodeIndex)){var y=0;for(m=u.firstChild;m;m=m.nextSibling)if(m.nodeType===1)m.nodeIndex=++y;u.sizcache=q}m=g.nodeIndex-p;return n===0?m===0:m%n===0&&m/n>=0}},ID:function(g,i){return g.nodeType===1&&g.getAttribute("id")===i},TAG:function(g,i){return i==="*"&&g.nodeType===1||g.nodeName.toLowerCase()===
|
||||
i},CLASS:function(g,i){return(" "+(g.className||g.getAttribute("class"))+" ").indexOf(i)>-1},ATTR:function(g,i){var n=i[1];n=o.attrHandle[n]?o.attrHandle[n](g):g[n]!=null?g[n]:g.getAttribute(n);var m=n+"",p=i[2],q=i[4];return n==null?p==="!=":p==="="?m===q:p==="*="?m.indexOf(q)>=0:p==="~="?(" "+m+" ").indexOf(q)>=0:!q?m&&n!==false:p==="!="?m!==q:p==="^="?m.indexOf(q)===0:p==="$="?m.substr(m.length-q.length)===q:p==="|="?m===q||m.substr(0,q.length+1)===q+"-":false},POS:function(g,i,n,m){var p=o.setFilters[i[2]];
|
||||
if(p)return p(g,n,i,m)}}},x=o.match.POS,r=function(g,i){return"\\"+(i-0+1)},A;for(A in o.match){o.match[A]=RegExp(o.match[A].source+/(?![^\[]*\])(?![^\(]*\))/.source);o.leftMatch[A]=RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[A].source.replace(/\\(\d+)/g,r))}var C=function(g,i){g=Array.prototype.slice.call(g,0);if(i){i.push.apply(i,g);return i}return g};try{Array.prototype.slice.call(t.documentElement.childNodes,0)}catch(J){C=function(g,i){var n=0,m=i||[];if(f.call(g)==="[object Array]")Array.prototype.push.apply(m,
|
||||
g);else if(typeof g.length==="number")for(var p=g.length;n<p;n++)m.push(g[n]);else for(;g[n];n++)m.push(g[n]);return m}}var w,I;if(t.documentElement.compareDocumentPosition)w=function(g,i){if(g===i){h=true;return 0}if(!g.compareDocumentPosition||!i.compareDocumentPosition)return g.compareDocumentPosition?-1:1;return g.compareDocumentPosition(i)&4?-1:1};else{w=function(g,i){var n,m,p=[],q=[];n=g.parentNode;m=i.parentNode;var u=n;if(g===i){h=true;return 0}else if(n===m)return I(g,i);else if(n){if(!m)return 1}else return-1;
|
||||
for(;u;){p.unshift(u);u=u.parentNode}for(u=m;u;){q.unshift(u);u=u.parentNode}n=p.length;m=q.length;for(u=0;u<n&&u<m;u++)if(p[u]!==q[u])return I(p[u],q[u]);return u===n?I(g,q[u],-1):I(p[u],i,1)};I=function(g,i,n){if(g===i)return n;for(g=g.nextSibling;g;){if(g===i)return-1;g=g.nextSibling}return 1}}k.getText=function(g){for(var i="",n,m=0;g[m];m++){n=g[m];if(n.nodeType===3||n.nodeType===4)i+=n.nodeValue;else if(n.nodeType!==8)i+=k.getText(n.childNodes)}return i};(function(){var g=t.createElement("div"),
|
||||
i="script"+(new Date).getTime(),n=t.documentElement;g.innerHTML="<a name='"+i+"'/>";n.insertBefore(g,n.firstChild);if(t.getElementById(i)){o.find.ID=function(m,p,q){if(typeof p.getElementById!=="undefined"&&!q)return(p=p.getElementById(m[1]))?p.id===m[1]||typeof p.getAttributeNode!=="undefined"&&p.getAttributeNode("id").nodeValue===m[1]?[p]:B:[]};o.filter.ID=function(m,p){var q=typeof m.getAttributeNode!=="undefined"&&m.getAttributeNode("id");return m.nodeType===1&&q&&q.nodeValue===p}}n.removeChild(g);
|
||||
n=g=null})();(function(){var g=t.createElement("div");g.appendChild(t.createComment(""));if(g.getElementsByTagName("*").length>0)o.find.TAG=function(i,n){var m=n.getElementsByTagName(i[1]);if(i[1]==="*"){for(var p=[],q=0;m[q];q++)m[q].nodeType===1&&p.push(m[q]);m=p}return m};g.innerHTML="<a href='#'></a>";if(g.firstChild&&typeof g.firstChild.getAttribute!=="undefined"&&g.firstChild.getAttribute("href")!=="#")o.attrHandle.href=function(i){return i.getAttribute("href",2)};g=null})();t.querySelectorAll&&
|
||||
function(){var g=k,i=t.createElement("div");i.innerHTML="<p class='TEST'></p>";if(!(i.querySelectorAll&&i.querySelectorAll(".TEST").length===0)){k=function(m,p,q,u){p=p||t;m=m.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!u&&!k.isXML(p))if(p.nodeType===9)try{return C(p.querySelectorAll(m),q)}catch(y){}else if(p.nodeType===1&&p.nodeName.toLowerCase()!=="object"){var F=p.getAttribute("id"),M=F||"__sizzle__";F||p.setAttribute("id",M);try{return C(p.querySelectorAll("#"+M+" "+m),q)}catch(N){}finally{F||
|
||||
p.removeAttribute("id")}}return g(m,p,q,u)};for(var n in g)k[n]=g[n];i=null}}();(function(){var g=t.documentElement,i=g.matchesSelector||g.mozMatchesSelector||g.webkitMatchesSelector||g.msMatchesSelector,n=false;try{i.call(t.documentElement,"[test!='']:sizzle")}catch(m){n=true}if(i)k.matchesSelector=function(p,q){q=q.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!k.isXML(p))try{if(n||!o.match.PSEUDO.test(q)&&!/!=/.test(q))return i.call(p,q)}catch(u){}return k(q,null,null,[p]).length>0}})();(function(){var g=
|
||||
t.createElement("div");g.innerHTML="<div class='test e'></div><div class='test'></div>";if(!(!g.getElementsByClassName||g.getElementsByClassName("e").length===0)){g.lastChild.className="e";if(g.getElementsByClassName("e").length!==1){o.order.splice(1,0,"CLASS");o.find.CLASS=function(i,n,m){if(typeof n.getElementsByClassName!=="undefined"&&!m)return n.getElementsByClassName(i[1])};g=null}}})();k.contains=t.documentElement.contains?function(g,i){return g!==i&&(g.contains?g.contains(i):true)}:t.documentElement.compareDocumentPosition?
|
||||
function(g,i){return!!(g.compareDocumentPosition(i)&16)}:function(){return false};k.isXML=function(g){return(g=(g?g.ownerDocument||g:0).documentElement)?g.nodeName!=="HTML":false};var L=function(g,i){for(var n,m=[],p="",q=i.nodeType?[i]:i;n=o.match.PSEUDO.exec(g);){p+=n[0];g=g.replace(o.match.PSEUDO,"")}g=o.relative[g]?g+"*":g;n=0;for(var u=q.length;n<u;n++)k(g,q[n],m);return k.filter(p,m)};c.find=k;c.expr=k.selectors;c.expr[":"]=c.expr.filters;c.unique=k.uniqueSort;c.text=k.getText;c.isXMLDoc=k.isXML;
|
||||
c.contains=k.contains})();var Za=/Until$/,$a=/^(?:parents|prevUntil|prevAll)/,ab=/,/,Na=/^.[^:#\[\.,]*$/,bb=Array.prototype.slice,cb=c.expr.match.POS;c.fn.extend({find:function(a){for(var b=this.pushStack("","find",a),d=0,e=0,f=this.length;e<f;e++){d=b.length;c.find(a,this[e],b);if(e>0)for(var h=d;h<b.length;h++)for(var l=0;l<d;l++)if(b[l]===b[h]){b.splice(h--,1);break}}return b},has:function(a){var b=c(a);return this.filter(function(){for(var d=0,e=b.length;d<e;d++)if(c.contains(this,b[d]))return true})},
|
||||
not:function(a){return this.pushStack(ma(this,a,false),"not",a)},filter:function(a){return this.pushStack(ma(this,a,true),"filter",a)},is:function(a){return!!a&&c.filter(a,this).length>0},closest:function(a,b){var d=[],e,f,h=this[0];if(c.isArray(a)){var l,k={},o=1;if(h&&a.length){e=0;for(f=a.length;e<f;e++){l=a[e];k[l]||(k[l]=c.expr.match.POS.test(l)?c(l,b||this.context):l)}for(;h&&h.ownerDocument&&h!==b;){for(l in k){e=k[l];if(e.jquery?e.index(h)>-1:c(h).is(e))d.push({selector:l,elem:h,level:o})}h=
|
||||
h.parentNode;o++}}return d}l=cb.test(a)?c(a,b||this.context):null;e=0;for(f=this.length;e<f;e++)for(h=this[e];h;)if(l?l.index(h)>-1:c.find.matchesSelector(h,a)){d.push(h);break}else{h=h.parentNode;if(!h||!h.ownerDocument||h===b)break}d=d.length>1?c.unique(d):d;return this.pushStack(d,"closest",a)},index:function(a){if(!a||typeof a==="string")return c.inArray(this[0],a?c(a):this.parent().children());return c.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var d=typeof a==="string"?c(a,b||this.context):
|
||||
c.makeArray(a),e=c.merge(this.get(),d);return this.pushStack(!d[0]||!d[0].parentNode||d[0].parentNode.nodeType===11||!e[0]||!e[0].parentNode||e[0].parentNode.nodeType===11?e:c.unique(e))},andSelf:function(){return this.add(this.prevObject)}});c.each({parent:function(a){return(a=a.parentNode)&&a.nodeType!==11?a:null},parents:function(a){return c.dir(a,"parentNode")},parentsUntil:function(a,b,d){return c.dir(a,"parentNode",d)},next:function(a){return c.nth(a,2,"nextSibling")},prev:function(a){return c.nth(a,
|
||||
2,"previousSibling")},nextAll:function(a){return c.dir(a,"nextSibling")},prevAll:function(a){return c.dir(a,"previousSibling")},nextUntil:function(a,b,d){return c.dir(a,"nextSibling",d)},prevUntil:function(a,b,d){return c.dir(a,"previousSibling",d)},siblings:function(a){return c.sibling(a.parentNode.firstChild,a)},children:function(a){return c.sibling(a.firstChild)},contents:function(a){return c.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:c.makeArray(a.childNodes)}},function(a,
|
||||
b){c.fn[a]=function(d,e){var f=c.map(this,b,d);Za.test(a)||(e=d);if(e&&typeof e==="string")f=c.filter(e,f);f=this.length>1?c.unique(f):f;if((this.length>1||ab.test(e))&&$a.test(a))f=f.reverse();return this.pushStack(f,a,bb.call(arguments).join(","))}});c.extend({filter:function(a,b,d){if(d)a=":not("+a+")";return b.length===1?c.find.matchesSelector(b[0],a)?[b[0]]:[]:c.find.matches(a,b)},dir:function(a,b,d){var e=[];for(a=a[b];a&&a.nodeType!==9&&(d===B||a.nodeType!==1||!c(a).is(d));){a.nodeType===1&&
|
||||
e.push(a);a=a[b]}return e},nth:function(a,b,d){b=b||1;for(var e=0;a;a=a[d])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){for(var d=[];a;a=a.nextSibling)a.nodeType===1&&a!==b&&d.push(a);return d}});var za=/ jQuery\d+="(?:\d+|null)"/g,$=/^\s+/,Aa=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Ba=/<([\w:]+)/,db=/<tbody/i,eb=/<|&#?\w+;/,Ca=/<(?:script|object|embed|option|style)/i,Da=/checked\s*(?:[^=]|=\s*.checked.)/i,fb=/\=([^="'>\s]+\/)>/g,P={option:[1,
|
||||
"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]};P.optgroup=P.option;P.tbody=P.tfoot=P.colgroup=P.caption=P.thead;P.th=P.td;if(!c.support.htmlSerialize)P._default=[1,"div<div>","</div>"];c.fn.extend({text:function(a){if(c.isFunction(a))return this.each(function(b){var d=
|
||||
c(this);d.text(a.call(this,b,d.text()))});if(typeof a!=="object"&&a!==B)return this.empty().append((this[0]&&this[0].ownerDocument||t).createTextNode(a));return c.text(this)},wrapAll:function(a){if(c.isFunction(a))return this.each(function(d){c(this).wrapAll(a.call(this,d))});if(this[0]){var b=c(a,this[0].ownerDocument).eq(0).clone(true);this[0].parentNode&&b.insertBefore(this[0]);b.map(function(){for(var d=this;d.firstChild&&d.firstChild.nodeType===1;)d=d.firstChild;return d}).append(this)}return this},
|
||||
wrapInner:function(a){if(c.isFunction(a))return this.each(function(b){c(this).wrapInner(a.call(this,b))});return this.each(function(){var b=c(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){c(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){c.nodeName(this,"body")||c(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.appendChild(a)})},
|
||||
prepend:function(){return this.domManip(arguments,true,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,this)});else if(arguments.length){var a=c(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,false,function(b){this.parentNode.insertBefore(b,
|
||||
this.nextSibling)});else if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,c(arguments[0]).toArray());return a}},remove:function(a,b){for(var d=0,e;(e=this[d])!=null;d++)if(!a||c.filter(a,[e]).length){if(!b&&e.nodeType===1){c.cleanData(e.getElementsByTagName("*"));c.cleanData([e])}e.parentNode&&e.parentNode.removeChild(e)}return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++)for(b.nodeType===1&&c.cleanData(b.getElementsByTagName("*"));b.firstChild;)b.removeChild(b.firstChild);
|
||||
return this},clone:function(a){var b=this.map(function(){if(!c.support.noCloneEvent&&!c.isXMLDoc(this)){var d=this.outerHTML,e=this.ownerDocument;if(!d){d=e.createElement("div");d.appendChild(this.cloneNode(true));d=d.innerHTML}return c.clean([d.replace(za,"").replace(fb,'="$1">').replace($,"")],e)[0]}else return this.cloneNode(true)});if(a===true){na(this,b);na(this.find("*"),b.find("*"))}return b},html:function(a){if(a===B)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(za,""):null;
|
||||
else if(typeof a==="string"&&!Ca.test(a)&&(c.support.leadingWhitespace||!$.test(a))&&!P[(Ba.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Aa,"<$1></$2>");try{for(var b=0,d=this.length;b<d;b++)if(this[b].nodeType===1){c.cleanData(this[b].getElementsByTagName("*"));this[b].innerHTML=a}}catch(e){this.empty().append(a)}}else c.isFunction(a)?this.each(function(f){var h=c(this);h.html(a.call(this,f,h.html()))}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&this[0].parentNode){if(c.isFunction(a))return this.each(function(b){var d=
|
||||
c(this),e=d.html();d.replaceWith(a.call(this,b,e))});if(typeof a!=="string")a=c(a).detach();return this.each(function(){var b=this.nextSibling,d=this.parentNode;c(this).remove();b?c(b).before(a):c(d).append(a)})}else return this.pushStack(c(c.isFunction(a)?a():a),"replaceWith",a)},detach:function(a){return this.remove(a,true)},domManip:function(a,b,d){var e,f,h,l=a[0],k=[];if(!c.support.checkClone&&arguments.length===3&&typeof l==="string"&&Da.test(l))return this.each(function(){c(this).domManip(a,
|
||||
b,d,true)});if(c.isFunction(l))return this.each(function(x){var r=c(this);a[0]=l.call(this,x,b?r.html():B);r.domManip(a,b,d)});if(this[0]){e=l&&l.parentNode;e=c.support.parentNode&&e&&e.nodeType===11&&e.childNodes.length===this.length?{fragment:e}:c.buildFragment(a,this,k);h=e.fragment;if(f=h.childNodes.length===1?h=h.firstChild:h.firstChild){b=b&&c.nodeName(f,"tr");f=0;for(var o=this.length;f<o;f++)d.call(b?c.nodeName(this[f],"table")?this[f].getElementsByTagName("tbody")[0]||this[f].appendChild(this[f].ownerDocument.createElement("tbody")):
|
||||
this[f]:this[f],f>0||e.cacheable||this.length>1?h.cloneNode(true):h)}k.length&&c.each(k,Oa)}return this}});c.buildFragment=function(a,b,d){var e,f,h;b=b&&b[0]?b[0].ownerDocument||b[0]:t;if(a.length===1&&typeof a[0]==="string"&&a[0].length<512&&b===t&&!Ca.test(a[0])&&(c.support.checkClone||!Da.test(a[0]))){f=true;if(h=c.fragments[a[0]])if(h!==1)e=h}if(!e){e=b.createDocumentFragment();c.clean(a,b,e,d)}if(f)c.fragments[a[0]]=h?e:1;return{fragment:e,cacheable:f}};c.fragments={};c.each({appendTo:"append",
|
||||
prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){c.fn[a]=function(d){var e=[];d=c(d);var f=this.length===1&&this[0].parentNode;if(f&&f.nodeType===11&&f.childNodes.length===1&&d.length===1){d[b](this[0]);return this}else{f=0;for(var h=d.length;f<h;f++){var l=(f>0?this.clone(true):this).get();c(d[f])[b](l);e=e.concat(l)}return this.pushStack(e,a,d.selector)}}});c.extend({clean:function(a,b,d,e){b=b||t;if(typeof b.createElement==="undefined")b=b.ownerDocument||
|
||||
b[0]&&b[0].ownerDocument||t;for(var f=[],h=0,l;(l=a[h])!=null;h++){if(typeof l==="number")l+="";if(l){if(typeof l==="string"&&!eb.test(l))l=b.createTextNode(l);else if(typeof l==="string"){l=l.replace(Aa,"<$1></$2>");var k=(Ba.exec(l)||["",""])[1].toLowerCase(),o=P[k]||P._default,x=o[0],r=b.createElement("div");for(r.innerHTML=o[1]+l+o[2];x--;)r=r.lastChild;if(!c.support.tbody){x=db.test(l);k=k==="table"&&!x?r.firstChild&&r.firstChild.childNodes:o[1]==="<table>"&&!x?r.childNodes:[];for(o=k.length-
|
||||
1;o>=0;--o)c.nodeName(k[o],"tbody")&&!k[o].childNodes.length&&k[o].parentNode.removeChild(k[o])}!c.support.leadingWhitespace&&$.test(l)&&r.insertBefore(b.createTextNode($.exec(l)[0]),r.firstChild);l=r.childNodes}if(l.nodeType)f.push(l);else f=c.merge(f,l)}}if(d)for(h=0;f[h];h++)if(e&&c.nodeName(f[h],"script")&&(!f[h].type||f[h].type.toLowerCase()==="text/javascript"))e.push(f[h].parentNode?f[h].parentNode.removeChild(f[h]):f[h]);else{f[h].nodeType===1&&f.splice.apply(f,[h+1,0].concat(c.makeArray(f[h].getElementsByTagName("script"))));
|
||||
d.appendChild(f[h])}return f},cleanData:function(a){for(var b,d,e=c.cache,f=c.event.special,h=c.support.deleteExpando,l=0,k;(k=a[l])!=null;l++)if(!(k.nodeName&&c.noData[k.nodeName.toLowerCase()]))if(d=k[c.expando]){if((b=e[d])&&b.events)for(var o in b.events)f[o]?c.event.remove(k,o):c.removeEvent(k,o,b.handle);if(h)delete k[c.expando];else k.removeAttribute&&k.removeAttribute(c.expando);delete e[d]}}});var Ea=/alpha\([^)]*\)/i,gb=/opacity=([^)]*)/,hb=/-([a-z])/ig,ib=/([A-Z])/g,Fa=/^-?\d+(?:px)?$/i,
|
||||
jb=/^-?\d/,kb={position:"absolute",visibility:"hidden",display:"block"},Pa=["Left","Right"],Qa=["Top","Bottom"],W,Ga,aa,lb=function(a,b){return b.toUpperCase()};c.fn.css=function(a,b){if(arguments.length===2&&b===B)return this;return c.access(this,a,b,true,function(d,e,f){return f!==B?c.style(d,e,f):c.css(d,e)})};c.extend({cssHooks:{opacity:{get:function(a,b){if(b){var d=W(a,"opacity","opacity");return d===""?"1":d}else return a.style.opacity}}},cssNumber:{zIndex:true,fontWeight:true,opacity:true,
|
||||
zoom:true,lineHeight:true},cssProps:{"float":c.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,b,d,e){if(!(!a||a.nodeType===3||a.nodeType===8||!a.style)){var f,h=c.camelCase(b),l=a.style,k=c.cssHooks[h];b=c.cssProps[h]||h;if(d!==B){if(!(typeof d==="number"&&isNaN(d)||d==null)){if(typeof d==="number"&&!c.cssNumber[h])d+="px";if(!k||!("set"in k)||(d=k.set(a,d))!==B)try{l[b]=d}catch(o){}}}else{if(k&&"get"in k&&(f=k.get(a,false,e))!==B)return f;return l[b]}}},css:function(a,b,d){var e,f=c.camelCase(b),
|
||||
h=c.cssHooks[f];b=c.cssProps[f]||f;if(h&&"get"in h&&(e=h.get(a,true,d))!==B)return e;else if(W)return W(a,b,f)},swap:function(a,b,d){var e={},f;for(f in b){e[f]=a.style[f];a.style[f]=b[f]}d.call(a);for(f in b)a.style[f]=e[f]},camelCase:function(a){return a.replace(hb,lb)}});c.curCSS=c.css;c.each(["height","width"],function(a,b){c.cssHooks[b]={get:function(d,e,f){var h;if(e){if(d.offsetWidth!==0)h=oa(d,b,f);else c.swap(d,kb,function(){h=oa(d,b,f)});if(h<=0){h=W(d,b,b);if(h==="0px"&&aa)h=aa(d,b,b);
|
||||
if(h!=null)return h===""||h==="auto"?"0px":h}if(h<0||h==null){h=d.style[b];return h===""||h==="auto"?"0px":h}return typeof h==="string"?h:h+"px"}},set:function(d,e){if(Fa.test(e)){e=parseFloat(e);if(e>=0)return e+"px"}else return e}}});if(!c.support.opacity)c.cssHooks.opacity={get:function(a,b){return gb.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var d=a.style;d.zoom=1;var e=c.isNaN(b)?"":"alpha(opacity="+b*100+")",f=
|
||||
d.filter||"";d.filter=Ea.test(f)?f.replace(Ea,e):d.filter+" "+e}};if(t.defaultView&&t.defaultView.getComputedStyle)Ga=function(a,b,d){var e;d=d.replace(ib,"-$1").toLowerCase();if(!(b=a.ownerDocument.defaultView))return B;if(b=b.getComputedStyle(a,null)){e=b.getPropertyValue(d);if(e===""&&!c.contains(a.ownerDocument.documentElement,a))e=c.style(a,d)}return e};if(t.documentElement.currentStyle)aa=function(a,b){var d,e,f=a.currentStyle&&a.currentStyle[b],h=a.style;if(!Fa.test(f)&&jb.test(f)){d=h.left;
|
||||
e=a.runtimeStyle.left;a.runtimeStyle.left=a.currentStyle.left;h.left=b==="fontSize"?"1em":f||0;f=h.pixelLeft+"px";h.left=d;a.runtimeStyle.left=e}return f===""?"auto":f};W=Ga||aa;if(c.expr&&c.expr.filters){c.expr.filters.hidden=function(a){var b=a.offsetHeight;return a.offsetWidth===0&&b===0||!c.support.reliableHiddenOffsets&&(a.style.display||c.css(a,"display"))==="none"};c.expr.filters.visible=function(a){return!c.expr.filters.hidden(a)}}var mb=c.now(),nb=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
|
||||
ob=/^(?:select|textarea)/i,pb=/^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,qb=/^(?:GET|HEAD)$/,Ra=/\[\]$/,T=/\=\?(&|$)/,ja=/\?/,rb=/([?&])_=[^&]*/,sb=/^(\w+:)?\/\/([^\/?#]+)/,tb=/%20/g,ub=/#.*$/,Ha=c.fn.load;c.fn.extend({load:function(a,b,d){if(typeof a!=="string"&&Ha)return Ha.apply(this,arguments);else if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var f=a.slice(e,a.length);a=a.slice(0,e)}e="GET";if(b)if(c.isFunction(b)){d=b;b=null}else if(typeof b===
|
||||
"object"){b=c.param(b,c.ajaxSettings.traditional);e="POST"}var h=this;c.ajax({url:a,type:e,dataType:"html",data:b,complete:function(l,k){if(k==="success"||k==="notmodified")h.html(f?c("<div>").append(l.responseText.replace(nb,"")).find(f):l.responseText);d&&h.each(d,[l.responseText,k,l])}});return this},serialize:function(){return c.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?c.makeArray(this.elements):this}).filter(function(){return this.name&&
|
||||
!this.disabled&&(this.checked||ob.test(this.nodeName)||pb.test(this.type))}).map(function(a,b){var d=c(this).val();return d==null?null:c.isArray(d)?c.map(d,function(e){return{name:b.name,value:e}}):{name:b.name,value:d}}).get()}});c.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){c.fn[b]=function(d){return this.bind(b,d)}});c.extend({get:function(a,b,d,e){if(c.isFunction(b)){e=e||d;d=b;b=null}return c.ajax({type:"GET",url:a,data:b,success:d,dataType:e})},
|
||||
getScript:function(a,b){return c.get(a,null,b,"script")},getJSON:function(a,b,d){return c.get(a,b,d,"json")},post:function(a,b,d,e){if(c.isFunction(b)){e=e||d;d=b;b={}}return c.ajax({type:"POST",url:a,data:b,success:d,dataType:e})},ajaxSetup:function(a){c.extend(c.ajaxSettings,a)},ajaxSettings:{url:location.href,global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,xhr:function(){return new E.XMLHttpRequest},accepts:{xml:"application/xml, text/xml",html:"text/html",
|
||||
script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},ajax:function(a){var b=c.extend(true,{},c.ajaxSettings,a),d,e,f,h=b.type.toUpperCase(),l=qb.test(h);b.url=b.url.replace(ub,"");b.context=a&&a.context!=null?a.context:b;if(b.data&&b.processData&&typeof b.data!=="string")b.data=c.param(b.data,b.traditional);if(b.dataType==="jsonp"){if(h==="GET")T.test(b.url)||(b.url+=(ja.test(b.url)?"&":"?")+(b.jsonp||"callback")+"=?");else if(!b.data||
|
||||
!T.test(b.data))b.data=(b.data?b.data+"&":"")+(b.jsonp||"callback")+"=?";b.dataType="json"}if(b.dataType==="json"&&(b.data&&T.test(b.data)||T.test(b.url))){d=b.jsonpCallback||"jsonp"+mb++;if(b.data)b.data=(b.data+"").replace(T,"="+d+"$1");b.url=b.url.replace(T,"="+d+"$1");b.dataType="script";var k=E[d];E[d]=function(m){if(c.isFunction(k))k(m);else{E[d]=B;try{delete E[d]}catch(p){}}f=m;c.handleSuccess(b,w,e,f);c.handleComplete(b,w,e,f);r&&r.removeChild(A)}}if(b.dataType==="script"&&b.cache===null)b.cache=
|
||||
false;if(b.cache===false&&l){var o=c.now(),x=b.url.replace(rb,"$1_="+o);b.url=x+(x===b.url?(ja.test(b.url)?"&":"?")+"_="+o:"")}if(b.data&&l)b.url+=(ja.test(b.url)?"&":"?")+b.data;b.global&&c.active++===0&&c.event.trigger("ajaxStart");o=(o=sb.exec(b.url))&&(o[1]&&o[1].toLowerCase()!==location.protocol||o[2].toLowerCase()!==location.host);if(b.dataType==="script"&&h==="GET"&&o){var r=t.getElementsByTagName("head")[0]||t.documentElement,A=t.createElement("script");if(b.scriptCharset)A.charset=b.scriptCharset;
|
||||
A.src=b.url;if(!d){var C=false;A.onload=A.onreadystatechange=function(){if(!C&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){C=true;c.handleSuccess(b,w,e,f);c.handleComplete(b,w,e,f);A.onload=A.onreadystatechange=null;r&&A.parentNode&&r.removeChild(A)}}}r.insertBefore(A,r.firstChild);return B}var J=false,w=b.xhr();if(w){b.username?w.open(h,b.url,b.async,b.username,b.password):w.open(h,b.url,b.async);try{if(b.data!=null&&!l||a&&a.contentType)w.setRequestHeader("Content-Type",
|
||||
b.contentType);if(b.ifModified){c.lastModified[b.url]&&w.setRequestHeader("If-Modified-Since",c.lastModified[b.url]);c.etag[b.url]&&w.setRequestHeader("If-None-Match",c.etag[b.url])}o||w.setRequestHeader("X-Requested-With","XMLHttpRequest");w.setRequestHeader("Accept",b.dataType&&b.accepts[b.dataType]?b.accepts[b.dataType]+", */*; q=0.01":b.accepts._default)}catch(I){}if(b.beforeSend&&b.beforeSend.call(b.context,w,b)===false){b.global&&c.active--===1&&c.event.trigger("ajaxStop");w.abort();return false}b.global&&
|
||||
c.triggerGlobal(b,"ajaxSend",[w,b]);var L=w.onreadystatechange=function(m){if(!w||w.readyState===0||m==="abort"){J||c.handleComplete(b,w,e,f);J=true;if(w)w.onreadystatechange=c.noop}else if(!J&&w&&(w.readyState===4||m==="timeout")){J=true;w.onreadystatechange=c.noop;e=m==="timeout"?"timeout":!c.httpSuccess(w)?"error":b.ifModified&&c.httpNotModified(w,b.url)?"notmodified":"success";var p;if(e==="success")try{f=c.httpData(w,b.dataType,b)}catch(q){e="parsererror";p=q}if(e==="success"||e==="notmodified")d||
|
||||
c.handleSuccess(b,w,e,f);else c.handleError(b,w,e,p);d||c.handleComplete(b,w,e,f);m==="timeout"&&w.abort();if(b.async)w=null}};try{var g=w.abort;w.abort=function(){w&&Function.prototype.call.call(g,w);L("abort")}}catch(i){}b.async&&b.timeout>0&&setTimeout(function(){w&&!J&&L("timeout")},b.timeout);try{w.send(l||b.data==null?null:b.data)}catch(n){c.handleError(b,w,null,n);c.handleComplete(b,w,e,f)}b.async||L();return w}},param:function(a,b){var d=[],e=function(h,l){l=c.isFunction(l)?l():l;d[d.length]=
|
||||
encodeURIComponent(h)+"="+encodeURIComponent(l)};if(b===B)b=c.ajaxSettings.traditional;if(c.isArray(a)||a.jquery)c.each(a,function(){e(this.name,this.value)});else for(var f in a)da(f,a[f],b,e);return d.join("&").replace(tb,"+")}});c.extend({active:0,lastModified:{},etag:{},handleError:function(a,b,d,e){a.error&&a.error.call(a.context,b,d,e);a.global&&c.triggerGlobal(a,"ajaxError",[b,a,e])},handleSuccess:function(a,b,d,e){a.success&&a.success.call(a.context,e,d,b);a.global&&c.triggerGlobal(a,"ajaxSuccess",
|
||||
[b,a])},handleComplete:function(a,b,d){a.complete&&a.complete.call(a.context,b,d);a.global&&c.triggerGlobal(a,"ajaxComplete",[b,a]);a.global&&c.active--===1&&c.event.trigger("ajaxStop")},triggerGlobal:function(a,b,d){(a.context&&a.context.url==null?c(a.context):c.event).trigger(b,d)},httpSuccess:function(a){try{return!a.status&&location.protocol==="file:"||a.status>=200&&a.status<300||a.status===304||a.status===1223}catch(b){}return false},httpNotModified:function(a,b){var d=a.getResponseHeader("Last-Modified"),
|
||||
e=a.getResponseHeader("Etag");if(d)c.lastModified[b]=d;if(e)c.etag[b]=e;return a.status===304},httpData:function(a,b,d){var e=a.getResponseHeader("content-type")||"",f=b==="xml"||!b&&e.indexOf("xml")>=0;a=f?a.responseXML:a.responseText;f&&a.documentElement.nodeName==="parsererror"&&c.error("parsererror");if(d&&d.dataFilter)a=d.dataFilter(a,b);if(typeof a==="string")if(b==="json"||!b&&e.indexOf("json")>=0)a=c.parseJSON(a);else if(b==="script"||!b&&e.indexOf("javascript")>=0)c.globalEval(a);return a}});
|
||||
if(E.ActiveXObject)c.ajaxSettings.xhr=function(){if(E.location.protocol!=="file:")try{return new E.XMLHttpRequest}catch(a){}try{return new E.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}};c.support.ajax=!!c.ajaxSettings.xhr();var ea={},vb=/^(?:toggle|show|hide)$/,wb=/^([+\-]=)?([\d+.\-]+)(.*)$/,ba,pa=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];c.fn.extend({show:function(a,b,d){if(a||a===0)return this.animate(S("show",
|
||||
3),a,b,d);else{d=0;for(var e=this.length;d<e;d++){a=this[d];b=a.style.display;if(!c.data(a,"olddisplay")&&b==="none")b=a.style.display="";b===""&&c.css(a,"display")==="none"&&c.data(a,"olddisplay",qa(a.nodeName))}for(d=0;d<e;d++){a=this[d];b=a.style.display;if(b===""||b==="none")a.style.display=c.data(a,"olddisplay")||""}return this}},hide:function(a,b,d){if(a||a===0)return this.animate(S("hide",3),a,b,d);else{a=0;for(b=this.length;a<b;a++){d=c.css(this[a],"display");d!=="none"&&c.data(this[a],"olddisplay",
|
||||
d)}for(a=0;a<b;a++)this[a].style.display="none";return this}},_toggle:c.fn.toggle,toggle:function(a,b,d){var e=typeof a==="boolean";if(c.isFunction(a)&&c.isFunction(b))this._toggle.apply(this,arguments);else a==null||e?this.each(function(){var f=e?a:c(this).is(":hidden");c(this)[f?"show":"hide"]()}):this.animate(S("toggle",3),a,b,d);return this},fadeTo:function(a,b,d,e){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,d,e)},animate:function(a,b,d,e){var f=c.speed(b,
|
||||
d,e);if(c.isEmptyObject(a))return this.each(f.complete);return this[f.queue===false?"each":"queue"](function(){var h=c.extend({},f),l,k=this.nodeType===1,o=k&&c(this).is(":hidden"),x=this;for(l in a){var r=c.camelCase(l);if(l!==r){a[r]=a[l];delete a[l];l=r}if(a[l]==="hide"&&o||a[l]==="show"&&!o)return h.complete.call(this);if(k&&(l==="height"||l==="width")){h.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY];if(c.css(this,"display")==="inline"&&c.css(this,"float")==="none")if(c.support.inlineBlockNeedsLayout)if(qa(this.nodeName)===
|
||||
"inline")this.style.display="inline-block";else{this.style.display="inline";this.style.zoom=1}else this.style.display="inline-block"}if(c.isArray(a[l])){(h.specialEasing=h.specialEasing||{})[l]=a[l][1];a[l]=a[l][0]}}if(h.overflow!=null)this.style.overflow="hidden";h.curAnim=c.extend({},a);c.each(a,function(A,C){var J=new c.fx(x,h,A);if(vb.test(C))J[C==="toggle"?o?"show":"hide":C](a);else{var w=wb.exec(C),I=J.cur()||0;if(w){var L=parseFloat(w[2]),g=w[3]||"px";if(g!=="px"){c.style(x,A,(L||1)+g);I=(L||
|
||||
1)/J.cur()*I;c.style(x,A,I+g)}if(w[1])L=(w[1]==="-="?-1:1)*L+I;J.custom(I,L,g)}else J.custom(I,C,"")}});return true})},stop:function(a,b){var d=c.timers;a&&this.queue([]);this.each(function(){for(var e=d.length-1;e>=0;e--)if(d[e].elem===this){b&&d[e](true);d.splice(e,1)}});b||this.dequeue();return this}});c.each({slideDown:S("show",1),slideUp:S("hide",1),slideToggle:S("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){c.fn[a]=function(d,e,f){return this.animate(b,
|
||||
d,e,f)}});c.extend({speed:function(a,b,d){var e=a&&typeof a==="object"?c.extend({},a):{complete:d||!d&&b||c.isFunction(a)&&a,duration:a,easing:d&&b||b&&!c.isFunction(b)&&b};e.duration=c.fx.off?0:typeof e.duration==="number"?e.duration:e.duration in c.fx.speeds?c.fx.speeds[e.duration]:c.fx.speeds._default;e.old=e.complete;e.complete=function(){e.queue!==false&&c(this).dequeue();c.isFunction(e.old)&&e.old.call(this)};return e},easing:{linear:function(a,b,d,e){return d+e*a},swing:function(a,b,d,e){return(-Math.cos(a*
|
||||
Math.PI)/2+0.5)*e+d}},timers:[],fx:function(a,b,d){this.options=b;this.elem=a;this.prop=d;if(!b.orig)b.orig={}}});c.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this);(c.fx.step[this.prop]||c.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a=parseFloat(c.css(this.elem,this.prop));return a&&a>-1E4?a:0},custom:function(a,b,d){function e(l){return f.step(l)}
|
||||
var f=this,h=c.fx;this.startTime=c.now();this.start=a;this.end=b;this.unit=d||this.unit||"px";this.now=this.start;this.pos=this.state=0;e.elem=this.elem;if(e()&&c.timers.push(e)&&!ba)ba=setInterval(h.tick,h.interval)},show:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.show=true;this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur());c(this.elem).show()},hide:function(){this.options.orig[this.prop]=c.style(this.elem,this.prop);this.options.hide=true;
|
||||
this.custom(this.cur(),0)},step:function(a){var b=c.now(),d=true;if(a||b>=this.options.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;for(var e in this.options.curAnim)if(this.options.curAnim[e]!==true)d=false;if(d){if(this.options.overflow!=null&&!c.support.shrinkWrapBlocks){var f=this.elem,h=this.options;c.each(["","X","Y"],function(k,o){f.style["overflow"+o]=h.overflow[k]})}this.options.hide&&c(this.elem).hide();if(this.options.hide||
|
||||
this.options.show)for(var l in this.options.curAnim)c.style(this.elem,l,this.options.orig[l]);this.options.complete.call(this.elem)}return false}else{a=b-this.startTime;this.state=a/this.options.duration;b=this.options.easing||(c.easing.swing?"swing":"linear");this.pos=c.easing[this.options.specialEasing&&this.options.specialEasing[this.prop]||b](this.state,a,0,1,this.options.duration);this.now=this.start+(this.end-this.start)*this.pos;this.update()}return true}};c.extend(c.fx,{tick:function(){for(var a=
|
||||
c.timers,b=0;b<a.length;b++)a[b]()||a.splice(b--,1);a.length||c.fx.stop()},interval:13,stop:function(){clearInterval(ba);ba=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){c.style(a.elem,"opacity",a.now)},_default:function(a){if(a.elem.style&&a.elem.style[a.prop]!=null)a.elem.style[a.prop]=(a.prop==="width"||a.prop==="height"?Math.max(0,a.now):a.now)+a.unit;else a.elem[a.prop]=a.now}}});if(c.expr&&c.expr.filters)c.expr.filters.animated=function(a){return c.grep(c.timers,function(b){return a===
|
||||
b.elem}).length};var xb=/^t(?:able|d|h)$/i,Ia=/^(?:body|html)$/i;c.fn.offset="getBoundingClientRect"in t.documentElement?function(a){var b=this[0],d;if(a)return this.each(function(l){c.offset.setOffset(this,a,l)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);try{d=b.getBoundingClientRect()}catch(e){}var f=b.ownerDocument,h=f.documentElement;if(!d||!c.contains(h,b))return d||{top:0,left:0};b=f.body;f=fa(f);return{top:d.top+(f.pageYOffset||c.support.boxModel&&
|
||||
h.scrollTop||b.scrollTop)-(h.clientTop||b.clientTop||0),left:d.left+(f.pageXOffset||c.support.boxModel&&h.scrollLeft||b.scrollLeft)-(h.clientLeft||b.clientLeft||0)}}:function(a){var b=this[0];if(a)return this.each(function(x){c.offset.setOffset(this,a,x)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return c.offset.bodyOffset(b);c.offset.initialize();var d,e=b.offsetParent,f=b.ownerDocument,h=f.documentElement,l=f.body;d=(f=f.defaultView)?f.getComputedStyle(b,null):b.currentStyle;
|
||||
for(var k=b.offsetTop,o=b.offsetLeft;(b=b.parentNode)&&b!==l&&b!==h;){if(c.offset.supportsFixedPosition&&d.position==="fixed")break;d=f?f.getComputedStyle(b,null):b.currentStyle;k-=b.scrollTop;o-=b.scrollLeft;if(b===e){k+=b.offsetTop;o+=b.offsetLeft;if(c.offset.doesNotAddBorder&&!(c.offset.doesAddBorderForTableAndCells&&xb.test(b.nodeName))){k+=parseFloat(d.borderTopWidth)||0;o+=parseFloat(d.borderLeftWidth)||0}e=b.offsetParent}if(c.offset.subtractsBorderForOverflowNotVisible&&d.overflow!=="visible"){k+=
|
||||
parseFloat(d.borderTopWidth)||0;o+=parseFloat(d.borderLeftWidth)||0}d=d}if(d.position==="relative"||d.position==="static"){k+=l.offsetTop;o+=l.offsetLeft}if(c.offset.supportsFixedPosition&&d.position==="fixed"){k+=Math.max(h.scrollTop,l.scrollTop);o+=Math.max(h.scrollLeft,l.scrollLeft)}return{top:k,left:o}};c.offset={initialize:function(){var a=t.body,b=t.createElement("div"),d,e,f,h=parseFloat(c.css(a,"marginTop"))||0;c.extend(b.style,{position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",
|
||||
height:"1px",visibility:"hidden"});b.innerHTML="<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>";a.insertBefore(b,a.firstChild);d=b.firstChild;e=d.firstChild;f=d.nextSibling.firstChild.firstChild;this.doesNotAddBorder=e.offsetTop!==5;this.doesAddBorderForTableAndCells=
|
||||
f.offsetTop===5;e.style.position="fixed";e.style.top="20px";this.supportsFixedPosition=e.offsetTop===20||e.offsetTop===15;e.style.position=e.style.top="";d.style.overflow="hidden";d.style.position="relative";this.subtractsBorderForOverflowNotVisible=e.offsetTop===-5;this.doesNotIncludeMarginInBodyOffset=a.offsetTop!==h;a.removeChild(b);c.offset.initialize=c.noop},bodyOffset:function(a){var b=a.offsetTop,d=a.offsetLeft;c.offset.initialize();if(c.offset.doesNotIncludeMarginInBodyOffset){b+=parseFloat(c.css(a,
|
||||
"marginTop"))||0;d+=parseFloat(c.css(a,"marginLeft"))||0}return{top:b,left:d}},setOffset:function(a,b,d){var e=c.css(a,"position");if(e==="static")a.style.position="relative";var f=c(a),h=f.offset(),l=c.css(a,"top"),k=c.css(a,"left"),o=e==="absolute"&&c.inArray("auto",[l,k])>-1;e={};var x={};if(o)x=f.position();l=o?x.top:parseInt(l,10)||0;k=o?x.left:parseInt(k,10)||0;if(c.isFunction(b))b=b.call(a,d,h);if(b.top!=null)e.top=b.top-h.top+l;if(b.left!=null)e.left=b.left-h.left+k;"using"in b?b.using.call(a,
|
||||
e):f.css(e)}};c.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),d=this.offset(),e=Ia.test(b[0].nodeName)?{top:0,left:0}:b.offset();d.top-=parseFloat(c.css(a,"marginTop"))||0;d.left-=parseFloat(c.css(a,"marginLeft"))||0;e.top+=parseFloat(c.css(b[0],"borderTopWidth"))||0;e.left+=parseFloat(c.css(b[0],"borderLeftWidth"))||0;return{top:d.top-e.top,left:d.left-e.left}},offsetParent:function(){return this.map(function(){for(var a=this.offsetParent||t.body;a&&!Ia.test(a.nodeName)&&
|
||||
c.css(a,"position")==="static";)a=a.offsetParent;return a})}});c.each(["Left","Top"],function(a,b){var d="scroll"+b;c.fn[d]=function(e){var f=this[0],h;if(!f)return null;if(e!==B)return this.each(function(){if(h=fa(this))h.scrollTo(!a?e:c(h).scrollLeft(),a?e:c(h).scrollTop());else this[d]=e});else return(h=fa(f))?"pageXOffset"in h?h[a?"pageYOffset":"pageXOffset"]:c.support.boxModel&&h.document.documentElement[d]||h.document.body[d]:f[d]}});c.each(["Height","Width"],function(a,b){var d=b.toLowerCase();
|
||||
c.fn["inner"+b]=function(){return this[0]?parseFloat(c.css(this[0],d,"padding")):null};c.fn["outer"+b]=function(e){return this[0]?parseFloat(c.css(this[0],d,e?"margin":"border")):null};c.fn[d]=function(e){var f=this[0];if(!f)return e==null?null:this;if(c.isFunction(e))return this.each(function(l){var k=c(this);k[d](e.call(this,l,k[d]()))});if(c.isWindow(f))return f.document.compatMode==="CSS1Compat"&&f.document.documentElement["client"+b]||f.document.body["client"+b];else if(f.nodeType===9)return Math.max(f.documentElement["client"+
|
||||
b],f.body["scroll"+b],f.documentElement["scroll"+b],f.body["offset"+b],f.documentElement["offset"+b]);else if(e===B){f=c.css(f,d);var h=parseFloat(f);return c.isNaN(h)?f:h}else return this.css(d,typeof e==="string"?e:e+"px")}})})(window);
|
4
js/jquery.min.js
vendored
Normal file
576
js/niceforms.js
@ -1,576 +0,0 @@
|
||||
/*#############################################################
|
||||
Name: Niceforms
|
||||
Version: 2.0
|
||||
Author: Lucian Slatineanu
|
||||
URL: http://www.emblematiq.com/projects/niceforms/
|
||||
|
||||
Feel free to use and modify but please keep this copyright intact.
|
||||
#################################################################*/
|
||||
|
||||
//Theme Variables - edit these to match your theme
|
||||
var imagesPath = "images/niceforms/";
|
||||
var selectRightWidthSimple = 19;
|
||||
var selectRightWidthScroll = 2;
|
||||
var selectMaxHeight = 200;
|
||||
var textareaTopPadding = 10;
|
||||
var textareaSidePadding = 10;
|
||||
|
||||
//Global Variables
|
||||
var NF = new Array();
|
||||
var isIE = false;
|
||||
var resizeTest = 1;
|
||||
|
||||
//Initialization function
|
||||
function NFInit() {
|
||||
try {
|
||||
document.execCommand('BackgroundImageCache', false, true);
|
||||
} catch(e) {}
|
||||
if(!document.getElementById) {return false;}
|
||||
//alert("click me first");
|
||||
NFDo('start');
|
||||
}
|
||||
function NFDo(what) {
|
||||
var niceforms = document.getElementsByTagName('form');
|
||||
var identifier = new RegExp('(^| )'+'niceform'+'( |$)');
|
||||
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
|
||||
var ieversion=new Number(RegExp.$1);
|
||||
if(ieversion < 7) {return false;} //exit script if IE6
|
||||
isIE = true;
|
||||
}
|
||||
for(var q = 0; q < niceforms.length; q++) {if(identifier.test(niceforms[q].className)) {
|
||||
if(what == "start") { //Load Niceforms
|
||||
NF[q] = new niceform(niceforms[q]);
|
||||
niceforms[q].start();
|
||||
}
|
||||
else { //Unload Niceforms
|
||||
niceforms[q].unload();
|
||||
NF[q] = "";
|
||||
}
|
||||
}}
|
||||
}
|
||||
function NFFix() {
|
||||
NFDo('stop');
|
||||
NFDo('start');
|
||||
}
|
||||
function niceform(nf) {
|
||||
nf._inputText = new Array(); nf._inputRadio = new Array(); nf._inputCheck = new Array(); nf._inputSubmit = new Array(); nf._inputFile = new Array(); nf._textarea = new Array(); nf._select = new Array(); nf._multiselect = new Array();
|
||||
nf.add_inputText = function(obj) {this._inputText[this._inputText.length] = obj; inputText(obj);}
|
||||
nf.add_inputRadio = function(obj) {this._inputRadio[this._inputRadio.length] = obj; inputRadio(obj);}
|
||||
nf.add_inputCheck = function(obj) {this._inputCheck[this._inputCheck.length] = obj; inputCheck(obj);}
|
||||
nf.add_inputSubmit = function(obj) {this._inputSubmit[this._inputSubmit.length] = obj; inputSubmit(obj);}
|
||||
nf.add_inputFile = function(obj) {this._inputFile[this._inputFile.length] = obj; inputFile(obj);}
|
||||
nf.add_textarea = function(obj) {this._textarea[this._textarea.length] = obj; textarea(obj);}
|
||||
nf.add_select = function(obj) {this._select[this._select.length] = obj; selects(obj);}
|
||||
nf.add_multiselect = function(obj) {this._multiselect[this._multiselect.length] = obj; multiSelects(obj);}
|
||||
nf.start = function() {
|
||||
//Separate and assign elements
|
||||
var allInputs = this.getElementsByTagName('input');
|
||||
for(var w = 0; w < allInputs.length; w++) {
|
||||
switch(allInputs[w].type) {
|
||||
case "text": case "password": {this.add_inputText(allInputs[w]); break;}
|
||||
case "radio": {this.add_inputRadio(allInputs[w]); break;}
|
||||
case "checkbox": {this.add_inputCheck(allInputs[w]); break;}
|
||||
case "submit": case "reset": case "button": {this.add_inputSubmit(allInputs[w]); break;}
|
||||
case "file": {this.add_inputFile(allInputs[w]); break;}
|
||||
}
|
||||
}
|
||||
var allButtons = this.getElementsByTagName('button');
|
||||
for(var w = 0; w < allButtons.length; w++) {
|
||||
this.add_inputSubmit(allButtons[w]);
|
||||
}
|
||||
var allTextareas = this.getElementsByTagName('textarea');
|
||||
for(var w = 0; w < allTextareas.length; w++) {
|
||||
this.add_textarea(allTextareas[w]);
|
||||
}
|
||||
var allSelects = this.getElementsByTagName('select');
|
||||
for(var w = 0; w < allSelects.length; w++) {
|
||||
if(allSelects[w].size == "1") {this.add_select(allSelects[w]);}
|
||||
else {this.add_multiselect(allSelects[w]);}
|
||||
}
|
||||
//Start
|
||||
for(w = 0; w < this._inputText.length; w++) {this._inputText[w].init();}
|
||||
for(w = 0; w < this._inputRadio.length; w++) {this._inputRadio[w].init();}
|
||||
for(w = 0; w < this._inputCheck.length; w++) {this._inputCheck[w].init();}
|
||||
for(w = 0; w < this._inputSubmit.length; w++) {this._inputSubmit[w].init();}
|
||||
for(w = 0; w < this._inputFile.length; w++) {this._inputFile[w].init();}
|
||||
for(w = 0; w < this._textarea.length; w++) {this._textarea[w].init();}
|
||||
for(w = 0; w < this._select.length; w++) {this._select[w].init(w);}
|
||||
for(w = 0; w < this._multiselect.length; w++) {this._multiselect[w].init(w);}
|
||||
}
|
||||
nf.unload = function() {
|
||||
//Stop
|
||||
for(w = 0; w < this._inputText.length; w++) {this._inputText[w].unload();}
|
||||
for(w = 0; w < this._inputRadio.length; w++) {this._inputRadio[w].unload();}
|
||||
for(w = 0; w < this._inputCheck.length; w++) {this._inputCheck[w].unload();}
|
||||
for(w = 0; w < this._inputSubmit.length; w++) {this._inputSubmit[w].unload();}
|
||||
for(w = 0; w < this._inputFile.length; w++) {this._inputFile[w].unload();}
|
||||
for(w = 0; w < this._textarea.length; w++) {this._textarea[w].unload();}
|
||||
for(w = 0; w < this._select.length; w++) {this._select[w].unload();}
|
||||
for(w = 0; w < this._multiselect.length; w++) {this._multiselect[w].unload();}
|
||||
}
|
||||
}
|
||||
function inputText(el) { //extent Text inputs
|
||||
el.oldClassName = el.className;
|
||||
el.left = document.createElement('img');
|
||||
el.left.src = imagesPath + "0.png";
|
||||
el.left.className = "NFTextLeft";
|
||||
el.right = document.createElement('img');
|
||||
el.right.src = imagesPath + "0.png";
|
||||
el.right.className = "NFTextRight";
|
||||
el.dummy = document.createElement('div');
|
||||
el.dummy.className = "NFTextCenter";
|
||||
el.onfocus = function() {
|
||||
this.dummy.className = "NFTextCenter NFh";
|
||||
this.left.className = "NFTextLeft NFh";
|
||||
this.right.className = "NFTextRight NFh";
|
||||
}
|
||||
el.onblur = function() {
|
||||
this.dummy.className = "NFTextCenter";
|
||||
this.left.className = "NFTextLeft";
|
||||
this.right.className = "NFTextRight";
|
||||
}
|
||||
el.init = function() {
|
||||
this.parentNode.insertBefore(this.left, this);
|
||||
this.parentNode.insertBefore(this.right, this.nextSibling);
|
||||
this.dummy.appendChild(this);
|
||||
this.right.parentNode.insertBefore(this.dummy, this.right);
|
||||
this.className = "NFText";
|
||||
}
|
||||
el.unload = function() {
|
||||
this.parentNode.parentNode.appendChild(this);
|
||||
this.parentNode.removeChild(this.left);
|
||||
this.parentNode.removeChild(this.right);
|
||||
this.parentNode.removeChild(this.dummy);
|
||||
this.className = this.oldClassName;
|
||||
}
|
||||
}
|
||||
function inputRadio(el) { //extent Radio buttons
|
||||
el.oldClassName = el.className;
|
||||
el.dummy = document.createElement('div');
|
||||
if(el.checked) {el.dummy.className = "NFRadio NFh";}
|
||||
else {el.dummy.className = "NFRadio";}
|
||||
el.dummy.ref = el;
|
||||
if(isIE == false) {el.dummy.style.left = findPosX(el) + 'px'; el.dummy.style.top = findPosY(el) + 'px';}
|
||||
else {el.dummy.style.left = findPosX(el) + 4 + 'px'; el.dummy.style.top = findPosY(el) + 4 + 'px';}
|
||||
el.dummy.onclick = function() {
|
||||
if(!this.ref.checked) {
|
||||
var siblings = getInputsByName(this.ref.name);
|
||||
for(var q = 0; q < siblings.length; q++) {
|
||||
siblings[q].checked = false;
|
||||
siblings[q].dummy.className = "NFRadio";
|
||||
}
|
||||
this.ref.checked = true;
|
||||
this.className = "NFRadio NFh";
|
||||
}
|
||||
}
|
||||
el.onclick = function() {
|
||||
if(this.checked) {
|
||||
var siblings = getInputsByName(this.name);
|
||||
for(var q = 0; q < siblings.length; q++) {
|
||||
siblings[q].dummy.className = "NFRadio";
|
||||
}
|
||||
this.dummy.className = "NFRadio NFh";
|
||||
}
|
||||
}
|
||||
el.onfocus = function() {this.dummy.className += " NFfocused";}
|
||||
el.onblur = function() {this.dummy.className = this.dummy.className.replace(/ NFfocused/g, "");}
|
||||
el.init = function() {
|
||||
this.parentNode.insertBefore(this.dummy, this);
|
||||
el.className = "NFhidden";
|
||||
}
|
||||
el.unload = function() {
|
||||
this.parentNode.removeChild(this.dummy);
|
||||
this.className = this.oldClassName;
|
||||
}
|
||||
}
|
||||
function inputCheck(el) { //extend Checkboxes
|
||||
el.oldClassName = el.className;
|
||||
el.dummy = document.createElement('img');
|
||||
el.dummy.src = imagesPath + "0.png";
|
||||
if(el.checked) {el.dummy.className = "NFCheck NFh";}
|
||||
else {el.dummy.className = "NFCheck";}
|
||||
el.dummy.ref = el;
|
||||
if(isIE == false) {el.dummy.style.left = findPosX(el) + 'px'; el.dummy.style.top = findPosY(el) + 'px';}
|
||||
else {el.dummy.style.left = findPosX(el) + 4 + 'px'; el.dummy.style.top = findPosY(el) + 4 + 'px';}
|
||||
el.dummy.onclick = function() {
|
||||
if(!this.ref.checked) {
|
||||
this.ref.checked = true;
|
||||
this.className = "NFCheck NFh";
|
||||
}
|
||||
else {
|
||||
this.ref.checked = false;
|
||||
this.className = "NFCheck";
|
||||
}
|
||||
}
|
||||
el.onclick = function() {
|
||||
if(this.checked) {this.dummy.className = "NFCheck NFh";}
|
||||
else {this.dummy.className = "NFCheck";}
|
||||
}
|
||||
el.onfocus = function() {this.dummy.className += " NFfocused";}
|
||||
el.onblur = function() {this.dummy.className = this.dummy.className.replace(/ NFfocused/g, "");}
|
||||
el.init = function() {
|
||||
this.parentNode.insertBefore(this.dummy, this);
|
||||
el.className = "NFhidden";
|
||||
}
|
||||
el.unload = function() {
|
||||
this.parentNode.removeChild(this.dummy);
|
||||
this.className = this.oldClassName;
|
||||
}
|
||||
}
|
||||
function inputSubmit(el) { //extend Buttons
|
||||
el.oldClassName = el.className;
|
||||
el.left = document.createElement('img');
|
||||
el.left.className = "NFButtonLeft";
|
||||
el.left.src = imagesPath + "0.png";
|
||||
el.right = document.createElement('img');
|
||||
el.right.src = imagesPath + "0.png";
|
||||
el.right.className = "NFButtonRight";
|
||||
el.onmouseover = function() {
|
||||
this.className = "NFButton NFh";
|
||||
this.left.className = "NFButtonLeft NFh";
|
||||
this.right.className = "NFButtonRight NFh";
|
||||
}
|
||||
el.onmouseout = function() {
|
||||
this.className = "NFButton";
|
||||
this.left.className = "NFButtonLeft";
|
||||
this.right.className = "NFButtonRight";
|
||||
}
|
||||
el.init = function() {
|
||||
this.parentNode.insertBefore(this.left, this);
|
||||
this.parentNode.insertBefore(this.right, this.nextSibling);
|
||||
this.className = "NFButton";
|
||||
}
|
||||
el.unload = function() {
|
||||
this.parentNode.removeChild(this.left);
|
||||
this.parentNode.removeChild(this.right);
|
||||
this.className = this.oldClassName;
|
||||
}
|
||||
}
|
||||
function inputFile(el) { //extend File inputs
|
||||
el.oldClassName = el.className;
|
||||
el.dummy = document.createElement('div');
|
||||
el.dummy.className = "NFFile";
|
||||
el.file = document.createElement('div');
|
||||
el.file.className = "NFFileNew";
|
||||
el.center = document.createElement('div');
|
||||
el.center.className = "NFTextCenter";
|
||||
el.clone = document.createElement('input');
|
||||
el.clone.type = "text";
|
||||
el.clone.className = "NFText";
|
||||
el.clone.ref = el;
|
||||
el.left = document.createElement('img');
|
||||
el.left.src = imagesPath + "0.png";
|
||||
el.left.className = "NFTextLeft";
|
||||
el.button = document.createElement('img');
|
||||
el.button.src = imagesPath + "0.png";
|
||||
el.button.className = "NFFileButton";
|
||||
el.button.ref = el;
|
||||
el.button.onclick = function() {this.ref.click();}
|
||||
el.init = function() {
|
||||
var top = this.parentNode;
|
||||
if(this.previousSibling) {var where = this.previousSibling;}
|
||||
else {var where = top.childNodes[0];}
|
||||
top.insertBefore(this.dummy, where);
|
||||
this.dummy.appendChild(this);
|
||||
this.center.appendChild(this.clone);
|
||||
this.file.appendChild(this.center);
|
||||
this.file.insertBefore(this.left, this.center);
|
||||
this.file.appendChild(this.button);
|
||||
this.dummy.appendChild(this.file);
|
||||
this.className = "NFhidden";
|
||||
this.relatedElement = this.clone;
|
||||
}
|
||||
el.unload = function() {
|
||||
this.parentNode.parentNode.appendChild(this);
|
||||
this.parentNode.removeChild(this.dummy);
|
||||
this.className = this.oldClassName;
|
||||
}
|
||||
el.onchange = el.onmouseout = function() {this.relatedElement.value = this.value;}
|
||||
el.onfocus = function() {
|
||||
this.left.className = "NFTextLeft NFh";
|
||||
this.center.className = "NFTextCenter NFh";
|
||||
this.button.className = "NFFileButton NFh";
|
||||
}
|
||||
el.onblur = function() {
|
||||
this.left.className = "NFTextLeft";
|
||||
this.center.className = "NFTextCenter";
|
||||
this.button.className = "NFFileButton";
|
||||
}
|
||||
el.onselect = function() {
|
||||
this.relatedElement.select();
|
||||
this.value = '';
|
||||
}
|
||||
}
|
||||
function textarea(el) { //extend Textareas
|
||||
el.oldClassName = el.className;
|
||||
el.height = el.offsetHeight - textareaTopPadding;
|
||||
el.width = el.offsetWidth - textareaSidePadding;
|
||||
el.topLeft = document.createElement('img');
|
||||
el.topLeft.src = imagesPath + "0.png";
|
||||
el.topLeft.className = "NFTextareaTopLeft";
|
||||
el.topRight = document.createElement('div');
|
||||
el.topRight.className = "NFTextareaTop";
|
||||
el.bottomLeft = document.createElement('img');
|
||||
el.bottomLeft.src = imagesPath + "0.png";
|
||||
el.bottomLeft.className = "NFTextareaBottomLeft";
|
||||
el.bottomRight = document.createElement('div');
|
||||
el.bottomRight.className = "NFTextareaBottom";
|
||||
el.left = document.createElement('div');
|
||||
el.left.className = "NFTextareaLeft";
|
||||
el.right = document.createElement('div');
|
||||
el.right.className = "NFTextareaRight";
|
||||
el.init = function() {
|
||||
var top = this.parentNode;
|
||||
if(this.previousSibling) {var where = this.previousSibling;}
|
||||
else {var where = top.childNodes[0];}
|
||||
top.insertBefore(el.topRight, where);
|
||||
top.insertBefore(el.right, where);
|
||||
top.insertBefore(el.bottomRight, where);
|
||||
this.topRight.appendChild(this.topLeft);
|
||||
this.right.appendChild(this.left);
|
||||
this.right.appendChild(this);
|
||||
this.bottomRight.appendChild(this.bottomLeft);
|
||||
el.style.width = el.topRight.style.width = el.bottomRight.style.width = el.width + 'px';
|
||||
el.style.height = el.left.style.height = el.right.style.height = el.height + 'px';
|
||||
this.className = "NFTextarea";
|
||||
}
|
||||
el.unload = function() {
|
||||
this.parentNode.parentNode.appendChild(this);
|
||||
this.parentNode.removeChild(this.topRight);
|
||||
this.parentNode.removeChild(this.bottomRight);
|
||||
this.parentNode.removeChild(this.right);
|
||||
this.className = this.oldClassName;
|
||||
this.style.width = this.style.height = "";
|
||||
}
|
||||
el.onfocus = function() {
|
||||
this.topLeft.className = "NFTextareaTopLeft NFh";
|
||||
this.topRight.className = "NFTextareaTop NFhr";
|
||||
this.left.className = "NFTextareaLeftH";
|
||||
this.right.className = "NFTextareaRightH";
|
||||
this.bottomLeft.className = "NFTextareaBottomLeft NFh";
|
||||
this.bottomRight.className = "NFTextareaBottom NFhr";
|
||||
}
|
||||
el.onblur = function() {
|
||||
this.topLeft.className = "NFTextareaTopLeft";
|
||||
this.topRight.className = "NFTextareaTop";
|
||||
this.left.className = "NFTextareaLeft";
|
||||
this.right.className = "NFTextareaRight";
|
||||
this.bottomLeft.className = "NFTextareaBottomLeft";
|
||||
this.bottomRight.className = "NFTextareaBottom";
|
||||
}
|
||||
}
|
||||
function selects(el) { //extend Selects
|
||||
el.oldClassName = el.className;
|
||||
el.dummy = document.createElement('div');
|
||||
el.dummy.className = "NFSelect";
|
||||
el.dummy.style.width = el.offsetWidth + 'px';
|
||||
el.dummy.ref = el;
|
||||
el.left = document.createElement('img');
|
||||
el.left.src = imagesPath + "0.png";
|
||||
el.left.className = "NFSelectLeft";
|
||||
el.right = document.createElement('div');
|
||||
el.right.className = "NFSelectRight";
|
||||
el.txt = document.createTextNode(el.options[0].text);
|
||||
el.bg = document.createElement('div');
|
||||
el.bg.className = "NFSelectTarget";
|
||||
el.bg.style.display = "none";
|
||||
el.opt = document.createElement('ul');
|
||||
el.opt.className = "NFSelectOptions";
|
||||
el.dummy.style.left = findPosX(el) + 'px';
|
||||
el.dummy.style.top = findPosY(el) + 'px';
|
||||
el.opts = new Array(el.options.length);
|
||||
el.init = function(pos) {
|
||||
this.dummy.appendChild(this.left);
|
||||
this.right.appendChild(this.txt);
|
||||
this.dummy.appendChild(this.right);
|
||||
this.bg.appendChild(this.opt);
|
||||
this.dummy.appendChild(this.bg);
|
||||
for(var q = 0; q < this.options.length; q++) {
|
||||
this.opts[q] = new option(this.options[q], q);
|
||||
this.opt.appendChild(this.options[q].li);
|
||||
this.options[q].lnk.onclick = function() {
|
||||
this._onclick();
|
||||
this.ref.dummy.getElementsByTagName('div')[0].innerHTML = this.ref.options[this.pos].text;
|
||||
this.ref.options[this.pos].selected = "selected";
|
||||
for(var w = 0; w < this.ref.options.length; w++) {this.ref.options[w].lnk.className = "";}
|
||||
this.ref.options[this.pos].lnk.className = "NFOptionActive";
|
||||
}
|
||||
}
|
||||
if(this.options.selectedIndex) {
|
||||
this.dummy.getElementsByTagName('div')[0].innerHTML = this.options[this.options.selectedIndex].text;
|
||||
this.options[this.options.selectedIndex].lnk.className = "NFOptionActive";
|
||||
}
|
||||
this.dummy.style.zIndex = 999 - pos;
|
||||
this.parentNode.insertBefore(this.dummy, this);
|
||||
this.className = "NFhidden";
|
||||
}
|
||||
el.unload = function() {
|
||||
this.parentNode.removeChild(this.dummy);
|
||||
this.className = this.oldClassName;
|
||||
}
|
||||
el.dummy.onclick = function() {
|
||||
var allDivs = document.getElementsByTagName('div'); for(var q = 0; q < allDivs.length; q++) {if((allDivs[q].className == "NFSelectTarget") && (allDivs[q] != this.ref.bg)) {allDivs[q].style.display = "none";}}
|
||||
if(this.ref.bg.style.display == "none") {this.ref.bg.style.display = "block";}
|
||||
else {this.ref.bg.style.display = "none";}
|
||||
if(this.ref.opt.offsetHeight > selectMaxHeight) {
|
||||
this.ref.bg.style.width = this.ref.offsetWidth - selectRightWidthScroll + 33 + 'px';
|
||||
this.ref.opt.style.width = this.ref.offsetWidth - selectRightWidthScroll + 'px';
|
||||
}
|
||||
else {
|
||||
this.ref.bg.style.width = this.ref.offsetWidth - selectRightWidthSimple + 33 + 'px';
|
||||
this.ref.opt.style.width = this.ref.offsetWidth - selectRightWidthSimple + 'px';
|
||||
}
|
||||
}
|
||||
el.bg.onmouseout = function(e) {
|
||||
if (!e) var e = window.event;
|
||||
e.cancelBubble = true;
|
||||
if (e.stopPropagation) e.stopPropagation();
|
||||
var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
|
||||
if((reltg.nodeName == 'A') || (reltg.nodeName == 'LI') || (reltg.nodeName == 'UL')) return;
|
||||
if((reltg.nodeName == 'DIV') || (reltg.className == 'NFSelectTarget')) return;
|
||||
else{this.style.display = "none";}
|
||||
}
|
||||
el.dummy.onmouseout = function(e) {
|
||||
if (!e) var e = window.event;
|
||||
e.cancelBubble = true;
|
||||
if (e.stopPropagation) e.stopPropagation();
|
||||
var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
|
||||
if((reltg.nodeName == 'A') || (reltg.nodeName == 'LI') || (reltg.nodeName == 'UL')) return;
|
||||
if((reltg.nodeName == 'DIV') || (reltg.className == 'NFSelectTarget')) return;
|
||||
else{this.ref.bg.style.display = "none";}
|
||||
}
|
||||
el.onfocus = function() {this.dummy.className += " NFfocused";}
|
||||
el.onblur = function() {this.dummy.className = this.dummy.className.replace(/ NFfocused/g, "");}
|
||||
el.onkeydown = function(e) {
|
||||
if (!e) var e = window.event;
|
||||
var thecode = e.keyCode;
|
||||
var active = this.selectedIndex;
|
||||
switch(thecode){
|
||||
case 40: //down
|
||||
if(active < this.options.length - 1) {
|
||||
for(var w = 0; w < this.options.length; w++) {this.options[w].lnk.className = "";}
|
||||
var newOne = active + 1;
|
||||
this.options[newOne].selected = "selected";
|
||||
this.options[newOne].lnk.className = "NFOptionActive";
|
||||
this.dummy.getElementsByTagName('div')[0].innerHTML = this.options[newOne].text;
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case 38: //up
|
||||
if(active > 0) {
|
||||
for(var w = 0; w < this.options.length; w++) {this.options[w].lnk.className = "";}
|
||||
var newOne = active - 1;
|
||||
this.options[newOne].selected = "selected";
|
||||
this.options[newOne].lnk.className = "NFOptionActive";
|
||||
this.dummy.getElementsByTagName('div')[0].innerHTML = this.options[newOne].text;
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
function multiSelects(el) { //extend Multiple Selects
|
||||
el.oldClassName = el.className;
|
||||
el.height = el.offsetHeight;
|
||||
el.width = el.offsetWidth;
|
||||
el.topLeft = document.createElement('img');
|
||||
el.topLeft.src = imagesPath + "0.png";
|
||||
el.topLeft.className = "NFMultiSelectTopLeft";
|
||||
el.topRight = document.createElement('div');
|
||||
el.topRight.className = "NFMultiSelectTop";
|
||||
el.bottomLeft = document.createElement('img');
|
||||
el.bottomLeft.src = imagesPath + "0.png";
|
||||
el.bottomLeft.className = "NFMultiSelectBottomLeft";
|
||||
el.bottomRight = document.createElement('div');
|
||||
el.bottomRight.className = "NFMultiSelectBottom";
|
||||
el.left = document.createElement('div');
|
||||
el.left.className = "NFMultiSelectLeft";
|
||||
el.right = document.createElement('div');
|
||||
el.right.className = "NFMultiSelectRight";
|
||||
el.init = function() {
|
||||
var top = this.parentNode;
|
||||
if(this.previousSibling) {var where = this.previousSibling;}
|
||||
else {var where = top.childNodes[0];}
|
||||
top.insertBefore(el.topRight, where);
|
||||
top.insertBefore(el.right, where);
|
||||
top.insertBefore(el.bottomRight, where);
|
||||
this.topRight.appendChild(this.topLeft);
|
||||
this.right.appendChild(this.left);
|
||||
this.right.appendChild(this);
|
||||
this.bottomRight.appendChild(this.bottomLeft);
|
||||
el.style.width = el.topRight.style.width = el.bottomRight.style.width = el.width + 'px';
|
||||
el.style.height = el.left.style.height = el.right.style.height = el.height + 'px';
|
||||
el.className = "NFMultiSelect";
|
||||
}
|
||||
el.unload = function() {
|
||||
this.parentNode.parentNode.appendChild(this);
|
||||
this.parentNode.removeChild(this.topRight);
|
||||
this.parentNode.removeChild(this.bottomRight);
|
||||
this.parentNode.removeChild(this.right);
|
||||
this.className = this.oldClassName;
|
||||
this.style.width = this.style.height = "";
|
||||
}
|
||||
el.onfocus = function() {
|
||||
this.topLeft.className = "NFMultiSelectTopLeft NFh";
|
||||
this.topRight.className = "NFMultiSelectTop NFhr";
|
||||
this.left.className = "NFMultiSelectLeftH";
|
||||
this.right.className = "NFMultiSelectRightH";
|
||||
this.bottomLeft.className = "NFMultiSelectBottomLeft NFh";
|
||||
this.bottomRight.className = "NFMultiSelectBottom NFhr";
|
||||
}
|
||||
el.onblur = function() {
|
||||
this.topLeft.className = "NFMultiSelectTopLeft";
|
||||
this.topRight.className = "NFMultiSelectTop";
|
||||
this.left.className = "NFMultiSelectLeft";
|
||||
this.right.className = "NFMultiSelectRight";
|
||||
this.bottomLeft.className = "NFMultiSelectBottomLeft";
|
||||
this.bottomRight.className = "NFMultiSelectBottom";
|
||||
}
|
||||
}
|
||||
function option(el, no) { //extend Options
|
||||
el.li = document.createElement('li');
|
||||
el.lnk = document.createElement('a');
|
||||
el.lnk.href = "javascript:;";
|
||||
el.lnk.ref = el.parentNode;
|
||||
el.lnk.pos = no;
|
||||
el.lnk._onclick = el.onclick || function () {};
|
||||
el.txt = document.createTextNode(el.text);
|
||||
el.lnk.appendChild(el.txt);
|
||||
el.li.appendChild(el.lnk);
|
||||
}
|
||||
|
||||
//Get Position
|
||||
function findPosY(obj) {
|
||||
var posTop = 0;
|
||||
do {posTop += obj.offsetTop;} while (obj = obj.offsetParent);
|
||||
return posTop;
|
||||
}
|
||||
function findPosX(obj) {
|
||||
var posLeft = 0;
|
||||
do {posLeft += obj.offsetLeft;} while (obj = obj.offsetParent);
|
||||
return posLeft;
|
||||
}
|
||||
//Get Siblings
|
||||
function getInputsByName(name) {
|
||||
var inputs = document.getElementsByTagName("input");
|
||||
var w = 0; var results = new Array();
|
||||
for(var q = 0; q < inputs.length; q++) {if(inputs[q].name == name) {results[w] = inputs[q]; ++w;}}
|
||||
return results;
|
||||
}
|
||||
|
||||
//Add events
|
||||
var existingLoadEvent = window.onload || function () {};
|
||||
var existingResizeEvent = window.onresize || function() {};
|
||||
window.onload = function () {
|
||||
existingLoadEvent();
|
||||
NFInit();
|
||||
}
|
||||
window.onresize = function() {
|
||||
if(resizeTest != document.documentElement.clientHeight) {
|
||||
existingResizeEvent();
|
||||
NFFix();
|
||||
}
|
||||
resizeTest = document.documentElement.clientHeight;
|
||||
}
|
@ -5,8 +5,8 @@
|
||||
* Uses patterns specified in site config files and auto detection (hNews/PHP Readability)
|
||||
* to extract content from HTML files.
|
||||
*
|
||||
* @version 0.6
|
||||
* @date 2011-05-04
|
||||
* @version 0.8
|
||||
* @date 2012-02-21
|
||||
* @author Keyvan Minoukadeh
|
||||
* @copyright 2011 Keyvan Minoukadeh
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.html AGPL v3
|
||||
@ -20,7 +20,7 @@ class ContentExtractor
|
||||
'logical-emphasis' => true,
|
||||
'show-body-only' => false,
|
||||
'new-blocklevel-tags' => 'article, aside, footer, header, hgroup, menu, nav, section, details, datagrid',
|
||||
'new-inline-tags' => 'new-inline-tags: mark, time, meter, progress',
|
||||
'new-inline-tags' => 'mark, time, meter, progress, data',
|
||||
'wrap' => 0,
|
||||
'drop-empty-paras' => true,
|
||||
'drop-proprietary-attributes' => false,
|
||||
@ -34,9 +34,13 @@ class ContentExtractor
|
||||
protected $html;
|
||||
protected $config;
|
||||
protected $title;
|
||||
protected $author = array();
|
||||
protected $language;
|
||||
protected $date;
|
||||
protected $body;
|
||||
protected $success = false;
|
||||
public $readability;
|
||||
public $fingerprints = array();
|
||||
public $readability;
|
||||
public $debug = false;
|
||||
|
||||
function __construct($path, $fallback=null) {
|
||||
@ -60,8 +64,30 @@ class ContentExtractor
|
||||
$this->config = null;
|
||||
$this->title = null;
|
||||
$this->body = null;
|
||||
$this->author = array();
|
||||
$this->language = null;
|
||||
$this->date = null;
|
||||
$this->success = false;
|
||||
}
|
||||
|
||||
public function findHostUsingFingerprints($html) {
|
||||
$this->debug('Checking fingerprints...');
|
||||
$head = substr($html, 0, 8000);
|
||||
foreach ($this->fingerprints as $_fp => $_fphost) {
|
||||
$lookin = 'html';
|
||||
if (is_array($_fphost)) {
|
||||
if (isset($_fphost['head']) && $_fphost['head']) {
|
||||
$lookin = 'head';
|
||||
}
|
||||
$_fphost = $_fphost['hostname'];
|
||||
}
|
||||
if (strpos($$lookin, $_fp) !== false) {
|
||||
$this->debug("Found match: $_fphost");
|
||||
return $_fphost;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// returns true on success, false on failure
|
||||
// $smart_tidy indicates that if tidy is used and no results are produced, we will
|
||||
@ -69,16 +95,28 @@ class ContentExtractor
|
||||
// but it has problems of its own which we try to avoid with this option.
|
||||
public function process($html, $url, $smart_tidy=true) {
|
||||
$this->reset();
|
||||
|
||||
// extract host name
|
||||
$host = @parse_url($url, PHP_URL_HOST);
|
||||
if (!($this->config = SiteConfig::build($host))) {
|
||||
// no match, so use defaults
|
||||
$this->config = new SiteConfig();
|
||||
// no match, check HTML for fingerprints
|
||||
if (!empty($this->fingerprints) && ($_fphost = $this->findHostUsingFingerprints($html))) {
|
||||
$this->config = SiteConfig::build($_fphost);
|
||||
}
|
||||
unset($_fphost);
|
||||
if (!$this->config) {
|
||||
// no match, so use defaults
|
||||
$this->config = new SiteConfig();
|
||||
}
|
||||
}
|
||||
// store copy of config in our static cache array in case we need to process another URL
|
||||
SiteConfig::add_to_cache($host, $this->config);
|
||||
|
||||
// do string replacements
|
||||
foreach ($this->config->replace_string as $_repl) {
|
||||
$html = str_replace($_repl[0], $_repl[1], $html);
|
||||
}
|
||||
unset($_repl);
|
||||
|
||||
// use tidy (if it exists)?
|
||||
// This fixes problems with some sites which would otherwise
|
||||
// trouble DOMDocument's HTML parsing. (Although sometimes it
|
||||
@ -102,6 +140,84 @@ class ContentExtractor
|
||||
// see http://en.wikipedia.org/wiki/XPath_1.0
|
||||
$xpath = new DOMXPath($this->readability->dom);
|
||||
|
||||
// try to get title
|
||||
foreach ($this->config->title as $pattern) {
|
||||
$elems = @$xpath->evaluate($pattern, $this->readability->dom);
|
||||
if (is_string($elems)) {
|
||||
$this->debug('Title expression evaluated as string');
|
||||
$this->title = trim($elems);
|
||||
break;
|
||||
} elseif ($elems instanceof DOMNodeList && $elems->length > 0) {
|
||||
$this->debug('Title matched');
|
||||
$this->title = $elems->item(0)->textContent;
|
||||
// remove title from document
|
||||
try {
|
||||
$elems->item(0)->parentNode->removeChild($elems->item(0));
|
||||
} catch (DOMException $e) {
|
||||
// do nothing
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// try to get author (if it hasn't already been set)
|
||||
if (empty($this->author)) {
|
||||
foreach ($this->config->author as $pattern) {
|
||||
$elems = @$xpath->evaluate($pattern, $this->readability->dom);
|
||||
if (is_string($elems)) {
|
||||
$this->debug('Author expression evaluated as string');
|
||||
if (trim($elems) != '') {
|
||||
$this->author[] = trim($elems);
|
||||
break;
|
||||
}
|
||||
} elseif ($elems instanceof DOMNodeList && $elems->length > 0) {
|
||||
foreach ($elems as $elem) {
|
||||
if (!isset($elem->parentNode)) continue;
|
||||
$this->author[] = trim($elem->textContent);
|
||||
}
|
||||
if (!empty($this->author)) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// try to get language
|
||||
$_lang_xpath = array('//html[@lang]/@lang', '//meta[@name="DC.language"]/@content');
|
||||
foreach ($_lang_xpath as $pattern) {
|
||||
$elems = @$xpath->evaluate($pattern, $this->readability->dom);
|
||||
if (is_string($elems)) {
|
||||
if (trim($elems) != '') {
|
||||
$this->language = trim($elems);
|
||||
break;
|
||||
}
|
||||
} elseif ($elems instanceof DOMNodeList && $elems->length > 0) {
|
||||
foreach ($elems as $elem) {
|
||||
if (!isset($elem->parentNode)) continue;
|
||||
$this->language = trim($elem->textContent);
|
||||
}
|
||||
if ($this->language) break;
|
||||
}
|
||||
}
|
||||
|
||||
// try to get date
|
||||
foreach ($this->config->date as $pattern) {
|
||||
$elems = @$xpath->evaluate($pattern, $this->readability->dom);
|
||||
if (is_string($elems)) {
|
||||
$this->debug('Date expression evaluated as string');
|
||||
$this->date = strtotime(trim($elems, "; \t\n\r\0\x0B"));
|
||||
} elseif ($elems instanceof DOMNodeList && $elems->length > 0) {
|
||||
$this->debug('Date matched');
|
||||
$this->date = $elems->item(0)->textContent;
|
||||
$this->date = strtotime(trim($this->date, "; \t\n\r\0\x0B"));
|
||||
// remove date from document
|
||||
// $elems->item(0)->parentNode->removeChild($elems->item(0));
|
||||
}
|
||||
if (!$this->date) {
|
||||
$this->date = null;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// strip elements (using xpath expressions)
|
||||
foreach ($this->config->strip as $pattern) {
|
||||
$elems = @$xpath->query($pattern, $this->readability->dom);
|
||||
@ -113,6 +229,7 @@ class ContentExtractor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// strip elements (using id and class attribute values)
|
||||
foreach ($this->config->strip_id_or_class as $string) {
|
||||
$string = strtr($string, array("'"=>'', '"'=>''));
|
||||
@ -125,6 +242,7 @@ class ContentExtractor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// strip images (using src attribute values)
|
||||
foreach ($this->config->strip_image_src as $string) {
|
||||
$string = strtr($string, array("'"=>'', '"'=>''));
|
||||
@ -160,19 +278,6 @@ class ContentExtractor
|
||||
}
|
||||
}
|
||||
|
||||
// try to get title
|
||||
foreach ($this->config->title as $pattern) {
|
||||
$elems = @$xpath->evaluate($pattern, $this->readability->dom);
|
||||
if (is_string($elems)) {
|
||||
$this->debug('Title expression evaluated as string');
|
||||
$this->title = trim($elems);
|
||||
break;
|
||||
} elseif ($elems instanceof DOMNodeList && $elems->length > 0) {
|
||||
$this->debug('Title matched');
|
||||
$this->title = $elems->item(0)->textContent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// try to get body
|
||||
foreach ($this->config->body as $pattern) {
|
||||
$elems = @$xpath->query($pattern, $this->readability->dom);
|
||||
@ -191,6 +296,7 @@ class ContentExtractor
|
||||
$this->body = $this->readability->dom->createElement('div');
|
||||
$this->debug($elems->length.' body elems found');
|
||||
foreach ($elems as $elem) {
|
||||
if (!isset($elem->parentNode)) continue;
|
||||
$isDescendant = false;
|
||||
foreach ($this->body->childNodes as $parent) {
|
||||
if ($this->isDescendant($parent, $elem)) {
|
||||
@ -215,20 +321,32 @@ class ContentExtractor
|
||||
}
|
||||
|
||||
// auto detect?
|
||||
$detect_title = $detect_body = false;
|
||||
$detect_title = $detect_body = $detect_author = $detect_date = false;
|
||||
// detect title?
|
||||
if (!isset($this->title)) {
|
||||
if (empty($this->config->title) || (!empty($this->config->title) && $this->config->autodetect_on_failure)) {
|
||||
if (empty($this->config->title) || $this->config->autodetect_on_failure) {
|
||||
$detect_title = true;
|
||||
}
|
||||
}
|
||||
// detect body?
|
||||
if (!isset($this->body)) {
|
||||
if (empty($this->config->body) || (!empty($this->config->body) && $this->config->autodetect_on_failure)) {
|
||||
if (empty($this->config->body) || $this->config->autodetect_on_failure) {
|
||||
$detect_body = true;
|
||||
}
|
||||
}
|
||||
|
||||
// detect author?
|
||||
if (empty($this->author)) {
|
||||
if (empty($this->config->author) || $this->config->autodetect_on_failure) {
|
||||
$detect_author = true;
|
||||
}
|
||||
}
|
||||
// detect date?
|
||||
if (!isset($this->date)) {
|
||||
if (empty($this->config->date) || $this->config->autodetect_on_failure) {
|
||||
$detect_date = true;
|
||||
}
|
||||
}
|
||||
|
||||
// check for hNews
|
||||
if ($detect_title || $detect_body) {
|
||||
// check for hentry
|
||||
@ -243,10 +361,50 @@ class ContentExtractor
|
||||
if ($elems && $elems->length > 0) {
|
||||
$this->debug('hNews: found entry-title');
|
||||
$this->title = $elems->item(0)->textContent;
|
||||
// remove title from document
|
||||
$elems->item(0)->parentNode->removeChild($elems->item(0));
|
||||
$detect_title = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($detect_date) {
|
||||
// check for time element with pubdate attribute
|
||||
$elems = @$xpath->query(".//time[@pubdate] | .//abbr[contains(concat(' ',normalize-space(@class),' '),' published ')]", $hentry);
|
||||
if ($elems && $elems->length > 0) {
|
||||
$this->debug('hNews: found publication date');
|
||||
$this->date = strtotime(trim($elems->item(0)->textContent));
|
||||
// remove date from document
|
||||
//$elems->item(0)->parentNode->removeChild($elems->item(0));
|
||||
if ($this->date) {
|
||||
$detect_date = false;
|
||||
} else {
|
||||
$this->date = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($detect_author) {
|
||||
// check for time element with pubdate attribute
|
||||
$elems = @$xpath->query(".//*[contains(concat(' ',normalize-space(@class),' '),' vcard ') and (contains(concat(' ',normalize-space(@class),' '),' author ') or contains(concat(' ',normalize-space(@class),' '),' byline '))]", $hentry);
|
||||
if ($elems && $elems->length > 0) {
|
||||
$this->debug('hNews: found author');
|
||||
$author = $elems->item(0);
|
||||
$fn = @$xpath->query(".//*[contains(concat(' ',normalize-space(@class),' '),' fn ')]", $author);
|
||||
if ($fn && $fn->length > 0) {
|
||||
foreach ($fn as $_fn) {
|
||||
if (trim($_fn->textContent) != '') {
|
||||
$this->author[] = trim($_fn->textContent);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (trim($author->textContent) != '') {
|
||||
$this->author[] = trim($author->textContent);
|
||||
}
|
||||
}
|
||||
$detect_author = empty($this->author);
|
||||
}
|
||||
}
|
||||
|
||||
// check for entry-content.
|
||||
// according to hAtom spec, if there are multiple elements marked entry-content,
|
||||
// we include all of these in the order they appear - see http://microformats.org/wiki/hatom#Entry_Content
|
||||
@ -273,6 +431,7 @@ class ContentExtractor
|
||||
$this->body = $this->readability->dom->createElement('div');
|
||||
$this->debug($elems->length.' entry-content elems found');
|
||||
foreach ($elems as $elem) {
|
||||
if (!isset($elem->parentNode)) continue;
|
||||
$isDescendant = false;
|
||||
foreach ($this->body->childNodes as $parent) {
|
||||
if ($this->isDescendant($parent, $elem)) {
|
||||
@ -306,6 +465,8 @@ class ContentExtractor
|
||||
if ($elems && $elems->length > 0) {
|
||||
$this->debug('title found (.instapaper_title)');
|
||||
$this->title = $elems->item(0)->textContent;
|
||||
// remove title from document
|
||||
$elems->item(0)->parentNode->removeChild($elems->item(0));
|
||||
$detect_title = false;
|
||||
}
|
||||
}
|
||||
@ -323,6 +484,41 @@ class ContentExtractor
|
||||
$detect_body = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Find author in rel="author" marked element
|
||||
// We only use this if there's exactly one.
|
||||
// If there's more than one, it could indicate more than
|
||||
// one author, but it could also indicate that we're processing
|
||||
// a page listing different articles with different authors.
|
||||
if ($detect_author) {
|
||||
$elems = @$xpath->query("//a[contains(concat(' ',normalize-space(@rel),' '),' author ')]", $this->readability->dom);
|
||||
if ($elems && $elems->length == 1) {
|
||||
$this->debug('Author found (rel="author")');
|
||||
$author = trim($elems->item(0)->textContent);
|
||||
if ($author != '') {
|
||||
$this->author[] = $author;
|
||||
$detect_author = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find date in pubdate marked time element
|
||||
// For the same reason given above, we only use this
|
||||
// if there's exactly one element.
|
||||
if ($detect_date) {
|
||||
$elems = @$xpath->query("//time[@pubdate]", $this->readability->dom);
|
||||
if ($elems && $elems->length == 1) {
|
||||
$this->debug('Date found (pubdate marked time element)');
|
||||
$this->date = strtotime(trim($elems->item(0)->textContent));
|
||||
// remove date from document
|
||||
//$elems->item(0)->parentNode->removeChild($elems->item(0));
|
||||
if ($this->date) {
|
||||
$detect_date = false;
|
||||
} else {
|
||||
$this->date = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// still missing title or body, so we detect using Readability
|
||||
if ($detect_title || $detect_body) {
|
||||
@ -350,6 +546,19 @@ class ContentExtractor
|
||||
if (isset($this->body)) {
|
||||
// remove scripts
|
||||
$this->readability->removeScripts($this->body);
|
||||
// remove any h1-h6 elements that appear as first thing in the body
|
||||
// and which match our title
|
||||
if (isset($this->title) && ($this->title != '')) {
|
||||
$firstChild = $this->body->firstChild;
|
||||
while ($firstChild->nodeType && ($firstChild->nodeType !== XML_ELEMENT_NODE)) {
|
||||
$firstChild = $firstChild->nextSibling;
|
||||
}
|
||||
if (($firstChild->nodeType === XML_ELEMENT_NODE)
|
||||
&& in_array(strtolower($firstChild->tagName), array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))
|
||||
&& (strtolower(trim($firstChild->textContent)) == strtolower(trim($this->title)))) {
|
||||
$this->body->removeChild($firstChild);
|
||||
}
|
||||
}
|
||||
$this->success = true;
|
||||
}
|
||||
|
||||
@ -375,11 +584,23 @@ class ContentExtractor
|
||||
public function getContent() {
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
|
||||
public function getTitle() {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function getAuthors() {
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
public function getLanguage() {
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
public function getDate() {
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function getSiteConfig() {
|
||||
return $this->config;
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
* Each instance of this class should hold extraction patterns and other directives
|
||||
* for a website. See ContentExtractor class to see how it's used.
|
||||
*
|
||||
* @version 0.5
|
||||
* @date 2011-03-08
|
||||
* @version 0.6
|
||||
* @date 2011-10-30
|
||||
* @author Keyvan Minoukadeh
|
||||
* @copyright 2011 Keyvan Minoukadeh
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.html AGPL v3
|
||||
@ -15,10 +15,16 @@
|
||||
class SiteConfig
|
||||
{
|
||||
// Use first matching element as title (0 or more xpath expressions)
|
||||
public $title = array();
|
||||
public $title = array();
|
||||
|
||||
// Use first matching element as body (0 or more xpath expressions)
|
||||
public $body = array();
|
||||
public $body = array();
|
||||
|
||||
// Use first matching element as author (0 or more xpath expressions)
|
||||
public $author = array();
|
||||
|
||||
// Use first matching element as date (0 or more xpath expressions)
|
||||
public $date = array();
|
||||
|
||||
// Strip elements matching these xpath expressions (0 or more)
|
||||
public $strip = array();
|
||||
@ -29,6 +35,10 @@ class SiteConfig
|
||||
// Strip images which contain these strings (0 or more) in the src attribute
|
||||
public $strip_image_src = array();
|
||||
|
||||
// Additional HTTP headers to send
|
||||
// NOT YET USED
|
||||
public $http_header = array();
|
||||
|
||||
// Process HTML with tidy before creating DOM
|
||||
public $tidy = true;
|
||||
|
||||
@ -62,6 +72,9 @@ class SiteConfig
|
||||
// TODO: which parser to use for turning raw HTML into a DOMDocument
|
||||
public $parser = 'libxml';
|
||||
|
||||
// String replacement to be made on HTML before processing begins
|
||||
public $replace_string = array();
|
||||
|
||||
// the options below cannot be set in the config files which this class represents
|
||||
|
||||
public static $debug = false;
|
||||
@ -150,14 +163,19 @@ class SiteConfig
|
||||
if ($command == '' || $val == '') continue;
|
||||
|
||||
// check for commands where we accept multiple statements
|
||||
if (in_array($command, array('title', 'body', 'strip', 'strip_id_or_class', 'strip_image_src', 'single_page_link', 'single_page_link_in_feed'))) {
|
||||
if (in_array($command, array('title', 'body', 'author', 'date', 'strip', 'strip_id_or_class', 'strip_image_src', 'single_page_link', 'single_page_link_in_feed', 'http_header'))) {
|
||||
array_push($config->$command, $val);
|
||||
// check for single statement commands that evaluate to true or false
|
||||
} elseif (in_array($command, array('tidy', 'prune', 'autodetect_on_failure'))) {
|
||||
$config->$command = ($val == 'yes');
|
||||
// check for single statement commands stored as strings
|
||||
} elseif (in_array($command, array('test_url'))) {
|
||||
} elseif (in_array($command, array('test_url', 'parser'))) {
|
||||
$config->$command = $val;
|
||||
} elseif ((substr($command, -1) == ')') && preg_match('!^([a-z0-9_]+)\((.*?)\)$!i', $command, $match)) {
|
||||
if (in_array($match[1], array('replace_string'))) {
|
||||
$command = $match[1];
|
||||
array_push($config->$command, array($match[2], $val));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
|
@ -1,18 +1,15 @@
|
||||
<?php
|
||||
// RSS 0.90 Officially obsoleted by 1.0
|
||||
// RSS 0.91, 0.92, 0.93 and 0.94 Officially obsoleted by 2.0
|
||||
// So, define constants for RSS 1.0, RSS 2.0 and ATOM
|
||||
|
||||
define('RSS1', 'RSS 1.0', true);
|
||||
define('RSS2', 'RSS 2.0', true);
|
||||
define('ATOM', 'ATOM', true);
|
||||
define('RSS2', 1, true);
|
||||
define('JSON', 2, true);
|
||||
|
||||
/**
|
||||
* Univarsel Feed Writer class
|
||||
*
|
||||
* Genarate RSS 1.0, RSS2.0 and ATOM Feed.
|
||||
* Genarate RSS2 or JSON (original: RSS 1.0, RSS2.0 and ATOM Feed)
|
||||
*
|
||||
* Modified for FiveFilters.org's Full-Text RSS project
|
||||
* to allow for inclusion of hubs
|
||||
* to allow for inclusion of hubs, JSON output.
|
||||
* Stripped RSS1 and ATOM support.
|
||||
*
|
||||
* @package UnivarselFeedWriter
|
||||
* @author Anis uddin Ahmad <anisniit@gmail.com>
|
||||
@ -27,13 +24,14 @@ define('ATOM', 'ATOM', true);
|
||||
private $data = array(); // Store some other version wise data
|
||||
private $CDATAEncoding = array(); // The tag names which have to encoded as CDATA
|
||||
private $xsl = null; // stylesheet to render RSS (used by Chrome)
|
||||
private $json = null; // JSON object
|
||||
|
||||
private $version = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param constant the version constant (RSS1/RSS2/ATOM).
|
||||
* @param constant the version constant (RSS2 or JSON).
|
||||
*/
|
||||
function __construct($version = RSS2)
|
||||
{
|
||||
@ -46,6 +44,10 @@ define('ATOM', 'ATOM', true);
|
||||
//Tag names to encode in CDATA
|
||||
$this->CDATAEncoding = array('description', 'content:encoded', 'content', 'subtitle', 'summary');
|
||||
}
|
||||
|
||||
public function setFormat($format) {
|
||||
$this->version = $format;
|
||||
}
|
||||
|
||||
// Start # public functions ---------------------------------------------
|
||||
|
||||
@ -79,19 +81,26 @@ define('ATOM', 'ATOM', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Genarate the actual RSS/ATOM file
|
||||
* Genarate the actual RSS/JSON file
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function genarateFeed()
|
||||
{
|
||||
header("Content-type: text/xml; charset=UTF-8");
|
||||
|
||||
if ($this->version == RSS2) {
|
||||
header('Content-type: text/xml; charset=UTF-8');
|
||||
} elseif ($this->version == JSON) {
|
||||
header('Content-type: application/json; charset=UTF-8');
|
||||
$this->json = new stdClass();
|
||||
}
|
||||
$this->printHead();
|
||||
$this->printChannels();
|
||||
$this->printItems();
|
||||
$this->printTale();
|
||||
if ($this->version == JSON) {
|
||||
echo json_encode($this->json);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,36 +216,6 @@ define('ATOM', 'ATOM', true);
|
||||
$this->setChannelElement('image', array('title'=>$title, 'link'=>$link, 'url'=>$url));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the 'about' channel element. Only for RSS 1.0
|
||||
*
|
||||
* @access public
|
||||
* @param srting value of 'about' channel tag
|
||||
* @return void
|
||||
*/
|
||||
public function setChannelAbout($url)
|
||||
{
|
||||
$this->data['ChannelAbout'] = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Genarates an UUID
|
||||
* @author Anis uddin Ahmad <admin@ajaxray.com>
|
||||
* @param string an optional prefix
|
||||
* @return string the formated uuid
|
||||
*/
|
||||
public function uuid($key = null, $prefix = '')
|
||||
{
|
||||
$key = ($key == null)? uniqid(rand()) : $key;
|
||||
$chars = md5($key);
|
||||
$uuid = substr($chars,0,8) . '-';
|
||||
$uuid .= substr($chars,8,4) . '-';
|
||||
$uuid .= substr($chars,12,4) . '-';
|
||||
$uuid .= substr($chars,16,4) . '-';
|
||||
$uuid .= substr($chars,20,12);
|
||||
|
||||
return $prefix . $uuid;
|
||||
}
|
||||
// End # public functions ----------------------------------------------
|
||||
|
||||
// Start # private functions ----------------------------------------------
|
||||
@ -249,26 +228,17 @@ define('ATOM', 'ATOM', true);
|
||||
*/
|
||||
private function printHead()
|
||||
{
|
||||
$out = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
|
||||
|
||||
if($this->version == RSS2)
|
||||
if ($this->version == RSS2)
|
||||
{
|
||||
$out = '<?xml version="1.0" encoding="utf-8"?>'."\n";
|
||||
if ($this->xsl) $out .= '<?xml-stylesheet type="text/xsl" href="'.htmlspecialchars($this->xsl).'"?>' . PHP_EOL;
|
||||
$out .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">' . PHP_EOL;
|
||||
}
|
||||
elseif($this->version == RSS1)
|
||||
{
|
||||
$out .= '<rdf:RDF
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns="http://purl.org/rss/1.0/"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
>' . PHP_EOL;;
|
||||
$out .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">' . PHP_EOL;
|
||||
echo $out;
|
||||
}
|
||||
else if($this->version == ATOM)
|
||||
elseif ($this->version == JSON)
|
||||
{
|
||||
$out .= '<feed xmlns="http://www.w3.org/2005/Atom">' . PHP_EOL;;
|
||||
$this->json->rss = array('@attributes' => array('version' => '2.0'));
|
||||
}
|
||||
echo $out;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -279,70 +249,83 @@ define('ATOM', 'ATOM', true);
|
||||
*/
|
||||
private function printTale()
|
||||
{
|
||||
if($this->version == RSS2)
|
||||
if ($this->version == RSS2)
|
||||
{
|
||||
echo '</channel>' . PHP_EOL . '</rss>';
|
||||
echo '</channel>',PHP_EOL,'</rss>';
|
||||
}
|
||||
elseif($this->version == RSS1)
|
||||
{
|
||||
echo '</rdf:RDF>';
|
||||
}
|
||||
else if($this->version == ATOM)
|
||||
{
|
||||
echo '</feed>';
|
||||
}
|
||||
|
||||
// do nothing for JSON
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a single node as xml format
|
||||
*
|
||||
* @access private
|
||||
* @param srting name of the tag
|
||||
* @param string name of the tag
|
||||
* @param mixed tag value as string or array of nested tags in 'tagName' => 'tagValue' format
|
||||
* @param array Attributes(if any) in 'attrName' => 'attrValue' format
|
||||
* @return string formatted xml tag
|
||||
*/
|
||||
private function makeNode($tagName, $tagContent, $attributes = null)
|
||||
{
|
||||
$nodeText = '';
|
||||
$attrText = '';
|
||||
|
||||
if(is_array($attributes))
|
||||
if ($this->version == RSS2)
|
||||
{
|
||||
foreach ($attributes as $key => $value)
|
||||
$nodeText = '';
|
||||
$attrText = '';
|
||||
if (is_array($attributes))
|
||||
{
|
||||
$attrText .= " $key=\"$value\" ";
|
||||
foreach ($attributes as $key => $value)
|
||||
{
|
||||
$attrText .= " $key=\"$value\" ";
|
||||
}
|
||||
}
|
||||
$nodeText .= "<{$tagName}{$attrText}>";
|
||||
if (is_array($tagContent))
|
||||
{
|
||||
foreach ($tagContent as $key => $value)
|
||||
{
|
||||
$nodeText .= $this->makeNode($key, $value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : htmlentities($tagContent);
|
||||
$nodeText .= htmlspecialchars($tagContent);
|
||||
}
|
||||
//$nodeText .= (in_array($tagName, $this->CDATAEncoding))? "]]></$tagName>" : "</$tagName>";
|
||||
$nodeText .= "</$tagName>";
|
||||
return $nodeText . PHP_EOL;
|
||||
}
|
||||
elseif ($this->version == JSON)
|
||||
{
|
||||
$tagName = (string)$tagName;
|
||||
$tagName = strtr($tagName, ':', '_');
|
||||
$node = null;
|
||||
if (!$tagContent && is_array($attributes) && count($attributes))
|
||||
{
|
||||
$node = array('@attributes' => $this->json_keys($attributes));
|
||||
} else {
|
||||
if (is_array($tagContent)) {
|
||||
$node = $this->json_keys($tagContent);
|
||||
} else {
|
||||
$node = $tagContent;
|
||||
}
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
return ''; // should not get here
|
||||
}
|
||||
|
||||
private function json_keys(array $array) {
|
||||
$new = array();
|
||||
foreach ($array as $key => $val) {
|
||||
if (is_string($key)) $key = strtr($key, ':', '_');
|
||||
if (is_array($val)) {
|
||||
$new[$key] = $this->json_keys($val);
|
||||
} else {
|
||||
$new[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($tagContent) && $this->version == RSS1)
|
||||
{
|
||||
$attrText = ' rdf:parseType="Resource"';
|
||||
}
|
||||
|
||||
|
||||
$attrText .= (in_array($tagName, $this->CDATAEncoding) && $this->version == ATOM)? ' type="html" ' : '';
|
||||
//$nodeText .= (in_array($tagName, $this->CDATAEncoding))? "<{$tagName}{$attrText}><![CDATA[" : "<{$tagName}{$attrText}>";
|
||||
$nodeText .= "<{$tagName}{$attrText}>";
|
||||
|
||||
if(is_array($tagContent))
|
||||
{
|
||||
foreach ($tagContent as $key => $value)
|
||||
{
|
||||
$nodeText .= $this->makeNode($key, $value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//$nodeText .= (in_array($tagName, $this->CDATAEncoding))? $tagContent : htmlentities($tagContent);
|
||||
$nodeText .= htmlspecialchars($tagContent);
|
||||
}
|
||||
|
||||
//$nodeText .= (in_array($tagName, $this->CDATAEncoding))? "]]></$tagName>" : "</$tagName>";
|
||||
$nodeText .= "</$tagName>";
|
||||
|
||||
return $nodeText . PHP_EOL;
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -367,40 +350,16 @@ define('ATOM', 'ATOM', true);
|
||||
//echo $this->makeNode('link', '', array('rel'=>'self', 'href'=>$this->self, 'xmlns'=>'http://www.w3.org/2005/Atom'));
|
||||
echo '<link rel="self" href="'.htmlspecialchars($this->self).'" xmlns="http://www.w3.org/2005/Atom" />' . PHP_EOL;
|
||||
}
|
||||
//Print Items of channel
|
||||
foreach ($this->channels as $key => $value)
|
||||
{
|
||||
echo $this->makeNode($key, $value);
|
||||
}
|
||||
break;
|
||||
case RSS1:
|
||||
echo (isset($this->data['ChannelAbout']))? "<channel rdf:about=\"{$this->data['ChannelAbout']}\">" : "<channel rdf:about=\"{$this->channels['link']}\">";
|
||||
case JSON:
|
||||
$this->json->rss['channel'] = (object)$this->json_keys($this->channels);
|
||||
break;
|
||||
}
|
||||
|
||||
//Print Items of channel
|
||||
foreach ($this->channels as $key => $value)
|
||||
{
|
||||
if($this->version == ATOM && $key == 'link')
|
||||
{
|
||||
// ATOM prints link element as href attribute
|
||||
echo $this->makeNode($key,'',array('href'=>$value));
|
||||
//Add the id for ATOM
|
||||
echo $this->makeNode('id',$this->uuid($value,'urn:uuid:'));
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $this->makeNode($key, $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//RSS 1.0 have special tag <rdf:Seq> with channel
|
||||
if($this->version == RSS1)
|
||||
{
|
||||
echo "<items>" . PHP_EOL . "<rdf:Seq>" . PHP_EOL;
|
||||
foreach ($this->items as $item)
|
||||
{
|
||||
$thisItems = $item->getElements();
|
||||
echo "<rdf:li resource=\"{$thisItems['link']['content']}\"/>" . PHP_EOL;
|
||||
}
|
||||
echo "</rdf:Seq>" . PHP_EOL . "</items>" . PHP_EOL . "</channel>" . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -415,14 +374,28 @@ define('ATOM', 'ATOM', true);
|
||||
{
|
||||
$thisItems = $item->getElements();
|
||||
|
||||
//the argument is printed as rdf:about attribute of item in rss 1.0
|
||||
echo $this->startItem($thisItems['link']['content']);
|
||||
echo $this->startItem();
|
||||
|
||||
if ($this->version == JSON) {
|
||||
$json_item = array();
|
||||
}
|
||||
|
||||
foreach ($thisItems as $feedItem )
|
||||
{
|
||||
echo $this->makeNode($feedItem['name'], $feedItem['content'], $feedItem['attributes']);
|
||||
if ($this->version == RSS2) {
|
||||
echo $this->makeNode($feedItem['name'], $feedItem['content'], $feedItem['attributes']);
|
||||
} elseif ($this->version == JSON) {
|
||||
$json_item[strtr($feedItem['name'], ':', '_')] = $this->makeNode($feedItem['name'], $feedItem['content'], $feedItem['attributes']);
|
||||
}
|
||||
}
|
||||
echo $this->endItem();
|
||||
if ($this->version == JSON) {
|
||||
if (count($this->items) > 1) {
|
||||
$this->json->rss['channel']->item[] = $json_item;
|
||||
} else {
|
||||
$this->json->rss['channel']->item = $json_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -430,30 +403,15 @@ define('ATOM', 'ATOM', true);
|
||||
* Make the starting tag of channels
|
||||
*
|
||||
* @access private
|
||||
* @param srting The vale of about tag which is used for only RSS 1.0
|
||||
* @return void
|
||||
*/
|
||||
private function startItem($about = false)
|
||||
private function startItem()
|
||||
{
|
||||
if($this->version == RSS2)
|
||||
if ($this->version == RSS2)
|
||||
{
|
||||
echo '<item>' . PHP_EOL;
|
||||
}
|
||||
elseif($this->version == RSS1)
|
||||
{
|
||||
if($about)
|
||||
{
|
||||
echo "<item rdf:about=\"$about\">" . PHP_EOL;
|
||||
}
|
||||
else
|
||||
{
|
||||
die('link element is not set .\n It\'s required for RSS 1.0 to be used as about attribute of item');
|
||||
}
|
||||
}
|
||||
else if($this->version == ATOM)
|
||||
{
|
||||
echo "<entry>" . PHP_EOL;
|
||||
}
|
||||
// nothing for JSON
|
||||
}
|
||||
|
||||
/**
|
||||
@ -464,18 +422,12 @@ define('ATOM', 'ATOM', true);
|
||||
*/
|
||||
private function endItem()
|
||||
{
|
||||
if($this->version == RSS2 || $this->version == RSS1)
|
||||
if ($this->version == RSS2)
|
||||
{
|
||||
echo '</item>' . PHP_EOL;
|
||||
}
|
||||
else if($this->version == ATOM)
|
||||
{
|
||||
echo "</entry>" . PHP_EOL;
|
||||
}
|
||||
// nothing for JSON
|
||||
}
|
||||
|
||||
|
||||
|
||||
// End # private functions ----------------------------------------------
|
||||
|
||||
} // end of class FeedWriter
|
||||
}
|
@ -7,11 +7,11 @@
|
||||
* For environments which do not have these options, it reverts to standard sequential
|
||||
* requests (using file_get_contents())
|
||||
*
|
||||
* @version 0.9.5
|
||||
* @date 2011-05-23
|
||||
* @version 1.0
|
||||
* @date 2012-02-09
|
||||
* @see http://php.net/HttpRequestPool
|
||||
* @author Keyvan Minoukadeh
|
||||
* @copyright 2011 Keyvan Minoukadeh
|
||||
* @copyright 2011-2012 Keyvan Minoukadeh
|
||||
* @license http://www.gnu.org/licenses/agpl-3.0.html AGPL v3
|
||||
*/
|
||||
|
||||
@ -20,6 +20,10 @@ class HumbleHttpAgent
|
||||
const METHOD_REQUEST_POOL = 1;
|
||||
const METHOD_CURL_MULTI = 2;
|
||||
const METHOD_FILE_GET_CONTENTS = 4;
|
||||
//const UA_BROWSER = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1';
|
||||
const UA_BROWSER = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.92 Safari/535.2';
|
||||
const UA_PHP = 'PHP/5.2';
|
||||
const REF_GOOGLE = 'http://www.google.co.uk/url?sa=t&source=web&cd=1';
|
||||
|
||||
protected $requests = array();
|
||||
protected $redirectQueue = array();
|
||||
@ -33,12 +37,27 @@ class HumbleHttpAgent
|
||||
protected $cookieJar;
|
||||
public $rewriteHashbangFragment = true; // see http://code.google.com/web/ajaxcrawling/docs/specification.html
|
||||
public $maxRedirects = 5;
|
||||
public $userAgentMap = array();
|
||||
public $rewriteUrls = array();
|
||||
public $userAgentDefault;
|
||||
public $referer;
|
||||
//public $userAgent = 'Mozilla/5.0';
|
||||
|
||||
// Prevent certain file/mime types
|
||||
// HTTP responses which match these content types will
|
||||
// be returned without body.
|
||||
public $headerOnlyTypes = array();
|
||||
// URLs ending with one of these extensions will
|
||||
// prompt Humble HTTP Agent to send a HEAD request first
|
||||
// to see if returned content type matches $headerOnlyTypes.
|
||||
public $headerOnlyClues = array('pdf','mp3','zip','exe','gif','gzip','gz','jpeg','jpg','mpg','mpeg','png','ppt','mov');
|
||||
|
||||
//TODO: prevent certain file/mime types
|
||||
//TODO: set max file size
|
||||
//TODO: normalise headers
|
||||
|
||||
function __construct($requestOptions=null, $method=null) {
|
||||
$this->userAgentDefault = self::UA_BROWSER;
|
||||
$this->referer = self::REF_GOOGLE;
|
||||
// set the request method
|
||||
if (in_array($method, array(1,2,4))) {
|
||||
$this->method = $method;
|
||||
@ -58,7 +77,7 @@ class HumbleHttpAgent
|
||||
$this->cookieJar = new CookieJar();
|
||||
// set request options (redirect must be 0)
|
||||
$this->requestOptions = array(
|
||||
'timeout' => 10,
|
||||
'timeout' => 15,
|
||||
'redirect' => 0 // we handle redirects manually so we can rewrite the new hashbang URLs that are creeping up over the web
|
||||
// TODO: test onprogress?
|
||||
);
|
||||
@ -70,8 +89,7 @@ class HumbleHttpAgent
|
||||
'ignore_errors' => true,
|
||||
'timeout' => $this->requestOptions['timeout'],
|
||||
'max_redirects' => $this->requestOptions['redirect'],
|
||||
'header' => "User-Agent: PHP/".phpversion()."\r\n".
|
||||
"Accept: */*\r\n"
|
||||
'header' => "Accept: */*\r\n"
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -87,21 +105,49 @@ class HumbleHttpAgent
|
||||
}
|
||||
}
|
||||
|
||||
protected function getUserAgent($url, $asArray=false) {
|
||||
$host = @parse_url($url, PHP_URL_HOST);
|
||||
if (strtolower(substr($host, 0, 4)) == 'www.') {
|
||||
$host = substr($host, 4);
|
||||
}
|
||||
if ($host) {
|
||||
$try = array($host);
|
||||
$split = explode('.', $host);
|
||||
if (count($split) > 1) {
|
||||
array_shift($split);
|
||||
$try[] = '.'.implode('.', $split);
|
||||
}
|
||||
foreach ($try as $h) {
|
||||
if (isset($this->userAgentMap[$h])) {
|
||||
$ua = $this->userAgentMap[$h];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isset($ua)) $ua = $this->userAgentDefault;
|
||||
if ($asArray) {
|
||||
return array('User-Agent' => $ua);
|
||||
} else {
|
||||
return 'User-Agent: '.$ua;
|
||||
}
|
||||
}
|
||||
|
||||
public function rewriteHashbangFragment($url) {
|
||||
// return $url if there's no '#!'
|
||||
if (strpos($url, '#!') === false) return $url;
|
||||
// split $url and rewrite
|
||||
$iri = new IRI($url);
|
||||
$fragment = substr($iri->ifragment, 1); // strip '!'
|
||||
// TODO: is SimplePie_IRI included?
|
||||
$iri = new SimplePie_IRI($url);
|
||||
$fragment = substr($iri->fragment, 1); // strip '!'
|
||||
$iri->fragment = null;
|
||||
if (isset($iri->iquery)) {
|
||||
parse_str($iri->iquery, $query);
|
||||
if (isset($iri->query)) {
|
||||
parse_str($iri->query, $query);
|
||||
} else {
|
||||
$query = array();
|
||||
}
|
||||
$query['_escaped_fragment_'] = (string)$fragment;
|
||||
$iri->query = str_replace('%2F', '/', http_build_query($query)); // needed for some sites
|
||||
return $iri->uri;
|
||||
return $iri->get_iri();
|
||||
}
|
||||
|
||||
public function removeFragment($url) {
|
||||
@ -111,7 +157,18 @@ class HumbleHttpAgent
|
||||
} else {
|
||||
return substr($url, 0, $pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function rewriteUrls($url) {
|
||||
foreach ($this->rewriteUrls as $find => $action) {
|
||||
if (strpos($url, $find) !== false) {
|
||||
if (is_array($action)) {
|
||||
return strtr($url, $action);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function enableDebug($bool=true) {
|
||||
$this->debug = (bool)$bool;
|
||||
@ -139,48 +196,6 @@ class HumbleHttpAgent
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cache object.
|
||||
* The cache object passed should implement Zend_Cache_Backend_Interface
|
||||
* @param Zend_Cache_Backend_Interface
|
||||
*/
|
||||
/* all disk caching temporily disabled - needs work
|
||||
public function useCache($cache) {
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
public function isCached($url) {
|
||||
if (!isset($this->cache)) return false;
|
||||
return ($this->cache->test(md5($url)) !== false);
|
||||
}
|
||||
|
||||
public function getCached($url) {
|
||||
$cached = $this->cache->load(md5($url));
|
||||
$cached['fromCache'] = true;
|
||||
return $cached;
|
||||
}
|
||||
|
||||
public function cache($url) {
|
||||
if (isset($this->cache) && !isset($this->requests[$url]['fromCache']) && isset($this->requests[$url]['body'])) {
|
||||
$this->debug("Saving to cache ($url)");
|
||||
$res = $this->cache->save($this->requests[$url], md5($url));
|
||||
//$res = @file_put_contents($this->cacheFolder.'/'.md5($url).'.txt', serialize($this->requests[$url]));
|
||||
return ($res !== false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function cacheAll() {
|
||||
if (isset($this->cache)) {
|
||||
foreach (array_keys($this->requests) as $url) {
|
||||
$this->cache($url);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
public function fetchAll(array $urls) {
|
||||
$this->fetchAllOnce($urls, $isRedirect=false);
|
||||
$redirects = 0;
|
||||
@ -219,14 +234,25 @@ class HumbleHttpAgent
|
||||
*/
|
||||
} else {
|
||||
$this->debug("......adding to pool");
|
||||
$req_url = ($this->rewriteHashbangFragment) ? $this->rewriteHashbangFragment($url) : $url;
|
||||
$req_url = $this->rewriteUrls($url);
|
||||
$req_url = ($this->rewriteHashbangFragment) ? $this->rewriteHashbangFragment($req_url) : $req_url;
|
||||
$req_url = $this->removeFragment($req_url);
|
||||
$httpRequest = new HttpRequest($req_url, HttpRequest::METH_GET, $this->requestOptions);
|
||||
if (!empty($this->headerOnlyTypes) && !isset($this->requests[$orig]['wrongGuess']) && $this->possibleUnsupportedType($req_url)) {
|
||||
$_meth = HttpRequest::METH_HEAD;
|
||||
} else {
|
||||
$_meth = HttpRequest::METH_GET;
|
||||
unset($this->requests[$orig]['wrongGuess']);
|
||||
}
|
||||
$httpRequest = new HttpRequest($req_url, $_meth, $this->requestOptions);
|
||||
// send cookies, if we have any
|
||||
if ($cookies = $this->cookieJar->getMatchingCookies($req_url)) {
|
||||
$this->debug("......sending cookies: $cookies");
|
||||
$httpRequest->addHeaders(array('Cookie' => $cookies));
|
||||
}
|
||||
//$httpRequest->addHeaders(array('User-Agent' => $this->userAgent));
|
||||
$httpRequest->addHeaders($this->getUserAgent($req_url, true));
|
||||
// add referer for picky sites
|
||||
$httpRequest->addheaders(array('Referer' => $this->referer));
|
||||
$this->requests[$orig] = array('headers'=>null, 'body'=>null, 'httpRequest'=>$httpRequest);
|
||||
$this->requests[$orig]['original_url'] = $orig;
|
||||
$pool->attach($httpRequest);
|
||||
@ -243,42 +269,56 @@ class HumbleHttpAgent
|
||||
$this->debug('Received responses');
|
||||
foreach($subset as $orig => $url) {
|
||||
if (!$isRedirect) $orig = $url;
|
||||
//if (!isset($this->requests[$url]['fromCache'])) {
|
||||
$request = $this->requests[$orig]['httpRequest'];
|
||||
//$this->requests[$orig]['headers'] = $this->headersToString($request->getResponseHeader());
|
||||
// getResponseHeader() doesn't return status line, so, for consistency...
|
||||
$this->requests[$orig]['headers'] = substr($request->getRawResponseMessage(), 0, $request->getResponseInfo('header_size'));
|
||||
$request = $this->requests[$orig]['httpRequest'];
|
||||
//$this->requests[$orig]['headers'] = $this->headersToString($request->getResponseHeader());
|
||||
// getResponseHeader() doesn't return status line, so, for consistency...
|
||||
$this->requests[$orig]['headers'] = substr($request->getRawResponseMessage(), 0, $request->getResponseInfo('header_size'));
|
||||
// check content type
|
||||
// TODO: use getResponseHeader('content-type') or getResponseInfo()
|
||||
if ($this->headerOnlyType($this->requests[$orig]['headers'])) {
|
||||
$this->requests[$orig]['body'] = '';
|
||||
$_header_only_type = true;
|
||||
$this->debug('Header only type returned');
|
||||
} else {
|
||||
$this->requests[$orig]['body'] = $request->getResponseBody();
|
||||
$this->requests[$orig]['effective_url'] = $request->getResponseInfo('effective_url');
|
||||
$this->requests[$orig]['status_code'] = $status_code = $request->getResponseCode();
|
||||
// is redirect?
|
||||
if ((in_array($status_code, array(300, 301, 302, 303, 307)) || $status_code > 307 && $status_code < 400) && $request->getResponseHeader('location')) {
|
||||
$redirectURL = $request->getResponseHeader('location');
|
||||
if (!preg_match('!^https?://!i', $redirectURL)) {
|
||||
$redirectURL = SimplePie_Misc::absolutize_url($redirectURL, $url);
|
||||
}
|
||||
if ($this->validateURL($redirectURL)) {
|
||||
$this->debug('Redirect detected. Valid URL: '.$redirectURL);
|
||||
// store any cookies
|
||||
$cookies = $request->getResponseHeader('set-cookie');
|
||||
if ($cookies && !is_array($cookies)) $cookies = array($cookies);
|
||||
if ($cookies) $this->cookieJar->storeCookies($url, $cookies);
|
||||
$this->redirectQueue[$orig] = $redirectURL;
|
||||
} else {
|
||||
$this->debug('Redirect detected. Invalid URL: '.$redirectURL);
|
||||
}
|
||||
$_header_only_type = false;
|
||||
}
|
||||
$this->requests[$orig]['effective_url'] = $request->getResponseInfo('effective_url');
|
||||
$this->requests[$orig]['status_code'] = $status_code = $request->getResponseCode();
|
||||
// is redirect?
|
||||
if ((in_array($status_code, array(300, 301, 302, 303, 307)) || $status_code > 307 && $status_code < 400) && $request->getResponseHeader('location')) {
|
||||
$redirectURL = $request->getResponseHeader('location');
|
||||
if (!preg_match('!^https?://!i', $redirectURL)) {
|
||||
$redirectURL = SimplePie_Misc::absolutize_url($redirectURL, $url);
|
||||
}
|
||||
//die($url.' -multi- '.$request->getResponseInfo('effective_url'));
|
||||
$pool->detach($request);
|
||||
unset($this->requests[$orig]['httpRequest'], $request);
|
||||
/*
|
||||
if ($this->minimiseMemoryUse) {
|
||||
if ($this->cache($url)) {
|
||||
unset($this->requests[$url]);
|
||||
}
|
||||
if ($this->validateURL($redirectURL)) {
|
||||
$this->debug('Redirect detected. Valid URL: '.$redirectURL);
|
||||
// store any cookies
|
||||
$cookies = $request->getResponseHeader('set-cookie');
|
||||
if ($cookies && !is_array($cookies)) $cookies = array($cookies);
|
||||
if ($cookies) $this->cookieJar->storeCookies($url, $cookies);
|
||||
$this->redirectQueue[$orig] = $redirectURL;
|
||||
} else {
|
||||
$this->debug('Redirect detected. Invalid URL: '.$redirectURL);
|
||||
}
|
||||
*/
|
||||
//}
|
||||
} elseif (!$_header_only_type && $request->getMethod() === HttpRequest::METH_HEAD) {
|
||||
// the response content-type did not match our 'header only' types,
|
||||
// but we'd issues a HEAD request because we assumed it would. So
|
||||
// let's queue a proper GET request for this item...
|
||||
$this->debug('Wrong guess at content-type, queing GET request');
|
||||
$this->requests[$orig]['wrongGuess'] = true;
|
||||
$this->redirectQueue[$orig] = $this->requests[$orig]['effective_url'];
|
||||
}
|
||||
//die($url.' -multi- '.$request->getResponseInfo('effective_url'));
|
||||
$pool->detach($request);
|
||||
unset($this->requests[$orig]['httpRequest'], $request);
|
||||
/*
|
||||
if ($this->minimiseMemoryUse) {
|
||||
if ($this->cache($url)) {
|
||||
unset($this->requests[$url]);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -313,15 +353,26 @@ class HumbleHttpAgent
|
||||
*/
|
||||
} else {
|
||||
$this->debug("......adding to pool");
|
||||
$req_url = ($this->rewriteHashbangFragment) ? $this->rewriteHashbangFragment($url) : $url;
|
||||
$req_url = $this->rewriteUrls($url);
|
||||
$req_url = ($this->rewriteHashbangFragment) ? $this->rewriteHashbangFragment($req_url) : $req_url;
|
||||
$req_url = $this->removeFragment($req_url);
|
||||
if (!empty($this->headerOnlyTypes) && !isset($this->requests[$orig]['wrongGuess']) && $this->possibleUnsupportedType($req_url)) {
|
||||
$_meth = 'HEAD';
|
||||
} else {
|
||||
$_meth = 'GET';
|
||||
unset($this->requests[$orig]['wrongGuess']);
|
||||
}
|
||||
$headers = array();
|
||||
//$headers[] = 'User-Agent: '.$this->userAgent;
|
||||
$headers[] = $this->getUserAgent($req_url);
|
||||
// add referer for picky sites
|
||||
$headers[] = 'Referer: '.$this->referer;
|
||||
// send cookies, if we have any
|
||||
if ($cookies = $this->cookieJar->getMatchingCookies($req_url)) {
|
||||
$this->debug("......sending cookies: $cookies");
|
||||
$headers[] = 'Cookie: '.$cookies;
|
||||
}
|
||||
$httpRequest = new RollingCurlRequest($req_url, 'GET', null, $headers, array(
|
||||
$httpRequest = new RollingCurlRequest($req_url, $_meth, null, $headers, array(
|
||||
CURLOPT_CONNECTTIMEOUT => $this->requestOptions['timeout'],
|
||||
CURLOPT_TIMEOUT => $this->requestOptions['timeout']
|
||||
));
|
||||
@ -341,6 +392,14 @@ class HumbleHttpAgent
|
||||
// $this->requests[$orig]['headers']
|
||||
// $this->requests[$orig]['body']
|
||||
// $this->requests[$orig]['effective_url']
|
||||
// check content type
|
||||
if ($this->headerOnlyType($this->requests[$orig]['headers'])) {
|
||||
$this->requests[$orig]['body'] = '';
|
||||
$_header_only_type = true;
|
||||
$this->debug('Header only type returned');
|
||||
} else {
|
||||
$_header_only_type = false;
|
||||
}
|
||||
$status_code = $this->requests[$orig]['status_code'];
|
||||
if ((in_array($status_code, array(300, 301, 302, 303, 307)) || $status_code > 307 && $status_code < 400) && isset($this->requests[$orig]['location'])) {
|
||||
$redirectURL = $this->requests[$orig]['location'];
|
||||
@ -356,9 +415,16 @@ class HumbleHttpAgent
|
||||
} else {
|
||||
$this->debug('Redirect detected. Invalid URL: '.$redirectURL);
|
||||
}
|
||||
} elseif (!$_header_only_type && $this->requests[$orig]['method'] == 'HEAD') {
|
||||
// the response content-type did not match our 'header only' types,
|
||||
// but we'd issues a HEAD request because we assumed it would. So
|
||||
// let's queue a proper GET request for this item...
|
||||
$this->debug('Wrong guess at content-type, queing GET request');
|
||||
$this->requests[$orig]['wrongGuess'] = true;
|
||||
$this->redirectQueue[$orig] = $this->requests[$orig]['effective_url'];
|
||||
}
|
||||
// die($url.' -multi- '.$request->getResponseInfo('effective_url'));
|
||||
unset($this->requests[$orig]['httpRequest']);
|
||||
unset($this->requests[$orig]['httpRequest'], $this->requests[$orig]['method']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -384,11 +450,15 @@ class HumbleHttpAgent
|
||||
*/
|
||||
} else {
|
||||
$this->debug("Sending request for $url");
|
||||
$this->requests[$orig]['original_url'] = $orig;
|
||||
$req_url = ($this->rewriteHashbangFragment) ? $this->rewriteHashbangFragment($url) : $url;
|
||||
$this->requests[$orig]['original_url'] = $orig;
|
||||
$req_url = $this->rewriteUrls($url);
|
||||
$req_url = ($this->rewriteHashbangFragment) ? $this->rewriteHashbangFragment($req_url) : $req_url;
|
||||
$req_url = $this->removeFragment($req_url);
|
||||
// send cookies, if we have any
|
||||
$httpContext = $this->httpContext;
|
||||
$httpContext['http']['header'] .= $this->getUserAgent($req_url)."\r\n";
|
||||
// add referer for picky sites
|
||||
$httpContext['http']['header'] .= 'Referer: '.$this->referer."\r\n";
|
||||
if ($cookies = $this->cookieJar->getMatchingCookies($req_url)) {
|
||||
$this->debug("......sending cookies: $cookies");
|
||||
$httpContext['http']['header'] .= 'Cookie: '.$cookies."\r\n";
|
||||
@ -401,7 +471,12 @@ class HumbleHttpAgent
|
||||
// TODO: handle error - no status code
|
||||
} else {
|
||||
$this->requests[$orig]['headers'] = $this->headersToString($http_response_header, false);
|
||||
$this->requests[$orig]['body'] = $html;
|
||||
// check content type
|
||||
if ($this->headerOnlyType($this->requests[$orig]['headers'])) {
|
||||
$this->requests[$orig]['body'] = '';
|
||||
} else {
|
||||
$this->requests[$orig]['body'] = $html;
|
||||
}
|
||||
$this->requests[$orig]['effective_url'] = $req_url;
|
||||
$this->requests[$orig]['status_code'] = $status_code = (int)$match[1];
|
||||
unset($match);
|
||||
@ -442,6 +517,7 @@ class HumbleHttpAgent
|
||||
$orig = $request->url_original;
|
||||
$this->requests[$orig]['headers'] = substr($response, 0, $info['header_size']);
|
||||
$this->requests[$orig]['body'] = substr($response, $info['header_size']);
|
||||
$this->requests[$orig]['method'] = $request->method;
|
||||
$this->requests[$orig]['effective_url'] = $info['url'];
|
||||
$this->requests[$orig]['status_code'] = (int)$info['http_code'];
|
||||
if (preg_match('/^Location:(.*?)$/m', $this->requests[$orig]['headers'], $match)) {
|
||||
@ -465,7 +541,7 @@ class HumbleHttpAgent
|
||||
}
|
||||
}
|
||||
|
||||
public function get($url, $remove=false) {
|
||||
public function get($url, $remove=false, $gzdecode=true) {
|
||||
$url = "$url";
|
||||
if (isset($this->requests[$url]) && isset($this->requests[$url]['body'])) {
|
||||
$this->debug("URL already fetched - in memory ($url, effective: {$this->requests[$url]['effective_url']})");
|
||||
@ -493,11 +569,152 @@ class HumbleHttpAgent
|
||||
}
|
||||
*/
|
||||
if ($remove && $response) unset($this->requests[$url]);
|
||||
if ($gzdecode && stripos($response['headers'], 'Content-Encoding: gzip')) {
|
||||
if ($html = gzdecode($response['body'])) {
|
||||
$response['body'] = $html;
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function parallelSupport() {
|
||||
return class_exists('HttpRequestPool') || function_exists('curl_multi_init');
|
||||
}
|
||||
|
||||
private function headerOnlyType($headers) {
|
||||
if (preg_match('!^Content-Type:\s*(([a-z-]+)/([^;\r\n ]+))!im', $headers, $match)) {
|
||||
// look for full mime type (e.g. image/jpeg) or just type (e.g. image)
|
||||
$match[1] = strtolower(trim($match[1]));
|
||||
$match[2] = strtolower(trim($match[2]));
|
||||
foreach (array($match[1], $match[2]) as $mime) {
|
||||
if (in_array($mime, $this->headerOnlyTypes)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function possibleUnsupportedType($url) {
|
||||
$path = @parse_url($url, PHP_URL_PATH);
|
||||
if ($path && strpos($path, '.') !== false) {
|
||||
$ext = strtolower(trim(pathinfo($path, PATHINFO_EXTENSION)));
|
||||
return in_array($ext, $this->headerOnlyClues);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// gzdecode from http://www.php.net/manual/en/function.gzdecode.php#82930
|
||||
if (!function_exists('gzdecode')) {
|
||||
function gzdecode($data,&$filename='',&$error='',$maxlength=null)
|
||||
{
|
||||
$len = strlen($data);
|
||||
if ($len < 18 || strcmp(substr($data,0,2),"\x1f\x8b")) {
|
||||
$error = "Not in GZIP format.";
|
||||
return null; // Not GZIP format (See RFC 1952)
|
||||
}
|
||||
$method = ord(substr($data,2,1)); // Compression method
|
||||
$flags = ord(substr($data,3,1)); // Flags
|
||||
if ($flags & 31 != $flags) {
|
||||
$error = "Reserved bits not allowed.";
|
||||
return null;
|
||||
}
|
||||
// NOTE: $mtime may be negative (PHP integer limitations)
|
||||
$mtime = unpack("V", substr($data,4,4));
|
||||
$mtime = $mtime[1];
|
||||
$xfl = substr($data,8,1);
|
||||
$os = substr($data,8,1);
|
||||
$headerlen = 10;
|
||||
$extralen = 0;
|
||||
$extra = "";
|
||||
if ($flags & 4) {
|
||||
// 2-byte length prefixed EXTRA data in header
|
||||
if ($len - $headerlen - 2 < 8) {
|
||||
return false; // invalid
|
||||
}
|
||||
$extralen = unpack("v",substr($data,8,2));
|
||||
$extralen = $extralen[1];
|
||||
if ($len - $headerlen - 2 - $extralen < 8) {
|
||||
return false; // invalid
|
||||
}
|
||||
$extra = substr($data,10,$extralen);
|
||||
$headerlen += 2 + $extralen;
|
||||
}
|
||||
$filenamelen = 0;
|
||||
$filename = "";
|
||||
if ($flags & 8) {
|
||||
// C-style string
|
||||
if ($len - $headerlen - 1 < 8) {
|
||||
return false; // invalid
|
||||
}
|
||||
$filenamelen = strpos(substr($data,$headerlen),chr(0));
|
||||
if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
|
||||
return false; // invalid
|
||||
}
|
||||
$filename = substr($data,$headerlen,$filenamelen);
|
||||
$headerlen += $filenamelen + 1;
|
||||
}
|
||||
$commentlen = 0;
|
||||
$comment = "";
|
||||
if ($flags & 16) {
|
||||
// C-style string COMMENT data in header
|
||||
if ($len - $headerlen - 1 < 8) {
|
||||
return false; // invalid
|
||||
}
|
||||
$commentlen = strpos(substr($data,$headerlen),chr(0));
|
||||
if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
|
||||
return false; // Invalid header format
|
||||
}
|
||||
$comment = substr($data,$headerlen,$commentlen);
|
||||
$headerlen += $commentlen + 1;
|
||||
}
|
||||
$headercrc = "";
|
||||
if ($flags & 2) {
|
||||
// 2-bytes (lowest order) of CRC32 on header present
|
||||
if ($len - $headerlen - 2 < 8) {
|
||||
return false; // invalid
|
||||
}
|
||||
$calccrc = crc32(substr($data,0,$headerlen)) & 0xffff;
|
||||
$headercrc = unpack("v", substr($data,$headerlen,2));
|
||||
$headercrc = $headercrc[1];
|
||||
if ($headercrc != $calccrc) {
|
||||
$error = "Header checksum failed.";
|
||||
return false; // Bad header CRC
|
||||
}
|
||||
$headerlen += 2;
|
||||
}
|
||||
// GZIP FOOTER
|
||||
$datacrc = unpack("V",substr($data,-8,4));
|
||||
$datacrc = sprintf('%u',$datacrc[1] & 0xFFFFFFFF);
|
||||
$isize = unpack("V",substr($data,-4));
|
||||
$isize = $isize[1];
|
||||
// decompression:
|
||||
$bodylen = $len-$headerlen-8;
|
||||
if ($bodylen < 1) {
|
||||
// IMPLEMENTATION BUG!
|
||||
return null;
|
||||
}
|
||||
$body = substr($data,$headerlen,$bodylen);
|
||||
$data = "";
|
||||
if ($bodylen > 0) {
|
||||
switch ($method) {
|
||||
case 8:
|
||||
// Currently the only supported compression method:
|
||||
$data = gzinflate($body,$maxlength);
|
||||
break;
|
||||
default:
|
||||
$error = "Unknown compression method.";
|
||||
return false;
|
||||
}
|
||||
} // zero-byte body content is allowed
|
||||
// Verifiy CRC32
|
||||
$crc = sprintf("%u",crc32($data));
|
||||
$crcOK = $crc == $datacrc;
|
||||
$lenOK = $isize == strlen($data);
|
||||
if (!$lenOK || !$crcOK) {
|
||||
$error = ( $lenOK ? '' : 'Length check FAILED. ') . ( $crcOK ? '' : 'Checksum FAILED.');
|
||||
return false;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
?>
|
@ -384,6 +384,11 @@ class RollingCurl implements Countable {
|
||||
}
|
||||
// return response headers
|
||||
$options[CURLOPT_HEADER] = 1;
|
||||
|
||||
// send HEAD request?
|
||||
if ($request->method == 'HEAD') {
|
||||
$options[CURLOPT_NOBODY] = 1;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
@ -1,26 +0,0 @@
|
||||
Copyright (c) 2007, Geoffrey Sneddon and Steve Minutillo.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are
|
||||
permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list of
|
||||
conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
of conditions and the following disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
* Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
to endorse or promote products derived from this software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
1635
libraries/language-detect/LanguageDetect.php
Normal file
354
libraries/language-detect/Parser.php
Normal file
@ -0,0 +1,354 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This class represents a text sample to be parsed.
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_LanguageDetect
|
||||
* @author Nicholas Pisarro
|
||||
* @copyright 2006
|
||||
* @license BSD
|
||||
* @version CVS: $Id: Parser.php,v 1.5 2006/03/11 05:45:05 taak Exp $
|
||||
* @link http://pear.php.net/package/Text_LanguageDetect/
|
||||
* @link http://langdetect.blogspot.com/
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class represents a text sample to be parsed.
|
||||
*
|
||||
* This separates the analysis of a text sample from the primary LanguageDetect
|
||||
* class. After a new profile has been built, the data can be retrieved using
|
||||
* the accessor functions.
|
||||
*
|
||||
* This class is intended to be used by the Text_LanguageDetect class, not
|
||||
* end-users.
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_LanguageDetect
|
||||
* @author Nicholas Pisarro
|
||||
* @copyright 2006
|
||||
* @license BSD
|
||||
* @version release: 0.2.3
|
||||
*/
|
||||
class Text_LanguageDetect_Parser extends Text_LanguageDetect
|
||||
{
|
||||
/**
|
||||
* the piece of text being parsed
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $_string;
|
||||
|
||||
/**
|
||||
* stores the trigram frequencies of the sample
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $_trigrams = array();
|
||||
|
||||
/**
|
||||
* stores the trigram ranks of the sample
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $_trigram_ranks = array();
|
||||
|
||||
/**
|
||||
* stores the unicode blocks of the sample
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $_unicode_blocks = array();
|
||||
|
||||
/**
|
||||
* Whether the parser should compile the unicode ranges
|
||||
*
|
||||
* @access private
|
||||
* @var bool
|
||||
*/
|
||||
var $_compile_unicode = false;
|
||||
|
||||
/**
|
||||
* Whether the parser should compile trigrams
|
||||
*
|
||||
* @access private
|
||||
* @var bool
|
||||
*/
|
||||
var $_compile_trigram = false;
|
||||
|
||||
/**
|
||||
* Whether the trigram parser should pad the beginning of the string
|
||||
*
|
||||
* @access private
|
||||
* @var bool
|
||||
*/
|
||||
var $_trigram_pad_start = false;
|
||||
|
||||
/**
|
||||
* Whether the unicode parser should skip non-alphabetical ascii chars
|
||||
*
|
||||
* @access private
|
||||
* @var bool
|
||||
*/
|
||||
var $_unicode_skip_symbols = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access private
|
||||
* @param string $string string to be parsed
|
||||
*/
|
||||
function Text_LanguageDetect_Parser($string, $db=null, $unicode_db=null) {
|
||||
if (isset($db)) $this->_db_filename = $db;
|
||||
if (isset($unicode_db)) $this->_unicode_db_filename = $unicode_db;
|
||||
$this->_string = $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a string is suitable for parsing
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $str input string to test
|
||||
* @return bool true if acceptable, false if not
|
||||
*/
|
||||
function validateString($str) {
|
||||
if (!empty($str) && strlen($str) > 3 && preg_match('/\S/', $str)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* turn on/off trigram counting
|
||||
*
|
||||
* @access public
|
||||
* @param bool $bool true for on, false for off
|
||||
*/
|
||||
function prepareTrigram($bool = true)
|
||||
{
|
||||
$this->_compile_trigram = $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* turn on/off unicode block counting
|
||||
*
|
||||
* @access public
|
||||
* @param bool $bool true for on, false for off
|
||||
*/
|
||||
function prepareUnicode($bool = true)
|
||||
{
|
||||
$this->_compile_unicode = $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* turn on/off padding the beginning of the sample string
|
||||
*
|
||||
* @access public
|
||||
* @param bool $bool true for on, false for off
|
||||
*/
|
||||
function setPadStart($bool = true)
|
||||
{
|
||||
$this->_trigram_pad_start = $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the unicode block counter skip non-alphabetical ascii chars?
|
||||
*
|
||||
* @access public
|
||||
* @param bool $bool true for on, false for off
|
||||
*/
|
||||
function setUnicodeSkipSymbols($bool = true)
|
||||
{
|
||||
$this->_unicode_skip_symbols = $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the trigram ranks for the text sample
|
||||
*
|
||||
* @access public
|
||||
* @return array trigram ranks in the text sample
|
||||
*/
|
||||
function &getTrigramRanks()
|
||||
{
|
||||
return $this->_trigram_ranks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the trigram freqency table
|
||||
*
|
||||
* only used in testing to make sure the parser is working
|
||||
*
|
||||
* @access public
|
||||
* @return array trigram freqencies in the text sample
|
||||
*/
|
||||
function &getTrigramFreqs()
|
||||
{
|
||||
return $this->_trigram;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the array of unicode blocks
|
||||
*
|
||||
* @access public
|
||||
* @return array unicode blocks in the text sample
|
||||
*/
|
||||
function &getUnicodeBlocks()
|
||||
{
|
||||
return $this->_unicode_blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the parsing operation
|
||||
*
|
||||
* Be sure to call the set*() functions to set options and the
|
||||
* prepare*() functions first to tell it what kind of data to compute
|
||||
*
|
||||
* Afterwards the get*() functions can be used to access the compiled
|
||||
* information.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function analyze()
|
||||
{
|
||||
$len = strlen($this->_string);
|
||||
$byte_counter = 0;
|
||||
|
||||
|
||||
// unicode startup
|
||||
if ($this->_compile_unicode) {
|
||||
$blocks =& $this->_read_unicode_block_db();
|
||||
|
||||
$block_count = count($blocks);
|
||||
|
||||
$skipped_count = 0;
|
||||
$unicode_chars = array();
|
||||
}
|
||||
|
||||
// trigram startup
|
||||
if ($this->_compile_trigram) {
|
||||
// initialize them as blank so the parser will skip the first two
|
||||
// (since it skips trigrams with more than 2 contiguous spaces)
|
||||
$a = ' ';
|
||||
$b = ' ';
|
||||
|
||||
// kludge
|
||||
// if it finds a valid trigram to start and the start pad option is
|
||||
// off, then set a variable that will be used to reduce this
|
||||
// trigram after parsing has finished
|
||||
if (!$this->_trigram_pad_start) {
|
||||
$a = $this->_next_char($this->_string, $byte_counter, true);
|
||||
|
||||
if ($a != ' ') {
|
||||
$b = $this->_next_char($this->_string, $byte_counter, true);
|
||||
$dropone = " $a$b";
|
||||
}
|
||||
|
||||
$byte_counter = 0;
|
||||
$a = ' ';
|
||||
$b = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
while ($byte_counter < $len) {
|
||||
$char = $this->_next_char($this->_string, $byte_counter, true);
|
||||
|
||||
|
||||
// language trigram detection
|
||||
if ($this->_compile_trigram) {
|
||||
if (!($b == ' ' && ($a == ' ' || $char == ' '))) {
|
||||
if (!isset($this->_trigram[$a . $b . $char])) {
|
||||
$this->_trigram[$a . $b . $char] = 1;
|
||||
} else {
|
||||
$this->_trigram[$a . $b . $char]++;
|
||||
}
|
||||
}
|
||||
|
||||
$a = $b;
|
||||
$b = $char;
|
||||
}
|
||||
|
||||
// unicode block detection
|
||||
if ($this->_compile_unicode) {
|
||||
if ($this->_unicode_skip_symbols
|
||||
&& strlen($char) == 1
|
||||
&& ($char < 'A' || $char > 'z'
|
||||
|| ($char > 'Z' && $char < 'a'))
|
||||
&& $char != "'") { // does not skip the apostrophe
|
||||
// since it's included in the language
|
||||
// models
|
||||
|
||||
$skipped_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// build an array of all the characters
|
||||
if (isset($unicode_chars[$char])) {
|
||||
$unicode_chars[$char]++;
|
||||
} else {
|
||||
$unicode_chars[$char] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// todo: add byte detection here
|
||||
}
|
||||
|
||||
// unicode cleanup
|
||||
if ($this->_compile_unicode) {
|
||||
foreach ($unicode_chars as $utf8_char => $count) {
|
||||
$search_result = $this->_unicode_block_name(
|
||||
$this->_utf8char2unicode($utf8_char), $blocks, $block_count);
|
||||
|
||||
if ($search_result != -1) {
|
||||
$block_name = $search_result[2];
|
||||
} else {
|
||||
$block_name = '[Malformatted]';
|
||||
}
|
||||
|
||||
if (isset($this->_unicode_blocks[$block_name])) {
|
||||
$this->_unicode_blocks[$block_name] += $count;
|
||||
} else {
|
||||
$this->_unicode_blocks[$block_name] = $count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// trigram cleanup
|
||||
if ($this->_compile_trigram) {
|
||||
// pad the end
|
||||
if ($b != ' ') {
|
||||
if (!isset($this->_trigram["$a$b "])) {
|
||||
$this->_trigram["$a$b "] = 1;
|
||||
} else {
|
||||
$this->_trigram["$a$b "]++;
|
||||
}
|
||||
}
|
||||
|
||||
// perl compatibility; Language::Guess does not pad the beginning
|
||||
// kludge
|
||||
if (isset($dropone)) {
|
||||
if ($this->_trigram[$dropone] == 1) {
|
||||
unset($this->_trigram[$dropone]);
|
||||
} else {
|
||||
$this->_trigram[$dropone]--;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->_trigram)) {
|
||||
$this->_trigram_ranks = $this->_arr_rank($this->_trigram);
|
||||
} else {
|
||||
$this->_trigram_ranks = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
?>
|
1
libraries/language-detect/lang.dat
Normal file
1
libraries/language-detect/unicode_blocks.dat
Normal file
@ -10,7 +10,7 @@
|
||||
* More information: http://fivefilters.org/content-only/
|
||||
* License: Apache License, Version 2.0
|
||||
* Requires: PHP5
|
||||
* Date: 2010-10-29
|
||||
* Date: 2011-07-22
|
||||
*
|
||||
* Differences between the PHP port and the original
|
||||
* ------------------------------------------------------
|
||||
@ -46,7 +46,7 @@
|
||||
require_once(dirname(__FILE__).'/JSLikeHTMLElement.php');
|
||||
|
||||
// Alternative usage (for testing only!)
|
||||
// uncomment the lins below and call Readability.php in your browser
|
||||
// uncomment the lines below and call Readability.php in your browser
|
||||
// passing it the URL of the page you'd like content from, e.g.:
|
||||
// Readability.php?url=http://medialens.org/alerts/09/090615_the_guardian_climate.php
|
||||
|
||||
@ -150,6 +150,7 @@ class Readability
|
||||
**/
|
||||
public function init()
|
||||
{
|
||||
if (!isset($this->dom->documentElement)) return false;
|
||||
$this->removeScripts($this->dom);
|
||||
//die($this->getInnerHTML($this->dom->documentElement));
|
||||
|
||||
@ -293,7 +294,6 @@ class Readability
|
||||
$this->body = $this->dom->createElement('body');
|
||||
$this->dom->documentElement->appendChild($this->body);
|
||||
}
|
||||
|
||||
$this->body->setAttribute('id', 'readabilityBody');
|
||||
|
||||
/* Remove all style tags in head */
|
||||
@ -664,9 +664,19 @@ class Readability
|
||||
if ($topCandidate === null || strtoupper($topCandidate->tagName) == 'BODY')
|
||||
{
|
||||
$topCandidate = $this->dom->createElement('div');
|
||||
$topCandidate->innerHTML = ($page instanceof DOMDocument) ? $page->saveXML($page->documentElement) : $page->innerHTML;
|
||||
$page->innerHTML = '';
|
||||
$page->appendChild($topCandidate);
|
||||
if ($page instanceof DOMDocument) {
|
||||
if (!isset($page->documentElement)) {
|
||||
// we don't have a body either? what a mess! :)
|
||||
} else {
|
||||
$topCandidate->innerHTML = $page->documentElement->innerHTML;
|
||||
$page->documentElement->innerHTML = '';
|
||||
$page->documentElement->appendChild($topCandidate);
|
||||
}
|
||||
} else {
|
||||
$topCandidate->innerHTML = $page->innerHTML;
|
||||
$page->innerHTML = '';
|
||||
$page->appendChild($topCandidate);
|
||||
}
|
||||
$this->initializeNode($topCandidate);
|
||||
}
|
||||
|
||||
@ -678,6 +688,10 @@ class Readability
|
||||
$articleContent->setAttribute('id', 'readability-content');
|
||||
$siblingScoreThreshold = max(10, ((int)$topCandidate->getAttribute('readability')) * 0.2);
|
||||
$siblingNodes = $topCandidate->parentNode->childNodes;
|
||||
if (!isset($siblingNodes)) {
|
||||
$siblingNodes = new stdClass;
|
||||
$siblingNodes->length = 0;
|
||||
}
|
||||
|
||||
for ($s=0, $sl=$siblingNodes->length; $s < $sl; $s++)
|
||||
{
|
||||
@ -769,6 +783,9 @@ class Readability
|
||||
**/
|
||||
if (strlen($this->getInnerText($articleContent, false)) < 250)
|
||||
{
|
||||
// TODO: find out why element disappears sometimes, e.g. for this URL http://www.businessinsider.com/6-hedge-fund-etfs-for-average-investors-2011-7
|
||||
// in the meantime, we check and create an empty element if it's not there.
|
||||
if (!isset($this->body->childNodes)) $this->body = $this->dom->createElement('body');
|
||||
$this->body->innerHTML = $this->bodyCache;
|
||||
|
||||
if ($this->flagIsActive(self::FLAG_STRIP_UNLIKELYS)) {
|
||||
@ -846,6 +863,7 @@ class Readability
|
||||
* @return void
|
||||
*/
|
||||
public function cleanStyles($e) {
|
||||
if (!is_object($e)) return;
|
||||
$elems = $e->getElementsByTagName('*');
|
||||
foreach ($elems as $elem) {
|
||||
$elem->removeAttribute('style');
|
||||
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
require_once '../JSLikeHTMLElement.php';
|
||||
header('Content-Type: text/plain');
|
||||
$doc = new DOMDocument();
|
||||
$doc->registerNodeClass('DOMElement', 'JSLikeHTMLElement');
|
||||
$doc->loadHTML('<div><p>Para 1</p><p>Para 2</p></div>');
|
||||
$elem = $doc->getElementsByTagName('div')->item(0);
|
||||
|
||||
// print innerHTML
|
||||
echo $elem->innerHTML; // prints '<p>Para 1</p><p>Para 2</p>'
|
||||
echo "\n\n";
|
||||
|
||||
// set innerHTML
|
||||
$elem->innerHTML = '<a href="http://fivefilters.org">FiveFilters.org</a>';
|
||||
echo $elem->innerHTML; // prints '<a href="http://fivefilters.org">FiveFilters.org</a>'
|
||||
echo "\n\n";
|
||||
|
||||
// print document (with our changes)
|
||||
echo $doc->saveXML();
|
||||
?>
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
require_once '../Readability.php';
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
|
||||
// get latest Medialens alert
|
||||
// (change this URL to whatever you'd like to test)
|
||||
$url = 'http://medialens.org/alerts/index.php';
|
||||
$html = file_get_contents($url);
|
||||
|
||||
// Note: PHP Readability expects UTF-8 encoded content.
|
||||
// If your content is not UTF-8 encoded, convert it
|
||||
// first before passing it to PHP Readability.
|
||||
// Both iconv() and mb_convert_encoding() can do this.
|
||||
|
||||
// If we've got Tidy, let's clean up input.
|
||||
// This step is highly recommended - PHP's default HTML parser
|
||||
// often does a terrible job and results in strange output.
|
||||
if (function_exists('tidy_parse_string')) {
|
||||
$tidy = tidy_parse_string($html, array(), 'UTF8');
|
||||
$tidy->cleanRepair();
|
||||
$html = $tidy->value;
|
||||
}
|
||||
|
||||
// give it to Readability
|
||||
$readability = new Readability($html, $url);
|
||||
// print debug output?
|
||||
// useful to compare against Arc90's original JS version -
|
||||
// simply click the bookmarklet with FireBug's console window open
|
||||
$readability->debug = false;
|
||||
// convert links to footnotes?
|
||||
$readability->convertLinksToFootnotes = true;
|
||||
// process it
|
||||
$result = $readability->init();
|
||||
// does it look like we found what we wanted?
|
||||
if ($result) {
|
||||
echo "== Title =====================================\n";
|
||||
echo $readability->getTitle()->textContent, "\n\n";
|
||||
echo "== Body ======================================\n";
|
||||
$content = $readability->getContent()->innerHTML;
|
||||
// if we've got Tidy, let's clean it up for output
|
||||
if (function_exists('tidy_parse_string')) {
|
||||
$tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8');
|
||||
$tidy->cleanRepair();
|
||||
$content = $tidy->value;
|
||||
}
|
||||
echo $content;
|
||||
} else {
|
||||
echo 'Looks like we couldn\'t find the content. :(';
|
||||
}
|
||||
?>
|
@ -1,30 +0,0 @@
|
||||
SIMPLEPIE
|
||||
http://simplepie.org
|
||||
By Ryan Parman and Geoffrey Sneddon
|
||||
|
||||
BSD-LICENSED
|
||||
http://www.opensource.org/licenses/bsd-license.php
|
||||
|
||||
WHAT COMES IN THE PACKAGE?
|
||||
1) simplepie.inc - The SimplePie library. This is all that's required for your pages.
|
||||
2) README.txt - This document.
|
||||
3) LICENSE.txt - A copy of the BSD license.
|
||||
4) compatibility_test - The SimplePie compatibility test that checks your server for required settings.
|
||||
5) demo - A basic feed reader demo that shows off some of SimplePie's more noticable features.
|
||||
6) idn - A third-party library that SimplePie can optionally use to understand Internationalized Domain Names (IDNs).
|
||||
7) test - SimplePie's unit test suite. This is only available in SVN builds.
|
||||
|
||||
TO START THE DEMO:
|
||||
1) Upload this package to your webserver.
|
||||
2) Make sure that the cache folder inside of the demo folder is server-writable.
|
||||
3) Navigate your browser to the demo folder.
|
||||
|
||||
SUPPORT:
|
||||
For further setup and install documentation, function references, etc., visit:
|
||||
http://simplepie.org/wiki/
|
||||
|
||||
For bug reports, feature requests and other support, visit:
|
||||
http://simplepie.org/support/
|
||||
|
||||
For more insight on SimplePie development, visit:
|
||||
http://simplepie.org/development/
|
56
libraries/simplepie/SimplePie.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
/**
|
||||
* SimplePie class.
|
||||
*
|
||||
* Class for backward compatibility.
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class SimplePie extends SimplePie_Core
|
||||
{
|
||||
|
||||
}
|
103
libraries/simplepie/SimplePie/Author.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Author
|
||||
{
|
||||
var $name;
|
||||
var $link;
|
||||
var $email;
|
||||
|
||||
// Constructor, used to input the data
|
||||
public function __construct($name = null, $link = null, $email = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->link = $link;
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
if ($this->name !== null)
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_link()
|
||||
{
|
||||
if ($this->link !== null)
|
||||
{
|
||||
return $this->link;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_email()
|
||||
{
|
||||
if ($this->email !== null)
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
109
libraries/simplepie/SimplePie/Cache.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Cache
|
||||
{
|
||||
/**
|
||||
* Cache handler classes
|
||||
*
|
||||
* These receive 3 parameters to their constructor, as documented in
|
||||
* {@see register()}
|
||||
* @var array
|
||||
*/
|
||||
protected static $handlers = array(
|
||||
'mysql' => 'SimplePie_Cache_MySQL',
|
||||
'memcache' => 'SimplePie_Cache_Memcache',
|
||||
);
|
||||
|
||||
/**
|
||||
* Don't call the constructor. Please.
|
||||
*/
|
||||
private function __construct() { }
|
||||
|
||||
/**
|
||||
* Create a new SimplePie_Cache object
|
||||
*/
|
||||
public static function create($location, $filename, $extension)
|
||||
{
|
||||
$type = explode(':', $location, 2);
|
||||
$type = $type[0];
|
||||
if (!empty(self::$handlers[$type]))
|
||||
{
|
||||
$class = self::$handlers[$type];
|
||||
return new $class($location, $filename, $extension);
|
||||
}
|
||||
|
||||
return new SimplePie_Cache_File($location, $filename, $extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a handler
|
||||
*
|
||||
* @param string $type DSN type to register for
|
||||
* @param string $class Name of handler class. Must implement SimplePie_Cache_Base
|
||||
*/
|
||||
public static function register($type, $class)
|
||||
{
|
||||
self::$handlers[$type] = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a URL into an array
|
||||
*
|
||||
* @param string $url
|
||||
* @return array
|
||||
*/
|
||||
public static function parse_URL($url)
|
||||
{
|
||||
$params = parse_url($url);
|
||||
$params['extras'] = array();
|
||||
if (isset($params['query']))
|
||||
{
|
||||
parse_str($params['query'], $params['extras']);
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
}
|
102
libraries/simplepie/SimplePie/Cache/Base.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
interface SimplePie_Cache_Base
|
||||
{
|
||||
/**
|
||||
* Feed cache type
|
||||
*/
|
||||
const TYPE_FEED = 'spc';
|
||||
|
||||
/**
|
||||
* Image cache type
|
||||
*/
|
||||
const TYPE_IMAGE = 'spi';
|
||||
|
||||
/**
|
||||
* Create a new cache object
|
||||
*
|
||||
* @param string $location Location string (from SimplePie::$cache_location)
|
||||
* @param string $name Unique ID for the cache
|
||||
* @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
|
||||
*/
|
||||
public function __construct($location, $name, $type);
|
||||
|
||||
/**
|
||||
* Save data to the cache
|
||||
*
|
||||
* @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
|
||||
*/
|
||||
public function save($data);
|
||||
|
||||
/**
|
||||
* Retrieve the data saved to the cache
|
||||
*
|
||||
* @return array Data for SimplePie::$data
|
||||
*/
|
||||
public function load();
|
||||
|
||||
/**
|
||||
* Retrieve the last modified time for the cache
|
||||
*
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function mtime();
|
||||
|
||||
/**
|
||||
* Set the last modified time to the current time
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function touch();
|
||||
|
||||
/**
|
||||
* Remove the cache
|
||||
*
|
||||
* @return bool Success status
|
||||
*/
|
||||
public function unlink();
|
||||
}
|
124
libraries/simplepie/SimplePie/Cache/DB.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base
|
||||
{
|
||||
protected static function prepare_simplepie_object_for_cache(&$data)
|
||||
{
|
||||
$items = $data->get_items();
|
||||
$items_by_id = array();
|
||||
|
||||
if (!empty($items))
|
||||
{
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$items_by_id[$item->get_id()] = $item;
|
||||
}
|
||||
|
||||
if (count($items_by_id) !== count($items))
|
||||
{
|
||||
$items_by_id = array();
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$items_by_id[$item->get_id(true)] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
|
||||
}
|
||||
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
|
||||
}
|
||||
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
|
||||
}
|
||||
elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
|
||||
{
|
||||
$channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$channel = null;
|
||||
}
|
||||
|
||||
if ($channel !== null)
|
||||
{
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
|
||||
}
|
||||
if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
|
||||
{
|
||||
unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
|
||||
}
|
||||
}
|
||||
if (isset($data->data['items']))
|
||||
{
|
||||
unset($data->data['items']);
|
||||
}
|
||||
if (isset($data->data['ordered_items']))
|
||||
{
|
||||
unset($data->data['ordered_items']);
|
||||
}
|
||||
}
|
||||
return array(serialize($data->data), $items_by_id);
|
||||
}
|
||||
}
|
112
libraries/simplepie/SimplePie/Cache/File.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Cache_File implements SimplePie_Cache_Base
|
||||
{
|
||||
protected $location;
|
||||
protected $filename;
|
||||
protected $extension;
|
||||
protected $name;
|
||||
|
||||
public function __construct($location, $filename, $extension)
|
||||
{
|
||||
$this->location = $location;
|
||||
$this->filename = $filename;
|
||||
$this->extension = $extension;
|
||||
$this->name = "$this->location/$this->filename.$this->extension";
|
||||
}
|
||||
|
||||
public function save($data)
|
||||
{
|
||||
if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
|
||||
{
|
||||
if (is_a($data, 'SimplePie'))
|
||||
{
|
||||
$data = $data->data;
|
||||
}
|
||||
|
||||
$data = serialize($data);
|
||||
return (bool) file_put_contents($this->name, $data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
if (file_exists($this->name) && is_readable($this->name))
|
||||
{
|
||||
return unserialize(file_get_contents($this->name));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function mtime()
|
||||
{
|
||||
if (file_exists($this->name))
|
||||
{
|
||||
return filemtime($this->name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function touch()
|
||||
{
|
||||
if (file_exists($this->name))
|
||||
{
|
||||
return touch($this->name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function unlink()
|
||||
{
|
||||
if (file_exists($this->name))
|
||||
{
|
||||
return unlink($this->name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
118
libraries/simplepie/SimplePie/Cache/Memcache.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
class SimplePie_Cache_Memcache implements SimplePie_Cache_Base
|
||||
{
|
||||
protected $cache;
|
||||
protected $options;
|
||||
protected $name;
|
||||
|
||||
public function __construct($url, $filename, $extension)
|
||||
{
|
||||
$this->options = array(
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 11211,
|
||||
'extras' => array(
|
||||
'timeout' => 3600, // one hour
|
||||
'prefix' => 'simplepie_',
|
||||
),
|
||||
);
|
||||
$this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($url));
|
||||
$this->name = $this->options['extras']['prefix'] . md5("$filename:$extension");
|
||||
|
||||
$this->cache = new Memcache();
|
||||
$this->cache->addServer($this->options['host'], (int) $this->options['port']);
|
||||
}
|
||||
|
||||
public function save($data)
|
||||
{
|
||||
if (is_a($data, 'SimplePie'))
|
||||
{
|
||||
$data = $data->data;
|
||||
}
|
||||
return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false)
|
||||
{
|
||||
return unserialize($data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function mtime()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false)
|
||||
{
|
||||
// essentially ignore the mtime because Memcache expires on it's own
|
||||
return time();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function touch()
|
||||
{
|
||||
$data = $this->cache->get($this->name);
|
||||
|
||||
if ($data !== false)
|
||||
{
|
||||
return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->duration);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function unlink()
|
||||
{
|
||||
return $this->cache->delete($this->name);
|
||||
}
|
||||
}
|
378
libraries/simplepie/SimplePie/Cache/MySQL.php
Normal file
@ -0,0 +1,378 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
|
||||
{
|
||||
protected $mysql;
|
||||
protected $options;
|
||||
protected $id;
|
||||
|
||||
public function __construct($url, $name, $extension)
|
||||
{
|
||||
$this->options = array(
|
||||
'user' => null,
|
||||
'pass' => null,
|
||||
'host' => '127.0.0.1',
|
||||
'port' => '3306',
|
||||
'path' => '',
|
||||
'extras' => array(
|
||||
'prefix' => '',
|
||||
),
|
||||
);
|
||||
$this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($url));
|
||||
|
||||
// Path is prefixed with a "/"
|
||||
$this->options['dbname'] = substr($this->options['path'], 1);
|
||||
|
||||
try
|
||||
{
|
||||
$this->mysql = new PDO("mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options['user'], $this->options['pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
$this->mysql = null;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->id = $name . $extension;
|
||||
|
||||
if (!$query = $this->mysql->query('SHOW TABLES'))
|
||||
{
|
||||
$this->mysql = null;
|
||||
return;
|
||||
}
|
||||
|
||||
$db = array();
|
||||
while ($row = $query->fetchColumn())
|
||||
{
|
||||
$db[] = $row;
|
||||
}
|
||||
|
||||
if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db))
|
||||
{
|
||||
$query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))');
|
||||
if ($query === false)
|
||||
{
|
||||
$this->mysql = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_array($this->options['extras']['prefix'] . 'items', $db))
|
||||
{
|
||||
$query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` TEXT CHARACTER SET utf8 NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))');
|
||||
if ($query === false)
|
||||
{
|
||||
$this->mysql = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function save($data)
|
||||
{
|
||||
if ($this->mysql === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_a($data, 'SimplePie'))
|
||||
{
|
||||
$data = clone $data;
|
||||
|
||||
$prepared = self::prepare_simplepie_object_for_cache($data);
|
||||
|
||||
$query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($query->execute())
|
||||
{
|
||||
if ($query->fetchColumn() > 0)
|
||||
{
|
||||
$items = count($prepared[1]);
|
||||
if ($items)
|
||||
{
|
||||
$sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
|
||||
$query = $this->mysql->prepare($sql);
|
||||
$query->bindValue(':items', $items);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
|
||||
$query = $this->mysql->prepare($sql);
|
||||
}
|
||||
|
||||
$query->bindValue(':data', $prepared[0]);
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if (!$query->execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
$query->bindValue(':count', count($prepared[1]));
|
||||
$query->bindValue(':data', $prepared[0]);
|
||||
$query->bindValue(':time', time());
|
||||
if (!$query->execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$ids = array_keys($prepared[1]);
|
||||
if (!empty($ids))
|
||||
{
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
$database_ids[] = $this->mysql->quote($id);
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
|
||||
if ($query->execute())
|
||||
{
|
||||
$existing_ids = array();
|
||||
while ($row = $query->fetchColumn())
|
||||
{
|
||||
$existing_ids[] = $row;
|
||||
}
|
||||
|
||||
$new_ids = array_diff($ids, $existing_ids);
|
||||
|
||||
foreach ($new_ids as $new_id)
|
||||
{
|
||||
if (!($date = $prepared[1][$new_id]->get_date('U')))
|
||||
{
|
||||
$date = time();
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
$query->bindValue(':id', $new_id);
|
||||
$query->bindValue(':data', serialize($prepared[1][$new_id]->data));
|
||||
$query->bindValue(':date', $date);
|
||||
if (!$query->execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($query->execute())
|
||||
{
|
||||
if ($query->rowCount() > 0)
|
||||
{
|
||||
$query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
|
||||
$query->bindValue(':data', serialize($data));
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($this->execute())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)');
|
||||
$query->bindValue(':id', $this->id);
|
||||
$query->bindValue(':data', serialize($data));
|
||||
$query->bindValue(':time', time());
|
||||
if ($query->execute())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function load()
|
||||
{
|
||||
if ($this->mysql === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
|
||||
$query->bindValue(':id', $this->id);
|
||||
if ($query->execute() && ($row = $query->fetch()))
|
||||
{
|
||||
$data = unserialize($row[1]);
|
||||
|
||||
if (isset($this->options['items'][0]))
|
||||
{
|
||||
$items = (int) $this->options['items'][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$items = (int) $row[0];
|
||||
}
|
||||
|
||||
if ($items !== 0)
|
||||
{
|
||||
if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
|
||||
{
|
||||
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
|
||||
}
|
||||
elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
|
||||
{
|
||||
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
|
||||
}
|
||||
elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
|
||||
{
|
||||
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
|
||||
}
|
||||
elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]))
|
||||
{
|
||||
$feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$feed = null;
|
||||
}
|
||||
|
||||
if ($feed !== null)
|
||||
{
|
||||
$sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC';
|
||||
if ($items > 0)
|
||||
{
|
||||
$sql .= ' LIMIT ' . $items;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare($sql);
|
||||
$query->bindValue(':feed', $this->id);
|
||||
if ($query->execute())
|
||||
{
|
||||
while ($row = $query->fetchColumn())
|
||||
{
|
||||
$feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function mtime()
|
||||
{
|
||||
if ($this->mysql === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
|
||||
$query->bindValue(':id', $this->id);
|
||||
if ($query->execute() && ($time = $query->fetchColumn()))
|
||||
{
|
||||
return $time;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function touch()
|
||||
{
|
||||
if ($this->mysql === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id');
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':id', $this->id);
|
||||
if ($query->execute() && $query->rowCount() > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function unlink()
|
||||
{
|
||||
if ($this->mysql === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
|
||||
$query->bindValue(':id', $this->id);
|
||||
$query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id');
|
||||
$query2->bindValue(':id', $this->id);
|
||||
if ($query->execute() && $query2->execute())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
131
libraries/simplepie/SimplePie/Caption.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Caption
|
||||
{
|
||||
var $type;
|
||||
var $lang;
|
||||
var $startTime;
|
||||
var $endTime;
|
||||
var $text;
|
||||
|
||||
// Constructor, used to input the data
|
||||
public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->lang = $lang;
|
||||
$this->startTime = $startTime;
|
||||
$this->endTime = $endTime;
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
public function get_endtime()
|
||||
{
|
||||
if ($this->endTime !== null)
|
||||
{
|
||||
return $this->endTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_language()
|
||||
{
|
||||
if ($this->lang !== null)
|
||||
{
|
||||
return $this->lang;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_starttime()
|
||||
{
|
||||
if ($this->startTime !== null)
|
||||
{
|
||||
return $this->startTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_text()
|
||||
{
|
||||
if ($this->text !== null)
|
||||
{
|
||||
return $this->text;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_type()
|
||||
{
|
||||
if ($this->type !== null)
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
103
libraries/simplepie/SimplePie/Category.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Category
|
||||
{
|
||||
var $term;
|
||||
var $scheme;
|
||||
var $label;
|
||||
|
||||
// Constructor, used to input the data
|
||||
public function __construct($term = null, $scheme = null, $label = null)
|
||||
{
|
||||
$this->term = $term;
|
||||
$this->scheme = $scheme;
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
public function get_term()
|
||||
{
|
||||
if ($this->term !== null)
|
||||
{
|
||||
return $this->term;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_scheme()
|
||||
{
|
||||
if ($this->scheme !== null)
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_label()
|
||||
{
|
||||
if ($this->label !== null)
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->get_term();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
325
libraries/simplepie/SimplePie/Content/Type/Sniffer.php
Normal file
@ -0,0 +1,325 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Content-type sniffing
|
||||
*
|
||||
* Based on the rules in http://tools.ietf.org/html/draft-abarth-mime-sniff-06
|
||||
* @package SimplePie
|
||||
*/
|
||||
class SimplePie_Content_Type_Sniffer
|
||||
{
|
||||
/**
|
||||
* File object
|
||||
*
|
||||
* @var SimplePie_File
|
||||
*/
|
||||
var $file;
|
||||
|
||||
/**
|
||||
* Create an instance of the class with the input file
|
||||
*
|
||||
* @param SimplePie_Content_Type_Sniffer $file Input file
|
||||
*/
|
||||
public function __construct($file)
|
||||
{
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Content-Type of the specified file
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function get_type()
|
||||
{
|
||||
if (isset($this->file->headers['content-type']))
|
||||
{
|
||||
if (!isset($this->file->headers['content-encoding'])
|
||||
&& ($this->file->headers['content-type'] === 'text/plain'
|
||||
|| $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
|
||||
|| $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'
|
||||
|| $this->file->headers['content-type'] === 'text/plain; charset=UTF-8'))
|
||||
{
|
||||
return $this->text_or_binary();
|
||||
}
|
||||
|
||||
if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
|
||||
{
|
||||
$official = substr($this->file->headers['content-type'], 0, $pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
$official = $this->file->headers['content-type'];
|
||||
}
|
||||
$official = trim(strtolower($official));
|
||||
|
||||
if ($official === 'unknown/unknown'
|
||||
|| $official === 'application/unknown')
|
||||
{
|
||||
return $this->unknown();
|
||||
}
|
||||
elseif (substr($official, -4) === '+xml'
|
||||
|| $official === 'text/xml'
|
||||
|| $official === 'application/xml')
|
||||
{
|
||||
return $official;
|
||||
}
|
||||
elseif (substr($official, 0, 6) === 'image/')
|
||||
{
|
||||
if ($return = $this->image())
|
||||
{
|
||||
return $return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $official;
|
||||
}
|
||||
}
|
||||
elseif ($official === 'text/html')
|
||||
{
|
||||
return $this->feed_or_html();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $official;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->unknown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff text or binary
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function text_or_binary()
|
||||
{
|
||||
if (substr($this->file->body, 0, 2) === "\xFE\xFF"
|
||||
|| substr($this->file->body, 0, 2) === "\xFF\xFE"
|
||||
|| substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
|
||||
|| substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
|
||||
{
|
||||
return 'text/plain';
|
||||
}
|
||||
elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
|
||||
{
|
||||
return 'application/octect-stream';
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'text/plain';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff unknown
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function unknown()
|
||||
{
|
||||
$ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
|
||||
if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
|
||||
|| strtolower(substr($this->file->body, $ws, 5)) === '<html'
|
||||
|| strtolower(substr($this->file->body, $ws, 7)) === '<script')
|
||||
{
|
||||
return 'text/html';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 5) === '%PDF-')
|
||||
{
|
||||
return 'application/pdf';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
|
||||
{
|
||||
return 'application/postscript';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 6) === 'GIF87a'
|
||||
|| substr($this->file->body, 0, 6) === 'GIF89a')
|
||||
{
|
||||
return 'image/gif';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
|
||||
{
|
||||
return 'image/png';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
|
||||
{
|
||||
return 'image/jpeg';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
|
||||
{
|
||||
return 'image/bmp';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
|
||||
{
|
||||
return 'image/vnd.microsoft.icon';
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->text_or_binary();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff images
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function image()
|
||||
{
|
||||
if (substr($this->file->body, 0, 6) === 'GIF87a'
|
||||
|| substr($this->file->body, 0, 6) === 'GIF89a')
|
||||
{
|
||||
return 'image/gif';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
|
||||
{
|
||||
return 'image/png';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
|
||||
{
|
||||
return 'image/jpeg';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
|
||||
{
|
||||
return 'image/bmp';
|
||||
}
|
||||
elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
|
||||
{
|
||||
return 'image/vnd.microsoft.icon';
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sniff HTML
|
||||
*
|
||||
* @return string Actual Content-Type
|
||||
*/
|
||||
public function feed_or_html()
|
||||
{
|
||||
$len = strlen($this->file->body);
|
||||
$pos = strspn($this->file->body, "\x09\x0A\x0D\x20");
|
||||
|
||||
while ($pos < $len)
|
||||
{
|
||||
switch ($this->file->body[$pos])
|
||||
{
|
||||
case "\x09":
|
||||
case "\x0A":
|
||||
case "\x0D":
|
||||
case "\x20":
|
||||
$pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
|
||||
continue 2;
|
||||
|
||||
case '<':
|
||||
$pos++;
|
||||
break;
|
||||
|
||||
default:
|
||||
return 'text/html';
|
||||
}
|
||||
|
||||
if (substr($this->file->body, $pos, 3) === '!--')
|
||||
{
|
||||
$pos += 3;
|
||||
if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false)
|
||||
{
|
||||
$pos += 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'text/html';
|
||||
}
|
||||
}
|
||||
elseif (substr($this->file->body, $pos, 1) === '!')
|
||||
{
|
||||
if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false)
|
||||
{
|
||||
$pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'text/html';
|
||||
}
|
||||
}
|
||||
elseif (substr($this->file->body, $pos, 1) === '?')
|
||||
{
|
||||
if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false)
|
||||
{
|
||||
$pos += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'text/html';
|
||||
}
|
||||
}
|
||||
elseif (substr($this->file->body, $pos, 3) === 'rss'
|
||||
|| substr($this->file->body, $pos, 7) === 'rdf:RDF')
|
||||
{
|
||||
return 'application/rss+xml';
|
||||
}
|
||||
elseif (substr($this->file->body, $pos, 4) === 'feed')
|
||||
{
|
||||
return 'application/atom+xml';
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'text/html';
|
||||
}
|
||||
}
|
||||
|
||||
return 'text/html';
|
||||
}
|
||||
}
|
||||
|
89
libraries/simplepie/SimplePie/Copyright.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Copyright
|
||||
{
|
||||
var $url;
|
||||
var $label;
|
||||
|
||||
// Constructor, used to input the data
|
||||
public function __construct($url = null, $label = null)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
public function get_url()
|
||||
{
|
||||
if ($this->url !== null)
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_attribution()
|
||||
{
|
||||
if ($this->label !== null)
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2838
libraries/simplepie/SimplePie/Core.php
Normal file
103
libraries/simplepie/SimplePie/Credit.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Credit
|
||||
{
|
||||
var $role;
|
||||
var $scheme;
|
||||
var $name;
|
||||
|
||||
// Constructor, used to input the data
|
||||
public function __construct($role = null, $scheme = null, $name = null)
|
||||
{
|
||||
$this->role = $role;
|
||||
$this->scheme = $scheme;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
public function get_role()
|
||||
{
|
||||
if ($this->role !== null)
|
||||
{
|
||||
return $this->role;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_scheme()
|
||||
{
|
||||
if ($this->scheme !== null)
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
if ($this->name !== null)
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
250
libraries/simplepie/SimplePie/Decode/HTML/Entities.php
Normal file
990
libraries/simplepie/SimplePie/Enclosure.php
Normal file
@ -0,0 +1,990 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Enclosure
|
||||
{
|
||||
var $bitrate;
|
||||
var $captions;
|
||||
var $categories;
|
||||
var $channels;
|
||||
var $copyright;
|
||||
var $credits;
|
||||
var $description;
|
||||
var $duration;
|
||||
var $expression;
|
||||
var $framerate;
|
||||
var $handler;
|
||||
var $hashes;
|
||||
var $height;
|
||||
var $javascript;
|
||||
var $keywords;
|
||||
var $lang;
|
||||
var $length;
|
||||
var $link;
|
||||
var $medium;
|
||||
var $player;
|
||||
var $ratings;
|
||||
var $restrictions;
|
||||
var $samplingrate;
|
||||
var $thumbnails;
|
||||
var $title;
|
||||
var $type;
|
||||
var $width;
|
||||
|
||||
// Constructor, used to input the data
|
||||
public function __construct($link = null, $type = null, $length = null, $javascript = null, $bitrate = null, $captions = null, $categories = null, $channels = null, $copyright = null, $credits = null, $description = null, $duration = null, $expression = null, $framerate = null, $hashes = null, $height = null, $keywords = null, $lang = null, $medium = null, $player = null, $ratings = null, $restrictions = null, $samplingrate = null, $thumbnails = null, $title = null, $width = null)
|
||||
{
|
||||
$this->bitrate = $bitrate;
|
||||
$this->captions = $captions;
|
||||
$this->categories = $categories;
|
||||
$this->channels = $channels;
|
||||
$this->copyright = $copyright;
|
||||
$this->credits = $credits;
|
||||
$this->description = $description;
|
||||
$this->duration = $duration;
|
||||
$this->expression = $expression;
|
||||
$this->framerate = $framerate;
|
||||
$this->hashes = $hashes;
|
||||
$this->height = $height;
|
||||
$this->keywords = $keywords;
|
||||
$this->lang = $lang;
|
||||
$this->length = $length;
|
||||
$this->link = $link;
|
||||
$this->medium = $medium;
|
||||
$this->player = $player;
|
||||
$this->ratings = $ratings;
|
||||
$this->restrictions = $restrictions;
|
||||
$this->samplingrate = $samplingrate;
|
||||
$this->thumbnails = $thumbnails;
|
||||
$this->title = $title;
|
||||
$this->type = $type;
|
||||
$this->width = $width;
|
||||
|
||||
if (class_exists('idna_convert'))
|
||||
{
|
||||
$idn = new idna_convert();
|
||||
$parsed = SimplePie_Misc::parse_url($link);
|
||||
$this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
|
||||
}
|
||||
$this->handler = $this->get_handler(); // Needs to load last
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
public function get_bitrate()
|
||||
{
|
||||
if ($this->bitrate !== null)
|
||||
{
|
||||
return $this->bitrate;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_caption($key = 0)
|
||||
{
|
||||
$captions = $this->get_captions();
|
||||
if (isset($captions[$key]))
|
||||
{
|
||||
return $captions[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_captions()
|
||||
{
|
||||
if ($this->captions !== null)
|
||||
{
|
||||
return $this->captions;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_category($key = 0)
|
||||
{
|
||||
$categories = $this->get_categories();
|
||||
if (isset($categories[$key]))
|
||||
{
|
||||
return $categories[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_categories()
|
||||
{
|
||||
if ($this->categories !== null)
|
||||
{
|
||||
return $this->categories;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_channels()
|
||||
{
|
||||
if ($this->channels !== null)
|
||||
{
|
||||
return $this->channels;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_copyright()
|
||||
{
|
||||
if ($this->copyright !== null)
|
||||
{
|
||||
return $this->copyright;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_credit($key = 0)
|
||||
{
|
||||
$credits = $this->get_credits();
|
||||
if (isset($credits[$key]))
|
||||
{
|
||||
return $credits[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_credits()
|
||||
{
|
||||
if ($this->credits !== null)
|
||||
{
|
||||
return $this->credits;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_description()
|
||||
{
|
||||
if ($this->description !== null)
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_duration($convert = false)
|
||||
{
|
||||
if ($this->duration !== null)
|
||||
{
|
||||
if ($convert)
|
||||
{
|
||||
$time = SimplePie_Misc::time_hms($this->duration);
|
||||
return $time;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->duration;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_expression()
|
||||
{
|
||||
if ($this->expression !== null)
|
||||
{
|
||||
return $this->expression;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'full';
|
||||
}
|
||||
}
|
||||
|
||||
public function get_extension()
|
||||
{
|
||||
if ($this->link !== null)
|
||||
{
|
||||
$url = SimplePie_Misc::parse_url($this->link);
|
||||
if ($url['path'] !== '')
|
||||
{
|
||||
return pathinfo($url['path'], PATHINFO_EXTENSION);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_framerate()
|
||||
{
|
||||
if ($this->framerate !== null)
|
||||
{
|
||||
return $this->framerate;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_handler()
|
||||
{
|
||||
return $this->get_real_type(true);
|
||||
}
|
||||
|
||||
public function get_hash($key = 0)
|
||||
{
|
||||
$hashes = $this->get_hashes();
|
||||
if (isset($hashes[$key]))
|
||||
{
|
||||
return $hashes[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_hashes()
|
||||
{
|
||||
if ($this->hashes !== null)
|
||||
{
|
||||
return $this->hashes;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_height()
|
||||
{
|
||||
if ($this->height !== null)
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_language()
|
||||
{
|
||||
if ($this->lang !== null)
|
||||
{
|
||||
return $this->lang;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_keyword($key = 0)
|
||||
{
|
||||
$keywords = $this->get_keywords();
|
||||
if (isset($keywords[$key]))
|
||||
{
|
||||
return $keywords[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_keywords()
|
||||
{
|
||||
if ($this->keywords !== null)
|
||||
{
|
||||
return $this->keywords;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_length()
|
||||
{
|
||||
if ($this->length !== null)
|
||||
{
|
||||
return $this->length;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_link()
|
||||
{
|
||||
if ($this->link !== null)
|
||||
{
|
||||
return urldecode($this->link);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_medium()
|
||||
{
|
||||
if ($this->medium !== null)
|
||||
{
|
||||
return $this->medium;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_player()
|
||||
{
|
||||
if ($this->player !== null)
|
||||
{
|
||||
return $this->player;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_rating($key = 0)
|
||||
{
|
||||
$ratings = $this->get_ratings();
|
||||
if (isset($ratings[$key]))
|
||||
{
|
||||
return $ratings[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_ratings()
|
||||
{
|
||||
if ($this->ratings !== null)
|
||||
{
|
||||
return $this->ratings;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_restriction($key = 0)
|
||||
{
|
||||
$restrictions = $this->get_restrictions();
|
||||
if (isset($restrictions[$key]))
|
||||
{
|
||||
return $restrictions[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_restrictions()
|
||||
{
|
||||
if ($this->restrictions !== null)
|
||||
{
|
||||
return $this->restrictions;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_sampling_rate()
|
||||
{
|
||||
if ($this->samplingrate !== null)
|
||||
{
|
||||
return $this->samplingrate;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_size()
|
||||
{
|
||||
$length = $this->get_length();
|
||||
if ($length !== null)
|
||||
{
|
||||
return round($length/1048576, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_thumbnail($key = 0)
|
||||
{
|
||||
$thumbnails = $this->get_thumbnails();
|
||||
if (isset($thumbnails[$key]))
|
||||
{
|
||||
return $thumbnails[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_thumbnails()
|
||||
{
|
||||
if ($this->thumbnails !== null)
|
||||
{
|
||||
return $this->thumbnails;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_title()
|
||||
{
|
||||
if ($this->title !== null)
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_type()
|
||||
{
|
||||
if ($this->type !== null)
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_width()
|
||||
{
|
||||
if ($this->width !== null)
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function native_embed($options='')
|
||||
{
|
||||
return $this->embed($options, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'.
|
||||
*/
|
||||
public function embed($options = '', $native = false)
|
||||
{
|
||||
// Set up defaults
|
||||
$audio = '';
|
||||
$video = '';
|
||||
$alt = '';
|
||||
$altclass = '';
|
||||
$loop = 'false';
|
||||
$width = 'auto';
|
||||
$height = 'auto';
|
||||
$bgcolor = '#ffffff';
|
||||
$mediaplayer = '';
|
||||
$widescreen = false;
|
||||
$handler = $this->get_handler();
|
||||
$type = $this->get_real_type();
|
||||
|
||||
// Process options and reassign values as necessary
|
||||
if (is_array($options))
|
||||
{
|
||||
extract($options);
|
||||
}
|
||||
else
|
||||
{
|
||||
$options = explode(',', $options);
|
||||
foreach($options as $option)
|
||||
{
|
||||
$opt = explode(':', $option, 2);
|
||||
if (isset($opt[0], $opt[1]))
|
||||
{
|
||||
$opt[0] = trim($opt[0]);
|
||||
$opt[1] = trim($opt[1]);
|
||||
switch ($opt[0])
|
||||
{
|
||||
case 'audio':
|
||||
$audio = $opt[1];
|
||||
break;
|
||||
|
||||
case 'video':
|
||||
$video = $opt[1];
|
||||
break;
|
||||
|
||||
case 'alt':
|
||||
$alt = $opt[1];
|
||||
break;
|
||||
|
||||
case 'altclass':
|
||||
$altclass = $opt[1];
|
||||
break;
|
||||
|
||||
case 'loop':
|
||||
$loop = $opt[1];
|
||||
break;
|
||||
|
||||
case 'width':
|
||||
$width = $opt[1];
|
||||
break;
|
||||
|
||||
case 'height':
|
||||
$height = $opt[1];
|
||||
break;
|
||||
|
||||
case 'bgcolor':
|
||||
$bgcolor = $opt[1];
|
||||
break;
|
||||
|
||||
case 'mediaplayer':
|
||||
$mediaplayer = $opt[1];
|
||||
break;
|
||||
|
||||
case 'widescreen':
|
||||
$widescreen = $opt[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$mime = explode('/', $type, 2);
|
||||
$mime = $mime[0];
|
||||
|
||||
// Process values for 'auto'
|
||||
if ($width === 'auto')
|
||||
{
|
||||
if ($mime === 'video')
|
||||
{
|
||||
if ($height === 'auto')
|
||||
{
|
||||
$width = 480;
|
||||
}
|
||||
elseif ($widescreen)
|
||||
{
|
||||
$width = round((intval($height)/9)*16);
|
||||
}
|
||||
else
|
||||
{
|
||||
$width = round((intval($height)/3)*4);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$width = '100%';
|
||||
}
|
||||
}
|
||||
|
||||
if ($height === 'auto')
|
||||
{
|
||||
if ($mime === 'audio')
|
||||
{
|
||||
$height = 0;
|
||||
}
|
||||
elseif ($mime === 'video')
|
||||
{
|
||||
if ($width === 'auto')
|
||||
{
|
||||
if ($widescreen)
|
||||
{
|
||||
$height = 270;
|
||||
}
|
||||
else
|
||||
{
|
||||
$height = 360;
|
||||
}
|
||||
}
|
||||
elseif ($widescreen)
|
||||
{
|
||||
$height = round((intval($width)/16)*9);
|
||||
}
|
||||
else
|
||||
{
|
||||
$height = round((intval($width)/4)*3);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$height = 376;
|
||||
}
|
||||
}
|
||||
elseif ($mime === 'audio')
|
||||
{
|
||||
$height = 0;
|
||||
}
|
||||
|
||||
// Set proper placeholder value
|
||||
if ($mime === 'audio')
|
||||
{
|
||||
$placeholder = $audio;
|
||||
}
|
||||
elseif ($mime === 'video')
|
||||
{
|
||||
$placeholder = $video;
|
||||
}
|
||||
|
||||
$embed = '';
|
||||
|
||||
// Odeo Feed MP3's
|
||||
if ($handler === 'odeo')
|
||||
{
|
||||
if ($native)
|
||||
{
|
||||
$embed .= '<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://adobe.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url=' . $this->get_link() . '"></embed>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$embed .= '<script type="text/javascript">embed_odeo("' . $this->get_link() . '");</script>';
|
||||
}
|
||||
}
|
||||
|
||||
// Flash
|
||||
elseif ($handler === 'flash')
|
||||
{
|
||||
if ($native)
|
||||
{
|
||||
$embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
|
||||
}
|
||||
}
|
||||
|
||||
// Flash Media Player file types.
|
||||
// Preferred handler for MP3 file types.
|
||||
elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== ''))
|
||||
{
|
||||
$height += 20;
|
||||
if ($native)
|
||||
{
|
||||
$embed .= "<embed src=\"$mediaplayer\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" width=\"$width\" height=\"$height\" wmode=\"transparent\" flashvars=\"file=" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "&autostart=false&repeat=$loop&showdigits=true&showfsbutton=false\"></embed>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>";
|
||||
}
|
||||
}
|
||||
|
||||
// QuickTime 7 file types. Need to test with QuickTime 6.
|
||||
// Only handle MP3's if the Flash Media Player is not present.
|
||||
elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === ''))
|
||||
{
|
||||
$height += 16;
|
||||
if ($native)
|
||||
{
|
||||
if ($placeholder !== '')
|
||||
{
|
||||
$embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" href=\"" . $this->get_link() . "\" src=\"$placeholder\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"false\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" src=\"" . $this->get_link() . "\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"true\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
|
||||
}
|
||||
}
|
||||
|
||||
// Windows Media
|
||||
elseif ($handler === 'wmedia')
|
||||
{
|
||||
$height += 45;
|
||||
if ($native)
|
||||
{
|
||||
$embed .= "<embed type=\"application/x-mplayer2\" src=\"" . $this->get_link() . "\" autosize=\"1\" width=\"$width\" height=\"$height\" showcontrols=\"1\" showstatusbar=\"0\" showdisplay=\"0\" autostart=\"0\"></embed>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
|
||||
}
|
||||
}
|
||||
|
||||
// Everything else
|
||||
else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
|
||||
|
||||
return $embed;
|
||||
}
|
||||
|
||||
public function get_real_type($find_handler = false)
|
||||
{
|
||||
// If it's Odeo, let's get it out of the way.
|
||||
if (substr(strtolower($this->get_link()), 0, 15) === 'http://odeo.com')
|
||||
{
|
||||
return 'odeo';
|
||||
}
|
||||
|
||||
// Mime-types by handler.
|
||||
$types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash
|
||||
$types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player
|
||||
$types_quicktime = array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mp4', 'audio/m4a', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'video/3gpp', 'video/3gpp2', 'video/m4v', 'video/x-m4v', 'video/mp4', 'video/mpeg', 'video/x-mpeg', 'video/quicktime', 'video/sd-video'); // QuickTime
|
||||
$types_wmedia = array('application/asx', 'application/x-mplayer2', 'audio/x-ms-wma', 'audio/x-ms-wax', 'video/x-ms-asf-plugin', 'video/x-ms-asf', 'video/x-ms-wm', 'video/x-ms-wmv', 'video/x-ms-wvx'); // Windows Media
|
||||
$types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3
|
||||
|
||||
if ($this->get_type() !== null)
|
||||
{
|
||||
$type = strtolower($this->type);
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = null;
|
||||
}
|
||||
|
||||
// If we encounter an unsupported mime-type, check the file extension and guess intelligently.
|
||||
if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
|
||||
{
|
||||
switch (strtolower($this->get_extension()))
|
||||
{
|
||||
// Audio mime-types
|
||||
case 'aac':
|
||||
case 'adts':
|
||||
$type = 'audio/acc';
|
||||
break;
|
||||
|
||||
case 'aif':
|
||||
case 'aifc':
|
||||
case 'aiff':
|
||||
case 'cdda':
|
||||
$type = 'audio/aiff';
|
||||
break;
|
||||
|
||||
case 'bwf':
|
||||
$type = 'audio/wav';
|
||||
break;
|
||||
|
||||
case 'kar':
|
||||
case 'mid':
|
||||
case 'midi':
|
||||
case 'smf':
|
||||
$type = 'audio/midi';
|
||||
break;
|
||||
|
||||
case 'm4a':
|
||||
$type = 'audio/x-m4a';
|
||||
break;
|
||||
|
||||
case 'mp3':
|
||||
case 'swa':
|
||||
$type = 'audio/mp3';
|
||||
break;
|
||||
|
||||
case 'wav':
|
||||
$type = 'audio/wav';
|
||||
break;
|
||||
|
||||
case 'wax':
|
||||
$type = 'audio/x-ms-wax';
|
||||
break;
|
||||
|
||||
case 'wma':
|
||||
$type = 'audio/x-ms-wma';
|
||||
break;
|
||||
|
||||
// Video mime-types
|
||||
case '3gp':
|
||||
case '3gpp':
|
||||
$type = 'video/3gpp';
|
||||
break;
|
||||
|
||||
case '3g2':
|
||||
case '3gp2':
|
||||
$type = 'video/3gpp2';
|
||||
break;
|
||||
|
||||
case 'asf':
|
||||
$type = 'video/x-ms-asf';
|
||||
break;
|
||||
|
||||
case 'flv':
|
||||
$type = 'video/x-flv';
|
||||
break;
|
||||
|
||||
case 'm1a':
|
||||
case 'm1s':
|
||||
case 'm1v':
|
||||
case 'm15':
|
||||
case 'm75':
|
||||
case 'mp2':
|
||||
case 'mpa':
|
||||
case 'mpeg':
|
||||
case 'mpg':
|
||||
case 'mpm':
|
||||
case 'mpv':
|
||||
$type = 'video/mpeg';
|
||||
break;
|
||||
|
||||
case 'm4v':
|
||||
$type = 'video/x-m4v';
|
||||
break;
|
||||
|
||||
case 'mov':
|
||||
case 'qt':
|
||||
$type = 'video/quicktime';
|
||||
break;
|
||||
|
||||
case 'mp4':
|
||||
case 'mpg4':
|
||||
$type = 'video/mp4';
|
||||
break;
|
||||
|
||||
case 'sdv':
|
||||
$type = 'video/sd-video';
|
||||
break;
|
||||
|
||||
case 'wm':
|
||||
$type = 'video/x-ms-wm';
|
||||
break;
|
||||
|
||||
case 'wmv':
|
||||
$type = 'video/x-ms-wmv';
|
||||
break;
|
||||
|
||||
case 'wvx':
|
||||
$type = 'video/x-ms-wvx';
|
||||
break;
|
||||
|
||||
// Flash mime-types
|
||||
case 'spl':
|
||||
$type = 'application/futuresplash';
|
||||
break;
|
||||
|
||||
case 'swf':
|
||||
$type = 'application/x-shockwave-flash';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($find_handler)
|
||||
{
|
||||
if (in_array($type, $types_flash))
|
||||
{
|
||||
return 'flash';
|
||||
}
|
||||
elseif (in_array($type, $types_fmedia))
|
||||
{
|
||||
return 'fmedia';
|
||||
}
|
||||
elseif (in_array($type, $types_quicktime))
|
||||
{
|
||||
return 'quicktime';
|
||||
}
|
||||
elseif (in_array($type, $types_wmedia))
|
||||
{
|
||||
return 'wmedia';
|
||||
}
|
||||
elseif (in_array($type, $types_mp3))
|
||||
{
|
||||
return 'mp3';
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
278
libraries/simplepie/SimplePie/File.php
Normal file
@ -0,0 +1,278 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @todo Move to properly supporting RFC2616 (HTTP/1.1)
|
||||
*/
|
||||
class SimplePie_File
|
||||
{
|
||||
var $url;
|
||||
var $useragent;
|
||||
var $success = true;
|
||||
var $headers = array();
|
||||
var $body;
|
||||
var $status_code;
|
||||
var $redirects = 0;
|
||||
var $error;
|
||||
var $method = SIMPLEPIE_FILE_SOURCE_NONE;
|
||||
|
||||
public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
|
||||
{
|
||||
if (class_exists('idna_convert'))
|
||||
{
|
||||
$idn = new idna_convert();
|
||||
$parsed = SimplePie_Misc::parse_url($url);
|
||||
$url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
|
||||
}
|
||||
$this->url = $url;
|
||||
$this->useragent = $useragent;
|
||||
if (preg_match('/^http(s)?:\/\//i', $url))
|
||||
{
|
||||
if ($useragent === null)
|
||||
{
|
||||
$useragent = ini_get('user_agent');
|
||||
$this->useragent = $useragent;
|
||||
}
|
||||
if (!is_array($headers))
|
||||
{
|
||||
$headers = array();
|
||||
}
|
||||
if (!$force_fsockopen && function_exists('curl_exec'))
|
||||
{
|
||||
$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
|
||||
$fp = curl_init();
|
||||
$headers2 = array();
|
||||
foreach ($headers as $key => $value)
|
||||
{
|
||||
$headers2[] = "$key: $value";
|
||||
}
|
||||
if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>='))
|
||||
{
|
||||
curl_setopt($fp, CURLOPT_ENCODING, '');
|
||||
}
|
||||
curl_setopt($fp, CURLOPT_URL, $url);
|
||||
curl_setopt($fp, CURLOPT_HEADER, 1);
|
||||
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
|
||||
curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||||
curl_setopt($fp, CURLOPT_REFERER, $url);
|
||||
curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
|
||||
curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
|
||||
if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>='))
|
||||
{
|
||||
curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
|
||||
}
|
||||
|
||||
$this->headers = curl_exec($fp);
|
||||
if (curl_errno($fp) === 23 || curl_errno($fp) === 61)
|
||||
{
|
||||
curl_setopt($fp, CURLOPT_ENCODING, 'none');
|
||||
$this->headers = curl_exec($fp);
|
||||
}
|
||||
if (curl_errno($fp))
|
||||
{
|
||||
$this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
|
||||
$this->success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$info = curl_getinfo($fp);
|
||||
curl_close($fp);
|
||||
$this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 1);
|
||||
$this->headers = array_pop($this->headers);
|
||||
$parser = new SimplePie_HTTP_Parser($this->headers);
|
||||
if ($parser->parse())
|
||||
{
|
||||
$this->headers = $parser->headers;
|
||||
$this->body = $parser->body;
|
||||
$this->status_code = $parser->status_code;
|
||||
if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
|
||||
{
|
||||
$this->redirects++;
|
||||
$location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
|
||||
return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_FSOCKOPEN;
|
||||
$url_parts = parse_url($url);
|
||||
$socket_host = $url_parts['host'];
|
||||
if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https')
|
||||
{
|
||||
$socket_host = "ssl://$url_parts[host]";
|
||||
$url_parts['port'] = 443;
|
||||
}
|
||||
if (!isset($url_parts['port']))
|
||||
{
|
||||
$url_parts['port'] = 80;
|
||||
}
|
||||
$fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
|
||||
if (!$fp)
|
||||
{
|
||||
$this->error = 'fsockopen error: ' . $errstr;
|
||||
$this->success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
stream_set_timeout($fp, $timeout);
|
||||
if (isset($url_parts['path']))
|
||||
{
|
||||
if (isset($url_parts['query']))
|
||||
{
|
||||
$get = "$url_parts[path]?$url_parts[query]";
|
||||
}
|
||||
else
|
||||
{
|
||||
$get = $url_parts['path'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$get = '/';
|
||||
}
|
||||
$out = "GET $get HTTP/1.1\r\n";
|
||||
$out .= "Host: $url_parts[host]\r\n";
|
||||
$out .= "User-Agent: $useragent\r\n";
|
||||
if (extension_loaded('zlib'))
|
||||
{
|
||||
$out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
|
||||
}
|
||||
|
||||
if (isset($url_parts['user']) && isset($url_parts['pass']))
|
||||
{
|
||||
$out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
|
||||
}
|
||||
foreach ($headers as $key => $value)
|
||||
{
|
||||
$out .= "$key: $value\r\n";
|
||||
}
|
||||
$out .= "Connection: Close\r\n\r\n";
|
||||
fwrite($fp, $out);
|
||||
|
||||
$info = stream_get_meta_data($fp);
|
||||
|
||||
$this->headers = '';
|
||||
while (!$info['eof'] && !$info['timed_out'])
|
||||
{
|
||||
$this->headers .= fread($fp, 1160);
|
||||
$info = stream_get_meta_data($fp);
|
||||
}
|
||||
if (!$info['timed_out'])
|
||||
{
|
||||
$parser = new SimplePie_HTTP_Parser($this->headers);
|
||||
if ($parser->parse())
|
||||
{
|
||||
$this->headers = $parser->headers;
|
||||
$this->body = $parser->body;
|
||||
$this->status_code = $parser->status_code;
|
||||
if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
|
||||
{
|
||||
$this->redirects++;
|
||||
$location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
|
||||
return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
|
||||
}
|
||||
if (isset($this->headers['content-encoding']))
|
||||
{
|
||||
// Hey, we act dumb elsewhere, so let's do that here too
|
||||
switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20")))
|
||||
{
|
||||
case 'gzip':
|
||||
case 'x-gzip':
|
||||
$decoder = new SimplePie_gzdecode($this->body);
|
||||
if (!$decoder->parse())
|
||||
{
|
||||
$this->error = 'Unable to decode HTTP "gzip" stream';
|
||||
$this->success = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->body = $decoder->data;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'deflate':
|
||||
if (($body = gzuncompress($this->body)) === false)
|
||||
{
|
||||
if (($body = gzinflate($this->body)) === false)
|
||||
{
|
||||
$this->error = 'Unable to decode HTTP "deflate" stream';
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
$this->body = $body;
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->error = 'Unknown content coding';
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error = 'fsocket timed out';
|
||||
$this->success = false;
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->method = SIMPLEPIE_FILE_SOURCE_LOCAL | SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS;
|
||||
if (!$this->body = file_get_contents($url))
|
||||
{
|
||||
$this->error = 'file_get_contents could not read the file';
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
492
libraries/simplepie/SimplePie/HTTP/Parser.php
Normal file
@ -0,0 +1,492 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* HTTP Response Parser
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class SimplePie_HTTP_Parser
|
||||
{
|
||||
/**
|
||||
* HTTP Version
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $http_version = 0.0;
|
||||
|
||||
/**
|
||||
* Status code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $status_code = 0;
|
||||
|
||||
/**
|
||||
* Reason phrase
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $reason = '';
|
||||
|
||||
/**
|
||||
* Key/value pairs of the headers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $headers = array();
|
||||
|
||||
/**
|
||||
* Body of the response
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $body = '';
|
||||
|
||||
/**
|
||||
* Current state of the state machine
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $state = 'http_version';
|
||||
|
||||
/**
|
||||
* Input data
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $data = '';
|
||||
|
||||
/**
|
||||
* Input data length (to avoid calling strlen() everytime this is needed)
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $data_length = 0;
|
||||
|
||||
/**
|
||||
* Current position of the pointer
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $position = 0;
|
||||
|
||||
/**
|
||||
* Name of the hedaer currently being parsed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = '';
|
||||
|
||||
/**
|
||||
* Value of the hedaer currently being parsed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $value = '';
|
||||
|
||||
/**
|
||||
* Create an instance of the class with the input data
|
||||
*
|
||||
* @param string $data Input data
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->data_length = strlen($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the input data
|
||||
*
|
||||
* @return bool true on success, false on failure
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
while ($this->state && $this->state !== 'emit' && $this->has_data())
|
||||
{
|
||||
$state = $this->state;
|
||||
$this->$state();
|
||||
}
|
||||
$this->data = '';
|
||||
if ($this->state === 'emit' || $this->state === 'body')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->http_version = '';
|
||||
$this->status_code = '';
|
||||
$this->reason = '';
|
||||
$this->headers = array();
|
||||
$this->body = '';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether there is data beyond the pointer
|
||||
*
|
||||
* @return bool true if there is further data, false if not
|
||||
*/
|
||||
protected function has_data()
|
||||
{
|
||||
return (bool) ($this->position < $this->data_length);
|
||||
}
|
||||
|
||||
/**
|
||||
* See if the next character is LWS
|
||||
*
|
||||
* @return bool true if the next character is LWS, false if not
|
||||
*/
|
||||
protected function is_linear_whitespace()
|
||||
{
|
||||
return (bool) ($this->data[$this->position] === "\x09"
|
||||
|| $this->data[$this->position] === "\x20"
|
||||
|| ($this->data[$this->position] === "\x0A"
|
||||
&& isset($this->data[$this->position + 1])
|
||||
&& ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the HTTP version
|
||||
*/
|
||||
protected function http_version()
|
||||
{
|
||||
if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/')
|
||||
{
|
||||
$len = strspn($this->data, '0123456789.', 5);
|
||||
$this->http_version = substr($this->data, 5, $len);
|
||||
$this->position += 5 + $len;
|
||||
if (substr_count($this->http_version, '.') <= 1)
|
||||
{
|
||||
$this->http_version = (float) $this->http_version;
|
||||
$this->position += strspn($this->data, "\x09\x20", $this->position);
|
||||
$this->state = 'status';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the status code
|
||||
*/
|
||||
protected function status()
|
||||
{
|
||||
if ($len = strspn($this->data, '0123456789', $this->position))
|
||||
{
|
||||
$this->status_code = (int) substr($this->data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
$this->state = 'reason';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the reason phrase
|
||||
*/
|
||||
protected function reason()
|
||||
{
|
||||
$len = strcspn($this->data, "\x0A", $this->position);
|
||||
$this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20");
|
||||
$this->position += $len + 1;
|
||||
$this->state = 'new_line';
|
||||
}
|
||||
|
||||
/**
|
||||
* Deal with a new line, shifting data around as needed
|
||||
*/
|
||||
protected function new_line()
|
||||
{
|
||||
$this->value = trim($this->value, "\x0D\x20");
|
||||
if ($this->name !== '' && $this->value !== '')
|
||||
{
|
||||
$this->name = strtolower($this->name);
|
||||
// We should only use the last Content-Type header. c.f. issue #1
|
||||
if (isset($this->headers[$this->name]) && $this->name !== 'content-type')
|
||||
{
|
||||
$this->headers[$this->name] .= ', ' . $this->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->headers[$this->name] = $this->value;
|
||||
}
|
||||
}
|
||||
$this->name = '';
|
||||
$this->value = '';
|
||||
if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A")
|
||||
{
|
||||
$this->position += 2;
|
||||
$this->state = 'body';
|
||||
}
|
||||
elseif ($this->data[$this->position] === "\x0A")
|
||||
{
|
||||
$this->position++;
|
||||
$this->state = 'body';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'name';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a header name
|
||||
*/
|
||||
protected function name()
|
||||
{
|
||||
$len = strcspn($this->data, "\x0A:", $this->position);
|
||||
if (isset($this->data[$this->position + $len]))
|
||||
{
|
||||
if ($this->data[$this->position + $len] === "\x0A")
|
||||
{
|
||||
$this->position += $len;
|
||||
$this->state = 'new_line';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->name = substr($this->data, $this->position, $len);
|
||||
$this->position += $len + 1;
|
||||
$this->state = 'value';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse LWS, replacing consecutive LWS characters with a single space
|
||||
*/
|
||||
protected function linear_whitespace()
|
||||
{
|
||||
do
|
||||
{
|
||||
if (substr($this->data, $this->position, 2) === "\x0D\x0A")
|
||||
{
|
||||
$this->position += 2;
|
||||
}
|
||||
elseif ($this->data[$this->position] === "\x0A")
|
||||
{
|
||||
$this->position++;
|
||||
}
|
||||
$this->position += strspn($this->data, "\x09\x20", $this->position);
|
||||
} while ($this->has_data() && $this->is_linear_whitespace());
|
||||
$this->value .= "\x20";
|
||||
}
|
||||
|
||||
/**
|
||||
* See what state to move to while within non-quoted header values
|
||||
*/
|
||||
protected function value()
|
||||
{
|
||||
if ($this->is_linear_whitespace())
|
||||
{
|
||||
$this->linear_whitespace();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($this->data[$this->position])
|
||||
{
|
||||
case '"':
|
||||
// Workaround for ETags: we have to include the quotes as
|
||||
// part of the tag.
|
||||
if (strtolower($this->name) === 'etag')
|
||||
{
|
||||
$this->value .= '"';
|
||||
$this->position++;
|
||||
$this->state = 'value_char';
|
||||
break;
|
||||
}
|
||||
$this->position++;
|
||||
$this->state = 'quote';
|
||||
break;
|
||||
|
||||
case "\x0A":
|
||||
$this->position++;
|
||||
$this->state = 'new_line';
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->state = 'value_char';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a header value while outside quotes
|
||||
*/
|
||||
protected function value_char()
|
||||
{
|
||||
$len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
|
||||
$this->value .= substr($this->data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
$this->state = 'value';
|
||||
}
|
||||
|
||||
/**
|
||||
* See what state to move to while within quoted header values
|
||||
*/
|
||||
protected function quote()
|
||||
{
|
||||
if ($this->is_linear_whitespace())
|
||||
{
|
||||
$this->linear_whitespace();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($this->data[$this->position])
|
||||
{
|
||||
case '"':
|
||||
$this->position++;
|
||||
$this->state = 'value';
|
||||
break;
|
||||
|
||||
case "\x0A":
|
||||
$this->position++;
|
||||
$this->state = 'new_line';
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
$this->position++;
|
||||
$this->state = 'quote_escaped';
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->state = 'quote_char';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a header value while within quotes
|
||||
*/
|
||||
protected function quote_char()
|
||||
{
|
||||
$len = strcspn($this->data, "\x09\x20\x0A\"\\", $this->position);
|
||||
$this->value .= substr($this->data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
$this->state = 'value';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an escaped character within quotes
|
||||
*/
|
||||
protected function quote_escaped()
|
||||
{
|
||||
$this->value .= $this->data[$this->position];
|
||||
$this->position++;
|
||||
$this->state = 'quote';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the body
|
||||
*/
|
||||
protected function body()
|
||||
{
|
||||
$this->body = substr($this->data, $this->position);
|
||||
if (!empty($this->headers['transfer-encoding']))
|
||||
{
|
||||
unset($this->headers['transfer-encoding']);
|
||||
$this->state = 'chunked';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'emit';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsed a "Transfer-Encoding: chunked" body
|
||||
*/
|
||||
protected function chunked()
|
||||
{
|
||||
if (!preg_match('/^[0-9a-f]+(\s|\r|\n)+/mi', trim($this->body)))
|
||||
{
|
||||
$this->state = 'emit';
|
||||
return;
|
||||
}
|
||||
|
||||
$decoded = '';
|
||||
$encoded = $this->body;
|
||||
|
||||
while (true)
|
||||
{
|
||||
$is_chunked = (bool) preg_match( '/^([0-9a-f]+)(\s|\r|\n)+/mi', $encoded, $matches );
|
||||
if (!$is_chunked)
|
||||
{
|
||||
// Looks like it's not chunked after all
|
||||
$this->state = 'emit';
|
||||
return;
|
||||
}
|
||||
|
||||
$length = hexdec($matches[1]);
|
||||
$chunk_length = strlen($matches[0]);
|
||||
$decoded .= $part = substr($encoded, $chunk_length, $length);
|
||||
$encoded = ltrim(substr($encoded, $chunk_length + $length), "\r\n");
|
||||
|
||||
if (trim($encoded) === '0')
|
||||
{
|
||||
$this->state = 'emit';
|
||||
$this->body = $decoded;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
997
libraries/simplepie/SimplePie/IRI.php
Normal file
@ -0,0 +1,997 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
/**
|
||||
* IRI parser/serialiser
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class SimplePie_IRI
|
||||
{
|
||||
/**
|
||||
* Scheme
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $scheme;
|
||||
|
||||
/**
|
||||
* User Information
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $userinfo;
|
||||
|
||||
/**
|
||||
* Host
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $host;
|
||||
|
||||
/**
|
||||
* Port
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $port;
|
||||
|
||||
/**
|
||||
* Path
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $path;
|
||||
|
||||
/**
|
||||
* Query
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $query;
|
||||
|
||||
/**
|
||||
* Fragment
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $fragment;
|
||||
|
||||
/**
|
||||
* Whether the object represents a valid IRI
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $valid = array();
|
||||
|
||||
/**
|
||||
* Return the entire IRI when you try and read the object as a string
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->get_iri();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new IRI object, from a specified string
|
||||
*
|
||||
* @access public
|
||||
* @param string $iri
|
||||
* @return SimplePie_IRI
|
||||
*/
|
||||
public function __construct($iri)
|
||||
{
|
||||
$iri = (string) $iri;
|
||||
if ($iri !== '')
|
||||
{
|
||||
$parsed = $this->parse_iri($iri);
|
||||
$this->set_scheme($parsed['scheme']);
|
||||
$this->set_authority($parsed['authority']);
|
||||
$this->set_path($parsed['path']);
|
||||
$this->set_query($parsed['query']);
|
||||
$this->set_fragment($parsed['fragment']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new IRI object by resolving a relative IRI
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param SimplePie_IRI $base Base IRI
|
||||
* @param string $relative Relative IRI
|
||||
* @return SimplePie_IRI
|
||||
*/
|
||||
public static function absolutize($base, $relative)
|
||||
{
|
||||
$relative = (string) $relative;
|
||||
if ($relative !== '')
|
||||
{
|
||||
$relative = new SimplePie_IRI($relative);
|
||||
if ($relative->get_scheme() !== null)
|
||||
{
|
||||
$target = $relative;
|
||||
}
|
||||
elseif ($base->get_iri() !== null)
|
||||
{
|
||||
if ($relative->get_authority() !== null)
|
||||
{
|
||||
$target = $relative;
|
||||
$target->set_scheme($base->get_scheme());
|
||||
}
|
||||
else
|
||||
{
|
||||
$target = new SimplePie_IRI('');
|
||||
$target->set_scheme($base->get_scheme());
|
||||
$target->set_userinfo($base->get_userinfo());
|
||||
$target->set_host($base->get_host());
|
||||
$target->set_port($base->get_port());
|
||||
if ($relative->get_path() !== null)
|
||||
{
|
||||
if (strpos($relative->get_path(), '/') === 0)
|
||||
{
|
||||
$target->set_path($relative->get_path());
|
||||
}
|
||||
elseif (($base->get_userinfo() !== null || $base->get_host() !== null || $base->get_port() !== null) && $base->get_path() === null)
|
||||
{
|
||||
$target->set_path('/' . $relative->get_path());
|
||||
}
|
||||
elseif (($last_segment = strrpos($base->get_path(), '/')) !== false)
|
||||
{
|
||||
$target->set_path(substr($base->get_path(), 0, $last_segment + 1) . $relative->get_path());
|
||||
}
|
||||
else
|
||||
{
|
||||
$target->set_path($relative->get_path());
|
||||
}
|
||||
$target->set_query($relative->get_query());
|
||||
}
|
||||
else
|
||||
{
|
||||
$target->set_path($base->get_path());
|
||||
if ($relative->get_query() !== null)
|
||||
{
|
||||
$target->set_query($relative->get_query());
|
||||
}
|
||||
elseif ($base->get_query() !== null)
|
||||
{
|
||||
$target->set_query($base->get_query());
|
||||
}
|
||||
}
|
||||
}
|
||||
$target->set_fragment($relative->get_fragment());
|
||||
}
|
||||
else
|
||||
{
|
||||
// No base URL, just return the relative URL
|
||||
$target = $relative;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$target = $base;
|
||||
}
|
||||
return $target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an IRI into scheme/authority/path/query/fragment segments
|
||||
*
|
||||
* @access private
|
||||
* @param string $iri
|
||||
* @return array
|
||||
*/
|
||||
public function parse_iri($iri)
|
||||
{
|
||||
preg_match('/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $iri, $match);
|
||||
for ($i = count($match); $i <= 9; $i++)
|
||||
{
|
||||
$match[$i] = '';
|
||||
}
|
||||
return array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[7], 'fragment' => $match[9]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove dot segments from a path
|
||||
*
|
||||
* @access private
|
||||
* @param string $input
|
||||
* @return string
|
||||
*/
|
||||
public function remove_dot_segments($input)
|
||||
{
|
||||
$output = '';
|
||||
while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..')
|
||||
{
|
||||
// A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
|
||||
if (strpos($input, '../') === 0)
|
||||
{
|
||||
$input = substr($input, 3);
|
||||
}
|
||||
elseif (strpos($input, './') === 0)
|
||||
{
|
||||
$input = substr($input, 2);
|
||||
}
|
||||
// B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise,
|
||||
elseif (strpos($input, '/./') === 0)
|
||||
{
|
||||
$input = substr_replace($input, '/', 0, 3);
|
||||
}
|
||||
elseif ($input === '/.')
|
||||
{
|
||||
$input = '/';
|
||||
}
|
||||
// C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise,
|
||||
elseif (strpos($input, '/../') === 0)
|
||||
{
|
||||
$input = substr_replace($input, '/', 0, 4);
|
||||
$output = substr_replace($output, '', strrpos($output, '/'));
|
||||
}
|
||||
elseif ($input === '/..')
|
||||
{
|
||||
$input = '/';
|
||||
$output = substr_replace($output, '', strrpos($output, '/'));
|
||||
}
|
||||
// D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
|
||||
elseif ($input === '.' || $input === '..')
|
||||
{
|
||||
$input = '';
|
||||
}
|
||||
// E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer
|
||||
elseif (($pos = strpos($input, '/', 1)) !== false)
|
||||
{
|
||||
$output .= substr($input, 0, $pos);
|
||||
$input = substr_replace($input, '', 0, $pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= $input;
|
||||
$input = '';
|
||||
}
|
||||
}
|
||||
return $output . $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace invalid character with percent encoding
|
||||
*
|
||||
* @param string $string Input string
|
||||
* @param string $valid_chars Valid characters not in iunreserved or iprivate (this is ASCII-only)
|
||||
* @param int $case Normalise case
|
||||
* @param bool $iprivate Allow iprivate
|
||||
* @return string
|
||||
*/
|
||||
protected function replace_invalid_with_pct_encoding($string, $valid_chars, $case = SIMPLEPIE_SAME_CASE, $iprivate = false)
|
||||
{
|
||||
// Normalize as many pct-encoded sections as possible
|
||||
$string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array(&$this, 'remove_iunreserved_percent_encoded'), $string);
|
||||
|
||||
// Replace invalid percent characters
|
||||
$string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string);
|
||||
|
||||
// Add unreserved and % to $valid_chars (the latter is safe because all
|
||||
// pct-encoded sections are now valid).
|
||||
$valid_chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%';
|
||||
|
||||
// Now replace any bytes that aren't allowed with their pct-encoded versions
|
||||
$position = 0;
|
||||
$strlen = strlen($string);
|
||||
while (($position += strspn($string, $valid_chars, $position)) < $strlen)
|
||||
{
|
||||
$value = ord($string[$position]);
|
||||
|
||||
// Start position
|
||||
$start = $position;
|
||||
|
||||
// By default we are valid
|
||||
$valid = true;
|
||||
|
||||
// No one byte sequences are valid due to the while.
|
||||
// Two byte sequence:
|
||||
if (($value & 0xE0) === 0xC0)
|
||||
{
|
||||
$character = ($value & 0x1F) << 6;
|
||||
$length = 2;
|
||||
$remaining = 1;
|
||||
}
|
||||
// Three byte sequence:
|
||||
elseif (($value & 0xF0) === 0xE0)
|
||||
{
|
||||
$character = ($value & 0x0F) << 12;
|
||||
$length = 3;
|
||||
$remaining = 2;
|
||||
}
|
||||
// Four byte sequence:
|
||||
elseif (($value & 0xF8) === 0xF0)
|
||||
{
|
||||
$character = ($value & 0x07) << 18;
|
||||
$length = 4;
|
||||
$remaining = 3;
|
||||
}
|
||||
// Invalid byte:
|
||||
else
|
||||
{
|
||||
$valid = false;
|
||||
$length = 1;
|
||||
$remaining = 0;
|
||||
}
|
||||
|
||||
if ($remaining)
|
||||
{
|
||||
if ($position + $length <= $strlen)
|
||||
{
|
||||
for ($position++; $remaining; $position++)
|
||||
{
|
||||
$value = ord($string[$position]);
|
||||
|
||||
// Check that the byte is valid, then add it to the character:
|
||||
if (($value & 0xC0) === 0x80)
|
||||
{
|
||||
$character |= ($value & 0x3F) << (--$remaining * 6);
|
||||
}
|
||||
// If it is invalid, count the sequence as invalid and reprocess the current byte:
|
||||
else
|
||||
{
|
||||
$valid = false;
|
||||
$position--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$position = $strlen - 1;
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Percent encode anything invalid or not in ucschar
|
||||
if (
|
||||
// Invalid sequences
|
||||
!$valid
|
||||
// Non-shortest form sequences are invalid
|
||||
|| $length > 1 && $character <= 0x7F
|
||||
|| $length > 2 && $character <= 0x7FF
|
||||
|| $length > 3 && $character <= 0xFFFF
|
||||
// Outside of range of ucschar codepoints
|
||||
// Noncharacters
|
||||
|| ($character & 0xFFFE) === 0xFFFE
|
||||
|| $character >= 0xFDD0 && $character <= 0xFDEF
|
||||
|| (
|
||||
// Everything else not in ucschar
|
||||
$character > 0xD7FF && $character < 0xF900
|
||||
|| $character < 0xA0
|
||||
|| $character > 0xEFFFD
|
||||
)
|
||||
&& (
|
||||
// Everything not in iprivate, if it applies
|
||||
!$iprivate
|
||||
|| $character < 0xE000
|
||||
|| $character > 0x10FFFD
|
||||
)
|
||||
)
|
||||
{
|
||||
// If we were a character, pretend we weren't, but rather an error.
|
||||
if ($valid)
|
||||
$position--;
|
||||
|
||||
for ($j = $start; $j <= $position; $j++)
|
||||
{
|
||||
$string = substr_replace($string, sprintf('%%%02X', ord($string[$j])), $j, 1);
|
||||
$j += 2;
|
||||
$position += 2;
|
||||
$strlen += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Normalise case
|
||||
if ($case & SIMPLEPIE_LOWERCASE)
|
||||
{
|
||||
$string = strtolower($string);
|
||||
}
|
||||
elseif ($case & SIMPLEPIE_UPPERCASE)
|
||||
{
|
||||
$string = strtoupper($string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback function for preg_replace_callback.
|
||||
*
|
||||
* Removes sequences of percent encoded bytes that represent UTF-8
|
||||
* encoded characters in iunreserved
|
||||
*
|
||||
* @param array $match PCRE match
|
||||
* @return string Replacement
|
||||
*/
|
||||
protected function remove_iunreserved_percent_encoded($match)
|
||||
{
|
||||
// As we just have valid percent encoded sequences we can just explode
|
||||
// and ignore the first member of the returned array (an empty string).
|
||||
$bytes = explode('%', $match[0]);
|
||||
|
||||
// Initialize the new string (this is what will be returned) and that
|
||||
// there are no bytes remaining in the current sequence (unsurprising
|
||||
// at the first byte!).
|
||||
$string = '';
|
||||
$remaining = 0;
|
||||
|
||||
// Loop over each and every byte, and set $value to its value
|
||||
for ($i = 1, $len = count($bytes); $i < $len; $i++)
|
||||
{
|
||||
$value = hexdec($bytes[$i]);
|
||||
|
||||
// If we're the first byte of sequence:
|
||||
if (!$remaining)
|
||||
{
|
||||
// Start position
|
||||
$start = $i;
|
||||
|
||||
// By default we are valid
|
||||
$valid = true;
|
||||
|
||||
// One byte sequence:
|
||||
if ($value <= 0x7F)
|
||||
{
|
||||
$character = $value;
|
||||
$length = 1;
|
||||
}
|
||||
// Two byte sequence:
|
||||
elseif (($value & 0xE0) === 0xC0)
|
||||
{
|
||||
$character = ($value & 0x1F) << 6;
|
||||
$length = 2;
|
||||
$remaining = 1;
|
||||
}
|
||||
// Three byte sequence:
|
||||
elseif (($value & 0xF0) === 0xE0)
|
||||
{
|
||||
$character = ($value & 0x0F) << 12;
|
||||
$length = 3;
|
||||
$remaining = 2;
|
||||
}
|
||||
// Four byte sequence:
|
||||
elseif (($value & 0xF8) === 0xF0)
|
||||
{
|
||||
$character = ($value & 0x07) << 18;
|
||||
$length = 4;
|
||||
$remaining = 3;
|
||||
}
|
||||
// Invalid byte:
|
||||
else
|
||||
{
|
||||
$valid = false;
|
||||
$remaining = 0;
|
||||
}
|
||||
}
|
||||
// Continuation byte:
|
||||
else
|
||||
{
|
||||
// Check that the byte is valid, then add it to the character:
|
||||
if (($value & 0xC0) === 0x80)
|
||||
{
|
||||
$remaining--;
|
||||
$character |= ($value & 0x3F) << ($remaining * 6);
|
||||
}
|
||||
// If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence:
|
||||
else
|
||||
{
|
||||
$valid = false;
|
||||
$remaining = 0;
|
||||
$i--;
|
||||
}
|
||||
}
|
||||
|
||||
// If we've reached the end of the current byte sequence, append it to Unicode::$data
|
||||
if (!$remaining)
|
||||
{
|
||||
// Percent encode anything invalid or not in iunreserved
|
||||
if (
|
||||
// Invalid sequences
|
||||
!$valid
|
||||
// Non-shortest form sequences are invalid
|
||||
|| $length > 1 && $character <= 0x7F
|
||||
|| $length > 2 && $character <= 0x7FF
|
||||
|| $length > 3 && $character <= 0xFFFF
|
||||
// Outside of range of iunreserved codepoints
|
||||
|| $character < 0x2D
|
||||
|| $character > 0xEFFFD
|
||||
// Noncharacters
|
||||
|| ($character & 0xFFFE) === 0xFFFE
|
||||
|| $character >= 0xFDD0 && $character <= 0xFDEF
|
||||
// Everything else not in iunreserved (this is all BMP)
|
||||
|| $character === 0x2F
|
||||
|| $character > 0x39 && $character < 0x41
|
||||
|| $character > 0x5A && $character < 0x61
|
||||
|| $character > 0x7A && $character < 0x7E
|
||||
|| $character > 0x7E && $character < 0xA0
|
||||
|| $character > 0xD7FF && $character < 0xF900
|
||||
)
|
||||
{
|
||||
for ($j = $start; $j <= $i; $j++)
|
||||
{
|
||||
$string .= '%' . strtoupper($bytes[$j]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for ($j = $start; $j <= $i; $j++)
|
||||
{
|
||||
$string .= chr(hexdec($bytes[$j]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we have any bytes left over they are invalid (i.e., we are
|
||||
// mid-way through a multi-byte sequence)
|
||||
if ($remaining)
|
||||
{
|
||||
for ($j = $start; $j < $len; $j++)
|
||||
{
|
||||
$string .= '%' . strtoupper($bytes[$j]);
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the object represents a valid IRI
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function is_valid()
|
||||
{
|
||||
return array_sum($this->valid) === count($this->valid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the scheme. Returns true on success, false on failure (if there are
|
||||
* any invalid characters).
|
||||
*
|
||||
* @access public
|
||||
* @param string $scheme
|
||||
* @return bool
|
||||
*/
|
||||
public function set_scheme($scheme)
|
||||
{
|
||||
if ($scheme === null || $scheme === '')
|
||||
{
|
||||
$this->scheme = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$len = strlen($scheme);
|
||||
switch (true)
|
||||
{
|
||||
case $len > 1:
|
||||
if (!strspn($scheme, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-.', 1))
|
||||
{
|
||||
$this->scheme = null;
|
||||
$this->valid[__FUNCTION__] = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
case $len > 0:
|
||||
if (!strspn($scheme, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 0, 1))
|
||||
{
|
||||
$this->scheme = null;
|
||||
$this->valid[__FUNCTION__] = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$this->scheme = strtolower($scheme);
|
||||
}
|
||||
$this->valid[__FUNCTION__] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the authority. Returns true on success, false on failure (if there are
|
||||
* any invalid characters).
|
||||
*
|
||||
* @access public
|
||||
* @param string $authority
|
||||
* @return bool
|
||||
*/
|
||||
public function set_authority($authority)
|
||||
{
|
||||
if (($userinfo_end = strrpos($authority, '@')) !== false)
|
||||
{
|
||||
$userinfo = substr($authority, 0, $userinfo_end);
|
||||
$authority = substr($authority, $userinfo_end + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$userinfo = null;
|
||||
}
|
||||
|
||||
if (($port_start = strpos($authority, ':')) !== false)
|
||||
{
|
||||
$port = substr($authority, $port_start + 1);
|
||||
if ($port === false)
|
||||
{
|
||||
$port = null;
|
||||
}
|
||||
$authority = substr($authority, 0, $port_start);
|
||||
}
|
||||
else
|
||||
{
|
||||
$port = null;
|
||||
}
|
||||
|
||||
return $this->set_userinfo($userinfo) && $this->set_host($authority) && $this->set_port($port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the userinfo.
|
||||
*
|
||||
* @access public
|
||||
* @param string $userinfo
|
||||
* @return bool
|
||||
*/
|
||||
public function set_userinfo($userinfo)
|
||||
{
|
||||
if ($userinfo === null || $userinfo === '')
|
||||
{
|
||||
$this->userinfo = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->userinfo = $this->replace_invalid_with_pct_encoding($userinfo, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=:');
|
||||
}
|
||||
$this->valid[__FUNCTION__] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the host. Returns true on success, false on failure (if there are
|
||||
* any invalid characters).
|
||||
*
|
||||
* @access public
|
||||
* @param string $host
|
||||
* @return bool
|
||||
*/
|
||||
public function set_host($host)
|
||||
{
|
||||
if ($host === null || $host === '')
|
||||
{
|
||||
$this->host = null;
|
||||
$this->valid[__FUNCTION__] = true;
|
||||
return true;
|
||||
}
|
||||
elseif ($host[0] === '[' && substr($host, -1) === ']')
|
||||
{
|
||||
if (SimplePie_Net_IPv6::checkIPv6(substr($host, 1, -1)))
|
||||
{
|
||||
$this->host = $host;
|
||||
$this->valid[__FUNCTION__] = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->host = null;
|
||||
$this->valid[__FUNCTION__] = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->host = $this->replace_invalid_with_pct_encoding($host, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=', SIMPLEPIE_LOWERCASE);
|
||||
$this->valid[__FUNCTION__] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the port. Returns true on success, false on failure (if there are
|
||||
* any invalid characters).
|
||||
*
|
||||
* @access public
|
||||
* @param string $port
|
||||
* @return bool
|
||||
*/
|
||||
public function set_port($port)
|
||||
{
|
||||
if ($port === null || $port === '')
|
||||
{
|
||||
$this->port = null;
|
||||
$this->valid[__FUNCTION__] = true;
|
||||
return true;
|
||||
}
|
||||
elseif (strspn($port, '0123456789') === strlen($port))
|
||||
{
|
||||
$this->port = (int) $port;
|
||||
$this->valid[__FUNCTION__] = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->port = null;
|
||||
$this->valid[__FUNCTION__] = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path.
|
||||
*
|
||||
* @access public
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
public function set_path($path)
|
||||
{
|
||||
if ($path === null || $path === '')
|
||||
{
|
||||
$this->path = null;
|
||||
$this->valid[__FUNCTION__] = true;
|
||||
return true;
|
||||
}
|
||||
elseif (substr($path, 0, 2) === '//' && $this->userinfo === null && $this->host === null && $this->port === null)
|
||||
{
|
||||
$this->path = null;
|
||||
$this->valid[__FUNCTION__] = false;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->path = $this->replace_invalid_with_pct_encoding($path, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=@/');
|
||||
if ($this->scheme !== null)
|
||||
{
|
||||
$this->path = $this->remove_dot_segments($this->path);
|
||||
}
|
||||
$this->valid[__FUNCTION__] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the query.
|
||||
*
|
||||
* @access public
|
||||
* @param string $query
|
||||
* @return bool
|
||||
*/
|
||||
public function set_query($query)
|
||||
{
|
||||
if ($query === null || $query === '')
|
||||
{
|
||||
$this->query = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->query = $this->replace_invalid_with_pct_encoding($query, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$\'()*+,;:@/?&=');
|
||||
}
|
||||
$this->valid[__FUNCTION__] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fragment.
|
||||
*
|
||||
* @access public
|
||||
* @param string $fragment
|
||||
* @return bool
|
||||
*/
|
||||
public function set_fragment($fragment)
|
||||
{
|
||||
if ($fragment === null || $fragment === '')
|
||||
{
|
||||
$this->fragment = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->fragment = $this->replace_invalid_with_pct_encoding($fragment, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~!$&\'()*+,;=:@/?');
|
||||
}
|
||||
$this->valid[__FUNCTION__] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the complete IRI
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_iri()
|
||||
{
|
||||
$iri = '';
|
||||
if ($this->scheme !== null)
|
||||
{
|
||||
$iri .= $this->scheme . ':';
|
||||
}
|
||||
if (($authority = $this->get_authority()) !== null)
|
||||
{
|
||||
$iri .= '//' . $authority;
|
||||
}
|
||||
if ($this->path !== null)
|
||||
{
|
||||
$iri .= $this->path;
|
||||
}
|
||||
if ($this->query !== null)
|
||||
{
|
||||
$iri .= '?' . $this->query;
|
||||
}
|
||||
if ($this->fragment !== null)
|
||||
{
|
||||
$iri .= '#' . $this->fragment;
|
||||
}
|
||||
|
||||
if ($iri !== '')
|
||||
{
|
||||
return $iri;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the scheme
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_scheme()
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the complete authority
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_authority()
|
||||
{
|
||||
$authority = '';
|
||||
if ($this->userinfo !== null)
|
||||
{
|
||||
$authority .= $this->userinfo . '@';
|
||||
}
|
||||
if ($this->host !== null)
|
||||
{
|
||||
$authority .= $this->host;
|
||||
}
|
||||
if ($this->port !== null)
|
||||
{
|
||||
$authority .= ':' . $this->port;
|
||||
}
|
||||
|
||||
if ($authority !== '')
|
||||
{
|
||||
return $authority;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user information
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_userinfo()
|
||||
{
|
||||
return $this->userinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the host
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_host()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the port
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_port()
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_path()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_query()
|
||||
{
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fragment
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function get_fragment()
|
||||
{
|
||||
return $this->fragment;
|
||||
}
|
||||
}
|
2576
libraries/simplepie/SimplePie/Item.php
Normal file
314
libraries/simplepie/SimplePie/Locator.php
Normal file
@ -0,0 +1,314 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Locator
|
||||
{
|
||||
var $useragent;
|
||||
var $timeout;
|
||||
var $file;
|
||||
var $local = array();
|
||||
var $elsewhere = array();
|
||||
var $file_class = 'SimplePie_File';
|
||||
var $cached_entities = array();
|
||||
var $http_base;
|
||||
var $base;
|
||||
var $base_location = 0;
|
||||
var $checked_feeds = 0;
|
||||
var $max_checked_feeds = 10;
|
||||
var $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer';
|
||||
|
||||
public function __construct(&$file, $timeout = 10, $useragent = null, $file_class = 'SimplePie_File', $max_checked_feeds = 10, $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer')
|
||||
{
|
||||
$this->file =& $file;
|
||||
$this->file_class = $file_class;
|
||||
$this->useragent = $useragent;
|
||||
$this->timeout = $timeout;
|
||||
$this->max_checked_feeds = $max_checked_feeds;
|
||||
$this->content_type_sniffer_class = $content_type_sniffer_class;
|
||||
}
|
||||
|
||||
public function find($type = SIMPLEPIE_LOCATOR_ALL, &$working)
|
||||
{
|
||||
if ($this->is_feed($this->file))
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
if ($this->file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
|
||||
{
|
||||
$sniffer = new $this->content_type_sniffer_class($this->file);
|
||||
if ($sniffer->get_type() !== 'text/html')
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($type & ~SIMPLEPIE_LOCATOR_NONE)
|
||||
{
|
||||
$this->get_base();
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery())
|
||||
{
|
||||
return $working[0];
|
||||
}
|
||||
|
||||
if ($type & (SIMPLEPIE_LOCATOR_LOCAL_EXTENSION | SIMPLEPIE_LOCATOR_LOCAL_BODY | SIMPLEPIE_LOCATOR_REMOTE_EXTENSION | SIMPLEPIE_LOCATOR_REMOTE_BODY) && $this->get_links())
|
||||
{
|
||||
if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local))
|
||||
{
|
||||
return $working;
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local))
|
||||
{
|
||||
return $working;
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere))
|
||||
{
|
||||
return $working;
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere))
|
||||
{
|
||||
return $working;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function is_feed(&$file)
|
||||
{
|
||||
if ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
|
||||
{
|
||||
$sniffer = new $this->content_type_sniffer_class($file);
|
||||
$sniffed = $sniffer->get_type();
|
||||
if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'text/rdf', 'application/atom+xml', 'text/xml', 'application/xml')))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_base()
|
||||
{
|
||||
$this->http_base = $this->file->url;
|
||||
$this->base = $this->http_base;
|
||||
$elements = SimplePie_Misc::get_element('base', $this->file->body);
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
if ($element['attribs']['href']['data'] !== '')
|
||||
{
|
||||
$this->base = SimplePie_Misc::absolutize_url(trim($element['attribs']['href']['data']), $this->http_base);
|
||||
$this->base_location = $element['offset'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function autodiscovery()
|
||||
{
|
||||
$links = array_merge(SimplePie_Misc::get_element('link', $this->file->body), SimplePie_Misc::get_element('a', $this->file->body), SimplePie_Misc::get_element('area', $this->file->body));
|
||||
$done = array();
|
||||
$feeds = array();
|
||||
foreach ($links as $link)
|
||||
{
|
||||
if ($this->checked_feeds === $this->max_checked_feeds)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (isset($link['attribs']['href']['data']) && isset($link['attribs']['rel']['data']))
|
||||
{
|
||||
$rel = array_unique(SimplePie_Misc::space_seperated_tokens(strtolower($link['attribs']['rel']['data'])));
|
||||
|
||||
if ($this->base_location < $link['offset'])
|
||||
{
|
||||
$href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->base);
|
||||
}
|
||||
else
|
||||
{
|
||||
$href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->http_base);
|
||||
}
|
||||
|
||||
if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !in_array('stylesheet', $rel) && !empty($link['attribs']['type']['data']) && in_array(strtolower(SimplePie_Misc::parse_mime($link['attribs']['type']['data'])), array('application/rss+xml', 'application/atom+xml'))) && !isset($feeds[$href]))
|
||||
{
|
||||
$this->checked_feeds++;
|
||||
$headers = array(
|
||||
'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
|
||||
);
|
||||
$feed = new $this->file_class($href, $this->timeout, 5, $headers, $this->useragent);
|
||||
if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed))
|
||||
{
|
||||
$feeds[$href] = $feed;
|
||||
}
|
||||
}
|
||||
$done[] = $href;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($feeds))
|
||||
{
|
||||
return array_values($feeds);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_links()
|
||||
{
|
||||
$links = SimplePie_Misc::get_element('a', $this->file->body);
|
||||
foreach ($links as $link)
|
||||
{
|
||||
if (isset($link['attribs']['href']['data']))
|
||||
{
|
||||
$href = trim($link['attribs']['href']['data']);
|
||||
$parsed = SimplePie_Misc::parse_url($href);
|
||||
if ($parsed['scheme'] === '' || preg_match('/^(http(s)|feed)?$/i', $parsed['scheme']))
|
||||
{
|
||||
if ($this->base_location < $link['offset'])
|
||||
{
|
||||
$href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->base);
|
||||
}
|
||||
else
|
||||
{
|
||||
$href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->http_base);
|
||||
}
|
||||
|
||||
$current = SimplePie_Misc::parse_url($this->file->url);
|
||||
|
||||
if ($parsed['authority'] === '' || $parsed['authority'] === $current['authority'])
|
||||
{
|
||||
$this->local[] = $href;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->elsewhere[] = $href;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->local = array_unique($this->local);
|
||||
$this->elsewhere = array_unique($this->elsewhere);
|
||||
if (!empty($this->local) || !empty($this->elsewhere))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function extension(&$array)
|
||||
{
|
||||
foreach ($array as $key => $value)
|
||||
{
|
||||
if ($this->checked_feeds === $this->max_checked_feeds)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (in_array(strtolower(strrchr($value, '.')), array('.rss', '.rdf', '.atom', '.xml')))
|
||||
{
|
||||
$this->checked_feeds++;
|
||||
|
||||
$headers = array(
|
||||
'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
|
||||
);
|
||||
$feed = new $this->file_class($value, $this->timeout, 5, $headers, $this->useragent);
|
||||
if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed))
|
||||
{
|
||||
return $feed;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($array[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function body(&$array)
|
||||
{
|
||||
foreach ($array as $key => $value)
|
||||
{
|
||||
if ($this->checked_feeds === $this->max_checked_feeds)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (preg_match('/(rss|rdf|atom|xml)/i', $value))
|
||||
{
|
||||
$this->checked_feeds++;
|
||||
$headers = array(
|
||||
'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
|
||||
);
|
||||
$feed = new $this->file_class($value, $this->timeout, 5, null, $this->useragent);
|
||||
if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed))
|
||||
{
|
||||
return $feed;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($array[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
2365
libraries/simplepie/SimplePie/Misc.php
Normal file
258
libraries/simplepie/SimplePie/Net/IPv6.php
Normal file
@ -0,0 +1,258 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Class to validate and to work with IPv6 addresses.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @copyright 2003-2005 The PHP Group
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||
* @link http://pear.php.net/package/Net_IPv6
|
||||
* @author Alexander Merz <alexander.merz@web.de>
|
||||
* @author elfrink at introweb dot nl
|
||||
* @author Josh Peck <jmp at joshpeck dot org>
|
||||
* @author Geoffrey Sneddon <geoffers@gmail.com>
|
||||
*/
|
||||
class SimplePie_Net_IPv6
|
||||
{
|
||||
/**
|
||||
* Removes a possible existing netmask specification of an IP address.
|
||||
*
|
||||
* @param string $ip the (compressed) IP as Hex representation
|
||||
* @return string the IP the without netmask
|
||||
* @since 1.1.0
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
public static function removeNetmaskSpec($ip)
|
||||
{
|
||||
if (strpos($ip, '/') !== false)
|
||||
{
|
||||
list($addr, $nm) = explode('/', $ip);
|
||||
}
|
||||
else
|
||||
{
|
||||
$addr = $ip;
|
||||
}
|
||||
return $addr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uncompresses an IPv6 address
|
||||
*
|
||||
* RFC 2373 allows you to compress zeros in an address to '::'. This
|
||||
* function expects an valid IPv6 address and expands the '::' to
|
||||
* the required zeros.
|
||||
*
|
||||
* Example: FF01::101 -> FF01:0:0:0:0:0:0:101
|
||||
* ::1 -> 0:0:0:0:0:0:0:1
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param string $ip a valid IPv6-address (hex format)
|
||||
* @return string the uncompressed IPv6-address (hex format)
|
||||
*/
|
||||
public static function Uncompress($ip)
|
||||
{
|
||||
$uip = SimplePie_Net_IPv6::removeNetmaskSpec($ip);
|
||||
$c1 = -1;
|
||||
$c2 = -1;
|
||||
if (strpos($ip, '::') !== false)
|
||||
{
|
||||
list($ip1, $ip2) = explode('::', $ip);
|
||||
if ($ip1 === '')
|
||||
{
|
||||
$c1 = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$pos = 0;
|
||||
if (($pos = substr_count($ip1, ':')) > 0)
|
||||
{
|
||||
$c1 = $pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
$c1 = 0;
|
||||
}
|
||||
}
|
||||
if ($ip2 === '')
|
||||
{
|
||||
$c2 = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$pos = 0;
|
||||
if (($pos = substr_count($ip2, ':')) > 0)
|
||||
{
|
||||
$c2 = $pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
$c2 = 0;
|
||||
}
|
||||
}
|
||||
if (strstr($ip2, '.'))
|
||||
{
|
||||
$c2++;
|
||||
}
|
||||
// ::
|
||||
if ($c1 === -1 && $c2 === -1)
|
||||
{
|
||||
$uip = '0:0:0:0:0:0:0:0';
|
||||
}
|
||||
// ::xxx
|
||||
else if ($c1 === -1)
|
||||
{
|
||||
$fill = str_repeat('0:', 7 - $c2);
|
||||
$uip = str_replace('::', $fill, $uip);
|
||||
}
|
||||
// xxx::
|
||||
else if ($c2 === -1)
|
||||
{
|
||||
$fill = str_repeat(':0', 7 - $c1);
|
||||
$uip = str_replace('::', $fill, $uip);
|
||||
}
|
||||
// xxx::xxx
|
||||
else
|
||||
{
|
||||
$fill = str_repeat(':0:', 6 - $c2 - $c1);
|
||||
$uip = str_replace('::', $fill, $uip);
|
||||
$uip = str_replace('::', ':', $uip);
|
||||
}
|
||||
}
|
||||
return $uip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits an IPv6 address into the IPv6 and a possible IPv4 part
|
||||
*
|
||||
* RFC 2373 allows you to note the last two parts of an IPv6 address as
|
||||
* an IPv4 compatible address
|
||||
*
|
||||
* Example: 0:0:0:0:0:0:13.1.68.3
|
||||
* 0:0:0:0:0:FFFF:129.144.52.38
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param string $ip a valid IPv6-address (hex format)
|
||||
* @return array [0] contains the IPv6 part, [1] the IPv4 part (hex format)
|
||||
*/
|
||||
public static function SplitV64($ip)
|
||||
{
|
||||
$ip = SimplePie_Net_IPv6::Uncompress($ip);
|
||||
if (strstr($ip, '.'))
|
||||
{
|
||||
$pos = strrpos($ip, ':');
|
||||
$ip[$pos] = '_';
|
||||
$ipPart = explode('_', $ip);
|
||||
return $ipPart;
|
||||
}
|
||||
else
|
||||
{
|
||||
return array($ip, '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks an IPv6 address
|
||||
*
|
||||
* Checks if the given IP is IPv6-compatible
|
||||
*
|
||||
* @access public
|
||||
* @static
|
||||
* @param string $ip a valid IPv6-address
|
||||
* @return bool true if $ip is an IPv6 address
|
||||
*/
|
||||
public static function checkIPv6($ip)
|
||||
{
|
||||
$ipPart = SimplePie_Net_IPv6::SplitV64($ip);
|
||||
$count = 0;
|
||||
if (!empty($ipPart[0]))
|
||||
{
|
||||
$ipv6 = explode(':', $ipPart[0]);
|
||||
for ($i = 0; $i < count($ipv6); $i++)
|
||||
{
|
||||
$dec = hexdec($ipv6[$i]);
|
||||
$hex = strtoupper(preg_replace('/^[0]{1,3}(.*[0-9a-fA-F])$/', '\\1', $ipv6[$i]));
|
||||
if ($ipv6[$i] >= 0 && $dec <= 65535 && $hex === strtoupper(dechex($dec)))
|
||||
{
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if ($count === 8)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
elseif ($count === 6 && !empty($ipPart[1]))
|
||||
{
|
||||
$ipv4 = explode('.', $ipPart[1]);
|
||||
$count = 0;
|
||||
foreach ($ipv4 as $ipv4_part)
|
||||
{
|
||||
if ($ipv4_part >= 0 && $ipv4_part <= 255 && preg_match('/^\d{1,3}$/', $ipv4_part))
|
||||
{
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if ($count === 4)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
983
libraries/simplepie/SimplePie/Parse/Date.php
Normal file
@ -0,0 +1,983 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Date Parser
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class SimplePie_Parse_Date
|
||||
{
|
||||
/**
|
||||
* Input data
|
||||
*
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
var $date;
|
||||
|
||||
/**
|
||||
* List of days, calendar day name => ordinal day number in the week
|
||||
*
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
var $day = array(
|
||||
// English
|
||||
'mon' => 1,
|
||||
'monday' => 1,
|
||||
'tue' => 2,
|
||||
'tuesday' => 2,
|
||||
'wed' => 3,
|
||||
'wednesday' => 3,
|
||||
'thu' => 4,
|
||||
'thursday' => 4,
|
||||
'fri' => 5,
|
||||
'friday' => 5,
|
||||
'sat' => 6,
|
||||
'saturday' => 6,
|
||||
'sun' => 7,
|
||||
'sunday' => 7,
|
||||
// Dutch
|
||||
'maandag' => 1,
|
||||
'dinsdag' => 2,
|
||||
'woensdag' => 3,
|
||||
'donderdag' => 4,
|
||||
'vrijdag' => 5,
|
||||
'zaterdag' => 6,
|
||||
'zondag' => 7,
|
||||
// French
|
||||
'lundi' => 1,
|
||||
'mardi' => 2,
|
||||
'mercredi' => 3,
|
||||
'jeudi' => 4,
|
||||
'vendredi' => 5,
|
||||
'samedi' => 6,
|
||||
'dimanche' => 7,
|
||||
// German
|
||||
'montag' => 1,
|
||||
'dienstag' => 2,
|
||||
'mittwoch' => 3,
|
||||
'donnerstag' => 4,
|
||||
'freitag' => 5,
|
||||
'samstag' => 6,
|
||||
'sonnabend' => 6,
|
||||
'sonntag' => 7,
|
||||
// Italian
|
||||
'lunedì' => 1,
|
||||
'martedì' => 2,
|
||||
'mercoledì' => 3,
|
||||
'giovedì' => 4,
|
||||
'venerdì' => 5,
|
||||
'sabato' => 6,
|
||||
'domenica' => 7,
|
||||
// Spanish
|
||||
'lunes' => 1,
|
||||
'martes' => 2,
|
||||
'miércoles' => 3,
|
||||
'jueves' => 4,
|
||||
'viernes' => 5,
|
||||
'sábado' => 6,
|
||||
'domingo' => 7,
|
||||
// Finnish
|
||||
'maanantai' => 1,
|
||||
'tiistai' => 2,
|
||||
'keskiviikko' => 3,
|
||||
'torstai' => 4,
|
||||
'perjantai' => 5,
|
||||
'lauantai' => 6,
|
||||
'sunnuntai' => 7,
|
||||
// Hungarian
|
||||
'hétfő' => 1,
|
||||
'kedd' => 2,
|
||||
'szerda' => 3,
|
||||
'csütörtok' => 4,
|
||||
'péntek' => 5,
|
||||
'szombat' => 6,
|
||||
'vasárnap' => 7,
|
||||
// Greek
|
||||
'Δευ' => 1,
|
||||
'Τρι' => 2,
|
||||
'Τετ' => 3,
|
||||
'Πεμ' => 4,
|
||||
'Παρ' => 5,
|
||||
'Σαβ' => 6,
|
||||
'Κυρ' => 7,
|
||||
);
|
||||
|
||||
/**
|
||||
* List of months, calendar month name => calendar month number
|
||||
*
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
var $month = array(
|
||||
// English
|
||||
'jan' => 1,
|
||||
'january' => 1,
|
||||
'feb' => 2,
|
||||
'february' => 2,
|
||||
'mar' => 3,
|
||||
'march' => 3,
|
||||
'apr' => 4,
|
||||
'april' => 4,
|
||||
'may' => 5,
|
||||
// No long form of May
|
||||
'jun' => 6,
|
||||
'june' => 6,
|
||||
'jul' => 7,
|
||||
'july' => 7,
|
||||
'aug' => 8,
|
||||
'august' => 8,
|
||||
'sep' => 9,
|
||||
'september' => 8,
|
||||
'oct' => 10,
|
||||
'october' => 10,
|
||||
'nov' => 11,
|
||||
'november' => 11,
|
||||
'dec' => 12,
|
||||
'december' => 12,
|
||||
// Dutch
|
||||
'januari' => 1,
|
||||
'februari' => 2,
|
||||
'maart' => 3,
|
||||
'april' => 4,
|
||||
'mei' => 5,
|
||||
'juni' => 6,
|
||||
'juli' => 7,
|
||||
'augustus' => 8,
|
||||
'september' => 9,
|
||||
'oktober' => 10,
|
||||
'november' => 11,
|
||||
'december' => 12,
|
||||
// French
|
||||
'janvier' => 1,
|
||||
'février' => 2,
|
||||
'mars' => 3,
|
||||
'avril' => 4,
|
||||
'mai' => 5,
|
||||
'juin' => 6,
|
||||
'juillet' => 7,
|
||||
'août' => 8,
|
||||
'septembre' => 9,
|
||||
'octobre' => 10,
|
||||
'novembre' => 11,
|
||||
'décembre' => 12,
|
||||
// German
|
||||
'januar' => 1,
|
||||
'februar' => 2,
|
||||
'märz' => 3,
|
||||
'april' => 4,
|
||||
'mai' => 5,
|
||||
'juni' => 6,
|
||||
'juli' => 7,
|
||||
'august' => 8,
|
||||
'september' => 9,
|
||||
'oktober' => 10,
|
||||
'november' => 11,
|
||||
'dezember' => 12,
|
||||
// Italian
|
||||
'gennaio' => 1,
|
||||
'febbraio' => 2,
|
||||
'marzo' => 3,
|
||||
'aprile' => 4,
|
||||
'maggio' => 5,
|
||||
'giugno' => 6,
|
||||
'luglio' => 7,
|
||||
'agosto' => 8,
|
||||
'settembre' => 9,
|
||||
'ottobre' => 10,
|
||||
'novembre' => 11,
|
||||
'dicembre' => 12,
|
||||
// Spanish
|
||||
'enero' => 1,
|
||||
'febrero' => 2,
|
||||
'marzo' => 3,
|
||||
'abril' => 4,
|
||||
'mayo' => 5,
|
||||
'junio' => 6,
|
||||
'julio' => 7,
|
||||
'agosto' => 8,
|
||||
'septiembre' => 9,
|
||||
'setiembre' => 9,
|
||||
'octubre' => 10,
|
||||
'noviembre' => 11,
|
||||
'diciembre' => 12,
|
||||
// Finnish
|
||||
'tammikuu' => 1,
|
||||
'helmikuu' => 2,
|
||||
'maaliskuu' => 3,
|
||||
'huhtikuu' => 4,
|
||||
'toukokuu' => 5,
|
||||
'kesäkuu' => 6,
|
||||
'heinäkuu' => 7,
|
||||
'elokuu' => 8,
|
||||
'suuskuu' => 9,
|
||||
'lokakuu' => 10,
|
||||
'marras' => 11,
|
||||
'joulukuu' => 12,
|
||||
// Hungarian
|
||||
'január' => 1,
|
||||
'február' => 2,
|
||||
'március' => 3,
|
||||
'április' => 4,
|
||||
'május' => 5,
|
||||
'június' => 6,
|
||||
'július' => 7,
|
||||
'augusztus' => 8,
|
||||
'szeptember' => 9,
|
||||
'október' => 10,
|
||||
'november' => 11,
|
||||
'december' => 12,
|
||||
// Greek
|
||||
'Ιαν' => 1,
|
||||
'Φεβ' => 2,
|
||||
'Μάώ' => 3,
|
||||
'Μαώ' => 3,
|
||||
'Απρ' => 4,
|
||||
'Μάι' => 5,
|
||||
'Μαϊ' => 5,
|
||||
'Μαι' => 5,
|
||||
'Ιούν' => 6,
|
||||
'Ιον' => 6,
|
||||
'Ιούλ' => 7,
|
||||
'Ιολ' => 7,
|
||||
'Αύγ' => 8,
|
||||
'Αυγ' => 8,
|
||||
'Σεπ' => 9,
|
||||
'Οκτ' => 10,
|
||||
'Νοέ' => 11,
|
||||
'Δεκ' => 12,
|
||||
);
|
||||
|
||||
/**
|
||||
* List of timezones, abbreviation => offset from UTC
|
||||
*
|
||||
* @access protected
|
||||
* @var array
|
||||
*/
|
||||
var $timezone = array(
|
||||
'ACDT' => 37800,
|
||||
'ACIT' => 28800,
|
||||
'ACST' => 34200,
|
||||
'ACT' => -18000,
|
||||
'ACWDT' => 35100,
|
||||
'ACWST' => 31500,
|
||||
'AEDT' => 39600,
|
||||
'AEST' => 36000,
|
||||
'AFT' => 16200,
|
||||
'AKDT' => -28800,
|
||||
'AKST' => -32400,
|
||||
'AMDT' => 18000,
|
||||
'AMT' => -14400,
|
||||
'ANAST' => 46800,
|
||||
'ANAT' => 43200,
|
||||
'ART' => -10800,
|
||||
'AZOST' => -3600,
|
||||
'AZST' => 18000,
|
||||
'AZT' => 14400,
|
||||
'BIOT' => 21600,
|
||||
'BIT' => -43200,
|
||||
'BOT' => -14400,
|
||||
'BRST' => -7200,
|
||||
'BRT' => -10800,
|
||||
'BST' => 3600,
|
||||
'BTT' => 21600,
|
||||
'CAST' => 18000,
|
||||
'CAT' => 7200,
|
||||
'CCT' => 23400,
|
||||
'CDT' => -18000,
|
||||
'CEDT' => 7200,
|
||||
'CET' => 3600,
|
||||
'CGST' => -7200,
|
||||
'CGT' => -10800,
|
||||
'CHADT' => 49500,
|
||||
'CHAST' => 45900,
|
||||
'CIST' => -28800,
|
||||
'CKT' => -36000,
|
||||
'CLDT' => -10800,
|
||||
'CLST' => -14400,
|
||||
'COT' => -18000,
|
||||
'CST' => -21600,
|
||||
'CVT' => -3600,
|
||||
'CXT' => 25200,
|
||||
'DAVT' => 25200,
|
||||
'DTAT' => 36000,
|
||||
'EADT' => -18000,
|
||||
'EAST' => -21600,
|
||||
'EAT' => 10800,
|
||||
'ECT' => -18000,
|
||||
'EDT' => -14400,
|
||||
'EEST' => 10800,
|
||||
'EET' => 7200,
|
||||
'EGT' => -3600,
|
||||
'EKST' => 21600,
|
||||
'EST' => -18000,
|
||||
'FJT' => 43200,
|
||||
'FKDT' => -10800,
|
||||
'FKST' => -14400,
|
||||
'FNT' => -7200,
|
||||
'GALT' => -21600,
|
||||
'GEDT' => 14400,
|
||||
'GEST' => 10800,
|
||||
'GFT' => -10800,
|
||||
'GILT' => 43200,
|
||||
'GIT' => -32400,
|
||||
'GST' => 14400,
|
||||
'GST' => -7200,
|
||||
'GYT' => -14400,
|
||||
'HAA' => -10800,
|
||||
'HAC' => -18000,
|
||||
'HADT' => -32400,
|
||||
'HAE' => -14400,
|
||||
'HAP' => -25200,
|
||||
'HAR' => -21600,
|
||||
'HAST' => -36000,
|
||||
'HAT' => -9000,
|
||||
'HAY' => -28800,
|
||||
'HKST' => 28800,
|
||||
'HMT' => 18000,
|
||||
'HNA' => -14400,
|
||||
'HNC' => -21600,
|
||||
'HNE' => -18000,
|
||||
'HNP' => -28800,
|
||||
'HNR' => -25200,
|
||||
'HNT' => -12600,
|
||||
'HNY' => -32400,
|
||||
'IRDT' => 16200,
|
||||
'IRKST' => 32400,
|
||||
'IRKT' => 28800,
|
||||
'IRST' => 12600,
|
||||
'JFDT' => -10800,
|
||||
'JFST' => -14400,
|
||||
'JST' => 32400,
|
||||
'KGST' => 21600,
|
||||
'KGT' => 18000,
|
||||
'KOST' => 39600,
|
||||
'KOVST' => 28800,
|
||||
'KOVT' => 25200,
|
||||
'KRAST' => 28800,
|
||||
'KRAT' => 25200,
|
||||
'KST' => 32400,
|
||||
'LHDT' => 39600,
|
||||
'LHST' => 37800,
|
||||
'LINT' => 50400,
|
||||
'LKT' => 21600,
|
||||
'MAGST' => 43200,
|
||||
'MAGT' => 39600,
|
||||
'MAWT' => 21600,
|
||||
'MDT' => -21600,
|
||||
'MESZ' => 7200,
|
||||
'MEZ' => 3600,
|
||||
'MHT' => 43200,
|
||||
'MIT' => -34200,
|
||||
'MNST' => 32400,
|
||||
'MSDT' => 14400,
|
||||
'MSST' => 10800,
|
||||
'MST' => -25200,
|
||||
'MUT' => 14400,
|
||||
'MVT' => 18000,
|
||||
'MYT' => 28800,
|
||||
'NCT' => 39600,
|
||||
'NDT' => -9000,
|
||||
'NFT' => 41400,
|
||||
'NMIT' => 36000,
|
||||
'NOVST' => 25200,
|
||||
'NOVT' => 21600,
|
||||
'NPT' => 20700,
|
||||
'NRT' => 43200,
|
||||
'NST' => -12600,
|
||||
'NUT' => -39600,
|
||||
'NZDT' => 46800,
|
||||
'NZST' => 43200,
|
||||
'OMSST' => 25200,
|
||||
'OMST' => 21600,
|
||||
'PDT' => -25200,
|
||||
'PET' => -18000,
|
||||
'PETST' => 46800,
|
||||
'PETT' => 43200,
|
||||
'PGT' => 36000,
|
||||
'PHOT' => 46800,
|
||||
'PHT' => 28800,
|
||||
'PKT' => 18000,
|
||||
'PMDT' => -7200,
|
||||
'PMST' => -10800,
|
||||
'PONT' => 39600,
|
||||
'PST' => -28800,
|
||||
'PWT' => 32400,
|
||||
'PYST' => -10800,
|
||||
'PYT' => -14400,
|
||||
'RET' => 14400,
|
||||
'ROTT' => -10800,
|
||||
'SAMST' => 18000,
|
||||
'SAMT' => 14400,
|
||||
'SAST' => 7200,
|
||||
'SBT' => 39600,
|
||||
'SCDT' => 46800,
|
||||
'SCST' => 43200,
|
||||
'SCT' => 14400,
|
||||
'SEST' => 3600,
|
||||
'SGT' => 28800,
|
||||
'SIT' => 28800,
|
||||
'SRT' => -10800,
|
||||
'SST' => -39600,
|
||||
'SYST' => 10800,
|
||||
'SYT' => 7200,
|
||||
'TFT' => 18000,
|
||||
'THAT' => -36000,
|
||||
'TJT' => 18000,
|
||||
'TKT' => -36000,
|
||||
'TMT' => 18000,
|
||||
'TOT' => 46800,
|
||||
'TPT' => 32400,
|
||||
'TRUT' => 36000,
|
||||
'TVT' => 43200,
|
||||
'TWT' => 28800,
|
||||
'UYST' => -7200,
|
||||
'UYT' => -10800,
|
||||
'UZT' => 18000,
|
||||
'VET' => -14400,
|
||||
'VLAST' => 39600,
|
||||
'VLAT' => 36000,
|
||||
'VOST' => 21600,
|
||||
'VUT' => 39600,
|
||||
'WAST' => 7200,
|
||||
'WAT' => 3600,
|
||||
'WDT' => 32400,
|
||||
'WEST' => 3600,
|
||||
'WFT' => 43200,
|
||||
'WIB' => 25200,
|
||||
'WIT' => 32400,
|
||||
'WITA' => 28800,
|
||||
'WKST' => 18000,
|
||||
'WST' => 28800,
|
||||
'YAKST' => 36000,
|
||||
'YAKT' => 32400,
|
||||
'YAPT' => 36000,
|
||||
'YEKST' => 21600,
|
||||
'YEKT' => 18000,
|
||||
);
|
||||
|
||||
/**
|
||||
* Cached PCRE for SimplePie_Parse_Date::$day
|
||||
*
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
var $day_pcre;
|
||||
|
||||
/**
|
||||
* Cached PCRE for SimplePie_Parse_Date::$month
|
||||
*
|
||||
* @access protected
|
||||
* @var string
|
||||
*/
|
||||
var $month_pcre;
|
||||
|
||||
/**
|
||||
* Array of user-added callback methods
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $built_in = array();
|
||||
|
||||
/**
|
||||
* Array of user-added callback methods
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
var $user = array();
|
||||
|
||||
/**
|
||||
* Create new SimplePie_Parse_Date object, and set self::day_pcre,
|
||||
* self::month_pcre, and self::built_in
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')';
|
||||
$this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')';
|
||||
|
||||
static $cache;
|
||||
if (!isset($cache[get_class($this)]))
|
||||
{
|
||||
$all_methods = get_class_methods($this);
|
||||
|
||||
foreach ($all_methods as $method)
|
||||
{
|
||||
if (strtolower(substr($method, 0, 5)) === 'date_')
|
||||
{
|
||||
$cache[get_class($this)][] = $method;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($cache[get_class($this)] as $method)
|
||||
{
|
||||
$this->built_in[] = $method;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public static function get()
|
||||
{
|
||||
static $object;
|
||||
if (!$object)
|
||||
{
|
||||
$object = new SimplePie_Parse_Date;
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a date
|
||||
*
|
||||
* @final
|
||||
* @access public
|
||||
* @param string $date Date to parse
|
||||
* @return int Timestamp corresponding to date string, or false on failure
|
||||
*/
|
||||
public function parse($date)
|
||||
{
|
||||
foreach ($this->user as $method)
|
||||
{
|
||||
if (($returned = call_user_func($method, $date)) !== false)
|
||||
{
|
||||
return $returned;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->built_in as $method)
|
||||
{
|
||||
if (($returned = call_user_func(array(&$this, $method), $date)) !== false)
|
||||
{
|
||||
return $returned;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a callback method to parse a date
|
||||
*
|
||||
* @final
|
||||
* @access public
|
||||
* @param callback $callback
|
||||
*/
|
||||
public function add_callback($callback)
|
||||
{
|
||||
if (is_callable($callback))
|
||||
{
|
||||
$this->user[] = $callback;
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error('User-supplied function must be a valid callback', E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as
|
||||
* well as allowing any of upper or lower case "T", horizontal tabs, or
|
||||
* spaces to be used as the time seperator (including more than one))
|
||||
*
|
||||
* @access protected
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function date_w3cdtf($date)
|
||||
{
|
||||
static $pcre;
|
||||
if (!$pcre)
|
||||
{
|
||||
$year = '([0-9]{4})';
|
||||
$month = $day = $hour = $minute = $second = '([0-9]{2})';
|
||||
$decimal = '([0-9]*)';
|
||||
$zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))';
|
||||
$pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/';
|
||||
}
|
||||
if (preg_match($pcre, $date, $match))
|
||||
{
|
||||
/*
|
||||
Capturing subpatterns:
|
||||
1: Year
|
||||
2: Month
|
||||
3: Day
|
||||
4: Hour
|
||||
5: Minute
|
||||
6: Second
|
||||
7: Decimal fraction of a second
|
||||
8: Zulu
|
||||
9: Timezone ±
|
||||
10: Timezone hours
|
||||
11: Timezone minutes
|
||||
*/
|
||||
|
||||
// Fill in empty matches
|
||||
for ($i = count($match); $i <= 3; $i++)
|
||||
{
|
||||
$match[$i] = '1';
|
||||
}
|
||||
|
||||
for ($i = count($match); $i <= 7; $i++)
|
||||
{
|
||||
$match[$i] = '0';
|
||||
}
|
||||
|
||||
// Numeric timezone
|
||||
if (isset($match[9]) && $match[9] !== '')
|
||||
{
|
||||
$timezone = $match[10] * 3600;
|
||||
$timezone += $match[11] * 60;
|
||||
if ($match[9] === '-')
|
||||
{
|
||||
$timezone = 0 - $timezone;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$timezone = 0;
|
||||
}
|
||||
|
||||
// Convert the number of seconds to an integer, taking decimals into account
|
||||
$second = round($match[6] + $match[7] / pow(10, strlen($match[7])));
|
||||
|
||||
return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove RFC822 comments
|
||||
*
|
||||
* @access protected
|
||||
* @param string $data Data to strip comments from
|
||||
* @return string Comment stripped string
|
||||
*/
|
||||
public function remove_rfc2822_comments($string)
|
||||
{
|
||||
$string = (string) $string;
|
||||
$position = 0;
|
||||
$length = strlen($string);
|
||||
$depth = 0;
|
||||
|
||||
$output = '';
|
||||
|
||||
while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
|
||||
{
|
||||
$output .= substr($string, $position, $pos - $position);
|
||||
$position = $pos + 1;
|
||||
if ($string[$pos - 1] !== '\\')
|
||||
{
|
||||
$depth++;
|
||||
while ($depth && $position < $length)
|
||||
{
|
||||
$position += strcspn($string, '()', $position);
|
||||
if ($string[$position - 1] === '\\')
|
||||
{
|
||||
$position++;
|
||||
continue;
|
||||
}
|
||||
elseif (isset($string[$position]))
|
||||
{
|
||||
switch ($string[$position])
|
||||
{
|
||||
case '(':
|
||||
$depth++;
|
||||
break;
|
||||
|
||||
case ')':
|
||||
$depth--;
|
||||
break;
|
||||
}
|
||||
$position++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= '(';
|
||||
}
|
||||
}
|
||||
$output .= substr($string, $position);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse RFC2822's date format
|
||||
*
|
||||
* @access protected
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function date_rfc2822($date)
|
||||
{
|
||||
static $pcre;
|
||||
if (!$pcre)
|
||||
{
|
||||
$wsp = '[\x09\x20]';
|
||||
$fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
|
||||
$optional_fws = $fws . '?';
|
||||
$day_name = $this->day_pcre;
|
||||
$month = $this->month_pcre;
|
||||
$day = '([0-9]{1,2})';
|
||||
$hour = $minute = $second = '([0-9]{2})';
|
||||
$year = '([0-9]{2,4})';
|
||||
$num_zone = '([+\-])([0-9]{2})([0-9]{2})';
|
||||
$character_zone = '([A-Z]{1,5})';
|
||||
$zone = '(?:' . $num_zone . '|' . $character_zone . ')';
|
||||
$pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
|
||||
}
|
||||
if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
|
||||
{
|
||||
/*
|
||||
Capturing subpatterns:
|
||||
1: Day name
|
||||
2: Day
|
||||
3: Month
|
||||
4: Year
|
||||
5: Hour
|
||||
6: Minute
|
||||
7: Second
|
||||
8: Timezone ±
|
||||
9: Timezone hours
|
||||
10: Timezone minutes
|
||||
11: Alphabetic timezone
|
||||
*/
|
||||
|
||||
// Find the month number
|
||||
$month = $this->month[strtolower($match[3])];
|
||||
|
||||
// Numeric timezone
|
||||
if ($match[8] !== '')
|
||||
{
|
||||
$timezone = $match[9] * 3600;
|
||||
$timezone += $match[10] * 60;
|
||||
if ($match[8] === '-')
|
||||
{
|
||||
$timezone = 0 - $timezone;
|
||||
}
|
||||
}
|
||||
// Character timezone
|
||||
elseif (isset($this->timezone[strtoupper($match[11])]))
|
||||
{
|
||||
$timezone = $this->timezone[strtoupper($match[11])];
|
||||
}
|
||||
// Assume everything else to be -0000
|
||||
else
|
||||
{
|
||||
$timezone = 0;
|
||||
}
|
||||
|
||||
// Deal with 2/3 digit years
|
||||
if ($match[4] < 50)
|
||||
{
|
||||
$match[4] += 2000;
|
||||
}
|
||||
elseif ($match[4] < 1000)
|
||||
{
|
||||
$match[4] += 1900;
|
||||
}
|
||||
|
||||
// Second is optional, if it is empty set it to zero
|
||||
if ($match[7] !== '')
|
||||
{
|
||||
$second = $match[7];
|
||||
}
|
||||
else
|
||||
{
|
||||
$second = 0;
|
||||
}
|
||||
|
||||
return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse RFC850's date format
|
||||
*
|
||||
* @access protected
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function date_rfc850($date)
|
||||
{
|
||||
static $pcre;
|
||||
if (!$pcre)
|
||||
{
|
||||
$space = '[\x09\x20]+';
|
||||
$day_name = $this->day_pcre;
|
||||
$month = $this->month_pcre;
|
||||
$day = '([0-9]{1,2})';
|
||||
$year = $hour = $minute = $second = '([0-9]{2})';
|
||||
$zone = '([A-Z]{1,5})';
|
||||
$pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
|
||||
}
|
||||
if (preg_match($pcre, $date, $match))
|
||||
{
|
||||
/*
|
||||
Capturing subpatterns:
|
||||
1: Day name
|
||||
2: Day
|
||||
3: Month
|
||||
4: Year
|
||||
5: Hour
|
||||
6: Minute
|
||||
7: Second
|
||||
8: Timezone
|
||||
*/
|
||||
|
||||
// Month
|
||||
$month = $this->month[strtolower($match[3])];
|
||||
|
||||
// Character timezone
|
||||
if (isset($this->timezone[strtoupper($match[8])]))
|
||||
{
|
||||
$timezone = $this->timezone[strtoupper($match[8])];
|
||||
}
|
||||
// Assume everything else to be -0000
|
||||
else
|
||||
{
|
||||
$timezone = 0;
|
||||
}
|
||||
|
||||
// Deal with 2 digit year
|
||||
if ($match[4] < 50)
|
||||
{
|
||||
$match[4] += 2000;
|
||||
}
|
||||
else
|
||||
{
|
||||
$match[4] += 1900;
|
||||
}
|
||||
|
||||
return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse C99's asctime()'s date format
|
||||
*
|
||||
* @access protected
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function date_asctime($date)
|
||||
{
|
||||
static $pcre;
|
||||
if (!$pcre)
|
||||
{
|
||||
$space = '[\x09\x20]+';
|
||||
$wday_name = $this->day_pcre;
|
||||
$mon_name = $this->month_pcre;
|
||||
$day = '([0-9]{1,2})';
|
||||
$hour = $sec = $min = '([0-9]{2})';
|
||||
$year = '([0-9]{4})';
|
||||
$terminator = '\x0A?\x00?';
|
||||
$pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
|
||||
}
|
||||
if (preg_match($pcre, $date, $match))
|
||||
{
|
||||
/*
|
||||
Capturing subpatterns:
|
||||
1: Day name
|
||||
2: Month
|
||||
3: Day
|
||||
4: Hour
|
||||
5: Minute
|
||||
6: Second
|
||||
7: Year
|
||||
*/
|
||||
|
||||
$month = $this->month[strtolower($match[2])];
|
||||
return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse dates using strtotime()
|
||||
*
|
||||
* @access protected
|
||||
* @return int Timestamp
|
||||
*/
|
||||
public function date_strtotime($date)
|
||||
{
|
||||
$strtotime = strtotime($date);
|
||||
if ($strtotime === -1 || $strtotime === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $strtotime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
387
libraries/simplepie/SimplePie/Parser.php
Normal file
@ -0,0 +1,387 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Parser
|
||||
{
|
||||
var $error_code;
|
||||
var $error_string;
|
||||
var $current_line;
|
||||
var $current_column;
|
||||
var $current_byte;
|
||||
var $separator = ' ';
|
||||
var $namespace = array('');
|
||||
var $element = array('');
|
||||
var $xml_base = array('');
|
||||
var $xml_base_explicit = array(false);
|
||||
var $xml_lang = array('');
|
||||
var $data = array();
|
||||
var $datas = array(array());
|
||||
var $current_xhtml_construct = -1;
|
||||
var $encoding;
|
||||
|
||||
public function parse(&$data, $encoding)
|
||||
{
|
||||
// Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
|
||||
if (strtoupper($encoding) === 'US-ASCII')
|
||||
{
|
||||
$this->encoding = 'UTF-8';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->encoding = $encoding;
|
||||
}
|
||||
|
||||
// Strip BOM:
|
||||
// UTF-32 Big Endian BOM
|
||||
if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
|
||||
{
|
||||
$data = substr($data, 4);
|
||||
}
|
||||
// UTF-32 Little Endian BOM
|
||||
elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
|
||||
{
|
||||
$data = substr($data, 4);
|
||||
}
|
||||
// UTF-16 Big Endian BOM
|
||||
elseif (substr($data, 0, 2) === "\xFE\xFF")
|
||||
{
|
||||
$data = substr($data, 2);
|
||||
}
|
||||
// UTF-16 Little Endian BOM
|
||||
elseif (substr($data, 0, 2) === "\xFF\xFE")
|
||||
{
|
||||
$data = substr($data, 2);
|
||||
}
|
||||
// UTF-8 BOM
|
||||
elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
|
||||
{
|
||||
$data = substr($data, 3);
|
||||
}
|
||||
|
||||
if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false)
|
||||
{
|
||||
$declaration = new SimplePie_XML_Declaration_Parser(substr($data, 5, $pos - 5));
|
||||
if ($declaration->parse())
|
||||
{
|
||||
$data = substr($data, $pos + 2);
|
||||
$data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error_string = 'SimplePie bug! Please report this!';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$return = true;
|
||||
|
||||
static $xml_is_sane = null;
|
||||
if ($xml_is_sane === null)
|
||||
{
|
||||
$parser_check = xml_parser_create();
|
||||
xml_parse_into_struct($parser_check, '<foo>&</foo>', $values);
|
||||
xml_parser_free($parser_check);
|
||||
$xml_is_sane = isset($values[0]['value']);
|
||||
}
|
||||
|
||||
// Create the parser
|
||||
if ($xml_is_sane)
|
||||
{
|
||||
$xml = xml_parser_create_ns($this->encoding, $this->separator);
|
||||
xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
|
||||
xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
|
||||
xml_set_object($xml, $this);
|
||||
xml_set_character_data_handler($xml, 'cdata');
|
||||
xml_set_element_handler($xml, 'tag_open', 'tag_close');
|
||||
|
||||
// Parse!
|
||||
if (!xml_parse($xml, $data, true))
|
||||
{
|
||||
$this->error_code = xml_get_error_code($xml);
|
||||
$this->error_string = xml_error_string($this->error_code);
|
||||
$return = false;
|
||||
}
|
||||
$this->current_line = xml_get_current_line_number($xml);
|
||||
$this->current_column = xml_get_current_column_number($xml);
|
||||
$this->current_byte = xml_get_current_byte_index($xml);
|
||||
xml_parser_free($xml);
|
||||
return $return;
|
||||
}
|
||||
else
|
||||
{
|
||||
libxml_clear_errors();
|
||||
$xml = new XMLReader();
|
||||
$xml->xml($data);
|
||||
while (@$xml->read())
|
||||
{
|
||||
switch ($xml->nodeType)
|
||||
{
|
||||
|
||||
case constant('XMLReader::END_ELEMENT'):
|
||||
if ($xml->namespaceURI !== '')
|
||||
{
|
||||
$tagName = $xml->namespaceURI . $this->separator . $xml->localName;
|
||||
}
|
||||
else
|
||||
{
|
||||
$tagName = $xml->localName;
|
||||
}
|
||||
$this->tag_close(null, $tagName);
|
||||
break;
|
||||
case constant('XMLReader::ELEMENT'):
|
||||
$empty = $xml->isEmptyElement;
|
||||
if ($xml->namespaceURI !== '')
|
||||
{
|
||||
$tagName = $xml->namespaceURI . $this->separator . $xml->localName;
|
||||
}
|
||||
else
|
||||
{
|
||||
$tagName = $xml->localName;
|
||||
}
|
||||
$attributes = array();
|
||||
while ($xml->moveToNextAttribute())
|
||||
{
|
||||
if ($xml->namespaceURI !== '')
|
||||
{
|
||||
$attrName = $xml->namespaceURI . $this->separator . $xml->localName;
|
||||
}
|
||||
else
|
||||
{
|
||||
$attrName = $xml->localName;
|
||||
}
|
||||
$attributes[$attrName] = $xml->value;
|
||||
}
|
||||
$this->tag_open(null, $tagName, $attributes);
|
||||
if ($empty)
|
||||
{
|
||||
$this->tag_close(null, $tagName);
|
||||
}
|
||||
break;
|
||||
case constant('XMLReader::TEXT'):
|
||||
|
||||
case constant('XMLReader::CDATA'):
|
||||
$this->cdata(null, $xml->value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($error = libxml_get_last_error())
|
||||
{
|
||||
$this->error_code = $error->code;
|
||||
$this->error_string = $error->message;
|
||||
$this->current_line = $error->line;
|
||||
$this->current_column = $error->column;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get_error_code()
|
||||
{
|
||||
return $this->error_code;
|
||||
}
|
||||
|
||||
public function get_error_string()
|
||||
{
|
||||
return $this->error_string;
|
||||
}
|
||||
|
||||
public function get_current_line()
|
||||
{
|
||||
return $this->current_line;
|
||||
}
|
||||
|
||||
public function get_current_column()
|
||||
{
|
||||
return $this->current_column;
|
||||
}
|
||||
|
||||
public function get_current_byte()
|
||||
{
|
||||
return $this->current_byte;
|
||||
}
|
||||
|
||||
public function get_data()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function tag_open($parser, $tag, $attributes)
|
||||
{
|
||||
list($this->namespace[], $this->element[]) = $this->split_ns($tag);
|
||||
|
||||
$attribs = array();
|
||||
foreach ($attributes as $name => $value)
|
||||
{
|
||||
list($attrib_namespace, $attribute) = $this->split_ns($name);
|
||||
$attribs[$attrib_namespace][$attribute] = $value;
|
||||
}
|
||||
|
||||
if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['base']))
|
||||
{
|
||||
$this->xml_base[] = SimplePie_Misc::absolutize_url($attribs[SIMPLEPIE_NAMESPACE_XML]['base'], end($this->xml_base));
|
||||
$this->xml_base_explicit[] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->xml_base[] = end($this->xml_base);
|
||||
$this->xml_base_explicit[] = end($this->xml_base_explicit);
|
||||
}
|
||||
|
||||
if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['lang']))
|
||||
{
|
||||
$this->xml_lang[] = $attribs[SIMPLEPIE_NAMESPACE_XML]['lang'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->xml_lang[] = end($this->xml_lang);
|
||||
}
|
||||
|
||||
if ($this->current_xhtml_construct >= 0)
|
||||
{
|
||||
$this->current_xhtml_construct++;
|
||||
if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML)
|
||||
{
|
||||
$this->data['data'] .= '<' . end($this->element);
|
||||
if (isset($attribs['']))
|
||||
{
|
||||
foreach ($attribs[''] as $name => $value)
|
||||
{
|
||||
$this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"';
|
||||
}
|
||||
}
|
||||
$this->data['data'] .= '>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->datas[] =& $this->data;
|
||||
$this->data =& $this->data['child'][end($this->namespace)][end($this->element)][];
|
||||
$this->data = array('data' => '', 'attribs' => $attribs, 'xml_base' => end($this->xml_base), 'xml_base_explicit' => end($this->xml_base_explicit), 'xml_lang' => end($this->xml_lang));
|
||||
if ((end($this->namespace) === SIMPLEPIE_NAMESPACE_ATOM_03 && in_array(end($this->element), array('title', 'tagline', 'copyright', 'info', 'summary', 'content')) && isset($attribs['']['mode']) && $attribs['']['mode'] === 'xml')
|
||||
|| (end($this->namespace) === SIMPLEPIE_NAMESPACE_ATOM_10 && in_array(end($this->element), array('rights', 'subtitle', 'summary', 'info', 'title', 'content')) && isset($attribs['']['type']) && $attribs['']['type'] === 'xhtml'))
|
||||
{
|
||||
$this->current_xhtml_construct = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function cdata($parser, $cdata)
|
||||
{
|
||||
if ($this->current_xhtml_construct >= 0)
|
||||
{
|
||||
$this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->data['data'] .= $cdata;
|
||||
}
|
||||
}
|
||||
|
||||
public function tag_close($parser, $tag)
|
||||
{
|
||||
if ($this->current_xhtml_construct >= 0)
|
||||
{
|
||||
$this->current_xhtml_construct--;
|
||||
if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML && !in_array(end($this->element), array('area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param')))
|
||||
{
|
||||
$this->data['data'] .= '</' . end($this->element) . '>';
|
||||
}
|
||||
}
|
||||
if ($this->current_xhtml_construct === -1)
|
||||
{
|
||||
$this->data =& $this->datas[count($this->datas) - 1];
|
||||
array_pop($this->datas);
|
||||
}
|
||||
|
||||
array_pop($this->element);
|
||||
array_pop($this->namespace);
|
||||
array_pop($this->xml_base);
|
||||
array_pop($this->xml_base_explicit);
|
||||
array_pop($this->xml_lang);
|
||||
}
|
||||
|
||||
public function split_ns($string)
|
||||
{
|
||||
static $cache = array();
|
||||
if (!isset($cache[$string]))
|
||||
{
|
||||
if ($pos = strpos($string, $this->separator))
|
||||
{
|
||||
static $separator_length;
|
||||
if (!$separator_length)
|
||||
{
|
||||
$separator_length = strlen($this->separator);
|
||||
}
|
||||
$namespace = substr($string, 0, $pos);
|
||||
$local_name = substr($string, $pos + $separator_length);
|
||||
if (strtolower($namespace) === SIMPLEPIE_NAMESPACE_ITUNES)
|
||||
{
|
||||
$namespace = SIMPLEPIE_NAMESPACE_ITUNES;
|
||||
}
|
||||
|
||||
// Normalize the Media RSS namespaces
|
||||
if ($namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG ||
|
||||
$namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2 ||
|
||||
$namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3 ||
|
||||
$namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4 ||
|
||||
$namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5 )
|
||||
{
|
||||
$namespace = SIMPLEPIE_NAMESPACE_MEDIARSS;
|
||||
}
|
||||
$cache[$string] = array($namespace, $local_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cache[$string] = array('', $string);
|
||||
}
|
||||
}
|
||||
return $cache[$string];
|
||||
}
|
||||
}
|
88
libraries/simplepie/SimplePie/Rating.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Rating
|
||||
{
|
||||
var $scheme;
|
||||
var $value;
|
||||
|
||||
// Constructor, used to input the data
|
||||
public function __construct($scheme = null, $value = null)
|
||||
{
|
||||
$this->scheme = $scheme;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
public function get_scheme()
|
||||
{
|
||||
if ($this->scheme !== null)
|
||||
{
|
||||
return $this->scheme;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_value()
|
||||
{
|
||||
if ($this->value !== null)
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
102
libraries/simplepie/SimplePie/Restriction.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Restriction
|
||||
{
|
||||
var $relationship;
|
||||
var $type;
|
||||
var $value;
|
||||
|
||||
// Constructor, used to input the data
|
||||
public function __construct($relationship = null, $type = null, $value = null)
|
||||
{
|
||||
$this->relationship = $relationship;
|
||||
$this->type = $type;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
// There is no $this->data here
|
||||
return md5(serialize($this));
|
||||
}
|
||||
|
||||
public function get_relationship()
|
||||
{
|
||||
if ($this->relationship !== null)
|
||||
{
|
||||
return $this->relationship;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_type()
|
||||
{
|
||||
if ($this->type !== null)
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_value()
|
||||
{
|
||||
if ($this->value !== null)
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
400
libraries/simplepie/SimplePie/Sanitize.php
Normal file
@ -0,0 +1,400 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @todo Move to using an actual HTML parser (this will allow tags to be properly stripped, and to switch between HTML and XHTML), this will also make it easier to shorten a string while preserving HTML tags
|
||||
*/
|
||||
class SimplePie_Sanitize
|
||||
{
|
||||
// Private vars
|
||||
var $base;
|
||||
|
||||
// Options
|
||||
var $remove_div = true;
|
||||
var $image_handler = '';
|
||||
var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
|
||||
var $encode_instead_of_strip = false;
|
||||
var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
|
||||
var $strip_comments = false;
|
||||
var $output_encoding = 'UTF-8';
|
||||
var $enable_cache = true;
|
||||
var $cache_location = './cache';
|
||||
var $cache_name_function = 'md5';
|
||||
var $cache_class = 'SimplePie_Cache';
|
||||
var $file_class = 'SimplePie_File';
|
||||
var $timeout = 10;
|
||||
var $useragent = '';
|
||||
var $force_fsockopen = false;
|
||||
|
||||
var $replace_url_attributes = array(
|
||||
'a' => 'href',
|
||||
'area' => 'href',
|
||||
'blockquote' => 'cite',
|
||||
'del' => 'cite',
|
||||
'form' => 'action',
|
||||
'img' => array('longdesc', 'src'),
|
||||
'input' => 'src',
|
||||
'ins' => 'cite',
|
||||
'q' => 'cite'
|
||||
);
|
||||
|
||||
public function remove_div($enable = true)
|
||||
{
|
||||
$this->remove_div = (bool) $enable;
|
||||
}
|
||||
|
||||
public function set_image_handler($page = false)
|
||||
{
|
||||
if ($page)
|
||||
{
|
||||
$this->image_handler = (string) $page;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->image_handler = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function pass_cache_data($enable_cache = true, $cache_location = './cache', $cache_name_function = 'md5', $cache_class = 'SimplePie_Cache')
|
||||
{
|
||||
if (isset($enable_cache))
|
||||
{
|
||||
$this->enable_cache = (bool) $enable_cache;
|
||||
}
|
||||
|
||||
if ($cache_location)
|
||||
{
|
||||
$this->cache_location = (string) $cache_location;
|
||||
}
|
||||
|
||||
if ($cache_name_function)
|
||||
{
|
||||
$this->cache_name_function = (string) $cache_name_function;
|
||||
}
|
||||
|
||||
if ($cache_class)
|
||||
{
|
||||
$this->cache_class = (string) $cache_class;
|
||||
}
|
||||
}
|
||||
|
||||
public function pass_file_data($file_class = 'SimplePie_File', $timeout = 10, $useragent = '', $force_fsockopen = false)
|
||||
{
|
||||
if ($file_class)
|
||||
{
|
||||
$this->file_class = (string) $file_class;
|
||||
}
|
||||
|
||||
if ($timeout)
|
||||
{
|
||||
$this->timeout = (string) $timeout;
|
||||
}
|
||||
|
||||
if ($useragent)
|
||||
{
|
||||
$this->useragent = (string) $useragent;
|
||||
}
|
||||
|
||||
if ($force_fsockopen)
|
||||
{
|
||||
$this->force_fsockopen = (string) $force_fsockopen;
|
||||
}
|
||||
}
|
||||
|
||||
public function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
|
||||
{
|
||||
if ($tags)
|
||||
{
|
||||
if (is_array($tags))
|
||||
{
|
||||
$this->strip_htmltags = $tags;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->strip_htmltags = explode(',', $tags);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->strip_htmltags = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function encode_instead_of_strip($encode = false)
|
||||
{
|
||||
$this->encode_instead_of_strip = (bool) $encode;
|
||||
}
|
||||
|
||||
public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
|
||||
{
|
||||
if ($attribs)
|
||||
{
|
||||
if (is_array($attribs))
|
||||
{
|
||||
$this->strip_attributes = $attribs;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->strip_attributes = explode(',', $attribs);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->strip_attributes = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function strip_comments($strip = false)
|
||||
{
|
||||
$this->strip_comments = (bool) $strip;
|
||||
}
|
||||
|
||||
public function set_output_encoding($encoding = 'UTF-8')
|
||||
{
|
||||
$this->output_encoding = (string) $encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set element/attribute key/value pairs of HTML attributes
|
||||
* containing URLs that need to be resolved relative to the feed
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @param array $element_attribute Element/attribute key/value pairs
|
||||
*/
|
||||
public function set_url_replacements($element_attribute = array('a' => 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite'))
|
||||
{
|
||||
$this->replace_url_attributes = (array) $element_attribute;
|
||||
}
|
||||
|
||||
public function sanitize($data, $type, $base = '')
|
||||
{
|
||||
$data = trim($data);
|
||||
if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI)
|
||||
{
|
||||
if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML)
|
||||
{
|
||||
if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data))
|
||||
{
|
||||
$type |= SIMPLEPIE_CONSTRUCT_HTML;
|
||||
}
|
||||
else
|
||||
{
|
||||
$type |= SIMPLEPIE_CONSTRUCT_TEXT;
|
||||
}
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_CONSTRUCT_BASE64)
|
||||
{
|
||||
$data = base64_decode($data);
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_CONSTRUCT_XHTML)
|
||||
{
|
||||
if ($this->remove_div)
|
||||
{
|
||||
$data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data);
|
||||
$data = preg_replace('/<\/div>$/', '', $data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data);
|
||||
}
|
||||
}
|
||||
|
||||
if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML))
|
||||
{
|
||||
// Strip comments
|
||||
if ($this->strip_comments)
|
||||
{
|
||||
$data = SimplePie_Misc::strip_comments($data);
|
||||
}
|
||||
|
||||
// Strip out HTML tags and attributes that might cause various security problems.
|
||||
// Based on recommendations by Mark Pilgrim at:
|
||||
// http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
|
||||
if ($this->strip_htmltags)
|
||||
{
|
||||
foreach ($this->strip_htmltags as $tag)
|
||||
{
|
||||
$pcre = "/<($tag)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$tag" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>|(\/)?>)/siU';
|
||||
while (preg_match($pcre, $data))
|
||||
{
|
||||
$data = preg_replace_callback($pcre, array(&$this, 'do_strip_htmltags'), $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->strip_attributes)
|
||||
{
|
||||
foreach ($this->strip_attributes as $attrib)
|
||||
{
|
||||
$data = preg_replace('/(<[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*)' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . trim($attrib) . '(?:\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>/', '\1\2\3>', $data);
|
||||
}
|
||||
}
|
||||
|
||||
// Replace relative URLs
|
||||
$this->base = $base;
|
||||
foreach ($this->replace_url_attributes as $element => $attributes)
|
||||
{
|
||||
$data = $this->replace_urls($data, $element, $attributes);
|
||||
}
|
||||
|
||||
// If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
|
||||
if (isset($this->image_handler) && ((string) $this->image_handler) !== '' && $this->enable_cache)
|
||||
{
|
||||
$images = SimplePie_Misc::get_element('img', $data);
|
||||
foreach ($images as $img)
|
||||
{
|
||||
if (isset($img['attribs']['src']['data']))
|
||||
{
|
||||
$image_url = call_user_func($this->cache_name_function, $img['attribs']['src']['data']);
|
||||
$cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, $image_url, 'spi');
|
||||
|
||||
if ($cache->load())
|
||||
{
|
||||
$img['attribs']['src']['data'] = $this->image_handler . $image_url;
|
||||
$data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = new $this->file_class($img['attribs']['src']['data'], $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen);
|
||||
$headers = $file->headers;
|
||||
|
||||
if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
|
||||
{
|
||||
if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
|
||||
{
|
||||
$img['attribs']['src']['data'] = $this->image_handler . $image_url;
|
||||
$data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Having (possibly) taken stuff out, there may now be whitespace at the beginning/end of the data
|
||||
$data = trim($data);
|
||||
}
|
||||
|
||||
if ($type & SIMPLEPIE_CONSTRUCT_IRI)
|
||||
{
|
||||
$data = SimplePie_Misc::absolutize_url($data, $base);
|
||||
}
|
||||
|
||||
if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI))
|
||||
{
|
||||
$data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
|
||||
}
|
||||
|
||||
if ($this->output_encoding !== 'UTF-8')
|
||||
{
|
||||
$data = SimplePie_Misc::change_encoding($data, 'UTF-8', $this->output_encoding);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function replace_urls($data, $tag, $attributes)
|
||||
{
|
||||
if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags))
|
||||
{
|
||||
$elements = SimplePie_Misc::get_element($tag, $data);
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
if (is_array($attributes))
|
||||
{
|
||||
foreach ($attributes as $attribute)
|
||||
{
|
||||
if (isset($element['attribs'][$attribute]['data']))
|
||||
{
|
||||
$element['attribs'][$attribute]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attribute]['data'], $this->base);
|
||||
$new_element = SimplePie_Misc::element_implode($element);
|
||||
$data = str_replace($element['full'], $new_element, $data);
|
||||
$element['full'] = $new_element;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (isset($element['attribs'][$attributes]['data']))
|
||||
{
|
||||
$element['attribs'][$attributes]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attributes]['data'], $this->base);
|
||||
$data = str_replace($element['full'], SimplePie_Misc::element_implode($element), $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function do_strip_htmltags($match)
|
||||
{
|
||||
if ($this->encode_instead_of_strip)
|
||||
{
|
||||
if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
|
||||
{
|
||||
$match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
|
||||
$match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
|
||||
return "<$match[1]$match[2]>$match[3]</$match[1]>";
|
||||
}
|
||||
else
|
||||
{
|
||||
return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
|
||||
}
|
||||
}
|
||||
elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
|
||||
{
|
||||
return $match[4];
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
597
libraries/simplepie/SimplePie/Source.php
Normal file
@ -0,0 +1,597 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
class SimplePie_Source
|
||||
{
|
||||
var $item;
|
||||
var $data = array();
|
||||
|
||||
public function __construct($item, $data)
|
||||
{
|
||||
$this->item = $item;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return md5(serialize($this->data));
|
||||
}
|
||||
|
||||
public function get_source_tags($namespace, $tag)
|
||||
{
|
||||
if (isset($this->data['child'][$namespace][$tag]))
|
||||
{
|
||||
return $this->data['child'][$namespace][$tag];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_base($element = array())
|
||||
{
|
||||
return $this->item->get_base($element);
|
||||
}
|
||||
|
||||
public function sanitize($data, $type, $base = '')
|
||||
{
|
||||
return $this->item->sanitize($data, $type, $base);
|
||||
}
|
||||
|
||||
public function get_item()
|
||||
{
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
public function get_title()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_category($key = 0)
|
||||
{
|
||||
$categories = $this->get_categories();
|
||||
if (isset($categories[$key]))
|
||||
{
|
||||
return $categories[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_categories()
|
||||
{
|
||||
$categories = array();
|
||||
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
|
||||
{
|
||||
$term = null;
|
||||
$scheme = null;
|
||||
$label = null;
|
||||
if (isset($category['attribs']['']['term']))
|
||||
{
|
||||
$term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($category['attribs']['']['scheme']))
|
||||
{
|
||||
$scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($category['attribs']['']['label']))
|
||||
{
|
||||
$label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
$categories[] = new $this->item->feed->category_class($term, $scheme, $label);
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
|
||||
{
|
||||
// This is really the label, but keep this as the term also for BC.
|
||||
// Label will also work on retrieving because that falls back to term.
|
||||
$term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
if (isset($category['attribs']['']['domain']))
|
||||
{
|
||||
$scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
else
|
||||
{
|
||||
$scheme = null;
|
||||
}
|
||||
$categories[] = new $this->item->feed->category_class($term, $scheme, null);
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
|
||||
{
|
||||
$categories[] = new $this->item->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
|
||||
{
|
||||
$categories[] = new $this->item->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
|
||||
}
|
||||
|
||||
if (!empty($categories))
|
||||
{
|
||||
return SimplePie_Misc::array_unique($categories);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_author($key = 0)
|
||||
{
|
||||
$authors = $this->get_authors();
|
||||
if (isset($authors[$key]))
|
||||
{
|
||||
return $authors[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_authors()
|
||||
{
|
||||
$authors = array();
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
|
||||
{
|
||||
$name = null;
|
||||
$uri = null;
|
||||
$email = null;
|
||||
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
|
||||
{
|
||||
$name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
|
||||
{
|
||||
$uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
|
||||
}
|
||||
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
|
||||
{
|
||||
$email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if ($name !== null || $email !== null || $uri !== null)
|
||||
{
|
||||
$authors[] = new $this->item->feed->author_class($name, $uri, $email);
|
||||
}
|
||||
}
|
||||
if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
|
||||
{
|
||||
$name = null;
|
||||
$url = null;
|
||||
$email = null;
|
||||
if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
|
||||
{
|
||||
$name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
|
||||
{
|
||||
$url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
|
||||
}
|
||||
if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
|
||||
{
|
||||
$email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if ($name !== null || $email !== null || $url !== null)
|
||||
{
|
||||
$authors[] = new $this->item->feed->author_class($name, $url, $email);
|
||||
}
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
|
||||
{
|
||||
$authors[] = new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
|
||||
{
|
||||
$authors[] = new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
|
||||
{
|
||||
$authors[] = new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
|
||||
}
|
||||
|
||||
if (!empty($authors))
|
||||
{
|
||||
return SimplePie_Misc::array_unique($authors);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_contributor($key = 0)
|
||||
{
|
||||
$contributors = $this->get_contributors();
|
||||
if (isset($contributors[$key]))
|
||||
{
|
||||
return $contributors[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_contributors()
|
||||
{
|
||||
$contributors = array();
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
|
||||
{
|
||||
$name = null;
|
||||
$uri = null;
|
||||
$email = null;
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
|
||||
{
|
||||
$name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
|
||||
{
|
||||
$uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
|
||||
}
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
|
||||
{
|
||||
$email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if ($name !== null || $email !== null || $uri !== null)
|
||||
{
|
||||
$contributors[] = new $this->item->feed->author_class($name, $uri, $email);
|
||||
}
|
||||
}
|
||||
foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
|
||||
{
|
||||
$name = null;
|
||||
$url = null;
|
||||
$email = null;
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
|
||||
{
|
||||
$name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
|
||||
{
|
||||
$url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
|
||||
}
|
||||
if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
|
||||
{
|
||||
$email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
if ($name !== null || $email !== null || $url !== null)
|
||||
{
|
||||
$contributors[] = new $this->item->feed->author_class($name, $url, $email);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($contributors))
|
||||
{
|
||||
return SimplePie_Misc::array_unique($contributors);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_link($key = 0, $rel = 'alternate')
|
||||
{
|
||||
$links = $this->get_links($rel);
|
||||
if (isset($links[$key]))
|
||||
{
|
||||
return $links[$key];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Added for parity between the parent-level and the item/entry-level.
|
||||
*/
|
||||
public function get_permalink()
|
||||
{
|
||||
return $this->get_link(0);
|
||||
}
|
||||
|
||||
public function get_links($rel = 'alternate')
|
||||
{
|
||||
if (!isset($this->data['links']))
|
||||
{
|
||||
$this->data['links'] = array();
|
||||
if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
|
||||
{
|
||||
foreach ($links as $link)
|
||||
{
|
||||
if (isset($link['attribs']['']['href']))
|
||||
{
|
||||
$link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
|
||||
$this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
|
||||
{
|
||||
foreach ($links as $link)
|
||||
{
|
||||
if (isset($link['attribs']['']['href']))
|
||||
{
|
||||
$link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
|
||||
$this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
|
||||
{
|
||||
$this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
|
||||
}
|
||||
if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
|
||||
{
|
||||
$this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
|
||||
}
|
||||
if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
|
||||
{
|
||||
$this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
|
||||
}
|
||||
|
||||
$keys = array_keys($this->data['links']);
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if (SimplePie_Misc::is_isegment_nz_nc($key))
|
||||
{
|
||||
if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
|
||||
{
|
||||
$this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
|
||||
$this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
|
||||
}
|
||||
}
|
||||
elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
|
||||
{
|
||||
$this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
|
||||
}
|
||||
$this->data['links'][$key] = array_unique($this->data['links'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->data['links'][$rel]))
|
||||
{
|
||||
return $this->data['links'][$rel];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_description()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_copyright()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_language()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
elseif (isset($this->data['xml_lang']))
|
||||
{
|
||||
return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_latitude()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
|
||||
{
|
||||
return (float) $return[0]['data'];
|
||||
}
|
||||
elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
|
||||
{
|
||||
return (float) $match[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_longitude()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
|
||||
{
|
||||
return (float) $return[0]['data'];
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
|
||||
{
|
||||
return (float) $return[0]['data'];
|
||||
}
|
||||
elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
|
||||
{
|
||||
return (float) $match[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_image_url()
|
||||
{
|
||||
if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
|
||||
{
|
||||
return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
|
||||
}
|
||||
elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
|
||||
{
|
||||
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
362
libraries/simplepie/SimplePie/XML/Declaration/Parser.php
Normal file
@ -0,0 +1,362 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Parses the XML Declaration
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class SimplePie_XML_Declaration_Parser
|
||||
{
|
||||
/**
|
||||
* XML Version
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $version = '1.0';
|
||||
|
||||
/**
|
||||
* Encoding
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
var $encoding = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Standalone
|
||||
*
|
||||
* @access public
|
||||
* @var bool
|
||||
*/
|
||||
var $standalone = false;
|
||||
|
||||
/**
|
||||
* Current state of the state machine
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $state = 'before_version_name';
|
||||
|
||||
/**
|
||||
* Input data
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
var $data = '';
|
||||
|
||||
/**
|
||||
* Input data length (to avoid calling strlen() everytime this is needed)
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
var $data_length = 0;
|
||||
|
||||
/**
|
||||
* Current position of the pointer
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $position = 0;
|
||||
|
||||
/**
|
||||
* Create an instance of the class with the input data
|
||||
*
|
||||
* @access public
|
||||
* @param string $data Input data
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->data_length = strlen($this->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the input data
|
||||
*
|
||||
* @access public
|
||||
* @return bool true on success, false on failure
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
while ($this->state && $this->state !== 'emit' && $this->has_data())
|
||||
{
|
||||
$state = $this->state;
|
||||
$this->$state();
|
||||
}
|
||||
$this->data = '';
|
||||
if ($this->state === 'emit')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->version = '';
|
||||
$this->encoding = '';
|
||||
$this->standalone = '';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether there is data beyond the pointer
|
||||
*
|
||||
* @access private
|
||||
* @return bool true if there is further data, false if not
|
||||
*/
|
||||
public function has_data()
|
||||
{
|
||||
return (bool) ($this->position < $this->data_length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Advance past any whitespace
|
||||
*
|
||||
* @return int Number of whitespace characters passed
|
||||
*/
|
||||
public function skip_whitespace()
|
||||
{
|
||||
$whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position);
|
||||
$this->position += $whitespace;
|
||||
return $whitespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read value
|
||||
*/
|
||||
public function get_value()
|
||||
{
|
||||
$quote = substr($this->data, $this->position, 1);
|
||||
if ($quote === '"' || $quote === "'")
|
||||
{
|
||||
$this->position++;
|
||||
$len = strcspn($this->data, $quote, $this->position);
|
||||
if ($this->has_data())
|
||||
{
|
||||
$value = substr($this->data, $this->position, $len);
|
||||
$this->position += $len + 1;
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function before_version_name()
|
||||
{
|
||||
if ($this->skip_whitespace())
|
||||
{
|
||||
$this->state = 'version_name';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function version_name()
|
||||
{
|
||||
if (substr($this->data, $this->position, 7) === 'version')
|
||||
{
|
||||
$this->position += 7;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'version_equals';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function version_equals()
|
||||
{
|
||||
if (substr($this->data, $this->position, 1) === '=')
|
||||
{
|
||||
$this->position++;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'version_value';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function version_value()
|
||||
{
|
||||
if ($this->version = $this->get_value())
|
||||
{
|
||||
$this->skip_whitespace();
|
||||
if ($this->has_data())
|
||||
{
|
||||
$this->state = 'encoding_name';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'emit';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function encoding_name()
|
||||
{
|
||||
if (substr($this->data, $this->position, 8) === 'encoding')
|
||||
{
|
||||
$this->position += 8;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'encoding_equals';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'standalone_name';
|
||||
}
|
||||
}
|
||||
|
||||
public function encoding_equals()
|
||||
{
|
||||
if (substr($this->data, $this->position, 1) === '=')
|
||||
{
|
||||
$this->position++;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'encoding_value';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function encoding_value()
|
||||
{
|
||||
if ($this->encoding = $this->get_value())
|
||||
{
|
||||
$this->skip_whitespace();
|
||||
if ($this->has_data())
|
||||
{
|
||||
$this->state = 'standalone_name';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'emit';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function standalone_name()
|
||||
{
|
||||
if (substr($this->data, $this->position, 10) === 'standalone')
|
||||
{
|
||||
$this->position += 10;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'standalone_equals';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function standalone_equals()
|
||||
{
|
||||
if (substr($this->data, $this->position, 1) === '=')
|
||||
{
|
||||
$this->position++;
|
||||
$this->skip_whitespace();
|
||||
$this->state = 'standalone_value';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function standalone_value()
|
||||
{
|
||||
if ($standalone = $this->get_value())
|
||||
{
|
||||
switch ($standalone)
|
||||
{
|
||||
case 'yes':
|
||||
$this->standalone = true;
|
||||
break;
|
||||
|
||||
case 'no':
|
||||
$this->standalone = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->state = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->skip_whitespace();
|
||||
if ($this->has_data())
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = 'emit';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->state = false;
|
||||
}
|
||||
}
|
||||
}
|
355
libraries/simplepie/SimplePie/gzdecode.php
Normal file
@ -0,0 +1,355 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* gzdecode
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class SimplePie_gzdecode
|
||||
{
|
||||
/**
|
||||
* Compressed data
|
||||
*
|
||||
* @access private
|
||||
* @see gzdecode::$data
|
||||
*/
|
||||
var $compressed_data;
|
||||
|
||||
/**
|
||||
* Size of compressed data
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
var $compressed_size;
|
||||
|
||||
/**
|
||||
* Minimum size of a valid gzip string
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
var $min_compressed_size = 18;
|
||||
|
||||
/**
|
||||
* Current position of pointer
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
var $position = 0;
|
||||
|
||||
/**
|
||||
* Flags (FLG)
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
var $flags;
|
||||
|
||||
/**
|
||||
* Uncompressed data
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$compressed_data
|
||||
*/
|
||||
var $data;
|
||||
|
||||
/**
|
||||
* Modified time
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
var $MTIME;
|
||||
|
||||
/**
|
||||
* Extra Flags
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
var $XFL;
|
||||
|
||||
/**
|
||||
* Operating System
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
var $OS;
|
||||
|
||||
/**
|
||||
* Subfield ID 1
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$extra_field
|
||||
* @see gzdecode::$SI2
|
||||
*/
|
||||
var $SI1;
|
||||
|
||||
/**
|
||||
* Subfield ID 2
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$extra_field
|
||||
* @see gzdecode::$SI1
|
||||
*/
|
||||
var $SI2;
|
||||
|
||||
/**
|
||||
* Extra field content
|
||||
*
|
||||
* @access public
|
||||
* @see gzdecode::$SI1
|
||||
* @see gzdecode::$SI2
|
||||
*/
|
||||
var $extra_field;
|
||||
|
||||
/**
|
||||
* Original filename
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
var $filename;
|
||||
|
||||
/**
|
||||
* Human readable comment
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
var $comment;
|
||||
|
||||
/**
|
||||
* Don't allow anything to be set
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
trigger_error("Cannot write property $name", E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the compressed string and related properties
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->compressed_data = $data;
|
||||
$this->compressed_size = strlen($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the GZIP stream
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
if ($this->compressed_size >= $this->min_compressed_size)
|
||||
{
|
||||
// Check ID1, ID2, and CM
|
||||
if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the FLG (FLaGs)
|
||||
$this->flags = ord($this->compressed_data[3]);
|
||||
|
||||
// FLG bits above (1 << 4) are reserved
|
||||
if ($this->flags > 0x1F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Advance the pointer after the above
|
||||
$this->position += 4;
|
||||
|
||||
// MTIME
|
||||
$mtime = substr($this->compressed_data, $this->position, 4);
|
||||
// Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
|
||||
if (current(unpack('S', "\x00\x01")) === 1)
|
||||
{
|
||||
$mtime = strrev($mtime);
|
||||
}
|
||||
$this->MTIME = current(unpack('l', $mtime));
|
||||
$this->position += 4;
|
||||
|
||||
// Get the XFL (eXtra FLags)
|
||||
$this->XFL = ord($this->compressed_data[$this->position++]);
|
||||
|
||||
// Get the OS (Operating System)
|
||||
$this->OS = ord($this->compressed_data[$this->position++]);
|
||||
|
||||
// Parse the FEXTRA
|
||||
if ($this->flags & 4)
|
||||
{
|
||||
// Read subfield IDs
|
||||
$this->SI1 = $this->compressed_data[$this->position++];
|
||||
$this->SI2 = $this->compressed_data[$this->position++];
|
||||
|
||||
// SI2 set to zero is reserved for future use
|
||||
if ($this->SI2 === "\x00")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the length of the extra field
|
||||
$len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
|
||||
$this->position += 2;
|
||||
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 4;
|
||||
if ($this->compressed_size >= $this->min_compressed_size)
|
||||
{
|
||||
// Set the extra field to the given data
|
||||
$this->extra_field = substr($this->compressed_data, $this->position, $len);
|
||||
$this->position += $len;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the FNAME
|
||||
if ($this->flags & 8)
|
||||
{
|
||||
// Get the length of the filename
|
||||
$len = strcspn($this->compressed_data, "\x00", $this->position);
|
||||
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 1;
|
||||
if ($this->compressed_size >= $this->min_compressed_size)
|
||||
{
|
||||
// Set the original filename to the given string
|
||||
$this->filename = substr($this->compressed_data, $this->position, $len);
|
||||
$this->position += $len + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the FCOMMENT
|
||||
if ($this->flags & 16)
|
||||
{
|
||||
// Get the length of the comment
|
||||
$len = strcspn($this->compressed_data, "\x00", $this->position);
|
||||
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 1;
|
||||
if ($this->compressed_size >= $this->min_compressed_size)
|
||||
{
|
||||
// Set the original comment to the given string
|
||||
$this->comment = substr($this->compressed_data, $this->position, $len);
|
||||
$this->position += $len + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the FHCRC
|
||||
if ($this->flags & 2)
|
||||
{
|
||||
// Check the length of the string is still valid
|
||||
$this->min_compressed_size += $len + 2;
|
||||
if ($this->compressed_size >= $this->min_compressed_size)
|
||||
{
|
||||
// Read the CRC
|
||||
$crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
|
||||
|
||||
// Check the CRC matches
|
||||
if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc)
|
||||
{
|
||||
$this->position += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Decompress the actual data
|
||||
if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->position = $this->compressed_size - 8;
|
||||
}
|
||||
|
||||
// Check CRC of data
|
||||
$crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
|
||||
$this->position += 4;
|
||||
/*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
|
||||
{
|
||||
return false;
|
||||
}*/
|
||||
|
||||
// Check ISIZE of data
|
||||
$isize = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
|
||||
$this->position += 4;
|
||||
if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Wow, against all odds, we've actually got a valid gzip string
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
80
libraries/simplepie/SimplePieAutoloader.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* SimplePie
|
||||
*
|
||||
* A PHP-Based RSS and Atom Feed Framework.
|
||||
* Takes the hard work out of managing a complete RSS/Atom solution.
|
||||
*
|
||||
* Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
|
||||
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @package SimplePie
|
||||
* @version 1.3-dev
|
||||
* @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
|
||||
* @author Ryan Parman
|
||||
* @author Geoffrey Sneddon
|
||||
* @author Ryan McCue
|
||||
* @link http://simplepie.org/ SimplePie
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
|
||||
* @todo phpDoc comments
|
||||
*/
|
||||
|
||||
|
||||
// autoloader
|
||||
spl_autoload_register(array(new SimplePie_Autoloader(), 'autoload'));
|
||||
|
||||
/**
|
||||
* SimplePie Autoloader class.
|
||||
*
|
||||
* @package SimplePie
|
||||
*/
|
||||
class SimplePie_Autoloader
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->path = dirname(__FILE__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoloader.
|
||||
*
|
||||
* @param string $class The name of the class to attempt to load.
|
||||
*/
|
||||
public function autoload($class)
|
||||
{
|
||||
// see if this request should be handled by this autoloader
|
||||
if (strpos($class, 'SimplePie') !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$filename = $this->path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
|
||||
include $filename;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
SIMPLEPIE COMPATIBILITY TEST
|
||||
|
||||
1) Upload sp_compatibility_test.php to the web-accessible root of your website.
|
||||
For example, if your website is www.example.com, upload it so that you can get
|
||||
to it at www.example.com/sp_compatibility_test.php
|
||||
|
||||
2) Open your web browser and go to the page you just uploaded.
|
@ -1,163 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once 'simplepie.inc';
|
||||
|
||||
function normalize_character_set($charset)
|
||||
{
|
||||
return strtolower(preg_replace('/[\x09-\x0D\x20-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]/', '', $charset));
|
||||
}
|
||||
|
||||
function build_character_set_list()
|
||||
{
|
||||
$file = new SimplePie_File('http://www.iana.org/assignments/character-sets');
|
||||
if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = explode("\n", $file->body);
|
||||
unset($file);
|
||||
|
||||
foreach ($data as $line)
|
||||
{
|
||||
// New character set
|
||||
if (substr($line, 0, 5) === 'Name:')
|
||||
{
|
||||
// If we already have one, push it on to the array
|
||||
if (isset($aliases))
|
||||
{
|
||||
natcasesort($aliases);
|
||||
for ($i = 0, $count = count($aliases); $i < $count; $i++)
|
||||
{
|
||||
$aliases[$i] = normalize_character_set($aliases[$i]);
|
||||
}
|
||||
$charsets[$preferred] = $aliases;
|
||||
}
|
||||
|
||||
$start = 5 + strspn($line, "\x09\x0A\x0B\xC\x0D\x20", 5);
|
||||
$chars = strcspn($line, "\x09\x0A\x0B\xC\x0D\x20", $start);
|
||||
$aliases = array(substr($line, $start, $chars));
|
||||
$preferred = end($aliases);
|
||||
}
|
||||
// Another alias
|
||||
elseif(substr($line, 0, 6) === 'Alias:')
|
||||
{
|
||||
$start = 7 + strspn($line, "\x09\x0A\x0B\xC\x0D\x20", 7);
|
||||
$chars = strcspn($line, "\x09\x0A\x0B\xC\x0D\x20", $start);
|
||||
$aliases[] = substr($line, $start, $chars);
|
||||
|
||||
if (end($aliases) === 'None')
|
||||
{
|
||||
array_pop($aliases);
|
||||
}
|
||||
elseif (substr($line, 7 + $chars + 1, 21) === '(preferred MIME name)')
|
||||
{
|
||||
$preferred = end($aliases);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Compatibility replacements
|
||||
$compat = array(
|
||||
'EUC-KR' => 'Windows-949',
|
||||
'GB2312' => 'GBK',
|
||||
'GB_2312-80' => 'GBK',
|
||||
'ISO-8859-1' => 'Windows-1252',
|
||||
'ISO-8859-9' => 'Windows-1254',
|
||||
'ISO-8859-11' => 'Windows-874',
|
||||
'KS_C_5601-1987' => 'Windows-949',
|
||||
'TIS-620' => 'Windows-874',
|
||||
'x-x-big5' => 'Big5',
|
||||
);
|
||||
|
||||
foreach ($compat as $real => $replace)
|
||||
{
|
||||
if (isset($charsets[$real]) && isset($charsets[$replace]))
|
||||
{
|
||||
$charsets[$replace] = array_merge($charsets[$replace], $charsets[$real]);
|
||||
unset($charsets[$real]);
|
||||
}
|
||||
elseif (isset($charsets[$real]))
|
||||
{
|
||||
$charsets[$replace] = $charsets[$real];
|
||||
$charsets[$replace][] = normalize_character_set($replace);
|
||||
$charsets[$replace] = array_unique($charsets[$replace]);
|
||||
unset($charsets[$real]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$charsets[$replace][] = normalize_character_set($real);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort it
|
||||
uksort($charsets, 'strnatcasecmp');
|
||||
|
||||
// And we're done!
|
||||
return $charsets;
|
||||
}
|
||||
}
|
||||
|
||||
function charset($charset)
|
||||
{
|
||||
$normalized_charset = normalize_character_set($charset);
|
||||
if ($charsets = build_character_set_list())
|
||||
{
|
||||
foreach ($charsets as $preferred => $aliases)
|
||||
{
|
||||
if (in_array($normalized_charset, $aliases))
|
||||
{
|
||||
return $preferred;
|
||||
}
|
||||
}
|
||||
return $charset;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function build_function()
|
||||
{
|
||||
if ($charsets = build_character_set_list())
|
||||
{
|
||||
$return = <<<EOF
|
||||
function charset(\$charset)
|
||||
{
|
||||
/* Character sets are case-insensitive, and also need some further
|
||||
normalization in the real world (though we'll return them in the form given
|
||||
in their registration). */
|
||||
switch (strtolower(preg_replace('/[\\x09-\\x0D\\x20-\\x2F\\x3A-\\x40\\x5B-\\x60\\x7B-\\x7E]/', '', \$charset)))
|
||||
{
|
||||
|
||||
EOF;
|
||||
foreach ($charsets as $preferred => $aliases)
|
||||
{
|
||||
foreach ($aliases as $alias)
|
||||
{
|
||||
$return .= "\t\tcase " . var_export($alias, true) . ":\n";
|
||||
}
|
||||
$return .= "\t\t\treturn " . var_export($preferred, true) . ";\n\n";
|
||||
}
|
||||
$return .= <<<EOF
|
||||
default:
|
||||
return \$charset;
|
||||
}
|
||||
}
|
||||
EOF;
|
||||
return $return;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (php_sapi_name() === 'cli' && realpath($_SERVER['argv'][0]) === __FILE__)
|
||||
{
|
||||
echo build_function();
|
||||
}
|
||||
|
||||
?>
|
@ -1,502 +0,0 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
@ -1,123 +0,0 @@
|
||||
*******************************************************************************
|
||||
* *
|
||||
* IDNA Convert (idna_convert.class.php) *
|
||||
* *
|
||||
* http://idnaconv.phlymail.de mailto:phlymail@phlylabs.de *
|
||||
*******************************************************************************
|
||||
* (c) 2004-2007 phlyLabs, Berlin *
|
||||
* This file is encoded in UTF-8 *
|
||||
*******************************************************************************
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
The class idna_convert allows to convert internationalized domain names
|
||||
(see RFC 3490, 3491, 3492 and 3454 for detials) as they can be used with various
|
||||
registries worldwide to be translated between their original (localized) form
|
||||
and their encoded form as it will be used in the DNS (Domain Name System).
|
||||
|
||||
The class provides two public methods, encode() and decode(), which do exactly
|
||||
what you would expect them to do. You are allowed to use complete domain names,
|
||||
simple strings and complete email addresses as well. That means, that you might
|
||||
use any of the following notations:
|
||||
|
||||
- www.nörgler.com
|
||||
- xn--nrgler-wxa
|
||||
- xn--brse-5qa.xn--knrz-1ra.info
|
||||
|
||||
Errors, incorrectly encoded or invalid strings will lead to either a FALSE
|
||||
response (when in strict mode) or to only partially converted strings.
|
||||
You can query the occured error by calling the method get_last_error().
|
||||
|
||||
Unicode strings are expected to be either UTF-8 strings, UCS-4 strings or UCS-4
|
||||
arrays. The default format is UTF-8. For setting different encodings, you can
|
||||
call the method setParams() - please see the inline documentation for details.
|
||||
ACE strings (the Punycode form) are always 7bit ASCII strings.
|
||||
|
||||
ATTENTION: We no longer supply the PHP5 version of the class. It is not
|
||||
necessary for achieving a successfull conversion, since the supplied PHP code is
|
||||
compatible with both PHP4 and PHP5. We expect to see no compatibility issues
|
||||
with the upcoming PHP6, too.
|
||||
|
||||
|
||||
Files
|
||||
-----
|
||||
|
||||
idna_convert.class.php - The actual class
|
||||
idna_convert.create.npdata.php - Useful for (re)creating the NPData file
|
||||
npdata.ser - Serialized data for NamePrep
|
||||
example.php - An example web page for converting
|
||||
ReadMe.txt - This file
|
||||
LICENCE - The LGPL licence file
|
||||
|
||||
The class is contained in idna_convert.class.php.
|
||||
MAKE SURE to copy the npdata.ser file into the same folder as the class file
|
||||
itself!
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
1. Say we wish to encode the domain name nörgler.com:
|
||||
|
||||
// Include the class
|
||||
include_once('idna_convert.class.php');
|
||||
// Instantiate it *
|
||||
$IDN = new idna_convert();
|
||||
// The input string, if input is not UTF-8 or UCS-4, it must be converted before
|
||||
$input = utf8_encode('nörgler.com');
|
||||
// Encode it to its punycode presentation
|
||||
$output = $IDN->encode($input);
|
||||
// Output, what we got now
|
||||
echo $output; // This will read: xn--nrgler-wxa.com
|
||||
|
||||
|
||||
2. We received an email from a punycoded domain and are willing to learn, how
|
||||
the domain name reads originally
|
||||
|
||||
// Include the class
|
||||
include_once('idna_convert.class.php');
|
||||
// Instantiate it (depending on the version you are using) with
|
||||
$IDN = new idna_convert();
|
||||
// The input string
|
||||
$input = 'andre@xn--brse-5qa.xn--knrz-1ra.info';
|
||||
// Encode it to its punycode presentation
|
||||
$output = $IDN->decode($input);
|
||||
// Output, what we got now, if output should be in a format different to UTF-8
|
||||
// or UCS-4, you will have to convert it before outputting it
|
||||
echo utf8_decode($output); // This will read: andre@börse.knörz.info
|
||||
|
||||
|
||||
3. The input is read from a UCS-4 coded file and encoded line by line. By
|
||||
appending the optional second parameter we tell enode() about the input
|
||||
format to be used
|
||||
|
||||
// Include the class
|
||||
include_once('idna_convert.class.php');
|
||||
// Instantiate it
|
||||
$IDN = new dinca_convert();
|
||||
// Iterate through the input file line by line
|
||||
foreach (file('ucs4-domains.txt') as $line) {
|
||||
echo $IDN->encode(trim($line), 'ucs4_string');
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
|
||||
NPData
|
||||
------
|
||||
|
||||
Should you need to recreate the npdata.ser file, which holds all necessary translation
|
||||
tables in a serialized format, you can run the file idna_convert.create.npdata.php, which
|
||||
creates the file for you and stores it in the same folder, where it is placed.
|
||||
Should you need to do changes to the tables you can do so, but beware of the consequences.
|
||||
|
||||
|
||||
Contact us
|
||||
----------
|
||||
|
||||
In case of errors, bugs, questions, wishes, please don't hesitate to contact us
|
||||
under the email address above.
|
||||
|
||||
The team of phlyLabs
|
||||
http://phlylabs.de
|
||||
mailto:phlymail@phlylabs.de
|
@ -1,969 +0,0 @@
|
||||
<?php
|
||||
// {{{ license
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This library is free software; you can redistribute it and/or modify |
|
||||
// | it under the terms of the GNU Lesser General Public License as |
|
||||
// | published by the Free Software Foundation; either version 2.1 of the |
|
||||
// | License, or (at your option) any later version. |
|
||||
// | |
|
||||
// | This library is distributed in the hope that it will be useful, but |
|
||||
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
||||
// | Lesser General Public License for more details. |
|
||||
// | |
|
||||
// | You should have received a copy of the GNU Lesser General Public |
|
||||
// | License along with this library; if not, write to the Free Software |
|
||||
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
||||
// | USA. |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
|
||||
// }}}
|
||||
|
||||
/**
|
||||
* Encode/decode Internationalized Domain Names.
|
||||
*
|
||||
* The class allows to convert internationalized domain names
|
||||
* (see RFC 3490 for details) as they can be used with various registries worldwide
|
||||
* to be translated between their original (localized) form and their encoded form
|
||||
* as it will be used in the DNS (Domain Name System).
|
||||
*
|
||||
* The class provides two public methods, encode() and decode(), which do exactly
|
||||
* what you would expect them to do. You are allowed to use complete domain names,
|
||||
* simple strings and complete email addresses as well. That means, that you might
|
||||
* use any of the following notations:
|
||||
*
|
||||
* - www.nörgler.com
|
||||
* - xn--nrgler-wxa
|
||||
* - xn--brse-5qa.xn--knrz-1ra.info
|
||||
*
|
||||
* Unicode input might be given as either UTF-8 string, UCS-4 string or UCS-4
|
||||
* array. Unicode output is available in the same formats.
|
||||
* You can select your preferred format via {@link set_paramter()}.
|
||||
*
|
||||
* ACE input and output is always expected to be ASCII.
|
||||
*
|
||||
* @author Matthias Sommerfeld <mso@phlylabs.de>
|
||||
* @copyright 2004-2007 phlyLabs Berlin, http://phlylabs.de
|
||||
* @version 0.5.1
|
||||
*
|
||||
*/
|
||||
class idna_convert
|
||||
{
|
||||
/**
|
||||
* Holds all relevant mapping tables, loaded from a seperate file on construct
|
||||
* See RFC3454 for details
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $NP = array();
|
||||
|
||||
// Internal settings, do not mess with them
|
||||
var $_punycode_prefix = 'xn--';
|
||||
var $_invalid_ucs = 0x80000000;
|
||||
var $_max_ucs = 0x10FFFF;
|
||||
var $_base = 36;
|
||||
var $_tmin = 1;
|
||||
var $_tmax = 26;
|
||||
var $_skew = 38;
|
||||
var $_damp = 700;
|
||||
var $_initial_bias = 72;
|
||||
var $_initial_n = 0x80;
|
||||
var $_sbase = 0xAC00;
|
||||
var $_lbase = 0x1100;
|
||||
var $_vbase = 0x1161;
|
||||
var $_tbase = 0x11A7;
|
||||
var $_lcount = 19;
|
||||
var $_vcount = 21;
|
||||
var $_tcount = 28;
|
||||
var $_ncount = 588; // _vcount * _tcount
|
||||
var $_scount = 11172; // _lcount * _tcount * _vcount
|
||||
var $_error = false;
|
||||
|
||||
// See {@link set_paramter()} for details of how to change the following
|
||||
// settings from within your script / application
|
||||
var $_api_encoding = 'utf8'; // Default input charset is UTF-8
|
||||
var $_allow_overlong = false; // Overlong UTF-8 encodings are forbidden
|
||||
var $_strict_mode = false; // Behave strict or not
|
||||
|
||||
// The constructor
|
||||
function idna_convert($options = false)
|
||||
{
|
||||
$this->slast = $this->_sbase + $this->_lcount * $this->_vcount * $this->_tcount;
|
||||
if (function_exists('file_get_contents')) {
|
||||
$this->NP = unserialize(file_get_contents(dirname(__FILE__).'/npdata.ser'));
|
||||
} else {
|
||||
$this->NP = unserialize(join('', file(dirname(__FILE__).'/npdata.ser')));
|
||||
}
|
||||
// If parameters are given, pass these to the respective method
|
||||
if (is_array($options)) {
|
||||
return $this->set_parameter($options);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new option value. Available options and values:
|
||||
* [encoding - Use either UTF-8, UCS4 as array or UCS4 as string as input ('utf8' for UTF-8,
|
||||
* 'ucs4_string' and 'ucs4_array' respectively for UCS4); The output is always UTF-8]
|
||||
* [overlong - Unicode does not allow unnecessarily long encodings of chars,
|
||||
* to allow this, set this parameter to true, else to false;
|
||||
* default is false.]
|
||||
* [strict - true: strict mode, good for registration purposes - Causes errors
|
||||
* on failures; false: loose mode, ideal for "wildlife" applications
|
||||
* by silently ignoring errors and returning the original input instead
|
||||
*
|
||||
* @param mixed Parameter to set (string: single parameter; array of Parameter => Value pairs)
|
||||
* @param string Value to use (if parameter 1 is a string)
|
||||
* @return boolean true on success, false otherwise
|
||||
* @access public
|
||||
*/
|
||||
function set_parameter($option, $value = false)
|
||||
{
|
||||
if (!is_array($option)) {
|
||||
$option = array($option => $value);
|
||||
}
|
||||
foreach ($option as $k => $v) {
|
||||
switch ($k) {
|
||||
case 'encoding':
|
||||
switch ($v) {
|
||||
case 'utf8':
|
||||
case 'ucs4_string':
|
||||
case 'ucs4_array':
|
||||
$this->_api_encoding = $v;
|
||||
break;
|
||||
default:
|
||||
$this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 'overlong':
|
||||
$this->_allow_overlong = ($v) ? true : false;
|
||||
break;
|
||||
case 'strict':
|
||||
$this->_strict_mode = ($v) ? true : false;
|
||||
break;
|
||||
default:
|
||||
$this->_error('Set Parameter: Unknown option '.$k);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a given ACE domain name
|
||||
* @param string Domain name (ACE string)
|
||||
* [@param string Desired output encoding, see {@link set_parameter}]
|
||||
* @return string Decoded Domain name (UTF-8 or UCS-4)
|
||||
* @access public
|
||||
*/
|
||||
function decode($input, $one_time_encoding = false)
|
||||
{
|
||||
// Optionally set
|
||||
if ($one_time_encoding) {
|
||||
switch ($one_time_encoding) {
|
||||
case 'utf8':
|
||||
case 'ucs4_string':
|
||||
case 'ucs4_array':
|
||||
break;
|
||||
default:
|
||||
$this->_error('Unknown encoding '.$one_time_encoding);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Make sure to drop any newline characters around
|
||||
$input = trim($input);
|
||||
|
||||
// Negotiate input and try to determine, whether it is a plain string,
|
||||
// an email address or something like a complete URL
|
||||
if (strpos($input, '@')) { // Maybe it is an email address
|
||||
// No no in strict mode
|
||||
if ($this->_strict_mode) {
|
||||
$this->_error('Only simple domain name parts can be handled in strict mode');
|
||||
return false;
|
||||
}
|
||||
list ($email_pref, $input) = explode('@', $input, 2);
|
||||
$arr = explode('.', $input);
|
||||
foreach ($arr as $k => $v) {
|
||||
if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) {
|
||||
$conv = $this->_decode($v);
|
||||
if ($conv) $arr[$k] = $conv;
|
||||
}
|
||||
}
|
||||
$input = join('.', $arr);
|
||||
$arr = explode('.', $email_pref);
|
||||
foreach ($arr as $k => $v) {
|
||||
if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) {
|
||||
$conv = $this->_decode($v);
|
||||
if ($conv) $arr[$k] = $conv;
|
||||
}
|
||||
}
|
||||
$email_pref = join('.', $arr);
|
||||
$return = $email_pref . '@' . $input;
|
||||
} elseif (preg_match('![:\./]!', $input)) { // Or a complete domain name (with or without paths / parameters)
|
||||
// No no in strict mode
|
||||
if ($this->_strict_mode) {
|
||||
$this->_error('Only simple domain name parts can be handled in strict mode');
|
||||
return false;
|
||||
}
|
||||
$parsed = parse_url($input);
|
||||
if (isset($parsed['host'])) {
|
||||
$arr = explode('.', $parsed['host']);
|
||||
foreach ($arr as $k => $v) {
|
||||
$conv = $this->_decode($v);
|
||||
if ($conv) $arr[$k] = $conv;
|
||||
}
|
||||
$parsed['host'] = join('.', $arr);
|
||||
$return =
|
||||
(empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://'))
|
||||
.(empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@')
|
||||
.$parsed['host']
|
||||
.(empty($parsed['port']) ? '' : ':'.$parsed['port'])
|
||||
.(empty($parsed['path']) ? '' : $parsed['path'])
|
||||
.(empty($parsed['query']) ? '' : '?'.$parsed['query'])
|
||||
.(empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']);
|
||||
} else { // parse_url seems to have failed, try without it
|
||||
$arr = explode('.', $input);
|
||||
foreach ($arr as $k => $v) {
|
||||
$conv = $this->_decode($v);
|
||||
$arr[$k] = ($conv) ? $conv : $v;
|
||||
}
|
||||
$return = join('.', $arr);
|
||||
}
|
||||
} else { // Otherwise we consider it being a pure domain name string
|
||||
$return = $this->_decode($input);
|
||||
if (!$return) $return = $input;
|
||||
}
|
||||
// The output is UTF-8 by default, other output formats need conversion here
|
||||
// If one time encoding is given, use this, else the objects property
|
||||
switch (($one_time_encoding) ? $one_time_encoding : $this->_api_encoding) {
|
||||
case 'utf8':
|
||||
return $return;
|
||||
break;
|
||||
case 'ucs4_string':
|
||||
return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return));
|
||||
break;
|
||||
case 'ucs4_array':
|
||||
return $this->_utf8_to_ucs4($return);
|
||||
break;
|
||||
default:
|
||||
$this->_error('Unsupported output format');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a given UTF-8 domain name
|
||||
* @param string Domain name (UTF-8 or UCS-4)
|
||||
* [@param string Desired input encoding, see {@link set_parameter}]
|
||||
* @return string Encoded Domain name (ACE string)
|
||||
* @access public
|
||||
*/
|
||||
function encode($decoded, $one_time_encoding = false)
|
||||
{
|
||||
// Forcing conversion of input to UCS4 array
|
||||
// If one time encoding is given, use this, else the objects property
|
||||
switch ($one_time_encoding ? $one_time_encoding : $this->_api_encoding) {
|
||||
case 'utf8':
|
||||
$decoded = $this->_utf8_to_ucs4($decoded);
|
||||
break;
|
||||
case 'ucs4_string':
|
||||
$decoded = $this->_ucs4_string_to_ucs4($decoded);
|
||||
case 'ucs4_array':
|
||||
break;
|
||||
default:
|
||||
$this->_error('Unsupported input format: '.($one_time_encoding ? $one_time_encoding : $this->_api_encoding));
|
||||
return false;
|
||||
}
|
||||
|
||||
// No input, no output, what else did you expect?
|
||||
if (empty($decoded)) return '';
|
||||
|
||||
// Anchors for iteration
|
||||
$last_begin = 0;
|
||||
// Output string
|
||||
$output = '';
|
||||
foreach ($decoded as $k => $v) {
|
||||
// Make sure to use just the plain dot
|
||||
switch($v) {
|
||||
case 0x3002:
|
||||
case 0xFF0E:
|
||||
case 0xFF61:
|
||||
$decoded[$k] = 0x2E;
|
||||
// Right, no break here, the above are converted to dots anyway
|
||||
// Stumbling across an anchoring character
|
||||
case 0x2E:
|
||||
case 0x2F:
|
||||
case 0x3A:
|
||||
case 0x3F:
|
||||
case 0x40:
|
||||
// Neither email addresses nor URLs allowed in strict mode
|
||||
if ($this->_strict_mode) {
|
||||
$this->_error('Neither email addresses nor URLs are allowed in strict mode.');
|
||||
return false;
|
||||
} else {
|
||||
// Skip first char
|
||||
if ($k) {
|
||||
$encoded = '';
|
||||
$encoded = $this->_encode(array_slice($decoded, $last_begin, (($k)-$last_begin)));
|
||||
if ($encoded) {
|
||||
$output .= $encoded;
|
||||
} else {
|
||||
$output .= $this->_ucs4_to_utf8(array_slice($decoded, $last_begin, (($k)-$last_begin)));
|
||||
}
|
||||
$output .= chr($decoded[$k]);
|
||||
}
|
||||
$last_begin = $k + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Catch the rest of the string
|
||||
if ($last_begin) {
|
||||
$inp_len = sizeof($decoded);
|
||||
$encoded = '';
|
||||
$encoded = $this->_encode(array_slice($decoded, $last_begin, (($inp_len)-$last_begin)));
|
||||
if ($encoded) {
|
||||
$output .= $encoded;
|
||||
} else {
|
||||
$output .= $this->_ucs4_to_utf8(array_slice($decoded, $last_begin, (($inp_len)-$last_begin)));
|
||||
}
|
||||
return $output;
|
||||
} else {
|
||||
if ($output = $this->_encode($decoded)) {
|
||||
return $output;
|
||||
} else {
|
||||
return $this->_ucs4_to_utf8($decoded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to get the last error ocurred
|
||||
* @param void
|
||||
* @return string The last error, that occured
|
||||
* @access public
|
||||
*/
|
||||
function get_last_error()
|
||||
{
|
||||
return $this->_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual decoding algorithm
|
||||
* @access private
|
||||
*/
|
||||
function _decode($encoded)
|
||||
{
|
||||
// We do need to find the Punycode prefix
|
||||
if (!preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $encoded)) {
|
||||
$this->_error('This is not a punycode string');
|
||||
return false;
|
||||
}
|
||||
$encode_test = preg_replace('!^'.preg_quote($this->_punycode_prefix, '!').'!', '', $encoded);
|
||||
// If nothing left after removing the prefix, it is hopeless
|
||||
if (!$encode_test) {
|
||||
$this->_error('The given encoded string was empty');
|
||||
return false;
|
||||
}
|
||||
// Find last occurence of the delimiter
|
||||
$delim_pos = strrpos($encoded, '-');
|
||||
if ($delim_pos > strlen($this->_punycode_prefix)) {
|
||||
for ($k = strlen($this->_punycode_prefix); $k < $delim_pos; ++$k) {
|
||||
$decoded[] = ord($encoded{$k});
|
||||
}
|
||||
} else {
|
||||
$decoded = array();
|
||||
}
|
||||
$deco_len = count($decoded);
|
||||
$enco_len = strlen($encoded);
|
||||
|
||||
// Wandering through the strings; init
|
||||
$is_first = true;
|
||||
$bias = $this->_initial_bias;
|
||||
$idx = 0;
|
||||
$char = $this->_initial_n;
|
||||
|
||||
for ($enco_idx = ($delim_pos) ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len) {
|
||||
for ($old_idx = $idx, $w = 1, $k = $this->_base; 1 ; $k += $this->_base) {
|
||||
$digit = $this->_decode_digit($encoded{$enco_idx++});
|
||||
$idx += $digit * $w;
|
||||
$t = ($k <= $bias) ? $this->_tmin :
|
||||
(($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias));
|
||||
if ($digit < $t) break;
|
||||
$w = (int) ($w * ($this->_base - $t));
|
||||
}
|
||||
$bias = $this->_adapt($idx - $old_idx, $deco_len + 1, $is_first);
|
||||
$is_first = false;
|
||||
$char += (int) ($idx / ($deco_len + 1));
|
||||
$idx %= ($deco_len + 1);
|
||||
if ($deco_len > 0) {
|
||||
// Make room for the decoded char
|
||||
for ($i = $deco_len; $i > $idx; $i--) {
|
||||
$decoded[$i] = $decoded[($i - 1)];
|
||||
}
|
||||
}
|
||||
$decoded[$idx++] = $char;
|
||||
}
|
||||
return $this->_ucs4_to_utf8($decoded);
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual encoding algorithm
|
||||
* @access private
|
||||
*/
|
||||
function _encode($decoded)
|
||||
{
|
||||
// We cannot encode a domain name containing the Punycode prefix
|
||||
$extract = strlen($this->_punycode_prefix);
|
||||
$check_pref = $this->_utf8_to_ucs4($this->_punycode_prefix);
|
||||
$check_deco = array_slice($decoded, 0, $extract);
|
||||
|
||||
if ($check_pref == $check_deco) {
|
||||
$this->_error('This is already a punycode string');
|
||||
return false;
|
||||
}
|
||||
// We will not try to encode strings consisting of basic code points only
|
||||
$encodable = false;
|
||||
foreach ($decoded as $k => $v) {
|
||||
if ($v > 0x7a) {
|
||||
$encodable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$encodable) {
|
||||
$this->_error('The given string does not contain encodable chars');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Do NAMEPREP
|
||||
$decoded = $this->_nameprep($decoded);
|
||||
if (!$decoded || !is_array($decoded)) return false; // NAMEPREP failed
|
||||
|
||||
$deco_len = count($decoded);
|
||||
if (!$deco_len) return false; // Empty array
|
||||
|
||||
$codecount = 0; // How many chars have been consumed
|
||||
|
||||
$encoded = '';
|
||||
// Copy all basic code points to output
|
||||
for ($i = 0; $i < $deco_len; ++$i) {
|
||||
$test = $decoded[$i];
|
||||
// Will match [-0-9a-zA-Z]
|
||||
if ((0x2F < $test && $test < 0x40) || (0x40 < $test && $test < 0x5B)
|
||||
|| (0x60 < $test && $test <= 0x7B) || (0x2D == $test)) {
|
||||
$encoded .= chr($decoded[$i]);
|
||||
$codecount++;
|
||||
}
|
||||
}
|
||||
if ($codecount == $deco_len) return $encoded; // All codepoints were basic ones
|
||||
|
||||
// Start with the prefix; copy it to output
|
||||
$encoded = $this->_punycode_prefix.$encoded;
|
||||
|
||||
// If we have basic code points in output, add an hyphen to the end
|
||||
if ($codecount) $encoded .= '-';
|
||||
|
||||
// Now find and encode all non-basic code points
|
||||
$is_first = true;
|
||||
$cur_code = $this->_initial_n;
|
||||
$bias = $this->_initial_bias;
|
||||
$delta = 0;
|
||||
while ($codecount < $deco_len) {
|
||||
// Find the smallest code point >= the current code point and
|
||||
// remember the last ouccrence of it in the input
|
||||
for ($i = 0, $next_code = $this->_max_ucs; $i < $deco_len; $i++) {
|
||||
if ($decoded[$i] >= $cur_code && $decoded[$i] <= $next_code) {
|
||||
$next_code = $decoded[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$delta += ($next_code - $cur_code) * ($codecount + 1);
|
||||
$cur_code = $next_code;
|
||||
|
||||
// Scan input again and encode all characters whose code point is $cur_code
|
||||
for ($i = 0; $i < $deco_len; $i++) {
|
||||
if ($decoded[$i] < $cur_code) {
|
||||
$delta++;
|
||||
} elseif ($decoded[$i] == $cur_code) {
|
||||
for ($q = $delta, $k = $this->_base; 1; $k += $this->_base) {
|
||||
$t = ($k <= $bias) ? $this->_tmin :
|
||||
(($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias);
|
||||
if ($q < $t) break;
|
||||
$encoded .= $this->_encode_digit(intval($t + (($q - $t) % ($this->_base - $t)))); //v0.4.5 Changed from ceil() to intval()
|
||||
$q = (int) (($q - $t) / ($this->_base - $t));
|
||||
}
|
||||
$encoded .= $this->_encode_digit($q);
|
||||
$bias = $this->_adapt($delta, $codecount+1, $is_first);
|
||||
$codecount++;
|
||||
$delta = 0;
|
||||
$is_first = false;
|
||||
}
|
||||
}
|
||||
$delta++;
|
||||
$cur_code++;
|
||||
}
|
||||
return $encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt the bias according to the current code point and position
|
||||
* @access private
|
||||
*/
|
||||
function _adapt($delta, $npoints, $is_first)
|
||||
{
|
||||
$delta = intval($is_first ? ($delta / $this->_damp) : ($delta / 2));
|
||||
$delta += intval($delta / $npoints);
|
||||
for ($k = 0; $delta > (($this->_base - $this->_tmin) * $this->_tmax) / 2; $k += $this->_base) {
|
||||
$delta = intval($delta / ($this->_base - $this->_tmin));
|
||||
}
|
||||
return intval($k + ($this->_base - $this->_tmin + 1) * $delta / ($delta + $this->_skew));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encoding a certain digit
|
||||
* @access private
|
||||
*/
|
||||
function _encode_digit($d)
|
||||
{
|
||||
return chr($d + 22 + 75 * ($d < 26));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a certain digit
|
||||
* @access private
|
||||
*/
|
||||
function _decode_digit($cp)
|
||||
{
|
||||
$cp = ord($cp);
|
||||
return ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $this->_base));
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal error handling method
|
||||
* @access private
|
||||
*/
|
||||
function _error($error = '')
|
||||
{
|
||||
$this->_error = $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do Nameprep according to RFC3491 and RFC3454
|
||||
* @param array Unicode Characters
|
||||
* @return string Unicode Characters, Nameprep'd
|
||||
* @access private
|
||||
*/
|
||||
function _nameprep($input)
|
||||
{
|
||||
$output = array();
|
||||
$error = false;
|
||||
//
|
||||
// Mapping
|
||||
// Walking through the input array, performing the required steps on each of
|
||||
// the input chars and putting the result into the output array
|
||||
// While mapping required chars we apply the cannonical ordering
|
||||
foreach ($input as $v) {
|
||||
// Map to nothing == skip that code point
|
||||
if (in_array($v, $this->NP['map_nothing'])) continue;
|
||||
|
||||
// Try to find prohibited input
|
||||
if (in_array($v, $this->NP['prohibit']) || in_array($v, $this->NP['general_prohibited'])) {
|
||||
$this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v));
|
||||
return false;
|
||||
}
|
||||
foreach ($this->NP['prohibit_ranges'] as $range) {
|
||||
if ($range[0] <= $v && $v <= $range[1]) {
|
||||
$this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//
|
||||
// Hangul syllable decomposition
|
||||
if (0xAC00 <= $v && $v <= 0xD7AF) {
|
||||
foreach ($this->_hangul_decompose($v) as $out) {
|
||||
$output[] = (int) $out;
|
||||
}
|
||||
// There's a decomposition mapping for that code point
|
||||
} elseif (isset($this->NP['replacemaps'][$v])) {
|
||||
foreach ($this->_apply_cannonical_ordering($this->NP['replacemaps'][$v]) as $out) {
|
||||
$output[] = (int) $out;
|
||||
}
|
||||
} else {
|
||||
$output[] = (int) $v;
|
||||
}
|
||||
}
|
||||
// Before applying any Combining, try to rearrange any Hangul syllables
|
||||
$output = $this->_hangul_compose($output);
|
||||
//
|
||||
// Combine code points
|
||||
//
|
||||
$last_class = 0;
|
||||
$last_starter = 0;
|
||||
$out_len = count($output);
|
||||
for ($i = 0; $i < $out_len; ++$i) {
|
||||
$class = $this->_get_combining_class($output[$i]);
|
||||
if ((!$last_class || $last_class > $class) && $class) {
|
||||
// Try to match
|
||||
$seq_len = $i - $last_starter;
|
||||
$out = $this->_combine(array_slice($output, $last_starter, $seq_len));
|
||||
// On match: Replace the last starter with the composed character and remove
|
||||
// the now redundant non-starter(s)
|
||||
if ($out) {
|
||||
$output[$last_starter] = $out;
|
||||
if (count($out) != $seq_len) {
|
||||
for ($j = $i+1; $j < $out_len; ++$j) {
|
||||
$output[$j-1] = $output[$j];
|
||||
}
|
||||
unset($output[$out_len]);
|
||||
}
|
||||
// Rewind the for loop by one, since there can be more possible compositions
|
||||
$i--;
|
||||
$out_len--;
|
||||
$last_class = ($i == $last_starter) ? 0 : $this->_get_combining_class($output[$i-1]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// The current class is 0
|
||||
if (!$class) $last_starter = $i;
|
||||
$last_class = $class;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decomposes a Hangul syllable
|
||||
* (see http://www.unicode.org/unicode/reports/tr15/#Hangul
|
||||
* @param integer 32bit UCS4 code point
|
||||
* @return array Either Hangul Syllable decomposed or original 32bit value as one value array
|
||||
* @access private
|
||||
*/
|
||||
function _hangul_decompose($char)
|
||||
{
|
||||
$sindex = (int) $char - $this->_sbase;
|
||||
if ($sindex < 0 || $sindex >= $this->_scount) {
|
||||
return array($char);
|
||||
}
|
||||
$result = array();
|
||||
$result[] = (int) $this->_lbase + $sindex / $this->_ncount;
|
||||
$result[] = (int) $this->_vbase + ($sindex % $this->_ncount) / $this->_tcount;
|
||||
$T = intval($this->_tbase + $sindex % $this->_tcount);
|
||||
if ($T != $this->_tbase) $result[] = $T;
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
* Ccomposes a Hangul syllable
|
||||
* (see http://www.unicode.org/unicode/reports/tr15/#Hangul
|
||||
* @param array Decomposed UCS4 sequence
|
||||
* @return array UCS4 sequence with syllables composed
|
||||
* @access private
|
||||
*/
|
||||
function _hangul_compose($input)
|
||||
{
|
||||
$inp_len = count($input);
|
||||
if (!$inp_len) return array();
|
||||
$result = array();
|
||||
$last = (int) $input[0];
|
||||
$result[] = $last; // copy first char from input to output
|
||||
|
||||
for ($i = 1; $i < $inp_len; ++$i) {
|
||||
$char = (int) $input[$i];
|
||||
$sindex = $last - $this->_sbase;
|
||||
$lindex = $last - $this->_lbase;
|
||||
$vindex = $char - $this->_vbase;
|
||||
$tindex = $char - $this->_tbase;
|
||||
// Find out, whether two current characters are LV and T
|
||||
if (0 <= $sindex && $sindex < $this->_scount && ($sindex % $this->_tcount == 0)
|
||||
&& 0 <= $tindex && $tindex <= $this->_tcount) {
|
||||
// create syllable of form LVT
|
||||
$last += $tindex;
|
||||
$result[(count($result) - 1)] = $last; // reset last
|
||||
continue; // discard char
|
||||
}
|
||||
// Find out, whether two current characters form L and V
|
||||
if (0 <= $lindex && $lindex < $this->_lcount && 0 <= $vindex && $vindex < $this->_vcount) {
|
||||
// create syllable of form LV
|
||||
$last = (int) $this->_sbase + ($lindex * $this->_vcount + $vindex) * $this->_tcount;
|
||||
$result[(count($result) - 1)] = $last; // reset last
|
||||
continue; // discard char
|
||||
}
|
||||
// if neither case was true, just add the character
|
||||
$last = $char;
|
||||
$result[] = $char;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the combining class of a certain wide char
|
||||
* @param integer Wide char to check (32bit integer)
|
||||
* @return integer Combining class if found, else 0
|
||||
* @access private
|
||||
*/
|
||||
function _get_combining_class($char)
|
||||
{
|
||||
return isset($this->NP['norm_combcls'][$char]) ? $this->NP['norm_combcls'][$char] : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apllies the cannonical ordering of a decomposed UCS4 sequence
|
||||
* @param array Decomposed UCS4 sequence
|
||||
* @return array Ordered USC4 sequence
|
||||
* @access private
|
||||
*/
|
||||
function _apply_cannonical_ordering($input)
|
||||
{
|
||||
$swap = true;
|
||||
$size = count($input);
|
||||
while ($swap) {
|
||||
$swap = false;
|
||||
$last = $this->_get_combining_class(intval($input[0]));
|
||||
for ($i = 0; $i < $size-1; ++$i) {
|
||||
$next = $this->_get_combining_class(intval($input[$i+1]));
|
||||
if ($next != 0 && $last > $next) {
|
||||
// Move item leftward until it fits
|
||||
for ($j = $i + 1; $j > 0; --$j) {
|
||||
if ($this->_get_combining_class(intval($input[$j-1])) <= $next) break;
|
||||
$t = intval($input[$j]);
|
||||
$input[$j] = intval($input[$j-1]);
|
||||
$input[$j-1] = $t;
|
||||
$swap = true;
|
||||
}
|
||||
// Reentering the loop looking at the old character again
|
||||
$next = $last;
|
||||
}
|
||||
$last = $next;
|
||||
}
|
||||
}
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do composition of a sequence of starter and non-starter
|
||||
* @param array UCS4 Decomposed sequence
|
||||
* @return array Ordered USC4 sequence
|
||||
* @access private
|
||||
*/
|
||||
function _combine($input)
|
||||
{
|
||||
$inp_len = count($input);
|
||||
foreach ($this->NP['replacemaps'] as $np_src => $np_target) {
|
||||
if ($np_target[0] != $input[0]) continue;
|
||||
if (count($np_target) != $inp_len) continue;
|
||||
$hit = false;
|
||||
foreach ($input as $k2 => $v2) {
|
||||
if ($v2 == $np_target[$k2]) {
|
||||
$hit = true;
|
||||
} else {
|
||||
$hit = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($hit) return $np_src;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This converts an UTF-8 encoded string to its UCS-4 representation
|
||||
* By talking about UCS-4 "strings" we mean arrays of 32bit integers representing
|
||||
* each of the "chars". This is due to PHP not being able to handle strings with
|
||||
* bit depth different from 8. This apllies to the reverse method _ucs4_to_utf8(), too.
|
||||
* The following UTF-8 encodings are supported:
|
||||
* bytes bits representation
|
||||
* 1 7 0xxxxxxx
|
||||
* 2 11 110xxxxx 10xxxxxx
|
||||
* 3 16 1110xxxx 10xxxxxx 10xxxxxx
|
||||
* 4 21 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
* 5 26 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
* 6 31 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
* Each x represents a bit that can be used to store character data.
|
||||
* The five and six byte sequences are part of Annex D of ISO/IEC 10646-1:2000
|
||||
* @access private
|
||||
*/
|
||||
function _utf8_to_ucs4($input)
|
||||
{
|
||||
$output = array();
|
||||
$out_len = 0;
|
||||
$inp_len = strlen($input);
|
||||
$mode = 'next';
|
||||
$test = 'none';
|
||||
for ($k = 0; $k < $inp_len; ++$k) {
|
||||
$v = ord($input{$k}); // Extract byte from input string
|
||||
|
||||
if ($v < 128) { // We found an ASCII char - put into stirng as is
|
||||
$output[$out_len] = $v;
|
||||
++$out_len;
|
||||
if ('add' == $mode) {
|
||||
$this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k);
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ('next' == $mode) { // Try to find the next start byte; determine the width of the Unicode char
|
||||
$start_byte = $v;
|
||||
$mode = 'add';
|
||||
$test = 'range';
|
||||
if ($v >> 5 == 6) { // &110xxxxx 10xxxxx
|
||||
$next_byte = 0; // Tells, how many times subsequent bitmasks must rotate 6bits to the left
|
||||
$v = ($v - 192) << 6;
|
||||
} elseif ($v >> 4 == 14) { // &1110xxxx 10xxxxxx 10xxxxxx
|
||||
$next_byte = 1;
|
||||
$v = ($v - 224) << 12;
|
||||
} elseif ($v >> 3 == 30) { // &11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
$next_byte = 2;
|
||||
$v = ($v - 240) << 18;
|
||||
} elseif ($v >> 2 == 62) { // &111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
$next_byte = 3;
|
||||
$v = ($v - 248) << 24;
|
||||
} elseif ($v >> 1 == 126) { // &1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
$next_byte = 4;
|
||||
$v = ($v - 252) << 30;
|
||||
} else {
|
||||
$this->_error('This might be UTF-8, but I don\'t understand it at byte '.$k);
|
||||
return false;
|
||||
}
|
||||
if ('add' == $mode) {
|
||||
$output[$out_len] = (int) $v;
|
||||
++$out_len;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ('add' == $mode) {
|
||||
if (!$this->_allow_overlong && $test == 'range') {
|
||||
$test = 'none';
|
||||
if (($v < 0xA0 && $start_byte == 0xE0) || ($v < 0x90 && $start_byte == 0xF0) || ($v > 0x8F && $start_byte == 0xF4)) {
|
||||
$this->_error('Bogus UTF-8 character detected (out of legal range) at byte '.$k);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ($v >> 6 == 2) { // Bit mask must be 10xxxxxx
|
||||
$v = ($v - 128) << ($next_byte * 6);
|
||||
$output[($out_len - 1)] += $v;
|
||||
--$next_byte;
|
||||
} else {
|
||||
$this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k);
|
||||
return false;
|
||||
}
|
||||
if ($next_byte < 0) {
|
||||
$mode = 'next';
|
||||
}
|
||||
}
|
||||
} // for
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert UCS-4 string into UTF-8 string
|
||||
* See _utf8_to_ucs4() for details
|
||||
* @access private
|
||||
*/
|
||||
function _ucs4_to_utf8($input)
|
||||
{
|
||||
$output = '';
|
||||
$k = 0;
|
||||
foreach ($input as $v) {
|
||||
++$k;
|
||||
// $v = ord($v);
|
||||
if ($v < 128) { // 7bit are transferred literally
|
||||
$output .= chr($v);
|
||||
} elseif ($v < (1 << 11)) { // 2 bytes
|
||||
$output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63));
|
||||
} elseif ($v < (1 << 16)) { // 3 bytes
|
||||
$output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
|
||||
} elseif ($v < (1 << 21)) { // 4 bytes
|
||||
$output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63))
|
||||
. chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
|
||||
} elseif ($v < (1 << 26)) { // 5 bytes
|
||||
$output .= chr(248 + ($v >> 24)) . chr(128 + (($v >> 18) & 63))
|
||||
. chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63))
|
||||
. chr(128 + ($v & 63));
|
||||
} elseif ($v < (1 << 31)) { // 6 bytes
|
||||
$output .= chr(252 + ($v >> 30)) . chr(128 + (($v >> 24) & 63))
|
||||
. chr(128 + (($v >> 18) & 63)) . chr(128 + (($v >> 12) & 63))
|
||||
. chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63));
|
||||
} else {
|
||||
$this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert UCS-4 array into UCS-4 string
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _ucs4_to_ucs4_string($input)
|
||||
{
|
||||
$output = '';
|
||||
// Take array values and split output to 4 bytes per value
|
||||
// The bit mask is 255, which reads &11111111
|
||||
foreach ($input as $v) {
|
||||
$output .= chr(($v >> 24) & 255).chr(($v >> 16) & 255).chr(($v >> 8) & 255).chr($v & 255);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert UCS-4 strin into UCS-4 garray
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _ucs4_string_to_ucs4($input)
|
||||
{
|
||||
$output = array();
|
||||
$inp_len = strlen($input);
|
||||
// Input length must be dividable by 4
|
||||
if ($inp_len % 4) {
|
||||
$this->_error('Input UCS4 string is broken');
|
||||
return false;
|
||||
}
|
||||
// Empty input - return empty output
|
||||
if (!$inp_len) return $output;
|
||||
for ($i = 0, $out_len = -1; $i < $inp_len; ++$i) {
|
||||
// Increment output position every 4 input bytes
|
||||
if (!($i % 4)) {
|
||||
$out_len++;
|
||||
$output[$out_len] = 0;
|
||||
}
|
||||
$output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4) ) );
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter class for aligning the API of idna_convert with that of Net_IDNA
|
||||
* @author Matthias Sommerfeld <mso@phlylabs.de>
|
||||
*/
|
||||
class Net_IDNA_php4 extends idna_convert
|
||||
{
|
||||
/**
|
||||
* Sets a new option value. Available options and values:
|
||||
* [encoding - Use either UTF-8, UCS4 as array or UCS4 as string as input ('utf8' for UTF-8,
|
||||
* 'ucs4_string' and 'ucs4_array' respectively for UCS4); The output is always UTF-8]
|
||||
* [overlong - Unicode does not allow unnecessarily long encodings of chars,
|
||||
* to allow this, set this parameter to true, else to false;
|
||||
* default is false.]
|
||||
* [strict - true: strict mode, good for registration purposes - Causes errors
|
||||
* on failures; false: loose mode, ideal for "wildlife" applications
|
||||
* by silently ignoring errors and returning the original input instead
|
||||
*
|
||||
* @param mixed Parameter to set (string: single parameter; array of Parameter => Value pairs)
|
||||
* @param string Value to use (if parameter 1 is a string)
|
||||
* @return boolean true on success, false otherwise
|
||||
* @access public
|
||||
*/
|
||||
function setParams($option, $param = false)
|
||||
{
|
||||
return $this->IC->set_parameters($option, $param);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,10 +1,12 @@
|
||||
<?php
|
||||
// Create Full-Text Feeds
|
||||
// Author: Keyvan Minoukadeh
|
||||
// Copyright (c) 2011 Keyvan Minoukadeh
|
||||
// Copyright (c) 2012 Keyvan Minoukadeh
|
||||
// License: AGPLv3
|
||||
// Version: 2.8
|
||||
// Date: 2011-05-23
|
||||
// Version: 2.9.5
|
||||
// Date: 2012-04-29
|
||||
// More info: http://fivefilters.org/content-only/
|
||||
// Help: http://help.fivefilters.org
|
||||
|
||||
/*
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@ -36,16 +38,15 @@ ini_set("display_errors", 1);
|
||||
|
||||
// set include path
|
||||
set_include_path(realpath(dirname(__FILE__).'/libraries').PATH_SEPARATOR.get_include_path());
|
||||
|
||||
// Autoloading of classes allows us to include files only when they're
|
||||
// needed. If we've got a cached copy, for example, only Zend_Cache is loaded.
|
||||
function __autoload($class_name) {
|
||||
function autoload($class_name) {
|
||||
static $mapping = array(
|
||||
// Include SimplePie for RSS/Atom parsing
|
||||
'SimplePie' => 'simplepie/simplepie.class.php',
|
||||
'SimplePie_Misc' => 'simplepie/simplepie.class.php',
|
||||
'SimplePie_HTTP_Parser' => 'simplepie/simplepie.class.php',
|
||||
'SimplePie_File' => 'simplepie/simplepie.class.php',
|
||||
// 'SimplePie' => 'simplepie/simplepie.class.php',
|
||||
// 'SimplePie_Misc' => 'simplepie/simplepie.class.php',
|
||||
// 'SimplePie_HTTP_Parser' => 'simplepie/simplepie.class.php',
|
||||
// 'SimplePie_File' => 'simplepie/simplepie.class.php',
|
||||
// Include FeedCreator for RSS/Atom creation
|
||||
'FeedWriter' => 'feedwriter/FeedWriter.php',
|
||||
'FeedItem' => 'feedwriter/FeedItem.php',
|
||||
@ -58,11 +59,13 @@ function __autoload($class_name) {
|
||||
'SimplePie_HumbleHttpAgent' => 'humble-http-agent/SimplePie_HumbleHttpAgent.php',
|
||||
'CookieJar' => 'humble-http-agent/CookieJar.php',
|
||||
// Include IRI class for resolving relative URLs
|
||||
'IRI' => 'iri/iri.php',
|
||||
// 'IRI' => 'iri/iri.php',
|
||||
// Include Zend Cache to improve performance (cache results)
|
||||
'Zend_Cache' => 'Zend/Cache.php',
|
||||
// Include Zend CSS to XPath for dealing with custom patterns
|
||||
'Zend_Dom_Query_Css2Xpath' => 'Zend/Dom/Query/Css2Xpath.php'
|
||||
'Zend_Dom_Query_Css2Xpath' => 'Zend/Dom/Query/Css2Xpath.php',
|
||||
// Language detect
|
||||
'Text_LanguageDetect' => 'language-detect/LanguageDetect.php'
|
||||
);
|
||||
if (isset($mapping[$class_name])) {
|
||||
//echo "Loading $class_name\n<br />";
|
||||
@ -72,12 +75,27 @@ function __autoload($class_name) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
spl_autoload_register('autoload');
|
||||
require_once 'libraries/simplepie/SimplePieAutoloader.php';
|
||||
// always include Simplepie_Core as it defines constants which other SimplePie components
|
||||
// assume will always be available.
|
||||
require_once 'libraries/simplepie/SimplePie/Core.php';
|
||||
|
||||
////////////////////////////////
|
||||
// Load config file if it exists
|
||||
// Load config file
|
||||
////////////////////////////////
|
||||
require_once(dirname(__FILE__).'/config.php');
|
||||
|
||||
////////////////////////////////
|
||||
// Prevent indexing/following by search engines because:
|
||||
// 1. The content is already public and presumably indexed (why create duplicates?)
|
||||
// 2. Not doing so might increase number of requests from search engines, thus increasing server load
|
||||
// Note: feed readers and services such as Yahoo Pipes will not be affected by this header.
|
||||
// Note: Using Disallow in a robots.txt file will be more effective (search engines will check
|
||||
// that before even requesting makefulltextfeed.php).
|
||||
////////////////////////////////
|
||||
header('X-Robots-Tag: noindex, nofollow');
|
||||
|
||||
////////////////////////////////
|
||||
// Check if service is enabled
|
||||
////////////////////////////////
|
||||
@ -92,6 +110,9 @@ if (!isset($_GET['url'])) {
|
||||
die('No URL supplied');
|
||||
}
|
||||
$url = trim($_GET['url']);
|
||||
if (strtolower(substr($url, 0, 7)) == 'feed://') {
|
||||
$url = 'http://'.substr($url, 7);
|
||||
}
|
||||
if (!preg_match('!^https?://.+!i', $url)) {
|
||||
$url = 'http://'.$url;
|
||||
}
|
||||
@ -114,13 +135,14 @@ if ($test !== false && $test !== null && preg_match('!^https?://!', $url)) {
|
||||
////////////////////////////////
|
||||
if ($options->alternative_url != '' && !isset($_GET['redir']) && mt_rand(0, 100) > 50) {
|
||||
$redirect = $options->alternative_url.'?redir=true&url='.urlencode($url);
|
||||
if (isset($_GET['html'])) $redirect .= '&html='.urlencode($_GET['html']);
|
||||
if (isset($_GET['html'])) $redirect .= '&html='.urlencode($_GET['html']);
|
||||
if (isset($_GET['key'])) $redirect .= '&key='.urlencode($_GET['key']);
|
||||
if (isset($_GET['max'])) $redirect .= '&max='.(int)$_GET['max'];
|
||||
if (isset($_GET['links'])) $redirect .= '&links='.$_GET['links'];
|
||||
if (isset($_GET['exc'])) $redirect .= '&exc='.$_GET['exc'];
|
||||
if (isset($_GET['what'])) $redirect .= '&what='.$_GET['what'];
|
||||
if (isset($_GET['format'])) $redirect .= '&format='.$_GET['format'];
|
||||
if (isset($_GET['what'])) $redirect .= '&what='.$_GET['what'];
|
||||
if (isset($_GET['format'])) $redirect .= '&format='.$_GET['format'];
|
||||
if (isset($_GET['l'])) $redirect .= '&format='.$_GET['l'];
|
||||
header("Location: $redirect");
|
||||
exit;
|
||||
}
|
||||
@ -140,6 +162,7 @@ if (isset($_GET['key']) && ($key_index = array_search($_GET['key'], $options->ap
|
||||
if (isset($_GET['exc'])) $redirect .= '&exc='.urlencode($_GET['exc']);
|
||||
if (isset($_GET['what'])) $redirect .= '&what='.urlencode($_GET['what']);
|
||||
if (isset($_GET['format'])) $redirect .= '&format='.urlencode($_GET['format']);
|
||||
if (isset($_GET['l'])) $redirect .= '&l='.urlencode($_GET['l']);
|
||||
header("Location: $redirect");
|
||||
exit;
|
||||
}
|
||||
@ -166,6 +189,15 @@ $valid_key = false;
|
||||
if (isset($_GET['key']) && isset($_GET['hash']) && isset($options->api_keys[(int)$_GET['key']])) {
|
||||
$valid_key = ($_GET['hash'] == sha1($options->api_keys[(int)$_GET['key']].$url));
|
||||
}
|
||||
$key_index = ($valid_key) ? (int)$_GET['key'] : 0;
|
||||
if (!$valid_key && $options->key_required) {
|
||||
die('A valid key must be supplied');
|
||||
}
|
||||
if (!$valid_key && isset($_GET['key']) && $_GET['key'] != '') {
|
||||
die('The entered key is invalid');
|
||||
}
|
||||
|
||||
if (file_exists('custom_init.php')) require 'custom_init.php';
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Check URL against list of blacklisted URLs
|
||||
@ -209,6 +241,30 @@ if ($options->exclude_items_on_fail == 'user') {
|
||||
$exclude_on_fail = $options->exclude_items_on_fail;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Detect language
|
||||
///////////////////////////////////////////////
|
||||
if ((string)$options->detect_language == 'user') {
|
||||
if (isset($_GET['l'])) {
|
||||
$detect_language = (int)$_GET['l'];
|
||||
} else {
|
||||
$detect_language = 1;
|
||||
}
|
||||
} else {
|
||||
$detect_language = $options->detect_language;
|
||||
}
|
||||
|
||||
if ($detect_language >= 2) {
|
||||
$language_codes = array('albanian' => 'sq','arabic' => 'ar','azeri' => 'az','bengali' => 'bn','bulgarian' => 'bg',
|
||||
'cebuano' => 'ceb', // ISO 639-2
|
||||
'croatian' => 'hr','czech' => 'cs','danish' => 'da','dutch' => 'nl','english' => 'en','estonian' => 'et','farsi' => 'fa','finnish' => 'fi','french' => 'fr','german' => 'de','hausa' => 'ha',
|
||||
'hawaiian' => 'haw', // ISO 639-2
|
||||
'hindi' => 'hi','hungarian' => 'hu','icelandic' => 'is','indonesian' => 'id','italian' => 'it','kazakh' => 'kk','kyrgyz' => 'ky','latin' => 'la','latvian' => 'lv','lithuanian' => 'lt','macedonian' => 'mk','mongolian' => 'mn','nepali' => 'ne','norwegian' => 'no','pashto' => 'ps',
|
||||
'pidgin' => 'cpe', // ISO 639-2
|
||||
'polish' => 'pl','portuguese' => 'pt','romanian' => 'ro','russian' => 'ru','serbian' => 'sr','slovak' => 'sk','slovene' => 'sl','somali' => 'so','spanish' => 'es','swahili' => 'sw','swedish' => 'sv','tagalog' => 'tl','turkish' => 'tr','ukrainian' => 'uk','urdu' => 'ur','uzbek' => 'uz','vietnamese' => 'vi','welsh' => 'cy');
|
||||
}
|
||||
$use_cld = extension_loaded('cld') && (version_compare(PHP_VERSION, '5.3.0') >= 0);
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Extraction pattern
|
||||
///////////////////////////////////////////////
|
||||
@ -278,7 +334,7 @@ if ($options->caching) {
|
||||
|
||||
// getting a Zend_Cache_Core object
|
||||
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
|
||||
$cache_id = md5($max.$url.$valid_key.$links.$exclude_on_fail.$auto_extract.$extract_pattern.$format.(int)isset($_GET['pubsub']));
|
||||
$cache_id = md5($max.$url.$valid_key.$links.$exclude_on_fail.$auto_extract.$extract_pattern.$format.(int)isset($_GET['l']).(int)isset($_GET['pubsub']));
|
||||
|
||||
if ($data = $cache->load($cache_id)) {
|
||||
if ($format == 'json') {
|
||||
@ -305,11 +361,15 @@ if ($valid_key) {
|
||||
// Set up HTTP agent
|
||||
//////////////////////////////////
|
||||
$http = new HumbleHttpAgent();
|
||||
$http->userAgentMap = $options->user_agents;
|
||||
$http->headerOnlyTypes = array_keys($options->content_type_exc);
|
||||
$http->rewriteUrls = $options->rewrite_url;
|
||||
|
||||
//////////////////////////////////
|
||||
// Set up Content Extractor
|
||||
//////////////////////////////////
|
||||
$extractor = new ContentExtractor(dirname(__FILE__).'/site_config/custom', dirname(__FILE__).'/site_config/standard');
|
||||
$extractor->fingerprints = $options->fingerprints;
|
||||
|
||||
/*
|
||||
if ($options->caching) {
|
||||
@ -339,9 +399,13 @@ if ($options->caching) {
|
||||
// Get RSS/Atom feed
|
||||
////////////////////////////////
|
||||
if (!$html_only) {
|
||||
// Send user agent header showing PHP (prevents a HTML response from feedburner)
|
||||
$http->userAgentDefault = HumbleHttpAgent::UA_PHP;
|
||||
// configure SimplePie HTTP extension class to use our HumbleHttpAgent instance
|
||||
SimplePie_HumbleHttpAgent::set_agent($http);
|
||||
$feed = new SimplePie();
|
||||
// some feeds use the text/html content type - force_feed tells SimplePie to process anyway
|
||||
$feed->force_feed(true);
|
||||
$feed->set_file_class('SimplePie_HumbleHttpAgent');
|
||||
//$feed->set_feed_url($url); // colons appearing in the URL's path get encoded
|
||||
$feed->feed_url = $url;
|
||||
@ -359,6 +423,8 @@ if (!$html_only) {
|
||||
if ($result && (!is_array($feed->data) || count($feed->data) == 0)) {
|
||||
die('Sorry, no feed items found');
|
||||
}
|
||||
// from now on, we'll identify ourselves as a browser
|
||||
$http->userAgentDefault = HumbleHttpAgent::UA_BROWSER;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -377,6 +443,7 @@ if ($html_only || !$result) {
|
||||
public function get_title() { return ''; }
|
||||
public function get_description() { return 'Content extracted from '.$this->item->url; }
|
||||
public function get_link() { return $this->item->url; }
|
||||
public function get_language() { return false; }
|
||||
public function get_image_url() { return false; }
|
||||
public function get_items($start=0, $max=1) { return array(0=>$this->item); }
|
||||
}
|
||||
@ -386,8 +453,11 @@ if ($html_only || !$result) {
|
||||
public function get_permalink() { return $this->url; }
|
||||
public function get_title() { return ''; }
|
||||
public function get_date($format='') { return false; }
|
||||
public function get_author() { return false; }
|
||||
public function get_author($key=0) { return null; }
|
||||
public function get_authors() { return null; }
|
||||
public function get_description() { return ''; }
|
||||
public function get_enclosure($key=0, $prefer=null) { return null; }
|
||||
public function get_enclosures() { return null; }
|
||||
}
|
||||
$feed = new DummySingleItemFeed($url);
|
||||
}
|
||||
@ -408,10 +478,12 @@ $output->setLink($feed->get_link()); // Google Reader uses this for pulling in f
|
||||
if ($img_url = $feed->get_image_url()) {
|
||||
$output->setImage($feed->get_title(), $feed->get_link(), $img_url);
|
||||
}
|
||||
/*
|
||||
if ($format == 'atom') {
|
||||
$output->setChannelElement('updated', date(DATE_ATOM));
|
||||
$output->setChannelElement('author', array('name'=>'Five Filters', 'uri'=>'http://fivefilters.org'));
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////
|
||||
// Loop through feed items
|
||||
@ -424,7 +496,9 @@ foreach ($items as $key => $item) {
|
||||
$permalink = htmlspecialchars_decode($item->get_permalink());
|
||||
// Colons in URL path segments get encoded by SimplePie, yet some sites expect them unencoded
|
||||
$permalink = str_replace('%3A', ':', $permalink);
|
||||
$permalink = $http->validateUrl($permalink);
|
||||
// validateUrl() strips non-ascii characters
|
||||
// simplepie already sanitizes URLs so let's not do it again here.
|
||||
//$permalink = $http->validateUrl($permalink);
|
||||
if ($permalink) {
|
||||
$urls_sanitized[] = $permalink;
|
||||
}
|
||||
@ -433,8 +507,13 @@ foreach ($items as $key => $item) {
|
||||
$http->fetchAll($urls_sanitized);
|
||||
//$http->cacheAll();
|
||||
|
||||
// count number of items added to full feed
|
||||
$item_count = 0;
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
$do_content_extraction = true;
|
||||
$extract_result = false;
|
||||
$text_sample = null;
|
||||
$permalink = $urls[$key];
|
||||
$newitem = $output->createNewItem();
|
||||
$newitem->setTitle(htmlspecialchars_decode($item->get_title()));
|
||||
@ -451,129 +530,256 @@ foreach ($items as $key => $item) {
|
||||
$newitem->setLink($item->get_permalink());
|
||||
}
|
||||
}
|
||||
if ($permalink && ($response = $http->get($permalink, true)) && $response['status_code'] < 300) {
|
||||
// TODO: Allow error codes - some sites return correct content with error status
|
||||
// e.g. prospectmagazine.co.uk returns 403
|
||||
//if ($permalink && ($response = $http->get($permalink, true)) && $response['status_code'] < 300) {
|
||||
if ($permalink && ($response = $http->get($permalink, true)) && ($response['status_code'] < 300 || $response['status_code'] > 400)) {
|
||||
$effective_url = $response['effective_url'];
|
||||
if (!url_allowed($effective_url)) continue;
|
||||
$html = $response['body'];
|
||||
// remove strange things
|
||||
$html = str_replace('</[>', '', $html);
|
||||
$html = convert_to_utf8($html, $response['headers']);
|
||||
if ($auto_extract) {
|
||||
// check site config for single page URL - fetch it if found
|
||||
if ($single_page_response = getSinglePage($item, $html, $effective_url)) {
|
||||
$html = $single_page_response['body'];
|
||||
// remove strange things
|
||||
$html = str_replace('</[>', '', $html);
|
||||
$html = convert_to_utf8($html, $single_page_response['headers']);
|
||||
$effective_url = $single_page_response['effective_url'];
|
||||
unset($single_page_response);
|
||||
// check if action defined for returned Content-Type
|
||||
$type = null;
|
||||
if (preg_match('!^Content-Type:\s*(([-\w]+)/([-\w\+]+))!im', $response['headers'], $match)) {
|
||||
// look for full mime type (e.g. image/jpeg) or just type (e.g. image)
|
||||
$match[1] = strtolower(trim($match[1]));
|
||||
$match[2] = strtolower(trim($match[2]));
|
||||
foreach (array($match[1], $match[2]) as $_mime) {
|
||||
if (isset($options->content_type_exc[$_mime])) {
|
||||
$type = $match[1];
|
||||
$_act = $options->content_type_exc[$_mime]['action'];
|
||||
$_name = $options->content_type_exc[$_mime]['name'];
|
||||
if ($_act == 'exclude') {
|
||||
continue 2; // skip this feed item entry
|
||||
} elseif ($_act == 'link') {
|
||||
if ($match[2] == 'image') {
|
||||
$html = "<a href=\"$effective_url\"><img src=\"$effective_url\" alt=\"$_name\" /></a>";
|
||||
} else {
|
||||
$html = "<a href=\"$effective_url\">Download $_name</a>";
|
||||
}
|
||||
$title = $_name;
|
||||
$do_content_extraction = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($_mime, $_act, $_name, $match);
|
||||
}
|
||||
if ($do_content_extraction) {
|
||||
$html = $response['body'];
|
||||
// remove strange things
|
||||
$html = str_replace('</[>', '', $html);
|
||||
$html = convert_to_utf8($html, $response['headers']);
|
||||
if ($auto_extract) {
|
||||
// check site config for single page URL - fetch it if found
|
||||
if ($single_page_response = getSinglePage($item, $html, $effective_url)) {
|
||||
$html = $single_page_response['body'];
|
||||
// remove strange things
|
||||
$html = str_replace('</[>', '', $html);
|
||||
$html = convert_to_utf8($html, $single_page_response['headers']);
|
||||
$effective_url = $single_page_response['effective_url'];
|
||||
unset($single_page_response);
|
||||
}
|
||||
$extract_result = $extractor->process($html, $effective_url);
|
||||
$readability = $extractor->readability;
|
||||
$content_block = ($extract_result) ? $extractor->getContent() : null;
|
||||
$title = ($extract_result) ? $extractor->getTitle() : '';
|
||||
} else {
|
||||
$readability = new Readability($html, $effective_url);
|
||||
// content block is entire document (for now...)
|
||||
$content_block = $readability->dom;
|
||||
//TODO: get title
|
||||
$title = '';
|
||||
}
|
||||
$extract_result = $extractor->process($html, $effective_url);
|
||||
$readability = $extractor->readability;
|
||||
$content_block = ($extract_result) ? $extractor->getContent() : null;
|
||||
$title = ($extract_result) ? $extractor->getTitle() : '';
|
||||
} else {
|
||||
$readability = new Readability($html, $effective_url);
|
||||
// content block is entire document (for now...)
|
||||
$content_block = $readability->dom;
|
||||
//TODO: get title
|
||||
$title = '';
|
||||
}
|
||||
// use extracted title for both feed and item title if we're using single-item dummy feed
|
||||
if ($isDummyFeed) {
|
||||
$output->setTitle($title);
|
||||
$newitem->setTitle($title);
|
||||
}
|
||||
if ($extract_pattern && isset($content_block)) {
|
||||
$xpath = new DOMXPath($readability->dom);
|
||||
$elems = @$xpath->query($extract_pattern, $content_block);
|
||||
// check if our custom extraction pattern matched
|
||||
if ($elems && $elems->length > 0) {
|
||||
$extract_result = true;
|
||||
// get the first matched element
|
||||
$content_block = $elems->item(0);
|
||||
// clean it up
|
||||
$readability->removeScripts($content_block);
|
||||
$readability->prepArticle($content_block);
|
||||
if ($do_content_extraction) {
|
||||
if ($extract_pattern && isset($content_block)) {
|
||||
$xpath = new DOMXPath($readability->dom);
|
||||
$elems = @$xpath->query($extract_pattern, $content_block);
|
||||
// check if our custom extraction pattern matched
|
||||
if ($elems && $elems->length > 0) {
|
||||
$extract_result = true;
|
||||
// get the first matched element
|
||||
$content_block = $elems->item(0);
|
||||
// clean it up
|
||||
$readability->removeScripts($content_block);
|
||||
$readability->prepArticle($content_block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if we failed to extract content...
|
||||
if (!$extract_result) {
|
||||
if ($exclude_on_fail) continue; // skip this and move to next item
|
||||
if (!$valid_key) {
|
||||
$html = $options->error_message;
|
||||
} else {
|
||||
$html = $options->error_message_with_key;
|
||||
}
|
||||
// keep the original item description
|
||||
$html .= $item->get_description();
|
||||
} else {
|
||||
$readability->clean($content_block, 'select');
|
||||
if ($options->rewrite_relative_urls) makeAbsolute($effective_url, $content_block);
|
||||
// footnotes
|
||||
if (($links == 'footnotes') && (strpos($effective_url, 'wikipedia.org') === false)) {
|
||||
$readability->addFootnotes($content_block);
|
||||
}
|
||||
if ($extract_pattern) {
|
||||
// get outerHTML
|
||||
$html = $content_block->ownerDocument->saveXML($content_block);
|
||||
} else {
|
||||
if ($content_block->childNodes->length == 1 && $content_block->firstChild->nodeType === XML_ELEMENT_NODE) {
|
||||
$html = $content_block->firstChild->innerHTML;
|
||||
if ($do_content_extraction) {
|
||||
// if we failed to extract content...
|
||||
if (!$extract_result) {
|
||||
if ($exclude_on_fail) continue; // skip this and move to next item
|
||||
//TODO: get text sample for language detection
|
||||
if (!$valid_key) {
|
||||
$html = $options->error_message;
|
||||
} else {
|
||||
$html = $content_block->innerHTML;
|
||||
$html = $options->error_message_with_key;
|
||||
}
|
||||
// keep the original item description
|
||||
$html .= $item->get_description();
|
||||
} else {
|
||||
$readability->clean($content_block, 'select');
|
||||
if ($options->rewrite_relative_urls) makeAbsolute($effective_url, $content_block);
|
||||
// footnotes
|
||||
if (($links == 'footnotes') && (strpos($effective_url, 'wikipedia.org') === false)) {
|
||||
$readability->addFootnotes($content_block);
|
||||
}
|
||||
if ($extract_pattern) {
|
||||
// get outerHTML
|
||||
$html = $content_block->ownerDocument->saveXML($content_block);
|
||||
} else {
|
||||
if ($content_block->childNodes->length == 1 && $content_block->firstChild->nodeType === XML_ELEMENT_NODE) {
|
||||
$html = $content_block->firstChild->innerHTML;
|
||||
} else {
|
||||
$html = $content_block->innerHTML;
|
||||
}
|
||||
}
|
||||
// post-processing cleanup
|
||||
$html = preg_replace('!<p>[\s\h\v]*</p>!u', '', $html);
|
||||
if ($links == 'remove') {
|
||||
$html = preg_replace('!</?a[^>]*>!', '', $html);
|
||||
}
|
||||
// get text sample for language detection
|
||||
$text_sample = strip_tags(substr($html, 0, 500));
|
||||
if (!$valid_key) {
|
||||
$html = make_substitutions($options->message_to_prepend).$html;
|
||||
$html .= make_substitutions($options->message_to_append);
|
||||
} else {
|
||||
$html = make_substitutions($options->message_to_prepend_with_key).$html;
|
||||
$html .= make_substitutions($options->message_to_append_with_key);
|
||||
}
|
||||
}
|
||||
// post-processing cleanup
|
||||
$html = preg_replace('!<p>[\s\h\v]*</p>!u', '', $html);
|
||||
if ($links == 'remove') {
|
||||
$html = preg_replace('!</?a[^>]*>!', '', $html);
|
||||
}
|
||||
if (!$valid_key) {
|
||||
$html = make_substitutions($options->message_to_prepend).$html;
|
||||
$html .= make_substitutions($options->message_to_append);
|
||||
} else {
|
||||
$html = make_substitutions($options->message_to_prepend_with_key).$html;
|
||||
$html .= make_substitutions($options->message_to_append_with_key);
|
||||
}
|
||||
}
|
||||
/*
|
||||
if ($format == 'atom') {
|
||||
$newitem->addElement('content', $html);
|
||||
$newitem->setDate((int)$item->get_date('U'));
|
||||
if ($author = $item->get_author()) {
|
||||
$newitem->addElement('author', array('name'=>$author->get_name()));
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
*/
|
||||
if ($valid_key && isset($_GET['pubsub'])) { // used only on fivefilters.org at the moment
|
||||
$newitem->addElement('guid', 'http://fivefilters.org/content-only/redirect.php?url='.urlencode($item->get_permalink()), array('isPermaLink'=>'false'));
|
||||
} else {
|
||||
$newitem->addElement('guid', $item->get_permalink(), array('isPermaLink'=>'true'));
|
||||
}
|
||||
$newitem->setDescription($html);
|
||||
|
||||
// set date
|
||||
if ((int)$item->get_date('U') > 0) {
|
||||
$newitem->setDate((int)$item->get_date('U'));
|
||||
} elseif ($extractor->getDate()) {
|
||||
$newitem->setDate($extractor->getDate());
|
||||
}
|
||||
if ($author = $item->get_author()) {
|
||||
$newitem->addElement('dc:creator', $author->get_name());
|
||||
|
||||
// add authors
|
||||
if ($authors = $item->get_authors()) {
|
||||
foreach ($authors as $author) {
|
||||
$newitem->addElement('dc:creator', $author->get_name());
|
||||
}
|
||||
} elseif ($authors = $extractor->getAuthors()) {
|
||||
//TODO: make sure the list size is reasonable
|
||||
foreach ($authors as $author) {
|
||||
//TODO: addElement replaces this element each time
|
||||
$newitem->addElement('dc:creator', $author);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add language
|
||||
if ($detect_language) {
|
||||
$language = $extractor->getLanguage();
|
||||
if (!$language) $language = $feed->get_language();
|
||||
if (($detect_language == 3 || (!$language && $detect_language == 2)) && $text_sample) {
|
||||
try {
|
||||
if ($use_cld) {
|
||||
// Use PHP-CLD extension
|
||||
$php_cld = 'CLD\detect'; // in quotes to prevent PHP 5.2 parse error
|
||||
$res = $php_cld($text_sample);
|
||||
if (is_array($res) && count($res) > 0) {
|
||||
$language = $res[0]['code'];
|
||||
}
|
||||
} else {
|
||||
//die('what');
|
||||
// Use PEAR's Text_LanguageDetect
|
||||
if (!isset($l)) {
|
||||
$l = new Text_LanguageDetect('libraries/language-detect/lang.dat', 'libraries/language-detect/unicode_blocks.dat');
|
||||
}
|
||||
$l_result = $l->detect($text_sample, 1);
|
||||
if (count($l_result) > 0) {
|
||||
$language = $language_codes[key($l_result)];
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
//die('error: '.$e);
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
if ($language && (strlen($language) < 7)) {
|
||||
$newitem->addElement('dc:language', $language);
|
||||
}
|
||||
}
|
||||
|
||||
// add MIME type (if it appeared in our exclusions lists)
|
||||
if (isset($type)) $newitem->addElement('dc:format', $type);
|
||||
// add effective URL (URL after redirects)
|
||||
if (isset($effective_url)) {
|
||||
//TODO: ensure $effective_url is valid witout - sometimes it causes problems, e.g.
|
||||
//http://www.siasat.pk/forum/showthread.php?108883-Pakistan-Chowk-by-Rana-Mubashir-–-25th-March-2012-Special-Program-from-Liari-(Karachi)
|
||||
//temporary measure: use utf8_encode()
|
||||
$newitem->addElement('dc:identifier', remove_url_cruft(utf8_encode($effective_url)));
|
||||
} else {
|
||||
$newitem->addElement('dc:identifier', remove_url_cruft($item->get_permalink()));
|
||||
}
|
||||
// check for enclosures
|
||||
if ($options->keep_enclosures) {
|
||||
if ($enclosures = $item->get_enclosures()) {
|
||||
foreach ($enclosures as $enclosure) {
|
||||
if (!$enclosure->get_link()) continue;
|
||||
$enc = array();
|
||||
// Media RSS spec ($enc): http://search.yahoo.com/mrss
|
||||
// SimplePie methods ($enclosure): http://simplepie.org/wiki/reference/start#methods4
|
||||
$enc['url'] = $enclosure->get_link();
|
||||
if ($enclosure->get_length()) $enc['fileSize'] = $enclosure->get_length();
|
||||
if ($enclosure->get_type()) $enc['type'] = $enclosure->get_type();
|
||||
if ($enclosure->get_medium()) $enc['medium'] = $enclosure->get_medium();
|
||||
if ($enclosure->get_expression()) $enc['expression'] = $enclosure->get_expression();
|
||||
if ($enclosure->get_bitrate()) $enc['bitrate'] = $enclosure->get_bitrate();
|
||||
if ($enclosure->get_framerate()) $enc['framerate'] = $enclosure->get_framerate();
|
||||
if ($enclosure->get_sampling_rate()) $enc['samplingrate'] = $enclosure->get_sampling_rate();
|
||||
if ($enclosure->get_channels()) $enc['channels'] = $enclosure->get_channels();
|
||||
if ($enclosure->get_duration()) $enc['duration'] = $enclosure->get_duration();
|
||||
if ($enclosure->get_height()) $enc['height'] = $enclosure->get_height();
|
||||
if ($enclosure->get_width()) $enc['width'] = $enclosure->get_width();
|
||||
if ($enclosure->get_language()) $enc['lang'] = $enclosure->get_language();
|
||||
$newitem->addElement('media:content', '', $enc);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* } */
|
||||
$output->addItem($newitem);
|
||||
unset($html);
|
||||
$item_count++;
|
||||
}
|
||||
|
||||
// output feed
|
||||
if ($options->caching || $format == 'json') {
|
||||
if ($format == 'json') $output->setFormat(JSON);
|
||||
if ($options->caching) {
|
||||
ob_start();
|
||||
$output->genarateFeed();
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
if ($format == 'json') {
|
||||
$jsonrss = new stdClass();
|
||||
$jsonrss->rss = @simplexml_load_string($output);
|
||||
$output = json_encode($jsonrss);
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
if ($html_only && $item_count == 0) {
|
||||
// do not cache - in case of temporary server glitch at source URL
|
||||
} else {
|
||||
$cache->save($output, $cache_id);
|
||||
}
|
||||
if ($options->caching) $cache->save($output, $cache_id);
|
||||
echo $output;
|
||||
} else {
|
||||
$output->genarateFeed();
|
||||
@ -618,50 +824,64 @@ function convert_to_utf8($html, $header=null)
|
||||
// error parsing the response
|
||||
} else {
|
||||
$match = end($match); // get last matched element (in case of redirects)
|
||||
if (isset($match[2])) $encoding = trim($match[2], '"\'');
|
||||
if (isset($match[2])) $encoding = trim($match[2], "\"' \r\n\0\x0B\t");
|
||||
}
|
||||
if (!$encoding) {
|
||||
if (preg_match('/^<\?xml\s+version=(?:"[^"]*"|\'[^\']*\')\s+encoding=("[^"]*"|\'[^\']*\')/s', $html, $match)) {
|
||||
// TODO: check to see if encoding is supported (can we convert it?)
|
||||
// If it's not, result will be empty string.
|
||||
// For now we'll check for invalid encoding types returned by some sites, e.g. 'none'
|
||||
// Problem URL: http://facta.co.jp/blog/archives/20111026001026.html
|
||||
if (!$encoding || $encoding == 'none') {
|
||||
// search for encoding in HTML - only look at the first 35000 characters
|
||||
$html_head = substr($html, 0, 40000);
|
||||
if (preg_match('/^<\?xml\s+version=(?:"[^"]*"|\'[^\']*\')\s+encoding=("[^"]*"|\'[^\']*\')/s', $html_head, $match)) {
|
||||
$encoding = trim($match[1], '"\'');
|
||||
} elseif(preg_match('/<meta\s+http-equiv=["\']Content-Type["\'] content=["\'][^;]+;\s*charset=["\']?([^;"\'>]+)/i', $html, $match)) {
|
||||
if (isset($match[1])) $encoding = trim($match[1]);
|
||||
} elseif (preg_match('/<meta\s+http-equiv=["\']?Content-Type["\']? content=["\'][^;]+;\s*charset=["\']?([^;"\'>]+)/i', $html_head, $match)) {
|
||||
$encoding = trim($match[1]);
|
||||
} elseif (preg_match_all('/<meta\s+([^>]+)>/i', $html_head, $match)) {
|
||||
foreach ($match[1] as $_test) {
|
||||
if (preg_match('/charset=["\']?([^"\']+)/i', $_test, $_m)) {
|
||||
$encoding = trim($_m[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($encoding)) $encoding = trim($encoding);
|
||||
// trim is important here!
|
||||
if (!$encoding || (strtolower($encoding) == 'iso-8859-1')) {
|
||||
// replace MS Word smart qutoes
|
||||
$trans = array();
|
||||
$trans[chr(130)] = '‚'; // Single Low-9 Quotation Mark
|
||||
$trans[chr(131)] = 'ƒ'; // Latin Small Letter F With Hook
|
||||
$trans[chr(132)] = '„'; // Double Low-9 Quotation Mark
|
||||
$trans[chr(133)] = '…'; // Horizontal Ellipsis
|
||||
$trans[chr(134)] = '†'; // Dagger
|
||||
$trans[chr(135)] = '‡'; // Double Dagger
|
||||
$trans[chr(136)] = 'ˆ'; // Modifier Letter Circumflex Accent
|
||||
$trans[chr(137)] = '‰'; // Per Mille Sign
|
||||
$trans[chr(138)] = 'Š'; // Latin Capital Letter S With Caron
|
||||
$trans[chr(139)] = '‹'; // Single Left-Pointing Angle Quotation Mark
|
||||
$trans[chr(140)] = 'Œ'; // Latin Capital Ligature OE
|
||||
$trans[chr(145)] = '‘'; // Left Single Quotation Mark
|
||||
$trans[chr(146)] = '’'; // Right Single Quotation Mark
|
||||
$trans[chr(147)] = '“'; // Left Double Quotation Mark
|
||||
$trans[chr(148)] = '”'; // Right Double Quotation Mark
|
||||
$trans[chr(149)] = '•'; // Bullet
|
||||
$trans[chr(150)] = '–'; // En Dash
|
||||
$trans[chr(151)] = '—'; // Em Dash
|
||||
$trans[chr(152)] = '˜'; // Small Tilde
|
||||
$trans[chr(153)] = '™'; // Trade Mark Sign
|
||||
$trans[chr(154)] = 'š'; // Latin Small Letter S With Caron
|
||||
$trans[chr(155)] = '›'; // Single Right-Pointing Angle Quotation Mark
|
||||
$trans[chr(156)] = 'œ'; // Latin Small Ligature OE
|
||||
$trans[chr(159)] = 'Ÿ'; // Latin Capital Letter Y With Diaeresis
|
||||
$html = strtr($html, $trans);
|
||||
}
|
||||
if (!$encoding) {
|
||||
$encoding = 'utf-8';
|
||||
} else {
|
||||
if (strtolower($encoding) != 'utf-8') {
|
||||
if (strtolower($encoding) == 'iso-8859-1') {
|
||||
// replace MS Word smart qutoes
|
||||
$trans = array();
|
||||
$trans[chr(130)] = '‚'; // Single Low-9 Quotation Mark
|
||||
$trans[chr(131)] = 'ƒ'; // Latin Small Letter F With Hook
|
||||
$trans[chr(132)] = '„'; // Double Low-9 Quotation Mark
|
||||
$trans[chr(133)] = '…'; // Horizontal Ellipsis
|
||||
$trans[chr(134)] = '†'; // Dagger
|
||||
$trans[chr(135)] = '‡'; // Double Dagger
|
||||
$trans[chr(136)] = 'ˆ'; // Modifier Letter Circumflex Accent
|
||||
$trans[chr(137)] = '‰'; // Per Mille Sign
|
||||
$trans[chr(138)] = 'Š'; // Latin Capital Letter S With Caron
|
||||
$trans[chr(139)] = '‹'; // Single Left-Pointing Angle Quotation Mark
|
||||
$trans[chr(140)] = 'Œ'; // Latin Capital Ligature OE
|
||||
$trans[chr(145)] = '‘'; // Left Single Quotation Mark
|
||||
$trans[chr(146)] = '’'; // Right Single Quotation Mark
|
||||
$trans[chr(147)] = '“'; // Left Double Quotation Mark
|
||||
$trans[chr(148)] = '”'; // Right Double Quotation Mark
|
||||
$trans[chr(149)] = '•'; // Bullet
|
||||
$trans[chr(150)] = '–'; // En Dash
|
||||
$trans[chr(151)] = '—'; // Em Dash
|
||||
$trans[chr(152)] = '˜'; // Small Tilde
|
||||
$trans[chr(153)] = '™'; // Trade Mark Sign
|
||||
$trans[chr(154)] = 'š'; // Latin Small Letter S With Caron
|
||||
$trans[chr(155)] = '›'; // Single Right-Pointing Angle Quotation Mark
|
||||
$trans[chr(156)] = 'œ'; // Latin Small Ligature OE
|
||||
$trans[chr(159)] = 'Ÿ'; // Latin Capital Letter Y With Diaeresis
|
||||
$html = strtr($html, $trans);
|
||||
}
|
||||
$html = SimplePie_Misc::change_encoding($html, $encoding, 'utf-8');
|
||||
|
||||
/*
|
||||
if (function_exists('iconv')) {
|
||||
// iconv appears to handle certain character encodings better than mb_convert_encoding
|
||||
@ -677,9 +897,10 @@ function convert_to_utf8($html, $header=null)
|
||||
}
|
||||
|
||||
function makeAbsolute($base, $elem) {
|
||||
$base = new IRI($base);
|
||||
// remove '//' in URL path (causes URLs not to resolve properly)
|
||||
if (isset($base->ipath)) $base->ipath = preg_replace('!//+!', '/', $base->ipath);
|
||||
$base = new SimplePie_IRI($base);
|
||||
// remove '//' in URL path (used to prevent URLs from resolving properly)
|
||||
// TODO: check if this is still the case
|
||||
if (isset($base->path)) $base->path = preg_replace('!//+!', '/', $base->path);
|
||||
foreach(array('a'=>'href', 'img'=>'src') as $tag => $attr) {
|
||||
$elems = $elem->getElementsByTagName($tag);
|
||||
for ($i = $elems->length-1; $i >= 0; $i--) {
|
||||
@ -697,32 +918,42 @@ function makeAbsoluteAttr($base, $e, $attr) {
|
||||
$url = trim(str_replace('%20', ' ', $e->getAttribute($attr)));
|
||||
$url = str_replace(' ', '%20', $url);
|
||||
if (!preg_match('!https?://!i', $url)) {
|
||||
$absolute = IRI::absolutize($base, $url);
|
||||
if ($absolute) {
|
||||
if ($absolute = SimplePie_IRI::absolutize($base, $url)) {
|
||||
$e->setAttribute($attr, $absolute);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function makeAbsoluteStr($base, $url) {
|
||||
$base = new IRI($base);
|
||||
$base = new SimplePie_IRI($base);
|
||||
// remove '//' in URL path (causes URLs not to resolve properly)
|
||||
if (isset($base->ipath)) $base->ipath = preg_replace('!//+!', '/', $base->ipath);
|
||||
if (isset($base->path)) $base->path = preg_replace('!//+!', '/', $base->path);
|
||||
if (preg_match('!^https?://!i', $url)) {
|
||||
// already absolute
|
||||
return $url;
|
||||
} else {
|
||||
$absolute = IRI::absolutize($base, $url);
|
||||
if ($absolute) return $absolute;
|
||||
if ($absolute = SimplePie_IRI::absolutize($base, $url)) {
|
||||
return $absolute;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// returns single page response, or false if not found
|
||||
function getSinglePage($item, $html, $url) {
|
||||
global $http;
|
||||
global $http, $extractor;
|
||||
$host = @parse_url($url, PHP_URL_HOST);
|
||||
$site_config = SiteConfig::build($host);
|
||||
if ($site_config === false) return false;
|
||||
if ($site_config === false) {
|
||||
// check for fingerprints
|
||||
if (!empty($extractor->fingerprints) && ($_fphost = $extractor->findHostUsingFingerprints($html))) {
|
||||
$site_config = SiteConfig::build($_fphost);
|
||||
}
|
||||
if ($site_config === false) $site_config = new SiteConfig();
|
||||
SiteConfig::add_to_cache($host, $site_config);
|
||||
return false;
|
||||
} else {
|
||||
SiteConfig::add_to_cache($host, $site_config);
|
||||
}
|
||||
$splink = null;
|
||||
if (!empty($site_config->single_page_link)) {
|
||||
$splink = $site_config->single_page_link;
|
||||
@ -745,9 +976,12 @@ function getSinglePage($item, $html, $url) {
|
||||
break;
|
||||
} elseif ($elems instanceof DOMNodeList && $elems->length > 0) {
|
||||
foreach ($elems as $item) {
|
||||
if ($item->hasAttribute('href')) {
|
||||
if ($item instanceof DOMElement && $item->hasAttribute('href')) {
|
||||
$single_page_url = $item->getAttribute('href');
|
||||
break;
|
||||
} elseif ($item instanceof DOMAttr && $item->value) {
|
||||
$single_page_url = $item->value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -757,15 +991,26 @@ function getSinglePage($item, $html, $url) {
|
||||
// check it's not what we have already!
|
||||
if ($single_page_url != $url) {
|
||||
// it's not, so let's try to fetch it...
|
||||
$_prev_ref = $http->referer;
|
||||
$http->referer = $single_page_url;
|
||||
if (($response = $http->get($single_page_url, true)) && $response['status_code'] < 300) {
|
||||
$http->referer = $_prev_ref;
|
||||
return $response;
|
||||
}
|
||||
$http->referer = $_prev_ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function remove_url_cruft($url) {
|
||||
// remove google analytics for the time being
|
||||
// regex adapted from http://navitronic.co.uk/2010/12/removing-google-analytics-cruft-from-urls/
|
||||
// https://gist.github.com/758177
|
||||
return preg_replace('/(\?|\&)utm_[a-z]+=[^\&]+/', '', $url);
|
||||
}
|
||||
|
||||
function make_substitutions($string) {
|
||||
if ($string == '') return $string;
|
||||
global $item, $effective_url;
|
||||
|
@ -1,59 +1,6 @@
|
||||
Full-Text RSS Site Patterns
|
||||
---------------------------
|
||||
|
||||
NOTE: The information here is not up to date, but probably covers what you need for this version. For the most up to date information on Full-Text RSS site patterns, please see http://help.fivefilters.org/customer/portal/articles/223153-site-patterns
|
||||
|
||||
We recommend using the latest release of Full-Text RSS - available for purchase at http://fivefilters.org/content-only/#download - which also comes bundled with hundreds of site patterns to improve extraction.
|
||||
|
||||
Site patterns allow you to specify what should be extracted from specific sites.
|
||||
|
||||
How it works
|
||||
------------
|
||||
After we fetch the contents of a URL, we use the hostname (e.g. example.org) and check to see if a config file exists for that hostname. If there is a matching file (e.g. example.org.txt) in one of the config folders, we will fetch the rules it contains. If no such file is found, we attempt to detect the appropriate content block and title automatically. When there is a matching site config, we first try to use the patterns within to extract the content. If these patterns fail to match, we will, by default, revert to auto-detection - this gives us another chance to get at the content (useful when site redesigns invalidate our stored patterns).
|
||||
|
||||
The 'standard' folder contains site config files bundled with Full-Text RSS. Users may contribute their own patterns and we will try to update with each release.
|
||||
|
||||
The 'custom' folder can be used for sites not listed in standard, or to override sites in standard. If a site has an entry in both folders, only the one in 'custom' will be used. The custom folder allows you to separate your entries from the bundled ones, which also makes the task of upgrading to a new release easier (you benefit from the updated patterns in standard and copy over your existing patterns to custom).
|
||||
|
||||
The pattern format has been borrowed from Instapaper. Please see http://blog.instapaper.com/post/730281947 and http://www.instapaper.com/bodytext (requires login). We make use of the patterns provided by Instapaper and, in the same spirit, will soon make available our own additions.
|
||||
|
||||
|
||||
Command reference (based on Instapaper)
|
||||
---------------------------------------
|
||||
title: [XPath]
|
||||
The page title.
|
||||
XPaths evaluating to strings are also accepted.
|
||||
Multiple statements accepted.
|
||||
Will evaluate in order until a result is found.
|
||||
|
||||
body: [XPath]
|
||||
The body-text container. Auto-detected by default.
|
||||
Multiple statements accepted.
|
||||
Will evaluate in order until a result is found.
|
||||
|
||||
strip: [XPath]
|
||||
Strip any matching element and its children.
|
||||
Multiple statements accepted.
|
||||
|
||||
strip_id_or_class: [string]
|
||||
Strip any element whose @id or @class contains this substring.
|
||||
Multiple statements accepted.
|
||||
|
||||
strip_image_src: [string]
|
||||
Strip any <IMG> whose @src contains this substring.
|
||||
Multiple statements accepted.
|
||||
|
||||
tidy: [yes|no] (default: yes)
|
||||
Preprocess with Tidy. May cause "no text" errors.
|
||||
|
||||
prune: [yes|no] (default: yes)
|
||||
Strip elements within body that do not resemble content elements.
|
||||
|
||||
autodetect_on_failure: [yes|no] (default: yes)
|
||||
If set to no, we will not attempt to auto-detect the title or content block.
|
||||
|
||||
test_url: [string]
|
||||
Must be URL of an article from this site, not the site's front page.
|
||||
|
||||
# comments
|
||||
Lines beginning with # are ignored.
|
||||
Please see http://help.fivefilters.org/customer/portal/articles/223153-site-patterns for more information.
|
@ -1,5 +1,19 @@
|
||||
body: //div[@id = 'content']
|
||||
title: //h1[@id='firstHeading']
|
||||
body: //div[@id = 'bodyContent']
|
||||
strip_id_or_class: editsection
|
||||
strip_id_or_class: toc
|
||||
#strip_id_or_class: toc
|
||||
strip_id_or_class: vertical-navbox
|
||||
strip: //table[@id='toc']
|
||||
strip: //div[@id='catlinks']
|
||||
strip: //div[@id='jump-to-nav']
|
||||
strip: //div[@class='thumbcaption']//div[@class='magnify']
|
||||
strip: //table[@class='navbox']
|
||||
strip: //table[contains(@class, 'infobox')]
|
||||
strip: //div[@class='dablink']
|
||||
strip: //div[@id='contentSub']
|
||||
strip: //table[contains(@class, 'metadata')]
|
||||
strip: //*[contains(@class, 'noprint')]
|
||||
strip: //span[@title='pronunciation:']
|
||||
prune: no
|
||||
tidy: no
|
||||
test_url: http://en.wikipedia.org/wiki/Christopher_Lloyd
|