Updated FP-specific Smarty plugins to v4 OOP style. Moved list_categories plugin to the Smarty plugin folder in order to have it loaded properly.
This commit is contained in:
parent
52bf429a01
commit
fb43fe3ea9
@ -1,157 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* File: function.list_categories.php
|
||||
* Type: function
|
||||
* Name: list_categories
|
||||
* Purpose: print out the comment form
|
||||
*
|
||||
* @param string after
|
||||
* @param string before
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_function_list_categories($params) //, &$smarty)
|
||||
{
|
||||
$cat_params = array(
|
||||
'ild'=>'<li>','ird'=>"</li>\n",
|
||||
'old'=>"<ul>\n",'ord'=>"</ul>\n",
|
||||
'name' => isset($params['name'])? $params['name'] : '',
|
||||
'selected' => array()
|
||||
);
|
||||
|
||||
$cat_params = array_merge($cat_params, $params);
|
||||
|
||||
// makese 'selected' an arr
|
||||
$cat_params['selected'] = (array)$params['selected'];
|
||||
|
||||
//echo "<pre>" . print_r(entry_categories_get()) . "</pre>";
|
||||
|
||||
if (file_exists(CONTENT_DIR . 'categories.txt')) {
|
||||
$cats = trim(io_load_file(CONTENT_DIR . 'categories.txt'));
|
||||
$stack=array(0);
|
||||
$arr=array();
|
||||
|
||||
$line36error = explode("\n", $cats);
|
||||
$line35error = '<ul>'.do_print_categories_list($line36error, $stack, $arr, $cat_params).'</ul>';
|
||||
|
||||
return $line35error;
|
||||
} else {
|
||||
global $lang;
|
||||
|
||||
$content = '<a href="'.BLOG_BASEURL.'">Unfiled</a>';
|
||||
if (isset($lang['admin']['entry']['publish']['nocategories']))
|
||||
$content = $lang['admin']['entry']['publish']['nocategories'];
|
||||
return '<ul><li>' . $content .'</li></ul>' ;
|
||||
}
|
||||
|
||||
//<label><input name="cats[{$catId}]"
|
||||
//{if (bool)array_intersect(array($catId),$categories) }
|
||||
//checked="checked"{/if} type="checkbox" /> {$cat} </label><br />
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function do_print_categories_list(&$lines, &$indentstack, &$result, $params) {
|
||||
|
||||
global $smarty, $fpdb;
|
||||
|
||||
extract($params);
|
||||
|
||||
if (empty($lines)) {
|
||||
$l = count($indentstack)-1;
|
||||
if ($l > 0)
|
||||
$arr = array_fill(0, $l, $ord.$ird);
|
||||
else
|
||||
$arr = array();
|
||||
|
||||
$result = array_merge($result, $arr);
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
$str = '';
|
||||
$v = reset($lines);
|
||||
$vt = ltrim($v);
|
||||
|
||||
$indent = utils_countdashes($vt, $text);
|
||||
$indent_old = end($indentstack);
|
||||
|
||||
$val = explode(':', $text);
|
||||
$vt = $val[0];
|
||||
$vid = trim($val[1]);
|
||||
|
||||
$catname = $params['name'];
|
||||
|
||||
if ($indent > $indent_old) {
|
||||
array_push($indentstack, $indent);
|
||||
|
||||
array_pop($result);
|
||||
array_push($result, $old);
|
||||
//array_push($result, $ild);
|
||||
do_print_categories_list($lines, $indentstack, $result, $params);
|
||||
}elseif($indent < $indent_old) {
|
||||
array_pop($indentstack);
|
||||
|
||||
array_push($result, $ord);
|
||||
array_push($result, $ird);
|
||||
|
||||
do_print_categories_list($lines, $indentstack, $result, $params);
|
||||
}else{
|
||||
array_push($result, $ild);
|
||||
|
||||
|
||||
$cat_entry = $params['selected'];
|
||||
|
||||
if (isset($params['type']) && ($params['type']=='form' || $params['type']=='check')) {
|
||||
$string = '<label><input name="'.$catname.'cats['.$vid.']" ';
|
||||
|
||||
if ((bool) array_intersect(array($vid), $cat_entry))
|
||||
$string .= 'checked="checked" ';
|
||||
|
||||
$string .= 'type="checkbox" />';
|
||||
$before = $string;
|
||||
}elseif (isset($params['type']) && $params['type']=='radio') {
|
||||
$string = '<label><input name="'.$catname.'cats" type="radio" value="'.$vid.'"';
|
||||
if ((bool) array_intersect(array($vid), $cat_entry))
|
||||
$string .= 'checked="checked" ';
|
||||
|
||||
$string .= ' />';
|
||||
$before = $string;
|
||||
|
||||
|
||||
}elseif(isset($params['type']) && $params['type']=='linked'){
|
||||
$before = '<a href="'.get_category_link($vid).'">';
|
||||
}
|
||||
|
||||
|
||||
array_push($result, $before);
|
||||
|
||||
|
||||
array_push($result, $vt);
|
||||
|
||||
if (isset($params['type']) && ($params['type']=='form' || $params['type']=='check' || $params['type']=='radio')) {
|
||||
$string = '</label>';
|
||||
$after = $string;
|
||||
}elseif(isset($params['type']) && $params['type']=='linked'){
|
||||
$after='</a>';
|
||||
if (isset($params['count']) && $params['count']) {
|
||||
$index =& $fpdb->get_index($vid);
|
||||
$count = ($index)? $index->length() : 0;
|
||||
$after = " ($count) ". $after;
|
||||
}
|
||||
}
|
||||
|
||||
array_push($result, $after);
|
||||
|
||||
array_push($result, $ird);
|
||||
array_shift($lines);
|
||||
do_print_categories_list($lines, $indentstack, $result, $params);
|
||||
}
|
||||
|
||||
return implode($result);
|
||||
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* File: function.list_categories.php
|
||||
* Type: function
|
||||
* Name: list_categories
|
||||
* Purpose: print out the comment form
|
||||
*
|
||||
* @param
|
||||
* string after
|
||||
* @param
|
||||
* string before
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_function_list_categories($params) // , &$smarty)
|
||||
{
|
||||
$cat_params = array(
|
||||
'ild' => '<li>',
|
||||
'ird' => "</li>\n",
|
||||
'old' => "<ul>\n",
|
||||
'ord' => "</ul>\n",
|
||||
'name' => isset($params ['name']) ? $params ['name'] : '',
|
||||
'selected' => array()
|
||||
);
|
||||
|
||||
$cat_params = array_merge($cat_params, $params);
|
||||
|
||||
// makese 'selected' an arr
|
||||
$cat_params ['selected'] = array_key_exists('selected', $params) ? (array) $params ['selected'] : false;
|
||||
|
||||
// echo "<pre>" . print_r(entry_categories_get()) . "</pre>";
|
||||
|
||||
if (file_exists(CONTENT_DIR . 'categories.txt')) {
|
||||
$cats = trim(io_load_file(CONTENT_DIR . 'categories.txt'));
|
||||
$stack = array(
|
||||
0
|
||||
);
|
||||
$arr = array();
|
||||
|
||||
$line36error = explode("\n", $cats);
|
||||
$line35error = '<ul>' . do_print_categories_list($line36error, $stack, $arr, $cat_params) . '</ul>';
|
||||
|
||||
return $line35error;
|
||||
} else {
|
||||
global $lang;
|
||||
|
||||
$content = '<a href="' . BLOG_BASEURL . '">Unfiled</a>';
|
||||
if (isset($lang ['admin'] ['entry'] ['publish'] ['nocategories']))
|
||||
$content = $lang ['admin'] ['entry'] ['publish'] ['nocategories'];
|
||||
return '<ul><li>' . $content . '</li></ul>';
|
||||
}
|
||||
|
||||
// <label><input name="cats[{$catId}]"
|
||||
// {if (bool)array_intersect(array($catId),$categories) }
|
||||
// checked="checked"{/if} type="checkbox" /> {$cat} </label><br />
|
||||
}
|
||||
|
||||
function do_print_categories_list(&$lines, &$indentstack, &$result, $params) {
|
||||
global $smarty, $fpdb;
|
||||
|
||||
extract($params);
|
||||
|
||||
if (empty($lines)) {
|
||||
$l = count($indentstack) - 1;
|
||||
if ($l > 0)
|
||||
$arr = array_fill(0, $l, $ord . $ird);
|
||||
else
|
||||
$arr = array();
|
||||
|
||||
$result = array_merge($result, $arr);
|
||||
return '';
|
||||
}
|
||||
|
||||
$str = '';
|
||||
$v = reset($lines);
|
||||
$vt = ltrim($v);
|
||||
|
||||
$indent = utils_countdashes($vt, $text);
|
||||
$indent_old = end($indentstack);
|
||||
|
||||
$val = explode(':', $text);
|
||||
$vt = $val [0];
|
||||
$vid = trim($val [1]);
|
||||
|
||||
$catname = $params ['name'];
|
||||
|
||||
if ($indent > $indent_old) {
|
||||
array_push($indentstack, $indent);
|
||||
|
||||
array_pop($result);
|
||||
array_push($result, $old);
|
||||
// array_push($result, $ild);
|
||||
do_print_categories_list($lines, $indentstack, $result, $params);
|
||||
} elseif ($indent < $indent_old) {
|
||||
array_pop($indentstack);
|
||||
|
||||
array_push($result, $ord);
|
||||
array_push($result, $ird);
|
||||
|
||||
do_print_categories_list($lines, $indentstack, $result, $params);
|
||||
} else {
|
||||
array_push($result, $ild);
|
||||
|
||||
$cat_entry = $params ['selected'];
|
||||
|
||||
if (isset($params ['type']) && ($params ['type'] == 'form' || $params ['type'] == 'check')) {
|
||||
$string = '<label><input name="' . $catname . 'cats[' . $vid . ']" ';
|
||||
|
||||
if ((bool) array_intersect(array(
|
||||
$vid
|
||||
), $cat_entry))
|
||||
$string .= 'checked="checked" ';
|
||||
|
||||
$string .= 'type="checkbox" />';
|
||||
$before = $string;
|
||||
} elseif (isset($params ['type']) && $params ['type'] == 'radio') {
|
||||
$string = '<label><input name="' . $catname . 'cats" type="radio" value="' . $vid . '"';
|
||||
if ((bool) array_intersect(array(
|
||||
$vid
|
||||
), $cat_entry))
|
||||
$string .= 'checked="checked" ';
|
||||
|
||||
$string .= ' />';
|
||||
$before = $string;
|
||||
} elseif (isset($params ['type']) && $params ['type'] == 'linked') {
|
||||
$before = '<a href="' . get_category_link($vid) . '">';
|
||||
}
|
||||
|
||||
array_push($result, $before);
|
||||
|
||||
array_push($result, $vt);
|
||||
|
||||
if (isset($params ['type']) && ($params ['type'] == 'form' || $params ['type'] == 'check' || $params ['type'] == 'radio')) {
|
||||
$string = '</label>';
|
||||
$after = $string;
|
||||
} elseif (isset($params ['type']) && $params ['type'] == 'linked') {
|
||||
$after = '</a>';
|
||||
if (isset($params ['count']) && $params ['count']) {
|
||||
$index = & $fpdb->get_index($vid);
|
||||
$count = ($index) ? $index->length() : 0;
|
||||
$after = " ($count) " . $after;
|
||||
}
|
||||
}
|
||||
|
||||
array_push($result, $after);
|
||||
|
||||
array_push($result, $ird);
|
||||
array_shift($lines);
|
||||
do_print_categories_list($lines, $indentstack, $result, $params);
|
||||
}
|
||||
|
||||
return implode($result);
|
||||
}
|
@ -1,54 +1,74 @@
|
||||
<?php
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* File: resource.plugin.php
|
||||
* Type: plugin tpls
|
||||
* Name: plugin
|
||||
* Purpose: convenient way to call stored tpls in PLUGINS_DIR
|
||||
* Use: plugin:PLUGINNAME/PLUGINFILE realpath=> PLUGINS_DIR/plugin.PLUGINNAME/PLUGINFILE
|
||||
* -------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Resoure plugin that conveniently allows to include templates from the plugin templates folder via {include file="plugin:example.tpl"}
|
||||
*
|
||||
* @author FlatPress
|
||||
* @see https://www.smarty.net/docs/en/plugins.resources.tpl
|
||||
*/
|
||||
|
||||
class Smarty_Resource_Plugin extends Smarty_Resource_Custom {
|
||||
|
||||
function smarty_resource_plugin_parsename($tpl_name) {
|
||||
$path = null;
|
||||
|
||||
$f=explode('/',$tpl_name);
|
||||
$path = ABS_PATH . PLUGINS_DIR . "{$f[0]}/tpls/{$f[1]}.tpl";
|
||||
|
||||
return $path;
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* {@inheritdoc}
|
||||
* @see Smarty_Resource_Custom::fetch()
|
||||
*/
|
||||
protected function fetch($name, &$source, &$mtime) {
|
||||
$filePath = $this->getFilePath($name);
|
||||
|
||||
function smarty_resource_plugin_source($tpl_name, &$tpl_source, &$smarty)
|
||||
{
|
||||
$fname = smarty_resource_plugin_parsename($tpl_name);
|
||||
if ($tpl_source = io_load_file($fname)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
if ($source = io_load_file($filePath)) {
|
||||
$mtime = filemtime($filePath);
|
||||
} else {
|
||||
$source = null;
|
||||
$mtime = null;
|
||||
}
|
||||
}
|
||||
|
||||
private function getFilePath($templateName) {
|
||||
$path = null;
|
||||
|
||||
$f = explode('/', $templateName);
|
||||
$path = ABS_PATH . PLUGINS_DIR . "{$f[0]}/tpls/{$f[1]}.tpl";
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function smarty_resource_plugin_timestamp($tpl_name, &$tpl_timestamp, &$smarty)
|
||||
{
|
||||
$fname = smarty_resource_plugin_parsename($tpl_name);
|
||||
if (file_exists($fname)) {
|
||||
$tpl_timestamp = filemtime($fname);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// /*
|
||||
// * Smarty plugin
|
||||
// * -------------------------------------------------------------
|
||||
// * File: resource.plugin.php
|
||||
// * Type: plugin tpls
|
||||
// * Name: plugin
|
||||
// * Purpose: convenient way to call stored tpls in PLUGINS_DIR
|
||||
// * Use: plugin:PLUGINNAME/PLUGINFILE realpath=> PLUGINS_DIR/plugin.PLUGINNAME/PLUGINFILE
|
||||
// * -------------------------------------------------------------
|
||||
// */
|
||||
// function smarty_resource_plugin_parsename($tpl_name) {
|
||||
// $path = null;
|
||||
|
||||
function smarty_resource_plugin_secure($tpl_name, &$smarty)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// $f = explode('/', $tpl_name);
|
||||
// $path = ABS_PATH . PLUGINS_DIR . "{$f[0]}/tpls/{$f[1]}.tpl";
|
||||
|
||||
function smarty_resource_plugin_trusted($tpl_name, &$smarty)
|
||||
{
|
||||
|
||||
}
|
||||
?>
|
||||
// return $path;
|
||||
// }
|
||||
|
||||
// function smarty_resource_plugin_source($tpl_name, &$tpl_source, &$smarty) {
|
||||
// $fname = smarty_resource_plugin_parsename($tpl_name);
|
||||
// if ($tpl_source = io_load_file($fname)) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// function smarty_resource_plugin_timestamp($tpl_name, &$tpl_timestamp, &$smarty) {
|
||||
// $fname = smarty_resource_plugin_parsename($tpl_name);
|
||||
// if (file_exists($fname)) {
|
||||
// $tpl_timestamp = filemtime($fname);
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
@ -1,39 +1,25 @@
|
||||
<?php
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* File: resource.shared.php
|
||||
* Type: shared tpls
|
||||
* Name: shared
|
||||
* Purpose: convenient way to call stored tpls in SHARED_TPLS
|
||||
* -------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Resoure plugin that conveniently allows to include templates from the shared templates folder via {include file="shared:example.tpl"}
|
||||
*
|
||||
* @author FlatPress
|
||||
* @see https://www.smarty.net/docs/en/plugins.resources.tpl
|
||||
*/
|
||||
function smarty_resource_shared_source($tpl_name, &$tpl_source, &$smarty)
|
||||
{
|
||||
if ($tpl_source = io_load_file(SHARED_TPLS . $tpl_name)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
class Smarty_Resource_Shared extends Smarty_Resource_Custom {
|
||||
|
||||
function smarty_resource_shared_timestamp($tpl_name, &$tpl_timestamp, &$smarty)
|
||||
{
|
||||
if (file_exists(SHARED_TPLS . $tpl_name)) {
|
||||
$tpl_timestamp = filemtime(SHARED_TPLS . $tpl_name);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* {@inheritdoc}
|
||||
* @see Smarty_Resource_Custom::fetch()
|
||||
*/
|
||||
protected function fetch($name, &$source, &$mtime) {
|
||||
if ($source = io_load_file(SHARED_TPLS . $name)) {
|
||||
$mtime = filemtime(SHARED_TPLS . $name);
|
||||
} else {
|
||||
$source = null;
|
||||
$mtime = null;
|
||||
}
|
||||
}
|
||||
|
||||
function smarty_resource_shared_secure($tpl_name, &$smarty)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
function smarty_resource_shared_trusted($tpl_name, &$smarty)
|
||||
{
|
||||
|
||||
}
|
||||
?>
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user