[8771] | 1 | <?php |
---|
| 2 | global $user, $conf; |
---|
| 3 | |
---|
[19968] | 4 | class Piwecard { |
---|
[20088] | 5 | var $config; |
---|
[8771] | 6 | var $user_groups = array(); |
---|
| 7 | |
---|
[20431] | 8 | /** |
---|
| 9 | * Constructor |
---|
| 10 | */ |
---|
[19956] | 11 | function __construct() { |
---|
[20032] | 12 | $this->get_config(); |
---|
[8771] | 13 | } |
---|
| 14 | |
---|
[20431] | 15 | /** |
---|
| 16 | * Load configuration from database |
---|
| 17 | * Assign value to the variable $config |
---|
| 18 | */ |
---|
[20032] | 19 | function get_config() { |
---|
[19956] | 20 | $query = 'SELECT value FROM '.CONFIG_TABLE.' WHERE param="piwecard";'; |
---|
[8771] | 21 | $result = pwg_query($query); |
---|
| 22 | |
---|
[19732] | 23 | if(isset($result)) { |
---|
[19968] | 24 | $row = pwg_db_fetch_row($result); |
---|
[19732] | 25 | if(is_string($row[0])) { |
---|
[20088] | 26 | $this->config = unserialize(($row[0])); |
---|
[19732] | 27 | } |
---|
[8771] | 28 | } |
---|
[20032] | 29 | $this->get_default_config(); |
---|
[8771] | 30 | } |
---|
| 31 | |
---|
[20431] | 32 | /** |
---|
| 33 | * Load default configuration from the install directory |
---|
| 34 | * Assign value to the variable $config |
---|
| 35 | */ |
---|
[20032] | 36 | private function get_default_config() { |
---|
[20059] | 37 | require(PIWECARD_INSTALL_PATH.'default_values.inc.php'); |
---|
[19732] | 38 | foreach ($ecard_default_values as $key => $value) { |
---|
[20088] | 39 | if (!isset($this->config[$key])) |
---|
| 40 | $this->config[$key] = $value; |
---|
[8771] | 41 | } |
---|
| 42 | } |
---|
| 43 | |
---|
[20431] | 44 | /** |
---|
| 45 | * Get the default value of a parameter |
---|
| 46 | * @param name of the parameter |
---|
| 47 | * @return the default config of the parameter |
---|
| 48 | */ |
---|
[20202] | 49 | function get_default_config_param($param) { |
---|
| 50 | require(PIWECARD_INSTALL_PATH.'default_values.inc.php'); |
---|
| 51 | return $ecard_default_values[$param]; |
---|
| 52 | } |
---|
| 53 | |
---|
[20431] | 54 | /** |
---|
| 55 | * Save the current configuration (ie the value of $config) to the database |
---|
| 56 | */ |
---|
[20032] | 57 | function set_config() { |
---|
[20088] | 58 | conf_update_param('piwecard', pwg_db_real_escape_string(serialize($this->config))); |
---|
[8771] | 59 | } |
---|
| 60 | |
---|
[20431] | 61 | /** |
---|
| 62 | * Initialize the section parameter of the page |
---|
| 63 | */ |
---|
[19732] | 64 | function section_init_ecard() { |
---|
[8771] | 65 | global $tokens, $page; |
---|
[19732] | 66 | |
---|
[8771] | 67 | if ($tokens[0] == 'ecard') |
---|
[19732] | 68 | $page['section'] = 'ecard'; |
---|
[8771] | 69 | } |
---|
| 70 | |
---|
[20431] | 71 | /** |
---|
| 72 | * Load the ecard |
---|
| 73 | */ |
---|
[19732] | 74 | function index_ecard() { |
---|
[20431] | 75 | global $page; |
---|
[19732] | 76 | if (isset($page['section']) and $page['section'] == 'ecard') { |
---|
[20032] | 77 | include('publish.inc.php'); |
---|
[8771] | 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
[20431] | 81 | /** |
---|
| 82 | * Get a random string |
---|
| 83 | * @param Integer number of caracter of the random string |
---|
| 84 | * @return String the random string |
---|
| 85 | */ |
---|
[8771] | 86 | private function random($car) { |
---|
[19732] | 87 | $string = ""; |
---|
| 88 | $chaine = "abcdefghijklmnpqrstuvwxy0123456789"; |
---|
| 89 | srand((double)microtime()*1000000); |
---|
| 90 | for($i=0; $i<$car; $i++) { |
---|
| 91 | $string .= $chaine[rand()%strlen($chaine)]; |
---|
| 92 | } |
---|
| 93 | return $string; |
---|
[8771] | 94 | } |
---|
| 95 | |
---|
[20431] | 96 | /** |
---|
| 97 | * Parse the message |
---|
| 98 | * @param String string to parse |
---|
| 99 | * @param Array parser parameters |
---|
| 100 | * @param Array an array with the id and the url of the image |
---|
| 101 | * @return String the parsed string |
---|
| 102 | */ |
---|
[20180] | 103 | function parse($data, $values, $image_element) { |
---|
[20421] | 104 | include (PIWECARD_PATH.'include/parse_param.inc.php'); |
---|
[8771] | 105 | |
---|
| 106 | $patterns = array(); |
---|
| 107 | $replacements = array(); |
---|
[19956] | 108 | foreach ($ecard_parse as $key => $value) { |
---|
[8771] | 109 | array_push($patterns, $key); |
---|
| 110 | array_push($replacements, $value); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | return str_replace($patterns, $replacements, $data); |
---|
| 114 | } |
---|
| 115 | |
---|
[20431] | 116 | /** |
---|
| 117 | * Get the number of ecards in the database |
---|
| 118 | * @return Integer number of ecards |
---|
| 119 | */ |
---|
[19732] | 120 | function get_nb_ecard() { |
---|
[20202] | 121 | $query = 'SELECT COUNT(DISTINCT ecard_id) AS nb FROM '.PIWECARD_TABLE.' ORDER BY date_creation;'; |
---|
[8771] | 122 | $result = pwg_query($query); |
---|
[19956] | 123 | |
---|
[19732] | 124 | if ($result) { |
---|
[19968] | 125 | $nb=pwg_db_fetch_assoc($result); |
---|
[8771] | 126 | return $nb['nb']; |
---|
[19956] | 127 | } else |
---|
[8771] | 128 | return 0; |
---|
| 129 | } |
---|
| 130 | |
---|
[20431] | 131 | /** |
---|
| 132 | * Get the number of validecards in the database |
---|
| 133 | * @return Integer number of valid ecards |
---|
| 134 | */ |
---|
[19732] | 135 | function get_nb_valid_ecard() { |
---|
[20202] | 136 | $query = 'SELECT COUNT(DISTINCT ecard_id) AS nb FROM '.PIWECARD_TABLE.' WHERE date_validity IS NULL OR date_validity > NOW();'; |
---|
[8771] | 137 | $result = pwg_query($query); |
---|
[19956] | 138 | |
---|
| 139 | if ($result) { |
---|
[19968] | 140 | $nb=pwg_db_fetch_assoc($result); |
---|
[19956] | 141 | return $nb['nb']; |
---|
| 142 | } else |
---|
| 143 | return 0; |
---|
[8771] | 144 | } |
---|
| 145 | |
---|
[20431] | 146 | /** |
---|
| 147 | * Get ecard informations into an array |
---|
| 148 | * @param Integer ecard id |
---|
| 149 | * @return Array informations of the ecard |
---|
| 150 | */ |
---|
| 151 | function get_ecard($ecard_id) { |
---|
[19732] | 152 | if ($ecard_id!== null) { |
---|
[20202] | 153 | $query = 'SELECT * FROM ' . PIWECARD_TABLE .' WHERE ecard_id="' . $ecard_id . '" LIMIT 1;'; |
---|
[8771] | 154 | |
---|
| 155 | $result = pwg_query($query); |
---|
| 156 | if ($result) |
---|
[19968] | 157 | return pwg_db_fetch_assoc($result); |
---|
[8771] | 158 | else |
---|
| 159 | return false; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
[20431] | 163 | /** |
---|
| 164 | * Is the ecard valid? |
---|
| 165 | * @param Integer ecard id |
---|
| 166 | * @return Boolean True if valid, False otherwise |
---|
| 167 | */ |
---|
| 168 | function is_valid($ecard_id) { |
---|
[19956] | 169 | if (isset($ecard_id)) { |
---|
[8771] | 170 | $ecard_info = $this->get_ecard($ecard_id); |
---|
[19956] | 171 | if (isset($ecard_info)) { |
---|
[8771] | 172 | // Valid duration for an ecard |
---|
[19956] | 173 | $date_validity = $ecard_info['date_validity']; |
---|
[8771] | 174 | |
---|
[19956] | 175 | if (isset($date_validity)) { |
---|
| 176 | $now = new DateTime(date("Y-m-d H:i:s")); |
---|
| 177 | $date_validity = new DateTime($date_validity); |
---|
| 178 | if ($date_validity > $now) |
---|
| 179 | return true; |
---|
| 180 | else |
---|
| 181 | return false; |
---|
[19732] | 182 | } else { |
---|
[8771] | 183 | return true; |
---|
| 184 | } |
---|
[19956] | 185 | } else |
---|
[8771] | 186 | return false; |
---|
[19732] | 187 | } else { |
---|
[19956] | 188 | return false; |
---|
[8771] | 189 | } |
---|
| 190 | } |
---|
| 191 | |
---|
[20431] | 192 | /** |
---|
| 193 | * Delete one ecard |
---|
| 194 | * @param Integer ecard id |
---|
| 195 | */ |
---|
| 196 | function delete_ecard($ecard_id) { |
---|
[19956] | 197 | if (isset($ecard_id)) { |
---|
[20202] | 198 | $query = 'DELETE FROM ' . PIWECARD_TABLE .' WHERE ecard_id="' . $ecard_id . '";'; |
---|
[8771] | 199 | pwg_query($query); |
---|
[19956] | 200 | } else |
---|
[19732] | 201 | return false; |
---|
[8771] | 202 | } |
---|
| 203 | |
---|
[20431] | 204 | /** |
---|
| 205 | * Delete all invalid ecards |
---|
| 206 | */ |
---|
[19732] | 207 | function delete_allinvalid_ecard() { |
---|
[20059] | 208 | $query = 'DELETE FROM ' . PIWECARD_TABLE .' WHERE date_validity < NOW();'; |
---|
[8771] | 209 | pwg_query($query); |
---|
| 210 | } |
---|
| 211 | |
---|
[20431] | 212 | /** |
---|
| 213 | * Is the email valid? |
---|
| 214 | * @param String email address |
---|
| 215 | * @return Boolean True if valid, False otherwise |
---|
| 216 | */ |
---|
[20047] | 217 | function is_valid_email($email_address) { |
---|
| 218 | $syntax = '#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#'; |
---|
| 219 | |
---|
| 220 | if(preg_match($syntax, $email_address)) |
---|
| 221 | return true; |
---|
| 222 | else |
---|
| 223 | return false; |
---|
| 224 | } |
---|
| 225 | |
---|
[20431] | 226 | /** |
---|
| 227 | * Add tpl to picture.php page to display ecard informations |
---|
| 228 | */ |
---|
[19732] | 229 | function display_ecard_to_picture() { |
---|
| 230 | global $page, $user, $template; |
---|
[8771] | 231 | |
---|
[19732] | 232 | // Only on category page! |
---|
| 233 | if (isset($page['section'])) { |
---|
[8771] | 234 | $upper_names = null; |
---|
[19732] | 235 | |
---|
| 236 | if (!empty($page['category'])) { |
---|
[20341] | 237 | // Gets all upper categories from the image category to test |
---|
| 238 | // - if the upper category is activated for this function |
---|
[20010] | 239 | $query = 'SELECT * FROM '.CATEGORIES_TABLE.' WHERE id = '.pwg_db_real_escape_string($page['category']['id']).';'; |
---|
[19968] | 240 | $cat = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[19732] | 241 | |
---|
| 242 | if (empty($cat)) { |
---|
| 243 | $upper_ids = null; |
---|
| 244 | } else { |
---|
| 245 | $upper_ids = explode(',', $cat['uppercats']); |
---|
| 246 | } |
---|
[8771] | 247 | } |
---|
[19732] | 248 | |
---|
[20088] | 249 | if ($this->config['authorized_cats'] == 'user') { // !Function only allowed on user image |
---|
[19732] | 250 | if (isset($cat) and !empty($cat)) { |
---|
| 251 | $catname[0] = $cat['name']; |
---|
[20010] | 252 | if (isset($upper_ids)) { |
---|
[19732] | 253 | $nb=1; |
---|
| 254 | foreach ($upper_ids as $upper_cat) { |
---|
| 255 | $cat_info = get_cat_info($upper_cat); |
---|
| 256 | $catname[$nb++] = $cat_info['name']; |
---|
| 257 | } |
---|
| 258 | } |
---|
[8771] | 259 | } |
---|
| 260 | // Username or the current user |
---|
| 261 | $username = $user['username']; |
---|
[20162] | 262 | if (!$this->config['user_cats_case_sensitive']) |
---|
| 263 | $catname = array_map('strtolower', $catname); |
---|
[8771] | 264 | |
---|
| 265 | // author of the photo |
---|
[19956] | 266 | $query = 'SELECT author FROM '.IMAGES_TABLE.' WHERE id = '.$page['image_id'].' LIMIT 1;'; |
---|
[8771] | 267 | $result = pwg_query($query); |
---|
[19732] | 268 | if (isset($result)) { |
---|
[22072] | 269 | $img_infos = pwg_db_fetch_assoc($result); |
---|
[8771] | 270 | $authorname = $img_infos['author']; |
---|
| 271 | } |
---|
[20010] | 272 | } |
---|
| 273 | |
---|
[20180] | 274 | if ($this->config['authorized_groups_users'] == 'granted' OR $this->config['authorized_groups_users'] == 'denied') { |
---|
| 275 | $user_groups = array(); |
---|
| 276 | $query = 'SELECT group_id FROM '.USER_GROUP_TABLE.' WHERE user_id='.$user['id'].';'; |
---|
| 277 | $result = pwg_query($query); |
---|
| 278 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
| 279 | array_push($user_groups, $row['group_id']); |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | |
---|
[19732] | 283 | // Only on available cats |
---|
[20088] | 284 | if (($this->config['authorized_cats'] == 'all') //Parameter : all |
---|
| 285 | OR ($this->config['authorized_cats'] == 'selected' AND !empty($upper_ids) AND (array_intersect($upper_ids, $this->config['selected_cats']) != array())) //Parameter : selected |
---|
[20162] | 286 | OR ($this->config['authorized_cats'] == 'user' AND $this->config['user_cats_case_sensitive'] AND (in_array($username, $catname) OR $username == $authorname)) //Parameter : user AND case sensitive |
---|
| 287 | OR ($this->config['authorized_cats'] == 'user' AND !$this->config['user_cats_case_sensitive'] AND (in_array(strtolower($username), $catname) OR $username == $authorname)) //Parameter : user AND not case sensitive |
---|
[20010] | 288 | ) { |
---|
[20180] | 289 | if (($this->config['authorized_groups_users'] == 'all') //Parameter : all |
---|
| 290 | OR ($this->config['authorized_groups_users'] == 'granted' AND ((array_intersect($user_groups, $this->config['selected_groups']) != array()) OR in_array($user['id'], $this->config['selected_users']))) //Parameter : granted |
---|
| 291 | OR ($this->config['authorized_groups_users'] == 'denied' AND ((array_intersect($user_groups, $this->config['selected_groups']) == array()) AND !in_array($user['id'], $this->config['selected_users']))) //Parameter : denied |
---|
| 292 | ) { |
---|
| 293 | // Check if user is guest. |
---|
| 294 | // In this case, force mail to default mail (in configuration) |
---|
| 295 | if (is_a_guest()) { |
---|
| 296 | if (!empty($this->config['default_guest_email'])) |
---|
| 297 | $user['email'] = $this->config['default_guest_email']; |
---|
[19968] | 298 | } |
---|
[20180] | 299 | |
---|
| 300 | // Template informations |
---|
| 301 | $template->assign('ecard', array( |
---|
| 302 | 'title' => l10n('Title'), |
---|
| 303 | 'message' => l10n('piwecard_message'), |
---|
| 304 | 'sender_name' => $user['username'], |
---|
| 305 | 'sender_email' => $user['email'], |
---|
| 306 | 'recipient_name' => l10n('piwecard_recipient_name'), |
---|
| 307 | 'recipient_email' => l10n('piwecard_recipient_email'), |
---|
| 308 | 'copy' => $this->config['sender_copy'] ? 'checked="checked"' : '', |
---|
[20254] | 309 | 'changemail' => (!isset($user['email']) OR $this->config['sender_email_change']) ? '' : 'disabled="disabled"', |
---|
| 310 | 'nb_max_recipients' => $this->config['nb_max_recipients'], |
---|
[20180] | 311 | ) |
---|
[20010] | 312 | ); |
---|
[8771] | 313 | |
---|
[20180] | 314 | // Template add for the active parameter choice by the user |
---|
| 315 | if ($this->config['validity_choice']) { |
---|
| 316 | foreach($this->config['validity'] as $validity) { |
---|
| 317 | $template->append('ecard_validity', array( |
---|
| 318 | 'id' => $validity, |
---|
| 319 | 'name' => ($validity == 0) ? l10n('piwecard_nolimit') : $validity.' '.l10n('piwecard_days'), |
---|
| 320 | 'selected' => ($this->config['validity_default'] == $validity ? 'checked' : '') |
---|
| 321 | ) |
---|
| 322 | ); |
---|
| 323 | } |
---|
| 324 | } else { |
---|
| 325 | $template->assign('ecard_validity_hidden', $this->config['validity_default']); |
---|
[20162] | 326 | } |
---|
[20180] | 327 | |
---|
| 328 | foreach ($this->config['email_format_authorized'] as $email_format) { |
---|
| 329 | $template->append('ecard_email_format', array( |
---|
| 330 | 'id' => $email_format, |
---|
| 331 | 'name' => l10n('piwecard_email_format_'.$email_format), |
---|
| 332 | 'selected' => (($this->config['email_format_default'] == $email_format) ? 'checked' : ''), |
---|
| 333 | ) |
---|
| 334 | ); |
---|
[20162] | 335 | } |
---|
| 336 | |
---|
[20180] | 337 | $template->set_filenames(array('ecard_template' => PIWECARD_ROOT.'/template/ecard.tpl')); |
---|
| 338 | $template->concat('COMMENT_IMG', $template->parse('ecard_template', true)); |
---|
[8771] | 339 | |
---|
[20180] | 340 | // Send the card |
---|
| 341 | if (isset($_POST['ecard_submit'])) { |
---|
| 342 | // If conf doesn't allow to modify the %yourmail% param, force it to user mail |
---|
| 343 | if (!$this->config['sender_email_change']) |
---|
| 344 | $_POST['ecard_sender_email'] = $user['email']; |
---|
| 345 | |
---|
| 346 | $email_format = $_POST['ecard_email_format']; |
---|
| 347 | |
---|
| 348 | //Check fields |
---|
| 349 | if ($_POST['ecard_sender_name'] == '' |
---|
| 350 | OR $_POST['ecard_title'] == '' |
---|
| 351 | OR $_POST['ecard_message'] == '') { |
---|
| 352 | return; |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | if ($_POST['ecard_sender_email'] == '' OR !$this->is_valid_email($_POST['ecard_sender_email'])) |
---|
| 356 | return; |
---|
| 357 | |
---|
| 358 | // Initialize the array for image element |
---|
| 359 | $image_element = array(); |
---|
| 360 | |
---|
| 361 | // Get all image informations |
---|
| 362 | $query = 'SELECT * FROM '.IMAGES_TABLE.' WHERE id='.$page['image_id'].' LIMIT 1;'; |
---|
| 363 | $result = pwg_query($query); |
---|
| 364 | if (isset($result)) |
---|
[22072] | 365 | $image_element = pwg_db_fetch_assoc($result); |
---|
[20180] | 366 | |
---|
| 367 | // Generate random number |
---|
[20080] | 368 | $next_element_id_random = $this->random(64); |
---|
[20202] | 369 | while (pwg_db_num_rows(pwg_query('SELECT ecard_id FROM '.PIWECARD_TABLE.' WHERE ecard_id="'.$next_element_id_random.'";')) != 0) { |
---|
[20180] | 370 | $next_element_id_random = $this->random(64); |
---|
| 371 | } |
---|
| 372 | $image_element['next_element_id'] = $next_element_id_random; |
---|
[8771] | 373 | |
---|
[20180] | 374 | // Image infos |
---|
| 375 | if ($this->config['show_image_infos']) { |
---|
| 376 | if (isset($image_element['name'])) { |
---|
| 377 | $image_element['picture_infos'] = $image_element['name']; |
---|
| 378 | if (isset($image_element['author'])) |
---|
| 379 | $image_element['picture_infos'] .= ' ('.$image_element['author'].')'; |
---|
| 380 | } |
---|
[8771] | 381 | } |
---|
[20180] | 382 | |
---|
| 383 | // Complete the image_element array with Link for the ecard url to be added in the mail |
---|
| 384 | set_make_full_url(); |
---|
| 385 | $ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$image_element['next_element_id']); |
---|
| 386 | $image_element['ecard_url'] = $ecard_url; |
---|
| 387 | unset_make_full_url(); |
---|
| 388 | |
---|
| 389 | // Complete the image_element with the url to point to the image url |
---|
| 390 | set_make_full_url(); |
---|
| 391 | $image_element['picture_url'] = duplicate_picture_url( |
---|
| 392 | array( |
---|
| 393 | 'image_id' => $image_element['id'], |
---|
| 394 | 'image_file' => $image_element['file'] |
---|
| 395 | ), |
---|
| 396 | array('start') |
---|
| 397 | ); |
---|
| 398 | unset_make_full_url(); |
---|
| 399 | |
---|
| 400 | // Send the mail |
---|
| 401 | $recipient_infos = array_combine($_POST['ecard_recipient_name'], $_POST['ecard_recipient_email']); |
---|
| 402 | foreach ($recipient_infos as $recipient_name => $recipient_email) { |
---|
[20202] | 403 | if ($recipient_name == '' OR $recipient_email == '' OR !$this->is_valid_email($recipient_email)) |
---|
| 404 | continue; |
---|
| 405 | |
---|
[20180] | 406 | $parse_list = array( |
---|
| 407 | 'ecard_sender_name' => $_POST['ecard_sender_name'], |
---|
| 408 | 'ecard_sender_email' => $_POST['ecard_sender_email'], |
---|
| 409 | 'ecard_recipient_name' => $recipient_name, |
---|
| 410 | 'ecard_recipient_email' => $recipient_email, |
---|
| 411 | 'ecard_title' => $_POST['ecard_title'], |
---|
| 412 | 'ecard_message' => $_POST['ecard_message'], |
---|
| 413 | ); |
---|
| 414 | |
---|
[20202] | 415 | $email_infos = array( |
---|
| 416 | 'from_name' => $_POST['ecard_sender_name'], |
---|
| 417 | 'from_email' => (isset($_POST['ecard_sender_email']) ? $_POST['ecard_sender_email'] : $user['email']), |
---|
| 418 | 'to' => $recipient_email, |
---|
| 419 | 'subject' => htmlspecialchars_decode($this->parse($this->config['email_subject'], $parse_list, $image_element)), |
---|
| 420 | ); |
---|
[20180] | 421 | |
---|
[20202] | 422 | $email_message_text = stripslashes(strip_tags($this->parse($this->config['email_message']['text'], $parse_list, $image_element))); |
---|
| 423 | $email_message_html = stripslashes($this->parse($this->config['email_message']['html'], $parse_list, $image_element)); |
---|
[20180] | 424 | switch($email_format) { |
---|
| 425 | case 'text': // text |
---|
[20202] | 426 | $email_infos['message'] = array( |
---|
| 427 | 'text' => $email_message_text |
---|
[20010] | 428 | ); |
---|
[20180] | 429 | break; |
---|
| 430 | case 'html': // html |
---|
[20202] | 431 | $email_infos['message'] = array( |
---|
| 432 | 'text' => $email_message_text, |
---|
| 433 | 'html' => $email_message_html, |
---|
[20180] | 434 | ); |
---|
| 435 | default: |
---|
| 436 | break; |
---|
| 437 | } |
---|
| 438 | |
---|
[20202] | 439 | $this->mail($email_infos); |
---|
| 440 | |
---|
[20180] | 441 | // Add the copy to expe if param. |
---|
| 442 | if (isset($_POST['ecard_copy'])) // send copy to sender |
---|
[20202] | 443 | $email_infos['bcc'] = $email_infos['from_email']; |
---|
| 444 | |
---|
| 445 | //Insert into database |
---|
[20180] | 446 | $insert = array( |
---|
[20202] | 447 | 'ecard_id' => $image_element['next_element_id'], |
---|
[20180] | 448 | 'sender_name' => $_POST['ecard_sender_name'], |
---|
| 449 | 'recipient_name' => $recipient_name, |
---|
| 450 | 'sender_email' => $_POST['ecard_sender_email'], |
---|
| 451 | 'recipient_email' => $recipient_email, |
---|
| 452 | 'title' => $_POST['ecard_title'], |
---|
| 453 | 'message' => $_POST['ecard_message'], |
---|
| 454 | 'image' => $image_element['id'], |
---|
| 455 | 'date_creation' => date("Y-m-d H:i:s"), |
---|
[20032] | 456 | ); |
---|
[20180] | 457 | if ($_POST['ecard_validity'] != '0') { |
---|
| 458 | $date = new DateTime(); |
---|
| 459 | $date->modify("+".$_POST['ecard_validity']." day"); |
---|
| 460 | $insert['date_validity'] = $date->format('Y-m-d H:i:s'); |
---|
| 461 | } |
---|
| 462 | single_insert(PIWECARD_TABLE, $insert); |
---|
| 463 | } |
---|
[8771] | 464 | } |
---|
| 465 | } |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | } |
---|
[20202] | 469 | |
---|
[20431] | 470 | /** |
---|
| 471 | * Send an email |
---|
| 472 | * @param Array informations of the email |
---|
| 473 | */ |
---|
[20202] | 474 | function mail($email_infos) { |
---|
[20284] | 475 | global $lang_info; |
---|
[20254] | 476 | $template_mail = new Template(PIWECARD_MAIL_PATH.'template'); |
---|
| 477 | $smarty = $template_mail->smarty; |
---|
| 478 | |
---|
[20284] | 479 | $from = '"'.$email_infos['from_name'].'" <'.$email_infos['from_email'].'>'; |
---|
[20202] | 480 | $subject = encode_mime_header(trim(preg_replace('#[\n\r]+#s', '', $email_infos['subject']))); |
---|
| 481 | $boundary = '_----------='.md5(uniqid(mt_rand())); |
---|
| 482 | |
---|
| 483 | $headers = 'From: '.$from."\n"; |
---|
| 484 | $headers .= 'Reply-To: '.$from."\n"; |
---|
| 485 | if (!empty($email_infos['bcc'])) |
---|
| 486 | $headers .= 'Bcc: '.$email_infos['bcc']."\n"; |
---|
| 487 | $headers .= 'X-Sender: <'.get_absolute_root_url().'>'."\n"; |
---|
| 488 | $headers .= 'X-Mailer: Piwigo Mailer'."\n"; |
---|
| 489 | $headers .= 'X-auth-smtp-user: '.$from."\n"; |
---|
| 490 | $headers .= 'X-abuse-contact: '.$from."\n"; |
---|
| 491 | $headers .= 'Date: '.date("D, j M Y G:i:s O")."\n"; |
---|
| 492 | |
---|
| 493 | $message = ''; |
---|
| 494 | |
---|
| 495 | if (empty($email_infos['message']['html'])) { //Text plain email |
---|
[20284] | 496 | $headers .= 'Content-Type: text/plain; charset="'.get_pwg_charset().'"'."\n"; |
---|
[20202] | 497 | $headers .= 'Content-Transfer-Encoding: 8bit'."\n"; |
---|
[20284] | 498 | $message = $this->get_text_message($email_infos['message']['text'], $smarty); |
---|
[20202] | 499 | } else { |
---|
| 500 | $headers .= 'MIME-Version: 1.0'."\n"; |
---|
| 501 | $headers .= 'Content-Type: multipart/alternative; boundary="'.$boundary.'"'; |
---|
[20254] | 502 | $message .= 'This is a multi-part message in MIME format'."\n\n"; |
---|
[20202] | 503 | $message .= '--'.$boundary."\n"; |
---|
| 504 | $message .= 'Content-Type: text/plain; charset="'.get_pwg_charset().'"'."\n"; |
---|
| 505 | $message .= 'Content-Transfer-Encoding: binary'."\n\n"; |
---|
[20284] | 506 | $message .= $this->get_text_message($email_infos['message']['text'], $smarty); |
---|
| 507 | $message .= "\n\n"; |
---|
[20202] | 508 | $message .= '--'.$boundary."\n"; |
---|
| 509 | $message .= 'Content-Type: text/html; charset="'.get_pwg_charset().'"'."\n"; |
---|
| 510 | $message .= 'Content-Transfer-Encoding: binary;'."\n\n"; |
---|
[20284] | 511 | $message .= $this->get_html_message($email_infos['message']['html'], $smarty); |
---|
[20254] | 512 | $message .= "\n\n"; |
---|
[20202] | 513 | $message .= '--'.$boundary."--\n"; |
---|
| 514 | } |
---|
| 515 | |
---|
| 516 | mail($email_infos['to'], $subject, $message, $headers); |
---|
| 517 | } |
---|
[20284] | 518 | |
---|
[20431] | 519 | /** |
---|
| 520 | * Get the content of the email when the format is plain text |
---|
| 521 | * @param String the email message |
---|
| 522 | * @param Smarty a smarty object |
---|
| 523 | */ |
---|
[20284] | 524 | function get_text_message($message_text, $smarty) { |
---|
| 525 | global $page, $conf; |
---|
| 526 | |
---|
| 527 | $message = $message_text; |
---|
| 528 | $smarty->assign(array( |
---|
| 529 | 'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'], |
---|
| 530 | 'GALLERY_URL' => get_absolute_root_url(), |
---|
| 531 | 'MAIL' => get_webmaster_mail_address(), |
---|
| 532 | ) |
---|
| 533 | ); |
---|
| 534 | $message .= $smarty->fetch('mail_text.tpl'); |
---|
| 535 | |
---|
| 536 | return $message; |
---|
| 537 | } |
---|
| 538 | |
---|
[20431] | 539 | /** |
---|
| 540 | * Get the content of the email when the format is html |
---|
| 541 | * @param String the email message |
---|
| 542 | * @param Smarty a smarty object |
---|
| 543 | */ |
---|
[20284] | 544 | function get_html_message($message_html, $smarty) { |
---|
| 545 | global $page, $conf; |
---|
| 546 | |
---|
[20320] | 547 | $border_config = $this->config['image_border']; |
---|
[20284] | 548 | $smarty->assign(array( |
---|
[20320] | 549 | 'BORDER' => (($border_config['display']) ? 'border-style: '.$border_config['style'].'; border-width: '.$border_config['width'].'; border-color: #'.$border_config['color'].';' : ''), |
---|
[20284] | 550 | 'CONTENT_ENCODING' => get_pwg_charset(), |
---|
| 551 | 'GALLERY_URL' => get_absolute_root_url(), |
---|
| 552 | 'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'], |
---|
| 553 | 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', |
---|
| 554 | 'MAIL' => get_webmaster_mail_address(), |
---|
| 555 | 'MESSAGE_HTML' => $message_html, |
---|
| 556 | ) |
---|
| 557 | ); |
---|
| 558 | $message = $smarty->fetch('mail_html.tpl'); |
---|
| 559 | |
---|
| 560 | return $message; |
---|
| 561 | } |
---|
[8771] | 562 | } |
---|
[19923] | 563 | ?> |
---|