Changeset 20010 for extensions/Piwecard/include/piwecard.class.php
- Timestamp:
- Jan 8, 2013, 10:48:14 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Piwecard/include/piwecard.class.php
r19968 r20010 27 27 // Initialize default values of params 28 28 private function load_default_config() { 29 require _once(ECARD_INSTALL_PATH.'default_values.inc.php');29 require(ECARD_INSTALL_PATH.'default_values.inc.php'); 30 30 foreach ($ecard_default_values as $key => $value) { 31 31 if (!isset($this->my_config[$key])) … … 36 36 // Save general configuration to config_database 37 37 function save_config() { 38 $query = 'UPDATE '.CONFIG_TABLE.' SET value="'.pwg_db_real_escape_string(serialize($this->my_config)).'" WHERE param="piwecard";'; 39 $result = pwg_query($query); 40 41 if($result) 42 return true; 43 else 44 return false; 45 } 46 47 48 // Retrieve user groups 49 function get_user_groups() { 50 global $user; 51 52 $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id=' . $user['id'] . ';'; 53 54 $result = pwg_query($query); 55 while ($row = pwg_db_fetch_assoc($result)) { 56 array_push($this->user_groups, $row['group_id']); 57 } 58 } 59 60 38 conf_update_param('piwecard', pwg_db_real_escape_string(serialize($this->my_config))); 39 } 40 61 41 function section_init_ecard() { 62 42 global $tokens, $page; … … 179 159 function display_ecard_to_picture() { 180 160 global $page, $user, $template; 181 182 // Init user groups183 $this->get_user_groups();184 161 185 162 // Only on category page! … … 191 168 // - if the parameter for "recursive" is OK 192 169 // - if the upper category is activated for this function 193 $query = 'SELECT * 194 FROM '.CATEGORIES_TABLE.' 195 WHERE id = '.pwg_db_real_escape_string($page['category']['id']).' 196 ;'; 170 $query = 'SELECT * FROM '.CATEGORIES_TABLE.' WHERE id = '.pwg_db_real_escape_string($page['category']['id']).';'; 197 171 $cat = pwg_db_fetch_assoc(pwg_query($query)); 198 172 … … 211 185 } 212 186 213 if ($this->my_config[' user_cat']) { // !Function only allowed on user image187 if ($this->my_config['authorizations'] == 'user_cats') { // !Function only allowed on user image 214 188 // Check the category name, user name et img author 215 189 // Get all name for upper categories and current category 216 190 if (isset($cat) and !empty($cat)) { 217 191 $catname[0] = $cat['name']; 218 if (isset($upper_ids) and $upper_ids != null) {192 if (isset($upper_ids)) { 219 193 $nb=1; 220 194 foreach ($upper_ids as $upper_cat) { … … 235 209 $authorname = $img_infos['author']; 236 210 } 237 } 238 211 } 212 239 213 // Only on available cats 240 if ($this->my_config['allcats'] // Available on all cats 241 OR (!empty($page['category']) AND in_array($page['category']['id'], $this->my_config['cats'])) // Available on specific cats 242 OR ($this->my_config['recursive'] AND isset($upper_ids) AND // Available on upper cats this recursiv mode 243 (array_intersect($upper_ids, $this->my_config['cats']) != array())) 244 OR // Available based on usename 245 ($this->my_config['user_cat'] 246 AND (in_array($username, $catname) // Available user categories 247 OR $username == $authorname) 248 249 ) 250 ) 251 { 252 // And only available groups 253 if (empty($this->my_config['groups']) 254 OR (!empty($this->my_config['groups']) 255 AND (array_intersect($this->user_groups, $this->my_config['groups']) != array())) 256 ) 257 { 258 259 // Check if user is guest. 260 // In this case, force mail to default mail (in params) 261 if (is_a_guest()) { 262 if (!empty($this->my_config['defaultmail'])) 263 $user['email'] = $this->my_config['defaultmail']; 264 } 265 266 // Template informations 267 $template->assign('ecard', array( 268 'subject' => l10n('ecard_send_title'), 269 'message' => l10n('ecard_send_message'), 270 'sender_name' => $user['username'], 271 'sender_email' => $user['email'], 272 'recipient_name' => l10n('ecard_send_dest_name'), 273 'recipient_email' => l10n('ecard_send_dest_mail'), 274 'copy' => $this->my_config['send_copy'] ? 'checked="checked"' : '', 275 'changemail' => ($this->my_config['expmail_change'] ? '' : 'disabled="disabled"') 276 )); 277 278 // Template add for the active parameter choice by the user 279 if ($this->my_config['active_parameter']) { // Allowed for the user 280 $template->append('ecard_validity',array('id' => 0, 'name' => l10n('ecard_nolimit'), 'selected' => ($this->my_config['activ'] == 0 ? 'checked' : ''))); 281 for($jj=5; $jj < 30; $jj+=5) 282 $template->append('ecard_validity',array('id' => $jj, 'name' => $jj , 'selected' => ($this->my_config['activ'] == $jj ? 'checked' : ''))); 283 } 284 285 // Template add for the send method to be chose, by the user 286 // default : text 287 $template->append('ecard_send_method',array('id' => 0, 'name' => l10n('ecard_maillink'), 'selected' => ($this->my_config['send_HTML'] ? '' : 'checked'))); 288 if ($this->my_config['send_HTML']) { // Allowed for the user 289 $template->append('ecard_send_method',array('id' => 1, 'name' => l10n('ecard_mailhtml'), 'selected' => ($this->my_config['send_HTML'] ? 'checked' : ''))); 290 } 291 292 // Send the card 293 if (isset($_POST['ecard_submit'])) { 294 $send_method = $_POST['ecard_send_method']; 295 296 // If conf doesn't allow to modify the %votremail param, force it to user mail 297 if (!isset($_POST['ecard_sender_email'])) 298 $_POST['ecard_sender_email'] = $user['email']; 299 300 // Initialize the array for image element 301 $image_element = array(); 302 303 // Get all image informations 304 $query = 'SELECT * FROM '.IMAGES_TABLE.' WHERE id='.$page['image_id'].' LIMIT 1;'; 305 $result = pwg_query($query); 306 if (isset($result)) 307 $image_element = mysql_fetch_array($result); 308 309 // Generate random number 310 $image_element['next_element_id'] = $this->random(64); 311 312 // Image infos 313 if ($this->my_config['ecard_showinfos']) { 314 if (isset($image_element['name'])) { 315 $image_element['picture_infos'] = $image_element['name']; 316 if (isset($image_element['author'])) 317 $image_element['picture_infos'] .= ' ('.$image_element['author'].')'; 318 } 214 if (($this->my_config['authorizations'] == 'all_cats') //Parameter : all_cats 215 OR ($this->my_config['authorizations'] == 'selected_cats' AND !empty($page['category']) AND in_array($page['category']['id'], $this->my_config['selected_cats'])) //Parameter : selected_cats but not recursive 216 OR ($this->my_config['authorizations'] == 'selected_cats' AND $this->my_config['recursive'] AND isset($upper_ids) AND (array_intersect($upper_ids, $this->my_config['selected_cats']) != array())) //Parameter : selected_cats and recursive 217 OR ($this->my_config['authorizations'] == 'user_cats' AND (in_array($username, $catname) OR $username == $authorname)) //Parameter : selected_cats and recursive 218 ) { 219 // Check if user is guest. 220 // In this case, force mail to default mail (in params) 221 if (is_a_guest()) { 222 if (!empty($this->my_config['default_guest_email'])) 223 $user['email'] = $this->my_config['default_guest_email']; 224 } 225 226 // Template informations 227 $template->assign('ecard', array( 228 'subject' => l10n('ecard_send_title'), 229 'message' => l10n('ecard_send_message'), 230 'sender_name' => $user['username'], 231 'sender_email' => $user['email'], 232 'recipient_name' => l10n('ecard_send_dest_name'), 233 'recipient_email' => l10n('ecard_send_dest_mail'), 234 'copy' => $this->my_config['sender_copy'] ? 'checked="checked"' : '', 235 'changemail' => (!isset($user['email']) OR $this->my_config['sender_email_change']) ? '' : 'disabled="disabled"') 236 )); 237 238 // Template add for the active parameter choice by the user 239 if ($this->my_config['validity_choice']) { 240 foreach($this->my_config['validity'] as $validity) { 241 $template->append('ecard_validity', array( 242 'id' => $validity, 243 'name' => ($validity == 0) ? l10n('ecard_nolimit') : $validity.' '.l10n('ecard_days'), 244 'selected' => ($this->my_config['validity_default'] == $validity ? 'checked' : '') 245 ) 246 ); 247 } 248 } 249 250 foreach ($this->my_config['email_format'] as $email_format) { 251 $template->append('ecard_send_method', array( 252 'id' => $email_format, 253 'name' => l10n('ecard_mail_format_'.$email_format), 254 'selected' => (($this->my_config['email_format_default'] == $email_format) ? '' : 'checked') 255 ) 256 ); 257 } 258 259 // Send the card 260 if (isset($_POST['ecard_submit'])) { 261 $send_method = $_POST['ecard_send_method']; 262 263 // If conf doesn't allow to modify the %votremail param, force it to user mail 264 if (!$this->my_config['sender_email_change']) 265 $_POST['ecard_sender_email'] = $user['email']; 266 267 // Initialize the array for image element 268 $image_element = array(); 269 270 // Get all image informations 271 $query = 'SELECT * FROM '.IMAGES_TABLE.' WHERE id='.$page['image_id'].' LIMIT 1;'; 272 $result = pwg_query($query); 273 if (isset($result)) 274 $image_element = mysql_fetch_array($result); 275 276 // Generate random number 277 $image_element['next_element_id'] = $this->random(64); 278 279 // Image infos 280 if ($this->my_config['show_image_infos']) { 281 if (isset($image_element['name'])) { 282 $image_element['picture_infos'] = $image_element['name']; 283 if (isset($image_element['author'])) 284 $image_element['picture_infos'] .= ' ('.$image_element['author'].')'; 319 285 } 320 321 $insert = array( 322 'id' => $image_element['next_element_id'], 323 'sender_name' => $_POST['ecard_sender_name'], 324 'recipient_name' => $_POST['ecard_recipient_name'], 325 'sender_email' => $_POST['ecard_sender_email'], 326 'recipient_email' => $_POST['ecard_recipient_email'], 327 'subject' => $_POST['ecard_subject'], 328 'message' => $_POST['ecard_message'], 329 'image' => $image_element['id'], 330 'date_creation' => date("Y-m-d H:i:s"), 331 ); 332 if ($_POST['ecard_validity'] != '0') { 333 $date = new DateTime(); 334 $date->modify("+".$_POST['ecard_validity']." day"); 335 $insert['date_validity'] = $date->format('Y-m-d H:i:s'); 336 } 337 single_insert(ECARD_TABLE, $insert); 338 339 // Complete the image_element array with Link for the ecard url to be added in the mail 340 set_make_full_url(); 341 $ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$image_element['next_element_id']); 342 $image_element['ecard_url'] = $ecard_url; 343 unset_make_full_url(); 344 345 // Complete the image_element with the url to point to the image url 346 set_make_full_url(); 347 $image_element['picture_url'] = duplicate_picture_url( 348 array( 349 'image_id' => $image_element['id'], 350 'image_file' => $image_element['file'] 351 ), 352 array('start') 353 ); 354 unset_make_full_url(); 355 356 $mail_subject = htmlspecialchars_decode($this->parse( $this->my_config['subject_link'], $_POST)); 357 358 switch($send_method) { 359 case 0 : // text 360 // Get the standard message (in admin param) and parse it with the informations 361 $mail_message = stripslashes(htmlspecialchars_decode($this->parse($this->my_config['message_link'], $_POST, $image_element))); 362 $mail_arg=array('from' => $_POST['ecard_sender_email'], 363 'subject' => $mail_subject, 364 'content' => $mail_message, 365 'content_format' => "text/plain", 366 'email_format' => "text/html" 367 ); 368 break; 369 case 1 : // html 370 $mail_message_HTML = stripslashes(htmlspecialchars_decode($this->parse($this->my_config['message_HTML'], $_POST, $image_element))); 371 $mail_arg=array('from' => $_POST['ecard_sender_email'], 372 'subject' => $mail_subject, 373 'content' => $mail_message_HTML, 374 'content_format' => "text/html", 286 } 287 288 $insert = array( 289 'id' => $image_element['next_element_id'], 290 'sender_name' => $_POST['ecard_sender_name'], 291 'recipient_name' => $_POST['ecard_recipient_name'], 292 'sender_email' => $_POST['ecard_sender_email'], 293 'recipient_email' => $_POST['ecard_recipient_email'], 294 'subject' => $_POST['ecard_subject'], 295 'message' => $_POST['ecard_message'], 296 'image' => $image_element['id'], 297 'date_creation' => date("Y-m-d H:i:s"), 298 ); 299 if ($_POST['ecard_validity'] != '0') { 300 $date = new DateTime(); 301 $date->modify("+".$_POST['ecard_validity']." day"); 302 $insert['date_validity'] = $date->format('Y-m-d H:i:s'); 303 } 304 single_insert(ECARD_TABLE, $insert); 305 306 // Complete the image_element array with Link for the ecard url to be added in the mail 307 set_make_full_url(); 308 $ecard_url = embellish_url(get_absolute_root_url() . './index.php?/ecard/'.$image_element['next_element_id']); 309 $image_element['ecard_url'] = $ecard_url; 310 unset_make_full_url(); 311 312 // Complete the image_element with the url to point to the image url 313 set_make_full_url(); 314 $image_element['picture_url'] = duplicate_picture_url( 315 array( 316 'image_id' => $image_element['id'], 317 'image_file' => $image_element['file'] 318 ), 319 array('start') 320 ); 321 unset_make_full_url(); 322 323 $email_subject = htmlspecialchars_decode($this->parse( $this->my_config['email_subject'], $_POST)); 324 $email_message = htmlspecialchars_decode($this->parse($this->my_config['email_'.$this->my_config['email_format']], $_POST, $image_element)); 325 $email_arg=array( 'from' => $_POST['ecard_sender_email'], 326 'subject' => $email_subject, 327 'content' => $email_message, 328 ); 329 330 switch($send_method) { 331 case 'text': // text 332 $email_arg=array( 'content_format' => "text/plain", 333 'email_format' => "text/plain" 334 ); 335 break; 336 case 'html': // html 337 $email_arg=array( 'content_format' => "text/html", 375 338 'email_format' => "text/html" 376 ); 377 break; 378 default: 379 break; 380 } 381 382 // Add the copy to expe if param. 383 if (isset($_POST['ecard_copy'])) // send copy to sender 384 $mail_arg['Bcc'] = array((isset($_POST['ecard_sender_email']) ? $_POST['ecard_sender_email'] : $user['email'])); 385 386 // Send the mail 387 pwg_mail($_POST['ecard_recipient_email'], $mail_arg); 388 } 389 390 $template->set_filenames(array('ecard_template' => ECARD_ROOT.'/template/ecard.tpl')); 391 $template->concat('COMMENT_IMG', $template->parse('ecard_template', true)); 392 } 339 ); 340 break; 341 default: 342 break; 343 } 344 345 // Add the copy to expe if param. 346 if (isset($_POST['ecard_copy'])) // send copy to sender 347 $email_arg['Bcc'] = array((isset($_POST['ecard_sender_email']) ? $_POST['ecard_sender_email'] : $user['email'])); 348 349 // Send the mail 350 pwg_mail($_POST['ecard_recipient_email'], $email_arg); 351 } 352 353 $template->set_filenames(array('ecard_template' => ECARD_ROOT.'/template/ecard.tpl')); 354 $template->concat('COMMENT_IMG', $template->parse('ecard_template', true)); 393 355 } 394 356 }
Note: See TracChangeset
for help on using the changeset viewer.