/** * Detect if one message has one VCALENDAR part * * @param Mail_mimeDecode $message * @return boolean * @access private */ function has_calendar_object($message) { if (is_calendar($message)) { return true; } else { if (isset($message->parts)) { for ($i = 0; $i < count($message->parts); $i++) { if (is_calendar($message->parts[$i])) { return true; } } } } return false; }
/** * Processes a response to a meeting request. * * @param string $requestid id of the object containing the request * @param string $folderid id of the parent folder of $requestid * @param string $response * * @access public * @return string id of the created/updated calendar obj * @throws StatusException */ public function MeetingResponse($requestid, $folderid, $response) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MeetingResponse('%s','%s','%s')", $requestid, $folderid, $response)); $folderImapid = $this->getImapIdFromFolderId($folderid); $this->imap_reopen_folder($folderImapid); $mail = @imap_fetchheader($this->mbox, $requestid, FT_UID) . @imap_body($this->mbox, $requestid, FT_PEEK | FT_UID); if (empty($mail)) { throw new StatusException("BackendIMAP->MeetingResponse(): Error, message not found, maybe was moved", SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); } // Get the original calendar request, so we don't need to create it from scratch $mobj = new Mail_mimeDecode($mail); unset($mail); $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'rfc_822bodies' => true, 'charset' => 'utf-8')); unset($mobj); $body_part = null; if (isset($message->parts)) { $mparts = $message->parts; for ($i = 0; $i < count($mparts); $i++) { $part = $mparts[$i]; //recursively add parts if (isset($part->ctype_primary) && $part->ctype_primary == "multipart" && (isset($part->ctype_secondary) && ($part->ctype_secondary == "mixed" || $part->ctype_secondary == "alternative" || $part->ctype_secondary == "related"))) { foreach ($part->parts as $spart) { $mparts[] = $spart; } continue; } if (is_calendar($part)) { ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->MeetingResponse - text/calendar part found, trying to reply"); // FIXME: here we should use the user email address, that could not be username $body_part = reply_meeting_calendar($part, $response, $this->username); } } unset($mparts); } unset($message); if ($body_part === null) { throw new StatusException("BackendIMAP->MeetingResponse(): Error, no calendar part modified", SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); } $uuid_calendar = ""; switch ($response) { case 1: // ACCEPTED // ACCEPTED case 2: // TENTATIVE $uuid_calendar = create_calendar_dav($body_part); break; case 3: // DECLINED // Do nothing break; } // We don't need to send a reply, because the client will do it // Remove message: answered invitation // Roundcube client doesn't remove the original message, but Zarafa backend does $s1 = @imap_delete($this->mbox, $requestid, FT_UID); $s11 = @imap_setflag_full($this->mbox, $requestid, "\\Deleted", FT_UID); $s2 = @imap_expunge($this->mbox); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MeetingResponse('%s','%s'): removing message result: s-delete: '%s' s-expunge: '%s' setflag: '%s'", $folderid, $requestid, $s1, $s2, $s11)); return $uuid_calendar; }
/** * Processes a response to a meeting request. * * @param string $requestid id of the object containing the request * @param string $folderid id of the parent folder of $requestid * @param string $response * * @access public * @return string id of the created/updated calendar obj * @throws StatusException */ public function MeetingResponse($requestid, $folderid, $response) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MeetingResponse('%s','%s','%s')", $requestid, $folderid, $response)); $folderImapid = $this->getImapIdFromFolderId($folderid); $this->imap_reopen_folder($folderImapid); $mail = @imap_fetchheader($this->mbox, $requestid, FT_UID) . @imap_body($this->mbox, $requestid, FT_PEEK | FT_UID); if (empty($mail)) { throw new StatusException(sprintf("BackendIMAP->MeetingResponse(): Error, message not found, maybe was moved"), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); } $mobj = new Mail_mimeDecode($mail); unset($mail); $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'rfc_822bodies' => true, 'charset' => 'utf-8')); unset($mobj); $Mail_RFC822 = new Mail_RFC822(); $from_header = $this->getDefaultFromValue(); $fromaddr = $this->parseAddr($Mail_RFC822->parseAddressList($from_header)); $to_header = ""; if (isset($message->headers["from"])) { $to_header = $message->headers["from"]; } else { if (isset($message->headers["return-path"])) { $to_header = $message->headers["return-path"]; } else { throw new StatusException(sprintf("BackendIMAP->MeetingResponse(): Error, no reply address"), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); } } $toaddr = $this->parseAddr($Mail_RFC822->parseAddressList($to_header)); if (isset($message->headers["subject"])) { $subject_header = $message->headers["subject"]; } else { $subject_header = ""; } $body_part = null; if (isset($message->parts)) { $mparts = $message->parts; for ($i = 0; $i < count($mparts); $i++) { $part = $mparts[$i]; //recursively add parts if (isset($part->ctype_primary) && $part->ctype_primary == "multipart" && (isset($part->ctype_secondary) && ($part->ctype_secondary == "mixed" || $part->ctype_secondary == "alternative" || $part->ctype_secondary == "related"))) { foreach ($part->parts as $spart) { $mparts[] = $spart; } continue; } if (is_calendar($part)) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MeetingResponse - text/calendar part found, trying to reply")); $body_part = $this->replyMeetingCalendar($part, $response); } } unset($mparts); } unset($message); if ($body_part === null) { throw new StatusException(sprintf("BackendIMAP->MeetingResponse(): Error, no calendar part modified"), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); } ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MeetingResponse - Creating response message")); $mail = new Mail_mimepart(); $headers = array("MIME-version" => "1.0", "From" => $mail->encodeHeader("from", $from_header, "UTF-8"), "To" => $mail->encodeHeader("to", $to_header, "UTF-8"), "Date" => gmdate("D, d M Y H:i:s", time()) . " GMT", "Subject" => $mail->encodeHeader("subject", $subject_header, "UTF-8"), "Content-class" => "urn:content-classes:calendarmessage", "Content-transfer-encoding" => "8BIT"); unset($mail); $mail = new Mail_mimepart($body_part, array("content_type" => "text/calendar; method=REPLY; charset=UTF-8", "headers" => $headers)); $encoded_mail = $mail->encode(); unset($mail); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MeetingResponse - Response message")); foreach ($encoded_mail["headers"] as $k => $v) { ZLog::Write(LOGLEVEL_DEBUG, sprintf("%s: %s", $k, $v)); } ZLog::Write(LOGLEVEL_DEBUG, sprintf("%s", $encoded_mail["body"])); $send = $this->sendMessage($fromaddr, $toaddr, $encoded_mail["headers"], $encoded_mail["body"]); if ($send) { $this->saveSentMessage($encoded_mail["headers"], $encoded_mail["body"]); } unset($encoded_mail); return $send; }
/** * Get the page context * @version 2.0 */ function get_context() { // Setup placeholders $title = SITENAME; $desc = get_bloginfo('description'); $classes = get_body_class(); $crumbs = array(); // Get some data $id = $this->queried_object_id; $object = $this->queried_object; $sep = " • "; /*-------------------------------------------- DEFAULT CONTEXT ---------------------------------------------*/ $classes[] = 0 == get_current_user_id() ? 'logged-out' : 'logged-in'; $crumbs[] = '<a href="' . SITEURL . '" title="' . SITENAME . '" rel="home" class="trail-home">Home</a>'; // Homepage if (is_home()) { $title = SITENAME . $sep . 'Home'; $classes[] = 'home'; $classes[] = 'sidebar'; $classes[] = 'archive'; /*-------------------------------------------- BUDDYPRESS CONTEXT ---------------------------------------------*/ } elseif (class_exists('BuddyPress') && is_buddypress()) { // BuddyPress Defaults $title = "BuddyPress Page"; $desc = "This is a BuddyPress page."; $classes[] = 'buddypress'; // User Profiles if (bp_is_user()) { $title = bp_get_displayed_user_fullname() . $sep . "User Profile"; $desc = SITENAME . " user profile for member " . bp_get_displayed_user_fullname(); // Your own profile if (bp_is_my_profile()) { $crumbs[] = 'Your Profile'; } else { $crumbs[] = '<a href="' . bp_get_members_directory_permalink() . '" title="Members Directory">Members</a>'; $crumbs[] = '<a href="' . bp_displayed_user_domain() . '" title="' . bp_get_displayed_user_fullname() . '">' . bp_get_displayed_user_fullname() . '</a>'; } // Display the profile component if it isnt the profile home if (!bp_is_user_profile()) { $crumbs[] = ucfirst(bp_current_component()); } // Display the current action if it is not the default public profile if (!in_array(bp_current_action(), array('public', 'just-me', 'my-friends'))) { $crumbs[] = ucfirst(bp_current_action()); } // Single Group } elseif (bp_is_group() || bp_is_group_create()) { // Group Creation if (bp_is_group_create()) { $title = 'Submit New Group'; $desc = 'Submit a new user group for listing on the ' . SITENAME . ' community groups directory.'; $crumbs[] = '<a href="' . SITEURL . '/' . bp_get_groups_root_slug() . '" title="Groups Directory">Groups</a>'; $crumbs[] = 'Create Group'; } elseif (bp_is_group()) { // Default entries $title = bp_get_group_name(); $desc = SITENAME . ' guild profile for ' . bp_get_group_name(); $classes = array_diff($classes, array('page', 'page-template-default')); $crumbs[] = '<a href="' . bp_get_groups_directory_permalink() . '" title="Groups Directory">Groups</a>'; // Group Profile Home if (bp_is_group_home()) { $title = $title . $sep . 'Profile'; $crumbs[] = bp_get_group_name(); // Advanced Component } else { // Link back to group profile $crumbs[] = '<a href="' . bp_get_group_permalink() . '" title="Return to Group Profile">' . bp_get_group_name() . '</a>'; // Members if (bp_is_group_members()) { $title = $title . $sep . 'Members'; $crumbs[] = 'Members'; // Activity } elseif (bp_is_group_activity()) { $title = $title . $sep . 'Activity'; $crumbs[] = 'Activity'; // Invites } elseif (bp_is_group_invites()) { $title = $title . $sep . 'Invitations'; $crumbs[] = 'Invitations'; // Admin } elseif (bp_is_group_admin_page()) { $title = $title . $sep . 'Admin'; $crumbs[] = 'Admin'; // Forum } else { // Forum Root if (NULL == bp_action_variable()) { $title = $title . $sep . 'Forum'; $crumbs[] = 'Forum'; // Sub-Component } else { $crumbs[] = '<a href="' . bp_get_group_permalink() . 'forum/" title="Group Forum">Forum</a>'; // Retrieve topic information from the database global $bp; global $wpdb; // Single Topic if (bp_is_action_variable('topic', 0)) { // Get the topic $topic = $wpdb->get_row($wpdb->prepare("SELECT post_title AS title, post_name AS url\n\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts} \n\t\t\t\t\t\t\t\t\t\tWHERE post_name = %s", $bp->action_variables[1])); $title = $topic->title; $crumbs[] = $topic->title; // Replies } elseif (bp_is_action_variable('reply', 0)) { // Get the reply parent topic $topic = $wpdb->get_row($wpdb->prepare("SELECT post_title AS title, post_name AS url\n\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts} \n\t\t\t\t\t\t\t\t\t\tWHERE ID = ( \n\t\t\t\t\t\t\t\t\t\t\tSELECT post_parent\n\t\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t\t\t\t\t\t\t\tWHERE post_name = %s \n\t\t\t\t\t\t\t\t\t\t)", $bp->action_variables[1])); $title = $topic->title; $crumbs[] = $topic->title; } // Topic and Reply Edits if (bp_is_action_variable('edit', 2)) { $crumbs[] = 'Edit'; } } } } } // Directories } elseif (bp_is_directory()) { // Sitewide Activity if (bp_is_activity_component()) { $title = SITENAME . ' Sitewide Activity Feed'; $desc = 'A listing of all recent activity happening throughout the ' . SITENAME . ' community.'; $crumbs[] = 'Sitewide Activity'; // Members Directory } elseif (bp_is_members_component()) { $title = SITENAME . ' Members Directory'; $desc = 'A listing of all registered members in the ' . SITENAME . ' community.'; $crumbs[] = 'Members Directory'; // Groups Directory } elseif (bp_is_groups_component()) { $title = SITENAME . ' Guilds Directory'; $desc = 'A directory listing of guilds active within in the ' . SITENAME . ' community.'; $crumbs[] = 'Guilds Directory'; } // Registration } elseif (bp_is_register_page()) { $title = SITENAME . ' User Registration'; $desc = "Register to join the " . SITENAME . " community."; $crumbs[] = "User Registration"; // Activation } elseif (bp_is_activation_page()) { $title = SITENAME . ' Account Activation'; $desc = "Activate a pending " . SITENAME . " user account."; $crumbs[] = "Account Activation"; } /*-------------------------------------------- BBPRESS CONTEXT ---------------------------------------------*/ } elseif (class_exists('bbPress') && is_bbpress()) { // bbPress Defaults $classes[] = 'bbpress'; $classes[] = 'forums'; $crumbs[] = bbp_is_forum_archive() ? "Forums" : '<a href="' . get_post_type_archive_link('forum') . '">Forums</a>'; // Main Forum Archive if (bbp_is_forum_archive()) { $title = SITENAME . " Forums"; $desc = "Get involved in the community on the " . SITENAME . " forums."; // Recent Topics } elseif (bbp_is_topic_archive()) { $title = "Recent Topics in the " . SITENAME . " Forums"; $desc = "Browse a list of the most recent topics in the " . SITENAME . " Forums."; $crumbs[] = "Recent Topics"; // Single Forum } elseif (bbp_is_single_forum()) { $title = $object->post_title; $desc = $object->post_content; // Loop through parent forums $parent_id = bbp_get_forum_parent_id($id); if (0 != $parent_id) { $crumbs = array_merge($crumbs, $this->parent_crumbs($parent_id)); } $crumbs[] = $object->post_title; // Single Topic } elseif (bbp_is_single_topic()) { $title = $object->post_title; $desc = bbp_get_topic_excerpt($id); $crumbs = array_merge($crumbs, $this->parent_crumbs(bbp_get_topic_forum_id($id))); $crumbs[] = $object->post_title; // Edit Topic } elseif (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $title = 'Edit Topic' . $sep . $object->post_title; $desc = bbp_get_topic_excerpt($id); $crumbs = array_merge($crumbs, $this->parent_crumbs($id)); // Tag the specific task if (bbp_is_topic_split()) { $crumbs[] = 'Split Topic'; } elseif (bbp_is_topic_merge()) { $crumbs[] = 'Merge Topic'; } elseif (bbp_is_topic_edit()) { $crumbs[] = 'Edit Topic'; } // Edit Reply } elseif (bbp_is_reply_edit()) { $title = 'Edit Reply' . $sep . bbp_get_reply_topic_title($id); $desc = bbp_get_reply_excerpt($id); $crumbs = array_merge($crumbs, $this->parent_crumbs(bbp_get_reply_topic_id($id))); $crumbs[] = 'Edit Reply'; } /*-------------------------------------------- WORDPRESS CONTEXT ---------------------------------------------*/ } else { // Singular Posts and Pages if (is_singular()) { $title = $object->post_title; $desc = get_post_meta($id, 'description', true); // If no description is found, use an excerpt if (empty($desc)) { $desc = get_post_field('post_excerpt', $id); } // Check for custom template $template = get_post_meta($id, "_wp_{$object->post_type}_template", true); if ('' != $template) { $template = str_replace(array("{$object->post_type}-template-", "{$object->post_type}-"), '', basename($template, '.php')); $classes[] = "{$template}-template"; } // Generate breadcrumbs by post type switch ($object->post_type) { // Single Posts case 'post': // Is the post in a category? $categories = get_the_category(); if ($categories) { // Start with the first category $term = $categories[0]; // If the category has a parent, add it to the trail. if (0 != $term->parent) { $crumbs = array_merge($crumbs, $this->parent_crumbs($term->parent, 'category')); } // Add the category archive link to the trail. $crumbs[] = '<a href="' . get_term_link($term) . '" title="' . esc_attr($term->name) . '">' . $term->name . '</a>'; } // Does the post have an ancestor? if ($object->post_parent) { $crumbs = array_merge($crumbs, $this->parent_crumbs($object->post_parent)); } // Editing a comment on this post if (is_comment_edit()) { $crumbs[] = '<a href="' . get_permalink() . '" title="Return to article">' . get_the_title() . '</a>'; $crumbs[] = 'Edit Comment'; // Reading the post } else { $crumbs[] = get_the_title(); } break; // Pages // Pages case 'page': // Does the page have an ancestor? if ($object->post_parent) { $crumbs = array_merge($crumbs, $this->parent_crumbs($object->post_parent)); } // Otherwise, viewing the page $crumbs[] = get_the_title(); break; // Events // Events case 'event': // Get the calendar the event belongs to $calendar = get_the_terms($object->ID, 'calendar'); $calendar = array_shift($calendar); $desc = 'Upcoming event on the ' . $calendar->name . ' calendar.'; $crumbs[] = '<a href="' . SITEURL . '/calendar/' . $calendar->slug . '" title="' . $calendar->name . ' Calendar">' . $calendar->name . ' Calendar</a>'; $crumbs[] = get_the_title(); break; } // Archives } elseif (is_archive()) { // Category Archives if (is_category()) { $crumbs[] = 'Category'; // If the category has a parent, add it to the trail. if ($object->parent != 0) { $crumbs = array_merge($crumbs, $this->trail_parents($object->parent)); } // Finish up with the term name $crumbs[] = $object->name; // Author Archive } elseif (is_author()) { $title = 'Author Archive' . $sep . $object->display_name; $desc = 'An archive of articles written by ' . $object->display_name; $crumbs[] = 'Author'; $crumbs[] = $object->display_name; // Advanced Search Page } elseif (is_search()) { $title = SITENAME . " Advanced Search"; $desc = "Search for a variety of content types throughout " . SITENAME; $crumbs[] = 'Advanced Search'; $classes[] = 'page'; // Calendar } elseif (is_calendar()) { $title = $object->name . " Calendar"; $desc = "Upcoming events on the " . $object->name . " calendar."; $crumbs[] = $object->name . " Calendar"; } // 404 } elseif (is_404()) { $title = "Error" . $sep . "Page Not Found"; $desc = "Sorry, but this page does not exist, or is not accessible at this time."; $classes[] = 'page'; $crumbs[] = '404 Page Not Found'; } } /*-------------------------------------------- RETURN DATA ---------------------------------------------*/ $this->title = html_entity_decode($title); $this->description = html_entity_decode($desc); $this->classes = $classes; $this->crumbs = $crumbs; }