if ($anchor->get_type() != 'user') { Members::free($anchor->get_reference(), 'user:'******'section') { $label = i18n::s('a section'); } else { $label = i18n::s('a page'); } $context['page_title'] = sprintf(i18n::s('You have left %s'), $label); // splash message $context['text'] .= '<p>' . sprintf(i18n::s('The operation has completed, and you have no specific access rights to %s.'), Skin::build_link($anchor->get_url(), $anchor->get_title())) . '</p>'; // back to the anchor page $links = array(); $url = Surfer::get_permalink(); $links[] = Skin::build_link($url, i18n::s('Done'), 'button'); $context['text'] .= Skin::finalize_list($links, 'assistant_bar'); // confirm that i want to suppress my editor rights } else { // page title $type = $anchor->get_type(); if ($type == 'section') { $label = i18n::s('a section'); } else { $label = i18n::s('a page'); } $context['page_title'] = sprintf(i18n::s('Leave %s'), $label); // splash message if ($type == 'section') { $context['text'] .= '<p>' . sprintf(i18n::s('You have been assigned as an editor of %s, and this allows you to post new content, to contribute to pages from other persons, and to be notified of changes.'), Skin::build_link($anchor->get_url(), $anchor->get_title())) . '</p>';
/** * build a notification related to a section * * This function builds a mail message that displays: * - an image of the contributor (if possible) * - a headline mentioning the contribution * - the full content of the section * - a button linked to the section * - a link to the containing section, if any * * Note: this function returns legacy HTML, not modern XHTML, because this is what most * e-mail client software can afford. * * @param string either 'apply', 'create' or 'update' * @param array attributes of the item * @param object overlay of the item, if any * @return string text to be send by e-mail */ public static function build_notification($action, $item, $overlay = NULL) { global $context; // get the main anchor $anchor = Anchors::get($item['anchor']); // compute page title if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // headline template switch ($action) { case 'apply': $template = i18n::c('%s is requesting access to %s'); break; case 'create': $template = i18n::c('%s has created section %s'); break; case 'update': $template = i18n::c('%s has updated section %s'); break; } // headline $headline = sprintf($template, Surfer::get_link(), '<a href="' . Sections::get_permalink($item) . '">' . $title . '</a>'); // panel content $content = ''; // signal restricted and private articles if ($item['active'] == 'N') { $title = PRIVATE_FLAG . $title; } elseif ($item['active'] == 'R') { $title = RESTRICTED_FLAG . $title; } // insert page title $content .= '<h3><span>' . $title . '</span></h3>'; // insert anchor prefix if (is_object($anchor)) { $content .= $anchor->get_prefix(); } // the introduction text, if any if (is_object($overlay)) { $content .= Skin::build_block($overlay->get_text('introduction', $item), 'introduction'); } elseif (isset($item['introduction']) && trim($item['introduction'])) { $content .= Skin::build_block($item['introduction'], 'introduction'); } // get text related to the overlay, if any if (is_object($overlay)) { $content .= $overlay->get_text('view', $item); } // filter description, if necessary if (is_object($overlay)) { $description = $overlay->get_text('description', $item); } else { $description = $item['description']; } // the beautified description, which is the actual page body if ($description) { // use adequate label if (is_object($overlay) && ($label = $overlay->get_label('description'))) { $content .= Skin::build_block($label, 'title'); } // beautify the target page $content .= Skin::build_block($description, 'description', '', $item['options']); } // attachment details $details = array(); // info on related sections if ($count = Sections::count_for_anchor('section:' . $item['id'])) { $details[] = sprintf(i18n::nc('%d section', '%d sections', $count), $count); } // info on related articles if ($count = Articles::count_for_anchor('section:' . $item['id'])) { $details[] = sprintf(i18n::nc('%d page', '%d pages', $count), $count); } // info on related files if ($count = Files::count_for_anchor('section:' . $item['id'], TRUE)) { // the actual list of files attached to this section if (preg_match('/\\bfiles_by_title\\b/i', $item['options'])) { $items = Files::list_by_title_for_anchor('section:' . $item['id'], 0, 300, 'compact'); } else { $items = Files::list_by_date_for_anchor('section:' . $item['id'], 0, 300, 'compact'); } // wrap it with some header if (is_array($items)) { $items = Skin::build_list($items); } if ($items) { $content .= '<h3><span>' . i18n::s('Files') . '</span></h3>' . $items; } // details to be displayed at page bottom $details[] = sprintf(i18n::nc('%d file', '%d files', $count), $count); } // info on related links include_once $context['path_to_root'] . 'links/links.php'; if ($count = Links::count_for_anchor('section:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::nc('%d link', '%d links', $count), $count); } // comments include_once $context['path_to_root'] . 'comments/comments.php'; if ($count = Comments::count_for_anchor('section:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::nc('%d comment', '%d comments', $count), $count); } // describe attachments if (count($details)) { $content .= '<hr align="left" size=1" width="150">' . '<p style="margin: 3px 0;">' . sprintf(i18n::c('This section has %s'), join(', ', $details)) . '</p>'; } // assemble main content of this message $text = Skin::build_mail_content($headline, $content); // a set of links $menu = array(); // request access to the item if ($action == 'apply') { // call for action $link = $context['url_to_home'] . $context['url_to_root'] . Sections::get_url($item['id'], 'invite', Surfer::get_id()); $label = sprintf(i18n::c('Invite %s to participate'), Surfer::get_name()); $menu[] = Skin::build_mail_button($link, $label, TRUE); // link to user profile $link = Surfer::get_permalink(); $label = sprintf(i18n::c('View the profile of %s'), Surfer::get_name()); $menu[] = Skin::build_mail_button($link, $label, FALSE); // invite to visit the item } else { // call for action $link = Sections::get_permalink($item); if (!is_object($overlay) || !($label = $overlay->get_label('permalink_command', 'sections', FALSE))) { $label = i18n::c('View the section'); } $menu[] = Skin::build_mail_button($link, $label, TRUE); // link to the container if (is_object($anchor)) { $link = $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url(); $menu[] = Skin::build_mail_button($link, $anchor->get_title(), FALSE); } } // finalize links $text .= Skin::build_mail_menu($menu); // the full message return $text; }
<?php /* * Redirect automaticaly a user to its profile * or invite him to log in (and then redirect) * can be a usefull target for a link in email for example. * * @author Alexis Raimbault * @reference * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License */ include_once '../shared/global.php'; if (!Surfer::is_logged()) { Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode($context['url_to_home'] . $context['url_to_root'] . 'users/profile.php')); } else { Safe::redirect(Surfer::get_permalink()); }
$message = Articles::build_notification('apply', $item, $overlay); $headers = Mailer::set_thread('article:' . $item['id']); // allow for skinnable template $message = Skin::build_mail_message($message); // build multiple parts, for HTML rendering $message = Mailer::build_multipart($message); // send the message to requested user if (Mailer::post(Surfer::from(), $to, $subject, $message, NULL, $headers)) { $text = sprintf(i18n::s('Your request has been transmitted to %s. Check your mailbox for feed-back.'), Skin::build_link(Users::get_permalink($requested), Codes::beautify_title($requested['full_name']), 'user')); $context['text'] .= Skin::build_block($text, 'note'); } // follow-up navigation $context['text'] .= '<div>' . i18n::s('Where do you want to go now?') . '</div>'; $menu = array(); $menu[] = Skin::build_link($context['url_to_root'], i18n::s('Front page'), 'button'); $menu[] = Skin::build_link(Surfer::get_permalink(), i18n::s('My profile'), 'span'); $context['text'] .= Skin::finalize_list($menu, 'menu_bar'); // offer to request some owner } else { // provide feed-back to surfer $context['text'] .= Skin::build_block(i18n::s('You are not allowed to access this page.'), 'caution'); // list owners $owners = array(); // owner of this section if (isset($item['owner_id']) && $item['owner_id'] && ($user = Users::get($item['owner_id'])) && $user['email']) { $owners[] = $user['id']; } // owners of parent containers $reference = $item['anchor']; while ($reference) { if (!($parent = Anchors::get($reference))) {
// we are tracking a user if (!strncmp($track, 'user:'******'user:'******'', $track))) && isset($user['email']) && $user['email'] && $user['without_alerts'] != 'Y') { // contact target user by e-mail $subject = sprintf(i18n::c('%s is following you'), strip_tags(Surfer::get_name())); // headline $headline = sprintf(i18n::c('%s is following you'), Surfer::get_link()); // information $message = '<p>' . sprintf(i18n::c('%s will receive notifications when you will update your followers at %s'), Surfer::get_name(), $context['site_name']) . '</p>'; // assemble main content of this message $message = Skin::build_mail_content($headline, $message); // a set of links $menu = array(); // call for action $link = Surfer::get_permalink(); $menu[] = Skin::build_mail_button($link, ucfirst(strip_tags(Surfer::get_name())), TRUE); // finalize links $message .= Skin::build_mail_menu($menu); // enable threading $headers = Mailer::set_thread('user:'******'id']); // sent by the server Mailer::notify(NULL, $user['email'], $subject, $message, $headers); } // feed-back to poster $context['text'] .= '<p>' . sprintf(i18n::s('You have been connected to %s.'), Skin::build_link($anchor->get_url(), $anchor->get_title())) . "</p>\n"; $menu[] = Skin::build_link(Users::get_url($track, 'track'), i18n::s('I have changed my mind'), 'span'); // we are tracking a page } else { // reference the anchor page if (is_object($anchor) && $anchor->is_viewable()) {
/** * build the navigation menu for this surfer * * This function has to be called from the template, once the skin has been loaded. * * @param string the type of each link * @return string to be displayed as user menu * * @see skins/skin_skeleton.php */ public static function &build_user_menu($type = 'submenu') { global $context; // surfer is a valid user if (Surfer::is_logged()) { // all available commands $menu = array(); if ($link = Surfer::get_permalink()) { $menu[$link] = array('', i18n::s('My profile'), '', $type, '', i18n::s('View all data this site knows about you')); } if (Surfer::is_associate()) { $menu['articles/review.php'] = array('', i18n::s('Review queue'), '', $type, '', i18n::s('Check requests, publish submitted articles, review old pages')); } if (Surfer::is_associate()) { $menu['control/'] = array('', i18n::s('Control Panel'), '', $type, '', i18n::s('System commands, configuration panels, content overview')); } $menu['users/logout.php'] = array('', i18n::s('Logout'), '', $type, '', i18n::s('You will be considered as an anonymous surfer')); $content = Skin::build_list($menu, 'compact'); // no user menu during installation } elseif (!file_exists($context['path_to_root'] . 'parameters/switch.on') && !file_exists($context['path_to_root'] . 'parameters/switch.off')) { } elseif (!isset($context['users_without_login_box']) || $context['users_without_login_box'] != 'Y') { $content = '<form method="post" action="' . $context['url_to_root'] . 'users/login.php" id="login_form"><p>' . "\n"; // use cookie, if any -- don't populate the name to enable caching $name = ''; // the id or email field $content .= i18n::s('User') . BR . '<input type="text" name="login_name" size="10" maxlength="255" value="' . encode_field($name) . '" />' . BR; // the password $content .= i18n::s('Password') . BR . '<input type="password" name="login_password" size="10" maxlength="255" />' . BR; // Remember me ? if ($context['users_with_permanent_authentication'] == 'U') { $content .= '<span class="details"><input type="checkbox" name="remember" value="Y" /> ' . i18n::s('Stay connected') . '</span>' . BR; } // the button $content .= Skin::build_submit_button(i18n::s('Login')); // end of the form $content .= '</p></form>'; // additional commands $menu = array(); // self-registration is allowed if (!isset($context['users_without_registration']) || $context['users_without_registration'] != 'Y') { $menu['users/edit.php'] = array('', i18n::s('Register'), '', $type, '', i18n::s('Share your profile in this community')); } $menu['users/password.php'] = array('', i18n::s('Lost password'), '', $type, '', i18n::s('Prove who you are')); $content .= Skin::build_list($menu, 'compact'); } // return by reference return $content; }
/** * build a notification related to an article * * The action can be one of the following: * - 'apply' - surfer would like to get access to the page * - 'publish' - either a published page has been posted, or a draft page has been published * - 'submit' - a draft page has been posted * - 'update' - a page (draft or published) has been modified * * This function builds a mail message that displays: * - an image of the contributor (if possible) * - a headline mentioning the contribution * - the full content of the new comment * - a button linked to the reply page * - a link to the containing page * * Note: this function returns legacy HTML, not modern XHTML, because this is what most * e-mail client software can afford. * * @param string either 'apply', 'publish', 'submit' or 'update' * @param array attributes of the item * @param object overlay of the item, if any * @return string text to be send by e-mail */ public static function build_notification($action = 'publish', $item, $overlay = NULL) { global $context; // sanity check if (!isset($item['anchor']) || !($anchor = Anchors::get($item['anchor']))) { throw new Exception('no anchor for this article'); } // compute page title if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // headline link to section $headline_link = '<a href="' . $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url() . '">' . $anchor->get_title() . '</a>'; // headline template switch ($action) { case 'apply': $template = i18n::c('%s is requesting access to %s'); $headline_link = '<a href="' . Articles::get_permalink($item) . '">' . $title . '</a>'; break; case 'publish': $template = i18n::c('%s has posted a page in %s'); break; case 'submit': $template = i18n::c('%s has submitted a page in %s'); break; case 'update': $template = i18n::c('%s has updated a page in %s'); break; } // headline $headline = sprintf($template, Surfer::get_link(), $headline_link); // panel content $content = ''; // more insight on this page $prefix = $suffix = ''; // signal articles to be published if (!isset($item['publish_date']) || $item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $prefix .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // flag expired articles if (isset($item['expiry_date']) && $item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG . ' '; } // signal locked articles if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) { $suffix .= ' ' . LOCKED_FLAG; } // insert page title $content .= '<h3><span>' . $prefix . $title . $suffix . '</span></h3>'; // insert anchor prefix if (is_object($anchor)) { $content .= $anchor->get_prefix(); } // the introduction text, if any if (is_object($overlay)) { $content .= Skin::build_block($overlay->get_text('introduction', $item), 'introduction'); } elseif (isset($item['introduction']) && trim($item['introduction'])) { $content .= Skin::build_block($item['introduction'], 'introduction'); } // get text related to the overlay, if any if (is_object($overlay)) { $content .= $overlay->get_text('diff', $item); } // filter description, if necessary if (is_object($overlay)) { $description = $overlay->get_text('description', $item); } else { $description = $item['description']; } // the beautified description, which is the actual page body if ($description) { // use adequate label if (is_object($overlay) && ($label = $overlay->get_label('description'))) { $content .= Skin::build_block($label, 'title'); } // beautify the target page $content .= Skin::build_block($description, 'description', '', $item['options']); } // attachment details $details = array(); // avoid first file in list if mentioned in last comment $file_offset = 0; // comments include_once $context['path_to_root'] . 'comments/comments.php'; if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) { // get last contribution for this page if ($comment = Comments::get_newest_for_anchor('article:' . $item['id'])) { if (preg_match('/\\[(download|file)=/', $comment['description'])) { $file_offset++; } // bars around the last contribution $bottom_menu = array(); // last contributor $contributor = Users::get_link($comment['create_name'], $comment['create_address'], $comment['create_id']); $flag = ''; if ($comment['create_date'] >= $context['fresh']) { $flag = NEW_FLAG; } elseif ($comment['edit_date'] >= $context['fresh']) { $flag = UPDATED_FLAG; } $bottom_menu[] = sprintf(i18n::s('By %s'), $contributor) . ' ' . Skin::build_date($comment['create_date']) . $flag; // gather pieces $pieces = array(); // last contribution, and user signature $pieces[] = ucfirst(trim($comment['description'])) . Users::get_signature($comment['create_id']); // bottom if ($bottom_menu) { $pieces[] = '<div>' . ucfirst(trim(Skin::finalize_list($bottom_menu, 'menu'))) . '</div>'; } // put all pieces together $content .= '<div>' . "\n" . join("\n", $pieces) . '</div>' . "\n"; } // count comments $details[] = sprintf(i18n::nc('%d comment', '%d comments', $count), $count); } // info on related files if ($count = Files::count_for_anchor('article:' . $item['id'])) { // most recent files attached to this page if ($items = Files::list_by_date_for_anchor('article:' . $item['id'], $file_offset, 3, 'dates')) { // more files than listed $more = ''; if ($count > 3) { $more = '<span class="details">' . sprintf(i18n::s('%d files, including:'), $count) . '</span>'; } if (is_array($items)) { $items = Skin::build_list($items, 'compact'); } $items = '<div>' . $more . $items . '</div>'; } // wrap it with some header if ($items) { $content .= '<h3><span>' . i18n::c('Files') . '</span></h3>' . $items; } // count files $details[] = sprintf(i18n::nc('%d file', '%d files', $count), $count); } // info on related links include_once $context['path_to_root'] . 'links/links.php'; if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::nc('%d link', '%d links', $count), $count); } // describe attachments if (count($details)) { $content .= '<hr align="left" size=1" width="150">' . '<p>' . sprintf(i18n::c('This page has %s'), join(', ', $details)) . '</p>'; } // assemble main content of this message $text = Skin::build_mail_content($headline, $content); // a set of links $menu = array(); // request access to the item if ($action == 'apply') { // call for action $link = $context['url_to_home'] . $context['url_to_root'] . Articles::get_url($item['id'], 'invite', Surfer::get_id()); $label = sprintf(i18n::c('Invite %s to participate'), Surfer::get_name()); $menu[] = Skin::build_mail_button($link, $label, TRUE); // link to user profile $link = Surfer::get_permalink(); $label = sprintf(i18n::c('View the profile of %s'), Surfer::get_name()); $menu[] = Skin::build_mail_button($link, $label, FALSE); // invite to visit the item } else { // call for action $link = Articles::get_permalink($item); if (!is_object($overlay) || !($label = $overlay->get_label('permalink_command', 'articles', FALSE))) { $label = i18n::c('View the page'); } $menu[] = Skin::build_mail_button($link, $label, TRUE); // link to the container $link = $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url(); $menu[] = Skin::build_mail_button($link, $anchor->get_title(), FALSE); } // finalize links $text .= Skin::build_mail_menu($menu); // the full message return $text; }
} elseif ($item['email'] && !Mailer::notify(Surfer::from(), $item['email'], $mail['subject'], $mail['message'], $mail['headers'])) { Logger::error(sprintf(i18n::s('Impossible to send a message to %s.'), $item['email'])); } } } } // follow-up commands if (!$render_overlaid) { $menu = array(); if (isset($article['id'])) { $menu = array(Articles::get_permalink($article) => i18n::s('View the new thread')); } if (count($items) == 1 && ($item = $items[0]) && isset($item['id'])) { $menu = array_merge($menu, array(Users::get_permalink($item) => sprintf(i18n::s('Back to %s'), $item['nick_name']))); } elseif (Surfer::get_id()) { $menu = array_merge($menu, array(Surfer::get_permalink() => i18n::s('Back to my profile'))); } if (count($menu)) { $context['text'] .= Skin::build_block(i18n::s('Where do you want to go now?') . Skin::build_list($menu, 'menu_bar'), 'bottom'); } } } elseif ($with_form) { // target user statut doen't allow MP, except from associates if (!Surfer::is_associate() && ($overlay->attributes['user_status'] == 'donotdisturb' || $overlay->attributes['user_status'] == 'anonymous' || $item['without_alerts'] == 'Y')) { $context['text'] .= '<p>' . sprintf(i18n::s('Sorry, "%s" wish not to receive private message'), $item['nick_name']) . '</p>' . "\n"; render_skin(); finalize_page(TRUE); } $context['text'] .= Users::get_thread_creation_form($item['id']); // layout the available contact options } elseif ($threads = Sections::get('threads')) {