commit
4ff31d0a41
@ -28,3 +28,4 @@ AddType audio/ogg .oga
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^(.*)$ index.php?q=$1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
|
||||
</IfModule>
|
||||
|
||||
|
18
Zotlabs/Identity/BasicId.php
Normal file
18
Zotlabs/Identity/BasicId.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Zotlabs\Identity\BasicId;
|
||||
|
||||
class BasicId {
|
||||
|
||||
private $name;
|
||||
private $profile_photo;
|
||||
private $profile_url;
|
||||
private $address;
|
||||
private $protocol;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
16
Zotlabs/Identity/ProfilePhoto.php
Normal file
16
Zotlabs/Identity/ProfilePhoto.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Zotlabs\Identity\ProfilePhoto;
|
||||
|
||||
class ProfilePhoto {
|
||||
|
||||
private $photo_large_url;
|
||||
private $photo_medium_url;
|
||||
private $photo_small_url;
|
||||
private $photo_mimetype;
|
||||
private $photo_updated;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
345
Zotlabs/Zot/Auth.php
Normal file
345
Zotlabs/Zot/Auth.php
Normal file
@ -0,0 +1,345 @@
|
||||
<?php
|
||||
|
||||
namespace Zotlabs\Zot;
|
||||
|
||||
class Auth {
|
||||
|
||||
protected $test;
|
||||
protected $test_results;
|
||||
protected $debug_msg;
|
||||
|
||||
protected $address;
|
||||
protected $desturl;
|
||||
protected $sec;
|
||||
protected $version;
|
||||
protected $delegate;
|
||||
protected $success;
|
||||
protected $delegate_success;
|
||||
|
||||
protected $remote;
|
||||
protected $remote_service_class;
|
||||
protected $remote_level;
|
||||
protected $remote_hub;
|
||||
protected $dnt;
|
||||
|
||||
function __construct($req) {
|
||||
|
||||
|
||||
$this->test = ((array_key_exists('test',$req)) ? intval($req['test']) : 0);
|
||||
$this->test_results = array('success' => false);
|
||||
$this->debug_msg = '';
|
||||
|
||||
$this->success = false;
|
||||
$this->address = $req['auth'];
|
||||
$this->desturl = $req['dest'];
|
||||
$this->sec = $req['sec'];
|
||||
$this->version = $req['version'];
|
||||
$this->delegate = $req['delegate'];
|
||||
|
||||
$c = get_sys_channel();
|
||||
if(! $c) {
|
||||
logger('unable to obtain response (sys) channel');
|
||||
$this->Debug('no local channels found.');
|
||||
$this->Finalise();
|
||||
}
|
||||
|
||||
$x = $this->GetHublocs($this->address);
|
||||
|
||||
if($x) {
|
||||
foreach($x as $xx) {
|
||||
if($this->Verify($c,$xx))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @FIXME we really want to save the return_url in the session before we
|
||||
* visit rmagic. This does however prevent a recursion if you visit
|
||||
* rmagic directly, as it would otherwise send you back here again.
|
||||
* But z_root() probably isn't where you really want to go.
|
||||
*/
|
||||
|
||||
if(strstr($this->desturl,z_root() . '/rmagic'))
|
||||
goaway(z_root());
|
||||
|
||||
$this->Finalise();
|
||||
|
||||
}
|
||||
|
||||
function GetHublocs($address) {
|
||||
|
||||
// Try and find a hubloc for the person attempting to auth.
|
||||
// Since we're matching by address, we have to return all entries
|
||||
// some of which may be from re-installed hubs; and we'll need to
|
||||
// try each sequentially to see if one can pass the test
|
||||
|
||||
$x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash
|
||||
where hubloc_addr = '%s' order by hubloc_id desc",
|
||||
dbesc($address)
|
||||
);
|
||||
|
||||
if(! $x) {
|
||||
// finger them if they can't be found.
|
||||
$ret = zot_finger($address, null);
|
||||
if ($ret['success']) {
|
||||
$j = json_decode($ret['body'], true);
|
||||
if($j)
|
||||
import_xchan($j);
|
||||
$x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash
|
||||
where hubloc_addr = '%s' order by hubloc_id desc",
|
||||
dbesc($address)
|
||||
);
|
||||
}
|
||||
}
|
||||
if(! $x) {
|
||||
logger('mod_zot: auth: unable to finger ' . $address);
|
||||
$this->Debug('no hubloc found for ' . $address . ' and probing failed.');
|
||||
$this->Finalise();
|
||||
}
|
||||
|
||||
return $x;
|
||||
}
|
||||
|
||||
|
||||
function Verify($channel,$hubloc) {
|
||||
|
||||
logger('auth request received from ' . $hubloc['hubloc_addr'] );
|
||||
|
||||
$this->remote = remote_channel();
|
||||
$this->remote_service_class = '';
|
||||
$this->remote_level = 0;
|
||||
$this->remote_hub = $hubloc['hubloc_url'];
|
||||
$this->dnt = 0;
|
||||
|
||||
// check credentials and access
|
||||
|
||||
// If they are already authenticated and haven't changed credentials,
|
||||
// we can save an expensive network round trip and improve performance.
|
||||
|
||||
// Also check that they are coming from the same site as they authenticated with originally.
|
||||
|
||||
$already_authed = (((remote_channel()) && ($hubloc['hubloc_hash'] == remote_channel())
|
||||
&& ($hubloc['hubloc_url'] === $_SESSION['remote_hub'])) ? true : false);
|
||||
|
||||
if($this->delegate && $this->delegate !== $_SESSION['delegate_channel'])
|
||||
$already_authed = false;
|
||||
|
||||
if($already_authed)
|
||||
return true;
|
||||
|
||||
if(local_channel()) {
|
||||
|
||||
// tell them to logout if they're logged in locally as anything but the target remote account
|
||||
// in which case just shut up because they don't need to be doing this at all.
|
||||
|
||||
if (get_app()->channel['channel_hash'] == $hubloc['xchan_hash']) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
logger('already authenticated locally as somebody else.');
|
||||
notice( t('Remote authentication blocked. You are logged into this site locally. Please logout and retry.') . EOL);
|
||||
if($this->test) {
|
||||
$this->Debug('already logged in locally with a conflicting identity.');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Auth packets MUST use ultra top-secret hush-hush mode - e.g. the entire packet is encrypted using the
|
||||
// site private key
|
||||
// The actual channel sending the packet ($c[0]) is not important, but this provides a
|
||||
// generic zot packet with a sender which can be verified
|
||||
|
||||
$p = zot_build_packet($channel,$type = 'auth_check',
|
||||
array(array('guid' => $hubloc['hubloc_guid'],'guid_sig' => $hubloc['hubloc_guid_sig'])),
|
||||
$hubloc['hubloc_sitekey'], $this->sec);
|
||||
|
||||
$this->Debug('auth check packet created using sitekey ' . $hubloc['hubloc_sitekey']);
|
||||
$this->Debug('packet contents: ' . $p);
|
||||
|
||||
$result = zot_zot($hubloc['hubloc_callback'],$p);
|
||||
if(! $result['success']) {
|
||||
logger('auth_check callback failed.');
|
||||
if($this->test)
|
||||
$this->Debug('auth check request to your site returned .' . print_r($result, true));
|
||||
return false;
|
||||
}
|
||||
|
||||
$j = json_decode($result['body'], true);
|
||||
if(! $j) {
|
||||
logger('auth_check json data malformed.');
|
||||
if($this->test)
|
||||
$this->Debug('json malformed: ' . $result['body']);
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->Debug('auth check request returned .' . print_r($j, true));
|
||||
|
||||
if(! $j['success'])
|
||||
return false;
|
||||
|
||||
// legit response, but we do need to check that this wasn't answered by a man-in-middle
|
||||
|
||||
if (! rsa_verify($this->sec . $hubloc['xchan_hash'],base64url_decode($j['confirm']),$hubloc['xchan_pubkey'])) {
|
||||
logger('final confirmation failed.');
|
||||
if($this->test)
|
||||
$this->Debug('final confirmation failed. ' . $sec . print_r($j,true) . print_r($hubloc,true));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (array_key_exists('service_class',$j))
|
||||
$this->remote_service_class = $j['service_class'];
|
||||
if (array_key_exists('level',$j))
|
||||
$this->remote_level = $j['level'];
|
||||
if (array_key_exists('DNT',$j))
|
||||
$this->dnt = $j['DNT'];
|
||||
|
||||
|
||||
// log them in
|
||||
|
||||
if ($this->test) {
|
||||
// testing only - return the success result
|
||||
$this->test_results['success'] = true;
|
||||
$this->Debug('Authentication Success!');
|
||||
$this->Finalise();
|
||||
}
|
||||
|
||||
$_SESSION['authenticated'] = 1;
|
||||
|
||||
// check for delegation and if all is well, log them in locally with delegation restrictions
|
||||
|
||||
$this->delegate_success = false;
|
||||
|
||||
if($this->delegate) {
|
||||
$r = q("select * from channel left join xchan on channel_hash = xchan_hash where xchan_addr = '%s' limit 1",
|
||||
dbesc($this->delegate)
|
||||
);
|
||||
if ($r && intval($r[0]['channel_id'])) {
|
||||
$allowed = perm_is_allowed($r[0]['channel_id'],$hubloc['xchan_hash'],'delegate');
|
||||
if($allowed) {
|
||||
$_SESSION['delegate_channel'] = $r[0]['channel_id'];
|
||||
$_SESSION['delegate'] = $hubloc['xchan_hash'];
|
||||
$_SESSION['account_id'] = intval($r[0]['channel_account_id']);
|
||||
require_once('include/security.php');
|
||||
// this will set the local_channel authentication in the session
|
||||
change_channel($r[0]['channel_id']);
|
||||
$this->delegate_success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! $this->delegate_success) {
|
||||
// normal visitor (remote_channel) login session credentials
|
||||
$_SESSION['visitor_id'] = $hubloc['xchan_hash'];
|
||||
$_SESSION['my_url'] = $hubloc['xchan_url'];
|
||||
$_SESSION['my_address'] = $this->address;
|
||||
$_SESSION['remote_service_class'] = $this->remote_service_class;
|
||||
$_SESSION['remote_level'] = $this->remote_level;
|
||||
$_SESSION['remote_hub'] = $this->remote_hub;
|
||||
$_SESSION['DNT'] = $this->dnt;
|
||||
}
|
||||
|
||||
$arr = array('xchan' => $hubloc, 'url' => $this->desturl, 'session' => $_SESSION);
|
||||
call_hooks('magic_auth_success',$arr);
|
||||
get_app()->set_observer($hubloc);
|
||||
require_once('include/security.php');
|
||||
get_app()->set_groups(init_groups_visitor($_SESSION['visitor_id']));
|
||||
info(sprintf( t('Welcome %s. Remote authentication successful.'),$hubloc['xchan_name']));
|
||||
logger('mod_zot: auth success from ' . $hubloc['xchan_addr']);
|
||||
$this->success = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
function Debug($msg) {
|
||||
$this->debug_msg .= $msg . EOL;
|
||||
}
|
||||
|
||||
|
||||
function Finalise() {
|
||||
|
||||
if($this->test) {
|
||||
$this->test_results['message'] = $this->debug_msg;
|
||||
json_return_and_die($this->test_results);
|
||||
}
|
||||
|
||||
goaway($this->desturl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Magic Auth
|
||||
* ==========
|
||||
*
|
||||
* So-called "magic auth" takes place by a special exchange. On the site where the "channel to be authenticated" lives (e.g. $mysite),
|
||||
* a redirection is made via $mysite/magic to the zot endpoint of the remote site ($remotesite) with special GET parameters.
|
||||
*
|
||||
* The endpoint is typically https://$remotesite/post - or whatever was specified as the callback url in prior communications
|
||||
* (we will bootstrap an address and fetch a zot info packet if possible where no prior communications exist)
|
||||
*
|
||||
* Five GET parameters are supplied:
|
||||
* * auth => the urlencoded webbie (channel@host.domain) of the channel requesting access
|
||||
* * dest => the desired destination URL (urlencoded)
|
||||
* * sec => a random string which is also stored on $mysite for use during the verification phase.
|
||||
* * version => the zot revision
|
||||
* * delegate => optional urlencoded webbie of a local channel to invoke delegation rights for
|
||||
*
|
||||
* * test => (optional 1 or 0 - debugs the authentication exchange and returns a json response instead of redirecting the browser session)
|
||||
*
|
||||
* When this packet is received, an "auth-check" zot message is sent to $mysite.
|
||||
* (e.g. if $_GET['auth'] is foobar@podunk.edu, a zot packet is sent to the podunk.edu zot endpoint, which is typically /post)
|
||||
* If no information has been recorded about the requesting identity a zot information packet will be retrieved before
|
||||
* continuing.
|
||||
*
|
||||
* The sender of this packet is an arbitrary/random site channel. The recipients will be a single recipient corresponding
|
||||
* to the guid and guid_sig we have associated with the requesting auth identity
|
||||
*
|
||||
* \code{.json}
|
||||
* {
|
||||
* "type":"auth_check",
|
||||
* "sender":{
|
||||
* "guid":"kgVFf_...",
|
||||
* "guid_sig":"PT9-TApz...",
|
||||
* "url":"http:\/\/podunk.edu",
|
||||
* "url_sig":"T8Bp7j...",
|
||||
* "sitekey":"aMtgKTiirXrICP..."
|
||||
* },
|
||||
* "recipients":{
|
||||
* {
|
||||
* "guid":"ZHSqb...",
|
||||
* "guid_sig":"JsAAXi..."
|
||||
* }
|
||||
* }
|
||||
* "callback":"\/post",
|
||||
* "version":1,
|
||||
* "secret":"1eaa661",
|
||||
* "secret_sig":"eKV968b1..."
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* auth_check messages MUST use encapsulated encryption. This message is sent to the origination site, which checks the 'secret' to see
|
||||
* if it is the same as the 'sec' which it passed originally. It also checks the secret_sig which is the secret signed by the
|
||||
* destination channel's private key and base64url encoded. If everything checks out, a json packet is returned:
|
||||
*
|
||||
* \code{.json}
|
||||
* {
|
||||
* "success":1,
|
||||
* "confirm":"q0Ysovd1u...",
|
||||
* "service_class":(optional)
|
||||
* "level":(optional)
|
||||
* "DNT": (optional do-not-track - 1 or 0)
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* 'confirm' in this case is the base64url encoded RSA signature of the concatenation of 'secret' with the
|
||||
* base64url encoded whirlpool hash of the requestor's guid and guid_sig; signed with the source channel private key.
|
||||
* This prevents a man-in-the-middle from inserting a rogue success packet. Upon receipt and successful
|
||||
* verification of this packet, the destination site will redirect to the original destination URL and indicate a successful remote login.
|
||||
* Service_class can be used by cooperating sites to provide different access rights based on account rights and subscription plans. It is
|
||||
* a string whose contents are not defined by protocol. Example: "basic" or "gold".
|
||||
*
|
||||
* @param[in,out] App &$a
|
||||
*/
|
22
Zotlabs/Zot/IHandler.php
Normal file
22
Zotlabs/Zot/IHandler.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Zotlabs\Zot;
|
||||
|
||||
interface IHandler {
|
||||
|
||||
function Ping();
|
||||
|
||||
function Pickup($data);
|
||||
|
||||
function Notify($data);
|
||||
|
||||
function Request($data);
|
||||
|
||||
function AuthCheck($data,$encrypted);
|
||||
|
||||
function Purge($sender,$recipients);
|
||||
|
||||
function Refresh($sender,$recipients);
|
||||
|
||||
}
|
||||
|
296
Zotlabs/Zot/Receiver.php
Normal file
296
Zotlabs/Zot/Receiver.php
Normal file
@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
namespace Zotlabs\Zot;
|
||||
|
||||
class Receiver {
|
||||
|
||||
protected $data;
|
||||
protected $encrypted;
|
||||
protected $error;
|
||||
protected $messagetype;
|
||||
protected $sender;
|
||||
protected $validated;
|
||||
protected $recipients;
|
||||
protected $response;
|
||||
protected $handler;
|
||||
|
||||
function __construct($data,$prvkey,$handler) {
|
||||
|
||||
$this->error = false;
|
||||
$this->validated = false;
|
||||
$this->messagetype = '';
|
||||
$this->response = array('success' => false);
|
||||
|
||||
$this->handler = $handler;
|
||||
|
||||
if(! is_array($data))
|
||||
$data = json_decode($data,true);
|
||||
|
||||
if($data && is_array($data)) {
|
||||
$this->encrypted = ((array_key_exists('iv',$data)) ? true : false);
|
||||
|
||||
if($this->encrypted) {
|
||||
$this->data = @json_decode(@crypto_unencapsulate($data,$prvkey),true);
|
||||
}
|
||||
if(! $this->data)
|
||||
$this->data = $data;
|
||||
|
||||
if($this->data && is_array($this->data) && array_key_exists('type',$this->data))
|
||||
$this->messagetype = $this->data['type'];
|
||||
}
|
||||
if(! $this->messagetype)
|
||||
$this->error = true;
|
||||
|
||||
$this->sender = ((array_key_exists('sender',$this->data)) ? $this->data['sender'] : null);
|
||||
$this->recipients = ((array_key_exists('recipients',$this->data)) ? $this->data['recipients'] : null);
|
||||
|
||||
|
||||
if($this->sender)
|
||||
$this->ValidateSender();
|
||||
|
||||
$this->Dispatch();
|
||||
}
|
||||
|
||||
function ValidateSender() {
|
||||
$hubs = zot_gethub($this->sender,true);
|
||||
if (! $hubs) {
|
||||
|
||||
/* Have never seen this guid or this guid coming from this location. Check it and register it. */
|
||||
/* (!!) this will validate the sender. */
|
||||
|
||||
$result = zot_register_hub($this->sender);
|
||||
|
||||
if ((! $result['success']) || (! ($hubs = zot_gethub($this->sender,true)))) {
|
||||
$this->response['message'] = 'Hub not available.';
|
||||
json_return_and_die($this->response);
|
||||
}
|
||||
}
|
||||
foreach($hubs as $hub) {
|
||||
update_hub_connected($hub,((array_key_exists('sitekey',$this->sender)) ? $this->sender['sitekey'] : ''));
|
||||
}
|
||||
$this->validated = true;
|
||||
}
|
||||
|
||||
|
||||
function Dispatch() {
|
||||
|
||||
/* Handle tasks which don't require sender validation */
|
||||
|
||||
switch($this->messagetype) {
|
||||
case 'ping':
|
||||
/* no validation needed */
|
||||
$this->handler->Ping();
|
||||
break;
|
||||
case 'pickup':
|
||||
/* perform site validation, as opposed to sender validation */
|
||||
$this->handler->Pickup($this->data);
|
||||
break;
|
||||
|
||||
default:
|
||||
if(! $this->validated) {
|
||||
$this->response['message'] = 'Sender not valid';
|
||||
json_return_and_die($this->response);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Now handle tasks which require sender validation */
|
||||
|
||||
switch($this->messagetype) {
|
||||
|
||||
case 'auth_check':
|
||||
$this->handler->AuthCheck($this->data,$this->encrypted);
|
||||
break;
|
||||
|
||||
case 'request':
|
||||
$this->handler->Request($this->data);
|
||||
break;
|
||||
|
||||
case 'purge':
|
||||
$this->handler->Purge($this->sender,$this->recipients);
|
||||
break;
|
||||
|
||||
case 'refresh':
|
||||
case 'force_refresh':
|
||||
$this->handler->Refresh($this->sender,$this->recipients);
|
||||
break;
|
||||
|
||||
case 'notify':
|
||||
$this->handler->Notify($this->data);
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->response['message'] = 'Not implemented';
|
||||
json_return_and_die($this->response);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief zot communications and messaging.
|
||||
*
|
||||
* Sender HTTP posts to this endpoint ($site/post typically) with 'data' parameter set to json zot message packet.
|
||||
* This packet is optionally encrypted, which we will discover if the json has an 'iv' element.
|
||||
* $contents => array( 'alg' => 'aes256cbc', 'iv' => initialisation vector, 'key' => decryption key, 'data' => encrypted data);
|
||||
* $contents->iv and $contents->key are random strings encrypted with this site's RSA public key and then base64url encoded.
|
||||
* Currently only 'aes256cbc' is used, but this is extensible should that algorithm prove inadequate.
|
||||
*
|
||||
* Once decrypted, one will find the normal json_encoded zot message packet.
|
||||
*
|
||||
* Defined packet types are: notify, purge, refresh, force_refresh, auth_check, ping, and pickup
|
||||
*
|
||||
* Standard packet: (used by notify, purge, refresh, force_refresh, and auth_check)
|
||||
* \code{.json}
|
||||
* {
|
||||
* "type": "notify",
|
||||
* "sender":{
|
||||
* "guid":"kgVFf_1...",
|
||||
* "guid_sig":"PT9-TApzp...",
|
||||
* "url":"http:\/\/podunk.edu",
|
||||
* "url_sig":"T8Bp7j5...",
|
||||
* },
|
||||
* "recipients": { optional recipient array },
|
||||
* "callback":"\/post",
|
||||
* "version":1,
|
||||
* "secret":"1eaa...",
|
||||
* "secret_sig": "df89025470fac8..."
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* Signature fields are all signed with the sender channel private key and base64url encoded.
|
||||
* Recipients are arrays of guid and guid_sig, which were previously signed with the recipients private
|
||||
* key and base64url encoded and later obtained via channel discovery. Absence of recipients indicates
|
||||
* a public message or visible to all potential listeners on this site.
|
||||
*
|
||||
* "pickup" packet:
|
||||
* The pickup packet is sent in response to a notify packet from another site
|
||||
* \code{.json}
|
||||
* {
|
||||
* "type":"pickup",
|
||||
* "url":"http:\/\/example.com",
|
||||
* "callback":"http:\/\/example.com\/post",
|
||||
* "callback_sig":"teE1_fLI...",
|
||||
* "secret":"1eaa...",
|
||||
* "secret_sig":"O7nB4_..."
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* In the pickup packet, the sig fields correspond to the respective data
|
||||
* element signed with this site's system private key and then base64url encoded.
|
||||
* The "secret" is the same as the original secret from the notify packet.
|
||||
*
|
||||
* If verification is successful, a json structure is returned containing a
|
||||
* success indicator and an array of type 'pickup'.
|
||||
* Each pickup element contains the original notify request and a message field
|
||||
* whose contents are dependent on the message type.
|
||||
*
|
||||
* This JSON array is AES encapsulated using the site public key of the site
|
||||
* that sent the initial zot pickup packet.
|
||||
* Using the above example, this would be example.com.
|
||||
*
|
||||
* \code{.json}
|
||||
* {
|
||||
* "success":1,
|
||||
* "pickup":{
|
||||
* "notify":{
|
||||
* "type":"notify",
|
||||
* "sender":{
|
||||
* "guid":"kgVFf_...",
|
||||
* "guid_sig":"PT9-TApz...",
|
||||
* "url":"http:\/\/z.podunk.edu",
|
||||
* "url_sig":"T8Bp7j5D..."
|
||||
* },
|
||||
* "callback":"\/post",
|
||||
* "version":1,
|
||||
* "secret":"1eaa661..."
|
||||
* },
|
||||
* "message":{
|
||||
* "type":"activity",
|
||||
* "message_id":"10b049ce384cbb2da9467319bc98169ab36290b8bbb403aa0c0accd9cb072e76@podunk.edu",
|
||||
* "message_top":"10b049ce384cbb2da9467319bc98169ab36290b8bbb403aa0c0accd9cb072e76@podunk.edu",
|
||||
* "message_parent":"10b049ce384cbb2da9467319bc98169ab36290b8bbb403aa0c0accd9cb072e76@podunk.edu",
|
||||
* "created":"2012-11-20 04:04:16",
|
||||
* "edited":"2012-11-20 04:04:16",
|
||||
* "title":"",
|
||||
* "body":"Hi Nickordo",
|
||||
* "app":"",
|
||||
* "verb":"post",
|
||||
* "object_type":"",
|
||||
* "target_type":"",
|
||||
* "permalink":"",
|
||||
* "location":"",
|
||||
* "longlat":"",
|
||||
* "owner":{
|
||||
* "name":"Indigo",
|
||||
* "address":"indigo@podunk.edu",
|
||||
* "url":"http:\/\/podunk.edu",
|
||||
* "photo":{
|
||||
* "mimetype":"image\/jpeg",
|
||||
* "src":"http:\/\/podunk.edu\/photo\/profile\/m\/5"
|
||||
* },
|
||||
* "guid":"kgVFf_...",
|
||||
* "guid_sig":"PT9-TAp...",
|
||||
* },
|
||||
* "author":{
|
||||
* "name":"Indigo",
|
||||
* "address":"indigo@podunk.edu",
|
||||
* "url":"http:\/\/podunk.edu",
|
||||
* "photo":{
|
||||
* "mimetype":"image\/jpeg",
|
||||
* "src":"http:\/\/podunk.edu\/photo\/profile\/m\/5"
|
||||
* },
|
||||
* "guid":"kgVFf_...",
|
||||
* "guid_sig":"PT9-TAp..."
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* Currently defined message types are 'activity', 'mail', 'profile', 'location'
|
||||
* and 'channel_sync', which each have different content schemas.
|
||||
*
|
||||
* Ping packet:
|
||||
* A ping packet does not require any parameters except the type. It may or may
|
||||
* not be encrypted.
|
||||
*
|
||||
* \code{.json}
|
||||
* {
|
||||
* "type": "ping"
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* On receipt of a ping packet a ping response will be returned:
|
||||
*
|
||||
* \code{.json}
|
||||
* {
|
||||
* "success" : 1,
|
||||
* "site" {
|
||||
* "url": "http:\/\/podunk.edu",
|
||||
* "url_sig": "T8Bp7j5...",
|
||||
* "sitekey": "-----BEGIN PUBLIC KEY-----
|
||||
* MIICIjANBgkqhkiG9w0BAQE..."
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* The ping packet can be used to verify that a site has not been re-installed, and to
|
||||
* initiate corrective action if it has. The url_sig is signed with the site private key
|
||||
* and base64url encoded - and this should verify with the enclosed sitekey. Failure to
|
||||
* verify indicates the site is corrupt or otherwise unable to communicate using zot.
|
||||
* This return packet is not otherwise verified, so should be compared with other
|
||||
* results obtained from this site which were verified prior to taking action. For instance
|
||||
* if you have one verified result with this signature and key, and other records for this
|
||||
* url which have different signatures and keys, it indicates that the site was re-installed
|
||||
* and corrective action may commence (remove or mark invalid any entries with different
|
||||
* signatures).
|
||||
* If you have no records which match this url_sig and key - no corrective action should
|
||||
* be taken as this packet may have been returned by an imposter.
|
||||
*
|
||||
* @param[in,out] App &$a
|
||||
*/
|
||||
|
38
Zotlabs/Zot/ZotHandler.php
Normal file
38
Zotlabs/Zot/ZotHandler.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Zotlabs\Zot;
|
||||
|
||||
require_once('Zotlabs/Zot/IHandler.php');
|
||||
|
||||
|
||||
class ZotHandler implements IHandler {
|
||||
|
||||
function Ping() {
|
||||
zot_reply_ping();
|
||||
}
|
||||
|
||||
function Pickup($data) {
|
||||
zot_reply_pickup($data);
|
||||
}
|
||||
|
||||
function Notify($data) {
|
||||
zot_reply_notify($data);
|
||||
}
|
||||
|
||||
function Request($data) {
|
||||
zot_reply_message_request($data);
|
||||
}
|
||||
|
||||
function AuthCheck($data,$encrypted) {
|
||||
zot_reply_auth_check($data,$encrypted);
|
||||
}
|
||||
|
||||
function Purge($sender,$recipients) {
|
||||
zot_reply_purge($sender,$recipients);
|
||||
}
|
||||
|
||||
function Refresh($sender,$recipients) {
|
||||
zot_reply_refresh($sender,$recipients);
|
||||
}
|
||||
|
||||
}
|
31
boot.php
31
boot.php
@ -48,9 +48,10 @@ require_once('include/AccessList.php');
|
||||
|
||||
define ( 'PLATFORM_NAME', 'hubzilla' );
|
||||
define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'H');
|
||||
define ( 'STD_VERSION', '1.0' );
|
||||
define ( 'ZOT_REVISION', 1 );
|
||||
|
||||
define ( 'DB_UPDATE_VERSION', 1160 );
|
||||
define ( 'DB_UPDATE_VERSION', 1161 );
|
||||
|
||||
|
||||
/**
|
||||
@ -65,10 +66,10 @@ define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
|
||||
//define ( 'NULL_DATE', '0000-00-00 00:00:00' );
|
||||
define ( 'TEMPLATE_BUILD_PATH', 'store/[data]/smarty3' );
|
||||
|
||||
define ( 'DIRECTORY_MODE_NORMAL', 0x0000); // This is technically DIRECTORY_MODE_TERTIARY, but it's the default, hence 0x0000
|
||||
define ( 'DIRECTORY_MODE_PRIMARY', 0x0001);
|
||||
define ( 'DIRECTORY_MODE_SECONDARY', 0x0002);
|
||||
define ( 'DIRECTORY_MODE_STANDALONE', 0x0100);
|
||||
define ( 'DIRECTORY_MODE_NORMAL', 0x0000); // A directory client
|
||||
define ( 'DIRECTORY_MODE_PRIMARY', 0x0001); // There can only be *one* primary directory server in a directory_realm.
|
||||
define ( 'DIRECTORY_MODE_SECONDARY', 0x0002); // All other mirror directory servers
|
||||
define ( 'DIRECTORY_MODE_STANDALONE', 0x0100); // A detached (off the grid) hub with itself as directory server.
|
||||
|
||||
// We will look for upstream directories whenever me make contact
|
||||
// with other sites, but if this is a new installation and isn't
|
||||
@ -82,9 +83,9 @@ $DIRECTORY_FALLBACK_SERVERS = array(
|
||||
'https://zothub.com',
|
||||
'https://hubzilla.site',
|
||||
'https://red.zottel.red',
|
||||
'https://gravizot.de',
|
||||
'https://blablanet.com',
|
||||
'https://my.federated.social'
|
||||
'https://hub.pixelbits.de',
|
||||
'https://my.federated.social',
|
||||
'https://hubzilla.nl'
|
||||
);
|
||||
|
||||
|
||||
@ -621,10 +622,10 @@ class App {
|
||||
public $poi = null; // "person of interest", generally a referenced connection
|
||||
private $oauth_key = null; // consumer_id of oauth request, if used
|
||||
public $layout = array(); // Comanche parsed template
|
||||
public $pdl = null;
|
||||
public $pdl = null; // Comanche page description
|
||||
private $perms = null; // observer permissions
|
||||
private $widgets = array(); // widgets for this page
|
||||
//private $widgetlist = null; // widget ordering and inclusion directives
|
||||
|
||||
|
||||
public $groups;
|
||||
public $language;
|
||||
@ -1157,7 +1158,7 @@ function z_root() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return absolut URL for given $path.
|
||||
* @brief Return absolute URL for given $path.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
@ -1323,7 +1324,7 @@ function check_config(&$a) {
|
||||
*
|
||||
*/
|
||||
|
||||
$r = q("SELECT * FROM `addon` WHERE `installed` = 1");
|
||||
$r = q("SELECT * FROM addon WHERE installed = 1");
|
||||
if($r)
|
||||
$installed = $r;
|
||||
else
|
||||
@ -1469,12 +1470,6 @@ function login($register = false, $form_id = 'main-login', $hiddens=false) {
|
||||
$tpl = get_markup_template("logout.tpl");
|
||||
}
|
||||
else {
|
||||
// There's no such thing as login_head.tpl, has never been in Red, removed from Friendica 1 Jun 2013...
|
||||
|
||||
// $a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"), array(
|
||||
// '$baseurl' => $a->get_baseurl(true)
|
||||
// ));
|
||||
|
||||
$tpl = get_markup_template("login.tpl");
|
||||
if(strlen($a->query_string))
|
||||
$_SESSION['login_return_url'] = $a->query_string;
|
||||
|
@ -8,7 +8,7 @@ Create an account on OpenShift, then use the registration e-mail and password to
|
||||
[code]rhc app-create your_app_name php-5.4 mysql-5.5 cron phpmyadmin --namespace your_domain --from-code https://github.com/redmatrix/hubzilla.git -l your@email.address -p your_account_password
|
||||
[/code]
|
||||
|
||||
Make a note of the database username and password OpenShift creates for your instance, and use these at [url=https://your_app_name-your_domain.rhcloud.com/]https://your_app_name-your_domain.rhcloud.com/[/url] to complete the setup.
|
||||
Make a note of the database username and password OpenShift creates for your instance, and use these at [url=https://your_app_name-your_domain.rhcloud.com/]https://your_app_name-your_domain.rhcloud.com/[/url] to complete the setup. You MUST change server address from 127.0.0.1 to localhost.
|
||||
|
||||
NOTE: PostgreSQL is NOT supported by the deploy script yet, see [zrl=https://zot-mor.rhcloud.com/display/3c7035f2a6febf87057d84ea0ae511223e9b38dc27913177bc0df053edecac7c@zot-mor.rhcloud.com?zid=haakon%40zot-mor.rhcloud.com]this thread[/zrl].
|
||||
|
||||
|
@ -39,8 +39,9 @@
|
||||
[tr][td]abook_unconnected[/td][td]currently unused. Projected usage is to indicate "one-way" connections which were insitgated on this end but are still pending on the remote end. [/td][td]int(11)[/td][td]NO[/td][td]MUL[/td][td]0[/td][td]
|
||||
[tr][td]abook_self[/td][td]is a special case where the owner is the target. Every channel has one abook entry with abook_self and with a target abook_xchan set to channel.channel_hash . When this flag is present, abook_my_perms is the default permissions granted to all new connections and several other fields are unused.[/td][td]int(11)[/td][td]NO[/td][td]MUL[/td][td]0[/td][td]
|
||||
[tr][td]abook_feed[/td][td]indicates this connection is an RSS/Atom feed and may trigger special handling.[/td][td]int(11)[/td][td]NO[/td][td]MUL[/td][td]0[/td][td]
|
||||
[tr][td]abook_incl[/td][td]connection filter allow rules separated by LF[/td][td]int(11)[/td][td]NO[/td][td]MUL[/td][td]0[/td][td]
|
||||
[tr][td]abook_excl[/td][td]connection filter deny rules separated by LF[/td][td]int(11)[/td][td]NO[/td][td]MUL[/td][td]0[/td][td]
|
||||
[tr][td]abook_incl[/td][td]connection filter allow rules separated by LF[/td][td]text[/td][td]NO[/td][td]MUL[/td][td]0[/td][td]
|
||||
[tr][td]abook_excl[/td][td]connection filter deny rules separated by LF[/td][td]text[/td][td]NO[/td][td]MUL[/td][td]0[/td][td]
|
||||
[tr][td]abook_instance[/td][td]comma separated list of site urls of all channel clones that this connection is connected with (used only for singleton networks which don't support cloning)[/td][td]text[/td][td]NO[/td][td]MUL[/td][td]0[/td][td]
|
||||
[/table]
|
||||
|
||||
|
||||
|
@ -65,7 +65,7 @@ This document assumes you're an administrator.
|
||||
this website. Can be overwritten by user settings.
|
||||
[b]system > projecthome[/b]
|
||||
Set the project homepage as the homepage of your hub.
|
||||
[b]system > workflowchannelnext[/b]
|
||||
[b]system > workflow_channel_next[/b]
|
||||
The page to direct users to immediately after creating a channel.
|
||||
[b]system > max_daily_registrations[/b]
|
||||
Set the maximum number of new registrations allowed on any day.
|
||||
@ -154,6 +154,8 @@ This document assumes you're an administrator.
|
||||
Needed in some Windows installations to locate the openssl configuration file on the system.
|
||||
[b]system > hide_help[/b]
|
||||
Don't display help documentation link in nav bar
|
||||
[b]system > expire_delivery_reports[/b]
|
||||
Expiration in days for delivery reports - default 30
|
||||
|
||||
[b]Directory config[/b]
|
||||
[b]Directory search defaults[/b]
|
||||
|
11
doc/hook/check_channelallowed.bb
Normal file
11
doc/hook/check_channelallowed.bb
Normal file
@ -0,0 +1,11 @@
|
||||
[h2]check_channelallowed[/h2]
|
||||
|
||||
Called when checking the channel (xchan) black and white lists to see if a channel is blocked.
|
||||
|
||||
Hook data
|
||||
|
||||
array('hash' => xchan_hash of xchan to check);
|
||||
|
||||
create and set array element 'allowed' to true or false to override the system checks
|
||||
|
||||
|
10
doc/hook/check_siteallowed.bb
Normal file
10
doc/hook/check_siteallowed.bb
Normal file
@ -0,0 +1,10 @@
|
||||
[h2]check_siteallowed[/h2]
|
||||
|
||||
Called when checking the site black and white lists to see if a site is blocked.
|
||||
|
||||
Hook data
|
||||
|
||||
array('url' => URL of site to check);
|
||||
|
||||
create and set array element 'allowed' to true or false to override the system checks
|
||||
|
@ -82,6 +82,12 @@ Hooks allow plugins/addons to "hook into" the code at many points and alter the
|
||||
[zrl=[baseurl]/help/hook/check_account_password]check_account_password[/zrl]
|
||||
Used to provide policy control over account passwords (minimum length, character set inclusion, etc.)
|
||||
|
||||
[zrl=[baseurl]/help/hook/check_channelallowed]check_channelallowed[/zrl]
|
||||
Used to over-ride or bypass the channel black/white block lists
|
||||
|
||||
[zrl=[baseurl]/help/hook/check_siteallowed]check_siteallowed[/zrl]
|
||||
Used to over-ride or bypass the site black/white block lists
|
||||
|
||||
[zrl=[baseurl]/help/hook/connect_premium]connect_premium[/zrl]
|
||||
Called when connecting to a premium channel
|
||||
|
||||
|
@ -188,7 +188,7 @@ class RedBrowser extends DAV\Browser\Plugin {
|
||||
|
||||
$parentHash = '';
|
||||
$owner = $this->auth->owner_id;
|
||||
$splitPath = split('/', $fullPath);
|
||||
$splitPath = explode('/', $fullPath);
|
||||
if (count($splitPath) > 3) {
|
||||
for ($i = 3; $i < count($splitPath); $i++) {
|
||||
$attachName = urldecode($splitPath[$i]);
|
||||
|
@ -67,7 +67,7 @@ function check_account_invite($invite_code) {
|
||||
$result['message'] .= t('An invitation is required.') . EOL;
|
||||
}
|
||||
$r = q("select * from register where `hash` = '%s' limit 1", dbesc($invite_code));
|
||||
if(! results($r)) {
|
||||
if(! $r) {
|
||||
$result['message'] .= t('Invitation could not be verified.') . EOL;
|
||||
}
|
||||
}
|
||||
@ -718,4 +718,4 @@ function upgrade_message($bbcode = false) {
|
||||
function upgrade_bool_message($bbcode = false) {
|
||||
$x = upgrade_link($bbcode);
|
||||
return t('This action is not available under your subscription plan.') . (($x) ? ' ' . $x : '') ;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once("bbcode.php");
|
||||
require_once("datetime.php");
|
||||
require_once("conversation.php");
|
||||
require_once("oauth.php");
|
||||
require_once("html2plain.php");
|
||||
require_once("include/bbcode.php");
|
||||
require_once("include/datetime.php");
|
||||
require_once("include/conversation.php");
|
||||
require_once("include/oauth.php");
|
||||
require_once("include/html2plain.php");
|
||||
require_once('include/security.php');
|
||||
require_once('include/photos.php');
|
||||
require_once('include/items.php');
|
||||
@ -382,7 +382,6 @@ require_once('include/api_auth.php');
|
||||
|
||||
|
||||
function api_item_get_user(&$a, $item) {
|
||||
global $usercache;
|
||||
|
||||
// The author is our direct contact, in a conversation with us.
|
||||
|
||||
@ -396,11 +395,11 @@ require_once('include/api_auth.php');
|
||||
$name = $item['author']['xchan_name'];
|
||||
|
||||
// Generating a random ID
|
||||
if (is_null($usercache[$nick]) or !array_key_exists($nick, $usercache))
|
||||
$usercache[$nick] = mt_rand(2000000, 2100000);
|
||||
if (! $nick)
|
||||
$nick = mt_rand(2000000, 2100000);
|
||||
|
||||
$ret = array(
|
||||
'id' => $usercache[$nick],
|
||||
'id' => $nick,
|
||||
'name' => $name,
|
||||
'screen_name' => $nick,
|
||||
'location' => '', //$uinfo[0]['default-location'],
|
||||
@ -2299,12 +2298,11 @@ require_once('include/api_auth.php');
|
||||
api_register_func('api/direct_messages','api_direct_messages_inbox',true);
|
||||
|
||||
|
||||
|
||||
function api_oauth_request_token(&$a, $type){
|
||||
try{
|
||||
$oauth = new FKOAuth1();
|
||||
$oauth = new ZotOAuth1();
|
||||
$req = OAuthRequest::from_request();
|
||||
logger('Req: ' . var_export($req,true));
|
||||
logger('Req: ' . var_export($req,true),LOGGER_DATA);
|
||||
$r = $oauth->fetch_request_token($req);
|
||||
}catch(Exception $e){
|
||||
logger('oauth_exception: ' . print_r($e->getMessage(),true));
|
||||
@ -2314,9 +2312,10 @@ logger('Req: ' . var_export($req,true));
|
||||
echo $r;
|
||||
killme();
|
||||
}
|
||||
|
||||
function api_oauth_access_token(&$a, $type){
|
||||
try{
|
||||
$oauth = new FKOAuth1();
|
||||
$oauth = new ZotOAuth1();
|
||||
$req = OAuthRequest::from_request();
|
||||
$r = $oauth->fetch_access_token($req);
|
||||
}catch(Exception $e){
|
||||
|
@ -1,16 +1,18 @@
|
||||
<?php /** @file */
|
||||
|
||||
require_once("oauth.php");
|
||||
|
||||
|
||||
/**
|
||||
* Simple HTTP Login
|
||||
* API Login via basic-auth or OAuth
|
||||
*/
|
||||
|
||||
function api_login(&$a){
|
||||
|
||||
$record = null;
|
||||
|
||||
require_once('include/oauth.php');
|
||||
|
||||
// login with oauth
|
||||
try {
|
||||
$oauth = new FKOAuth1();
|
||||
$oauth = new ZotOAuth1();
|
||||
$req = OAuthRequest::from_request();
|
||||
|
||||
list($consumer,$token) = $oauth->verify_request($req);
|
||||
@ -23,16 +25,14 @@ function api_login(&$a){
|
||||
call_hooks('logged_in', $a->user);
|
||||
return;
|
||||
}
|
||||
echo __file__.__line__.__function__."<pre>";
|
||||
// var_dump($consumer, $token);
|
||||
die();
|
||||
killme();
|
||||
}
|
||||
catch(Exception $e) {
|
||||
logger(__file__.__line__.__function__."\n".$e);
|
||||
}
|
||||
|
||||
|
||||
// workaround for HTTP-auth in CGI mode
|
||||
// workarounds for HTTP-auth in CGI mode
|
||||
|
||||
if(x($_SERVER,'REDIRECT_REMOTE_USER')) {
|
||||
$userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"],6)) ;
|
||||
if(strlen($userpass)) {
|
||||
@ -51,45 +51,49 @@ function api_login(&$a){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||
header('WWW-Authenticate: Basic realm="Red"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
die('This api requires login');
|
||||
}
|
||||
|
||||
// process normal login request
|
||||
require_once('include/auth.php');
|
||||
$channel_login = 0;
|
||||
$record = account_verify_password($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']);
|
||||
if(! $record) {
|
||||
$r = q("select * from channel where channel_address = '%s' limit 1",
|
||||
require_once('include/security.php');
|
||||
|
||||
// process normal login request
|
||||
|
||||
if(isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
$channel_login = 0;
|
||||
$record = account_verify_password($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']);
|
||||
if(! $record) {
|
||||
$r = q("select * from channel left join account on account.account_id = channel.channel_account_id
|
||||
where channel.channel_address = '%s' limit 1",
|
||||
dbesc($_SERVER['PHP_AUTH_USER'])
|
||||
);
|
||||
if ($r) {
|
||||
$x = q("select * from account where account_id = %d limit 1",
|
||||
intval($r[0]['channel_account_id'])
|
||||
);
|
||||
if ($x) {
|
||||
$record = account_verify_password($x[0]['account_email'],$_SERVER['PHP_AUTH_PW']);
|
||||
$record = account_verify_password($r[0]['account_email'],$_SERVER['PHP_AUTH_PW']);
|
||||
if($record)
|
||||
$channel_login = $r[0]['channel_id'];
|
||||
}
|
||||
}
|
||||
if(! $record) {
|
||||
logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||
header('WWW-Authenticate: Basic realm="Red"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
die('This api requires login');
|
||||
}
|
||||
}
|
||||
|
||||
require_once('include/security.php');
|
||||
authenticate_success($record);
|
||||
if($record) {
|
||||
authenticate_success($record);
|
||||
|
||||
if($channel_login)
|
||||
change_channel($channel_login);
|
||||
if($channel_login)
|
||||
change_channel($channel_login);
|
||||
|
||||
$_SESSION['allow_api'] = true;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
$_SERVER['PHP_AUTH_PW'] = '*****';
|
||||
logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||
log_failed_login('API login failure');
|
||||
retry_basic_auth();
|
||||
}
|
||||
|
||||
$_SESSION['allow_api'] = true;
|
||||
}
|
||||
|
||||
|
||||
function retry_basic_auth() {
|
||||
header('WWW-Authenticate: Basic realm="Hubzilla"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
echo('This api requires login');
|
||||
killme();
|
||||
}
|
@ -282,15 +282,16 @@ function comanche_widget($name, $text) {
|
||||
}
|
||||
}
|
||||
|
||||
if(file_exists('widget/' . trim($name) . '.php'))
|
||||
$func = 'widget_' . trim($name);
|
||||
|
||||
if((! function_exists($func)) && file_exists('widget/' . trim($name) . '.php'))
|
||||
require_once('widget/' . trim($name) . '.php');
|
||||
else {
|
||||
$theme_widget = 'widget_' . trim($name) . '.php';
|
||||
if(theme_include($theme_widget))
|
||||
$theme_widget = $func . '.php';
|
||||
if((! function_exists($func)) && theme_include($theme_widget))
|
||||
require_once(theme_include($theme_widget));
|
||||
}
|
||||
|
||||
$func = 'widget_' . trim($name);
|
||||
if (function_exists($func))
|
||||
return $func($vars);
|
||||
}
|
||||
|
@ -28,7 +28,10 @@ function externals_run($argv, $argc){
|
||||
}
|
||||
else {
|
||||
$randfunc = db_getfunc('RAND');
|
||||
$r = q("select site_url, site_pull from site where site_url != '%s' and site_flags != %d and site_type = %d order by $randfunc limit 1",
|
||||
|
||||
// fixme this query does not deal with directory realms.
|
||||
|
||||
$r = q("select site_url, site_pull from site where site_url != '%s' and site_flags != %d and site_type = %d and site_dead = 0 order by $randfunc limit 1",
|
||||
dbesc(z_root()),
|
||||
intval(DIRECTORY_MODE_STANDALONE),
|
||||
intval(SITE_TYPE_ZOT)
|
||||
@ -37,19 +40,11 @@ function externals_run($argv, $argc){
|
||||
$url = $r[0]['site_url'];
|
||||
}
|
||||
|
||||
// Note: blacklisted sites must be stored in the config as an array.
|
||||
// No simple way to turn this into a personal config because we have no identity here.
|
||||
// For that we probably need a variant of superblock.
|
||||
|
||||
$blacklisted = false;
|
||||
$bl1 = get_config('system','blacklisted_sites');
|
||||
if(is_array($bl1) && $bl1) {
|
||||
foreach($bl1 as $bl) {
|
||||
if($bl && strpos($url,$bl) !== false) {
|
||||
$blacklisted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(! check_siteallowed($url)) {
|
||||
logger('blacklisted site: ' . $url);
|
||||
$blacklisted = true;
|
||||
}
|
||||
|
||||
$attempts ++;
|
||||
|
@ -161,6 +161,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
}
|
||||
}
|
||||
if($r) {
|
||||
$xchan = $r[0];
|
||||
$xchan_hash = $r[0]['xchan_hash'];
|
||||
$their_perms = 0;
|
||||
}
|
||||
@ -172,7 +173,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
return $result;
|
||||
}
|
||||
|
||||
$x = array('channel_id' => $uid, 'follow_address' => $url, 'xchan' => $r[0], 'allowed' => 1);
|
||||
$x = array('channel_id' => $uid, 'follow_address' => $url, 'xchan' => $r[0], 'allowed' => 1, 'singleton' => 0);
|
||||
|
||||
call_hooks('follow_allow',$x);
|
||||
|
||||
@ -180,7 +181,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
$result['message'] = t('Protocol disabled.');
|
||||
return $result;
|
||||
}
|
||||
|
||||
$singleton = intval($x['singleton']);
|
||||
|
||||
if((local_channel()) && $uid == local_channel()) {
|
||||
$aid = get_account_id();
|
||||
@ -221,13 +222,22 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
return $result;
|
||||
}
|
||||
|
||||
$r = q("select abook_xchan from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
|
||||
$r = q("select abook_xchan, abook_instance from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
|
||||
dbesc($xchan_hash),
|
||||
intval($uid)
|
||||
);
|
||||
if($r) {
|
||||
$x = q("update abook set abook_their_perms = %d where abook_id = %d",
|
||||
$abook_instance = $r[0]['abook_instance'];
|
||||
|
||||
if(($singleton) && strpos($abook_instance,z_root()) === false) {
|
||||
if($abook_instance)
|
||||
$abook_instance .= ',';
|
||||
$abook_instance .= z_root();
|
||||
}
|
||||
|
||||
$x = q("update abook set abook_their_perms = %d, abook_instance = '%s' where abook_id = %d",
|
||||
intval($their_perms),
|
||||
dbesc($abook_instance),
|
||||
intval($r[0]['abook_id'])
|
||||
);
|
||||
}
|
||||
@ -237,8 +247,8 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
if($closeness === false)
|
||||
$closeness = 80;
|
||||
|
||||
$r = q("insert into abook ( abook_account, abook_channel, abook_closeness, abook_xchan, abook_feed, abook_their_perms, abook_my_perms, abook_created, abook_updated )
|
||||
values( %d, %d, %d, '%s', %d, %d, %d, '%s', '%s' ) ",
|
||||
$r = q("insert into abook ( abook_account, abook_channel, abook_closeness, abook_xchan, abook_feed, abook_their_perms, abook_my_perms, abook_created, abook_updated, abook_instance )
|
||||
values( %d, %d, %d, '%s', %d, %d, %d, '%s', '%s', '%s' ) ",
|
||||
intval($aid),
|
||||
intval($uid),
|
||||
intval($closeness),
|
||||
@ -247,7 +257,8 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
|
||||
intval(($is_http) ? $their_perms|PERMS_R_STREAM|PERMS_A_REPUBLISH : $their_perms),
|
||||
intval($my_perms),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert())
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(($singleton) ? z_root() : '')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -896,12 +896,6 @@ function profile_load(&$a, $nickname, $profile = '') {
|
||||
|
||||
$_SESSION['theme'] = $p[0]['channel_theme'];
|
||||
|
||||
// $a->set_template_engine(); // reset the template engine to the default in case the user's theme doesn't specify one
|
||||
|
||||
// $theme_info_file = "view/theme/".current_theme()."/php/theme.php";
|
||||
// if (file_exists($theme_info_file)){
|
||||
// require_once($theme_info_file);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -550,6 +550,7 @@ function get_public_feed($channel, $params) {
|
||||
$params['direction'] = ((x($params,'direction')) ? $params['direction'] : 'desc');
|
||||
$params['pages'] = ((x($params,'pages')) ? intval($params['pages']) : 0);
|
||||
$params['top'] = ((x($params,'top')) ? intval($params['top']) : 0);
|
||||
$params['cat'] = ((x($params,'cat')) ? $params['cat'] : '');
|
||||
|
||||
switch($params['type']) {
|
||||
case 'json':
|
||||
@ -593,7 +594,8 @@ function get_feed_for($channel, $observer_hash, $params) {
|
||||
'direction' => $params['direction'], // FIXME
|
||||
'pages' => $params['pages'],
|
||||
'order' => 'post',
|
||||
'top' => $params['top']
|
||||
'top' => $params['top'],
|
||||
'cat' => $params['cat']
|
||||
), $channel, $observer_hash, CLIENT_MODE_NORMAL, get_app()->module);
|
||||
|
||||
|
||||
@ -3472,7 +3474,7 @@ function post_is_importable($item,$abook) {
|
||||
unobscure($item);
|
||||
|
||||
$text = prepare_text($item['body'],$item['mimetype']);
|
||||
$text = html2plain($text);
|
||||
$text = html2plain(($item['title']) ? $item['title'] . ' ' . $text : $text);
|
||||
|
||||
|
||||
$lang = null;
|
||||
@ -4817,6 +4819,9 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
|
||||
if($arr['since_id'])
|
||||
$sql_extra .= " and item.id > " . $since_id . " ";
|
||||
|
||||
if($arr['cat'])
|
||||
$sql_extra .= protect_sprintf(term_query('item', $arr['cat'], TERM_CATEGORY));
|
||||
|
||||
if($arr['gid'] && $uid) {
|
||||
$r = q("SELECT * FROM `groups` WHERE id = %d AND uid = %d LIMIT 1",
|
||||
intval($arr['group']),
|
||||
|
@ -13,6 +13,7 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
|
||||
$ret = array('success' => false);
|
||||
|
||||
$a = get_app();
|
||||
$observer_hash = get_observer_hash();
|
||||
|
||||
if(! $recipient) {
|
||||
$ret['message'] = t('No recipient provided.');
|
||||
@ -148,8 +149,8 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
|
||||
|
||||
$match = null;
|
||||
$images = null;
|
||||
if(preg_match_all("/\[zmg\](.*?)\[\/zmg\]/",((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$match))
|
||||
$images = $match[1];
|
||||
if(preg_match_all("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/",((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$match))
|
||||
$images = $match[3];
|
||||
|
||||
$match = false;
|
||||
|
||||
@ -173,7 +174,7 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
|
||||
'revision' => $r['data']['revision']
|
||||
);
|
||||
}
|
||||
$body = str_replace($match[1],'',$body);
|
||||
$body = trim(str_replace($match[1],'',$body));
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,7 +231,7 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
|
||||
dbesc($image_uri),
|
||||
intval($channel['channel_id']),
|
||||
dbesc('<' . $channel['channel_hash'] . '>')
|
||||
);
|
||||
);
|
||||
$r = q("UPDATE attach SET allow_cid = '%s' WHERE hash = '%s' AND is_photo = 1 and uid = %d and allow_cid = '%s'",
|
||||
dbesc('<' . $recipient . '>'),
|
||||
dbesc($image_uri),
|
||||
@ -239,7 +240,7 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto='
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($attaches) {
|
||||
foreach($attaches as $attach) {
|
||||
$hash = substr($attach,0,strpos($attach,','));
|
||||
@ -505,3 +506,4 @@ function private_messages_fetch_conversation($channel_id, $messageitem_id, $upda
|
||||
return $messages;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1709,3 +1709,190 @@ function do_delivery($deliveries) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function get_site_info() {
|
||||
|
||||
global $db;
|
||||
global $a;
|
||||
|
||||
$register_policy = Array('REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN');
|
||||
$directory_mode = Array('DIRECTORY_MODE_NORMAL', 'DIRECTORY_MODE_SECONDARY','DIRECTORY_MODE_PRIMARY', 256 => 'DIRECTORY_MODE_STANDALONE');
|
||||
|
||||
$sql_extra = '';
|
||||
|
||||
$r = q("select * from channel left join account on account_id = channel_account_id where ( account_roles & 4096 )>0 and account_default_channel = channel_id");
|
||||
|
||||
|
||||
if($r) {
|
||||
$admin = array();
|
||||
foreach($r as $rr) {
|
||||
if($rr['channel_pageflags'] & PAGE_HUBADMIN)
|
||||
$admin[] = array( 'name' => $rr['channel_name'], 'address' => $rr['channel_address'] . '@' . get_app()->get_hostname(), 'channel' => z_root() . '/channel/' . $rr['channel_address']);
|
||||
}
|
||||
if(! $admin) {
|
||||
foreach($r as $rr) {
|
||||
$admin[] = array( 'name' => $rr['channel_name'], 'address' => $rr['channel_address'] . '@' . get_app()->get_hostname(), 'channel' => z_root() . '/channel/' . $rr['channel_address']);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$admin = false;
|
||||
}
|
||||
|
||||
$def_service_class = get_config('system','default_service_class');
|
||||
if($def_service_class)
|
||||
$service_class = get_config('service_class',$def_service_class);
|
||||
else
|
||||
$service_class = false;
|
||||
|
||||
$visible_plugins = array();
|
||||
if(is_array($a->plugins) && count($a->plugins)) {
|
||||
$r = q("select * from addon where hidden = 0");
|
||||
if(count($r))
|
||||
foreach($r as $rr)
|
||||
$visible_plugins[] = $rr['name'];
|
||||
}
|
||||
sort($visible_plugins);
|
||||
|
||||
if(@is_dir('.git') && function_exists('shell_exec'))
|
||||
$commit = trim(@shell_exec('git log -1 --format="%h"'));
|
||||
if(! isset($commit) || strlen($commit) > 16)
|
||||
$commit = '';
|
||||
|
||||
$site_info = get_config('system','info');
|
||||
$site_name = get_config('system','sitename');
|
||||
if(! get_config('system','hidden_version_siteinfo')) {
|
||||
$version = RED_VERSION;
|
||||
$tag = get_std_version();
|
||||
|
||||
if(@is_dir('.git') && function_exists('shell_exec')) {
|
||||
$commit = trim( @shell_exec('git log -1 --format="%h"'));
|
||||
// if(! get_config('system','hidden_tag_siteinfo'))
|
||||
// $tag = trim( @shell_exec('git describe --tags --abbrev=0'));
|
||||
// else
|
||||
// $tag = '';
|
||||
}
|
||||
if(! isset($commit) || strlen($commit) > 16)
|
||||
$commit = '';
|
||||
}
|
||||
else {
|
||||
$version = $commit = '';
|
||||
}
|
||||
|
||||
//Statistics
|
||||
$channels_total_stat = intval(get_config('system','channels_total_stat'));
|
||||
$channels_active_halfyear_stat = intval(get_config('system','channels_active_halfyear_stat'));
|
||||
$channels_active_monthly_stat = intval(get_config('system','channels_active_monthly_stat'));
|
||||
$local_posts_stat = intval(get_config('system','local_posts_stat'));
|
||||
$hide_in_statistics = intval(get_config('system','hide_in_statistics'));
|
||||
$site_expire = intval(get_config('system', 'default_expire_days'));
|
||||
|
||||
|
||||
$data = Array(
|
||||
'version' => $version,
|
||||
'version_tag' => $tag,
|
||||
'commit' => $commit,
|
||||
'url' => z_root(),
|
||||
'plugins' => $visible_plugins,
|
||||
'register_policy' => $register_policy[get_config('system','register_policy')],
|
||||
'directory_mode' => $directory_mode[get_config('system','directory_mode')],
|
||||
'language' => get_config('system','language'),
|
||||
'rss_connections' => get_config('system','feed_contacts'),
|
||||
'expiration' => $site_expire,
|
||||
'default_service_restrictions' => $service_class,
|
||||
'admin' => $admin,
|
||||
'site_name' => (($site_name) ? $site_name : ''),
|
||||
'platform' => PLATFORM_NAME,
|
||||
'dbdriver' => $db->getdriver(),
|
||||
'lastpoll' => get_config('system','lastpoll'),
|
||||
'info' => (($site_info) ? $site_info : ''),
|
||||
'channels_total' => $channels_total_stat,
|
||||
'channels_active_halfyear' => $channels_active_halfyear_stat,
|
||||
'channels_active_monthly' => $channels_active_monthly_stat,
|
||||
'local_posts' => $local_posts_stat,
|
||||
'hide_in_statistics' => $hide_in_statistics
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function check_siteallowed($url) {
|
||||
|
||||
$retvalue = true;
|
||||
|
||||
|
||||
$arr = array('url' => $url);
|
||||
call_hooks('check_siteallowed',$arr);
|
||||
|
||||
if(array_key_exists('allowed',$arr))
|
||||
return $arr['allowed'];
|
||||
|
||||
$bl1 = get_config('system','whitelisted_sites');
|
||||
if(is_array($bl1) && $bl1) {
|
||||
foreach($bl1 as $bl) {
|
||||
if($bl1 === '*')
|
||||
$retvalue = true;
|
||||
if($bl && strpos($url,$bl) !== false)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$bl1 = get_config('system','blacklisted_sites');
|
||||
if(is_array($bl1) && $bl1) {
|
||||
foreach($bl1 as $bl) {
|
||||
if($bl1 === '*')
|
||||
$retvalue = false;
|
||||
if($bl && strpos($url,$bl) !== false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $retvalue;
|
||||
}
|
||||
|
||||
function check_channelallowed($hash) {
|
||||
|
||||
$retvalue = true;
|
||||
|
||||
$arr = array('hash' => $hash);
|
||||
call_hooks('check_channelallowed',$arr);
|
||||
|
||||
if(array_key_exists('allowed',$arr))
|
||||
return $arr['allowed'];
|
||||
|
||||
$bl1 = get_config('system','whitelisted_channels');
|
||||
if(is_array($bl1) && $bl1) {
|
||||
foreach($bl1 as $bl) {
|
||||
if($bl1 === '*')
|
||||
$retvalue = true;
|
||||
if($bl && strpos($hash,$bl) !== false)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
$bl1 = get_config('system','blacklisted_channels');
|
||||
if(is_array($bl1) && $bl1) {
|
||||
foreach($bl1 as $bl) {
|
||||
if($bl1 === '*')
|
||||
$retvalue = false;
|
||||
if($bl && strpos($hash,$bl) !== false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $retvalue;
|
||||
}
|
||||
|
||||
function deliverable_singleton($xchan) {
|
||||
$r = q("select abook_instance from abook where abook_xchan = '%s' limit 1",
|
||||
dbesc($xchan['xchan_hash'])
|
||||
);
|
||||
if($r) {
|
||||
if(! $r[0]['abook_instance'])
|
||||
return true;
|
||||
if(strpos($r[0]['abook_instance'],z_root()) !== false)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,8 @@ require_once('include/html2plain.php');
|
||||
* purge_all channel_id
|
||||
* expire channel_id
|
||||
* relay item_id (item was relayed to owner, we will deliver it as owner)
|
||||
* single_activity item_id (deliver to a singleton network from the appropriate clone)
|
||||
* single_mail mail_id (deliver to a singleton network from the appropriate clone)
|
||||
* location channel_id
|
||||
* request channel_id xchan_hash message_id
|
||||
* rating xlink_id
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php /** @file */
|
||||
|
||||
/**
|
||||
* OAuth server
|
||||
* Based on oauth2-php <http://code.google.com/p/oauth2-php/>
|
||||
@ -9,16 +10,17 @@ define('REQUEST_TOKEN_DURATION', 300);
|
||||
define('ACCESS_TOKEN_DURATION', 31536000);
|
||||
|
||||
require_once("library/OAuth1.php");
|
||||
require_once("library/oauth2-php/lib/OAuth2.inc");
|
||||
|
||||
class FKOAuthDataStore extends OAuthDataStore {
|
||||
function gen_token(){
|
||||
//require_once("library/oauth2-php/lib/OAuth2.inc");
|
||||
|
||||
class ZotOAuthDataStore extends OAuthDataStore {
|
||||
|
||||
function gen_token(){
|
||||
return md5(base64_encode(pack('N6', mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), uniqid())));
|
||||
}
|
||||
}
|
||||
|
||||
function lookup_consumer($consumer_key) {
|
||||
logger(__function__.":".$consumer_key);
|
||||
// echo "<pre>"; var_dump($consumer_key); killme();
|
||||
function lookup_consumer($consumer_key) {
|
||||
logger('consumer_key: ' . $consumer_key, LOGGER_DEBUG);
|
||||
|
||||
$r = q("SELECT client_id, pw, redirect_uri FROM clients WHERE client_id = '%s'",
|
||||
dbesc($consumer_key)
|
||||
@ -29,10 +31,11 @@ class FKOAuthDataStore extends OAuthDataStore {
|
||||
return new OAuthConsumer($r[0]['client_id'],$r[0]['pw'],$r[0]['redirect_uri']);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function lookup_token($consumer, $token_type, $token) {
|
||||
logger(__function__.":".$consumer.", ". $token_type.", ".$token);
|
||||
function lookup_token($consumer, $token_type, $token) {
|
||||
|
||||
logger(__function__.":".$consumer.", ". $token_type.", ".$token, LOGGER_DEBUG);
|
||||
|
||||
$r = q("SELECT id, secret, scope, expires, uid FROM tokens WHERE client_id = '%s' AND scope = '%s' AND id = '%s'",
|
||||
dbesc($consumer->key),
|
||||
@ -48,10 +51,9 @@ class FKOAuthDataStore extends OAuthDataStore {
|
||||
return $ot;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function lookup_nonce($consumer, $token, $nonce, $timestamp) {
|
||||
// echo __file__.":".__line__."<pre>"; var_dump($consumer,$key); killme();
|
||||
function lookup_nonce($consumer, $token, $nonce, $timestamp) {
|
||||
|
||||
$r = q("SELECT id, secret FROM tokens WHERE client_id = '%s' AND id = '%s' AND expires = %d",
|
||||
dbesc($consumer->key),
|
||||
@ -62,10 +64,12 @@ class FKOAuthDataStore extends OAuthDataStore {
|
||||
if (count($r))
|
||||
return new OAuthToken($r[0]['id'],$r[0]['secret']);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function new_request_token($consumer, $callback = null) {
|
||||
|
||||
logger(__function__.":".$consumer.", ". $callback, LOGGER_DEBUG);
|
||||
|
||||
function new_request_token($consumer, $callback = null) {
|
||||
logger(__function__.":".$consumer.", ". $callback);
|
||||
$key = $this->gen_token();
|
||||
$sec = $this->gen_token();
|
||||
|
||||
@ -82,29 +86,31 @@ class FKOAuthDataStore extends OAuthDataStore {
|
||||
'request',
|
||||
time()+intval(REQUEST_TOKEN_DURATION));
|
||||
|
||||
if (!$r) return null;
|
||||
if(! $r)
|
||||
return null;
|
||||
return new OAuthToken($key,$sec);
|
||||
}
|
||||
}
|
||||
|
||||
function new_access_token($token, $consumer, $verifier = null) {
|
||||
logger(__function__.":".$token.", ". $consumer.", ". $verifier);
|
||||
function new_access_token($token, $consumer, $verifier = null) {
|
||||
|
||||
logger(__function__.":".$token.", ". $consumer.", ". $verifier, LOGGER_DEBUG);
|
||||
|
||||
// return a new access token attached to this consumer
|
||||
// for the user associated with this token if the request token
|
||||
// is authorized
|
||||
// should also invalidate the request token
|
||||
|
||||
$ret=Null;
|
||||
|
||||
// get user for this verifier
|
||||
$uverifier = get_config("oauth", $verifier);
|
||||
logger(__function__.":".$verifier.",".$uverifier);
|
||||
if (is_null($verifier) || ($uverifier!==false)){
|
||||
// return a new access token attached to this consumer
|
||||
// for the user associated with this token if the request token
|
||||
// is authorized
|
||||
// should also invalidate the request token
|
||||
|
||||
$ret=Null;
|
||||
|
||||
// get user for this verifier
|
||||
$uverifier = get_config("oauth", $verifier);
|
||||
logger(__function__.":".$verifier.",".$uverifier, LOGGER_DEBUG);
|
||||
if (is_null($verifier) || ($uverifier!==false)) {
|
||||
|
||||
$key = $this->gen_token();
|
||||
$sec = $this->gen_token();
|
||||
$key = $this->gen_token();
|
||||
$sec = $this->gen_token();
|
||||
|
||||
$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires, uid) VALUES ('%s','%s','%s','%s', %d, %d)",
|
||||
$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires, uid) VALUES ('%s','%s','%s','%s', %d, %d)",
|
||||
dbesc($key),
|
||||
dbesc($sec),
|
||||
dbesc($consumer->key),
|
||||
@ -112,81 +118,70 @@ class FKOAuthDataStore extends OAuthDataStore {
|
||||
time()+intval(ACCESS_TOKEN_DURATION),
|
||||
intval($uverifier));
|
||||
|
||||
if ($r)
|
||||
$ret = new OAuthToken($key,$sec);
|
||||
}
|
||||
if ($r)
|
||||
$ret = new OAuthToken($key,$sec);
|
||||
}
|
||||
|
||||
|
||||
q("DELETE FROM tokens WHERE id='%s'", $token->key);
|
||||
q("DELETE FROM tokens WHERE id='%s'", $token->key);
|
||||
|
||||
|
||||
if (!is_null($ret) && $uverifier!==false){
|
||||
del_config("oauth", $verifier);
|
||||
/* $apps = get_pconfig($uverifier, "oauth", "apps");
|
||||
if ($apps===false) $apps=array();
|
||||
$apps[] = $consumer->key;
|
||||
set_pconfig($uverifier, "oauth", "apps", $apps);*/
|
||||
if (!is_null($ret) && $uverifier!==false) {
|
||||
del_config("oauth", $verifier);
|
||||
|
||||
// $apps = get_pconfig($uverifier, "oauth", "apps");
|
||||
// if ($apps===false) $apps=array();
|
||||
// $apps[] = $consumer->key;
|
||||
// set_pconfig($uverifier, "oauth", "apps", $apps);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class FKOAuth1 extends OAuthServer {
|
||||
class ZotOAuth1 extends OAuthServer {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct(new FKOAuthDataStore());
|
||||
parent::__construct(new ZotOAuthDataStore());
|
||||
$this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
|
||||
$this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
|
||||
}
|
||||
|
||||
function loginUser($uid){
|
||||
logger("RedOAuth1::loginUser $uid");
|
||||
$a = get_app();
|
||||
|
||||
logger("ZotOAuth1::loginUser $uid");
|
||||
|
||||
$r = q("SELECT * FROM channel WHERE channel_id = %d LIMIT 1",
|
||||
intval($uid)
|
||||
);
|
||||
if(count($r)){
|
||||
$record = $r[0];
|
||||
} else {
|
||||
logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
die('This api requires login');
|
||||
logger('ZotOAuth1::loginUser failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
echo('This api requires login');
|
||||
killme();
|
||||
}
|
||||
|
||||
$_SESSION['uid'] = $record['channel_id'];
|
||||
$_SESSION['theme'] = $record['channel_theme'];
|
||||
$_SESSION['account_id'] = $record['channel_account_id'];
|
||||
$_SESSION['mobile_theme'] = get_pconfig($record['channel_id'], 'system', 'mobile_theme');
|
||||
$_SESSION['authenticated'] = 1;
|
||||
$_SESSION['my_url'] = $a->get_baseurl() . '/channel/' . $record['channel_address'];
|
||||
$_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
|
||||
$_SESSION['allow_api'] = true;
|
||||
|
||||
$x = q("select * from account where account_id = %d limit 1",
|
||||
intval($record['channel_account_id'])
|
||||
);
|
||||
if($x)
|
||||
$a->account = $x[0];
|
||||
|
||||
change_channel($record['channel_id']);
|
||||
|
||||
$a->channel = $record;
|
||||
|
||||
if(strlen($a->channel['channel_timezone'])) {
|
||||
date_default_timezone_set($a->channel['channel_timezone']);
|
||||
if($x) {
|
||||
require_once('include/security.php');
|
||||
authenticate_success($x[0],true,false,true,true);
|
||||
$_SESSION['allow_api'] = true;
|
||||
}
|
||||
|
||||
// q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d LIMIT 1",
|
||||
// dbesc(datetime_convert()),
|
||||
// intval($_SESSION['uid'])
|
||||
// );
|
||||
//
|
||||
// call_hooks('logged_in', $a->user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
|
||||
not yet used
|
||||
|
||||
class FKOAuth2 extends OAuth2 {
|
||||
|
||||
private function db_secret($client_secret){
|
||||
|
@ -495,6 +495,15 @@ function format_css_if_exists($source) {
|
||||
return '<link rel="stylesheet" href="' . script_path() . '/' . $path . '" type="text/css" media="' . $source[1] . '">' . "\r\n";
|
||||
}
|
||||
|
||||
/*
|
||||
* This basically calculates the baseurl. We have other functions to do that, but
|
||||
* there was an issue with script paths and mixed-content whose details are arcane
|
||||
* and perhaps lost in the message archives. The short answer is that we're ignoring
|
||||
* the URL which we are "supposed" to use, and generating script paths relative to
|
||||
* the URL which we are currently using; in order to ensure they are found and aren't
|
||||
* blocked due to mixed content issues.
|
||||
*/
|
||||
|
||||
function script_path() {
|
||||
if(x($_SERVER,'HTTPS') && $_SERVER['HTTPS'])
|
||||
$scheme = 'https';
|
||||
@ -616,3 +625,14 @@ function get_markup_template($s, $root = '') {
|
||||
$template = $t->get_markup_template($s, $root);
|
||||
return $template;
|
||||
}
|
||||
|
||||
// return the standardised version. Since we can't easily compare
|
||||
// before the STD_VERSION definition was applied, we have to treat
|
||||
// all prior release versions the same. You can dig through them
|
||||
// with other means (such as RED_VERSION) if necessary.
|
||||
|
||||
function get_std_version() {
|
||||
if(defined('STD_VERSION'))
|
||||
return STD_VERSION;
|
||||
return '0.0.0';
|
||||
}
|
||||
|
@ -93,6 +93,7 @@ function change_channel($change_channel) {
|
||||
$ret = false;
|
||||
|
||||
if($change_channel) {
|
||||
|
||||
$r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel_id = %d and channel_account_id = %d and channel_removed = 0 limit 1",
|
||||
intval($change_channel),
|
||||
intval(get_account_id())
|
||||
@ -136,14 +137,14 @@ function change_channel($change_channel) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates an addiontal SQL where statement to check permissions.
|
||||
* @brief Creates an additional SQL where statement to check permissions.
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param bool $remote_verified default false, not used at all
|
||||
* @param string $groups this param is not used at all
|
||||
* @param bool $remote_observer - if unset use current observer
|
||||
*
|
||||
* @return string additional SQL where statement
|
||||
*/
|
||||
|
||||
function permissions_sql($owner_id, $remote_observer = null) {
|
||||
|
||||
$local_channel = local_channel();
|
||||
@ -208,8 +209,7 @@ function permissions_sql($owner_id, $remote_observer = null) {
|
||||
* @brief Creates an addiontal SQL where statement to check permissions for an item.
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param bool $remote_verified default false, not used at all
|
||||
* @param string $groups this param is not used at all
|
||||
* @param bool $remote_observer, use current observer if unset
|
||||
*
|
||||
* @return string additional SQL where statement
|
||||
*/
|
||||
@ -400,11 +400,9 @@ function check_form_security_token_ForbiddenOnErr($typename = '', $formname = 'f
|
||||
}
|
||||
|
||||
|
||||
// Returns an array of group id's this contact is a member of.
|
||||
// This array will only contain group id's related to the uid of this
|
||||
// DFRN contact. They are *not* neccessarily unique across the entire site.
|
||||
// Returns an array of group hash id's on this entire site (across all channels) that this connection is a member of.
|
||||
// var $contact_id = xchan_hash of connection
|
||||
|
||||
if(! function_exists('init_groups_visitor')) {
|
||||
function init_groups_visitor($contact_id) {
|
||||
$groups = array();
|
||||
$r = q("SELECT hash FROM `groups` left join group_member on groups.id = group_member.gid WHERE xchan = '%s' ",
|
||||
@ -415,7 +413,7 @@ function init_groups_visitor($contact_id) {
|
||||
$groups[] = $rr['hash'];
|
||||
}
|
||||
return $groups;
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -666,7 +666,7 @@ function widget_eventsmenu($arr) {
|
||||
if (! local_channel())
|
||||
return;
|
||||
|
||||
return replace_macros(get_markup_template('events_side.tpl'), array(
|
||||
return replace_macros(get_markup_template('events_menu_side.tpl'), array(
|
||||
'$title' => t('Events Menu'),
|
||||
'$day' => t('Day View'),
|
||||
'$week' => t('Week View'),
|
||||
@ -677,6 +677,18 @@ function widget_eventsmenu($arr) {
|
||||
));
|
||||
}
|
||||
|
||||
function widget_eventstools($arr) {
|
||||
if (! local_channel())
|
||||
return;
|
||||
|
||||
return replace_macros(get_markup_template('events_tools_side.tpl'), array(
|
||||
'$title' => t('Events Tools'),
|
||||
'$export' => t('Export Calendar'),
|
||||
'$import' => t('Import Calendar'),
|
||||
'$submit' => t('Submit')
|
||||
));
|
||||
}
|
||||
|
||||
function widget_design_tools($arr) {
|
||||
$a = get_app();
|
||||
|
||||
@ -1136,7 +1148,7 @@ function widget_forums($arr) {
|
||||
foreach($r1 as $rr) {
|
||||
if($unseen && (! intval($rr['unseen'])))
|
||||
continue;
|
||||
$o .= '<li><span class="pull-right">' . ((intval($rr['unseen'])) ? intval($rr['unseen']) : '') . '</span><a href="network?f=&pf=1&cid=' . $rr['abook_id'] . '" ><img src="' . $rr['xchan_photo_s'] . '" style="width: 16px; height: 16px;" /> ' . $rr['xchan_name'] . '</a></li>';
|
||||
$o .= '<li><a href="network?f=&pf=1&cid=' . $rr['abook_id'] . '" ><span class="badge pull-right">' . ((intval($rr['unseen'])) ? intval($rr['unseen']) : '') . '</span><img src="' . $rr['xchan_photo_s'] . '" style="width: 16px; height: 16px;" /> ' . $rr['xchan_name'] . '</a></li>';
|
||||
}
|
||||
$o .= '</ul></div>';
|
||||
}
|
||||
@ -1147,6 +1159,8 @@ function widget_forums($arr) {
|
||||
|
||||
function widget_tasklist($arr) {
|
||||
|
||||
if (! local_channel())
|
||||
return;
|
||||
|
||||
require_once('include/event.php');
|
||||
$o .= '<script>var tasksShowAll = 0; $(document).ready(function() { tasksFetch(); $("#tasklist-new-form").submit(function(event) { event.preventDefault(); $.post( "tasks/new", $("#tasklist-new-form").serialize(), function(data) { tasksFetch(); $("#tasklist-new-summary").val(""); } ); return false; } )});</script>';
|
||||
@ -1285,7 +1299,6 @@ function widget_album($args) {
|
||||
//edit album name
|
||||
$album_edit = null;
|
||||
|
||||
|
||||
$photos = array();
|
||||
if($r) {
|
||||
$twist = 'rotright';
|
||||
@ -1324,6 +1337,7 @@ function widget_album($args) {
|
||||
$o .= replace_macros($tpl, array(
|
||||
'$photos' => $photos,
|
||||
'$album' => (($title) ? $title : $album),
|
||||
'$album_id' => rand(),
|
||||
'$album_edit' => array(t('Edit Album'), $album_edit),
|
||||
'$can_post' => false,
|
||||
'$upload' => array(t('Upload'), z_root() . '/photos/' . get_app()->profile['channel_address'] . '/upload/' . bin2hex($album)),
|
||||
|
464
include/zot.php
464
include/zot.php
@ -554,18 +554,8 @@ function zot_gethub($arr,$multiple = false) {
|
||||
|
||||
if($arr['guid'] && $arr['guid_sig'] && $arr['url'] && $arr['url_sig']) {
|
||||
|
||||
$blacklisted = false;
|
||||
$bl1 = get_config('system','blacklisted_sites');
|
||||
if(is_array($bl1) && $bl1) {
|
||||
foreach($bl1 as $bl) {
|
||||
if($bl && strpos($arr['url'],$bl) !== false) {
|
||||
$blacklisted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($blacklisted) {
|
||||
logger('zot_gethub: blacklisted site: ' . $arr['url']);
|
||||
if(! check_siteallowed($arr['url'])) {
|
||||
logger('blacklisted site: ' . $arr['url']);
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1246,6 +1236,10 @@ function zot_import($arr, $sender_url) {
|
||||
$no_dups = array();
|
||||
if($deliveries) {
|
||||
foreach($deliveries as $d) {
|
||||
if(! is_array($d)) {
|
||||
logger('Delivery hash array is not an array: ' . print_r($d,true));
|
||||
continue;
|
||||
}
|
||||
if(! in_array($d['hash'],$no_dups))
|
||||
$no_dups[] = $d['hash'];
|
||||
}
|
||||
@ -1617,6 +1611,14 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $
|
||||
$channel = $r[0];
|
||||
$DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>');
|
||||
|
||||
/* blacklisted channels get a permission denied, no special message to tip them off */
|
||||
|
||||
if(! check_channelallowed($sender['hash'])) {
|
||||
$DR->update('permission denied');
|
||||
$result[] = $DR->get();
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @FIXME: Somehow we need to block normal message delivery from our clones, as the delivered
|
||||
* message doesn't have ACL information in it as the cloned copy does. That copy
|
||||
@ -2088,6 +2090,14 @@ function process_mail_delivery($sender, $arr, $deliveries) {
|
||||
$channel = $r[0];
|
||||
$DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>');
|
||||
|
||||
/* blacklisted channels get a permission denied, no special message to tip them off */
|
||||
|
||||
if(! check_channelallowed($sender['hash'])) {
|
||||
$DR->update('permission denied');
|
||||
$result[] = $DR->get();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(! perm_is_allowed($channel['channel_id'],$sender['hash'],'post_mail')) {
|
||||
logger("permission denied for mail delivery {$channel['channel_id']}");
|
||||
$DR->update('permission denied');
|
||||
@ -3484,13 +3494,13 @@ function import_author_zot($x) {
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
function zot_process_message_request($data) {
|
||||
function zot_reply_message_request($data) {
|
||||
$ret = array('success' => false);
|
||||
|
||||
if (! $data['message_id']) {
|
||||
$ret['message'] = 'no message_id';
|
||||
logger('no message_id');
|
||||
return $ret;
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
$sender = $data['sender'];
|
||||
@ -3508,7 +3518,7 @@ function zot_process_message_request($data) {
|
||||
if (! $c) {
|
||||
logger('recipient channel not found.');
|
||||
$ret['message'] .= 'recipient not found.' . EOL;
|
||||
return $ret;
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -3526,7 +3536,7 @@ function zot_process_message_request($data) {
|
||||
);
|
||||
if (! $r) {
|
||||
logger('no hubs');
|
||||
return $ret;
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
$hubs = $r;
|
||||
|
||||
@ -3567,8 +3577,7 @@ function zot_process_message_request($data) {
|
||||
}
|
||||
}
|
||||
$ret['success'] = true;
|
||||
|
||||
return $ret;
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
|
||||
@ -3789,6 +3798,7 @@ function zotinfo($arr) {
|
||||
$ret['site'] = array();
|
||||
$ret['site']['url'] = z_root();
|
||||
$ret['site']['url_sig'] = base64url_encode(rsa_sign(z_root(),$e['channel_prvkey']));
|
||||
$ret['site']['zot_auth'] = z_root() . '/magic';
|
||||
|
||||
$dirmode = get_config('system','directory_mode');
|
||||
if(($dirmode === false) || ($dirmode == DIRECTORY_MODE_NORMAL))
|
||||
@ -3979,3 +3989,421 @@ function delivery_report_is_storable($dr) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
function update_hub_connected($hub,$sitekey = '') {
|
||||
|
||||
if($sitekey) {
|
||||
|
||||
/*
|
||||
* This hub has now been proven to be valid.
|
||||
* Any hub with the same URL and a different sitekey cannot be valid.
|
||||
* Get rid of them (mark them deleted). There's a good chance they were re-installs.
|
||||
*/
|
||||
|
||||
q("update hubloc set hubloc_deleted = 1, hubloc_error = 1 where hubloc_url = '%s' and hubloc_sitekey != '%s' ",
|
||||
dbesc($hub['hubloc_url']),
|
||||
dbesc($sitekey)
|
||||
);
|
||||
|
||||
}
|
||||
else {
|
||||
$sitekey = $hub['sitekey'];
|
||||
}
|
||||
|
||||
// $sender['sitekey'] is a new addition to the protcol to distinguish
|
||||
// hublocs coming from re-installed sites. Older sites will not provide
|
||||
// this field and we have to still mark them valid, since we can't tell
|
||||
// if this hubloc has the same sitekey as the packet we received.
|
||||
|
||||
|
||||
// Update our DB to show when we last communicated successfully with this hub
|
||||
// This will allow us to prune dead hubs from using up resources
|
||||
|
||||
$r = q("update hubloc set hubloc_connected = '%s' where hubloc_id = %d and hubloc_sitekey = '%s' ",
|
||||
dbesc(datetime_convert()),
|
||||
intval($hub['hubloc_id']),
|
||||
dbesc($sitekey)
|
||||
);
|
||||
|
||||
// a dead hub came back to life - reset any tombstones we might have
|
||||
|
||||
if(intval($hub['hubloc_error'])) {
|
||||
q("update hubloc set hubloc_error = 0 where hubloc_id = %d and hubloc_sitekey = '%s' ",
|
||||
intval($hub['hubloc_id']),
|
||||
dbesc($sitekey)
|
||||
);
|
||||
if(intval($r[0]['hubloc_orphancheck'])) {
|
||||
q("update hubloc set hubloc_orhpancheck = 0 where hubloc_id = %d and hubloc_sitekey = '%s' ",
|
||||
intval($hub['hubloc_id']),
|
||||
dbesc($sitekey)
|
||||
);
|
||||
}
|
||||
q("update xchan set xchan_orphan = 0 where xchan_orphan = 1 and xchan_hash = '%s'",
|
||||
dbesc($hub['hubloc_hash'])
|
||||
);
|
||||
}
|
||||
|
||||
return $hub['hubloc_url'];
|
||||
}
|
||||
|
||||
|
||||
function zot_reply_ping() {
|
||||
|
||||
$ret = array('success'=> false);
|
||||
|
||||
// Useful to get a health check on a remote site.
|
||||
// This will let us know if any important communication details
|
||||
// that we may have stored are no longer valid, regardless of xchan details.
|
||||
logger('POST: got ping send pong now back: ' . z_root() , LOGGER_DEBUG );
|
||||
|
||||
$ret['success'] = true;
|
||||
$ret['site'] = array();
|
||||
$ret['site']['url'] = z_root();
|
||||
$ret['site']['url_sig'] = base64url_encode(rsa_sign(z_root(),get_config('system','prvkey')));
|
||||
$ret['site']['sitekey'] = get_config('system','pubkey');
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
function zot_reply_pickup($data) {
|
||||
|
||||
$ret = array('success'=> false);
|
||||
|
||||
/*
|
||||
* The 'pickup' message arrives with a tracking ID which is associated with a particular outq_hash
|
||||
* First verify that that the returned signatures verify, then check that we have an outbound queue item
|
||||
* with the correct hash.
|
||||
* If everything verifies, find any/all outbound messages in the queue for this hubloc and send them back
|
||||
*/
|
||||
|
||||
if((! $data['secret']) || (! $data['secret_sig'])) {
|
||||
$ret['message'] = 'no verification signature';
|
||||
logger('mod_zot: pickup: ' . $ret['message'], LOGGER_DEBUG);
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
$r = q("select distinct hubloc_sitekey from hubloc where hubloc_url = '%s' and hubloc_callback = '%s' and hubloc_sitekey != '' group by hubloc_sitekey ",
|
||||
dbesc($data['url']),
|
||||
dbesc($data['callback'])
|
||||
);
|
||||
if(! $r) {
|
||||
$ret['message'] = 'site not found';
|
||||
logger('mod_zot: pickup: ' . $ret['message']);
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
foreach ($r as $hubsite) {
|
||||
|
||||
// verify the url_sig
|
||||
// If the server was re-installed at some point, there could be multiple hubs with the same url and callback.
|
||||
// Only one will have a valid key.
|
||||
|
||||
$forgery = true;
|
||||
$secret_fail = true;
|
||||
|
||||
$sitekey = $hubsite['hubloc_sitekey'];
|
||||
|
||||
logger('mod_zot: Checking sitekey: ' . $sitekey, LOGGER_DATA);
|
||||
|
||||
if(rsa_verify($data['callback'],base64url_decode($data['callback_sig']),$sitekey)) {
|
||||
$forgery = false;
|
||||
}
|
||||
if(rsa_verify($data['secret'],base64url_decode($data['secret_sig']),$sitekey)) {
|
||||
$secret_fail = false;
|
||||
}
|
||||
if((! $forgery) && (! $secret_fail))
|
||||
break;
|
||||
}
|
||||
|
||||
if($forgery) {
|
||||
$ret['message'] = 'possible site forgery';
|
||||
logger('mod_zot: pickup: ' . $ret['message']);
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
if($secret_fail) {
|
||||
$ret['message'] = 'secret validation failed';
|
||||
logger('mod_zot: pickup: ' . $ret['message']);
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we made it to here, the signatures verify, but we still don't know if the tracking ID is valid.
|
||||
* It wouldn't be an error if the tracking ID isn't found, because we may have sent this particular
|
||||
* queue item with another pickup (after the tracking ID for the other pickup was verified).
|
||||
*/
|
||||
|
||||
$r = q("select outq_posturl from outq where outq_hash = '%s' and outq_posturl = '%s' limit 1",
|
||||
dbesc($data['secret']),
|
||||
dbesc($data['callback'])
|
||||
);
|
||||
if(! $r) {
|
||||
$ret['message'] = 'nothing to pick up';
|
||||
logger('mod_zot: pickup: ' . $ret['message']);
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* Everything is good if we made it here, so find all messages that are going to this location
|
||||
* and send them all.
|
||||
*/
|
||||
|
||||
$r = q("select * from outq where outq_posturl = '%s'",
|
||||
dbesc($data['callback'])
|
||||
);
|
||||
if($r) {
|
||||
logger('mod_zot: successful pickup message received from ' . $data['callback'] . ' ' . count($r) . ' message(s) picked up', LOGGER_DEBUG);
|
||||
|
||||
$ret['success'] = true;
|
||||
$ret['pickup'] = array();
|
||||
foreach($r as $rr) {
|
||||
if($rr['outq_msg']) {
|
||||
$x = json_decode($rr['outq_msg'],true);
|
||||
|
||||
if(! $x)
|
||||
continue;
|
||||
|
||||
if(array_key_exists('message_list',$x)) {
|
||||
foreach($x['message_list'] as $xx) {
|
||||
$ret['pickup'][] = array('notify' => json_decode($rr['outq_notify'],true),'message' => $xx);
|
||||
}
|
||||
}
|
||||
else
|
||||
$ret['pickup'][] = array('notify' => json_decode($rr['outq_notify'],true),'message' => $x);
|
||||
$x = q("delete from outq where outq_hash = '%s'",
|
||||
dbesc($rr['outq_hash'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$encrypted = crypto_encapsulate(json_encode($ret),$sitekey);
|
||||
json_return_and_die($encrypted);
|
||||
|
||||
/* pickup: end */
|
||||
}
|
||||
|
||||
|
||||
|
||||
function zot_reply_auth_check($data,$encrypted_packet) {
|
||||
|
||||
$ret = array('success' => false);
|
||||
|
||||
/*
|
||||
* Requestor visits /magic/?dest=somewhere on their own site with a browser
|
||||
* magic redirects them to $destsite/post [with auth args....]
|
||||
* $destsite sends an auth_check packet to originator site
|
||||
* The auth_check packet is handled here by the originator's site
|
||||
* - the browser session is still waiting
|
||||
* inside $destsite/post for everything to verify
|
||||
* If everything checks out we'll return a token to $destsite
|
||||
* and then $destsite will verify the token, authenticate the browser
|
||||
* session and then redirect to the original destination.
|
||||
* If authentication fails, the redirection to the original destination
|
||||
* will still take place but without authentication.
|
||||
*/
|
||||
logger('mod_zot: auth_check', LOGGER_DEBUG);
|
||||
|
||||
if (! $encrypted_packet) {
|
||||
logger('mod_zot: auth_check packet was not encrypted.');
|
||||
$ret['message'] .= 'no packet encryption' . EOL;
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
$arr = $data['sender'];
|
||||
$sender_hash = make_xchan_hash($arr['guid'],$arr['guid_sig']);
|
||||
|
||||
// garbage collect any old unused notifications
|
||||
|
||||
// This was and should be 10 minutes but my hosting provider has time lag between the DB and
|
||||
// the web server. We should probably convert this to webserver time rather than DB time so
|
||||
// that the different clocks won't affect it and allow us to keep the time short.
|
||||
|
||||
q("delete from verify where type = 'auth' and created < %s - INTERVAL %s",
|
||||
db_utcnow(), db_quoteinterval('30 MINUTE')
|
||||
);
|
||||
|
||||
$y = q("select xchan_pubkey from xchan where xchan_hash = '%s' limit 1",
|
||||
dbesc($sender_hash)
|
||||
);
|
||||
|
||||
// We created a unique hash in mod/magic.php when we invoked remote auth, and stored it in
|
||||
// the verify table. It is now coming back to us as 'secret' and is signed by a channel at the other end.
|
||||
// First verify their signature. We will have obtained a zot-info packet from them as part of the sender
|
||||
// verification.
|
||||
|
||||
if ((! $y) || (! rsa_verify($data['secret'], base64url_decode($data['secret_sig']),$y[0]['xchan_pubkey']))) {
|
||||
logger('mod_zot: auth_check: sender not found or secret_sig invalid.');
|
||||
$ret['message'] .= 'sender not found or sig invalid ' . print_r($y,true) . EOL;
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
// There should be exactly one recipient, the original auth requestor
|
||||
|
||||
$ret['message'] .= 'recipients ' . print_r($recipients,true) . EOL;
|
||||
|
||||
if ($data['recipients']) {
|
||||
|
||||
$arr = $data['recipients'][0];
|
||||
$recip_hash = make_xchan_hash($arr['guid'], $arr['guid_sig']);
|
||||
$c = q("select channel_id, channel_account_id, channel_prvkey from channel where channel_hash = '%s' limit 1",
|
||||
dbesc($recip_hash)
|
||||
);
|
||||
if (! $c) {
|
||||
logger('mod_zot: auth_check: recipient channel not found.');
|
||||
$ret['message'] .= 'recipient not found.' . EOL;
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
$confirm = base64url_encode(rsa_sign($data['secret'] . $recip_hash,$c[0]['channel_prvkey']));
|
||||
|
||||
// This additionally checks for forged sites since we already stored the expected result in meta
|
||||
// and we've already verified that this is them via zot_gethub() and that their key signed our token
|
||||
|
||||
$z = q("select id from verify where channel = %d and type = 'auth' and token = '%s' and meta = '%s' limit 1",
|
||||
intval($c[0]['channel_id']),
|
||||
dbesc($data['secret']),
|
||||
dbesc($data['sender']['url'])
|
||||
);
|
||||
if (! $z) {
|
||||
logger('mod_zot: auth_check: verification key not found.');
|
||||
$ret['message'] .= 'verification key not found' . EOL;
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
$r = q("delete from verify where id = %d",
|
||||
intval($z[0]['id'])
|
||||
);
|
||||
|
||||
$u = q("select account_service_class from account where account_id = %d limit 1",
|
||||
intval($c[0]['channel_account_id'])
|
||||
);
|
||||
|
||||
logger('mod_zot: auth_check: success', LOGGER_DEBUG);
|
||||
$ret['success'] = true;
|
||||
$ret['confirm'] = $confirm;
|
||||
if ($u && $u[0]['account_service_class'])
|
||||
$ret['service_class'] = $u[0]['account_service_class'];
|
||||
|
||||
// Set "do not track" flag if this site or this channel's profile is restricted
|
||||
// in some way
|
||||
|
||||
if (intval(get_config('system','block_public')))
|
||||
$ret['DNT'] = true;
|
||||
if (! perm_is_allowed($c[0]['channel_id'],'','view_profile'))
|
||||
$ret['DNT'] = true;
|
||||
if (get_pconfig($c[0]['channel_id'],'system','do_not_track'))
|
||||
$ret['DNT'] = true;
|
||||
if (get_pconfig($c[0]['channel_id'],'system','hide_online_status'))
|
||||
$ret['DNT'] = true;
|
||||
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
|
||||
function zot_reply_purge($sender,$recipients) {
|
||||
|
||||
$ret = array('success' => false);
|
||||
|
||||
if ($recipients) {
|
||||
// basically this means "unfriend"
|
||||
foreach ($recipients as $recip) {
|
||||
$r = q("select channel.*,xchan.* from channel
|
||||
left join xchan on channel_hash = xchan_hash
|
||||
where channel_guid = '%s' and channel_guid_sig = '%s' limit 1",
|
||||
dbesc($recip['guid']),
|
||||
dbesc($recip['guid_sig'])
|
||||
);
|
||||
if ($r) {
|
||||
$r = q("select abook_id from abook where uid = %d and abook_xchan = '%s' limit 1",
|
||||
intval($r[0]['channel_id']),
|
||||
dbesc(make_xchan_hash($sender['guid'],$sender['guid_sig']))
|
||||
);
|
||||
if ($r) {
|
||||
contact_remove($r[0]['channel_id'],$r[0]['abook_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$ret['success'] = true;
|
||||
}
|
||||
else {
|
||||
// Unfriend everybody - basically this means the channel has committed suicide
|
||||
$arr = $sender;
|
||||
$sender_hash = make_xchan_hash($arr['guid'],$arr['guid_sig']);
|
||||
|
||||
require_once('include/Contact.php');
|
||||
remove_all_xchan_resources($sender_hash);
|
||||
|
||||
$ret['success'] = true;
|
||||
}
|
||||
|
||||
json_return_and_die($ret);
|
||||
}
|
||||
|
||||
|
||||
function zot_reply_refresh($sender,$recipients) {
|
||||
|
||||
$ret = array('success' => false);
|
||||
|
||||
// remote channel info (such as permissions or photo or something)
|
||||
// has been updated. Grab a fresh copy and sync it.
|
||||
// The difference between refresh and force_refresh is that
|
||||
// force_refresh unconditionally creates a directory update record,
|
||||
// even if no changes were detected upon processing.
|
||||
|
||||
if($recipients) {
|
||||
|
||||
// This would be a permissions update, typically for one connection
|
||||
|
||||
foreach ($recipients as $recip) {
|
||||
$r = q("select channel.*,xchan.* from channel
|
||||
left join xchan on channel_hash = xchan_hash
|
||||
where channel_guid = '%s' and channel_guid_sig = '%s' limit 1",
|
||||
dbesc($recip['guid']),
|
||||
dbesc($recip['guid_sig'])
|
||||
);
|
||||
|
||||
$x = zot_refresh(array(
|
||||
'xchan_guid' => $sender['guid'],
|
||||
'xchan_guid_sig' => $sender['guid_sig'],
|
||||
'hubloc_url' => $sender['url']
|
||||
), $r[0], (($msgtype === 'force_refresh') ? true : false));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// system wide refresh
|
||||
|
||||
$x = zot_refresh(array(
|
||||
'xchan_guid' => $sender['guid'],
|
||||
'xchan_guid_sig' => $sender['guid_sig'],
|
||||
'hubloc_url' => $sender['url']
|
||||
), null, (($msgtype === 'force_refresh') ? true : false));
|
||||
}
|
||||
|
||||
$ret['success'] = true;
|
||||
json_return_and_die($ret);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function zot_reply_notify($data) {
|
||||
|
||||
$ret = array('success' => false);
|
||||
|
||||
logger('notify received from ' . $data['sender']['url']);
|
||||
|
||||
$async = get_config('system','queued_fetch');
|
||||
|
||||
if($async) {
|
||||
// add to receive queue
|
||||
// qreceive_add($data);
|
||||
}
|
||||
else {
|
||||
$x = zot_fetch($data);
|
||||
$ret['delivery_report'] = $x;
|
||||
}
|
||||
|
||||
$ret['success'] = true;
|
||||
json_return_and_die($ret);
|
||||
|
||||
}
|
@ -23,6 +23,7 @@ CREATE TABLE IF NOT EXISTS `abook` (
|
||||
`abook_profile` char(64) NOT NULL DEFAULT '',
|
||||
`abook_incl` TEXT NOT NULL DEFAULT '',
|
||||
`abook_excl` TEXT NOT NULL DEFAULT '',
|
||||
`abook_instance` TEXT NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`abook_id`),
|
||||
KEY `abook_account` (`abook_account`),
|
||||
KEY `abook_channel` (`abook_channel`),
|
||||
|
@ -22,6 +22,7 @@ CREATE TABLE "abook" (
|
||||
"abook_profile" char(64) NOT NULL DEFAULT '',
|
||||
"abook_incl" TEXT NOT NULL DEFAULT '',
|
||||
"abook_excl" TEXT NOT NULL DEFAULT '',
|
||||
"abook_instance" TEXT NOT NULL DEFAULT '',
|
||||
PRIMARY KEY ("abook_id")
|
||||
);
|
||||
create index "abook_account" on abook ("abook_account");
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
define( 'UPDATE_VERSION' , 1160 );
|
||||
define( 'UPDATE_VERSION' , 1161 );
|
||||
|
||||
/**
|
||||
*
|
||||
@ -1950,3 +1950,10 @@ function update_r1159() {
|
||||
}
|
||||
|
||||
|
||||
function update_r1160() {
|
||||
$r = q("alter table abook add abook_instance text not null default '' ");
|
||||
if($r)
|
||||
return UPDATE_SUCCESS;
|
||||
return UPDATE_FAILED;
|
||||
}
|
||||
|
||||
|
128
library/Smarty/NEW_FEATURES.txt
Normal file
128
library/Smarty/NEW_FEATURES.txt
Normal file
@ -0,0 +1,128 @@
|
||||
|
||||
|
||||
This file contains a brief description of new features which have been added to Smarty 3.1
|
||||
|
||||
Smarty 3.1.28
|
||||
|
||||
OPCACHE
|
||||
=======
|
||||
Smarty does now invalidate automatically updated and cleared compiled or cached template files in OPCACHE.
|
||||
Correct operation is no longer dependent on OPCACHE configuration settings.
|
||||
|
||||
Template inheritance
|
||||
====================
|
||||
Template inheritance is now processed in run time.
|
||||
See the INHERITANCE_RELEASE_NOTES
|
||||
|
||||
Modifier regex_replace
|
||||
======================
|
||||
An optional limit parameter was added
|
||||
|
||||
fetch() and display()
|
||||
=====================
|
||||
The fetch() and display() methods of the template object accept now optionally the same parameter
|
||||
as the corresponding Smarty methods the get tne content of another template.
|
||||
|
||||
File: resource
|
||||
==============
|
||||
Multiple template_dir entries can now be selected by a comma separated list of indices.
|
||||
The template_dir array is searched in the order of the indices. (could be used to change the default search order)
|
||||
|
||||
Filter support
|
||||
==============
|
||||
Optional filter names
|
||||
An optional filter name was added to $smarty->registerFilter(). It can be used to unregister a filter by name.
|
||||
- $smarty->registerFilter('output', $callback, 'name');
|
||||
$smarty->unregister('output', 'name');
|
||||
|
||||
Closures
|
||||
$smarty->registerFilter() does now accept closures.
|
||||
- $smarty->registerFilter('pre', function($source) {return $source;});
|
||||
If no optional filter name was specified it gets the default name 'closure'.
|
||||
If you register multiple closures register each with a unique filter name.
|
||||
- $smarty->registerFilter('pre', function($source) {return $source;}, 'clousre_1');
|
||||
- $smarty->registerFilter('pre', function($source) {return $source;}, 'clousre_2');
|
||||
|
||||
|
||||
Smarty 3.1.22
|
||||
|
||||
Namespace support within templates
|
||||
==================================
|
||||
Within templates you can now use namespace specifications on:
|
||||
- Constants like foo\bar\FOO
|
||||
- Class names like foo\bar\Baz::FOO, foo\bar\Baz::$foo, foo\bar\Baz::foo()
|
||||
- PHP function names like foo\bar\baz()
|
||||
|
||||
Security
|
||||
========
|
||||
- disable special $smarty variable -
|
||||
The Smarty_Security class has the new property $disabled_special_smarty_vars.
|
||||
It's an array which can be loaded with the $smarty special variable names like
|
||||
'template_object', 'template', 'current_dir' and others which will be disabled.
|
||||
Note: That this security check is performed at compile time.
|
||||
|
||||
- limit template nesting -
|
||||
Property $max_template_nesting of Smarty_Security does set the maximum template nesting level.
|
||||
The main template is level 1. The nesting level is checked at run time. When the maximum will be exceeded
|
||||
an Exception will be thrown. The default setting is 0 which does disable this check.
|
||||
|
||||
- trusted static methods -
|
||||
The Smarty_Security class has the new property $trusted_static_methods to restrict access to static methods.
|
||||
It's an nested array of trusted class and method names.
|
||||
Format:
|
||||
array (
|
||||
'class_1' => array('method_1', 'method_2'), // allowed methods
|
||||
'class_2' => array(), // all methods of class allowed
|
||||
)
|
||||
To disable access for all methods of all classes set $trusted_static_methods = null;
|
||||
The default value is an empty array() which does enables all methods of all classes, but for backward compatibility
|
||||
the setting of $static_classes will be checked.
|
||||
Note: That this security check is performed at compile time.
|
||||
|
||||
- trusted static properties -
|
||||
The Smarty_Security class has the new property $trusted_static_properties to restrict access to static properties.
|
||||
It's an nested array of trusted class and property names.
|
||||
Format:
|
||||
array (
|
||||
'class_1' => array('prop_1', 'prop_2'), // allowed properties listed
|
||||
'class_2' => array(), // all properties of class allowed
|
||||
}
|
||||
To disable access for all properties of all classes set $trusted_static_properties = null;
|
||||
The default value is an empty array() which does enables all properties of all classes, but for backward compatibility
|
||||
the setting of $static_classes will be checked.
|
||||
Note: That this security check is performed at compile time.
|
||||
|
||||
- trusted constants .
|
||||
The Smarty_Security class has the new property $trusted_constants to restrict access to constants.
|
||||
It's an array of trusted constant names.
|
||||
Format:
|
||||
array (
|
||||
'SMARTY_DIR' , // allowed constant
|
||||
}
|
||||
If the array is empty (default) the usage of constants can be controlled with the
|
||||
Smarty_Security::$allow_constants property (default true)
|
||||
|
||||
|
||||
|
||||
Compiled Templates
|
||||
==================
|
||||
Smarty does now automatically detects a change of the $merge_compiled_includes and $escape_html
|
||||
property and creates different compiled templates files depending on the setting.
|
||||
|
||||
Same applies to config files and the $config_overwrite, $config_booleanize and
|
||||
$config_read_hidden properties.
|
||||
|
||||
Debugging
|
||||
=========
|
||||
The layout of the debug window has been changed for better readability
|
||||
|
||||
New class constants
|
||||
Smarty::DEBUG_OFF
|
||||
Smarty::DEBUG_ON
|
||||
Smarty::DEBUG_INDIVIDUAL
|
||||
have been introduced for setting the $debugging property.
|
||||
|
||||
Smarty::DEBUG_INDIVIDUAL will create for each display() and fetch() call an individual debug window.
|
||||
|
||||
.
|
||||
|
@ -1,4 +1,4 @@
|
||||
Smarty 3.1.21
|
||||
Smarty 3.x
|
||||
|
||||
Author: Monte Ohrt <monte at ohrt dot com >
|
||||
Author: Uwe Tews
|
||||
@ -460,12 +460,13 @@ included template.
|
||||
PLUGINS
|
||||
=======
|
||||
|
||||
Smarty3 are following the same coding rules as in Smarty2.
|
||||
The only difference is that the template object is passed as additional third parameter.
|
||||
Smarty 3 plugins follow the same coding rules as in Smarty 2.
|
||||
The main difference is that the template object is now passed in place of the smarty object.
|
||||
The smarty object can be still be accessed through $template->smarty.
|
||||
|
||||
smarty_plugintype_name (array $params, object $smarty, object $template)
|
||||
smarty_plugintype_name (array $params, Smarty_Internal_Template $template)
|
||||
|
||||
The Smarty 2 plugins are still compatible as long as they do not make use of specific Smarty2 internals.
|
||||
The Smarty 2 plugins are still compatible as long as they do not make use of specific Smarty 2 internals.
|
||||
|
||||
|
||||
TEMPLATE INHERITANCE:
|
||||
|
@ -1,109 +0,0 @@
|
||||
= Known incompatibilities with Smarty 2 =
|
||||
|
||||
== Syntax ==
|
||||
|
||||
Smarty 3 API has a new syntax. Much of the Smarty 2 syntax is supported
|
||||
by a wrapper but deprecated. See the README that comes with Smarty 3 for more
|
||||
information.
|
||||
|
||||
The {$array|@mod} syntax has always been a bit confusing, where an "@" is required
|
||||
to apply a modifier to an array instead of the individual elements. Normally you
|
||||
always want the modifier to apply to the variable regardless of its type. In Smarty 3,
|
||||
{$array|mod} and {$array|@mod} behave identical. It is safe to drop the "@" and the
|
||||
modifier will still apply to the array. If you really want the modifier to apply to
|
||||
each array element, you must loop the array in-template, or use a custom modifier that
|
||||
supports array iteration. Most smarty functions already escape values where necessary
|
||||
such as {html_options}
|
||||
|
||||
== PHP Version ==
|
||||
Smarty 3 is PHP 5 only. It will not work with PHP 4.
|
||||
|
||||
== {php} Tag ==
|
||||
The {php} tag is disabled by default. The use of {php} tags is
|
||||
deprecated. It can be enabled with $smarty->allow_php_tag=true.
|
||||
|
||||
But if you scatter PHP code which belongs together into several
|
||||
{php} tags it may not work any longer.
|
||||
|
||||
== Delimiters and whitespace ==
|
||||
Delimiters surrounded by whitespace are no longer treated as Smarty tags.
|
||||
Therefore, { foo } will not compile as a tag, you must use {foo}. This change
|
||||
Makes Javascript/CSS easier to work with, eliminating the need for {literal}.
|
||||
This can be disabled by setting $smarty->auto_literal = false;
|
||||
|
||||
== Unquoted Strings ==
|
||||
Smarty 2 was a bit more forgiving (and ambiguous) when it comes to unquoted strings
|
||||
in parameters. Smarty3 is more restrictive. You can still pass strings without quotes
|
||||
so long as they contain no special characters. (anything outside of A-Za-z0-9_)
|
||||
|
||||
For example filename strings must be quoted
|
||||
<source lang="smarty">
|
||||
{include file='path/foo.tpl'}
|
||||
</source>
|
||||
|
||||
== Extending the Smarty class ==
|
||||
Smarty 3 makes use of the __construct method for initialization. If you are extending
|
||||
the Smarty class, its constructor is not called implicitly if the your child class defines
|
||||
its own constructor. In order to run Smarty's constructor, a call to parent::__construct()
|
||||
within your child constructor is required.
|
||||
|
||||
<source lang="php">
|
||||
class MySmarty extends Smarty {
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
// your initialization code goes here
|
||||
|
||||
}
|
||||
}
|
||||
</source>
|
||||
|
||||
== Autoloader ==
|
||||
Smarty 3 does register its own autoloader with spl_autoload_register. If your code has
|
||||
an existing __autoload function then this function must be explicitly registered on
|
||||
the __autoload stack. See http://us3.php.net/manual/en/function.spl-autoload-register.php
|
||||
for further details.
|
||||
|
||||
== Plugin Filenames ==
|
||||
Smarty 3 optionally supports the PHP spl_autoloader. The autoloader requires filenames
|
||||
to be lower case. Because of this, Smarty plugin file names must also be lowercase.
|
||||
In Smarty 2, mixed case file names did work.
|
||||
|
||||
== Scope of Special Smarty Variables ==
|
||||
In Smarty 2 the special Smarty variables $smarty.section... and $smarty.foreach...
|
||||
had global scope. If you had loops with the same name in subtemplates you could accidentally
|
||||
overwrite values of parent template.
|
||||
|
||||
In Smarty 3 these special Smarty variable have only local scope in the template which
|
||||
is defining the loop. If you need their value in a subtemplate you have to pass them
|
||||
as parameter.
|
||||
<source lang="smarty">
|
||||
{include file='path/foo.tpl' index=$smarty.section.foo.index}
|
||||
</source>
|
||||
|
||||
== SMARTY_RESOURCE_CHAR_SET ==
|
||||
Smarty 3 sets the constant SMARTY_RESOURCE_CHAR_SET to utf-8 as default template charset.
|
||||
This is now used also on modifiers like escape as default charset. If your templates use
|
||||
other charsets make sure that you define the constant accordingly. Otherwise you may not
|
||||
get any output.
|
||||
|
||||
== newline at {if} tags ==
|
||||
A \n was added to the compiled code of the {if},{else},{elseif},{/if} tags to get output of newlines as expected by the template source.
|
||||
If one of the {if} tags is at the line end you will now get a newline in the HTML output.
|
||||
|
||||
== trigger_error() ==
|
||||
The API function trigger_error() has been removed because it did just map to PHP trigger_error.
|
||||
However it's still included in the Smarty2 API wrapper.
|
||||
|
||||
== Smarty constants ==
|
||||
The constants
|
||||
SMARTY_PHP_PASSTHRU
|
||||
SMARTY_PHP_QUOTE
|
||||
SMARTY_PHP_REMOVE
|
||||
SMARTY_PHP_ALLOW
|
||||
have been replaced with class constants
|
||||
Smarty::PHP_PASSTHRU
|
||||
Smarty::PHP_QUOTE
|
||||
Smarty::PHP_REMOVE
|
||||
Smarty::PHP_ALLOW
|
||||
|
@ -1,24 +0,0 @@
|
||||
== Smarty2 backward compatibility ==
|
||||
All Smarty2 specific API functions and deprecated functionallity has been moved
|
||||
to the SmartyBC class.
|
||||
|
||||
== {php} Tag ==
|
||||
The {php} tag is no longer available in the standard Smarty calls.
|
||||
The use of {php} tags is deprecated and only available in the SmartyBC class.
|
||||
|
||||
== {include_php} Tag ==
|
||||
The {include_php} tag is no longer available in the standard Smarty calls.
|
||||
The use of {include_php} tags is deprecated and only available in the SmartyBC class.
|
||||
|
||||
== php template resource ==
|
||||
The support of the php template resource is removed.
|
||||
|
||||
== $cache_dir, $compile_dir, $config_dir, $template_dir access ==
|
||||
The mentioned properties can't be accessed directly any longer. You must use
|
||||
corresponding getter/setters like addConfigDir(), setConfigDir(), getConfigDir()
|
||||
|
||||
== obsolete Smarty class properties ==
|
||||
The following no longer used properties are removed:
|
||||
$allow_php_tag
|
||||
$allow_php_template
|
||||
$deprecation_notices
|
@ -1,306 +0,0 @@
|
||||
Smarty 3.1 Notes
|
||||
================
|
||||
|
||||
Smarty 3.1 is a departure from 2.0 compatibility. Most notably, all
|
||||
backward compatibility has been moved to a separate class file named
|
||||
SmartyBC.class.php. If you require compatibility with 2.0, you will
|
||||
need to use this class.
|
||||
|
||||
Some differences from 3.0 are also present. 3.1 begins the journey of
|
||||
requiring setters/getters for property access. So far this is only
|
||||
implemented on the five directory properties: template_dir,
|
||||
plugins_dir, configs_dir, compile_dir and cache_dir. These properties
|
||||
are now protected, it is required to use the setters/getters instead.
|
||||
That said, direct property access will still work, however slightly
|
||||
slower since they will now fall through __set() and __get() and in
|
||||
turn passed through the setter/getter methods. 3.2 will exhibit a full
|
||||
list of setter/getter methods for all (currently) public properties,
|
||||
so code-completion in your IDE will work as expected.
|
||||
|
||||
There is absolutely no PHP allowed in templates any more. All
|
||||
deprecated features of Smarty 2.0 are gone. Again, use the SmartyBC
|
||||
class if you need any backward compatibility.
|
||||
|
||||
Internal Changes
|
||||
|
||||
Full UTF-8 Compatibility
|
||||
|
||||
The plugins shipped with Smarty 3.1 have been rewritten to fully
|
||||
support UTF-8 strings if Multibyte String is available. Without
|
||||
MBString UTF-8 cannot be handled properly. For those rare cases where
|
||||
templates themselves have to juggle encodings, the new modifiers
|
||||
to_charset and from_charset may come in handy.
|
||||
|
||||
Plugin API and Performance
|
||||
|
||||
All Plugins (modifiers, functions, blocks, resources,
|
||||
default_template_handlers, etc) are now receiving the
|
||||
Smarty_Internal_Template instance, where they were supplied with the
|
||||
Smarty instance in Smarty 3.0. *. As The Smarty_Internal_Template
|
||||
mimics the behavior of Smarty, this API simplification should not
|
||||
require any changes to custom plugins.
|
||||
|
||||
The plugins shipped with Smarty 3.1 have been rewritten for better
|
||||
performance. Most notably {html_select_date} and {html_select_time}
|
||||
have been improved vastly. Performance aside, plugins have also been
|
||||
reviewed and generalized in their API. {html_select_date} and
|
||||
{html_select_time} now share almost all available options.
|
||||
|
||||
The escape modifier now knows the $double_encode option, which will
|
||||
prevent entities from being encoded again.
|
||||
|
||||
The capitalize modifier now know the $lc_rest option, which makes sure
|
||||
all letters following a captial letter are lower-cased.
|
||||
|
||||
The count_sentences modifier now accepts (.?!) as
|
||||
legitimate endings of a sentence - previously only (.) was
|
||||
accepted
|
||||
|
||||
The new unescape modifier is there to reverse the effects of the
|
||||
escape modifier. This applies to the escape formats html, htmlall and
|
||||
entity.
|
||||
|
||||
default_template_handler_func
|
||||
|
||||
The invocation of $smarty->$default_template_handler_func had to be
|
||||
altered. Instead of a Smarty_Internal_Template, the fifth argument is
|
||||
now provided with the Smarty instance. New footprint:
|
||||
|
||||
|
||||
/**
|
||||
* Default Template Handler
|
||||
*
|
||||
* called when Smarty's file: resource is unable to load a requested file
|
||||
*
|
||||
* @param string $type resource type (e.g. "file", "string", "eval", "resource")
|
||||
* @param string $name resource name (e.g. "foo/bar.tpl")
|
||||
* @param string &$content template's content
|
||||
* @param integer &$modified template's modification time
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @return string|boolean path to file or boolean true if $content and $modified
|
||||
* have been filled, boolean false if no default template
|
||||
* could be loaded
|
||||
*/
|
||||
function default_template_handler_func($type, $name, &$content, &$modified, Smarty $smarty) {
|
||||
if (false) {
|
||||
// return corrected filepath
|
||||
return "/tmp/some/foobar.tpl";
|
||||
} elseif (false) {
|
||||
// return a template directly
|
||||
$content = "the template source";
|
||||
$modified = time();
|
||||
return true;
|
||||
} else {
|
||||
// tell smarty that we failed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Stuff done to the compiler
|
||||
|
||||
Many performance improvements have happened internally. One notable
|
||||
improvement is that all compiled templates are now handled as PHP
|
||||
functions. This speeds up repeated templates tremendously, as each one
|
||||
calls an (in-memory) PHP function instead of performing another file
|
||||
include/scan.
|
||||
|
||||
New Features
|
||||
|
||||
Template syntax
|
||||
|
||||
{block}..{/block}
|
||||
|
||||
The {block} tag has a new hide option flag. It does suppress the block
|
||||
content if no corresponding child block exists.
|
||||
EXAMPLE:
|
||||
parent.tpl
|
||||
{block name=body hide} child content "{$smarty.block.child}" was
|
||||
inserted {block}
|
||||
In the above example the whole block will be suppressed if no child
|
||||
block "body" is existing.
|
||||
|
||||
{setfilter}..{/setfilter}
|
||||
|
||||
The new {setfilter} block tag allows the definition of filters which
|
||||
run on variable output.
|
||||
SYNTAX:
|
||||
{setfilter filter1|filter2|filter3....}
|
||||
Smarty3 will lookup up matching filters in the following search order:
|
||||
1. varibale filter plugin in plugins_dir.
|
||||
2. a valid modifier. A modifier specification will also accept
|
||||
additional parameter like filter2:'foo'
|
||||
3. a PHP function
|
||||
{/setfilter} will turn previous filter setting off again.
|
||||
{setfilter} tags can be nested.
|
||||
EXAMPLE:
|
||||
{setfilter filter1}
|
||||
{$foo}
|
||||
{setfilter filter2}
|
||||
{$bar}
|
||||
{/setfilter}
|
||||
{$buh}
|
||||
{/setfilter}
|
||||
{$blar}
|
||||
In the above example filter1 will run on the output of $foo, filter2
|
||||
on $bar, filter1 again on $buh and no filter on $blar.
|
||||
NOTES:
|
||||
- {$foo nofilter} will suppress the filters
|
||||
- These filters will run in addition to filters defined by
|
||||
registerFilter('variable',...), autoLoadFilter('variable',...) and
|
||||
defined default modifier.
|
||||
- {setfilter} will effect only the current template, not included
|
||||
subtemplates.
|
||||
|
||||
Resource API
|
||||
|
||||
Smarty 3.1 features a new approach to resource management. The
|
||||
Smarty_Resource API allows simple, yet powerful integration of custom
|
||||
resources for templates and configuration files. It offers simple
|
||||
functions for loading data from a custom resource (e.g. database) as
|
||||
well as define new template types adhering to the special
|
||||
non-compiling (e,g, plain php) and non-compile-caching (e.g. eval:
|
||||
resource type) resources.
|
||||
|
||||
See demo/plugins/resource.mysql.php for an example custom database
|
||||
resource.
|
||||
|
||||
Note that old-fashioned registration of callbacks for resource
|
||||
management has been deprecated but is still possible with SmartyBC.
|
||||
|
||||
CacheResource API
|
||||
|
||||
In line with the Resource API, the CacheResource API offers a more
|
||||
comfortable handling of output-cache data. With the
|
||||
Smarty_CacheResource_Custom accessing databases is made simple. With
|
||||
the introduction of Smarty_CacheResource_KeyValueStore the
|
||||
implementation of resources like memcache or APC became a no-brainer;
|
||||
simple hash-based storage systems are now supporting hierarchical
|
||||
output-caches.
|
||||
|
||||
See demo/plugins/cacheresource.mysql.php for an example custom
|
||||
database CacheResource.
|
||||
See demo/plugins/cacheresource.memcache.php for an example custom
|
||||
memcache CacheResource using the KeyValueStore helper.
|
||||
|
||||
Note that old-fashioned registration of $cache_handler is not possible
|
||||
anymore. As the functionality had not been ported to Smarty 3.0.x
|
||||
properly, it has been dropped from 3.1 completely.
|
||||
|
||||
Locking facilities have been implemented to avoid concurrent cache
|
||||
generation. Enable cache locking by setting
|
||||
$smarty->cache_locking = true;
|
||||
|
||||
Relative Paths in Templates (File-Resource)
|
||||
|
||||
As of Smarty 3.1 {include file="../foo.tpl"} and {include
|
||||
file="./foo.tpl"} will resolve relative to the template they're in.
|
||||
Relative paths are available with {include file="..."} and
|
||||
{extends file="..."}. As $smarty->fetch('../foo.tpl') and
|
||||
$smarty->fetch('./foo.tpl') cannot be relative to a template, an
|
||||
exception is thrown.
|
||||
|
||||
Addressing a specific $template_dir
|
||||
|
||||
Smarty 3.1 introduces the $template_dir index notation.
|
||||
$smarty->fetch('[foo]bar.tpl') and {include file="[foo]bar.tpl"}
|
||||
require the template bar.tpl to be loaded from $template_dir['foo'];
|
||||
Smarty::setTemplateDir() and Smarty::addTemplateDir() offer ways to
|
||||
define indexes along with the actual directories.
|
||||
|
||||
Mixing Resources in extends-Resource
|
||||
|
||||
Taking the php extends: template resource one step further, it is now
|
||||
possible to mix resources within an extends: call like
|
||||
$smarty->fetch("extends:file:foo.tpl|db:bar.tpl");
|
||||
|
||||
To make eval: and string: resources available to the inheritance
|
||||
chain, eval:base64:TPL_STRING and eval:urlencode:TPL_STRING have been
|
||||
introduced. Supplying the base64 or urlencode flags will trigger
|
||||
decoding the TPL_STRING in with either base64_decode() or urldecode().
|
||||
|
||||
extends-Resource in template inheritance
|
||||
|
||||
Template based inheritance may now inherit from php's extends:
|
||||
resource like {extends file="extends:foo.tpl|db:bar.tpl"}.
|
||||
|
||||
New Smarty property escape_html
|
||||
|
||||
$smarty->escape_html = true will autoescape all template variable
|
||||
output by calling htmlspecialchars({$output}, ENT_QUOTES,
|
||||
SMARTY_RESOURCE_CHAR_SET).
|
||||
NOTE:
|
||||
This is a compile time option. If you change the setting you must make
|
||||
sure that the templates get recompiled.
|
||||
|
||||
New option at Smarty property compile_check
|
||||
|
||||
The automatic recompilation of modified templates can now be
|
||||
controlled by the following settings:
|
||||
$smarty->compile_check = COMPILECHECK_OFF (false) - template files
|
||||
will not be checked
|
||||
$smarty->compile_check = COMPILECHECK_ON (true) - template files will
|
||||
always be checked
|
||||
$smarty->compile_check = COMPILECHECK_CACHEMISS - template files will
|
||||
be checked if caching is enabled and there is no existing cache file
|
||||
or it has expired
|
||||
|
||||
Automatic recompilation on Smarty version change
|
||||
|
||||
Templates will now be automatically recompiled on Smarty version
|
||||
changes to avoide incompatibillities in the compiled code. Compiled
|
||||
template checked against the current setting of the SMARTY_VERSION
|
||||
constant.
|
||||
|
||||
default_config_handler_func()
|
||||
|
||||
Analogous to the default_template_handler_func()
|
||||
default_config_handler_func() has been introduced.
|
||||
|
||||
default_plugin_handler_func()
|
||||
|
||||
An optional default_plugin_handler_func() can be defined which gets called
|
||||
by the compiler on tags which can't be resolved internally or by plugins.
|
||||
The default_plugin_handler() can map tags to plugins on the fly.
|
||||
|
||||
New getters/setters
|
||||
|
||||
The following setters/getters will be part of the official
|
||||
documentation, and will be strongly recommended. Direct property
|
||||
access will still work for the foreseeable future... it will be
|
||||
transparently routed through the setters/getters, and consequently a
|
||||
bit slower.
|
||||
|
||||
array|string getTemplateDir( [string $index] )
|
||||
replaces $smarty->template_dir; and $smarty->template_dir[$index];
|
||||
Smarty setTemplateDir( array|string $path )
|
||||
replaces $smarty->template_dir = "foo"; and $smarty->template_dir =
|
||||
array("foo", "bar");
|
||||
Smarty addTemplateDir( array|string $path, [string $index])
|
||||
replaces $smarty->template_dir[] = "bar"; and
|
||||
$smarty->template_dir[$index] = "bar";
|
||||
|
||||
array|string getConfigDir( [string $index] )
|
||||
replaces $smarty->config_dir; and $smarty->config_dir[$index];
|
||||
Smarty setConfigDir( array|string $path )
|
||||
replaces $smarty->config_dir = "foo"; and $smarty->config_dir =
|
||||
array("foo", "bar");
|
||||
Smarty addConfigDir( array|string $path, [string $index])
|
||||
replaces $smarty->config_dir[] = "bar"; and
|
||||
$smarty->config_dir[$index] = "bar";
|
||||
|
||||
array getPluginsDir()
|
||||
replaces $smarty->plugins_dir;
|
||||
Smarty setPluginsDir( array|string $path )
|
||||
replaces $smarty->plugins_dir = "foo";
|
||||
Smarty addPluginsDir( array|string $path )
|
||||
replaces $smarty->plugins_dir[] = "bar";
|
||||
|
||||
string getCompileDir()
|
||||
replaces $smarty->compile_dir;
|
||||
Smarty setCompileDir( string $path )
|
||||
replaces $smarty->compile_dir = "foo";
|
||||
|
||||
string getCacheDir()
|
||||
replaces $smarty->cache_dir;
|
||||
Smarty setCacheDir( string $path )
|
||||
replaces $smarty->cache_dir;
|
@ -1,8 +1,407 @@
|
||||
===== 3.1.22-dev ===== (xx.xx.2014)
|
||||
===== 3.1.28-dev===== (xx.xx.2015)
|
||||
05.12.2015
|
||||
-bugfix {strip} should insert a single space https://github.com/smarty-php/smarty/issues/111
|
||||
|
||||
25.11.2015
|
||||
-bugfix a left delimter like '[%' did fail on [%$var_[%$variable%]%] (forum topic 25798)
|
||||
|
||||
02.11.2015
|
||||
- bugfix {include} with variable file name like {include file="foo_`$bar`.tpl"} did fail in 3.1.28-dev https://github.com/smarty-php/smarty/issues/102
|
||||
|
||||
01.11.2015
|
||||
- update config file processing
|
||||
|
||||
31.10.2015
|
||||
- bugfix add missing $trusted_dir property to SmartyBC class (forum topic 25751)
|
||||
|
||||
29.10.2015
|
||||
- improve template scope handling
|
||||
|
||||
24.10.2015
|
||||
- more optimizations of template processing
|
||||
- bugfix Error when using {include} within {capture} https://github.com/smarty-php/smarty/issues/100
|
||||
|
||||
21.10.2015
|
||||
- move some code into runtime extensions
|
||||
|
||||
18.10.2015
|
||||
- optimize filepath normalization
|
||||
- rework of template inheritance
|
||||
- speed and size optimizations
|
||||
- bugfix under HHVM temporary cache file must only be created when caches template was updated
|
||||
- fix compiled code for new {block} assign attribute
|
||||
- update code generated by template function call handler
|
||||
|
||||
18.09.2015
|
||||
- bugfix {if $foo instanceof $bar} failed to compile if 2nd value is a variable https://github.com/smarty-php/smarty/issues/92
|
||||
|
||||
17.09.2015
|
||||
- bugfix {foreach} first attribute was not correctly reset since commit 05a8fa2 of 02.08.2015 https://github.com/smarty-php/smarty/issues/90
|
||||
|
||||
16.09.2015
|
||||
- update compiler by moving no longer needed properties, code optimizations and other
|
||||
|
||||
14.09.2015
|
||||
- optimize autoloader
|
||||
- optimize subtemplate handling
|
||||
- update template inheritance processing
|
||||
- move code of {call} processing back into Smarty_Internal_Template class
|
||||
- improvement invalidate OPCACHE for cleared compiled and cached template files (forum topic 25557)
|
||||
- bugfix unintended multiple debug windows (forum topic 25699)
|
||||
|
||||
30.08.2015
|
||||
- size optimization move some runtime functions into extension
|
||||
- optimize inline template processing
|
||||
- optimization merge inheritance child and parent templates into one compiled template file
|
||||
|
||||
29.08.2015
|
||||
- improvement convert template inheritance into runtime processing
|
||||
- bugfix {$smarty.block.parent} did always reference the root parent block https://github.com/smarty-php/smarty/issues/68
|
||||
|
||||
23.08.2015
|
||||
- introduce Smarty::$resource_cache_mode and cache template object of {include} inside loop
|
||||
- load seldom used Smarty API methods dynamically to reduce memory footprint
|
||||
- cache template object of {include} if same template is included several times
|
||||
- convert debug console processing to object
|
||||
- use output buffers for better performance and less memory usage
|
||||
- optimize nocache hash processing
|
||||
- remove not really needed properties
|
||||
- optimize rendering
|
||||
- move caching to Smarty::_cache
|
||||
- remove properties with redundant content
|
||||
- optimize Smarty::templateExists()
|
||||
- optimize use_include_path processing
|
||||
- relocate properties for size optimization
|
||||
- remove redundant code
|
||||
- bugfix compiling super globals like {$smarty.get.foo} did fail in the master branch https://github.com/smarty-php/smarty/issues/77
|
||||
|
||||
06.08.2015
|
||||
- avoid possible circular object references caused by parser/lexer objects
|
||||
- rewrite compileAll... utility methods
|
||||
- commit several internal improvements
|
||||
- bugfix Smarty failed when compile_id did contain "|"
|
||||
|
||||
03.08.2015
|
||||
- rework clear cache methods
|
||||
- bugfix compileAllConfig() was broken since 3.1.22 because of the changes in config file processing
|
||||
- improve getIncludePath() to return directory if no file was given
|
||||
|
||||
02.08.2015
|
||||
- optimization and code cleanup of {foreach} and {section} compiler
|
||||
- rework {capture} compiler
|
||||
|
||||
01.08.2015
|
||||
- update DateTime object can be instance of DateTimeImmutable since PHP5.5 https://github.com/smarty-php/smarty/pull/75
|
||||
- improvement show resource type and start of template source instead of uid on eval: and string: resource (forum topic 25630)
|
||||
|
||||
31.07.2015
|
||||
- optimize {foreach} and {section} compiler
|
||||
|
||||
29.07.2015
|
||||
- optimize {section} compiler for speed and size of compiled code
|
||||
|
||||
28.07.2015
|
||||
- update for PHP 7 compatibility
|
||||
|
||||
26.07.2015
|
||||
- improvement impement workaround for HHVM PHP incompatibillity https://github.com/facebook/hhvm/issues/4797
|
||||
|
||||
25.07.2015
|
||||
- bugfix parser did hang on text starting <?something https://github.com/smarty-php/smarty/issues/74
|
||||
|
||||
20.07.2015
|
||||
- bugfix config files got recompiled on each request
|
||||
- improvement invalidate PHP 5.5 opcache for recompiled and cached templates https://github.com/smarty-php/smarty/issues/72
|
||||
|
||||
12.07.2015
|
||||
- optimize {extends} compilation
|
||||
|
||||
10.07.2015
|
||||
- bugfix force file: resource in demo resource.extendsall.php
|
||||
|
||||
08.07.2015
|
||||
- bugfix convert each word of class names to ucfirst in in compiler. (forum topic 25588)
|
||||
|
||||
07.07.2015
|
||||
- improvement allow fetch() or display() called on a template object to get output from other template
|
||||
like $template->fetch('foo.tpl') https://github.com/smarty-php/smarty/issues/70
|
||||
- improvement Added $limit parameter to regex_replace modifier #71
|
||||
- new feature multiple indices on file: resource
|
||||
|
||||
06.07.2015
|
||||
- optimize {block} compilation
|
||||
- optimization get rid of __get and __set in source object
|
||||
|
||||
01.07.2015
|
||||
- optimize compile check handling
|
||||
- update {foreach} compiler
|
||||
- bugfix debugging console did not display string values containing \n, \r or \t correctly https://github.com/smarty-php/smarty/issues/66
|
||||
- optimize source resources
|
||||
|
||||
28.06.2015
|
||||
- move $smarty->enableSecurity() into Smarty_Security class
|
||||
- optimize security isTrustedResourceDir()
|
||||
- move auto load filter methods into extension
|
||||
- move $smarty->getTemplateVars() into extension
|
||||
- move getStreamVariable() into extension
|
||||
- move $smarty->append() and $smarty->appendByRef() into extension
|
||||
- optimize autoloader
|
||||
- optimize file path normalization
|
||||
- bugfix PATH_SEPARATOR was replaced by mistake in autoloader
|
||||
- remove redundant code
|
||||
|
||||
27.06.2015
|
||||
- bugfix resolve naming conflict between custom Smarty delimiter '<%' and PHP ASP tags https://github.com/smarty-php/smarty/issues/64
|
||||
- update $smarty->_realpath for relative path not starting with './'
|
||||
- update Smarty security with new realpath handling
|
||||
- update {include_php} with new realpath handling
|
||||
- move $smarty->loadPlugin() into extension
|
||||
- minor compiler optimizations
|
||||
- bugfix allow function plugins with name ending with 'close' https://github.com/smarty-php/smarty/issues/52
|
||||
- rework of $smarty->clearCompiledTemplate() and move it to its own extension
|
||||
|
||||
19.06.2015
|
||||
- improvement allow closures as callback at $smarty->registerFilter() https://github.com/smarty-php/smarty/issues/59
|
||||
|
||||
===== 3.1.27===== (18.06.2015)
|
||||
18.06.2015
|
||||
- bugfix another update on file path normalization failed on path containing something like "/.foo/" https://github.com/smarty-php/smarty/issues/56
|
||||
|
||||
===== 3.1.26===== (18.06.2015)
|
||||
18.06.2015
|
||||
- bugfix file path normalization failed on path containing something like "/.foo/" https://github.com/smarty-php/smarty/issues/56
|
||||
|
||||
17.06.2015
|
||||
- bugfix calling a plugin with nocache option but no other attributes like {foo nocache} caused call to undefined function https://github.com/smarty-php/smarty/issues/55
|
||||
|
||||
===== 3.1.25===== (15.06.2015)
|
||||
15.06.2015
|
||||
- optimization of smarty_cachereource_keyvaluestore.php code
|
||||
|
||||
14.06.2015
|
||||
- bugfix a relative sub template path could fail if template_dir path did contain /../ https://github.com/smarty-php/smarty/issues/50
|
||||
- optimization rework of path normalization
|
||||
- bugfix an output tag with variable, modifier followed by an operator like {$foo|modifier+1} did fail https://github.com/smarty-php/smarty/issues/53
|
||||
|
||||
13.06.2015
|
||||
- bugfix a custom cache resource using smarty_cachereource_keyvaluestore.php did fail if php.ini mbstring.func_overload = 2 (forum topic 25568)
|
||||
|
||||
11.06.2015
|
||||
- bugfix the lexer could hang on very large quoted strings (forum topic 25570)
|
||||
|
||||
08.06.2015
|
||||
- bugfix using {$foo} as array index like $bar.{$foo} or in double quoted string like "some {$foo} thing" failed https://github.com/smarty-php/smarty/issues/49
|
||||
|
||||
04.06.2015
|
||||
- bugfix possible error message on unset() while compiling {block} tags https://github.com/smarty-php/smarty/issues/46
|
||||
|
||||
01.06.2015
|
||||
- bugfix <?xml ... ?> including template variables broken since 3.1.22 https://github.com/smarty-php/smarty/issues/47
|
||||
|
||||
27.05.2015
|
||||
- bugfix {include} with variable file name must not create by default individual cache file (since 3.1.22) https://github.com/smarty-php/smarty/issues/43
|
||||
|
||||
24.05.2015
|
||||
- bugfix if condition string 'neq' broken due to a typo https://github.com/smarty-php/smarty/issues/42
|
||||
|
||||
===== 3.1.24===== (23.05.2015)
|
||||
23.05.2015
|
||||
- improvement on php_handling to allow very large PHP sections, better error handling
|
||||
- improvement allow extreme large comment sections (forum 25538)
|
||||
|
||||
21.05.2015
|
||||
- bugfix broken PHP 5.2 compatibility when compiling <?php tags https://github.com/smarty-php/smarty/issues/40
|
||||
- bugfix named {foreach} comparison like $smarty.foreach.foobar.index > 1 did compile into wrong code https://github.com/smarty-php/smarty/issues/41
|
||||
|
||||
19.05.2015
|
||||
- bugfix compiler did overwrite existing variable value when setting the nocache attribute https://github.com/smarty-php/smarty/issues/39
|
||||
- bugfix output filter trimwhitespace could run into the pcre.backtrack_limit on large output (code.google issue 220)
|
||||
- bugfix compiler could run into the pcre.backtrack_limit on larger comment or {php} tag sections (forum 25538)
|
||||
|
||||
18.05.2015
|
||||
- improvement introduce shortcuts in lexer/parser rules for most frequent terms for higher
|
||||
compilation speed
|
||||
|
||||
16.05.2015
|
||||
- bugfix {php}{/php} did work just for single lines https://github.com/smarty-php/smarty/issues/33
|
||||
- improvement remove not needed ?><?php transitions from compiled code
|
||||
- improvement reduce number of lexer tokens on operators and if conditions
|
||||
- improvement higher compilation speed by modified lexer/parser generator at "smarty/smarty-lexer"
|
||||
|
||||
13.05.2015
|
||||
- improvement remove not needed ?><?php transitions from compiled code
|
||||
- improvement of debugging:
|
||||
- use fresh Smarty object to display the debug console because of possible problems when the Smarty
|
||||
was extended or Smarty properties had been modified in the class source
|
||||
- display Smarty version number
|
||||
- Truncate lenght of Origin display and extend strin value display to 80 character
|
||||
- bugfix in Smarty_Security 'nl2br' should be a trusted modifier, not PHP function (code.google issue 223)
|
||||
|
||||
12.05.2015
|
||||
- bugfix {$smarty.constant.TEST} did fail on undefined constant https://github.com/smarty-php/smarty/issues/28
|
||||
- bugfix access to undefined config variable like {#undef#} did fail https://github.com/smarty-php/smarty/issues/29
|
||||
- bugfix in nested {foreach} saved item attributes got overwritten https://github.com/smarty-php/smarty/issues/33
|
||||
|
||||
===== 3.1.23 ===== (12.05.2015)
|
||||
12.05.2015
|
||||
- bugfix of smaller performance issue introduce in 3.1.22 when caching is enabled
|
||||
- bugfix missig entry for smarty-temmplate-config in autoloader
|
||||
|
||||
===== 3.1.22 ===== tag was deleted because 3.1.22 did fail caused by the missing entry for smarty-temmplate-config in autoloader
|
||||
10.05.2015
|
||||
- bugfix custom cache resource did not observe compile_id and cache_id when $cache_locking == true
|
||||
- bugfix cache lock was not handled correctly after timeout when $cache_locking == true
|
||||
- improvement added constants for $debugging
|
||||
|
||||
07.05.2015
|
||||
- improvement of the debugging console. Read NEW_FEATURES.txt
|
||||
- optimization of resource class loading
|
||||
|
||||
06.05.2015
|
||||
- bugfix in 3.1.22-dev cache resource must not be loaded for subtemplates
|
||||
- bugfix/improvement in 3.1.22-dev cache locking did not work as expected
|
||||
|
||||
05.05.2015
|
||||
- optimization on cache update when main template is modified
|
||||
- optimization move <?php ?> handling from parser to new compiler module
|
||||
|
||||
05.05.2015
|
||||
- bugfix code could be messed up when {tags} are used in multiple attributes https://github.com/smarty-php/smarty/issues/23
|
||||
|
||||
04.05.2015
|
||||
- bugfix Smarty_Resource::parseResourceName incompatible with Google AppEngine (https://github.com/smarty-php/smarty/issues/22)
|
||||
- improvement use is_file() checks to avoid errors suppressed by @ which could still cause problems (https://github.com/smarty-php/smarty/issues/24)
|
||||
|
||||
28.04.2015
|
||||
- bugfix plugins of merged subtemplates not loaded in 3.1.22-dev (forum topic 25508) 2nd fix
|
||||
|
||||
28.04.2015
|
||||
- bugfix plugins of merged subtemplates not loaded in 3.1.22-dev (forum topic 25508)
|
||||
|
||||
23.04.2015
|
||||
- bugfix a nocache template variable used as parameter at {insert} was by mistake cached
|
||||
|
||||
20.04.2015
|
||||
- bugfix at a template function containing nocache code a parmeter could overwrite a template variable of same name
|
||||
|
||||
27.03.2015
|
||||
- bugfix Smarty_Security->allow_constants=false; did also disable true, false and null (change of 16.03.2015)
|
||||
- improvement added a whitelist for trusted constants to security Smarty_Security::$trusted_constants (forum topic 25471)
|
||||
|
||||
20.03.2015
|
||||
- bugfix make sure that function properties get saved only in compiled files containing the fuction definition {forum topic 25452}
|
||||
- bugfix correct update of global variable values on exit of template functions. (reported under Smarty Developers)
|
||||
|
||||
16.03.2015
|
||||
- bugfix problems with {function}{/function} and {call} tags in different subtemplate cache files {forum topic 25452}
|
||||
- bugfix Smarty_Security->allow_constants=false; did not disallow direct usage of defined constants like {SMARTY_DIR} {forum topic 25457}
|
||||
- bugfix {block}{/block} tags did not work inside double quoted strings https://github.com/smarty-php/smarty/issues/18
|
||||
|
||||
|
||||
15.03.2015
|
||||
- bugfix $smarty->compile_check must be restored before rendering of a just updated cache file {forum 25452}
|
||||
|
||||
14.03.2015
|
||||
- bugfix {nocache} {/nocache} tags corrupted code when used within a nocache section caused by a nocache template variable.
|
||||
|
||||
- bugfix template functions defined with {function} in an included subtemplate could not be called in nocache
|
||||
mode with {call... nocache} if the subtemplate had it's own cache file {forum 25452}
|
||||
|
||||
10.03.2015
|
||||
- bugfix {include ... nocache} whith variable file or compile_id attribute was not executed in nocache mode.
|
||||
|
||||
12.02.2015
|
||||
- bugfix multiple Smarty::fetch() of same template when $smarty->merge_compiled_includes = true; could cause function already defined error
|
||||
|
||||
11.02.2015
|
||||
- bugfix recursive {includes} did create E_NOTICE message when $smarty->merge_compiled_includes = true; (github issue #16)
|
||||
|
||||
22.01.2015
|
||||
- new feature security can now control access to static methods and properties
|
||||
see also NEW_FEATURES.txt
|
||||
|
||||
21.01.2015
|
||||
- bugfix clearCompiledTemplates(), clearAll() and clear() could try to delete whole drive at wrong path permissions because realpath() fail (forum 25397)
|
||||
- bugfix 'self::' and 'parent::' was interpreted in template syntax as static class
|
||||
|
||||
04.01.2015
|
||||
- push last weeks changes to github
|
||||
|
||||
- different optimizations
|
||||
- improvement automatically create different versions of compiled templates and config files depending
|
||||
on property settings.
|
||||
- optimization restructure template processing by moving code into classes it better belongs to
|
||||
- optimization restructure config file processing
|
||||
|
||||
31.12.2014
|
||||
- bugfix use function_exists('mb_get_info') for setting Smarty::$_MBSTRING.
|
||||
Function mb_split could be overloaded depending on php.ini mbstring.func_overload
|
||||
|
||||
|
||||
29.12.2014
|
||||
- new feature security can now limit the template nesting level by property $max_template_nesting
|
||||
see also NEW_FEATURES.txt (forum 25370)
|
||||
|
||||
29.12.2014
|
||||
- new feature security can now disable special $smarty variables listed in property $disabled_special_smarty_vars
|
||||
see also NEW_FEATURES.txt (forum 25370)
|
||||
|
||||
27.12.2014
|
||||
- bugfix clear internal _is_file_cache when plugins_dir was modified
|
||||
|
||||
13.12.2014
|
||||
- improvement optimization of lexer and parser resulting in a up to 30% higher compiling speed
|
||||
|
||||
11.12.2014
|
||||
- bugfix resolve parser ambiguity between constant print tag {CONST} and other smarty tags after change of 09.12.2014
|
||||
|
||||
09.12.2014
|
||||
- bugfix variables $null, $true and $false did not work after the change of 12.11.2014 (forum 25342)
|
||||
- bugfix call of template function by a variable name did not work after latest changes (forum 25342)
|
||||
|
||||
23.11.2014
|
||||
- bugfix a plugin with attached modifier could fail if the tag was immediately followed by another Smarty tag (since 3.1.21) (forum 25326)
|
||||
|
||||
13.11.2014
|
||||
- improvement move autoload code into Autoloader.php. Use Composer autoloader when possible
|
||||
|
||||
12.11.2014
|
||||
- new feature added support of namespaces to template code
|
||||
|
||||
08.11.2014 - 10.11.2014
|
||||
- bugfix subtemplate called in nocache mode could be called with wrong compile_id when it did change on one of the calling templates
|
||||
- improvement add code of template functions called in nocache mode dynamically to cache file (related to bugfix of 01.11.2014)
|
||||
- bugfix Debug Console did not include all data from merged compiled subtemplates
|
||||
|
||||
04.11.2014
|
||||
- new feature $smarty->debugging = true; => overwrite existing Debug Console window (old behaviour)
|
||||
$smarty->debugging = 2; => individual Debug Console window by template name
|
||||
|
||||
03.11.2014
|
||||
- bugfix Debug Console did not show included subtemplates since 3.1.17 (forum 25301)
|
||||
- bugfix Modifier debug_print_var did not limit recursion or prevent recursive object display at Debug Console
|
||||
(ATTENTION: parameter order has changed to be able to specify maximum recursion)
|
||||
- bugfix Debug consol did not include subtemplate information with $smarty->merge_compiled_includes = true
|
||||
- improvement The template variables are no longer displayed as objects on the Debug Console
|
||||
- improvement $smarty->createData($parent = null, $name = null) new optional name parameter for display at Debug Console
|
||||
- addition of some hooks for future extension of Debug Console
|
||||
|
||||
01.11.2014
|
||||
- bugfix and enhancement on subtemplate {include} and template {function} tags.
|
||||
* Calling a template which has a nocache section could fail if it was called from a cached and a not cached subtemplate.
|
||||
* Calling the same subtemplate cached and not cached with the $smarty->merge_compiled_includes enabled could cause problems
|
||||
* Many smaller related changes
|
||||
|
||||
30.10.2014
|
||||
- bugfix access to class constant by object like {$object::CONST} or variable class name {$class::CONST} did not work (forum 25301)
|
||||
|
||||
26.10.2014
|
||||
- bugfix E_NOTICE message was created during compilation when ASP tags '<%' or '%>' are in template source text
|
||||
- bugfix merge_compiled_includes option failed when caching enables and same subtemplate was included cached and not cached
|
||||
|
||||
===== 3.1.21 ===== (18.10.2014)
|
||||
18.10.2014
|
||||
- composer moved to github
|
||||
- add COMPOSER_RELEASE_NOTES
|
||||
- composer moved to github
|
||||
|
||||
17.10.2014
|
||||
- bugfix on $php_handling security and optimization of smarty_internal_parsetree (Thue Kristensen)
|
||||
@ -43,7 +442,7 @@
|
||||
04.07.2014
|
||||
- bugfix the bufix of 02.06.2014 broke correct handling of child templates with same name but different template folders in extends resource (issue 194 and topic 25099)
|
||||
|
||||
===== 3.1.19 ===== (06.30.2014)
|
||||
===== 3.1.19 ===== (30.06.2014)
|
||||
20.06.2014
|
||||
- bugfix template variables could not be passed as parameter in {include} when the include was in a {nocache} section (topic 25131)
|
||||
|
||||
@ -732,7 +1131,7 @@
|
||||
|
||||
15/07/2011
|
||||
- bugfix individual cache_lifetime of {include} did not work correctly inside {block} tags
|
||||
- added caches for Smarty_Template_Source and Smarty_Template_Compiled to reduce I/O for multiple cache_id rendering
|
||||
- added caches for Smarty_Internal_TemplateSource and Smarty_Internal_TemplateCompiled to reduce I/O for multiple cache_id rendering
|
||||
|
||||
14/07/2011
|
||||
- made Smarty::loadPlugin() respect the include_path if required
|
||||
|
@ -1,5 +0,0 @@
|
||||
title = Welcome to Smarty!
|
||||
cutoff_size = 40
|
||||
|
||||
[setup]
|
||||
bold = true
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Example Application
|
||||
*
|
||||
* @package Example-application
|
||||
*/
|
||||
|
||||
require '../libs/Smarty.class.php';
|
||||
|
||||
$smarty = new Smarty;
|
||||
|
||||
//$smarty->force_compile = true;
|
||||
$smarty->debugging = true;
|
||||
$smarty->caching = true;
|
||||
$smarty->cache_lifetime = 120;
|
||||
|
||||
$smarty->assign("Name", "Fred Irving Johnathan Bradley Peppergill", true);
|
||||
$smarty->assign("FirstName", array("John", "Mary", "James", "Henry"));
|
||||
$smarty->assign("LastName", array("Doe", "Smith", "Johnson", "Case"));
|
||||
$smarty->assign("Class", array(array("A", "B", "C", "D"), array("E", "F", "G", "H"),
|
||||
array("I", "J", "K", "L"), array("M", "N", "O", "P")));
|
||||
|
||||
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
|
||||
array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
|
||||
|
||||
$smarty->assign("option_values", array("NY", "NE", "KS", "IA", "OK", "TX"));
|
||||
$smarty->assign("option_output", array("New York", "Nebraska", "Kansas", "Iowa", "Oklahoma", "Texas"));
|
||||
$smarty->assign("option_selected", "NE");
|
||||
|
||||
$smarty->display('index.tpl');
|
@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* APC CacheResource
|
||||
* CacheResource Implementation based on the KeyValueStore API to use
|
||||
* memcache as the storage resource for Smarty's output caching.
|
||||
* *
|
||||
*
|
||||
* @package CacheResource-examples
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
class Smarty_CacheResource_Apc extends Smarty_CacheResource_KeyValueStore
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// test if APC is present
|
||||
if (!function_exists('apc_cache_info')) {
|
||||
throw new Exception('APC Template Caching Error: APC is not installed');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read values for a set of keys from cache
|
||||
*
|
||||
* @param array $keys list of keys to fetch
|
||||
*
|
||||
* @return array list of values with the given keys used as indexes
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function read(array $keys)
|
||||
{
|
||||
$_res = array();
|
||||
$res = apc_fetch($keys);
|
||||
foreach ($res as $k => $v) {
|
||||
$_res[$k] = $v;
|
||||
}
|
||||
|
||||
return $_res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save values for a set of keys to cache
|
||||
*
|
||||
* @param array $keys list of values to save
|
||||
* @param int $expire expiration time
|
||||
*
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function write(array $keys, $expire = null)
|
||||
{
|
||||
foreach ($keys as $k => $v) {
|
||||
apc_store($k, $v, $expire);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove values from cache
|
||||
*
|
||||
* @param array $keys list of keys to delete
|
||||
*
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function delete(array $keys)
|
||||
{
|
||||
foreach ($keys as $k) {
|
||||
apc_delete($k);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove *all* values from cache
|
||||
*
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function purge()
|
||||
{
|
||||
return apc_clear_cache('user');
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Memcache CacheResource
|
||||
* CacheResource Implementation based on the KeyValueStore API to use
|
||||
* memcache as the storage resource for Smarty's output caching.
|
||||
* Note that memcache has a limitation of 256 characters per cache-key.
|
||||
* To avoid complications all cache-keys are translated to a sha1 hash.
|
||||
*
|
||||
* @package CacheResource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
|
||||
{
|
||||
/**
|
||||
* memcache instance
|
||||
*
|
||||
* @var Memcache
|
||||
*/
|
||||
protected $memcache = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->memcache = new Memcache();
|
||||
$this->memcache->addServer('127.0.0.1', 11211);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read values for a set of keys from cache
|
||||
*
|
||||
* @param array $keys list of keys to fetch
|
||||
*
|
||||
* @return array list of values with the given keys used as indexes
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function read(array $keys)
|
||||
{
|
||||
$_keys = $lookup = array();
|
||||
foreach ($keys as $k) {
|
||||
$_k = sha1($k);
|
||||
$_keys[] = $_k;
|
||||
$lookup[$_k] = $k;
|
||||
}
|
||||
$_res = array();
|
||||
$res = $this->memcache->get($_keys);
|
||||
foreach ($res as $k => $v) {
|
||||
$_res[$lookup[$k]] = $v;
|
||||
}
|
||||
|
||||
return $_res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save values for a set of keys to cache
|
||||
*
|
||||
* @param array $keys list of values to save
|
||||
* @param int $expire expiration time
|
||||
*
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function write(array $keys, $expire = null)
|
||||
{
|
||||
foreach ($keys as $k => $v) {
|
||||
$k = sha1($k);
|
||||
$this->memcache->set($k, $v, 0, $expire);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove values from cache
|
||||
*
|
||||
* @param array $keys list of keys to delete
|
||||
*
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function delete(array $keys)
|
||||
{
|
||||
foreach ($keys as $k) {
|
||||
$k = sha1($k);
|
||||
$this->memcache->delete($k);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove *all* values from cache
|
||||
*
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
protected function purge()
|
||||
{
|
||||
$this->memcache->flush();
|
||||
}
|
||||
}
|
@ -1,162 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* MySQL CacheResource
|
||||
* CacheResource Implementation based on the Custom API to use
|
||||
* MySQL as the storage resource for Smarty's output caching.
|
||||
* Table definition:
|
||||
* <pre>CREATE TABLE IF NOT EXISTS `output_cache` (
|
||||
* `id` CHAR(40) NOT NULL COMMENT 'sha1 hash',
|
||||
* `name` VARCHAR(250) NOT NULL,
|
||||
* `cache_id` VARCHAR(250) NULL DEFAULT NULL,
|
||||
* `compile_id` VARCHAR(250) NULL DEFAULT NULL,
|
||||
* `modified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
* `content` LONGTEXT NOT NULL,
|
||||
* PRIMARY KEY (`id`),
|
||||
* INDEX(`name`),
|
||||
* INDEX(`cache_id`),
|
||||
* INDEX(`compile_id`),
|
||||
* INDEX(`modified`)
|
||||
* ) ENGINE = InnoDB;</pre>
|
||||
*
|
||||
* @package CacheResource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_CacheResource_Mysql extends Smarty_CacheResource_Custom
|
||||
{
|
||||
// PDO instance
|
||||
protected $db;
|
||||
protected $fetch;
|
||||
protected $fetchTimestamp;
|
||||
protected $save;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
|
||||
}
|
||||
$this->fetch = $this->db->prepare('SELECT modified, content FROM output_cache WHERE id = :id');
|
||||
$this->fetchTimestamp = $this->db->prepare('SELECT modified FROM output_cache WHERE id = :id');
|
||||
$this->save = $this->db->prepare('REPLACE INTO output_cache (id, name, cache_id, compile_id, content)
|
||||
VALUES (:id, :name, :cache_id, :compile_id, :content)');
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch cached content and its modification time from data source
|
||||
*
|
||||
* @param string $id unique cache content identifier
|
||||
* @param string $name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param string $content cached content
|
||||
* @param integer $mtime cache modification timestamp (epoch)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function fetch($id, $name, $cache_id, $compile_id, &$content, &$mtime)
|
||||
{
|
||||
$this->fetch->execute(array('id' => $id));
|
||||
$row = $this->fetch->fetch();
|
||||
$this->fetch->closeCursor();
|
||||
if ($row) {
|
||||
$content = $row['content'];
|
||||
$mtime = strtotime($row['modified']);
|
||||
} else {
|
||||
$content = null;
|
||||
$mtime = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch cached content's modification timestamp from data source
|
||||
*
|
||||
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the complete cached content.
|
||||
*
|
||||
* @param string $id unique cache content identifier
|
||||
* @param string $name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
*
|
||||
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
|
||||
*/
|
||||
protected function fetchTimestamp($id, $name, $cache_id, $compile_id)
|
||||
{
|
||||
$this->fetchTimestamp->execute(array('id' => $id));
|
||||
$mtime = strtotime($this->fetchTimestamp->fetchColumn());
|
||||
$this->fetchTimestamp->closeCursor();
|
||||
|
||||
return $mtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save content to cache
|
||||
*
|
||||
* @param string $id unique cache content identifier
|
||||
* @param string $name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param integer|null $exp_time seconds till expiration time in seconds or null
|
||||
* @param string $content content to cache
|
||||
*
|
||||
* @return boolean success
|
||||
*/
|
||||
protected function save($id, $name, $cache_id, $compile_id, $exp_time, $content)
|
||||
{
|
||||
$this->save->execute(array(
|
||||
'id' => $id,
|
||||
'name' => $name,
|
||||
'cache_id' => $cache_id,
|
||||
'compile_id' => $compile_id,
|
||||
'content' => $content,
|
||||
));
|
||||
|
||||
return !!$this->save->rowCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete content from cache
|
||||
*
|
||||
* @param string $name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
* @param integer|null $exp_time seconds till expiration or null
|
||||
*
|
||||
* @return integer number of deleted caches
|
||||
*/
|
||||
protected function delete($name, $cache_id, $compile_id, $exp_time)
|
||||
{
|
||||
// delete the whole cache
|
||||
if ($name === null && $cache_id === null && $compile_id === null && $exp_time === null) {
|
||||
// returning the number of deleted caches would require a second query to count them
|
||||
$query = $this->db->query('TRUNCATE TABLE output_cache');
|
||||
|
||||
return - 1;
|
||||
}
|
||||
// build the filter
|
||||
$where = array();
|
||||
// equal test name
|
||||
if ($name !== null) {
|
||||
$where[] = 'name = ' . $this->db->quote($name);
|
||||
}
|
||||
// equal test compile_id
|
||||
if ($compile_id !== null) {
|
||||
$where[] = 'compile_id = ' . $this->db->quote($compile_id);
|
||||
}
|
||||
// range test expiration time
|
||||
if ($exp_time !== null) {
|
||||
$where[] = 'modified < DATE_SUB(NOW(), INTERVAL ' . intval($exp_time) . ' SECOND)';
|
||||
}
|
||||
// equal test cache_id and match sub-groups
|
||||
if ($cache_id !== null) {
|
||||
$where[] = '(cache_id = ' . $this->db->quote($cache_id)
|
||||
. ' OR cache_id LIKE ' . $this->db->quote($cache_id . '|%') . ')';
|
||||
}
|
||||
// run delete query
|
||||
$query = $this->db->query('DELETE FROM output_cache WHERE ' . join(' AND ', $where));
|
||||
|
||||
return $query->rowCount();
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Extends All Resource
|
||||
* Resource Implementation modifying the extends-Resource to walk
|
||||
* through the template_dirs and inherit all templates of the same name
|
||||
*
|
||||
* @package Resource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
|
||||
{
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$uid = '';
|
||||
$sources = array();
|
||||
$exists = true;
|
||||
foreach ($_template->smarty->getTemplateDir() as $key => $directory) {
|
||||
try {
|
||||
$s = Smarty_Resource::source(null, $source->smarty, '[' . $key . ']' . $source->name);
|
||||
if (!$s->exists) {
|
||||
continue;
|
||||
}
|
||||
$sources[$s->uid] = $s;
|
||||
$uid .= $s->filepath;
|
||||
}
|
||||
catch (SmartyException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!$sources) {
|
||||
$source->exists = false;
|
||||
$source->template = $_template;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$sources = array_reverse($sources, true);
|
||||
reset($sources);
|
||||
$s = current($sources);
|
||||
|
||||
$source->components = $sources;
|
||||
$source->filepath = $s->filepath;
|
||||
$source->uid = sha1($uid);
|
||||
$source->exists = $exists;
|
||||
if ($_template && $_template->smarty->compile_check) {
|
||||
$source->timestamp = $s->timestamp;
|
||||
}
|
||||
// need the template at getContent()
|
||||
$source->template = $_template;
|
||||
}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* MySQL Resource
|
||||
* Resource Implementation based on the Custom API to use
|
||||
* MySQL as the storage resource for Smarty's templates and configs.
|
||||
* Table definition:
|
||||
* <pre>CREATE TABLE IF NOT EXISTS `templates` (
|
||||
* `name` varchar(100) NOT NULL,
|
||||
* `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
* `source` text,
|
||||
* PRIMARY KEY (`name`)
|
||||
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8;</pre>
|
||||
* Demo data:
|
||||
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');</pre>
|
||||
*
|
||||
* @package Resource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Resource_Mysql extends Smarty_Resource_Custom
|
||||
{
|
||||
// PDO instance
|
||||
protected $db;
|
||||
// prepared fetch() statement
|
||||
protected $fetch;
|
||||
// prepared fetchTimestamp() statement
|
||||
protected $mtime;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
|
||||
}
|
||||
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
|
||||
$this->mtime = $this->db->prepare('SELECT modified FROM templates WHERE name = :name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a template and its modification time from database
|
||||
*
|
||||
* @param string $name template name
|
||||
* @param string $source template source
|
||||
* @param integer $mtime template modification timestamp (epoch)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function fetch($name, &$source, &$mtime)
|
||||
{
|
||||
$this->fetch->execute(array('name' => $name));
|
||||
$row = $this->fetch->fetch();
|
||||
$this->fetch->closeCursor();
|
||||
if ($row) {
|
||||
$source = $row['source'];
|
||||
$mtime = strtotime($row['modified']);
|
||||
} else {
|
||||
$source = null;
|
||||
$mtime = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a template's modification time from database
|
||||
*
|
||||
* @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the comple template source.
|
||||
*
|
||||
* @param string $name template name
|
||||
*
|
||||
* @return integer timestamp (epoch) the template was modified
|
||||
*/
|
||||
protected function fetchTimestamp($name)
|
||||
{
|
||||
$this->mtime->execute(array('name' => $name));
|
||||
$mtime = $this->mtime->fetchColumn();
|
||||
$this->mtime->closeCursor();
|
||||
|
||||
return strtotime($mtime);
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* MySQL Resource
|
||||
* Resource Implementation based on the Custom API to use
|
||||
* MySQL as the storage resource for Smarty's templates and configs.
|
||||
* Note that this MySQL implementation fetches the source and timestamps in
|
||||
* a single database query, instead of two separate like resource.mysql.php does.
|
||||
* Table definition:
|
||||
* <pre>CREATE TABLE IF NOT EXISTS `templates` (
|
||||
* `name` varchar(100) NOT NULL,
|
||||
* `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
* `source` text,
|
||||
* PRIMARY KEY (`name`)
|
||||
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8;</pre>
|
||||
* Demo data:
|
||||
* <pre>INSERT INTO `templates` (`name`, `modified`, `source`) VALUES ('test.tpl', "2010-12-25 22:00:00", '{$x="hello world"}{$x}');</pre>
|
||||
*
|
||||
* @package Resource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
|
||||
{
|
||||
// PDO instance
|
||||
protected $db;
|
||||
// prepared fetch() statement
|
||||
protected $fetch;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
$this->db = new PDO("mysql:dbname=test;host=127.0.0.1", "smarty");
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
|
||||
}
|
||||
$this->fetch = $this->db->prepare('SELECT modified, source FROM templates WHERE name = :name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a template and its modification time from database
|
||||
*
|
||||
* @param string $name template name
|
||||
* @param string $source template source
|
||||
* @param integer $mtime template modification timestamp (epoch)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function fetch($name, &$source, &$mtime)
|
||||
{
|
||||
$this->fetch->execute(array('name' => $name));
|
||||
$row = $this->fetch->fetch();
|
||||
$this->fetch->closeCursor();
|
||||
if ($row) {
|
||||
$source = $row['source'];
|
||||
$mtime = strtotime($row['modified']);
|
||||
} else {
|
||||
$source = null;
|
||||
$mtime = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
</BODY>
|
||||
</HTML>
|
@ -1,5 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>{$title} - {$Name}</TITLE>
|
||||
</HEAD>
|
||||
<BODY bgcolor="#ffffff">
|
@ -1,87 +0,0 @@
|
||||
{config_load file="test.conf" section="setup"}
|
||||
{include file="header.tpl" title=foo}
|
||||
|
||||
<PRE>
|
||||
|
||||
{* bold and title are read from the config file *}
|
||||
{if #bold#}<b>{/if}
|
||||
{* capitalize the first letters of each word of the title *}
|
||||
Title: {#title#|capitalize}
|
||||
{if #bold#}</b>{/if}
|
||||
|
||||
The current date and time is {$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}
|
||||
|
||||
The value of global assigned variable $SCRIPT_NAME is {$SCRIPT_NAME}
|
||||
|
||||
Example of accessing server environment variable SERVER_NAME: {$smarty.server.SERVER_NAME}
|
||||
|
||||
The value of {ldelim}$Name{rdelim} is <b>{$Name}</b>
|
||||
|
||||
variable modifier example of {ldelim}$Name|upper{rdelim}
|
||||
|
||||
<b>{$Name|upper}</b>
|
||||
|
||||
|
||||
An example of a section loop:
|
||||
|
||||
{section name=outer
|
||||
loop=$FirstName}
|
||||
{if $smarty.section.outer.index is odd by 2}
|
||||
{$smarty.section.outer.rownum} . {$FirstName[outer]} {$LastName[outer]}
|
||||
{else}
|
||||
{$smarty.section.outer.rownum} * {$FirstName[outer]} {$LastName[outer]}
|
||||
{/if}
|
||||
{sectionelse}
|
||||
none
|
||||
{/section}
|
||||
|
||||
An example of section looped key values:
|
||||
|
||||
{section name=sec1 loop=$contacts}
|
||||
phone: {$contacts[sec1].phone}
|
||||
<br>
|
||||
|
||||
fax: {$contacts[sec1].fax}
|
||||
<br>
|
||||
|
||||
cell: {$contacts[sec1].cell}
|
||||
<br>
|
||||
{/section}
|
||||
<p>
|
||||
|
||||
testing strip tags
|
||||
{strip}
|
||||
<table border=0>
|
||||
<tr>
|
||||
<td>
|
||||
<A HREF="{$SCRIPT_NAME}">
|
||||
<font color="red">This is a test </font>
|
||||
</A>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{/strip}
|
||||
|
||||
</PRE>
|
||||
|
||||
This is an example of the html_select_date function:
|
||||
|
||||
<form>
|
||||
{html_select_date start_year=1998 end_year=2010}
|
||||
</form>
|
||||
|
||||
This is an example of the html_select_time function:
|
||||
|
||||
<form>
|
||||
{html_select_time use_24_hours=false}
|
||||
</form>
|
||||
|
||||
This is an example of the html_options function:
|
||||
|
||||
<form>
|
||||
<select name=states>
|
||||
{html_options values=$option_values selected=$option_selected output=$option_output}
|
||||
</select>
|
||||
</form>
|
||||
|
||||
{include file="footer.tpl"}
|
124
library/Smarty/libs/Autoloader.php
Normal file
124
library/Smarty/libs/Autoloader.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Autoloader
|
||||
*
|
||||
* @package Smarty
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Autoloader
|
||||
*
|
||||
* @package Smarty
|
||||
* @author Uwe Tews
|
||||
* Usage:
|
||||
* require_once '...path/Autoloader.php';
|
||||
* Smarty_Autoloader::register();
|
||||
* $smarty = new Smarty();
|
||||
* Note: This autoloader is not needed if you use Composer.
|
||||
* Composer will automatically add the classes of the Smarty package to it common autoloader.
|
||||
*/
|
||||
class Smarty_Autoloader
|
||||
{
|
||||
/**
|
||||
* Filepath to Smarty root
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $SMARTY_DIR = '';
|
||||
|
||||
/**
|
||||
* Filepath to Smarty internal plugins
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $SMARTY_SYSPLUGINS_DIR = '';
|
||||
|
||||
/**
|
||||
* Array with Smarty core classes and their filename
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',);
|
||||
|
||||
/**
|
||||
* Registers Smarty_Autoloader backward compatible to older installations.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not.
|
||||
*/
|
||||
public static function registerBC($prepend = false)
|
||||
{
|
||||
/**
|
||||
* register the class autoloader
|
||||
*/
|
||||
if (!defined('SMARTY_SPL_AUTOLOAD')) {
|
||||
define('SMARTY_SPL_AUTOLOAD', 0);
|
||||
}
|
||||
if (SMARTY_SPL_AUTOLOAD &&
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
|
||||
) {
|
||||
$registeredAutoLoadFunctions = spl_autoload_functions();
|
||||
if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
|
||||
spl_autoload_register();
|
||||
}
|
||||
} else {
|
||||
self::register($prepend);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers Smarty_Autoloader as an SPL autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not.
|
||||
*/
|
||||
public static function register($prepend = false)
|
||||
{
|
||||
self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR;
|
||||
self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR :
|
||||
self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR;
|
||||
if (version_compare(phpversion(), '5.3.0', '>=')) {
|
||||
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
||||
} else {
|
||||
spl_autoload_register(array(__CLASS__, 'autoload'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles auto loading of classes.
|
||||
*
|
||||
* @param string $class A class name.
|
||||
*/
|
||||
public static function autoload($class)
|
||||
{
|
||||
$_class = strtolower($class);
|
||||
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
|
||||
if (strpos($_class, 'smarty_internal_') === 0) {
|
||||
if (strpos($_class, 'smarty_internal_compile_') === 0) {
|
||||
if (is_file($file)) {
|
||||
require $file;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@include $file;
|
||||
return;
|
||||
}
|
||||
if (preg_match('/^(smarty_(((template_(source|config|cache|compiled|resource_base))|((cached|compiled)?resource)|(variable|security)))|(smarty(bc)?)$)/',
|
||||
$_class, $match)) {
|
||||
if (!empty($match[3])) {
|
||||
@include $file;
|
||||
return;
|
||||
} elseif (!empty($match[9]) && isset(self::$rootClasses[$_class])) {
|
||||
$file = self::$rootClasses[$_class];
|
||||
require $file;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (0 !== strpos($_class, 'smarty')) {
|
||||
return;
|
||||
}
|
||||
if (is_file($file)) {
|
||||
require $file;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -44,6 +44,13 @@ class SmartyBC extends Smarty
|
||||
*/
|
||||
public $_version = self::SMARTY_VERSION;
|
||||
|
||||
/**
|
||||
* This is an array of directories where trusted php scripts reside.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $trusted_dir = array();
|
||||
|
||||
/**
|
||||
* Initialize new SmartyBC object
|
||||
*
|
||||
@ -52,8 +59,6 @@ class SmartyBC extends Smarty
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
parent::__construct($options);
|
||||
// register {php} tag
|
||||
$this->registerPlugin('block', 'php', 'smarty_php_tag');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,10 +120,10 @@ class SmartyBC extends Smarty
|
||||
/**
|
||||
* Registers object to be used in templates
|
||||
*
|
||||
* @param string $object name of template object
|
||||
* @param object $object_impl the referenced PHP object to register
|
||||
* @param array $allowed list of allowed methods (empty = all)
|
||||
* @param boolean $smarty_args smarty argument format, else traditional
|
||||
* @param string $object name of template object
|
||||
* @param object $object_impl the referenced PHP object to register
|
||||
* @param array $allowed list of allowed methods (empty = all)
|
||||
* @param boolean $smarty_args smarty argument format, else traditional
|
||||
* @param array $block_methods list of methods that are block format
|
||||
*
|
||||
* @throws SmartyException
|
||||
@ -448,20 +453,3 @@ class SmartyBC extends Smarty
|
||||
trigger_error("Smarty error: $error_msg", $error_type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty {php}{/php} block function
|
||||
*
|
||||
* @param array $params parameter list
|
||||
* @param string $content contents of the block
|
||||
* @param object $template template object
|
||||
* @param boolean &$repeat repeat flag
|
||||
*
|
||||
* @return string content re-formatted
|
||||
*/
|
||||
function smarty_php_tag($params, $content, $template, &$repeat)
|
||||
{
|
||||
eval($content);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
<title>Smarty Debug Console</title>
|
||||
<style type="text/css">
|
||||
{literal}
|
||||
body, h1, h2, td, th, p {
|
||||
body, h1, h2, h3, td, th, p {
|
||||
font-family: sans-serif;
|
||||
font-weight: normal;
|
||||
font-size: 0.9em;
|
||||
@ -31,6 +31,13 @@
|
||||
padding: 2px;
|
||||
border-top: 1px solid black;
|
||||
}
|
||||
h3 {
|
||||
text-align: left;
|
||||
font-weight: bold;
|
||||
color: black;
|
||||
font-size: 0.7em;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
body {
|
||||
background: black;
|
||||
@ -54,7 +61,6 @@
|
||||
font-family: monospace;
|
||||
vertical-align: top;
|
||||
text-align: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
td {
|
||||
@ -74,8 +80,20 @@
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
#bold div {
|
||||
color: black;
|
||||
font-weight: bold;
|
||||
}
|
||||
#blue h3 {
|
||||
color: blue;
|
||||
}
|
||||
#normal div {
|
||||
color: black;
|
||||
font-weight: normal;
|
||||
}
|
||||
#table_assigned_vars th {
|
||||
color: blue;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#table_config_vars th {
|
||||
@ -87,18 +105,17 @@
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Smarty Debug Console
|
||||
- {if isset($template_name)}{$template_name|debug_print_var nofilter}{else}Total Time {$execution_time|string_format:"%.5f"}{/if}</h1>
|
||||
<h1>Smarty {Smarty::SMARTY_VERSION} Debug Console
|
||||
- {if isset($template_name)}{$template_name|debug_print_var nofilter} {/if}{if !empty($template_data)}Total Time {$execution_time|string_format:"%.5f"}{/if}</h1>
|
||||
|
||||
{if !empty($template_data)}
|
||||
<h2>included templates & config files (load time in seconds)</h2>
|
||||
<div>
|
||||
{foreach $template_data as $template}
|
||||
<font color=brown>{$template.name}</font>
|
||||
<span class="exectime">
|
||||
(compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"}
|
||||
)
|
||||
</span>
|
||||
<br> <span class="exectime">
|
||||
(compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"})
|
||||
</span>
|
||||
<br>
|
||||
{/foreach}
|
||||
</div>
|
||||
@ -109,19 +126,24 @@
|
||||
<table id="table_assigned_vars">
|
||||
{foreach $assigned_vars as $vars}
|
||||
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
|
||||
<th>${$vars@key|escape:'html'}</th>
|
||||
<td>{$vars|debug_print_var nofilter}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
<td><h3><font color=blue>${$vars@key}</font></h3>
|
||||
{if isset($vars['nocache'])}<b>Nocache</b></br>{/if}
|
||||
{if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if}
|
||||
</td>
|
||||
<td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td>
|
||||
<td>{if isset($vars['attributes'])}<h3>Attributes</h3>{$vars['attributes']|debug_print_var nofilter} {/if}</td>
|
||||
{/foreach}
|
||||
</table>
|
||||
|
||||
<h2>assigned config file variables (outer template scope)</h2>
|
||||
<h2>assigned config file variables</h2>
|
||||
|
||||
<table id="table_config_vars">
|
||||
{foreach $config_vars as $vars}
|
||||
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
|
||||
<th>{$vars@key|escape:'html'}</th>
|
||||
<td>{$vars|debug_print_var nofilter}</td>
|
||||
<td><h3><font color=blue>#{$vars@key}#</font></h3>
|
||||
{if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if}
|
||||
</td>
|
||||
<td>{$vars['value']|debug_print_var:10:80 nofilter}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
|
||||
@ -130,8 +152,9 @@
|
||||
</html>
|
||||
{/capture}
|
||||
<script type="text/javascript">
|
||||
{$id = $template_name|default:''|md5}
|
||||
_smarty_console = window.open("", "console{$id}", "width=680,height=600,resizable,scrollbars=yes");
|
||||
{$id = '__Smarty__'}
|
||||
{if $display_mode}{$id = "$offset$template_name"|md5}{/if}
|
||||
_smarty_console = window.open("", "console{$id}", "width=1024,height=600,left={$offset},top={$offset},resizable,scrollbars=yes");
|
||||
_smarty_console.document.write("{$debug_output|escape:'javascript' nofilter}");
|
||||
_smarty_console.document.close();
|
||||
</script>
|
||||
|
@ -33,7 +33,7 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
|
||||
$format = Smarty::$_DATE_FORMAT;
|
||||
}
|
||||
/**
|
||||
* Include the {@link shared.make_timestamp.php} plugin
|
||||
* require_once the {@link shared.make_timestamp.php} plugin
|
||||
*/
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
|
||||
if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {
|
||||
|
@ -14,26 +14,30 @@
|
||||
*
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
*
|
||||
* @param array|object $var variable to be formatted
|
||||
* @param integer $depth maximum recursion depth if $var is an array
|
||||
* @param integer $length maximum string length if $var is a string
|
||||
* @param array|object $var variable to be formatted
|
||||
* @param int $max maximum recursion depth if $var is an array or object
|
||||
* @param int $length maximum string length if $var is a string
|
||||
* @param int $depth actual recursion depth
|
||||
* @param array $objects processed objects in actual depth to prevent recursive object processing
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
|
||||
function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = 0, $objects = array())
|
||||
{
|
||||
$_replace = array("\n" => '<i>\n</i>',
|
||||
"\r" => '<i>\r</i>',
|
||||
"\t" => '<i>\t</i>'
|
||||
$_replace = array("\n" => '\n',
|
||||
"\r" => '\r',
|
||||
"\t" => '\t'
|
||||
);
|
||||
|
||||
switch (gettype($var)) {
|
||||
case 'array' :
|
||||
$results = '<b>Array (' . count($var) . ')</b>';
|
||||
if ($depth == $max) {
|
||||
break;
|
||||
}
|
||||
foreach ($var as $curr_key => $curr_val) {
|
||||
$results .= '<br>' . str_repeat(' ', $depth * 2)
|
||||
. '<b>' . strtr($curr_key, $_replace) . '</b> => '
|
||||
. smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
|
||||
. smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
|
||||
$depth --;
|
||||
}
|
||||
break;
|
||||
@ -41,10 +45,18 @@ function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
|
||||
case 'object' :
|
||||
$object_vars = get_object_vars($var);
|
||||
$results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
|
||||
if (in_array($var, $objects)) {
|
||||
$results .= ' called recursive';
|
||||
break;
|
||||
}
|
||||
if ($depth == $max) {
|
||||
break;
|
||||
}
|
||||
$objects[] = $var;
|
||||
foreach ($object_vars as $curr_key => $curr_val) {
|
||||
$results .= '<br>' . str_repeat(' ', $depth * 2)
|
||||
. '<b> ->' . strtr($curr_key, $_replace) . '</b> = '
|
||||
. smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
|
||||
. smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
|
||||
$depth --;
|
||||
}
|
||||
break;
|
||||
|
@ -19,10 +19,11 @@
|
||||
* @param string $string input string
|
||||
* @param string|array $search regular expression(s) to search for
|
||||
* @param string|array $replace string(s) that should be replaced
|
||||
* @param int $limit the maximum number of replacements
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_modifier_regex_replace($string, $search, $replace)
|
||||
function smarty_modifier_regex_replace($string, $search, $replace, $limit = -1)
|
||||
{
|
||||
if (is_array($search)) {
|
||||
foreach ($search as $idx => $s) {
|
||||
@ -32,7 +33,7 @@ function smarty_modifier_regex_replace($string, $search, $replace)
|
||||
$search = _smarty_regex_replace_check($search);
|
||||
}
|
||||
|
||||
return preg_replace($search, $replace, $string);
|
||||
return preg_replace($search, $replace, $string, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,11 +115,11 @@ function smarty_modifiercompiler_escape($params, $compiler)
|
||||
|
||||
// could not optimize |escape call, so fallback to regular plugin
|
||||
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
|
||||
$compiler->template->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
|
||||
$compiler->template->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape';
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape';
|
||||
} else {
|
||||
$compiler->template->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
|
||||
$compiler->template->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape';
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape';
|
||||
}
|
||||
|
||||
return 'smarty_modifier_escape(' . join(', ', $params) . ')';
|
||||
|
@ -34,11 +34,11 @@ function smarty_modifiercompiler_wordwrap($params, $compiler)
|
||||
$function = 'wordwrap';
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
|
||||
$compiler->template->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
|
||||
$compiler->template->required_plugins['nocache']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap';
|
||||
} else {
|
||||
$compiler->template->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
|
||||
$compiler->template->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap';
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap';
|
||||
}
|
||||
$function = 'smarty_mb_wordwrap';
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ function smarty_outputfilter_trimwhitespace($source)
|
||||
|
||||
// capture html elements not to be messed with
|
||||
$_offset = 0;
|
||||
if (preg_match_all('#<(script|pre|textarea)[^>]*>.*?</\\1>#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
|
||||
if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
|
||||
foreach ($matches as $match) {
|
||||
$store[] = $match[0][0];
|
||||
$_length = strlen($match[0][0]);
|
||||
@ -62,7 +62,7 @@ function smarty_outputfilter_trimwhitespace($source)
|
||||
// can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements
|
||||
'#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
|
||||
// remove spaces between attributes (but not in attribute values!)
|
||||
'#(([a-z0-9]\s*=\s*(["\'])[^\3]*?\3)|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \4',
|
||||
'#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
|
||||
// note: for some very weird reason trim() seems to remove spaces inside attributes.
|
||||
// maybe a \0 byte or something is interfering?
|
||||
'#^\s+<#Ss' => '<',
|
||||
|
@ -21,8 +21,8 @@ function smarty_make_timestamp($string)
|
||||
if (empty($string)) {
|
||||
// use "now":
|
||||
return time();
|
||||
} elseif ($string instanceof DateTime) {
|
||||
return $string->getTimestamp();
|
||||
} elseif ($string instanceof DateTime || (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)) {
|
||||
return (int) $string->format('U'); // PHP 5.2 BC
|
||||
} elseif (strlen($string) == 14 && ctype_digit($string)) {
|
||||
// it is mysql timestamp format of YYYYMMDDHHMMSS?
|
||||
return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2),
|
||||
|
@ -15,21 +15,12 @@
|
||||
*/
|
||||
abstract class Smarty_CacheResource
|
||||
{
|
||||
/**
|
||||
* cache for Smarty_CacheResource instances
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $resources = array();
|
||||
|
||||
/**
|
||||
* resource types provided by the core
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $sysplugins = array(
|
||||
'file' => true,
|
||||
);
|
||||
protected static $sysplugins = array('file' => 'smarty_internal_cacheresource_file.php',);
|
||||
|
||||
/**
|
||||
* populate Cached Object with meta data from Resource
|
||||
@ -55,10 +46,11 @@ abstract class Smarty_CacheResource
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @param bool $update flag if called because cache update
|
||||
*
|
||||
* @return boolean true or false if the cached content does not exist
|
||||
* @return bool true or false if the cached content does not exist
|
||||
*/
|
||||
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null);
|
||||
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false);
|
||||
|
||||
/**
|
||||
* Write the rendered template output to cache
|
||||
@ -81,8 +73,8 @@ abstract class Smarty_CacheResource
|
||||
{
|
||||
if ($_template->cached->handler->process($_template)) {
|
||||
ob_start();
|
||||
$_template->properties['unifunc']($_template);
|
||||
|
||||
$unifunc = $_template->cached->unifunc;
|
||||
$unifunc($_template);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
@ -193,32 +185,24 @@ abstract class Smarty_CacheResource
|
||||
}
|
||||
|
||||
// try smarty's cache
|
||||
if (isset($smarty->_cacheresource_handlers[$type])) {
|
||||
return $smarty->_cacheresource_handlers[$type];
|
||||
if (isset($smarty->_cache['cacheresource_handlers'][$type])) {
|
||||
return $smarty->_cache['cacheresource_handlers'][$type];
|
||||
}
|
||||
|
||||
// try registered resource
|
||||
if (isset($smarty->registered_cache_resources[$type])) {
|
||||
// do not cache these instances as they may vary from instance to instance
|
||||
return $smarty->_cacheresource_handlers[$type] = $smarty->registered_cache_resources[$type];
|
||||
return $smarty->_cache['cacheresource_handlers'][$type] = $smarty->registered_cache_resources[$type];
|
||||
}
|
||||
// try sysplugins dir
|
||||
if (isset(self::$sysplugins[$type])) {
|
||||
if (!isset(self::$resources[$type])) {
|
||||
$cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
|
||||
self::$resources[$type] = new $cache_resource_class();
|
||||
}
|
||||
|
||||
return $smarty->_cacheresource_handlers[$type] = self::$resources[$type];
|
||||
$cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
|
||||
return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class();
|
||||
}
|
||||
// try plugins dir
|
||||
$cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
|
||||
if ($smarty->loadPlugin($cache_resource_class)) {
|
||||
if (!isset(self::$resources[$type])) {
|
||||
self::$resources[$type] = new $cache_resource_class();
|
||||
}
|
||||
|
||||
return $smarty->_cacheresource_handlers[$type] = self::$resources[$type];
|
||||
return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class();
|
||||
}
|
||||
// give up
|
||||
throw new SmartyException("Unable to load cache resource '{$type}'");
|
||||
@ -229,214 +213,14 @@ abstract class Smarty_CacheResource
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
*/
|
||||
public static function invalidLoadedCache(Smarty $smarty)
|
||||
public function invalidLoadedCache(Smarty $smarty)
|
||||
{
|
||||
foreach ($smarty->template_objects as $tpl) {
|
||||
if (isset($tpl->cached)) {
|
||||
$tpl->cached->valid = false;
|
||||
$tpl->cached->processed = false;
|
||||
if (isset($smarty->_cache['template_objects'])) {
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
|
||||
if (isset($tpl->cached)) {
|
||||
unset ($smarty->_cache['template_objects'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Resource Data Object
|
||||
* Cache Data Container for Template Files
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Template_Cached
|
||||
{
|
||||
/**
|
||||
* Source Filepath
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $filepath = false;
|
||||
|
||||
/**
|
||||
* Source Content
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $content = null;
|
||||
|
||||
/**
|
||||
* Source Timestamp
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $timestamp = false;
|
||||
|
||||
/**
|
||||
* Source Existence
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $exists = false;
|
||||
|
||||
/**
|
||||
* Cache Is Valid
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $valid = false;
|
||||
|
||||
/**
|
||||
* Cache was processed
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $processed = false;
|
||||
|
||||
/**
|
||||
* CacheResource Handler
|
||||
*
|
||||
* @var Smarty_CacheResource
|
||||
*/
|
||||
public $handler = null;
|
||||
|
||||
/**
|
||||
* Template Compile Id (Smarty_Internal_Template::$compile_id)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $compile_id = null;
|
||||
|
||||
/**
|
||||
* Template Cache Id (Smarty_Internal_Template::$cache_id)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $cache_id = null;
|
||||
|
||||
/**
|
||||
* Id for cache locking
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $lock_id = null;
|
||||
|
||||
/**
|
||||
* flag that cache is locked by this instance
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $is_locked = false;
|
||||
|
||||
/**
|
||||
* Source Object
|
||||
*
|
||||
* @var Smarty_Template_Source
|
||||
*/
|
||||
public $source = null;
|
||||
|
||||
/**
|
||||
* create Cached Object container
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*/
|
||||
public function __construct(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$this->compile_id = $_template->compile_id;
|
||||
$this->cache_id = $_template->cache_id;
|
||||
$this->source = $_template->source;
|
||||
$_template->cached = $this;
|
||||
$smarty = $_template->smarty;
|
||||
|
||||
//
|
||||
// load resource handler
|
||||
//
|
||||
$this->handler = $handler = Smarty_CacheResource::load($smarty); // Note: prone to circular references
|
||||
|
||||
//
|
||||
// check if cache is valid
|
||||
//
|
||||
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled) {
|
||||
$handler->populate($this, $_template);
|
||||
|
||||
return;
|
||||
}
|
||||
while (true) {
|
||||
while (true) {
|
||||
$handler->populate($this, $_template);
|
||||
if ($this->timestamp === false || $smarty->force_compile || $smarty->force_cache) {
|
||||
$this->valid = false;
|
||||
} else {
|
||||
$this->valid = true;
|
||||
}
|
||||
if ($this->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT && $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)) {
|
||||
// lifetime expired
|
||||
$this->valid = false;
|
||||
}
|
||||
if ($this->valid || !$_template->smarty->cache_locking) {
|
||||
break;
|
||||
}
|
||||
if (!$this->handler->locked($_template->smarty, $this)) {
|
||||
$this->handler->acquireLock($_template->smarty, $this);
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
if ($this->valid) {
|
||||
if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
|
||||
// load cache file for the following checks
|
||||
if ($smarty->debugging) {
|
||||
Smarty_Internal_Debug::start_cache($_template);
|
||||
}
|
||||
if ($handler->process($_template, $this) === false) {
|
||||
$this->valid = false;
|
||||
} else {
|
||||
$this->processed = true;
|
||||
}
|
||||
if ($smarty->debugging) {
|
||||
Smarty_Internal_Debug::end_cache($_template);
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && (time() > ($_template->cached->timestamp + $_template->properties['cache_lifetime']))) {
|
||||
$this->valid = false;
|
||||
}
|
||||
if (!$this->valid && $_template->smarty->cache_locking) {
|
||||
$this->handler->acquireLock($_template->smarty, $this);
|
||||
|
||||
return;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write this cache object to handler
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param string $content content to cache
|
||||
*
|
||||
* @return boolean success
|
||||
*/
|
||||
public function write(Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
if (!$_template->source->recompiled) {
|
||||
if ($this->handler->writeCachedContent($_template, $content)) {
|
||||
$this->content = null;
|
||||
$this->timestamp = time();
|
||||
$this->exists = true;
|
||||
$this->valid = true;
|
||||
if ($_template->smarty->cache_locking) {
|
||||
$this->handler->releaseLock($_template->smarty, $this);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -83,9 +83,12 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null;
|
||||
$_compile_id = isset($cached->compile_id) ? preg_replace('![^\w\|]+!', '_', $cached->compile_id) : null;
|
||||
|
||||
$cached->filepath = sha1($cached->source->filepath . $_cache_id . $_compile_id);
|
||||
$_compile_id = isset($cached->compile_id) ? preg_replace('![^\w]+!', '_', $cached->compile_id) : null;
|
||||
$path = $cached->source->filepath . $_cache_id . $_compile_id;
|
||||
$cached->filepath = sha1($path);
|
||||
if ($_template->smarty->cache_locking) {
|
||||
$cached->lock_id = sha1('lock.' . $path);
|
||||
}
|
||||
$this->populateTimestamp($cached);
|
||||
}
|
||||
|
||||
@ -116,10 +119,11 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @param bool $update flag if called because cache update
|
||||
*
|
||||
* @return boolean true or false if the cached content does not exist
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
|
||||
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
|
||||
{
|
||||
if (!$cached) {
|
||||
$cached = $_template->cached;
|
||||
@ -127,14 +131,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
$content = $cached->content ? $cached->content : null;
|
||||
$timestamp = $cached->timestamp ? $cached->timestamp : null;
|
||||
if ($content === null || !$timestamp) {
|
||||
$this->fetch(
|
||||
$_template->cached->filepath,
|
||||
$_template->source->name,
|
||||
$_template->cache_id,
|
||||
$_template->compile_id,
|
||||
$content,
|
||||
$timestamp
|
||||
);
|
||||
$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp);
|
||||
}
|
||||
if (isset($content)) {
|
||||
/** @var Smarty_Internal_Template $_smarty_tpl
|
||||
@ -142,7 +139,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
*/
|
||||
$_smarty_tpl = $_template;
|
||||
eval("?>" . $content);
|
||||
|
||||
$cached->content = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -159,14 +156,28 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
*/
|
||||
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
return $this->save(
|
||||
$_template->cached->filepath,
|
||||
$_template->source->name,
|
||||
$_template->cache_id,
|
||||
$_template->compile_id,
|
||||
$_template->properties['cache_lifetime'],
|
||||
$content
|
||||
);
|
||||
return $this->save($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $_template->cache_lifetime, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read cached template from cache
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function readCachedContent(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$content = $_template->cached->content ? $_template->cached->content : null;
|
||||
$timestamp = null;
|
||||
if ($content === null) {
|
||||
$timestamp = null;
|
||||
$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp);
|
||||
}
|
||||
if (isset($content)) {
|
||||
return $content;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -179,8 +190,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
*/
|
||||
public function clearAll(Smarty $smarty, $exp_time = null)
|
||||
{
|
||||
$this->cache = array();
|
||||
|
||||
return $this->delete(null, null, null, $exp_time);
|
||||
}
|
||||
|
||||
@ -197,32 +206,23 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
*/
|
||||
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
|
||||
{
|
||||
$this->cache = array();
|
||||
$cache_name = null;
|
||||
|
||||
if (isset($resource_name)) {
|
||||
$_save_stat = $smarty->caching;
|
||||
$smarty->caching = true;
|
||||
$tpl = new $smarty->template_class($resource_name, $smarty);
|
||||
$smarty->caching = $_save_stat;
|
||||
|
||||
if ($tpl->source->exists) {
|
||||
$cache_name = $tpl->source->name;
|
||||
$source = Smarty_Template_Source::load(null, $smarty, $resource_name);
|
||||
if ($source->exists) {
|
||||
$cache_name = $source->name;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
// remove from template cache
|
||||
if ($smarty->allow_ambiguous_resources) {
|
||||
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
|
||||
} else {
|
||||
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
|
||||
if (isset($smarty->_cache['template_objects'])) {
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $_tpl) {
|
||||
if (isset($_tpl->cached) && $_tpl->source->uid == $source->uid) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($_templateId[150])) {
|
||||
$_templateId = sha1($_templateId);
|
||||
}
|
||||
unset($smarty->template_objects[$_templateId]);
|
||||
// template object no longer needed
|
||||
unset($tpl);
|
||||
}
|
||||
|
||||
return $this->delete($cache_name, $cache_id, $compile_id, $exp_time);
|
||||
@ -238,15 +238,14 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
*/
|
||||
public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
$id = $cached->filepath;
|
||||
$id = $cached->lock_id;
|
||||
$name = $cached->source->name . '.lock';
|
||||
|
||||
$mtime = $this->fetchTimestamp($id, $name, null, null);
|
||||
$mtime = $this->fetchTimestamp($id, $name, $cached->cache_id, $cached->compile_id);
|
||||
if ($mtime === null) {
|
||||
$this->fetch($id, $name, null, null, $content, $mtime);
|
||||
$this->fetch($id, $name, $cached->cache_id, $cached->compile_id, $content, $mtime);
|
||||
}
|
||||
|
||||
return $mtime && time() - $mtime < $smarty->locking_timeout;
|
||||
return $mtime && ($t = time()) - $mtime < $smarty->locking_timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -260,10 +259,9 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
public function acquireLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
$cached->is_locked = true;
|
||||
|
||||
$id = $cached->filepath;
|
||||
$id = $cached->lock_id;
|
||||
$name = $cached->source->name . '.lock';
|
||||
$this->save($id, $name, null, null, $smarty->locking_timeout, '');
|
||||
$this->save($id, $name, $cached->cache_id, $cached->compile_id, $smarty->locking_timeout, '');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -277,8 +275,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
|
||||
public function releaseLock(Smarty $smarty, Smarty_Template_Cached $cached)
|
||||
{
|
||||
$cached->is_locked = false;
|
||||
|
||||
$name = $cached->source->name . '.lock';
|
||||
$this->delete($name, null, null, null);
|
||||
$this->delete($name, $cached->cache_id, $cached->compile_id, null);
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
* @var array
|
||||
*/
|
||||
protected $contents = array();
|
||||
|
||||
/**
|
||||
* cache for timestamps
|
||||
*
|
||||
@ -53,10 +54,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
*/
|
||||
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$cached->filepath = $_template->source->uid
|
||||
. '#' . $this->sanitize($cached->source->resource)
|
||||
. '#' . $this->sanitize($cached->cache_id)
|
||||
. '#' . $this->sanitize($cached->compile_id);
|
||||
$cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' .
|
||||
$this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
|
||||
|
||||
$this->populateTimestamp($cached);
|
||||
}
|
||||
@ -83,10 +82,11 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @param bool $update flag if called because cache update
|
||||
*
|
||||
* @return boolean true or false if the cached content does not exist
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
|
||||
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
|
||||
{
|
||||
if (!$cached) {
|
||||
$cached = $_template->cached;
|
||||
@ -123,7 +123,29 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
{
|
||||
$this->addMetaTimestamp($content);
|
||||
|
||||
return $this->write(array($_template->cached->filepath => $content), $_template->properties['cache_lifetime']);
|
||||
return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read cached template from cache
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function readCachedContent(Smarty_Internal_Template $_template)
|
||||
{
|
||||
$content = $_template->cached->content ? $_template->cached->content : null;
|
||||
$timestamp = null;
|
||||
if ($content === null) {
|
||||
if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (isset($content)) {
|
||||
return $content;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,7 +164,14 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
if (!$this->purge()) {
|
||||
$this->invalidate(null);
|
||||
}
|
||||
|
||||
// remove from template cache
|
||||
if (isset($smarty->_cache['template_objects'])) {
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
|
||||
if (isset($tpl->cached)) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return - 1;
|
||||
}
|
||||
|
||||
@ -163,11 +192,21 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
*/
|
||||
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
|
||||
{
|
||||
$uid = $this->getTemplateUid($smarty, $resource_name, $cache_id, $compile_id);
|
||||
$cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $this->sanitize($compile_id);
|
||||
$uid = $this->getTemplateUid($smarty, $resource_name);
|
||||
$cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' .
|
||||
$this->sanitize($compile_id);
|
||||
$this->delete(array($cid));
|
||||
$this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid);
|
||||
|
||||
// remove from template cache
|
||||
if (isset($resource_name) && isset($smarty->_cache['template_objects'])) {
|
||||
if (isset($smarty->_cache['template_objects'])) {
|
||||
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
|
||||
if ($tpl->source->uid == $uid && isset($tpl->cached)) {
|
||||
unset($smarty->_cache['template_objects'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return - 1;
|
||||
}
|
||||
|
||||
@ -176,33 +215,20 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
*
|
||||
* @param Smarty $smarty Smarty object
|
||||
* @param string $resource_name template name
|
||||
* @param string $cache_id cache id
|
||||
* @param string $compile_id compile id
|
||||
*
|
||||
* @return string filepath of cache file
|
||||
* @throws \SmartyException
|
||||
*
|
||||
*/
|
||||
protected function getTemplateUid(Smarty $smarty, $resource_name, $cache_id, $compile_id)
|
||||
protected function getTemplateUid(Smarty $smarty, $resource_name)
|
||||
{
|
||||
$uid = '';
|
||||
if (isset($resource_name)) {
|
||||
$tpl = new $smarty->template_class($resource_name, $smarty);
|
||||
if ($tpl->source->exists) {
|
||||
$uid = $tpl->source->uid;
|
||||
$source = Smarty_Template_Source::load(null, $smarty, $resource_name);
|
||||
if ($source->exists) {
|
||||
return $source->uid;
|
||||
}
|
||||
|
||||
// remove from template cache
|
||||
if ($smarty->allow_ambiguous_resources) {
|
||||
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
|
||||
} else {
|
||||
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
|
||||
}
|
||||
if (isset($_templateId[150])) {
|
||||
$_templateId = sha1($_templateId);
|
||||
}
|
||||
unset($smarty->template_objects[$_templateId]);
|
||||
}
|
||||
|
||||
return $uid;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,12 +240,10 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
*/
|
||||
protected function sanitize($string)
|
||||
{
|
||||
// some poeple smoke bad weed
|
||||
$string = trim($string, '|');
|
||||
if (!$string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return preg_replace('#[^\w\|]+#S', '_', $string);
|
||||
}
|
||||
|
||||
@ -275,11 +299,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
*/
|
||||
protected function getMetaTimestamp(&$content)
|
||||
{
|
||||
$s = unpack("N", substr($content, 0, 4));
|
||||
$m = unpack("N", substr($content, 4, 4));
|
||||
$content = substr($content, 8);
|
||||
|
||||
return $s[1] + ($m[1] / 100000000);
|
||||
extract(unpack('N1s/N1m/a*content', $content));
|
||||
return $s + ($m / 100000000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -380,7 +401,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
|
||||
$t[] = 'IVK#COMPILE' . $_compile;
|
||||
}
|
||||
$_name .= '#';
|
||||
// some poeple smoke bad weed
|
||||
$cid = trim($cache_id, '|');
|
||||
if (!$cid) {
|
||||
return $t;
|
||||
|
@ -1,94 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Resource Data Object
|
||||
* Meta Data Container for Config Files
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
* @property string $content
|
||||
* @property int $timestamp
|
||||
* @property bool $exists
|
||||
*/
|
||||
class Smarty_Config_Source extends Smarty_Template_Source
|
||||
{
|
||||
/**
|
||||
* create Config Object container
|
||||
*
|
||||
* @param Smarty_Resource $handler Resource Handler this source object communicates with
|
||||
* @param Smarty $smarty Smarty instance this source object belongs to
|
||||
* @param string $resource full config_resource
|
||||
* @param string $type type of resource
|
||||
* @param string $name resource name
|
||||
* @param string $unique_resource unqiue resource name
|
||||
*/
|
||||
public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name, $unique_resource)
|
||||
{
|
||||
$this->handler = $handler; // Note: prone to circular references
|
||||
|
||||
// Note: these may be ->config_compiler_class etc in the future
|
||||
//$this->config_compiler_class = $handler->config_compiler_class;
|
||||
//$this->config_lexer_class = $handler->config_lexer_class;
|
||||
//$this->config_parser_class = $handler->config_parser_class;
|
||||
|
||||
$this->smarty = $smarty;
|
||||
$this->resource = $resource;
|
||||
$this->type = $type;
|
||||
$this->name = $name;
|
||||
$this->unique_resource = $unique_resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* <<magic>> Generic setter.
|
||||
*
|
||||
* @param string $property_name valid: content, timestamp, exists
|
||||
* @param mixed $value newly assigned value (not check for correct type)
|
||||
*
|
||||
* @throws SmartyException when the given property name is not valid
|
||||
*/
|
||||
public function __set($property_name, $value)
|
||||
{
|
||||
switch ($property_name) {
|
||||
case 'content':
|
||||
case 'timestamp':
|
||||
case 'exists':
|
||||
$this->$property_name = $value;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new SmartyException("invalid config property '$property_name'.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <<magic>> Generic getter.
|
||||
*
|
||||
* @param string $property_name valid: content, timestamp, exists
|
||||
*
|
||||
* @return mixed|void
|
||||
* @throws SmartyException when the given property name is not valid
|
||||
*/
|
||||
public function __get($property_name)
|
||||
{
|
||||
switch ($property_name) {
|
||||
case 'timestamp':
|
||||
case 'exists':
|
||||
$this->handler->populateTimestamp($this);
|
||||
|
||||
return $this->$property_name;
|
||||
|
||||
case 'content':
|
||||
return $this->content = $this->handler->getContent($this);
|
||||
|
||||
default:
|
||||
throw new SmartyException("config property '$property_name' does not exist.");
|
||||
}
|
||||
}
|
||||
}
|
68
library/Smarty/libs/sysplugins/smarty_data.php
Normal file
68
library/Smarty/libs/sysplugins/smarty_data.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Plugin Data
|
||||
* This file contains the data object
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Template
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for the Smarty data object
|
||||
* The Smarty data object will hold Smarty variables in the current scope
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Template
|
||||
*/
|
||||
class Smarty_Data extends Smarty_Internal_Data
|
||||
{
|
||||
/**
|
||||
* Counter
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
static $count = 0;
|
||||
|
||||
/**
|
||||
* Data block name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dataObjectName = '';
|
||||
|
||||
/**
|
||||
* Smarty object
|
||||
*
|
||||
* @var Smarty
|
||||
*/
|
||||
public $smarty = null;
|
||||
|
||||
/**
|
||||
* create Smarty data object
|
||||
*
|
||||
* @param Smarty|array $_parent parent template
|
||||
* @param Smarty|Smarty_Internal_Template $smarty global smarty instance
|
||||
* @param string $name optional data block name
|
||||
*
|
||||
* @throws SmartyException
|
||||
*/
|
||||
public function __construct($_parent = null, $smarty = null, $name = null)
|
||||
{
|
||||
parent::__construct();
|
||||
self::$count ++;
|
||||
$this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count);
|
||||
$this->smarty = $smarty;
|
||||
if (is_object($_parent)) {
|
||||
// when object set up back pointer
|
||||
$this->parent = $_parent;
|
||||
} elseif (is_array($_parent)) {
|
||||
// set up variable values
|
||||
foreach ($_parent as $_key => $_val) {
|
||||
$this->tpl_vars[$_key] = new Smarty_Variable($_val);
|
||||
}
|
||||
} elseif ($_parent != null) {
|
||||
throw new SmartyException("Wrong type for template variables");
|
||||
}
|
||||
}
|
||||
}
|
@ -29,14 +29,12 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
{
|
||||
$_source_file_path = str_replace(':', '.', $_template->source->filepath);
|
||||
$_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null;
|
||||
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
|
||||
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w]+!', '_', $_template->compile_id) : null;
|
||||
$_filepath = $_template->source->uid;
|
||||
// if use_sub_dirs, break file into directories
|
||||
if ($_template->smarty->use_sub_dirs) {
|
||||
$_filepath = substr($_filepath, 0, 2) . DS
|
||||
. substr($_filepath, 2, 2) . DS
|
||||
. substr($_filepath, 4, 2) . DS
|
||||
. $_filepath;
|
||||
$_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS .
|
||||
$_filepath;
|
||||
}
|
||||
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
|
||||
if (isset($_cache_id)) {
|
||||
@ -60,9 +58,12 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
}
|
||||
$cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock';
|
||||
}
|
||||
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
|
||||
$cached->timestamp = @filemtime($cached->filepath);
|
||||
$cached->exists = !!$cached->timestamp;
|
||||
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) .
|
||||
'.php';
|
||||
$cached->timestamp = $cached->exists = is_file($cached->filepath);
|
||||
if ($cached->exists) {
|
||||
$cached->timestamp = filemtime($cached->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,8 +75,10 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
*/
|
||||
public function populateTimestamp(Smarty_Template_Cached $cached)
|
||||
{
|
||||
$cached->timestamp = @filemtime($cached->filepath);
|
||||
$cached->exists = !!$cached->timestamp;
|
||||
$cached->timestamp = $cached->exists = is_file($cached->filepath);
|
||||
if ($cached->exists) {
|
||||
$cached->timestamp = filemtime($cached->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,17 +86,22 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty_Template_Cached $cached cached object
|
||||
* @param bool $update flag if called because cache update
|
||||
*
|
||||
* @return booleantrue or false if the cached content does not exist
|
||||
* @return boolean true or false if the cached content does not exist
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
|
||||
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
|
||||
{
|
||||
/** @var Smarty_Internal_Template $_smarty_tpl
|
||||
* used in included file
|
||||
*/
|
||||
$_smarty_tpl = $_template;
|
||||
|
||||
return @include $_template->cached->filepath;
|
||||
$_template->cached->valid = false;
|
||||
if ($update && defined('HHVM_VERSION')) {
|
||||
return $_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->cached->filepath);
|
||||
} else {
|
||||
return @include $_template->cached->filepath;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,14 +114,32 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
*/
|
||||
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
|
||||
{
|
||||
if (Smarty_Internal_Write_File::writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
|
||||
$_template->cached->timestamp = @filemtime($_template->cached->filepath);
|
||||
$_template->cached->exists = !!$_template->cached->timestamp;
|
||||
if ($_template->cached->exists) {
|
||||
if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
|
||||
if (function_exists('opcache_invalidate')) {
|
||||
opcache_invalidate($_template->cached->filepath);
|
||||
}
|
||||
$cached = $_template->cached;
|
||||
$cached->timestamp = $cached->exists = is_file($cached->filepath);
|
||||
if ($cached->exists) {
|
||||
$cached->timestamp = filemtime($cached->filepath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read cached template from cache
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function readCachedContent(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if (is_file($_template->cached->filepath)) {
|
||||
return file_get_contents($_template->cached->filepath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -127,7 +153,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
*/
|
||||
public function clearAll(Smarty $smarty, $exp_time = null)
|
||||
{
|
||||
return $this->clear($smarty, null, null, null, $exp_time);
|
||||
return Smarty_Internal_Extension_Clear::clear($smarty, null, null, null, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,108 +169,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
*/
|
||||
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
|
||||
{
|
||||
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
|
||||
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
|
||||
$_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
|
||||
$_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0;
|
||||
if (($_dir = realpath($smarty->getCacheDir())) === false) {
|
||||
return 0;
|
||||
}
|
||||
$_dir .= '/';
|
||||
$_dir_length = strlen($_dir);
|
||||
if (isset($_cache_id)) {
|
||||
$_cache_id_parts = explode('|', $_cache_id);
|
||||
$_cache_id_parts_count = count($_cache_id_parts);
|
||||
if ($smarty->use_sub_dirs) {
|
||||
foreach ($_cache_id_parts as $id_part) {
|
||||
$_dir .= $id_part . DS;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($resource_name)) {
|
||||
$_save_stat = $smarty->caching;
|
||||
$smarty->caching = true;
|
||||
$tpl = new $smarty->template_class($resource_name, $smarty);
|
||||
$smarty->caching = $_save_stat;
|
||||
|
||||
// remove from template cache
|
||||
$tpl->source; // have the template registered before unset()
|
||||
if ($smarty->allow_ambiguous_resources) {
|
||||
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
|
||||
} else {
|
||||
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
|
||||
}
|
||||
if (isset($_templateId[150])) {
|
||||
$_templateId = sha1($_templateId);
|
||||
}
|
||||
unset($smarty->template_objects[$_templateId]);
|
||||
|
||||
if ($tpl->source->exists) {
|
||||
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
$_count = 0;
|
||||
$_time = time();
|
||||
if (file_exists($_dir)) {
|
||||
$_cacheDirs = new RecursiveDirectoryIterator($_dir);
|
||||
$_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($_cache as $_file) {
|
||||
if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
|
||||
continue;
|
||||
}
|
||||
// directory ?
|
||||
if ($_file->isDir()) {
|
||||
if (!$_cache->isDot()) {
|
||||
// delete folder if empty
|
||||
@rmdir($_file->getPathname());
|
||||
}
|
||||
} else {
|
||||
$_parts = explode($_dir_sep, str_replace('\\', '/', substr((string) $_file, $_dir_length)));
|
||||
$_parts_count = count($_parts);
|
||||
// check name
|
||||
if (isset($resource_name)) {
|
||||
if ($_parts[$_parts_count - 1] != $_resourcename_parts) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// check compile id
|
||||
if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) {
|
||||
continue;
|
||||
}
|
||||
// check cache id
|
||||
if (isset($_cache_id)) {
|
||||
// count of cache id parts
|
||||
$_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset;
|
||||
if ($_parts_count < $_cache_id_parts_count) {
|
||||
continue;
|
||||
}
|
||||
for ($i = 0; $i < $_cache_id_parts_count; $i ++) {
|
||||
if ($_parts[$i] != $_cache_id_parts[$i]) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
// expired ?
|
||||
if (isset($exp_time)) {
|
||||
if ($exp_time < 0) {
|
||||
preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match);
|
||||
if ($_time < (@filemtime($_file) + $match[1])) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if ($_time - @filemtime($_file) < $exp_time) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
$_count += @unlink((string) $_file) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $_count;
|
||||
return Smarty_Internal_Extension_Clear::clear($smarty, $resource_name, $cache_id, $compile_id, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -262,9 +187,12 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
|
||||
} else {
|
||||
clearstatcache();
|
||||
}
|
||||
$t = @filemtime($cached->lock_id);
|
||||
|
||||
return $t && (time() - $t < $smarty->locking_timeout);
|
||||
if (is_file($cached->lock_id)) {
|
||||
$t = @filemtime($cached->lock_id);
|
||||
return $t && (time() - $t < $smarty->locking_timeout);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,13 +19,13 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
|
||||
/**
|
||||
* Compiles code for the {append} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// the following must be assigned at runtime because it will be overwritten in parent class
|
||||
$this->required_attributes = array('var', 'value');
|
||||
|
@ -16,23 +16,31 @@
|
||||
*/
|
||||
class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
||||
{
|
||||
/**
|
||||
* Valid scope names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
|
||||
'smarty' => true, 'tpl_root' => true);
|
||||
|
||||
/**
|
||||
* Compiles code for the {assign} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
|
||||
$this->required_attributes = array('var', 'value');
|
||||
$this->shorttag_order = array('var', 'value');
|
||||
$this->optional_attributes = array('scope');
|
||||
$this->optional_attributes = array('scope', 'bubble_up');
|
||||
$_nocache = 'null';
|
||||
$_scope = Smarty::SCOPE_LOCAL;
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// nocache ?
|
||||
@ -42,43 +50,47 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
|
||||
if (isset($compiler->template->tpl_vars[trim($_attr['var'], "'")])) {
|
||||
$compiler->template->tpl_vars[trim($_attr['var'], "'")]->nocache = true;
|
||||
} else {
|
||||
$compiler->template->tpl_vars[trim($_attr['var'], "'")] = new Smarty_variable(null, true);
|
||||
$compiler->template->tpl_vars[trim($_attr['var'], "'")] = new Smarty_Variable(null, true);
|
||||
}
|
||||
}
|
||||
// scope setup
|
||||
$_scope = Smarty::SCOPE_LOCAL;
|
||||
if (isset($_attr['scope'])) {
|
||||
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
||||
if ($_attr['scope'] == 'parent') {
|
||||
$_scope = Smarty::SCOPE_PARENT;
|
||||
} elseif ($_attr['scope'] == 'root') {
|
||||
$_scope = Smarty::SCOPE_ROOT;
|
||||
} elseif ($_attr['scope'] == 'global') {
|
||||
$_scope = Smarty::SCOPE_GLOBAL;
|
||||
} else {
|
||||
$compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
|
||||
if (!isset($this->valid_scopes[$_attr['scope']])) {
|
||||
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true);
|
||||
}
|
||||
if ($_attr['scope'] != 'local') {
|
||||
if ($_attr['scope'] == 'parent') {
|
||||
$_scope = Smarty::SCOPE_PARENT;
|
||||
} elseif ($_attr['scope'] == 'root') {
|
||||
$_scope = Smarty::SCOPE_ROOT;
|
||||
} elseif ($_attr['scope'] == 'global') {
|
||||
$_scope = Smarty::SCOPE_GLOBAL;
|
||||
} elseif ($_attr['scope'] == 'smarty') {
|
||||
$_scope = Smarty::SCOPE_SMARTY;
|
||||
} elseif ($_attr['scope'] == 'tpl_root') {
|
||||
$_scope = Smarty::SCOPE_TPL_ROOT;
|
||||
}
|
||||
$_scope += (isset($_attr['bubble_up']) && $_attr['bubble_up'] == 'false') ? 0 : Smarty::SCOPE_BUBBLE_UP;
|
||||
}
|
||||
}
|
||||
// compiled output
|
||||
if (isset($parameter['smarty_internal_index'])) {
|
||||
$output = "<?php \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
|
||||
$output =
|
||||
"<?php \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, $_attr[var], $_nocache);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
|
||||
} else {
|
||||
// implement Smarty2's behaviour of variables assigned by reference
|
||||
if ($compiler->template->smarty instanceof SmartyBC) {
|
||||
$output = "<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
|
||||
$output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache; \$_smarty_tpl->tpl_vars[$_attr[var]]->scope = $_scope;";
|
||||
$output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);";
|
||||
$output =
|
||||
"<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
|
||||
$output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache;";
|
||||
$output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache);";
|
||||
} else {
|
||||
$output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);";
|
||||
$output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache);";
|
||||
}
|
||||
}
|
||||
if ($_scope == Smarty::SCOPE_PARENT) {
|
||||
$output .= "\nif (\$_smarty_tpl->parent != null) \$_smarty_tpl->parent->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
|
||||
} elseif ($_scope == Smarty::SCOPE_ROOT || $_scope == Smarty::SCOPE_GLOBAL) {
|
||||
$output .= "\n\$_ptr = \$_smarty_tpl->parent; while (\$_ptr != null) {\$_ptr->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]]; \$_ptr = \$_ptr->parent; }";
|
||||
}
|
||||
if ($_scope == Smarty::SCOPE_GLOBAL) {
|
||||
$output .= "\nSmarty::\$global_tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
|
||||
}
|
||||
$output .= "\n\$_smarty_tpl->ext->_updateScope->updateScope(\$_smarty_tpl, $_attr[var], $_scope);";
|
||||
$output .= '?>';
|
||||
|
||||
return $output;
|
||||
|
@ -1,24 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Block
|
||||
* Compiles the {block}{/block} tags
|
||||
/*
|
||||
* This file is part of Smarty.
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
* (c) 2015 Uwe Tews
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Block Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews <uwe.tews@googlemail.com>
|
||||
*/
|
||||
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
||||
class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inheritance
|
||||
{
|
||||
|
||||
const parent = '____SMARTY_BLOCK_PARENT____';
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -41,7 +37,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $option_flags = array('hide', 'append', 'prepend', 'nocache');
|
||||
public $option_flags = array('hide', 'nocache');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
@ -49,396 +45,248 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('internal_file', 'internal_uid', 'internal_line');
|
||||
/**
|
||||
* nested child block names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $nested_block_names = array();
|
||||
public $optional_attributes = array('assign');
|
||||
|
||||
/**
|
||||
* child block source buffer
|
||||
* nesting level of block tags
|
||||
*
|
||||
* @var array
|
||||
* @var int
|
||||
*/
|
||||
public static $block_data = array();
|
||||
public static $blockTagNestingLevel = 0;
|
||||
|
||||
/**
|
||||
* Saved compiler object
|
||||
*
|
||||
* @var Smarty_Internal_TemplateCompilerBase
|
||||
*/
|
||||
public $compiler = null;
|
||||
|
||||
/**
|
||||
* Compiles code for the {block} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return boolean true
|
||||
* @return bool true
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
if (!isset($compiler->_cache['blockNesting'])) {
|
||||
$compiler->_cache['blockNesting'] = 0;
|
||||
}
|
||||
if ($compiler->_cache['blockNesting'] == 0) {
|
||||
// make sure that inheritance gets initialized in template code
|
||||
$this->registerInit($compiler);
|
||||
$this->option_flags = array('hide', 'nocache', 'append', 'prepend');
|
||||
} else {
|
||||
$this->option_flags = array('hide', 'nocache');
|
||||
}
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$_name = trim($_attr['name'], "\"'");
|
||||
|
||||
// existing child must override parent settings
|
||||
if (isset($compiler->template->block_data[$_name]) && $compiler->template->block_data[$_name]['mode'] == 'replace') {
|
||||
$_attr['append'] = false;
|
||||
$_attr['prepend'] = false;
|
||||
$compiler->_cache['blockNesting'] ++;
|
||||
$compiler->_cache['blockName'][$compiler->_cache['blockNesting']] = $_attr['name'];
|
||||
$compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][0] = 'block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true));
|
||||
$compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][1] = false;
|
||||
$this->openTag($compiler, 'block', array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
|
||||
$compiler->template->compiled->has_nocache_code,
|
||||
$compiler->template->caching));
|
||||
// must whole block be nocache ?
|
||||
if ($compiler->tag_nocache) {
|
||||
$i = 0;
|
||||
}
|
||||
|
||||
// check if we process an inheritance child template
|
||||
if ($compiler->inheritance_child) {
|
||||
array_unshift(self::$nested_block_names, $_name);
|
||||
// build {block} for child block
|
||||
self::$block_data[$_name]['source'] =
|
||||
"{$compiler->smarty->left_delimiter}private_child_block name={$_attr['name']} file='{$compiler->template->source->filepath}' type='{$compiler->template->source->type}' resource='{$compiler->template->template_resource}'" .
|
||||
" uid='{$compiler->template->source->uid}' line={$compiler->lex->line}";
|
||||
if ($_attr['nocache']) {
|
||||
self::$block_data[$_name]['source'] .= ' nocache';
|
||||
}
|
||||
self::$block_data[$_name]['source'] .= $compiler->smarty->right_delimiter;
|
||||
|
||||
$save = array($_attr, $compiler->inheritance);
|
||||
$this->openTag($compiler, 'block', $save);
|
||||
// set flag for {block} tag
|
||||
$compiler->inheritance = true;
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
$compiler->has_code = false;
|
||||
return;
|
||||
}
|
||||
// must merge includes
|
||||
if ($_attr['nocache'] == true) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
$save = array($_attr, $compiler->inheritance, $compiler->parser->current_buffer, $compiler->nocache);
|
||||
$this->openTag($compiler, 'block', $save);
|
||||
$compiler->inheritance = true;
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
|
||||
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
|
||||
$compiler->has_code = false;
|
||||
|
||||
return true;
|
||||
// $compiler->suppressNocacheProcessing = true;
|
||||
if ($_attr['nocache'] === true) {
|
||||
//$compiler->trigger_template_error('nocache option not allowed', $compiler->parser->lex->taglineno);
|
||||
}
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
$compiler->template->compiled->has_nocache_code = false;
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile saved child block source
|
||||
*
|
||||
* @param object $compiler compiler object
|
||||
* @param string $_name optional name of child block
|
||||
* @param \Smarty_Internal_TemplateCompilerBase compiler object
|
||||
* @param string $_name optional name of child block
|
||||
*
|
||||
* @return string compiled code of child block
|
||||
*/
|
||||
static function compileChildBlock($compiler, $_name = null)
|
||||
static function compileChildBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null)
|
||||
{
|
||||
if ($compiler->inheritance_child) {
|
||||
$name1 = Smarty_Internal_Compile_Block::$nested_block_names[0];
|
||||
if (isset($compiler->template->block_data[$name1])) {
|
||||
// replace inner block name with generic
|
||||
Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .= $compiler->template->block_data[$name1]['source'];
|
||||
Smarty_Internal_Compile_Block::$block_data[$name1]['child'] = true;
|
||||
}
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
$compiler->has_code = false;
|
||||
return;
|
||||
if (!isset($compiler->_cache['blockNesting'])) {
|
||||
$compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ',
|
||||
$compiler->parser->lex->taglineno);
|
||||
}
|
||||
// if called by {$smarty.block.child} we must search the name of enclosing {block}
|
||||
if ($_name == null) {
|
||||
$stack_count = count($compiler->_tag_stack);
|
||||
while (--$stack_count >= 0) {
|
||||
if ($compiler->_tag_stack[$stack_count][0] == 'block') {
|
||||
$_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "\"'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($_name == null) {
|
||||
$compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ', $compiler->lex->taglineno);
|
||||
}
|
||||
// undefined child?
|
||||
if (!isset($compiler->template->block_data[$_name]['source'])) {
|
||||
$compiler->popTrace();
|
||||
return '';
|
||||
}
|
||||
// flag that child is already compile by {$smarty.block.child} inclusion
|
||||
$compiler->template->block_data[$_name]['compiled'] = true;
|
||||
$_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
|
||||
$compiler->template->compile_id, $compiler->template->caching, $compiler->template->cache_lifetime);
|
||||
if ($compiler->smarty->debugging) {
|
||||
Smarty_Internal_Debug::ignore($_tpl);
|
||||
}
|
||||
$_tpl->tpl_vars = $compiler->template->tpl_vars;
|
||||
$_tpl->variable_filters = $compiler->template->variable_filters;
|
||||
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
||||
$_tpl->allow_relative_path = true;
|
||||
$_tpl->compiler->inheritance = true;
|
||||
$_tpl->compiler->suppressHeader = true;
|
||||
$_tpl->compiler->suppressFilter = true;
|
||||
$_tpl->compiler->suppressTemplatePropertyHeader = true;
|
||||
$_tpl->compiler->suppressMergedTemplates = true;
|
||||
$nocache = $compiler->nocache || $compiler->tag_nocache;
|
||||
if (strpos($compiler->template->block_data[$_name]['source'], self::parent) !== false) {
|
||||
$_output = str_replace(self::parent, $compiler->parser->current_buffer->to_smarty_php(), $_tpl->compiler->compileTemplate($_tpl, $nocache));
|
||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
||||
$_output = $_tpl->compiler->compileTemplate($_tpl, $nocache) . $compiler->parser->current_buffer->to_smarty_php();
|
||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
|
||||
$_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->compiler->compileTemplate($_tpl, $nocache);
|
||||
} elseif (!empty($compiler->template->block_data[$_name])) {
|
||||
$_output = $_tpl->compiler->compileTemplate($_tpl, $nocache);
|
||||
}
|
||||
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
|
||||
$compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $_tpl->properties['function']);
|
||||
$compiler->merged_templates = array_merge($compiler->merged_templates, $_tpl->compiler->merged_templates);
|
||||
$compiler->template->variable_filters = $_tpl->variable_filters;
|
||||
if ($_tpl->has_nocache_code) {
|
||||
$compiler->template->has_nocache_code = true;
|
||||
}
|
||||
foreach ($_tpl->required_plugins as $key => $tmp1) {
|
||||
if ($compiler->nocache && $compiler->template->caching) {
|
||||
$code = 'nocache';
|
||||
} else {
|
||||
$code = $key;
|
||||
}
|
||||
foreach ($tmp1 as $name => $tmp) {
|
||||
foreach ($tmp as $type => $data) {
|
||||
$compiler->template->required_plugins[$code][$name][$type] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($_tpl);
|
||||
$compiler->has_code = true;
|
||||
return $_output;
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
$compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][1] = true;
|
||||
$output = "<?php \n\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 2, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile $smarty.block.parent
|
||||
*
|
||||
* @param object $compiler compiler object
|
||||
* @param string $_name optional name of child block
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param string $_name optional name of child block
|
||||
*
|
||||
* @return string compiled code of child block
|
||||
*/
|
||||
static function compileParentBlock($compiler, $_name = null)
|
||||
static function compileParentBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null)
|
||||
{
|
||||
// if called by {$smarty.block.parent} we must search the name of enclosing {block}
|
||||
if ($_name == null) {
|
||||
$stack_count = count($compiler->_tag_stack);
|
||||
while (--$stack_count >= 0) {
|
||||
if ($compiler->_tag_stack[$stack_count][0] == 'block') {
|
||||
$_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "\"'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isset($compiler->_cache['blockNesting'])) {
|
||||
$compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ',
|
||||
$compiler->parser->lex->taglineno);
|
||||
}
|
||||
if ($_name == null) {
|
||||
$compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->lex->taglineno);
|
||||
}
|
||||
if (empty(Smarty_Internal_Compile_Block::$nested_block_names)) {
|
||||
$compiler->trigger_template_error(' illegal {$smarty.block.parent} in parent template ', $compiler->lex->taglineno);
|
||||
}
|
||||
Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= Smarty_Internal_Compile_Block::parent;
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
$compiler->has_code = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process block source
|
||||
*
|
||||
* @param $compiler
|
||||
* @param string $source source text
|
||||
*
|
||||
*/
|
||||
static function blockSource($compiler, $source)
|
||||
{
|
||||
Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= $source;
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
$compiler->has_code = true;
|
||||
$output = "<?php \n\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 3, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n";
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile BlockClose Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
|
||||
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_Inheritance
|
||||
{
|
||||
/**
|
||||
* Compiles code for the {/block} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @return bool true
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
list($_attr, $_nocache, $_buffer, $_has_nocache_code, $_caching) = $this->closeTag($compiler, array('block'));
|
||||
// init block parameter
|
||||
$_block = $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']];
|
||||
unset($compiler->_cache['blockParams'][$compiler->_cache['blockNesting']]);
|
||||
$_block[2] = $_block[3] = 0;
|
||||
$_name = trim($_attr['name'], "'\"");
|
||||
$_assign = isset($_attr['assign']) ? $_attr['assign'] : null;
|
||||
unset($_attr['assign'], $_attr['name']);
|
||||
foreach ($_attr as $name => $stat) {
|
||||
if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat != 'false')) {
|
||||
$_block[$name] = is_string($stat) ? trim($stat, "'\"") : $stat;
|
||||
}
|
||||
}
|
||||
$_funcName = $_block[0];
|
||||
// get compiled block code
|
||||
$_functionCode = $compiler->parser->current_buffer;
|
||||
// setup buffer for template function code
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
|
||||
if ($compiler->template->compiled->has_nocache_code) {
|
||||
// $compiler->parent_compiler->template->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching;
|
||||
$_block[6] = $_funcNameCaching = $_funcName . '_nocache';
|
||||
$output = "<?php\n";
|
||||
$output .= "/* {block '{$_name}'} {$compiler->template->source->type}:{$compiler->template->source->name} */\n";
|
||||
$output .= "function {$_funcNameCaching} (\$_smarty_tpl, \$_blockParentStack) {\n";
|
||||
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
|
||||
$output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n";
|
||||
if (isset($_assign)) {
|
||||
$output .= "ob_start();\n";
|
||||
}
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
$output));
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||||
$output = "<?php\n";
|
||||
if (isset($_assign)) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[{$_assign}] = new Smarty_Variable(ob_get_clean());\n";
|
||||
}
|
||||
$output .= "/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
|
||||
$output .= "}\n";
|
||||
$output .= "/* {/block '{$_name}'} */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
$output));
|
||||
$compiler->blockOrFunctionCode .= $f = $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
$this->compiler = $compiler;
|
||||
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
|
||||
array($this, 'removeNocache'),
|
||||
$_functionCode->to_smarty_php($compiler->parser)));
|
||||
$this->compiler = null;
|
||||
}
|
||||
$output = "<?php\n";
|
||||
$output .= "/* {block '{$_name}'} {$compiler->template->source->type}:{$compiler->template->source->name} */\n";
|
||||
$output .= "function {$_funcName}(\$_smarty_tpl, \$_blockParentStack) {\n";
|
||||
if (isset($_assign)) {
|
||||
$output .= "ob_start();\n";
|
||||
}
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
$output));
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||||
$output = "<?php\n";
|
||||
if (isset($_assign)) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[{$_assign}] = new Smarty_Variable(ob_get_clean());\n";
|
||||
}
|
||||
$output .= "}\n";
|
||||
$output .= "/* {/block '{$_name}'} */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
$output));
|
||||
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||
// nocache plugins must be copied
|
||||
if (!empty($compiler->template->compiled->required_plugins['nocache'])) {
|
||||
foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) {
|
||||
foreach ($tmp as $type => $data) {
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$plugin][$type] =
|
||||
$data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// restore old status
|
||||
$compiler->template->compiled->has_nocache_code = $_has_nocache_code;
|
||||
$compiler->tag_nocache = $compiler->nocache;
|
||||
$compiler->nocache = $_nocache;
|
||||
$compiler->parser->current_buffer = $_buffer;
|
||||
$output = "<?php \n";
|
||||
if ($compiler->_cache['blockNesting'] == 1) {
|
||||
$output .= "\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " .
|
||||
var_export($_block, true) . ");\n";
|
||||
} else {
|
||||
$output .= "\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " .
|
||||
var_export($_block, true) . ", \$_blockParentStack);\n";
|
||||
|
||||
}
|
||||
$output .= "?>\n";
|
||||
$compiler->_cache['blockNesting'] --;
|
||||
if ($compiler->_cache['blockNesting'] == 0) {
|
||||
unset($compiler->_cache['blockNesting']);
|
||||
}
|
||||
$compiler->has_code = true;
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$saved_data = $this->closeTag($compiler, array('block'));
|
||||
$_name = trim($saved_data[0]['name'], "\"'");
|
||||
// reset flag for {block} tag
|
||||
$compiler->inheritance = $saved_data[1];
|
||||
// check if we process an inheritance child template
|
||||
if ($compiler->inheritance_child) {
|
||||
$name1 = Smarty_Internal_Compile_Block::$nested_block_names[0];
|
||||
Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .= "{$compiler->smarty->left_delimiter}/private_child_block{$compiler->smarty->right_delimiter}";
|
||||
array_shift(Smarty_Internal_Compile_Block::$nested_block_names);
|
||||
if (!empty(Smarty_Internal_Compile_Block::$nested_block_names)) {
|
||||
$name2 = Smarty_Internal_Compile_Block::$nested_block_names[0];
|
||||
if (isset($compiler->template->block_data[$name1]) || !$saved_data[0]['hide']) {
|
||||
if (isset(Smarty_Internal_Compile_Block::$block_data[$name1]['child']) || !isset($compiler->template->block_data[$name1])) {
|
||||
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
|
||||
} else {
|
||||
if ($compiler->template->block_data[$name1]['mode'] == 'append') {
|
||||
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'] . $compiler->template->block_data[$name1]['source'];
|
||||
} elseif ($compiler->template->block_data[$name1]['mode'] == 'prepend') {
|
||||
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= $compiler->template->block_data[$name1]['source'] . Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
|
||||
} else {
|
||||
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= $compiler->template->block_data[$name1]['source'];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset(Smarty_Internal_Compile_Block::$block_data[$name1]);
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||
} else {
|
||||
if (isset($compiler->template->block_data[$name1]) || !$saved_data[0]['hide']) {
|
||||
if (isset($compiler->template->block_data[$name1]) && !isset(Smarty_Internal_Compile_Block::$block_data[$name1]['child'])) {
|
||||
if (strpos($compiler->template->block_data[$name1]['source'], Smarty_Internal_Compile_Block::parent) !== false) {
|
||||
$compiler->template->block_data[$name1]['source'] =
|
||||
str_replace(Smarty_Internal_Compile_Block::parent, Smarty_Internal_Compile_Block::$block_data[$name1]['source'], $compiler->template->block_data[$name1]['source']);
|
||||
} elseif ($compiler->template->block_data[$name1]['mode'] == 'prepend') {
|
||||
$compiler->template->block_data[$name1]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
|
||||
} elseif ($compiler->template->block_data[$name1]['mode'] == 'append') {
|
||||
$compiler->template->block_data[$name1]['source'] = Smarty_Internal_Compile_Block::$block_data[$name1]['source'] . $compiler->template->block_data[$name1]['source'];
|
||||
}
|
||||
} else {
|
||||
$compiler->template->block_data[$name1]['source'] = Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
|
||||
}
|
||||
$compiler->template->block_data[$name1]['mode'] = 'replace';
|
||||
if ($saved_data[0]['append']) {
|
||||
$compiler->template->block_data[$name1]['mode'] = 'append';
|
||||
}
|
||||
if ($saved_data[0]['prepend']) {
|
||||
$compiler->template->block_data[$name1]['mode'] = 'prepend';
|
||||
}
|
||||
}
|
||||
unset(Smarty_Internal_Compile_Block::$block_data[$name1]);
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
|
||||
}
|
||||
$compiler->has_code = false;
|
||||
return;
|
||||
}
|
||||
if (isset($compiler->template->block_data[$_name]) && !isset($compiler->template->block_data[$_name]['compiled'])) {
|
||||
$_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name);
|
||||
} else {
|
||||
if ($saved_data[0]['hide'] && !isset($compiler->template->block_data[$_name]['source'])) {
|
||||
$_output = '';
|
||||
} else {
|
||||
$_output = $compiler->parser->current_buffer->to_smarty_php();
|
||||
}
|
||||
}
|
||||
unset($compiler->template->block_data[$_name]['compiled']);
|
||||
// reset flags
|
||||
$compiler->parser->current_buffer = $saved_data[2];
|
||||
if ($compiler->nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
$compiler->nocache = $saved_data[3];
|
||||
// $_output content has already nocache code processed
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
|
||||
return $_output;
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Child Block Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_CompileBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
* @param $match
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
* @return mixed
|
||||
*/
|
||||
public $required_attributes = array('name', 'file', 'uid', 'line', 'type', 'resource');
|
||||
|
||||
/**
|
||||
* Compiles code for the {private_child_block} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
*
|
||||
* @return boolean true
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
function removeNocache($match)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
// update template with original template resource of {block}
|
||||
if (trim($_attr['type'], "'") == 'file') {
|
||||
$compiler->template->template_resource = 'file:' . realpath(trim($_attr['file'], "'"));
|
||||
} else {
|
||||
$compiler->template->template_resource = trim($_attr['resource'], "'");
|
||||
}
|
||||
// source object
|
||||
unset ($compiler->template->source);
|
||||
$exists = $compiler->template->source->exists;
|
||||
|
||||
// must merge includes
|
||||
if ($_attr['nocache'] == true) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
$save = array($_attr, $compiler->nocache);
|
||||
|
||||
// set trace back to child block
|
||||
$compiler->pushTrace(trim($_attr['file'], "\"'"), trim($_attr['uid'], "\"'"), $_attr['line'] - $compiler->lex->line);
|
||||
|
||||
$this->openTag($compiler, 'private_child_block', $save);
|
||||
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
$compiler->has_code = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Child Block Close Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Child_Blockclose extends Smarty_Internal_CompileBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Compiles code for the {/private_child_block} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
*
|
||||
* @return boolean true
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
$saved_data = $this->closeTag($compiler, array('private_child_block'));
|
||||
|
||||
// end of child block
|
||||
$compiler->popTrace();
|
||||
|
||||
$compiler->nocache = $saved_data[1];
|
||||
$compiler->has_code = false;
|
||||
|
||||
return true;
|
||||
$code =
|
||||
preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
|
||||
'', $match[0]);
|
||||
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('levels');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -34,25 +35,26 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {break} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
if ($_attr['nocache'] === true) {
|
||||
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('nocache option not allowed', null, true);
|
||||
}
|
||||
|
||||
if (isset($_attr['levels'])) {
|
||||
if (!is_numeric($_attr['levels'])) {
|
||||
$compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
|
||||
}
|
||||
$_levels = $_attr['levels'];
|
||||
} else {
|
||||
@ -67,7 +69,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
|
||||
$stack_count --;
|
||||
}
|
||||
if ($level_count != 0) {
|
||||
$compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error("cannot break {$_levels} level(s)", null, true);
|
||||
}
|
||||
|
||||
return "<?php break {$_levels};?>";
|
||||
|
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -55,13 +57,11 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
|
||||
// output will be stored in a smarty variable instead of being displayed
|
||||
$_assign = $_attr['assign'];
|
||||
}
|
||||
//$_name = trim($_attr['name'], "'\"");
|
||||
$_name = $_attr['name'];
|
||||
if ($compiler->compiles_template_function) {
|
||||
$compiler->called_functions[] = trim($_name, "'\"");
|
||||
}
|
||||
unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
|
||||
// set flag (compiled code of {function} must be included in cache file
|
||||
if ($compiler->nocache || $compiler->tag_nocache) {
|
||||
if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) {
|
||||
$_nocache = 'true';
|
||||
} else {
|
||||
$_nocache = 'false';
|
||||
@ -74,54 +74,16 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
|
||||
$_paramsArray[] = "'$_key'=>$_value";
|
||||
}
|
||||
}
|
||||
if (isset($compiler->template->properties['function'][$_name]['parameter'])) {
|
||||
foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) {
|
||||
if (!isset($_attr[$_key])) {
|
||||
if (is_int($_key)) {
|
||||
$_paramsArray[] = "$_key=>$_value";
|
||||
} else {
|
||||
$_paramsArray[] = "'$_key'=>$_value";
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif (isset($compiler->smarty->template_functions[$_name]['parameter'])) {
|
||||
foreach ($compiler->smarty->template_functions[$_name]['parameter'] as $_key => $_value) {
|
||||
if (!isset($_attr[$_key])) {
|
||||
if (is_int($_key)) {
|
||||
$_paramsArray[] = "$_key=>$_value";
|
||||
} else {
|
||||
$_paramsArray[] = "'$_key'=>$_value";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//variable name?
|
||||
if (!(strpos($_name, '$') === false)) {
|
||||
$call_cache = $_name;
|
||||
$call_function = '$tmp = "smarty_template_function_".' . $_name . '; $tmp';
|
||||
} else {
|
||||
$_name = trim($_name, "'\"");
|
||||
$call_cache = "'{$_name}'";
|
||||
$call_function = 'smarty_template_function_' . $_name;
|
||||
}
|
||||
|
||||
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
||||
$_hash = str_replace('-', '_', $compiler->template->properties['nocache_hash']);
|
||||
//$compiler->suppressNocacheProcessing = true;
|
||||
// was there an assign attribute
|
||||
if (isset($_assign)) {
|
||||
if ($compiler->template->caching) {
|
||||
$_output = "<?php ob_start(); Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
|
||||
} else {
|
||||
$_output = "<?php ob_start(); {$call_function}(\$_smarty_tpl,{$_params}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
|
||||
}
|
||||
$_output =
|
||||
"<?php ob_start();\n\$_smarty_tpl->smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
|
||||
} else {
|
||||
if ($compiler->template->caching) {
|
||||
$_output = "<?php Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache});?>\n";
|
||||
} else {
|
||||
$_output = "<?php {$call_function}(\$_smarty_tpl,{$_params});?>\n";
|
||||
}
|
||||
$_output =
|
||||
"<?php \$_smarty_tpl->smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n";
|
||||
}
|
||||
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -34,12 +35,12 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {capture} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@ -51,10 +52,31 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
|
||||
$compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache);
|
||||
// maybe nocache because of nocache variables
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
$_output = "<?php \$_smarty_tpl->_capture_stack[0][] = array($buffer, $assign, $append); ob_start(); ?>";
|
||||
$_output = "<?php \$_smarty_tpl->_cache['capture_stack'][] = array($buffer, $assign, $append); ob_start(); ?>";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles code for the {$smarty.capture.xxx}
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// make all lower case
|
||||
$parameter = array_map('strtolower', $parameter);
|
||||
$tag = trim($parameter[0], '"\'');
|
||||
if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) {
|
||||
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
|
||||
}
|
||||
return "isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,12 +90,12 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {/capture} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@ -84,11 +106,11 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
|
||||
|
||||
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]);
|
||||
|
||||
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack[0]);\n";
|
||||
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_cache['capture_stack']);\n";
|
||||
$_output .= "if (!empty(\$_capture_buffer)) {\n";
|
||||
$_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n";
|
||||
$_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n";
|
||||
$_output .= " Smarty::\$_smarty_vars['capture'][\$_capture_buffer]=ob_get_clean();\n";
|
||||
$_output .= "\$_smarty_tpl->_cache['__smarty_capture'][\$_capture_buffer]=ob_get_clean();\n";
|
||||
$_output .= "} else \$_smarty_tpl->capture_error();?>";
|
||||
|
||||
return $_output;
|
||||
|
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -30,30 +31,39 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('file', 'section');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('section', 'scope');
|
||||
public $optional_attributes = array('section', 'scope', 'bubble_up');
|
||||
|
||||
/**
|
||||
* Valid scope names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
|
||||
'smarty' => true, 'tpl_root' => true);
|
||||
|
||||
/**
|
||||
* Compiles code for the {config_load} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
static $_is_legal_scope = array('local' => true, 'parent' => true, 'root' => true, 'global' => true);
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
if ($_attr['nocache'] === true) {
|
||||
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('nocache option not allowed', null, true);
|
||||
}
|
||||
|
||||
// save possible attributes
|
||||
@ -63,19 +73,31 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
||||
} else {
|
||||
$section = 'null';
|
||||
}
|
||||
$scope = 'local';
|
||||
// scope setup
|
||||
$_scope = Smarty::SCOPE_LOCAL;
|
||||
if (isset($_attr['scope'])) {
|
||||
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
||||
if (isset($_is_legal_scope[$_attr['scope']])) {
|
||||
$scope = $_attr['scope'];
|
||||
} else {
|
||||
$compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
|
||||
if (!isset($this->valid_scopes[$_attr['scope']])) {
|
||||
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true);
|
||||
}
|
||||
if ($_attr['scope'] != 'local') {
|
||||
if ($_attr['scope'] == 'parent') {
|
||||
$_scope = Smarty::SCOPE_PARENT;
|
||||
} elseif ($_attr['scope'] == 'root') {
|
||||
$_scope = Smarty::SCOPE_ROOT;
|
||||
} elseif ($_attr['scope'] == 'global') {
|
||||
$_scope = Smarty::SCOPE_GLOBAL;
|
||||
} elseif ($_attr['scope'] == 'smarty') {
|
||||
$_scope = Smarty::SCOPE_SMARTY;
|
||||
} elseif ($_attr['scope'] == 'tpl_root') {
|
||||
$_scope = Smarty::SCOPE_TPL_ROOT;
|
||||
}
|
||||
$_scope += (isset($_attr['bubble_up']) && $_attr['bubble_up'] == 'false') ? 0 : Smarty::SCOPE_BUBBLE_UP;
|
||||
}
|
||||
}
|
||||
|
||||
// create config object
|
||||
$_output = "<?php \$_config = new Smarty_Internal_Config($conf_file, \$_smarty_tpl->smarty, \$_smarty_tpl);";
|
||||
$_output .= "\$_config->loadConfigVars($section, '$scope'); ?>";
|
||||
$_output =
|
||||
"<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('levels');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -34,25 +35,26 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {continue} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
if ($_attr['nocache'] === true) {
|
||||
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('nocache option not allowed', null, true);
|
||||
}
|
||||
|
||||
if (isset($_attr['levels'])) {
|
||||
if (!is_numeric($_attr['levels'])) {
|
||||
$compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
|
||||
}
|
||||
$_levels = $_attr['levels'];
|
||||
} else {
|
||||
@ -67,7 +69,7 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
|
||||
$stack_count --;
|
||||
}
|
||||
if ($level_count != 0) {
|
||||
$compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error("cannot continue {$_levels} level(s)", null, true);
|
||||
}
|
||||
|
||||
return "<?php continue {$_levels};?>";
|
||||
|
@ -34,8 +34,8 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
|
||||
$compiler->tag_nocache = true;
|
||||
|
||||
// display debug template
|
||||
$_output = "<?php \$_smarty_tpl->smarty->loadPlugin('Smarty_Internal_Debug'); Smarty_Internal_Debug::display_debug(\$_smarty_tpl); ?>";
|
||||
|
||||
$_output = "<?php \$_smarty_debug = new Smarty_Internal_Debug;\n \$_smarty_debug->display_debug(\$_smarty_tpl);\n";
|
||||
$_output .= "unset(\$_smarty_debug);\n?>";
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
|
||||
class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inheritance
|
||||
{
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
@ -24,6 +24,15 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('file');
|
||||
|
||||
/**
|
||||
* Array of names of optional attribute required by tag
|
||||
* use array('_any') if there is no restriction of attributes names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $optional_attributes = array('extends_resource');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -33,53 +42,93 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
|
||||
public $shorttag_order = array('file');
|
||||
|
||||
/**
|
||||
* Compiles code for the {extends} tag
|
||||
* Compiles code for the {extends} tag extends: resource
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('nocache option not allowed', $compiler->parser->lex->line - 1);
|
||||
}
|
||||
if (strpos($_attr['file'], '$_tmp') !== false) {
|
||||
$compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('illegal value for file attribute', $compiler->parser->lex->line - 1);
|
||||
}
|
||||
|
||||
$name = $_attr['file'];
|
||||
/** @var Smarty_Internal_Template $_smarty_tpl
|
||||
* used in evaluated code
|
||||
*/
|
||||
$_smarty_tpl = $compiler->template;
|
||||
eval("\$tpl_name = $name;");
|
||||
// create template object
|
||||
$_template = new $compiler->smarty->template_class($tpl_name, $compiler->smarty, $compiler->template);
|
||||
// check for recursion
|
||||
$uid = $_template->source->uid;
|
||||
if (isset($compiler->extends_uid[$uid])) {
|
||||
$compiler->trigger_template_error("illegal recursive call of \"$include_file\"", $compiler->lex->line - 1);
|
||||
}
|
||||
$compiler->extends_uid[$uid] = true;
|
||||
if (empty($_template->source->components)) {
|
||||
array_unshift($compiler->sources, $_template->source);
|
||||
} else {
|
||||
foreach ($_template->source->components as $source) {
|
||||
array_unshift($compiler->sources, $source);
|
||||
$uid = $source->uid;
|
||||
if (isset($compiler->extends_uid[$uid])) {
|
||||
$compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - 1);
|
||||
// add code to initialize inheritance
|
||||
$this->registerInit($compiler, true);
|
||||
$file = trim($_attr['file'], '\'"');
|
||||
if (strlen($file) > 8 && substr($file, 0, 8) == 'extends:') {
|
||||
// generate code for each template
|
||||
$files = array_reverse(explode('|', substr($file, 8)));
|
||||
$i = 0;
|
||||
foreach ($files as $file) {
|
||||
if ($file[0] == '"') {
|
||||
$file = trim($file, '".');
|
||||
} else {
|
||||
$file = "'{$file}'";
|
||||
}
|
||||
$compiler->extends_uid[$uid] = true;
|
||||
$i ++;
|
||||
if ($i == count($files) && isset($_attr['extends_resource'])) {
|
||||
$this->compileEndChild($compiler);
|
||||
}
|
||||
$this->compileInclude($compiler, $file);
|
||||
}
|
||||
if (!isset($_attr['extends_resource'])) {
|
||||
$this->compileEndChild($compiler);
|
||||
}
|
||||
} else {
|
||||
$this->compileEndChild($compiler);
|
||||
$this->compileInclude($compiler, $_attr['file']);
|
||||
}
|
||||
unset ($_template);
|
||||
$compiler->inheritance_child = true;
|
||||
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
|
||||
$compiler->has_code = false;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add code for inheritance endChild() method to end of template
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
*/
|
||||
private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
"<?php \$_smarty_tpl->ext->_inheritance->endChild(\$_smarty_tpl);\n?>\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add code for including subtemplate to end of template
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
* @param string $file subtemplate name
|
||||
*/
|
||||
private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $file)
|
||||
{
|
||||
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
$compiler->compileTag('include',
|
||||
array($file,
|
||||
array('scope' => 'parent'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create source code for {extends} from source components array
|
||||
*
|
||||
* @param []\Smarty_Internal_Template_Source $components
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function extendsSourceArrayCode($components)
|
||||
{
|
||||
$resources = array();
|
||||
foreach ($components as $source) {
|
||||
$resources[] = $source->resource;
|
||||
}
|
||||
return '{extends file=\'extends:' . join('|', $resources) . '\' extends_resource=true}';
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$compiler->loopNesting++;
|
||||
if ($parameter == 0) {
|
||||
$this->required_attributes = array('start', 'to');
|
||||
$this->optional_attributes = array('max', 'step');
|
||||
@ -44,30 +45,51 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
$output = "<?php ";
|
||||
$output = "<?php\n";
|
||||
if ($parameter == 1) {
|
||||
foreach ($_attr['start'] as $_statement) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;";
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value];\n";
|
||||
if (is_array($_statement['var'])) {
|
||||
$var = $_statement['var']['var'];
|
||||
$index = $_statement['var']['smarty_internal_index'];
|
||||
} else {
|
||||
$var = $_statement['var'];
|
||||
$index = '';
|
||||
}
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;\n";
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$var]->value{$index} = {$_statement['value']};\n";
|
||||
}
|
||||
$output .= " if ($_attr[ifexp]) { for (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$_attr[var]]->value$_attr[step]) {\n";
|
||||
if (is_array($_attr['var'])) {
|
||||
$var = $_attr['var']['var'];
|
||||
$index = $_attr['var']['smarty_internal_index'];
|
||||
} else {
|
||||
$var = $_attr['var'];
|
||||
$index = '';
|
||||
}
|
||||
$output .= "if ($_attr[ifexp]) {\nfor (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$var]->value{$index}$_attr[step]) {\n";
|
||||
} else {
|
||||
$_statement = $_attr['start'];
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]] = new Smarty_Variable;";
|
||||
if (isset($_attr['step'])) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = $_attr[step];";
|
||||
if (is_array($_statement['var'])) {
|
||||
$var = $_statement['var']['var'];
|
||||
$index = $_statement['var']['smarty_internal_index'];
|
||||
} else {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = 1;";
|
||||
$var = $_statement['var'];
|
||||
$index = '';
|
||||
}
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;";
|
||||
if (isset($_attr['step'])) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$var]->step = $_attr[step];";
|
||||
} else {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$var]->step = 1;";
|
||||
}
|
||||
if (isset($_attr['max'])) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->total = (int) min(ceil((\$_smarty_tpl->tpl_vars[$_statement[var]]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$_statement[var]]->step)),$_attr[max]);\n";
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$var]->total = (int) min(ceil((\$_smarty_tpl->tpl_vars[$var]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$var]->step)),$_attr[max]);\n";
|
||||
} else {
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->total = (int) ceil((\$_smarty_tpl->tpl_vars[$_statement[var]]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$_statement[var]]->step));\n";
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$var]->total = (int) ceil((\$_smarty_tpl->tpl_vars[$var]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$var]->step));\n";
|
||||
}
|
||||
$output .= "if (\$_smarty_tpl->tpl_vars[$_statement[var]]->total > 0) {\n";
|
||||
$output .= "for (\$_smarty_tpl->tpl_vars[$_statement[var]]->value = $_statement[value], \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration = 1;\$_smarty_tpl->tpl_vars[$_statement[var]]->iteration <= \$_smarty_tpl->tpl_vars[$_statement[var]]->total;\$_smarty_tpl->tpl_vars[$_statement[var]]->value += \$_smarty_tpl->tpl_vars[$_statement[var]]->step, \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration++) {\n";
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->first = \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration == 1;";
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->last = \$_smarty_tpl->tpl_vars[$_statement[var]]->iteration == \$_smarty_tpl->tpl_vars[$_statement[var]]->total;";
|
||||
$output .= "if (\$_smarty_tpl->tpl_vars[$var]->total > 0) {\n";
|
||||
$output .= "for (\$_smarty_tpl->tpl_vars[$var]->value{$index} = $_statement[value], \$_smarty_tpl->tpl_vars[$var]->iteration = 1;\$_smarty_tpl->tpl_vars[$var]->iteration <= \$_smarty_tpl->tpl_vars[$var]->total;\$_smarty_tpl->tpl_vars[$var]->value{$index} += \$_smarty_tpl->tpl_vars[$var]->step, \$_smarty_tpl->tpl_vars[$var]->iteration++) {\n";
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$var]->first = \$_smarty_tpl->tpl_vars[$var]->iteration == 1;";
|
||||
$output .= "\$_smarty_tpl->tpl_vars[$var]->last = \$_smarty_tpl->tpl_vars[$var]->iteration == \$_smarty_tpl->tpl_vars[$var]->total;";
|
||||
}
|
||||
$output .= "?>";
|
||||
|
||||
@ -127,6 +149,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
{
|
||||
$compiler->loopNesting--;
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// must endblock be nocache?
|
||||
@ -136,10 +159,11 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
|
||||
|
||||
list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse'));
|
||||
|
||||
if ($openTag == 'forelse') {
|
||||
return "<?php } ?>";
|
||||
} else {
|
||||
return "<?php }} ?>";
|
||||
}
|
||||
$output = "<?php }\n";
|
||||
if ($openTag != 'forelse') {
|
||||
$output .= "}\n";
|
||||
}
|
||||
$output .= "?>\n";
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
|
||||
class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_ForeachSection
|
||||
{
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('from', 'item');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('name', 'key');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -38,129 +40,229 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('from', 'item', 'key', 'name');
|
||||
|
||||
/**
|
||||
* counter
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $counter = 0;
|
||||
|
||||
/**
|
||||
* Name of this tag
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $tagName = 'foreach';
|
||||
|
||||
/**
|
||||
* Valid properties of $smarty.foreach.name.xxx variable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total');
|
||||
|
||||
/**
|
||||
* Valid properties of $item@xxx variable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $itemProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'key');
|
||||
|
||||
/**
|
||||
* Flag if tag had name attribute
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isNamed = false;
|
||||
|
||||
/**
|
||||
* Compiles code for the {foreach} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
$compiler->loopNesting ++;
|
||||
// init
|
||||
$this->isNamed = false;
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
$from = $_attr['from'];
|
||||
$item = $_attr['item'];
|
||||
if (!strncmp("\$_smarty_tpl->tpl_vars[$item]", $from, strlen($item) + 24)) {
|
||||
$compiler->trigger_template_error("item variable {$item} may not be the same variable as at 'from'", $compiler->lex->taglineno);
|
||||
$item = $compiler->getId($_attr['item']);
|
||||
if ($item === false) {
|
||||
$item = $compiler->getVariableName($_attr['item']);
|
||||
}
|
||||
|
||||
$attributes = array('item' => $item);
|
||||
if (isset($_attr['key'])) {
|
||||
$key = $_attr['key'];
|
||||
} else {
|
||||
$key = null;
|
||||
$key = $compiler->getId($_attr['key']);
|
||||
if ($key === false) {
|
||||
$key = $compiler->getVariableName($_attr['key']);
|
||||
}
|
||||
$attributes['key'] = $key;
|
||||
}
|
||||
if (isset($_attr['name'])) {
|
||||
$this->isNamed = true;
|
||||
$attributes['name'] = $compiler->getId($_attr['name']);
|
||||
}
|
||||
foreach ($attributes as $a => $v) {
|
||||
if ($v === false) {
|
||||
$compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true);
|
||||
}
|
||||
}
|
||||
$fromName = $compiler->getVariableName($_attr['from']);
|
||||
if ($fromName) {
|
||||
foreach (array('item', 'key') as $a) {
|
||||
if (isset($attributes[$a]) && $attributes[$a] == $fromName) {
|
||||
$compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'",
|
||||
null, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->openTag($compiler, 'foreach', array('foreach', $compiler->nocache, $item, $key));
|
||||
$itemVar = "\$_smarty_tpl->tpl_vars['{$item}']";
|
||||
$local = '$__foreach_' . (isset($attributes['name']) ? $attributes['name'] : $attributes['item']) . '_' .
|
||||
$this->counter ++ . '_';
|
||||
$needIteration = false;
|
||||
// search for used tag attributes
|
||||
$itemAttr = array();
|
||||
$namedAttr = array();
|
||||
$this->scanForProperties($attributes, $compiler);
|
||||
if (!empty($this->matchResults['item'])) {
|
||||
$itemAttr = $this->matchResults['item'];
|
||||
}
|
||||
if (!empty($this->matchResults['named'])) {
|
||||
$namedAttr = $this->matchResults['named'];
|
||||
}
|
||||
if (isset($itemAttr['last'])) {
|
||||
$needIteration = true;
|
||||
}
|
||||
if (isset($namedAttr['last'])) {
|
||||
$needIteration = true;
|
||||
}
|
||||
|
||||
$keyTerm = '';
|
||||
if (isset($itemAttr['key'])) {
|
||||
$keyTerm = "{$itemVar}->key => ";
|
||||
} elseif (isset($attributes['key'])) {
|
||||
$keyTerm = "\$_smarty_tpl->tpl_vars['{$key}']->value => ";
|
||||
}
|
||||
|
||||
$saveVars = array();
|
||||
$restoreVars = array();
|
||||
if ($this->isNamed) {
|
||||
$foreachVar = "\$_smarty_tpl->tpl_vars['__smarty_foreach_{$attributes['name']}']";
|
||||
if (!empty($namedAttr)) {
|
||||
$saveVars['saved'] = "isset({$foreachVar}) ? {$foreachVar} : false;";
|
||||
$restoreVars[] = "if ({$local}saved) {\n{$foreachVar} = {$local}saved;\n}\n";
|
||||
}
|
||||
}
|
||||
foreach (array('item', 'key') as $a) {
|
||||
if (isset($attributes[$a])) {
|
||||
$saveVars['saved_' . $a] =
|
||||
"isset(\$_smarty_tpl->tpl_vars['{$attributes[$a]}']) ? \$_smarty_tpl->tpl_vars['{$attributes[$a]}'] : false;";
|
||||
$restoreVars[] =
|
||||
"if ({$local}saved_{$a}) {\n\$_smarty_tpl->tpl_vars['{$attributes[$a]}'] = {$local}saved_{$a};\n}\n";
|
||||
}
|
||||
}
|
||||
$this->openTag($compiler, 'foreach',
|
||||
array('foreach', $compiler->nocache, $local, $restoreVars, $itemVar, true));
|
||||
// maybe nocache because of nocache variables
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
|
||||
if (isset($_attr['name'])) {
|
||||
$name = $_attr['name'];
|
||||
$has_name = true;
|
||||
$SmartyVarName = '$smarty.foreach.' . trim($name, '\'"') . '.';
|
||||
} else {
|
||||
$name = null;
|
||||
$has_name = false;
|
||||
}
|
||||
$ItemVarName = '$' . trim($item, '\'"') . '@';
|
||||
// evaluates which Smarty variables and properties have to be computed
|
||||
if ($has_name) {
|
||||
$usesSmartyFirst = strpos($compiler->lex->data, $SmartyVarName . 'first') !== false;
|
||||
$usesSmartyLast = strpos($compiler->lex->data, $SmartyVarName . 'last') !== false;
|
||||
$usesSmartyIndex = strpos($compiler->lex->data, $SmartyVarName . 'index') !== false;
|
||||
$usesSmartyIteration = strpos($compiler->lex->data, $SmartyVarName . 'iteration') !== false;
|
||||
$usesSmartyShow = strpos($compiler->lex->data, $SmartyVarName . 'show') !== false;
|
||||
$usesSmartyTotal = strpos($compiler->lex->data, $SmartyVarName . 'total') !== false;
|
||||
} else {
|
||||
$usesSmartyFirst = false;
|
||||
$usesSmartyLast = false;
|
||||
$usesSmartyTotal = false;
|
||||
$usesSmartyShow = false;
|
||||
}
|
||||
|
||||
$usesPropFirst = $usesSmartyFirst || strpos($compiler->lex->data, $ItemVarName . 'first') !== false;
|
||||
$usesPropLast = $usesSmartyLast || strpos($compiler->lex->data, $ItemVarName . 'last') !== false;
|
||||
$usesPropIndex = $usesPropFirst || strpos($compiler->lex->data, $ItemVarName . 'index') !== false;
|
||||
$usesPropIteration = $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'iteration') !== false;
|
||||
$usesPropShow = strpos($compiler->lex->data, $ItemVarName . 'show') !== false;
|
||||
$usesPropTotal = $usesSmartyTotal || $usesSmartyShow || $usesPropShow || $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'total') !== false;
|
||||
// generate output code
|
||||
$output = "<?php ";
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable; \$_smarty_tpl->tpl_vars[$item]->_loop = false;\n";
|
||||
if ($key != null) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable;\n";
|
||||
$output = "<?php\n";
|
||||
$output .= "\$_from = $from;\n";
|
||||
$output .= "if (!is_array(\$_from) && !is_object(\$_from)) {\n";
|
||||
$output .= "settype(\$_from, 'array');\n";
|
||||
$output .= "}\n";
|
||||
foreach ($saveVars as $k => $code) {
|
||||
$output .= "{$local}{$k} = {$code}\n";
|
||||
}
|
||||
$output .= " \$_from = $from; if (!is_array(\$_from) && !is_object(\$_from)) { settype(\$_from, 'array');}\n";
|
||||
if ($usesPropTotal) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->total= \$_smarty_tpl->_count(\$_from);\n";
|
||||
$output .= "{$itemVar} = new Smarty_Variable();\n";
|
||||
$output .= "{$local}total = \$_smarty_tpl->smarty->ext->_foreach->count(\$_from);\n";
|
||||
if (isset($itemAttr['show'])) {
|
||||
$output .= "{$itemVar}->show = ({$local}total > 0);\n";
|
||||
}
|
||||
if ($usesPropIteration) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->iteration=0;\n";
|
||||
if (isset($itemAttr['total'])) {
|
||||
$output .= "{$itemVar}->total= {$local}total;\n";
|
||||
}
|
||||
if ($usesPropIndex) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->index=-1;\n";
|
||||
}
|
||||
if ($usesPropShow) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->show = (\$_smarty_tpl->tpl_vars[$item]->total > 0);\n";
|
||||
}
|
||||
if ($has_name) {
|
||||
if ($usesSmartyTotal) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['total'] = \$_smarty_tpl->tpl_vars[$item]->total;\n";
|
||||
if ($this->isNamed) {
|
||||
$prop = array();
|
||||
if (isset($namedAttr['total'])) {
|
||||
$prop['total'] = "'total' => {$local}total";
|
||||
}
|
||||
if ($usesSmartyIteration) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['iteration']=0;\n";
|
||||
if (isset($namedAttr['iteration'])) {
|
||||
$prop['iteration'] = "'iteration' => 0";
|
||||
}
|
||||
if ($usesSmartyIndex) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['index']=-1;\n";
|
||||
if (isset($namedAttr['index'])) {
|
||||
$prop['index'] = "'index' => -1";
|
||||
}
|
||||
if ($usesSmartyShow) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['show']=(\$_smarty_tpl->tpl_vars[$item]->total > 0);\n";
|
||||
if (isset($namedAttr['show'])) {
|
||||
$prop['show'] = "'show' => ({$local}total > 0)";
|
||||
}
|
||||
if (!empty($namedAttr)) {
|
||||
$_vars = 'array(' . join(', ', $prop) . ')';
|
||||
$output .= "{$foreachVar} = new Smarty_Variable({$_vars});\n";
|
||||
}
|
||||
}
|
||||
$output .= "foreach (\$_from as \$_smarty_tpl->tpl_vars[$item]->key => \$_smarty_tpl->tpl_vars[$item]->value) {\n\$_smarty_tpl->tpl_vars[$item]->_loop = true;\n";
|
||||
if ($key != null) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$key]->value = \$_smarty_tpl->tpl_vars[$item]->key;\n";
|
||||
$output .= "if ({$local}total) {\n";
|
||||
if (isset($attributes['key'])) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars['{$key}'] = new Smarty_Variable();\n";
|
||||
}
|
||||
if ($usesPropIteration) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->iteration++;\n";
|
||||
if (isset($namedAttr['first']) || isset($itemAttr['first'])) {
|
||||
$output .= "{$local}first = true;\n";
|
||||
}
|
||||
if ($usesPropIndex) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->index++;\n";
|
||||
if (isset($itemAttr['iteration'])) {
|
||||
$output .= "{$itemVar}->iteration=0;\n";
|
||||
}
|
||||
if ($usesPropFirst) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->first = \$_smarty_tpl->tpl_vars[$item]->index === 0;\n";
|
||||
if (isset($itemAttr['index'])) {
|
||||
$output .= "{$itemVar}->index=-1;\n";
|
||||
}
|
||||
if ($usesPropLast) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars[$item]->last = \$_smarty_tpl->tpl_vars[$item]->iteration === \$_smarty_tpl->tpl_vars[$item]->total;\n";
|
||||
if ($needIteration) {
|
||||
$output .= "{$local}iteration=0;\n";
|
||||
}
|
||||
if ($has_name) {
|
||||
if ($usesSmartyFirst) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['first'] = \$_smarty_tpl->tpl_vars[$item]->first;\n";
|
||||
$output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
|
||||
if (isset($attributes['key']) && isset($itemAttr['key'])) {
|
||||
$output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n";
|
||||
}
|
||||
if (isset($itemAttr['iteration'])) {
|
||||
$output .= "{$itemVar}->iteration++;\n";
|
||||
}
|
||||
if (isset($itemAttr['index'])) {
|
||||
$output .= "{$itemVar}->index++;\n";
|
||||
}
|
||||
if ($needIteration) {
|
||||
$output .= "{$local}iteration++;\n";
|
||||
}
|
||||
if (isset($itemAttr['first'])) {
|
||||
$output .= "{$itemVar}->first = {$local}first;\n";
|
||||
}
|
||||
if (isset($itemAttr['last'])) {
|
||||
$output .= "{$itemVar}->last = {$local}iteration == {$local}total;\n";
|
||||
}
|
||||
if ($this->isNamed) {
|
||||
if (isset($namedAttr['iteration'])) {
|
||||
$output .= "{$foreachVar}->value['iteration']++;\n";
|
||||
}
|
||||
if ($usesSmartyIteration) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['iteration']++;\n";
|
||||
if (isset($namedAttr['index'])) {
|
||||
$output .= "{$foreachVar}->value['index']++;\n";
|
||||
}
|
||||
if ($usesSmartyIndex) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['index']++;\n";
|
||||
if (isset($namedAttr['first'])) {
|
||||
$output .= "{$foreachVar}->value['first'] = {$local}first;\n";
|
||||
}
|
||||
if ($usesSmartyLast) {
|
||||
$output .= " \$_smarty_tpl->tpl_vars['smarty']->value['foreach'][$name]['last'] = \$_smarty_tpl->tpl_vars[$item]->last;\n";
|
||||
if (isset($namedAttr['last'])) {
|
||||
$output .= "{$foreachVar}->value['last'] = {$local}iteration == {$local}total;\n";
|
||||
}
|
||||
}
|
||||
if (isset($namedAttr['first']) || isset($itemAttr['first'])) {
|
||||
$output .= "{$local}first = false;\n";
|
||||
}
|
||||
$output .= "{$local}saved_local_item = {$itemVar};\n";
|
||||
$output .= "?>";
|
||||
|
||||
return $output;
|
||||
@ -178,21 +280,24 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {foreachelse} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
list($openTag, $nocache, $item, $key) = $this->closeTag($compiler, array('foreach'));
|
||||
$this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $item, $key));
|
||||
|
||||
return "<?php }\nif (!\$_smarty_tpl->tpl_vars[$item]->_loop) {\n?>";
|
||||
list($openTag, $nocache, $local, $restoreVars, $itemVar, $foo) = $this->closeTag($compiler, array('foreach'));
|
||||
$this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $restoreVars, $itemVar, false));
|
||||
$output = "<?php\n";
|
||||
$output .= "{$itemVar} = {$local}saved_local_item;\n";
|
||||
$output .= "}\n";
|
||||
$output .= "} else {\n?>";
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,23 +312,34 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {/foreach} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$compiler->loopNesting --;
|
||||
// must endblock be nocache?
|
||||
if ($compiler->nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
list($openTag, $compiler->nocache, $item, $key) = $this->closeTag($compiler, array('foreach', 'foreachelse'));
|
||||
list($openTag, $compiler->nocache, $local, $restoreVars, $itemVar, $restore) =
|
||||
$this->closeTag($compiler, array('foreach', 'foreachelse'));
|
||||
$output = "<?php\n";
|
||||
|
||||
return "<?php } ?>";
|
||||
if ($restore) {
|
||||
$output .= "{$itemVar} = {$local}saved_local_item;\n";
|
||||
$output .= "}\n";
|
||||
}
|
||||
$output .= "}\n";
|
||||
foreach ($restoreVars as $restore) {
|
||||
$output .= $restore;
|
||||
}
|
||||
$output .= "?>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -23,6 +24,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -30,6 +32,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -41,54 +44,31 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {function} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return boolean true
|
||||
* @return bool true
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
$compiler->loopNesting++;
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
if ($_attr['nocache'] === true) {
|
||||
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('nocache option not allowed', null, true);
|
||||
}
|
||||
unset($_attr['nocache']);
|
||||
$save = array($_attr, $compiler->parser->current_buffer,
|
||||
$compiler->template->has_nocache_code, $compiler->template->required_plugins);
|
||||
$this->openTag($compiler, 'function', $save);
|
||||
$_name = trim($_attr['name'], "'\"");
|
||||
unset($_attr['name']);
|
||||
// set flag that we are compiling a template function
|
||||
$compiler->compiles_template_function = true;
|
||||
$compiler->template->properties['function'][$_name]['parameter'] = array();
|
||||
/** @var Smarty_Internal_Template $_smarty_tpl
|
||||
* used in evaluated code
|
||||
*/
|
||||
$_smarty_tpl = $compiler->template;
|
||||
foreach ($_attr as $_key => $_data) {
|
||||
eval ('$tmp=' . $_data . ';');
|
||||
$compiler->template->properties['function'][$_name]['parameter'][$_key] = $tmp;
|
||||
}
|
||||
$compiler->smarty->template_functions[$_name]['parameter'] = $compiler->template->properties['function'][$_name]['parameter'];
|
||||
if ($compiler->template->caching) {
|
||||
$output = '';
|
||||
} else {
|
||||
$output = "<?php if (!function_exists('smarty_template_function_{$_name}')) {
|
||||
function smarty_template_function_{$_name}(\$_smarty_tpl,\$params) {
|
||||
\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;
|
||||
foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);};
|
||||
foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";
|
||||
}
|
||||
$compiler->parent_compiler->template->tpl_function[$_name] = array();
|
||||
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
|
||||
$compiler->template->caching);
|
||||
$this->openTag($compiler, 'function', $save);
|
||||
// Init temporary context
|
||||
$compiler->template->required_plugins = array('compiled' => array(), 'nocache' => array());
|
||||
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
|
||||
$compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output));
|
||||
$compiler->template->has_nocache_code = false;
|
||||
$compiler->has_code = false;
|
||||
$compiler->template->properties['function'][$_name]['compiled'] = '';
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
$compiler->template->compiled->has_nocache_code = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -101,62 +81,130 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Compiler object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $compiler = null;
|
||||
|
||||
/**
|
||||
* Compiles code for the {/function} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object|\Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return boolean true
|
||||
* @return bool true
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$compiler->loopNesting--;
|
||||
$this->compiler = $compiler;
|
||||
$saved_data = $this->closeTag($compiler, array('function'));
|
||||
$_name = trim($saved_data[0]['name'], "'\"");
|
||||
// build plugin include code
|
||||
$plugins_string = '';
|
||||
if (!empty($compiler->template->required_plugins['compiled'])) {
|
||||
$plugins_string = '<?php ';
|
||||
foreach ($compiler->template->required_plugins['compiled'] as $tmp) {
|
||||
foreach ($tmp as $data) {
|
||||
$plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n";
|
||||
}
|
||||
$_attr = $saved_data[0];
|
||||
$_name = trim($_attr['name'], "'\"");
|
||||
$compiler->parent_compiler->template->tpl_function[$_name]['called_functions'] = $compiler->called_functions;
|
||||
$compiler->parent_compiler->template->tpl_function[$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath;
|
||||
$compiler->parent_compiler->template->tpl_function[$_name]['uid'] = $compiler->template->source->uid;
|
||||
$compiler->called_functions = array();
|
||||
$_parameter = $_attr;
|
||||
unset($_parameter['name']);
|
||||
// default parameter
|
||||
$_paramsArray = array();
|
||||
foreach ($_parameter as $_key => $_value) {
|
||||
if (is_int($_key)) {
|
||||
$_paramsArray[] = "$_key=>$_value";
|
||||
} else {
|
||||
$_paramsArray[] = "'$_key'=>$_value";
|
||||
}
|
||||
$plugins_string .= '?>';
|
||||
}
|
||||
if (!empty($compiler->template->required_plugins['nocache'])) {
|
||||
$plugins_string .= "<?php echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
|
||||
foreach ($compiler->template->required_plugins['nocache'] as $tmp) {
|
||||
foreach ($tmp as $data) {
|
||||
$plugins_string .= "if (!is_callable(\'{$data['function']}\')) include \'{$data['file']}\';\n";
|
||||
}
|
||||
}
|
||||
$plugins_string .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';?>\n";
|
||||
}
|
||||
// if caching save template function for possible nocache call
|
||||
if ($compiler->template->caching) {
|
||||
$compiler->template->properties['function'][$_name]['compiled'] .= $plugins_string
|
||||
. $compiler->parser->current_buffer->to_smarty_php();
|
||||
$compiler->template->properties['function'][$_name]['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
||||
$compiler->template->properties['function'][$_name]['has_nocache_code'] = $compiler->template->has_nocache_code;
|
||||
$compiler->template->properties['function'][$_name]['called_functions'] = $compiler->called_functions;
|
||||
$compiler->called_functions = array();
|
||||
$compiler->smarty->template_functions[$_name] = $compiler->template->properties['function'][$_name];
|
||||
$compiler->has_code = false;
|
||||
$output = true;
|
||||
if (!empty($_paramsArray)) {
|
||||
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
||||
$_paramsCode = "\$params = array_merge($_params, \$params);\n";
|
||||
} else {
|
||||
$output = $plugins_string . $compiler->parser->current_buffer->to_smarty_php() . "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;
|
||||
foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl->tpl_vars[\$key])) \$_smarty_tpl->tpl_vars[\$key] = \$value;}}?>\n";
|
||||
$_paramsCode = '';
|
||||
}
|
||||
// reset flag that we are compiling a template function
|
||||
$compiler->compiles_template_function = false;
|
||||
// restore old compiler status
|
||||
$compiler->parser->current_buffer = $saved_data[1];
|
||||
$compiler->template->has_nocache_code = $compiler->template->has_nocache_code | $saved_data[2];
|
||||
$compiler->template->required_plugins = $saved_data[3];
|
||||
$_functionCode = $compiler->parser->current_buffer;
|
||||
// setup buffer for template function code
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
|
||||
return $output;
|
||||
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}";
|
||||
$_funcNameCaching = $_funcName . '_nocache';
|
||||
if ($compiler->template->compiled->has_nocache_code) {
|
||||
$compiler->parent_compiler->template->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching;
|
||||
$output = "<?php\n";
|
||||
$output .= "/* {$_funcNameCaching} */\n";
|
||||
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
|
||||
$output .= "function {$_funcNameCaching} (\$_smarty_tpl,\$params) {\n";
|
||||
$output .= "ob_start();\n";
|
||||
$output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n";
|
||||
$output .= $_paramsCode;
|
||||
$output .= "\$_smarty_tpl->_cache['saved_tpl_vars'][] = \$_smarty_tpl->tpl_vars;\n";
|
||||
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}";
|
||||
$output .= "\$params = var_export(\$params, true);\n";
|
||||
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
|
||||
$output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value);\n}\n?>";
|
||||
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n\";?>";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||||
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
|
||||
$output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value){\n";
|
||||
$output .= "if (!isset(\\\$_smarty_tpl->tpl_vars[\\\$key]) || \\\$_smarty_tpl->tpl_vars[\\\$key] === \\\$value) \\\$saved_tpl_vars[\\\$key] = \\\$value;\n}\n";
|
||||
$output .= "\\\$_smarty_tpl->tpl_vars = \\\$saved_tpl_vars;?>\n";
|
||||
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>";
|
||||
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash, ob_get_clean());\n";
|
||||
$output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->_cache['saved_tpl_vars']);\n}\n}\n";
|
||||
$output .= "/*/ {$_funcName}_nocache */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", array($this,
|
||||
'removeNocache'), $_functionCode->to_smarty_php($compiler->parser)));
|
||||
}
|
||||
$compiler->parent_compiler->template->tpl_function[$_name]['call_name'] = $_funcName;
|
||||
$output = "<?php\n";
|
||||
$output .= "/* {$_funcName} */\n";
|
||||
$output .= "if (!function_exists('{$_funcName}')) {\n";
|
||||
$output .= "function {$_funcName}(\$_smarty_tpl,\$params) {\n";
|
||||
$output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n";
|
||||
$output .= $_paramsCode;
|
||||
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||||
$output = "<?php foreach (Smarty::\$global_tpl_vars as \$key => \$value){\n";
|
||||
$output .= "if (!isset(\$_smarty_tpl->tpl_vars[\$key]) || \$_smarty_tpl->tpl_vars[\$key] === \$value) \$saved_tpl_vars[\$key] = \$value;\n}\n";
|
||||
$output .= "\$_smarty_tpl->tpl_vars = \$saved_tpl_vars;\n}\n}\n";
|
||||
$output .= "/*/ {$_funcName} */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||
// nocache plugins must be copied
|
||||
if (!empty($compiler->template->compiled->required_plugins['nocache'])) {
|
||||
foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) {
|
||||
foreach ($tmp as $type => $data) {
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$plugin][$type] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
// restore old buffer
|
||||
|
||||
$compiler->parser->current_buffer = $saved_data[1];
|
||||
// restore old status
|
||||
$compiler->template->compiled->has_nocache_code = $saved_data[2];
|
||||
$compiler->template->caching = $saved_data[3];
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $match
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function removeNocache($match)
|
||||
{
|
||||
$code = preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", '', $match[0]);
|
||||
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,14 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {if} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@ -34,7 +35,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
|
||||
if (!array_key_exists("if condition", $parameter)) {
|
||||
$compiler->trigger_template_error("missing if condition", $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error("missing if condition", null, true);
|
||||
}
|
||||
|
||||
if (is_array($parameter['if condition'])) {
|
||||
@ -42,19 +43,32 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
|
||||
$_nocache = ',true';
|
||||
// create nocache var to make it know for further compiling
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
|
||||
$var = trim($parameter['if condition']['var']['var'], "'");
|
||||
} else {
|
||||
$compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
|
||||
$var = trim($parameter['if condition']['var'], "'");
|
||||
}
|
||||
if (isset($compiler->template->tpl_vars[$var])) {
|
||||
$compiler->template->tpl_vars[$var]->nocache = true;
|
||||
} else {
|
||||
$compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true);
|
||||
}
|
||||
} else {
|
||||
$_nocache = '';
|
||||
}
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
||||
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
||||
"]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] .
|
||||
"$_nocache);\n";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
||||
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
} else {
|
||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
|
||||
"])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
|
||||
"] = new Smarty_Variable(null{$_nocache});";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
}
|
||||
|
||||
return $_output;
|
||||
@ -75,13 +89,13 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {else} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
|
||||
$this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
|
||||
@ -101,13 +115,14 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {elseif} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@ -115,7 +130,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
|
||||
|
||||
if (!array_key_exists("if condition", $parameter)) {
|
||||
$compiler->trigger_template_error("missing elseif condition", $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error("missing elseif condition", null, true);
|
||||
}
|
||||
|
||||
if (is_array($parameter['if condition'])) {
|
||||
@ -124,9 +139,14 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
$_nocache = ',true';
|
||||
// create nocache var to make it know for further compiling
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
|
||||
$var = trim($parameter['if condition']['var']['var'], "'");
|
||||
} else {
|
||||
$compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
|
||||
$var = trim($parameter['if condition']['var'], "'");
|
||||
}
|
||||
if (isset($compiler->template->tpl_vars[$var])) {
|
||||
$compiler->template->tpl_vars[$var]->nocache = true;
|
||||
} else {
|
||||
$compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true);
|
||||
}
|
||||
} else {
|
||||
$_nocache = '';
|
||||
@ -139,11 +159,20 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
if ($condition_by_assign) {
|
||||
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" .
|
||||
$parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" .
|
||||
$parameter['if condition']['var']['var'] .
|
||||
"]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " .
|
||||
$parameter['if condition']['var']['var'] . "$_nocache);\n";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
||||
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
} else {
|
||||
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" .
|
||||
$parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" .
|
||||
$parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
}
|
||||
|
||||
return $_output;
|
||||
@ -155,22 +184,35 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
|
||||
} else {
|
||||
$tmp = '';
|
||||
foreach ($compiler->prefix_code as $code) {
|
||||
$tmp .= $code;
|
||||
$tmp = $compiler->appendCode($tmp, $code);
|
||||
}
|
||||
$compiler->prefix_code = array();
|
||||
$tmp = $compiler->appendCode("<?php } else {?>", $tmp);
|
||||
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
|
||||
if ($condition_by_assign) {
|
||||
if (is_array($parameter['if condition']['var'])) {
|
||||
$_output = "<?php } else {?>{$tmp}<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" .
|
||||
$parameter['if condition']['var']['var'] .
|
||||
"]) || !is_array(\$_smarty_tpl->tpl_vars[" .
|
||||
$parameter['if condition']['var']['var'] .
|
||||
"]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " .
|
||||
$parameter['if condition']['var']['var'] . "$_nocache);\n");
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
||||
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
} else {
|
||||
$_output = "<?php } else {?>{$tmp}<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
|
||||
$_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" .
|
||||
$parameter['if condition']['var'] .
|
||||
"])) \$_smarty_tpl->tpl_vars[" .
|
||||
$parameter['if condition']['var'] .
|
||||
"] = new Smarty_Variable(null{$_nocache});");
|
||||
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
|
||||
$parameter['if condition']['value'] . ") {?>";
|
||||
}
|
||||
|
||||
return $_output;
|
||||
} else {
|
||||
return "<?php } else {?>{$tmp}<?php if ({$parameter['if condition']}) {?>";
|
||||
return $compiler->appendCode($tmp, "<?php if ({$parameter['if condition']}) {?>");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -187,13 +229,13 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {/if} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// must endblock be nocache?
|
||||
if ($compiler->nocache) {
|
||||
|
@ -20,6 +20,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* caching mode to create nocache code but no cache file
|
||||
*/
|
||||
const CACHING_NOCACHE_CODE = 9999;
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -27,6 +28,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -34,13 +36,15 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $option_flags = array('nocache', 'inline', 'caching');
|
||||
public $option_flags = array('nocache', 'inline', 'caching', 'bubble_up');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -49,65 +53,161 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Valid scope names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
|
||||
'smarty' => true, 'tpl_root' => true);
|
||||
|
||||
/**
|
||||
* Compiles code for the {include} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @throws SmartyCompilerException
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler, $parameter)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// save possible attributes
|
||||
$include_file = $_attr['file'];
|
||||
|
||||
$hashResourceName = $fullResourceName = $source_resource = $_attr['file'];
|
||||
$variable_template = false;
|
||||
$cache_tpl = false;
|
||||
// parse resource_name
|
||||
if (preg_match('/^([\'"])(([A-Za-z0-9_\-]{2,})[:])?(([^$()]+)|(.+))\1$/', $source_resource, $match)) {
|
||||
$type = !empty($match[3]) ? $match[3] : $compiler->template->smarty->default_resource_type;
|
||||
$name = !empty($match[5]) ? $match[5] : $match[6];
|
||||
$handler = Smarty_Resource::load($compiler->smarty, $type);
|
||||
if ($handler->recompiled || $handler->uncompiled) {
|
||||
$variable_template = true;
|
||||
}
|
||||
if (!$variable_template) {
|
||||
if ($type != 'string') {
|
||||
$fullResourceName = "{$type}:{$name}";
|
||||
$compiled = $compiler->parent_compiler->template->compiled;
|
||||
if (isset($compiled->includes[$fullResourceName])) {
|
||||
$compiled->includes[$fullResourceName] ++;
|
||||
$cache_tpl = true;
|
||||
} else {
|
||||
$compiled->includes[$fullResourceName] = 1;
|
||||
}
|
||||
$fullResourceName = '"' . $fullResourceName . '"';
|
||||
}
|
||||
}
|
||||
if (empty($match[5])) {
|
||||
$variable_template = true;
|
||||
}
|
||||
} else {
|
||||
$variable_template = true;
|
||||
}
|
||||
|
||||
if (isset($_attr['assign'])) {
|
||||
// output will be stored in a smarty variable instead of being displayed
|
||||
$_assign = $_attr['assign'];
|
||||
}
|
||||
|
||||
$_parent_scope = Smarty::SCOPE_LOCAL;
|
||||
// scope setup
|
||||
$_scope = Smarty::SCOPE_LOCAL;
|
||||
if (isset($_attr['scope'])) {
|
||||
$_attr['scope'] = trim($_attr['scope'], "'\"");
|
||||
if ($_attr['scope'] == 'parent') {
|
||||
$_parent_scope = Smarty::SCOPE_PARENT;
|
||||
} elseif ($_attr['scope'] == 'root') {
|
||||
$_parent_scope = Smarty::SCOPE_ROOT;
|
||||
} elseif ($_attr['scope'] == 'global') {
|
||||
$_parent_scope = Smarty::SCOPE_GLOBAL;
|
||||
if (!isset($this->valid_scopes[$_attr['scope']])) {
|
||||
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true);
|
||||
}
|
||||
if ($_attr['scope'] != 'local') {
|
||||
if ($_attr['scope'] == 'parent') {
|
||||
$_scope = Smarty::SCOPE_PARENT;
|
||||
} elseif ($_attr['scope'] == 'root') {
|
||||
$_scope = Smarty::SCOPE_ROOT;
|
||||
} elseif ($_attr['scope'] == 'global') {
|
||||
$_scope = Smarty::SCOPE_GLOBAL;
|
||||
} elseif ($_attr['scope'] == 'smarty') {
|
||||
$_scope = Smarty::SCOPE_SMARTY;
|
||||
} elseif ($_attr['scope'] == 'tpl_root') {
|
||||
$_scope = Smarty::SCOPE_TPL_ROOT;
|
||||
}
|
||||
if ($_attr['bubble_up'] === true) {
|
||||
$_scope = $_scope + Smarty::SCOPE_BUBBLE_UP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set flag to cache subtemplate object when called within loop or template name is variable.
|
||||
if ($cache_tpl || $variable_template || $compiler->loopNesting > 0) {
|
||||
$_cache_tpl = 'true';
|
||||
} else {
|
||||
$_cache_tpl = 'false';
|
||||
}
|
||||
// assume caching is off
|
||||
$_caching = Smarty::CACHING_OFF;
|
||||
|
||||
// flag if included template code should be merged into caller
|
||||
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) || $_attr['inline'] === true) && !$compiler->template->source->recompiled;
|
||||
if ($_attr['nocache'] === true) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
// set default when in nocache mode
|
||||
// if ($compiler->template->caching && ($compiler->nocache || $compiler->tag_nocache || $compiler->forceNocache == 2)) {
|
||||
if ($compiler->template->caching && ((!$compiler->inheritance && !$compiler->nocache && !$compiler->tag_nocache) || ($compiler->inheritance && ($compiler->nocache || $compiler->tag_nocache)))) {
|
||||
$call_nocache = $compiler->tag_nocache || $compiler->nocache;
|
||||
|
||||
// caching was on and {include} is not in nocache mode
|
||||
if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) {
|
||||
$_caching = self::CACHING_NOCACHE_CODE;
|
||||
}
|
||||
|
||||
// flag if included template code should be merged into caller
|
||||
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) &&
|
||||
!$compiler->template->source->handler->recompiled;
|
||||
|
||||
if ($merge_compiled_includes && $_attr['inline'] !== true) {
|
||||
// variable template name ?
|
||||
if ($variable_template) {
|
||||
$merge_compiled_includes = false;
|
||||
if ($compiler->template->caching) {
|
||||
// must use individual cache file
|
||||
//$_attr['caching'] = 1;
|
||||
}
|
||||
}
|
||||
// variable compile_id?
|
||||
if (isset($_attr['compile_id'])) {
|
||||
if (!((substr_count($_attr['compile_id'], '"') == 2 || substr_count($_attr['compile_id'], "'") == 2 ||
|
||||
is_numeric($_attr['compile_id']))) || substr_count($_attr['compile_id'], '(') != 0 ||
|
||||
substr_count($_attr['compile_id'], '$_smarty_tpl->') != 0
|
||||
) {
|
||||
$merge_compiled_includes = false;
|
||||
if ($compiler->template->caching) {
|
||||
// must use individual cache file
|
||||
//$_attr['caching'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* if the {include} tag provides individual parameter for caching
|
||||
* it will not be included into the common cache file and treated like
|
||||
* a nocache section
|
||||
* if the {include} tag provides individual parameter for caching or compile_id
|
||||
* the subtemplate must not be included into the common cache file and is treated like
|
||||
* a call in nocache mode.
|
||||
*
|
||||
*/
|
||||
if ($_attr['nocache'] !== true && $_attr['caching']) {
|
||||
$_caching = $_new_caching = (int) $_attr['caching'];
|
||||
$call_nocache = true;
|
||||
} else {
|
||||
$_new_caching = Smarty::CACHING_LIFETIME_CURRENT;
|
||||
}
|
||||
if (isset($_attr['cache_lifetime'])) {
|
||||
$_cache_lifetime = $_attr['cache_lifetime'];
|
||||
$compiler->tag_nocache = true;
|
||||
$_caching = Smarty::CACHING_LIFETIME_CURRENT;
|
||||
$call_nocache = true;
|
||||
$_caching = $_new_caching;
|
||||
} else {
|
||||
$_cache_lifetime = 'null';
|
||||
$_cache_lifetime = '$_smarty_tpl->cache_lifetime';
|
||||
}
|
||||
if (isset($_attr['cache_id'])) {
|
||||
$_cache_id = $_attr['cache_id'];
|
||||
$compiler->tag_nocache = true;
|
||||
$_caching = Smarty::CACHING_LIFETIME_CURRENT;
|
||||
$call_nocache = true;
|
||||
$_caching = $_new_caching;
|
||||
} else {
|
||||
$_cache_id = '$_smarty_tpl->cache_id';
|
||||
}
|
||||
@ -116,150 +216,151 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
} else {
|
||||
$_compile_id = '$_smarty_tpl->compile_id';
|
||||
}
|
||||
if ($_attr['caching'] === true) {
|
||||
$_caching = Smarty::CACHING_LIFETIME_CURRENT;
|
||||
}
|
||||
if ($_attr['nocache'] === true) {
|
||||
$compiler->tag_nocache = true;
|
||||
if ($merge_compiled_includes) {
|
||||
$_caching = self::CACHING_NOCACHE_CODE;
|
||||
} else {
|
||||
$_caching = Smarty::CACHING_OFF;
|
||||
}
|
||||
|
||||
// if subtemplate will be called in nocache mode do not merge
|
||||
if ($compiler->template->caching && $call_nocache) {
|
||||
$merge_compiled_includes = false;
|
||||
}
|
||||
|
||||
$has_compiled_template = false;
|
||||
if ($merge_compiled_includes && $_attr['inline'] !== true) {
|
||||
// variable template name ?
|
||||
if ($compiler->has_variable_string || !((substr_count($include_file, '"') == 2 || substr_count($include_file, "'") == 2))
|
||||
|| substr_count($include_file, '(') != 0 || substr_count($include_file, '$_smarty_tpl->') != 0
|
||||
) {
|
||||
$merge_compiled_includes = false;
|
||||
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) {
|
||||
$compiler->trigger_template_error(' variable template file names not allow within {block} tags');
|
||||
}
|
||||
}
|
||||
// variable compile_id?
|
||||
if (isset($_attr['compile_id'])) {
|
||||
if (!((substr_count($_attr['compile_id'], '"') == 2 || substr_count($_attr['compile_id'], "'") == 2))
|
||||
|| substr_count($_attr['compile_id'], '(') != 0 || substr_count($_attr['compile_id'], '$_smarty_tpl->') != 0
|
||||
) {
|
||||
$merge_compiled_includes = false;
|
||||
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) {
|
||||
$compiler->trigger_template_error(' variable compile_id not allow within {block} tags');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($merge_compiled_includes) {
|
||||
if ($compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache) && $_caching != self::CACHING_NOCACHE_CODE) {
|
||||
$merge_compiled_includes = false;
|
||||
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) {
|
||||
$compiler->trigger_template_error(' invalid caching mode of subtemplate within {block} tags');
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($merge_compiled_includes) {
|
||||
// we must observe different compile_id
|
||||
$uid = sha1($_compile_id);
|
||||
$tpl_name = null;
|
||||
$nocache = false;
|
||||
/** @var Smarty_Internal_Template $_smarty_tpl
|
||||
* used in evaluated code
|
||||
*/
|
||||
$_smarty_tpl = $compiler->template;
|
||||
eval("\$tpl_name = $include_file;");
|
||||
if (!isset($compiler->smarty->merged_templates_func[$tpl_name][$uid])) {
|
||||
$tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $compiler->template->compile_id);
|
||||
// save unique function name
|
||||
$compiler->smarty->merged_templates_func[$tpl_name][$uid]['func'] = $tpl->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
||||
// use current nocache hash for inlined code
|
||||
$compiler->smarty->merged_templates_func[$tpl_name][$uid]['nocache_hash'] = $tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
||||
if ($compiler->template->caching && $_caching == self::CACHING_NOCACHE_CODE) {
|
||||
// all code must be nocache
|
||||
$nocache = true;
|
||||
}
|
||||
if ($compiler->inheritance) {
|
||||
$tpl->compiler->inheritance = true;
|
||||
}
|
||||
// make sure whole chain gets compiled
|
||||
$tpl->mustCompile = true;
|
||||
if (!($tpl->source->uncompiled) && $tpl->source->exists) {
|
||||
|
||||
// get compiled code
|
||||
$compiled_code = $tpl->compiler->compileTemplate($tpl, $nocache);
|
||||
// release compiler object to free memory
|
||||
unset($tpl->compiler);
|
||||
// merge compiled code for {function} tags
|
||||
$compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $tpl->properties['function']);
|
||||
// merge filedependency
|
||||
$tpl->properties['file_dependency'][$tpl->source->uid] = array($tpl->source->filepath, $tpl->source->timestamp, $tpl->source->type);
|
||||
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $tpl->properties['file_dependency']);
|
||||
// remove header code
|
||||
$compiled_code = preg_replace("/(<\?php \/\*%%SmartyHeaderCode:{$tpl->properties['nocache_hash']}%%\*\/(.+?)\/\*\/%%SmartyHeaderCode%%\*\/\?>\n)/s", '', $compiled_code);
|
||||
if ($tpl->has_nocache_code) {
|
||||
// replace nocache_hash
|
||||
$compiled_code = str_replace("{$tpl->properties['nocache_hash']}", $compiler->template->properties['nocache_hash'], $compiled_code);
|
||||
$compiler->template->has_nocache_code = true;
|
||||
}
|
||||
$compiler->merged_templates[$tpl->properties['unifunc']] = $compiled_code;
|
||||
$has_compiled_template = true;
|
||||
unset ($tpl);
|
||||
}
|
||||
$c_id = isset($_attr['compile_id']) ? $_attr['compile_id'] : $compiler->template->compile_id;
|
||||
// we must observe different compile_id and caching
|
||||
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
|
||||
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash])) {
|
||||
$has_compiled_template =
|
||||
$this->compileInlineTemplate($compiler, $fullResourceName, $_caching, $hashResourceName, $t_hash,
|
||||
$c_id);
|
||||
} else {
|
||||
$has_compiled_template = true;
|
||||
}
|
||||
}
|
||||
// delete {include} standard attributes
|
||||
unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline']);
|
||||
unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline'], $_attr['bubble_up']);
|
||||
// remaining attributes must be assigned as smarty variable
|
||||
$_vars_nc = '';
|
||||
if (!empty($_attr)) {
|
||||
if ($_parent_scope == Smarty::SCOPE_LOCAL) {
|
||||
if ($_scope == Smarty::SCOPE_LOCAL) {
|
||||
$_pairs = array();
|
||||
// create variables
|
||||
$nccode = '';
|
||||
foreach ($_attr as $key => $value) {
|
||||
$_pairs[] = "'$key'=>$value";
|
||||
$nccode .= "\$_smarty_tpl->tpl_vars['$key'] = new Smarty_variable($value);\n";
|
||||
$_vars_nc .= "\$_smarty_tpl->tpl_vars['$key'] = new Smarty_Variable($value);\n";
|
||||
}
|
||||
$_vars = 'array(' . join(',', $_pairs) . ')';
|
||||
} else {
|
||||
$compiler->trigger_template_error('variable passing not allowed in parent/global scope', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('variable passing not allowed in parent/global scope', null, true);
|
||||
}
|
||||
} else {
|
||||
$_vars = 'array()';
|
||||
}
|
||||
if ($has_compiled_template) {
|
||||
// never call inline templates in nocache mode
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
$_hash = $compiler->smarty->merged_templates_func[$tpl_name][$uid]['nocache_hash'];
|
||||
$_output = "<?php /* Call merged included template \"" . $tpl_name . "\" */\n";
|
||||
$_output .= "\$_tpl_stack[] = \$_smarty_tpl;\n";
|
||||
if (!empty($nccode) && $_caching == 9999 && $_smarty_tpl->caching) {
|
||||
$compiler->suppressNocacheProcessing = false;
|
||||
$_output .= substr($compiler->processNocacheCode('<?php ' .$nccode . "?>\n", true), 6, -3);
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
$update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache &&
|
||||
$_compile_id != '$_smarty_tpl->compile_id';
|
||||
if ($has_compiled_template && !$call_nocache) {
|
||||
$_output = "<?php\n";
|
||||
if ($update_compile_id) {
|
||||
$_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n");
|
||||
}
|
||||
if (!empty($_vars_nc) && $_caching == 9999 && $compiler->template->caching) {
|
||||
//$compiler->suppressNocacheProcessing = false;
|
||||
$_output .= substr($compiler->processNocacheCode('<?php ' . $_vars_nc . "?>\n", true), 6, - 3);
|
||||
//$compiler->suppressNocacheProcessing = true;
|
||||
}
|
||||
$_output .= " \$_smarty_tpl = \$_smarty_tpl->setupInlineSubTemplate($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope, '$_hash');\n";
|
||||
if (isset($_assign)) {
|
||||
$_output .= 'ob_start(); ';
|
||||
$_output .= "ob_start();\n";
|
||||
}
|
||||
$_output .= $compiler->smarty->merged_templates_func[$tpl_name][$uid]['func'] . "(\$_smarty_tpl);\n";
|
||||
$_output .= "\$_smarty_tpl = array_pop(\$_tpl_stack); ";
|
||||
$_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func']}');\n";
|
||||
if (isset($_assign)) {
|
||||
$_output .= " \$_smarty_tpl->tpl_vars[$_assign] = new Smarty_variable(ob_get_clean());";
|
||||
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
|
||||
}
|
||||
$_output .= "\n/* End of included template \"" . $tpl_name . "\" */?>";
|
||||
if ($update_compile_id) {
|
||||
$_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n");
|
||||
}
|
||||
$_output .= "?>\n";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
|
||||
if ($call_nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
$_output = "<?php ";
|
||||
if ($update_compile_id) {
|
||||
$_output .= "\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n";
|
||||
}
|
||||
// was there an assign attribute
|
||||
if (isset($_assign)) {
|
||||
$_output = "<?php \$_smarty_tpl->tpl_vars[$_assign] = new Smarty_variable(\$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope));?>\n";;
|
||||
} else {
|
||||
$_output = "<?php echo \$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope);?>\n";
|
||||
$_output .= "ob_start();\n";
|
||||
}
|
||||
|
||||
$_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_scope, {$_cache_tpl});\n";
|
||||
if (isset($_assign)) {
|
||||
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
|
||||
}
|
||||
if ($update_compile_id) {
|
||||
$_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n";
|
||||
}
|
||||
$_output .= "?>\n";
|
||||
return $_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile inline sub template
|
||||
*
|
||||
* @param \Smarty_Internal_SmartyTemplateCompiler $compiler
|
||||
* @param $fullResourceName
|
||||
* @param $_caching
|
||||
* @param $hashResourceName
|
||||
* @param $t_hash
|
||||
* @param $c_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler, $fullResourceName,
|
||||
$_caching, $hashResourceName, $t_hash, $c_id)
|
||||
{
|
||||
$compiler->smarty->allow_ambiguous_resources = true;
|
||||
/* @var Smarty_Internal_Template $tpl */
|
||||
$tpl =
|
||||
new $compiler->smarty->template_class (trim($fullResourceName, '"\''), $compiler->smarty, $compiler->template,
|
||||
$compiler->template->cache_id, $c_id, $_caching);
|
||||
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid'] = $tpl->source->uid;
|
||||
if (isset($compiler->template->_inheritance)) {
|
||||
$tpl->_inheritance = clone $compiler->template->_inheritance;
|
||||
}
|
||||
$tpl->compiled = new Smarty_Template_Compiled();
|
||||
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
|
||||
$tpl->loadCompiler();
|
||||
// save unique function name
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func'] =
|
||||
$tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
||||
// make sure whole chain gets compiled
|
||||
$tpl->mustCompile = true;
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['nocache_hash'] =
|
||||
$tpl->compiled->nocache_hash;
|
||||
// get compiled code
|
||||
$compiled_code = "<?php\n\n";
|
||||
$compiled_code .= "/* Start inline template \"{$tpl->source->type}:{$tpl->source->name}\" =============================*/\n";
|
||||
$compiled_code .= "function {$tpl->compiled->unifunc} (\$_smarty_tpl) {\n";
|
||||
$compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler);
|
||||
$compiled_code .= "<?php\n";
|
||||
$compiled_code .= "}\n?>\n";
|
||||
$compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode);
|
||||
$compiled_code .= "<?php\n\n";
|
||||
$compiled_code .= "/* End inline template \"{$tpl->source->type}:{$tpl->source->name}\" =============================*/\n";
|
||||
$compiled_code .= "?>";
|
||||
unset($tpl->compiler);
|
||||
if ($tpl->compiled->has_nocache_code) {
|
||||
// replace nocache_hash
|
||||
$compiled_code =
|
||||
str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash,
|
||||
$compiled_code);
|
||||
$compiler->template->compiled->has_nocache_code = true;
|
||||
}
|
||||
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -41,13 +43,14 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {include_php} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @return string compiled code
|
||||
* @return string
|
||||
* @throws \SmartyCompilerException
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||
throw new SmartyException("{include_php} is deprecated, use SmartyBC class to enable");
|
||||
@ -60,9 +63,10 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$_filepath = false;
|
||||
eval('$_file = ' . $_attr['file'] . ';');
|
||||
$_file = null;
|
||||
eval('$_file = @' . $_attr['file'] . ';');
|
||||
if (!isset($compiler->smarty->security_policy) && file_exists($_file)) {
|
||||
$_filepath = $_file;
|
||||
$_filepath = $compiler->smarty->_realpath($_file, true);
|
||||
} else {
|
||||
if (isset($compiler->smarty->security_policy)) {
|
||||
$_dir = $compiler->smarty->security_policy->trusted_dir;
|
||||
@ -71,16 +75,16 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
|
||||
}
|
||||
if (!empty($_dir)) {
|
||||
foreach ((array) $_dir as $_script_dir) {
|
||||
$_script_dir = rtrim($_script_dir, '/\\') . DS;
|
||||
if (file_exists($_script_dir . $_file)) {
|
||||
$_filepath = $_script_dir . $_file;
|
||||
$_path = $compiler->smarty->_realpath($_script_dir . DS . $_file, true);
|
||||
if (file_exists($_path)) {
|
||||
$_filepath = $_path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($_filepath == false) {
|
||||
$compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", null, true);
|
||||
}
|
||||
|
||||
if (isset($compiler->smarty->security_policy)) {
|
||||
@ -99,7 +103,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
|
||||
}
|
||||
|
||||
if (isset($_assign)) {
|
||||
return "<?php ob_start(); include{$_once} ('{$_filepath}'); \$_smarty_tpl->assign({$_assign},ob_get_contents()); ob_end_clean();?>";
|
||||
return "<?php ob_start();\ninclude{$_once} ('{$_filepath}');\n\$_smarty_tpl->assign({$_assign},ob_get_clean());\n?>";
|
||||
} else {
|
||||
return "<?php include{$_once} ('{$_filepath}');?>\n";
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -31,6 +32,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -42,17 +44,21 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {insert} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// never compile as nocache code
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
$nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache);
|
||||
if (!$nocacheParam) {
|
||||
// do not compile as nocache code
|
||||
$compiler->suppressNocacheProcessing = true;
|
||||
}
|
||||
$compiler->tag_nocache = true;
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$_name = null;
|
||||
@ -60,19 +66,24 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
|
||||
$_output = '<?php ';
|
||||
// save possible attributes
|
||||
eval('$_name = ' . $_attr['name'] . ';');
|
||||
eval('$_name = @' . $_attr['name'] . ';');
|
||||
if (isset($_attr['assign'])) {
|
||||
// output will be stored in a smarty variable instead of being displayed
|
||||
$_assign = $_attr['assign'];
|
||||
// create variable to make sure that the compiler knows about its nocache status
|
||||
$compiler->template->tpl_vars[trim($_attr['assign'], "'")] = new Smarty_Variable(null, true);
|
||||
$var = trim($_attr['assign'], "'");
|
||||
if (isset($compiler->template->tpl_vars[$var])) {
|
||||
$compiler->template->tpl_vars[$var]->nocache = true;
|
||||
} else {
|
||||
$compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true);
|
||||
}
|
||||
}
|
||||
if (isset($_attr['script'])) {
|
||||
// script which must be included
|
||||
$_function = "smarty_insert_{$_name}";
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$_filepath = false;
|
||||
eval('$_script = ' . $_attr['script'] . ';');
|
||||
eval('$_script = @' . $_attr['script'] . ';');
|
||||
if (!isset($compiler->smarty->security_policy) && file_exists($_script)) {
|
||||
$_filepath = $_script;
|
||||
} else {
|
||||
@ -92,13 +103,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
}
|
||||
}
|
||||
if ($_filepath == false) {
|
||||
$compiler->trigger_template_error("{insert} missing script file '{$_script}'", $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true);
|
||||
}
|
||||
// code for script file loading
|
||||
$_output .= "require_once '{$_filepath}' ;";
|
||||
require_once $_filepath;
|
||||
if (!is_callable($_function)) {
|
||||
$compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", null, true);
|
||||
}
|
||||
} else {
|
||||
$_filepath = 'null';
|
||||
@ -107,7 +118,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
if (!is_callable($_function)) {
|
||||
// try plugin
|
||||
if (!$_function = $compiler->getPlugin($_name, 'insert')) {
|
||||
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", null, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,14 +132,14 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
$_params = 'array(' . implode(", ", $_paramsArray) . ')';
|
||||
// call insert
|
||||
if (isset($_assign)) {
|
||||
if ($_smarty_tpl->caching) {
|
||||
if ($_smarty_tpl->caching && !$nocacheParam) {
|
||||
$_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}',{$_assign});?>";
|
||||
} else {
|
||||
$_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl), true);?>";
|
||||
}
|
||||
} else {
|
||||
$compiler->has_output = true;
|
||||
if ($_smarty_tpl->caching) {
|
||||
if ($_smarty_tpl->caching && !$nocacheParam) {
|
||||
$_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}');?>";
|
||||
} else {
|
||||
$_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>";
|
||||
|
@ -20,16 +20,17 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
|
||||
* Compiles code for the {ldelim} tag
|
||||
* This tag does output the left delimiter
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('nocache option not allowed', null, true);
|
||||
}
|
||||
// this tag does not return compiled code
|
||||
$compiler->has_code = true;
|
||||
|
@ -16,21 +16,26 @@
|
||||
*/
|
||||
class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
|
||||
{
|
||||
/**
|
||||
* Array of names of valid option flags
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $option_flags = array();
|
||||
|
||||
/**
|
||||
* Compiles code for the {nocache} tag
|
||||
* This tag does not generate compiled output. It only sets a compiler flag.
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
|
||||
}
|
||||
$this->openTag($compiler, 'nocache', array($compiler->nocache));
|
||||
// enter nocache mode
|
||||
$compiler->nocache = true;
|
||||
// this tag does not return compiled code
|
||||
@ -52,16 +57,16 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
|
||||
* Compiles code for the {/nocache} tag
|
||||
* This tag does not generate compiled output. It only sets a compiler flag.
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
// leave nocache mode
|
||||
$compiler->nocache = false;
|
||||
list($compiler->nocache) = $this->closeTag($compiler, array('nocache'));
|
||||
// this tag does not return compiled code
|
||||
$compiler->has_code = false;
|
||||
|
||||
|
@ -27,15 +27,15 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
||||
/**
|
||||
* Compiles code for the execution of block plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block plugin
|
||||
* @param string $function PHP function name
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block plugin
|
||||
* @param string $function PHP function name
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter, $tag, $function)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
|
||||
{
|
||||
if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
|
||||
// opening tag of block plugin
|
||||
@ -60,7 +60,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
||||
// maybe nocache because of nocache variables or nocache plugin
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
// compile code
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
|
||||
$output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
|
||||
} else {
|
||||
// must endblock be nocache?
|
||||
if ($compiler->nocache) {
|
||||
@ -75,9 +75,13 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
||||
$mod_pre = $mod_post = '';
|
||||
} else {
|
||||
$mod_pre = ' ob_start(); ';
|
||||
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';';
|
||||
$mod_post = 'echo ' .
|
||||
$compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'],
|
||||
'value' => 'ob_get_clean()')) . ';';
|
||||
}
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
|
||||
" echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post .
|
||||
" } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
|
||||
}
|
||||
|
||||
return $output . "\n";
|
||||
|
@ -0,0 +1,224 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile ForeachSection
|
||||
* Shared methods for {foreach} {section} tags
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile ForeachSection Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_CompileBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Preg search pattern
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $propertyPreg = '';
|
||||
|
||||
/**
|
||||
* Offsets in preg match result
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $resultOffsets = array();
|
||||
|
||||
/**
|
||||
* Start offset
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $startOffset = 0;
|
||||
|
||||
/**
|
||||
* Name of this tag
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $tagName = '';
|
||||
|
||||
/**
|
||||
* Valid properties of $smarty.xxx variable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $nameProperties = array();
|
||||
|
||||
/**
|
||||
* {section} tag has no item properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $itemProperties = null;
|
||||
|
||||
/**
|
||||
* {section} tag has always name attribute
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isNamed = true;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $matchResults = array();
|
||||
|
||||
/**
|
||||
* Scan sources for used tag attributes
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
*/
|
||||
public function scanForProperties($attributes, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$this->propertyPreg = '~(';
|
||||
$this->startOffset = 0;
|
||||
$this->resultOffsets = array();
|
||||
$this->matchResults = array('named' => array(), 'item' => array());
|
||||
if ($this->isNamed) {
|
||||
$this->buildPropertyPreg(true, $attributes);
|
||||
}
|
||||
if (isset($this->itemProperties)) {
|
||||
if ($this->isNamed) {
|
||||
$this->propertyPreg .= '|';
|
||||
}
|
||||
$this->buildPropertyPreg(false, $attributes);
|
||||
}
|
||||
$this->propertyPreg .= ')\W~i';
|
||||
// Template source
|
||||
$this->matchTemplateSource($compiler);
|
||||
// Parent template source
|
||||
$this->matchParentTemplateSource($compiler);
|
||||
// {block} source
|
||||
$this->matchBlockSource($compiler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build property preg string
|
||||
*
|
||||
* @param bool $named
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function buildPropertyPreg($named, $attributes)
|
||||
{
|
||||
if ($named) {
|
||||
$this->resultOffsets['named'] = $this->startOffset + 3;
|
||||
$this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.](";
|
||||
$className = get_class($this);
|
||||
$properties = $className::$nameProperties;
|
||||
} else {
|
||||
$this->resultOffsets['item'] = $this->startOffset + 3;
|
||||
$this->propertyPreg .= "([\$]{$attributes['item']}[@](";
|
||||
$properties = $this->itemProperties;
|
||||
}
|
||||
$this->startOffset += count($properties) + 2;
|
||||
$propName = reset($properties);
|
||||
while ($propName) {
|
||||
$this->propertyPreg .= "({$propName})";
|
||||
$propName = next($properties);
|
||||
if ($propName) {
|
||||
$this->propertyPreg .= '|';
|
||||
}
|
||||
}
|
||||
$this->propertyPreg .= '))';
|
||||
}
|
||||
|
||||
/**
|
||||
* Find matches in source string
|
||||
*
|
||||
* @param string $source
|
||||
*/
|
||||
public function matchProperty($source)
|
||||
{
|
||||
preg_match_all($this->propertyPreg, $source, $match, PREG_SET_ORDER);
|
||||
foreach ($this->resultOffsets as $key => $offset) {
|
||||
foreach ($match as $m) {
|
||||
if (isset($m[$offset]) && !empty($m[$offset])) {
|
||||
$this->matchResults[$key][strtolower($m[$offset])] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find matches in template source
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
*/
|
||||
public function matchTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$this->matchProperty($compiler->parser->lex->data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find matches in all parent template source
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
*/
|
||||
public function matchParentTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
// search parent compiler template source
|
||||
$nextCompiler = $compiler;
|
||||
while ($nextCompiler !== $nextCompiler->parent_compiler) {
|
||||
$nextCompiler = $nextCompiler->parent_compiler;
|
||||
if ($compiler !== $nextCompiler) {
|
||||
// get template source
|
||||
$_content = $nextCompiler->template->source->getContent();
|
||||
if ($_content != '') {
|
||||
// run pre filter if required
|
||||
if ((isset($nextCompiler->smarty->autoload_filters['pre']) ||
|
||||
isset($nextCompiler->smarty->registered_filters['pre']))) {
|
||||
$_content = $nextCompiler->smarty->ext->_filter_Handler->runFilter('pre', $_content, $nextCompiler->template);
|
||||
}
|
||||
$this->matchProperty($_content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find matches in {block} tag source
|
||||
*
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler
|
||||
*/
|
||||
public function matchBlockSource(Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// make all lower case
|
||||
$parameter = array_map('strtolower', $parameter);
|
||||
$tag = trim($parameter[0], '"\'');
|
||||
if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) {
|
||||
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
|
||||
}
|
||||
$className = 'Smarty_Internal_Compile_' . ucfirst($tag);
|
||||
if ((!isset($parameter[2]) || false === $property = $compiler->getId($parameter[2])) ||
|
||||
!in_array($property, $className::$nameProperties)
|
||||
) {
|
||||
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true);
|
||||
}
|
||||
$tagVar = "'__smarty_{$tag}_{$name}'";
|
||||
return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)";
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array();
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -34,15 +35,15 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
|
||||
/**
|
||||
* Compiles code for the execution of function plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function plugin
|
||||
* @param string $function PHP function name
|
||||
* @param string $function PHP function name
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter, $tag, $function)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
|
||||
{
|
||||
// This tag does create output
|
||||
$compiler->has_output = true;
|
||||
|
@ -20,13 +20,14 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
/**
|
||||
* Compiles code for modifier execution
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@ -52,7 +53,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
$output = "{$function}({$params})";
|
||||
} else {
|
||||
if (is_object($function[0])) {
|
||||
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
|
||||
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
|
||||
$modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
|
||||
} else {
|
||||
$output = $function[0] . '::' . $function[1] . '(' . $params . ')';
|
||||
}
|
||||
@ -73,7 +75,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
// modifiercompiler plugin
|
||||
if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
|
||||
// check if modifier allowed
|
||||
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
|
||||
if (!is_object($compiler->smarty->security_policy) ||
|
||||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
|
||||
) {
|
||||
$plugin = 'smarty_modifiercompiler_' . $modifier;
|
||||
$output = $plugin($single_modifier, $compiler);
|
||||
}
|
||||
@ -85,7 +89,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
// modifier plugin
|
||||
if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
|
||||
// check if modifier allowed
|
||||
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
|
||||
if (!is_object($compiler->smarty->security_policy) ||
|
||||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
|
||||
) {
|
||||
$output = "{$function}({$params})";
|
||||
}
|
||||
$compiler->known_modifier_type[$modifier] = $type;
|
||||
@ -96,7 +102,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
// PHP function
|
||||
if (is_callable($modifier)) {
|
||||
// check if modifier allowed
|
||||
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) {
|
||||
if (!is_object($compiler->smarty->security_policy) ||
|
||||
$compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
|
||||
) {
|
||||
$output = "{$modifier}({$params})";
|
||||
}
|
||||
$compiler->known_modifier_type[$modifier] = $type;
|
||||
@ -105,21 +113,29 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
break;
|
||||
case 6:
|
||||
// default plugin handler
|
||||
if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || (is_callable($compiler->smarty->default_plugin_handler_func) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))) {
|
||||
if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) ||
|
||||
(is_callable($compiler->smarty->default_plugin_handler_func) &&
|
||||
$compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
|
||||
) {
|
||||
$function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
|
||||
// check if modifier allowed
|
||||
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
|
||||
if (!is_object($compiler->smarty->security_policy) ||
|
||||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
|
||||
) {
|
||||
if (!is_array($function)) {
|
||||
$output = "{$function}({$params})";
|
||||
} else {
|
||||
if (is_object($function[0])) {
|
||||
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
|
||||
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
|
||||
$modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
|
||||
} else {
|
||||
$output = $function[0] . '::' . $function[1] . '(' . $params . ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) {
|
||||
if (isset($compiler->parent_compiler->template->compiled->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) ||
|
||||
isset($compiler->parent_compiler->template->compiled->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])
|
||||
) {
|
||||
// was a plugin
|
||||
$compiler->known_modifier_type[$modifier] = 4;
|
||||
} else {
|
||||
@ -130,7 +146,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
}
|
||||
}
|
||||
if (!isset($compiler->known_modifier_type[$modifier])) {
|
||||
$compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", null, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,15 +27,15 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
|
||||
/**
|
||||
* Compiles code for the execution of block plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block object
|
||||
* @param string $method name of method to call
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block object
|
||||
* @param string $method name of method to call
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter, $tag, $method)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
|
||||
{
|
||||
if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
|
||||
// opening tag of block plugin
|
||||
@ -60,7 +60,8 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
|
||||
// maybe nocache because of nocache variables or nocache plugin
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
// compile code
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}->{$method}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
|
||||
$output =
|
||||
"<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}->{$method}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
|
||||
} else {
|
||||
$base_tag = substr($tag, 0, - 5);
|
||||
// must endblock be nocache?
|
||||
@ -76,9 +77,13 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
|
||||
$mod_pre = $mod_post = '';
|
||||
} else {
|
||||
$mod_pre = ' ob_start(); ';
|
||||
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';';
|
||||
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(),
|
||||
array('modifierlist' => $parameter['modifier_list'],
|
||||
'value' => 'ob_get_clean()')) . ';';
|
||||
}
|
||||
$output = "<?php \$_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;" . $mod_pre . " echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
|
||||
" echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
|
||||
$mod_post . " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
|
||||
}
|
||||
|
||||
return $output . "\n";
|
||||
|
@ -27,15 +27,15 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
|
||||
/**
|
||||
* Compiles code for the execution of function plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function
|
||||
* @param string $method name of method to call
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function
|
||||
* @param string $method name of method to call
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter, $tag, $method)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile PHP Expression
|
||||
* Compiles any tag which will output an expression or variable
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile PHP Expression Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('code', 'type');
|
||||
|
||||
/**
|
||||
* Compiles code for generating output from any expression
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$compiler->has_code = false;
|
||||
if ($_attr['type'] == 'xml') {
|
||||
$compiler->tag_nocache = true;
|
||||
$save = $compiler->template->compiled->has_nocache_code;
|
||||
$output = addcslashes($_attr['code'], "'\\");
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" .
|
||||
$output .
|
||||
"';?>", $compiler, true)));
|
||||
$compiler->template->compiled->has_nocache_code = $save;
|
||||
return '';
|
||||
}
|
||||
if ($_attr['type'] != 'tag') {
|
||||
if ($compiler->php_handling == Smarty::PHP_REMOVE) {
|
||||
return '';
|
||||
} elseif ($compiler->php_handling == Smarty::PHP_QUOTE) {
|
||||
$output = preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', array($this,
|
||||
'quote'), $_attr['code']);
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Text($output));
|
||||
return '';
|
||||
} elseif ($compiler->php_handling == Smarty::PHP_PASSTHRU || $_attr['type'] == 'unmatched') {
|
||||
$compiler->tag_nocache = true;
|
||||
$save = $compiler->template->compiled->has_nocache_code;
|
||||
$output = addcslashes($_attr['code'], "'\\");
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" .
|
||||
$output .
|
||||
"';?>", $compiler, true)));
|
||||
$compiler->template->compiled->has_nocache_code = $save;
|
||||
return '';
|
||||
} elseif ($compiler->php_handling == Smarty::PHP_ALLOW) {
|
||||
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||
$compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', null, true);
|
||||
}
|
||||
$compiler->has_code = true;
|
||||
return $_attr['code'];
|
||||
} else {
|
||||
$compiler->trigger_template_error('Illegal $smarty->php_handling value', null, true);
|
||||
}
|
||||
} else {
|
||||
$compiler->has_code = true;
|
||||
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||
$compiler->trigger_template_error('{php}[/php} tags not allowed. Use SmartyBC to enable them', null, true);
|
||||
}
|
||||
$ldel = preg_quote($compiler->smarty->left_delimiter, '#');
|
||||
$rdel = preg_quote($compiler->smarty->right_delimiter, '#');
|
||||
preg_match("#^({$ldel}php\\s*)((.)*?)({$rdel})#", $_attr['code'], $match);
|
||||
if (!empty($match[2])) {
|
||||
if ('nocache' == trim($match[2])) {
|
||||
$compiler->tag_nocache = true;
|
||||
} else {
|
||||
$compiler->trigger_template_error("illegal value of option flag \"{$match[2]}\"", null, true);
|
||||
}
|
||||
}
|
||||
return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#",
|
||||
"#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), array('<?php ', '?>'), $_attr['code']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lexer code for PHP tags
|
||||
*
|
||||
* This code has been moved from lexer here fo easier debugging and maintenance
|
||||
*
|
||||
* @param $lex
|
||||
*/
|
||||
public function parsePhp($lex)
|
||||
{
|
||||
$lex->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||
$close = 0;
|
||||
$lex->taglineno = $lex->line;
|
||||
$closeTag = '?>';
|
||||
if (strpos($lex->value, '<?xml') === 0) {
|
||||
$lex->is_xml = true;
|
||||
$lex->token = Smarty_Internal_Templateparser::TP_NOCACHE;
|
||||
return;
|
||||
} elseif (strpos($lex->value, '<?') === 0) {
|
||||
$lex->phpType = 'php';
|
||||
} elseif (strpos($lex->value, '<%') === 0) {
|
||||
$lex->phpType = 'asp';
|
||||
$closeTag = '%>';
|
||||
} elseif (strpos($lex->value, '%>') === 0) {
|
||||
$lex->phpType = 'unmatched';
|
||||
} elseif (strpos($lex->value, '?>') === 0) {
|
||||
if ($lex->is_xml) {
|
||||
$lex->is_xml = false;
|
||||
$lex->token = Smarty_Internal_Templateparser::TP_NOCACHE;
|
||||
return;
|
||||
}
|
||||
$lex->phpType = 'unmatched';
|
||||
} elseif (strpos($lex->value, '<s') === 0) {
|
||||
$lex->phpType = 'script';
|
||||
$closeTag = '</script>';
|
||||
} elseif (strpos($lex->value, $lex->smarty->left_delimiter) === 0) {
|
||||
if ($lex->isAutoLiteral()) {
|
||||
$lex->token = Smarty_Internal_Templateparser::TP_TEXT;
|
||||
return;
|
||||
}
|
||||
$closeTag = "{$lex->smarty->left_delimiter}/php{$lex->smarty->right_delimiter}";
|
||||
if ($lex->value == $closeTag) {
|
||||
$lex->compiler->trigger_template_error("unexpected closing tag '{$closeTag}'");
|
||||
}
|
||||
$lex->phpType = 'tag';
|
||||
}
|
||||
if ($lex->phpType == 'unmatched') {
|
||||
return;
|
||||
}
|
||||
if (($lex->phpType == 'php' || $lex->phpType == 'asp') &&
|
||||
($lex->compiler->php_handling == Smarty::PHP_PASSTHRU || $lex->compiler->php_handling == Smarty::PHP_QUOTE)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
$start = $lex->counter + strlen($lex->value);
|
||||
$body = true;
|
||||
if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $start)) {
|
||||
$close = $match[0][1];
|
||||
} else {
|
||||
$lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'");
|
||||
}
|
||||
while ($body) {
|
||||
if (preg_match('~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~', $lex->data, $match, PREG_OFFSET_CAPTURE, $start)) {
|
||||
$value = $match[0][0];
|
||||
$from = $pos = $match[0][1];
|
||||
if ($pos > $close) {
|
||||
$body = false;
|
||||
} else {
|
||||
$start = $pos + strlen($value);
|
||||
$phpCommentStart = $value == '/*';
|
||||
if ($phpCommentStart) {
|
||||
$phpCommentEnd = preg_match('~([*][/])~', $lex->data, $match, PREG_OFFSET_CAPTURE, $start);
|
||||
if ($phpCommentEnd) {
|
||||
$pos2 = $match[0][1];
|
||||
$start = $pos2 + strlen($match[0][0]);
|
||||
}
|
||||
}
|
||||
while ($close > $pos && $close < $start) {
|
||||
if (preg_match('~' . preg_quote($closeTag, '~') .
|
||||
'~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $from)) {
|
||||
$close = $match[0][1];
|
||||
$from = $close + strlen($match[0][0]);
|
||||
} else {
|
||||
$lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'");
|
||||
}
|
||||
}
|
||||
if ($phpCommentStart && (!$phpCommentEnd || $pos2 > $close)) {
|
||||
$lex->taglineno = $lex->line + substr_count(substr($lex->data, $lex->counter, $start), "\n");
|
||||
$lex->compiler->trigger_template_error("missing PHP comment closing tag '*/'");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$body = false;
|
||||
}
|
||||
}
|
||||
$lex->value = substr($lex->data, $lex->counter, $close + strlen($closeTag) - $lex->counter);
|
||||
}
|
||||
|
||||
/*
|
||||
* Call back function for $php_handling = PHP_QUOTE
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @param $match
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function quote($match)
|
||||
{
|
||||
return htmlspecialchars($match[0], ENT_QUOTES);
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('assign');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -34,14 +35,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
/**
|
||||
* Compiles code for generating output from any expression
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @return string compiled code
|
||||
* @return string
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@ -57,7 +58,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
$output = $parameter['value'];
|
||||
// tag modifier
|
||||
if (!empty($parameter['modifierlist'])) {
|
||||
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'], 'value' => $output));
|
||||
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'],
|
||||
'value' => $output));
|
||||
}
|
||||
if (!$_attr['nofilter']) {
|
||||
// default modifier
|
||||
@ -74,7 +76,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
}
|
||||
$compiler->default_modifier_list = $modifierlist;
|
||||
}
|
||||
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list, 'value' => $output));
|
||||
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list,
|
||||
'value' => $output));
|
||||
}
|
||||
// autoescape html
|
||||
if ($compiler->template->smarty->escape_html) {
|
||||
@ -82,7 +85,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
}
|
||||
// loop over registered filters
|
||||
if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) {
|
||||
foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key => $function) {
|
||||
foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key =>
|
||||
$function) {
|
||||
if (!is_array($function)) {
|
||||
$output = "{$function}({$output},\$_smarty_tpl)";
|
||||
} elseif (is_object($function[0])) {
|
||||
@ -104,13 +108,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($compiler->template->variable_filters)) {
|
||||
foreach ($compiler->template->variable_filters as $filter) {
|
||||
if (count($filter) == 1 && ($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false) {
|
||||
$output = $result;
|
||||
} else {
|
||||
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter), 'value' => $output));
|
||||
}
|
||||
foreach ($compiler->variable_filters as $filter) {
|
||||
if (count($filter) == 1 &&
|
||||
($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false
|
||||
) {
|
||||
$output = $result;
|
||||
} else {
|
||||
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter),
|
||||
'value' => $output));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -123,23 +128,23 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $compiler compiler object
|
||||
* @param string $name name of variable filter
|
||||
* @param string $output embedded output
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param string $name name of variable filter
|
||||
* @param string $output embedded output
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function compile_output_filter($compiler, $name, $output)
|
||||
private function compile_output_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
|
||||
{
|
||||
$plugin_name = "smarty_variablefilter_{$name}";
|
||||
$path = $compiler->smarty->loadPlugin($plugin_name, false);
|
||||
if ($path) {
|
||||
if ($compiler->template->caching) {
|
||||
$compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
|
||||
$compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
|
||||
} else {
|
||||
$compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
|
||||
$compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
|
||||
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
|
||||
}
|
||||
} else {
|
||||
// not found
|
||||
|
@ -27,14 +27,14 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
||||
/**
|
||||
* Compiles code for the execution of a block function
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block function
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of block function
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter, $tag)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag)
|
||||
{
|
||||
if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
|
||||
// opening tag of block plugin
|
||||
@ -69,11 +69,11 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
||||
$function = $tag_info[0];
|
||||
// compile code
|
||||
if (!is_array($function)) {
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
|
||||
$output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
|
||||
} elseif (is_object($function[0])) {
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
|
||||
$output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
|
||||
} else {
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
|
||||
$output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
|
||||
}
|
||||
} else {
|
||||
// must endblock be nocache?
|
||||
@ -95,14 +95,22 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
||||
$mod_pre = $mod_post = '';
|
||||
} else {
|
||||
$mod_pre = ' ob_start(); ';
|
||||
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';';
|
||||
$mod_post = 'echo ' .
|
||||
$compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'],
|
||||
'value' => 'ob_get_clean()')) . ';';
|
||||
}
|
||||
if (!is_array($function)) {
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
|
||||
" echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post .
|
||||
" } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
|
||||
} elseif (is_object($function[0])) {
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
|
||||
" echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
|
||||
$mod_post . "} array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
|
||||
} else {
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
|
||||
" echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
|
||||
$mod_post . "} array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,14 +27,14 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
|
||||
/**
|
||||
* Compiles code for the execution of a registered function
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
* @param string $tag name of function
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter, $tag)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag)
|
||||
{
|
||||
// This tag does create output
|
||||
$compiler->has_output = true;
|
||||
|
@ -19,96 +19,111 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
/**
|
||||
* Compiles code for the special $smarty variables
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param $parameter
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param $parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler, $parameter)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
|
||||
$compiled_ref = ' ';
|
||||
$variable = trim($_index[0], "'");
|
||||
switch ($variable) {
|
||||
case 'foreach':
|
||||
return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
|
||||
case 'section':
|
||||
return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
|
||||
case 'capture':
|
||||
return "Smarty::\$_smarty_vars$parameter";
|
||||
case 'now':
|
||||
return 'time()';
|
||||
case 'cookies':
|
||||
if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
|
||||
$compiler->trigger_template_error("(secure mode) super globals not permitted");
|
||||
break;
|
||||
}
|
||||
$compiled_ref = '$_COOKIE';
|
||||
break;
|
||||
|
||||
case 'get':
|
||||
case 'post':
|
||||
case 'env':
|
||||
case 'server':
|
||||
case 'session':
|
||||
case 'request':
|
||||
if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
|
||||
$compiler->trigger_template_error("(secure mode) super globals not permitted");
|
||||
break;
|
||||
}
|
||||
$compiled_ref = '$_' . strtoupper($variable);
|
||||
break;
|
||||
|
||||
case 'template':
|
||||
return 'basename($_smarty_tpl->source->filepath)';
|
||||
|
||||
case 'template_object':
|
||||
return '$_smarty_tpl';
|
||||
|
||||
case 'current_dir':
|
||||
return 'dirname($_smarty_tpl->source->filepath)';
|
||||
|
||||
case 'version':
|
||||
$_version = Smarty::SMARTY_VERSION;
|
||||
|
||||
return "'$_version'";
|
||||
|
||||
case 'const':
|
||||
if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_constants) {
|
||||
$compiler->trigger_template_error("(secure mode) constants not permitted");
|
||||
break;
|
||||
}
|
||||
|
||||
return "@constant({$_index[1]})";
|
||||
|
||||
case 'config':
|
||||
if (isset($_index[2])) {
|
||||
return "(is_array(\$tmp = \$_smarty_tpl->getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)";
|
||||
} else {
|
||||
return "\$_smarty_tpl->getConfigVariable($_index[1])";
|
||||
}
|
||||
case 'ldelim':
|
||||
$_ldelim = $compiler->smarty->left_delimiter;
|
||||
|
||||
return "'$_ldelim'";
|
||||
|
||||
case 'rdelim':
|
||||
$_rdelim = $compiler->smarty->right_delimiter;
|
||||
|
||||
return "'$_rdelim'";
|
||||
|
||||
default:
|
||||
$compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
|
||||
break;
|
||||
$variable = strtolower($compiler->getId($_index[0]));
|
||||
if ($variable === false) {
|
||||
$compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true);
|
||||
}
|
||||
if (isset($_index[1])) {
|
||||
array_shift($_index);
|
||||
foreach ($_index as $_ind) {
|
||||
$compiled_ref = $compiled_ref . "[$_ind]";
|
||||
if (!isset($compiler->smarty->security_policy) ||
|
||||
$compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)
|
||||
) {
|
||||
switch ($variable) {
|
||||
case 'foreach':
|
||||
case 'section':
|
||||
return Smarty_Internal_Compile_Private_ForeachSection::compileSpecialVariable(array(), $compiler, $_index);
|
||||
case 'capture':
|
||||
if (class_exists('Smarty_Internal_Compile_Capture')) {
|
||||
return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
|
||||
}
|
||||
return '';
|
||||
case 'now':
|
||||
return 'time()';
|
||||
case 'cookies':
|
||||
if (isset($compiler->smarty->security_policy) &&
|
||||
!$compiler->smarty->security_policy->allow_super_globals
|
||||
) {
|
||||
$compiler->trigger_template_error("(secure mode) super globals not permitted");
|
||||
break;
|
||||
}
|
||||
return '$_COOKIE';
|
||||
case 'get':
|
||||
case 'post':
|
||||
case 'env':
|
||||
case 'server':
|
||||
case 'session':
|
||||
case 'request':
|
||||
if (isset($compiler->smarty->security_policy) &&
|
||||
!$compiler->smarty->security_policy->allow_super_globals
|
||||
) {
|
||||
$compiler->trigger_template_error("(secure mode) super globals not permitted");
|
||||
break;
|
||||
}
|
||||
$compiled_ref = '$_' . strtoupper($variable);
|
||||
break;
|
||||
|
||||
case 'template':
|
||||
return 'basename($_smarty_tpl->source->filepath)';
|
||||
|
||||
case 'template_object':
|
||||
return '$_smarty_tpl';
|
||||
|
||||
case 'current_dir':
|
||||
return 'dirname($_smarty_tpl->source->filepath)';
|
||||
|
||||
case 'version':
|
||||
$_version = Smarty::SMARTY_VERSION;
|
||||
|
||||
return "'$_version'";
|
||||
|
||||
case 'const':
|
||||
if (isset($compiler->smarty->security_policy) &&
|
||||
!$compiler->smarty->security_policy->allow_constants
|
||||
) {
|
||||
$compiler->trigger_template_error("(secure mode) constants not permitted");
|
||||
break;
|
||||
}
|
||||
if (strpos($_index[1], '$') === false && strpos($_index[1], '\'') === false) {
|
||||
return "@constant('{$_index[1]}')";
|
||||
} else {
|
||||
return "@constant({$_index[1]})";
|
||||
}
|
||||
|
||||
case 'config':
|
||||
if (isset($_index[2])) {
|
||||
return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
|
||||
} else {
|
||||
return "\$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])";
|
||||
}
|
||||
case 'ldelim':
|
||||
$_ldelim = $compiler->smarty->left_delimiter;
|
||||
|
||||
return "'$_ldelim'";
|
||||
|
||||
case 'rdelim':
|
||||
$_rdelim = $compiler->smarty->right_delimiter;
|
||||
|
||||
return "'$_rdelim'";
|
||||
|
||||
default:
|
||||
$compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
|
||||
break;
|
||||
}
|
||||
if (isset($_index[1])) {
|
||||
array_shift($_index);
|
||||
foreach ($_index as $_ind) {
|
||||
$compiled_ref = $compiled_ref . "[$_ind]";
|
||||
}
|
||||
}
|
||||
return $compiled_ref;
|
||||
}
|
||||
|
||||
return $compiled_ref;
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,11 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
if ($_attr['nocache'] === true) {
|
||||
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
|
||||
$compiler->trigger_template_error('nocache option not allowed', null, true);
|
||||
}
|
||||
// this tag does not return compiled code
|
||||
$compiler->has_code = true;
|
||||
|
@ -14,7 +14,7 @@
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
|
||||
class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_ForeachSection
|
||||
{
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('name', 'loop');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name', 'loop');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@ -38,103 +40,343 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('start', 'step', 'max', 'show');
|
||||
|
||||
/**
|
||||
* counter
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $counter = 0;
|
||||
|
||||
/**
|
||||
* Name of this tag
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $tagName = 'section';
|
||||
|
||||
/**
|
||||
* Valid properties of $smarty.section.name.xxx variable
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum',
|
||||
'index_prev', 'index_next');
|
||||
|
||||
/**
|
||||
* {section} tag has no item properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $itemProperties = null;
|
||||
|
||||
/**
|
||||
* {section} tag has always name attribute
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $isNamed = true;
|
||||
|
||||
/**
|
||||
* Compiles code for the {section} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
$compiler->loopNesting++;
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
$this->openTag($compiler, 'section', array('section', $compiler->nocache));
|
||||
$attributes = array('name' => $compiler->getId($_attr['name']));
|
||||
unset($_attr['name']);
|
||||
foreach ($attributes as $a => $v) {
|
||||
if ($v === false) {
|
||||
$compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true);
|
||||
}
|
||||
}
|
||||
$local = "\$__section_{$attributes['name']}_" . $this->counter ++ . '_';
|
||||
$sectionVar = "\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']";
|
||||
$this->openTag($compiler, 'section', array('section', $compiler->nocache, $local, $sectionVar));
|
||||
// maybe nocache because of nocache variables
|
||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||
|
||||
$output = "<?php ";
|
||||
|
||||
$section_name = $_attr['name'];
|
||||
|
||||
$output .= "if (isset(\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name])) unset(\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]);\n";
|
||||
$section_props = "\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]";
|
||||
$initLocal = array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__section_{$attributes['name']}'] : false",);
|
||||
$initNamedProperty = array();
|
||||
$initFor = array();
|
||||
$incFor = array();
|
||||
$cmpFor = array();
|
||||
$propValue = array('index' => "{$sectionVar}->value['index']", 'show' => 'true', 'step' => 1,
|
||||
'iteration' => "{$local}iteration",
|
||||
|
||||
);
|
||||
$propType = array('index' => 2, 'iteration' => 2, 'show' => 0, 'step' => 0,);
|
||||
// search for used tag attributes
|
||||
$this->scanForProperties($attributes, $compiler);
|
||||
if (!empty($this->matchResults['named'])) {
|
||||
$namedAttr = $this->matchResults['named'];
|
||||
}
|
||||
$namedAttr['index'] = true;
|
||||
$output = "<?php\n";
|
||||
foreach ($_attr as $attr_name => $attr_value) {
|
||||
switch ($attr_name) {
|
||||
case 'loop':
|
||||
$output .= "{$section_props}['loop'] = is_array(\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop); unset(\$_loop);\n";
|
||||
if (is_numeric($attr_value)) {
|
||||
$v = (int) $attr_value;
|
||||
$t = 0;
|
||||
} else {
|
||||
$v = "(is_array(@\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop))";
|
||||
$t = 1;
|
||||
}
|
||||
if (isset($namedAttr['loop'])) {
|
||||
$initNamedProperty['loop'] = "'loop' => {$v}";
|
||||
if ($t == 1) {
|
||||
$v = "{$sectionVar}->value['loop']";
|
||||
}
|
||||
} elseif ($t == 1) {
|
||||
$initLocal['loop'] = $v;
|
||||
$v = "{$local}loop";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'show':
|
||||
if (is_bool($attr_value)) {
|
||||
$show_attr_value = $attr_value ? 'true' : 'false';
|
||||
$v = $attr_value ? 'true' : 'false';
|
||||
$t = 0;
|
||||
} else {
|
||||
$show_attr_value = "(bool) $attr_value";
|
||||
$v = "(bool) $attr_value";
|
||||
$t = 3;
|
||||
}
|
||||
$output .= "{$section_props}['show'] = $show_attr_value;\n";
|
||||
break;
|
||||
|
||||
case 'name':
|
||||
$output .= "{$section_props}['$attr_name'] = $attr_value;\n";
|
||||
case 'step':
|
||||
if (is_numeric($attr_value)) {
|
||||
$v = (int) $attr_value;
|
||||
$v = ($v == 0) ? 1 : $v;
|
||||
$t = 0;
|
||||
break;
|
||||
}
|
||||
$initLocal['step'] = "((int)@$attr_value) == 0 ? 1 : (int)@$attr_value";
|
||||
$v = "{$local}step";
|
||||
$t = 2;
|
||||
break;
|
||||
|
||||
case 'max':
|
||||
case 'start':
|
||||
$output .= "{$section_props}['$attr_name'] = (int) $attr_value;\n";
|
||||
if (is_numeric($attr_value)) {
|
||||
$v = (int) $attr_value;
|
||||
$t = 0;
|
||||
break;
|
||||
}
|
||||
$v = "(int)@$attr_value";
|
||||
$t = 3;
|
||||
break;
|
||||
}
|
||||
if ($t == 3 && $compiler->getId($attr_value)) {
|
||||
$t = 1;
|
||||
}
|
||||
$propValue[$attr_name] = $v;
|
||||
$propType[$attr_name] = $t;
|
||||
}
|
||||
|
||||
case 'step':
|
||||
$output .= "{$section_props}['$attr_name'] = ((int) $attr_value) == 0 ? 1 : (int) $attr_value;\n";
|
||||
break;
|
||||
if (isset($namedAttr['step'])) {
|
||||
$initNamedProperty['step'] = $propValue['step'];
|
||||
}
|
||||
if (isset($namedAttr['iteration'])) {
|
||||
$propValue['iteration'] = "{$sectionVar}->value['iteration']";
|
||||
}
|
||||
$incFor['iteration'] = "{$propValue['iteration']}++";
|
||||
$initFor['iteration'] = "{$propValue['iteration']} = 1";
|
||||
|
||||
if ($propType['step'] == 0) {
|
||||
if ($propValue['step'] == 1) {
|
||||
$incFor['index'] = "{$sectionVar}->value['index']++";
|
||||
} elseif ($propValue['step'] > 1) {
|
||||
$incFor['index'] = "{$sectionVar}->value['index'] += {$propValue['step']}";
|
||||
} else {
|
||||
$incFor['index'] = "{$sectionVar}->value['index'] -= " . - $propValue['step'];
|
||||
}
|
||||
} else {
|
||||
$incFor['index'] = "{$sectionVar}->value['index'] += {$propValue['step']}";
|
||||
}
|
||||
|
||||
if (!isset($propValue['max'])) {
|
||||
$propValue['max'] = $propValue['loop'];
|
||||
$propType['max'] = $propType['loop'];
|
||||
} elseif ($propType['max'] != 0) {
|
||||
$propValue['max'] = "{$propValue['max']} < 0 ? {$propValue['loop']} : {$propValue['max']}";
|
||||
$propType['max'] = 1;
|
||||
} else {
|
||||
if ($propValue['max'] < 0) {
|
||||
$propValue['max'] = $propValue['loop'];
|
||||
$propType['max'] = $propType['loop'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($_attr['show'])) {
|
||||
$output .= "{$section_props}['show'] = true;\n";
|
||||
}
|
||||
|
||||
if (!isset($_attr['loop'])) {
|
||||
$output .= "{$section_props}['loop'] = 1;\n";
|
||||
}
|
||||
|
||||
if (!isset($_attr['max'])) {
|
||||
$output .= "{$section_props}['max'] = {$section_props}['loop'];\n";
|
||||
if (!isset($propValue['start'])) {
|
||||
$start_code = array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue['loop'],
|
||||
5 => ' - 1');
|
||||
if ($propType['loop'] == 0) {
|
||||
$start_code[5] = '';
|
||||
$start_code[4] = $propValue['loop'] - 1;
|
||||
}
|
||||
if ($propType['step'] == 0) {
|
||||
if ($propValue['step'] > 0) {
|
||||
$start_code = array(1 => '0');
|
||||
$propType['start'] = 0;
|
||||
} else {
|
||||
$start_code[1] = $start_code[2] = $start_code[3] = '';
|
||||
$propType['start'] = $propType['loop'];
|
||||
}
|
||||
} else {
|
||||
$propType['start'] = 1;
|
||||
}
|
||||
$propValue['start'] = join('', $start_code);
|
||||
} else {
|
||||
$output .= "if ({$section_props}['max'] < 0)\n" . " {$section_props}['max'] = {$section_props}['loop'];\n";
|
||||
$start_code = array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ",
|
||||
4 => '0', 5 => ' : ', 6 => '-1', 7 => ', ',
|
||||
8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')', 11 => ' : ',
|
||||
12 => 'min(', 13 => $propValue['start'], 14 => ', ',
|
||||
15 => "{$propValue['step']} > 0 ? ", 16 => $propValue['loop'], 17 => ' : ',
|
||||
18 => $propType['loop'] == 0 ? $propValue['loop'] - 1 : "{$propValue['loop']} - 1",
|
||||
19 => ')');
|
||||
if ($propType['step'] == 0) {
|
||||
$start_code[3] = $start_code[5] = $start_code[15] = $start_code[17] = '';
|
||||
if ($propValue['step'] > 0) {
|
||||
$start_code[6] = $start_code[18] = '';
|
||||
} else {
|
||||
$start_code[4] = $start_code[16] = '';
|
||||
}
|
||||
}
|
||||
if ($propType['start'] == 0) {
|
||||
if ($propType['loop'] == 0) {
|
||||
$start_code[8] = $propValue['start'] + $propValue['loop'];
|
||||
}
|
||||
$propType['start'] = $propType['step'] + $propType['loop'];
|
||||
$start_code[1] = '';
|
||||
if ($propValue['start'] < 0) {
|
||||
for ($i = 11; $i <= 19; $i ++) {
|
||||
$start_code[$i] = '';
|
||||
}
|
||||
if ($propType['start'] == 0) {
|
||||
$start_code = array(max($propValue['step'] > 0 ? 0 : - 1, $propValue['start'] +
|
||||
$propValue['loop']));
|
||||
}
|
||||
} else {
|
||||
for ($i = 1; $i <= 11; $i ++) {
|
||||
$start_code[$i] = '';
|
||||
}
|
||||
if ($propType['start'] == 0) {
|
||||
$start_code = array(min($propValue['step'] > 0 ? $propValue['loop'] : $propValue['loop'] -
|
||||
1, $propValue['start']));
|
||||
}
|
||||
}
|
||||
}
|
||||
$propValue['start'] = join('', $start_code);
|
||||
}
|
||||
if ($propType['start'] != 0) {
|
||||
$initLocal['start'] = $propValue['start'];
|
||||
$propValue['start'] = "{$local}start";
|
||||
}
|
||||
|
||||
if (!isset($_attr['step'])) {
|
||||
$output .= "{$section_props}['step'] = 1;\n";
|
||||
}
|
||||
$initFor['index'] = "{$sectionVar}->value['index'] = {$propValue['start']}";
|
||||
|
||||
if (!isset($_attr['start'])) {
|
||||
$output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n";
|
||||
} else {
|
||||
$output .= "if ({$section_props}['start'] < 0)\n" . " {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" . "else\n" . " {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n";
|
||||
}
|
||||
|
||||
$output .= "if ({$section_props}['show']) {\n";
|
||||
if (!isset($_attr['start']) && !isset($_attr['step']) && !isset($_attr['max'])) {
|
||||
$output .= " {$section_props}['total'] = {$section_props}['loop'];\n";
|
||||
$propValue['total'] = $propValue['loop'];
|
||||
$propType['total'] = $propType['loop'];
|
||||
} else {
|
||||
$output .= " {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n";
|
||||
$propType['total'] = $propType['start'] + $propType['loop'] + $propType['step'] + $propType['max'];
|
||||
if ($propType['total'] == 0) {
|
||||
$propValue['total'] = min(ceil(($propValue['step'] > 0 ? $propValue['loop'] -
|
||||
$propValue['start'] : (int) $propValue['start'] + 1) /
|
||||
abs($propValue['step'])), $propValue['max']);
|
||||
} else {
|
||||
$total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ",
|
||||
5 => $propValue['loop'], 6 => ' - ', 7 => $propValue['start'], 8 => ' : ',
|
||||
9 => $propValue['start'], 10 => '+ 1', 11 => ')', 12 => '/ ', 13 => 'abs(',
|
||||
14 => $propValue['step'], 15 => ')', 16 => ')', 17 => ", {$propValue['max']})",);
|
||||
if (!isset($propValue['max'])) {
|
||||
$total_code[1] = $total_code[17] = '';
|
||||
}
|
||||
if ($propType['loop'] + $propType['start'] == 0) {
|
||||
$total_code[5] = $propValue['loop'] - $propValue['start'];
|
||||
$total_code[6] = $total_code[7] = '';
|
||||
}
|
||||
if ($propType['start'] == 0) {
|
||||
$total_code[9] = (int) $propValue['start'] + 1;
|
||||
$total_code[10] = '';
|
||||
}
|
||||
if ($propType['step'] == 0) {
|
||||
$total_code[13] = $total_code[15] = '';
|
||||
if ($propValue['step'] == 1 || $propValue['step'] == - 1) {
|
||||
$total_code[2] = $total_code[12] = $total_code[14] = $total_code[16] = '';
|
||||
} elseif ($propValue['step'] < 0) {
|
||||
$total_code[14] = - $propValue['step'];
|
||||
}
|
||||
$total_code[4] = '';
|
||||
if ($propValue['step'] > 0) {
|
||||
$total_code[8] = $total_code[9] = $total_code[10] = '';
|
||||
} else {
|
||||
$total_code[5] = $total_code[6] = $total_code[7] = $total_code[8] = '';
|
||||
}
|
||||
}
|
||||
$propValue['total'] = join('', $total_code);
|
||||
}
|
||||
}
|
||||
$output .= " if ({$section_props}['total'] == 0)\n" . " {$section_props}['show'] = false;\n" . "} else\n" . " {$section_props}['total'] = 0;\n";
|
||||
|
||||
$output .= "if ({$section_props}['show']):\n";
|
||||
$output .= "
|
||||
for ({$section_props}['index'] = {$section_props}['start'], {$section_props}['iteration'] = 1;
|
||||
{$section_props}['iteration'] <= {$section_props}['total'];
|
||||
{$section_props}['index'] += {$section_props}['step'], {$section_props}['iteration']++):\n";
|
||||
$output .= "{$section_props}['rownum'] = {$section_props}['iteration'];\n";
|
||||
$output .= "{$section_props}['index_prev'] = {$section_props}['index'] - {$section_props}['step'];\n";
|
||||
$output .= "{$section_props}['index_next'] = {$section_props}['index'] + {$section_props}['step'];\n";
|
||||
$output .= "{$section_props}['first'] = ({$section_props}['iteration'] == 1);\n";
|
||||
$output .= "{$section_props}['last'] = ({$section_props}['iteration'] == {$section_props}['total']);\n";
|
||||
if (isset($namedAttr['total'])) {
|
||||
$initNamedProperty['total'] = "'total' => {$propValue['total']}";
|
||||
if ($propType['total'] > 0) {
|
||||
$propValue['total'] = "{$sectionVar}->value['total']";
|
||||
}
|
||||
} elseif ($propType['total'] > 0) {
|
||||
$initLocal['total'] = $propValue['total'];
|
||||
$propValue['total'] = "{$local}total";
|
||||
}
|
||||
|
||||
$cmpFor['iteration'] = "{$propValue['iteration']} <= {$propValue['total']}";
|
||||
|
||||
foreach ($initLocal as $key => $code) {
|
||||
$output .= "{$local}{$key} = {$code};\n";
|
||||
}
|
||||
|
||||
$_vars = 'array(' . join(', ', $initNamedProperty) . ')';
|
||||
$output .= "{$sectionVar} = new Smarty_Variable({$_vars});\n";
|
||||
$cond_code = "{$propValue['total']} != 0";
|
||||
if ($propType['total'] == 0) {
|
||||
if ($propValue['total'] == 0) {
|
||||
$cond_code = 'false';
|
||||
} else {
|
||||
$cond_code = 'true';
|
||||
}
|
||||
}
|
||||
if ($propType['show'] > 0) {
|
||||
$output .= "{$local}show = {$propValue['show']} ? {$cond_code} : false;\n";
|
||||
$output .= "if ({$local}show) {\n";
|
||||
} elseif ($propValue['show'] == 'true') {
|
||||
$output .= "if ({$cond_code}) {\n";
|
||||
} else {
|
||||
$output .= "if (false) {\n";
|
||||
}
|
||||
$jinit = join(', ', $initFor);
|
||||
$jcmp = join(', ', $cmpFor);
|
||||
$jinc = join(', ', $incFor);
|
||||
$output .= "for ({$jinit}; {$jcmp}; {$jinc}){\n";
|
||||
if (isset($namedAttr['rownum'])) {
|
||||
$output .= "{$sectionVar}->value['rownum'] = {$propValue['iteration']};\n";
|
||||
}
|
||||
if (isset($namedAttr['index_prev'])) {
|
||||
$output .= "{$sectionVar}->value['index_prev'] = {$propValue['index']} - {$propValue['step']};\n";
|
||||
}
|
||||
if (isset($namedAttr['index_next'])) {
|
||||
$output .= "{$sectionVar}->value['index_next'] = {$propValue['index']} + {$propValue['step']};\n";
|
||||
}
|
||||
if (isset($namedAttr['first'])) {
|
||||
$output .= "{$sectionVar}->value['first'] = ({$propValue['iteration']} == 1);\n";
|
||||
}
|
||||
if (isset($namedAttr['last'])) {
|
||||
$output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n";
|
||||
}
|
||||
$output .= "?>";
|
||||
|
||||
return $output;
|
||||
@ -152,20 +394,20 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {sectionelse} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
list($openTag, $nocache) = $this->closeTag($compiler, array('section'));
|
||||
$this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache));
|
||||
list($openTag, $nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section'));
|
||||
$this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache, $local, $sectionVar));
|
||||
|
||||
return "<?php endfor; else: ?>";
|
||||
return "<?php }} else {\n ?>";
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,27 +422,33 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
|
||||
/**
|
||||
* Compiles code for the {/section} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
$compiler->loopNesting--;
|
||||
// must endblock be nocache?
|
||||
if ($compiler->nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('section', 'sectionelse'));
|
||||
list($openTag, $compiler->nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section',
|
||||
'sectionelse'));
|
||||
|
||||
$output = "<?php\n";
|
||||
if ($openTag == 'sectionelse') {
|
||||
return "<?php endif; ?>";
|
||||
$output .= "}\n";
|
||||
} else {
|
||||
return "<?php endfor; endif; ?>";
|
||||
$output .= "}\n}\n";
|
||||
}
|
||||
$output .= "if ({$local}saved) {\n";
|
||||
$output .= "{$sectionVar} = {$local}saved;\n";
|
||||
$output .= "}\n";
|
||||
$output .= "?>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user