$fields['anchor'] = 'article:' . $_REQUEST['id']; $fields['description'] = $_REQUEST['first_comment']; Comments::post($fields); } // post an overlay, with the new article id --don't stop on error if (is_object($overlay)) { $overlay->remember('insert', $_REQUEST, 'article:' . $_REQUEST['id']); } // increment the post counter of the surfer Users::increment_posts(Surfer::get_id()); // do whatever is necessary on page publication if (isset($_REQUEST['publish_date']) && $_REQUEST['publish_date'] > NULL_DATE) { Articles::finalize_publication($anchor, $_REQUEST, $overlay, isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y', isset($_REQUEST['notify_followers']) && $_REQUEST['notify_followers'] == 'Y'); // else do whatever is necessary on page submission } else { Articles::finalize_submission($anchor, $_REQUEST, $overlay); } // get the new item $article = Anchors::get('article:' . $_REQUEST['id'], TRUE); // list persons that have been notified $context['text'] .= Mailer::build_recipients('article:' . $_REQUEST['id']); // list endpoints that have been notified $context['text'] .= Servers::build_endpoints(i18n::s('Servers that have been notified')); // follow-up commands $follow_up = i18n::s('What do you want to do now?'); $menu = array(); $menu = array_merge($menu, array($article->get_url() => i18n::s('View the page'))); if (Surfer::may_upload()) { $menu = array_merge($menu, array('files/edit.php?anchor=' . urlencode('article:' . $_REQUEST['id']) => i18n::s('Add a file'))); } if ((!isset($_REQUEST['publish_date']) || $_REQUEST['publish_date'] <= NULL_DATE) && Surfer::is_empowered()) {
/** * create a page out of a textual entity * * If a target is provided, it is extended with the text of this entity. * Else if the anchor is an article, a comment is created. Otherwise an article is created. * * @param array of entity attributes * @param string the textual entity to process * @param array poster attributes * @param string an optional anchor (e.g., 'article:123') * @param string reference of the object to be extended, if any * @return string reference to the created or updated object, or NULL */ public static function submit_page($entity_headers, $text, $user, $anchor = NULL, $target = NULL) { global $context; // retrieve queue parameters list($server, $account, $password, $allowed, $match, $section, $options, $hooks, $prefix, $suffix) = $context['mail_queue']; // preserve breaks $text = preg_replace('/\\s*<(br|div|h|p)/is', "\n\n<\$1", $text); // suppress dangerous html tags $text = strip_tags($text, $context['users_allowed_tags']); // trim white spaces while (TRUE) { $text = trim($text, " \t\r\n"); if (!strncmp($text, '<br>', 4)) { $text = substr($text, 4); } elseif (!strncmp($text, '<br/>', 5)) { $text = substr($text, 5); } elseif (!strncmp($text, '<br />', 6)) { $text = substr($text, 6); } else { break; } } // parse article content include_once $context['path_to_root'] . 'articles/article.php'; $article = new Article(); $entry_fields = array(); $entry_fields = $article->parse($text, $entry_fields); // trim the header if ($prefix) { $tokens = explode($prefix, $entry_fields['description']); if (isset($tokens[1])) { $entry_fields['description'] = $tokens[1]; } else { $entry_fields['description'] = $tokens[0]; } } // trim the signature if ($suffix) { list($entry_fields['description'], $dropped) = explode($suffix, $entry_fields['description']); } // strip extra text $entry_fields['description'] = trim(preg_replace('/\\(See attached file: [^\\)]+?\\)/', '', $entry_fields['description'])); // anchor this item to something $entry_fields['anchor'] = $anchor; // make a title if (!isset($entry_fields['title'])) { $entry_fields['title'] = $context['mail_subject']; } // message creation stamp $entry_fields['create_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', strtotime($context['mail_date'])); if (!isset($entry_fields['create_name'])) { $entry_fields['create_name'] = $user['nick_name']; } if (!isset($entry_fields['create_id'])) { $entry_fields['create_id'] = $user['id']; } if (!isset($entry_fields['create_address'])) { $entry_fields['create_address'] = $user['email']; } // message edition stamp $entry_fields['edit_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', time()); if (!isset($entry_fields['edit_name'])) { $entry_fields['edit_name'] = $user['nick_name']; } if (!isset($entry_fields['edit_id'])) { $entry_fields['edit_id'] = $user['id']; } if (!isset($entry_fields['edit_address'])) { $entry_fields['edit_address'] = $user['email']; } // we have to extend an existing article --this entity is mutable if ($target && !strncmp($target, 'article:', 8) && ($article = Articles::get(substr($target, 8), TRUE))) { // append the text to article description field $fields = array(); $fields['id'] = $article['id']; $fields['description'] = $article['description'] . $entry_fields['description']; $fields['silent'] = TRUE; Articles::put_attributes($fields); return $target; // we have to extend an existing comment --this entity is mutable } elseif ($target && !strncmp($target, 'comment:', 8) && ($comment = Comments::get(substr($target, 8), TRUE))) { // append the text to comment description field $comment['description'] .= $entry_fields['description']; Comments::post($comment); return $target; // we have to comment an existing page } elseif (!strncmp($anchor, 'article:', 8)) { // insert comment in the database if (!($entry_fields['id'] = Comments::post($entry_fields))) { Logger::remember('agents/messages.php: ' . Logger::error_pop()); return NULL; } // debug, if required to do so if ($context['debug_messages'] == 'Y') { Logger::remember('agents/messages.php: Messages::submit_page() as a comment', $entry_fields, 'debug'); } // increment the post counter of the surfer Users::increment_posts($user['id']); // clear cache $parent = Anchors::get($entry_fields['anchor']); // touch the related anchor if (is_object($parent) && isset($entry_fields['id'])) { $parent->touch('comment:create', $entry_fields['id'], TRUE); } return 'comment:' . $entry_fields['id']; // create a new page } else { // publish automatically, if required to do so $section = Anchors::get($entry_fields['anchor']); if (isset($context['users_with_auto_publish']) && $context['users_with_auto_publish'] == 'Y' || preg_match('/\\bauto_publish\\b/i', $options) || is_object($section) && $section->has_option('auto_publish')) { $entry_fields['publish_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', time()); if (!isset($entry_fields['publish_name'])) { $entry_fields['publish_name'] = $user['nick_name']; } if (!isset($entry_fields['publish_id'])) { $entry_fields['publish_id'] = $user['id']; } if (!isset($entry_fields['publish_address'])) { $entry_fields['publish_address'] = $user['email']; } } // ensure we are using ids instead of nicknames if (is_object($section)) { $entry_fields['anchor'] = $section->get_reference(); } // save in the database if (!($entry_fields['id'] = Articles::post($entry_fields))) { Logger::remember('agents/messages.php: ' . Logger::error_pop()); return NULL; } // debugging log if (isset($context['debug_messages']) && $context['debug_messages'] == 'Y') { $entry_fields['description'] = substr($entry_fields['description'], 0, 1024); Logger::remember('agents/messages.php: Messages::submit_page() as an article', $entry_fields, 'debug'); } // increment the post counter of the surfer Users::increment_posts($user['id']); // do whatever is necessary on page creation if (isset($entry_fields['publish_date']) && $entry_fields['publish_date'] > NULL_DATE) { Articles::finalize_publication($section, $entry_fields); } else { Articles::finalize_submission($section, $entry_fields); } // get the new item $article = Anchors::get($anchor); // if replies are allowed if (!preg_match('/\\bno_reply\\b/i', $options)) { // let the sender know about his post if (isset($entry_fields['publish_date']) && $entry_fields['publish_date'] > NULL_DATE) { $splash = i18n::s("The page received by e-mail has been successfully published. Please review it now to ensure that it reflects your mind."); } else { $splash = i18n::s("The page received by e-mail has been posted. Don't forget to read it online. Then click on the Publish command to make it publicly available."); } $message = '<p>' . $splash . '</p>' . '<p><a href="' . $context['url_to_home'] . $context['url_to_root'] . $article->get_url() . '">' . $article->get_title() . '</a></p>' . '<div>' . $article->get_teaser('basic') . '</div>' . '<p>' . i18n::c('Thank you for your contribution') . '</p>'; // enable threading $headers = Mailer::set_thread($section); // send a mail message Mailer::notify(NULL, $post_sender, 'Re: ' . $post_subject, $message, $headers); } // reference to the new page return 'article:' . $entry_fields['id']; } // job ends return NULL; }