PEEL Shopping
Open source ecommerce : PEEL Shopping
fonctions.php
Go to the documentation of this file.
1 <?php
2 // This file should be in UTF8 without BOM - Accents examples: éèê
3 // +----------------------------------------------------------------------+
4 // | Copyright (c) 2004-2015 Advisto SAS, service PEEL - contact@peel.fr |
5 // +----------------------------------------------------------------------+
6 // | This file is part of PEEL Shopping 8.0.0, which is subject to an |
7 // | opensource GPL license: you are allowed to customize the code |
8 // | for your own needs, but must keep your changes under GPL |
9 // | More information: https://www.peel.fr/lire/licence-gpl-70.html |
10 // +----------------------------------------------------------------------+
11 // | Author: Advisto SAS, RCS 479 205 452, France, https://www.peel.fr/ |
12 // +----------------------------------------------------------------------+
13 // $Id: fonctions.php 46935 2015-09-18 08:49:48Z gboussin $
14 if (!defined('IN_PEEL')) {
15  die();
16 }
17 
25  if (mt_rand(1, 10000) == 5000 && !check_if_module_active('crons')) {
27  }
28 }
29 
39 function securityCodeCreate($code, $fileName, $noise_level = null, $noise_max_size = 3)
40 {
41  // Paramètres
42  $font = $GLOBALS['dirroot'] . "/modules/captcha/security_codes/bkant.ttf";
43  if($noise_level === null) {
44  $noise_level = 1000;
45  }
46  $fontSize = 25;
47  $imageWidth = 200;
48  $imageHeight = 70;
49  // Create image
50  $image = imagecreatetruecolor($imageWidth, $imageHeight);
51  // On crée une image
52  $colorWhite = imagecolorallocate($image, 255, 255, 255);
53  $colorBlack = imagecolorallocate($image, 0, 0, 0);
54  // On la remplit de blanc
55  imagefill($image, 0, 0, $colorWhite);
56  $x = mt_rand(15, 20);
57  $y = mt_rand(0, 7);
58 
59  for ($i = 0; $i < String::strlen($code); $i++) {
60  $x_rand = mt_rand(32, 37) * $i + 20;
61  $y_rand = mt_rand(35, 55);
62  $f_rand = mt_rand(-30, 30);
63  $color = imagecolorallocate($image, mt_rand(30, 100), mt_rand(30, 100), mt_rand(30, 100));
64  imagettftext ($image, $fontSize, $f_rand, $x_rand, $y_rand, $color, $font, $code{$i});
65  }
66  for($i = 1;$i <= $noise_level;$i++) {
67  // Boucle pour faire $noise_level points de $color
68  $x = mt_rand(0, $imageWidth);
69  $y = mt_rand(0, $imageHeight);
70  $color = imagecolorallocate($image, mt_rand(0, 180), mt_rand(0, 180), mt_rand(0, 180));
71  if (rand(1, 5) > 1) {
72  imagesetpixel($image, $x, $y, $color);
73  } else {
74  $size = rand(1, $noise_max_size);
75  imagefilledarc($image, $x, $y, $size, $size, 0, 360, $color, IMG_ARC_PIE);
76  }
77  }
78 
79  imagepng($image, $fileName);
80  imagedestroy($image);
81 }
82 
90 {
91  $output = '';
92  // Code security
93  $codeSecurityPath = '/modules/captcha/security_codes/' . '%s.png';
94  $generateNewCode = false;
95 
96  if (empty($frm['code_id'])) {
97  $generateNewCode = true;
98  } elseif (isset($frm['form_regenerate_code']) && $frm['form_regenerate_code'] == '1') {
99  $generateNewCode = true;
100  } else {
101  $test = sprintf($GLOBALS['dirroot'] . $codeSecurityPath, $frm['code_id']);
102  if (!file_exists($test)) {
103  $generateNewCode = true;
104  } else {
105  $code_id = $frm['code_id'];
106  $codeSecurityPath = sprintf($codeSecurityPath, $code_id);
107  }
108  }
109 
110  if ($generateNewCode === true) {
111  // Réinitialisation de la donnée du formulaire
112  $frm['code'] = null;
113  $code = '';
114  while ($code < 10000) {
115  $n = mt_rand(0, 9);
116  if ($n != 1 && $n != 7 && ($code !== '' || $n != 0)) {
117  // On ne prend pas de 1 ou de 7 pour éviter confusions
118  $code .= $n;
119  }
120  }
121  query('INSERT INTO peel_security_codes
122  SET code="' . nohtml_real_escape_string($code) . '", time="' . time() . '"');
123  $code_id = insert_id();
124  $codeSecurityPath = sprintf($codeSecurityPath, $code_id);
125  securityCodeCreate($code, $GLOBALS['dirroot'] . $codeSecurityPath, vn($GLOBALS['site_parameters']['captcha_noise_level'], 1000), vn($GLOBALS['site_parameters']['captcha_noise_max_size'], 2));
126  }
127 
128  $output .= '<img src="' . $GLOBALS['wwwroot'] . $codeSecurityPath . '" alt="Captcha" class="well" style="padding:0px; margin-bottom:0px" /><input type="hidden" name="code_id" value="' . intval($code_id) . '" />';
129  return $output;
130 }
131 
138 function check_captcha($code, $id)
139 {
140  $q_code = query('SELECT COUNT(*)
141  FROM peel_security_codes
142  WHERE id="' . nohtml_real_escape_string($id) . '" AND code="' . nohtml_real_escape_string($code) . '"');
143  if ($r_code = fetch_row($q_code)) {
144  return $r_code[0];
145  } else {
146  return false;
147  }
148 }
154 function delete_captcha($form_object_id)
155 {
156  $codeSecurityPath = $GLOBALS['dirroot'] . '/modules/captcha/security_codes/' . $form_object_id . '.png';
157 
158  query('DELETE
159  FROM peel_security_codes
160  WHERE id="' . nohtml_real_escape_string($form_object_id) . '"');
161  @unlink($codeSecurityPath);
162 }
163 
170 function clean_security_codes($older_than_hours = 4)
171 {
172  // On supprime tout ce qui dépasse $older_than_hours heures
173  query('DELETE FROM peel_security_codes
174  WHERE time<="' . intval(time() - 3600 * $older_than_hours) . '"');
175  $dir = $GLOBALS['dirroot'] . '/modules/captcha/security_codes/';
176  $i = 0;
177  if ($handle = opendir($dir)) {
178  while (false !== ($file = readdir($handle))) {
179  // On supprime les anciens fichiers de plus de $older_than_hours heures qui ne sont pas des fichiers de typo (.ttf)
180  if ($file != '.' && $file != '..' && $file[0] != '.' && String::strpos($file, '.ttf') === false && filemtime($dir . $file) < time() - 3600 * $older_than_hours) {
181  @unlink($dir . $file);
182  $i++;
183  }
184  }
185  }
186  if (!empty($GLOBALS['contentMail'])) {
187  $GLOBALS['contentMail'] .= 'Suppression des fichiers de plus de ' . $older_than_hours . ' heures dans le dossier ' . $dir . ' : ';
188  $GLOBALS['contentMail'] .= 'Ok - ' . $i . ' fichiers supprimés' . "\r\n\r\n";
189  }
190 }
191 
fetch_row($query_result)
fetch_row()
Definition: database.php:264
if(!empty($GLOBALS['site_parameters']['order_specific_field_titles'])) if(check_if_module_active('socolissimo')&&!empty($_REQUEST)&&!empty($_REQUEST['PUDOFOID'])&&!empty($_REQUEST['CEEMAIL'])&&!empty($_REQUEST['SIGNATURE'])&&!empty($_REQUEST['ORDERID'])) elseif(!empty($_POST)) elseif(check_if_module_active('socolissimo')&&!empty($_SESSION['session_commande']['is_socolissimo_order'])) foreach(array('bill'=> 1, 'ship'=> 2) as $address_type=> $session_commande_address_id) $frm['societe1']
static strpos($haystack, $needle, $offset=0)
Returns the numeric position of the first occurrence of needle in the haystack string.
Definition: String.php:54
get_captcha_inside_form(&$frm)
get_captcha_inside_form()
Definition: fonctions.php:89
check_captcha($code, $id)
Definition: fonctions.php:138
if(!defined('IN_PEEL')) captcha_hook_close_page_generation($params)
Traitement de la fin de la génération d'une page.
Definition: fonctions.php:24
delete_captcha($form_object_id)
Definition: fonctions.php:154
insert_id($database_object=null)
insert_id()
Definition: database.php:339
static strlen($string)
Returns the length of the given string.
Definition: String.php:36
nohtml_real_escape_string($value, $allowed_tags=null)
Protège les données pour insertion dans MySQL ET supprime les tags HTML pour protéger de toute sorte ...
Definition: database.php:400
if(!defined('IN_PEEL')) $GLOBALS['page_types_array']
Definition: fonctions.php:19
clean_security_codes($older_than_hours=4)
clean_security_codes()
Definition: fonctions.php:170
query($query, $die_if_error=false, $database_object=null, $silent_if_error=false, $security_sql_filter=true)
The query() function is meant to be called anywhere you want to make a query.
Definition: database.php:158
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160
securityCodeCreate($code, $fileName, $noise_level=null, $noise_max_size=3)
securityCodeCreate()
Definition: fonctions.php:39
vn(&$var, $default=0)
Variable nulle if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:110
$id
Definition: articles.php:22
check_if_module_active($module_name, $specific_file_name=null)
Renvoie si un module est présent et activé ou non - Peut être appelé avant ou après le chargement d'u...

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:30:55 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.