version 2.2
28
changelog.txt
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
FiveFilters.org: Full-Text RSS
|
||||||
|
http://fivefilters.org/content-only/
|
||||||
|
CHANGELOG
|
||||||
|
------------------------------------
|
||||||
|
|
||||||
|
2.2 (2010-10-30)
|
||||||
|
- Character-encoding detection improved (minor change)
|
||||||
|
- Rewriting of relative URLs improved (tracks redirect URLs)
|
||||||
|
- Minor changes to prevent errors in certain hosting environments
|
||||||
|
- Compatibility test file updated with more tests
|
||||||
|
|
||||||
|
2.1 (2010-09-13)
|
||||||
|
- Better content extraction (using PHP Readability 1.7.1)
|
||||||
|
- Parallel HTTP requests (using Humble HTTP Agent)
|
||||||
|
- Auto loading of necessary classes
|
||||||
|
- Rewriting of relative URLs (using IRI)
|
||||||
|
- Added compatibility test file (to check if server meets requirements)
|
||||||
|
- Character-encoding support improved (using SimplePie)
|
||||||
|
|
||||||
|
1.5 (2010-05-30)
|
||||||
|
- Support for PHP 5.3 (thanks Murilo!)
|
||||||
|
- Character-encoding support improved (favours iconv over mb_convert_encoding)
|
||||||
|
|
||||||
|
1.0 (2010-03-05)
|
||||||
|
- Better support for different character-encodings
|
||||||
|
- Auto-cleanup of cache files
|
||||||
|
- Very basic option for load distribution (if you're planning on installing the code on multiple servers)
|
||||||
|
- Separate config file (see config-sample.php)
|
130
config-sample.php
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
/* Full-Text RSS options */
|
||||||
|
|
||||||
|
// Enable service
|
||||||
|
// ----------------------
|
||||||
|
// Set this to false if you want to disable the service.
|
||||||
|
// If set to false, no feed is produced and users will
|
||||||
|
// be told that the service is disabled.
|
||||||
|
$options->enabled = true;
|
||||||
|
|
||||||
|
// Restrict service
|
||||||
|
// ----------------------
|
||||||
|
// Set this to true if you'd like certain features
|
||||||
|
// to be available only to key holders.
|
||||||
|
// Affected features:
|
||||||
|
// * Link handling (disabled for non-key holders if set to true)
|
||||||
|
// * Cache time (20 minutes for non-key holders if set to true)
|
||||||
|
$options->restrict = false;
|
||||||
|
|
||||||
|
// Default entries (without API key)
|
||||||
|
// ----------------------
|
||||||
|
// The number of feed items to process when no API key is supplied.
|
||||||
|
$options->default_entries = 5;
|
||||||
|
|
||||||
|
// Max entries (without API key)
|
||||||
|
// ----------------------
|
||||||
|
// The maximum number of feed items to process when no API key is supplied.
|
||||||
|
$options->max_entries = 10;
|
||||||
|
|
||||||
|
// Rewrite relative URLs
|
||||||
|
// ----------------------
|
||||||
|
// With this enabled relative URLs found in the extracted content
|
||||||
|
// block are automatically rewritten as absolute URLs.
|
||||||
|
// Set to false if you want to preserve relative URLs appearing in
|
||||||
|
// the extracted content block.
|
||||||
|
$options->rewrite_relative_urls = true;
|
||||||
|
|
||||||
|
// Enable caching
|
||||||
|
// ----------------------
|
||||||
|
// Enable this if you'd like to cache results
|
||||||
|
// for 10 minutes. Initially it's best
|
||||||
|
// to keep this disabled to make sure everything works
|
||||||
|
// as expected.
|
||||||
|
$options->caching = false;
|
||||||
|
|
||||||
|
// Cache directory
|
||||||
|
// ----------------------
|
||||||
|
// Only used if caching is true
|
||||||
|
$options->cache_dir = dirname(__FILE__).'/cache';
|
||||||
|
|
||||||
|
// Message to prepend (without API key)
|
||||||
|
// ----------------------
|
||||||
|
// HTML to insert at the beginning of each feed item when no API key is supplied.
|
||||||
|
$options->message_to_prepend = '';
|
||||||
|
|
||||||
|
// Message to append (without API key)
|
||||||
|
// ----------------------
|
||||||
|
// HTML to insert at the end of each feed item when no API key is supplied.
|
||||||
|
$options->message_to_append = '';
|
||||||
|
|
||||||
|
// URLs to block
|
||||||
|
// ----------------------
|
||||||
|
// List of URLs (or parts of a URL) which the service should not accept
|
||||||
|
$options->blocked_urls = array();
|
||||||
|
|
||||||
|
// Error message when content extraction fails (without API key)
|
||||||
|
// ----------------------
|
||||||
|
$options->error_message = '[unable to retrieve full-text content]';
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
/// ADVANCED OPTIONS ////////////////////////////
|
||||||
|
/////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// API keys
|
||||||
|
// ----------------------
|
||||||
|
// 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)
|
||||||
|
// ----------------------
|
||||||
|
// 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)
|
||||||
|
// ----------------------
|
||||||
|
// 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)
|
||||||
|
// ----------------------
|
||||||
|
// HTML to insert at the beginning of each feed item when a valid API key is supplied.
|
||||||
|
$options->message_to_prepend_with_key = '';
|
||||||
|
|
||||||
|
// Message to append (with API key)
|
||||||
|
// ----------------------
|
||||||
|
// HTML to insert at the end of each feed item when a valid API key is supplied.
|
||||||
|
$options->message_to_append_with_key = '';
|
||||||
|
|
||||||
|
// Error message when content extraction fails (with API key)
|
||||||
|
// ----------------------
|
||||||
|
$options->error_message_with_key = '[unable to retrieve full-text content]';
|
||||||
|
|
||||||
|
// Alternative Full-Text RSS service URL
|
||||||
|
// ----------------------
|
||||||
|
// This option is to offer very simple load distribution for the service.
|
||||||
|
// If you've set up another instance of the Full-Text RSS service on a different
|
||||||
|
// server, you can enter its full URL here.
|
||||||
|
// E.g. 'http://my-other-server.org/full-text-rss/makefulltextfeed.php'
|
||||||
|
// If you specify a URL here, 50% of the requests to makefulltextfeed.php on
|
||||||
|
// this server will be redirected to the URL specified here.
|
||||||
|
$options->alternative_url = '';
|
||||||
|
|
||||||
|
// Cache directory level
|
||||||
|
// ----------------------
|
||||||
|
// Spread cache files over different directories (only used if caching is enabled).
|
||||||
|
// Used to prevent large number of files in one directory.
|
||||||
|
// This corresponds to Zend_Cache's hashed_directory_level
|
||||||
|
// see http://framework.zend.com/manual/en/zend.cache.backends.html
|
||||||
|
// It's best not to change this if you're unsure.
|
||||||
|
$options->cache_directory_level = 0;
|
||||||
|
|
||||||
|
?>
|
92
css/niceforms-default.css
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/*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:90px; line-height:25px; margin:0 10px 10px 0;}
|
||||||
|
dd {float:left; width:475px; 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;}
|
362
ftr_compatibility_test.php
Normal file
@ -0,0 +1,362 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
FULL-TEXT-RSS V2 COMPATIBILITY TEST
|
||||||
|
|
||||||
|
1) Upload ftr_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/ftr_compatibility_test.php
|
||||||
|
|
||||||
|
2) Open your web browser and go to the page you just uploaded.
|
||||||
|
|
||||||
|
Note: This compatibility test has been borrowed (and slightly adapted) from the one supplied by
|
||||||
|
SimplePie.org. We have kept most of their checks intact as we use SimplePie in our application.
|
||||||
|
http://github.com/simplepie/simplepie/tree/master/compatibility_test/
|
||||||
|
*/
|
||||||
|
|
||||||
|
$app_name = 'Full-Text RSS v2';
|
||||||
|
|
||||||
|
// test redirect
|
||||||
|
$url = parse_url('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
|
||||||
|
$redirect_url = 'http://'.$url['host'].$url['path'].'?redirect=true';
|
||||||
|
if (isset($_GET['redirect'])) {
|
||||||
|
$url = parse_url('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
|
||||||
|
$url = 'http://'.$url['host'].$url['path'].'?redirected=true';
|
||||||
|
header('Location: '.$url);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (isset($_GET['redirected'])) {
|
||||||
|
die('Redirect works');
|
||||||
|
}
|
||||||
|
|
||||||
|
$php_ok = (function_exists('version_compare') && version_compare(phpversion(), '5.2.0', '>='));
|
||||||
|
$pcre_ok = extension_loaded('pcre');
|
||||||
|
$zlib_ok = extension_loaded('zlib');
|
||||||
|
$mbstring_ok = extension_loaded('mbstring');
|
||||||
|
$iconv_ok = extension_loaded('iconv');
|
||||||
|
$tidy_ok = function_exists('tidy_parse_string');
|
||||||
|
$curl_ok = function_exists('curl_exec');
|
||||||
|
$http_ok = (extension_loaded('http') && class_exists('HttpRequestPool'));
|
||||||
|
$allow_url_fopen_ok = (bool)ini_get('allow_url_fopen');
|
||||||
|
$redirect_ok = ($allow_url_fopen_ok && file_get_contents($redirect_url) == 'Redirect works');
|
||||||
|
|
||||||
|
if (extension_loaded('xmlreader')) {
|
||||||
|
$xml_ok = true;
|
||||||
|
} elseif (extension_loaded('xml')) {
|
||||||
|
$parser_check = xml_parser_create();
|
||||||
|
xml_parse_into_struct($parser_check, '<foo>&</foo>', $values);
|
||||||
|
xml_parser_free($parser_check);
|
||||||
|
$xml_ok = isset($values[0]['value']);
|
||||||
|
} else {
|
||||||
|
$xml_ok = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Content-type: text/html; charset=UTF-8');
|
||||||
|
|
||||||
|
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
||||||
|
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title><?php echo $app_name; ?>: Server Compatibility Test</title>
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
font:14px/1.4em "Lucida Grande", Verdana, Arial, Helvetica, Clean, Sans, sans-serif;
|
||||||
|
letter-spacing:0px;
|
||||||
|
color:#333;
|
||||||
|
margin:0;
|
||||||
|
padding:0;
|
||||||
|
background:#fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#site {
|
||||||
|
width:550px;
|
||||||
|
margin:20px auto 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color:#000;
|
||||||
|
text-decoration:underline;
|
||||||
|
padding:0 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover {
|
||||||
|
color:#fff;
|
||||||
|
background-color:#333;
|
||||||
|
text-decoration:none;
|
||||||
|
padding:0 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin:0;
|
||||||
|
padding:5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
em {
|
||||||
|
font-style:normal;
|
||||||
|
background-color:#ffc;
|
||||||
|
padding: 0.1em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul, ol {
|
||||||
|
margin:10px 0 10px 20px;
|
||||||
|
padding:0 0 0 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul li, ol li {
|
||||||
|
margin:0 0 7px 0;
|
||||||
|
padding:0 0 0 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size:18px;
|
||||||
|
padding:0;
|
||||||
|
margin:30px 0 20px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
font-size:16px;
|
||||||
|
padding:0;
|
||||||
|
margin:20px 0 5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
font-size:14px;
|
||||||
|
padding:0;
|
||||||
|
margin:15px 0 5px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-size:1.1em;
|
||||||
|
background-color:#f3f3ff;
|
||||||
|
color:#000;
|
||||||
|
}
|
||||||
|
|
||||||
|
em strong {
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
table#chart {
|
||||||
|
border-collapse:collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
table#chart th {
|
||||||
|
background-color:#eee;
|
||||||
|
padding:2px 3px;
|
||||||
|
border:1px solid #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
table#chart td {
|
||||||
|
text-align:center;
|
||||||
|
padding:2px 3px;
|
||||||
|
border:1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
table#chart tr.enabled td {
|
||||||
|
/* Leave this alone */
|
||||||
|
}
|
||||||
|
|
||||||
|
table#chart tr.disabled td,
|
||||||
|
table#chart tr.disabled td a {
|
||||||
|
color:#999;
|
||||||
|
font-style:italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
table#chart tr.disabled td a {
|
||||||
|
text-decoration:underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.chunk {
|
||||||
|
margin:20px 0 0 0;
|
||||||
|
padding:0 0 10px 0;
|
||||||
|
border-bottom:1px solid #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footnote,
|
||||||
|
.footnote a {
|
||||||
|
font:10px/12px verdana, sans-serif;
|
||||||
|
color:#aaa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footnote em {
|
||||||
|
background-color:transparent;
|
||||||
|
font-style:italic;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="site">
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
<div class="chunk">
|
||||||
|
<h2 style="text-align:center;"><?php echo $app_name; ?>: Compatibility Test</h2>
|
||||||
|
<table cellpadding="0" cellspacing="0" border="0" width="100%" id="chart">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Test</th>
|
||||||
|
<th>Should Be</th>
|
||||||
|
<th>What You Have</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr class="<?php echo ($php_ok) ? 'enabled' : 'disabled'; ?>">
|
||||||
|
<td>PHP</td>
|
||||||
|
<td>5.2.0 or higher</td>
|
||||||
|
<td><?php echo phpversion(); ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="<?php echo ($xml_ok) ? 'enabled, and sane' : 'disabled, or broken'; ?>">
|
||||||
|
<td><a href="http://php.net/xml">XML</a></td>
|
||||||
|
<td>Enabled</td>
|
||||||
|
<td><?php echo ($xml_ok) ? 'Enabled, and sane' : 'Disabled, or broken'; ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="<?php echo ($pcre_ok) ? 'enabled' : 'disabled'; ?>">
|
||||||
|
<td><a href="http://php.net/pcre">PCRE</a></td>
|
||||||
|
<td>Enabled</td>
|
||||||
|
<td><?php echo ($pcre_ok) ? 'Enabled' : 'Disabled'; ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="<?php echo ($zlib_ok) ? 'enabled' : 'disabled'; ?>">
|
||||||
|
<td><a href="http://php.net/zlib">Zlib</a></td>
|
||||||
|
<td>Enabled</td>
|
||||||
|
<td><?php echo ($zlib_ok) ? 'Enabled' : 'Disabled'; ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="<?php echo ($mbstring_ok) ? 'enabled' : 'disabled'; ?>">
|
||||||
|
<td><a href="http://php.net/mbstring">mbstring</a></td>
|
||||||
|
<td>Enabled</td>
|
||||||
|
<td><?php echo ($mbstring_ok) ? 'Enabled' : 'Disabled'; ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="<?php echo ($iconv_ok) ? 'enabled' : 'disabled'; ?>">
|
||||||
|
<td><a href="http://php.net/iconv">iconv</a></td>
|
||||||
|
<td>Enabled</td>
|
||||||
|
<td><?php echo ($iconv_ok) ? 'Enabled' : 'Disabled'; ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="<?php echo ($tidy_ok) ? 'enabled' : 'disabled'; ?>">
|
||||||
|
<td><a href="http://php.net/tidy">Tidy</a></td>
|
||||||
|
<td>Enabled</td>
|
||||||
|
<td><?php echo ($tidy_ok) ? 'Enabled' : 'Disabled'; ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="<?php echo ($curl_ok) ? 'enabled' : 'disabled'; ?>">
|
||||||
|
<td><a href="http://php.net/curl">cURL</a></td>
|
||||||
|
<td>Enabled</td>
|
||||||
|
<td><?php echo (extension_loaded('curl')) ? 'Enabled' : 'Disabled'; ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="<?php echo ($http_ok) ? 'enabled' : 'disabled'; ?>">
|
||||||
|
<td><a href="http://php.net/HttpRequestPool">HttpRequestPool</a></td>
|
||||||
|
<td>Enabled</td>
|
||||||
|
<td><?php echo ($http_ok) ? 'Enabled' : 'Disabled'; ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="<?php echo ($allow_url_fopen_ok) ? 'enabled' : 'disabled'; ?>">
|
||||||
|
<td><a href="http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen">allow_url_fopen</a></td>
|
||||||
|
<td>Enabled</td>
|
||||||
|
<td><?php echo ($allow_url_fopen_ok) ? 'Enabled' : 'Disabled'; ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr class="<?php echo ($redirect_ok) ? 'enabled' : 'disabled'; ?>">
|
||||||
|
<td>HTTP Redirects</td>
|
||||||
|
<td>Enabled</td>
|
||||||
|
<td><?php echo ($redirect_ok) ? 'Enabled' : 'Disabled'; ?></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chunk">
|
||||||
|
<h3>What does this mean?</h3>
|
||||||
|
<ol>
|
||||||
|
<?php if ($php_ok && $xml_ok && $pcre_ok && $mbstring_ok && $iconv_ok && $zlib_ok && $tidy_ok && $curl_ok && $http_ok && $allow_url_fopen_ok && $redirect_ok): ?>
|
||||||
|
<li><em>You have everything you need to run <?php echo $app_name; ?> properly! Congratulations!</em></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php if ($php_ok): ?>
|
||||||
|
<li><strong>PHP:</strong> You are running a supported version of PHP. <em>No problems here.</em></li>
|
||||||
|
<?php if ($xml_ok): ?>
|
||||||
|
<li><strong>XML:</strong> You have XMLReader support or a version of XML support that isn't broken installed. <em>No problems here.</em></li>
|
||||||
|
<?php if ($pcre_ok): ?>
|
||||||
|
<li><strong>PCRE:</strong> You have PCRE support installed. <em>No problems here.</em></li>
|
||||||
|
|
||||||
|
<?php if ($allow_url_fopen_ok): ?>
|
||||||
|
<li><strong>allow_url_fopen:</strong> You have allow_url_fopen enabled. <em>No problems here.</em></li>
|
||||||
|
|
||||||
|
<?php if ($zlib_ok): ?>
|
||||||
|
<li><strong>Zlib:</strong> You have <code>Zlib</code> enabled. This allows SimplePie to support GZIP-encoded feeds. <em>No problems here.</em></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li><strong>Zlib:</strong> The <code>Zlib</code> extension is not available. SimplePie will ignore any GZIP-encoding, and instead handle feeds as uncompressed text.</li>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($mbstring_ok && $iconv_ok): ?>
|
||||||
|
<li><strong>mbstring and iconv:</strong> You have both <code>mbstring</code> and <code>iconv</code> installed! This will allow <?php echo $app_name; ?> to handle the greatest number of languages. <em>No problems here.</em></li>
|
||||||
|
<?php elseif ($mbstring_ok): ?>
|
||||||
|
<li><strong>mbstring:</strong> <code>mbstring</code> is installed, but <code>iconv</code> is not.</li>
|
||||||
|
<?php elseif ($iconv_ok): ?>
|
||||||
|
<li><strong>iconv:</strong> <code>iconv</code> is installed, but <code>mbstring</code> is not.</li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li><strong>mbstring and iconv:</strong> <em>You do not have either of the extensions installed.</em> This will significantly impair your ability to read non-English feeds, as well as even some English ones.</li>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($tidy_ok): ?>
|
||||||
|
<li><strong>Tidy:</strong> You have <code>Tidy</code> support installed. <em>No problems here.</em></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li><strong>Tidy:</strong> The <code>Tidy</code> extension is not available. <?php echo $app_name; ?> should still work with most feeds, but you may experience problems with some.</li>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($curl_ok): ?>
|
||||||
|
<li><strong>cURL:</strong> You have <code>cURL</code> support installed. <em>No problems here.</em></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li><strong>cURL:</strong> The <code>cURL</code> extension is not available. SimplePie will use <code>fsockopen()</code> instead.</li>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($http_ok): ?>
|
||||||
|
<li><strong>HttpRequestPool:</strong> You have <code>HttpRequestPool</code> support installed. <em>No problems here.</em></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li><strong>HttpRequestPool:</strong> The <code>HttpRequestPool</code> class is not available. <?php echo $app_name; ?> will use <code>file_get_contents()</code> instead to fetch URLs sequentially rather than in parallel.</li>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($redirect_ok): ?>
|
||||||
|
<li><strong>HTTP Redirects:</strong> Your server appears to handle redirects ok. <em>No problems here.</em></li>
|
||||||
|
<?php else: ?>
|
||||||
|
<li><strong>HTTP Redirects:</strong> Your server appears not to be able to handle HTTP redirects. <?php echo $app_name; ?> should still work with most feeds, but you may experience problems with some.</li>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php else: ?>
|
||||||
|
<li><strong>allow_url_fopen:</strong> Your PHP configuration has allow_url_fopen disabled. <em><?php echo $app_name; ?> will not work here.</em></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php else: ?>
|
||||||
|
<li><strong>PCRE:</strong> Your PHP installation doesn't support Perl-Compatible Regular Expressions. <em><?php echo $app_name; ?> will not work here.</em></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<li><strong>XML:</strong> Your PHP installation doesn't support XML parsing. <em><?php echo $app_name; ?> will not work here.</em></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php else: ?>
|
||||||
|
<li><strong>PHP:</strong> You are running an unsupported version of PHP. <em><?php echo $app_name; ?> will not work here.</em></li>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chunk">
|
||||||
|
<?php if ($php_ok && $xml_ok && $pcre_ok && $mbstring_ok && $iconv_ok && $allow_url_fopen_ok) { ?>
|
||||||
|
<h3>Bottom Line: Yes, you can!</h3>
|
||||||
|
<p><em>Your webhost has its act together!</em></p>
|
||||||
|
<p>You can download the latest version of <?php echo $app_name; ?> from <a href="http://fivefilters.org/content-only/#download">FiveFilters.org</a>.</p>
|
||||||
|
<p><strong>Note</strong>: Passing this test does not guarantee that <?php echo $app_name; ?> will run on your webhost — it only ensures that the basic requirements have been addressed. If you experience any problems, please let us know.</p>
|
||||||
|
<?php } else if ($php_ok && $xml_ok && $pcre_ok && $allow_url_fopen_ok) { ?>
|
||||||
|
<h3>Bottom Line: Yes, you can!</h3>
|
||||||
|
<p><em>For most feeds, it'll run with no problems.</em> There are certain languages that you might have a hard time with though.</p>
|
||||||
|
<p>You can download the latest version of <?php echo $app_name; ?> from <a href="http://fivefilters.org/content-only/#download">FiveFilters.org</a>.</p>
|
||||||
|
<p><strong>Note</strong>: Passing this test does not guarantee that <?php echo $app_name; ?> will run on your webhost — it only ensures that the basic requirements have been addressed. If you experience any problems, please let us know.</p>
|
||||||
|
<?php } else { ?>
|
||||||
|
<h3>Bottom Line: We're sorry…</h3>
|
||||||
|
<p><em>Your webhost does not support the minimum requirements for <?php echo $app_name; ?>.</em> It may be a good idea to contact your webhost, and ask them to install a more recent version of PHP as well as the <code>xmlreader</code>, <code>xml</code>, <code>mbstring</code>, <code>iconv</code>, <code>curl</code>, and <code>zlib</code> extensions. And ask them to enable allow_url_fopen.</p>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chunk">
|
||||||
|
<p class="footnote">This compatibility test has been borrowed (and slightly adapted) from the one supplied by <a href="http://simplepie.org/">SimplePie.org</a>. We have kept most of their checks intact as we use SimplePie in our application.</a></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
BIN
images/agplv3.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
images/background.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
images/icon_feed.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
images/niceforms/0.png
Normal file
After Width: | Height: | Size: 110 B |
BIN
images/niceforms/button-left.png
Normal file
After Width: | Height: | Size: 661 B |
BIN
images/niceforms/button-right.png
Normal file
After Width: | Height: | Size: 711 B |
BIN
images/niceforms/button.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
images/niceforms/checkbox.png
Normal file
After Width: | Height: | Size: 701 B |
BIN
images/niceforms/file.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
images/niceforms/input-left.png
Normal file
After Width: | Height: | Size: 578 B |
BIN
images/niceforms/input-right.png
Normal file
After Width: | Height: | Size: 581 B |
BIN
images/niceforms/input.png
Normal file
After Width: | Height: | Size: 260 B |
BIN
images/niceforms/radio.png
Normal file
After Width: | Height: | Size: 1013 B |
BIN
images/niceforms/select-left.png
Normal file
After Width: | Height: | Size: 263 B |
BIN
images/niceforms/select-right.png
Normal file
After Width: | Height: | Size: 869 B |
BIN
images/niceforms/textarea-bl.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
images/niceforms/textarea-br.png
Normal file
After Width: | Height: | Size: 488 B |
BIN
images/niceforms/textarea-l-off.png
Normal file
After Width: | Height: | Size: 168 B |
BIN
images/niceforms/textarea-l-over.png
Normal file
After Width: | Height: | Size: 167 B |
BIN
images/niceforms/textarea-r-off.png
Normal file
After Width: | Height: | Size: 266 B |
BIN
images/niceforms/textarea-r-over.png
Normal file
After Width: | Height: | Size: 270 B |
BIN
images/niceforms/textarea-tl.png
Normal file
After Width: | Height: | Size: 269 B |
BIN
images/niceforms/textarea-tr.png
Normal file
After Width: | Height: | Size: 488 B |
BIN
images/tekzilla.jpg
Normal file
After Width: | Height: | Size: 57 KiB |
BIN
images/title.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
144
index.html
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<title>Full-Text RSS Feeds | from fivefilters.org</title>
|
||||||
|
<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.3.2/jquery.min.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var baseUrl = 'http://'+window.location.host+window.location.pathname.replace(/(\/index\.html|\/)$/, '');
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body style="background-color: #eee; margin: 0; line-height: 1.4em;">
|
||||||
|
<div id="container">
|
||||||
|
<h1 style="padding-bottom: 30px;">Create Full-Text Feeds <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">
|
||||||
|
<fieldset>
|
||||||
|
<legend>Create full-text feed from webpage or feed URL</legend>
|
||||||
|
<dl>
|
||||||
|
<dt><label for="url">Enter URL:</label></dt>
|
||||||
|
<dd><input type="text" id="url" name="url" style="width: 450px" /></dd>
|
||||||
|
</dl>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Options</legend>
|
||||||
|
<!-- Remove the comments below to include API key field -->
|
||||||
|
<!--
|
||||||
|
<dl>
|
||||||
|
<dt><label for="key">API key:</label></dt>
|
||||||
|
<dd><input type="text" id="key" name="key" /></dd>
|
||||||
|
</dl>
|
||||||
|
-->
|
||||||
|
<dl>
|
||||||
|
<dt><label for="max">Max items:</label></dt>
|
||||||
|
<dd><select name="max" id="max">
|
||||||
|
<option value="1">1</option>
|
||||||
|
<option value="2">2</option>
|
||||||
|
<option value="3">3</option>
|
||||||
|
<option value="4">4</option>
|
||||||
|
<option value="5" selected="selected">5</option>
|
||||||
|
<option value="6">6</option>
|
||||||
|
<option value="7">7</option>
|
||||||
|
<option value="8">8</option>
|
||||||
|
<option value="9">9</option>
|
||||||
|
<option value="10">10</option>
|
||||||
|
</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>
|
||||||
|
</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>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>For the site owner</h2>
|
||||||
|
|
||||||
|
<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.</p>
|
||||||
|
<p>If everything's okay, feel free to edit this file (index.html) and make any changes you like. If you plan
|
||||||
|
to offer this service to others, 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).
|
||||||
|
That's one requirement of the license.</p>
|
||||||
|
<p>Thanks! :)</p>
|
||||||
|
|
||||||
|
<h2>For everyone else</h2>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<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.
|
||||||
|
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=\'+escape(document.location.href);">Full-Text RSS</a>');
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h3 id="api">API</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>If you have an API key, add that to the querystring:</p>
|
||||||
|
<ul>
|
||||||
|
<li style="font-family: monospace; white-space:nowrap;"><script type="text/javascript">document.write(baseUrl);</script>/makefulltextfeed.php?key=<strong>[key]</strong>&url=<strong>[url]</strong></li>
|
||||||
|
<li style="font-family: monospace; white-space:nowrap;"><script type="text/javascript">document.write(baseUrl);</script>/makefulltextfeed.php?key=<strong>[key]</strong>&max=<strong>[number of feed items]</strong>&url=<strong>[url]</strong></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>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><a href="https://code.launchpad.net/~keyvan/fivefilters/content-only">Source code available on launchpad.net</a>.</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, <a href="http://framework.zend.com/manual/en/zend.cache.introduction.html">Zend Cache</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>System Requirements</h3>
|
||||||
|
|
||||||
|
<p>PHP 5.2 or above is required.
|
||||||
|
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>.</p>
|
||||||
|
|
||||||
|
<h3 id="download">Download and Installation</h3>
|
||||||
|
<p>The software can be downloaded free of charge through launchpad.net using a Bazaar client (see below).
|
||||||
|
However, for those who'd like a simpler solution, you can also <a href="http://fivefilters.org/content-only/#download">buy a zip package</a> with the
|
||||||
|
source code.</p>
|
||||||
|
|
||||||
|
<h3>Installation with the Bazaar client</h3>
|
||||||
|
|
||||||
|
<ol style="width: 800px">
|
||||||
|
<li>Log in to your host using SSH</li>
|
||||||
|
<li>Change to the directory where you want Full-Text RSS installed</li>
|
||||||
|
<li>Enter <kbd>bzr export full-text-rss http://bazaar.launchpad.net/~keyvan/fivefilters/content-only/</kbd></li>
|
||||||
|
<li>Now enter <kbd>chmod -R 0777 full-text-rss/cache/</kbd></li>
|
||||||
|
<li><strong>That's it!</strong> Try accessing the full-text-rss folder through your web browser, you should see the form asking for a URL.</li>
|
||||||
|
<li>(Optional) If you'd like to customise the software, rename config-sample.php to config.php and edit the file.</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<p>If you'd like to create a feed without going through the form first, you can simply pass the URL in the query string to makefulltextfeed.php (see the <a href="#api">API section</a> above).</p>
|
||||||
|
|
||||||
|
<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 do the same 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>
|
||||||
|
<ul>
|
||||||
|
<li>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 Cache: <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>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3 id="donate">Donate</h3>
|
||||||
|
<p>To support the development of the Full-Text RSS project, please <a href="http://fivefilters.org/content-only/#donate">donate</a>. All donations greatly appreciated.</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
19
js/jquery-1.3.2.min.js
vendored
Normal file
576
js/niceforms.js
Normal file
@ -0,0 +1,576 @@
|
|||||||
|
/*#############################################################
|
||||||
|
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;
|
||||||
|
}
|
250
libraries/Zend/Cache.php
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Cache.php 21974 2010-04-23 17:10:17Z alexander $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
abstract class Zend_Cache
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Standard frontends
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $standardFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Standard backends
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $standardBackends = array('File', 'Sqlite', 'Memcached', 'Apc', 'ZendPlatform',
|
||||||
|
'Xcache', 'TwoLevels', 'ZendServer_Disk', 'ZendServer_ShMem');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Standard backends which implement the ExtendedInterface
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Sqlite');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only for backward compatibily (may be removed in next major release)
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public static $availableFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only for backward compatibily (may be removed in next major release)
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Apc', 'ZendPlatform', 'Xcache', 'TwoLevels');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consts for clean() method
|
||||||
|
*/
|
||||||
|
const CLEANING_MODE_ALL = 'all';
|
||||||
|
const CLEANING_MODE_OLD = 'old';
|
||||||
|
const CLEANING_MODE_MATCHING_TAG = 'matchingTag';
|
||||||
|
const CLEANING_MODE_NOT_MATCHING_TAG = 'notMatchingTag';
|
||||||
|
const CLEANING_MODE_MATCHING_ANY_TAG = 'matchingAnyTag';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory
|
||||||
|
*
|
||||||
|
* @param mixed $frontend frontend name (string) or Zend_Cache_Frontend_ object
|
||||||
|
* @param mixed $backend backend name (string) or Zend_Cache_Backend_ object
|
||||||
|
* @param array $frontendOptions associative array of options for the corresponding frontend constructor
|
||||||
|
* @param array $backendOptions associative array of options for the corresponding backend constructor
|
||||||
|
* @param boolean $customFrontendNaming if true, the frontend argument is used as a complete class name ; if false, the frontend argument is used as the end of "Zend_Cache_Frontend_[...]" class name
|
||||||
|
* @param boolean $customBackendNaming if true, the backend argument is used as a complete class name ; if false, the backend argument is used as the end of "Zend_Cache_Backend_[...]" class name
|
||||||
|
* @param boolean $autoload if true, there will no require_once for backend and frontend (usefull only for custom backends/frontends)
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return Zend_Cache_Core|Zend_Cache_Frontend
|
||||||
|
*/
|
||||||
|
public static function factory($frontend, $backend, $frontendOptions = array(), $backendOptions = array(), $customFrontendNaming = false, $customBackendNaming = false, $autoload = false)
|
||||||
|
{
|
||||||
|
if (is_string($backend)) {
|
||||||
|
$backendObject = self::_makeBackend($backend, $backendOptions, $customBackendNaming, $autoload);
|
||||||
|
} else {
|
||||||
|
if ((is_object($backend)) && (in_array('Zend_Cache_Backend_Interface', class_implements($backend)))) {
|
||||||
|
$backendObject = $backend;
|
||||||
|
} else {
|
||||||
|
self::throwException('backend must be a backend name (string) or an object which implements Zend_Cache_Backend_Interface');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_string($frontend)) {
|
||||||
|
$frontendObject = self::_makeFrontend($frontend, $frontendOptions, $customFrontendNaming, $autoload);
|
||||||
|
} else {
|
||||||
|
if (is_object($frontend)) {
|
||||||
|
$frontendObject = $frontend;
|
||||||
|
} else {
|
||||||
|
self::throwException('frontend must be a frontend name (string) or an object');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$frontendObject->setBackend($backendObject);
|
||||||
|
return $frontendObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frontend Constructor
|
||||||
|
*
|
||||||
|
* @param string $backend
|
||||||
|
* @param array $backendOptions
|
||||||
|
* @param boolean $customBackendNaming
|
||||||
|
* @param boolean $autoload
|
||||||
|
* @return Zend_Cache_Backend
|
||||||
|
*/
|
||||||
|
public static function _makeBackend($backend, $backendOptions, $customBackendNaming = false, $autoload = false)
|
||||||
|
{
|
||||||
|
if (!$customBackendNaming) {
|
||||||
|
$backend = self::_normalizeName($backend);
|
||||||
|
}
|
||||||
|
if (in_array($backend, Zend_Cache::$standardBackends)) {
|
||||||
|
// we use a standard backend
|
||||||
|
$backendClass = 'Zend_Cache_Backend_' . $backend;
|
||||||
|
// security controls are explicit
|
||||||
|
require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
|
||||||
|
} else {
|
||||||
|
// we use a custom backend
|
||||||
|
if (!preg_match('~^[\w]+$~D', $backend)) {
|
||||||
|
Zend_Cache::throwException("Invalid backend name [$backend]");
|
||||||
|
}
|
||||||
|
if (!$customBackendNaming) {
|
||||||
|
// we use this boolean to avoid an API break
|
||||||
|
$backendClass = 'Zend_Cache_Backend_' . $backend;
|
||||||
|
} else {
|
||||||
|
$backendClass = $backend;
|
||||||
|
}
|
||||||
|
if (!$autoload) {
|
||||||
|
$file = str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
|
||||||
|
if (!(self::_isReadable($file))) {
|
||||||
|
self::throwException("file $file not found in include_path");
|
||||||
|
}
|
||||||
|
require_once $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new $backendClass($backendOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backend Constructor
|
||||||
|
*
|
||||||
|
* @param string $frontend
|
||||||
|
* @param array $frontendOptions
|
||||||
|
* @param boolean $customFrontendNaming
|
||||||
|
* @param boolean $autoload
|
||||||
|
* @return Zend_Cache_Core|Zend_Cache_Frontend
|
||||||
|
*/
|
||||||
|
public static function _makeFrontend($frontend, $frontendOptions = array(), $customFrontendNaming = false, $autoload = false)
|
||||||
|
{
|
||||||
|
if (!$customFrontendNaming) {
|
||||||
|
$frontend = self::_normalizeName($frontend);
|
||||||
|
}
|
||||||
|
if (in_array($frontend, self::$standardFrontends)) {
|
||||||
|
// we use a standard frontend
|
||||||
|
// For perfs reasons, with frontend == 'Core', we can interact with the Core itself
|
||||||
|
$frontendClass = 'Zend_Cache_' . ($frontend != 'Core' ? 'Frontend_' : '') . $frontend;
|
||||||
|
// security controls are explicit
|
||||||
|
require_once str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php';
|
||||||
|
} else {
|
||||||
|
// we use a custom frontend
|
||||||
|
if (!preg_match('~^[\w]+$~D', $frontend)) {
|
||||||
|
Zend_Cache::throwException("Invalid frontend name [$frontend]");
|
||||||
|
}
|
||||||
|
if (!$customFrontendNaming) {
|
||||||
|
// we use this boolean to avoid an API break
|
||||||
|
$frontendClass = 'Zend_Cache_Frontend_' . $frontend;
|
||||||
|
} else {
|
||||||
|
$frontendClass = $frontend;
|
||||||
|
}
|
||||||
|
if (!$autoload) {
|
||||||
|
$file = str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php';
|
||||||
|
if (!(self::_isReadable($file))) {
|
||||||
|
self::throwException("file $file not found in include_path");
|
||||||
|
}
|
||||||
|
require_once $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new $frontendClass($frontendOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throw an exception
|
||||||
|
*
|
||||||
|
* Note : for perf reasons, the "load" of Zend/Cache/Exception is dynamic
|
||||||
|
* @param string $msg Message for the exception
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
*/
|
||||||
|
public static function throwException($msg, Exception $e = null)
|
||||||
|
{
|
||||||
|
// For perfs reasons, we use this dynamic inclusion
|
||||||
|
require_once 'Zend/Cache/Exception.php';
|
||||||
|
throw new Zend_Cache_Exception($msg, 0, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize frontend and backend names to allow multiple words TitleCased
|
||||||
|
*
|
||||||
|
* @param string $name Name to normalize
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function _normalizeName($name)
|
||||||
|
{
|
||||||
|
$name = ucfirst(strtolower($name));
|
||||||
|
$name = str_replace(array('-', '_', '.'), ' ', $name);
|
||||||
|
$name = ucwords($name);
|
||||||
|
$name = str_replace(' ', '', $name);
|
||||||
|
if (stripos($name, 'ZendServer') === 0) {
|
||||||
|
$name = 'ZendServer_' . substr($name, strlen('ZendServer'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if the $filename is readable, or FALSE otherwise.
|
||||||
|
* This function uses the PHP include_path, where PHP's is_readable()
|
||||||
|
* does not.
|
||||||
|
*
|
||||||
|
* Note : this method comes from Zend_Loader (see #ZF-2891 for details)
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private static function _isReadable($filename)
|
||||||
|
{
|
||||||
|
if (!$fh = @fopen($filename, 'r', true)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@fclose($fh);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
266
libraries/Zend/Cache/Backend.php
Normal file
@ -0,0 +1,266 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Backend.php 20882 2010-02-03 18:19:44Z matthew $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Backend
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Frontend or Core directives
|
||||||
|
*
|
||||||
|
* =====> (int) lifetime :
|
||||||
|
* - Cache lifetime (in seconds)
|
||||||
|
* - If null, the cache is valid forever
|
||||||
|
*
|
||||||
|
* =====> (int) logging :
|
||||||
|
* - if set to true, a logging is activated throw Zend_Log
|
||||||
|
*
|
||||||
|
* @var array directives
|
||||||
|
*/
|
||||||
|
protected $_directives = array(
|
||||||
|
'lifetime' => 3600,
|
||||||
|
'logging' => false,
|
||||||
|
'logger' => null
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available options
|
||||||
|
*
|
||||||
|
* @var array available options
|
||||||
|
*/
|
||||||
|
protected $_options = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options Associative array of options
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
while (list($name, $value) = each($options)) {
|
||||||
|
$this->setOption($name, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the frontend directives
|
||||||
|
*
|
||||||
|
* @param array $directives Assoc of directives
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setDirectives($directives)
|
||||||
|
{
|
||||||
|
if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array');
|
||||||
|
while (list($name, $value) = each($directives)) {
|
||||||
|
if (!is_string($name)) {
|
||||||
|
Zend_Cache::throwException("Incorrect option name : $name");
|
||||||
|
}
|
||||||
|
$name = strtolower($name);
|
||||||
|
if (array_key_exists($name, $this->_directives)) {
|
||||||
|
$this->_directives[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_loggerSanity();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an option
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param mixed $value
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setOption($name, $value)
|
||||||
|
{
|
||||||
|
if (!is_string($name)) {
|
||||||
|
Zend_Cache::throwException("Incorrect option name : $name");
|
||||||
|
}
|
||||||
|
$name = strtolower($name);
|
||||||
|
if (array_key_exists($name, $this->_options)) {
|
||||||
|
$this->_options[$name] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the life time
|
||||||
|
*
|
||||||
|
* if $specificLifetime is not false, the given specific life time is used
|
||||||
|
* else, the global lifetime is used
|
||||||
|
*
|
||||||
|
* @param int $specificLifetime
|
||||||
|
* @return int Cache life time
|
||||||
|
*/
|
||||||
|
public function getLifetime($specificLifetime)
|
||||||
|
{
|
||||||
|
if ($specificLifetime === false) {
|
||||||
|
return $this->_directives['lifetime'];
|
||||||
|
}
|
||||||
|
return $specificLifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the automatic cleaning is available for the backend
|
||||||
|
*
|
||||||
|
* DEPRECATED : use getCapabilities() instead
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isAutomaticCleaningAvailable()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine system TMP directory and detect if we have read access
|
||||||
|
*
|
||||||
|
* inspired from Zend_File_Transfer_Adapter_Abstract
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws Zend_Cache_Exception if unable to determine directory
|
||||||
|
*/
|
||||||
|
public function getTmpDir()
|
||||||
|
{
|
||||||
|
$tmpdir = array();
|
||||||
|
foreach (array($_ENV, $_SERVER) as $tab) {
|
||||||
|
foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
|
||||||
|
if (isset($tab[$key])) {
|
||||||
|
if (($key == 'windir') or ($key == 'SystemRoot')) {
|
||||||
|
$dir = realpath($tab[$key] . '\\temp');
|
||||||
|
} else {
|
||||||
|
$dir = realpath($tab[$key]);
|
||||||
|
}
|
||||||
|
if ($this->_isGoodTmpDir($dir)) {
|
||||||
|
return $dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$upload = ini_get('upload_tmp_dir');
|
||||||
|
if ($upload) {
|
||||||
|
$dir = realpath($upload);
|
||||||
|
if ($this->_isGoodTmpDir($dir)) {
|
||||||
|
return $dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (function_exists('sys_get_temp_dir')) {
|
||||||
|
$dir = sys_get_temp_dir();
|
||||||
|
if ($this->_isGoodTmpDir($dir)) {
|
||||||
|
return $dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Attemp to detect by creating a temporary file
|
||||||
|
$tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
|
||||||
|
if ($tempFile) {
|
||||||
|
$dir = realpath(dirname($tempFile));
|
||||||
|
unlink($tempFile);
|
||||||
|
if ($this->_isGoodTmpDir($dir)) {
|
||||||
|
return $dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->_isGoodTmpDir('/tmp')) {
|
||||||
|
return '/tmp';
|
||||||
|
}
|
||||||
|
if ($this->_isGoodTmpDir('\\temp')) {
|
||||||
|
return '\\temp';
|
||||||
|
}
|
||||||
|
Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify if the given temporary directory is readable and writable
|
||||||
|
*
|
||||||
|
* @param $dir temporary directory
|
||||||
|
* @return boolean true if the directory is ok
|
||||||
|
*/
|
||||||
|
protected function _isGoodTmpDir($dir)
|
||||||
|
{
|
||||||
|
if (is_readable($dir)) {
|
||||||
|
if (is_writable($dir)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure if we enable logging that the Zend_Log class
|
||||||
|
* is available.
|
||||||
|
* Create a default log object if none is set.
|
||||||
|
*
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _loggerSanity()
|
||||||
|
{
|
||||||
|
if (!isset($this->_directives['logging']) || !$this->_directives['logging']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->_directives['logger'])) {
|
||||||
|
if ($this->_directives['logger'] instanceof Zend_Log) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a default logger to the standard output stream
|
||||||
|
require_once 'Zend/Log.php';
|
||||||
|
require_once 'Zend/Log/Writer/Stream.php';
|
||||||
|
$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
|
||||||
|
$this->_directives['logger'] = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a message at the WARN (4) priority.
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _log($message, $priority = 4)
|
||||||
|
{
|
||||||
|
if (!$this->_directives['logging']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($this->_directives['logger'])) {
|
||||||
|
Zend_Cache::throwException('Logging is enabled but logger is not set.');
|
||||||
|
}
|
||||||
|
$logger = $this->_directives['logger'];
|
||||||
|
if (!$logger instanceof Zend_Log) {
|
||||||
|
Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
|
||||||
|
}
|
||||||
|
$logger->log($message, $priority);
|
||||||
|
}
|
||||||
|
}
|
355
libraries/Zend/Cache/Backend/Apc.php
Normal file
@ -0,0 +1,355 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Apc.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend_Interface
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Log message
|
||||||
|
*/
|
||||||
|
const TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::clean() : tags are unsupported by the Apc backend';
|
||||||
|
const TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::save() : tags are unsupported by the Apc backend';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options associative array of options
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
if (!extension_loaded('apc')) {
|
||||||
|
Zend_Cache::throwException('The apc extension must be loaded for using this backend !');
|
||||||
|
}
|
||||||
|
parent::__construct($options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* WARNING $doNotTestCacheValidity=true is unsupported by the Apc backend
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||||
|
* @return string cached datas (or false)
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false)
|
||||||
|
{
|
||||||
|
$tmp = apc_fetch($id);
|
||||||
|
if (is_array($tmp)) {
|
||||||
|
return $tmp[0];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available or not (for the given id)
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
$tmp = apc_fetch($id);
|
||||||
|
if (is_array($tmp)) {
|
||||||
|
return $tmp[1];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some string datas into a cache record
|
||||||
|
*
|
||||||
|
* Note : $data is always "string" (serialization is done by the
|
||||||
|
* core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $data datas to cache
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||||
|
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||||
|
{
|
||||||
|
$lifetime = $this->getLifetime($specificLifetime);
|
||||||
|
$result = apc_store($id, array($data, time(), $lifetime), $lifetime);
|
||||||
|
if (count($tags) > 0) {
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function remove($id)
|
||||||
|
{
|
||||||
|
return apc_delete($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||||
|
* 'old' => unsupported
|
||||||
|
* 'matchingTag' => unsupported
|
||||||
|
* 'notMatchingTag' => unsupported
|
||||||
|
* 'matchingAnyTag' => unsupported
|
||||||
|
*
|
||||||
|
* @param string $mode clean mode
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||||
|
{
|
||||||
|
switch ($mode) {
|
||||||
|
case Zend_Cache::CLEANING_MODE_ALL:
|
||||||
|
return apc_clear_cache('user');
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_OLD:
|
||||||
|
$this->_log("Zend_Cache_Backend_Apc::clean() : CLEANING_MODE_OLD is unsupported by the Apc backend");
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||||
|
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the automatic cleaning is available for the backend
|
||||||
|
*
|
||||||
|
* DEPRECATED : use getCapabilities() instead
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isAutomaticCleaningAvailable()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the filling percentage of the backend storage
|
||||||
|
*
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return int integer between 0 and 100
|
||||||
|
*/
|
||||||
|
public function getFillingPercentage()
|
||||||
|
{
|
||||||
|
$mem = apc_sma_info(true);
|
||||||
|
$memSize = $mem['num_seg'] * $mem['seg_size'];
|
||||||
|
$memAvailable= $mem['avail_mem'];
|
||||||
|
$memUsed = $memSize - $memAvailable;
|
||||||
|
if ($memSize == 0) {
|
||||||
|
Zend_Cache::throwException('can\'t get apc memory size');
|
||||||
|
}
|
||||||
|
if ($memUsed > $memSize) {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
return ((int) (100. * ($memUsed / $memSize)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored tags
|
||||||
|
*
|
||||||
|
* @return array array of stored tags (string)
|
||||||
|
*/
|
||||||
|
public function getTags()
|
||||||
|
{
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which don't match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical OR is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of not matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsNotMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match any given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of any matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingAnyTags($tags = array())
|
||||||
|
{
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids
|
||||||
|
*
|
||||||
|
* @return array array of stored cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIds()
|
||||||
|
{
|
||||||
|
$res = array();
|
||||||
|
$array = apc_cache_info('user', false);
|
||||||
|
$records = $array['cache_list'];
|
||||||
|
foreach ($records as $record) {
|
||||||
|
$res[] = $record['info'];
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of metadatas for the given cache id
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - expire : the expire timestamp
|
||||||
|
* - tags : a string array of tags
|
||||||
|
* - mtime : timestamp of last modification time
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return array array of metadatas (false if the cache id is not found)
|
||||||
|
*/
|
||||||
|
public function getMetadatas($id)
|
||||||
|
{
|
||||||
|
$tmp = apc_fetch($id);
|
||||||
|
if (is_array($tmp)) {
|
||||||
|
$data = $tmp[0];
|
||||||
|
$mtime = $tmp[1];
|
||||||
|
if (!isset($tmp[2])) {
|
||||||
|
// because this record is only with 1.7 release
|
||||||
|
// if old cache records are still there...
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$lifetime = $tmp[2];
|
||||||
|
return array(
|
||||||
|
'expire' => $mtime + $lifetime,
|
||||||
|
'tags' => array(),
|
||||||
|
'mtime' => $mtime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give (if possible) an extra lifetime to the given cache id
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param int $extraLifetime
|
||||||
|
* @return boolean true if ok
|
||||||
|
*/
|
||||||
|
public function touch($id, $extraLifetime)
|
||||||
|
{
|
||||||
|
$tmp = apc_fetch($id);
|
||||||
|
if (is_array($tmp)) {
|
||||||
|
$data = $tmp[0];
|
||||||
|
$mtime = $tmp[1];
|
||||||
|
if (!isset($tmp[2])) {
|
||||||
|
// because this record is only with 1.7 release
|
||||||
|
// if old cache records are still there...
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$lifetime = $tmp[2];
|
||||||
|
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||||
|
if ($newLifetime <=0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
apc_store($id, array($data, time(), $newLifetime), $newLifetime);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an associative array of capabilities (booleans) of the backend
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - automatic_cleaning (is automating cleaning necessary)
|
||||||
|
* - tags (are tags supported)
|
||||||
|
* - expired_read (is it possible to read expired cache records
|
||||||
|
* (for doNotTestCacheValidity option for example))
|
||||||
|
* - priority does the backend deal with priority when saving
|
||||||
|
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||||
|
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||||
|
*
|
||||||
|
* @return array associative of with capabilities
|
||||||
|
*/
|
||||||
|
public function getCapabilities()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'automatic_cleaning' => false,
|
||||||
|
'tags' => false,
|
||||||
|
'expired_read' => false,
|
||||||
|
'priority' => false,
|
||||||
|
'infinite_lifetime' => false,
|
||||||
|
'get_list' => true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
250
libraries/Zend/Cache/Backend/BlackHole.php
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: BlackHole.php 17867 2009-08-28 09:42:11Z yoshida@zend.co.jp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend_Interface
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Backend_BlackHole
|
||||||
|
extends Zend_Cache_Backend
|
||||||
|
implements Zend_Cache_Backend_ExtendedInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||||
|
* @return string|false cached datas
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available or not (for the given id)
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some string datas into a cache record
|
||||||
|
*
|
||||||
|
* Note : $data is always "string" (serialization is done by the
|
||||||
|
* core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $data Datas to cache
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||||
|
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function remove($id)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||||
|
* 'old' => remove too old cache entries ($tags is not used)
|
||||||
|
* 'matchingTag' => remove cache entries matching all given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* 'notMatchingTag' => remove cache entries not matching one of the given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* 'matchingAnyTag' => remove cache entries matching any given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
*
|
||||||
|
* @param string $mode clean mode
|
||||||
|
* @param tags array $tags array of tags
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids
|
||||||
|
*
|
||||||
|
* @return array array of stored cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIds()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored tags
|
||||||
|
*
|
||||||
|
* @return array array of stored tags (string)
|
||||||
|
*/
|
||||||
|
public function getTags()
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which don't match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical OR is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of not matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsNotMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match any given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of any matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingAnyTags($tags = array())
|
||||||
|
{
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the filling percentage of the backend storage
|
||||||
|
*
|
||||||
|
* @return int integer between 0 and 100
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
*/
|
||||||
|
public function getFillingPercentage()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of metadatas for the given cache id
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - expire : the expire timestamp
|
||||||
|
* - tags : a string array of tags
|
||||||
|
* - mtime : timestamp of last modification time
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return array array of metadatas (false if the cache id is not found)
|
||||||
|
*/
|
||||||
|
public function getMetadatas($id)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give (if possible) an extra lifetime to the given cache id
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param int $extraLifetime
|
||||||
|
* @return boolean true if ok
|
||||||
|
*/
|
||||||
|
public function touch($id, $extraLifetime)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an associative array of capabilities (booleans) of the backend
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - automatic_cleaning (is automating cleaning necessary)
|
||||||
|
* - tags (are tags supported)
|
||||||
|
* - expired_read (is it possible to read expired cache records
|
||||||
|
* (for doNotTestCacheValidity option for example))
|
||||||
|
* - priority does the backend deal with priority when saving
|
||||||
|
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||||
|
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||||
|
*
|
||||||
|
* @return array associative of with capabilities
|
||||||
|
*/
|
||||||
|
public function getCapabilities()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'automatic_cleaning' => true,
|
||||||
|
'tags' => true,
|
||||||
|
'expired_read' => true,
|
||||||
|
'priority' => true,
|
||||||
|
'infinite_lifetime' => true,
|
||||||
|
'get_list' => true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUBLIC METHOD FOR UNIT TESTING ONLY !
|
||||||
|
*
|
||||||
|
* Force a cache record to expire
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
*/
|
||||||
|
public function ___expire($id)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
126
libraries/Zend/Cache/Backend/ExtendedInterface.php
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: ExtendedInterface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend_Interface
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend/Interface.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interface
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids
|
||||||
|
*
|
||||||
|
* @return array array of stored cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIds();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored tags
|
||||||
|
*
|
||||||
|
* @return array array of stored tags (string)
|
||||||
|
*/
|
||||||
|
public function getTags();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingTags($tags = array());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which don't match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical OR is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of not matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsNotMatchingTags($tags = array());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match any given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of any matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingAnyTags($tags = array());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the filling percentage of the backend storage
|
||||||
|
*
|
||||||
|
* @return int integer between 0 and 100
|
||||||
|
*/
|
||||||
|
public function getFillingPercentage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of metadatas for the given cache id
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - expire : the expire timestamp
|
||||||
|
* - tags : a string array of tags
|
||||||
|
* - mtime : timestamp of last modification time
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return array array of metadatas (false if the cache id is not found)
|
||||||
|
*/
|
||||||
|
public function getMetadatas($id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give (if possible) an extra lifetime to the given cache id
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param int $extraLifetime
|
||||||
|
* @return boolean true if ok
|
||||||
|
*/
|
||||||
|
public function touch($id, $extraLifetime);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an associative array of capabilities (booleans) of the backend
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - automatic_cleaning (is automating cleaning necessary)
|
||||||
|
* - tags (are tags supported)
|
||||||
|
* - expired_read (is it possible to read expired cache records
|
||||||
|
* (for doNotTestCacheValidity option for example))
|
||||||
|
* - priority does the backend deal with priority when saving
|
||||||
|
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||||
|
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||||
|
*
|
||||||
|
* @return array associative of with capabilities
|
||||||
|
*/
|
||||||
|
public function getCapabilities();
|
||||||
|
|
||||||
|
}
|
1006
libraries/Zend/Cache/Backend/File.php
Normal file
99
libraries/Zend/Cache/Backend/Interface.php
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Interface.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
interface Zend_Cache_Backend_Interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Set the frontend directives
|
||||||
|
*
|
||||||
|
* @param array $directives assoc of directives
|
||||||
|
*/
|
||||||
|
public function setDirectives($directives);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||||
|
* @return string|false cached datas
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available or not (for the given id)
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||||
|
*/
|
||||||
|
public function test($id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some string datas into a cache record
|
||||||
|
*
|
||||||
|
* Note : $data is always "string" (serialization is done by the
|
||||||
|
* core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $data Datas to cache
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||||
|
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id, $tags = array(), $specificLifetime = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function remove($id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
*
|
||||||
|
* @param string $mode Clean mode
|
||||||
|
* @param array $tags Array of tags
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array());
|
||||||
|
|
||||||
|
}
|
504
libraries/Zend/Cache/Backend/Memcached.php
Normal file
@ -0,0 +1,504 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Memcached.php 22208 2010-05-20 16:59:02Z mabe $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend_Interface
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Default Values
|
||||||
|
*/
|
||||||
|
const DEFAULT_HOST = '127.0.0.1';
|
||||||
|
const DEFAULT_PORT = 11211;
|
||||||
|
const DEFAULT_PERSISTENT = true;
|
||||||
|
const DEFAULT_WEIGHT = 1;
|
||||||
|
const DEFAULT_TIMEOUT = 1;
|
||||||
|
const DEFAULT_RETRY_INTERVAL = 15;
|
||||||
|
const DEFAULT_STATUS = true;
|
||||||
|
const DEFAULT_FAILURE_CALLBACK = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log message
|
||||||
|
*/
|
||||||
|
const TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::clean() : tags are unsupported by the Memcached backend';
|
||||||
|
const TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available options
|
||||||
|
*
|
||||||
|
* =====> (array) servers :
|
||||||
|
* an array of memcached server ; each memcached server is described by an associative array :
|
||||||
|
* 'host' => (string) : the name of the memcached server
|
||||||
|
* 'port' => (int) : the port of the memcached server
|
||||||
|
* 'persistent' => (bool) : use or not persistent connections to this memcached server
|
||||||
|
* 'weight' => (int) : number of buckets to create for this server which in turn control its
|
||||||
|
* probability of it being selected. The probability is relative to the total
|
||||||
|
* weight of all servers.
|
||||||
|
* 'timeout' => (int) : value in seconds which will be used for connecting to the daemon. Think twice
|
||||||
|
* before changing the default value of 1 second - you can lose all the
|
||||||
|
* advantages of caching if your connection is too slow.
|
||||||
|
* 'retry_interval' => (int) : controls how often a failed server will be retried, the default value
|
||||||
|
* is 15 seconds. Setting this parameter to -1 disables automatic retry.
|
||||||
|
* 'status' => (bool) : controls if the server should be flagged as online.
|
||||||
|
* 'failure_callback' => (callback) : Allows the user to specify a callback function to run upon
|
||||||
|
* encountering an error. The callback is run before failover
|
||||||
|
* is attempted. The function takes two parameters, the hostname
|
||||||
|
* and port of the failed server.
|
||||||
|
*
|
||||||
|
* =====> (boolean) compression :
|
||||||
|
* true if you want to use on-the-fly compression
|
||||||
|
*
|
||||||
|
* =====> (boolean) compatibility :
|
||||||
|
* true if you use old memcache server or extension
|
||||||
|
*
|
||||||
|
* @var array available options
|
||||||
|
*/
|
||||||
|
protected $_options = array(
|
||||||
|
'servers' => array(array(
|
||||||
|
'host' => self::DEFAULT_HOST,
|
||||||
|
'port' => self::DEFAULT_PORT,
|
||||||
|
'persistent' => self::DEFAULT_PERSISTENT,
|
||||||
|
'weight' => self::DEFAULT_WEIGHT,
|
||||||
|
'timeout' => self::DEFAULT_TIMEOUT,
|
||||||
|
'retry_interval' => self::DEFAULT_RETRY_INTERVAL,
|
||||||
|
'status' => self::DEFAULT_STATUS,
|
||||||
|
'failure_callback' => self::DEFAULT_FAILURE_CALLBACK
|
||||||
|
)),
|
||||||
|
'compression' => false,
|
||||||
|
'compatibility' => false,
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Memcache object
|
||||||
|
*
|
||||||
|
* @var mixed memcache object
|
||||||
|
*/
|
||||||
|
protected $_memcache = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options associative array of options
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
if (!extension_loaded('memcache')) {
|
||||||
|
Zend_Cache::throwException('The memcache extension must be loaded for using this backend !');
|
||||||
|
}
|
||||||
|
parent::__construct($options);
|
||||||
|
if (isset($this->_options['servers'])) {
|
||||||
|
$value= $this->_options['servers'];
|
||||||
|
if (isset($value['host'])) {
|
||||||
|
// in this case, $value seems to be a simple associative array (one server only)
|
||||||
|
$value = array(0 => $value); // let's transform it into a classical array of associative arrays
|
||||||
|
}
|
||||||
|
$this->setOption('servers', $value);
|
||||||
|
}
|
||||||
|
$this->_memcache = new Memcache;
|
||||||
|
foreach ($this->_options['servers'] as $server) {
|
||||||
|
if (!array_key_exists('port', $server)) {
|
||||||
|
$server['port'] = self::DEFAULT_PORT;
|
||||||
|
}
|
||||||
|
if (!array_key_exists('persistent', $server)) {
|
||||||
|
$server['persistent'] = self::DEFAULT_PERSISTENT;
|
||||||
|
}
|
||||||
|
if (!array_key_exists('weight', $server)) {
|
||||||
|
$server['weight'] = self::DEFAULT_WEIGHT;
|
||||||
|
}
|
||||||
|
if (!array_key_exists('timeout', $server)) {
|
||||||
|
$server['timeout'] = self::DEFAULT_TIMEOUT;
|
||||||
|
}
|
||||||
|
if (!array_key_exists('retry_interval', $server)) {
|
||||||
|
$server['retry_interval'] = self::DEFAULT_RETRY_INTERVAL;
|
||||||
|
}
|
||||||
|
if (!array_key_exists('status', $server)) {
|
||||||
|
$server['status'] = self::DEFAULT_STATUS;
|
||||||
|
}
|
||||||
|
if (!array_key_exists('failure_callback', $server)) {
|
||||||
|
$server['failure_callback'] = self::DEFAULT_FAILURE_CALLBACK;
|
||||||
|
}
|
||||||
|
if ($this->_options['compatibility']) {
|
||||||
|
// No status for compatibility mode (#ZF-5887)
|
||||||
|
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
|
||||||
|
$server['weight'], $server['timeout'],
|
||||||
|
$server['retry_interval']);
|
||||||
|
} else {
|
||||||
|
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
|
||||||
|
$server['weight'], $server['timeout'],
|
||||||
|
$server['retry_interval'],
|
||||||
|
$server['status'], $server['failure_callback']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||||
|
* @return string|false cached datas
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false)
|
||||||
|
{
|
||||||
|
$tmp = $this->_memcache->get($id);
|
||||||
|
if (is_array($tmp) && isset($tmp[0])) {
|
||||||
|
return $tmp[0];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available or not (for the given id)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
$tmp = $this->_memcache->get($id);
|
||||||
|
if (is_array($tmp)) {
|
||||||
|
return $tmp[1];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some string datas into a cache record
|
||||||
|
*
|
||||||
|
* Note : $data is always "string" (serialization is done by the
|
||||||
|
* core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $data Datas to cache
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||||
|
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||||
|
{
|
||||||
|
$lifetime = $this->getLifetime($specificLifetime);
|
||||||
|
if ($this->_options['compression']) {
|
||||||
|
$flag = MEMCACHE_COMPRESSED;
|
||||||
|
} else {
|
||||||
|
$flag = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ZF-8856: using set because add needs a second request if item already exists
|
||||||
|
$result = @$this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime);
|
||||||
|
|
||||||
|
if (count($tags) > 0) {
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function remove($id)
|
||||||
|
{
|
||||||
|
return $this->_memcache->delete($id, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||||
|
* 'old' => unsupported
|
||||||
|
* 'matchingTag' => unsupported
|
||||||
|
* 'notMatchingTag' => unsupported
|
||||||
|
* 'matchingAnyTag' => unsupported
|
||||||
|
*
|
||||||
|
* @param string $mode Clean mode
|
||||||
|
* @param array $tags Array of tags
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||||
|
{
|
||||||
|
switch ($mode) {
|
||||||
|
case Zend_Cache::CLEANING_MODE_ALL:
|
||||||
|
return $this->_memcache->flush();
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_OLD:
|
||||||
|
$this->_log("Zend_Cache_Backend_Memcached::clean() : CLEANING_MODE_OLD is unsupported by the Memcached backend");
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||||
|
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the automatic cleaning is available for the backend
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isAutomaticCleaningAvailable()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the frontend directives
|
||||||
|
*
|
||||||
|
* @param array $directives Assoc of directives
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setDirectives($directives)
|
||||||
|
{
|
||||||
|
parent::setDirectives($directives);
|
||||||
|
$lifetime = $this->getLifetime(false);
|
||||||
|
if ($lifetime > 2592000) {
|
||||||
|
// #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
|
||||||
|
$this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
|
||||||
|
}
|
||||||
|
if ($lifetime === null) {
|
||||||
|
// #ZF-4614 : we tranform null to zero to get the maximal lifetime
|
||||||
|
parent::setDirectives(array('lifetime' => 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids
|
||||||
|
*
|
||||||
|
* @return array array of stored cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIds()
|
||||||
|
{
|
||||||
|
$this->_log("Zend_Cache_Backend_Memcached::save() : getting the list of cache ids is unsupported by the Memcache backend");
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored tags
|
||||||
|
*
|
||||||
|
* @return array array of stored tags (string)
|
||||||
|
*/
|
||||||
|
public function getTags()
|
||||||
|
{
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which don't match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical OR is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of not matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsNotMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match any given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of any matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingAnyTags($tags = array())
|
||||||
|
{
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the filling percentage of the backend storage
|
||||||
|
*
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return int integer between 0 and 100
|
||||||
|
*/
|
||||||
|
public function getFillingPercentage()
|
||||||
|
{
|
||||||
|
$mems = $this->_memcache->getExtendedStats();
|
||||||
|
|
||||||
|
$memSize = null;
|
||||||
|
$memUsed = null;
|
||||||
|
foreach ($mems as $key => $mem) {
|
||||||
|
if ($mem === false) {
|
||||||
|
$this->_log('can\'t get stat from ' . $key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$eachSize = $mem['limit_maxbytes'];
|
||||||
|
$eachUsed = $mem['bytes'];
|
||||||
|
if ($eachUsed > $eachSize) {
|
||||||
|
$eachUsed = $eachSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
$memSize += $eachSize;
|
||||||
|
$memUsed += $eachUsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($memSize === null || $memUsed === null) {
|
||||||
|
Zend_Cache::throwException('Can\'t get filling percentage');
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((int) (100. * ($memUsed / $memSize)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of metadatas for the given cache id
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - expire : the expire timestamp
|
||||||
|
* - tags : a string array of tags
|
||||||
|
* - mtime : timestamp of last modification time
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return array array of metadatas (false if the cache id is not found)
|
||||||
|
*/
|
||||||
|
public function getMetadatas($id)
|
||||||
|
{
|
||||||
|
$tmp = $this->_memcache->get($id);
|
||||||
|
if (is_array($tmp)) {
|
||||||
|
$data = $tmp[0];
|
||||||
|
$mtime = $tmp[1];
|
||||||
|
if (!isset($tmp[2])) {
|
||||||
|
// because this record is only with 1.7 release
|
||||||
|
// if old cache records are still there...
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$lifetime = $tmp[2];
|
||||||
|
return array(
|
||||||
|
'expire' => $mtime + $lifetime,
|
||||||
|
'tags' => array(),
|
||||||
|
'mtime' => $mtime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give (if possible) an extra lifetime to the given cache id
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param int $extraLifetime
|
||||||
|
* @return boolean true if ok
|
||||||
|
*/
|
||||||
|
public function touch($id, $extraLifetime)
|
||||||
|
{
|
||||||
|
if ($this->_options['compression']) {
|
||||||
|
$flag = MEMCACHE_COMPRESSED;
|
||||||
|
} else {
|
||||||
|
$flag = 0;
|
||||||
|
}
|
||||||
|
$tmp = $this->_memcache->get($id);
|
||||||
|
if (is_array($tmp)) {
|
||||||
|
$data = $tmp[0];
|
||||||
|
$mtime = $tmp[1];
|
||||||
|
if (!isset($tmp[2])) {
|
||||||
|
// because this record is only with 1.7 release
|
||||||
|
// if old cache records are still there...
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$lifetime = $tmp[2];
|
||||||
|
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||||
|
if ($newLifetime <=0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// #ZF-5702 : we try replace() first becase set() seems to be slower
|
||||||
|
if (!($result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $flag, $newLifetime))) {
|
||||||
|
$result = $this->_memcache->set($id, array($data, time(), $newLifetime), $flag, $newLifetime);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an associative array of capabilities (booleans) of the backend
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - automatic_cleaning (is automating cleaning necessary)
|
||||||
|
* - tags (are tags supported)
|
||||||
|
* - expired_read (is it possible to read expired cache records
|
||||||
|
* (for doNotTestCacheValidity option for example))
|
||||||
|
* - priority does the backend deal with priority when saving
|
||||||
|
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||||
|
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||||
|
*
|
||||||
|
* @return array associative of with capabilities
|
||||||
|
*/
|
||||||
|
public function getCapabilities()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'automatic_cleaning' => false,
|
||||||
|
'tags' => false,
|
||||||
|
'expired_read' => false,
|
||||||
|
'priority' => false,
|
||||||
|
'infinite_lifetime' => false,
|
||||||
|
'get_list' => false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
679
libraries/Zend/Cache/Backend/Sqlite.php
Normal file
@ -0,0 +1,679 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Sqlite.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend_Interface
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Backend_Sqlite extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Available options
|
||||||
|
*
|
||||||
|
* =====> (string) cache_db_complete_path :
|
||||||
|
* - the complete path (filename included) of the SQLITE database
|
||||||
|
*
|
||||||
|
* ====> (int) automatic_vacuum_factor :
|
||||||
|
* - Disable / Tune the automatic vacuum process
|
||||||
|
* - The automatic vacuum process defragment the database file (and make it smaller)
|
||||||
|
* when a clean() or delete() is called
|
||||||
|
* 0 => no automatic vacuum
|
||||||
|
* 1 => systematic vacuum (when delete() or clean() methods are called)
|
||||||
|
* x (integer) > 1 => automatic vacuum randomly 1 times on x clean() or delete()
|
||||||
|
*
|
||||||
|
* @var array Available options
|
||||||
|
*/
|
||||||
|
protected $_options = array(
|
||||||
|
'cache_db_complete_path' => null,
|
||||||
|
'automatic_vacuum_factor' => 10
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DB ressource
|
||||||
|
*
|
||||||
|
* @var mixed $_db
|
||||||
|
*/
|
||||||
|
private $_db = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Boolean to store if the structure has benn checked or not
|
||||||
|
*
|
||||||
|
* @var boolean $_structureChecked
|
||||||
|
*/
|
||||||
|
private $_structureChecked = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options Associative array of options
|
||||||
|
* @throws Zend_cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
parent::__construct($options);
|
||||||
|
if ($this->_options['cache_db_complete_path'] === null) {
|
||||||
|
Zend_Cache::throwException('cache_db_complete_path option has to set');
|
||||||
|
}
|
||||||
|
if (!extension_loaded('sqlite')) {
|
||||||
|
Zend_Cache::throwException("Cannot use SQLite storage because the 'sqlite' extension is not loaded in the current PHP environment");
|
||||||
|
}
|
||||||
|
$this->_getConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __destruct()
|
||||||
|
{
|
||||||
|
@sqlite_close($this->_getConnection());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||||
|
* @return string|false Cached datas
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false)
|
||||||
|
{
|
||||||
|
$this->_checkAndBuildStructure();
|
||||||
|
$sql = "SELECT content FROM cache WHERE id='$id'";
|
||||||
|
if (!$doNotTestCacheValidity) {
|
||||||
|
$sql = $sql . " AND (expire=0 OR expire>" . time() . ')';
|
||||||
|
}
|
||||||
|
$result = $this->_query($sql);
|
||||||
|
$row = @sqlite_fetch_array($result);
|
||||||
|
if ($row) {
|
||||||
|
return $row['content'];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available or not (for the given id)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
$this->_checkAndBuildStructure();
|
||||||
|
$sql = "SELECT lastModified FROM cache WHERE id='$id' AND (expire=0 OR expire>" . time() . ')';
|
||||||
|
$result = $this->_query($sql);
|
||||||
|
$row = @sqlite_fetch_array($result);
|
||||||
|
if ($row) {
|
||||||
|
return ((int) $row['lastModified']);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some string datas into a cache record
|
||||||
|
*
|
||||||
|
* Note : $data is always "string" (serialization is done by the
|
||||||
|
* core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $data Datas to cache
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||||
|
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||||
|
{
|
||||||
|
$this->_checkAndBuildStructure();
|
||||||
|
$lifetime = $this->getLifetime($specificLifetime);
|
||||||
|
$data = @sqlite_escape_string($data);
|
||||||
|
$mktime = time();
|
||||||
|
if ($lifetime === null) {
|
||||||
|
$expire = 0;
|
||||||
|
} else {
|
||||||
|
$expire = $mktime + $lifetime;
|
||||||
|
}
|
||||||
|
$this->_query("DELETE FROM cache WHERE id='$id'");
|
||||||
|
$sql = "INSERT INTO cache (id, content, lastModified, expire) VALUES ('$id', '$data', $mktime, $expire)";
|
||||||
|
$res = $this->_query($sql);
|
||||||
|
if (!$res) {
|
||||||
|
$this->_log("Zend_Cache_Backend_Sqlite::save() : impossible to store the cache id=$id");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$res = true;
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$res = $this->_registerTag($id, $tag) && $res;
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function remove($id)
|
||||||
|
{
|
||||||
|
$this->_checkAndBuildStructure();
|
||||||
|
$res = $this->_query("SELECT COUNT(*) AS nbr FROM cache WHERE id='$id'");
|
||||||
|
$result1 = @sqlite_fetch_single($res);
|
||||||
|
$result2 = $this->_query("DELETE FROM cache WHERE id='$id'");
|
||||||
|
$result3 = $this->_query("DELETE FROM tag WHERE id='$id'");
|
||||||
|
$this->_automaticVacuum();
|
||||||
|
return ($result1 && $result2 && $result3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
*
|
||||||
|
* @param string $mode Clean mode
|
||||||
|
* @param array $tags Array of tags
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||||
|
{
|
||||||
|
$this->_checkAndBuildStructure();
|
||||||
|
$return = $this->_clean($mode, $tags);
|
||||||
|
$this->_automaticVacuum();
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids
|
||||||
|
*
|
||||||
|
* @return array array of stored cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIds()
|
||||||
|
{
|
||||||
|
$this->_checkAndBuildStructure();
|
||||||
|
$res = $this->_query("SELECT id FROM cache WHERE (expire=0 OR expire>" . time() . ")");
|
||||||
|
$result = array();
|
||||||
|
while ($id = @sqlite_fetch_single($res)) {
|
||||||
|
$result[] = $id;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored tags
|
||||||
|
*
|
||||||
|
* @return array array of stored tags (string)
|
||||||
|
*/
|
||||||
|
public function getTags()
|
||||||
|
{
|
||||||
|
$this->_checkAndBuildStructure();
|
||||||
|
$res = $this->_query("SELECT DISTINCT(name) AS name FROM tag");
|
||||||
|
$result = array();
|
||||||
|
while ($id = @sqlite_fetch_single($res)) {
|
||||||
|
$result[] = $id;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
$first = true;
|
||||||
|
$ids = array();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$res = $this->_query("SELECT DISTINCT(id) AS id FROM tag WHERE name='$tag'");
|
||||||
|
if (!$res) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||||
|
$ids2 = array();
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$ids2[] = $row['id'];
|
||||||
|
}
|
||||||
|
if ($first) {
|
||||||
|
$ids = $ids2;
|
||||||
|
$first = false;
|
||||||
|
} else {
|
||||||
|
$ids = array_intersect($ids, $ids2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = array();
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$result[] = $id;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which don't match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical OR is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of not matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsNotMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
$res = $this->_query("SELECT id FROM cache");
|
||||||
|
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||||
|
$result = array();
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$id = $row['id'];
|
||||||
|
$matching = false;
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$res = $this->_query("SELECT COUNT(*) AS nbr FROM tag WHERE name='$tag' AND id='$id'");
|
||||||
|
if (!$res) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
$nbr = (int) @sqlite_fetch_single($res);
|
||||||
|
if ($nbr > 0) {
|
||||||
|
$matching = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$matching) {
|
||||||
|
$result[] = $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match any given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of any matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingAnyTags($tags = array())
|
||||||
|
{
|
||||||
|
$first = true;
|
||||||
|
$ids = array();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$res = $this->_query("SELECT DISTINCT(id) AS id FROM tag WHERE name='$tag'");
|
||||||
|
if (!$res) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||||
|
$ids2 = array();
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$ids2[] = $row['id'];
|
||||||
|
}
|
||||||
|
if ($first) {
|
||||||
|
$ids = $ids2;
|
||||||
|
$first = false;
|
||||||
|
} else {
|
||||||
|
$ids = array_merge($ids, $ids2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = array();
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$result[] = $id;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the filling percentage of the backend storage
|
||||||
|
*
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return int integer between 0 and 100
|
||||||
|
*/
|
||||||
|
public function getFillingPercentage()
|
||||||
|
{
|
||||||
|
$dir = dirname($this->_options['cache_db_complete_path']);
|
||||||
|
$free = disk_free_space($dir);
|
||||||
|
$total = disk_total_space($dir);
|
||||||
|
if ($total == 0) {
|
||||||
|
Zend_Cache::throwException('can\'t get disk_total_space');
|
||||||
|
} else {
|
||||||
|
if ($free >= $total) {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
return ((int) (100. * ($total - $free) / $total));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of metadatas for the given cache id
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - expire : the expire timestamp
|
||||||
|
* - tags : a string array of tags
|
||||||
|
* - mtime : timestamp of last modification time
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return array array of metadatas (false if the cache id is not found)
|
||||||
|
*/
|
||||||
|
public function getMetadatas($id)
|
||||||
|
{
|
||||||
|
$tags = array();
|
||||||
|
$res = $this->_query("SELECT name FROM tag WHERE id='$id'");
|
||||||
|
if ($res) {
|
||||||
|
$rows = @sqlite_fetch_all($res, SQLITE_ASSOC);
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$tags[] = $row['name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->_query('CREATE TABLE cache (id TEXT PRIMARY KEY, content BLOB, lastModified INTEGER, expire INTEGER)');
|
||||||
|
$res = $this->_query("SELECT lastModified,expire FROM cache WHERE id='$id'");
|
||||||
|
if (!$res) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$row = @sqlite_fetch_array($res, SQLITE_ASSOC);
|
||||||
|
return array(
|
||||||
|
'tags' => $tags,
|
||||||
|
'mtime' => $row['lastModified'],
|
||||||
|
'expire' => $row['expire']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give (if possible) an extra lifetime to the given cache id
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param int $extraLifetime
|
||||||
|
* @return boolean true if ok
|
||||||
|
*/
|
||||||
|
public function touch($id, $extraLifetime)
|
||||||
|
{
|
||||||
|
$sql = "SELECT expire FROM cache WHERE id='$id' AND (expire=0 OR expire>" . time() . ')';
|
||||||
|
$res = $this->_query($sql);
|
||||||
|
if (!$res) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$expire = @sqlite_fetch_single($res);
|
||||||
|
$newExpire = $expire + $extraLifetime;
|
||||||
|
$res = $this->_query("UPDATE cache SET lastModified=" . time() . ", expire=$newExpire WHERE id='$id'");
|
||||||
|
if ($res) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an associative array of capabilities (booleans) of the backend
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - automatic_cleaning (is automating cleaning necessary)
|
||||||
|
* - tags (are tags supported)
|
||||||
|
* - expired_read (is it possible to read expired cache records
|
||||||
|
* (for doNotTestCacheValidity option for example))
|
||||||
|
* - priority does the backend deal with priority when saving
|
||||||
|
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||||
|
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||||
|
*
|
||||||
|
* @return array associative of with capabilities
|
||||||
|
*/
|
||||||
|
public function getCapabilities()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'automatic_cleaning' => true,
|
||||||
|
'tags' => true,
|
||||||
|
'expired_read' => true,
|
||||||
|
'priority' => false,
|
||||||
|
'infinite_lifetime' => true,
|
||||||
|
'get_list' => true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUBLIC METHOD FOR UNIT TESTING ONLY !
|
||||||
|
*
|
||||||
|
* Force a cache record to expire
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
*/
|
||||||
|
public function ___expire($id)
|
||||||
|
{
|
||||||
|
$time = time() - 1;
|
||||||
|
$this->_query("UPDATE cache SET lastModified=$time, expire=$time WHERE id='$id'");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the connection resource
|
||||||
|
*
|
||||||
|
* If we are not connected, the connection is made
|
||||||
|
*
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return resource Connection resource
|
||||||
|
*/
|
||||||
|
private function _getConnection()
|
||||||
|
{
|
||||||
|
if (is_resource($this->_db)) {
|
||||||
|
return $this->_db;
|
||||||
|
} else {
|
||||||
|
$this->_db = @sqlite_open($this->_options['cache_db_complete_path']);
|
||||||
|
if (!(is_resource($this->_db))) {
|
||||||
|
Zend_Cache::throwException("Impossible to open " . $this->_options['cache_db_complete_path'] . " cache DB file");
|
||||||
|
}
|
||||||
|
return $this->_db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute an SQL query silently
|
||||||
|
*
|
||||||
|
* @param string $query SQL query
|
||||||
|
* @return mixed|false query results
|
||||||
|
*/
|
||||||
|
private function _query($query)
|
||||||
|
{
|
||||||
|
$db = $this->_getConnection();
|
||||||
|
if (is_resource($db)) {
|
||||||
|
$res = @sqlite_query($db, $query);
|
||||||
|
if ($res === false) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deal with the automatic vacuum process
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function _automaticVacuum()
|
||||||
|
{
|
||||||
|
if ($this->_options['automatic_vacuum_factor'] > 0) {
|
||||||
|
$rand = rand(1, $this->_options['automatic_vacuum_factor']);
|
||||||
|
if ($rand == 1) {
|
||||||
|
$this->_query('VACUUM');
|
||||||
|
@sqlite_close($this->_getConnection());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a cache id with the given tag
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param string $tag Tag
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
private function _registerTag($id, $tag) {
|
||||||
|
$res = $this->_query("DELETE FROM TAG WHERE name='$tag' AND id='$id'");
|
||||||
|
$res = $this->_query("INSERT INTO tag (name, id) VALUES ('$tag', '$id')");
|
||||||
|
if (!$res) {
|
||||||
|
$this->_log("Zend_Cache_Backend_Sqlite::_registerTag() : impossible to register tag=$tag on id=$id");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the database structure
|
||||||
|
*
|
||||||
|
* @return false
|
||||||
|
*/
|
||||||
|
private function _buildStructure()
|
||||||
|
{
|
||||||
|
$this->_query('DROP INDEX tag_id_index');
|
||||||
|
$this->_query('DROP INDEX tag_name_index');
|
||||||
|
$this->_query('DROP INDEX cache_id_expire_index');
|
||||||
|
$this->_query('DROP TABLE version');
|
||||||
|
$this->_query('DROP TABLE cache');
|
||||||
|
$this->_query('DROP TABLE tag');
|
||||||
|
$this->_query('CREATE TABLE version (num INTEGER PRIMARY KEY)');
|
||||||
|
$this->_query('CREATE TABLE cache (id TEXT PRIMARY KEY, content BLOB, lastModified INTEGER, expire INTEGER)');
|
||||||
|
$this->_query('CREATE TABLE tag (name TEXT, id TEXT)');
|
||||||
|
$this->_query('CREATE INDEX tag_id_index ON tag(id)');
|
||||||
|
$this->_query('CREATE INDEX tag_name_index ON tag(name)');
|
||||||
|
$this->_query('CREATE INDEX cache_id_expire_index ON cache(id, expire)');
|
||||||
|
$this->_query('INSERT INTO version (num) VALUES (1)');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the database structure is ok (with the good version)
|
||||||
|
*
|
||||||
|
* @return boolean True if ok
|
||||||
|
*/
|
||||||
|
private function _checkStructureVersion()
|
||||||
|
{
|
||||||
|
$result = $this->_query("SELECT num FROM version");
|
||||||
|
if (!$result) return false;
|
||||||
|
$row = @sqlite_fetch_array($result);
|
||||||
|
if (!$row) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (((int) $row['num']) != 1) {
|
||||||
|
// old cache structure
|
||||||
|
$this->_log('Zend_Cache_Backend_Sqlite::_checkStructureVersion() : old cache structure version detected => the cache is going to be dropped');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
*
|
||||||
|
* @param string $mode Clean mode
|
||||||
|
* @param array $tags Array of tags
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
private function _clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||||
|
{
|
||||||
|
switch ($mode) {
|
||||||
|
case Zend_Cache::CLEANING_MODE_ALL:
|
||||||
|
$res1 = $this->_query('DELETE FROM cache');
|
||||||
|
$res2 = $this->_query('DELETE FROM tag');
|
||||||
|
return $res1 && $res2;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_OLD:
|
||||||
|
$mktime = time();
|
||||||
|
$res1 = $this->_query("DELETE FROM tag WHERE id IN (SELECT id FROM cache WHERE expire>0 AND expire<=$mktime)");
|
||||||
|
$res2 = $this->_query("DELETE FROM cache WHERE expire>0 AND expire<=$mktime");
|
||||||
|
return $res1 && $res2;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||||
|
$ids = $this->getIdsMatchingTags($tags);
|
||||||
|
$result = true;
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$result = $this->remove($id) && $result;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||||
|
$ids = $this->getIdsNotMatchingTags($tags);
|
||||||
|
$result = true;
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$result = $this->remove($id) && $result;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||||
|
$ids = $this->getIdsMatchingAnyTags($tags);
|
||||||
|
$result = true;
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$result = $this->remove($id) && $result;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the database structure is ok (with the good version), if no : build it
|
||||||
|
*
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return boolean True if ok
|
||||||
|
*/
|
||||||
|
private function _checkAndBuildStructure()
|
||||||
|
{
|
||||||
|
if (!($this->_structureChecked)) {
|
||||||
|
if (!$this->_checkStructureVersion()) {
|
||||||
|
$this->_buildStructure();
|
||||||
|
if (!$this->_checkStructureVersion()) {
|
||||||
|
Zend_Cache::throwException("Impossible to build cache structure in " . $this->_options['cache_db_complete_path']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->_structureChecked = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
566
libraries/Zend/Cache/Backend/Static.php
Normal file
@ -0,0 +1,566 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: BlackHole.php 17867 2009-08-28 09:42:11Z yoshida@zend.co.jp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend_Interface
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend/Interface.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Backend_Static
|
||||||
|
extends Zend_Cache_Backend
|
||||||
|
implements Zend_Cache_Backend_Interface
|
||||||
|
{
|
||||||
|
const INNER_CACHE_NAME = 'zend_cache_backend_static_tagcache';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static backend options
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_options = array(
|
||||||
|
'public_dir' => null,
|
||||||
|
'sub_dir' => 'html',
|
||||||
|
'file_extension' => '.html',
|
||||||
|
'index_filename' => 'index',
|
||||||
|
'file_locking' => true,
|
||||||
|
'cache_file_umask' => 0600,
|
||||||
|
'cache_directory_umask' => 0700,
|
||||||
|
'debug_header' => false,
|
||||||
|
'tag_cache' => null,
|
||||||
|
'disable_caching' => false
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache for handling tags
|
||||||
|
* @var Zend_Cache_Core
|
||||||
|
*/
|
||||||
|
protected $_tagCache = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tagged items
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_tagged = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interceptor child method to handle the case where an Inner
|
||||||
|
* Cache object is being set since it's not supported by the
|
||||||
|
* standard backend interface
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param mixed $value
|
||||||
|
* @return Zend_Cache_Backend_Static
|
||||||
|
*/
|
||||||
|
public function setOption($name, $value)
|
||||||
|
{
|
||||||
|
if ($name == 'tag_cache') {
|
||||||
|
$this->setInnerCache($value);
|
||||||
|
} else {
|
||||||
|
parent::setOption($name, $value);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve any option via interception of the parent's statically held
|
||||||
|
* options including the local option for a tag cache.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getOption($name)
|
||||||
|
{
|
||||||
|
if ($name == 'tag_cache') {
|
||||||
|
return $this->getInnerCache();
|
||||||
|
} else {
|
||||||
|
if (in_array($name, $this->_options)) {
|
||||||
|
return $this->_options[$name];
|
||||||
|
}
|
||||||
|
if ($name == 'lifetime') {
|
||||||
|
return parent::getLifetime();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||||
|
* @return string|false cached datas
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false)
|
||||||
|
{
|
||||||
|
if (empty($id)) {
|
||||||
|
$id = $this->_detectId();
|
||||||
|
} else {
|
||||||
|
$id = $this->_decodeId($id);
|
||||||
|
}
|
||||||
|
if (!$this->_verifyPath($id)) {
|
||||||
|
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||||
|
}
|
||||||
|
if ($doNotTestCacheValidity) {
|
||||||
|
$this->_log("Zend_Cache_Backend_Static::load() : \$doNotTestCacheValidity=true is unsupported by the Static backend");
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileName = basename($id);
|
||||||
|
if (empty($fileName)) {
|
||||||
|
$fileName = $this->_options['index_filename'];
|
||||||
|
}
|
||||||
|
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||||
|
$file = rtrim($pathName, '/') . '/' . $fileName . $this->_options['file_extension'];
|
||||||
|
if (file_exists($file)) {
|
||||||
|
$content = file_get_contents($file);
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available or not (for the given id)
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
$id = $this->_decodeId($id);
|
||||||
|
if (!$this->_verifyPath($id)) {
|
||||||
|
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileName = basename($id);
|
||||||
|
if (empty($fileName)) {
|
||||||
|
$fileName = $this->_options['index_filename'];
|
||||||
|
}
|
||||||
|
if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||||
|
$this->_tagged = $tagged;
|
||||||
|
} elseif (!$this->_tagged) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||||
|
|
||||||
|
// Switch extension if needed
|
||||||
|
if (isset($this->_tagged[$id])) {
|
||||||
|
$extension = $this->_tagged[$id]['extension'];
|
||||||
|
} else {
|
||||||
|
$extension = $this->_options['file_extension'];
|
||||||
|
}
|
||||||
|
$file = $pathName . '/' . $fileName . $extension;
|
||||||
|
if (file_exists($file)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some string datas into a cache record
|
||||||
|
*
|
||||||
|
* Note : $data is always "string" (serialization is done by the
|
||||||
|
* core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $data Datas to cache
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||||
|
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||||
|
{
|
||||||
|
if ($this->_options['disable_caching']) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$extension = null;
|
||||||
|
if ($this->_isSerialized($data)) {
|
||||||
|
$data = unserialize($data);
|
||||||
|
$extension = '.' . ltrim($data[1], '.');
|
||||||
|
$data = $data[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
clearstatcache();
|
||||||
|
if (is_null($id) || strlen($id) == 0) {
|
||||||
|
$id = $this->_detectId();
|
||||||
|
} else {
|
||||||
|
$id = $this->_decodeId($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileName = basename($id);
|
||||||
|
if (empty($fileName)) {
|
||||||
|
$fileName = $this->_options['index_filename'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$pathName = realpath($this->_options['public_dir']) . dirname($id);
|
||||||
|
$this->_createDirectoriesFor($pathName);
|
||||||
|
|
||||||
|
if (is_null($id) || strlen($id) == 0) {
|
||||||
|
$dataUnserialized = unserialize($data);
|
||||||
|
$data = $dataUnserialized['data'];
|
||||||
|
}
|
||||||
|
$ext = $this->_options['file_extension'];
|
||||||
|
if ($extension) $ext = $extension;
|
||||||
|
$file = rtrim($pathName, '/') . '/' . $fileName . $ext;
|
||||||
|
if ($this->_options['file_locking']) {
|
||||||
|
$result = file_put_contents($file, $data, LOCK_EX);
|
||||||
|
} else {
|
||||||
|
$result = file_put_contents($file, $data);
|
||||||
|
}
|
||||||
|
@chmod($file, $this->_octdec($this->_options['cache_file_umask']));
|
||||||
|
|
||||||
|
if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||||
|
$this->_tagged = $tagged;
|
||||||
|
} elseif (is_null($this->_tagged)) {
|
||||||
|
$this->_tagged = array();
|
||||||
|
}
|
||||||
|
if (!isset($this->_tagged[$id])) {
|
||||||
|
$this->_tagged[$id] = array();
|
||||||
|
}
|
||||||
|
if (!isset($this->_tagged[$id]['tags'])) {
|
||||||
|
$this->_tagged[$id]['tags'] = array();
|
||||||
|
}
|
||||||
|
$this->_tagged[$id]['tags'] = array_unique(array_merge($this->_tagged[$id]['tags'], $tags));
|
||||||
|
$this->_tagged[$id]['extension'] = $ext;
|
||||||
|
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||||
|
return (bool) $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively create the directories needed to write the static file
|
||||||
|
*/
|
||||||
|
protected function _createDirectoriesFor($path)
|
||||||
|
{
|
||||||
|
if ( !is_dir($path)
|
||||||
|
&& !@mkdir($path, $this->_options['cache_directory_umask'], true)) {
|
||||||
|
$lastErr = error_get_last();
|
||||||
|
Zend_Cache::throwException("Can't create directory: {$lastErr['message']}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
$parts = explode('/', $path);
|
||||||
|
$directory = '';
|
||||||
|
foreach ($parts as $part) {
|
||||||
|
$directory = rtrim($directory, '/') . '/' . $part;
|
||||||
|
if (!is_dir($directory)) {
|
||||||
|
mkdir($directory, $this->_octdec($this->_options['cache_directory_umask']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect serialization of data (cannot predict since this is the only way
|
||||||
|
* to obey the interface yet pass in another parameter).
|
||||||
|
*
|
||||||
|
* In future, ZF 2.0, check if we can just avoid the interface restraints.
|
||||||
|
*
|
||||||
|
* This format is the only valid one possible for the class, so it's simple
|
||||||
|
* to just run a regular expression for the starting serialized format.
|
||||||
|
*/
|
||||||
|
protected function _isSerialized($data)
|
||||||
|
{
|
||||||
|
return preg_match("/a:2:\{i:0;s:\d+:\"/", $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function remove($id)
|
||||||
|
{
|
||||||
|
if (!$this->_verifyPath($id)) {
|
||||||
|
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||||
|
}
|
||||||
|
$fileName = basename($id);
|
||||||
|
if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||||
|
$this->_tagged = $tagged;
|
||||||
|
} elseif (!$this->_tagged) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (isset($this->_tagged[$id])) {
|
||||||
|
$extension = $this->_tagged[$id]['extension'];
|
||||||
|
} else {
|
||||||
|
$extension = $this->_options['file_extension'];
|
||||||
|
}
|
||||||
|
if (empty($fileName)) {
|
||||||
|
$fileName = $this->_options['index_filename'];
|
||||||
|
}
|
||||||
|
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||||
|
$file = realpath($pathName) . '/' . $fileName . $extension;
|
||||||
|
if (!file_exists($file)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return unlink($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record recursively for the given directory matching a
|
||||||
|
* REQUEST_URI based relative path (deletes the actual file matching this
|
||||||
|
* in addition to the matching directory)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function removeRecursively($id)
|
||||||
|
{
|
||||||
|
if (!$this->_verifyPath($id)) {
|
||||||
|
Zend_Cache::throwException('Invalid cache id: does not match expected public_dir path');
|
||||||
|
}
|
||||||
|
$fileName = basename($id);
|
||||||
|
if (empty($fileName)) {
|
||||||
|
$fileName = $this->_options['index_filename'];
|
||||||
|
}
|
||||||
|
$pathName = $this->_options['public_dir'] . dirname($id);
|
||||||
|
$file = $pathName . '/' . $fileName . $this->_options['file_extension'];
|
||||||
|
$directory = $pathName . '/' . $fileName;
|
||||||
|
if (file_exists($directory)) {
|
||||||
|
if (!is_writable($directory)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach (new DirectoryIterator($directory) as $file) {
|
||||||
|
if (true === $file->isFile()) {
|
||||||
|
if (false === unlink($file->getPathName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rmdir(dirname($path));
|
||||||
|
}
|
||||||
|
if (file_exists($file)) {
|
||||||
|
if (!is_writable($file)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return unlink($file);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
*
|
||||||
|
* @param string $mode Clean mode
|
||||||
|
* @param array $tags Array of tags
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||||
|
{
|
||||||
|
$result = false;
|
||||||
|
switch ($mode) {
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||||
|
if (empty($tags)) {
|
||||||
|
throw new Zend_Exception('Cannot use tag matching modes as no tags were defined');
|
||||||
|
}
|
||||||
|
if (is_null($this->_tagged) && $tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME)) {
|
||||||
|
$this->_tagged = $tagged;
|
||||||
|
} elseif (!$this->_tagged) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$urls = array_keys($this->_tagged);
|
||||||
|
foreach ($urls as $url) {
|
||||||
|
if (isset($this->_tagged[$url]['tags']) && in_array($tag, $this->_tagged[$url]['tags'])) {
|
||||||
|
$this->remove($url);
|
||||||
|
unset($this->_tagged[$url]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||||
|
$result = true;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_ALL:
|
||||||
|
if (is_null($this->_tagged)) {
|
||||||
|
$tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME);
|
||||||
|
$this->_tagged = $tagged;
|
||||||
|
}
|
||||||
|
if (is_null($this->_tagged) || empty($this->_tagged)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$urls = array_keys($this->_tagged);
|
||||||
|
foreach ($urls as $url) {
|
||||||
|
$this->remove($url);
|
||||||
|
unset($this->_tagged[$url]);
|
||||||
|
}
|
||||||
|
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||||
|
$result = true;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_OLD:
|
||||||
|
$this->_log("Zend_Cache_Backend_Static : Selected Cleaning Mode Currently Unsupported By This Backend");
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||||
|
if (empty($tags)) {
|
||||||
|
throw new Zend_Exception('Cannot use tag matching modes as no tags were defined');
|
||||||
|
}
|
||||||
|
if (is_null($this->_tagged)) {
|
||||||
|
$tagged = $this->getInnerCache()->load(self::INNER_CACHE_NAME);
|
||||||
|
$this->_tagged = $tagged;
|
||||||
|
}
|
||||||
|
if (is_null($this->_tagged) || empty($this->_tagged)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$urls = array_keys($this->_tagged);
|
||||||
|
foreach ($urls as $url) {
|
||||||
|
$difference = array_diff($tags, $this->_tagged[$url]['tags']);
|
||||||
|
if (count($tags) == count($difference)) {
|
||||||
|
$this->remove($url);
|
||||||
|
unset($this->_tagged[$url]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->getInnerCache()->save($this->_tagged, self::INNER_CACHE_NAME);
|
||||||
|
$result = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an Inner Cache, used here primarily to store Tags associated
|
||||||
|
* with caches created by this backend. Note: If Tags are lost, the cache
|
||||||
|
* should be completely cleaned as the mapping of tags to caches will
|
||||||
|
* have been irrevocably lost.
|
||||||
|
*
|
||||||
|
* @param Zend_Cache_Core
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setInnerCache(Zend_Cache_Core $cache)
|
||||||
|
{
|
||||||
|
$this->_tagCache = $cache;
|
||||||
|
$this->_options['tag_cache'] = $cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Inner Cache if set
|
||||||
|
*
|
||||||
|
* @return Zend_Cache_Core
|
||||||
|
*/
|
||||||
|
public function getInnerCache()
|
||||||
|
{
|
||||||
|
if (is_null($this->_tagCache)) {
|
||||||
|
Zend_Cache::throwException('An Inner Cache has not been set; use setInnerCache()');
|
||||||
|
}
|
||||||
|
return $this->_tagCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify path exists and is non-empty
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function _verifyPath($path)
|
||||||
|
{
|
||||||
|
$path = realpath($path);
|
||||||
|
$base = realpath($this->_options['public_dir']);
|
||||||
|
return strncmp($path, $base, strlen($base)) !== 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the page to save from the request
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function _detectId()
|
||||||
|
{
|
||||||
|
return $_SERVER['REQUEST_URI'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate a cache id or a tag (security, reliable filenames, reserved prefixes...)
|
||||||
|
*
|
||||||
|
* Throw an exception if a problem is found
|
||||||
|
*
|
||||||
|
* @param string $string Cache id or tag
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
* @deprecated Not usable until perhaps ZF 2.0
|
||||||
|
*/
|
||||||
|
protected static function _validateIdOrTag($string)
|
||||||
|
{
|
||||||
|
if (!is_string($string)) {
|
||||||
|
Zend_Cache::throwException('Invalid id or tag : must be a string');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal only checked in Frontend - not here!
|
||||||
|
if (substr($string, 0, 9) == 'internal-') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validation assumes no query string, fragments or scheme included - only the path
|
||||||
|
if (!preg_match(
|
||||||
|
'/^(?:\/(?:(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*\'()\[\]:@&=+$,;])*)?)+$/',
|
||||||
|
$string
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Zend_Cache::throwException("Invalid id or tag '$string' : must be a valid URL path");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect an octal string and return its octal value for file permission ops
|
||||||
|
* otherwise return the non-string (assumed octal or decimal int already)
|
||||||
|
*
|
||||||
|
* @param $val The potential octal in need of conversion
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
protected function _octdec($val)
|
||||||
|
{
|
||||||
|
if (decoct(octdec($val)) == $val && is_string($val)) {
|
||||||
|
return octdec($val);
|
||||||
|
}
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode a request URI from the provided ID
|
||||||
|
*/
|
||||||
|
protected function _decodeId($id)
|
||||||
|
{
|
||||||
|
return pack('H*', $id);;
|
||||||
|
}
|
||||||
|
}
|
412
libraries/Zend/Cache/Backend/Test.php
Normal file
@ -0,0 +1,412 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Test.php 22504 2010-06-30 17:05:07Z mabe $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend_Interface
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Backend_Test extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Available options
|
||||||
|
*
|
||||||
|
* @var array available options
|
||||||
|
*/
|
||||||
|
protected $_options = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frontend or Core directives
|
||||||
|
*
|
||||||
|
* @var array directives
|
||||||
|
*/
|
||||||
|
protected $_directives = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array to log actions
|
||||||
|
*
|
||||||
|
* @var array $_log
|
||||||
|
*/
|
||||||
|
private $_log = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current index for log array
|
||||||
|
*
|
||||||
|
* @var int $_index
|
||||||
|
*/
|
||||||
|
private $_index = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options associative array of options
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($options = array())
|
||||||
|
{
|
||||||
|
$this->_addLog('construct', array($options));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the frontend directives
|
||||||
|
*
|
||||||
|
* @param array $directives assoc of directives
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setDirectives($directives)
|
||||||
|
{
|
||||||
|
$this->_addLog('setDirectives', array($directives));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* For this test backend only, if $id == 'false', then the method will return false
|
||||||
|
* if $id == 'serialized', the method will return a serialized array
|
||||||
|
* ('foo' else)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||||
|
* @return string Cached datas (or false)
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false)
|
||||||
|
{
|
||||||
|
$this->_addLog('get', array($id, $doNotTestCacheValidity));
|
||||||
|
|
||||||
|
if ( $id == 'false'
|
||||||
|
|| $id == 'd8523b3ee441006261eeffa5c3d3a0a7'
|
||||||
|
|| $id == 'e83249ea22178277d5befc2c5e2e9ace'
|
||||||
|
|| $id == '40f649b94977c0a6e76902e2a0b43587'
|
||||||
|
|| $id == '88161989b73a4cbfd0b701c446115a99'
|
||||||
|
|| $id == '205fc79cba24f0f0018eb92c7c8b3ba4')
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($id=='serialized') {
|
||||||
|
return serialize(array('foo'));
|
||||||
|
}
|
||||||
|
if ($id=='serialized2') {
|
||||||
|
return serialize(array('headers' => array(), 'data' => 'foo'));
|
||||||
|
}
|
||||||
|
if ( $id == '71769f39054f75894288e397df04e445' || $id == '615d222619fb20b527168340cebd0578'
|
||||||
|
|| $id == '8a02d218a5165c467e7a5747cc6bd4b6' || $id == '648aca1366211d17cbf48e65dc570bee'
|
||||||
|
|| $id == '4a923ef02d7f997ca14d56dfeae25ea7') {
|
||||||
|
return serialize(array('foo', 'bar'));
|
||||||
|
}
|
||||||
|
return 'foo';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available or not (for the given id)
|
||||||
|
*
|
||||||
|
* For this test backend only, if $id == 'false', then the method will return false
|
||||||
|
* (123456 else)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return mixed|false false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
$this->_addLog('test', array($id));
|
||||||
|
if ($id=='false') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (($id=='3c439c922209e2cb0b54d6deffccd75a')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return 123456;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some string datas into a cache record
|
||||||
|
*
|
||||||
|
* For this test backend only, if $id == 'false', then the method will return false
|
||||||
|
* (true else)
|
||||||
|
*
|
||||||
|
* @param string $data Datas to cache
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||||
|
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||||
|
{
|
||||||
|
$this->_addLog('save', array($data, $id, $tags));
|
||||||
|
if ($id=='false') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record
|
||||||
|
*
|
||||||
|
* For this test backend only, if $id == 'false', then the method will return false
|
||||||
|
* (true else)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function remove($id)
|
||||||
|
{
|
||||||
|
$this->_addLog('remove', array($id));
|
||||||
|
if ($id=='false') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* For this test backend only, if $mode == 'false', then the method will return false
|
||||||
|
* (true else)
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
*
|
||||||
|
* @param string $mode Clean mode
|
||||||
|
* @param array $tags Array of tags
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||||
|
{
|
||||||
|
$this->_addLog('clean', array($mode, $tags));
|
||||||
|
if ($mode=='false') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the last log
|
||||||
|
*
|
||||||
|
* @return string The last log
|
||||||
|
*/
|
||||||
|
public function getLastLog()
|
||||||
|
{
|
||||||
|
return $this->_log[$this->_index - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the log index
|
||||||
|
*
|
||||||
|
* @return int Log index
|
||||||
|
*/
|
||||||
|
public function getLogIndex()
|
||||||
|
{
|
||||||
|
return $this->_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the complete log array
|
||||||
|
*
|
||||||
|
* @return array Complete log array
|
||||||
|
*/
|
||||||
|
public function getAllLogs()
|
||||||
|
{
|
||||||
|
return $this->_log;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the automatic cleaning is available for the backend
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isAutomaticCleaningAvailable()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids
|
||||||
|
*
|
||||||
|
* @return array array of stored cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIds()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'prefix_id1', 'prefix_id2'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored tags
|
||||||
|
*
|
||||||
|
* @return array array of stored tags (string)
|
||||||
|
*/
|
||||||
|
public function getTags()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'tag1', 'tag2'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
if ($tags == array('tag1', 'tag2')) {
|
||||||
|
return array('prefix_id1', 'prefix_id2');
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which don't match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical OR is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of not matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsNotMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
if ($tags == array('tag3', 'tag4')) {
|
||||||
|
return array('prefix_id3', 'prefix_id4');
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match any given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of any matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingAnyTags($tags = array())
|
||||||
|
{
|
||||||
|
if ($tags == array('tag5', 'tag6')) {
|
||||||
|
return array('prefix_id5', 'prefix_id6');
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the filling percentage of the backend storage
|
||||||
|
*
|
||||||
|
* @return int integer between 0 and 100
|
||||||
|
*/
|
||||||
|
public function getFillingPercentage()
|
||||||
|
{
|
||||||
|
return 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of metadatas for the given cache id
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - expire : the expire timestamp
|
||||||
|
* - tags : a string array of tags
|
||||||
|
* - mtime : timestamp of last modification time
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return array array of metadatas (false if the cache id is not found)
|
||||||
|
*/
|
||||||
|
public function getMetadatas($id)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give (if possible) an extra lifetime to the given cache id
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param int $extraLifetime
|
||||||
|
* @return boolean true if ok
|
||||||
|
*/
|
||||||
|
public function touch($id, $extraLifetime)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an associative array of capabilities (booleans) of the backend
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - automatic_cleaning (is automating cleaning necessary)
|
||||||
|
* - tags (are tags supported)
|
||||||
|
* - expired_read (is it possible to read expired cache records
|
||||||
|
* (for doNotTestCacheValidity option for example))
|
||||||
|
* - priority does the backend deal with priority when saving
|
||||||
|
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||||
|
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||||
|
*
|
||||||
|
* @return array associative of with capabilities
|
||||||
|
*/
|
||||||
|
public function getCapabilities()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'automatic_cleaning' => true,
|
||||||
|
'tags' => true,
|
||||||
|
'expired_read' => false,
|
||||||
|
'priority' => true,
|
||||||
|
'infinite_lifetime' => true,
|
||||||
|
'get_list' => true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an event to the log array
|
||||||
|
*
|
||||||
|
* @param string $methodName MethodName
|
||||||
|
* @param array $args Arguments
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function _addLog($methodName, $args)
|
||||||
|
{
|
||||||
|
$this->_log[$this->_index] = array(
|
||||||
|
'methodName' => $methodName,
|
||||||
|
'args' => $args
|
||||||
|
);
|
||||||
|
$this->_index = $this->_index + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
536
libraries/Zend/Cache/Backend/TwoLevels.php
Normal file
@ -0,0 +1,536 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: TwoLevels.php 22737 2010-07-30 16:30:42Z andyfowler $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend_ExtendedInterface
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Zend_Cache_Backend_TwoLevels extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Available options
|
||||||
|
*
|
||||||
|
* =====> (string) slow_backend :
|
||||||
|
* - Slow backend name
|
||||||
|
* - Must implement the Zend_Cache_Backend_ExtendedInterface
|
||||||
|
* - Should provide a big storage
|
||||||
|
*
|
||||||
|
* =====> (string) fast_backend :
|
||||||
|
* - Flow backend name
|
||||||
|
* - Must implement the Zend_Cache_Backend_ExtendedInterface
|
||||||
|
* - Must be much faster than slow_backend
|
||||||
|
*
|
||||||
|
* =====> (array) slow_backend_options :
|
||||||
|
* - Slow backend options (see corresponding backend)
|
||||||
|
*
|
||||||
|
* =====> (array) fast_backend_options :
|
||||||
|
* - Fast backend options (see corresponding backend)
|
||||||
|
*
|
||||||
|
* =====> (int) stats_update_factor :
|
||||||
|
* - Disable / Tune the computation of the fast backend filling percentage
|
||||||
|
* - When saving a record into cache :
|
||||||
|
* 1 => systematic computation of the fast backend filling percentage
|
||||||
|
* x (integer) > 1 => computation of the fast backend filling percentage randomly 1 times on x cache write
|
||||||
|
*
|
||||||
|
* =====> (boolean) slow_backend_custom_naming :
|
||||||
|
* =====> (boolean) fast_backend_custom_naming :
|
||||||
|
* =====> (boolean) slow_backend_autoload :
|
||||||
|
* =====> (boolean) fast_backend_autoload :
|
||||||
|
* - See Zend_Cache::factory() method
|
||||||
|
*
|
||||||
|
* =====> (boolean) auto_refresh_fast_cache
|
||||||
|
* - If true, auto refresh the fast cache when a cache record is hit
|
||||||
|
*
|
||||||
|
* @var array available options
|
||||||
|
*/
|
||||||
|
protected $_options = array(
|
||||||
|
'slow_backend' => 'File',
|
||||||
|
'fast_backend' => 'Apc',
|
||||||
|
'slow_backend_options' => array(),
|
||||||
|
'fast_backend_options' => array(),
|
||||||
|
'stats_update_factor' => 10,
|
||||||
|
'slow_backend_custom_naming' => false,
|
||||||
|
'fast_backend_custom_naming' => false,
|
||||||
|
'slow_backend_autoload' => false,
|
||||||
|
'fast_backend_autoload' => false,
|
||||||
|
'auto_refresh_fast_cache' => true
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Slow Backend
|
||||||
|
*
|
||||||
|
* @var Zend_Cache_Backend_ExtendedInterface
|
||||||
|
*/
|
||||||
|
protected $_slowBackend;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fast Backend
|
||||||
|
*
|
||||||
|
* @var Zend_Cache_Backend_ExtendedInterface
|
||||||
|
*/
|
||||||
|
protected $_fastBackend;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache for the fast backend filling percentage
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $_fastBackendFillingPercentage = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options Associative array of options
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
parent::__construct($options);
|
||||||
|
|
||||||
|
if ($this->_options['slow_backend'] === null) {
|
||||||
|
Zend_Cache::throwException('slow_backend option has to set');
|
||||||
|
} elseif ($this->_options['slow_backend'] instanceof Zend_Cache_Backend_ExtendedInterface) {
|
||||||
|
$this->_slowBackend = $this->_options['slow_backend'];
|
||||||
|
} else {
|
||||||
|
$this->_slowBackend = Zend_Cache::_makeBackend(
|
||||||
|
$this->_options['slow_backend'],
|
||||||
|
$this->_options['slow_backend_options'],
|
||||||
|
$this->_options['slow_backend_custom_naming'],
|
||||||
|
$this->_options['slow_backend_autoload']
|
||||||
|
);
|
||||||
|
if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_slowBackend))) {
|
||||||
|
Zend_Cache::throwException('slow_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->_options['fast_backend'] === null) {
|
||||||
|
Zend_Cache::throwException('fast_backend option has to set');
|
||||||
|
} elseif ($this->_options['fast_backend'] instanceof Zend_Cache_Backend_ExtendedInterface) {
|
||||||
|
$this->_fastBackend = $this->_options['fast_backend'];
|
||||||
|
} else {
|
||||||
|
$this->_fastBackend = Zend_Cache::_makeBackend(
|
||||||
|
$this->_options['fast_backend'],
|
||||||
|
$this->_options['fast_backend_options'],
|
||||||
|
$this->_options['fast_backend_custom_naming'],
|
||||||
|
$this->_options['fast_backend_autoload']
|
||||||
|
);
|
||||||
|
if (!in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_fastBackend))) {
|
||||||
|
Zend_Cache::throwException('fast_backend must implement the Zend_Cache_Backend_ExtendedInterface interface');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_slowBackend->setDirectives($this->_directives);
|
||||||
|
$this->_fastBackend->setDirectives($this->_directives);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available or not (for the given id)
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
$fastTest = $this->_fastBackend->test($id);
|
||||||
|
if ($fastTest) {
|
||||||
|
return $fastTest;
|
||||||
|
} else {
|
||||||
|
return $this->_slowBackend->test($id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some string datas into a cache record
|
||||||
|
*
|
||||||
|
* Note : $data is always "string" (serialization is done by the
|
||||||
|
* core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $data Datas to cache
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||||
|
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id, $tags = array(), $specificLifetime = false, $priority = 8)
|
||||||
|
{
|
||||||
|
$usage = $this->_getFastFillingPercentage('saving');
|
||||||
|
$boolFast = true;
|
||||||
|
$lifetime = $this->getLifetime($specificLifetime);
|
||||||
|
$preparedData = $this->_prepareData($data, $lifetime, $priority);
|
||||||
|
if (($priority > 0) && (10 * $priority >= $usage)) {
|
||||||
|
$fastLifetime = $this->_getFastLifetime($lifetime, $priority);
|
||||||
|
$boolFast = $this->_fastBackend->save($preparedData, $id, array(), $fastLifetime);
|
||||||
|
$boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime);
|
||||||
|
} else {
|
||||||
|
$boolSlow = $this->_slowBackend->save($preparedData, $id, $tags, $lifetime);
|
||||||
|
if ($boolSlow === true) {
|
||||||
|
$boolFast = $this->_fastBackend->remove($id);
|
||||||
|
if (!$boolFast && !$this->_fastBackend->test($id)) {
|
||||||
|
// some backends return false on remove() even if the key never existed. (and it won't if fast is full)
|
||||||
|
// all we care about is that the key doesn't exist now
|
||||||
|
$boolFast = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($boolFast && $boolSlow);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||||
|
* @return string|false cached datas
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false)
|
||||||
|
{
|
||||||
|
$res = $this->_fastBackend->load($id, $doNotTestCacheValidity);
|
||||||
|
if ($res === false) {
|
||||||
|
$res = $this->_slowBackend->load($id, $doNotTestCacheValidity);
|
||||||
|
if ($res === false) {
|
||||||
|
// there is no cache at all for this id
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$array = unserialize($res);
|
||||||
|
// maybe, we have to refresh the fast cache ?
|
||||||
|
if ($this->_options['auto_refresh_fast_cache']) {
|
||||||
|
if ($array['priority'] == 10) {
|
||||||
|
// no need to refresh the fast cache with priority = 10
|
||||||
|
return $array['data'];
|
||||||
|
}
|
||||||
|
$newFastLifetime = $this->_getFastLifetime($array['lifetime'], $array['priority'], time() - $array['expire']);
|
||||||
|
// we have the time to refresh the fast cache
|
||||||
|
$usage = $this->_getFastFillingPercentage('loading');
|
||||||
|
if (($array['priority'] > 0) && (10 * $array['priority'] >= $usage)) {
|
||||||
|
// we can refresh the fast cache
|
||||||
|
$preparedData = $this->_prepareData($array['data'], $array['lifetime'], $array['priority']);
|
||||||
|
$this->_fastBackend->save($preparedData, $id, array(), $newFastLifetime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $array['data'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function remove($id)
|
||||||
|
{
|
||||||
|
$boolFast = $this->_fastBackend->remove($id);
|
||||||
|
$boolSlow = $this->_slowBackend->remove($id);
|
||||||
|
return $boolFast && $boolSlow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
*
|
||||||
|
* @param string $mode Clean mode
|
||||||
|
* @param array $tags Array of tags
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||||
|
{
|
||||||
|
switch($mode) {
|
||||||
|
case Zend_Cache::CLEANING_MODE_ALL:
|
||||||
|
$boolFast = $this->_fastBackend->clean(Zend_Cache::CLEANING_MODE_ALL);
|
||||||
|
$boolSlow = $this->_slowBackend->clean(Zend_Cache::CLEANING_MODE_ALL);
|
||||||
|
return $boolFast && $boolSlow;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_OLD:
|
||||||
|
return $this->_slowBackend->clean(Zend_Cache::CLEANING_MODE_OLD);
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||||
|
$ids = $this->_slowBackend->getIdsMatchingTags($tags);
|
||||||
|
$res = true;
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$bool = $this->remove($id);
|
||||||
|
$res = $res && $bool;
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||||
|
$ids = $this->_slowBackend->getIdsNotMatchingTags($tags);
|
||||||
|
$res = true;
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$bool = $this->remove($id);
|
||||||
|
$res = $res && $bool;
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||||
|
$ids = $this->_slowBackend->getIdsMatchingAnyTags($tags);
|
||||||
|
$res = true;
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$bool = $this->remove($id);
|
||||||
|
$res = $res && $bool;
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids
|
||||||
|
*
|
||||||
|
* @return array array of stored cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIds()
|
||||||
|
{
|
||||||
|
return $this->_slowBackend->getIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored tags
|
||||||
|
*
|
||||||
|
* @return array array of stored tags (string)
|
||||||
|
*/
|
||||||
|
public function getTags()
|
||||||
|
{
|
||||||
|
return $this->_slowBackend->getTags();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
return $this->_slowBackend->getIdsMatchingTags($tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which don't match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical OR is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of not matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsNotMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
return $this->_slowBackend->getIdsNotMatchingTags($tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match any given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of any matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingAnyTags($tags = array())
|
||||||
|
{
|
||||||
|
return $this->_slowBackend->getIdsMatchingAnyTags($tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the filling percentage of the backend storage
|
||||||
|
*
|
||||||
|
* @return int integer between 0 and 100
|
||||||
|
*/
|
||||||
|
public function getFillingPercentage()
|
||||||
|
{
|
||||||
|
return $this->_slowBackend->getFillingPercentage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of metadatas for the given cache id
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - expire : the expire timestamp
|
||||||
|
* - tags : a string array of tags
|
||||||
|
* - mtime : timestamp of last modification time
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return array array of metadatas (false if the cache id is not found)
|
||||||
|
*/
|
||||||
|
public function getMetadatas($id)
|
||||||
|
{
|
||||||
|
return $this->_slowBackend->getMetadatas($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give (if possible) an extra lifetime to the given cache id
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param int $extraLifetime
|
||||||
|
* @return boolean true if ok
|
||||||
|
*/
|
||||||
|
public function touch($id, $extraLifetime)
|
||||||
|
{
|
||||||
|
return $this->_slowBackend->touch($id, $extraLifetime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an associative array of capabilities (booleans) of the backend
|
||||||
|
*
|
||||||
|
* The array must include these keys :
|
||||||
|
* - automatic_cleaning (is automating cleaning necessary)
|
||||||
|
* - tags (are tags supported)
|
||||||
|
* - expired_read (is it possible to read expired cache records
|
||||||
|
* (for doNotTestCacheValidity option for example))
|
||||||
|
* - priority does the backend deal with priority when saving
|
||||||
|
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||||
|
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||||
|
*
|
||||||
|
* @return array associative of with capabilities
|
||||||
|
*/
|
||||||
|
public function getCapabilities()
|
||||||
|
{
|
||||||
|
$slowBackendCapabilities = $this->_slowBackend->getCapabilities();
|
||||||
|
return array(
|
||||||
|
'automatic_cleaning' => $slowBackendCapabilities['automatic_cleaning'],
|
||||||
|
'tags' => $slowBackendCapabilities['tags'],
|
||||||
|
'expired_read' => $slowBackendCapabilities['expired_read'],
|
||||||
|
'priority' => $slowBackendCapabilities['priority'],
|
||||||
|
'infinite_lifetime' => $slowBackendCapabilities['infinite_lifetime'],
|
||||||
|
'get_list' => $slowBackendCapabilities['get_list']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare a serialized array to store datas and metadatas informations
|
||||||
|
*
|
||||||
|
* @param string $data data to store
|
||||||
|
* @param int $lifetime original lifetime
|
||||||
|
* @param int $priority priority
|
||||||
|
* @return string serialize array to store into cache
|
||||||
|
*/
|
||||||
|
private function _prepareData($data, $lifetime, $priority)
|
||||||
|
{
|
||||||
|
$lt = $lifetime;
|
||||||
|
if ($lt === null) {
|
||||||
|
$lt = 9999999999;
|
||||||
|
}
|
||||||
|
return serialize(array(
|
||||||
|
'data' => $data,
|
||||||
|
'lifetime' => $lifetime,
|
||||||
|
'expire' => time() + $lt,
|
||||||
|
'priority' => $priority
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute and return the lifetime for the fast backend
|
||||||
|
*
|
||||||
|
* @param int $lifetime original lifetime
|
||||||
|
* @param int $priority priority
|
||||||
|
* @param int $maxLifetime maximum lifetime
|
||||||
|
* @return int lifetime for the fast backend
|
||||||
|
*/
|
||||||
|
private function _getFastLifetime($lifetime, $priority, $maxLifetime = null)
|
||||||
|
{
|
||||||
|
if ($lifetime === null) {
|
||||||
|
// if lifetime is null, we have an infinite lifetime
|
||||||
|
// we need to use arbitrary lifetimes
|
||||||
|
$fastLifetime = (int) (2592000 / (11 - $priority));
|
||||||
|
} else {
|
||||||
|
$fastLifetime = (int) ($lifetime / (11 - $priority));
|
||||||
|
}
|
||||||
|
if (($maxLifetime !== null) && ($maxLifetime >= 0)) {
|
||||||
|
if ($fastLifetime > $maxLifetime) {
|
||||||
|
return $maxLifetime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $fastLifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUBLIC METHOD FOR UNIT TESTING ONLY !
|
||||||
|
*
|
||||||
|
* Force a cache record to expire
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
*/
|
||||||
|
public function ___expire($id)
|
||||||
|
{
|
||||||
|
$this->_fastBackend->remove($id);
|
||||||
|
$this->_slowBackend->___expire($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _getFastFillingPercentage($mode)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($mode == 'saving') {
|
||||||
|
// mode saving
|
||||||
|
if ($this->_fastBackendFillingPercentage === null) {
|
||||||
|
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
|
||||||
|
} else {
|
||||||
|
$rand = rand(1, $this->_options['stats_update_factor']);
|
||||||
|
if ($rand == 1) {
|
||||||
|
// we force a refresh
|
||||||
|
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// mode loading
|
||||||
|
// we compute the percentage only if it's not available in cache
|
||||||
|
if ($this->_fastBackendFillingPercentage === null) {
|
||||||
|
$this->_fastBackendFillingPercentage = $this->_fastBackend->getFillingPercentage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->_fastBackendFillingPercentage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
216
libraries/Zend/Cache/Backend/Xcache.php
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Xcache.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend_Interface
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend/Interface.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Backend_Xcache extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log message
|
||||||
|
*/
|
||||||
|
const TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::clean() : tags are unsupported by the Xcache backend';
|
||||||
|
const TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::save() : tags are unsupported by the Xcache backend';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available options
|
||||||
|
*
|
||||||
|
* =====> (string) user :
|
||||||
|
* xcache.admin.user (necessary for the clean() method)
|
||||||
|
*
|
||||||
|
* =====> (string) password :
|
||||||
|
* xcache.admin.pass (clear, not MD5) (necessary for the clean() method)
|
||||||
|
*
|
||||||
|
* @var array available options
|
||||||
|
*/
|
||||||
|
protected $_options = array(
|
||||||
|
'user' => null,
|
||||||
|
'password' => null
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options associative array of options
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
if (!extension_loaded('xcache')) {
|
||||||
|
Zend_Cache::throwException('The xcache extension must be loaded for using this backend !');
|
||||||
|
}
|
||||||
|
parent::__construct($options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* WARNING $doNotTestCacheValidity=true is unsupported by the Xcache backend
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||||
|
* @return string cached datas (or false)
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false)
|
||||||
|
{
|
||||||
|
if ($doNotTestCacheValidity) {
|
||||||
|
$this->_log("Zend_Cache_Backend_Xcache::load() : \$doNotTestCacheValidity=true is unsupported by the Xcache backend");
|
||||||
|
}
|
||||||
|
$tmp = xcache_get($id);
|
||||||
|
if (is_array($tmp)) {
|
||||||
|
return $tmp[0];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available or not (for the given id)
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
if (xcache_isset($id)) {
|
||||||
|
$tmp = xcache_get($id);
|
||||||
|
if (is_array($tmp)) {
|
||||||
|
return $tmp[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some string datas into a cache record
|
||||||
|
*
|
||||||
|
* Note : $data is always "string" (serialization is done by the
|
||||||
|
* core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $data datas to cache
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||||
|
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||||
|
{
|
||||||
|
$lifetime = $this->getLifetime($specificLifetime);
|
||||||
|
$result = xcache_set($id, array($data, time()), $lifetime);
|
||||||
|
if (count($tags) > 0) {
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function remove($id)
|
||||||
|
{
|
||||||
|
return xcache_unset($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||||
|
* 'old' => unsupported
|
||||||
|
* 'matchingTag' => unsupported
|
||||||
|
* 'notMatchingTag' => unsupported
|
||||||
|
* 'matchingAnyTag' => unsupported
|
||||||
|
*
|
||||||
|
* @param string $mode clean mode
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||||
|
{
|
||||||
|
switch ($mode) {
|
||||||
|
case Zend_Cache::CLEANING_MODE_ALL:
|
||||||
|
// Necessary because xcache_clear_cache() need basic authentification
|
||||||
|
$backup = array();
|
||||||
|
if (isset($_SERVER['PHP_AUTH_USER'])) {
|
||||||
|
$backup['PHP_AUTH_USER'] = $_SERVER['PHP_AUTH_USER'];
|
||||||
|
}
|
||||||
|
if (isset($_SERVER['PHP_AUTH_PW'])) {
|
||||||
|
$backup['PHP_AUTH_PW'] = $_SERVER['PHP_AUTH_PW'];
|
||||||
|
}
|
||||||
|
if ($this->_options['user']) {
|
||||||
|
$_SERVER['PHP_AUTH_USER'] = $this->_options['user'];
|
||||||
|
}
|
||||||
|
if ($this->_options['password']) {
|
||||||
|
$_SERVER['PHP_AUTH_PW'] = $this->_options['password'];
|
||||||
|
}
|
||||||
|
xcache_clear_cache(XC_TYPE_VAR, 0);
|
||||||
|
if (isset($backup['PHP_AUTH_USER'])) {
|
||||||
|
$_SERVER['PHP_AUTH_USER'] = $backup['PHP_AUTH_USER'];
|
||||||
|
$_SERVER['PHP_AUTH_PW'] = $backup['PHP_AUTH_PW'];
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_OLD:
|
||||||
|
$this->_log("Zend_Cache_Backend_Xcache::clean() : CLEANING_MODE_OLD is unsupported by the Xcache backend");
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||||
|
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||||
|
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the automatic cleaning is available for the backend
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isAutomaticCleaningAvailable()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
317
libraries/Zend/Cache/Backend/ZendPlatform.php
Normal file
@ -0,0 +1,317 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: ZendPlatform.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend_Interface
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Backend_Interface
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Backend/Interface.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Impementation of Zend Cache Backend using the Zend Platform (Output Content Caching)
|
||||||
|
*
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Backend_ZendPlatform extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* internal ZP prefix
|
||||||
|
*/
|
||||||
|
const TAGS_PREFIX = "internal_ZPtag:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* Validate that the Zend Platform is loaded and licensed
|
||||||
|
*
|
||||||
|
* @param array $options Associative array of options
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
if (!function_exists('accelerator_license_info')) {
|
||||||
|
Zend_Cache::throwException('The Zend Platform extension must be loaded for using this backend !');
|
||||||
|
}
|
||||||
|
if (!function_exists('accelerator_get_configuration')) {
|
||||||
|
$licenseInfo = accelerator_license_info();
|
||||||
|
Zend_Cache::throwException('The Zend Platform extension is not loaded correctly: '.$licenseInfo['failure_reason']);
|
||||||
|
}
|
||||||
|
$accConf = accelerator_get_configuration();
|
||||||
|
if (@!$accConf['output_cache_licensed']) {
|
||||||
|
Zend_Cache::throwException('The Zend Platform extension does not have the proper license to use content caching features');
|
||||||
|
}
|
||||||
|
if (@!$accConf['output_cache_enabled']) {
|
||||||
|
Zend_Cache::throwException('The Zend Platform content caching feature must be enabled for using this backend, set the \'zend_accelerator.output_cache_enabled\' directive to On !');
|
||||||
|
}
|
||||||
|
if (!is_writable($accConf['output_cache_dir'])) {
|
||||||
|
Zend_Cache::throwException('The cache copies directory \''. ini_get('zend_accelerator.output_cache_dir') .'\' must be writable !');
|
||||||
|
}
|
||||||
|
parent:: __construct($options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||||
|
* @return string Cached data (or false)
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false)
|
||||||
|
{
|
||||||
|
// doNotTestCacheValidity implemented by giving zero lifetime to the cache
|
||||||
|
if ($doNotTestCacheValidity) {
|
||||||
|
$lifetime = 0;
|
||||||
|
} else {
|
||||||
|
$lifetime = $this->_directives['lifetime'];
|
||||||
|
}
|
||||||
|
$res = output_cache_get($id, $lifetime);
|
||||||
|
if($res) {
|
||||||
|
return $res[0];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available or not (for the given id)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return mixed|false false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
$result = output_cache_get($id, $this->_directives['lifetime']);
|
||||||
|
if ($result) {
|
||||||
|
return $result[1];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some string datas into a cache record
|
||||||
|
*
|
||||||
|
* Note : $data is always "string" (serialization is done by the
|
||||||
|
* core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $data Data to cache
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||||
|
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||||
|
{
|
||||||
|
if (!($specificLifetime === false)) {
|
||||||
|
$this->_log("Zend_Cache_Backend_ZendPlatform::save() : non false specifc lifetime is unsuported for this backend");
|
||||||
|
}
|
||||||
|
|
||||||
|
$lifetime = $this->_directives['lifetime'];
|
||||||
|
$result1 = output_cache_put($id, array($data, time()));
|
||||||
|
$result2 = (count($tags) == 0);
|
||||||
|
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$tagid = self::TAGS_PREFIX.$tag;
|
||||||
|
$old_tags = output_cache_get($tagid, $lifetime);
|
||||||
|
if ($old_tags === false) {
|
||||||
|
$old_tags = array();
|
||||||
|
}
|
||||||
|
$old_tags[$id] = $id;
|
||||||
|
output_cache_remove_key($tagid);
|
||||||
|
$result2 = output_cache_put($tagid, $old_tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result1 && $result2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function remove($id)
|
||||||
|
{
|
||||||
|
return output_cache_remove_key($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||||
|
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||||
|
* This mode is not supported in this backend
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => unsupported
|
||||||
|
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
*
|
||||||
|
* @param string $mode Clean mode
|
||||||
|
* @param array $tags Array of tags
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||||
|
{
|
||||||
|
switch ($mode) {
|
||||||
|
case Zend_Cache::CLEANING_MODE_ALL:
|
||||||
|
case Zend_Cache::CLEANING_MODE_OLD:
|
||||||
|
$cache_dir = ini_get('zend_accelerator.output_cache_dir');
|
||||||
|
if (!$cache_dir) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$cache_dir .= '/.php_cache_api/';
|
||||||
|
return $this->_clean($cache_dir, $mode);
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||||
|
$idlist = null;
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime']);
|
||||||
|
if ($idlist) {
|
||||||
|
$idlist = array_intersect_assoc($idlist, $next_idlist);
|
||||||
|
} else {
|
||||||
|
$idlist = $next_idlist;
|
||||||
|
}
|
||||||
|
if (count($idlist) == 0) {
|
||||||
|
// if ID list is already empty - we may skip checking other IDs
|
||||||
|
$idlist = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($idlist) {
|
||||||
|
foreach ($idlist as $id) {
|
||||||
|
output_cache_remove_key($id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||||
|
$this->_log("Zend_Cache_Backend_ZendPlatform::clean() : CLEANING_MODE_NOT_MATCHING_TAG is not supported by the Zend Platform backend");
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||||
|
$idlist = null;
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$next_idlist = output_cache_get(self::TAGS_PREFIX.$tag, $this->_directives['lifetime']);
|
||||||
|
if ($idlist) {
|
||||||
|
$idlist = array_merge_recursive($idlist, $next_idlist);
|
||||||
|
} else {
|
||||||
|
$idlist = $next_idlist;
|
||||||
|
}
|
||||||
|
if (count($idlist) == 0) {
|
||||||
|
// if ID list is already empty - we may skip checking other IDs
|
||||||
|
$idlist = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($idlist) {
|
||||||
|
foreach ($idlist as $id) {
|
||||||
|
output_cache_remove_key($id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean a directory and recursivly go over it's subdirectories
|
||||||
|
*
|
||||||
|
* Remove all the cached files that need to be cleaned (according to mode and files mtime)
|
||||||
|
*
|
||||||
|
* @param string $dir Path of directory ot clean
|
||||||
|
* @param string $mode The same parameter as in Zend_Cache_Backend_ZendPlatform::clean()
|
||||||
|
* @return boolean True if ok
|
||||||
|
*/
|
||||||
|
private function _clean($dir, $mode)
|
||||||
|
{
|
||||||
|
$d = @dir($dir);
|
||||||
|
if (!$d) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$result = true;
|
||||||
|
while (false !== ($file = $d->read())) {
|
||||||
|
if ($file == '.' || $file == '..') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$file = $d->path . $file;
|
||||||
|
if (is_dir($file)) {
|
||||||
|
$result = ($this->_clean($file .'/', $mode)) && ($result);
|
||||||
|
} else {
|
||||||
|
if ($mode == Zend_Cache::CLEANING_MODE_ALL) {
|
||||||
|
$result = ($this->_remove($file)) && ($result);
|
||||||
|
} else if ($mode == Zend_Cache::CLEANING_MODE_OLD) {
|
||||||
|
// Files older than lifetime get deleted from cache
|
||||||
|
if ($this->_directives['lifetime'] !== null) {
|
||||||
|
if ((time() - @filemtime($file)) > $this->_directives['lifetime']) {
|
||||||
|
$result = ($this->_remove($file)) && ($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$d->close();
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a file
|
||||||
|
*
|
||||||
|
* If we can't remove the file (because of locks or any problem), we will touch
|
||||||
|
* the file to invalidate it
|
||||||
|
*
|
||||||
|
* @param string $file Complete file path
|
||||||
|
* @return boolean True if ok
|
||||||
|
*/
|
||||||
|
private function _remove($file)
|
||||||
|
{
|
||||||
|
if (!@unlink($file)) {
|
||||||
|
# If we can't remove the file (because of locks or any problem), we will touch
|
||||||
|
# the file to invalidate it
|
||||||
|
$this->_log("Zend_Cache_Backend_ZendPlatform::_remove() : we can't remove $file => we are going to try to invalidate it");
|
||||||
|
if ($this->_directives['lifetime'] === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!file_exists($file)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return @touch($file, time() - 2*abs($this->_directives['lifetime']));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
207
libraries/Zend/Cache/Backend/ZendServer.php
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: ZendServer.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @see Zend_Cache_Backend_Interface */
|
||||||
|
require_once 'Zend/Cache/Backend/Interface.php';
|
||||||
|
|
||||||
|
/** @see Zend_Cache_Backend */
|
||||||
|
require_once 'Zend/Cache/Backend.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
abstract class Zend_Cache_Backend_ZendServer extends Zend_Cache_Backend implements Zend_Cache_Backend_Interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Available options
|
||||||
|
*
|
||||||
|
* =====> (string) namespace :
|
||||||
|
* Namespace to be used for chaching operations
|
||||||
|
*
|
||||||
|
* @var array available options
|
||||||
|
*/
|
||||||
|
protected $_options = array(
|
||||||
|
'namespace' => 'zendframework'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store data
|
||||||
|
*
|
||||||
|
* @param mixed $data Object to store
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param int $timeToLive Time to live in seconds
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
*/
|
||||||
|
abstract protected function _store($data, $id, $timeToLive);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch data
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
*/
|
||||||
|
abstract protected function _fetch($id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unset data
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
*/
|
||||||
|
abstract protected function _unset($id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear cache
|
||||||
|
*/
|
||||||
|
abstract protected function _clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||||
|
* @return string cached datas (or false)
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false)
|
||||||
|
{
|
||||||
|
$tmp = $this->_fetch($id);
|
||||||
|
if ($tmp !== null) {
|
||||||
|
return $tmp;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available or not (for the given id)
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
$tmp = $this->_fetch('internal-metadatas---' . $id);
|
||||||
|
if ($tmp !== false) {
|
||||||
|
if (!is_array($tmp) || !isset($tmp['mtime'])) {
|
||||||
|
Zend_Cache::throwException('Cache metadata for \'' . $id . '\' id is corrupted' );
|
||||||
|
}
|
||||||
|
return $tmp['mtime'];
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute & return the expire time
|
||||||
|
*
|
||||||
|
* @return int expire time (unix timestamp)
|
||||||
|
*/
|
||||||
|
private function _expireTime($lifetime)
|
||||||
|
{
|
||||||
|
if ($lifetime === null) {
|
||||||
|
return 9999999999;
|
||||||
|
}
|
||||||
|
return time() + $lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some string datas into a cache record
|
||||||
|
*
|
||||||
|
* Note : $data is always "string" (serialization is done by the
|
||||||
|
* core not by the backend)
|
||||||
|
*
|
||||||
|
* @param string $data datas to cache
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||||
|
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||||
|
{
|
||||||
|
$lifetime = $this->getLifetime($specificLifetime);
|
||||||
|
$metadatas = array(
|
||||||
|
'mtime' => time(),
|
||||||
|
'expire' => $this->_expireTime($lifetime),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (count($tags) > 0) {
|
||||||
|
$this->_log('Zend_Cache_Backend_ZendServer::save() : tags are unsupported by the ZendServer backends');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_store($data, $id, $lifetime) &&
|
||||||
|
$this->_store($metadatas, 'internal-metadatas---' . $id, $lifetime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache record
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function remove($id)
|
||||||
|
{
|
||||||
|
$result1 = $this->_unset($id);
|
||||||
|
$result2 = $this->_unset('internal-metadatas---' . $id);
|
||||||
|
|
||||||
|
return $result1 && $result2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean some cache records
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||||
|
* 'old' => unsupported
|
||||||
|
* 'matchingTag' => unsupported
|
||||||
|
* 'notMatchingTag' => unsupported
|
||||||
|
* 'matchingAnyTag' => unsupported
|
||||||
|
*
|
||||||
|
* @param string $mode clean mode
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||||
|
{
|
||||||
|
switch ($mode) {
|
||||||
|
case Zend_Cache::CLEANING_MODE_ALL:
|
||||||
|
$this->_clear();
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_OLD:
|
||||||
|
$this->_log("Zend_Cache_Backend_ZendServer::clean() : CLEANING_MODE_OLD is unsupported by the Zend Server backends.");
|
||||||
|
break;
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||||
|
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||||
|
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||||
|
$this->_clear();
|
||||||
|
$this->_log('Zend_Cache_Backend_ZendServer::clean() : tags are unsupported by the Zend Server backends.');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
100
libraries/Zend/Cache/Backend/ZendServer/Disk.php
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Disk.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @see Zend_Cache_Backend_Interface */
|
||||||
|
require_once 'Zend/Cache/Backend/Interface.php';
|
||||||
|
|
||||||
|
/** @see Zend_Cache_Backend_ZendServer */
|
||||||
|
require_once 'Zend/Cache/Backend/ZendServer.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Backend_ZendServer_Disk extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options associative array of options
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
if (!function_exists('zend_disk_cache_store')) {
|
||||||
|
Zend_Cache::throwException('Zend_Cache_ZendServer_Disk backend has to be used within Zend Server environment.');
|
||||||
|
}
|
||||||
|
parent::__construct($options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store data
|
||||||
|
*
|
||||||
|
* @param mixed $data Object to store
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param int $timeToLive Time to live in seconds
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
protected function _store($data, $id, $timeToLive)
|
||||||
|
{
|
||||||
|
if (zend_disk_cache_store($this->_options['namespace'] . '::' . $id,
|
||||||
|
$data,
|
||||||
|
$timeToLive) === false) {
|
||||||
|
$this->_log('Store operation failed.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch data
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
*/
|
||||||
|
protected function _fetch($id)
|
||||||
|
{
|
||||||
|
return zend_disk_cache_fetch($this->_options['namespace'] . '::' . $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unset data
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
protected function _unset($id)
|
||||||
|
{
|
||||||
|
return zend_disk_cache_delete($this->_options['namespace'] . '::' . $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear cache
|
||||||
|
*/
|
||||||
|
protected function _clear()
|
||||||
|
{
|
||||||
|
zend_disk_cache_clear($this->_options['namespace']);
|
||||||
|
}
|
||||||
|
}
|
100
libraries/Zend/Cache/Backend/ZendServer/ShMem.php
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: ShMem.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @see Zend_Cache_Backend_Interface */
|
||||||
|
require_once 'Zend/Cache/Backend/Interface.php';
|
||||||
|
|
||||||
|
/** @see Zend_Cache_Backend_ZendServer */
|
||||||
|
require_once 'Zend/Cache/Backend/ZendServer.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Backend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Backend_ZendServer_ShMem extends Zend_Cache_Backend_ZendServer implements Zend_Cache_Backend_Interface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options associative array of options
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
if (!function_exists('zend_shm_cache_store')) {
|
||||||
|
Zend_Cache::throwException('Zend_Cache_ZendServer_ShMem backend has to be used within Zend Server environment.');
|
||||||
|
}
|
||||||
|
parent::__construct($options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store data
|
||||||
|
*
|
||||||
|
* @param mixed $data Object to store
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param int $timeToLive Time to live in seconds
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function _store($data, $id, $timeToLive)
|
||||||
|
{
|
||||||
|
if (zend_shm_cache_store($this->_options['namespace'] . '::' . $id,
|
||||||
|
$data,
|
||||||
|
$timeToLive) === false) {
|
||||||
|
$this->_log('Store operation failed.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch data
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
*/
|
||||||
|
protected function _fetch($id)
|
||||||
|
{
|
||||||
|
return zend_shm_cache_fetch($this->_options['namespace'] . '::' . $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unset data
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return boolean true if no problem
|
||||||
|
*/
|
||||||
|
protected function _unset($id)
|
||||||
|
{
|
||||||
|
return zend_shm_cache_delete($this->_options['namespace'] . '::' . $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear cache
|
||||||
|
*/
|
||||||
|
protected function _clear()
|
||||||
|
{
|
||||||
|
zend_shm_cache_clear($this->_options['namespace']);
|
||||||
|
}
|
||||||
|
}
|
757
libraries/Zend/Cache/Core.php
Normal file
@ -0,0 +1,757 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Core.php 22652 2010-07-21 04:30:24Z ramon $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Messages
|
||||||
|
*/
|
||||||
|
const BACKEND_NOT_SUPPORTS_TAG = 'tags are not supported by the current backend';
|
||||||
|
const BACKEND_NOT_IMPLEMENTS_EXTENDED_IF = 'Current backend doesn\'t implement the Zend_Cache_Backend_ExtendedInterface, so this method is not available';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backend Object
|
||||||
|
*
|
||||||
|
* @var Zend_Cache_Backend_Interface $_backend
|
||||||
|
*/
|
||||||
|
protected $_backend = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available options
|
||||||
|
*
|
||||||
|
* ====> (boolean) write_control :
|
||||||
|
* - Enable / disable write control (the cache is read just after writing to detect corrupt entries)
|
||||||
|
* - Enable write control will lightly slow the cache writing but not the cache reading
|
||||||
|
* Write control can detect some corrupt cache files but maybe it's not a perfect control
|
||||||
|
*
|
||||||
|
* ====> (boolean) caching :
|
||||||
|
* - Enable / disable caching
|
||||||
|
* (can be very useful for the debug of cached scripts)
|
||||||
|
*
|
||||||
|
* =====> (string) cache_id_prefix :
|
||||||
|
* - prefix for cache ids (namespace)
|
||||||
|
*
|
||||||
|
* ====> (boolean) automatic_serialization :
|
||||||
|
* - Enable / disable automatic serialization
|
||||||
|
* - It can be used to save directly datas which aren't strings (but it's slower)
|
||||||
|
*
|
||||||
|
* ====> (int) automatic_cleaning_factor :
|
||||||
|
* - Disable / Tune the automatic cleaning process
|
||||||
|
* - The automatic cleaning process destroy too old (for the given life time)
|
||||||
|
* cache files when a new cache file is written :
|
||||||
|
* 0 => no automatic cache cleaning
|
||||||
|
* 1 => systematic cache cleaning
|
||||||
|
* x (integer) > 1 => automatic cleaning randomly 1 times on x cache write
|
||||||
|
*
|
||||||
|
* ====> (int) lifetime :
|
||||||
|
* - Cache lifetime (in seconds)
|
||||||
|
* - If null, the cache is valid forever.
|
||||||
|
*
|
||||||
|
* ====> (boolean) logging :
|
||||||
|
* - If set to true, logging is activated (but the system is slower)
|
||||||
|
*
|
||||||
|
* ====> (boolean) ignore_user_abort
|
||||||
|
* - If set to true, the core will set the ignore_user_abort PHP flag inside the
|
||||||
|
* save() method to avoid cache corruptions in some cases (default false)
|
||||||
|
*
|
||||||
|
* @var array $_options available options
|
||||||
|
*/
|
||||||
|
protected $_options = array(
|
||||||
|
'write_control' => true,
|
||||||
|
'caching' => true,
|
||||||
|
'cache_id_prefix' => null,
|
||||||
|
'automatic_serialization' => false,
|
||||||
|
'automatic_cleaning_factor' => 10,
|
||||||
|
'lifetime' => 3600,
|
||||||
|
'logging' => false,
|
||||||
|
'logger' => null,
|
||||||
|
'ignore_user_abort' => false
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of options which have to be transfered to backend
|
||||||
|
*
|
||||||
|
* @var array $_directivesList
|
||||||
|
*/
|
||||||
|
protected static $_directivesList = array('lifetime', 'logging', 'logger');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Not used for the core, just a sort a hint to get a common setOption() method (for the core and for frontends)
|
||||||
|
*
|
||||||
|
* @var array $_specificOptions
|
||||||
|
*/
|
||||||
|
protected $_specificOptions = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last used cache id
|
||||||
|
*
|
||||||
|
* @var string $_lastId
|
||||||
|
*/
|
||||||
|
private $_lastId = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if the backend implements Zend_Cache_Backend_ExtendedInterface
|
||||||
|
*
|
||||||
|
* @var boolean $_extendedBackend
|
||||||
|
*/
|
||||||
|
protected $_extendedBackend = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of capabilities of the backend (only if it implements Zend_Cache_Backend_ExtendedInterface)
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_backendCapabilities = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array|Zend_Config $options Associative array of options or Zend_Config instance
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($options = array())
|
||||||
|
{
|
||||||
|
if ($options instanceof Zend_Config) {
|
||||||
|
$options = $options->toArray();
|
||||||
|
}
|
||||||
|
if (!is_array($options)) {
|
||||||
|
Zend_Cache::throwException("Options passed were not an array"
|
||||||
|
. " or Zend_Config instance.");
|
||||||
|
}
|
||||||
|
while (list($name, $value) = each($options)) {
|
||||||
|
$this->setOption($name, $value);
|
||||||
|
}
|
||||||
|
$this->_loggerSanity();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set options using an instance of type Zend_Config
|
||||||
|
*
|
||||||
|
* @param Zend_Config $config
|
||||||
|
* @return Zend_Cache_Core
|
||||||
|
*/
|
||||||
|
public function setConfig(Zend_Config $config)
|
||||||
|
{
|
||||||
|
$options = $config->toArray();
|
||||||
|
while (list($name, $value) = each($options)) {
|
||||||
|
$this->setOption($name, $value);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the backend
|
||||||
|
*
|
||||||
|
* @param Zend_Cache_Backend $backendObject
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setBackend(Zend_Cache_Backend $backendObject)
|
||||||
|
{
|
||||||
|
$this->_backend= $backendObject;
|
||||||
|
// some options (listed in $_directivesList) have to be given
|
||||||
|
// to the backend too (even if they are not "backend specific")
|
||||||
|
$directives = array();
|
||||||
|
foreach (Zend_Cache_Core::$_directivesList as $directive) {
|
||||||
|
$directives[$directive] = $this->_options[$directive];
|
||||||
|
}
|
||||||
|
$this->_backend->setDirectives($directives);
|
||||||
|
if (in_array('Zend_Cache_Backend_ExtendedInterface', class_implements($this->_backend))) {
|
||||||
|
$this->_extendedBackend = true;
|
||||||
|
$this->_backendCapabilities = $this->_backend->getCapabilities();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the backend
|
||||||
|
*
|
||||||
|
* @return Zend_Cache_Backend backend object
|
||||||
|
*/
|
||||||
|
public function getBackend()
|
||||||
|
{
|
||||||
|
return $this->_backend;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public frontend to set an option
|
||||||
|
*
|
||||||
|
* There is an additional validation (relatively to the protected _setOption method)
|
||||||
|
*
|
||||||
|
* @param string $name Name of the option
|
||||||
|
* @param mixed $value Value of the option
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setOption($name, $value)
|
||||||
|
{
|
||||||
|
if (!is_string($name)) {
|
||||||
|
Zend_Cache::throwException("Incorrect option name : $name");
|
||||||
|
}
|
||||||
|
$name = strtolower($name);
|
||||||
|
if (array_key_exists($name, $this->_options)) {
|
||||||
|
// This is a Core option
|
||||||
|
$this->_setOption($name, $value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (array_key_exists($name, $this->_specificOptions)) {
|
||||||
|
// This a specic option of this frontend
|
||||||
|
$this->_specificOptions[$name] = $value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public frontend to get an option value
|
||||||
|
*
|
||||||
|
* @param string $name Name of the option
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return mixed option value
|
||||||
|
*/
|
||||||
|
public function getOption($name)
|
||||||
|
{
|
||||||
|
if (is_string($name)) {
|
||||||
|
$name = strtolower($name);
|
||||||
|
if (array_key_exists($name, $this->_options)) {
|
||||||
|
// This is a Core option
|
||||||
|
return $this->_options[$name];
|
||||||
|
}
|
||||||
|
if (array_key_exists($name, $this->_specificOptions)) {
|
||||||
|
// This a specic option of this frontend
|
||||||
|
return $this->_specificOptions[$name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Zend_Cache::throwException("Incorrect option name : $name");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set an option
|
||||||
|
*
|
||||||
|
* @param string $name Name of the option
|
||||||
|
* @param mixed $value Value of the option
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function _setOption($name, $value)
|
||||||
|
{
|
||||||
|
if (!is_string($name) || !array_key_exists($name, $this->_options)) {
|
||||||
|
Zend_Cache::throwException("Incorrect option name : $name");
|
||||||
|
}
|
||||||
|
if ($name == 'lifetime' && empty($value)) {
|
||||||
|
$value = null;
|
||||||
|
}
|
||||||
|
$this->_options[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force a new lifetime
|
||||||
|
*
|
||||||
|
* The new value is set for the core/frontend but for the backend too (directive)
|
||||||
|
*
|
||||||
|
* @param int $newLifetime New lifetime (in seconds)
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setLifetime($newLifetime)
|
||||||
|
{
|
||||||
|
$this->_options['lifetime'] = $newLifetime;
|
||||||
|
$this->_backend->setDirectives(array(
|
||||||
|
'lifetime' => $newLifetime
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||||
|
* @param boolean $doNotUnserialize Do not serialize (even if automatic_serialization is true) => for internal use
|
||||||
|
* @return mixed|false Cached datas
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false)
|
||||||
|
{
|
||||||
|
if (!$this->_options['caching']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$id = $this->_id($id); // cache id may need prefix
|
||||||
|
$this->_lastId = $id;
|
||||||
|
self::_validateIdOrTag($id);
|
||||||
|
$data = $this->_backend->load($id, $doNotTestCacheValidity);
|
||||||
|
if ($data===false) {
|
||||||
|
// no cache available
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((!$doNotUnserialize) && $this->_options['automatic_serialization']) {
|
||||||
|
// we need to unserialize before sending the result
|
||||||
|
return unserialize($data);
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return int|false Last modified time of cache entry if it is available, false otherwise
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
if (!$this->_options['caching']) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$id = $this->_id($id); // cache id may need prefix
|
||||||
|
self::_validateIdOrTag($id);
|
||||||
|
$this->_lastId = $id;
|
||||||
|
return $this->_backend->test($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save some data in a cache
|
||||||
|
*
|
||||||
|
* @param mixed $data Data to put in cache (can be another type than string if automatic_serialization is on)
|
||||||
|
* @param string $id Cache id (if not set, the last cache id will be used)
|
||||||
|
* @param array $tags Cache tags
|
||||||
|
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return boolean True if no problem
|
||||||
|
*/
|
||||||
|
public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8)
|
||||||
|
{
|
||||||
|
if (!$this->_options['caching']) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ($id === null) {
|
||||||
|
$id = $this->_lastId;
|
||||||
|
} else {
|
||||||
|
$id = $this->_id($id);
|
||||||
|
}
|
||||||
|
self::_validateIdOrTag($id);
|
||||||
|
self::_validateTagsArray($tags);
|
||||||
|
if ($this->_options['automatic_serialization']) {
|
||||||
|
// we need to serialize datas before storing them
|
||||||
|
$data = serialize($data);
|
||||||
|
} else {
|
||||||
|
if (!is_string($data)) {
|
||||||
|
Zend_Cache::throwException("Datas must be string or set automatic_serialization = true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// automatic cleaning
|
||||||
|
if ($this->_options['automatic_cleaning_factor'] > 0) {
|
||||||
|
$rand = rand(1, $this->_options['automatic_cleaning_factor']);
|
||||||
|
if ($rand==1) {
|
||||||
|
if ($this->_extendedBackend) {
|
||||||
|
// New way
|
||||||
|
if ($this->_backendCapabilities['automatic_cleaning']) {
|
||||||
|
$this->clean(Zend_Cache::CLEANING_MODE_OLD);
|
||||||
|
} else {
|
||||||
|
$this->_log('Zend_Cache_Core::save() / automatic cleaning is not available/necessary with this backend');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Deprecated way (will be removed in next major version)
|
||||||
|
if (method_exists($this->_backend, 'isAutomaticCleaningAvailable') && ($this->_backend->isAutomaticCleaningAvailable())) {
|
||||||
|
$this->clean(Zend_Cache::CLEANING_MODE_OLD);
|
||||||
|
} else {
|
||||||
|
$this->_log('Zend_Cache_Core::save() / automatic cleaning is not available/necessary with this backend');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->_options['ignore_user_abort']) {
|
||||||
|
$abort = ignore_user_abort(true);
|
||||||
|
}
|
||||||
|
if (($this->_extendedBackend) && ($this->_backendCapabilities['priority'])) {
|
||||||
|
$result = $this->_backend->save($data, $id, $tags, $specificLifetime, $priority);
|
||||||
|
} else {
|
||||||
|
$result = $this->_backend->save($data, $id, $tags, $specificLifetime);
|
||||||
|
}
|
||||||
|
if ($this->_options['ignore_user_abort']) {
|
||||||
|
ignore_user_abort($abort);
|
||||||
|
}
|
||||||
|
if (!$result) {
|
||||||
|
// maybe the cache is corrupted, so we remove it !
|
||||||
|
if ($this->_options['logging']) {
|
||||||
|
$this->_log("Zend_Cache_Core::save() : impossible to save cache (id=$id)");
|
||||||
|
}
|
||||||
|
$this->remove($id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($this->_options['write_control']) {
|
||||||
|
$data2 = $this->_backend->load($id, true);
|
||||||
|
if ($data!=$data2) {
|
||||||
|
$this->_log('Zend_Cache_Core::save() / write_control : written and read data do not match');
|
||||||
|
$this->_backend->remove($id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a cache
|
||||||
|
*
|
||||||
|
* @param string $id Cache id to remove
|
||||||
|
* @return boolean True if ok
|
||||||
|
*/
|
||||||
|
public function remove($id)
|
||||||
|
{
|
||||||
|
if (!$this->_options['caching']) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$id = $this->_id($id); // cache id may need prefix
|
||||||
|
self::_validateIdOrTag($id);
|
||||||
|
return $this->_backend->remove($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean cache entries
|
||||||
|
*
|
||||||
|
* Available modes are :
|
||||||
|
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||||
|
* 'old' => remove too old cache entries ($tags is not used)
|
||||||
|
* 'matchingTag' => remove cache entries matching all given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* 'notMatchingTag' => remove cache entries not matching one of the given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
* 'matchingAnyTag' => remove cache entries matching any given tags
|
||||||
|
* ($tags can be an array of strings or a single string)
|
||||||
|
*
|
||||||
|
* @param string $mode
|
||||||
|
* @param array|string $tags
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return boolean True if ok
|
||||||
|
*/
|
||||||
|
public function clean($mode = 'all', $tags = array())
|
||||||
|
{
|
||||||
|
if (!$this->_options['caching']) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!in_array($mode, array(Zend_Cache::CLEANING_MODE_ALL,
|
||||||
|
Zend_Cache::CLEANING_MODE_OLD,
|
||||||
|
Zend_Cache::CLEANING_MODE_MATCHING_TAG,
|
||||||
|
Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG,
|
||||||
|
Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG))) {
|
||||||
|
Zend_Cache::throwException('Invalid cleaning mode');
|
||||||
|
}
|
||||||
|
self::_validateTagsArray($tags);
|
||||||
|
return $this->_backend->clean($mode, $tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical AND is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
if (!$this->_extendedBackend) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||||
|
}
|
||||||
|
if (!($this->_backendCapabilities['tags'])) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_SUPPORTS_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ids = $this->_backend->getIdsMatchingTags($tags);
|
||||||
|
|
||||||
|
// we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600)
|
||||||
|
if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') {
|
||||||
|
$prefix = & $this->_options['cache_id_prefix'];
|
||||||
|
$prefixLen = strlen($prefix);
|
||||||
|
foreach ($ids as &$id) {
|
||||||
|
if (strpos($id, $prefix) === 0) {
|
||||||
|
$id = substr($id, $prefixLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which don't match given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical OR is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of not matching cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsNotMatchingTags($tags = array())
|
||||||
|
{
|
||||||
|
if (!$this->_extendedBackend) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||||
|
}
|
||||||
|
if (!($this->_backendCapabilities['tags'])) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_SUPPORTS_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ids = $this->_backend->getIdsNotMatchingTags($tags);
|
||||||
|
|
||||||
|
// we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600)
|
||||||
|
if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') {
|
||||||
|
$prefix = & $this->_options['cache_id_prefix'];
|
||||||
|
$prefixLen = strlen($prefix);
|
||||||
|
foreach ($ids as &$id) {
|
||||||
|
if (strpos($id, $prefix) === 0) {
|
||||||
|
$id = substr($id, $prefixLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids which match any given tags
|
||||||
|
*
|
||||||
|
* In case of multiple tags, a logical OR is made between tags
|
||||||
|
*
|
||||||
|
* @param array $tags array of tags
|
||||||
|
* @return array array of matching any cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIdsMatchingAnyTags($tags = array())
|
||||||
|
{
|
||||||
|
if (!$this->_extendedBackend) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||||
|
}
|
||||||
|
if (!($this->_backendCapabilities['tags'])) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_SUPPORTS_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ids = $this->_backend->getIdsMatchingAnyTags($tags);
|
||||||
|
|
||||||
|
// we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600)
|
||||||
|
if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') {
|
||||||
|
$prefix = & $this->_options['cache_id_prefix'];
|
||||||
|
$prefixLen = strlen($prefix);
|
||||||
|
foreach ($ids as &$id) {
|
||||||
|
if (strpos($id, $prefix) === 0) {
|
||||||
|
$id = substr($id, $prefixLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored cache ids
|
||||||
|
*
|
||||||
|
* @return array array of stored cache ids (string)
|
||||||
|
*/
|
||||||
|
public function getIds()
|
||||||
|
{
|
||||||
|
if (!$this->_extendedBackend) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ids = $this->_backend->getIds();
|
||||||
|
|
||||||
|
// we need to remove cache_id_prefix from ids (see #ZF-6178, #ZF-7600)
|
||||||
|
if (isset($this->_options['cache_id_prefix']) && $this->_options['cache_id_prefix'] !== '') {
|
||||||
|
$prefix = & $this->_options['cache_id_prefix'];
|
||||||
|
$prefixLen = strlen($prefix);
|
||||||
|
foreach ($ids as &$id) {
|
||||||
|
if (strpos($id, $prefix) === 0) {
|
||||||
|
$id = substr($id, $prefixLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of stored tags
|
||||||
|
*
|
||||||
|
* @return array array of stored tags (string)
|
||||||
|
*/
|
||||||
|
public function getTags()
|
||||||
|
{
|
||||||
|
if (!$this->_extendedBackend) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||||
|
}
|
||||||
|
if (!($this->_backendCapabilities['tags'])) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_SUPPORTS_TAG);
|
||||||
|
}
|
||||||
|
return $this->_backend->getTags();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the filling percentage of the backend storage
|
||||||
|
*
|
||||||
|
* @return int integer between 0 and 100
|
||||||
|
*/
|
||||||
|
public function getFillingPercentage()
|
||||||
|
{
|
||||||
|
if (!$this->_extendedBackend) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||||
|
}
|
||||||
|
return $this->_backend->getFillingPercentage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array of metadatas for the given cache id
|
||||||
|
*
|
||||||
|
* The array will include these keys :
|
||||||
|
* - expire : the expire timestamp
|
||||||
|
* - tags : a string array of tags
|
||||||
|
* - mtime : timestamp of last modification time
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @return array array of metadatas (false if the cache id is not found)
|
||||||
|
*/
|
||||||
|
public function getMetadatas($id)
|
||||||
|
{
|
||||||
|
if (!$this->_extendedBackend) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||||
|
}
|
||||||
|
$id = $this->_id($id); // cache id may need prefix
|
||||||
|
return $this->_backend->getMetadatas($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give (if possible) an extra lifetime to the given cache id
|
||||||
|
*
|
||||||
|
* @param string $id cache id
|
||||||
|
* @param int $extraLifetime
|
||||||
|
* @return boolean true if ok
|
||||||
|
*/
|
||||||
|
public function touch($id, $extraLifetime)
|
||||||
|
{
|
||||||
|
if (!$this->_extendedBackend) {
|
||||||
|
Zend_Cache::throwException(self::BACKEND_NOT_IMPLEMENTS_EXTENDED_IF);
|
||||||
|
}
|
||||||
|
$id = $this->_id($id); // cache id may need prefix
|
||||||
|
return $this->_backend->touch($id, $extraLifetime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate a cache id or a tag (security, reliable filenames, reserved prefixes...)
|
||||||
|
*
|
||||||
|
* Throw an exception if a problem is found
|
||||||
|
*
|
||||||
|
* @param string $string Cache id or tag
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function _validateIdOrTag($string)
|
||||||
|
{
|
||||||
|
if (!is_string($string)) {
|
||||||
|
Zend_Cache::throwException('Invalid id or tag : must be a string');
|
||||||
|
}
|
||||||
|
if (substr($string, 0, 9) == 'internal-') {
|
||||||
|
Zend_Cache::throwException('"internal-*" ids or tags are reserved');
|
||||||
|
}
|
||||||
|
if (!preg_match('~^[a-zA-Z0-9_]+$~D', $string)) {
|
||||||
|
Zend_Cache::throwException("Invalid id or tag '$string' : must use only [a-zA-Z0-9_]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate a tags array (security, reliable filenames, reserved prefixes...)
|
||||||
|
*
|
||||||
|
* Throw an exception if a problem is found
|
||||||
|
*
|
||||||
|
* @param array $tags Array of tags
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function _validateTagsArray($tags)
|
||||||
|
{
|
||||||
|
if (!is_array($tags)) {
|
||||||
|
Zend_Cache::throwException('Invalid tags array : must be an array');
|
||||||
|
}
|
||||||
|
foreach($tags as $tag) {
|
||||||
|
self::_validateIdOrTag($tag);
|
||||||
|
}
|
||||||
|
reset($tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure if we enable logging that the Zend_Log class
|
||||||
|
* is available.
|
||||||
|
* Create a default log object if none is set.
|
||||||
|
*
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _loggerSanity()
|
||||||
|
{
|
||||||
|
if (!isset($this->_options['logging']) || !$this->_options['logging']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->_options['logger']) && $this->_options['logger'] instanceof Zend_Log) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a default logger to the standard output stream
|
||||||
|
require_once 'Zend/Log/Writer/Stream.php';
|
||||||
|
require_once 'Zend/Log.php';
|
||||||
|
$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
|
||||||
|
$this->_options['logger'] = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a message at the WARN (4) priority.
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _log($message, $priority = 4)
|
||||||
|
{
|
||||||
|
if (!$this->_options['logging']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!(isset($this->_options['logger']) || $this->_options['logger'] instanceof Zend_Log)) {
|
||||||
|
Zend_Cache::throwException('Logging is enabled but logger is not set');
|
||||||
|
}
|
||||||
|
$logger = $this->_options['logger'];
|
||||||
|
$logger->log($message, $priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make and return a cache id
|
||||||
|
*
|
||||||
|
* Checks 'cache_id_prefix' and returns new id with prefix or simply the id if null
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return string Cache id (with or without prefix)
|
||||||
|
*/
|
||||||
|
protected function _id($id)
|
||||||
|
{
|
||||||
|
if (($id !== null) && isset($this->_options['cache_id_prefix'])) {
|
||||||
|
return $this->_options['cache_id_prefix'] . $id; // return with prefix
|
||||||
|
}
|
||||||
|
return $id; // no prefix, just return the $id passed
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
libraries/Zend/Cache/Exception.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Exception
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Exception.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Exception extends Zend_Exception {}
|
87
libraries/Zend/Cache/Frontend/Capture.php
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Core
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Core.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Frontend_Capture extends Zend_Cache_Core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Page identifiers
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_idStack = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tags
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_tags = array();
|
||||||
|
|
||||||
|
protected $_extension = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the cache
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas)
|
||||||
|
*/
|
||||||
|
public function start($id, array $tags, $extension = null)
|
||||||
|
{
|
||||||
|
$this->_tags = $tags;
|
||||||
|
$this->_extension = $extension;
|
||||||
|
ob_start(array($this, '_flush'));
|
||||||
|
ob_implicit_flush(false);
|
||||||
|
$this->_idStack[] = $id;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* callback for output buffering
|
||||||
|
* (shouldn't really be called manually)
|
||||||
|
*
|
||||||
|
* @param string $data Buffered output
|
||||||
|
* @return string Data to send to browser
|
||||||
|
*/
|
||||||
|
public function _flush($data)
|
||||||
|
{
|
||||||
|
$id = array_pop($this->_idStack);
|
||||||
|
if (is_null($id)) {
|
||||||
|
Zend_Cache::throwException('use of _flush() without a start()');
|
||||||
|
}
|
||||||
|
if ($this->_extension) {
|
||||||
|
$this->save(serialize(array($data, $this->_extension)), $id, $this->_tags);
|
||||||
|
} else {
|
||||||
|
$this->save($data, $id, $this->_tags);
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
254
libraries/Zend/Cache/Frontend/Class.php
Normal file
@ -0,0 +1,254 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Class.php 22654 2010-07-22 18:44:13Z mabe $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Core
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Core.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Frontend_Class extends Zend_Cache_Core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Available options
|
||||||
|
*
|
||||||
|
* ====> (mixed) cached_entity :
|
||||||
|
* - if set to a class name, we will cache an abstract class and will use only static calls
|
||||||
|
* - if set to an object, we will cache this object methods
|
||||||
|
*
|
||||||
|
* ====> (boolean) cache_by_default :
|
||||||
|
* - if true, method calls will be cached by default
|
||||||
|
*
|
||||||
|
* ====> (array) cached_methods :
|
||||||
|
* - an array of method names which will be cached (even if cache_by_default = false)
|
||||||
|
*
|
||||||
|
* ====> (array) non_cached_methods :
|
||||||
|
* - an array of method names which won't be cached (even if cache_by_default = true)
|
||||||
|
*
|
||||||
|
* @var array available options
|
||||||
|
*/
|
||||||
|
protected $_specificOptions = array(
|
||||||
|
'cached_entity' => null,
|
||||||
|
'cache_by_default' => true,
|
||||||
|
'cached_methods' => array(),
|
||||||
|
'non_cached_methods' => array()
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tags array
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_tags = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpecificLifetime value
|
||||||
|
*
|
||||||
|
* false => no specific life time
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_specificLifetime = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The cached object or the name of the cached abstract class
|
||||||
|
*
|
||||||
|
* @var mixed
|
||||||
|
*/
|
||||||
|
private $_cachedEntity = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class name of the cached object or cached abstract class
|
||||||
|
*
|
||||||
|
* Used to differentiate between different classes with the same method calls.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $_cachedEntityLabel = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Priority (used by some particular backends)
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $_priority = 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options Associative array of options
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
while (list($name, $value) = each($options)) {
|
||||||
|
$this->setOption($name, $value);
|
||||||
|
}
|
||||||
|
if ($this->_specificOptions['cached_entity'] === null) {
|
||||||
|
Zend_Cache::throwException('cached_entity must be set !');
|
||||||
|
}
|
||||||
|
$this->setCachedEntity($this->_specificOptions['cached_entity']);
|
||||||
|
$this->setOption('automatic_serialization', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a specific life time
|
||||||
|
*
|
||||||
|
* @param int $specificLifetime
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setSpecificLifetime($specificLifetime = false)
|
||||||
|
{
|
||||||
|
$this->_specificLifetime = $specificLifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the priority (used by some particular backends)
|
||||||
|
*
|
||||||
|
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority)
|
||||||
|
*/
|
||||||
|
public function setPriority($priority)
|
||||||
|
{
|
||||||
|
$this->_priority = $priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public frontend to set an option
|
||||||
|
*
|
||||||
|
* Just a wrapper to get a specific behaviour for cached_entity
|
||||||
|
*
|
||||||
|
* @param string $name Name of the option
|
||||||
|
* @param mixed $value Value of the option
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setOption($name, $value)
|
||||||
|
{
|
||||||
|
if ($name == 'cached_entity') {
|
||||||
|
$this->setCachedEntity($value);
|
||||||
|
} else {
|
||||||
|
parent::setOption($name, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specific method to set the cachedEntity
|
||||||
|
*
|
||||||
|
* if set to a class name, we will cache an abstract class and will use only static calls
|
||||||
|
* if set to an object, we will cache this object methods
|
||||||
|
*
|
||||||
|
* @param mixed $cachedEntity
|
||||||
|
*/
|
||||||
|
public function setCachedEntity($cachedEntity)
|
||||||
|
{
|
||||||
|
if (!is_string($cachedEntity) && !is_object($cachedEntity)) {
|
||||||
|
Zend_Cache::throwException('cached_entity must be an object or a class name');
|
||||||
|
}
|
||||||
|
$this->_cachedEntity = $cachedEntity;
|
||||||
|
$this->_specificOptions['cached_entity'] = $cachedEntity;
|
||||||
|
if (is_string($this->_cachedEntity)){
|
||||||
|
$this->_cachedEntityLabel = $this->_cachedEntity;
|
||||||
|
} else {
|
||||||
|
$ro = new ReflectionObject($this->_cachedEntity);
|
||||||
|
$this->_cachedEntityLabel = $ro->getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the cache array
|
||||||
|
*
|
||||||
|
* @param array $tags
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setTagsArray($tags = array())
|
||||||
|
{
|
||||||
|
$this->_tags = $tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main method : call the specified method or get the result from cache
|
||||||
|
*
|
||||||
|
* @param string $name Method name
|
||||||
|
* @param array $parameters Method parameters
|
||||||
|
* @return mixed Result
|
||||||
|
*/
|
||||||
|
public function __call($name, $parameters)
|
||||||
|
{
|
||||||
|
$cacheBool1 = $this->_specificOptions['cache_by_default'];
|
||||||
|
$cacheBool2 = in_array($name, $this->_specificOptions['cached_methods']);
|
||||||
|
$cacheBool3 = in_array($name, $this->_specificOptions['non_cached_methods']);
|
||||||
|
$cache = (($cacheBool1 || $cacheBool2) && (!$cacheBool3));
|
||||||
|
if (!$cache) {
|
||||||
|
// We do not have not cache
|
||||||
|
return call_user_func_array(array($this->_cachedEntity, $name), $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $this->_makeId($name, $parameters);
|
||||||
|
if ( ($rs = $this->load($id)) && isset($rs[0], $rs[1]) ) {
|
||||||
|
// A cache is available
|
||||||
|
$output = $rs[0];
|
||||||
|
$return = $rs[1];
|
||||||
|
} else {
|
||||||
|
// A cache is not available (or not valid for this frontend)
|
||||||
|
ob_start();
|
||||||
|
ob_implicit_flush(false);
|
||||||
|
$return = call_user_func_array(array($this->_cachedEntity, $name), $parameters);
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
$data = array($output, $return);
|
||||||
|
$this->save($data, $id, $this->_tags, $this->_specificLifetime, $this->_priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $output;
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ZF-9970
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
private function _makeId($name, $args)
|
||||||
|
{
|
||||||
|
return $this->makeId($name, $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a cache id from the method name and parameters
|
||||||
|
*
|
||||||
|
* @param string $name Method name
|
||||||
|
* @param array $args Method parameters
|
||||||
|
* @return string Cache id
|
||||||
|
*/
|
||||||
|
public function makeId($name, array $args = array())
|
||||||
|
{
|
||||||
|
return md5($this->_cachedEntityLabel . '__' . $name . '__' . serialize($args));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
209
libraries/Zend/Cache/Frontend/File.php
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: File.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Core
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Core.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Frontend_File extends Zend_Cache_Core
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consts for master_files_mode
|
||||||
|
*/
|
||||||
|
const MODE_AND = 'AND';
|
||||||
|
const MODE_OR = 'OR';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available options
|
||||||
|
*
|
||||||
|
* ====> (string) master_file :
|
||||||
|
* - a complete path of the master file
|
||||||
|
* - deprecated (see master_files)
|
||||||
|
*
|
||||||
|
* ====> (array) master_files :
|
||||||
|
* - an array of complete path of master files
|
||||||
|
* - this option has to be set !
|
||||||
|
*
|
||||||
|
* ====> (string) master_files_mode :
|
||||||
|
* - Zend_Cache_Frontend_File::MODE_AND or Zend_Cache_Frontend_File::MODE_OR
|
||||||
|
* - if MODE_AND, then all master files have to be touched to get a cache invalidation
|
||||||
|
* - if MODE_OR (default), then a single touched master file is enough to get a cache invalidation
|
||||||
|
*
|
||||||
|
* ====> (boolean) ignore_missing_master_files
|
||||||
|
* - if set to true, missing master files are ignored silently
|
||||||
|
* - if set to false (default), an exception is thrown if there is a missing master file
|
||||||
|
* @var array available options
|
||||||
|
*/
|
||||||
|
protected $_specificOptions = array(
|
||||||
|
'master_file' => null,
|
||||||
|
'master_files' => null,
|
||||||
|
'master_files_mode' => 'OR',
|
||||||
|
'ignore_missing_master_files' => false
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Master file mtimes
|
||||||
|
*
|
||||||
|
* Array of int
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_masterFile_mtimes = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options Associative array of options
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
while (list($name, $value) = each($options)) {
|
||||||
|
$this->setOption($name, $value);
|
||||||
|
}
|
||||||
|
if (!isset($this->_specificOptions['master_files'])) {
|
||||||
|
Zend_Cache::throwException('master_files option must be set');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the master_file option
|
||||||
|
*
|
||||||
|
* @param string $masterFile the complete path and name of the master file
|
||||||
|
*/
|
||||||
|
public function setMasterFiles($masterFiles)
|
||||||
|
{
|
||||||
|
clearstatcache();
|
||||||
|
$this->_specificOptions['master_file'] = $masterFiles[0]; // to keep a compatibility
|
||||||
|
$this->_specificOptions['master_files'] = $masterFiles;
|
||||||
|
$this->_masterFile_mtimes = array();
|
||||||
|
$i = 0;
|
||||||
|
foreach ($masterFiles as $masterFile) {
|
||||||
|
$this->_masterFile_mtimes[$i] = @filemtime($masterFile);
|
||||||
|
if ((!($this->_specificOptions['ignore_missing_master_files'])) && (!($this->_masterFile_mtimes[$i]))) {
|
||||||
|
Zend_Cache::throwException('Unable to read master_file : '.$masterFile);
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the master_file option
|
||||||
|
*
|
||||||
|
* To keep the compatibility
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* @param string $masterFile the complete path and name of the master file
|
||||||
|
*/
|
||||||
|
public function setMasterFile($masterFile)
|
||||||
|
{
|
||||||
|
$this->setMasterFiles(array(0 => $masterFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public frontend to set an option
|
||||||
|
*
|
||||||
|
* Just a wrapper to get a specific behaviour for master_file
|
||||||
|
*
|
||||||
|
* @param string $name Name of the option
|
||||||
|
* @param mixed $value Value of the option
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setOption($name, $value)
|
||||||
|
{
|
||||||
|
if ($name == 'master_file') {
|
||||||
|
$this->setMasterFile($value);
|
||||||
|
} else if ($name == 'master_files') {
|
||||||
|
$this->setMasterFiles($value);
|
||||||
|
} else {
|
||||||
|
parent::setOption($name, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||||
|
* @param boolean $doNotUnserialize Do not serialize (even if automatic_serialization is true) => for internal use
|
||||||
|
* @return mixed|false Cached datas
|
||||||
|
*/
|
||||||
|
public function load($id, $doNotTestCacheValidity = false, $doNotUnserialize = false)
|
||||||
|
{
|
||||||
|
if (!$doNotTestCacheValidity) {
|
||||||
|
if ($this->test($id)) {
|
||||||
|
return parent::load($id, true, $doNotUnserialize);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return parent::load($id, true, $doNotUnserialize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if a cache is available for the given id
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @return int|false Last modified time of cache entry if it is available, false otherwise
|
||||||
|
*/
|
||||||
|
public function test($id)
|
||||||
|
{
|
||||||
|
$lastModified = parent::test($id);
|
||||||
|
if ($lastModified) {
|
||||||
|
if ($this->_specificOptions['master_files_mode'] == self::MODE_AND) {
|
||||||
|
// MODE_AND
|
||||||
|
foreach($this->_masterFile_mtimes as $masterFileMTime) {
|
||||||
|
if ($masterFileMTime) {
|
||||||
|
if ($lastModified > $masterFileMTime) {
|
||||||
|
return $lastModified;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// MODE_OR
|
||||||
|
$res = true;
|
||||||
|
foreach($this->_masterFile_mtimes as $masterFileMTime) {
|
||||||
|
if ($masterFileMTime) {
|
||||||
|
if ($lastModified <= $masterFileMTime) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $lastModified;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
180
libraries/Zend/Cache/Frontend/Function.php
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Function.php 22654 2010-07-22 18:44:13Z mabe $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Core
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Core.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Frontend_Function extends Zend_Cache_Core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* This frontend specific options
|
||||||
|
*
|
||||||
|
* ====> (boolean) cache_by_default :
|
||||||
|
* - if true, function calls will be cached by default
|
||||||
|
*
|
||||||
|
* ====> (array) cached_functions :
|
||||||
|
* - an array of function names which will be cached (even if cache_by_default = false)
|
||||||
|
*
|
||||||
|
* ====> (array) non_cached_functions :
|
||||||
|
* - an array of function names which won't be cached (even if cache_by_default = true)
|
||||||
|
*
|
||||||
|
* @var array options
|
||||||
|
*/
|
||||||
|
protected $_specificOptions = array(
|
||||||
|
'cache_by_default' => true,
|
||||||
|
'cached_functions' => array(),
|
||||||
|
'non_cached_functions' => array()
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options Associative array of options
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
while (list($name, $value) = each($options)) {
|
||||||
|
$this->setOption($name, $value);
|
||||||
|
}
|
||||||
|
$this->setOption('automatic_serialization', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main method : call the specified function or get the result from cache
|
||||||
|
*
|
||||||
|
* @param callback $callback A valid callback
|
||||||
|
* @param array $parameters Function parameters
|
||||||
|
* @param array $tags Cache tags
|
||||||
|
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
|
||||||
|
* @return mixed Result
|
||||||
|
*/
|
||||||
|
public function call($callback, array $parameters = array(), $tags = array(), $specificLifetime = false, $priority = 8)
|
||||||
|
{
|
||||||
|
if (!is_callable($callback, true, $name)) {
|
||||||
|
Zend_Cache::throwException('Invalid callback');
|
||||||
|
}
|
||||||
|
|
||||||
|
$cacheBool1 = $this->_specificOptions['cache_by_default'];
|
||||||
|
$cacheBool2 = in_array($name, $this->_specificOptions['cached_functions']);
|
||||||
|
$cacheBool3 = in_array($name, $this->_specificOptions['non_cached_functions']);
|
||||||
|
$cache = (($cacheBool1 || $cacheBool2) && (!$cacheBool3));
|
||||||
|
if (!$cache) {
|
||||||
|
// Caching of this callback is disabled
|
||||||
|
return call_user_func_array($callback, $parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $this->_makeId($callback, $parameters);
|
||||||
|
if ( ($rs = $this->load($id)) && isset($rs[0], $rs[1])) {
|
||||||
|
// A cache is available
|
||||||
|
$output = $rs[0];
|
||||||
|
$return = $rs[1];
|
||||||
|
} else {
|
||||||
|
// A cache is not available (or not valid for this frontend)
|
||||||
|
ob_start();
|
||||||
|
ob_implicit_flush(false);
|
||||||
|
$return = call_user_func_array($callback, $parameters);
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
$data = array($output, $return);
|
||||||
|
$this->save($data, $id, $tags, $specificLifetime, $priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $output;
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ZF-9970
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
private function _makeId($callback, array $args)
|
||||||
|
{
|
||||||
|
return $this->makeId($callback, $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a cache id from the function name and parameters
|
||||||
|
*
|
||||||
|
* @param callback $callback A valid callback
|
||||||
|
* @param array $args Function parameters
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return string Cache id
|
||||||
|
*/
|
||||||
|
public function makeId($callback, array $args = array())
|
||||||
|
{
|
||||||
|
if (!is_callable($callback, true, $name)) {
|
||||||
|
Zend_Cache::throwException('Invalid callback');
|
||||||
|
}
|
||||||
|
|
||||||
|
// functions, methods and classnames are case-insensitive
|
||||||
|
$name = strtolower($name);
|
||||||
|
|
||||||
|
// generate a unique id for object callbacks
|
||||||
|
if (is_object($callback)) { // Closures & __invoke
|
||||||
|
$object = $callback;
|
||||||
|
} elseif (isset($callback[0])) { // array($object, 'method')
|
||||||
|
$object = $callback[0];
|
||||||
|
}
|
||||||
|
if (isset($object)) {
|
||||||
|
try {
|
||||||
|
$tmp = @serialize($callback);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Zend_Cache::throwException($e->getMessage());
|
||||||
|
}
|
||||||
|
if (!$tmp) {
|
||||||
|
$lastErr = error_get_last();
|
||||||
|
Zend_Cache::throwException("Can't serialize callback object to generate id: {$lastErr['message']}");
|
||||||
|
}
|
||||||
|
$name.= '__' . $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// generate a unique id for arguments
|
||||||
|
$argsStr = '';
|
||||||
|
if ($args) {
|
||||||
|
try {
|
||||||
|
$argsStr = @serialize(array_values($args));
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Zend_Cache::throwException($e->getMessage());
|
||||||
|
}
|
||||||
|
if (!$argsStr) {
|
||||||
|
$lastErr = error_get_last();
|
||||||
|
throw Zend_Cache::throwException("Can't serialize arguments to generate id: {$lastErr['message']}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return md5($name . $argsStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
106
libraries/Zend/Cache/Frontend/Output.php
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Output.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Core
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Core.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Frontend_Output extends Zend_Cache_Core
|
||||||
|
{
|
||||||
|
|
||||||
|
private $_idStack = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options Associative array of options
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
parent::__construct($options);
|
||||||
|
$this->_idStack = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the cache
|
||||||
|
*
|
||||||
|
* @param string $id Cache id
|
||||||
|
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||||
|
* @param boolean $echoData If set to true, datas are sent to the browser if the cache is hit (simpy returned else)
|
||||||
|
* @return mixed True if the cache is hit (false else) with $echoData=true (default) ; string else (datas)
|
||||||
|
*/
|
||||||
|
public function start($id, $doNotTestCacheValidity = false, $echoData = true)
|
||||||
|
{
|
||||||
|
$data = $this->load($id, $doNotTestCacheValidity);
|
||||||
|
if ($data !== false) {
|
||||||
|
if ( $echoData ) {
|
||||||
|
echo($data);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ob_start();
|
||||||
|
ob_implicit_flush(false);
|
||||||
|
$this->_idStack[] = $id;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the cache
|
||||||
|
*
|
||||||
|
* @param array $tags Tags array
|
||||||
|
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||||
|
* @param string $forcedDatas If not null, force written datas with this
|
||||||
|
* @param boolean $echoData If set to true, datas are sent to the browser
|
||||||
|
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function end($tags = array(), $specificLifetime = false, $forcedDatas = null, $echoData = true, $priority = 8)
|
||||||
|
{
|
||||||
|
if ($forcedDatas === null) {
|
||||||
|
$data = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
} else {
|
||||||
|
$data =& $forcedDatas;
|
||||||
|
}
|
||||||
|
$id = array_pop($this->_idStack);
|
||||||
|
if ($id === null) {
|
||||||
|
Zend_Cache::throwException('use of end() without a start()');
|
||||||
|
}
|
||||||
|
$this->save($data, $id, $tags, $specificLifetime, $priority);
|
||||||
|
if ($echoData) {
|
||||||
|
echo($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
402
libraries/Zend/Cache/Frontend/Page.php
Normal file
@ -0,0 +1,402 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Page.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Zend_Cache_Core
|
||||||
|
*/
|
||||||
|
require_once 'Zend/Cache/Core.php';
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @subpackage Zend_Cache_Frontend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Frontend_Page extends Zend_Cache_Core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* This frontend specific options
|
||||||
|
*
|
||||||
|
* ====> (boolean) http_conditional :
|
||||||
|
* - if true, http conditional mode is on
|
||||||
|
* WARNING : http_conditional OPTION IS NOT IMPLEMENTED FOR THE MOMENT (TODO)
|
||||||
|
*
|
||||||
|
* ====> (boolean) debug_header :
|
||||||
|
* - if true, a debug text is added before each cached pages
|
||||||
|
*
|
||||||
|
* ====> (boolean) content_type_memorization :
|
||||||
|
* - deprecated => use memorize_headers instead
|
||||||
|
* - if the Content-Type header is sent after the cache was started, the
|
||||||
|
* corresponding value can be memorized and replayed when the cache is hit
|
||||||
|
* (if false (default), the frontend doesn't take care of Content-Type header)
|
||||||
|
*
|
||||||
|
* ====> (array) memorize_headers :
|
||||||
|
* - an array of strings corresponding to some HTTP headers name. Listed headers
|
||||||
|
* will be stored with cache datas and "replayed" when the cache is hit
|
||||||
|
*
|
||||||
|
* ====> (array) default_options :
|
||||||
|
* - an associative array of default options :
|
||||||
|
* - (boolean) cache : cache is on by default if true
|
||||||
|
* - (boolean) cacheWithXXXVariables (XXXX = 'Get', 'Post', 'Session', 'Files' or 'Cookie') :
|
||||||
|
* if true, cache is still on even if there are some variables in this superglobal array
|
||||||
|
* if false, cache is off if there are some variables in this superglobal array
|
||||||
|
* - (boolean) makeIdWithXXXVariables (XXXX = 'Get', 'Post', 'Session', 'Files' or 'Cookie') :
|
||||||
|
* if true, we have to use the content of this superglobal array to make a cache id
|
||||||
|
* if false, the cache id won't be dependent of the content of this superglobal array
|
||||||
|
* - (int) specific_lifetime : cache specific lifetime
|
||||||
|
* (false => global lifetime is used, null => infinite lifetime,
|
||||||
|
* integer => this lifetime is used), this "lifetime" is probably only
|
||||||
|
* usefull when used with "regexps" array
|
||||||
|
* - (array) tags : array of tags (strings)
|
||||||
|
* - (int) priority : integer between 0 (very low priority) and 10 (maximum priority) used by
|
||||||
|
* some particular backends
|
||||||
|
*
|
||||||
|
* ====> (array) regexps :
|
||||||
|
* - an associative array to set options only for some REQUEST_URI
|
||||||
|
* - keys are (pcre) regexps
|
||||||
|
* - values are associative array with specific options to set if the regexp matchs on $_SERVER['REQUEST_URI']
|
||||||
|
* (see default_options for the list of available options)
|
||||||
|
* - if several regexps match the $_SERVER['REQUEST_URI'], only the last one will be used
|
||||||
|
*
|
||||||
|
* @var array options
|
||||||
|
*/
|
||||||
|
protected $_specificOptions = array(
|
||||||
|
'http_conditional' => false,
|
||||||
|
'debug_header' => false,
|
||||||
|
'content_type_memorization' => false,
|
||||||
|
'memorize_headers' => array(),
|
||||||
|
'default_options' => array(
|
||||||
|
'cache_with_get_variables' => false,
|
||||||
|
'cache_with_post_variables' => false,
|
||||||
|
'cache_with_session_variables' => false,
|
||||||
|
'cache_with_files_variables' => false,
|
||||||
|
'cache_with_cookie_variables' => false,
|
||||||
|
'make_id_with_get_variables' => true,
|
||||||
|
'make_id_with_post_variables' => true,
|
||||||
|
'make_id_with_session_variables' => true,
|
||||||
|
'make_id_with_files_variables' => true,
|
||||||
|
'make_id_with_cookie_variables' => true,
|
||||||
|
'cache' => true,
|
||||||
|
'specific_lifetime' => false,
|
||||||
|
'tags' => array(),
|
||||||
|
'priority' => null
|
||||||
|
),
|
||||||
|
'regexps' => array()
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal array to store some options
|
||||||
|
*
|
||||||
|
* @var array associative array of options
|
||||||
|
*/
|
||||||
|
protected $_activeOptions = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, the page won't be cached
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $_cancel = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options Associative array of options
|
||||||
|
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = array())
|
||||||
|
{
|
||||||
|
while (list($name, $value) = each($options)) {
|
||||||
|
$name = strtolower($name);
|
||||||
|
switch ($name) {
|
||||||
|
case 'regexps':
|
||||||
|
$this->_setRegexps($value);
|
||||||
|
break;
|
||||||
|
case 'default_options':
|
||||||
|
$this->_setDefaultOptions($value);
|
||||||
|
break;
|
||||||
|
case 'content_type_memorization':
|
||||||
|
$this->_setContentTypeMemorization($value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$this->setOption($name, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($this->_specificOptions['http_conditional'])) {
|
||||||
|
if ($this->_specificOptions['http_conditional']) {
|
||||||
|
Zend_Cache::throwException('http_conditional is not implemented for the moment !');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->setOption('automatic_serialization', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specific setter for the 'default_options' option (with some additional tests)
|
||||||
|
*
|
||||||
|
* @param array $options Associative array
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _setDefaultOptions($options)
|
||||||
|
{
|
||||||
|
if (!is_array($options)) {
|
||||||
|
Zend_Cache::throwException('default_options must be an array !');
|
||||||
|
}
|
||||||
|
foreach ($options as $key=>$value) {
|
||||||
|
if (!is_string($key)) {
|
||||||
|
Zend_Cache::throwException("invalid option [$key] !");
|
||||||
|
}
|
||||||
|
$key = strtolower($key);
|
||||||
|
if (isset($this->_specificOptions['default_options'][$key])) {
|
||||||
|
$this->_specificOptions['default_options'][$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the deprecated contentTypeMemorization option
|
||||||
|
*
|
||||||
|
* @param boolean $value value
|
||||||
|
* @return void
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
protected function _setContentTypeMemorization($value)
|
||||||
|
{
|
||||||
|
$found = null;
|
||||||
|
foreach ($this->_specificOptions['memorize_headers'] as $key => $value) {
|
||||||
|
if (strtolower($value) == 'content-type') {
|
||||||
|
$found = $key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($value) {
|
||||||
|
if (!$found) {
|
||||||
|
$this->_specificOptions['memorize_headers'][] = 'Content-Type';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($found) {
|
||||||
|
unset($this->_specificOptions['memorize_headers'][$found]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specific setter for the 'regexps' option (with some additional tests)
|
||||||
|
*
|
||||||
|
* @param array $options Associative array
|
||||||
|
* @throws Zend_Cache_Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _setRegexps($regexps)
|
||||||
|
{
|
||||||
|
if (!is_array($regexps)) {
|
||||||
|
Zend_Cache::throwException('regexps option must be an array !');
|
||||||
|
}
|
||||||
|
foreach ($regexps as $regexp=>$conf) {
|
||||||
|
if (!is_array($conf)) {
|
||||||
|
Zend_Cache::throwException('regexps option must be an array of arrays !');
|
||||||
|
}
|
||||||
|
$validKeys = array_keys($this->_specificOptions['default_options']);
|
||||||
|
foreach ($conf as $key=>$value) {
|
||||||
|
if (!is_string($key)) {
|
||||||
|
Zend_Cache::throwException("unknown option [$key] !");
|
||||||
|
}
|
||||||
|
$key = strtolower($key);
|
||||||
|
if (!in_array($key, $validKeys)) {
|
||||||
|
unset($regexps[$regexp][$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->setOption('regexps', $regexps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the cache
|
||||||
|
*
|
||||||
|
* @param string $id (optional) A cache id (if you set a value here, maybe you have to use Output frontend instead)
|
||||||
|
* @param boolean $doNotDie For unit testing only !
|
||||||
|
* @return boolean True if the cache is hit (false else)
|
||||||
|
*/
|
||||||
|
public function start($id = false, $doNotDie = false)
|
||||||
|
{
|
||||||
|
$this->_cancel = false;
|
||||||
|
$lastMatchingRegexp = null;
|
||||||
|
foreach ($this->_specificOptions['regexps'] as $regexp => $conf) {
|
||||||
|
if (preg_match("`$regexp`", $_SERVER['REQUEST_URI'])) {
|
||||||
|
$lastMatchingRegexp = $regexp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->_activeOptions = $this->_specificOptions['default_options'];
|
||||||
|
if ($lastMatchingRegexp !== null) {
|
||||||
|
$conf = $this->_specificOptions['regexps'][$lastMatchingRegexp];
|
||||||
|
foreach ($conf as $key=>$value) {
|
||||||
|
$this->_activeOptions[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!($this->_activeOptions['cache'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!$id) {
|
||||||
|
$id = $this->_makeId();
|
||||||
|
if (!$id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$array = $this->load($id);
|
||||||
|
if ($array !== false) {
|
||||||
|
$data = $array['data'];
|
||||||
|
$headers = $array['headers'];
|
||||||
|
if (!headers_sent()) {
|
||||||
|
foreach ($headers as $key=>$headerCouple) {
|
||||||
|
$name = $headerCouple[0];
|
||||||
|
$value = $headerCouple[1];
|
||||||
|
header("$name: $value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->_specificOptions['debug_header']) {
|
||||||
|
echo 'DEBUG HEADER : This is a cached page !';
|
||||||
|
}
|
||||||
|
echo $data;
|
||||||
|
if ($doNotDie) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
ob_start(array($this, '_flush'));
|
||||||
|
ob_implicit_flush(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancel the current caching process
|
||||||
|
*/
|
||||||
|
public function cancel()
|
||||||
|
{
|
||||||
|
$this->_cancel = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* callback for output buffering
|
||||||
|
* (shouldn't really be called manually)
|
||||||
|
*
|
||||||
|
* @param string $data Buffered output
|
||||||
|
* @return string Data to send to browser
|
||||||
|
*/
|
||||||
|
public function _flush($data)
|
||||||
|
{
|
||||||
|
if ($this->_cancel) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
$contentType = null;
|
||||||
|
$storedHeaders = array();
|
||||||
|
$headersList = headers_list();
|
||||||
|
foreach($this->_specificOptions['memorize_headers'] as $key=>$headerName) {
|
||||||
|
foreach ($headersList as $headerSent) {
|
||||||
|
$tmp = explode(':', $headerSent);
|
||||||
|
$headerSentName = trim(array_shift($tmp));
|
||||||
|
if (strtolower($headerName) == strtolower($headerSentName)) {
|
||||||
|
$headerSentValue = trim(implode(':', $tmp));
|
||||||
|
$storedHeaders[] = array($headerSentName, $headerSentValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$array = array(
|
||||||
|
'data' => $data,
|
||||||
|
'headers' => $storedHeaders
|
||||||
|
);
|
||||||
|
$this->save($array, null, $this->_activeOptions['tags'], $this->_activeOptions['specific_lifetime'], $this->_activeOptions['priority']);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make an id depending on REQUEST_URI and superglobal arrays (depending on options)
|
||||||
|
*
|
||||||
|
* @return mixed|false a cache id (string), false if the cache should have not to be used
|
||||||
|
*/
|
||||||
|
protected function _makeId()
|
||||||
|
{
|
||||||
|
$tmp = $_SERVER['REQUEST_URI'];
|
||||||
|
$array = explode('?', $tmp, 2);
|
||||||
|
$tmp = $array[0];
|
||||||
|
foreach (array('Get', 'Post', 'Session', 'Files', 'Cookie') as $arrayName) {
|
||||||
|
$tmp2 = $this->_makePartialId($arrayName, $this->_activeOptions['cache_with_' . strtolower($arrayName) . '_variables'], $this->_activeOptions['make_id_with_' . strtolower($arrayName) . '_variables']);
|
||||||
|
if ($tmp2===false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$tmp = $tmp . $tmp2;
|
||||||
|
}
|
||||||
|
return md5($tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a partial id depending on options
|
||||||
|
*
|
||||||
|
* @param string $arrayName Superglobal array name
|
||||||
|
* @param bool $bool1 If true, cache is still on even if there are some variables in the superglobal array
|
||||||
|
* @param bool $bool2 If true, we have to use the content of the superglobal array to make a partial id
|
||||||
|
* @return mixed|false Partial id (string) or false if the cache should have not to be used
|
||||||
|
*/
|
||||||
|
protected function _makePartialId($arrayName, $bool1, $bool2)
|
||||||
|
{
|
||||||
|
switch ($arrayName) {
|
||||||
|
case 'Get':
|
||||||
|
$var = $_GET;
|
||||||
|
break;
|
||||||
|
case 'Post':
|
||||||
|
$var = $_POST;
|
||||||
|
break;
|
||||||
|
case 'Session':
|
||||||
|
if (isset($_SESSION)) {
|
||||||
|
$var = $_SESSION;
|
||||||
|
} else {
|
||||||
|
$var = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'Cookie':
|
||||||
|
if (isset($_COOKIE)) {
|
||||||
|
$var = $_COOKIE;
|
||||||
|
} else {
|
||||||
|
$var = null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'Files':
|
||||||
|
$var = $_FILES;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($bool1) {
|
||||||
|
if ($bool2) {
|
||||||
|
return serialize($var);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
if (count($var) > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
298
libraries/Zend/Cache/Manager.php
Normal file
@ -0,0 +1,298 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @see Zend_Cache_Exception */
|
||||||
|
require_once 'Zend/Cache/Exception.php';
|
||||||
|
|
||||||
|
/** @see Zend_Cache */
|
||||||
|
require_once 'Zend/Cache.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Cache
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Cache_Manager
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constant holding reserved name for default Page Cache
|
||||||
|
*/
|
||||||
|
const PAGECACHE = 'page';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant holding reserved name for default Page Tag Cache
|
||||||
|
*/
|
||||||
|
const PAGETAGCACHE = 'pagetag';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of caches stored by the Cache Manager instance
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_caches = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of ready made configuration templates for lazy
|
||||||
|
* loading caches.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_optionTemplates = array(
|
||||||
|
// Simple Common Default
|
||||||
|
'default' => array(
|
||||||
|
'frontend' => array(
|
||||||
|
'name' => 'Core',
|
||||||
|
'options' => array(
|
||||||
|
'automatic_serialization' => true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'backend' => array(
|
||||||
|
'name' => 'File',
|
||||||
|
'options' => array(
|
||||||
|
// use system temp dir by default of file backend
|
||||||
|
// 'cache_dir' => '../cache',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Static Page HTML Cache
|
||||||
|
'page' => array(
|
||||||
|
'frontend' => array(
|
||||||
|
'name' => 'Capture',
|
||||||
|
'options' => array(
|
||||||
|
'ignore_user_abort' => true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'backend' => array(
|
||||||
|
'name' => 'Static',
|
||||||
|
'options' => array(
|
||||||
|
'public_dir' => '../public',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Tag Cache
|
||||||
|
'pagetag' => array(
|
||||||
|
'frontend' => array(
|
||||||
|
'name' => 'Core',
|
||||||
|
'options' => array(
|
||||||
|
'automatic_serialization' => true,
|
||||||
|
'lifetime' => null
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'backend' => array(
|
||||||
|
'name' => 'File',
|
||||||
|
'options' => array(
|
||||||
|
// use system temp dir by default of file backend
|
||||||
|
// 'cache_dir' => '../cache',
|
||||||
|
// use default umask of file backend
|
||||||
|
// 'cache_file_umask' => 0644
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a new cache for the Cache Manager to contain
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param Zend_Cache_Core $cache
|
||||||
|
* @return Zend_Cache_Manager
|
||||||
|
*/
|
||||||
|
public function setCache($name, Zend_Cache_Core $cache)
|
||||||
|
{
|
||||||
|
$this->_caches[$name] = $cache;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the Cache Manager contains the named cache object, or a named
|
||||||
|
* configuration template to lazy load the cache object
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasCache($name)
|
||||||
|
{
|
||||||
|
if (isset($this->_caches[$name])
|
||||||
|
|| $this->hasCacheTemplate($name)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the named cache object, or instantiate and return a cache object
|
||||||
|
* using a named configuration template
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return Zend_Cache_Core
|
||||||
|
*/
|
||||||
|
public function getCache($name)
|
||||||
|
{
|
||||||
|
if (isset($this->_caches[$name])) {
|
||||||
|
return $this->_caches[$name];
|
||||||
|
}
|
||||||
|
if (isset($this->_optionTemplates[$name])) {
|
||||||
|
if ($name == self::PAGECACHE
|
||||||
|
&& (!isset($this->_optionTemplates[$name]['backend']['options']['tag_cache'])
|
||||||
|
|| !$this->_optionTemplates[$name]['backend']['options']['tag_cache'] instanceof Zend_Cache_Core)
|
||||||
|
) {
|
||||||
|
$this->_optionTemplates[$name]['backend']['options']['tag_cache']
|
||||||
|
= $this->getCache(self::PAGETAGCACHE);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_caches[$name] = Zend_Cache::factory(
|
||||||
|
$this->_optionTemplates[$name]['frontend']['name'],
|
||||||
|
$this->_optionTemplates[$name]['backend']['name'],
|
||||||
|
isset($this->_optionTemplates[$name]['frontend']['options']) ? $this->_optionTemplates[$name]['frontend']['options'] : array(),
|
||||||
|
isset($this->_optionTemplates[$name]['backend']['options']) ? $this->_optionTemplates[$name]['backend']['options'] : array(),
|
||||||
|
isset($this->_optionTemplates[$name]['frontend']['customFrontendNaming']) ? $this->_optionTemplates[$name]['frontend']['customFrontendNaming'] : false,
|
||||||
|
isset($this->_optionTemplates[$name]['backend']['customBackendNaming']) ? $this->_optionTemplates[$name]['backend']['customBackendNaming'] : false,
|
||||||
|
isset($this->_optionTemplates[$name]['frontendBackendAutoload']) ? $this->_optionTemplates[$name]['frontendBackendAutoload'] : false
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this->_caches[$name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all available caches
|
||||||
|
*
|
||||||
|
* @return array An array of all available caches with it's names as key
|
||||||
|
*/
|
||||||
|
public function getCaches()
|
||||||
|
{
|
||||||
|
$caches = $this->_caches;
|
||||||
|
foreach ($this->_optionTemplates as $name => $tmp) {
|
||||||
|
if (!isset($caches[$name])) {
|
||||||
|
$caches[$name] = $this->getCache($name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $caches;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a named configuration template from which a cache object can later
|
||||||
|
* be lazy loaded
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param array $options
|
||||||
|
* @return Zend_Cache_Manager
|
||||||
|
*/
|
||||||
|
public function setCacheTemplate($name, $options)
|
||||||
|
{
|
||||||
|
if ($options instanceof Zend_Config) {
|
||||||
|
$options = $options->toArray();
|
||||||
|
} elseif (!is_array($options)) {
|
||||||
|
require_once 'Zend/Cache/Exception.php';
|
||||||
|
throw new Zend_Cache_Exception('Options passed must be in'
|
||||||
|
. ' an associative array or instance of Zend_Config');
|
||||||
|
}
|
||||||
|
$this->_optionTemplates[$name] = $options;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the named configuration template
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasCacheTemplate($name)
|
||||||
|
{
|
||||||
|
if (isset($this->_optionTemplates[$name])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the named configuration template
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getCacheTemplate($name)
|
||||||
|
{
|
||||||
|
if (isset($this->_optionTemplates[$name])) {
|
||||||
|
return $this->_optionTemplates[$name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pass an array containing changes to be applied to a named
|
||||||
|
* configuration
|
||||||
|
* template
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param array $options
|
||||||
|
* @return Zend_Cache_Manager
|
||||||
|
* @throws Zend_Cache_Exception for invalid options format or if option templates do not have $name
|
||||||
|
*/
|
||||||
|
public function setTemplateOptions($name, $options)
|
||||||
|
{
|
||||||
|
if ($options instanceof Zend_Config) {
|
||||||
|
$options = $options->toArray();
|
||||||
|
} elseif (!is_array($options)) {
|
||||||
|
require_once 'Zend/Cache/Exception.php';
|
||||||
|
throw new Zend_Cache_Exception('Options passed must be in'
|
||||||
|
. ' an associative array or instance of Zend_Config');
|
||||||
|
}
|
||||||
|
if (!isset($this->_optionTemplates[$name])) {
|
||||||
|
throw new Zend_Cache_Exception('A cache configuration template'
|
||||||
|
. 'does not exist with the name "' . $name . '"');
|
||||||
|
}
|
||||||
|
$this->_optionTemplates[$name]
|
||||||
|
= $this->_mergeOptions($this->_optionTemplates[$name], $options);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple method to merge two configuration arrays
|
||||||
|
*
|
||||||
|
* @param array $current
|
||||||
|
* @param array $options
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function _mergeOptions(array $current, array $options)
|
||||||
|
{
|
||||||
|
if (isset($options['frontend']['name'])) {
|
||||||
|
$current['frontend']['name'] = $options['frontend']['name'];
|
||||||
|
}
|
||||||
|
if (isset($options['backend']['name'])) {
|
||||||
|
$current['backend']['name'] = $options['backend']['name'];
|
||||||
|
}
|
||||||
|
if (isset($options['frontend']['options'])) {
|
||||||
|
foreach ($options['frontend']['options'] as $key=>$value) {
|
||||||
|
$current['frontend']['options'][$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($options['backend']['options'])) {
|
||||||
|
foreach ($options['backend']['options'] as $key=>$value) {
|
||||||
|
$current['backend']['options'][$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $current;
|
||||||
|
}
|
||||||
|
}
|
95
libraries/Zend/Exception.php
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Exception extends Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var null|Exception
|
||||||
|
*/
|
||||||
|
private $_previous = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the exception
|
||||||
|
*
|
||||||
|
* @param string $msg
|
||||||
|
* @param int $code
|
||||||
|
* @param Exception $previous
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($msg = '', $code = 0, Exception $previous = null)
|
||||||
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
|
||||||
|
parent::__construct($msg, (int) $code);
|
||||||
|
$this->_previous = $previous;
|
||||||
|
} else {
|
||||||
|
parent::__construct($msg, (int) $code, $previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overloading
|
||||||
|
*
|
||||||
|
* For PHP < 5.3.0, provides access to the getPrevious() method.
|
||||||
|
*
|
||||||
|
* @param string $method
|
||||||
|
* @param array $args
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function __call($method, array $args)
|
||||||
|
{
|
||||||
|
if ('getprevious' == strtolower($method)) {
|
||||||
|
return $this->_getPrevious();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String representation of the exception
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
|
||||||
|
if (null !== ($e = $this->getPrevious())) {
|
||||||
|
return $e->__toString()
|
||||||
|
. "\n\nNext "
|
||||||
|
. parent::__toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parent::__toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns previous Exception
|
||||||
|
*
|
||||||
|
* @return Exception|null
|
||||||
|
*/
|
||||||
|
protected function _getPrevious()
|
||||||
|
{
|
||||||
|
return $this->_previous;
|
||||||
|
}
|
||||||
|
}
|
329
libraries/Zend/Loader.php
Normal file
@ -0,0 +1,329 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Zend Framework
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
*
|
||||||
|
* This source file is subject to the new BSD license that is bundled
|
||||||
|
* with this package in the file LICENSE.txt.
|
||||||
|
* It is also available through the world-wide-web at this URL:
|
||||||
|
* http://framework.zend.com/license/new-bsd
|
||||||
|
* If you did not receive a copy of the license and are unable to
|
||||||
|
* obtain it through the world-wide-web, please send an email
|
||||||
|
* to license@zend.com so we can send you a copy immediately.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Loader
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
* @version $Id: Loader.php 22020 2010-04-27 16:35:56Z matthew $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static methods for loading classes and files.
|
||||||
|
*
|
||||||
|
* @category Zend
|
||||||
|
* @package Zend_Loader
|
||||||
|
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||||
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||||
|
*/
|
||||||
|
class Zend_Loader
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Loads a class from a PHP file. The filename must be formatted
|
||||||
|
* as "$class.php".
|
||||||
|
*
|
||||||
|
* If $dirs is a string or an array, it will search the directories
|
||||||
|
* in the order supplied, and attempt to load the first matching file.
|
||||||
|
*
|
||||||
|
* If $dirs is null, it will split the class name at underscores to
|
||||||
|
* generate a path hierarchy (e.g., "Zend_Example_Class" will map
|
||||||
|
* to "Zend/Example/Class.php").
|
||||||
|
*
|
||||||
|
* If the file was not found in the $dirs, or if no $dirs were specified,
|
||||||
|
* it will attempt to load it from PHP's include_path.
|
||||||
|
*
|
||||||
|
* @param string $class - The full class name of a Zend component.
|
||||||
|
* @param string|array $dirs - OPTIONAL Either a path or an array of paths
|
||||||
|
* to search.
|
||||||
|
* @return void
|
||||||
|
* @throws Zend_Exception
|
||||||
|
*/
|
||||||
|
public static function loadClass($class, $dirs = null)
|
||||||
|
{
|
||||||
|
if (class_exists($class, false) || interface_exists($class, false)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((null !== $dirs) && !is_string($dirs) && !is_array($dirs)) {
|
||||||
|
require_once 'Zend/Exception.php';
|
||||||
|
throw new Zend_Exception('Directory argument must be a string or an array');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Autodiscover the path from the class name
|
||||||
|
// Implementation is PHP namespace-aware, and based on
|
||||||
|
// Framework Interop Group reference implementation:
|
||||||
|
// http://groups.google.com/group/php-standards/web/psr-0-final-proposal
|
||||||
|
$className = ltrim($class, '\\');
|
||||||
|
$file = '';
|
||||||
|
$namespace = '';
|
||||||
|
if ($lastNsPos = strripos($className, '\\')) {
|
||||||
|
$namespace = substr($className, 0, $lastNsPos);
|
||||||
|
$className = substr($className, $lastNsPos + 1);
|
||||||
|
$file = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
||||||
|
}
|
||||||
|
$file .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
|
||||||
|
|
||||||
|
if (!empty($dirs)) {
|
||||||
|
// use the autodiscovered path
|
||||||
|
$dirPath = dirname($file);
|
||||||
|
if (is_string($dirs)) {
|
||||||
|
$dirs = explode(PATH_SEPARATOR, $dirs);
|
||||||
|
}
|
||||||
|
foreach ($dirs as $key => $dir) {
|
||||||
|
if ($dir == '.') {
|
||||||
|
$dirs[$key] = $dirPath;
|
||||||
|
} else {
|
||||||
|
$dir = rtrim($dir, '\\/');
|
||||||
|
$dirs[$key] = $dir . DIRECTORY_SEPARATOR . $dirPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$file = basename($file);
|
||||||
|
self::loadFile($file, $dirs, true);
|
||||||
|
} else {
|
||||||
|
self::loadFile($file, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!class_exists($class, false) && !interface_exists($class, false)) {
|
||||||
|
require_once 'Zend/Exception.php';
|
||||||
|
throw new Zend_Exception("File \"$file\" does not exist or class \"$class\" was not found in the file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a PHP file. This is a wrapper for PHP's include() function.
|
||||||
|
*
|
||||||
|
* $filename must be the complete filename, including any
|
||||||
|
* extension such as ".php". Note that a security check is performed that
|
||||||
|
* does not permit extended characters in the filename. This method is
|
||||||
|
* intended for loading Zend Framework files.
|
||||||
|
*
|
||||||
|
* If $dirs is a string or an array, it will search the directories
|
||||||
|
* in the order supplied, and attempt to load the first matching file.
|
||||||
|
*
|
||||||
|
* If the file was not found in the $dirs, or if no $dirs were specified,
|
||||||
|
* it will attempt to load it from PHP's include_path.
|
||||||
|
*
|
||||||
|
* If $once is TRUE, it will use include_once() instead of include().
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @param string|array $dirs - OPTIONAL either a path or array of paths
|
||||||
|
* to search.
|
||||||
|
* @param boolean $once
|
||||||
|
* @return boolean
|
||||||
|
* @throws Zend_Exception
|
||||||
|
*/
|
||||||
|
public static function loadFile($filename, $dirs = null, $once = false)
|
||||||
|
{
|
||||||
|
self::_securityCheck($filename);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search in provided directories, as well as include_path
|
||||||
|
*/
|
||||||
|
$incPath = false;
|
||||||
|
if (!empty($dirs) && (is_array($dirs) || is_string($dirs))) {
|
||||||
|
if (is_array($dirs)) {
|
||||||
|
$dirs = implode(PATH_SEPARATOR, $dirs);
|
||||||
|
}
|
||||||
|
$incPath = get_include_path();
|
||||||
|
set_include_path($dirs . PATH_SEPARATOR . $incPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try finding for the plain filename in the include_path.
|
||||||
|
*/
|
||||||
|
if ($once) {
|
||||||
|
include_once $filename;
|
||||||
|
} else {
|
||||||
|
include $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If searching in directories, reset include_path
|
||||||
|
*/
|
||||||
|
if ($incPath) {
|
||||||
|
set_include_path($incPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns TRUE if the $filename is readable, or FALSE otherwise.
|
||||||
|
* This function uses the PHP include_path, where PHP's is_readable()
|
||||||
|
* does not.
|
||||||
|
*
|
||||||
|
* Note from ZF-2900:
|
||||||
|
* If you use custom error handler, please check whether return value
|
||||||
|
* from error_reporting() is zero or not.
|
||||||
|
* At mark of fopen() can not suppress warning if the handler is used.
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function isReadable($filename)
|
||||||
|
{
|
||||||
|
if (is_readable($filename)) {
|
||||||
|
// Return early if the filename is readable without needing the
|
||||||
|
// include_path
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'
|
||||||
|
&& preg_match('/^[a-z]:/i', $filename)
|
||||||
|
) {
|
||||||
|
// If on windows, and path provided is clearly an absolute path,
|
||||||
|
// return false immediately
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (self::explodeIncludePath() as $path) {
|
||||||
|
if ($path == '.') {
|
||||||
|
if (is_readable($filename)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$file = $path . '/' . $filename;
|
||||||
|
if (is_readable($file)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Explode an include path into an array
|
||||||
|
*
|
||||||
|
* If no path provided, uses current include_path. Works around issues that
|
||||||
|
* occur when the path includes stream schemas.
|
||||||
|
*
|
||||||
|
* @param string|null $path
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function explodeIncludePath($path = null)
|
||||||
|
{
|
||||||
|
if (null === $path) {
|
||||||
|
$path = get_include_path();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PATH_SEPARATOR == ':') {
|
||||||
|
// On *nix systems, include_paths which include paths with a stream
|
||||||
|
// schema cannot be safely explode'd, so we have to be a bit more
|
||||||
|
// intelligent in the approach.
|
||||||
|
$paths = preg_split('#:(?!//)#', $path);
|
||||||
|
} else {
|
||||||
|
$paths = explode(PATH_SEPARATOR, $path);
|
||||||
|
}
|
||||||
|
return $paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* spl_autoload() suitable implementation for supporting class autoloading.
|
||||||
|
*
|
||||||
|
* Attach to spl_autoload() using the following:
|
||||||
|
* <code>
|
||||||
|
* spl_autoload_register(array('Zend_Loader', 'autoload'));
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @deprecated Since 1.8.0
|
||||||
|
* @param string $class
|
||||||
|
* @return string|false Class name on success; false on failure
|
||||||
|
*/
|
||||||
|
public static function autoload($class)
|
||||||
|
{
|
||||||
|
trigger_error(__CLASS__ . '::' . __METHOD__ . ' is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead', E_USER_NOTICE);
|
||||||
|
try {
|
||||||
|
@self::loadClass($class);
|
||||||
|
return $class;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register {@link autoload()} with spl_autoload()
|
||||||
|
*
|
||||||
|
* @deprecated Since 1.8.0
|
||||||
|
* @param string $class (optional)
|
||||||
|
* @param boolean $enabled (optional)
|
||||||
|
* @return void
|
||||||
|
* @throws Zend_Exception if spl_autoload() is not found
|
||||||
|
* or if the specified class does not have an autoload() method.
|
||||||
|
*/
|
||||||
|
public static function registerAutoload($class = 'Zend_Loader', $enabled = true)
|
||||||
|
{
|
||||||
|
trigger_error(__CLASS__ . '::' . __METHOD__ . ' is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead', E_USER_NOTICE);
|
||||||
|
require_once 'Zend/Loader/Autoloader.php';
|
||||||
|
$autoloader = Zend_Loader_Autoloader::getInstance();
|
||||||
|
$autoloader->setFallbackAutoloader(true);
|
||||||
|
|
||||||
|
if ('Zend_Loader' != $class) {
|
||||||
|
self::loadClass($class);
|
||||||
|
$methods = get_class_methods($class);
|
||||||
|
if (!in_array('autoload', (array) $methods)) {
|
||||||
|
require_once 'Zend/Exception.php';
|
||||||
|
throw new Zend_Exception("The class \"$class\" does not have an autoload() method");
|
||||||
|
}
|
||||||
|
|
||||||
|
$callback = array($class, 'autoload');
|
||||||
|
|
||||||
|
if ($enabled) {
|
||||||
|
$autoloader->pushAutoloader($callback);
|
||||||
|
} else {
|
||||||
|
$autoloader->removeAutoloader($callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that filename does not contain exploits
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @return void
|
||||||
|
* @throws Zend_Exception
|
||||||
|
*/
|
||||||
|
protected static function _securityCheck($filename)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Security check
|
||||||
|
*/
|
||||||
|
if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename)) {
|
||||||
|
require_once 'Zend/Exception.php';
|
||||||
|
throw new Zend_Exception('Security check: Illegal character in filename');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to include() the file.
|
||||||
|
*
|
||||||
|
* include() is not prefixed with the @ operator because if
|
||||||
|
* the file is loaded and contains a parse error, execution
|
||||||
|
* will halt silently and this is difficult to debug.
|
||||||
|
*
|
||||||
|
* Always set display_errors = Off on production servers!
|
||||||
|
*
|
||||||
|
* @param string $filespec
|
||||||
|
* @param boolean $once
|
||||||
|
* @return boolean
|
||||||
|
* @deprecated Since 1.5.0; use loadFile() instead
|
||||||
|
*/
|
||||||
|
protected static function _includeFile($filespec, $once = false)
|
||||||
|
{
|
||||||
|
if ($once) {
|
||||||
|
return include_once $filespec;
|
||||||
|
} else {
|
||||||
|
return include $filespec ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
167
libraries/feedwriter/FeedItem.php
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Univarsel Feed Writer
|
||||||
|
*
|
||||||
|
* FeedItem class - Used as feed element in FeedWriter class
|
||||||
|
*
|
||||||
|
* @package UnivarselFeedWriter
|
||||||
|
* @author Anis uddin Ahmad <anisniit@gmail.com>
|
||||||
|
* @link http://www.ajaxray.com/projects/rss
|
||||||
|
*/
|
||||||
|
class FeedItem
|
||||||
|
{
|
||||||
|
private $elements = array(); //Collection of feed elements
|
||||||
|
private $version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param contant (RSS1/RSS2/ATOM) RSS2 is default.
|
||||||
|
*/
|
||||||
|
function __construct($version = RSS2)
|
||||||
|
{
|
||||||
|
$this->version = $version;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an element to elements array
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param srting The tag name of an element
|
||||||
|
* @param srting The content of tag
|
||||||
|
* @param array Attributes(if any) in 'attrName' => 'attrValue' format
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addElement($elementName, $content, $attributes = null)
|
||||||
|
{
|
||||||
|
$this->elements[$elementName]['name'] = $elementName;
|
||||||
|
$this->elements[$elementName]['content'] = $content;
|
||||||
|
$this->elements[$elementName]['attributes'] = $attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set multiple feed elements from an array.
|
||||||
|
* Elements which have attributes cannot be added by this method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param array array of elements in 'tagName' => 'tagContent' format.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addElementArray($elementArray)
|
||||||
|
{
|
||||||
|
if(! is_array($elementArray)) return;
|
||||||
|
foreach ($elementArray as $elementName => $content)
|
||||||
|
{
|
||||||
|
$this->addElement($elementName, $content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the collection of elements in this feed item
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getElements()
|
||||||
|
{
|
||||||
|
return $this->elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrapper functions ------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the 'dscription' element of feed item
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string The content of 'description' element
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setDescription($description)
|
||||||
|
{
|
||||||
|
$tag = ($this->version == ATOM)? 'summary' : 'description';
|
||||||
|
$this->addElement($tag, $description);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc Set the 'title' element of feed item
|
||||||
|
* @access public
|
||||||
|
* @param string The content of 'title' element
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setTitle($title)
|
||||||
|
{
|
||||||
|
$this->addElement('title', $title);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the 'date' element of feed item
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string The content of 'date' element
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setDate($date)
|
||||||
|
{
|
||||||
|
if(! is_numeric($date))
|
||||||
|
{
|
||||||
|
$date = strtotime($date);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->version == ATOM)
|
||||||
|
{
|
||||||
|
$tag = 'updated';
|
||||||
|
$value = date(DATE_ATOM, $date);
|
||||||
|
}
|
||||||
|
elseif($this->version == RSS2)
|
||||||
|
{
|
||||||
|
$tag = 'pubDate';
|
||||||
|
$value = date(DATE_RSS, $date);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$tag = 'dc:date';
|
||||||
|
$value = date("Y-m-d", $date);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->addElement($tag, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the 'link' element of feed item
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string The content of 'link' element
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setLink($link)
|
||||||
|
{
|
||||||
|
if($this->version == RSS2 || $this->version == RSS1)
|
||||||
|
{
|
||||||
|
$this->addElement('link', $link);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->addElement('link','',array('href'=>$link));
|
||||||
|
$this->addElement('id', FeedWriter::uuid($link,'urn:uuid:'));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the 'encloser' element of feed item
|
||||||
|
* For RSS 2.0 only
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string The url attribute of encloser tag
|
||||||
|
* @param string The length attribute of encloser tag
|
||||||
|
* @param string The type attribute of encloser tag
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setEncloser($url, $length, $type)
|
||||||
|
{
|
||||||
|
$attributes = array('url'=>$url, 'length'=>$length, 'type'=>$type);
|
||||||
|
$this->addElement('enclosure','',$attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of class FeedItem
|
||||||
|
?>
|
430
libraries/feedwriter/FeedWriter.php
Normal file
@ -0,0 +1,430 @@
|
|||||||
|
<?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);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Univarsel Feed Writer class
|
||||||
|
*
|
||||||
|
* Genarate RSS 1.0, RSS2.0 and ATOM Feed
|
||||||
|
*
|
||||||
|
* @package UnivarselFeedWriter
|
||||||
|
* @author Anis uddin Ahmad <anisniit@gmail.com>
|
||||||
|
* @link http://www.ajaxray.com/projects/rss
|
||||||
|
*/
|
||||||
|
class FeedWriter
|
||||||
|
{
|
||||||
|
private $channels = array(); // Collection of channel elements
|
||||||
|
private $items = array(); // Collection of items as object of FeedItem class.
|
||||||
|
private $data = array(); // Store some other version wise data
|
||||||
|
private $CDATAEncoding = array(); // The tag names which have to encoded as CDATA
|
||||||
|
|
||||||
|
private $version = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param constant the version constant (RSS1/RSS2/ATOM).
|
||||||
|
*/
|
||||||
|
function __construct($version = RSS2)
|
||||||
|
{
|
||||||
|
$this->version = $version;
|
||||||
|
|
||||||
|
// Setting default value for assential channel elements
|
||||||
|
$this->channels['title'] = $version . ' Feed';
|
||||||
|
$this->channels['link'] = 'http://www.ajaxray.com/blog';
|
||||||
|
|
||||||
|
//Tag names to encode in CDATA
|
||||||
|
$this->CDATAEncoding = array('description', 'content:encoded', 'content', 'subtitle', 'summary');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start # public functions ---------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a channel element
|
||||||
|
* @access public
|
||||||
|
* @param srting name of the channel tag
|
||||||
|
* @param string content of the channel tag
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setChannelElement($elementName, $content)
|
||||||
|
{
|
||||||
|
$this->channels[$elementName] = $content ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set multiple channel elements from an array. Array elements
|
||||||
|
* should be 'channelName' => 'channelContent' format.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param array array of channels
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setChannelElementsFromArray($elementArray)
|
||||||
|
{
|
||||||
|
if(! is_array($elementArray)) return;
|
||||||
|
foreach ($elementArray as $elementName => $content)
|
||||||
|
{
|
||||||
|
$this->setChannelElement($elementName, $content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Genarate the actual RSS/ATOM file
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function genarateFeed()
|
||||||
|
{
|
||||||
|
header("Content-type: text/xml; charset=UTF-8");
|
||||||
|
|
||||||
|
$this->printHead();
|
||||||
|
$this->printChannels();
|
||||||
|
$this->printItems();
|
||||||
|
$this->printTale();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new FeedItem.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return object instance of FeedItem class
|
||||||
|
*/
|
||||||
|
public function createNewItem()
|
||||||
|
{
|
||||||
|
$Item = new FeedItem($this->version);
|
||||||
|
return $Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a FeedItem to the main class
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param object instance of FeedItem class
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addItem($feedItem)
|
||||||
|
{
|
||||||
|
$this->items[] = $feedItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Wrapper functions -------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the 'title' channel element
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param srting value of 'title' channel tag
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setTitle($title)
|
||||||
|
{
|
||||||
|
$this->setChannelElement('title', $title);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the 'description' channel element
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param srting value of 'description' channel tag
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setDescription($desciption)
|
||||||
|
{
|
||||||
|
$tag = ($this->version == ATOM)? 'subtitle' : 'description';
|
||||||
|
$this->setChannelElement($tag, $desciption);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the 'link' channel element
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param srting value of 'link' channel tag
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setLink($link)
|
||||||
|
{
|
||||||
|
$this->setChannelElement('link', $link);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the 'image' channel element
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param srting title of image
|
||||||
|
* @param srting link url of the imahe
|
||||||
|
* @param srting path url of the image
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setImage($title, $link, $url)
|
||||||
|
{
|
||||||
|
$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 ----------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the xml and rss namespace
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function printHead()
|
||||||
|
{
|
||||||
|
$out = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
|
||||||
|
|
||||||
|
if($this->version == RSS2)
|
||||||
|
{
|
||||||
|
$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;;
|
||||||
|
}
|
||||||
|
else if($this->version == ATOM)
|
||||||
|
{
|
||||||
|
$out .= '<feed xmlns="http://www.w3.org/2005/Atom">' . PHP_EOL;;
|
||||||
|
}
|
||||||
|
echo $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the open tags at the end of file
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function printTale()
|
||||||
|
{
|
||||||
|
if($this->version == RSS2)
|
||||||
|
{
|
||||||
|
echo '</channel>' . PHP_EOL . '</rss>';
|
||||||
|
}
|
||||||
|
elseif($this->version == RSS1)
|
||||||
|
{
|
||||||
|
echo '</rdf:RDF>';
|
||||||
|
}
|
||||||
|
else if($this->version == ATOM)
|
||||||
|
{
|
||||||
|
echo '</feed>';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a single node as xml format
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @param srting 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))
|
||||||
|
{
|
||||||
|
foreach ($attributes as $key => $value)
|
||||||
|
{
|
||||||
|
$attrText .= " $key=\"$value\" ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @desc Print channels
|
||||||
|
* @access private
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function printChannels()
|
||||||
|
{
|
||||||
|
//Start channel tag
|
||||||
|
switch ($this->version)
|
||||||
|
{
|
||||||
|
case RSS2:
|
||||||
|
echo '<channel>' . PHP_EOL;
|
||||||
|
break;
|
||||||
|
case RSS1:
|
||||||
|
echo (isset($this->data['ChannelAbout']))? "<channel rdf:about=\"{$this->data['ChannelAbout']}\">" : "<channel rdf:about=\"{$this->channels['link']}\">";
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints formatted feed items
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function printItems()
|
||||||
|
{
|
||||||
|
foreach ($this->items as $item)
|
||||||
|
{
|
||||||
|
$thisItems = $item->getElements();
|
||||||
|
|
||||||
|
//the argument is printed as rdf:about attribute of item in rss 1.0
|
||||||
|
echo $this->startItem($thisItems['link']['content']);
|
||||||
|
|
||||||
|
foreach ($thisItems as $feedItem )
|
||||||
|
{
|
||||||
|
echo $this->makeNode($feedItem['name'], $feedItem['content'], $feedItem['attributes']);
|
||||||
|
}
|
||||||
|
echo $this->endItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes feed item tag
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function endItem()
|
||||||
|
{
|
||||||
|
if($this->version == RSS2 || $this->version == RSS1)
|
||||||
|
{
|
||||||
|
echo '</item>' . PHP_EOL;
|
||||||
|
}
|
||||||
|
else if($this->version == ATOM)
|
||||||
|
{
|
||||||
|
echo "</entry>" . PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// End # private functions ----------------------------------------------
|
||||||
|
|
||||||
|
} // end of class FeedWriter
|
247
libraries/humble-http-agent/HumbleHttpAgent.php
Normal file
@ -0,0 +1,247 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Humble HTTP Agent
|
||||||
|
*
|
||||||
|
* This class is designed to take advantage of parallel HTTP requests
|
||||||
|
* offered by PHP's PECL HTTP extension. For environments which
|
||||||
|
* do not have this extension, it reverts to standard sequential
|
||||||
|
* requests (using file_get_contents())
|
||||||
|
*
|
||||||
|
* @version 2010-10-19
|
||||||
|
* @see http://php.net/HttpRequestPool
|
||||||
|
* @author Keyvan Minoukadeh
|
||||||
|
* @copyright 2010 Keyvan Minoukadeh
|
||||||
|
* @license http://www.gnu.org/licenses/agpl-3.0.html AGPL v3
|
||||||
|
*/
|
||||||
|
|
||||||
|
class HumbleHttpAgent
|
||||||
|
{
|
||||||
|
protected $requests = array();
|
||||||
|
protected $requestOptions;
|
||||||
|
protected $parallelSupport;
|
||||||
|
protected $maxParallelRequests = 5;
|
||||||
|
protected $cache = null;
|
||||||
|
protected $httpContext;
|
||||||
|
protected $minimiseMemoryUse = false;
|
||||||
|
protected $debug = false;
|
||||||
|
|
||||||
|
//TODO: prevent certain file/mime types
|
||||||
|
//TODO: set max file size
|
||||||
|
//TODO: normalise headers
|
||||||
|
|
||||||
|
function __construct($requestOptions=null) {
|
||||||
|
$this->parallelSupport = class_exists('HttpRequestPool');
|
||||||
|
$this->requestOptions = array(
|
||||||
|
'timeout' => 10,
|
||||||
|
'redirect' => 5
|
||||||
|
// TODO: test onprogress?
|
||||||
|
);
|
||||||
|
if (is_array($requestOptions)) {
|
||||||
|
$this->requestOptions = array_merge($this->requestOptions, $requestOptions);
|
||||||
|
}
|
||||||
|
$this->httpContext = stream_context_create(array(
|
||||||
|
'http' => array(
|
||||||
|
'timeout' => $this->requestOptions['timeout'],
|
||||||
|
'max_redirects' => $this->requestOptions['redirect']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function debug($msg) {
|
||||||
|
if ($this->debug) {
|
||||||
|
$mem = round(memory_get_usage()/1024, 2);
|
||||||
|
$memPeak = round(memory_get_peak_usage()/1024, 2);
|
||||||
|
echo '* ',$msg;
|
||||||
|
echo ' - mem used: ',$mem," (peak: $memPeak)\n";
|
||||||
|
ob_flush();
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enableDebug($bool=true) {
|
||||||
|
$this->debug = (bool)$bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function minimiseMemoryUse($bool = true) {
|
||||||
|
$this->minimiseMemoryUse = $bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMaxParallelRequests($max) {
|
||||||
|
$this->maxParallelRequests = $max;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set cache object.
|
||||||
|
* The cache object passed should implement Zend_Cache_Backend_Interface
|
||||||
|
* @param Zend_Cache_Backend_Interface
|
||||||
|
*/
|
||||||
|
public function useCache($cache) {
|
||||||
|
$this->cache = $cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateUrl($url) {
|
||||||
|
$url = filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED);
|
||||||
|
if ($url !== false && $url !== null && preg_match('!^https?://!', $url)) {
|
||||||
|
return filter_var($url, FILTER_SANITIZE_URL);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
$urls = array_unique($urls);
|
||||||
|
// parallel
|
||||||
|
if (count($urls) > 1 && $this->parallelSupport() && $this->maxParallelRequests > 1) {
|
||||||
|
$this->debug('Starting parallel fetch');
|
||||||
|
try {
|
||||||
|
while (count($urls) > 0) {
|
||||||
|
$this->debug('Processing set of '.$this->maxParallelRequests);
|
||||||
|
$subset = array_splice($urls, 0, $this->maxParallelRequests);
|
||||||
|
$pool = new HttpRequestPool();
|
||||||
|
foreach ($subset as $url) {
|
||||||
|
$this->debug("...$url");
|
||||||
|
if (isset($this->requests[$url])) {
|
||||||
|
$this->debug("......in memory");
|
||||||
|
} elseif ($this->isCached($url)) {
|
||||||
|
$this->debug("......is cached");
|
||||||
|
if (!$this->minimiseMemoryUse) {
|
||||||
|
$this->requests[$url] = $this->getCached($url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->debug("......adding to pool");
|
||||||
|
$httpRequest = new HttpRequest($url, HttpRequest::METH_GET, $this->requestOptions);
|
||||||
|
$this->requests[$url] = array('headers'=>null, 'body'=>null, 'httpRequest'=>$httpRequest);
|
||||||
|
$pool->attach($httpRequest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// did we get anything into the pool?
|
||||||
|
if (count($pool) > 0) {
|
||||||
|
$this->debug('Sending request...');
|
||||||
|
$pool->send();
|
||||||
|
$this->debug('Received responses');
|
||||||
|
foreach($subset as $url) {
|
||||||
|
if (!isset($this->requests[$url]['fromCache'])) {
|
||||||
|
$request = $this->requests[$url]['httpRequest'];
|
||||||
|
$this->requests[$url]['headers'] = $this->headersToString($request->getResponseHeader());
|
||||||
|
$this->requests[$url]['body'] = $request->getResponseBody();
|
||||||
|
$this->requests[$url]['effective_url'] = $request->getResponseInfo('effective_url');
|
||||||
|
//die($url.' -multi- '.$request->getResponseInfo('effective_url'));
|
||||||
|
$pool->detach($request);
|
||||||
|
unset($this->requests[$url]['httpRequest'], $request);
|
||||||
|
if ($this->minimiseMemoryUse) {
|
||||||
|
if ($this->cache($url)) {
|
||||||
|
unset($this->requests[$url]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (HttpException $e) {
|
||||||
|
$this->debug($e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// sequential
|
||||||
|
} else {
|
||||||
|
$this->debug('Starting sequential fetch...');
|
||||||
|
foreach($urls as $url) {
|
||||||
|
$this->get($url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function headersToString(array $headers, $associative=true) {
|
||||||
|
if (!$associative) {
|
||||||
|
return implode("\n", $headers);
|
||||||
|
} else {
|
||||||
|
$str = '';
|
||||||
|
foreach ($headers as $key => $val) {
|
||||||
|
if (is_array($val)) {
|
||||||
|
foreach ($val as $v) $str .= "$key: $v\n";
|
||||||
|
} else {
|
||||||
|
$str .= "$key: $val\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rtrim($str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRedirectUrl($header) {
|
||||||
|
if (is_array($header)) $header = implode("\n", $header);
|
||||||
|
if (!$header || !preg_match_all('!^Location:\s*(https?://.+)!im', $header, $match, PREG_SET_ORDER)) {
|
||||||
|
// error parsing the response
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
$match = end($match); // get last matched element (in case of redirects)
|
||||||
|
return $match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($url) {
|
||||||
|
if (isset($this->requests[$url]) && isset($this->requests[$url]['body'])) {
|
||||||
|
$this->debug("URL already fetched - in memory ($url)");
|
||||||
|
$response = $this->requests[$url];
|
||||||
|
} elseif ($this->isCached($url)) {
|
||||||
|
$this->debug("URL already fetched - in disk cache ($url)");
|
||||||
|
$response = $this->getCached($url);
|
||||||
|
$this->requests[$url] = $response;
|
||||||
|
} else {
|
||||||
|
$this->debug("Fetching URL ($url)");
|
||||||
|
if ($html = @file_get_contents($url, false, $this->httpContext)) {
|
||||||
|
$header = $this->headersToString($http_response_header, false);
|
||||||
|
$response = array('headers'=>$header, 'body'=>$html);
|
||||||
|
if ($last_url = $this->getRedirectUrl($header)) {
|
||||||
|
$response['effective_url'] = $last_url;
|
||||||
|
//die($url .' -single- '. $response['effective_url']);
|
||||||
|
} else {
|
||||||
|
$response['effective_url'] = $url;
|
||||||
|
}
|
||||||
|
$this->requests[$url] = $response;
|
||||||
|
} else {
|
||||||
|
$response = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($this->minimiseMemoryUse && $response) {
|
||||||
|
$this->cache($url);
|
||||||
|
unset($this->requests[$url]);
|
||||||
|
}
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parallelSupport() {
|
||||||
|
return $this->parallelSupport;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
26
libraries/iri/LICENSE
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
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.
|
1397
libraries/iri/iri.php
Normal file
110
libraries/readability/JSLikeHTMLElement.php
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* JavaScript-like HTML DOM Element
|
||||||
|
*
|
||||||
|
* This class extends PHP's DOMElement to allow
|
||||||
|
* users to get and set the innerHTML property of
|
||||||
|
* HTML elements in the same way it's done in
|
||||||
|
* JavaScript.
|
||||||
|
*
|
||||||
|
* Example usage:
|
||||||
|
* @code
|
||||||
|
* 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();
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @author Keyvan Minoukadeh - http://www.keyvan.net - keyvan@keyvan.net
|
||||||
|
* @see http://fivefilters.org (the project this was written for)
|
||||||
|
*/
|
||||||
|
class JSLikeHTMLElement extends DOMElement
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Used for setting innerHTML like it's done in JavaScript:
|
||||||
|
* @code
|
||||||
|
* $div->innerHTML = '<h2>Chapter 2</h2><p>The story begins...</p>';
|
||||||
|
* @endcode
|
||||||
|
*/
|
||||||
|
public function __set($name, $value) {
|
||||||
|
if ($name == 'innerHTML') {
|
||||||
|
// first, empty the element
|
||||||
|
for ($x=$this->childNodes->length-1; $x>=0; $x--) {
|
||||||
|
$this->removeChild($this->childNodes->item($x));
|
||||||
|
}
|
||||||
|
// $value holds our new inner HTML
|
||||||
|
if ($value != '') {
|
||||||
|
$f = $this->ownerDocument->createDocumentFragment();
|
||||||
|
// appendXML() expects well-formed markup (XHTML)
|
||||||
|
$result = @$f->appendXML($value); // @ to suppress PHP warnings
|
||||||
|
if ($result) {
|
||||||
|
if ($f->hasChildNodes()) $this->appendChild($f);
|
||||||
|
} else {
|
||||||
|
// $value is probably ill-formed
|
||||||
|
$f = new DOMDocument();
|
||||||
|
$value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8');
|
||||||
|
// Using <htmlfragment> will generate a warning, but so will bad HTML
|
||||||
|
// (and by this point, bad HTML is what we've got).
|
||||||
|
// We use it (and suppress the warning) because an HTML fragment will
|
||||||
|
// be wrapped around <html><body> tags which we don't really want to keep.
|
||||||
|
// Note: despite the warning, if loadHTML succeeds it will return true.
|
||||||
|
$result = @$f->loadHTML('<htmlfragment>'.$value.'</htmlfragment>');
|
||||||
|
if ($result) {
|
||||||
|
$import = $f->getElementsByTagName('htmlfragment')->item(0);
|
||||||
|
foreach ($import->childNodes as $child) {
|
||||||
|
$importedNode = $this->ownerDocument->importNode($child, true);
|
||||||
|
$this->appendChild($importedNode);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// oh well, we tried, we really did. :(
|
||||||
|
// this element is now empty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$trace = debug_backtrace();
|
||||||
|
trigger_error('Undefined property via __set(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for getting innerHTML like it's done in JavaScript:
|
||||||
|
* @code
|
||||||
|
* $string = $div->innerHTML;
|
||||||
|
* @endcode
|
||||||
|
*/
|
||||||
|
public function __get($name)
|
||||||
|
{
|
||||||
|
if ($name == 'innerHTML') {
|
||||||
|
$inner = '';
|
||||||
|
foreach ($this->childNodes as $child) {
|
||||||
|
$inner .= $this->ownerDocument->saveXML($child);
|
||||||
|
}
|
||||||
|
return $inner;
|
||||||
|
}
|
||||||
|
|
||||||
|
$trace = debug_backtrace();
|
||||||
|
trigger_error('Undefined property via __get(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return '['.$this->tagName.']';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
1070
libraries/readability/Readability.php
Normal file
20
libraries/readability/examples/JSLikeHTMLElement.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?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();
|
||||||
|
?>
|
41
libraries/readability/examples/Readability.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?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.
|
||||||
|
|
||||||
|
// 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. :(';
|
||||||
|
}
|
||||||
|
?>
|
26
libraries/simplepie/LICENSE.txt
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
Copyright (c) 2004-2007, Ryan Parman and Geoffrey Sneddon.
|
||||||
|
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.
|
30
libraries/simplepie/README.txt
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
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/
|
@ -0,0 +1,7 @@
|
|||||||
|
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.
|
316
libraries/simplepie/compatibility_test/sp_compatibility_test.php
Normal file
163
libraries/simplepie/create.php
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
<?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();
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
502
libraries/simplepie/idn/LICENCE
Normal file
@ -0,0 +1,502 @@
|
|||||||
|
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!
|
123
libraries/simplepie/idn/ReadMe.txt
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
*******************************************************************************
|
||||||
|
* *
|
||||||
|
* 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
|
969
libraries/simplepie/idn/idna_convert.class.php
Normal file
@ -0,0 +1,969 @@
|
|||||||
|
<?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
libraries/simplepie/idn/npdata.ser
Normal file
14539
libraries/simplepie/simplepie.class.php
Normal file
661
license.txt
Normal file
@ -0,0 +1,661 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, 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
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If 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 convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero 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
|
||||||
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state 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 program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
577
makefulltextfeed.php
Normal file
@ -0,0 +1,577 @@
|
|||||||
|
<?php
|
||||||
|
// Create Full-Text Feeds
|
||||||
|
// Author: Keyvan Minoukadeh
|
||||||
|
// Copyright (c) 2010 Keyvan Minoukadeh
|
||||||
|
// License: AGPLv3
|
||||||
|
// Version: 2.2
|
||||||
|
// Date: 2010-10-30
|
||||||
|
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
// -----
|
||||||
|
// Request this file passing it your feed in the querystring: makefulltextfeed.php?url=mysite.org
|
||||||
|
// The following options can be passed in the querystring:
|
||||||
|
// * URL: url=[feed or website url] (required, should be URL-encoded - in php: urlencode($url))
|
||||||
|
// * URL points to HTML (not feed): html=true (optional, by default it's automatically detected)
|
||||||
|
// * API key: key=[api key] (optional, refer to config.php)
|
||||||
|
// * Max entries to process: max=[max number of items] (optional)
|
||||||
|
|
||||||
|
error_reporting(E_ALL ^ E_NOTICE);
|
||||||
|
ini_set("display_errors", 1);
|
||||||
|
@set_time_limit(120);
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
static $mapping = array(
|
||||||
|
// Include SimplePie for RSS/Atom parsing
|
||||||
|
'SimplePie' => 'simplepie/simplepie.class.php',
|
||||||
|
'SimplePie_Misc' => 'simplepie/simplepie.class.php',
|
||||||
|
// Include FeedCreator for RSS/Atom creation
|
||||||
|
'FeedWriter' => 'feedwriter/FeedWriter.php',
|
||||||
|
'FeedItem' => 'feedwriter/FeedItem.php',
|
||||||
|
// Include Readability for identifying and extracting content from URLs
|
||||||
|
'Readability' => 'readability/Readability.php',
|
||||||
|
// Include Humble HTTP Agent to allow parallel requests and response caching
|
||||||
|
'HumbleHttpAgent' => 'humble-http-agent/HumbleHttpAgent.php',
|
||||||
|
// Include IRI class for resolving relative URLs
|
||||||
|
'IRI' => 'iri/iri.php',
|
||||||
|
// Include Zend Cache to improve performance (cache results)
|
||||||
|
'Zend_Cache' => 'Zend/Cache.php'
|
||||||
|
);
|
||||||
|
if (isset($mapping[$class_name])) {
|
||||||
|
//echo "Loading $class_name\n<br />";
|
||||||
|
require_once $mapping[$class_name];
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
// Load config file if it exists
|
||||||
|
////////////////////////////////
|
||||||
|
// the config values below should be set in config.php (rename config-sample.php if config.php doesn't exist).
|
||||||
|
// the values below will only be used if config.php doesn't exist.
|
||||||
|
$options->enabled = true;
|
||||||
|
$options->restrict = false;
|
||||||
|
$options->default_entries = 5;
|
||||||
|
$options->max_entries = 10;
|
||||||
|
$options->rewrite_relative_urls = true;
|
||||||
|
$options->caching = false;
|
||||||
|
$options->cache_dir = dirname(__FILE__).'/cache';
|
||||||
|
$options->message_to_prepend = '';
|
||||||
|
$options->message_to_append = '';
|
||||||
|
$options->blocked_urls = array();
|
||||||
|
$options->alternative_url = '';
|
||||||
|
$options->error_message = '[unable to retrieve full-text content]';
|
||||||
|
$options->api_keys = array();
|
||||||
|
$options->default_entries_with_key = 5;
|
||||||
|
$options->max_entries_with_key = 10;
|
||||||
|
$options->message_to_prepend_with_key = '';
|
||||||
|
$options->message_to_append_with_key = '';
|
||||||
|
$options->error_message_with_key = '[unable to retrieve full-text content]';
|
||||||
|
$options->cache_directory_level = 0;
|
||||||
|
if (file_exists(dirname(__FILE__).'/config.php')) {
|
||||||
|
require_once(dirname(__FILE__).'/config.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////
|
||||||
|
// Convert $html to UTF8
|
||||||
|
// (uses HTTP headers and HTML to find encoding)
|
||||||
|
// adapted from http://stackoverflow.com/questions/910793/php-detect-encoding-and-make-everything-utf-8
|
||||||
|
//////////////////////////////////////////////
|
||||||
|
function convert_to_utf8($html, $header=null)
|
||||||
|
{
|
||||||
|
$accept = array(
|
||||||
|
'type' => array('application/rss+xml', 'application/xml', 'application/rdf+xml', 'text/xml', 'text/html'),
|
||||||
|
'charset' => array_diff(mb_list_encodings(), array('pass', 'auto', 'wchar', 'byte2be', 'byte2le', 'byte4be', 'byte4le', 'BASE64', 'UUENCODE', 'HTML-ENTITIES', 'Quoted-Printable', '7bit', '8bit'))
|
||||||
|
);
|
||||||
|
$encoding = null;
|
||||||
|
if ($html || $header) {
|
||||||
|
if (is_array($header)) $header = implode("\n", $header);
|
||||||
|
if (!$header || !preg_match_all('/^Content-Type:\s+([^;]+)(?:;\s*charset=["\']?([^;"\'\n]*))?/im', $header, $match, PREG_SET_ORDER)) {
|
||||||
|
// error parsing the response
|
||||||
|
} else {
|
||||||
|
$match = end($match); // get last matched element (in case of redirects)
|
||||||
|
if (!in_array(strtolower($match[1]), $accept['type'])) {
|
||||||
|
// type not accepted
|
||||||
|
// TODO: avoid conversion
|
||||||
|
}
|
||||||
|
if (isset($match[2])) $encoding = trim($match[2], '"\'');
|
||||||
|
}
|
||||||
|
if (!$encoding) {
|
||||||
|
if (preg_match('/^<\?xml\s+version=(?:"[^"]*"|\'[^\']*\')\s+encoding=("[^"]*"|\'[^\']*\')/s', $html, $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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$encoding) {
|
||||||
|
$encoding = 'utf-8';
|
||||||
|
} else {
|
||||||
|
if (!in_array($encoding, array_map('strtolower', $accept['charset']))) {
|
||||||
|
// encoding not accepted
|
||||||
|
// TODO: avoid conversion
|
||||||
|
}
|
||||||
|
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
|
||||||
|
$html = iconv($encoding, 'utf-8', $html);
|
||||||
|
} else {
|
||||||
|
$html = mb_convert_encoding($html, 'utf-8', $encoding);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeAbsolute($base, $elem) {
|
||||||
|
$base = new IRI($base);
|
||||||
|
foreach(array('a'=>'href', 'img'=>'src') as $tag => $attr) {
|
||||||
|
$elems = $elem->getElementsByTagName($tag);
|
||||||
|
for ($i = $elems->length-1; $i >= 0; $i--) {
|
||||||
|
$e = $elems->item($i);
|
||||||
|
//$e->parentNode->replaceChild($articleContent->ownerDocument->createTextNode($e->textContent), $e);
|
||||||
|
if ($e->hasAttribute($attr)) {
|
||||||
|
// Trim leading and trailing white space. I don't really like this but
|
||||||
|
// unfortunately it does appear on some sites. e.g. <img src=" /path/to/image.jpg" />
|
||||||
|
$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) {
|
||||||
|
$e->setAttribute($attr, $absolute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
// Check if service is enabled
|
||||||
|
////////////////////////////////
|
||||||
|
if (!$options->enabled) {
|
||||||
|
die('The full-text RSS service is currently disabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
// Check for feed URL
|
||||||
|
////////////////////////////////
|
||||||
|
if (!isset($_GET['url'])) {
|
||||||
|
die('No URL supplied');
|
||||||
|
}
|
||||||
|
$url = $_GET['url'];
|
||||||
|
if (!preg_match('!^https?://.+!i', $url)) {
|
||||||
|
$url = 'http://'.$url;
|
||||||
|
}
|
||||||
|
$valid_url = filter_var($url, FILTER_VALIDATE_URL);
|
||||||
|
if ($valid_url !== false && $valid_url !== null && preg_match('!^https?://!', $valid_url)) {
|
||||||
|
$url = filter_var($url, FILTER_SANITIZE_URL);
|
||||||
|
} else {
|
||||||
|
die('Invalid URL supplied');
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
// Redirect to alternative 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['key'])) $redirect .= '&key='.urlencode($_GET['key']);
|
||||||
|
if (isset($_GET['max'])) $redirect .= '&max='.(int)$_GET['max'];
|
||||||
|
if (isset($_GET['links'])) $redirect .= '&links='.$_GET['links'];
|
||||||
|
header("Location: $redirect");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
// Check if the request is explicitly for an HTML page
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
$html_only = (isset($_GET['html']) && $_GET['html'] == 'true');
|
||||||
|
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
// Check if valid key supplied
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
$valid_key = (isset($_GET['key']) && in_array($_GET['key'], $options->api_keys));
|
||||||
|
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
// Check URL against list of blacklisted URLs
|
||||||
|
// TODO: set up better system for this
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
foreach ($options->blocked_urls as $blockurl) {
|
||||||
|
if (strstr($url, $blockurl) !== false) {
|
||||||
|
die('URL blocked');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
// Max entries
|
||||||
|
// see config.php to find these values
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
if (isset($_GET['max'])) {
|
||||||
|
$max = (int)$_GET['max'];
|
||||||
|
if ($valid_key) {
|
||||||
|
$max = min($max, $options->max_entries_with_key);
|
||||||
|
} else {
|
||||||
|
$max = min($max, $options->max_entries);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($valid_key) {
|
||||||
|
$max = $options->default_entries_with_key;
|
||||||
|
} else {
|
||||||
|
$max = $options->default_entries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
// Link handling
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
if (($valid_key || !$options->restrict) && isset($_GET['links']) && in_array($_GET['links'], array('preserve', 'footnotes', 'remove'))) {
|
||||||
|
$links = $_GET['links'];
|
||||||
|
} else {
|
||||||
|
$links = 'preserve';
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////
|
||||||
|
// Check for valid format
|
||||||
|
// (stick to RSS for the time being)
|
||||||
|
/////////////////////////////////////
|
||||||
|
$format = 'rss';
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
// Check for cached copy
|
||||||
|
//////////////////////////////////
|
||||||
|
if ($options->caching) {
|
||||||
|
$frontendOptions = array(
|
||||||
|
'lifetime' => ($valid_key || !$options->restrict) ? 10*60 : 20*60, // cache lifetime of 10 or 20 minutes
|
||||||
|
'automatic_serialization' => false,
|
||||||
|
'write_control' => false,
|
||||||
|
'automatic_cleaning_factor' => 100,
|
||||||
|
'ignore_user_abort' => false
|
||||||
|
);
|
||||||
|
$backendOptions = array(
|
||||||
|
'cache_dir' => ($valid_key) ? $options->cache_dir.'/rss-with-key/' : $options->cache_dir.'/rss/', // directory where to put the cache files
|
||||||
|
'file_locking' => false,
|
||||||
|
'read_control' => true,
|
||||||
|
'read_control_type' => 'strlen',
|
||||||
|
'hashed_directory_level' => $options->cache_directory_level,
|
||||||
|
'hashed_directory_umask' => 0777,
|
||||||
|
'cache_file_umask' => 0664,
|
||||||
|
'file_name_prefix' => 'ff'
|
||||||
|
);
|
||||||
|
|
||||||
|
// getting a Zend_Cache_Core object
|
||||||
|
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
|
||||||
|
$cache_id = md5($max.$url.$valid_key.$links);
|
||||||
|
|
||||||
|
if ($data = $cache->load($cache_id)) {
|
||||||
|
header("Content-type: text/xml; charset=UTF-8");
|
||||||
|
if (headers_sent()) die('Some data has already been output, can\'t send RSS file');
|
||||||
|
echo $data;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
// Set Expires header
|
||||||
|
//////////////////////////////////
|
||||||
|
if ($valid_key) {
|
||||||
|
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+(60*10)) . ' GMT');
|
||||||
|
} else {
|
||||||
|
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+(60*20)) . ' GMT');
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
// Set up HTTP agent
|
||||||
|
//////////////////////////////////
|
||||||
|
$http = new HumbleHttpAgent();
|
||||||
|
|
||||||
|
if ($options->caching) {
|
||||||
|
$frontendOptions = array(
|
||||||
|
'lifetime' => 30*60, // cache lifetime of 30 minutes
|
||||||
|
'automatic_serialization' => true,
|
||||||
|
'write_control' => false,
|
||||||
|
'automatic_cleaning_factor' => 100,
|
||||||
|
'ignore_user_abort' => false
|
||||||
|
);
|
||||||
|
$backendOptions = array(
|
||||||
|
'cache_dir' => $options->cache_dir.'/http-responses/', // directory where to put the cache files
|
||||||
|
'file_locking' => false,
|
||||||
|
'read_control' => true,
|
||||||
|
'read_control_type' => 'strlen',
|
||||||
|
'hashed_directory_level' => $options->cache_directory_level,
|
||||||
|
'hashed_directory_umask' => 0777,
|
||||||
|
'cache_file_umask' => 0664,
|
||||||
|
'file_name_prefix' => 'ff'
|
||||||
|
);
|
||||||
|
$httpCache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
|
||||||
|
$http->useCache($httpCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
// Tidy config
|
||||||
|
////////////////////////////////
|
||||||
|
if (function_exists('tidy_parse_string')) {
|
||||||
|
$tidy_config = array(
|
||||||
|
'clean' => true,
|
||||||
|
'output-xhtml' => true,
|
||||||
|
'logical-emphasis' => true,
|
||||||
|
'show-body-only' => false,
|
||||||
|
'wrap' => 0,
|
||||||
|
'drop-empty-paras' => true,
|
||||||
|
'drop-proprietary-attributes' => false,
|
||||||
|
'enclose-text' => true,
|
||||||
|
'enclose-block-text' => true,
|
||||||
|
'merge-divs' => true,
|
||||||
|
'merge-spans' => true,
|
||||||
|
'char-encoding' => 'utf8',
|
||||||
|
'hide-comments' => true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
// Get RSS/Atom feed
|
||||||
|
////////////////////////////////
|
||||||
|
if (!$html_only) {
|
||||||
|
$feed = new SimplePie();
|
||||||
|
$feed->set_feed_url($url);
|
||||||
|
$feed->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
|
||||||
|
$feed->set_timeout(20);
|
||||||
|
$feed->enable_cache(false);
|
||||||
|
$feed->set_stupidly_fast(true);
|
||||||
|
$feed->enable_order_by_date(false); // we don't want to do anything to the feed
|
||||||
|
$feed->set_url_replacements(array());
|
||||||
|
// initialise the feed
|
||||||
|
// the @ suppresses notices which on some servers causes a 500 internal server error
|
||||||
|
$result = @$feed->init();
|
||||||
|
//$feed->handle_content_type();
|
||||||
|
//$feed->get_title();
|
||||||
|
if ($result && (!is_array($feed->data) || count($feed->data) == 0)) {
|
||||||
|
die('Sorry, no feed items found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Extract content from HTML (if URL is not feed or explicit HTML request has been made)
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
if ($html_only || !$result) {
|
||||||
|
unset($feed, $result);
|
||||||
|
if ($response = $http->get($url)) {
|
||||||
|
$effective_url = $response['effective_url'];
|
||||||
|
$html = $response['body'];
|
||||||
|
$html = convert_to_utf8($html, $response['headers']);
|
||||||
|
} else {
|
||||||
|
die('Error retrieving '.$url);
|
||||||
|
}
|
||||||
|
// Run through Tidy (if it exists).
|
||||||
|
// This fixes problems with some sites which would otherwise
|
||||||
|
// trouble DOMDocument's HTML parsing.
|
||||||
|
if (function_exists('tidy_parse_string')) {
|
||||||
|
$tidy = tidy_parse_string($html, $tidy_config, 'UTF8');
|
||||||
|
if (tidy_clean_repair($tidy)) {
|
||||||
|
$html = $tidy->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$readability = new Readability($html, $effective_url);
|
||||||
|
if ($links == 'footnotes') $readability->convertLinksToFootnotes = true;
|
||||||
|
$readability->init();
|
||||||
|
$readability->clean($readability->getContent(), 'select');
|
||||||
|
if ($options->rewrite_relative_urls) makeAbsolute($effective_url, $readability->getContent());
|
||||||
|
$title = $readability->getTitle()->textContent;
|
||||||
|
$content = $readability->getContent()->innerHTML;
|
||||||
|
if ($links == 'remove') {
|
||||||
|
$content = preg_replace('!</?a[^>]*>!', '', $content);
|
||||||
|
}
|
||||||
|
if (!$valid_key) {
|
||||||
|
$content = $options->message_to_prepend.$content;
|
||||||
|
$content .= $options->message_to_append;
|
||||||
|
} else {
|
||||||
|
$content = $options->message_to_prepend_with_key.$content;
|
||||||
|
$content .= $options->message_to_append_with_key;
|
||||||
|
}
|
||||||
|
unset($readability, $html);
|
||||||
|
$output = new FeedWriter(); //ATOM an option
|
||||||
|
$output->setTitle($title);
|
||||||
|
$output->setDescription("Content extracted from $url");
|
||||||
|
if ($format == 'atom') {
|
||||||
|
$output->setChannelElement('updated', date(DATE_ATOM));
|
||||||
|
$output->setChannelElement('author', array('name'=>'Five Filters', 'uri'=>'http://fivefilters.org'));
|
||||||
|
}
|
||||||
|
$output->setLink($url);
|
||||||
|
$newitem = $output->createNewItem();
|
||||||
|
$newitem->setTitle($title);
|
||||||
|
$newitem->setLink($url);
|
||||||
|
if ($format == 'atom') {
|
||||||
|
$newitem->setDate(time());
|
||||||
|
$newitem->addElement('content', $content);
|
||||||
|
} else {
|
||||||
|
$newitem->setDescription($content);
|
||||||
|
}
|
||||||
|
$output->addItem($newitem);
|
||||||
|
$output->genarateFeed();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
// Create full-text feed
|
||||||
|
////////////////////////////////////////////
|
||||||
|
$output = new FeedWriter();
|
||||||
|
$output->setTitle($feed->get_title());
|
||||||
|
$output->setDescription($feed->get_description());
|
||||||
|
$output->setLink($feed->get_link());
|
||||||
|
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
|
||||||
|
////////////////////////////////////////////
|
||||||
|
$items = $feed->get_items(0, $max);
|
||||||
|
// Request all feed items in parallel (if supported)
|
||||||
|
$urls_sanitized = array();
|
||||||
|
$urls = array();
|
||||||
|
foreach ($items as $key => $item) {
|
||||||
|
$permalink = htmlspecialchars_decode($item->get_permalink());
|
||||||
|
$permalink = $http->validateUrl($permalink);
|
||||||
|
if ($permalink) {
|
||||||
|
$urls_sanitized[] = $permalink;
|
||||||
|
}
|
||||||
|
$urls[$key] = $permalink;
|
||||||
|
}
|
||||||
|
$http->fetchAll($urls_sanitized);
|
||||||
|
$http->cacheAll();
|
||||||
|
|
||||||
|
foreach ($items as $key => $item) {
|
||||||
|
$permalink = $urls[$key];
|
||||||
|
$newitem = $output->createNewItem();
|
||||||
|
$newitem->setTitle(htmlspecialchars_decode($item->get_title()));
|
||||||
|
if ($permalink !== false) {
|
||||||
|
$newitem->setLink($permalink);
|
||||||
|
} else {
|
||||||
|
$newitem->setLink($item->get_permalink());
|
||||||
|
}
|
||||||
|
if ($permalink && $response = $http->get($permalink)) {
|
||||||
|
$effective_url = $response['effective_url'];
|
||||||
|
$html = $response['body'];
|
||||||
|
$html = convert_to_utf8($html, $response['headers']);
|
||||||
|
// Run through Tidy (if it exists).
|
||||||
|
// This fixes problems with some sites which would otherwise
|
||||||
|
// trouble DOMDocument's HTML parsing. (Although sometimes it fails
|
||||||
|
// to return anything, so it's a bit of tradeoff.)
|
||||||
|
if (function_exists('tidy_parse_string')) {
|
||||||
|
$tidy = tidy_parse_string($html, $tidy_config, 'UTF8');
|
||||||
|
$tidy->cleanRepair();
|
||||||
|
$html = $tidy->value;
|
||||||
|
}
|
||||||
|
$readability = new Readability($html, $effective_url);
|
||||||
|
if ($links == 'footnotes') $readability->convertLinksToFootnotes = true;
|
||||||
|
$readability->init();
|
||||||
|
$readability->clean($readability->getContent(), 'select');
|
||||||
|
if ($options->rewrite_relative_urls) makeAbsolute($effective_url, $readability->getContent());
|
||||||
|
$html = $readability->getContent()->innerHTML;
|
||||||
|
if ($links == 'remove') {
|
||||||
|
$html = preg_replace('!</?a[^>]*>!', '', $html);
|
||||||
|
}
|
||||||
|
if (!$valid_key) {
|
||||||
|
$html = $options->message_to_prepend.$html;
|
||||||
|
$html .= $options->message_to_append;
|
||||||
|
} else {
|
||||||
|
$html = $options->message_to_prepend_with_key.$html;
|
||||||
|
$html .= $options->message_to_append_with_key;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!$valid_key) {
|
||||||
|
$html = $options->error_message;
|
||||||
|
} else {
|
||||||
|
$html = $options->error_message_with_key;
|
||||||
|
}
|
||||||
|
$html .= $item->get_description();
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
$newitem->addElement('guid', $item->get_permalink(), array('isPermaLink'=>'true'));
|
||||||
|
$newitem->setDescription($html);
|
||||||
|
if ((int)$item->get_date('U') > 0) {
|
||||||
|
$newitem->setDate((int)$item->get_date('U'));
|
||||||
|
}
|
||||||
|
if ($author = $item->get_author()) {
|
||||||
|
$newitem->addElement('dc:creator', $author->get_name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$output->addItem($newitem);
|
||||||
|
unset($html);
|
||||||
|
}
|
||||||
|
// output feed
|
||||||
|
if ($options->caching) {
|
||||||
|
ob_start();
|
||||||
|
$output->genarateFeed();
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
$cache->save($output, $cache_id);
|
||||||
|
echo $output;
|
||||||
|
} else {
|
||||||
|
$output->genarateFeed();
|
||||||
|
}
|
||||||
|
?>
|