add version info to the Template plugin
This commit is contained in:
parent
0587dcc045
commit
afaefa6942
|
@ -22,13 +22,13 @@ if (!defined('STATUSNET')) {
|
||||||
define('TEMPLATEPLUGIN_VERSION', '0.1');
|
define('TEMPLATEPLUGIN_VERSION', '0.1');
|
||||||
|
|
||||||
class TemplatePlugin extends Plugin {
|
class TemplatePlugin extends Plugin {
|
||||||
|
|
||||||
var $blocks = array();
|
var $blocks = array();
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
// capture the RouterInitialized event
|
// capture the RouterInitialized event
|
||||||
// and connect a new API method
|
// and connect a new API method
|
||||||
// for updating the template
|
// for updating the template
|
||||||
|
@ -37,8 +37,7 @@ class TemplatePlugin extends Plugin {
|
||||||
'action' => 'template',
|
'action' => 'template',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// <%styles%>
|
// <%styles%>
|
||||||
// <%scripts%>
|
// <%scripts%>
|
||||||
// <%search%>
|
// <%search%>
|
||||||
|
@ -50,18 +49,18 @@ class TemplatePlugin extends Plugin {
|
||||||
$act->extraHead();
|
$act->extraHead();
|
||||||
$this->blocks['head'] = $act->xw->flush();
|
$this->blocks['head'] = $act->xw->flush();
|
||||||
$act->showStylesheets();
|
$act->showStylesheets();
|
||||||
$this->blocks['styles'] = $act->xw->flush();
|
$this->blocks['styles'] = $act->xw->flush();
|
||||||
$act->showScripts();
|
$act->showScripts();
|
||||||
$this->blocks['scripts'] = $act->xw->flush();
|
$this->blocks['scripts'] = $act->xw->flush();
|
||||||
$act->showFeeds();
|
$act->showFeeds();
|
||||||
$this->blocks['feeds'] = $act->xw->flush();
|
$this->blocks['feeds'] = $act->xw->flush();
|
||||||
$act->showOpenSearch();
|
$act->showOpenSearch();
|
||||||
$this->blocks['search'] = $act->xw->flush();
|
$this->blocks['search'] = $act->xw->flush();
|
||||||
$act->showDescription();
|
$act->showDescription();
|
||||||
$this->blocks['description'] = $act->xw->flush();
|
$this->blocks['description'] = $act->xw->flush();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <%bodytext%>
|
// <%bodytext%>
|
||||||
function onStartShowContentBlock( &$act ) {
|
function onStartShowContentBlock( &$act ) {
|
||||||
$this->clear_xmlWriter($act);
|
$this->clear_xmlWriter($act);
|
||||||
|
@ -70,7 +69,7 @@ class TemplatePlugin extends Plugin {
|
||||||
function onEndShowContentBlock( &$act ) {
|
function onEndShowContentBlock( &$act ) {
|
||||||
$this->blocks['bodytext'] = $act->xw->flush();
|
$this->blocks['bodytext'] = $act->xw->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
// <%localnav%>
|
// <%localnav%>
|
||||||
function onStartShowLocalNavBlock( &$act ) {
|
function onStartShowLocalNavBlock( &$act ) {
|
||||||
$this->clear_xmlWriter($act);
|
$this->clear_xmlWriter($act);
|
||||||
|
@ -79,7 +78,7 @@ class TemplatePlugin extends Plugin {
|
||||||
function onEndShowLocalNavBlock( &$act ) {
|
function onEndShowLocalNavBlock( &$act ) {
|
||||||
$this->blocks['localnav'] = $act->xw->flush();
|
$this->blocks['localnav'] = $act->xw->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
// <%export%>
|
// <%export%>
|
||||||
function onStartShowExportData( &$act ) {
|
function onStartShowExportData( &$act ) {
|
||||||
$this->clear_xmlWriter($act);
|
$this->clear_xmlWriter($act);
|
||||||
|
@ -88,7 +87,7 @@ class TemplatePlugin extends Plugin {
|
||||||
function onEndShowExportData( &$act ) {
|
function onEndShowExportData( &$act ) {
|
||||||
$this->blocks['export'] = $act->xw->flush();
|
$this->blocks['export'] = $act->xw->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
// <%subscriptions%>
|
// <%subscriptions%>
|
||||||
// <%subscribers%>
|
// <%subscribers%>
|
||||||
// <%groups%>
|
// <%groups%>
|
||||||
|
@ -149,7 +148,7 @@ class TemplatePlugin extends Plugin {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <%logo%>
|
// <%logo%>
|
||||||
// <%nav%>
|
// <%nav%>
|
||||||
// <%notice%>
|
// <%notice%>
|
||||||
|
@ -170,7 +169,7 @@ class TemplatePlugin extends Plugin {
|
||||||
$this->blocks['noticeform'] = $act->xw->flush();
|
$this->blocks['noticeform'] = $act->xw->flush();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// <%secondarynav%>
|
// <%secondarynav%>
|
||||||
// <%licenses%>
|
// <%licenses%>
|
||||||
function onStartShowFooter( &$act ) {
|
function onStartShowFooter( &$act ) {
|
||||||
|
@ -181,19 +180,19 @@ class TemplatePlugin extends Plugin {
|
||||||
$this->blocks['licenses'] = $act->xw->flush();
|
$this->blocks['licenses'] = $act->xw->flush();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// capture the EndHTML event
|
// capture the EndHTML event
|
||||||
// and include the template
|
// and include the template
|
||||||
function onEndEndHTML($act) {
|
function onEndEndHTML($act) {
|
||||||
|
|
||||||
global $action, $tags;
|
global $action, $tags;
|
||||||
|
|
||||||
// set the action and title values
|
// set the action and title values
|
||||||
$vars = array(
|
$vars = array(
|
||||||
'action'=>$action,
|
'action'=>$action,
|
||||||
'title'=>$act->title(). " - ". common_config('site', 'name')
|
'title'=>$act->title(). " - ". common_config('site', 'name')
|
||||||
);
|
);
|
||||||
|
|
||||||
// use the PHP template
|
// use the PHP template
|
||||||
// unless statusnet config:
|
// unless statusnet config:
|
||||||
// $config['template']['mode'] = 'html';
|
// $config['template']['mode'] = 'html';
|
||||||
|
@ -203,55 +202,55 @@ class TemplatePlugin extends Plugin {
|
||||||
include $tpl_file;
|
include $tpl_file;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl_file = $this->templateFolder() . '/index.html';
|
$tpl_file = $this->templateFolder() . '/index.html';
|
||||||
|
|
||||||
// read the static template
|
// read the static template
|
||||||
$output = file_get_contents( $tpl_file );
|
$output = file_get_contents( $tpl_file );
|
||||||
|
|
||||||
$tags = array();
|
$tags = array();
|
||||||
|
|
||||||
// get a list of the <%tags%> in the template
|
// get a list of the <%tags%> in the template
|
||||||
$pattern='/<%([a-z]+)%>/';
|
$pattern='/<%([a-z]+)%>/';
|
||||||
|
|
||||||
if ( 1 <= preg_match_all( $pattern, $output, $found ))
|
if ( 1 <= preg_match_all( $pattern, $output, $found ))
|
||||||
$tags[] = $found;
|
$tags[] = $found;
|
||||||
|
|
||||||
// for each found tag, set its value from the rendered blocks
|
// for each found tag, set its value from the rendered blocks
|
||||||
foreach( $tags[0][1] as $pos=>$tag ) {
|
foreach( $tags[0][1] as $pos=>$tag ) {
|
||||||
if (isset($this->blocks[$tag]))
|
if (isset($this->blocks[$tag]))
|
||||||
$vars[$tag] = $this->blocks[$tag];
|
$vars[$tag] = $this->blocks[$tag];
|
||||||
|
|
||||||
// didn't find a block for the tag
|
// didn't find a block for the tag
|
||||||
elseif (!isset($vars[$tag]))
|
elseif (!isset($vars[$tag]))
|
||||||
$vars[$tag] = '';
|
$vars[$tag] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace the tags in the template
|
// replace the tags in the template
|
||||||
foreach( $vars as $key=>$val )
|
foreach( $vars as $key=>$val )
|
||||||
$output = str_replace( '<%'.$key.'%>', $val, $output );
|
$output = str_replace( '<%'.$key.'%>', $val, $output );
|
||||||
|
|
||||||
echo $output;
|
echo $output;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
function templateFolder() {
|
function templateFolder() {
|
||||||
return 'tpl';
|
return 'tpl';
|
||||||
}
|
}
|
||||||
|
|
||||||
// catching the StartShowHTML event to halt the rendering
|
// catching the StartShowHTML event to halt the rendering
|
||||||
function onStartShowHTML( &$act ) {
|
function onStartShowHTML( &$act ) {
|
||||||
$this->clear_xmlWriter($act);
|
$this->clear_xmlWriter($act);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear the xmlWriter
|
// clear the xmlWriter
|
||||||
function clear_xmlWriter( &$act ) {
|
function clear_xmlWriter( &$act ) {
|
||||||
$act->xw->openMemory();
|
$act->xw->openMemory();
|
||||||
$act->xw->setIndent(true);
|
$act->xw->setIndent(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -267,7 +266,7 @@ class TemplatePlugin extends Plugin {
|
||||||
* @link http://megapump.com/
|
* @link http://megapump.com/
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class TemplateAction extends Action
|
class TemplateAction extends Action
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -275,54 +274,65 @@ class TemplateAction extends Action
|
||||||
parent::prepare($args);
|
parent::prepare($args);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle($args) {
|
function handle($args) {
|
||||||
|
|
||||||
parent::handle($args);
|
parent::handle($args);
|
||||||
|
|
||||||
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
||||||
|
|
||||||
// not authenticated, show login form
|
// not authenticated, show login form
|
||||||
header('WWW-Authenticate: Basic realm="StatusNet API"');
|
header('WWW-Authenticate: Basic realm="StatusNet API"');
|
||||||
|
|
||||||
// cancelled the browser login form
|
// cancelled the browser login form
|
||||||
$this->clientError(_('Authentication error!'), $code = 401);
|
$this->clientError(_('Authentication error!'), $code = 401);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$nick = $_SERVER['PHP_AUTH_USER'];
|
$nick = $_SERVER['PHP_AUTH_USER'];
|
||||||
$pass = $_SERVER['PHP_AUTH_PW'];
|
$pass = $_SERVER['PHP_AUTH_PW'];
|
||||||
|
|
||||||
// check username and password
|
// check username and password
|
||||||
$user = common_check_user($nick,$pass);
|
$user = common_check_user($nick,$pass);
|
||||||
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
|
|
||||||
// verify that user is admin
|
// verify that user is admin
|
||||||
if (!($user->id == 1))
|
if (!($user->id == 1))
|
||||||
$this->clientError(_('Only User #1 can update the template.'), $code = 401);
|
$this->clientError(_('Only User #1 can update the template.'), $code = 401);
|
||||||
|
|
||||||
// open the old template
|
// open the old template
|
||||||
$tpl_file = $this->templateFolder() . '/index.html';
|
$tpl_file = $this->templateFolder() . '/index.html';
|
||||||
$fp = fopen( $tpl_file, 'w+' );
|
$fp = fopen( $tpl_file, 'w+' );
|
||||||
|
|
||||||
// overwrite with the new template
|
// overwrite with the new template
|
||||||
fwrite($fp, $this->arg('template'));
|
fwrite($fp, $this->arg('template'));
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
|
||||||
header('HTTP/1.1 200 OK');
|
header('HTTP/1.1 200 OK');
|
||||||
header('Content-type: text/plain');
|
header('Content-type: text/plain');
|
||||||
print "Template Updated!";
|
print "Template Updated!";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// bad username and password
|
// bad username and password
|
||||||
$this->clientError(_('Authentication error!'), $code = 401);
|
$this->clientError(_('Authentication error!'), $code = 401);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function onPluginVersion(&$versions)
|
||||||
|
{
|
||||||
|
$versions[] = array('name' => 'Template',
|
||||||
|
'version' => TEMPLATEPLUGIN_VERSION,
|
||||||
|
'author' => 'Brian Hendrickson',
|
||||||
|
'homepage' => 'http://status.net/wiki/Plugin:Template',
|
||||||
|
'rawdescription' =>
|
||||||
|
_m('Use an HTML template for Web output.'));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user