Source for file xt_picture.class.php
Documentation is available at xt_picture.class.php
*@=@=@=@ START LICENSE @=@=@=@*
Copyright or © or Copr. Stéphane TRICHET and Nicolas SOTRON
stephane.t@simpliciweb.net and nicolas.s@simpliciweb.net
This software is a computer program whose purpose is to make a
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
*@=@=@=@ END LICENSE @=@=@=@*
* @version $Id: xt_picture.class.php 781 2007-12-27 13:07:16Z stephanet $
* Abstract class to manage Pictures
* @version $Id: xt_picture.class.php 781 2007-12-27 13:07:16Z stephanet $
* Database Connexion object
* SQL Request : Select by type
* SQL Request : Delete by type
* SQL Request : Update position by type
* SQL Request : Update desc
* Supported formats string
* Constructor, init the requests and objects
$this->req_insert =
"insert into t_picture(pic_filename,pic_height,pic_width,pic_type,pic_size,".
multilang('pic_desc', TRUE).
", pic_position ) values ('%s', %d, %d, '%s', %d, '%s', '%s');";
$this->req_select_by_type =
"select pic_id, pic_filename, pic_height, pic_width, pic_type, pic_size, ".
multilang('pic_desc').
", pic_position from t_picture where pic_type = '%s';";
$this->req_select =
"select pic_id, pic_filename, pic_height, pic_width, pic_type, pic_size, ".
multilang('pic_desc').
", pic_position from t_picture where pic_id = '%d' and pic_type = '%s';";
$this->req_delete =
"delete from t_picture where pic_id = '%d' and pic_type = '%s';";
$this->req_update_desc =
"update t_picture set ".
multilang('pic_desc', TRUE).
"='%s' where pic_id = '%d' and pic_type = '%s';";
// definition des t_picture que l'on peut accepter
$sf[sizeof($sf)] =
array(1, "GIF", 'imagecreatefromgif');
$sf[sizeof($sf)] =
array(2, "JPG", 'imagecreatefromjpeg');
$sf[sizeof($sf)] =
array(3, "PNG", 'imagecreatefrompng');
$sf[sizeof($sf)] =
array(15, "WBMP", 'imagecreatefromwbmp');
$sf[sizeof($sf)] =
array(16, "XBM", 'imagecreatefromxbm');
$supported_formats_string =
"";
for ($i=
0; $i<
sizeof($sf); $i++
) {
$supported_formats_string .=
", ";
$supported_formats_string .=
$sf[$i][1];
$this->m_types_used['logo_bill_type'] =
"lb"; //logo for bill
$this->m_types_used['product_little_type'] =
"pl"; //prodlittle
$this->m_types_used['product_medium_type'] =
"pm"; //prodmedium
$this->m_types_used['page_little_type'] =
"rl"; //page little
$this->m_types_used['page_medium_type'] =
"rm"; //page medium
* Parameter Integrity checker
* @return bool TRUE if not valid
* Parameter Integrity checker
* @return bool TRUE if not valid
* Parameter Integrity checker
* @return bool TRUE if not valid
* Parameter Integrity checker
* @return bool TRUE if not valid
* Parameter Integrity checker
* @return bool TRUE if not valid
* Parameter Integrity checker
* @return bool TRUE if not valid
* Parameter Integrity checker
* @return bool TRUE if not valid
if ((trim($value) ==
""))
* Parameter Integrity checker
* @return bool TRUE if not valid
if ((trim($value) ==
""))
* Get supported image format
// renvoi false et id=0 : si aucun fichier fourni
// renvoi true : si une erreur est survenue
//$p_form_src : bool - Si le fichier vient d'un formulaire ou pas
* @param string $p_picture_type
* @param array $p_file_array $_FILES
* @param integer $r_result_id
* @param integer $p_next_width
* @param integer $p_next_height
* @param bool $p_only_one_by_type
* @param string $p_pic_position
* @param bool $p_force_resize
* @param bool $p_form_src
* @return bool TRUE on error
function xInsert($p_picture_type, $p_file_array, &$r_result_id, $p_next_width =
0,
$p_only_one_by_type =
false,
$image_type_orig =
$p_picture_type;
if (($p_file_array['error'] !=
0) &&
(trim($p_file_array['name']) !=
"")) {
if ($p_file_array['error'] !=
0 ) {
// aucun fichier fourni donc on ne fait rien
//Essaies de charger la taille de m'image qu'on viend de télécharger
//echo("isn't uploaded file");
// verification du type de l'image
$picture_type =
$size[2];//exif_imagetype($p_file_array['tmp_name']);
//echo("(".$picture_type.")");
$is_supported_image_format =
false;
$to_evaluate_create_image =
"";
for ($i=
0; $i<
sizeof($sf); $i++
) {
if ($picture_type ==
$sf[$i][0]) {
$is_supported_image_format =
true;
$ext_src =
$sf[$i][1]; // Set source picture extension
$to_evaluate_create_image =
$sf[$i][2];
if (!$is_supported_image_format) {
//echo("not supported file format");
$current_width =
$size[0];
$current_height =
$size[1];
$must_destroy_temp_file =
false;
$have_got_to_resize =
false;
if ((( $current_width <=
$p_next_width) &&
($current_height <=
$p_next_height)) &&
!$p_force_resize)
$have_got_to_resize =
false;
$have_got_to_resize =
true;
if ((($p_next_width ==
0) &&
($p_next_height ==
0)))
$have_got_to_resize =
false;
if ($have_got_to_resize) {
$width_ratio =
$p_next_width/
$current_width;
$height_ratio =
$p_next_height/
$current_height;
if ($p_next_height ==
0) {
} else if ($p_next_width ==
0) {
if ($width_ratio <
$height_ratio)
$new_width =
$ratio*
$current_width;
$new_height =
$ratio*
$current_height;
// Determine destination extension
$ext_dst =
""; // After this switch can be only have 2 value:: GIF or JPG
// Can create gif for output
// Set source image in $src_im var
eval
("\$src_im = ".
$to_evaluate_create_image.
"(\$p_file_array['tmp_name']);");
$next_name =
$p_file_array['tmp_name'].
'_resized.'.
strtolower($ext_dst);
// Create picture by type
// Transform picture in reduce gif picture
// Create destination image
imagecopyresampled ($dst_im, $src_im, 0, 0, 0, 0, $new_width, $new_height, $current_width, $current_height);
imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $new_width, $new_height, $current_width, $current_height );
// Transform picture in reduce jpg picture
// Create destination image
imagecopyresampled ($dst_im, $src_im, 0, 0, 0, 0, $new_width, $new_height, $current_width, $current_height);
imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $new_width, $new_height, $current_width, $current_height );
// Replace picture by rezised picture
$p_file_array['tmp_name'] =
$next_name;
$p_file_array['size'] =
filesize($next_name);
$must_destroy_temp_file =
true;
// Reload size of resized picture
unlink($p_file_array['tmp_name']);
// Free memory used by picture transformation
// Don't change the extension
$stamp =
$array_stamp[0];
//Faut boucler sinon c'est trop rapide et on peut avoir 2 ids ==
for ($i=
0; $i<
1000; $i++
) {
$picture_id =
$stamp.
"-".
$_SERVER["REMOTE_ADDR"];
$upload_filename =
$p_picture_type.
'_'.
$size[0].
'_'.
$size[1].
'_'.
$p_file_array['size'].
'_'.
$picture_id.
'.'.
strtolower($ext_dst);
$upload_file =
$upload_dir.
$upload_filename;
// echo($p_file_array['tmp_name']."<br />");
// echo($upload_file."<br />");
if (!copy($p_file_array['tmp_name'], $upload_file)) {
if ($must_destroy_temp_file)
unlink($p_file_array['tmp_name']);
// si le fichier doit être le seul à avoir ce type en BD
if ($p_only_one_by_type) {
if ($must_destroy_temp_file)
unlink($p_file_array['tmp_name']);
$parameters[sizeof($parameters)] =
$upload_filename;
$parameters[sizeof($parameters)] =
$size[1];
$parameters[sizeof($parameters)] =
$size[0];
$parameters[sizeof($parameters)] =
$p_picture_type;
$parameters[sizeof($parameters)] =
$p_file_array['size'];
$parameters[sizeof($parameters)] =
$p_desc;
$parameters[sizeof($parameters)] =
$p_pic_position;
if ($must_destroy_temp_file)
unlink($p_file_array['tmp_name']);
if ($must_destroy_temp_file)
unlink($p_file_array['tmp_name']);
//On va stocker l'identifiant de l'image apres son insertion
//$this->setId(mysql_insert_id());
* @param string $p_picture_type
* @param string $p_database_selected
* @return bool TRUE on error
function xGetByType($p_picture_type, &$r_result, $p_database_selected=
"") {
$parameters[sizeof($parameters)] =
$p_picture_type;
$sousTableaux['pic_id'] =
$row[0];
$sousTableaux['pic_filename'] =
$row[1];
$sousTableaux['pic_height'] =
$row[2];
$sousTableaux['pic_width'] =
$row[3];
$sousTableaux['pic_type'] =
$row[4];
$sousTableaux['pic_size'] =
$row[5];
$sousTableaux['pic_position'] =
$row[7];
//$sousTableaux['pic_file_path'] = $this->m_object_siteinformation->getPictureFilePath().$row[1];
//$sousTableaux['pic_file_path'] = $this->m_object_siteinformation->getViewRootPath();
if (""==
$p_database_selected)
//$sousTableaux['pic_file_path'] .= $row[1];
$r_result[sizeof($r_result)] =
$sousTableaux;
* Provide an array with all the picture properties
* Va renvoyer un tableaux contenant toutes les informations necessaires à l'affichage d'une image
* int : represente l'identifiant de l'image
* @param string $p_picture_type
* @return bool TRUE on error
function xGet($id, $p_picture_type, &$r_result) {
//echo "\n<br />Debug - Class image - Recherche image par Id : ".$id;
// Detect if site is in website group
$master_website_group =
"";
$object_databaseconnect =
& $g_object_loader->getDatabaseconnectSa();
if ($object_databaseconnect->getSiteName($sitename, $master_website_group))
$sitename =
"http://".
$sitename;
else $sitename =
"http://".
$object_databaseconnect->getDbcSitenamePrefixForLocal().
$sitename;
// il faudra changer les informations de la picture pas d'image
// les lire dans le fichier no_photo.gif
// et mettre les params en variables membres
$r_result['pic_height'] =
'83';
$r_result['pic_width'] =
'82';
//echo_net($this->m_object_siteinformation->getIHavePersonalNoPhoto()?"oui":"non");
//echo_net($r_result['pic_http_path']);
$parameters[sizeof($parameters)] =
$id;
$parameters[sizeof($parameters)] =
$p_picture_type;
$r_result['pic_id'] =
$row[0];
$r_result['pic_filename'] =
$row[1];
$r_result['pic_height'] =
$row[2];
$r_result['pic_width'] =
$row[3];
$r_result['pic_type'] =
$row[4];
$r_result['pic_size'] =
$row[5];
$r_result['pic_position'] =
$row[7];
* Update position by type
* @param string $p_picture_type
* @param string $p_new_position
* @return bool TRUE on error
// suppression logique des t_picture en BD
$parameters[sizeof($parameters)] =
$p_new_position;
$parameters[sizeof($parameters)] =
$p_picture_type;
* @param string $p_picture_type
* @return bool TRUE on error
$orig_picture_type =
$p_picture_type;
// suppression physique des fichiers
$file_to_delete =
array();
$this->xGetByType($orig_picture_type, $file_to_delete);
for ($i=
0; $i<
sizeof($file_to_delete); $i++
) {
@unlink($file_to_delete[$i]['pic_file_path']);
// suppression logique des t_picture en BD
$parameters[sizeof($parameters)] =
$p_picture_type;
* @param integer $p_picture_id
* @param string $p_picture_type
* @return bool TRUE on error
function xDelete($p_picture_id, $p_picture_type) {
//echo("Avant le delete <br />");
$picture_orig_type =
$p_picture_type;
//echo("après verification <br />");
// suppression physique des fichiers
$file_to_delete =
array();
$this->xGet($p_picture_id, $picture_orig_type, $file_to_delete);
if ((0<
strlen(trim($file_to_delete['pic_file_path']))) &&
(file_exists($file_to_delete['pic_file_path'])))
if (!@unlink($file_to_delete['pic_file_path']))
trigger_error("PLICI - Unable to delete: *".
$file_to_delete['pic_file_path'].
"*");
//echo("après get et unlink <br />");
// suppression logique des t_picture en BD
$parameters[sizeof($parameters)] =
$p_picture_id;
$parameters[sizeof($parameters)] =
$p_picture_type;
* @param string $p_picture_type
* @return bool TRUE on error
function xUpdateDesc($p_id, $p_picture_type, $p_desc) {
$picture_orig_type =
$p_picture_type;
//echo("$p_desc, $p_id, $p_picture_type<br />");
$parameters[sizeof($parameters)] =
$p_desc;
$parameters[sizeof($parameters)] =
$p_id;
$parameters[sizeof($parameters)] =
$p_picture_type;
* @param array $p_array_picture
* @param integer $p_next_width
* @param integer $p_next_height
* @param integer $r_ratio
* @return bool TRUE on error
function getRatio($p_array_picture, $p_next_width, $p_next_height, &$r_ratio) {
$ratio1 =
$p_next_width/
$p_array_picture['pic_width'];
$ratio2 =
$p_next_height/
$p_array_picture['pic_height'];
Documentation generated on Tue, 25 Mar 2008 15:37:37 +0100 by phpDocumentor 1.3.2