load_config(); } // Load general configuration from config_database function load_config() { $query = 'SELECT value FROM '.CONFIG_TABLE.' WHERE param="piwecard";'; $result = pwg_query($query); if(isset($result)) { $row = pwg_db_fetch_row($result); if(is_string($row[0])) { $this->my_config = unserialize(($row[0])); } } $this->load_default_config(); } // Initialize default values of params private function load_default_config() { require(ECARD_INSTALL_PATH.'default_values.inc.php'); foreach ($ecard_default_values as $key => $value) { if (!isset($this->my_config[$key])) $this->my_config[$key] = $value; } } // Save general configuration to config_database function save_config() { conf_update_param('piwecard', pwg_db_real_escape_string(serialize($this->my_config))); } function section_init_ecard() { global $tokens, $page; if ($tokens[0] == 'ecard') $page['section'] = 'ecard'; } function index_ecard() { global $page; if (isset($page['section']) and $page['section'] == 'ecard') { include(ECARD_PATH . 'publish.php'); } } //Générer une chaine de caractère unique et aléatoire private function random($car) { $string = ""; $chaine = "abcdefghijklmnpqrstuvwxy0123456789"; srand((double)microtime()*1000000); for($i=0; $i<$car; $i++) { $string .= $chaine[rand()%strlen($chaine)]; } return $string; } function parse($data, $_POST = NULL, $image_element = NULL) { include (ECARD_PATH.'include/config_param.inc.php'); $patterns = array(); $replacements = array(); foreach ($ecard_parse as $key => $value) { array_push($patterns, $key); array_push($replacements, $value); } return str_replace($patterns, $replacements, $data); } // Get the number of ecard in the database function get_nb_ecard() { $query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.ECARD_TABLE.' ORDER BY date_creation;'; $result = pwg_query($query); if ($result) { $nb=pwg_db_fetch_assoc($result); return $nb['nb']; } else return 0; } // Get the number of valid ecard in the database function get_nb_valid_ecard() { $query = 'SELECT COUNT(DISTINCT id) AS nb FROM '.ECARD_TABLE.' WHERE date_validity IS NULL OR date_validity > NOW();'; $result = pwg_query($query); if ($result) { $nb=pwg_db_fetch_assoc($result); return $nb['nb']; } else return 0; } // Get ecard information into array function get_ecard($ecard_id = null) { if ($ecard_id!== null) { $query = 'SELECT * FROM ' . ECARD_TABLE .' WHERE id ="' . $ecard_id . '" LIMIT 1;'; $result = pwg_query($query); if ($result) return pwg_db_fetch_assoc($result); else return false; } } function is_valid($ecard_id = null) { if (isset($ecard_id)) { $ecard_info = $this->get_ecard($ecard_id); if (isset($ecard_info)) { // Valid duration for an ecard $date_validity = $ecard_info['date_validity']; if (isset($date_validity)) { $now = new DateTime(date("Y-m-d H:i:s")); $date_validity = new DateTime($date_validity); if ($date_validity > $now) return true; else return false; } else { return true; } } else return false; } else { return false; } } // delete one ecard // force to delete valid ecard function delete_ecard($ecard_id = null) { if (isset($ecard_id)) { $query = 'DELETE FROM ' . ECARD_TABLE .' WHERE id="' . $ecard_id . '";'; pwg_query($query); } else return false; } // Delete all invalid ecard function delete_allinvalid_ecard() { $query = 'DELETE FROM ' . ECARD_TABLE .' WHERE date_validity < NOW();'; pwg_query($query); } // Add tpl to picture.php page to display ecard informations function display_ecard_to_picture() { global $page, $user, $template; // Only on category page! if (isset($page['section'])) { $upper_names = null; if (!empty($page['category'])) { // Gets all upper categories from the image category to test // - if the upper category is activated for this function $query = 'SELECT * FROM '.CATEGORIES_TABLE.' WHERE id = '.pwg_db_real_escape_string($page['category']['id']).';'; $cat = pwg_db_fetch_assoc(pwg_query($query)); if (empty($cat)) { $upper_ids = null; } else { foreach ($cat as $k => $v) { // If the field is true or false, the variable is transformed into a // boolean value. if ($cat[$k] == 'true' or $cat[$k] == 'false') { $cat[$k] = get_boolean($cat[$k]); } } $upper_ids = explode(',', $cat['uppercats']); } } if ($this->my_config['authorizations'] == 'user_cats') { // !Function only allowed on user image // Check the category name, user name et img author // Get all name for upper categories and current category if (isset($cat) and !empty($cat)) { $catname[0] = $cat['name']; if (isset($upper_ids)) { $nb=1; foreach ($upper_ids as $upper_cat) { // Get upper cat info and store the name $cat_info = get_cat_info($upper_cat); $catname[$nb++] = $cat_info['name']; } } } // Username or the current user $username = $user['username']; // author of the photo $query = 'SELECT author FROM '.IMAGES_TABLE.' WHERE id = '.$page['image_id'].' LIMIT 1;'; $result = pwg_query($query); if (isset($result)) { $img_infos = mysql_fetch_array($result); $authorname = $img_infos['author']; } } // Only on available cats if (($this->my_config['authorizations'] == 'all_cats') //Parameter : all_cats OR ($this->my_config['authorizations'] == 'selected_cats' AND isset($upper_ids) AND (array_intersect($upper_ids, $this->my_config['selected_cats']) != array())) //Parameter : selected_cats and recursive OR ($this->my_config['authorizations'] == 'user_cats' AND (in_array($username, $catname) OR $username == $authorname)) //Parameter : user_cats ) { // Check if user is guest. // In this case, force mail to default mail (in params) if (is_a_guest()) { if (!empty($this->my_config['default_guest_email'])) $user['email'] = $this->my_config['default_guest_email']; } // Template informations $template->assign('ecard', array( 'subject' => l10n('ecard_send_title'), 'message' => l10n('ecard_send_message'), 'sender_name' => $user['username'], 'sender_email' => $user['email'], 'recipient_name' => l10n('ecard_send_dest_name'), 'recipient_email' => l10n('ecard_send_dest_mail'), 'copy' => $this->my_config['sender_copy'] ? 'checked="checked"' : '', 'changemail' => (!isset($user['email']) OR $this->my_config['sender_email_change']) ? '' : 'disabled="disabled"' ) ); // Template add for the active parameter choice by the user if ($this->my_config['validity_choice']) { foreach($this->my_config['validity'] as $validity) { $template->append('ecard_validity', array( 'id' => $validity, 'name' => ($validity == 0) ? l10n('ecard_nolimit') : $validity.' '.l10n('ecard_days'), 'selected' => ($this->my_config['validity_default'] == $validity ? 'checked' : '') ) ); } } foreach ($this->my_config['email_format'] as $email_format) { $template->append('ecard_send_method', array( 'id' => $email_format, 'name' => l10n('ecard_mail_format_'.$email_format), 'selected' => (($this->my_config['email_format_default'] == $email_format) ? '' : 'checked'), ) ); } // Send the card if (isset($_POST['ecard_submit'])) { $send_method = $_POST['ecard_send_method']; // If conf doesn't allow to modify the %votremail param, force it to user mail if (!$this->my_config['sender_email_change']) $_POST['ecard_sender_email'] = $user['email']; // Initialize the array for image element $image_element = array(); // Get all image informations $query = 'SELECT * FROM '.IMAGES_TABLE.' WHERE id='.$page['image_id'].' LIMIT 1;'; $result = pwg_query($query); if (isset($result)) $image_element = mysql_fetch_array($result); // Generate random number $image_element['next_element_id'] = $this->random(64); // Image infos if ($this->my_config['show_image_infos']) { if (isset($image_element['name'])) { $image_element['picture_infos'] = $image_element['name']; if (isset($image_element['author'])) $image_element['picture_infos'] .= ' ('.$image_element['author'].')'; } } $insert = array( 'id' => $image_element['next_element_id'], 'sender_name' => $_POST['ecard_sender_name'], 'recipient_name' => $_POST['ecard_recipient_name'], 'sender_email' => $_POST['ecard_sender_email'], 'recipient_email' => $_POST['ecard_recipient_email'], 'subject' => $_POST['ecard_subject'], 'message' => $_POST['ecard_message'], 'image' => $image_element['id'], 'date_creation' => date("Y-m-d H:i:s"), ); if ($_POST['ecard_validity'] != '0') { $date = new DateTime(); $date->modify("+".$_POST['ecard_validity']." day"); $insert['date_validity'] = $date->format('Y-m-d H:i:s'); } single_insert(ECARD_TABLE, $insert); // Complete the image_element array with Link for the ecard url to be added in the mail set_make_full_url(); $ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$image_element['next_element_id']); $image_element['ecard_url'] = $ecard_url; unset_make_full_url(); // Complete the image_element with the url to point to the image url set_make_full_url(); $image_element['picture_url'] = duplicate_picture_url( array( 'image_id' => $image_element['id'], 'image_file' => $image_element['file'] ), array('start') ); unset_make_full_url(); $email_subject = htmlspecialchars_decode($this->parse( $this->my_config['email_subject'], $_POST)); $email_message = htmlspecialchars_decode($this->parse($this->my_config['email_message'][$send_method], $_POST, $image_element)); $email_arg=array( 'from' => $_POST['ecard_sender_email'], 'subject' => $email_subject, 'content' => $email_message, ); switch($send_method) { case 'text': // text $email_arg=array( 'content_format' => "text/plain", 'email_format' => "text/plain" ); break; case 'html': // html $email_arg=array( 'content_format' => "text/html", 'email_format' => "text/html" ); break; default: break; } // Add the copy to expe if param. if (isset($_POST['ecard_copy'])) // send copy to sender $email_arg['Bcc'] = array((isset($_POST['ecard_sender_email']) ? $_POST['ecard_sender_email'] : $user['email'])); // Send the mail pwg_mail($_POST['ecard_recipient_email'], $email_arg); } $template->set_filenames(array('ecard_template' => ECARD_ROOT.'/template/ecard.tpl')); $template->concat('COMMENT_IMG', $template->parse('ecard_template', true)); } } } } ?>