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', ied_plugin_gTxt('ied_plugin_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'); global $ied_plugin_composer, $ied_plugin_prefs, $ied_plugin_globals, $prefs; $ied_plugin_globals = array( 'css_start' => '', 'dlm_start' => '#', 'dlm_end' => '', 'start' => ' --- BEGIN PLUGIN SECTION ---', 'end' => ' --- END PLUGIN SECTION ---', 'size_help' => '63535', 'size_css' => '2000', 'size_code' => '16777215', ); // Double array: 1st is a list of current prefs and their defaults, // 2nd is a list of legacy prefs that may need removing in future (defaults all set empty) $ied_plugin_prefs = array( array( 'ied_plugin_editor' => 'none', 'ied_plugin_editor_path' => hu.'js'.DS, 'ied_plugin_editor_width' => '110', 'ied_plugin_help_editor' => 'textile', 'ied_plugin_help_editor_path' => hu.'js'.DS, 'ied_plugin_output_order' => '0', 'ied_plugin_output_sfile' => '{name}_v{version}.txt', 'ied_plugin_output_sfilec' => '{name}_v{version}_zip.txt', 'ied_plugin_output_sfilep' => '{name}_v{version}.php', 'ied_plugin_output_tmpcache' => $prefs['tempdir'], ), array( 'ied_plugin_not_used_any_more_placeholder' => '', ) ); } // ------------------------------------------------------------- function ied_plugin_composer($event, $step) { if(!$step or !in_array($step, array( 'ied_plugin_delete', 'ied_plugin_edit', 'ied_plugin_help', 'ied_plugin_list', 'ied_plugin_install', 'ied_plugin_save', 'ied_plugin_restore', 'ied_switch_status', 'ied_set_order', 'ied_plugin_setup', 'ied_plugin_prefs_install', 'ied_plugin_prefs_remove', 'ied_plugin_prefs_update', 'ied_plugin_create_new', 'ied_plugin_save_as_file', 'ied_plugin_save_as_php_file', 'ied_plugin_upload', 'ied_plugin_help_viewer', ))) { ied_plugin_list(); } else $step(); } // ------------------------------------------------------------- function ied_plugin_welcome($event, $step) { $msg = ''; switch ($step) { case 'installed': ied_plugin_prefs_install(0); $msg = 'Thanks for installing the plugin composer. Please read the docs :-)'; break; case 'deleted': ied_plugin_prefs_remove(0); break; } return $msg; } // ------------------------------------------------------------- // Reurns an array of filenames; 1st is the standard plugin, 2nd is the compressed plugin, 3rd is the PHP template function ied_plugin_get_name($name, $version) { global $ied_plugin_prefs, $prefs; $out = array( ((isset($prefs['ied_plugin_output_sfile']) && !empty($prefs['ied_plugin_output_sfile'])) ? $prefs['ied_plugin_output_sfile'] : $ied_plugin_prefs[0]['ied_plugin_output_sfile']), ((isset($prefs['ied_plugin_output_sfilec']) && !empty($prefs['ied_plugin_output_sfilec'])) ? $prefs['ied_plugin_output_sfilec'] : $ied_plugin_prefs[0]['ied_plugin_output_sfilec']), ((isset($prefs['ied_plugin_output_sfilep']) && !empty($prefs['ied_plugin_output_sfilep'])) ? $prefs['ied_plugin_output_sfilep'] : $ied_plugin_prefs[0]['ied_plugin_output_sfilep']), ); $rep = array( "{name}" => $name, "{version}" => $version, ); foreach ($out as $fidx => $fname) { $fname = strtr($fname, $rep); $out[$fidx] = sanitizeForFile($fname); } return $out; } // ------------------------------------------------------------- function ied_plugin_list($message='') { global $prefs; pagetop(gTxt('edit_plugins'),$message); echo startTable('list'). tr(tda( form( fInput('text','name','','','','','30','0') . fInput('submit','submit',ied_plugin_gTxt('create_new'),'smallerbox') . sInput('ied_plugin_create_new') . eInput('ied_plugin_composer') ) ,' colspan="6" style="border:0;height:50px"') .tda(form(fInput('submit', 'submit', ied_plugin_gTxt('setup'), 'publish').sInput('ied_plugin_setup').eInput('ied_plugin_composer')),' colspan="6" style="border:0;height:50px"')). assHead('plugin','author',gTxt('version').' ('.gTxt('plugin_modified').')','description','publish','order','active',''); $rs = safe_rows_start("*","txp_plugin", "1=1 order by name"); while ($a = nextRow($rs)) { extract($a); $ename = ''.$name.''; $hlink = ($help) ? ''.gTxt('help').'' : 'None'; $oLink = ied_plugin_order_form($name, $load_order); $fnames = ied_plugin_get_name($name, $version); $pubtag = tag(gTxt('publish'),'a',' href="?event=ied_plugin_composer&step=ied_plugin_save_as_file&name='.$name.'" title="' . ied_plugin_gTxt('export') .' '.$fnames[0]. '"'); $pubztag = tag(ied_plugin_gTxt('compress'),'a',' href="?event=ied_plugin_composer&step=ied_plugin_save_as_file&name='.$name.'&zip=true" title="' . ied_plugin_gTxt('export') .' '.$fnames[1]. '"'); $modified = (strtolower($code) != (strtolower($code_restore))); $plugpref = (($flags & PLUGIN_HAS_PREFS) && $status) ? ' '.tag( '['.gTxt('plugin_prefs').']' , 'a', ' href="?event=plugin_prefs.'.urlencode($name).'"') : ''; echo tr(td($ename.$plugpref) .td(( ($author_uri) ? ''.$author.'' : $author),160) .td((($modified) ? ''.$version.'' : $version) . (($modified) ? ' ('.gTxt('yes').')' : ''),10) .td($description,260) .td($pubtag .' | '. $pubztag .' | '. $hlink) .td($oLink, 40) .td(ied_status_link($status,$name,yes_no($status)),30) .td(dLink('ied_plugin_composer','ied_plugin_delete','name',$name),30) ); unset($name,$page,$deletelink); } if (!empty($prefs['plugin_cache_dir']) && file_exists($prefs['plugin_cache_dir'])) { $filenames = array(); $dir = dir($prefs['plugin_cache_dir']); while ($file = $dir->read()) { if($file != "." && $file != "..") { $fileaddr = $prefs['plugin_cache_dir'].DS.$file; if (!is_dir($fileaddr)) { $filenames[]=$file; } } } $dir->close(); ($filenames)?natcasesort($filenames):''; echo tr( tda( tag(ied_plugin_gTxt('run_from').' '.tag('plugin_cache_dir','acronym',' title="'.$prefs['plugin_cache_dir'].'" style="border-bottom:1px dashed black"').':','h1') ,' colspan="8" style="border:0;height:50px;text-align:left"') ); echo assHead('plugin','author','version','description','publish','',''); foreach($filenames as $filename) { $fileext= array_pop(explode ('.',$filename)); if ($fileext=='php') { $basename=basename($filename); $plugin = ied_plugin_read_file($prefs['plugin_cache_dir'].DS.$filename); $hlink = ($plugin['help']) ? ''.gTxt('help').'' : 'None'; $efile = ''.$plugin['name'].''; $fnames = ied_plugin_get_name($plugin['name'], $plugin['version']); $plugpref = (($plugin['flags'] & PLUGIN_HAS_PREFS)) ? ' '.tag( '['.gTxt('plugin_prefs').']' , 'a', ' href="?event=plugin_prefs.'.urlencode($plugin['name']).'"') : ''; echo tr( td( tag($filename,'div',' style="color:gray;border:0;padding:1px 2px 2px 1px;"') .(isset($plugin['name'])?$efile.$plugpref.'
':'').' ' ) .td( ( isset($plugin['author_uri'])?'':'' ) . ( isset($plugin['author'])?$plugin['author']:' ' ). ( isset($plugin['author_uri'])?'':'' ), 160 ) .td((isset($plugin['version'])?$plugin['version']:' '),10) .td((isset($plugin['description'])?$plugin['description']:' '),260) .td((isset($plugin['name'])? tag(gTxt('publish'),'a',' href="?event=ied_plugin_composer&step=ied_plugin_save_as_file&filename='.$filename.'" title="' . ied_plugin_gTxt('export') .' '.$fnames[0]. '"') .' | '.tag(ied_plugin_gTxt('compress'),'a',' href="?event=ied_plugin_composer&step=ied_plugin_save_as_file&filename='.$filename.'&zip=true" title="' . ied_plugin_gTxt('export') .' '.$fnames[1]. '"'): tag(' ','span',' style="color:gray"') ).' | '.$hlink) .td('') .td('') ); } } } echo tr( tda( '
'. startTable('edit','left'). tr(tda( hInput('MAX_FILE_SIZE',1000000). graf(ied_plugin_gTxt('upload_php').': '. fInput('file','thefile','','edit'). fInput('submit','submit',gTxt('upload'),'smallerbox')). eInput('ied_plugin_composer'). sInput('ied_plugin_upload') , ' style="border:0px solid gray"' ). tda( tag(ied_plugin_gTxt('name'), 'acronym',' title="'.ied_plugin_gTxt('name_tooltip').'" style="border-bottom:1px dashed black"').': '. fInput('text','name','xxx_xxxxxx','','','','30','0') , ' style="border:0px solid gray;vertical-align:middle;"' )). endTable(). '
' ,' colspan="8" style="border:0;height:50px;text-align:left"') ); echo endTable(); } // ------------------------------------------------------------- function ied_status_link($status,$name,$linktext) { $out = ''; return $out; } // ------------------------------------------------------------- function ied_switch_status() { extract(doSlash(gpsa(array('name','status')))); $change = ($status) ? 0 : 1; safe_update("txp_plugin", "status=$change", "name='$name'"); ied_plugin_list(gTxt('plugin_saved', array('{name}' => $name))); } // ------------------------------------------------------------- function ied_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_list(gTxt('plugin_saved', array('{name}' => $name))); } // ------------------------------------------------------------- function ied_plugin_order_form($name, $load_order) { for ($i = 1; $i <= 9; $i++) $orders[$i] = $i; return form( eInput('ied_plugin_composer').n. sInput('ied_set_order').n. hInput('name', $name).n. selectInput('load_order', $orders, $load_order, 0, 1) ,'display:inline' ); } // ------------------------------------------------------------- function ied_plugin_delete() { $name = doSlash(ps('name')); safe_delete("txp_plugin","name='$name'"); ied_plugin_list(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_list(ied_plugin_gTxt('restored', array('{name}' => $name))); } // ------------------------------------------------------------- function ied_plugin_edit($message='',$newfile='') { $site_dir = hu; $newname = trim(gps('newname')); $name = empty($newname) ? gps('name') : $newname; pagetop(gTxt('edit_plugins'),$message); echo ied_insert_editors(); $theFile = ($newfile) ? $newfile : ((gps('filename')) ? gps('filename') : $name); echo ied_plugin_edit_form($theFile, gps('filename')? 1: 0); } // ------------------------------------------------------------- function ied_plugin_edit_form($name='',$editfile=0) { global $prefs, $ied_plugin_prefs, $ied_plugin_globals; if (!$editfile) { $rs = safe_row("author, author_uri, version, description, code, help, status, type, load_order, flags", "txp_plugin", "name='$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; $fileext = array_pop($name=explode ('.',$name)); $name = implode($name); extract($plugin); $status = ($fileext=='php')? 1: 0; } $edwidth = (isset($prefs['ied_plugin_editor_width']) && is_numeric($prefs['ied_plugin_editor_width'])) ? $prefs['ied_plugin_editor_width'] : $ied_plugin_prefs[0]['ied_plugin_editor_width']; list ($start_css, $end_css) = ied_plugin_make_markers("CSS", $ied_plugin_globals['css_start'], $ied_plugin_globals['css_end']); $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'] ); for ($i = 1; $i <= 9; $i++) $orders[$i] = $i; $distribution=''; $fnames = ied_plugin_get_name($plugin['name'], $plugin['version']); $namedLink = (isset($filename)) ? 'filename='.$filename : 'name='.$name; $slink = '' .ied_plugin_gTxt('export') .' '. $fnames[0]. ''; $sziplink = '' . ied_plugin_gTxt('export') .' '. $fnames[1]. ' (compressed)'; $sphplink = '' . ied_plugin_gTxt('save_as') .' '. $fnames[2]. ''; $vhelplinkfull = ($help) ? '[ '.strong(gTxt('view').' '.gTxt('help')).' ]' : ''; $newname = fInput('text','newname',$name,'edit','','',$edwidth - (int)($edwidth*0.3),'2'); $author = fInput('text','author',$author,'edit','','',$edwidth,'2'); $author_uri = fInput('text','author_uri',$author_uri,'edit','','',$edwidth,'2'); $version = fInput('text','version',$version,'edit','','',$edwidth - (int)($edwidth*0.3),'2') . '  '. (($editfile) ? checkbox('rename_file', '1', 0, '','rename_file') . ' ' : checkbox('restore_point', '1', 0, '','restore_point') . ' '); $description =fInput('text','description',$description,'edit','','',$edwidth,'2'); $code = '
'.ied_plugin_gTxt('jump_to_line').'
'; $help = '
'; $css = '
'; $plugstatus = (!$editfile) ? '  '.checkbox('status',1,$status, '','status'). ' ' : ''; $plugtype = radio('type',0,(($type==0)?1:0)).ied_plugin_gTxt('type_0')." " . radio('type',1,(($type==1)?1:0)).ied_plugin_gTxt('type_1')." " . radio('type',2,(($type==2)?1:0)).ied_plugin_gTxt('type_2')." " . radio('type',3,(($type==3)?1:0)).ied_plugin_gTxt('type_3'); $plugorder = selectInput('load_order', $orders, $load_order, 0, 0); $flaglist = checkbox('flags[]',PLUGIN_HAS_PREFS,(($flags & PLUGIN_HAS_PREFS)?1:0)) . '  ' .checkbox('flags[]',PLUGIN_LIFECYCLE_NOTIFY,(($flags & PLUGIN_LIFECYCLE_NOTIFY)?1:0)) . '  '; // .checkbox('flags[]',0x0004,(($flags & 0x0004)?1:0)) . '  '; $sub = fInput('submit','',gTxt('save'),'publish','','','','', 'ied_editSave'); return form(startTable('edit') . tr( fLabelCell(' ') . td($sub . $vhelplinkfull)) . tr( fLabelCell( 'plugin' ) . td($newname . $plugstatus . ( (isset($filename)) ? tag('  ('.$filename.')','span',' style="color:gray;"').hInput('filename',$filename) : '' ) )) . tr( fLabelCell( ied_plugin_gTxt('plugin_code') ) . td($code)) . tr( fLabelCell( ied_plugin_gTxt('type') ) . td($plugtype)) . tr( fLabelCell( ied_plugin_gTxt('flags') ) . td($flaglist)) . tr( fLabelCell( ied_plugin_gTxt('load_order') ) . td($plugorder.'  '.ied_plugin_gTxt('load_order_help'))) . tr( fLabelCell( 'version' ) . td($version)) . tr( fLabelCell( 'author' ) . td($author)) . tr( fLabelCell( 'website' ) . td($author_uri)) . tr( fLabelCell( 'description' ) . td($description)) . tr( tda(gTxt('plugin_help'), ' class="noline" style="text-align: right; vertical-align: middle;"') . td($help)) . tr( fLabelCell( 'css' ) . td($css)) . tr( fLabelCell(' ') . td($sub)) . tr( tdcs('
',2)) . tr( fLabelCell(' ') . td(ied_plugin_gTxt('utilities').':')) . tr( fLabelCell( ied_plugin_gTxt('code_dist') ) . td($distribution)) . tr( fLabelCell(' ') . td($slink)) . tr( fLabelCell(' ') . td($sziplink)) . tr( fLabelCell(' ') . td($sphplink)) . endTable() . sInput('ied_plugin_save') . eInput('ied_plugin_composer') . hInput('name',$name), '', '', 'post', 'ied_editForm') . << jQuery.fn.resizehandle = function(curh) { return this.each(function() { var me = jQuery(this); me.animate({height: curh}); me.after( jQuery('
--- + ---
').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, 30); }; 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(); } }); }; function ied_goToLine() { var line = parseInt(jQuery('#ied_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; } jQuery(function() { curh = getCookie('ied_plugin_edheight'); curh = (curh == null) ? '480' : curh; jQuery("#plugin_editor").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('.charsRemain').html('Chars remaining: '+ (max - jQuery(this).val().length)); }); jQuery('textarea[maxlength]').keyup(); jQuery('#ied_jumpToLine').keydown(function(e) { var code = (e.keyCode ? e.keyCode : e.which); if(code == 13) { e.preventDefault(); e.stopPropagation(); ied_goToLine(); return false; } }); }); EOF; } // ------------------------------------------------------------- function ied_plugin_save() { global $ied_plugin_globals, $prefs; extract(doSlash(gpsa(array('name','newname','filename','code','author','author_uri','version','description','help','css','status','type','load_order','rename_file','restore_point')))); $flags = gps('flags'); list ($start_css, $end_css) = ied_plugin_make_markers("CSS", $ied_plugin_globals['css_start'], $ied_plugin_globals['css_end']); $extraMsg = $newfilename = $msg1 = $msg2 = ''; $newname = trim($newname); if ($flags) { $flagout = 0; foreach ($flags as $flag) { $flagout |= $flag; } $flags = $flagout; } if (empty($newname)) { $msg1 = ied_plugin_gTxt('name_first'); } else { if (empty($filename)) { $hout = array(); $hout[0] = $help; if ($css) { $hout[1] = n.$start_css.n.$css.n.$end_css; } safe_update( 'txp_plugin', "name='".$newname."', status = ".intval($status).", type = ".intval($type).", author = '".$author."', author_uri = '".$author_uri."', version = '".$version."', description = '".$description."', help = '".join('',$hout)."', code = '".$code."', flags = ".intval($flags).", ".(($restore_point == 1)? "code_restore = '".$code."'," : '')." load_order = ".$load_order, "name = '".$name."'"); $msg1 = gTxt('plugin_saved', array('{name}' => $newname)); } else { $dir = $prefs['plugin_cache_dir'].DS; if (file_exists($dir.$filename)) { $filecontent = file($dir.$filename); } else { if (empty($prefs['plugin_cache_dir'])) { $filecontent = ''; $msg2 = ied_plugin_gTxt('cache_not_set'); } else { $oporder = (isset($prefs['ied_plugin_output_order']) && is_numeric($prefs['ied_plugin_output_order'])) ? $prefs['ied_plugin_output_order'] : 0; $helpchunk = ied_plugin_build_template('help', array($help, ' ')); // Use a space to force a CSS hunk in the file $codechunk = ied_plugin_build_template('code', $code); $filecontent = ied_plugin_build_template("preamble") .ied_plugin_build_template("name", $newname) .ied_plugin_build_template("html_help") .ied_plugin_build_template("version", $version) .ied_plugin_build_template("author", $author) .ied_plugin_build_template("author_uri", $author_uri) .ied_plugin_build_template("description", $description) .ied_plugin_build_template("load_order", $load_order) .ied_plugin_build_template("type", $type) .ied_plugin_build_template("flags", $flags) .ied_plugin_build_template("include") .(($oporder == 0) ? $codechunk : $helpchunk) .(($oporder == 1) ? $codechunk : $helpchunk) .ied_plugin_build_template("postamble"); $msg1 = ied_plugin_gTxt('edit_new'); } } $filecontent = ied_plugin_make_array($filecontent); $metavars = array("name" => "$newname", "version" => "$version", "author" => "$author", "author_uri" => "$author_uri", "description" => "$description", "type" => "$type", "flags" => "$flags", "order" => "$load_order", ); $hunkvars = array("CODE" => doStrip(str_replace('\r\n',' ',$code)), // newline workaround "HELP" => doStrip(str_replace('\r\n',' ',$help)), "CSS" => doStrip(str_replace('\r\n',' ',$css)), ); foreach ($metavars as $varname => $value) { for($idx = 0; $idx < count($filecontent); $idx++) { if (strpos($filecontent[$idx], '$plugin[\''.$varname.'\']') === 0) { $filecontent[$idx] = '$plugin[\''.$varname.'\'] = '.doQuote($value).';'; break; } } } foreach ($hunkvars as $varname => $hunk) { list ($start_delim, $end_delim) = ied_plugin_make_markers($varname, $ied_plugin_globals['dlm_start'], $ied_plugin_globals['dlm_end']); $start = array_search($start_delim, $filecontent) + 1; $end = array_search($end_delim, $filecontent); if (is_numeric($start) && is_numeric($end) && $end >= $start) { array_splice($filecontent, $start, $end-$start, $hunk); } } $filecontent = implode("\n", $filecontent); if ($filecontent) { $fh = fopen($dir.$filename, 'w+'); fwrite($fh, $filecontent); fclose($fh); } $msg1 = (empty($msg1)) ? gTxt('plugin_saved', array('{name}' => $newname)) : $msg1; // Make new file if required if ($rename_file == 1) { $fnames = ied_plugin_get_name($newname, $version); $newfilename = $fnames[2]; $res = rename($dir.$filename, $dir.$newfilename); $extraMsg = ($res) ? ied_plugin_gTxt('renamed') : ied_plugin_gTxt('rename_failed'); } } } if ($msg2) { ied_plugin_list($msg2); } else { // Check the plugin type matches the code used $extraMsg .= (ied_plugin_admin_check($code, $type)) ? '' : strong(ied_plugin_gTxt('check_type')); $message = $msg1.br.$extraMsg; ied_plugin_edit($message, $newfilename); } } // ------------------------------------------------------------- function ied_plugin_create_new() { extract(doSlash(gpsa(array('name')))); $fname = ''; if ($name=='') { ied_plugin_list(ied_plugin_gTxt('name_first')); return; } if (strpos($name, ".php") !== false) { $fname = $name; $name = basename($name, ".php"); } $exists = fetch('name','txp_plugin','name',$name); if (!$exists) { if ($fname) { // Put plugin in cache dir by faking a POST submission and saving $_POST['filename'] = $fname; $_POST['newname'] = $name; $_POST['status'] = 0; $_POST['type'] = 0; $_POST['version'] = '0.1'; $_POST['load_order'] = 5; $_POST['flags'] = 0; ied_plugin_save(); } else { safe_insert("txp_plugin", " name='$name', status=0, type=0, version='0.1', load_order=5, flags=0, description='', help='', code='', code_restore='' "); pagetop(gTxt('edit_plugins'), ied_plugin_gTxt('edit_new')); echo ied_plugin_edit_form($name); } } else { ied_plugin_list(gTxt('plugin').' '.$name.' '.gTxt('already_exists')); } } // ------------------------------------------------------------- function ied_plugin_save_as_file() { global $prefs, $ied_plugin_globals; if (gps('name')) { $name = gps('name'); $rs = safe_row("description, author, author_uri, version, code, help, type, load_order, flags", "txp_plugin", "name='$name'"); extract($rs); list($css,$help) = ($help) ? ied_plugin_extract_hunk($help, "CSS", "", true) : array('',$help); } elseif (gps('filename')) { $plugin=ied_plugin_read_file($prefs['plugin_cache_dir'].DS.gps('filename')); extract($plugin); } $zip = gps('zip'); if (gps('trim')==1) { $code=explode("\r\n",$code); $code=array_map('trim',$code); $code=implode("\r\n",$code); } list ($start_css, $end_css) = ied_plugin_make_markers("CSS", $ied_plugin_globals['css_start'], $ied_plugin_globals['css_end']); $fnames = ied_plugin_get_name($name, $version); header("Content-type: text/plain"); header('Content-Disposition: attachment; filename=' . (($zip) ? $fnames[1] : $fnames[0])); $types = array( 'Client side' , 'Admin/Client side' , 'Library' , 'Admin side'); $plugin['name'] = $name; $plugin['author'] = $author; $plugin['author_uri'] = $author_uri; $plugin['version'] = $version; $plugin['description'] = $description; $plugin['code'] = $code; $plugin['type'] = $type; $plugin['order'] = $load_order; $plugin['flags'] = $flags; // $plugin['allow_html_help'] = true; // $plugin['help_raw'] = $help.$start_css.$css.$end_css; $plugin['help'] = ied_plugin_textile($name, $help, $css, $start_css, $end_css); $plugin['md5'] = md5( $plugin['code'] ); echo '# Name: '.$name.' v'.$version.' '.(($zip) ? "(compressed)" : "").' # Type: '.$types[$type].' plugin # '.$description.' # Author: '.$author.' # URL: '.$author_uri.' # Recommended load order: '.$load_order.' # ..................................................................... # This is a plugin for Textpattern - http://textpattern.com/ # To install: textpattern > admin > plugins # Paste the following text into the \'Install plugin\' box: # ..................................................................... '.(($zip) ? chunk_split(base64_encode(gzencode(serialize($plugin))), 72) : chunk_split(base64_encode(serialize($plugin)), 72)); die(); } // ------------------------------------------------------------- function ied_plugin_save_as_php_file() { global $prefs; if (gps('name')) { $name = gps('name'); $rs = safe_row("description, author, author_uri, version, code, help, type, load_order, flags", "txp_plugin", "name='$name'"); extract($rs); list($css,$help) = ($help) ? ied_plugin_extract_hunk($help, "CSS", "", true) : array('',$help); } elseif (gps('filename')) { $plugin=ied_plugin_read_file($prefs['plugin_cache_dir'].DS.gps('filename')); extract($plugin); } $oporder = (isset($prefs['ied_plugin_output_order']) && is_numeric($prefs['ied_plugin_output_order'])) ? $prefs['ied_plugin_output_order'] : 0; $fnames = ied_plugin_get_name($name, $version); header("Content-type: text/php"); header('Content-Disposition: attachment; filename=' .$fnames[2]); $helpchunk = ied_plugin_build_template('help', array($help, $css)); $codechunk = ied_plugin_build_template('code', str_replace("\r\n","\n",$code)); echo ied_plugin_build_template("preamble"); echo ied_plugin_build_template("name", $name); echo ied_plugin_build_template("html_help"); echo ied_plugin_build_template("version", $version); echo ied_plugin_build_template("author", $author); echo ied_plugin_build_template("author_uri", $author_uri); echo ied_plugin_build_template("description", $description); echo ied_plugin_build_template("load_order", $load_order); echo ied_plugin_build_template("type", $type); echo ied_plugin_build_template("flags", $flags); echo ied_plugin_build_template("include"); echo (($oporder == 0) ? $codechunk : $helpchunk); echo (($oporder == 1) ? $codechunk : $helpchunk); echo ied_plugin_build_template("postamble"); die(); } // ------------------------------------------------------------- function ied_plugin_build_template($prt, $val='') { $css = $help = ''; if (is_array($val)) { $help = $val[0]; $css = isset($val[1]) ? $val[1] : ''; $val = ''; } $template = array( "preamble" => ' abc_myplugin-0.1.txt'.n.n, "name" => '// Plugin name is optional. If unset, it will be extracted from the current'.n .'// file name. Plugin names should start with a three letter prefix which is'.n .'// unique and reserved for each plugin author ("abc" is just an example).'.n .'// Uncomment and edit this line to override:'.n .'$plugin[\'name\'] = '.doQuote($val).';'.n.n, "html_help" => '// Allow raw HTML help, as opposed to Textile.'.n .'// 0 = Plugin help is in Textile format, no raw HTML allowed (default).'.n .'// 1 = Plugin help is in raw HTML. Not recommended.'.n .'# $plugin[\'allow_html_help\'] = 1;'.n.n, "version" => '$plugin[\'version\'] = '.doQuote($val).';'.n, "flags" => '// Plugin "flags" signal the presence of optional capabilities to the core plugin loader.'.n .'// Use an appropriately OR-ed combination of these flags.'.n .'// The four high-order bits 0xf000 are available for this plugin\'s private use'.n .'if (!defined(\'PLUGIN_HAS_PREFS\')) define(\'PLUGIN_HAS_PREFS\', 0x0001); // This plugin wants to receive "plugin_prefs.{$plugin[\'name\']}" events'.n .'if (!defined(\'PLUGIN_LIFECYCLE_NOTIFY\')) define(\'PLUGIN_LIFECYCLE_NOTIFY\', 0x0002); // This plugin wants to receive "plugin_lifecycle.{$plugin[\'name\']}" events'.n.n .'$plugin[\'flags\'] = '.doQuote($val).';'.n.n, "author" => '$plugin[\'author\'] = '.doQuote($val).';'.n, "author_uri" => '$plugin[\'author_uri\'] = '.doQuote($val).';'.n, "description" => '$plugin[\'description\'] = '.doQuote($val).';'.n.n, "load_order" => '// Plugin load order:'.n .'// The default value of 5 would fit most plugins, while for instance comment'.n .'// spam evaluators or URL redirectors would probably want to run earlier'.n .'// (1...4) to prepare the environment for everything else that follows.'.n .'// Values 6...9 should be considered for plugins which would work late.'.n .'// This order is user-overrideable.'.n .'$plugin[\'order\'] = '.doQuote($val).';'.n.n, "type" => '// Plugin \'type\' defines where the plugin is loaded'.n .'// 0 = public : only on the public side of the website (default)'.n .'// 1 = public+admin : on both the public and admin side'.n .'// 2 = library : only when include_plugin() or require_plugin() is called'.n .'// 3 = admin : only on the admin side'.n .'$plugin[\'type\'] = '.doQuote($val).';'.n.n, "include" => 'if (!defined(\'txpinterface\'))'.n .' @include_once(\'zem_tpl.php\');'.n.n, "help" => 'if (0) {'.n .'?>'.n . (($css) ? ''.n : '') .''.n .' '# --- BEGIN PLUGIN CODE ---'.n .$val.n .'# --- END PLUGIN CODE ---'.n, "postamble" => '?>', ); return (array_key_exists($prt, $template) ? $template[$prt] : ''); } // ------------------------------------------------------------- function ied_plugin_upload() { global $ied_plugin_globals; list ($start_css, $end_css) = ied_plugin_make_markers("CSS", $ied_plugin_globals['css_start'], $ied_plugin_globals['css_end']); if (!$_FILES['thefile']['tmp_name']) { ied_plugin_list(ied_plugin_gTxt('choose_file'));return; } $plugin = ied_plugin_read_file($_FILES['thefile']['tmp_name']); // $newname = (empty($plugin['name'])) ? basename($_FILES['thefile']['name'], '.php') : $plugin['name']; $newname = $plugin['name']; if (gps('name') and gps('name')!='xxx_xxxxxx') { $newname=gps('name'); } if (empty($plugin['code'])) { $plugin['code'] = implode ("", file($_FILES['thefile']['tmp_name'])); } if (MAGIC_QUOTES_GPC) { $plugin = doStrip($plugin); } extract(doSlash($plugin)); $md5=md5($code); $version = (empty($version)) ? "0.1" : $version; $help = $help.(($css) ? n.$start_css.n.$css.n.$end_css : ''); $exists = fetch('name','txp_plugin','name',$newname); if ($exists) { $status = fetch('status','txp_plugin','name',$newname); $rs = safe_update( "txp_plugin", "status = ".intval($status).", type = ".intval($type).", author = '$author', author_uri = '$author_uri', version = '$version', description = '$description', help = '$help', code = '$code', code_restore = '$code', code_md5 = '$md5', flags = ".intval($flags).", load_order = ".intval($load_order), "name = '$newname'" ); } else { $rs = safe_insert( "txp_plugin", "name = '$newname', status = 0, type = ".intval($type).", author = '$author', author_uri = '$author_uri', version = '$version', description = '$description', help = '$help', code = '$code', code_restore = '$code', code_md5 = '$md5', flags = ".intval($flags).", load_order = ".intval($load_order) ); } pagetop(gTxt('edit_plugins'), messenger('plugin',$newname,($exists)?'updated':'uploaded')); echo ied_plugin_edit_form($newname); } // ------------------------------------------------------------- function ied_plugin_read_file($filepath) { $content = file($filepath); $justfile = basename($filepath); $ext = array_pop(explode ('.',$justfile)); $ext = ($ext==$justfile) ? '' : '.'.$ext; // Only assign an extension if one exists $source_lines = count($content); $metadata = array( 'name' => '', 'version' => '', 'revision' => '', 'author' => '', 'author_uri' => '', 'description' => '', 'order' => '5', 'type' => '', 'flags' => '', ); for ($idx=0; $idx < $source_lines; $idx++) { $content[$idx] = rtrim($content[$idx]); // Bomb out if we reach the end of the definition area if (strpos( $content[$idx], 'if (!defined' ) === 0) { break; } if (strpos($content[$idx], '$plugin[') === 0) { // Found a plugin variable so extract it $parts = explode(" = ", $content[$idx]); $parts[0] = str_replace("'", "", $parts[0]); // Make the match easier! $parts[1] = str_replace(";", "", $parts[1]); // Ditto preg_match("/plugin\[(.*)\]/", $parts[0], $var); // Extract just the variable name if (is_numeric($parts[1])) { $parts[1] = "'".$parts[1]."'"; } preg_match("/.*'(.*)'.*/", $parts[1], $val); // Remove anything outside the quotes (e.g. $revision) if ($var[1] == 'revision' && !empty($val[1])) { $revparts = explode(' ', trim($val[1], '$ ')); $val[1] = $revparts[count($revparts)-1]; $val[1] = (empty($val[1])) ? '' : '.' .$val[1]; } $metadata[$var[1]] = $val[1]; } } $metadata['name'] = (empty($metadata['name'])) ? basename($justfile, $ext) : $metadata['name']; $metadata['load_order'] = $metadata['order']; $metadata['version'] .= $metadata['revision']; $metadata['help'] = ied_plugin_extract_hunk($content, 'HELP'); $metadata['css'] = ied_plugin_extract_hunk($content, 'CSS' ); $metadata['code'] = ied_plugin_extract_hunk($content, 'CODE'); return $metadata; } // ------------------------------------------------------------- // ripped and modded from net-carver's zem_tpl template function ied_plugin_extract_hunk($content, $hunk, $cmnt="#", $delete=false) { $dlm = explode("|", $cmnt); $dlmStart = $dlm[0]; $dlmEnd = (count($dlm) > 1) ? $dlm[1] : ''; $lines = ied_plugin_make_array($content); list ($start_delim, $end_delim) = ied_plugin_make_markers($hunk, $dlmStart, $dlmEnd); $start = array_search($start_delim, $lines) + 1; $end = array_search($end_delim, $lines); // Kludge to get round the delimiter change in v0.83 if ($hunk == 'CSS' && $end === false) { $start_delim = str_replace('---', '***', $start_delim); $end_delim = str_replace('---', '***', $end_delim); $start = array_search($start_delim, $lines) + 1; $end = array_search($end_delim, $lines); } $extracted = array(); if (count($lines) > 0 && is_numeric($start) && is_numeric($end) && $end > $start) { $extracted = array_slice($lines, $start, $end-$start); $lineNum = count($extracted)-1; while ($lineNum > 0 && trim($extracted[$lineNum--]) == "") { array_pop($extracted); } while (count($extracted) > 0 && trim($extracted[0]) == "") { array_shift($extracted); } if ($delete) { $chopped = array_splice($lines, $start-1, $end-$start+2, ""); } } $remains = $lines; // Check if the CSS section has ') === false) { $extracted[] = ''; } if (strpos($extracted[0], '