From a6188978d8ba300f49dddcfcbad04eabe838b12d Mon Sep 17 00:00:00 2001 From: azett Date: Sat, 9 Feb 2019 12:35:32 +0100 Subject: [PATCH] Blockparser plugin: Replaced deprecated create_function() call with anonymous function; FootNotes plugin: Renamed class-named constructor to "__construct" --- fp-plugins/blockparser/plugin.blockparser.php | 99 +++++----- fp-plugins/footnotes/plugin.footnotes.php | 171 ++++++++---------- 2 files changed, 123 insertions(+), 147 deletions(-) diff --git a/fp-plugins/blockparser/plugin.blockparser.php b/fp-plugins/blockparser/plugin.blockparser.php index 7134cfe..3947524 100644 --- a/fp-plugins/blockparser/plugin.blockparser.php +++ b/fp-plugins/blockparser/plugin.blockparser.php @@ -1,24 +1,22 @@ 'BlockParser::Error', - 'content' => "" ); + + return array( + 'subject' => 'BlockParser::Error', + 'content' => "" + ); } - function plugin_blockparser_init() { - - // for instance: + + // for instance: // $fp_config['plugins']['blockparser']['pages'] = array('menu'); // (these will) be registered from the panel - + // 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 // anyway the result is the same... - - $pgs = plugin_getoptions('blockparser', 'pages'); + $pgs = plugin_getoptions('blockparser', 'pages'); if (is_array($pgs)) { foreach ($pgs as $page) { - register_widget( - 'blockparser:'.$page, // widget id - 'BlockParser: ' .$page, // widget name - create_function('', "return plugin_blockparser_widget('$page');") // lambda func + register_widget('blockparser:' . $page, // widget id + 'BlockParser: ' . $page, // widget name + function () use ($page) { + return plugin_blockparser_widget($page); + } // lambda func ); } } - - } 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 $commands = array('enable', 'disable'); + + var $commands = array( + 'enable', + 'disable' + ); function doenable($id) { $success = -1; - $enabled =& $this->bp_enabled; + $enabled = & $this->bp_enabled; if (static_exists($id)) { if (!$enabled) { $enabled = array(); } if (!in_array($id, $enabled)) { - $enabled[] = $id; + $enabled [] = $id; sort($enabled); plugin_addoption('blockparser', 'pages', $enabled); plugin_saveoptions(); @@ -99,9 +98,9 @@ if (class_exists('AdminPanelAction')){ function dodisable($id) { $success = -2; - $enabled =& $this->bp_enabled; - if ($enabled && is_numeric( $v = array_search($id, $enabled ) ) ) { - unset($enabled[$v]); + $enabled = & $this->bp_enabled; + if ($enabled && is_numeric($v = array_search($id, $enabled))) { + unset($enabled [$v]); @sort($enabled); @plugin_addoption('blockparser', 'pages', $enabled); plugin_saveoptions(); @@ -110,25 +109,21 @@ if (class_exists('AdminPanelAction')){ $this->smarty->assign('success', $success); return PANEL_REDIRECT_CURRENT; } - + function setup() { $this->smarty->assign('admin_resource', "plugin:blockparser/admin.plugin.blockparser"); $this->smarty->assign('enabledlist', $this->bp_enabled = plugin_getoptions('blockparser', 'pages')); } - function main() { global $fp_config; // $this->smarty->assign_by_ref('enabledpages', plugin_getoptions('blockparser')); $this->smarty->assign('statics', $assign = static_getlist()); } - - + } admin_addpanelaction('widgets', 'blockparser', true); - } - ?> diff --git a/fp-plugins/footnotes/plugin.footnotes.php b/fp-plugins/footnotes/plugin.footnotes.php index 20a4460..47a1d27 100755 --- a/fp-plugins/footnotes/plugin.footnotes.php +++ b/fp-plugins/footnotes/plugin.footnotes.php @@ -1,123 +1,104 @@ -id = $id; - } - - function note($n,$s) { - $id=$this->id; + } + + function note($n, $s) { + $id = $this->id; $this->refs = true; - - return - '
  • '.trim($s). - " ^top". - '
  • '; + + return '
  • ' . trim($s) . " ^top" . '
  • '; } function footnotes($matches) { - $str = '

    Footnotes

      '; - - - $lines = preg_split('|\[([0-9]+)\]|', $matches[1], -1, PREG_SPLIT_DELIM_CAPTURE); - - // first array element is always empty - remove - array_shift($lines); - - // get each footnote's number ($n) and content ($s) from the array ... - while (($n = array_shift($lines)) && ($s = array_shift($lines))) { - // ... and add it to the result string - $str .=$this->note($n, $s); - } - + + $lines = preg_split('|\[([0-9]+)\]|', $matches [1], -1, PREG_SPLIT_DELIM_CAPTURE); + + // first array element is always empty - remove + array_shift($lines); + + // get each footnote's number ($n) and content ($s) from the array ... + while (($n = array_shift($lines)) && ($s = array_shift($lines))) { + // ... and add it to the result string + $str .= $this->note($n, $s); + } + $str .= '
    '; return $str; - } - + function references($matches) { - - $n = $matches[1]; - + $n = $matches [1]; + $id = $this->id; - + $href_rel = "{$id}-rel-{$n}"; $href_note = "{$id}-fn-{$n}"; - + return "{$n}"; - } - - function headings($matches) { - $i = 7-strlen($matches[1]); - return "{$matches[2]}"; - } - - + + function headings($matches) { + $i = 7 - strlen($matches [1]); + return "{$matches[2]}"; + } } - + function plugin_footnotes_filter($text) { - - - global $smarty; - - $footnotes_obj = new footnotes_class($id = $smarty->get_template_vars('id')); - - // *STRONG* emphasis - $text = preg_replace('|(?\w)|xs', '$1', $text); - // _emphasis_ (italic) - $text = preg_replace('|(?\w)|xs', '$1', $text); - - // heading - /* - $text = preg_replace_callback( - '(?\w)|xs' - //'/\n(#{1,6})([^#]+)# * /', - array(&$footnotes_obj, 'headings'), - $text); - - */ - - - - $text = preg_replace_callback('|\n'. preg_quote(FOOTNOTES_START) .'\s*(.*)|sm', - array(&$footnotes_obj, 'footnotes'), - $text); - - // no [footnotes] references at the bottom of the page: stops - if (!$footnotes_obj->refs) - return $text; - - $text = preg_replace_callback('|\[([0-9]+)\]|', - array(&$footnotes_obj, 'references'), - $text); - - + global $smarty; + + $footnotes_obj = new footnotes_class($id = $smarty->get_template_vars('id')); + + // *STRONG* emphasis + $text = preg_replace('|(?\w)|xs', '$1', $text); + // _emphasis_ (italic) + $text = preg_replace('|(?\w)|xs', '$1', $text); + + // heading + /* + * $text = preg_replace_callback( + * '(?\w)|xs' + * //'/\n(#{1,6})([^#]+)# * /', + * array(&$footnotes_obj, 'headings'), + * $text); + * + */ + + $text = preg_replace_callback('|\n' . preg_quote(FOOTNOTES_START) . '\s*(.*)|sm', array( + &$footnotes_obj, + 'footnotes' + ), $text); + + // no [footnotes] references at the bottom of the page: stops + if (!$footnotes_obj->refs) + return $text; + + $text = preg_replace_callback('|\[([0-9]+)\]|', array( + &$footnotes_obj, + 'references' + ), $text); + return $text; - } - - - - add_filter('the_content', 'plugin_footnotes_filter', 0); ?> \ No newline at end of file