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',
),
array(
'ied_plugin_not_used_any_more_tester' => '',
)
);
}
// -------------------------------------------------------------
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_save_file',
'ied_plugin_verify',
'ied_switch_status',
'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_list($message='') {
pagetop(gTxt('edit_plugins'),$message);
echo startTable('list').
tr(tda(
form(
fInput('text','name','','','','','30','0')
. fInput('submit','submit',ied_plugin_gTxt('ied_plugin_create_new'),'smallerbox')
. sInput('ied_plugin_create_new')
. eInput('ied_plugin_composer')
)
,' colspan="6" style="border:0;height:50px"')
.tda(form(fInput('submit', 'submit', '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','manage','publish', 'active','');
$rs = safe_rows_start("*","txp_plugin", "1=1 order by name");
while ($a = nextRow($rs)) {
extract($a);
$elink = ''.gTxt('edit').'';
$hlink = ($help) ? ''.gTxt('help').'' : 'None';
$pubtag = tag(gTxt('publish'),'a',' href="?event=ied_plugin_composer&step=ied_plugin_save_as_file&name='.$name.'" title="' . ied_plugin_gTxt('ied_plugin_export') .' '. $name.'_v'.$version. '.txt"');
$pubztag = tag(ied_plugin_gTxt('ied_plugin_compress'),'a',' href="?event=ied_plugin_composer&step=ied_plugin_save_as_file&name='.$name.'&zip=true" title="' . ied_plugin_gTxt('ied_plugin_export') .' '. $name.'_v'.$version. '_zip.txt"');
$modified = (strtolower($code) != (strtolower($code_restore)));
echo tr(td($name)
.td(''.$author.'',160)
.td($version . (($modified) ? ' ('.gTxt('yes').')' : ''),10)
.td($description,260)
.td($elink .' | '. $hlink)
.td($pubtag .' | '. $pubztag)
.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('ied_plugin_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','manage','publish','','');
foreach($filenames as $filename) {
$elink = ''.gTxt('edit').'';
$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';
echo tr(
td(
tag($filename,'div',' style="color:gray;border:0px solid gray;padding:1px 2px 2px 1px;"')
.(isset($plugin['name'])?$plugin['name'].'
':'').' '
)
.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($elink .' | '. $hlink)
.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('ied_plugin_export') .' '. $plugin['name'].'_v'.$plugin['version']. '.txt"')
.' | '.tag(ied_plugin_gTxt('ied_plugin_compress'),'a',' href="?event=ied_plugin_composer&step=ied_plugin_save_as_file&filename='.$filename.'&zip=true" title="' . ied_plugin_gTxt('ied_plugin_export') .' '. $plugin['name'].'_v'.$plugin['version']. '_zip.txt"'):
tag(' ','span',' style="color:gray"')
))
.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(messenger('plugin',$name,'updated'));
}
// -------------------------------------------------------------
function ied_plugin_delete() {
$name = doSlash(ps('name'));
safe_delete("txp_plugin","name='$name'");
ied_plugin_list(messenger('plugin',$name,'deleted'));
}
// -------------------------------------------------------------
function ied_plugin_edit($message='',$newfile='') {
$site_dir = hu;
$name = gps('newname')?gps('newname'):gps('name');
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;
if (!$editfile) {
$author = ($name) ? fetch('author','txp_plugin','name',$name) : '';
$author_uri = ($name) ? fetch('author_uri','txp_plugin','name',$name) : '';
$version = ($name) ? fetch('version','txp_plugin','name',$name) : '';
$description = ($name) ? fetch('description','txp_plugin','name',$name) : '';
$code = ($name) ? fetch('code','txp_plugin','name',$name) : '';
$help = ($name) ? fetch('help','txp_plugin','name',$name) : '';
$status = ($name) ? fetch('status','txp_plugin','name',$name) : '';
$type = ($name) ? fetch('type','txp_plugin','name',$name) : '';
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); // code, help, css, name, version, type, description, author, author_uri
$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'];
$plugin['name'] = $name;
$plugin['author'] = $author;
$plugin['author_uri'] = $author_uri;
$plugin['version'] = $version;
$plugin['description'] = $description;
$plugin['help'] = $help;
$plugin['code'] = $code;
$plugin['type'] = $type;
$plugin['md5'] = md5( $plugin['code'] );
$distribution='';
$namedLink = (isset($filename)) ? 'filename='.$filename : 'name='.$name;
$namedFile = (isset($filename)) ? $filename : $name.'_v'.$version.'.php';
$namedFileNoExt = preg_replace('/(.+)\..*$/', '$1', $namedFile);
$slink = '' .ied_plugin_gTxt('ied_plugin_export') .' '. $namedFileNoExt. '.txt';
$sziplink = '' . ied_plugin_gTxt('ied_plugin_export') .' '. $namedFileNoExt. '.txt (compressed)';
$sphplink = '' . ied_plugin_gTxt('ied_plugin_save_as') .' '. $namedFile. '';
$vhelplinkfull = ($help) ? '[ '.strong(gTxt('view').' '.gTxt('help')).' ]' : '';
$newname =fInput('text','newname',$name,'edit','','',$edwidth,'2');
$author =fInput('text','author',$author,'edit','','',$edwidth,'2');
$author_uri =fInput('text','author_uri',$author_uri,'edit','','',$edwidth,'2');
$version =($editfile) ? fInput('text','version',$version,'edit','','',$edwidth - (int)($edwidth*0.3),'2') . ' ' . checkbox('rename_file', '1', 0, '','rename_file') : fInput('text','version',$version,'edit','','',$edwidth,'2');
$description =fInput('text','description',$description,'edit','','',$edwidth,'2');
$code = '';
$help = '';
$css = '';
$prefs = ((!$editfile)?checkbox('status',1,$status). ' ':'') . ' '. radio('type',0,(($type==0)?1:0)).ied_plugin_gTxt('ied_plugin_type_0')." " . radio('type',1,(($type==1)?1:0)).ied_plugin_gTxt('ied_plugin_type_1')." " . radio('type',2,(($type==2)?1:0)).ied_plugin_gTxt('ied_plugin_type_2');
$sub = fInput('submit','',gTxt('save'),'publish');
return form(startTable('edit')
. tr( fLabelCell(' ') . td($sub . $vhelplinkfull))
. ( (isset($filename))? tr( fLabelCell(' ') . td($filename.hInput('filename',$filename))) : '' )
. tr( fLabelCell( 'plugin' ) . td($newname))
. tr( fLabelCell( 'plugin' ) . td($code))
. tr( fLabelCell( 'prefs' ) . td($prefs))
. 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('ied_plugin_utilities').':'))
. tr( fLabelCell( ied_plugin_gTxt('ied_plugin_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);
})
);
});
}
function setCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
} else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
\$(function() {
curh = getCookie('ied_plugin_edheight');
curh = (curh == null) ? '480' : curh;
\$("#plugin_editor").resizehandle(parseInt(curh));
});
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','rename_file'))));
list ($start_css, $end_css) = ied_plugin_make_markers("CSS", $ied_plugin_globals['css_start'], $ied_plugin_globals['css_end']);
$extraMsg = $newfilename = '';
if (empty($filename)) {
safe_update("txp_plugin","name='$newname'", "name='$name'");
safe_update("txp_plugin","code='$code'", "name='$newname'");
safe_update("txp_plugin","author='$author'", "name='$newname'");
safe_update("txp_plugin","author_uri='$author_uri'", "name='$newname'");
safe_update("txp_plugin","version='$version'", "name='$newname'");
safe_update("txp_plugin","description='$description'", "name='$newname'");
safe_update("txp_plugin","help='".$help.(($css) ? n.$start_css.n.$css.n.$end_css:'')."'", "name='$newname'");
safe_update("txp_plugin","status='$status'", "name='$newname'");
safe_update("txp_plugin","type='$type'", "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"
);
$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) {
$newfilename = $newname.'_v'.$version.'.php';
$res = rename($dir.$filename, $dir.$newfilename);
$extraMsg = ($res) ? ied_plugin_gTxt('ied_plugin_renamed') : ied_plugin_gTxt('ied_plugin_rename_failed');
}
}
// Check the plugin type matches the code used
$extraMsg .= (ied_plugin_admin_check($code, $type)) ? '' : strong(ied_plugin_gTxt('ied_plugin_check_type'));
$message = messenger('plugin',$newname,'saved').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('ied_plugin_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'
");
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');
$description = ($name) ? fetch('description','txp_plugin','name',$name) : '';
$author = ($name) ? fetch('author','txp_plugin','name',$name) : '';
$author_uri = ($name) ? fetch('author_uri','txp_plugin','name',$name) : '';
$version = ($name) ? fetch('version','txp_plugin','name',$name) : '';
$code = ($name) ? fetch('code','txp_plugin','name',$name) : '';
$help = ($name) ? fetch('help','txp_plugin','name',$name) : '';
$type = ($name) ? fetch('type','txp_plugin','name',$name) : '';
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']);
header("Content-type: text/plain");
header('Content-Disposition: attachment; filename="' . $name.'_v'.$version. (($zip)?'_zip':'') . '.txt');
$types = array( 'Client side' , 'Admin/Client side' , 'Library' );
$plugin['name'] = $name;
$plugin['author'] = $author;
$plugin['author_uri'] = $author_uri;
$plugin['version'] = $version;
$plugin['description'] = $description;
$plugin['code'] = $code;
$plugin['type'] = $type;
// $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.'
# .....................................................................
# 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');
$description = ($name) ? fetch('description','txp_plugin','name',$name) : '';
$author = ($name) ? fetch('author','txp_plugin','name',$name) : '';
$author_uri = ($name) ? fetch('author_uri','txp_plugin','name',$name) : '';
$version = ($name) ? fetch('version','txp_plugin','name',$name) : '';
$code = ($name) ? fetch('code','txp_plugin','name',$name) : '';
$help = ($name) ? fetch('help','txp_plugin','name',$name) : '';
$type = ($name) ? fetch('type','txp_plugin','name',$name) : '';
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);
}
$order = (isset($prefs['ied_plugin_output_order']) && is_numeric($prefs['ied_plugin_output_order'])) ? $prefs['ied_plugin_output_order'] : 0;
header("Content-type: text/php");
header('Content-Disposition: attachment; filename="' . $name.'_v'.$version. '.php');
$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
.'$plugin[\'version\'] = '.doQuote($version).';'.n
.'$plugin[\'author\'] = '.doQuote($author).';'.n
.'$plugin[\'author_uri\'] = '.doQuote($author_uri).';'.n
.'$plugin[\'description\'] = '.doQuote($description).';'.n
.n
.'// Plugin types:'.n
.'// 0 = regular plugin; loaded on the public web side only'.n
.'// 1 = admin plugin; loaded on both the public and admin side'.n
.'// 2 = library; loaded only when include_plugin() or require_plugin() is called'.n
.'$plugin[\'type\'] = '.doQuote($type).';'.n
.n
.'@include_once(\'zem_tpl.php\');'.n
.n
.(($order == 0) ? $codechunk : $helpchunk)
.(($order == 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('You are supposed to choose the file ;)');return;
}
$plugin = ied_plugin_read_file($_FILES['thefile']['tmp_name']);
$newname = (empty($plugin['name'])) ? basename($_FILES['thefile']['name'], '.php') : $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'",
"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'"
);
}
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);
$source_lines = count($content);
$metadata = array(
'name' => '',
'version' => '',
'revision' => '',
'author' => '',
'author_uri' => '',
'description' => '',
'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!
preg_match("/plugin\[(.*)\]/", $parts[0], $var); // Extract just the variable name
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['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], '