mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-17 04:45:16 +02:00
template engine rework
- use smarty3 as default engine - new pluggable template engine system
This commit is contained in:
parent
a34b1ceb3a
commit
ddf1caf0fd
5 changed files with 136 additions and 34 deletions
74
boot.php
74
boot.php
|
@ -385,6 +385,11 @@ if(! class_exists('App')) {
|
|||
'stylesheet' => '',
|
||||
'template_engine' => 'internal',
|
||||
);
|
||||
|
||||
// array of registered template engines ('name'=>'class name')
|
||||
public $template_engines = array();
|
||||
// array of instanced template engines ('name'=>'instance')
|
||||
public $template_engine_instance = array();
|
||||
|
||||
private $ldelim = array(
|
||||
'internal' => '',
|
||||
|
@ -539,6 +544,17 @@ if(! class_exists('App')) {
|
|||
$mobile_detect = new Mobile_Detect();
|
||||
$this->is_mobile = $mobile_detect->isMobile();
|
||||
$this->is_tablet = $mobile_detect->isTablet();
|
||||
|
||||
/**
|
||||
* register template engines
|
||||
*/
|
||||
$dc = get_declared_classes();
|
||||
foreach ($dc as $k) {
|
||||
if (in_array("ITemplateEngine", class_implements($k))){
|
||||
$this->register_template_engine($k);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function get_basepath() {
|
||||
|
@ -712,13 +728,63 @@ if(! class_exists('App')) {
|
|||
return $this->cached_profile_image[$avatar_image];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* register template engine class
|
||||
* if $name is "", is used class static property $class::$name
|
||||
* @param string $class
|
||||
* @param string $name
|
||||
*/
|
||||
function register_template_engine($class, $name = '') {
|
||||
if ($name===""){
|
||||
$v = get_class_vars( $class );
|
||||
if(x($v,"name")) $name = $v['name'];
|
||||
}
|
||||
if ($name===""){
|
||||
echo "template engine <tt>$class</tt> cannot be registered without a name.\n";
|
||||
killme();
|
||||
}
|
||||
$this->template_engines[$name] = $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* return template engine instance. If $name is not defined,
|
||||
* return engine defined by theme, or default
|
||||
*
|
||||
* @param strin $name Template engine name
|
||||
* @return object Template Engine instance
|
||||
*/
|
||||
function template_engine($name = ''){
|
||||
|
||||
if ($name!=="") {
|
||||
$template_engine = $name;
|
||||
} else {
|
||||
$template_engine = 'smarty3';
|
||||
if (x($this->theme, 'template_engine')) {
|
||||
$template_engine = $this->theme['template_engine'];
|
||||
}
|
||||
}
|
||||
if (isset($this->template_engines[$template_engine])){
|
||||
if(isset($this->template_engine_instance[$template_engine])){
|
||||
return $this->template_engine_instance[$template_engine];
|
||||
} else {
|
||||
$class = $this->template_engines[$template_engine];
|
||||
$obj = new $class;
|
||||
$this->template_engine_instance[$template_engine] = $obj;
|
||||
return $obj;
|
||||
}
|
||||
}
|
||||
|
||||
echo "template engine <tt>$template_engine</tt> is not registered!\n"; killme();
|
||||
}
|
||||
|
||||
function get_template_engine() {
|
||||
return $this->theme['template_engine'];
|
||||
}
|
||||
|
||||
function set_template_engine($engine = 'internal') {
|
||||
function set_template_engine($engine = 'smarty3') {
|
||||
|
||||
$this->theme['template_engine'] = 'internal';
|
||||
$this->theme['template_engine'] = 'smarty3';
|
||||
|
||||
switch($engine) {
|
||||
case 'smarty3':
|
||||
|
@ -730,11 +796,11 @@ if(! class_exists('App')) {
|
|||
}
|
||||
}
|
||||
|
||||
function get_template_ldelim($engine = 'internal') {
|
||||
function get_template_ldelim($engine = 'smarty3') {
|
||||
return $this->ldelim[$engine];
|
||||
}
|
||||
|
||||
function get_template_rdelim($engine = 'internal') {
|
||||
function get_template_rdelim($engine = 'smarty3') {
|
||||
return $this->rdelim[$engine];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue