Skip to content

Instantly share code, notes, and snippets.

@saltybeagle
Created August 20, 2014 19:01
Show Gist options
  • Save saltybeagle/3e7148c55fdf4a307c9b to your computer and use it in GitHub Desktop.
Save saltybeagle/3e7148c55fdf4a307c9b to your computer and use it in GitHub Desktop.
Undergrad Bulletin Savvy Turbo
### Eclipse Workspace Patch 1.0
#P UNL_UndergraduateBulletin
Index: includes/tests/phpsavant.com/Savvy/escape/Foo.tpl.php
===================================================================
--- includes/tests/phpsavant.com/Savvy/escape/Foo.tpl.php (revision 0)
+++ includes/tests/phpsavant.com/Savvy/escape/Foo.tpl.php (revision 0)
@@ -0,0 +1,3 @@
+<?php
+echo $context->var1;
+?>
\ No newline at end of file
Index: includes/tests/phpsavant.com/Savvy/globals/basic.tpl.php
===================================================================
--- includes/tests/phpsavant.com/Savvy/globals/basic.tpl.php (revision 0)
+++ includes/tests/phpsavant.com/Savvy/globals/basic.tpl.php (revision 0)
@@ -0,0 +1,6 @@
+<?php
+ if (isset($foo)
+ && true === $foo) {
+ echo '===DONE===';
+ }
+?>
\ No newline at end of file
Index: src/UNL/UndergraduateBulletin/OutputController.php
===================================================================
--- src/UNL/UndergraduateBulletin/OutputController.php (revision 954)
+++ src/UNL/UndergraduateBulletin/OutputController.php (working copy)
@@ -1,92 +1,8 @@
<?php
-class UNL_UndergraduateBulletin_OutputController extends Savvy
+class UNL_UndergraduateBulletin_OutputController extends Savvy_Turbo
{
- static protected $cache;
-
- static public $defaultExpireTimestamp = null;
-
- function __construct($options = array())
- {
- parent::__construct();
- }
-
- static public function setCacheInterface(UNL_UndergraduateBulletin_CacheInterface $cache)
- {
- self::$cache = $cache;
- }
-
- /**
- * get the cache interface
- * @return UNL_UndergraduateBulletin_CacheInterface
- */
- static public function getCacheInterface()
- {
- if (!isset(self::$cache)) {
- self::setCacheInterface(new UNL_UndergraduateBulletin_CacheInterface_UNLCacheLite());
- }
- return self::$cache;
- }
-
- static public function setDefaultExpireTimestamp($timestamp)
- {
- self::$defaultExpireTimestamp = $timestamp;
- }
-
- static public function getDefaultExpireTimestamp()
- {
- return self::$defaultExpireTimestamp;
- }
-
- public function renderObject($object, $template = null)
- {
- if ($object instanceof UNL_UndergraduateBulletin_CacheableInterface
- || ($object instanceof Savvy_ObjectProxy
- && $object->getRawObject() instanceof UNL_UndergraduateBulletin_CacheableInterface)) {
- $key = $object->getCacheKey();
-
- if (false !== $key) {
- $key .= UNL_UndergraduateBulletin_Controller::getEdition()->getCacheKey();
- }
-
- // We have a valid key to store the output of this object.
- if ($key !== false && $data = self::getCacheInterface()->get($key)) {
- // Tell the object we have cached data and will output that.
- $object->preRun(true);
- } else {
- // Content should be cached, but none could be found.
- //flush();
-
- ob_start();
- $object->preRun(false);
- try {
- $object->run();
-
- $data = parent::renderObject($object, $template);
-
- if ($key !== false) {
- self::getCacheInterface()->save($data, $key);
- }
-
- } catch (Exception $e) {
- ob_end_clean();
- return parent::renderObject($e);
- }
- ob_end_clean();
- }
-
- if ($object instanceof UNL_UndergraduateBulletin_PostRunReplacements) {
- $data = $object->postRun($data);
- }
-
- return $data;
- }
-
- return parent::renderObject($object, $template);
-
- }
-
/**
*
* @param timestamp $expires timestamp
Index: src/UNL/UndergraduateBulletin/PostRunReplacements.php
===================================================================
--- src/UNL/UndergraduateBulletin/PostRunReplacements.php (revision 954)
+++ src/UNL/UndergraduateBulletin/PostRunReplacements.php (working copy)
@@ -1,7 +1,5 @@
<?php
-interface UNL_UndergraduateBulletin_PostRunReplacements
+interface UNL_UndergraduateBulletin_PostRunReplacements extends Savvy_Turbo_PostRunReplacements
{
- static function setReplacementData($field, $data);
- public function postRun($data);
}
Index: www/templates/html/SubjectAreas.tpl.php
===================================================================
--- www/templates/html/SubjectAreas.tpl.php (revision 954)
+++ www/templates/html/SubjectAreas.tpl.php (working copy)
@@ -2,7 +2,7 @@
<ul id="subjectListing">
<?php
foreach ($context as $subject_code=>$area) {
- echo '<li><a href="'.UNL_UndergraduateBulletin_Controller::getURL().'courses/'.$subject_code.'/"><span class="subjectCode">'.$subject_code.'</span> <span class="title">'.$area->title.'</span></a></li>';
+ echo '<li><a href="'.$controller->getURL().'courses/'.$subject_code.'/"><span class="subjectCode">'.$subject_code.'</span> <span class="title">'.$area->title.'</span></a></li>';
}
?>
</ul>
\ No newline at end of file
Index: includes/php/Savvy.php
===================================================================
--- includes/php/Savvy.php (revision 954)
+++ includes/php/Savvy.php (working copy)
@@ -93,7 +93,13 @@
* @var MapperInterface
*/
protected $class_to_template;
-
+
+ /**
+ * Array of globals available within every template
+ *
+ * @var array
+ */
+ protected $globals = array();
// -----------------------------------------------------------------
//
// Constructor and magic methods
@@ -136,45 +142,171 @@
$this->addFilters($config['filters']);
}
}
-
+
+ /**
+ * Basic output controller
+ *
+ * @param mixed $context The context passed to the template
+ * @param mixed $parent Parent template with context and parents $parent->context
+ * @param mixed $file The filename to include
+ * @param Savvy $savvy The Savvy templating system
+ *
+ * @return string
+ */
protected static function basicOutputController($context, $parent, $file, $savvy)
{
+ foreach ($savvy->getGlobals() as $__name => $__value) {
+ $$__name = $__value;
+ }
+ unset($__name, $__value);
ob_start();
include $file;
return ob_get_clean();
}
-
+
+ /**
+ * Basic output controller
+ *
+ * @param mixed $context The context passed to the template
+ * @param mixed $parent Parent template with context and parents $parent->context
+ * @param mixed $file The filename to include
+ * @param Savvy $savvy The Savvy templating system
+ *
+ * @return string
+ */
protected static function filterOutputController($context, $parent, $file, $savvy)
{
+ foreach ($savvy->getGlobals() as $__name => $__value) {
+ $$__name = $__value;
+ }
+ unset($__name, $__value);
ob_start();
include $file;
return $savvy->applyFilters(ob_get_clean());
}
-
+
+ /**
+ * Basic output controller
+ *
+ * @param mixed $context The context passed to the template
+ * @param mixed $parent Parent template with context and parents $parent->context
+ * @param mixed $file The filename to include
+ * @param Savvy $savvy The Savvy templating system
+ *
+ * @return string
+ */
protected static function basicCompiledOutputController($context, $parent, $file, $savvy)
{
+ foreach ($savvy->getGlobals() as $__name => $__value) {
+ $$__name = $__value;
+ }
+ unset($__name, $__value);
ob_start();
include $savvy->template($file);
return ob_get_clean();
}
-
+
+ /**
+ * Basic output controller
+ *
+ * @param mixed $context The context passed to the template
+ * @param mixed $parent Parent template with context and parents $parent->context
+ * @param mixed $file The filename to include
+ * @param Savvy $savvy The Savvy templating system
+ *
+ * @return string
+ */
protected static function filterCompiledOutputController($context, $parent, $file, $savvy)
{
+ foreach ($savvy->getGlobals() as $__name => $__value) {
+ $$__name = $__value;
+ }
+ unset($__name, $__value);
ob_start();
include $savvy->template($file);
return $savvy->applyFilters(ob_get_clean());
}
-
+
+ /**
+ * Basic output controller
+ *
+ * @param mixed $context The context passed to the template
+ * @param mixed $parent Parent template with context and parents $parent->context
+ * @param mixed $file The filename to include
+ * @param Savvy $savvy The Savvy templating system
+ *
+ * @return string
+ */
protected static function basicFastCompiledOutputController($context, $parent, $file, $savvy)
{
return include $savvy->template($file);
}
-
+
+ /**
+ * Basic output controller
+ *
+ * @param mixed $context The context passed to the template
+ * @param mixed $parent Parent template with context and parents $parent->context
+ * @param mixed $file The filename to include
+ * @param Savvy $savvy The Savvy templating system
+ *
+ * @return string
+ */
protected static function filterFastCompiledOutputController($context, $parent, $file, $savvy)
{
return $savvy->applyFilters(include $savvy->template($file));
}
-
+
+ /**
+ * Add a global variable which will be available inside every template
+ *
+ * @param string $var The global variable name
+ * @param mixed $value The value
+ *
+ * @return void
+ */
+ function addGlobal($name, $value)
+ {
+ switch ($name) {
+ case 'context':
+ case 'parent':
+ case 'template':
+ case 'savvy':
+ case 'this':
+ throw new Savvy_BadMethodCallException('Invalid global variable name');
+ }
+
+ if ($this->__config['escape']) {
+ switch (gettype($value)) {
+ case 'object':
+ if (!$value instanceof Savvy_ObjectProxy) {
+ $value = Savvy_ObjectProxy::factory($value, $this);
+ }
+ break;
+ case 'string':
+ case 'int':
+ case 'double':
+ $value = $this->escape($value);
+ break;
+ case 'array':
+ $value = new Savvy_ObjectProxy_ArrayAccess(new ArrayIterator($value), $this);
+ break;
+ }
+ }
+
+ $this->globals[$name] = $value;
+ }
+
+ /**
+ * Get the array of assigned globals
+ *
+ * @return array
+ */
+ function getGlobals()
+ {
+ return $this->globals;
+ }
+
/**
* Return the current template set (if any)
*
Index: www/templates/html/MajorSearch.tpl.php
===================================================================
--- www/templates/html/MajorSearch.tpl.php (revision 954)
+++ www/templates/html/MajorSearch.tpl.php (working copy)
@@ -1,8 +1,8 @@
<?php
if ($context->options['view'] == 'searchmajors') {
- $url = UNL_UndergraduateBulletin_Controller::getURL();
- UNL_UndergraduateBulletin_Controller::setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Majors | Search');
- UNL_UndergraduateBulletin_Controller::setReplacementData('breadcrumbs', '
+ $url = $controller->getURL();
+ $controller->setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Majors | Search');
+ $controller->setReplacementData('breadcrumbs', '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li><a href="'.$url.'">Undergraduate Bulletin</a></li>
Index: includes/tests/phpsavant.com/Savvy/escape/echostring.tpl.php
===================================================================
--- includes/tests/phpsavant.com/Savvy/escape/echostring.tpl.php (revision 0)
+++ includes/tests/phpsavant.com/Savvy/escape/echostring.tpl.php (revision 0)
@@ -0,0 +1,3 @@
+<?php
+echo $context;
+?>
\ No newline at end of file
Index: www/templates/html/SubjectArea.tpl.php
===================================================================
--- www/templates/html/SubjectArea.tpl.php (revision 954)
+++ www/templates/html/SubjectArea.tpl.php (working copy)
@@ -1,9 +1,9 @@
<?php
if (isset($parent->context->options)
&& $parent->context->options['view'] == 'subject') {
- $url = UNL_UndergraduateBulletin_Controller::getURL();
- UNL_UndergraduateBulletin_Controller::setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | '.$context->subject);
- UNL_UndergraduateBulletin_Controller::setReplacementData('breadcrumbs', '
+ $url = $controller->getURL();
+ $controller->setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | '.$context->subject);
+ $controller->setReplacementData('breadcrumbs', '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li><a href="'.$url.'">Undergraduate Bulletin</a></li>
Index: src/UNL/UndergraduateBulletin/SubjectAreas.php
===================================================================
--- src/UNL/UndergraduateBulletin/SubjectAreas.php (revision 954)
+++ src/UNL/UndergraduateBulletin/SubjectAreas.php (working copy)
@@ -15,7 +15,7 @@
return 'subjectareas';
}
- function preRun()
+ function preRun($cached)
{
}
Index: includes/tests/phpsavant.com/Savvy/globals/basic.phpt
===================================================================
--- includes/tests/phpsavant.com/Savvy/globals/basic.phpt (revision 0)
+++ includes/tests/phpsavant.com/Savvy/globals/basic.phpt (revision 0)
@@ -0,0 +1,15 @@
+--TEST--
+Savvy::addGlobal() basic test
+--FILE--
+<?php
+require dirname(__FILE__) . '/../test_framework.php.inc';
+chdir(__DIR__);
+$savvy = new Savvy();
+
+$savvy->addGlobal('foo', true);
+
+echo $savvy->render(null, 'basic.tpl.php');
+
+?>
+--EXPECT--
+===DONE===
\ No newline at end of file
Index: includes/docs/phpsavant.com/Savvy/examples/baseball/PartialSeason.tpl.php
===================================================================
--- includes/docs/phpsavant.com/Savvy/examples/baseball/PartialSeason.tpl.php (revision 0)
+++ includes/docs/phpsavant.com/Savvy/examples/baseball/PartialSeason.tpl.php (revision 0)
@@ -0,0 +1 @@
+<?php echo $context->start; ?>&mdash;<?php echo $context->end; ?>
\ No newline at end of file
Index: www/templates/html/EditionNotice.tpl.php
===================================================================
--- www/templates/html/EditionNotice.tpl.php (revision 954)
+++ www/templates/html/EditionNotice.tpl.php (working copy)
@@ -1,6 +1,6 @@
<?php
$latest = UNL_UndergraduateBulletin_Editions::getLatest();
-$current = UNL_UndergraduateBulletin_Controller::getEdition();
+$current = $controller->getEdition();
?>
<div id="versioning">
<div class="content">
Index: includes/tests/phpsavant.com/Savvy/escape/object.phpt
===================================================================
--- includes/tests/phpsavant.com/Savvy/escape/object.phpt (revision 0)
+++ includes/tests/phpsavant.com/Savvy/escape/object.phpt (revision 0)
@@ -0,0 +1,24 @@
+--TEST--
+Savvy::addEscape() object variable escaping test
+--FILE--
+<?php
+require dirname(__FILE__) . '/../test_framework.php.inc';
+chdir(__DIR__);
+$savvy = new Savvy();
+$savvy->setEscape('htmlspecialchars');
+
+class Foo
+{
+ public $var1;
+}
+
+$object = new Foo();
+$object->var1 = '<p></p>';
+
+$test->assertEquals(htmlspecialchars($object->var1), $savvy->render($object), 'render object with variable escaping');
+
+$test->assertEquals($object->var1, $savvy->render($object, 'raw.tpl.php'), 'render object with raw variable access');
+?>
+===DONE===
+--EXPECT--
+===DONE===
\ No newline at end of file
Index: www/templates/html/CollegeList.tpl.php
===================================================================
--- www/templates/html/CollegeList.tpl.php (revision 954)
+++ www/templates/html/CollegeList.tpl.php (working copy)
@@ -1,7 +1,7 @@
<?php
-$url = UNL_UndergraduateBulletin_Controller::getURL();
-UNL_UndergraduateBulletin_Controller::setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Colleges');
- UNL_UndergraduateBulletin_Controller::setReplacementData('breadcrumbs', '
+$url = $controller->getURL();
+$controller->setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Colleges');
+ $controller->setReplacementData('breadcrumbs', '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li><a href="'.$url.'">Undergraduate Bulletin</a></li>
Index: includes/.pear2registry
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: includes/php/Savvy/ObjectProxy.php
===================================================================
--- includes/php/Savvy/ObjectProxy.php (revision 954)
+++ includes/php/Savvy/ObjectProxy.php (working copy)
@@ -81,9 +81,11 @@
return self::factory($var, $this->savvy);
case 'string':
case 'int':
- case 'bool':
case 'double':
return $this->savvy->escape($var);
+ case 'array':
+ return new Savvy_ObjectProxy_ArrayAccess(
+ new ArrayIterator($var), $this->savvy);
}
return $var;
}
@@ -185,7 +187,7 @@
if (method_exists($this->object, '__toString')) {
return $this->savvy->escape($this->object->__toString());
}
- return (string)$this->object;
+ throw new Savvy_BadMethodCallException('Object of class '.$this->__getClass().' could not be converted to string');
}
/**
Index: src/UNL/UndergraduateBulletin/Editor/Controller.php
===================================================================
--- src/UNL/UndergraduateBulletin/Editor/Controller.php (revision 954)
+++ src/UNL/UndergraduateBulletin/Editor/Controller.php (working copy)
@@ -14,7 +14,7 @@
UNL_UndergraduateBulletin_Controller::setEdition(new UNL_UndergraduateBulletin_Edition(array('year'=>UNL_UndergraduateBulletin_Editions::$latest+1)));
}
- function preRun()
+ function preRun($cached)
{
}
@@ -22,13 +22,12 @@
function run()
{
try {
- if (isset($this->view_map[$this->options['view']])) {
- $this->output[] = new $this->view_map[$this->options['view']]($this->options);
- } else {
- $this->output[] = new Exception('Sorry, that view does not exist.');
+ if (!isset($this->view_map[$this->options['view']])) {
+ throw new Exception('Sorry, that view does not exist.', 404);
}
+ $this->output = new $this->view_map[$this->options['view']]($this->options);
} catch(Exception $e) {
- $this->output[] = $e;
+ $this->output = $e;
}
}
@@ -37,7 +36,7 @@
return false;
}
- public static function setReplacementData($field, $value)
+ public function setReplacementData($field, $value)
{
}
Index: includes/tests/phpsavant.com/Savvy/globals/escape.nestedarrays.phpt
===================================================================
--- includes/tests/phpsavant.com/Savvy/globals/escape.nestedarrays.phpt (revision 0)
+++ includes/tests/phpsavant.com/Savvy/globals/escape.nestedarrays.phpt (revision 0)
@@ -0,0 +1,23 @@
+--TEST--
+Savvy::addGlobal() Escape added global array
+--FILE--
+<?php
+require dirname(__FILE__) . '/../test_framework.php.inc';
+chdir(__DIR__);
+$savvy = new Savvy();
+
+$savvy->setEscape('htmlspecialchars');
+
+$unescaped = array(
+ '<a href="Blah">Blah</a>'
+);
+
+$savvy->addGlobal('foo', array($unescaped));
+
+$escaped = $savvy->getGlobals();
+
+echo $escaped['foo'][0][0];
+
+?>
+--EXPECT--
+&lt;a href=&quot;Blah&quot;&gt;Blah&lt;/a&gt;
\ No newline at end of file
Index: src/UNL/UndergraduateBulletin/CacheInterface.php
===================================================================
--- src/UNL/UndergraduateBulletin/CacheInterface.php (revision 954)
+++ src/UNL/UndergraduateBulletin/CacheInterface.php (working copy)
@@ -4,23 +4,7 @@
*
* @author bbieber
*/
-interface UNL_UndergraduateBulletin_CacheInterface
+interface UNL_UndergraduateBulletin_CacheInterface extends Savvy_Turbo_CacheInterface
{
- /**
- * Get an item from the cache
- * @param string $key They unique key for the cached item.
- *
- * @return mixed
- */
- public function get($key);
- /**
- * Save an item to the cache.
- *
- * @param mixed $data The data to save to the cache.
- * @param string $key Unique key for this data.
- *
- * @return bool
- */
- public function save($data, $key);
}
Index: src/UNL/UndergraduateBulletin/Search.php
===================================================================
--- src/UNL/UndergraduateBulletin/Search.php (revision 954)
+++ src/UNL/UndergraduateBulletin/Search.php (working copy)
@@ -26,7 +26,7 @@
return 'overallsearch'.$this->options['q'].$this->options['format'];
}
- function preRun()
+ function preRun($cached)
{
}
Index: www/templates/html/College.tpl.php
===================================================================
--- www/templates/html/College.tpl.php (revision 954)
+++ www/templates/html/College.tpl.php (working copy)
@@ -1,8 +1,8 @@
<?php
-$url = UNL_UndergraduateBulletin_Controller::getURL();
-UNL_UndergraduateBulletin_Controller::setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | '.$context->name);
-UNL_UndergraduateBulletin_Controller::setReplacementData('pagetitle', '<h2>'.$context->name.'</h2>');
-UNL_UndergraduateBulletin_Controller::setReplacementData('breadcrumbs', '
+$url = $controller->getURL();
+$controller->setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | '.$context->name);
+$controller->setReplacementData('pagetitle', '<h2>'.$context->name.'</h2>');
+$controller->setReplacementData('breadcrumbs', '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li><a href="'.$url.'">Undergraduate Bulletin</a></li>
Index: includes/docs/phpsavant.com/Savvy/examples/basic.php
===================================================================
--- includes/docs/phpsavant.com/Savvy/examples/basic.php (revision 0)
+++ includes/docs/phpsavant.com/Savvy/examples/basic.php (revision 0)
@@ -0,0 +1,40 @@
+<?php
+ini_set('display_errors',true);
+error_reporting(E_ALL^E_STRICT);
+require_once dirname(__FILE__).'/../src/Savvy/Autoload.php';
+$classLoader = new Savvy_Autoload();
+$classLoader->register();
+
+// Set up a view object we'd like to display
+$class = new stdClass();
+$class->var1 = '<p>This is var1 inside a standard class</p>';
+
+$savvy = new Savvy();
+$savvy->addTemplatePath(__DIR__ . '/templates');
+
+// Display a simple string
+echo $savvy->render('<h1>Welcome to the Savvy Demo</h1>');
+
+// Display a string, in a custom template
+echo $savvy->render('mystring', 'StringView.tpl.php');
+
+// Display an array
+echo $savvy->render(array('<ul>', '<li>This is an array</li>', '</ul>'));
+
+// Display an object using a default class name to template mapping function
+echo $savvy->render($class);
+
+// Display the object using a specific template
+echo $savvy->render($class, 'MyTemplate.tpl.php');
+
+echo $savvy->render('<h2>Output Filtering</h2>');
+$savvy->addFilters('htmlspecialchars');
+
+// Now show an entire template with htmlspecialchars
+echo $savvy->render($class);
+
+// Ok, now remove the output filters
+$savvy->setFilters();
+
+highlight_file(__FILE__);
+
Index: src/UNL/UndergraduateBulletin/Controller.php
===================================================================
--- src/UNL/UndergraduateBulletin/Controller.php (revision 954)
+++ src/UNL/UndergraduateBulletin/Controller.php (working copy)
@@ -55,7 +55,7 @@
return serialize($this->options);
}
- function preRun()
+ function preRun($cached)
{
}
@@ -82,13 +82,13 @@
throw new Exception('Sorry, that view does not exist.', 404);
}
- $this->output[] = new $this->view_map[$this->options['view']]($this->options);
+ $this->output = new $this->view_map[$this->options['view']]($this->options);
} catch(Exception $e) {
- $this->output[] = $e;
+ $this->output = $e;
}
}
- public static function setReplacementData($field, $data)
+ public function setReplacementData($field, $data)
{
self::$replacement_data[$field] = $data;
}
Index: includes/tests/phpsavant.com/Savvy/render/object.phpt
===================================================================
--- includes/tests/phpsavant.com/Savvy/render/object.phpt (revision 0)
+++ includes/tests/phpsavant.com/Savvy/render/object.phpt (revision 0)
@@ -0,0 +1,30 @@
+--TEST--
+Savvy::render() object test
+--FILE--
+<?php
+require dirname(__FILE__) . '/../test_framework.php.inc';
+chdir(__DIR__);
+$savvy = new Savvy();
+
+class Foo
+{
+ public $var1;
+ function __toString()
+ {
+ return 'test';
+ }
+}
+
+$object = new Foo();
+$object->var1 = ' is my class';
+
+$savvy->setEscape();
+
+$test->assertEquals('Foo is my class', $savvy->render($object), 'render object');
+
+$test->assertEquals('test', $savvy->render($object, 'echostring.tpl.php'), 'render object with custom template');
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
\ No newline at end of file
Index: includes/docs/phpsavant.com/Savvy/examples/baseball/BaseballPlayer.tpl.php
===================================================================
--- includes/docs/phpsavant.com/Savvy/examples/baseball/BaseballPlayer.tpl.php (revision 0)
+++ includes/docs/phpsavant.com/Savvy/examples/baseball/BaseballPlayer.tpl.php (revision 0)
@@ -0,0 +1,5 @@
+<h2>Player :: <?php echo $context->name; ?></h2>
+<p>Years on team:</p>
+<ul>
+ <?php echo $savvy->render($context->years_on_team, 'ListItem.tpl.php'); ?>
+</ul>
\ No newline at end of file
Index: includes/docs/phpsavant.com/Savvy/examples/templates/MyTemplate.tpl.php
===================================================================
--- includes/docs/phpsavant.com/Savvy/examples/templates/MyTemplate.tpl.php (revision 0)
+++ includes/docs/phpsavant.com/Savvy/examples/templates/MyTemplate.tpl.php (revision 0)
@@ -0,0 +1,2 @@
+<h2>This is MyTemplate.tpl.php</h2>
+<p>This represents using a custom output template for an object.</p>
Index: includes/docs/phpsavant.com/Savvy/examples/baseball/ListItem.tpl.php
===================================================================
--- includes/docs/phpsavant.com/Savvy/examples/baseball/ListItem.tpl.php (revision 0)
+++ includes/docs/phpsavant.com/Savvy/examples/baseball/ListItem.tpl.php (revision 0)
@@ -0,0 +1 @@
+<li><?php echo $savvy->render($context); ?></li>
\ No newline at end of file
Index: includes/tests/phpsavant.com/Savvy/escape/string.phpt
===================================================================
--- includes/tests/phpsavant.com/Savvy/escape/string.phpt (revision 0)
+++ includes/tests/phpsavant.com/Savvy/escape/string.phpt (revision 0)
@@ -0,0 +1,19 @@
+--TEST--
+Savvy::render() string with addEscape() test
+--FILE--
+<?php
+require dirname(__FILE__) . '/../test_framework.php.inc';
+chdir(__DIR__);
+$savvy = new Savvy();
+$savvy->setEscape('htmlspecialchars');
+
+$string = 'test';
+$test->assertEquals($string, $savvy->escape($string), 'render');
+
+$string = '<p></p>';
+$test->assertEquals(htmlspecialchars($string), $savvy->escape($string), 'render string with special chars');
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
\ No newline at end of file
Index: www/templates/html/Course.tpl.php
===================================================================
--- www/templates/html/Course.tpl.php (revision 954)
+++ www/templates/html/Course.tpl.php (working copy)
@@ -1,8 +1,8 @@
<?php
- $url = UNL_UndergraduateBulletin_Controller::getURL();
+ $url = $controller->getURL();
/* example code for isArchvied and getNewestURL();
- if(UNL_UndergraduateBulletin_Controller::isArchived()){
- echo "This version may be out of date. ".UNL_UndergraduateBulletin_Controller::getNewestURL();
+ if($controller->isArchived()){
+ echo "This version may be out of date. ".$controller->getNewestURL();
}
*/
@@ -27,9 +27,9 @@
$listings[] = $listing->courseNumber;
if ($listing->hasGroups()) {
- $groups = array_merge($groups, $listing->groups);
- foreach ($listing->groups as $group) {
- $class .= ' grp_'.md5($group);
+ $groups = array_merge($groups, (array)$listing->getRaw('groups'));
+ foreach ($listing->getRaw('groups') as $group) {
+ $class .= ' grp_'.md5((string)$group);
}
}
} else {
@@ -83,17 +83,17 @@
$format = trim($format, ', ');
if (!empty($context->aceOutcomes)) {
- $class .= ' ace ace_'.implode(' ace_', $context->aceOutcomes);
+ $class .= ' ace ace_'.implode(' ace_', $context->getRaw('aceOutcomes'));
}
if (isset($parent->parent->context->options)
&& $parent->parent->context->options['view'] == 'course') {
- UNL_UndergraduateBulletin_Controller::setReplacementData('head', '
+ $controller->setReplacementData('head', '
<link rel="alternate" type="text/xml" href="'.$permalink.'?format=xml" />
<link rel="alternate" type="text/javascript" href="'.$permalink.'?format=json" />
<link rel="alternate" type="text/html" href="'.$permalink.'?format=partial" />');
- UNL_UndergraduateBulletin_Controller::setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | '.$subject.' '.$listings.': '.$context->title);
- UNL_UndergraduateBulletin_Controller::setReplacementData('breadcrumbs', '
+ $controller->setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | '.$subject.' '.$listings.': '.$context->title);
+ $controller->setReplacementData('breadcrumbs', '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li><a href="'.$url.'">Undergraduate Bulletin</a></li>
@@ -132,18 +132,18 @@
|| $context->campuses[0] != 'UNL')) {
echo '<tr class="campus">
<td class="label">Campus:</td>
- <td class="value">'.implode(', ', $context->campuses).'</td>
+ <td class="value">'.implode(', ', $context->getRaw('campuses')).'</td>
</tr>';
}
echo '<tr class="deliveryMethods">
<td class="label">Course Delivery:</td>
- <td class="value">'.implode(', ', $context->deliveryMethods).'</td>
+ <td class="value">'.implode(', ', $context->getRaw('deliveryMethods')).'</td>
</tr>';
$ace = '';
if (!empty($context->aceOutcomes)) {
$ace = '';
- foreach($context->aceOutcomes as $outcome) {
- $ace .= '<abbr title="'.UNL_UndergraduateBulletin_ACE::$descriptions[$outcome].'">'.$outcome.'</abbr>, ';
+ foreach($context->getRaw('aceOutcomes') as $outcome) {
+ $ace .= '<abbr title="'.UNL_UndergraduateBulletin_ACE::$descriptions[(string)$outcome].'">'.$outcome.'</abbr>, ';
}
$ace = trim($ace, ', ');
echo '<tr class="aceOutcomes">
Index: config.sample.php
===================================================================
--- config.sample.php (revision 954)
+++ config.sample.php (working copy)
@@ -18,8 +18,8 @@
UNL_UndergraduateBulletin_Controller::$url = '/workspace/UNL_UndergraduateBulletin/www/';
// Remove this line on production machines so the default UNLCacheLite cache interface is used
-UNL_UndergraduateBulletin_OutputController::setCacheInterface(new UNL_UndergraduateBulletin_CacheInterface_Mock());
-UNL_UndergraduateBulletin_OutputController::setDefaultExpireTimestamp(strtotime('+1 week'));
+$cache = new UNL_UndergraduateBulletin_CacheInterface_Mock();
+//$defaultExpireTimestamp = strtotime('+1 week');
//UNL_UndergraduateBulletin_CacheInterface_Mock::$logger = function($key) {
// $log = ' unlcache_5174748813ed8803e7651fae9d2d077f_'.md5($key);
Index: src/UNL/UndergraduateBulletin/Major.php
===================================================================
--- src/UNL/UndergraduateBulletin/Major.php (revision 954)
+++ src/UNL/UndergraduateBulletin/Major.php (working copy)
@@ -27,7 +27,7 @@
return 'major'.$this->title.$this->options['view'];
}
- function preRun()
+ function preRun($cached)
{
}
Index: src/UNL/UndergraduateBulletin/College.php
===================================================================
--- src/UNL/UndergraduateBulletin/College.php (revision 954)
+++ src/UNL/UndergraduateBulletin/College.php (working copy)
@@ -20,7 +20,7 @@
}
- function preRun()
+ function preRun($cached)
{
}
Index: includes/tests/phpsavant.com/Savvy/render/array.phpt
===================================================================
--- includes/tests/phpsavant.com/Savvy/render/array.phpt (revision 0)
+++ includes/tests/phpsavant.com/Savvy/render/array.phpt (revision 0)
@@ -0,0 +1,18 @@
+--TEST--
+Savvy::render() array test
+--FILE--
+<?php
+require dirname(__FILE__) . '/../test_framework.php.inc';
+chdir(__DIR__);
+$savvy = new Savvy();
+
+$array = array(1,2,3);
+$test->assertEquals('123', $savvy->render($array), 'render array');
+
+$array = array(1,2,3);
+$test->assertEquals('123', $savvy->render($array, 'echostring.tpl.php'), 'render array through custom template');
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
\ No newline at end of file
Index: www/templates/html/Developers.tpl.php
===================================================================
--- www/templates/html/Developers.tpl.php (revision 954)
+++ www/templates/html/Developers.tpl.php (working copy)
@@ -34,7 +34,7 @@
<script type="text/javascript">jQuery = $ = WDN.jQuery;</script>
-<script type="text/javascript" src="<?php echo UNL_UndergraduateBulletin_Controller::getBaseURL()?>templates/html/scripts/jquery.beautyOfCode.js"></script>
+<script type="text/javascript" src="<?php echo $controller->getBaseURL()?>templates/html/scripts/jquery.beautyOfCode.js"></script>
<script type="text/javascript">
$.beautyOfCode.init({
Index: includes/docs/phpsavant.com/Savvy/examples/templates/stdClass.tpl.php
===================================================================
--- includes/docs/phpsavant.com/Savvy/examples/templates/stdClass.tpl.php (revision 0)
+++ includes/docs/phpsavant.com/Savvy/examples/templates/stdClass.tpl.php (revision 0)
@@ -0,0 +1,6 @@
+<h2>This is stdClass.tpl.php</h2>
+<p>This represents the default mapping of class name to template.</p>
+<p>The class of this context is: <?php echo get_class($context); ?></p>
+<p>The $context object contains the stdClass object with access to all the member
+variables and functions, such as $context->var1</p>
+<?php echo $context->var1; ?>
\ No newline at end of file
Index: www/templates/html/Controller.tpl.php
===================================================================
--- www/templates/html/Controller.tpl.php (revision 954)
+++ www/templates/html/Controller.tpl.php (working copy)
@@ -2,12 +2,12 @@
UNL_Templates::$options['version'] = 3;
UNL_Templates::$options['sharedcodepath'] = dirname(__FILE__).'/sharedcode';
-$url = UNL_UndergraduateBulletin_Controller::getURL();
-$baseURL = UNL_UndergraduateBulletin_Controller::getBaseURL();
+$url = $controller->getURL();
+$baseURL = $controller->getBaseURL();
$page = UNL_Templates::factory('Fixed');
$page->doctitle = '<title>UNL | Undergraduate Bulletin</title>';
-$page->titlegraphic = '<h1>Undergraduate Bulletin '.UNL_UndergraduateBulletin_Controller::getEdition()->getRange().'</h1>';
+$page->titlegraphic = '<h1>Undergraduate Bulletin '.$controller->getEdition()->getRange().'</h1>';
$page->breadcrumbs = '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
@@ -69,7 +69,7 @@
$page->loadSharedCodeFiles();
$page->addStylesheet('/wdn/templates_3.0/css/content/notice.css');
$page->addStylesheet('/wdn/templates_3.0/css/content/zenform.css');
-if (UNL_UndergraduateBulletin_OutputController::getCacheInterface() instanceof UNL_UndergraduateBulletin_CacheInterface_Mock) {
+if ($savvy->getCacheInterface() instanceof UNL_UndergraduateBulletin_CacheInterface_Mock) {
$page->addStylesheet($baseURL. 'templates/html/css/debug.css');
} else {
$page->addStylesheet($baseURL. 'templates/html/css/all.css');
Index: src/UNL/UndergraduateBulletin/MajorList.php
===================================================================
--- src/UNL/UndergraduateBulletin/MajorList.php (revision 954)
+++ src/UNL/UndergraduateBulletin/MajorList.php (working copy)
@@ -20,7 +20,7 @@
}
- function preRun()
+ function preRun($cached)
{
}
Index: includes/tests/phpsavant.com/Savvy/render/echostring.tpl.php
===================================================================
--- includes/tests/phpsavant.com/Savvy/render/echostring.tpl.php (revision 0)
+++ includes/tests/phpsavant.com/Savvy/render/echostring.tpl.php (revision 0)
@@ -0,0 +1 @@
+<?php echo $context ?>
\ No newline at end of file
Index: includes/docs/phpsavant.com/Savvy/examples/templates/StringView.tpl.php
===================================================================
--- includes/docs/phpsavant.com/Savvy/examples/templates/StringView.tpl.php (revision 0)
+++ includes/docs/phpsavant.com/Savvy/examples/templates/StringView.tpl.php (revision 0)
@@ -0,0 +1 @@
+<p>We're in the string view template, the data is: <?php echo $context; ?></p>
\ No newline at end of file
Index: www/templates/html/MajorList.tpl.php
===================================================================
--- www/templates/html/MajorList.tpl.php (revision 954)
+++ www/templates/html/MajorList.tpl.php (working copy)
@@ -1,7 +1,7 @@
<?php
-$url = UNL_UndergraduateBulletin_Controller::getURL();
-UNL_UndergraduateBulletin_Controller::setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Majors/Areas of Study');
- UNL_UndergraduateBulletin_Controller::setReplacementData('breadcrumbs', '
+$url = $controller->getURL();
+$controller->setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Majors/Areas of Study');
+ $controller->setReplacementData('breadcrumbs', '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li><a href="'.$url.'">Undergraduate Bulletin</a></li>
Index: www/templates/html/BulletinRules.tpl.php
===================================================================
--- www/templates/html/BulletinRules.tpl.php (revision 954)
+++ www/templates/html/BulletinRules.tpl.php (working copy)
@@ -1,5 +1,5 @@
<?php
-$baseURL = UNL_UndergraduateBulletin_Controller::getBaseURL();
+$baseURL = $controller->getBaseURL();
?>
<h2>Bulletin Rules</h2>
<div class="wdn_notice" id="officialMessage">
@@ -8,7 +8,7 @@
</div>
<div class="message">
<h4 style="color:#a5690c;">PLEASE NOTE:</h4>
- <p>Students who enter a college within the University in the <?php echo UNL_UndergraduateBulletin_Controller::getEdition()->getRange(); ?> academic year are expected to complete the graduation requirements set forth by that college in this bulletin.
+ <p>Students who enter a college within the University in the <?php echo $controller->getEdition()->getRange(); ?> academic year are expected to complete the graduation requirements set forth by that college in this bulletin.
Students are responsible for knowing which bulletin they should follow.</p>
</div>
</div>
Index: includes/tests/phpsavant.com/Savvy/globals/escape.phpt
===================================================================
--- includes/tests/phpsavant.com/Savvy/globals/escape.phpt (revision 0)
+++ includes/tests/phpsavant.com/Savvy/globals/escape.phpt (revision 0)
@@ -0,0 +1,21 @@
+--TEST--
+Savvy::addGlobal() Escape added globals test
+--FILE--
+<?php
+require dirname(__FILE__) . '/../test_framework.php.inc';
+chdir(__DIR__);
+$savvy = new Savvy();
+
+function myEscape($var)
+{
+ echo '===DONE===';
+ return $var;
+}
+
+$savvy->setEscape('myEscape');
+
+$savvy->addGlobal('foo', 'lalalala');
+
+?>
+--EXPECT--
+===DONE===
\ No newline at end of file
Index: includes/tests/phpsavant.com/Savvy/render/string.phpt
===================================================================
--- includes/tests/phpsavant.com/Savvy/render/string.phpt (revision 0)
+++ includes/tests/phpsavant.com/Savvy/render/string.phpt (revision 0)
@@ -0,0 +1,24 @@
+--TEST--
+Savvy::render() string test
+--FILE--
+<?php
+require dirname(__FILE__) . '/../test_framework.php.inc';
+chdir(__DIR__);
+$savvy = new Savvy();
+$savvy->setEscape('htmlspecialchars');
+
+$string = 'test';
+$test->assertEquals($string, $savvy->render($string), 'render');
+
+$string = '<p></p>';
+$test->assertEquals(htmlspecialchars($string), $savvy->render($string), 'render string with special chars');
+
+$string = 'test';
+$test->assertEquals($string, $savvy->render($string, 'echostring.tpl.php'), 'render string through template');
+
+$string = '<p></p>';
+$test->assertEquals(htmlspecialchars($string), $savvy->render($string, 'echostring.tpl.php'), 'render string with special chars through template');
+?>
+===DONE===
+--EXPECT--
+===DONE===
\ No newline at end of file
Index: www/templates/html/GeneralInformation.tpl.php
===================================================================
--- www/templates/html/GeneralInformation.tpl.php (revision 954)
+++ www/templates/html/GeneralInformation.tpl.php (working copy)
@@ -1,7 +1,7 @@
<?php
-$url = UNL_UndergraduateBulletin_Controller::getURL();
-UNL_UndergraduateBulletin_Controller::setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Academic Policies &amp; General Information');
-UNL_UndergraduateBulletin_Controller::setReplacementData('breadcrumbs', '
+$url = $controller->getURL();
+$controller->setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Academic Policies &amp; General Information');
+$controller->setReplacementData('breadcrumbs', '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li><a href="'.$url.'">Undergraduate Bulletin</a></li>
@@ -16,7 +16,7 @@
<div id="toc_bar"></div>
<div id="long_content">
<?php
-$contents = file_get_contents(UNL_UndergraduateBulletin_Controller::getEdition()->getDataDir().'/General Information.xhtml');
+$contents = file_get_contents($controller->getEdition()->getDataDir().'/General Information.xhtml');
$xml = simplexml_load_string($contents);
Index: includes/tests/phpsavant.com/Savvy/globals/escape.arrays.phpt
===================================================================
--- includes/tests/phpsavant.com/Savvy/globals/escape.arrays.phpt (revision 0)
+++ includes/tests/phpsavant.com/Savvy/globals/escape.arrays.phpt (revision 0)
@@ -0,0 +1,23 @@
+--TEST--
+Savvy::addGlobal() Escape added global array
+--FILE--
+<?php
+require dirname(__FILE__) . '/../test_framework.php.inc';
+chdir(__DIR__);
+$savvy = new Savvy();
+
+$savvy->setEscape('htmlspecialchars');
+
+$unescaped = array(
+ '<a href="Blah">Blah</a>'
+);
+
+$savvy->addGlobal('foo', $unescaped);
+
+$escaped = $savvy->getGlobals();
+
+echo $escaped['foo'][0];
+
+?>
+--EXPECT--
+&lt;a href=&quot;Blah&quot;&gt;Blah&lt;/a&gt;
\ No newline at end of file
Index: www/templates/html/Search.tpl.php
===================================================================
--- www/templates/html/Search.tpl.php (revision 954)
+++ www/templates/html/Search.tpl.php (working copy)
@@ -1,7 +1,7 @@
<?php
-$url = UNL_UndergraduateBulletin_Controller::getURL();
-UNL_UndergraduateBulletin_Controller::setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Search');
-UNL_UndergraduateBulletin_Controller::setReplacementData('breadcrumbs', '
+$url = $controller->getURL();
+$controller->setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Search');
+$controller->setReplacementData('breadcrumbs', '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li><a href="'.$url.'">Undergraduate Bulletin</a></li>
Index: src/UNL/UndergraduateBulletin/CourseSearch.php
===================================================================
--- src/UNL/UndergraduateBulletin/CourseSearch.php (revision 954)
+++ src/UNL/UndergraduateBulletin/CourseSearch.php (working copy)
@@ -19,7 +19,7 @@
return 'coursesearch'.serialize($this->options);
}
- function preRun()
+ function preRun($cached)
{
}
Index: includes/docs/phpsavant.com/Savvy/examples/baseball/BaseballTeam.tpl.php
===================================================================
--- includes/docs/phpsavant.com/Savvy/examples/baseball/BaseballTeam.tpl.php (revision 0)
+++ includes/docs/phpsavant.com/Savvy/examples/baseball/BaseballTeam.tpl.php (revision 0)
@@ -0,0 +1,9 @@
+<html>
+<head>
+ <title><?php echo $context->name; ?></title>
+</head>
+<body>
+ <h1><?php echo $context->name; ?></h1>
+ <?php echo $savvy->render($context->output); ?>
+</body>
+</html>
\ No newline at end of file
Index: includes/tests/phpsavant.com/Savvy/render/fastcompile.phpt
===================================================================
--- includes/tests/phpsavant.com/Savvy/render/fastcompile.phpt (revision 0)
+++ includes/tests/phpsavant.com/Savvy/render/fastcompile.phpt (revision 0)
@@ -0,0 +1,49 @@
+--TEST--
+Savvy::render() fast compiler test
+--FILE--
+<?php
+require dirname(__FILE__) . '/../test_framework.php.inc';
+chdir(__DIR__);
+$savvy = new Savvy();
+
+class Foo
+{
+ public $var1;
+ function __toString()
+ {
+ return 'test';
+ }
+}
+
+$object = new Foo();
+$object->var1 = ' is my class';
+
+$savvy->setEscape();
+mkdir(__DIR__ . '/compiled');
+$compiler = new Savvy_BasicFastCompiler(__DIR__ . DIRECTORY_SEPARATOR . 'compiled');
+$savvy->setCompiler($compiler);
+
+$test->assertEquals(__DIR__ . DIRECTORY_SEPARATOR . 'compiled' . DIRECTORY_SEPARATOR .
+ md5('.' . DIRECTORY_SEPARATOR . 'Foo.tpl.php'), $savvy->template('Foo.tpl.php'),
+ 'verify compiler is called');
+$test->assertEquals("<?php return '' . get_class(\$context) . '
+' . \$context->var1 . '';", file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'compiled' . DIRECTORY_SEPARATOR .
+ md5('.' . DIRECTORY_SEPARATOR . 'Foo.tpl.php')), 'compiled template');
+
+$test->assertEquals('Foo is my class', $savvy->render($object), 'render object');
+
+$test->assertEquals('test', $savvy->render($object, 'echostring.tpl.php'), 'render object with custom template');
+
+?>
+===DONE===
+--CLEAN--
+<?php
+$a = opendir(__DIR__ . '/compiled');
+while (false !== ($b = readdir($a))) {
+ if (is_dir(__DIR__ . '/compiled/' . $b)) continue;
+ unlink(__DIR__ . '/compiled/' . $b);
+}
+rmdir(__DIR__ . '/compiled');
+?>
+--EXPECT--
+===DONE===
\ No newline at end of file
Index: www/editor/templates/Editor/Controller.tpl.php
===================================================================
--- www/editor/templates/Editor/Controller.tpl.php (revision 954)
+++ www/editor/templates/Editor/Controller.tpl.php (working copy)
@@ -2,8 +2,8 @@
UNL_Templates::$options['version'] = 3;
UNL_Templates::$options['sharedcodepath'] = dirname(dirname(__DIR__)).'/sharedcode';
-$url = UNL_UndergraduateBulletin_Controller::getURL();
-$baseURL = UNL_UndergraduateBulletin_Controller::getBaseURL();
+$url = $controller->getURL();
+$baseURL = $controller->getBaseURL();
$page = UNL_Templates::factory('Document');
$page->doctitle = '<title>UNL | Undergraduate Bulletin</title>';
Index: www/templates/html/MajorList/SearchForm.tpl.php
===================================================================
--- www/templates/html/MajorList/SearchForm.tpl.php (revision 954)
+++ www/templates/html/MajorList/SearchForm.tpl.php (working copy)
@@ -1,4 +1,4 @@
-<form class="zenform cool" action="<?php echo UNL_UndergraduateBulletin_Controller::getURL(); ?>major/search" method="get" style="margin-top:10px;">
+<form class="zenform cool" action="<?php echo $controller->getURL(); ?>major/search" method="get" style="margin-top:10px;">
<fieldset>
<legend>Find a Major or Degree</legend>
<ol>
Index: includes/downloads/Savvy-0.7.1.tgz
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: includes/downloads/Savvy-0.7.1.tgz
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: includes/docs/phpsavant.com/Savvy/examples/baseball/index.php
===================================================================
--- includes/docs/phpsavant.com/Savvy/examples/baseball/index.php (revision 0)
+++ includes/docs/phpsavant.com/Savvy/examples/baseball/index.php (revision 0)
@@ -0,0 +1,58 @@
+<?php
+ini_set('display_errors',true);
+error_reporting(E_ALL^E_STRICT);
+require_once dirname(__FILE__).'/../../src/Savvy/Autoload.php';
+$classLoader = new Savvy_Autoload();
+$classLoader->register();
+
+class BaseballTeam
+{
+ protected $view = 'player';
+
+ protected $view_map = array(
+ 'player' => 'BaseballPlayer'
+ );
+
+ public $name;
+
+ public $output;
+
+ function __construct($options = array())
+ {
+ if (isset($options['view'], $this->view_map[$options['view']])) {
+ $this->view = $options['view'];
+ }
+ $this->output = new $this->view_map[$this->view]();
+ }
+}
+
+class BaseballPlayer
+{
+ public $name = 'Joseph Baseball <AKA: Joey B>';
+ public $years_on_team = array(2005, 2008);
+ function __construct()
+ {
+ $this->years_on_team[] = new PartialSeason(date('Y'));
+ }
+}
+
+class PartialSeason
+{
+ public $start;
+ public $end;
+
+ function __construct($start, $end = null)
+ {
+ $this->start = $start;
+ if ($end) {
+ $this->end = $end;
+ }
+ }
+}
+
+$team = new BaseballTeam();
+$team->name = 'Phillies';
+
+$savvy = new Savvy();
+$savvy->setEscape('htmlspecialchars');
+echo $savvy->render($team);
\ No newline at end of file
Index: www/templates/html/Major.tpl.php
===================================================================
--- www/templates/html/Major.tpl.php (revision 954)
+++ www/templates/html/Major.tpl.php (working copy)
@@ -1,9 +1,9 @@
<?php
-$url = UNL_UndergraduateBulletin_Controller::getURL();
-UNL_UndergraduateBulletin_Controller::setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | '.$context->title);
-UNL_UndergraduateBulletin_Controller::setReplacementData('pagetitle', '<h2>'.$context->title.'</h2>');
-UNL_UndergraduateBulletin_Controller::setReplacementData('head', '<script type="text/javascript" src="'.$url.'templates/html/scripts/jQuery.toc.js"></script>');
-UNL_UndergraduateBulletin_Controller::setReplacementData('breadcrumbs', '
+$url = $controller->getURL();
+$controller->setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | '.$context->title);
+$controller->setReplacementData('pagetitle', '<h2>'.$context->title.'</h2>');
+$controller->setReplacementData('head', '<script type="text/javascript" src="'.$url.'templates/html/scripts/jQuery.toc.js"></script>');
+$controller->setReplacementData('breadcrumbs', '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li><a href="'.$url.'">Undergraduate Bulletin</a></li>
Index: www/templates/html/CourseSearchForm.tpl.php
===================================================================
--- www/templates/html/CourseSearchForm.tpl.php (revision 954)
+++ www/templates/html/CourseSearchForm.tpl.php (working copy)
@@ -1,4 +1,4 @@
-<form class="zenform cool coursesearch" action="<?php echo UNL_UndergraduateBulletin_Controller::getURL(); ?>courses/search" method="get">
+<form class="zenform cool coursesearch" action="<?php echo $controller->getURL(); ?>courses/search" method="get">
<fieldset>
<legend>Find a Course</legend>
<ol>
Index: includes/tests/phpsavant.com/Savvy/test_framework.php.inc
===================================================================
--- includes/tests/phpsavant.com/Savvy/test_framework.php.inc (revision 0)
+++ includes/tests/phpsavant.com/Savvy/test_framework.php.inc (revision 0)
@@ -0,0 +1,212 @@
+<?php
+$__e = error_reporting();
+error_reporting(E_ERROR|E_NOTICE|E_WARNING);
+require_once dirname(__FILE__) . '/../src/Savvy/Autoload.php';
+$classLoader = new Savvy_Autoload();
+$classLoader->register();
+@include_once 'Text/Diff.php';
+@include_once 'Text/Diff/Renderer.php';
+@include_once 'Text/Diff/Renderer/unified.php';
+error_reporting($__e);
+class PEAR2_PHPT
+{
+ var $_diffonly;
+ function __construct($diffonly = false)
+ {
+ $this->_diffonly = $diffonly;
+ $this->_errors = array();
+ }
+
+ function assertTrue($test, $message)
+ {
+ if ($test === true) {
+ return true;
+ }
+ $this->_failTest(debug_backtrace(), $message);
+ echo "Unexpected non-true value: \n";
+ var_export($test);
+ echo "\n'$message'\n";
+ return false;
+ }
+
+ function assertIsa($control, $test, $message)
+ {
+ if (is_a($test, $control)) {
+ return true;
+ }
+ $this->_failTest(debug_backtrace(), $message);
+ echo "Unexpected non-$control object: \n";
+ var_export($test);
+ echo "\n'$message'\n";
+ return false;
+ }
+
+ function assertNull($test, $message)
+ {
+ if ($test === null) {
+ return true;
+ }
+ $this->_failTest(debug_backtrace(), $message);
+ echo "Unexpected non-null value: \n";
+ var_export($test);
+ echo "\n'$message'\n";
+ return false;
+ }
+
+ function assertNotNull($test, $message)
+ {
+ if ($test !== null) {
+ return true;
+ }
+ $this->_failTest(debug_backtrace(), $message);
+ echo "Unexpected null: \n";
+ var_export($test);
+ echo "\n'$message'\n";
+ return false;
+ }
+
+ function assertSame($test, $test1, $message)
+ {
+ if ($test === $test1) {
+ return true;
+ }
+ $this->_failTest(debug_backtrace(), $message);
+ echo "Unexpectedly two vars are not the same thing: \n";
+ echo "\n'$message'\n";
+ return false;
+ }
+
+ function assertNotSame($test, $test1, $message)
+ {
+ if ($test !== $test1) {
+ return true;
+ }
+ $this->_failTest(debug_backtrace(), $message);
+ echo "Unexpectedly two vars are the same thing: \n";
+ echo "\n'$message'\n";
+ return false;
+ }
+
+ function assertFalse($test, $message)
+ {
+ if ($test === false) {
+ return true;
+ }
+ $this->_failTest(debug_backtrace(), $message);
+ echo "Unexpected non-false value: \n";
+ var_export($test);
+ echo "\n'$message'\n";
+ return false;
+ }
+
+ function assertNotTrue($test, $message)
+ {
+ if (!$test) {
+ return true;
+ }
+ $this->_failTest(debug_backtrace(), $message);
+ echo "Unexpected loose true value: \n";
+ var_export($test);
+ echo "\n'$message'\n";
+ return false;
+ }
+
+ function assertNotFalse($test, $message)
+ {
+ if ($test) {
+ return true;
+ }
+ $this->_failTest(debug_backtrace(), $message);
+ echo "Unexpected loose false value: \n";
+ var_export($test);
+ echo "\n'$message'\n";
+ return false;
+ }
+
+ function assertRegex($regex, $test, $message)
+ {
+ if (!preg_match($regex, $test)) {
+ $this->_failTest(debug_backtrace(), $message);
+ echo "Expecting:\nText Matching Regular Expression $regex\n";
+ echo "\nReceived:\n";
+ var_export($test);
+ echo "\n";
+ return false;
+ }
+ return true;
+ }
+
+ function assertException($exception, $class, $emessage, $message)
+ {
+ if (!($exception instanceof $class)) {
+ $this->_failTest(debug_backtrace(), $message);
+ echo "Expecting class $class, got ", get_class($exception);
+ }
+ $this->assertEquals($emessage, $exception->getMessage(), $message, debug_backtrace());
+ }
+
+ function assertEquals($control, $test, $message, $trace = null)
+ {
+ if (!$trace) {
+ $trace = debug_backtrace();
+ }
+ if (str_replace(array("\r", "\n"), array('', ''),
+ var_export($control, true)) != str_replace(array("\r", "\n"), array('', ''),
+ var_export($test, true))) {
+ $this->_failTest($trace, $message);
+ if (class_exists('Text_Diff', false)) {
+ echo "Diff of expecting/received:\n";
+ $diff = new Text_Diff(
+ explode("\n", var_export($control, true)),
+ explode("\n", var_export($test, true)));
+
+ // Output the diff in unified format.
+ $renderer = new Text_Diff_Renderer_unified();
+ echo $renderer->render($diff);
+ if ($this->_diffonly) {
+ return false;
+ }
+ }
+ echo "Expecting:\n";
+ var_export($control);
+ echo "\nReceived:\n";
+ var_export($test);
+ echo "\n";
+ return false;
+ }
+ return true;
+ }
+
+ function assertFileExists($fname, $message)
+ {
+ if (!@file_exists($fname)) {
+ $this->_failTest(debug_backtrace(), $message);
+ echo "File '$fname' does not exist, and should\n";
+ return false;
+ }
+ return true;
+ }
+
+ function assertFileNotExists($fname, $message)
+ {
+ if (@file_exists($fname)) {
+ $this->_failTest(debug_backtrace(), $message);
+ echo "File '$fname' exists, and should not\n";
+ return false;
+ }
+ return true;
+ }
+
+ function _failTest($trace, $message)
+ {
+ echo 'Test Failure: "' . $message . "\"\n in " . $trace[0]['file'] . ' line ' .
+ $trace[0]['line'] . "\n";
+ }
+
+ function showAll()
+ {
+ $this->_diffonly = false;
+ }
+}
+$test = new PEAR2_PHPT();
+?>
Index: www/templates/html/Major/Description.tpl.php
===================================================================
--- www/templates/html/Major/Description.tpl.php (revision 954)
+++ www/templates/html/Major/Description.tpl.php (working copy)
@@ -1,5 +1,5 @@
<?php
- $url = UNL_UndergraduateBulletin_Controller::getURL();
+ $url = $controller->getURL();
$regions = array(
'description' => 'Description',
'admission' => 'Admission',
Index: includes/.xmlregistry/packages/phpsavant.com/Savvy/0.7.1-info.xml
===================================================================
--- includes/.xmlregistry/packages/phpsavant.com/Savvy/0.7.1-info.xml (revision 0)
+++ includes/.xmlregistry/packages/phpsavant.com/Savvy/0.7.1-info.xml (revision 0)
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package xmlns="http://pear.php.net/dtd/package-2.1" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.1 http://pear.php.net/dtd/package-2.1.xsd" packagerversion="2.0.0">
+ <name>Savvy</name>
+ <channel>phpsavant.com</channel>
+ <summary>Savvy is a powerful but lightweight object-oriented template system for PHP.
+</summary>
+ <description>
+Unlike other template systems, Savvy by default does not compile your
+templates into PHP; instead, it uses PHP itself as its template language so you
+don't need to learn a new markup system.</description>
+ <lead>
+ <name>Brett Bieber</name>
+ <user>saltybeagle</user>
+ <email>saltybeagle@php.net</email>
+ <active>yes</active>
+ </lead>
+ <lead>
+ <name>Gregory Beaver</name>
+ <user>cellog</user>
+ <email>cellog@php.net</email>
+ <active>yes</active>
+ </lead>
+ <date>2011-05-31</date>
+ <time>16:41:25</time>
+ <version>
+ <release>0.7.1</release>
+ <api>0.1.0</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD License</license>
+ <notes>Bugfix Release:
+
+ - Improve escaping of arrays
+ - Add tests for globals
+
+
+Package Savvy API release notes for version 0.1.0.</notes>
+ <contents>
+ <dir name="/">
+ <file role="test" name="tests/test_framework.php.inc" md5sum="d7b66614eef48d4945901a43a9568b14"/>
+ <file role="test" name="tests/render/string.phpt" md5sum="1a60e68f87d277aa9c653472b8c0ef76"/>
+ <file role="test" name="tests/render/object.phpt" md5sum="5555262b6c42f604b38f3e3aaf77e974"/>
+ <file role="test" name="tests/render/Foo.tpl.php" md5sum="2af7ae28b4d35227c53921eaabfaeaad"/>
+ <file role="test" name="tests/render/fastcompile.phpt" md5sum="923e958a495177f4be567abd6d7d37f6"/>
+ <file role="test" name="tests/render/echostring.tpl.php" md5sum="138231e0b170c36ff602c09eaaa1690f"/>
+ <file role="test" name="tests/render/array.phpt" md5sum="3f284e6ec2d710398f4b67378f373de4"/>
+ <file role="test" name="tests/globals/escape.phpt" md5sum="d1b9276341877c681e62ddad93d2d1dc"/>
+ <file role="test" name="tests/globals/escape.nestedarrays.phpt" md5sum="7f1e04a1302995ed6c0a43d525ebd73d"/>
+ <file role="test" name="tests/globals/escape.arrays.phpt" md5sum="20312ab95ea7901b79e21fdd61f5dca4"/>
+ <file role="test" name="tests/globals/basic.tpl.php" md5sum="7898705f5a0a5792a191cca28501e22e"/>
+ <file role="test" name="tests/globals/basic.phpt" md5sum="ac2ae80d9f5344694e6f2d90c0417b2c"/>
+ <file role="test" name="tests/escape/string.phpt" md5sum="4fd594fef7e7621e79cefa341c2439a0"/>
+ <file role="test" name="tests/escape/raw.tpl.php" md5sum="2e7b87c466f106a575d6740258356109"/>
+ <file role="test" name="tests/escape/object.phpt" md5sum="7012a6b97c7cb20391bde8243b582e1b"/>
+ <file role="test" name="tests/escape/Foo.tpl.php" md5sum="d960fd1fa4867a04702db10cda65d772"/>
+ <file role="test" name="tests/escape/echostring.tpl.php" md5sum="a45c7c6b67b56e43935d844f358f080b"/>
+ <file role="php" name="src/Savvy/UnexpectedValueException.php" md5sum="bc88ee83b651bea0cb3190c4785be447"/>
+ <file role="php" name="src/Savvy/TemplateException.php" md5sum="0dcf725a67d3db2457f4f9793654e8d1"/>
+ <file role="php" name="src/Savvy/ObjectProxy/Traversable.php" md5sum="d8ecfde88e9de6d70e051ac27c1f5952"/>
+ <file role="php" name="src/Savvy/ObjectProxy/ArrayAccess.php" md5sum="a18cde5a30fcd4f6c5b6437a1fa702d9"/>
+ <file role="php" name="src/Savvy/ObjectProxy.php" md5sum="e00947b3a0e75f35076592189fed7737"/>
+ <file role="php" name="src/Savvy/MapperInterface.php" md5sum="127c43a259b071872044a492d101faca"/>
+ <file role="php" name="src/Savvy/FilterAbstract.php" md5sum="dc9abe43fa8f2a7ec038d8bc4e2fd0da"/>
+ <file role="php" name="src/Savvy/FastCompilerInterface.php" md5sum="213b589107a0b18d2074167f2d0fe864"/>
+ <file role="php" name="src/Savvy/Exception.php" md5sum="1e05784e2648c5daf2bf8848f302290d"/>
+ <file role="php" name="src/Savvy/CompilerInterface.php" md5sum="45622fa0a1eea84981eb8265b43ce2da"/>
+ <file role="php" name="src/Savvy/CompilerException.php" md5sum="05e9107fb803c7f54d512a4daee8cd30"/>
+ <file role="php" name="src/Savvy/ClassToTemplateMapper.php" md5sum="fd04a4a3f7bb2e2317bc32e5451b56a3"/>
+ <file role="php" name="src/Savvy/BasicFastCompiler.php" md5sum="313d6d9ac280509c7f0e072e6841d80d"/>
+ <file role="php" name="src/Savvy/BadMethodCallException.php" md5sum="e5d06612d101d72bc82709df7ae0426e"/>
+ <file role="php" name="src/Savvy/Autoload.php" md5sum="c0ee9b9628bed191991bc641721a39d8"/>
+ <file role="php" name="src/Savvy.php" md5sum="2a296e078915d90395ad47b1dd5ad4dc"/>
+ <file role="doc" name="examples/templates/StringView.tpl.php" md5sum="b4746d9c4e29624cb75c4bbf74600371"/>
+ <file role="doc" name="examples/templates/stdClass.tpl.php" md5sum="ecb083ab102eac7b1bc6d5306092b36d"/>
+ <file role="doc" name="examples/templates/MyTemplate.tpl.php" md5sum="b7004c1f5eed19602e5c7afe97dbbd27"/>
+ <file role="doc" name="examples/basic.php" md5sum="74ae4c065f1920ecfb59e9a9ad6e3746"/>
+ <file role="doc" name="examples/baseball/PartialSeason.tpl.php" md5sum="028f2aa4e14931455bf1c2b89407def3"/>
+ <file role="doc" name="examples/baseball/ListItem.tpl.php" md5sum="606d5c6b9e5987776d70f5eb4431783d"/>
+ <file role="doc" name="examples/baseball/index.php" md5sum="3a7e6408b0fc2ad9a2ff6fcbeee4a43a"/>
+ <file role="doc" name="examples/baseball/BaseballTeam.tpl.php" md5sum="dd3d25e88626d358a05050b3a5b22f78"/>
+ <file role="doc" name="examples/baseball/BaseballPlayer.tpl.php" md5sum="ff0ddb3f097ac934f71c442d6893bece"/>
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.2.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.0</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <phprelease/>
+</package>
Index: includes/tests/phpsavant.com/Savvy/render/Foo.tpl.php
===================================================================
--- includes/tests/phpsavant.com/Savvy/render/Foo.tpl.php (revision 0)
+++ includes/tests/phpsavant.com/Savvy/render/Foo.tpl.php (revision 0)
@@ -0,0 +1,2 @@
+<?php echo get_class($context) ?>
+<?php echo $context->var1 ?>
\ No newline at end of file
Index: www/index.php
===================================================================
--- www/index.php (revision 954)
+++ www/index.php (working copy)
@@ -8,9 +8,18 @@
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "UTF-8");
+if (!isset($defaultExpireTimestamp)) {
+ $defaultExpireTimestamp = strtotime('+1 week');
+}
+
+if (!isset($cache)) {
+ $cache = new UNL_UndergraduateBulletin_CacheInterface_UNLCacheLite();
+}
+
$controller = new UNL_UndergraduateBulletin_Controller(UNL_UndergraduateBulletin_Router::getRoute($_SERVER['REQUEST_URI']) + $_GET);
$outputcontroller = new UNL_UndergraduateBulletin_OutputController();
+$outputcontroller->setCacheInterface($cache);
$outputcontroller->setTemplatePath(dirname(__FILE__).'/templates/html');
switch($controller->options['format']) {
@@ -35,5 +44,6 @@
$outputcontroller->setEscape('htmlentities');
$outputcontroller->addFilters(array($controller, 'postRun'));
+$outputcontroller->addGlobal('controller', $controller);
echo $outputcontroller->render($controller);
Index: www/templates/html/About.tpl.php
===================================================================
--- www/templates/html/About.tpl.php (revision 954)
+++ www/templates/html/About.tpl.php (working copy)
@@ -1,7 +1,7 @@
<?php
-$url = UNL_UndergraduateBulletin_Controller::getURL();
-UNL_UndergraduateBulletin_Controller::setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | About the Bulletin');
-UNL_UndergraduateBulletin_Controller::setReplacementData('breadcrumbs', '
+$url = $controller->getURL();
+$controller->setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | About the Bulletin');
+$controller->setReplacementData('breadcrumbs', '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li><a href="'.$url.'">Undergraduate Bulletin</a></li>
Index: www/templates/html/CourseSearch.tpl.php
===================================================================
--- www/templates/html/CourseSearch.tpl.php (revision 954)
+++ www/templates/html/CourseSearch.tpl.php (working copy)
@@ -5,11 +5,11 @@
return;
}
-$url = UNL_UndergraduateBulletin_Controller::getURL();
+$url = $controller->getURL();
if (isset($context->options['view'])
&& $context->options['view'] == 'searchcourses') {
- UNL_UndergraduateBulletin_Controller::setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Courses | Search');
- UNL_UndergraduateBulletin_Controller::setReplacementData('breadcrumbs', '
+ $controller->setReplacementData('doctitle', 'UNL | Undergraduate Bulletin | Courses | Search');
+ $controller->setReplacementData('breadcrumbs', '
<ul>
<li><a href="http://www.unl.edu/">UNL</a></li>
<li><a href="'.$url.'">Undergraduate Bulletin</a></li>
Index: includes/tests/phpsavant.com/Savvy/escape/raw.tpl.php
===================================================================
--- includes/tests/phpsavant.com/Savvy/escape/raw.tpl.php (revision 0)
+++ includes/tests/phpsavant.com/Savvy/escape/raw.tpl.php (revision 0)
@@ -0,0 +1,3 @@
+<?php
+echo $context->getRaw('var1');
+?>
\ No newline at end of file
Index: src/UNL/UndergraduateBulletin/CacheableInterface.php
===================================================================
--- src/UNL/UndergraduateBulletin/CacheableInterface.php (revision 954)
+++ src/UNL/UndergraduateBulletin/CacheableInterface.php (working copy)
@@ -4,9 +4,6 @@
*
* @author bbieber
*/
-interface UNL_UndergraduateBulletin_CacheableInterface
+interface UNL_UndergraduateBulletin_CacheableInterface extends Savvy_Turbo_CacheableInterface
{
- public function getCacheKey();
- public function run();
- public function preRun();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment