Index: /extensions/Extended_author/TODO
===================================================================
--- /extensions/Extended_author/TODO	(revision 11819)
+++ /extensions/Extended_author/TODO	(revision 11819)
@@ -0,0 +1,6 @@
+=== TODO ===
+-	Everything that's todo in the copyrights plugin :P
+-	When assigning a default cpoyright to an author, update all 0's from that author in copyright_media
+
+=== Bugs ===
+-	We don't check if the url has 'http://' (or is this a TODO?)
Index: /extensions/Extended_author/admin.php
===================================================================
--- /extensions/Extended_author/admin.php	(revision 11819)
+++ /extensions/Extended_author/admin.php	(revision 11819)
@@ -0,0 +1,223 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+if (!defined("PHPWG_ROOT_PATH")){
+	die("Hacking attempt!");
+}
+
+global $prefixeTable;
+include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+load_language('plugin.lang', E_AUTHOR_PATH);
+
+// Check access and exit when user status is not ok
+check_status(ACCESS_ADMINISTRATOR);
+
+// Default is to create an author, if changed to 1, show the edit page
+$edit = 0;
+
+// The values for the form fields
+$EAid = 0;
+$EAname = '';
+$EAurl = '';
+$EAdescr = '';
+$EAcopyright_id = '';	// The default should be 0, but this equals 0, doesnt it?
+
+// Fetch all the copyrights and assign them to the template
+$query = sprintf(
+	'SELECT `cr_id`,`name`
+	FROM %s
+	WHERE `visible`<>0
+	AND cr_id <> -1
+	ORDER BY cr_id ASC
+	;',
+	COPYRIGHTS_ADMIN);
+$result = pwg_query($query);
+$EAcopyrights = array();
+while ($row = pwg_db_fetch_assoc($result)) {
+	$EAcopyrights[$row['cr_id']] = $row['name'];
+}
+$template->assign('EAcopyrights', $EAcopyrights);
+
+// Do managing of authors
+if (isset($_GET['tab'])) {
+	// Create a new author
+	if ($_GET['tab'] == 'create') {
+		// Fetch the values from the form
+		$name = pwg_db_real_escape_string($_REQUEST['name']);
+		$url = pwg_db_real_escape_string($_REQUEST['url']);
+		$descr = pwg_db_real_escape_string($_REQUEST['descr']);
+		$copyright = pwg_db_real_escape_string($_REQUEST['copyrightID']);
+
+		// Check whether an author with such a name exists
+		// Therefore count the number of authors with that name
+		$query = sprintf(
+			'SELECT COUNT(*)
+			FROM %s
+			WHERE `name` = \'%s\'
+			;',
+			AUTHORS, $name);
+		list($counter) = pwg_db_fetch_row(pwg_query($query));
+
+		if ($counter != 0) {
+			// The author exists already
+			array_push($page['errors'], l10n('This author already exists.'));
+		} else {
+			// The author did not yet exist
+			// Compose a query to insert the author
+			$query = sprintf(
+				'INSERT INTO %s
+				(`name`,`url`,`descr`,`copyright`) VALUES
+				("%s","%s","%s",%d)
+				;',
+				AUTHORS, $name, $url, $descr, $copyright);
+			pwg_query($query); // Execute the query
+		}
+	}
+
+	// Edit an existing author
+	if ($_GET['tab'] == 'edit') {
+		$edit = 1; // Show the edit page
+		$EAid = $_REQUEST['id']; // Fetch the id of the author to be edited
+
+		// Fetch the current attributes to the author
+		$query = sprintf(
+			'SELECT *
+			FROM %s
+			WHERE `author_id`=%d
+			;',
+			AUTHORS, $EAid);
+		$result = pwg_query($query);
+		$row = pwg_db_fetch_assoc($result);
+
+		// Save the attributes in convenient variables
+		$EAname = $row['name'];
+		$EAurl = $row['url'];
+		$EAdescr = $row['descr'];
+		$EAcopyright_id = $row['copyright'];
+	}
+
+	// Update an existing author
+	if ($_GET['tab'] == 'update') {
+		// Fetch the values from the edit form
+		$id = pwg_db_real_escape_string($_REQUEST['id']);
+		$name = pwg_db_real_escape_string($_REQUEST['name']);
+		$url = pwg_db_real_escape_string($_REQUEST['url']);
+		$descr = pwg_db_real_escape_string($_REQUEST['descr']);
+		$copyright = pwg_db_real_escape_string($_REQUEST['copyrightID']);
+
+		// Compose a query to update the author
+		$query = sprintf(
+			'UPDATE %s
+			SET `name`="%s", `url`="%s", `descr`="%s", `copyright`=%d
+			WHERE `author_id`=%d
+			;',
+			AUTHORS, $name, $url, $descr, $copyright, $id);
+		pwg_query($query); // Execute the query
+	}
+
+	// Delete an existing author
+	if ($_GET['tab'] == 'delete') {
+		// Fetch the id of the author to be deleted
+		$id = $_REQUEST['id'];
+		
+		// Get the author's name
+		$query = sprintf(
+			'SELECT name
+			FROM %s
+			WHERE author_id=%d
+			;',
+			AUTHORS, $id);
+		$result = pwg_query($query);
+		$row = pwg_db_fetch_assoc($result);
+		$name = $row['name'];
+		
+		// Delete all his 'default' entries from the copyright table
+		delete_default_CR($name);
+		
+		// Unset the author in the images table
+		$query = sprintf(
+			'UPDATE %s
+			SET `author`=NULL
+			WHERE `author`=\'%s\'
+			;',
+			IMAGES, $name);
+		pwg_query($query);
+		
+		// Delete the author
+		$query = sprintf(
+			'DELETE FROM %s
+			WHERE `author_id`=%d
+			;',
+			AUTHORS, $id);
+		pwg_query($query);
+	}
+}
+
+/* Assign variables to the template */
+global $template;
+
+// Add the admin.tpl template
+$template->set_filenames(
+	array('plugin_admin_content' => dirname(__FILE__).'/admin.tpl')
+);
+
+// Select the existing authors
+$query = sprintf(
+	'SELECT *
+	FROM %s
+	;',
+	AUTHORS);
+$result = pwg_query($query);
+
+// Append the authors to the Smarty array
+while ($row = pwg_db_fetch_assoc($result)) {
+	$template->append(
+		'EAs',
+		array(
+			'author_id' => $row['author_id'],
+			'name'      => $row['name'],
+			'url'       => $row['url'],
+			'descr'     => $row['descr'],
+			'copyright_id'   => $row['copyright']
+		)
+	);
+}
+
+// Assign the path for URL forming
+$template->assign(
+	'E_AUTHOR_PATH',
+	E_AUTHOR_WEB_PATH
+);
+
+// Assign all the variables we constructed above
+$template->assign('edit', $edit);
+$template->assign('EAid', $EAid);
+$template->assign('EAname', $EAname);
+$template->assign('EAurl', $EAurl);
+$template->assign('EAdescr', $EAdescr);
+$template->assign('EAcopyright_id', $EAcopyright_id);
+
+// Get it up and running
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
+
+?>
Index: /extensions/Extended_author/admin.tpl
===================================================================
--- /extensions/Extended_author/admin.tpl	(revision 11819)
+++ /extensions/Extended_author/admin.tpl	(revision 11819)
@@ -0,0 +1,87 @@
+<div class = "titlePage">
+  <h2>{'Extended author'|@translate}</h2>
+</div>
+
+<!-- create the form for EAeating and editing authors -->
+<form action='{$E_AUTHOR_PATH}-{if $edit == 0}create{else}update{/if}'
+      method='POST'>
+  <fieldset>
+    <legend>{if $edit == 0}{'Create author'|@translate}
+            {else}{'Update author'|@translate}{/if}</legend>
+      <!-- If $edit != 0 we should remember the id of the author that is
+           edited -->
+      {if $edit != 0}<input type='hidden' name='id' id='id' value='{$EAid}' />{/if}
+      <!-- Put all the attributes of the author in a nice table -->
+      <table>
+        <tr>
+          <td>{'Name'|@translate}</td>
+          <td><input type='text' name='name' id='name' value='{$EAname}' /></td>
+        </tr>
+        <tr>
+          <td>{'URL'|@translate}</td>
+          <td><input type='text' name='url'  id='url'  value='{$EAurl}' /></td>
+        </tr>
+        <tr>
+          <td>{'Description'|@translate}</td>
+          <td><textarea name='descr' id='descr'>{$EAdescr}</textarea></td>
+        </tr>
+        <tr>
+          <td>{'Default'|@translate} {'copright'|@translate}</td>
+          <td>
+				<select name="copyrightID">
+					<option value="0">--</option>
+					{html_options options=$EAcopyrights selected=$EAcopyright_id}
+				</select>
+		  </td>
+        </tr>
+        <tr>
+          <td></td>
+          <td><input type='submit' value="{if $edit == 0}{'Create'|@translate}{else}{'Update'|@translate}{/if}" /></td>
+        </tr>
+      </table>
+  </fieldset>
+</form>
+
+<!-- If we are on the 'homepage', show a table of all authors -->
+{if $edit == 0}
+<form>
+  <fieldset>
+    <legend>{'Edit author'|@translate}</legend>
+    <table>
+      <tr>
+        <!-- create a nice header row -->
+        <th>{'Name'|@translate}</th>
+        <th>{'URL'|@translate}</th>
+        <th>{'Description'|@translate}</th>
+        <th>{'Copyright'|@translate}</th>
+        <th>{'Actions'|@translate}</th>
+      </tr>
+    <!-- Loop over all copyrights -->
+    {if not empty($EAs)}
+    {foreach from=$EAs item=EA}
+    {strip}
+      <tr class="{cycle values="row1,row2"}"> <!-- This gives nicely colored
+                                                   table rows -->
+        <td>{$EA.name}</td>
+        <td><a href="{$EA.url}">{$EA.url}</a></td>
+        <td>{$EA.descr}</td>
+        <td>{$EAcopyrights[$EA.copyright_id]}</td>
+        <!-- Show nice Edit and Delete icons -->
+        <td>
+          <a href="{$E_AUTHOR_PATH}-edit&id={$EA.author_id}">
+            <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/edit_s.png"
+            alt="{'Edit'|@translate}" title="{'Edit'|@translate}" />
+          </a>
+          <a href="{$E_AUTHOR_PATH}-delete&id={$EA.author_id}" onclick="return confirm(document.getElementById('btn_delete').title + '\n\n' + '{'Are you sure?'|@translate|@escape:'javascript'}');">
+            <img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/delete.png"
+            id="btn_delete" alt="{'Delete'|@translate}" title="{'Delete author'|@translate}" />
+          </a>
+        </td>
+      </tr>
+    {/strip}
+    {/foreach}
+    {/if}
+    </table>
+  </fieldset>
+</form>
+{/if}
Index: /extensions/Extended_author/batch_global.php
===================================================================
--- /extensions/Extended_author/batch_global.php	(revision 11819)
+++ /extensions/Extended_author/batch_global.php	(revision 11819)
@@ -0,0 +1,57 @@
+<?php
+
+// Add event handlers for the prefilter
+add_event_handler('loc_end_element_set_global', 'EA_set_prefilter_batch_global', 55 );
+
+// Change the variables used by the function that changes the template
+add_event_handler('loc_end_element_set_global', 'EA_add_batch_single_vars_to_template');
+add_event_handler('element_set_global_action', 'EA_batch_global_submit', 50, 2);
+
+// Add a prefilter to the template
+function EA_set_prefilter_batch_global()
+{
+	global $template;
+	$template->set_prefilter('batch_manager_global', 'EA_batch_global');
+}
+
+// Insert the copyright selector to the template
+function EA_batch_global($content, &$smarty)
+{
+	// Replace the piwigo author by our own author stuff
+	$search = '/<div id="action_author".*?<\/div>/is';
+
+	// Tarkista jos ei ole toista <div> Välillä kirjailija divs
+	preg_match($search, $content, $result);
+	if (substr_count($result[0], '<div') > 1) {
+		global $page;
+		array_push($page['errors'], 'Error, someone added a <div> between the author <div>\'s. You can fix this long forseen bug in: extended_author plugin - batch_global.php - EA_batch_global - the regex expression ($search) :).');
+	}
+
+	$replacement = '<div id="action_author" class="bulkAction">
+			{\'Author\'|@translate}:
+			<select id="author" name="author">
+				<option value="">--</option>
+			{foreach from=$EAoptions item=option}
+				<option value="{$option}">
+					{$option}
+				</option>
+			{/foreach}
+			</select>
+		</div>';
+
+	$tempReturn = preg_replace($search, $replacement, $content);
+	
+	return $tempReturn;
+}
+
+// Process the submit action
+function EA_batch_global_submit($action, $collection)
+{
+	// If its our plugin that is called
+	if ($action == 'author') {
+		$name = pwg_db_real_escape_string($_POST['author']);
+		insert_default_CR($name);
+	}
+}
+
+?>
Index: /extensions/Extended_author/batch_single.php
===================================================================
--- /extensions/Extended_author/batch_single.php	(revision 11819)
+++ /extensions/Extended_author/batch_single.php	(revision 11819)
@@ -0,0 +1,113 @@
+<?php
+
+// Add event handlers for the prefilter
+add_event_handler('loc_end_element_set_unit', 'EA_set_prefilter_batch_single', 55 );
+add_event_handler('loc_begin_element_set_unit', 'EA_batch_single_submit', 50 );
+
+// Change the variables used by the function that changes the template
+add_event_handler('loc_end_element_set_unit', 'EA_add_batch_single_vars_to_template');
+
+// Add a prefilter to the template
+function EA_set_prefilter_batch_single()
+{
+	global $template;
+	$template->set_prefilter('batch_manager_unit', 'EA_batch_single');
+}
+
+// Insert the copyright selector to the template
+function EA_batch_single($content, &$smarty)
+{
+	// Replace the piwigo author by our own author stuff
+	$search = '/<td><input type="text" class="large" name="author-.*?<\/td>/is';
+
+	$replacement = '<td>
+			<select id="author-{$element.ID}" name="author-{$element.ID}">
+				<option value="">--</option>
+			{foreach from=$EAoptions item=option}
+				<option value="{$option}"{if $EAauthors[$element.ID] == $option} selected="selected"{/if}>
+					{$option}
+				</option>
+			{/foreach}
+			</select>
+		</td>';
+
+  return preg_replace($search, $replacement, $content);
+}
+
+// Assign the variables to the Smarty template
+function EA_add_batch_single_vars_to_template()
+{
+	global $template;
+
+	load_language('plugin.lang', dirname(__FILE__).'/');
+
+	// Fetch all the author names and assign them to the template
+	$query = sprintf(
+		'SELECT `author_id`,`name`
+		FROM %s
+		;',
+		AUTHORS);
+	$result = pwg_query($query);
+
+	$EAoptions = array();
+	while ($row = pwg_db_fetch_assoc($result)) {
+		$EAoptions[$row['author_id']] = $row['name'];
+	}
+	$template->assign('EAoptions', $EAoptions);
+	
+	// Get the author name for every image id
+	$query = sprintf(
+		'SELECT `id`, `author`
+		FROM %s
+		;',
+		IMAGES);
+	$result = pwg_query($query);
+	
+	// Get the author id for each element	
+	$EAauthors = array();
+	while ($row = pwg_db_fetch_assoc($result)) {
+		$EAauthors[$row['id']] = $row['author'];
+	}
+
+	// Assign the copyrights to the template
+	$template->assign('EAauthors', $EAauthors);
+}
+
+// Catch the submit and update the copyrights tables
+function EA_batch_single_submit()
+{
+	if (isset($_POST['submit']))
+	{
+		// The image id's:
+		$collection = explode(',', $_POST['element_ids']);
+		
+		// Check all authors, and give them defaults
+		$edits = array();
+		foreach ($collection as $image_id) {
+			// The copyright name's
+			$name = pwg_db_real_escape_string($_POST['author-'.$image_id]);
+			
+			// Create the array to be updated
+			array_push(
+				$edits,
+				array(
+					'id' => $image_id,
+					'author' => $name,
+				)
+			);
+			
+			// Add them to the images table
+			// (yes, this is double work, since the author will be set by the piwigo core. But its not set right now, and insert_default_CR needs it...)
+			mass_updates(
+				IMAGES,
+				array('primary' => array('id'), 'update' => array('author')),
+				$edits
+			);
+			
+			// Insert the default copyrights
+			insert_default_CR($name);
+		}
+	}
+}
+
+?>
Index: /extensions/Extended_author/image.php
===================================================================
--- /extensions/Extended_author/image.php	(revision 11819)
+++ /extensions/Extended_author/image.php	(revision 11819)
@@ -0,0 +1,78 @@
+<?php
+
+// Add an event handler for a prefilter
+add_event_handler('loc_begin_picture', 'EA_set_prefilter_add_to_pic_info', 55 );
+
+// Change the variables used by the function that changes the template
+add_event_handler('loc_begin_picture', 'EA_add_image_vars_to_template');
+
+// Add the prefilter to the template
+function EA_set_prefilter_add_to_pic_info()
+{
+	global $template;
+	$template->set_prefilter('picture', 'EA_add_to_pic_info');
+}
+
+// Insert the template for the author display
+function EA_add_to_pic_info($content, &$smarty)
+{
+	// Add the information after the author - so before the createdate
+	$search = '/<tr id="Author">.*?<\/tr>/is';
+	
+	$replacement = '
+	<tr id="extended_author">
+		<td class="label">{\'Author\'|@translate}</td>
+		<td class="value">
+		{if $EA_INFO_NAME}
+			{if $EA_INFO_URL}
+				<a target="_blanc" href="{$EA_INFO_URL}" title="{$EA_INFO_NAME}">
+			{/if}
+			{$EA_INFO_NAME}
+			{if $EA_INFO_URL}
+				</a>
+			{/if}
+		{else}
+			{\'N/A\'|@translate}
+		{/if}
+		</td>
+	</tr>';
+
+	return preg_replace($search, $replacement, $content);
+}
+
+// Assign values to the variables in the template
+function EA_add_image_vars_to_template()
+{
+	global $page, $template;
+
+	// Show block only on the photo page
+	if ( !empty($page['image_id']) )
+	{
+		// Get the author name and url that belongs to the current media_item
+		$query = sprintf('
+			select a.name, a.url
+			FROM %s i, %s a
+			WHERE i.author = a.name
+			AND i.id = %d
+		;',
+		IMAGES, AUTHORS, $page['image_id']);
+		$result = pwg_query($query);
+		$row = pwg_db_fetch_row($result);
+		$name = '';
+		$url = '';
+		if(count($row) > 0) {
+			$name = $row[0];
+			$url = $row[1];
+		}
+			
+		// Sending data to the template
+		$template->assign(
+			array(
+				'EA_INFO_NAME' => $name,
+				'EA_INFO_URL' => $url
+			)
+		);
+	}
+}
+
+?>
Index: /extensions/Extended_author/include/functions.inc.php
===================================================================
--- /extensions/Extended_author/include/functions.inc.php	(revision 11819)
+++ /extensions/Extended_author/include/functions.inc.php	(revision 11819)
@@ -0,0 +1,78 @@
+<?php
+
+// Replace all not assigned copyrights from a specific author, with the default copyright.
+function insert_default_CR($author) {
+	global $prefixeTable;
+	
+	// Get all the images from this author that have no copyrights
+	$query = sprintf(
+		'SELECT id
+		FROM %s
+		WHERE `author`=\'%s\'
+		AND id NOT IN (
+			SELECT media_id AS id
+			FROM %s
+		)
+		;',
+		IMAGES, $author, COPYRIGHTS_MEDIA);
+	$result = pwg_query($query);
+	
+	// Put them in an array
+	$edits = array();
+	while ($row = pwg_db_fetch_assoc($result)) {
+		array_push(
+			$edits,
+			array(
+				'media_id' => $row['id'],
+				'cr_id' => -1,
+			)
+		);
+	}
+	
+	// Put that array in the database
+	if (count($edits) > 0) {
+		mass_inserts(
+			COPYRIGHTS_MEDIA,
+			array_keys($edits[0]),
+			$edits
+		);
+	}
+}
+
+
+// Delete all copyrights from an author
+function delete_default_CR($author) {
+	global $prefixeTable;
+	// Get all image_id's with default copyrights from this author
+	$query = sprintf(
+		'SELECT id
+		FROM %s
+		WHERE (`author`=\'%s\' OR `author`=NULL)
+		AND id IN (
+			SELECT media_id AS id
+			FROM %s
+			WHERE cr_id = -1
+		)
+		;',
+		IMAGES, $author, COPYRIGHTS_MEDIA);
+	$result = pwg_query($query);
+	
+	// Put them in an array
+	$deletes = array();
+	while ($row = pwg_db_fetch_assoc($result)) {
+		$deletes[] = $row['id'];
+	}
+	
+	// Delete them
+	if (count($deletes) > 0) {
+		$query = sprintf(
+			'DELETE
+			FROM %s
+			WHERE media_id IN (%s)
+			;',
+			COPYRIGHTS_MEDIA, implode(',', $deletes));
+		pwg_query($query);
+	}
+}
+
+?>
Index: /extensions/Extended_author/index.php
===================================================================
--- /extensions/Extended_author/index.php	(revision 11819)
+++ /extensions/Extended_author/index.php	(revision 11819)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/Extended_author/language/en_UK/description.txt
===================================================================
--- /extensions/Extended_author/language/en_UK/description.txt	(revision 11819)
+++ /extensions/Extended_author/language/en_UK/description.txt	(revision 11819)
@@ -0,0 +1,3 @@
+Provides dropdown for the author, and gives the author the possibility to have a default copyright.
+
+This plugin requires the Copyrigts plugin to be installed.
Index: /extensions/Extended_author/language/en_UK/index.php
===================================================================
--- /extensions/Extended_author/language/en_UK/index.php	(revision 11819)
+++ /extensions/Extended_author/language/en_UK/index.php	(revision 11819)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/Extended_author/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/Extended_author/language/en_UK/plugin.lang.php	(revision 11819)
+++ /extensions/Extended_author/language/en_UK/plugin.lang.php	(revision 11819)
@@ -0,0 +1,10 @@
+<?php
+
+$lang['Author'] = 'Author';
+$lang['Create author'] = 'Create author';
+$lang['Edit author'] = 'Edit author';
+$lang['Update author'] = 'Update author';
+$lang['This author already exists.'] = 'This author already exists.';
+$lang['To install this plugin, you need to install the <a href="http://piwigo.org/ext/extension_view.php?eid=537">Copyrights plugin</a> first.'] = 'To install this plugin, you need to install the <a href="http://piwigo.org/ext/extension_view.php?eid=537">Copyrights plugin</a> first.';
+
+?>
Index: /extensions/Extended_author/language/index.php
===================================================================
--- /extensions/Extended_author/language/index.php	(revision 11819)
+++ /extensions/Extended_author/language/index.php	(revision 11819)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/Extended_author/language/nl_NL/description.txt
===================================================================
--- /extensions/Extended_author/language/nl_NL/description.txt	(revision 11819)
+++ /extensions/Extended_author/language/nl_NL/description.txt	(revision 11819)
@@ -0,0 +1,3 @@
+Zorgt voor een dropdown voor de auteur, en geeft de auteur de mogelijkheid om een standaard copyright te hebben.
+
+Voor deze plugin is het nodig dat de Copyrights plugin geinstalleerd is.
Index: /extensions/Extended_author/language/nl_NL/index.php
===================================================================
--- /extensions/Extended_author/language/nl_NL/index.php	(revision 11819)
+++ /extensions/Extended_author/language/nl_NL/index.php	(revision 11819)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/Extended_author/language/nl_NL/plugin.lang.php
===================================================================
--- /extensions/Extended_author/language/nl_NL/plugin.lang.php	(revision 11819)
+++ /extensions/Extended_author/language/nl_NL/plugin.lang.php	(revision 11819)
@@ -0,0 +1,10 @@
+<?php
+
+$lang['Author'] = 'Auteur';
+$lang['Create author'] = 'Maak auteur';
+$lang['Edit author'] = 'Bewerk auteur';
+$lang['Update author'] = 'Update auteur';
+$lang['This author already exists.'] = 'Deze auteur bestaat al.';
+$lang['To install this plugin, you need to install the <a href="http://piwigo.org/ext/extension_view.php?eid=537">Copyrights plugin</a> first.'] = 'Om deze plugin te installeren, moet je eerst de <a href="http://piwigo.org/ext/extension_view.php?eid=537">Copyrights plugin</a> installeren.';
+
+?>
Index: /extensions/Extended_author/main.inc.php
===================================================================
--- /extensions/Extended_author/main.inc.php	(revision 11819)
+++ /extensions/Extended_author/main.inc.php	(revision 11819)
@@ -0,0 +1,94 @@
+<?php
+/*
+Plugin Name: Extended_author
+Version: 1.0
+Description: Provide information about authors and default copyright (Copyrights plugin is nescessary).
+Plugin URI: http://piwigo.org/ext/revision_add.php?eid=571
+Author: Mattias & J.Commelin (dwo)
+*/
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+define('E_AUTHOR_PATH', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)) . '/');		 // The plugin path
+define('E_AUTHOR_WEB_PATH', get_root_url().'admin.php?page=plugin-Extended_author'); // The path used in admin.php
+
+global $prefixeTable;
+define('AUTHORS', $prefixeTable.'author_extended');				// The db
+define('IMAGES', $prefixeTable.'images');						// The db
+//define('EA_COPYRIGHTS_MEDIA', $prefixeTable.'copyrights_media');	// The db
+//define('EA_COPYRIGHTS_ADMIN', $prefixeTable.'copyrights_admin');	// The db
+
+include_once(E_AUTHOR_PATH . 'include/functions.inc.php');
+
+
+/* +-----------------------------------------------------------------------+
+ * | Plugin admin                                                          |
+ * +-----------------------------------------------------------------------+ */
+
+// Add an entry to the plugins menu
+add_event_handler('get_admin_plugin_menu_links', 'e_author_admin_menu');
+function e_author_admin_menu($menu) {
+  array_push(
+    $menu,
+    array(
+      'NAME'  => 'Extended author',
+      'URL'   => get_admin_plugin_menu_link(dirname(__FILE__)).'/admin.php'
+    )
+  );      
+  return $menu;
+}
+
+
+/* +-----------------------------------------------------------------------+
+ * | Plugin image                                                          |
+ * +-----------------------------------------------------------------------+ */
+
+// Add the author information to the picture's description
+include_once(dirname(__FILE__).'/image.php');
+
+
+/* +-----------------------------------------------------------------------+
+ * | Plugin batchmanager                                                   |
+ * +-----------------------------------------------------------------------+ */
+
+// With the batchmanager, authors can be assigned to photos. There are two
+// modes: Global mode, for mass assignment; Unit mode, for one by one
+// assignment to the photos.
+
+// Global mode
+include_once(dirname(__FILE__).'/batch_global.php');
+
+// Unit mode
+include_once(dirname(__FILE__).'/batch_single.php');
+
+
+/* +-----------------------------------------------------------------------+
+ * | Plugin picture_modify                                                 |
+ * +-----------------------------------------------------------------------+ */
+
+// Add the author dropdown menu to picture_modify
+include_once(dirname(__FILE__).'/modify.php');
+
+
+?>
Index: /extensions/Extended_author/maintain.inc.php
===================================================================
--- /extensions/Extended_author/maintain.inc.php	(revision 11819)
+++ /extensions/Extended_author/maintain.inc.php	(revision 11819)
@@ -0,0 +1,90 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+function plugin_install($plugin_id, $plugin_version, &$errors) {
+  global $conf, $prefixeTable;
+  load_language('plugin.lang', dirname(__FILE__).'/');
+  
+  // Check if the copyrights plugin is there
+  $query = '
+    SELECT `id`
+	FROM '.$prefixeTable.'plugins
+	WHERE id=\'Copyrights\'
+    ;';
+  $result = pwg_query($query);
+  // if not, cancel the install
+  if (!pwg_db_fetch_assoc($result)) {
+	$msg = l10n('To install this plugin, you need to install the <a href="http://piwigo.org/ext/extension_view.php?eid=537">Copyrights plugin</a> first.');
+	if(is_array($errors)) {
+	  array_push($errors, $msg);
+	} else {
+	  $errors=Array($msg);
+	}
+	return false;
+  }
+  
+  // Create the author table
+  $query = '
+    CREATE TABLE IF NOT EXISTS '.$prefixeTable.'author_extended (
+	  author_id int(11) NOT NULL AUTO_INCREMENT,
+      name varchar(255) UNIQUE NOT NULL,
+      url varchar(255),
+      descr text DEFAULT NULL,
+	  copyright int(11) DEFAULT NULL,
+      PRIMARY KEY (author_id)
+    ) ENGINE=MyISAM DEFAULT CHARACTER SET utf8
+    ;';
+  pwg_query($query);
+  
+  // Temporary disable the auto increment
+  $query = '
+	ALTER TABLE '.$prefixeTable.'copyrights_admin
+	MODIFY cr_id int(11) NOT NULL
+    ;';
+  pwg_query($query);
+  // Insert "author's default copyright" in the copyrights table. On duplicates, it does nothing.
+  $query = '
+	INSERT INTO '.$prefixeTable.'copyrights_admin
+	VALUES (-1, \'Author\'s default copyright\', \'\', \'This is the default copyright for an author.\', 1)
+	ON DUPLICATE KEY UPDATE cr_id = -1
+    ;';
+  pwg_query($query);
+  // Reenable the auto increment
+  $query = '
+	ALTER TABLE '.$prefixeTable.'copyrights_admin
+	MODIFY cr_id int(11) NOT NULL AUTO_INCREMENT
+    ;';
+  pwg_query($query);
+}
+
+function plugin_uninstall() {
+  global $prefixeTable;
+  
+  // Drop the author table
+  $query = '
+    DROP TABLE '.$prefixeTable.'author_extended
+    ;';
+  pwg_query($query);
+}
+
+?>
Index: /extensions/Extended_author/modify.php
===================================================================
--- /extensions/Extended_author/modify.php	(revision 11819)
+++ /extensions/Extended_author/modify.php	(revision 11819)
@@ -0,0 +1,107 @@
+<?php
+
+// Add a prefilter
+add_event_handler('loc_begin_admin', 'EA_set_prefilter_modify', 50 );
+add_event_handler('loc_begin_admin', 'EA_modify_submit', 46 );	// CR weight + 1
+
+// Change the variables used by the function that changes the template
+add_event_handler('loc_begin_admin', 'EA_add_modify_vars_to_template');
+
+function EA_set_prefilter_modify()
+{
+	global $template;
+	$template->set_prefilter('picture_modify', 'EA_modify');
+}
+
+function EA_modify($content, &$smarty)
+{
+	// Replace the piwigo author by our own author stuff
+	$search = '/<td><input type="text" class="large" name="author".*?<\/td>/is';
+
+	$replacement = '<td>
+			<select id="author" name="author">
+				<option value="">--</option>
+			{foreach from=$EAoptions item=option}
+				<option value="{$option}"{if $EAname == $option} selected="selected"{/if}>
+					{$option}
+				</option>
+			{/foreach}
+			</select>
+		</td>';
+
+	return preg_replace($search, $replacement, $content);
+}
+
+function EA_add_modify_vars_to_template()
+{
+	// Check if we are at the modify page (the problem is that this will send the stuff to every admin page that has an ?image_id...
+	if (isset($_GET['image_id']))
+	{
+		global $template;
+
+		load_language('plugin.lang', dirname(__FILE__).'/');
+
+		// Fetch all the authors and assign them to the template
+		$query = sprintf(
+			'SELECT `author_id`,`name`
+			FROM %s
+			;',
+			AUTHORS);
+		$result = pwg_query($query);
+
+		$EAoptions = array();
+		while ($row = pwg_db_fetch_assoc($result)) {
+			$EAoptions[$row['author_id']] = $row['name'];
+		}
+		$template->assign('EAoptions', $EAoptions);
+		
+		// Get the current author
+		$image_id = $_GET['image_id'];
+		$query = sprintf(
+			'SELECT author
+			FROM %s
+			WHERE id = %d
+			;',
+			IMAGES, $image_id);
+		$result = pwg_query($query);
+		
+		$EAname = '--'; // Default is '--'
+		while ($row = pwg_db_fetch_assoc($result)) {
+			$EAname = $row['author'];
+		}
+		$template->assign('EAname', $EAname);
+	}
+}
+
+function EA_modify_submit()
+{
+	// Check if we are at the modify page (the problem is that this will send the stuff to every admin page that has an ?image_id...
+	if (isset($_GET['image_id']))
+	{
+		if (isset($_POST['submit']))
+		{
+			// The data from the submit
+			$image_id = $_GET['image_id'];
+			$name = pwg_db_real_escape_string($_POST['author']);
+			
+			// Dont update anything when the name is empty
+			if(!$name)
+				return false;
+			
+			// Add him to the images table
+			// (yes, this is double work, since the author will be set by the piwigo core. But its not set right now, and insert_default_CR needs it...)
+			$query = sprintf(
+				'UPDATE %s
+				SET author=\'%s\'
+				WHERE id=%d
+				;',
+				IMAGES, $name, $image_id);
+			pwg_query($query);
+			
+			// Insert the default copyrights
+			insert_default_CR($name);
+		}
+	}
+}
+
+?>
