示例#1
0
文件: articles.php 项目: rair/yacs
 /**
  * do whatever is necessary when a page has been updated
  *
  * This function:
  * - logs the update
  * - sends notification to watchers and to followers
  * - "touches" the container of the page,
  * - ping referred pages remotely (via the pingback protocol)
  * - ping selected servers, if any
  * - and triggers the hook 'update'.
  *
  * The first parameter provides the watching context to consider. If call is related
  * to the creation of a published page, the context is the section that hosts the new
  * page. If call is related to a draft page that has been published, then the context
  * is the page itself.
  *
  * This function is also able to notify followers of the surfer who has initiated the
  * action.
  *
  * @param object the watching context
  * @param array attributes of the published page
  * @param object page overlay, if any
  * @param boolean TRUE if dates should be left unchanged, FALSE otherwise
  * @param boolean TRUE if watchers should be notified, FALSE otherwise
  * @param boolean TRUE if followers should be notified, FALSE otherwise
  */
 public static function finalize_update($anchor, $item, $overlay = NULL, $silently = FALSE, $with_watchers = TRUE, $with_followers = FALSE)
 {
     global $context;
     // proceed only if the page has been published
     if (isset($item['publish_date']) && $item['publish_date'] > NULL_DATE) {
         // notification to send by e-mail
         $mail = array();
         $mail['subject'] = sprintf(i18n::c('%s: %s'), i18n::c('Update'), strip_tags($item['title']));
         $mail['notification'] = Articles::build_notification('update', $item);
         $mail['headers'] = Mailer::set_thread('article:' . $item['id']);
         // allow the overlay to prevent notifications of watcherss
         if (is_object($overlay) && !$overlay->should_notify_watchers($mail)) {
             $with_watchers = FALSE;
         }
         // send to watchers of this page, and to watchers upwards
         if ($with_watchers && ($handle = new Article())) {
             $handle->load_by_content($item, $anchor);
             $handle->alert_watchers($mail, 'article:update', $item['active'] == 'N');
         }
         // never notify followers on private pages
         if (isset($item['active']) && $item['active'] == 'N') {
             $with_followers = FALSE;
         }
         // allow the overlay to prevent notifications of followers
         if (is_object($overlay) && !$overlay->should_notify_followers()) {
             $with_followers = FALSE;
         }
         // send to followers of this user
         if ($with_followers && Surfer::get_id()) {
             $mail['message'] = Mailer::build_notification($mail['notification'], 2);
             Users::alert_watchers('user:'******'article:update', $item['id'], $silently);
         // advertise public pages
         if (isset($item['active']) && $item['active'] == 'Y') {
             // expose links within the page
             $raw = '';
             if (isset($item['introduction'])) {
                 $raw .= $item['introduction'];
             }
             if (isset($item['source'])) {
                 $raw .= ' ' . $item['source'];
             }
             if (isset($item['description'])) {
                 $raw .= ' ' . $item['description'];
             }
             // pingback to referred links, if any
             include_once $context['path_to_root'] . 'links/links.php';
             Links::ping($raw, 'article:' . $item['id']);
             // ping servers, if any
             Servers::notify($anchor->get_url());
         }
     }
     // 'update' hook
     if (is_callable(array('Hooks', 'include_scripts'))) {
         Hooks::include_scripts('update', $item['id']);
     }
     // log page update
     $label = sprintf(i18n::c('Update: %s'), strip_tags($item['title']));
     $poster = Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']);
     $description = sprintf(i18n::c('Updated by %s in %s'), $poster, $anchor->get_title());
     $description .= "\n\n" . '<a href="' . Articles::get_permalink($item) . '">' . $item['title'] . '</a>';
     Logger::notify('articles/articles.php: ' . $label, $description);
 }
示例#2
0
文件: view.php 项目: rair/yacs
$context['page_link'] = Articles::get_permalink($item);
// not found -- help web crawlers
if (!isset($item['id'])) {
    include '../error.php';
    // permission denied
} elseif (!$permitted) {
    // make it clear to crawlers
    if (Surfer::is_crawler()) {
        Safe::header('Status: 401 Unauthorized', TRUE, 401);
    } elseif (!Surfer::is_logged()) {
        Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode(Articles::get_permalink($item)));
    } elseif (isset($_REQUEST['requested']) && ($requested = Users::get($_REQUEST['requested'])) && $requested['email']) {
        // prepare the mail message
        $to = Mailer::encode_recipient($requested['email'], $requested['full_name']);
        $subject = sprintf(i18n::c('%s: %s'), i18n::c('Request'), strip_tags($item['title']));
        $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');
示例#3
0
文件: contact.php 项目: rair/yacs
         Members::assign('user:'******'id'], 'article:' . $article['id']);
     }
 }
 // add this page to watch lists
 Members::assign('article:' . $article['id'], 'user:'******'id'])) {
         Members::assign('article:' . $article['id'], 'user:'******'id']);
     }
 }
 // email has to be activated
 if (isset($context['with_email']) && $context['with_email'] == 'Y') {
     // contact target user by e-mail
     $mail = array();
     $mail['subject'] = sprintf(i18n::c('Private message: %s'), strip_tags($article['title']));
     $mail['message'] = Articles::build_notification('message', $article, $overlay);
     // enable threading
     $mail['headers'] = Mailer::set_thread('article:' . $article['id'], $anchor);
     // each recipient, one at a time
     foreach ($items as $item) {
         // you cannot write to yourself
         if (isset($item['id']) && Surfer::get_id() == $item['id']) {
             continue;
         }
         // target recipient does not accept messages
         if (isset($item['without_messages']) && $item['without_messages'] == 'Y') {
             continue;
         }
         // target is known here
         if (isset($item['id'])) {
             // suggest to change user preferences if applicable