Index: /extensions/piwigopress/PiwigoPress_Admin.php
===================================================================
--- /extensions/piwigopress/PiwigoPress_Admin.php	(revision 4314)
+++ /extensions/piwigopress/PiwigoPress_Admin.php	(revision 4314)
@@ -0,0 +1,173 @@
+<?php
+if (defined('PHPWG_ROOT_PATH')) return; /* Avoid direct usage under Piwigo */
+if (!defined('PWGP_NAME')) return; /* Avoid unpredicted access */
+
+if (!function_exists('pwg_get_contents'))  include 'PiwigoPress_get.php';
+
+if(!class_exists('PiwigoPress_Admin')){
+	class PiwigoPress_Admin {
+		function PiwigoPress_Admin(){
+			//add_action("admin_menu", array($this, "getAdminMenu"));
+			add_action("admin_print_scripts", array(&$this, 'head'));
+			add_filter( 'media_buttons_context', array(&$this,'add_button'), 99 );
+			add_filter( 'media_upload_tabs', array(&$this, 'add_tab'), 99);
+			add_filter( 'media_upload_piwigo', array(&$this, 'add_Piwigo'), 99);
+			add_filter( 'media_upload_result', array(&$this, 'add_Piwigo'), 99);
+			add_filter( 'media_upload_criteria', array(&$this, 'add_Piwigo'), 99);
+			add_filter( 'media_upload_select', array(&$this, 'add_Piwigo'), 99);
+			$this->pwg_options = 'PiwigoPress_Admin';
+			add_option($this->pwg_options, serialize(array()));
+			$this->gallery = unserialize(get_option($this->pwg_options));
+			$this->previous = $this->gallery; // Previous is not currently used
+			$this->get_request();
+			$this->update();
+			update_option($this->pwg_options, serialize($this->gallery));
+			$piwigo = empty($this->gallery['piwigo']) ? '' : $this->gallery['piwigo'];
+			$piwigo_url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $piwigo ;
+			if (!empty($this->gallery['external'])) $piwigo_url = $this->gallery['external'];
+			if (substr($piwigo_url,-1)!='/') $piwigo_url .= '/';
+			$this->piwigo_url = $piwigo_url;
+		}
+
+		#add Piwigo button on editor-toolbar
+		function add_button($context=''){
+			global $post_ID, $temp_ID;
+			$_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
+			$this->post_id = $_ID;
+			$iframe_src = 'media-upload.php?post_id='.$_ID.'&type=piwigo&TB_iframe=true';
+			$title = __('Add Some Pictures From Piwigo');
+			$out = '<a href="'.$iframe_src.'" id="add_Piwigo_image" class="thickbox" title="'
+			.$title.'"><img src="'.PWGA_PATH.'images/piwigo.png"/></a>';
+			$context.=$out;
+			return $context;
+		}
+		function add_tab($tabs) {
+			global $wpdb; /* Need for recent thumbnail access */
+			if($_REQUEST['type'] != 'piwigo') return $tabs;
+			$response = pwg_get_contents( $this->piwigo_url 
+				. 'ws.php?method=pwg.categories.getList&format=php');
+			$this->gallery['categories'] = unserialize($response);
+			$this->gallery['images']['stat'] = $this->gallery['categories']['stat'];
+			if ($this->gallery['categories']['stat'] == 'ok') {
+				$options = '';
+				$number = empty($this->gallery['number']) ? 10 : intval($this->gallery['number']);
+				$options .= '&per_page=' . $number;
+				if (!empty($this->gallery['category'])) $options .= '&cat_id=' . intval($this->gallery['category']);
+				$from = empty($this->gallery['from']) ? '12' : intval($this->gallery['from']);
+				$r = (array) $wpdb->get_results('SELECT date_sub( date( now( ) ) , INTERVAL ' . $from . ' MONTH ) as begin');
+				$from = $r[0]->begin;
+				if (!empty($this->gallery['from'])) $options .= '&f_min_date_created=' . $from;
+				$response = pwg_get_contents( $this->piwigo_url 
+					. 'ws.php?method=pwg.categories.getImages&format=php'
+					. $options . '&recursive=true&order=random&f_with_thumbnail=true');
+				$this->gallery['images'] = unserialize($response);
+			}
+			$tab = (isset($_GET['tab'])) ? strip_tags(stripslashes($_GET['tab'])):'type'; // Default results
+			if ( $this->gallery['categories']['stat'] != 'ok') $tab = 'select'; // No WS available
+			if ( $this->gallery['images']['stat'] != 'ok') $tab = 'select'; // No WS available
+			if ( $tab != 'select' and $this->gallery['images']['result']['images']['count'] == 0  ) $tab = 'criteria'; // No pictures available
+			if ( $tab != 'select' and count($this->gallery['categories']['result']['categories']) == 0 ) $tab = 'select'; // No categories available
+			$this->gallery['tab'] = $tab;
+			if ( $this->gallery['images']['stat'] == 'ok' and $this->gallery['images']['result']['images']['count'] > 0 ) return array(
+					'result' => __('Select pictures'),
+					'criteria' => __('Your criteria'),
+					'select' => __('Select the Piwigo gallery'),
+				);
+			if ( $this->gallery['categories']['stat'] == 'ok' and count($this->gallery['categories']['result']['categories']) > 0 ) return array(
+					'criteria' => __('Your criteria'),
+					'select' => __('Select the Piwigo gallery'),
+				);
+			else return array(
+					'select' => __('Select the Piwigo gallery'),
+				);
+		}
+
+		function get_request() {
+			$this->request = $this->gallery;
+			foreach($_REQUEST as $key=>$value) {
+				if(substr($key, 0, 12) == "PiwigoPress_")
+				$this->request[substr($key, 12)] = trim($value);
+			}
+		}
+		function update(){
+			$this->gallery['piwigo'] = strip_tags(stripslashes($this->request['piwigo']));
+			$this->gallery['external'] = strip_tags(stripslashes($this->request['external']));
+		}
+		function head() {
+	?>
+		<link href="<?php bloginfo("wpurl"); ?>/wp-content/plugins/piwigopress/css/style.css" type="text/css" rel="stylesheet"/>
+		<script type="text/javascript" src="<?php bloginfo("wpurl"); ?>/wp-content/plugins/piwigopress/js/scripts.js"></script>
+	<?php
+		}
+		function add_Piwigo() {
+			return wp_iframe(array($this, "add_PiwigoContent"));
+		}
+		function add_PiwigoContent() {
+			$html = media_upload_header();
+			$html .= '<div class="wrapper Piwigo_container">';
+			switch ($this->gallery['tab']) {
+				case 'type':
+						$html .= $this->add_Piwigo_Select();
+						break;
+				case 'criteria':
+						$html .= $this->add_Piwigo_Select();
+						break;
+				case 'select':
+						$html .= $this->add_Piwigo_Select();
+						break;
+			}
+			$html .= '</div>';
+			echo $html;
+		}
+		function add_Piwigo_Select() {
+			$piwigo = (empty($this->gallery['piwigo'])) ? 'piwigo' : $this->gallery['piwigo'];
+			$external = (empty($this->gallery['external'])) ? '' : $this->gallery['external'];
+			
+			$iframe_src = 'media-upload.php?post_id='.$_ID.'&type=piwigo&TB_iframe=true';
+			$message = (isset($this->request['sub-url'])) ? __('Configuration saved'):'';
+			
+			return '<h3 class="media-title">'
+			. __('From my Piwigo gallery','pwg') . '</h3>'
+			. nl2br(__(<<<EOF
+				Set Piwigo gallery:
+				- directory, if Piwigo is on the same domain than your blog (relative path from the domain),
+				- URL, if Piwigo gallery is an external website or another subdomain.
+
+				Remind that only public images with a null privacy level could be collected from there.
+				Directory is ignored if an URL is provided.
+EOF
+			,'pwg')) . '<br/><br/>' . $message . '<br/>
+				<form id="piwigo-form" class="media-upload-form type-form validate" method="post" enctype="multipart/form-data"
+				action="media-upload.php?post_id=' . $this->post_id . '&type=piwigo&TB_iframe=true">
+				<input type="hidden" id="post_id" name="post_id" value="' . $this->post_id . '"/>
+				<input type="hidden" name="_wpnonce" id="_wpnonce" value="' . wp_create_nonce('media-form') . '"/>
+				<input type="hidden" name="_wp_http_referer"
+				value="media-upload.php?post_id=' . $this->post_id . '&type=piwigo&TB_iframe=true"/>
+
+				<p style="text-align:right;"><label for="piwigo">' . __('<strong>Local</strong> directory (if local)','pwg') . '
+				<input style="width: 200px;" id="piwigo" name="PiwigoPress_piwigo" type="text" value="' . $piwigo . '" /></label>
+				</p>
+
+				<p style="text-align:right;"><label for="external">' . __('(or) <strong>External</strong> gallery URL','pwg') . '
+				<input style="width: 250px;" id="external" name="PiwigoPress_external" type="text" value="' . $external . '" /></label>
+				</p>
+
+				<p style="text-align:right;">
+				<input type="submit" id="piwigo-submit" value="' . __('Submit','pwg') . '" name="PiwigoPress__sub-url" class="button-primary alignright">
+				</p>
+
+				</form>';
+		}
+	}
+}
+if (!is_object($PWG_Adm)) {
+	$PWG_Adm = new PiwigoPress_Admin();
+}
+
+/*
+	function getAdminMenu() {
+		add_submenu_page("plugins.php", "PiwigoPress", "PiwigoPress", "administrator", basename(__FILE__), array(&$PWG_Adm, "getAdminContent"));
+	}
+*/
+
+?>
Index: /extensions/piwigopress/PiwigoPress_code.php
===================================================================
--- /extensions/piwigopress/PiwigoPress_code.php	(revision 4313)
+++ /extensions/piwigopress/PiwigoPress_code.php	(revision 4314)
@@ -18,5 +18,5 @@
 $options = '';
 $number = empty($gallery['number']) ? 1 : intval($gallery['number']);
-$options .= '&per_page=' . intval($gallery['number']);
+$options .= '&per_page=' . $number;
 if (!empty($gallery['category'])) $options .= '&cat_id=' . intval($gallery['category']);
 $from = empty($gallery['from']) ? '12' : intval($gallery['from']);
Index: /extensions/piwigopress/css/style.css
===================================================================
--- /extensions/piwigopress/css/style.css	(revision 4314)
+++ /extensions/piwigopress/css/style.css	(revision 4314)
@@ -0,0 +1,411 @@
+div.Piwigo_container {
+	background:transparent url(../images/piwigo_logo.png) no-repeat fixed bottom right;
+	padding: 1em;
+	height:100%;
+	max-height:100%;
+}
+div#media-upload-header {
+	margin: 0;
+	padding: 0 5px;
+	font-weight: bold;
+	position: relative;
+	border-bottom-width: 1px;
+	border-bottom-style: solid;
+	height: 2.5em;
+}
+
+body#media-upload ul#sidemenu {
+	font-weight: normal;
+	margin: 0 5px;
+	position: absolute;
+	left: 0px;
+	bottom: -1px;
+}
+
+div#media-upload-error {
+	margin: 1em;
+	font-weight: bold;
+}
+
+form {
+	margin: 1em;
+}
+
+#search-filter {
+	text-align: right;
+}
+
+.media-upload-form label,
+.media-upload-form legend {
+	display: block;
+	font-weight: bold;
+	font-size: 13px;
+	margin-bottom: 0.5em;
+	margin: 0 0 0.5em 0;
+}
+
+th {
+	position: relative;
+}
+
+.media-upload-form label.form-help, td.help {
+	font-family: "Lucida Grande", "Bitstream Vera Sans", Verdana, Arial, sans-serif;
+	font-style: italic;
+	font-weight: normal;
+}
+
+.media-upload-form p.help {
+	margin: 0;
+	padding: 0;
+}
+
+.media-upload-form fieldset {
+	width: 100%;
+	border: none;
+	text-align: justify;
+	margin: 0 0 1em 0;
+	padding: 0;
+}
+
+/* specific to the image upload form */
+.align .field label {
+	display: inline;
+	padding: 0 0 0 28px;
+	margin: 0 1em 0 0;
+}
+
+.image-align-none-label {
+	background: url(../images/align-none.png) no-repeat center left;
+}
+
+.image-align-left-label {
+	background: url(../images/align-left.png) no-repeat center left;
+}
+
+.image-align-center-label {
+	background: url(../images/align-center.png) no-repeat center left;
+}
+
+.image-align-right-label {
+	background: url(../images/align-right.png) no-repeat center left;
+}
+
+tr.image-size td {
+	width: 460px;
+}
+
+tr.image-size div.image-size-item {
+	float: left;
+	width: 25%;
+	margin: 0;
+}
+
+tr.image-size label {
+	display: inline;
+	margin: 0 0 0 1em;
+}
+
+.pinkynail {
+	max-width: 40px;
+	max-height: 40px;
+}
+
+#library-form .progress,
+#gallery-form .progress,
+#flash-upload-ui,
+.insert-gallery,
+.describe.startopen,
+.describe.startclosed {
+	display: none;
+}
+
+.media-item .thumbnail {
+	max-width: 128px;
+	max-height: 128px;
+}
+
+.media-item .pinkynail {
+	float: left;
+	margin: 2px;
+	height: 32px;
+	max-width: 40px;
+}
+
+thead.media-item-info tr {
+	background-color: transparent;
+}
+
+thead.media-item-info th,
+thead.media-item-info td {
+	border: none;
+	margin: 0;
+}
+
+.form-table thead.media-item-info {
+	border: 8px solid #fff;
+}
+
+abbr.required {
+	text-decoration: none;
+	border: none;
+}
+
+.describe label {
+	display: inline;
+}
+
+.describe td {
+	vertical-align: middle;
+	padding: 0 5px 0 0;
+}
+
+.describe td.A1 {
+	width: 132px;
+}
+
+.describe input[type="text"],
+.describe textarea {
+	width: 460px;
+	border-width: 1px;
+	border-style: solid;
+}
+
+.describe-toggle-on,
+.describe-toggle-off {
+	display: block;
+	line-height: 36px;
+	float: right;
+	margin-right: 20px;
+}
+
+.describe-toggle-off {
+	display: none;
+}
+
+.hidden {
+	height: 0;
+	width: 0;
+	overflow: hidden;
+	border: none;
+}
+
+/* Specific to Uploader */
+
+#media-upload .media-upload-form p {
+	margin: 0 1em 1em 0;
+}
+
+#media-upload p.ml-submit {
+	padding: 1em 0;
+}
+
+#media-upload p.help,
+#media-upload label.help {
+	font-family: "Lucida Grande", "Bitstream Vera Sans", Verdana, Arial, sans-serif;
+	font-style: italic;
+	font-weight: normal;
+}
+
+#media-upload tr.image-size td.field {
+	text-align: center;
+}
+
+#media-upload #media-items {
+	border-width: 1px;
+	border-style: solid;
+	border-bottom: none;
+	width: 623px;
+}
+
+#media-upload .media-item {
+	border-bottom-width: 1px;
+	border-bottom-style: solid;
+	min-height: 36px;
+	width: 100%;
+}
+
+#media-upload .ui-sortable .media-item {
+	cursor: move;
+}
+
+.filename {
+	line-height: 36px;
+	padding: 0 10px;
+	overflow: hidden;
+}
+
+#media-upload .describe {
+	padding: 5px;
+	width: 100%;
+	clear: both;
+	cursor: default;
+}
+
+#media-upload .slidetoggle {
+	border-top-width: 1px;
+	border-top-style: solid;
+}
+
+#media-upload .describe th.label {
+	padding-top: .5em;
+	text-align: left;
+	min-width: 120px;
+}
+
+#media-upload tr.align td.field {
+	text-align: center;
+}
+
+#media-upload tr.image-size {
+	margin-bottom: 1em;
+	height: 3em;
+}
+
+#media-upload #filter {
+	width: 623px;
+}
+
+#media-upload #filter .subsubsub {
+	margin: 8px 0;
+}
+
+#filter .tablenav select {
+	border-style: solid;
+	border-width: 1px;
+	padding: 2px;
+	vertical-align: top;
+	width: auto;
+}
+
+#media-upload .del-attachment {
+	display: none;
+	margin: 5px 0;
+}
+
+.menu_order {
+	float: right;
+	font-size: 11px;
+	margin: 10px 10px 0;
+}
+
+.menu_order_input {
+	border: 1px solid #ddd;
+	font-size: 10px;
+	padding: 1px;
+	width: 23px;
+}
+
+.ui-sortable-helper {
+	background-color: #fff;
+	border: 1px solid #aaa;
+	opacity: 0.6;
+	filter: alpha(opacity=60);
+}
+
+#media-upload th.order-head {
+	width: 25%;
+	text-align: center;
+}
+
+#media-upload .widefat {
+	width: 626px;
+	border-style: solid solid none;
+}
+
+.sorthelper {
+	height: 37px;
+	width: 623px;
+	display: block;
+}
+
+#gallery-settings th.label {
+	width: 160px;
+}
+
+#gallery-settings #basic th.label {
+	padding: 5px 5px 5px 0;
+}
+
+#gallery-settings .title {
+	clear: both;
+	padding: 0 0 3px;
+	border-bottom-style: solid;
+	border-bottom-width: 1px;
+	font-family: Georgia,"Times New Roman",Times,serif;
+	font-size: 1.6em;
+	border-bottom-color: #DADADA;
+	color: #5A5A5A;
+}
+
+h3.media-title  {
+	color: #5A5A5A;
+	font-family: Georgia,"Times New Roman",Times,serif;
+	font-size: 1.6em;
+	font-weight: normal;
+}
+
+#gallery-settings .describe td {
+	vertical-align: middle;
+	height: 3.5em;
+}
+
+#gallery-settings .describe th.label {
+	padding-top: .5em;
+	text-align: left;
+}
+
+#gallery-settings .describe {
+	padding: 5px;
+	width: 615px;
+	clear: both;
+	cursor: default;
+}
+
+#gallery-settings .describe select {
+	width: 15em;
+	border: 1px solid #dfdfdf;
+}
+
+#gallery-settings label,
+#gallery-settings legend {
+	font-size: 13px;
+	color: #464646;
+	margin-right: 15px;
+}
+
+#gallery-settings .align .field label {
+	margin: 0 1.5em 0 0;
+}
+
+#gallery-settings p.ml-submit {
+	border-top: 1px solid #dfdfdf;
+}
+
+#gallery-settings select#columns {
+	width: 6em;
+}
+
+#sort-buttons {
+	font-size: 0.8em;
+	margin: 3px 25px -8px 0;
+	text-align: right;
+	max-width: 625px;
+}
+
+#sort-buttons a {
+	text-decoration: none;
+}
+
+#sort-buttons #asc,
+#sort-buttons #showall {
+	padding-left: 5px;
+}
+
+#sort-buttons span {
+	margin-right: 25px;
+}
+
+#piwigo-submit {
+	min-width:80px;
+	text-align:center;
+}
Index: /extensions/piwigopress/piwigopress.php
===================================================================
--- /extensions/piwigopress/piwigopress.php	(revision 4313)
+++ /extensions/piwigopress/piwigopress.php	(revision 4314)
@@ -26,4 +26,5 @@
 */
 if (!defined('PWGP_NAME')) define('PWGP_NAME','PiwigoPress');
+if (!defined('PWGA_PATH')) define('PWGA_PATH', '../wp-content/plugins/piwigopress/'); // Path from /wp-admin/
 
 load_plugin_textdomain('pwg', 'wp-content/plugins/piwigopress', 'piwigopress' );
@@ -74,8 +75,11 @@
 }
 
-// Add gallery pictures
-function PiwigoPress_media_buttons() {
+add_action('widgets_init', PWGP_NAME . '_Init');
+
+// Admin code only if distributed and in Admin
+if (strpos($_SERVER['REQUEST_URI'], "/wp-admin/") !== false) {
+  if (file_exists(PWGA_PATH.'PiwigoPress_Admin.php')) // Not commited currently.
+		include 'PiwigoPress_Admin.php';
 }
-add_action('widgets_init', PWGP_NAME . '_Init');
-add_action('media_buttons', PWGP_NAME . '_media_buttons');
+
 ?>
