Location: PHPKode > projects > Yappa-ng > yappa-ng/admin_modules/admin_module_captions.inc.php
<?php

/*
 * ***********************************************************************************************
 * Filename:     admin_module_captions.inc.php
 * Module:       Admin-Module
 * Subcategory:  Change Captions
 * Description:  Creates or Changes the Image Captions (Language specific)
 * ***********************************************************************************************
 *
 *
 * Project:     yappa-ng : yet another php photo album - next generation
 * Author:      Fritz Berger <hide@address.com>
 * Copyright:   2003 Fritz Berger
 * $Header: /cvsroot/yappa-ng/yappa-ng/admin_modules/admin_module_captions.inc.php,v 1.33 2005/04/25 18:02:06 zirkon13 Exp $
 *
 * 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; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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
 *
 * You may contact the author of yappa-ng by e-mail at:
 * hide@address.com
 *
 * The latest version of yappa-ng can be obtained from:
 *    http://www.zirkon.at/zirkon/scripts/yappa-ng/yappa-ng_main_ger.html (german)
 *    http://www.zirkon.at/zirkon/scripts/yappa-ng/yappa-ng_main_eng.html (english)
 *
 * ***********************************************************************************************
 * ***********************************************************************************************
 * ***                                                                                         ***
 * ***   yappa-ng is based on "YAPPA v1.7 devel - 22.April 2002"                               ***
 * ***                         released on http://sourceforge.net/projects/yappa/              ***
 * ***   YAPPA is Copyright Federico 'pix' Feroldi (hide@address.com)                           ***
 * ***   YAPPA is released under the GNU GPL                                                   ***
 * ***                                                                                         ***
 * ***********************************************************************************************
 * ***********************************************************************************************
 */

?>

<?php

/*
 * Standard Security Check
 */

if (!defined('SecCheck')) {
	die("You Cannot Access This Script Directly - Have a Nice Day.");
}


include_once($config['path_src_include'] . "common.inc.php");
include_once($config['path_src_include'] . "check_html.inc.php");

function SetPreviewNumber () {
	global $config, $config_album;
	global $selected_album;


	$admin_form = $_POST['admin_form'];
	$config_album['mini_images_per_page'] = $admin_form['mini_images_per_page'];
	/* write album config */
	$configfilename = singleslash($config["photo_root"] . "/" . $selected_album);
	$returncode = write_albumconf($configfilename, $config_album);
	return $returncode;


}

function HandleForm () {
	global $config;
	global $lang_akt, $lang_used;
	global $page, $album;



	$l_captionhelp[]= array();
	/* read all 'old' captions for ALL images */
	$config['lang_intuitive'] = "no";
	clearstatcache();
	//$album->clear_images_info();
	$album->read_images_info();
	for($i = 0; $i < $page["album_images"]; $i++) {
		$image_name = $album->get_imagename($i);
		$l_captionhelp[$image_name] = $album->get_caption($image_name);
	}
	$savecaption = "";
	for($i = 0; $i < $page["album_images"]; $i++) {
		$image_name = $album->get_imagename($i);
		/* check, if the imagecaption was posted.Because of the page for page viewing only the images of
		* the curretly viewd page gets posted.
		* If it was posted, check it and save it */
		if (isset($_POST['admin_form'][$image_name])) {
			// in the album-info ALL html-tags are forbidden IF it is a demo-gallery
			// else only a hrefs are forbidden!
			if ($config["demo_gallery"] == "yes") {
				$allow_a = "0";
				$allow_html=false;
			} else {
				$allow_html=true;
				/* if you think you want to permit <ahref...> x </a> tags then set it to yes in your config.inc.php ! */
				if ($config['permit_ahref'] != "yes") {
					$allow_a = "0";
				} else {
					$allow_a = "2";
				}
			}
			//$allow_br = false;
			$_lhelp = $_POST['admin_form'][$image_name];
			//$checkhtml_caption = SaveHTML($_lhelp,$allow_html,$allow_a,$allow_br);
			$_lhelp = str_replace("'","\"",$_lhelp);
			$checkhtml_caption = SaveHTML($_lhelp,$allow_html,$allow_a);
			$checkhtml_caption = str_replace("\"","'",$checkhtml_caption);
			//str_replace("\"","'",$checkhtml_caption);
			//str_replace("\"","'",$checkhtml_caption);
			//$checkhtml_caption = htmlentities($checkhtml_caption);
			//$checkhtml_caption = htmlspecialchars($checkhtml_caption);
			$savecaption .= $image_name . "|" .$checkhtml_caption . "\n";
		} else {
			/* else save the old one! */
			$savecaption .= $image_name . "|" .$l_captionhelp[$image_name] . "\n";
		}
	}
	$captionfilename = singleslash($config["photo_root"] . "/" . rawurldecode($_GET["album"]) . "/" . $config['data_dirname'] . "/" . $lang_akt["captions"]);
	$fd = fopen($captionfilename, "w");
	if ($fd) {
		flock($fd, 2); // get an exclusive lock
		fwrite($fd, $savecaption);
		flock($fd, 3); // release the lock
		fclose($fd);
		// log level 1: Administration
		if((int)"1" & (int)$config["loglevel"]) {
			$log_msg = date("U") . "|Administration|" . "AlbumAdmin Edit captions (" . $lang_used . "): &quot;" . $captionfilename . "&quot; captions saved.|" . $_SERVER['REMOTE_ADDR'] . "|-|admin_module_captions.inc.php|" . __LINE__ . "\n";
			@error_log($log_msg, 3, "yappa-ng.log");
		}
		return 1;
	} else {
		// log level: Warning
		if((int)"8" & (int)$config["loglevel"]) {
			$log_msg = date("U") . "|Warning|" . "AlbumAdmin Edit captions (" . $lang_used . "): ERROR in writing captions for album " . $captionfilename . "|" . $_SERVER['REMOTE_ADDR'] . "|-|admin_module_captions.inc.php|" . __LINE__ . "\n";
			@error_log($log_msg, 3, "yappa-ng.log");
		}
		return 2;
	}


}


$uri_base = str_replace("&admintask=Captions","",$global_var['self_url']);

clearstatcache();

$config['lang_intuitive'] = "no";

if(isset($_POST['BeenSubmitted'])) {
	$answer = HandleForm();
	$album->clear_images_info();
	$album->read_images_info();
}

if(isset($_POST['BeenSubmittedPreview'])) {
	$msg = SetPreviewNumber();
}

/* if the preview_per_page is not initialized (eg after upgrade) set it to a default value of 25 */
if($config_album['mini_images_per_page'] < 1 ) {
	$config_album['mini_images_per_page'] = 25;
}

clearstatcache();
$config['lang_intuitive'] = "no";
$album->clear_images_info();
$album->read_images_info();
//$album->read_album_info();
//$page["album_title"] = $album->_album_title;
//$page["album_comment"] = $album->_album_comment;


/* prepare all page-navigation links */
$prevnext = page_pn();

?>
<form action="<?php print $global_var['self_url']; ?>" method="post">
<table cellspacing="0" cellpadding="5" border="0" width="100%">
<tr valign="top">
<td class="thumbnailCell">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
	<tr>
	<tr><td colspan="4">&nbsp;</td></tr>
	<td width="75%">&nbsp;</td>
	<td width="20%" align="right" nowrap="nowrap"><input type="text" name="admin_form[mini_images_per_page]" size="5" value="<?php print $config_album['mini_images_per_page']; ?>"> <?php print $lang_akt["admin_main_perrowtext"]; ?></td>
	<td width="5%" align="left">
		<input type="hidden" name="BeenSubmittedPreview" value="true">
		<input type="submit" name="submit" value="<?php print $lang_akt['submit']; ?>">
	</td>
	<td>&nbsp;</td>
	</tr>
	<tr><td colspan="4"><hr></td></tr>
</table>
</td>
</tr>
</table>
</form>

<form action="<?php print $global_var['self_url']; ?>" method="post">
<table cellspacing="0" cellpadding="5" border="0" width="100%">
<tr valign="top">
<td class="thumbnailCell">
<table width="100%" border="0" cellspacing="0" cellpadding="3">

	<tr><td colspan=4 align="center" class="adminHeading"><?php print $lang_akt["admin_capt_hmain"]; ?></td></tr>
	<tr><td colspan=4 align="center" class="adminComments"><?php print $lang_akt["admin_info_expl1"]; ?></td></tr>
	<tr><td colspan=4 align="center" class="adminComments"><?php print $lang_akt["admin_info_expl2"]; ?></td></tr>
	<tr><td colspan="4" class="passwdAdminCancel" align="center" >
	[ <b><a href="<?php echo $uri_base ?>"><?php echo $lang_akt["passwd_admin_cancel"]; ?></b></a> ]</td></tr>
	<tr><td width="5%">&nbsp;</td><td width="5%">&nbsp;</td><td width="70%">&nbsp;</td><td>&nbsp;</td></tr>
	<tr><td colspan="4" align="center" class="adminStatus">
	<?php if(isset($_POST['BeenSubmitted'])) {
		switch($answer) {
			case 1:
				print $lang_akt["admin_capt_status1"];
				break;
			case 2:
				print $lang_akt["admin_capt_status2"];
				break;
			default:
				print "";
				break;
		}
	} ?>
	</td></tr>
	<tr><td colspan="4">&nbsp;</td></tr>
	<tr><td colspan=4 class="adminDescription"><?php print $lang_akt["admin_capt_titleh"]; ?></td></tr>
	<tr><td colspan=4 class="adminComments"><?php print $lang_akt["admin_capt_titlefull"]; ?></td></tr>

	
	
	

	<!-- next/prev page links - start -->
	<tr><td>&nbsp;</td>
	<td colspan="2">
	<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
	<td width="30%" align="left"><?php
	if($prevnext["navlink_previous"] != "") {
		?><font class="textNavlink"><a href="<?php print $prevnext["navlink_previous"]; ?>"><?php print $lang_akt["previousp"]; ?></a></font><?php
	}
	?></td>
	<td width="40%" align="center">
	<table border="0" cellspacing="1" cellpadding="1"><tr>
	<td><?php if($prevnext["navlink_back"] != "") { ?>
		<font class="textNavlink"><a href="<?php print $prevnext["navlink_back"]; ?>">&lt;&lt;</a>&nbsp;</font>
	<?php } ?></td>
	<?php
	if (@count($prevnext["navlinks"]) > 0) {
		foreach($prevnext["navlinks"] as $navlink) {
			?><td><font class="textNavlink"><?php
			if($navlink["selected"]) {
				print "<b>" . $navlink["page"] . "</b>&nbsp;";
			} else {
				?><a href="<?php print $navlink["link"]; ?>"><?php print $navlink["page"]; ?></a>&nbsp;<?php
			}
			?></font></td><?php
		}
	}
	?>
	<td><?php if($prevnext["navlink_forw"] != "") { ?>
	<font class="textNavlink"><a href="<?php print $prevnext["navlink_forw"]; ?>">&gt;&gt;</a></font>
	<?php } ?></td>
	</tr></table>

	</td>
	<td width="30%" align="right"><?php
	if($prevnext["navlink_next"] != "") {
	?><font class="textNavlink"><a href="<?php print $prevnext["navlink_next"]; ?>"><?php print $lang_akt["nextp"]; ?></a></font><?php
	}
	?></td>
	</tr></table>
	<td>&nbsp;</td></tr>
	<!-- next/prev page links - end -->


	
	
	

	<?php
	if ($page["album_images"] == "0" ) { ?>
		<tr><td colspan="4" align="center" class="adminStatus"><?php echo $lang_akt["admin_modules_noimage"]; ?></td></tr>
	<?php } else {
		for($i = $prevnext['mini_start']; $i < $prevnext['mini_end']; $i++) {
			$image_name = $album->get_imagename($i);
			$caption = $album->get_caption($image_name);
			$nav_icon = nav_icons($selected_album, $image_name);
			?>
			<tr>
			<td class="adminComments" align="right"><?php print $image_name; ?></td>
			<td align="center"><img src="<?php print $nav_icon['src']; ?>" name="<?php print $image_name; ?>" <?php print $nav_icon['size']; ?> alt="<?php print $image_name; ?>"></td>
			<td class="adminSelection"><input type="text" size="50" name="admin_form[<?php print $image_name; ?>]" value="<?php print $caption; ?>"></td>
			<td>&nbsp;</td></tr>
			<?php
		}
	}
	?>


	

	<!-- next/prev page links - start -->
	<tr><td>&nbsp;</td>
	<td colspan="2">
	<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
	<td width="30%" align="left"><?php
	if($prevnext["navlink_previous"] != "") {
		?><font class="textNavlink"><a href="<?php print $prevnext["navlink_previous"]; ?>"><?php print $lang_akt["previousp"]; ?></a></font><?php
	}
	?></td>
	<td width="40%" align="center">
	<table border="0" cellspacing="1" cellpadding="1"><tr>
	<td><?php if($prevnext["navlink_back"] != "") { ?>
		<font class="textNavlink"><a href="<?php print $prevnext["navlink_back"]; ?>">&lt;&lt;</a>&nbsp;</font>
	<?php } ?></td>
	<?php
	if (@count($prevnext["navlinks"]) > 0) {
		foreach($prevnext["navlinks"] as $navlink) {
			?><td><font class="textNavlink"><?php
			if($navlink["selected"]) {
				print "<b>" . $navlink["page"] . "</b>&nbsp;";
			} else {
				?><a href="<?php print $navlink["link"]; ?>"><?php print $navlink["page"]; ?></a>&nbsp;<?php
			}
			?></font></td><?php
		}
	}
	?>
	<td><?php if($prevnext["navlink_forw"] != "") { ?>
	<font class="textNavlink"><a href="<?php print $prevnext["navlink_forw"]; ?>">&gt;&gt;</a></font>
	<?php } ?></td>
	</tr></table>

	</td>
	<td width="30%" align="right"><?php
	if($prevnext["navlink_next"] != "") {
	?><font class="textNavlink"><a href="<?php print $prevnext["navlink_next"]; ?>"><?php print $lang_akt["nextp"]; ?></a></font><?php
	}
	?></td>
	</tr></table>
	<td>&nbsp;</td></tr>
	<!-- next/prev page links - end -->


	
	
	
	

	<tr><td colspan="4">&nbsp;</td></tr>
	<tr><td colspan="4" align="center">
		<input type="hidden" name="BeenSubmitted" value="true">
		<input type="submit" name="submit" value="<?php print $lang_akt['submit']; ?>">
	</td>
	</tr>


</table>
</td>
</tr>
</table>
</form>


<?php



?>
Return current item: Yappa-ng