Blockparser plugin: Replaced deprecated create_function() call with anonymous function;
FootNotes plugin: Renamed class-named constructor to "__construct"
This commit is contained in:
parent
6bae0cde9d
commit
a6188978d8
@ -1,24 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Plugin Name: BlockParser
|
* Plugin Name: BlockParser
|
||||||
Plugin URI: http://www.nowhereland.it/
|
* Plugin URI: http://www.nowhereland.it/
|
||||||
Type: Block
|
* Type: Block
|
||||||
Description: BlockParser plugin. Part of the standard distribution ;) This allow you to use simple non-plugin custom blocks :)
|
* Description: BlockParser plugin. Part of the standard distribution ;) This allow you to use simple non-plugin custom blocks :)
|
||||||
Author: NoWhereMan real_nowhereman at user dot sf dot net
|
* Author: NoWhereMan real_nowhereman at user dot sf dot net
|
||||||
Version: 1.0
|
* Version: 1.0
|
||||||
Author URI: http://www.nowhereland.it/
|
* Author URI: http://www.nowhereland.it/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//define('BLOCKS_DIR', CONTENT_DIR . 'blocks/');
|
// define('BLOCKS_DIR', CONTENT_DIR . 'blocks/');
|
||||||
|
|
||||||
// as a default blocks_dir == static_dir
|
|
||||||
// so you can edit blocks using the static editor!!
|
|
||||||
define('BLOCKS_DIR', STATIC_DIR);
|
|
||||||
|
|
||||||
|
// as a default blocks_dir == static_dir
|
||||||
|
// so you can edit blocks using the static editor!!
|
||||||
|
define('BLOCKS_DIR', STATIC_DIR);
|
||||||
|
|
||||||
function plugin_blockparser_parse($blockid) {
|
function plugin_blockparser_parse($blockid) {
|
||||||
|
|
||||||
if ($f_contents = io_load_file(BLOCKS_DIR . $blockid . EXT)) {
|
if ($f_contents = io_load_file(BLOCKS_DIR . $blockid . EXT)) {
|
||||||
$contents = utils_kexplode($f_contents);
|
$contents = utils_kexplode($f_contents);
|
||||||
return array_change_key_case($contents, CASE_LOWER);
|
return array_change_key_case($contents, CASE_LOWER);
|
||||||
@ -27,66 +25,67 @@ function plugin_blockparser_parse($blockid) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# register_widget('blockparser', 'BlockParser', 'plugin_blockparser_widget', 1);
|
// register_widget('blockparser', 'BlockParser', 'plugin_blockparser_widget', 1);
|
||||||
|
|
||||||
function plugin_blockparser_widget($blockid) {
|
function plugin_blockparser_widget($blockid) {
|
||||||
|
|
||||||
if ($contents = plugin_blockparser_parse($blockid)) {
|
if ($contents = plugin_blockparser_parse($blockid)) {
|
||||||
$contents['subject'] = apply_filters('the_title', $contents['subject']);
|
$contents ['subject'] = apply_filters('the_title', $contents ['subject']);
|
||||||
$contents['content'] = apply_filters('the_content', $contents['content']);
|
$contents ['content'] = apply_filters('the_content', $contents ['content']);
|
||||||
$contents['id'] = "widget-bp-$blockid";
|
$contents ['id'] = "widget-bp-$blockid";
|
||||||
return $contents;
|
return $contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array( 'subject' => 'BlockParser::Error',
|
return array(
|
||||||
'content' => "<ul><li>Error parsing block $blockid; file may not exist</li></ul>" );
|
'subject' => 'BlockParser::Error',
|
||||||
|
'content' => "<ul><li>Error parsing block $blockid; file may not exist</li></ul>"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function plugin_blockparser_init() {
|
function plugin_blockparser_init() {
|
||||||
|
|
||||||
// for instance:
|
// for instance:
|
||||||
// $fp_config['plugins']['blockparser']['pages'] = array('menu');
|
// $fp_config['plugins']['blockparser']['pages'] = array('menu');
|
||||||
// (these will) be registered from the panel
|
// (these will) be registered from the panel
|
||||||
|
|
||||||
// in this case functions are just a convenient way
|
// in this case functions are just a convenient way
|
||||||
// to create new instances of the plugin_blockparser_widget() function...
|
// to create new instances of the plugin_blockparser_widget() function...
|
||||||
|
|
||||||
// this would suggest to use an object, though :B
|
// this would suggest to use an object, though :B
|
||||||
// anyway the result is the same...
|
// anyway the result is the same...
|
||||||
|
$pgs = plugin_getoptions('blockparser', 'pages');
|
||||||
$pgs = plugin_getoptions('blockparser', 'pages');
|
|
||||||
if (is_array($pgs)) {
|
if (is_array($pgs)) {
|
||||||
foreach ($pgs as $page) {
|
foreach ($pgs as $page) {
|
||||||
register_widget(
|
register_widget('blockparser:' . $page, // widget id
|
||||||
'blockparser:'.$page, // widget id
|
'BlockParser: ' . $page, // widget name
|
||||||
'BlockParser: ' .$page, // widget name
|
function () use ($page) {
|
||||||
create_function('', "return plugin_blockparser_widget('$page');") // lambda func
|
return plugin_blockparser_widget($page);
|
||||||
|
} // lambda func
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_action('init', 'plugin_blockparser_init');
|
add_action('init', 'plugin_blockparser_init');
|
||||||
|
|
||||||
if (class_exists('AdminPanelAction')){
|
if (class_exists('AdminPanelAction')) {
|
||||||
|
|
||||||
|
class admin_widgets_blockparser extends AdminPanelAction {
|
||||||
|
|
||||||
class admin_widgets_blockparser extends AdminPanelAction {
|
|
||||||
|
|
||||||
var $langres = 'plugin:blockparser';
|
var $langres = 'plugin:blockparser';
|
||||||
var $commands = array('enable', 'disable');
|
|
||||||
|
var $commands = array(
|
||||||
|
'enable',
|
||||||
|
'disable'
|
||||||
|
);
|
||||||
|
|
||||||
function doenable($id) {
|
function doenable($id) {
|
||||||
$success = -1;
|
$success = -1;
|
||||||
$enabled =& $this->bp_enabled;
|
$enabled = & $this->bp_enabled;
|
||||||
if (static_exists($id)) {
|
if (static_exists($id)) {
|
||||||
if (!$enabled) {
|
if (!$enabled) {
|
||||||
$enabled = array();
|
$enabled = array();
|
||||||
}
|
}
|
||||||
if (!in_array($id, $enabled)) {
|
if (!in_array($id, $enabled)) {
|
||||||
$enabled[] = $id;
|
$enabled [] = $id;
|
||||||
sort($enabled);
|
sort($enabled);
|
||||||
plugin_addoption('blockparser', 'pages', $enabled);
|
plugin_addoption('blockparser', 'pages', $enabled);
|
||||||
plugin_saveoptions();
|
plugin_saveoptions();
|
||||||
@ -99,9 +98,9 @@ if (class_exists('AdminPanelAction')){
|
|||||||
|
|
||||||
function dodisable($id) {
|
function dodisable($id) {
|
||||||
$success = -2;
|
$success = -2;
|
||||||
$enabled =& $this->bp_enabled;
|
$enabled = & $this->bp_enabled;
|
||||||
if ($enabled && is_numeric( $v = array_search($id, $enabled ) ) ) {
|
if ($enabled && is_numeric($v = array_search($id, $enabled))) {
|
||||||
unset($enabled[$v]);
|
unset($enabled [$v]);
|
||||||
@sort($enabled);
|
@sort($enabled);
|
||||||
@plugin_addoption('blockparser', 'pages', $enabled);
|
@plugin_addoption('blockparser', 'pages', $enabled);
|
||||||
plugin_saveoptions();
|
plugin_saveoptions();
|
||||||
@ -110,25 +109,21 @@ if (class_exists('AdminPanelAction')){
|
|||||||
$this->smarty->assign('success', $success);
|
$this->smarty->assign('success', $success);
|
||||||
return PANEL_REDIRECT_CURRENT;
|
return PANEL_REDIRECT_CURRENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
$this->smarty->assign('admin_resource', "plugin:blockparser/admin.plugin.blockparser");
|
$this->smarty->assign('admin_resource', "plugin:blockparser/admin.plugin.blockparser");
|
||||||
$this->smarty->assign('enabledlist', $this->bp_enabled = plugin_getoptions('blockparser', 'pages'));
|
$this->smarty->assign('enabledlist', $this->bp_enabled = plugin_getoptions('blockparser', 'pages'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
global $fp_config;
|
global $fp_config;
|
||||||
// $this->smarty->assign_by_ref('enabledpages', plugin_getoptions('blockparser'));
|
// $this->smarty->assign_by_ref('enabledpages', plugin_getoptions('blockparser'));
|
||||||
$this->smarty->assign('statics', $assign = static_getlist());
|
$this->smarty->assign('statics', $assign = static_getlist());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
admin_addpanelaction('widgets', 'blockparser', true);
|
admin_addpanelaction('widgets', 'blockparser', true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,123 +1,104 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: FootNotes
|
* Plugin Name: FootNotes
|
||||||
Version: 0.1
|
* Version: 0.1
|
||||||
Plugin URI: http://flatpress.nowhereland.it
|
* Plugin URI: http://flatpress.nowhereland.it
|
||||||
Description: footnotes in your entry
|
* Description: footnotes in your entry
|
||||||
Author: NoWhereMan
|
* Author: NoWhereMan
|
||||||
Author URI: http://flatpress.nowhereland.it
|
* Author URI: http://flatpress.nowhereland.it
|
||||||
*/
|
*/
|
||||||
|
define('FOOTNOTES_START', '[footnotes]');
|
||||||
define('FOOTNOTES_START', '[footnotes]');
|
|
||||||
|
|
||||||
class footnotes_class {
|
class footnotes_class {
|
||||||
|
|
||||||
var $refs = false;
|
var $refs = false;
|
||||||
|
|
||||||
var $id = 'noid';
|
var $id = 'noid';
|
||||||
|
|
||||||
function footnotes_class($id) {
|
function __construct($id) {
|
||||||
if ($id)
|
if ($id)
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function note($n,$s) {
|
function note($n, $s) {
|
||||||
$id=$this->id;
|
$id = $this->id;
|
||||||
$this->refs = true;
|
$this->refs = true;
|
||||||
|
|
||||||
return
|
return '<li>' . trim($s) . " <a id=\"$id-fn-{$n}\" href=\"#$id-rel-{$n}\" " . "title=\"Back {$n}\">^top</a>" . '</li>';
|
||||||
'<li>'.trim($s).
|
|
||||||
" <a id=\"$id-fn-{$n}\" href=\"#$id-rel-{$n}\" ".
|
|
||||||
"title=\"Back {$n}\">^top</a>".
|
|
||||||
'</li>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function footnotes($matches) {
|
function footnotes($matches) {
|
||||||
|
|
||||||
$str = '<div class="footnotes"><h4>Footnotes</h4><ol>';
|
$str = '<div class="footnotes"><h4>Footnotes</h4><ol>';
|
||||||
|
|
||||||
|
$lines = preg_split('|\[([0-9]+)\]|', $matches [1], -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||||
$lines = preg_split('|\[([0-9]+)\]|', $matches[1], -1, PREG_SPLIT_DELIM_CAPTURE);
|
|
||||||
|
// first array element is always empty - remove
|
||||||
// first array element is always empty - remove
|
array_shift($lines);
|
||||||
array_shift($lines);
|
|
||||||
|
// get each footnote's number ($n) and content ($s) from the array ...
|
||||||
// get each footnote's number ($n) and content ($s) from the array ...
|
while (($n = array_shift($lines)) && ($s = array_shift($lines))) {
|
||||||
while (($n = array_shift($lines)) && ($s = array_shift($lines))) {
|
// ... and add it to the result string
|
||||||
// ... and add it to the result string
|
$str .= $this->note($n, $s);
|
||||||
$str .=$this->note($n, $s);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$str .= '</ol></div>';
|
$str .= '</ol></div>';
|
||||||
return $str;
|
return $str;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function references($matches) {
|
function references($matches) {
|
||||||
|
$n = $matches [1];
|
||||||
$n = $matches[1];
|
|
||||||
|
|
||||||
$id = $this->id;
|
$id = $this->id;
|
||||||
|
|
||||||
$href_rel = "{$id}-rel-{$n}";
|
$href_rel = "{$id}-rel-{$n}";
|
||||||
$href_note = "{$id}-fn-{$n}";
|
$href_note = "{$id}-fn-{$n}";
|
||||||
|
|
||||||
return "<sup><a id=\"$href_rel\" href=\"#$href_note\" title=\"note {$n}\">{$n}</a></sup>";
|
return "<sup><a id=\"$href_rel\" href=\"#$href_note\" title=\"note {$n}\">{$n}</a></sup>";
|
||||||
}
|
|
||||||
|
|
||||||
function headings($matches) {
|
|
||||||
$i = 7-strlen($matches[1]);
|
|
||||||
return "<h$i>{$matches[2]}</h$i>";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function headings($matches) {
|
||||||
|
$i = 7 - strlen($matches [1]);
|
||||||
|
return "<h$i>{$matches[2]}</h$i>";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function plugin_footnotes_filter($text) {
|
function plugin_footnotes_filter($text) {
|
||||||
|
global $smarty;
|
||||||
|
|
||||||
global $smarty;
|
$footnotes_obj = new footnotes_class($id = $smarty->get_template_vars('id'));
|
||||||
|
|
||||||
$footnotes_obj = new footnotes_class($id = $smarty->get_template_vars('id'));
|
// *STRONG* emphasis
|
||||||
|
$text = preg_replace('|(?<!\S)\*(?=\S) (?! \*) (.+?) (?<=\S) \*(?!>\w)|xs', '<strong>$1</strong>', $text);
|
||||||
// *STRONG* emphasis
|
// _emphasis_ (italic)
|
||||||
$text = preg_replace('|(?<!\S)\*(?=\S) (?! \*) (.+?) (?<=\S) \*(?!>\w)|xs', '<strong>$1</strong>', $text);
|
$text = preg_replace('|(?<!\S)\_(?=\S) (?! \_) (.+?) (?<=\S) \_(?!>\w)|xs', '<em>$1</em>', $text);
|
||||||
// _emphasis_ (italic)
|
|
||||||
$text = preg_replace('|(?<!\S)\_(?=\S) (?! \_) (.+?) (?<=\S) \_(?!>\w)|xs', '<em>$1</em>', $text);
|
// heading
|
||||||
|
/*
|
||||||
// heading
|
* $text = preg_replace_callback(
|
||||||
/*
|
* '(?<!\w)=(?=\S) (?! =) (.+?) (?<=\S) =(?!>\w)|xs'
|
||||||
$text = preg_replace_callback(
|
* //'/\n(#{1,6})([^#]+)# * /',
|
||||||
'(?<!\w)=(?=\S) (?! =) (.+?) (?<=\S) =(?!>\w)|xs'
|
* array(&$footnotes_obj, 'headings'),
|
||||||
//'/\n(#{1,6})([^#]+)# * /',
|
* $text);
|
||||||
array(&$footnotes_obj, 'headings'),
|
*
|
||||||
$text);
|
*/
|
||||||
|
|
||||||
*/
|
$text = preg_replace_callback('|\n' . preg_quote(FOOTNOTES_START) . '\s*(.*)|sm', array(
|
||||||
|
&$footnotes_obj,
|
||||||
|
'footnotes'
|
||||||
|
), $text);
|
||||||
$text = preg_replace_callback('|\n'. preg_quote(FOOTNOTES_START) .'\s*(.*)|sm',
|
|
||||||
array(&$footnotes_obj, 'footnotes'),
|
// no [footnotes] references at the bottom of the page: stops
|
||||||
$text);
|
if (!$footnotes_obj->refs)
|
||||||
|
return $text;
|
||||||
// no [footnotes] references at the bottom of the page: stops
|
|
||||||
if (!$footnotes_obj->refs)
|
$text = preg_replace_callback('|\[([0-9]+)\]|', array(
|
||||||
return $text;
|
&$footnotes_obj,
|
||||||
|
'references'
|
||||||
$text = preg_replace_callback('|\[([0-9]+)\]|',
|
), $text);
|
||||||
array(&$footnotes_obj, 'references'),
|
|
||||||
$text);
|
|
||||||
|
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
add_filter('the_content', 'plugin_footnotes_filter', 0);
|
add_filter('the_content', 'plugin_footnotes_filter', 0);
|
||||||
?>
|
?>
|
Loading…
x
Reference in New Issue
Block a user