mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-03-28 17:42:57 +01:00
Plugins:
- display author and and author url (if present) on plugin admin page - uniformized versions/authors... for all plugins in svn - security fix (html escape name, version, uri, author... to avoid javascript injection which could automatically simulate click on Install) - added confirmation for install/uninstall plugins Web services: - web service explorer now caches method details in order to avoid unnecessary web calls - web service explorer can now send parameters as arrays - web service explorer uses now prototype.js version 1.5 - small improvements - added and use function bad_request (sends http status code 400) git-svn-id: http://piwigo.org/svn/trunk@1852 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
@@ -41,25 +41,41 @@ function get_fs_plugins()
|
||||
and file_exists($path.'/main.inc.php')
|
||||
)
|
||||
{
|
||||
$plugin = array('name'=>$file, 'version'=>'0', 'uri'=>'', 'description'=>'');
|
||||
$plugin = array(
|
||||
'name'=>$file,
|
||||
'version'=>'0',
|
||||
'uri'=>'',
|
||||
'description'=>'',
|
||||
'author'=>'',
|
||||
);
|
||||
$plg_data = implode( '', file($path.'/main.inc.php') );
|
||||
|
||||
if ( preg_match("|Plugin Name: (.*)|i", $plg_data, $val) )
|
||||
if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) )
|
||||
{
|
||||
$plugin['name'] = trim( $val[1] );
|
||||
}
|
||||
if (preg_match("|Version: (.*)|i", $plg_data, $val))
|
||||
if (preg_match("|Version: (.*)|", $plg_data, $val))
|
||||
{
|
||||
$plugin['version'] = trim($val[1]);
|
||||
}
|
||||
if ( preg_match("|Plugin URI: (.*)|i", $plg_data, $val) )
|
||||
if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) )
|
||||
{
|
||||
$plugin['uri'] = $val[1];
|
||||
$plugin['uri'] = trim($val[1]);
|
||||
}
|
||||
if ( preg_match("|Description: (.*)|i", $plg_data, $val) )
|
||||
if ( preg_match("|Description: (.*)|", $plg_data, $val) )
|
||||
{
|
||||
$plugin['description'] = trim($val[1]);
|
||||
}
|
||||
if ( preg_match("|Author: (.*)|", $plg_data, $val) )
|
||||
{
|
||||
$plugin['author'] = trim($val[1]);
|
||||
}
|
||||
if ( preg_match("|Author URI: (.*)|", $plg_data, $val) )
|
||||
{
|
||||
$plugin['author uri'] = trim($val[1]);
|
||||
}
|
||||
// IMPORTANT SECURITY !
|
||||
$plugin = array_map('htmlspecialchars', $plugin);
|
||||
$plugins[$file] = $plugin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// | PhpWebGallery - a PHP based picture gallery |
|
||||
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | branch : BSF (Best So Far)
|
||||
// | file : $Id$
|
||||
// | last update : $Date$
|
||||
// | last modifier : $Author$
|
||||
@@ -38,9 +37,9 @@ $my_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugins';
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | perform requested actions |
|
||||
// +-----------------------------------------------------------------------+
|
||||
if ( isset($_REQUEST['action']) and isset($_REQUEST['plugin']) )
|
||||
if ( isset($_GET['action']) and isset($_GET['plugin']) )
|
||||
{
|
||||
$plugin_id = $_REQUEST['plugin'];
|
||||
$plugin_id = $_GET['plugin'];
|
||||
$crt_db_plugin = get_db_plugins('', $plugin_id);
|
||||
if (!empty($crt_db_plugin))
|
||||
{
|
||||
@@ -54,7 +53,7 @@ if ( isset($_REQUEST['action']) and isset($_REQUEST['plugin']) )
|
||||
$errors = array();
|
||||
$file_to_include = PHPWG_PLUGINS_PATH.$plugin_id.'/maintain.inc.php';
|
||||
|
||||
switch ( $_REQUEST['action'] )
|
||||
switch ( $_GET['action'] )
|
||||
{
|
||||
case 'install':
|
||||
if ( !empty($crt_db_plugin))
|
||||
@@ -89,7 +88,7 @@ INSERT INTO '.PLUGINS_TABLE.' (id,version) VALUES ("'
|
||||
case 'activate':
|
||||
if ( !isset($crt_db_plugin) )
|
||||
{
|
||||
array_push($errors, 'CANNOT '. $_REQUEST['action'] .' - NOT INSTALLED');
|
||||
array_push($errors, 'CANNOT '. $_GET['action'] .' - NOT INSTALLED');
|
||||
}
|
||||
if ($crt_db_plugin['state']!='inactive')
|
||||
{
|
||||
@@ -114,7 +113,7 @@ UPDATE '.PLUGINS_TABLE.' SET state="active" WHERE id="'.$plugin_id.'"';
|
||||
case 'deactivate':
|
||||
if ( !isset($crt_db_plugin) )
|
||||
{
|
||||
die ('CANNOT '. $_REQUEST['action'] .' - NOT INSTALLED');
|
||||
die ('CANNOT '. $_GET['action'] .' - NOT INSTALLED');
|
||||
}
|
||||
if ($crt_db_plugin['state']!='active')
|
||||
{
|
||||
@@ -134,7 +133,7 @@ UPDATE '.PLUGINS_TABLE.' SET state="inactive" WHERE id="'.$plugin_id.'"';
|
||||
case 'uninstall':
|
||||
if ( !isset($crt_db_plugin) )
|
||||
{
|
||||
die ('CANNOT '. $_REQUEST['action'] .' - NOT INSTALLED');
|
||||
die ('CANNOT '. $_GET['action'] .' - NOT INSTALLED');
|
||||
}
|
||||
$query = '
|
||||
DELETE FROM '.PLUGINS_TABLE.' WHERE id="'.$plugin_id.'"';
|
||||
@@ -181,11 +180,25 @@ foreach( $fs_plugins as $plugin_id => $fs_plugin )
|
||||
{
|
||||
$display_name='<a href="'.$fs_plugin['uri'].'">'.$display_name.'</a>';
|
||||
}
|
||||
$desc = $fs_plugin['description'];
|
||||
if (!empty($fs_plugin['author']))
|
||||
{
|
||||
$desc.= ' (<em>';
|
||||
if (!empty($fs_plugin['author uri']))
|
||||
{
|
||||
$desc.= '<a href="'.$fs_plugin['author uri'].'">'.$fs_plugin['author'].'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$desc.= $fs_plugin['author'];
|
||||
}
|
||||
$desc.= '</em>)';
|
||||
}
|
||||
$template->assign_block_vars( 'plugins.plugin',
|
||||
array(
|
||||
'NAME' => $display_name,
|
||||
'VERSION' => $fs_plugin['version'],
|
||||
'DESCRIPTION' => $fs_plugin['description'],
|
||||
'DESCRIPTION' => $desc,
|
||||
'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1',
|
||||
)
|
||||
);
|
||||
@@ -218,6 +231,7 @@ foreach( $fs_plugins as $plugin_id => $fs_plugin )
|
||||
'L_ACTION' => l10n('Uninstall'),
|
||||
)
|
||||
);
|
||||
$template->assign_block_vars( 'plugins.plugin.action.confirm', array());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -229,6 +243,7 @@ foreach( $fs_plugins as $plugin_id => $fs_plugin )
|
||||
'L_ACTION' => l10n('Install'),
|
||||
)
|
||||
);
|
||||
$template->assign_block_vars( 'plugins.plugin.action.confirm', array());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -626,6 +626,23 @@ function page_forbidden($msg, $alternate_url=null)
|
||||
5 );
|
||||
}
|
||||
|
||||
/**
|
||||
* exits the current script with 400 code
|
||||
* @param string msg a message to display
|
||||
* @param string alternate_url redirect to this url
|
||||
*/
|
||||
function bad_request($msg, $alternate_url=null)
|
||||
{
|
||||
set_status_header(400);
|
||||
if ($alternate_url==null)
|
||||
$alternate_url = make_index_url();
|
||||
redirect_html( $alternate_url,
|
||||
'<div style="text-align:left; margin-left:5em;margin-bottom:5em;">
|
||||
<h1 style="text-align:left; font-size:36px;">Bad request</h1><br/>'
|
||||
.$msg.'</div>',
|
||||
5 );
|
||||
}
|
||||
|
||||
/**
|
||||
* exits the current script with 404 code when a page cannot be found
|
||||
* @param string msg a message to display
|
||||
|
||||
@@ -271,4 +271,65 @@ SELECT id, name, url_name, count(*) counter
|
||||
usort($tags, 'name_compare');
|
||||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* return a list of tags corresponding to any of ids, url_names, names
|
||||
*
|
||||
* @param array ids
|
||||
* @param array url_names
|
||||
* @param array names
|
||||
* @return array
|
||||
*/
|
||||
function find_tags($ids, $url_names=array(), $names=array() )
|
||||
{
|
||||
$where_clauses = array();
|
||||
if ( !empty($ids) )
|
||||
{
|
||||
$where_clauses[] = 'id IN ('.implode(',', $ids).')';
|
||||
}
|
||||
if ( !empty($url_names) )
|
||||
{
|
||||
$where_clauses[] =
|
||||
'url_name IN ('.
|
||||
implode(
|
||||
',',
|
||||
array_map(
|
||||
create_function('$s', 'return "\'".$s."\'";'),
|
||||
$url_names
|
||||
)
|
||||
)
|
||||
.')';
|
||||
}
|
||||
if ( !empty($names) )
|
||||
{
|
||||
$where_clauses[] =
|
||||
'name IN ('.
|
||||
implode(
|
||||
',',
|
||||
array_map(
|
||||
create_function('$s', 'return "\'".$s."\'";'),
|
||||
$names
|
||||
)
|
||||
)
|
||||
.')';
|
||||
}
|
||||
if (empty($where_clauses))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$query = '
|
||||
SELECT id, url_name, name
|
||||
FROM '.TAGS_TABLE.'
|
||||
WHERE '. implode( '
|
||||
OR ', $where_clauses);
|
||||
|
||||
$result = pwg_query($query);
|
||||
$tags = array();
|
||||
while ($row = mysql_fetch_assoc($result))
|
||||
{
|
||||
array_push($tags, $row);
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
?>
|
||||
@@ -4,7 +4,6 @@
|
||||
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
|
||||
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | branch : BSF (Best So Far)
|
||||
// | file : $Id$
|
||||
// | last update : $Date$
|
||||
// | last modifier : $Author$
|
||||
@@ -119,7 +118,7 @@ if (script_basename() == 'picture') // basename without file extention
|
||||
}
|
||||
else
|
||||
{
|
||||
die('Fatal: picture identifier is missing');
|
||||
bad_request('picture identifier is missing');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +158,7 @@ else if (0 === strpos(@$tokens[$next_token], 'tag'))
|
||||
}
|
||||
else
|
||||
{
|
||||
array_push($requested_tag_url_names, "'".$tokens[$i]."'");
|
||||
array_push($requested_tag_url_names, $tokens[$i]);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
@@ -167,32 +166,10 @@ else if (0 === strpos(@$tokens[$next_token], 'tag'))
|
||||
|
||||
if ( empty($requested_tag_ids) && empty($requested_tag_url_names) )
|
||||
{
|
||||
die('Fatal: at least one tag required');
|
||||
}
|
||||
// tag infos
|
||||
$query = '
|
||||
SELECT name, url_name, id
|
||||
FROM '.TAGS_TABLE.'
|
||||
WHERE ';
|
||||
if ( !empty($requested_tag_ids) )
|
||||
{
|
||||
$query.= 'id IN ('.implode(',', $requested_tag_ids ).')';
|
||||
}
|
||||
if ( !empty($requested_tag_url_names) )
|
||||
{
|
||||
if ( !empty($requested_tag_ids) )
|
||||
{
|
||||
$query.= ' OR ';
|
||||
}
|
||||
$query.= 'url_name IN ('.implode(',', $requested_tag_url_names ).')';
|
||||
}
|
||||
$result = pwg_query($query);
|
||||
$tag_infos = array();
|
||||
while ($row = mysql_fetch_assoc($result))
|
||||
{
|
||||
$tag_infos[ $row['id'] ] = $row;
|
||||
array_push($page['tags'], $row );//we loose given tag order; is it important?
|
||||
bad_request('at least one tag required');
|
||||
}
|
||||
|
||||
$page['tags'] = find_tags($requested_tag_ids, $requested_tag_url_names);
|
||||
if ( empty($page['tags']) )
|
||||
{
|
||||
page_not_found('Requested tag does not exist', get_root_url().'tags.php' );
|
||||
@@ -228,10 +205,10 @@ else if ('search' == @$tokens[$next_token])
|
||||
$page['section'] = 'search';
|
||||
$next_token++;
|
||||
|
||||
preg_match('/(\d+)/', $tokens[$next_token], $matches);
|
||||
preg_match('/(\d+)/', @$tokens[$next_token], $matches);
|
||||
if (!isset($matches[1]))
|
||||
{
|
||||
die('Fatal: search identifier is missing');
|
||||
bad_request('search identifier is missing');
|
||||
}
|
||||
$page['search'] = $matches[1];
|
||||
$next_token++;
|
||||
@@ -254,7 +231,7 @@ else if ('list' == @$tokens[$next_token])
|
||||
{
|
||||
if (!preg_match('/^\d+(,\d+)*$/', $tokens[$next_token]))
|
||||
{
|
||||
die('wrong format on list GET parameter');
|
||||
bad_request('wrong format on list GET parameter');
|
||||
}
|
||||
foreach (explode(',', $tokens[$next_token]) as $image_id)
|
||||
{
|
||||
|
||||
@@ -464,6 +464,10 @@ Response format: ".@$this->_responseFormat." encoder:".$this->_responseEncoder."
|
||||
{
|
||||
$flags |= WS_PARAM_OPTIONAL;
|
||||
}
|
||||
if ( $flags & WS_PARAM_FORCE_ARRAY )
|
||||
{
|
||||
$flags |= WS_PARAM_ACCEPT_ARRAY;
|
||||
}
|
||||
$options['flags'] = $flags;
|
||||
$params[$param] = $options;
|
||||
}
|
||||
@@ -604,6 +608,7 @@ Response format: ".@$this->_responseFormat." encoder:".$this->_responseEncoder."
|
||||
$param_data = array(
|
||||
'name' => $name,
|
||||
'optional' => ($options['flags']&WS_PARAM_OPTIONAL)?true:false,
|
||||
'acceptArray' => ($options['flags']&WS_PARAM_ACCEPT_ARRAY)?true:false,
|
||||
);
|
||||
if (isset($options['default']))
|
||||
{
|
||||
|
||||
@@ -269,8 +269,11 @@ function ws_std_get_image_xml_attributes()
|
||||
*/
|
||||
function ws_getVersion($params, &$service)
|
||||
{
|
||||
// TODO = Version availability is under control of $conf['show_version']
|
||||
return PHPWG_VERSION;
|
||||
global $conf;
|
||||
if ($conf['show_version'])
|
||||
return PHPWG_VERSION;
|
||||
else
|
||||
return new PwgError(403, 'Forbidden');
|
||||
}
|
||||
|
||||
|
||||
@@ -336,14 +339,15 @@ SELECT id, name, image_order
|
||||
$where_clauses[] = ws_addControls( 'categories.getImages', $params, 'i.' );
|
||||
|
||||
$order_by = ws_std_image_sql_order($params, 'i.');
|
||||
if (empty($order_by))
|
||||
{// TODO check for category order by (image_order)
|
||||
$order_by = $conf['order_by'];
|
||||
}
|
||||
else
|
||||
if ( empty($order_by)
|
||||
and count($params['cat_id'])==1
|
||||
and isset($cats[ $params['cat_id'][0] ]['image_order'])
|
||||
)
|
||||
{
|
||||
$order_by = 'ORDER BY '.$order_by;
|
||||
$order_by = $cats[ $params['cat_id'][0] ]['image_order'];
|
||||
}
|
||||
$order_by = empty($order_by) ? $conf['order_by'] : 'ORDER BY '.$order_by;
|
||||
|
||||
$query = '
|
||||
SELECT i.*, GROUP_CONCAT(category_id) cat_ids
|
||||
FROM '.IMAGES_TABLE.' i
|
||||
@@ -499,6 +503,10 @@ ORDER BY global_rank';
|
||||
*/
|
||||
function ws_images_addComment($params, &$service)
|
||||
{
|
||||
if (!$service->isPost())
|
||||
{
|
||||
return new PwgError(405, "This method requires HTTP POST");
|
||||
}
|
||||
$params['image_id'] = (int)$params['image_id'];
|
||||
$query = '
|
||||
SELECT DISTINCT image_id
|
||||
@@ -579,7 +587,7 @@ LIMIT 1;';
|
||||
$image_row = mysql_fetch_assoc(pwg_query($query));
|
||||
if ($image_row==null)
|
||||
{
|
||||
return new PwgError(999, "image_id not found");
|
||||
return new PwgError(404, "image_id not found");
|
||||
}
|
||||
$image_row = array_merge( $image_row, ws_std_get_urls($image_row) );
|
||||
|
||||
@@ -859,7 +867,7 @@ function ws_session_login($params, &$service)
|
||||
|
||||
if (!$service->isPost())
|
||||
{
|
||||
return new PwgError(400, "This method requires POST");
|
||||
return new PwgError(405, "This method requires HTTP POST");
|
||||
}
|
||||
if (try_log_user($params['username'], $params['password'],false))
|
||||
{
|
||||
@@ -942,32 +950,19 @@ function ws_tags_getImages($params, &$service)
|
||||
{
|
||||
@include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
|
||||
global $conf;
|
||||
|
||||
|
||||
// first build all the tag_ids we are interested in
|
||||
$tag_ids = array();
|
||||
$tags = get_available_tags();
|
||||
$params['tag_id'] = array_map( 'intval',$params['tag_id'] );
|
||||
$tags = find_tags($params['tag_id'], $params['tag_url_name'], $params['tag_name']);
|
||||
$tags_by_id = array();
|
||||
for( $i=0; $i<count($tags); $i++ )
|
||||
{
|
||||
$tags[$i]['id']=(int)$tags[$i]['id'];
|
||||
}
|
||||
foreach( $tags as $tag )
|
||||
{
|
||||
$tags['id'] = (int)$tag['id'];
|
||||
$tags_by_id[ $tag['id'] ] = $tag;
|
||||
if (
|
||||
in_array($tag['name'], $params['tag_name'])
|
||||
or
|
||||
in_array($tag['url_name'], $params['tag_url_name'])
|
||||
or
|
||||
in_array($tag['id'], $params['tag_id'])
|
||||
)
|
||||
{
|
||||
$tag_ids[] = $tag['id'];
|
||||
}
|
||||
}
|
||||
unset($tags);
|
||||
$tag_ids = array_keys($tags_by_id);
|
||||
|
||||
$tag_ids = array_unique( $tag_ids );
|
||||
|
||||
$image_ids = array();
|
||||
$image_tag_map = array();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
/*
|
||||
<?php /*
|
||||
Plugin Name: Add Index
|
||||
Version: 1.1.0.0
|
||||
Version: 1.0
|
||||
Description: Add file index.php file on all sub-directories of local galleries pictures. / Ajoute le fichier index.php sur les sous-répertoires de galeries d'images locales.
|
||||
Plugin URI: http://www.phpwebgallery.net
|
||||
Author: PhpWebGallery team
|
||||
Author URI: http://www.phpwebgallery.net
|
||||
*/
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | PhpWebGallery - a PHP based picture gallery |
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<?php /*
|
||||
Plugin Name: Admin Advices !
|
||||
Version: 1.0.0
|
||||
Author: PhpWebGallery team
|
||||
Plugin Name: Admin Advices
|
||||
Version: 1.0
|
||||
Description: Give you an advice on the administration page.
|
||||
Plugin URI: http://www.phpwebgallery.net
|
||||
Author: PhpWebGallery team
|
||||
Author URI: http://www.phpwebgallery.net
|
||||
*/
|
||||
|
||||
add_event_handler('loc_end_page_header', 'set_admin_advice_add_css' );
|
||||
|
||||
@@ -3,6 +3,8 @@ Plugin Name: Multi view
|
||||
Version: 1.0
|
||||
Description: Allows administrators to view gallery as guests and/or change the language and/or theme on the fly. Practical to debug changes ...
|
||||
Plugin URI: http://www.phpwebgallery.net
|
||||
Author: PhpWebGallery team
|
||||
Author URI: http://www.phpwebgallery.net
|
||||
*/
|
||||
|
||||
add_event_handler('user_init', 'multiview_user_init' );
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
/*
|
||||
<?php /*
|
||||
Plugin Name: Event tracer
|
||||
Version: 1.0
|
||||
Description: For developers. Shows all calls to trigger_event.
|
||||
Plugin URI: http://www.phpwebgallery.net
|
||||
Author: PhpWebGallery team
|
||||
Author URI: http://www.phpwebgallery.net
|
||||
*/
|
||||
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<?php /*
|
||||
Plugin Name: Hello World !
|
||||
Author: PhpWebGallery team
|
||||
Plugin Name: Hello World
|
||||
Version: 1.0
|
||||
Description: This example plugin changes the page banner for the administration page.
|
||||
Plugin URI: http://www.phpwebgallery.net
|
||||
Author: PhpWebGallery team
|
||||
Author URI: http://www.phpwebgallery.net
|
||||
*/
|
||||
|
||||
add_event_handler('loc_begin_page_header', 'hello_world_begin_header' );
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
<td>{plugins.plugin.DESCRIPTION}</td>
|
||||
<td>
|
||||
<!-- BEGIN action -->
|
||||
<a href="{plugins.plugin.action.U_ACTION}" {TAG_INPUT_ENABLED}>{plugins.plugin.action.L_ACTION}</a>
|
||||
<a href="{plugins.plugin.action.U_ACTION}"
|
||||
<!-- BEGIN confirm -->
|
||||
onclick="return confirm('Are you sure?');"
|
||||
<!-- END confirm -->
|
||||
{TAG_INPUT_ENABLED}>{plugins.plugin.action.L_ACTION}</a>
|
||||
<!-- END action -->
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
1534
tools/prototype.js
vendored
1534
tools/prototype.js
vendored
File diff suppressed because it is too large
Load Diff
141
tools/ws.htm
141
tools/ws.htm
@@ -5,22 +5,10 @@
|
||||
<script type="text/javascript" src="prototype.js" ></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function setElementText(id, text)
|
||||
{
|
||||
if (!text) text="";
|
||||
var elt = document.getElementById(id);
|
||||
if (!elt) alert('setElementText '+id);
|
||||
elt.innerHTML = text;
|
||||
}
|
||||
|
||||
function setVisibility(id, vis)
|
||||
{
|
||||
document.getElementById(id).style.visibility = vis;
|
||||
}
|
||||
|
||||
function clearError()
|
||||
{
|
||||
setElementText("error", "");
|
||||
$(id).style.visibility = vis;
|
||||
}
|
||||
|
||||
function dumpError(err)
|
||||
@@ -37,11 +25,11 @@ function dumpError(err)
|
||||
s += '<br/><small><pre>'+ err.stack + '</pre></small>';
|
||||
}
|
||||
}
|
||||
setElementText("error", s);
|
||||
$("error").update(s);
|
||||
}
|
||||
|
||||
var gServiceUrl;
|
||||
var gCurrentMethodParams;
|
||||
var gCachedMethods;
|
||||
|
||||
Ajax.Responders.register({
|
||||
|
||||
@@ -100,13 +88,14 @@ function pwgGetJsonResult(transport)
|
||||
|
||||
function pwgChangeUrl()
|
||||
{
|
||||
clearError();
|
||||
$("error").update("");
|
||||
setVisibility("methodListWrapper", "hidden");
|
||||
setElementText("methodList", "");
|
||||
$("methodList").update("");
|
||||
setVisibility("methodWrapper", "hidden");
|
||||
setVisibility("methodDetailWrapper", "hidden");
|
||||
|
||||
gServiceUrl = $F('ws_url');
|
||||
gCurrentMethodParams = null;
|
||||
gCachedMethods = new Hash();
|
||||
|
||||
try {
|
||||
var ajaxReq = new Ajax.Request(
|
||||
@@ -130,29 +119,32 @@ function onSuccess_getMethodList(transport)
|
||||
{
|
||||
ml += '<li><a href="#" onclick="return pwgSelectMethod(this.innerHTML)">'+ result.methods[i]+'</a></li>';
|
||||
}
|
||||
setElementText("methodList", ml);
|
||||
$("methodList").update(ml);
|
||||
setVisibility("methodListWrapper", "visible");
|
||||
}
|
||||
|
||||
function pwgSelectMethod(method)
|
||||
function pwgSelectMethod(methodName)
|
||||
{
|
||||
clearError();
|
||||
setElementText("methodName", method);
|
||||
$("error").update("");
|
||||
$("methodName").update(methodName);
|
||||
setVisibility("methodDetailWrapper", "hidden");
|
||||
setVisibility("methodWrapper", "visible");
|
||||
gCurrentMethodParams = null;
|
||||
|
||||
try {
|
||||
|
||||
var ajaxReq = new Ajax.Request(
|
||||
gServiceUrl,
|
||||
{method:'get', parameters:'format=json&method=reflection.getMethodDetails&methodName='+method,
|
||||
onSuccess: function (r) { onSuccess_getMethodDetails(r); }
|
||||
}
|
||||
)
|
||||
}catch (e)
|
||||
if ( gCachedMethods[methodName] )
|
||||
fillNewMethod( gCachedMethods[methodName] );
|
||||
else
|
||||
{
|
||||
dumpError( e );
|
||||
try {
|
||||
var ajaxReq = new Ajax.Request(
|
||||
gServiceUrl,
|
||||
{method:'get', parameters:'format=json&method=reflection.getMethodDetails&methodName='+methodName,
|
||||
onSuccess: function (r) { onSuccess_getMethodDetails(r); }
|
||||
}
|
||||
)
|
||||
}catch (e)
|
||||
{
|
||||
dumpError( e );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -160,67 +152,90 @@ function pwgSelectMethod(method)
|
||||
function onSuccess_getMethodDetails(transport)
|
||||
{
|
||||
var result = pwgGetJsonResult(transport);
|
||||
fillNewMethod( gCachedMethods[result.name] = $H(result) );
|
||||
}
|
||||
|
||||
function fillNewMethod(method)
|
||||
{
|
||||
var methodParamsElt = $("methodParams");
|
||||
while (methodParamsElt.tBodies[0].rows.length)
|
||||
methodParamsElt.tBodies[0].deleteRow(methodParamsElt.tBodies[0].rows.length-1);
|
||||
|
||||
if (result.params)
|
||||
{
|
||||
gCurrentMethodParams = result.params;
|
||||
if (result.params.length>0)
|
||||
{
|
||||
for (var i=0; i<result.params.length; i++)
|
||||
if (method.params && method.params.length>0)
|
||||
{
|
||||
for (var i=0; i<method.params.length; i++)
|
||||
{
|
||||
var row = methodParamsElt.tBodies[0].insertRow(-1);
|
||||
var isOptional = result.params[i].optional;
|
||||
var defaultValue = result.params[i].defaultValue == null ? '' : result.params[i].defaultValue;
|
||||
var isOptional = method.params[i].optional;
|
||||
var acceptArray = method.params[i].acceptArray;
|
||||
var defaultValue = method.params[i].defaultValue == null ? '' : method.params[i].defaultValue;
|
||||
|
||||
row.insertCell(0).innerHTML = result.params[i].name;
|
||||
row.insertCell(1).innerHTML = (isOptional ? 'optional':'required');
|
||||
row.insertCell(0).innerHTML = method.params[i].name;
|
||||
row.insertCell(1).innerHTML = '<span title="parameter is '+(isOptional ? 'optional':'required') +'">'+(isOptional ? '?':'*')+'</span>'
|
||||
+ (method.params[i].acceptArray ? ' <span title="parameter can be an array; use | (pipe) character to split values">[ ]</span>':'');
|
||||
row.insertCell(2).innerHTML = '<input id="methodParameterSend_'+i+'" type="checkbox" '+(isOptional ? '':'checked="checked"')+'/>';
|
||||
row.insertCell(3).innerHTML = '<input id="methodParameterValue_'+i+'"" value="'+defaultValue+'" style="width:99%" onchange="$(\'methodParameterSend_'+i+'\').checked=true;"/>';
|
||||
}
|
||||
}
|
||||
}
|
||||
setElementText("methodDescription", result.description);
|
||||
}
|
||||
$("methodDescription").update(method.description);
|
||||
setVisibility("methodDetailWrapper", "visible");
|
||||
}
|
||||
|
||||
function pwgInvokeMethod( newWindow )
|
||||
{
|
||||
var method = document.getElementById('methodName').innerHTML;
|
||||
var methodName = $('methodName').innerHTML;
|
||||
var method = gCachedMethods[methodName];
|
||||
|
||||
var reqUrl = gServiceUrl;
|
||||
reqUrl += "?format="+$F('responseFormat');
|
||||
|
||||
if (document.getElementById('requestFormat').value == 'get')
|
||||
if ($('requestFormat').value == 'get')
|
||||
{
|
||||
reqUrl += "&method="+method;
|
||||
for ( var i=0; i<gCurrentMethodParams.length; i++)
|
||||
reqUrl += "&method="+methodName;
|
||||
for ( var i=0; i<method.params.length; i++)
|
||||
{
|
||||
if (document.getElementById('methodParameterSend_'+i).checked)
|
||||
reqUrl += '&'+gCurrentMethodParams[i].name+'='+$F('methodParameterValue_'+i);
|
||||
if (! $('methodParameterSend_'+i).checked)
|
||||
continue;
|
||||
|
||||
if ( method.params[i].acceptArray && $F('methodParameterValue_'+i).split('|').length > 1 )
|
||||
{
|
||||
$F('methodParameterValue_'+i).split('|').each(
|
||||
function(v) {
|
||||
reqUrl += '&'+method.params[i].name+'[]='+v;
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
reqUrl += '&'+method.params[i].name+'='+$F('methodParameterValue_'+i);
|
||||
}
|
||||
if ( !newWindow )
|
||||
document.getElementById("invokeFrame").src = reqUrl;
|
||||
$("invokeFrame").src = reqUrl;
|
||||
else
|
||||
window.open(reqUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
var form = document.getElementById("invokeForm");
|
||||
var form = $("invokeForm");
|
||||
form.action = reqUrl;
|
||||
var t = '<input type="hidden" name="'+'method'+'" value="'+method+'"/>';
|
||||
for ( var i=0; i<gCurrentMethodParams.length; i++)
|
||||
var t = '<input type="hidden" name="'+'method'+'" value="'+methodName+'"/>';
|
||||
for ( var i=0; i<method.params.length; i++)
|
||||
{
|
||||
if (document.getElementById('methodParameterSend_'+i).checked)
|
||||
t += '<input type="hidden" name="'+gCurrentMethodParams[i].name+'" value="'+$F('methodParameterValue_'+i)+'"/>';
|
||||
if (! $('methodParameterSend_'+i).checked)
|
||||
continue;
|
||||
|
||||
if ( method.params[i].acceptArray && $F('methodParameterValue_'+i).split('|').length > 1 )
|
||||
{
|
||||
$F('methodParameterValue_'+i).split('|').each(
|
||||
function(v) {
|
||||
t += '<input type="hidden" name="'+method.params[i].name+'[]" value="'+v+'"/>';
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
t += '<input type="hidden" name="'+method.params[i].name+'" value="'+$F('methodParameterValue_'+i)+'"/>';
|
||||
}
|
||||
form.innerHTML = t;
|
||||
if ( !newWindow )
|
||||
form.target = "invokeFrame";
|
||||
else
|
||||
form.target = "_blank";
|
||||
form.target = newWindow ? "_blank" : "invokeFrame";
|
||||
form.submit();
|
||||
}
|
||||
return false;
|
||||
@@ -356,7 +371,7 @@ a:hover {
|
||||
<thead>
|
||||
<tr>
|
||||
<td style="width:150px">Parameter</td>
|
||||
<td>Optional</td>
|
||||
<td>Extra</td>
|
||||
<td>Send</td>
|
||||
<td style="width:160px">Value</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user