if(@txpinterface == 'admin') {
add_privs('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');
global $ied_plugin_composer, $ied_plugin_prefs, $ied_plugin_globals;
$ied_plugin_globals = array(
'css_start' => '',
'dlm_start' => '#',
'dlm_end' => '',
'start' => ' --- BEGIN PLUGIN SECTION ---',
'end' => ' --- END PLUGIN SECTION ---',
);
// 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',
),
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();
}
// -------------------------------------------------------------
// 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] = smd_sanitizeForFile($fname);
}
return $out;
}
// -------------------------------------------------------------
function ied_plugin_list($message='') {
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)));
echo tr(td($ename)
.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($GLOBALS['prefs']['plugin_cache_dir'])) {
$filenames = array();
$dir = dir($GLOBALS['prefs']['plugin_cache_dir']);
while ($file = $dir->read()) {
if($file != "." && $file != "..") {
$fileaddr = $GLOBALS['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="'.$GLOBALS['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($GLOBALS['prefs']['plugin_cache_dir'].DS.$filename);
$hlink = ($plugin['help']) ? ''.gTxt('help').'' : 'None';
$efile = ''.$plugin['name'].'';
$fnames = ied_plugin_get_name($plugin['name'], $plugin['version']);
echo tr(
td(
tag($filename,'div',' style="color:gray;border:0;padding:1px 2px 2px 1px;"')
.(isset($plugin['name'])?$efile.'
':'').' '
)
.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(
'
'
,' 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", "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($GLOBALS['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($help, $css, $start_css, $end_css);
$plugin['code'] = $code;
$plugin['type'] = $type;
$plugin['order'] = $load_order;
$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;
// $namedFile = (isset($filename)) ? $filename : $fnames[2];
// $namedFileNoExt = preg_replace('/(.+)\..*$/', '$1', $namedFile);
$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 = '';
$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);
$sub = fInput('submit','',gTxt('save'),'publish');
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('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)) . <<
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(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();
});
EOF;
}
// -------------------------------------------------------------
function ied_plugin_save() {
global $ied_plugin_globals;
extract(doSlash(gpsa(array('name','newname','filename','code','author','author_uri','version','description','help','css','status','type','load_order','rename_file','restore_point'))));
list ($start_css, $end_css) = ied_plugin_make_markers("CSS", $ied_plugin_globals['css_start'], $ied_plugin_globals['css_end']);
$extraMsg = $newfilename = '';
$newname = trim($newname);
if (empty($newname)) {
$msg1 = ied_plugin_gTxt('name_first');
} else {
if (empty($filename)) {
$help = $help.(($css) ? n.$start_css.n.$css.n.$end_css : '');
safe_update(
"txp_plugin",
"name='$newname',
status = '$status',
type = '$type',
author = '$author',
author_uri = '$author_uri',
version = '$version',
description = '$description',
help = '$help',
code = '$code',
".(($restore_point == 1)? "code_restore = '$code'," : '')."
load_order = '$load_order'",
"name = '$name'");
$msg1 = gTxt('plugin_saved', array('{name}' => $newname));
} else {
$dir = $GLOBALS['prefs']['plugin_cache_dir'].DS;
$filecontent = file($dir.$filename);
$filecontent = ied_plugin_make_array($filecontent);
$metavars = array("name" => "$newname",
"version" => "$version",
"author" => "$author",
"author_uri" => "$author_uri",
"description" => "$description",
"type" => "$type",
"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);
$fh = fopen($dir.$filename, 'w+');
fwrite($fh, $filecontent);
fclose($fh);
// 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');
}
$msg1 = gTxt('plugin_saved', array('{name}' => $newname));
}
}
// 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'))));
if ($name=='') {
ied_plugin_list(ied_plugin_gTxt('name_first'));
return;
}
$exists = fetch('name','txp_plugin','name',$name);
if (!$exists) {
safe_insert("txp_plugin", "
name='$name',
status='0',
type='0',
version='0.1',
load_order='5'
");
pagetop(gTxt('edit_plugins'), 'edit your new plugin');
echo ied_plugin_edit_form($name);
} else {
ied_plugin_list(gTxt('plugin').' '.$name.' '.gTxt('already_exists'));
}
}
// -------------------------------------------------------------
function ied_plugin_save_as_file() {
global $ied_plugin_globals;
if (gps('name')) {
$name = gps('name');
$rs = safe_row("description, author, author_uri, version, code, help, type, load_order", "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($GLOBALS['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['allow_html_help'] = true;
// $plugin['help_raw'] = $help.$start_css.$css.$end_css;
$plugin['help'] = ied_plugin_textile($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", "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($GLOBALS['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 = 'if (0) {'.n
.'?>'.n
. (($css) ? ''.n : '')
.''.n
.' abc_myplugin-0.1.txt'.n
.n
.'// Plugin name is optional. If unset, it will be extracted from the current'.n
.'// file name. Uncomment and edit this line to override:'.n
.'$plugin[\'name\'] = '.doQuote($name).';'.n
.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
.'$plugin[\'version\'] = '.doQuote($version).';'.n
.'$plugin[\'author\'] = '.doQuote($author).';'.n
.'$plugin[\'author_uri\'] = '.doQuote($author_uri).';'.n
.'$plugin[\'description\'] = '.doQuote($description).';'.n
.n
.'// Plugin load order:'.n
.'// The default value of 5 would fit most plugins, while for instance comment spam evaluators or URL redirectors'.n
.'// would probably want to run earlier (1...4) to prepare the environment for everything else that follows.'.n
.'// Orders 6...9 should be considered for plugins which would work late. This order is user-overrideable.'.n
.'$plugin[\'order\'] = '.doQuote($load_order).';'.n
.n
.'// 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($type).';'.n
.n
.'if (!defined(\'txpinterface\'))'.n
.' @include_once(\'zem_tpl.php\');'.n
.n
.(($oporder == 0) ? $codechunk : $helpchunk)
.(($oporder == 1) ? $codechunk : $helpchunk)
.'?>';
die();
}
// -------------------------------------------------------------
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 = '$status',
type = '$type',
author = '$author',
author_uri = '$author_uri',
version = '$version',
description = '$description',
help = '$help',
code = '$code',
code_restore = '$code',
code_md5 = '$md5',
load_order = '$load_order'",
"name = '$newname'"
);
} else {
$rs = safe_insert(
"txp_plugin",
"name = '$newname',
status = 0,
type = '$type',
author = '$author',
author_uri = '$author_uri',
version = '$version',
description = '$description',
help = '$help',
code = '$code',
code_restore = '$code',
code_md5 = '$md5',
load_order = '$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' => '',
);
for ($idx=0; $idx < $source_lines; $idx++) {
$content[$idx] = rtrim($content[$idx]);
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);
$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], '