function get_mail_auteur($from, $toEmail, $replytoEmail) { global $auteur; DebugEcho("step-01b"); DebugDump("from " . $from); DebugDump("toEmail " . $toEmail); DebugDump("replytoEmail " . $replytoEmail); $fromField = $from; $toField = $toEmail; $posAt = strpos($fromField, '@'); if ($posAt !== false) { $auteur = substr($fromField, 0, $posAt); } return $fromField; }
function QFilters($Param) { global $debug; global $Basics; // Basics $FTmp = Fields($Param); $Basics["Fields"] = $FTmp["Fields"]; // Sets fields and Group based on "FieldGroup" $Basics["Header"] = $FTmp["Header"]; $Basics["Join"] = $FTmp["Join"]; $Basics["Group"] = $FTmp["Group"]; $Basics["From"] = $FTmp["From"]; $Basics["Where"] = $FTmp["Where"]; $Basics["Ord"] = $FTmp["Ord"]; $Basics["Prime"] = "ToDo"; if ($FTmp["Ord"] == '') { //$Basics[Ord]=" ORDER BY Next_Level_Org"; $Basics["Ord"] = ""; } else { $Basics["Ord"] = $FTmp["Ord"]; } //echo "Queries QFilters "; var_dump($Basics); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Mounting the Query /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $Query = $Basics["Fields"] . $Basics["From"] . $Basics["Join"] . $Basics["Where"] . $Basics["Group"] . $Basics["Ord"]; if ($debug) { echo $Query . "<HR>\n"; } $Stats["Query"] = $Query; $Ret["Basics"] = $Basics; $Ret["Stats"] = $Stats; if ($debug) { DebugDump($Ret); } return $Ret; }
function lookup_category($trial_category, $category_match) { global $wpdb; $trial_category = trim($trial_category); $found_category = NULL; DebugEcho("lookup_category: {$trial_category}"); $term = get_term_by('name', $trial_category, 'category'); if (!empty($term)) { DebugEcho("category: found by name {$trial_category}"); DebugDump($term); //then category is a named and found return $term->term_id; } if (is_numeric($trial_category)) { DebugEcho("category: looking for id '{$trial_category}'"); $cat_id = intval($trial_category); $term = get_term_by('id', $cat_id, 'category'); if (!empty($term) && $term->term_id == $trial_category) { DebugEcho("category: found by id '{$cat_id}'"); DebugDump($term); //then cateogry was an ID and found return $term->term_id; } } if ($category_match) { DebugEcho("category wildcard lookup: {$trial_category}"); $sql_sub_name = 'SELECT term_id FROM ' . $wpdb->terms . ' WHERE name LIKE \'' . addslashes($trial_category) . '%\' limit 1'; $found_category = $wpdb->get_var($sql_sub_name); DebugEcho("category wildcard found: {$found_category}"); } return intval($found_category); //force to integer }
/** * Returns a count of the number of messages * @return integer */ function getNumberOfMessages() { $status = imap_status($this->_connection, $this->_server_string, SA_ALL); //get all messages in debug mode so we can reprocess them //DebugEcho($this->_server_string); //DebugDump($status); if ($status) { return $status->messages; } else { LogInfo("Error imap_status did not return a value"); DebugDump($this); return 0; } }
/** * @return string */ function error() { DebugDump(imap_errors()); return imap_last_error(); }
include_once $wp_content_path . DIRECTORY_SEPARATOR . "filterPostie.php"; } $test_email = null; $config = config_Read(); extract($config); if (!isset($maxemails)) { $maxemails = 0; } $emails = FetchMail($mail_server, $mail_server_port, $mail_userid, $mail_password, $input_protocol, $time_offset, $test_email, $delete_mail_after_processing, $maxemails, $email_tls); $message = 'Done.'; EchoInfo(sprintf(__("There are %d messages to process", "postie"), count($emails))); if (function_exists('memory_get_usage')) { DebugEcho(__("memory at start of e-mail processing:") . memory_get_usage()); } DebugEcho("Error log: " . ini_get('error_log')); DebugDump($config); //loop through messages $message_number = 0; foreach ($emails as $email) { $message_number++; DebugEcho("{$message_number}: ------------------------------------"); //sanity check to see if there is any info in the message if ($email == NULL) { $message = __('Dang, message is empty!', 'postie'); EchoInfo("{$message_number}: {$message}"); continue; } else { if ($email == 'already read') { $message = __("Message is already marked 'read'.", 'postie'); EchoInfo("{$message_number}: {$message}"); continue;
function postie_get_mail() { require_once plugin_dir_path(__FILE__) . 'mimedecode.php'; if (!function_exists('file_get_html')) { require_once plugin_dir_path(__FILE__) . 'simple_html_dom.php'; } EchoInfo("Starting mail fetch"); postie_environment(); $wp_content_path = dirname(dirname(dirname(__FILE__))); DebugEcho("wp_content_path: {$wp_content_path}"); if (file_exists($wp_content_path . DIRECTORY_SEPARATOR . "filterPostie.php")) { DebugEcho("found filterPostie.php in {$wp_content_path}"); include_once $wp_content_path . DIRECTORY_SEPARATOR . "filterPostie.php"; } if (has_filter('postie_post')) { echo "Postie: filter 'postie_post' is depricated in favor of 'postie_post_before'"; } $test_email = null; $config = config_Read(); //extract($config); if (!array_key_exists('maxemails', $config)) { $config['maxemails'] = 0; } $emails = FetchMail($config['mail_server'], $config['mail_server_port'], $config['mail_userid'], $config['mail_password'], $config['input_protocol'], $config['time_offset'], $test_email, $config['delete_mail_after_processing'], $config['maxemails'], $config['email_tls']); $message = 'Done.'; EchoInfo(sprintf(__("There are %d messages to process", "postie"), count($emails))); if (function_exists('memory_get_usage')) { DebugEcho(__("memory at start of email processing:") . memory_get_usage()); } DebugDump($config); //loop through messages $message_number = 0; foreach ($emails as $email) { $message_number++; DebugEcho("{$message_number}: ------------------------------------"); //sanity check to see if there is any info in the message if ($email == NULL) { $message = __('Dang, message is empty!', 'postie'); EchoInfo("{$message_number}: {$message}"); continue; } else { if ($email == 'already read') { $message = __("Message is already marked 'read'.", 'postie'); EchoInfo("{$message_number}: {$message}"); continue; } } $mimeDecodedEmail = DecodeMIMEMail($email); DebugEmailOutput($email, $mimeDecodedEmail); //Check poster to see if a valid person $poster = ValidatePoster($mimeDecodedEmail, $config); if (!empty($poster)) { PostEmail($poster, $mimeDecodedEmail, $config); } else { EchoInfo("Ignoring email - not authorized."); } flush(); } EchoInfo("Mail fetch complete, {$message_number} emails"); if (function_exists('memory_get_usage')) { DebugEcho("memory at end of email processing:" . memory_get_usage()); } }
function postie_media_handle_upload($part, $post_id, $poster, $generate_thubnails = true) { $post_data = array(); $overrides = array('test_form' => false); $tmpFile = tempnam(get_temp_dir(), 'postie'); $fp = fopen($tmpFile, 'w'); if ($fp) { fwrite($fp, $part->body); fclose($fp); } else { EchoInfo("could not write to temp file: '{$tmpFile}' "); } //special case to deal with older png implementations if (strtolower($part->ctype_secondary == 'x-png')) { DebugEcho("postie_media_handle_upload: x-png found, renamed to png"); $part->ctype_secondary = 'png'; } $name = 'postie-media.' . $part->ctype_secondary; if (property_exists($part, 'ctype_parameters') && is_array($part->ctype_parameters)) { if (array_key_exists('name', $part->ctype_parameters) && $part->ctype_parameters['name'] != '') { $name = $part->ctype_parameters['name']; } if (array_key_exists('filename', $part->ctype_parameters) && $part->ctype_parameters['filename'] != '') { $name = $part->ctype_parameters['filename']; } } if (property_exists($part, 'd_parameters') && is_array($part->d_parameters) && array_key_exists('filename', $part->d_parameters) && $part->d_parameters['filename'] != '') { $name = $part->d_parameters['filename']; } DebugEcho("pre-sanitize name: {$name}, size: " . filesize($tmpFile)); $name = sanitize_file_name($name); DebugEcho("post sanitize name: {$name}"); //DebugDump($part); $the_file = array('name' => $name, 'tmp_name' => $tmpFile, 'size' => filesize($tmpFile), 'error' => ''); if (stristr('.zip', $name)) { DebugEcho("exploding zip file"); $parts = explode('.', $name); $ext = $parts[count($parts) - 1]; $type = $part->primary . '/' . $part->secondary; $the_file['ext'] = $ext; $the_file['type'] = $type; $overrides['test_type'] = false; } $time = current_time('mysql'); $post = get_post($post_id); if (substr($post->post_date, 0, 4) > 0) { DebugEcho("using post date"); $time = $post->post_date; } $file = postie_handle_upload($the_file, $overrides, $time); //unlink($tmpFile); if (isset($file['error'])) { DebugDump($file['error']); //throw new Exception($file['error']); return new WP_Error('upload_error', $file['error']); } $url = $file['url']; $type = $file['type']; $file = $file['file']; $title = preg_replace('/\\.[^.]+$/', '', basename($file)); $content = ''; // use image exif/iptc data for title and caption defaults if possible if (file_exists(ABSPATH . '/wp-admin/includes/image.php')) { include_once ABSPATH . '/wp-admin/includes/image.php'; if ($image_meta = @wp_read_image_metadata($file)) { if (trim($image_meta['title'])) { $title = $image_meta['title']; DebugEcho("Using metadata title: {$title}"); } if (trim($image_meta['caption'])) { $content = $image_meta['caption']; DebugEcho("Using metadata caption: {$caption}"); } } } // Construct the attachment array $attachment = array_merge(array('post_mime_type' => $type, 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_excerpt' => $content, 'post_content' => $content, 'post_author' => $poster), $post_data); // Save the data $id = wp_insert_attachment($attachment, $file, $post_id); DebugEcho("attachement id: {$id}"); if (!is_wp_error($id)) { if ($generate_thubnails) { $amd = wp_generate_attachment_metadata($id, $file); DebugEcho("wp_generate_attachment_metadata"); //DebugDump($amd); wp_update_attachment_metadata($id, $amd); DebugEcho("wp_update_attachment_metadata complete"); } else { DebugEcho("thumbnail generation disabled"); } } else { EchoInfo("There was an error adding the attachement: " . $id->get_error_message()); } return $id; }