Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch (pull request #247) 'template-global-fixes' of https://g…

…ithub.com/sminnee/sapphire into sminnee-template-global-fixes
  • Loading branch information...
commit e5e8f489a29a8c959857ac85e5330df1bca411cf 2 parents aaf9115 + 8bbfa97
@halkyon halkyon authored
View
26 control/Controller.php
@@ -406,32 +406,6 @@ function can($perm, $member = null) {
//-----------------------------------------------------------------------------------
/**
- * returns a date object for use within a template
- * Usage: $Now.Year - Returns 2006
- * @return Date The current date
- */
- function Now() {
- $d = new Date(null);
- $d->setValue(date("Y-m-d h:i:s"));
- return $d;
- }
-
- /**
- * Returns the currently logged in user
- */
- function CurrentMember() {
- return Member::currentUser();
- }
-
- /**
- * Return true if the visitor has signed up for a login account before
- * @return boolean
- */
- function PastMember() {
- return Cookie::get("PastMember") ? true : false;
- }
-
- /**
* Pushes this controller onto the stack of current controllers.
* This means that any redirection, session setting, or other things that rely on Controller::curr() will now write to this
* controller object.
View
10 docs/en/reference/built-in-page-controls.md
@@ -210,13 +210,13 @@ If the user is logged in this will print out
Welcome Back, Admin
-#### <% if PastMember %>
+#### <% if IsRepeatMember %>
-Detect the visitor's previous experience with the site. `$PastMember` will return true if the visitor has signed up or
-logged in on the site before.
+Detect the visitor's previous experience with the site. `$IsRepeatMember` will return true if the visitor has signed up or logged in on the site before.
-Note that as of version 2.4 `$PastVisitor` is deprecated. If you wish to check if a visitor has been to the site before,
-set a cookie with `Cookie::set()` and test for it with `Cookie::get()`.
+Note that as of version 2.4 `$PastVisitor` is deprecated. If you wish to check if a visitor has been to the site before, set a cookie with `Cookie::set()` and test for it with `Cookie::get()`.
+
+Note that in 2.4 this variable was called `$PastMember`. This still works in 3.0 but is deprecated.
### Date and Time
View
8 model/fieldtypes/Datetime.php
@@ -23,7 +23,7 @@
* @package framework
* @subpackage model
*/
-class SS_Datetime extends Date {
+class SS_Datetime extends Date implements TemplateGlobalProvider {
function setValue($value, $record = null) {
if($value === false || $value === null || (is_string($value) && !strlen($value))) {
@@ -132,5 +132,11 @@ static function set_mock_now($datetime) {
static function clear_mock_now() {
self::$mock_now = null;
}
+
+ public static function get_template_global_variables() {
+ return array(
+ 'Now' => array('method' => 'now', 'casting' => 'SS_Datetime'),
+ );
+ }
}
View
12 security/Member.php
@@ -551,7 +551,13 @@ static function currentUser() {
return DataObject::get_one("Member", "\"Member\".\"ID\" = $id", true, 1);
}
}
-
+
+ /**
+ * Returns true if the current member is a repeat visitor who has logged in more than once.
+ */
+ static function is_repeat_member() {
+ return Cookie::get("PastMember") ? true : false;
+ }
/**
* Get the ID of the current logged in user
@@ -1393,7 +1399,9 @@ function getHtmlEditorConfigForCMS() {
public static function get_template_global_variables() {
return array(
'CurrentMember' => 'currentUser',
- 'currentUser'
+ 'currentUser',
+ 'PastMember' => 'is_repeat_member',
+ 'IsRepeatMember' => 'is_repeat_member',
);
}
}
View
38 view/SSViewer.php
@@ -52,7 +52,12 @@ function resetLocalScope(){
array_splice($this->itemStack, $this->localIndex+1);
}
- function obj($name){
+ function getObj($name, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null) {
+ $on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
+ return $on->obj($name, $arguments, $forceReturnedObject, $cache, $cacheName);
+ }
+
+ function obj($name, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null){
switch ($name) {
case 'Up':
@@ -66,10 +71,7 @@ function obj($name){
break;
default:
- $on = $this->itemIterator ? $this->itemIterator->current() : $this->item;
-
- $arguments = func_get_args();
- $this->item = call_user_func_array(array($on, 'obj'), $arguments);
+ $this->item = $this->getObj($name, $arguments, $forceReturnedObject, $cache, $cacheName);
$this->itemIterator = null;
$this->upIndex = $this->currentIndex ? $this->currentIndex : count($this->itemStack)-1;
@@ -402,21 +404,33 @@ function getInjectedValue($property, $params, $cast = true) {
// If we want to provide a casted object, look up what type object to use
if ($cast) {
- // Get the object to cast as
- $casting = isset($source['casting']) ? $source['casting'] : null;
- // If not provided, use default
- if (!$casting) $casting = Config::inst()->get('ViewableData', 'default_cast', Config::FIRST_SET);
+ // If the handler returns an object, then we don't need to cast.
+ if(is_object($res['value'])) {
+ $res['obj'] = $res['value'];
+ } else {
+ // Get the object to cast as
+ $casting = isset($source['casting']) ? $source['casting'] : null;
- $obj = new $casting($property);
- $obj->setValue($res['value']);
+ // If not provided, use default
+ if (!$casting) $casting = Config::inst()->get('ViewableData', 'default_cast', Config::FIRST_SET);
- $res['obj'] = $obj;
+ $obj = new $casting($property);
+ $obj->setValue($res['value']);
+
+ $res['obj'] = $obj;
+ }
}
return $res;
}
}
+ function getObj($name, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null) {
+ $result = $this->getInjectedValue($name, (array)$arguments);
+ if($result) return $result['obj'];
+ else return parent::getObj($name, $arguments, $forceReturnedObject, $cache, $cacheName);
+ }
+
function __call($name, $arguments) {
//extract the method name and parameters
$property = $arguments[0]; //the name of the function being called
Please sign in to comment.
Something went wrong with that request. Please try again.