/~enabled/ied_plugin_composer.php
PHP | 3921 lines | 3026 code | 449 blank | 446 comment | 506 complexity | a0783449ec6e81388632c1026390cdfb MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- // This is a PLUGIN TEMPLATE for Textpattern CMS.
- // Copy this file to a new name like abc_myplugin.php. Edit the code, then
- // run this file at the command line to produce a plugin for distribution:
- // $ php abc_myplugin.php > abc_myplugin-0.1.txt
- // Plugin name is optional. If unset, it will be extracted from the current
- // file name. Plugin names should start with a three letter prefix which is
- // unique and reserved for each plugin author ("abc" is just an example).
- // Uncomment and edit this line to override:
- $plugin['name'] = 'ied_plugin_composer';
- // Allow raw HTML help, as opposed to Textile.
- // 0 = Plugin help is in Textile format, no raw HTML allowed (default).
- // 1 = Plugin help is in raw HTML. Not recommended.
- # $plugin['allow_html_help'] = 1;
- $plugin['version'] = '1.05';
- $plugin['author'] = 'Yura Linnyk / Stef Dawson / Steve Dickinson';
- $plugin['author_uri'] = 'http://stefdawson.com/';
- $plugin['description'] = 'Create, publish and edit plugins from within Textpattern';
- // Plugin load order:
- // The default value of 5 would fit most plugins, while for instance comment
- // spam evaluators or URL redirectors would probably want to run earlier
- // (1...4) to prepare the environment for everything else that follows.
- // Values 6...9 should be considered for plugins which would work late.
- // This order is user-overrideable.
- $plugin['order'] = '5';
- // Plugin 'type' defines where the plugin is loaded
- // 0 = public : only on the public side of the website (default)
- // 1 = public+admin : on both the public and admin side
- // 2 = library : only when include_plugin() or require_plugin() is called
- // 3 = admin : only on the admin side (no AJAX)
- // 4 = admin+ajax : only on the admin side (AJAX supported)
- // 5 = public+admin+ajax : on both the public and admin side (AJAX supported)
- $plugin['type'] = '5';
- // Plugin "flags" signal the presence of optional capabilities to the core plugin loader.
- // Use an appropriately OR-ed combination of these flags.
- // The four high-order bits 0xf000 are available for this plugin's private use
- if (!defined('PLUGIN_HAS_PREFS')) define('PLUGIN_HAS_PREFS', 0x0001); // This plugin wants to receive "plugin_prefs.{$plugin['name']}" events
- if (!defined('PLUGIN_LIFECYCLE_NOTIFY')) define('PLUGIN_LIFECYCLE_NOTIFY', 0x0002); // This plugin wants to receive "plugin_lifecycle.{$plugin['name']}" events
- $plugin['flags'] = '3';
- // Plugin 'textpack' is optional. It provides i18n strings to be used in conjunction with gTxt().
- // Syntax:
- // ## arbitrary comment
- // #@event
- // #@language ISO-LANGUAGE-CODE
- // abc_string_name => Localized String
- /** Uncomment me, if you need a textpack
- $plugin['textpack'] = <<<EOT
- #@admin
- #@language en-gb
- abc_sample_string => Sample String
- abc_one_more => One more
- #@language de-de
- abc_sample_string => Beispieltext
- abc_one_more => Noch einer
- EOT;
- **/
- // End of textpack
- if (!defined('txpinterface'))
- @include_once('zem_tpl.php');
- # --- BEGIN PLUGIN CODE ---
- // <?php
- /**
- * ied_plugin_composer
- *
- * A Textpattern CMS plugin for writing, editing and sharing plugins
- * -> Create and edit admin-side or public plugins
- * -> Supports plugin lifecycle events and prefs
- * -> Supports Textpacks
- * -> Optional syntax checker on save
- *
- * @author Yura Linnyk
- * @author Stef Dawson
- * @author Steve Dickinson
- * @link http://stefdawson.com/
- */
- // TODO:
- // * Use href() (from 4.6.+) for anchor creation to avoid double-encoded ampersands
- // * Figure out why syntax checker doesn't jump to line number sometimes (AJAX fails with error but it's not handled)
- // * Fix CSS/Markup so Textpack strings twisty label doesn't range right
- // * Show which langs have installed strings in the distribution section so the correct langs in the select list can be chosen
- // * Find out why uploading PHP files sometiems throws an error even though it succeeds
- // * jQuery on editor dropdowns in setup
- // * phpdoc
- global $ied_plugin_globals;
- $ied_plugin_globals = array(
- 'css_start' => '<!--',
- 'css_end' => '-->',
- 'dlm_start' => '#',
- 'dlm_end' => '',
- 'start' => ' --- BEGIN PLUGIN SECTION ---',
- 'end' => ' --- END PLUGIN SECTION ---',
- 'size_help' => '63535',
- 'size_css' => '2000',
- 'size_code' => '16777215',
- );
- if(@txpinterface == 'admin') {
- add_privs('ied_plugin_composer','1,2');
- add_privs('plugin_prefs.ied_plugin_composer','1,2');
- register_tab('extensions', 'ied_plugin_composer', gTxt('ied_plugin_lbl_composer'));
- register_callback('ied_plugin_composer', 'ied_plugin_composer');
- register_callback('ied_plugin_setup', 'plugin_prefs.ied_plugin_composer');
- register_callback('ied_plugin_welcome', 'plugin_lifecycle.ied_plugin_composer');
- register_callback('ied_plugin_inject_css', 'admin_side', 'head_end');
- global $ied_pc_event, $prefs;
- $ied_pc_event = 'ied_plugin_composer';
- } else {
- register_callback('ied_plugin_download', 'pretext');
- }
- // -------------------------------------------------------------
- // CSS definitions: hopefully kind to themers
- function ied_pc_get_style_rules() {
- $ied_pc_styles = array(
- 'ied_plugin' => '
- #ied_plugin64 { width:60%; }
- #ied_plugin_control h3 { text-align:left; }
- input[type="submit"] { margin:0.3em 0.7em; }
- .ied_label { margin:0 0.2em 0 0.6em;}
- .ied_plugin_setup { float:right; margin:-2em 0 0;}
- .ied_plugin_resizehandle { cursor:s-resize; float:left; text-align:center; font-size:1em; width:65%; padding:2px 0 6px; }
- .ied_plugin_info_bar { text-align:right; }
- #ied_plugin_jumpToLine { width:4em; margin:0 1em 0 0.4em; }
- .ied_editForm { width:{edwidth}; margin:0 auto; }
- .ied_subdue { color:gray; padding:1px 2px 2px 1px; }
- #ied_plugin_tp_controls input[type="text"] { width:16%; }
- #ied_plugin_tp_strings ul { list-style-type:none; }
- #ied_plugin_tp_strings ul label { margin:0 8px 0 0; }
- #ied_plugin_tp_strings ul input { width:450px; }
- .ied_plugin_edit_toolbar { text-align:right; width:95%; display:inline-block; margin:-2em 0 0 0; }
- #ied_plugin_msgpop { display:none; position:absolute; left:200px; max-width:500px; border:3px ridge #999; opacity:.92; filter:alpha(opacity:92); padding:15px 20px; background-color:#e2dfce; color:#80551e; }
- #ied_plugin_msgpop .publish { float:right; }
- ',
- );
- return $ied_pc_styles;
- }
- // -------------------------------------------------------------
- function ied_plugin_inject_css($evt, $stp) {
- global $ied_pc_event, $event;
- if ($event == $ied_pc_event) {
- $ied_plugin_prefs = ied_pc_get_prefs();
- $ied_plugin_styles = ied_pc_get_style_rules();
- // Possible variable replacements
- $edwidth = get_pref('ied_plugin_editor_width', $ied_plugin_prefs['ied_plugin_editor_width']['default']);
- $stylereps = array(
- '{edwidth}' => $edwidth,
- );
- echo '<style type="text/css">' . strtr($ied_plugin_styles['ied_plugin'], $stylereps) . '</style>';
- }
- return;
- }
- // -------------------------------------------------------------
- // Plugin jumpoff point
- function ied_plugin_composer($evt, $stp) {
- $available_steps = array(
- 'ied_plugin_code_save' => true,
- 'ied_plugin_create' => true,
- 'ied_plugin_delete' => true,
- 'ied_plugin_edit' => false,
- 'ied_plugin_generate_phpdoc' => true,
- 'ied_plugin_help' => true,
- 'ied_plugin_help_viewer' => false,
- 'ied_plugin_install' => true,
- 'ied_plugin_lang_set' => true,
- 'ied_plugin_table' => false,
- 'ied_plugin_multi_edit' => true,
- 'ied_plugin_prefs' => false,
- 'ied_plugin_restore' => true,
- 'ied_plugin_save' => true,
- 'ied_plugin_save_as_file' => true,
- 'ied_plugin_save_as_php_file' => true,
- 'ied_plugin_save_as_textpack' => true,
- 'ied_plugin_set_order' => true,
- 'ied_plugin_set_tp_prefix' => true,
- 'ied_plugin_switch_status' => true,
- 'ied_plugin_textpack_del' => true,
- 'ied_plugin_textpack_get' => true,
- 'ied_plugin_textpack_load' => true,
- 'ied_plugin_textpack_save' => true,
- 'ied_plugin_upload' => true,
- 'save_pane_state' => true,
- );
- if ($stp == 'save_pane_state') {
- $stp = 'ied_plugin_save_pane_state';
- } else if (!$stp or !bouncer($stp, $available_steps)) {
- $stp = 'ied_plugin_table';
- }
- $stp();
- }
- // -------------------------------------------------------------
- // Lifecycle handling, post-install / delete
- function ied_plugin_welcome($evt, $stp) {
- $msg = '';
- switch ($stp) {
- case 'installed':
- ied_plugin_prefs_update();
- $msg = 'Thanks for installing the plugin composer. Happy authoring :-)';
- break;
- case 'deleted':
- ied_plugin_prefs_remove(0);
- break;
- }
- return $msg;
- }
- // -------------------------------------------------------------
- // Table of plugins in both database and file system cache
- function ied_plugin_table($message='') {
- global $prefs, $ied_pc_event;
- pagetop(gTxt('ied_plugin_lbl_composer'),$message);
- require_privs('ied_plugin_composer');
- $ied_plugin_prefs = ied_pc_get_prefs();
- $lc_opts = do_list(get_pref('ied_plugin_lifecycle_options'));
- $auto_en = get_pref('ied_plugin_auto_enable');
- $cbout[] = '<p><label class="ied_label">'.gTxt('ied_plugin_run_install').'</label>';
- $checked = in_array('installed', $lc_opts);
- $cbout[] = yesnoradio('ied_plugin_installopts', $checked);
- $cbout[] = '<label class="ied_label">'.gTxt('ied_plugin_auto_enable').'</label>';
- $cbout[] = radioset($ied_plugin_prefs['ied_plugin_auto_enable']['content'], 'ied_plugin_autoenable', $auto_en).'</p>';
- extract(gpsa(array('sort', 'dir')));
- if ($sort === '') $sort = get_pref('ied_plugin_sort_column', 'name');
- if ($dir === '') $dir = get_pref('ied_plugin_sort_dir', 'asc');
- $dir = ($dir == 'desc') ? 'desc' : 'asc';
- if (!in_array($sort, array('name', 'status', 'author', 'version', 'load_order'))) $sort = 'name';
- $sort_sql = $sort.' '.$dir;
- set_pref('ied_plugin_sort_column', $sort, 'ied_plugin', PREF_HIDDEN, '', 0, PREF_PRIVATE);
- set_pref('ied_plugin_sort_dir', $dir, 'ied_plugin', PREF_HIDDEN, '', 0, PREF_PRIVATE);
- $switch_dir = ($dir == 'desc') ? 'asc' : 'desc';
- // Top control-panel part of screen
- echo '<h1 class="txp-heading">'.gTxt('ied_plugin_lbl_composer').sp.ied_plugin_anchor($ied_pc_event, 'ied_plugin_help_viewer', '?', array('name' => 'ied_plugin_composer'), array('class' => 'pophelp')).'</h1>'.
- n. '<div id="ied_plugin_control" class="txp-control-panel">'.
- n. sLink($ied_pc_event, 'ied_plugin_prefs', gTxt('ied_plugin_setup'), 'ied_plugin_setup').
- n. '<div class="summary-details"><h3 class="lever txp-summary'.(get_pref('pane_ied_plugin_cpanel_visible') ? ' expanded' : '').'"><a href="#ied_plugin_cpanel">' . gTxt('ied_plugin_cpanel_legend') . '</a></h3><div id="ied_plugin_cpanel" class="toggle" style="display:'.(get_pref('pane_ied_plugin_cpanel_visible') ? 'block' : 'none').'">'.
- n. '<form class="ied_plugin_form" enctype="multipart/form-data" action="index.php" method="post">'.
- n. '<p>'.
- n. '<label for="ied_plugin_newname" class="ied_label">'.gTxt('name').'</label>'.
- n. fInput('text', 'name', '', '', '', '', INPUT_REGULAR, '', 'ied_plugin_newname').
- n. fInput('submit', 'plugin_create', gTxt('ied_plugin_create_new')).
- n. '</p>'.
- n. '<p>'.
- n. '<label for="ied_plugin_file" class="ied_label">'.gTxt('ied_plugin_upload_php').'</label>'.
- n. fInput('file', 'thefile', '', '', '', '', '', '', 'ied_plugin_file').
- n. fInput('submit', 'plugin_upload', gTxt('upload')).
- n. '</p>'.
- n. '<p>'.
- n. '<label for="ied_plugin64" class="ied_label">'.gTxt('ied_plugin_install_txt').'</label>'.
- n. text_area('plugin64', '', '', '', 'ied_plugin64').
- n. fInput('submit', 'plugin_install', gTxt('install')).
- n. '</p>'.
- n. join(n, $cbout).
- n. eInput($ied_pc_event).
- n. sInput('ied_plugin_create').
- n. hInput('MAX_FILE_SIZE', 1000000).
- n. tInput().
- n. '</form>'.
- n. '</div>'.
- n. '</div>'.
- n. '</div>';
- // Main plugin list
- echo n. '<div id="ied_plugin_container" class="txp-container">';
- $rs = safe_rows('*', 'txp_plugin', '1=1 ORDER BY '.$sort_sql);
- if ($rs) {
- echo '<div class="summary-details">'.
- n. '<form action="index.php" id="ied_plugin_db_form" method="post">'.
- n. '<h3 class="lever txp-summary'.(get_pref('pane_ied_plugin_dbplugs_visible') ? ' expanded' : '').'">'.
- n. '<a href="#ied_plugin_dbplugs">' . gTxt('ied_plugin_dbplugs_legend') . '</a>'.
- n. '</h3>'.
- n. '<div id="ied_plugin_dbplugs" class="toggle" style="display:'.(get_pref('pane_ied_plugin_dbplugs_visible') ? 'block' : 'none').'">'.
- n. '<div class="txp-listtables">'.
- n. startTable('', '', 'txp-list').
- n.'<thead>'.
- n. tr(
- n.hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' title="'.gTxt('toggle_all_selected').'" class="multi-edit"')
- .n.column_head('plugin', 'name', 'ied_plugin_composer', true, $switch_dir, '', '', (('name' == $sort) ? "$dir " : '').'name')
- .n.column_head('author', 'author', 'ied_plugin_composer', true, $switch_dir, '', '', (('author' == $sort) ? "$dir " : '').'author')
- .n.column_head(gTxt('version').' ('.gTxt('plugin_modified').')', 'version', 'ied_plugin_composer', true, $switch_dir, '', '', (('version' == $sort) ? "$dir " : '').'version')
- .n.hCell(gTxt('description'), '', ' class="description"')
- .n.hCell(gTxt('manage'), '', ' class="manage"')
- .n.column_head('active', 'status', 'ied_plugin_composer', true, $switch_dir, '', '', (('status' == $sort) ? "$dir " : '').'status')
- ).
- n. '</thead>'.
- n. '<tbody>';
- foreach ($rs as $row) {
- extract($row);
- $ename = ied_plugin_anchor($ied_pc_event, 'ied_plugin_edit', $name, array('name' => $name));
- $hlink = ($help) ? ied_plugin_anchor($ied_pc_event, 'ied_plugin_help_viewer', gTxt('ied_plugin_docs'), array('name' => $name)) : gTxt('none');
- $fnames = ied_plugin_get_name($name, $version);
- $pubtag = ied_plugin_anchor($ied_pc_event, 'ied_plugin_save_as_file', gTxt('publish'), array('name' => $name), array('title' => gTxt('ied_plugin_export', array('{name}' => $fnames[0]))));
- $pubztag = ied_plugin_anchor($ied_pc_event, 'ied_plugin_save_as_file', gTxt('ied_plugin_compress'), array('name' => $name, 'type' => 'zip'), array('title' => gTxt('ied_plugin_export', array('{name}' => $fnames[1]))));
- $modified = (strtolower($code) != (strtolower($code_restore)));
- $plugpref = ($flags & PLUGIN_HAS_PREFS) ? (sp.ied_plugin_anchor('plugin_prefs.'.urlencode($name), '', '['.gTxt('plugin_prefs').']', array('name' => $name), array('class' => 'plugin_prefs'.( ($status) ? '' : ' empty'))) ) : '';
- echo tr(
- n.td(
- fInput('checkbox', 'selected[]', $name)
- ,'', 'multi-edit')
- .n.td($ename.$plugpref)
- .n.td(( ($author_uri) ? '<a href="'.txpspecialchars($author_uri).'">'.txpspecialchars($author).'</a>' : txpspecialchars($author)))
- .n.td(( ($modified) ? ied_plugin_anchor($ied_pc_event, 'ied_plugin_restore', $version, array('name' => $name), array('title' => gTxt('ied_plugin_restore_help'), 'onclick' => 'return verify(\''.gTxt('ied_plugin_restore_verify', array('{name}' => $name)).'\');')) : $version) . (($modified) ? sp.'('.gTxt('yes').')' : ''))
- .n.td(txpspecialchars($description))
- .n.td($pubtag .sp. '|' .sp. $pubztag .sp. '|' .sp. $hlink)
- .n.td(ied_plugin_status_link($status,$name,yes_no($status)))
- );
- unset($name,$page);
- }
- echo n. '</tbody>'.
- n. endTable().
- n. '</div>'.
- n. tInput().
- n. '</form>'.
- ied_plugin_multiedit_form('db', '', $sort, $dir, '', '').
- n. '</div>'.
- n. '</div>';
- }
- if (!empty($prefs['plugin_cache_dir']) && file_exists($prefs['plugin_cache_dir'])) {
- $filenames = array();
- $directory = dir($prefs['plugin_cache_dir']);
- while ($file = $directory->read()) {
- if($file != "." && $file != "..") {
- $fileaddr = $prefs['plugin_cache_dir'].DS.$file;
- if (!is_dir($fileaddr)) {
- $filenames[]=$file;
- }
- }
- }
- $directory->close();
- ($filenames)?natcasesort($filenames):'';
- $out = array();
- foreach($filenames as $filename) {
- $parts = explode ('.',$filename);
- $fileext = array_pop($parts);
- if ($fileext=='php') {
- $basename = basename($filename);
- $plugin = ied_plugin_read_file($prefs['plugin_cache_dir'].DS.$filename);
- $hlink = ($plugin['help']) ? ied_plugin_anchor($ied_pc_event, 'ied_plugin_help_viewer', gTxt('ied_plugin_docs'), array('filename' => $filename)) : gTxt('none');
- $efile = ied_plugin_anchor($ied_pc_event, 'ied_plugin_edit', $plugin['name'], array('filename' => $filename));
- $fnames = ied_plugin_get_name($plugin['name'], $plugin['version']);
- $plugpref = (($plugin['flags'] & PLUGIN_HAS_PREFS)) ? ' '.ied_plugin_anchor('plugin_prefs.'.urlencode($plugin['name']), '', ' ['.gTxt('plugin_prefs').']') : '';
- $pubtag = ied_plugin_anchor($ied_pc_event, 'ied_plugin_save_as_file', gTxt('publish'), array('filename' => $filename), array('title' => gTxt('ied_plugin_export', array('{name}' => $fnames[0]))));
- $pubztag = ied_plugin_anchor($ied_pc_event, 'ied_plugin_save_as_file', gTxt('ied_plugin_compress'), array('filename' => $filename, 'type' => 'zip'), array('title' => gTxt('ied_plugin_export', array('{name}' => $fnames[1]))));
- $out[] = tr(
- n.td(
- fInput('checkbox', 'selected-cache[]', $filename)
- ,'', 'multi-edit')
- .n.td(
- tag($filename,'div',' class="ied_subdue"')
- .(isset($plugin['name']) ? $efile.$plugpref.'<br />' : '').' '
- )
- .n.td(
- ( isset($plugin['author_uri']) ? '<a href="'.$plugin['author_uri'].'">' : '' ) .
- ( isset($plugin['author']) ? $plugin['author'] : ' ' ).
- ( isset($plugin['author_uri']) ? '</a>' : '' )
- )
- .n.td(
- (isset($plugin['version']) ? $plugin['version'] : ' ')
- )
- .n.td(
- (isset($plugin['description']) ? $plugin['description'] : ' ')
- )
- .n.td(
- (isset($plugin['name']) ? $pubtag .sp. '|' .sp. $pubztag
- : tag(' ', 'span')
- )
- .sp. '|' .sp. $hlink
- )
- );
- }
- }
- if ($out) {
- echo '<div class="summary-details">'.
- n. '<form action="index.php" id="ied_plugin_cache_form" method="post">'.
- n. '<h3 class="lever txp-summary'.(get_pref('pane_ied_plugin_cacheplugs_visible') ? ' expanded' : '').'">'.
- n. '<a href="#ied_plugin_cacheplugs">' . gTxt('ied_plugin_cacheplugs_legend') . '</a>'.
- n. '</h3>'.
- n. '<div id="ied_plugin_cacheplugs" class="toggle" style="display:'.(get_pref('pane_ied_plugin_cacheplugs_visible') ? 'block' : 'none').'">'.
- n. '<div class="txp-listtables ied_plugin_cacheplugs">'.
- n.startTable('', '', 'txp-list').
- n. '<thead>'.
- n. tr(
- n.hCell(fInput('checkbox', 'select_all', 0, '', '', '', '', '', 'select_all'), '', ' title="'.gTxt('toggle_all_selected').'" class="multi-edit"')
- .n.hCell(gTxt('plugin'), '', ' class="name"')
- .n.hCell(gTxt('author'), '', ' class="author"')
- .n.hCell(gTxt('version') . ' ('.gTxt('plugin_modified').')', '', ' class="version"')
- .n.hCell(gTxt('description'), '', ' class="description"')
- .n.hCell(gTxt('manage'), '', ' class="manage"')
- ).
- n. '</thead>'.
- n. '<tbody>'.
- n. join(n, $out).
- n. '</tbody>'.
- n. endTable().
- n. '</div>'.
- n. tInput().
- n. '</form>'.
- ied_plugin_multiedit_form('cache', '', $sort, $dir, '', '').
- n. '</div>'.
- n. '</div>';
- }
- }
- echo '</div>'.
- n. script_js( <<<EOS
- $(document).ready(function() {
- $('#ied_plugin_db_form').txpMultiEditForm({
- 'checkbox' : 'input[name="selected[]"][type=checkbox]'
- });
- $('#ied_plugin_cache_form').txpMultiEditForm({
- 'checkbox' : 'input[name="selected-cache[]"][type=checkbox]'
- });
- });
- EOS
- );
- // Show/hide "Options" link by setting the appropriate class on the plugin's TR
- echo script_js(<<<EOS
- textpattern.Relay.register('txpAsyncHref.success', function(event, data) {
- jQuery(data.this).closest('tr').find('a.plugin_prefs').toggleClass('empty');
- });
- EOS
- );
- }
- // -------------------------------------------------------------
- function ied_plugin_multiedit_form($flavour, $page, $sort, $dir, $crit, $search_method) {
- global $ied_pc_event;
- $orders = selectInput('order', array(1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9), 5, false);
- $stati = selectInput('switch_status', array('toggle' => gTxt('ied_plugin_toggle'), 'on' => gTxt('on'), 'off' => gTxt('off')), 'toggle', false);
- $lifecycles = selectInput('ied_lc_event', array(
- 'installed' => gTxt('ied_plugin_lbl_lc_install'),
- 'enabled' => gTxt('ied_plugin_lbl_lc_enable'),
- 'installed,enabled' => gTxt('ied_plugin_lbl_lc_instable'),
- 'disabled' => gTxt('ied_plugin_lbl_lc_disable'),
- 'deleted' => gTxt('ied_plugin_lbl_lc_delete'),
- 'disabled,deleted' => gTxt('ied_plugin_lbl_lc_disdel'),
- ));
- if ($flavour === 'db') {
- $methods = array(
- 'changestatus' => array('label' => gTxt('changestatus'), 'html' => $stati),
- 'changeorder' => array('label' => gTxt('changeorder'), 'html' => $orders),
- 'lifecycle' => array('label' => gTxt('ied_plugin_lifecycle'), 'html' => $lifecycles),
- 'delete' => gTxt('delete'),
- );
- } else {
- $methods = array(
- 'lifecycle' => array('label' => gTxt('ied_plugin_lifecycle'), 'html' => $lifecycles),
- 'textpack' => array('label' => gTxt('ied_plugin_install_textpack')),
- 'delete' => gTxt('delete'),
- );
- }
- return multi_edit($methods, $ied_pc_event, 'ied_plugin_multi_edit', $page, $sort, $dir, $crit, $search_method);
- }
- // -------------------------------------------------------------
- function ied_plugin_multi_edit() {
- global $prefs;
- $selected = ps('selected');
- $selected_cache = ps('selected-cache');
- $method = assert_string(ps('edit_method'));
- if ($selected && is_array($selected))
- {
- $where = "name IN ('".join("','", doSlash($selected))."')";
- $lc_opts = do_list(get_pref('ied_plugin_lifecycle_options'));
- switch ($method)
- {
- case 'delete':
- foreach ($selected as $name)
- {
- if (safe_field('flags', 'txp_plugin', "name ='".doSlash($name)."'") & PLUGIN_LIFECYCLE_NOTIFY)
- {
- load_plugin($name, true);
- if (in_array('disabled', $lc_opts)) {
- callback_event("plugin_lifecycle.$name", 'disabled');
- }
- if (in_array('deleted', $lc_opts)) {
- callback_event("plugin_lifecycle.$name", 'deleted');
- }
- }
- }
- safe_delete('txp_plugin', $where);
- break;
- case 'changestatus':
- switch (ps('switch_status')) {
- case 'on':
- $newstat = '1';
- break;
- case 'off':
- $newstat = '0';
- break;
- case 'toggle':
- default:
- $newstat = '(1-status)';
- break;
- }
- foreach ($selected as $name) {
- if (safe_field('flags', 'txp_plugin', "name ='".doSlash($name)."'") & PLUGIN_LIFECYCLE_NOTIFY) {
- $status = safe_field('status', 'txp_plugin', "name ='".doSlash($name)."'");
- $status = $status ? 'disabled' : 'enabled';
- load_plugin($name, true);
- if (in_array($status, $lc_opts)) {
- callback_event("plugin_lifecycle.$name", $status);
- }
- }
- }
- safe_update('txp_plugin', 'status = '.$newstat, $where);
- break;
-
- case 'changeorder':
- $order = min(max(intval(ps('order')), 1), 9);
- safe_update('txp_plugin', 'load_order = '.$order, $where);
- break;
- case 'lifecycle':
- $lc_evs = do_list(ps('ied_lc_event'));
- foreach ($selected as $name) {
- foreach ($lc_evs as $lc_ev) {
- callback_event("plugin_lifecycle.$name", $lc_ev);
- }
- }
- break;
- }
- } else {
- $selected = array();
- }
- if ($selected_cache && is_array($selected_cache))
- {
- switch ($method)
- {
- case 'delete':
- foreach ($selected_cache as $name) {
- $filenames = array();
- $dir = dir($prefs['plugin_cache_dir']);
- while ($file = $dir->read()) {
- if($file != "." && $file != ".." && in_array($file, $selected_cache)) {
- $fileaddr = $prefs['plugin_cache_dir'].DS.$file;
- if (!is_dir($fileaddr)) {
- unlink($fileaddr);
- }
- }
- }
- $dir->close();
- }
- break;
- case 'lifecycle':
- $lc_evs = do_list(ps('ied_lc_event'));
- foreach ($selected_cache as $name) {
- $name = str_replace('.php', '', $name);
- foreach ($lc_evs as $lc_ev) {
- callback_event("plugin_lifecycle.$name", $lc_ev);
- }
- }
- break;
- case 'textpack':
- // Read the textpack from the .php file and call install_textpack()
- $textpack = array();
- foreach ($selected_cache as $name) {
- $fileaddr = $prefs['plugin_cache_dir'].DS.$name;
- $contents = file($fileaddr);
- $in_tp = $in_comment = false;
- foreach ($contents as $row) {
- if (strpos($row, '/**') === 0) {
- $in_comment = true;
- }
- if (strpos($row, '**/') === 0) {
- $in_comment = false;
- }
- if (strpos($row, 'EOT;') !== false) {
- break;
- }
- if ($in_tp === true) {
- $textpack[] = trim($row);
- }
- if (!$in_comment && strpos($row, '$plugin[\'textpack\']') !== false) {
- $in_tp = true;
- }
- }
- }
- $done = install_textpack(join(n, $textpack));
- break;
- }
- } else {
- $selected_cache = array();
- }
- $message = '';
- if ($selected || $selected_cache) {
- if ($method === 'delete') {
- $message = gTxt('plugin_deleted', array('{name}' => join(', ', array_merge($selected, $selected_cache))));
- } else if ($method === 'lifecycle') {
- $message = gTxt('ied_plugin_lc_fired', array('{name}' => join(', ', array_merge($selected, $selected_cache)), '{event}' => join(',', $lc_evs)));
- } else if ($method === 'textpack') {
- $message = gTxt('textpack_strings_installed', array('{count}' => $done));
- } else {
- $message = gTxt('plugin_updated', array('{name}' => join(', ', $selected)));
- }
- }
- ied_plugin_table($message);
- }
- // -------------------------------------------------------------
- function ied_plugin_anchor($evt, $stp, $linktext, $nv = array(), $atts = array()) {
- $nv['_txp_token'] = form_token();
- $atts['href'] = '?event='.$evt.($stp ? '&step='.$stp : '').'&'.http_build_query($nv);
- $attribs = '';
- foreach ($atts as $n => $v) {
- $attribs .= ' '.txpspecialchars($n).'="'.txpspecialchars($v).'"';
- }
- return tag($linktext, 'a', $attribs);
- }
- // -------------------------------------------------------------
- function ied_plugin_status_link($status, $name, $linktext) {
- return asyncHref($linktext, array('step' => 'ied_plugin_switch_status', 'thing' => $name),' title="'.($status==1 ? gTxt('disable') : gTxt('enable')).'"' );
- }
- // -------------------------------------------------------------
- function ied_plugin_switch_status() {
- extract(array_map('assert_string', gpsa(array('thing', 'value'))));
- $change = ($value == gTxt('yes')) ? 0 : 1;
- safe_update('txp_plugin', "status = $change", "name = '".doSlash($thing)."'");
- $lc_opts = do_list(get_pref('ied_plugin_lifecycle_options'));
- $stp = $change ? 'enabled' : 'disabled';
- if (in_array($stp, $lc_opts) && (safe_field('flags', 'txp_plugin', "name='".doSlash($thing)."'") & PLUGIN_LIFECYCLE_NOTIFY) ) {
- load_plugin($thing, true);
- $message = callback_event("plugin_lifecycle.$thing", $stp);
- }
- echo gTxt($change ? 'yes' : 'no');
- }
- // -------------------------------------------------------------
- function ied_plugin_set_order() {
- extract(doSlash(gpsa(array('name', 'load_order'))));
- $order = min(max( intval($load_order), 1), 9);
- safe_update('txp_plugin', "load_order = $load_order", "name = '$name'");
- ied_plugin_table(gTxt('plugin_saved', array('{name}' => $name)));
- }
- // -------------------------------------------------------------
- function ied_plugin_delete() {
- $name = doSlash(ps('name'));
- $lc_opts = do_list(get_pref('ied_plugin_lifecycle_options'));
- $lc_dis = in_array('disabled', $lc_opts);
- $lc_del = in_array('deleted', $lc_opts);
- if ( ($lc_del || $lc_dis) && (safe_field('flags', 'txp_plugin', "name='".$name."'") & PLUGIN_LIFECYCLE_NOTIFY) ) {
- load_plugin($name, true);
- if ($lc_dis) {
- callback_event("plugin_lifecycle.$name", 'disabled');
- }
- if ($lc_del) {
- callback_event("plugin_lifecycle.$name", 'deleted');
- }
- }
- safe_delete('txp_plugin', "name='$name'");
- ied_plugin_table(gTxt('plugin_deleted', array('{name}' => $name)));
- }
- // -------------------------------------------------------------
- function ied_plugin_restore() {
- $name = doSlash(gps('name'));
- safe_update("txp_plugin","code = code_restore","name='$name'");
- ied_plugin_table(gTxt('ied_plugin_restored', array('{name}' => $name)));
- }
- // -------------------------------------------------------------
- function ied_plugin_edit($message='', $newfile='') {
- global $prefs, $ied_plugin_globals, $ied_pc_event;
- $newname = trim(gps('newname'));
- $filename = gps('filename');
- $editfile = $filename ? 1 : 0;
- $name = empty($newname) ? gps('name') : $newname;
- $name = ($newfile) ? $newfile : (($filename) ? $filename : $name);
- pagetop(gTxt('ied_plugin_editing', array('{name}' => txpspecialchars($name))), $message);
- require_privs('ied_plugin_composer');
- echo ied_insert_editors();
- if (!$editfile) {
- $rs = safe_row("author, author_uri, version, description, code, help, status, type, load_order, flags", "txp_plugin", "name='".doSlash($name)."'");
- extract($rs);
- list($css,$help) = ($help) ? ied_plugin_extract_hunk($help, "CSS", "<!--|-->", true) : array('',$help);
- } else {
- $plugin = ied_plugin_read_file($prefs['plugin_cache_dir'].DS.$name);
- $filename = $name;
- $name = explode ('.', $name);
- $fileext = array_pop($name);
- $name = implode($name);
- extract($plugin);
- $status = ($fileext=='php')? 1: 0;
- }
- $ifel = get_pref('ied_plugin_interface_elems');
- $distblock = (strpos($ifel, 'distribution') !== false);
- $styleblock = (strpos($ifel, 'style') !== false);
- $distribution = '';
- list ($start_css, $end_css) = ied_plugin_make_markers("CSS", $ied_plugin_globals['css_start'], $ied_plugin_globals['css_end']);
- if ($distblock) {
- $plugin['name'] = $name;
- $plugin['author'] = $author;
- $plugin['author_uri'] = $author_uri;
- $plugin['version'] = $version;
- $plugin['description'] = $description;
- $plugin['help'] = ied_plugin_textile($name, $help, $css, $start_css, $end_css);
- $plugin['code'] = $code;
- $plugin['type'] = $type;
- $plugin['order'] = $load_order;
- $plugin['flags'] = $flags;
- $plugin['md5'] = md5( $plugin['code'] );
- $distribution = '<textarea name="distribution" rows="1" onclick="this.select()">'.base64_encode(serialize($plugin)).'</textarea>';
- }
- for ($i = 1; $i <= 9; $i++) $orders[$i] = $i;
- $tp_pfx = unserialize(get_pref('ied_plugin_tp_prefix', '', 1));
- $tp_pfx = isset($tp_pfx[$name]) ? $tp_pfx[$name] : '';
- $fnames = ied_plugin_get_name($name, $version);
- $namedLink = ($filename) ? array('filename' => $filename) : array('name' => $name);
- $zippedLink = array_merge($namedLink, array('type' => 'zip'));
- $slink = ied_plugin_anchor($ied_pc_event, 'ied_plugin_save_as_file', gTxt('ied_plugin_export', array('{name}' => $fnames[0])), $namedLink);
- $sziplink = ied_plugin_anchor($ied_pc_event, 'ied_plugin_save_as_file', gTxt('ied_plugin_export_zip', array('{name}' => $fnames[1])), $zippedLink);
- $sphplink = ied_plugin_anchor($ied_pc_event, 'ied_plugin_save_as_php_file', gTxt('ied_plugin_save_as', array('{name}' => $fnames[2])), $namedLink);
- $stxtlink = ied_plugin_anchor($ied_pc_event, 'ied_plugin_save_as_textpack', gTxt('ied_plugin_export_textpack'), $namedLink);
- $vhelplinkfull = ($help) ? '[ ' .ied_plugin_anchor($ied_pc_event, 'ied_plugin_help_viewer', gTxt('ied_plugin_docs'), $namedLink) . ' ]' : '';
- $msgpop = '<div id="ied_plugin_msgpop"><input type="button" class="publish" value="'.gTxt('ok').'" onclick="ied_plugin_toggle_msgpop(\'0\');" /><h2>'.gTxt('ied_plugin_msgpop_lbl').'</h2><span class="ied_plugin_msgpop_content"></span></div>';
- $newname = fInput('text', 'newname', $name, '', '', '', INPUT_REGULAR);
- $author_widget = fInput('text', 'author', $author, '', '', '', INPUT_REGULAR);
- $author_uri_widget = fInput('text', 'author_uri', $author_uri, '', '', '', INPUT_REGULAR);
- $version_widget = fInput('text', 'version', $version, 'input-small', '', '',INPUT_SMALL) .sp. (($editfile) ? checkbox('rename_file', '1', 0, '','rename_file') . ' <label for="rename_file">'.gTxt('ied_plugin_rename_file').'</label>' : checkbox('restore_point', '1', 0, '','restore_point') . ' <label for="restore_point">'.gTxt('ied_plugin_restore_point').'</label>');
- $description_widget = fInput('text', 'description', $description, 'input-xlarge', '', '', INPUT_LARGE);
- $codeblock = '<textarea name="code" id="plugin_editor" rows="'.INPUT_REGULAR.'" class="code codepress php" maxlength="'.$ied_plugin_globals['size_code'].'">'.txpspecialchars($code).'</textarea><div class="ied_plugin_info_bar"><span>'.gTxt('ied_plugin_jump_to_line').'</span><input type="text" id="ied_plugin_jumpToLine" size="5" maxlength="6" /><span class="ied_plugin_charsRemain"></span></div>';
- $help_widget = '<textarea name="help" rows="'.INPUT_REGULAR.'" class="mceEditor" maxlength="'.$ied_plugin_globals['size_help'].'">'.txpspecialchars($help).'</textarea><div class="ied_plugin_info_bar"><span class="ied_plugin_charsRemain"></span></div>';
- $css_widget = ($styleblock) ? '<textarea name="css" rows="'.INPUT_MEDIUM.'" class="code" maxlength="'.$ied_plugin_globals['size_css'].'">'.txpspecialchars($css).'</textarea><div class="ied_plugin_info_bar"><span class="ied_plugin_charsRemain"></span></div>' : '';
- $plugstatus = (!$editfile) ? sp.sp.checkbox('status',1,$status, '','status'). ' <label for="status">'.gTxt('ied_plugin_enable').'</label>' : '';
- $plugtype = radio('type',0,(($type==0)?1:0)).gTxt('ied_plugin_type_0')." "
- . radio('type',1,(($type==1)?1:0)).gTxt('ied_plugin_type_1')." "
- . radio('type',2,(($type==2)?1:0)).gTxt('ied_plugin_type_2')." "
- . radio('type',3,(($type==3)?1:0)).gTxt('ied_plugin_type_3')." "
- . radio('type',4,(($type==4)?1:0)).gTxt('ied_plugin_type_4')." "
- . radio('type',5,(($type==5)?1:0)).gTxt('ied_plugin_type_5');
- $plugorder = selectInput('load_order', $orders, $load_order, 0, 0);
- $flaglist = checkbox('flags[]',PLUGIN_HAS_PREFS,(($flags & PLUGIN_HAS_PREFS)?1:0)) . '<label>'.gTxt('ied_plugin_flag_has_prefs').'</label> '
- .checkbox('flags[]',PLUGIN_LIFECYCLE_NOTIFY,(($flags & PLUGIN_LIFECYCLE_NOTIFY)?1:0)) . '<label>'.gTxt('ied_plugin_flag_lifecycle_notify').'</label> ';
- // .checkbox('flags[]',0x0004,(($flags & 0x0004)?1:0)) . '<label>Summat else</label> ';
- $sub = fInput('submit', '', gTxt('save'), 'publish', '', '', '', '', 'ied_editSave');
- $codesub = (!$editfile) ? '<a class="navlink" name="ied_plugin_code_save" id="ied_plugin_code_save">' . gTxt('ied_plugin_code_save') . '</a>' : '';
- // Language info. ied_visible_langs is the user's choice of which ones they want to see available.
- // ied_available_langs is the list of actual, currently-installed langs
- $ied_listlangs = get_pref('ied_plugin_lang_choose', 'installed');
- $ied_visible_langs = ied_plugin_lang_list($ied_listlangs);
- $ied_available_langs = ($ied_listlangs == 'installed') ? $ied_visible_langs : ied_plugin_lang_list('installed');
- $dflt_lang = get_pref('ied_plugin_lang_default', $prefs['language']);
- $dflt_lang = array_key_exists($dflt_lang, $ied_visible_langs) ? $dflt_lang : $prefs['language'];
- $langsel = selectInput('ied_plugin_tp_lang', $ied_visible_langs, $dflt_lang, '', '', 'ied_plugin_tp_lang')
- .fInput('button', 'ied_plugin_tp_refresh', gTxt('ied_plugin_load'), '', '', '', '', '', 'ied_plugin_tp_refresh');
- $preselected = do_list(get_pref('ied_plugin_lang_selected', ''));
- $op_langs[] = '<select name="ied_plugin_tp_oplangs" id="ied_plugin_tp_oplangs" multiple="multiple"><option value=""></option>';
- foreach ($ied_available_langs as $langcode => $alang) {
- $sel = in_array($langcode, $preselected) ? ' selected="selected"' : '';
- $op_langs[] = '<option value="'.$langcode.'"'.$sel.'>'.$alang.'</option>';
- }
- $op_langs[] = '</select>';
- $tp_strings = array();
- $tp_rows = ied_plugin_textpack_grab($dflt_lang, $tp_pfx);
- foreach ($tp_rows as $tp_string) {
- $apsel = selectInput('ied_plugin_tp_event', array('admin' => gTxt('admin'), 'public' => gTxt('public'), 'common' => gTxt('both')), ($tp_string['event'] == 'public' ? 'public' : ($tp_string['event'] == 'common' ? 'common' : 'admin')) );
- $tp_strings[] = '<li>'.fInput('text', 'textpack_'.$tp_string['name'], $tp_string['data']).' '.$apsel.' <label>'.$tp_string['name'].'</label>'.'</li>';
- }
- $err_prefix = gTxt('ied_plugin_syntax_err');
- $codesave_ok = gTxt('ied_plugin_code_saved');
- $phpdoc = '';
- // TODO
- $classFinder = '/class[\s\n]+(\w+)[\s\n]*\{?(function[\s\n]+(\w+)[\s\n]*\(.*\)[\s\n]*\{?)*/';
- $functionFinder = '/function[\s\n]+(\w+)[\s\n]*\(.*\)[\s\n]*\{?/';
- preg_match_all($functionFinder, $code , $functionArray);
- // selectInput requires key and value to be the same
- //dmp($functionArray);
- $fnArray = array();
- /*
- foreach($functionArray[1] as $key => $val) {
- $fnArray[$val] = $functionArray[1][$key];
- }
- $phpdoc = selectInput('ied_plugin_to_phpdoc', $fnArray, '', false, '', 'ied_plugin_to_phpdoc')
- .'<a class="navlink" name="ied_plugin_btn_phpdoc" id="ied_plugin_btn_phpdoc">' . gTxt('ied_plugin_php_doc') . '</a>';
- */
- $phpdoc = '';
- echo
- hed(gTxt('ied_plugin_edit', array('{name}' => $name, '{version}' => $version)).n.$vhelplinkfull, 2).
- n. form(
- '<div id="ied_plugin_sub">'. ($sub).'</div>'
- .n. '<div class="summary-details"><h3 class="lever txp-summary'.(get_pref('pane_ied_plugin_meta_visible') ? ' expanded' : '').'"><a href="#ied_plugin_meta">' . gTxt('ied_plugin_meta_legend') . '</a></h3><div id="ied_plugin_meta" class="toggle" style="display:'.(get_pref('pane_ied_plugin_meta_visible') ? 'block' : 'none').'">'
- .n. '<p><label>' . gTxt('name') . '</label>' . sp . $newname . sp. '<label>' . gTxt('version') . '</label>' . sp . $version_widget . $plugstatus . ( ($filename) ? tag(sp.sp.'('.$filename.')','span',' style="color:gray;"').hInput('filename',$filename) : '' ) . '</p>'
- .n. '<p><label>' . gTxt('description') . '</label>' . sp . $description_widget . '</p>'
- .n. '<p><label>' . gTxt('author') . '</label>' . sp . $author_widget . sp. '<label>' . gTxt('website') . '</label>' .sp. $author_uri_widget. '</p>'
- .n. '<p><label>' . gTxt('ied_plugin_type') . '</label>' . sp . $plugtype . '</p>'
- .n. '<p><label>' . gTxt('ied_plugin_flags') . '</label>' . sp . $flaglist .sp. '<label>' . gTxt('ied_plugin_load_order') . '</label>' . sp . $plugorder . sp.sp . gTxt('ied_plugin_load_order_help') . '</p>'
- .n. '</div></div>'
- .n. '<div class="summary-details"><h3 class="lever txp-summary'.(get_pref('pane_ied_plugin_code_visible') ? ' expanded' : '').'"><a href="#ied_plugin_code">'.gTxt('ied_plugin_code_legend').'</a></h3><div id="ied_plugin_code" class="toggle" style="display:'.(get_pref('pane_ied_plugin_code_visible') ? 'block' : 'none').'">'
- .n. '<span class="ied_plugin_edit_toolbar">' . $msgpop . $phpdoc . sp . $codesub . '</span>'
- .n. '<div>' . $codeblock . '</div>'
- .n. '</div></div>'
- .n. '<div class="summary-details"><h3 class="lever txp-summary'.(get_pref('pane_ied_plugin_tp_strings_visible') ? ' expanded' : '').'"><a href="#ied_plugin_tp_strings">' . gTxt('ied_plugin_tp_legend') . ' <span id="ied_plugin_tp_count"></span></a></h3><div id="ied_plugin_tp_strings" class="toggle" style="display:'.(get_pref('pane_ied_plugin_tp_strings_visible') ? 'block' : 'none').'">'
- .n. '<div id="ied_plugin_tp_controls">'
- .n. '<label>'
- .n. gTxt('ied_plugin_tp_prefix')
- .n. '</label>'
- .n. fInput('text', 'ied_plugin_tp_prefix', $tp_pfx, '', '', '', '', '', 'ied_plugin_tp_prefix')
- .n. sp
- .n. $langsel
- .n. sp
- .n. fInput('hidden', 'ied_plugin_tp_lang_dflt', $dflt_lang, '', '', '', '', '', 'ied_plugin_tp_lang_dflt')
- .n. gTxt('ied_plugin_tp_populate').n.'</label>'.fInput('text', 'ied_plugin_tp_populate', '', '', '', '', '', '', 'ied_plugin_tp_populate') . sp . '<button id="ied_plugin_tp_load">'.gTxt('go').'</button>'
- .n. '<span id="ied_plugin_tp_load_count"></span>'
- .n. '</div>'
- .n. '<a href="#" id="ied_plugin_add_string">+</a>'
- .n. '<ul>'
- .n. join(n, $tp_strings)
- .n. '</ul></div></div>'
- .n. '<div class="summary-details"><h3 class="lever txp-summary'.(get_pref('pane_ied_plugin_docs_visible') ? ' expanded' : '').'"><a href="#ied_plugin_docs">'.gTxt('ied_plugin_docs_legend').'</a></h3><div id="ied_plugin_docs" class="toggle" style="display:'.(get_pref('pane_ied_plugin_docs_visible') ? 'block' : 'none').'">'
- .n. '<div>' . $help_widget . '</div>'
- .n. (($styleblock) ? '<div>' . gTxt( 'css' ) . $css_widget . '</div>' : '')
- .n. '</div></div>'
- .n. '<div>' . $sub . '</div>'
- .n. '<div class="summary-details"><h3 class="lever txp-summary'.(get_pref('pane_ied_plugin_utils_visible') ? ' expanded' : '').'"><a href="#ied_plugin_utils">'.gTxt('ied_plugin_utils_legend').'</a></h3><div id="ied_plugin_utils" class="toggle" style="display:'.(get_pref('pane_ied_plugin_utils_visible') ? 'block' : 'none').'">'
- .n. (($distblock) ? '<div>' . gTxt('ied_plugin_code_dist') . $distribution . '</div>' : '')
- .n. '<div>' . join(n, $op_langs) . '</div>'
- .n. '<div>' . $slink . '</div>'
- .n. '<div>' . $sziplink . '</div>'
- .n. '<div>' . $stxtlink . '</div>'
- .n. '<div>' . $sphplink . '</div>'
- .n. '</div></div>'
- .n. sInput('ied_plugin_save')
- .n. eInput($ied_pc_event)
- .n. hInput('name',$name)
- , '', '', 'post', 'ied_editForm').
- script_js(<<<EOF
- var ied_plugin_tp_total = 0;
- jQuery.fn.ied_plugin_resizehandle = function(curh) {
- return this.each(function() {
- var me = jQuery(this);
- me.animate({height: curh});
- me.after(
- jQuery('<div class="ied_plugin_resizehandle">--- + ---</div>').bind("mousedown", function(e) {
- var h = me.height();
- var y = e.clientY;
- var moveHandler = function(e) {
- me.height(Math.max(20, e.clientY + h - y));
- };
- var upHandler = function(e) {
- jQuery("html").unbind("mousemove",moveHandler).unbind("mouseup",upHandler);
- newh = me.height();
- setCookie('ied_plugin_edheight', newh, 365);
- };
- jQuery("html").bind("mousemove", moveHandler).bind("mouseup", upHandler);
- })
- );
- });
- }
- jQuery.fn.selectRange = function(start, end) {
- return this.each(function() {
- if(this.setSelectionRange) {
- this.focus();
- this.setSelectionRange(start, end);
- } else if(this.createTextRange) {
- var range = this.createTextRange();
- range.collapse(true);
- range.moveEnd('character', end);
- range.moveStart('character', start);
- range.select();
- }
- });
- };
- Array.prototype.unique = function () {
- var r = new Array();
- o:for(var i = 0, n = this.length; i < n; i++) {
- for(var x = 0, y = r.length; x < y; x++) {
- if(r[x]==this[i]) {
- continue o;
- }
- }
- r[r.length] = this[i];
- }
- return r;
- }
- function ied_goToLine() {
- var line = parseInt(jQuery('#ied_plugin_jumpToLine').val());
- var ied_ed = jQuery('#plugin_editor');
- var ied_edd = document.getElementById('plugin_editor'); // Dunno how to convert a jQuery obj back to DOM
- var lines = ied_ed.val().split('\\n');
- var numchars = 0;
- var count = 0;
- var findstr = '';
- jQuery.each(lines, function() {
- count++;
- if (count >= line) {
- findstr = this;
- return false;
- }
- numchars += (this.length)+2; // Don't ask. +2 is something to do with line endings I think
- });
- // Find the line containing the string we found. Start counting from the line before.
- // Those pesky line endings come into play again so we need to subtract the number
- // of lines found from the start character position *shrug*
- start = ied_ed.val().indexOf(findstr, numchars-count);
- start = (findstr == '') ? start+1 : start;
- end = start+findstr.length;
- ied_ed.selectRange(end-1, end);
- if(document.createEvent) {
- var ied_theCode = ied_ed.val().charCodeAt(end-1);
- if( window.KeyEvent ) {
- var ev = document.createEvent('KeyEvents');
- ev.initKeyEvent('keypress', false, true, window, false, false, false, false, 0, ied_theCode);
- } else {
- var ev = document.createEvent('UIEvents');
- ev.initUIEvent('keypress', false, true, window, 0);
- ev.keyCode = ied_theCode;
- }
- ied_edd.dispatchEvent(ev); // cause scroll to cursor by replacing last char with itself
- }
- ied_ed.selectRange(start, end);
- return false;
- }
- function ied_plugin_toggle_msgpop(state) {
- var obj = jQuery("#ied_plugin_msgpop");
- if (state != undefined) {
- if (state == 1) {
- obj.show('normal');
- } else {
- obj.hide('normal');
- }
- } else {
- obj.toggle('normal');
- }
- }
- function ied_plugin_rtrim(str, chars) {
- chars = chars || "\s";
- return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
- }
- function ied_plugin_update_tp_count() {
- var tp_count = tp_warns = 0;
- jQuery('#ied_plugin_tp_strings ul label').each(function() {
- tp_count++;
- if (jQuery(this).hasClass('warning')) {
- tp_warns++;
- }
- });
- jQuery('#ied_plugin_tp_count').empty().append('('+tp_count+ ' | '+tp_warns+ ' warnings)');
- // Update the global var for use when loading strings
- ied_plugin_tp_total = tp_count;
- }
- jQuery(function() {
- curh = getCookie('ied_plugin_edheight');
- curh = (curh == null) ? '480' : curh;
- jQuery("#plugin_editor").ied_plugin_resizehandle(parseInt(curh));
- jQuery('textarea[maxlength]').keyup(function(){
- var max = parseInt(jQuery(this).attr('maxlength'));
- if(jQuery(this).val().length > max){
- jQuery(this).val(jQuery(this).val().substr(0, jQuery(this).attr('maxlength')));
- }
- jQuery(this).parent().find('.ied_plugin_charsRemain').html('Chars remaining: '+ (max - jQuery(this).val().length));
- });
- jQuery('textarea[maxlength]').keyup();
- jQuery('#ied_plugin_jumpToLine').keydown(function(e) {
- var code = (e.keyCode ? e.keyCode : e.which);
- if(code == 13) {
- e.preventDefault();
- e.stopPropagation();
- ied_goToLine();
- return false;
- }
- });
- // Store the prefix
- jQuery('#ied_plugin_tp_prefix').blur(function() {
- var pfx = jQuery(this).val();
- sendAsyncEvent(
- {
- event: textpattern.event,
- step: 'ied_plugin_set_tp_prefix',
- plugin: '{$name}',
- prefix: pfx
- });
- });
- // Find all occurrences of gTxt('something')
- jQuery('#plugin_editor, #ied_plugin_tp_prefix').blur(function() {
- var ied_tp_pfx = jQuery('#ied_plugin_tp_prefix').val();
- if (ied_tp_pfx != '') {
- var ied_gtxt_re = /gTxt\([\'\"]([a-zA-Z0-9_]*?)[\"\'][,\)]/gi;
- var ied_tp_ta = jQuery('#plugin_editor').val().replace(/\s*/g,''); // Strip spaces to make lookups easier
- var ied_tp_items = ied_tp_ta.match(ied_gtxt_re);
- // if JS RegExp captured parenthical expressions in global searches or it was easy to inject variables
- // into new RegExp() calls, this loop could be avoided
- var ied_tp_used = [];
- for (var idx = 0; idx < ied_tp_items.length; idx++) {
- var pos = ied_tp_items[idx].lastIndexOf("'");
- pos = (pos == -1) ? ied_tp_items[idx].lastIndexOf('"') : pos;
- tpstr = ied_tp_items[idx].substr(6,pos-6);
- if (tpstr.indexOf(ied_tp_pfx) == 0) {
- ied_tp_used[ied_tp_used.length] = tpstr;
- }
- }
- ied_tp_used = ied_tp_used.unique();
- // List of all current textpack strings in use (as of last Save operation)
- var ied_tp_curr = [];
- jQuery('#ied_plugin_tp_strings label').each(function() {
- ied_tp_curr[ied_tp_curr.length] = jQuery(this).text();
- });
- // Iterate over current array and check if each name is in the used textpack item list.
- // If it is, remove it from the final list.
- for (var idx = 0; idx < ied_tp_curr.length; idx++) {
- if ((pos = jQuery.inArray(ied_tp_curr[idx], ied_tp_used)) > -1) {
- ied_tp_used.splice(pos, 1);
- jQuery('#ied_plugin_tp_strings ul label:contains('+ied_tp_curr[idx]+')').toggleClass('warning', false).next(".ied_plugin_xbtn").remove();
- } else {
- setclass = 1;
- jQuery('#ied_plugin_tp_strings ul label:contains('+ied_tp_curr[idx]+')').toggleClass('warning', true).next(".ied_plugin_xbtn").remove().end().after('<a href="#" class="ied_plugin_xbtn">[x]</a>');
- }
- }
- // For each remaining item that has been used, add an input box
- // TODO: i18n the select options
- for (var idx = 0; idx < ied_tp_used.length; idx++) {
- jQuery('#ied_plugin_tp_strings ul').prepend('<li><input type="text" name="textpack_'+ied_tp_used[idx]+'" value="" /> <select name="ied_plugin_tp_event"><option value="admin">Admin</option><option value="public">Public</option><option value="common">Both</option></select> <label>'+ied_tp_used[idx]+'</label></li>');
- }
- ied_plugin_update_tp_count();
- }
- }).blur();
- // Handle adding new strings manually
- jQuery('#ied_plugin_add_string').click(function(ev) {
- jQuery('#ied_plugin_tp_strings ul').before('<div id="ied_plugin_new_container"><label>'+jQuery('#ied_plugin_tp_prefix').val()+'_<input type="text" name="ied_plugin_tp_newname" id="ied_plugin_tp_newname" value="" /></label></div>');
- jQuery('#ied_plugin_tp_newname').focus();
- ev.preventDefault();
- });
- jQuery(document).on('blur', '#ied_plugin_tp_newname', function() {
- var newname = ied_plugin_rtrim(jQuery('#ied_plugin_tp_prefix').val()+'_'+jQuery('#ied_plugin_tp_newname').val(), '_');
- var newok = true;
- jQuery('#ied_plugin_tp_strings ul li label').each(function() {
- if (jQuery(this).text() == newname) {
- jQuery('#ied_plugin_tp_newname').css('color', '#E00');
- newok = false;
- }
- });
- // TODO: i18n select option text
- if (newok) {
- jQuery('#ied_plugin_tp_strings ul').prepend('<li><input type="text" name="textpack_'+newname+'" value="" /> <select name="ied_plugin_tp_event"><option value="admin">Admin</option><option value="public">Public</option><option value="common">Both</option></select> <label>'+newname+'</label></li>');
- jQuery('#ied_plugin_new_container').remove();
- jQuery('input[name="textpack_'+newname+'"]').focus();
- }
- ied_plugin_update_tp_count();
- });
- // Initialise the generic AJAX error handler
- jQuery('.ied_editForm').ajaxError(function(event, request, settings) {
- var xhr = jQuery(request.responseText);
- // phpdoc generation barfed
- if (settings.data.indexOf('step=ied_plugin_generate_phpdoc') > -1)…
Large files files are truncated, but you can click here to view the full file