summaryrefslogtreecommitdiffstats
path: root/lib/template.php
diff options
context:
space:
mode:
authorJakob Sack <kde@jakobsack.de>2011-03-02 11:56:48 +0100
committerJakob Sack <kde@jakobsack.de>2011-03-02 11:56:48 +0100
commit66ac355f7845c56589dcd6c10a92a25af48c97fc (patch)
tree6f8563c33ece2b61cfe5482bf755a87d579ed378 /lib/template.php
parent015ab0eb6424bbde90f36a087326e769233ac577 (diff)
downloadnextcloud-server-66ac355f7845c56589dcd6c10a92a25af48c97fc.tar.gz
nextcloud-server-66ac355f7845c56589dcd6c10a92a25af48c97fc.zip
Getting rid of Smarty, using our own template system
Diffstat (limited to 'lib/template.php')
-rw-r--r--lib/template.php80
1 files changed, 42 insertions, 38 deletions
diff --git a/lib/template.php b/lib/template.php
index 0973d60c72d..7321d9957f5 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -21,74 +21,64 @@
*
*/
-oc_require_once( "Smarty/Smarty.class.php" );
-
/**
*
*/
-function oc_template_helper_link_to( $params, $smarty ){
- $app = "";
- if( isset( $params["app"] ))
- {
- $app = $params["app"];
- }
- $file = $params["file"];
+function link_to( $app, $file ){
return OC_UTIL::linkTo( $app, $file );
}
/**
*
*/
-function oc_template_helper_image_path( $params, $smarty ){
- $app = "";
- if( isset( $params["app"] ))
- {
- $app = $params["app"];
- }
- $file = $params["file"];
+function image_path( $app, $file ){
return OC_UTIL::imagePath( $app, $file );
}
class OC_TEMPLATE{
private $renderas; // Create a full page?
- private $name; // name of the template
private $application; // template Application
- private $smarty; // The smarty object
+ private $vars; // The smarty object
+ private $template; // The smarty object
public function __construct( $application, $name, $renderas = "" ){
// Global vars we need
global $SERVERROOT;
- $template_dir = "$SERVERROOT/templates/";
+ $template = "$SERVERROOT/templates/";
// Get the right template folder
- if( $application != "core" ){
- $template_dir = "$SERVERROOT/$application/templates/";
+ if( $application != "core" && $application != "" ){
+ $template = "$SERVERROOT/$application/templates/";
}
- // Set the OC-defaults for Smarty
- $smarty = new Smarty();
- $smarty->left_delimiter = "[%";
- $smarty->right_delimiter = "%]";
- $smarty->template_dir = $template_dir;
- $smarty->compile_dir = "$SERVERROOT/templates/_c";
- $smarty->registerPlugin( "function", "linkto", "oc_template_helper_link_to");
- $smarty->registerPlugin( "function", "imagepath", "oc_template_helper_image_path");
-
// Templates have the ending .tmpl
- $name = "$name.tmpl";
+ $template .= "$name.php";
+
// Set the private data
$this->renderas = $renderas;
$this->application = $application;
- $this->name = $name;
- $this->smarty = $smarty;
+ $this->template = $template;
+ $this->vars = array();
}
- public function assign( $a, $b = null ){
- $this->smarty->assign( $a, $b );
+ public function assign( $a, $b ){
+ $this->vars[$a] = $b;
}
- public function append( $a, $b = null ){
- $this->smarty->append( $a, $b );
+ public function append( $a, $b ){
+ if( array_key_exists( $this->vars[$a] )){
+ if( is_a( $this->vars[$a], "array" )){
+ $this->vars[$a][] = $b;
+ }
+ else
+ {
+ $array = array( $this->vars[$a], $b );
+ $this->vars[$a] = $array;
+ }
+ }
+ else{
+ $this->vars[$a] = $b;
+ }
}
public function printPage()
@@ -109,7 +99,7 @@ class OC_TEMPLATE{
{
// global Data we need
global $WEBROOT;
- $data = $this->smarty->fetch( $this->name );
+ $data = $this->_fetch();
if( $this->renderas )
{
@@ -154,6 +144,20 @@ class OC_TEMPLATE{
public function __destruct(){
}
+ private function _fetch(){
+ // Register the variables
+ $_ = $this->vars;
+
+ // Execute the template
+ ob_start();
+ oc_include( $this->template );
+ $data = ob_get_contents();
+ ob_end_clean();
+
+ // return the data
+ return $data;
+ }
+
/**
* @brief Shortcut to print a simple page for users
* @param $application The application we render the template for