Пример #1
0
         $context['text'] .= $recipients;
         // follow-up commands
         $follow_up = i18n::s('What do you want to do now?');
         $menu = array();
         $menu = array_merge($menu, array(Articles::get_permalink($_REQUEST) => i18n::s('View the page')));
         if (Surfer::may_upload()) {
             $menu = array_merge($menu, array('files/edit.php?anchor=' . urlencode('article:' . $item['id']) => i18n::s('Add a file')));
         }
         if ((!isset($item['publish_date']) || $item['publish_date'] <= NULL_DATE) && Surfer::is_empowered()) {
             $menu = array_merge($menu, array(Articles::get_url($item['id'], 'publish') => i18n::s('Publish the page')));
         }
         $follow_up .= Skin::build_list($menu, 'menu_bar');
         $context['text'] .= Skin::build_block($follow_up, 'bottom');
     }
     // create a new page
 } elseif (!($_REQUEST['id'] = Articles::post($_REQUEST))) {
     $item = $_REQUEST;
     $with_form = TRUE;
     // successful post
 } else {
     // page title
     $context['page_title'] = i18n::s('Thank you for your contribution');
     // the page has been published
     if (isset($_REQUEST['publish_date']) && $_REQUEST['publish_date'] > NULL_DATE) {
         $context['text'] .= '<p>' . i18n::s('The page has been successfully posted. Please review it now to ensure that it reflects your mind.') . '</p>';
     } elseif (Surfer::is_empowered()) {
         $context['text'] .= i18n::s('<p>Don\'t forget to publish the new page someday. Review the page, enhance it and then click on the Publish command to make it publicly available.</p>');
     } elseif (isset($context['users_with_auto_publish']) && $context['users_with_auto_publish'] == 'Y' || is_object($anchor) && $anchor->has_option('auto_publish')) {
         $context['text'] .= i18n::s('<p>Don\'t forget to publish the new page someday. Review the page, enhance it and then click on the Publish command to make it publicly available.</p>');
     } else {
         $context['text'] .= i18n::s('<p>The new page will now be reviewed before its publication. It is likely that this will be done within the next 24 hours at the latest.</p>');
Пример #2
0
Файл: new.php Проект: rair/yacs
 $context['text'] .= i18n::s('Archiving the new letter') . BR . "\n";
 // save the letter as a published article, but don't use special categories
 $fields = array();
 $fields['anchor'] = $anchor;
 $fields['title'] = $_REQUEST['letter_title'];
 $label = $_REQUEST['letter_recipients'];
 if ($_REQUEST['letter_recipients'] == 'custom' && isset($_REQUEST['mail_to'])) {
     $label = $_REQUEST['mail_to'];
 }
 $fields['introduction'] = sprintf(i18n::c('Sent %s to&nbsp;"%s"'), Skin::build_date(time(), 'full', $context['preferred_language']), $label);
 $fields['description'] = $_REQUEST['letter_body'];
 $fields['publish_name'] = Surfer::get_name();
 $fields['publish_id'] = Surfer::get_id();
 $fields['publish_address'] = Surfer::get_email_address();
 $fields['publish_date'] = gmstrftime('%Y-%m-%d %H:%M:%S');
 $fields['id'] = Articles::post($fields);
 // from: from configuration files
 if (isset($context['letter_reply_to']) && $context['letter_reply_to']) {
     $from = $context['letter_reply_to'];
 } elseif (isset($context['mail_from']) && $context['mail_from']) {
     $from = $context['mail_from'];
 } else {
     $from = $context['site_name'];
 }
 // to: build the list of recipients
 $recipients = array();
 switch ($_REQUEST['letter_recipients']) {
     case 'all':
         $recipients = Users::list_by_posts(0, MAXIMUM_RECIPIENTS, 'address');
         break;
     case 'members':
Пример #3
0
 unset($item['create_date']);
 unset($item['create_id']);
 unset($item['create_name']);
 unset($item['edit_address']);
 unset($item['edit_date']);
 unset($item['edit_id']);
 unset($item['edit_name']);
 // page will have to be published after modification
 unset($item['publish_address']);
 unset($item['publish_date']);
 unset($item['publish_id']);
 unset($item['publish_name']);
 // ensure this is a copy
 $item['title'] = sprintf(i18n::s('Copy of %s'), $item['title']);
 // create a new page
 if ($item['id'] = Articles::post($item)) {
     // also duplicate the provided overlay, if any -- re-use 'overlay_type' only
     $overlay = Overlay::load($item, 'article:' . $item['id']);
     // post an overlay, with the new article id
     if (is_object($overlay)) {
         $overlay->remember('insert', $item, 'article:' . $item['id']);
     }
     // duplicate all related items, images, etc.
     Anchors::duplicate_related_to($original_anchor, 'article:' . $item['id']);
     // if poster is a registered user
     if (Surfer::get_id()) {
         // increment the post counter of the surfer
         Users::increment_posts(Surfer::get_id());
         // add this page to watch list
         Members::assign('article:' . $item['id'], 'user:' . Surfer::get_id());
     }
Пример #4
0
Файл: new.php Проект: rair/yacs
 $fields['index_map'] = 'N';
 // not mentioned at the home page
 $fields['options'] = 'forward_notifications articles_by_publication';
 $fields['rank'] = 1000;
 $fields['thumbnail_url'] = $context['url_to_home'] . $context['url_to_root'] . 'skins/_reference/thumbnails/news.gif';
 $fields['title'] = i18n::c("What is new?");
 if ($id = Sections::post($fields)) {
     // a welcome thread
     $fields = array();
     $fields['anchor'] = 'section:' . $id;
     $fields['index_map'] = 'N';
     // not mentioned at the home page
     $fields['options'] = 'edit_as_simple';
     $fields['publish_date'] = gmstrftime('%Y-%m-%d %H:%M:%S');
     $fields['title'] = sprintf(i18n::c('Welcome to "%s"'), $_REQUEST['title']);
     Articles::post($fields);
 }
 // a yabb sub-section, for team joint activities
 $fields = array();
 $fields['anchor'] = 'section:' . $_REQUEST['id'];
 $fields['articles_layout'] = 'yabb';
 $fields['content_options'] = 'auto_publish with_neighbours';
 $fields['index_map'] = 'N';
 // not mentioned at the home page
 $fields['introduction'] = i18n::c('Working together');
 $fields['options'] = 'forward_notifications';
 $fields['rank'] = 2000;
 $fields['thumbnail_url'] = $context['url_to_home'] . $context['url_to_root'] . 'skins/_reference/thumbnails/meeting.gif';
 $fields['title'] = i18n::c('Activities');
 Sections::post($fields);
 // a wiki sub-section, for project documentation
Пример #5
0
 }
 // articles
 //
 $text .= Skin::build_block(i18n::s('Pages'), 'subtitle');
 // 'my_article' article
 if (Articles::get('my_article')) {
     $text .= sprintf(i18n::s('A page "%s" already exists.'), 'my_article') . BR . "\n";
 } elseif ($anchor = Sections::lookup('my_section')) {
     $fields = array();
     $fields['anchor'] = $anchor;
     $fields['nick_name'] = 'my_article';
     $fields['title'] = i18n::c('Edit me');
     $fields['introduction'] = i18n::c('Sample article');
     $fields['description'] = i18n::c('This is a sample article to let you learn and practice.') . "\n\nabcdefghijklmnopqrstuvwxyz" . " &&eacute;\"'(-&egrave;_&ccedil;&agrave; )=~#{[|`\\x^@]}" . " ^β&ecirc;&icirc;&ocirc;ϋ¨δλοφό£&ugrave;%*µ,;:!?./§¤" . "\\a\\b\\c\\d\f\\g\\h\\i\\j\\k\\l\\m\\o\\p\\q\r\\s\t\\u\v\\w\\x\\y\\z" . "\n:) 8) :D :O ;) :( X( !! ?? ?! -- ++ >> §§" . "\n[b]bold[/b] and [i]italic[/i][nl][u]underlined[/u]" . "\n<a href=\"http://myweb/mypage.html\">anchor</a><!-- comment -->" . "\nCheck my [link=document]http://myweb/mypage.html[/link] on this subject;" . " more info [email=here>>]me@dummy.com[/email]" . "\n[code]// say hello\necho \"hello world\";[/code]" . "\n[quote]Once upon a time...[/quote]" . "\n[*]First item[nl][nl][*]Second item" . "\n[list][*]First item [*]Second item[/list]" . "\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. " . "\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ";
     $fields['publish_date'] = gmstrftime('%Y-%m-%d %H:%M:%S');
     if (Articles::post($fields)) {
         $text .= sprintf(i18n::s('A page "%s" has been created.'), $fields['nick_name']) . BR . "\n";
     } else {
         $text .= Logger::error_pop() . BR . "\n";
     }
 }
 // comments
 //
 $text .= Skin::build_block(i18n::s('Comments'), 'subtitle');
 // add a sample comment to 'my_article'
 if ($anchor = Articles::lookup('my_article')) {
     $fields = array();
     $fields['anchor'] = $anchor;
     $fields['description'] = i18n::c('Hello world');
     $fields['edit_name'] = $names[rand(0, 2)];
     if (Comments::post($fields)) {
Пример #6
0
 /**
  * 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;
 }
Пример #7
0
 /**
  * duplicate all articles for a given anchor
  *
  * This function duplicates records in the database, and changes anchors
  * to attach new records as per second parameter.
  *
  * @param string the source anchor
  * @param string the target anchor
  * @return int the number of duplicated records
  *
  * @see shared/anchors.php
  */
 public static function duplicate_for_anchor($anchor_from, $anchor_to)
 {
     global $context;
     // look for records attached to this anchor
     $count = 0;
     $query = "SELECT * FROM " . SQL::table_name('articles') . " WHERE anchor LIKE '" . SQL::escape($anchor_from) . "'";
     if (($result = SQL::query($query)) && SQL::count($result)) {
         // the list of transcoded strings
         $transcoded = array();
         // process all matching records one at a time
         while ($item = SQL::fetch($result)) {
             // a new id will be allocated
             $old_id = $item['id'];
             unset($item['id']);
             // creator has to be the person who duplicates
             unset($item['create_address']);
             unset($item['create_date']);
             unset($item['create_id']);
             unset($item['create_name']);
             unset($item['edit_address']);
             unset($item['edit_date']);
             unset($item['edit_id']);
             unset($item['edit_name']);
             // target anchor
             $item['anchor'] = $anchor_to;
             // actual duplication
             if ($new_id = Articles::post($item)) {
                 // more pairs of strings to transcode
                 $transcoded[] = array('/\\[article=' . preg_quote($old_id, '/') . '/i', '[article=' . $new_id);
                 $transcoded[] = array('/\\[next=' . preg_quote($old_id, '/') . '/i', '[next=' . $new_id);
                 $transcoded[] = array('/\\[previous=' . preg_quote($old_id, '/') . '/i', '[previous=' . $new_id);
                 // duplicate elements related to this item
                 Anchors::duplicate_related_to('article:' . $old_id, 'article:' . $new_id);
                 // stats
                 $count++;
             }
         }
         // transcode in anchor
         if ($anchor = Anchors::get($anchor_to)) {
             $anchor->transcode($transcoded);
         }
     }
     // number of duplicated records
     return $count;
 }
Пример #8
0
 $article = array();
 $article['anchor'] = $anchor;
 $article['title'] = isset($_REQUEST['title']) ? $_REQUEST['title'] : utf8::transcode(Skin::build_date(gmstrftime('%Y-%m-%d %H:%M:%S GMT'), 'full'));
 $article['active_set'] = 'N';
 // this is private
 $article['publish_date'] = gmstrftime('%Y-%m-%d %H:%M:%S');
 // no review is required
 $article['options'] = 'view_as_zic_pm';
 // include some overlay
 $overlay = Overlay::bind('thread');
 $article['overlay'] = $overlay->save();
 $article['overlay_id'] = $overlay->get_id();
 // ensure everything is positioned as expected
 Surfer::empower();
 // post the new thread
 if (!($article['id'] = Articles::post($article))) {
     Logger::error(i18n::s('Impossible to add a page.'));
 } else {
     //get full article
     $article = Articles::get($article['id']);
     // attach some file
     if (isset($_FILES['upload']) && ($file = Files::upload($_FILES['upload'], 'files/article/' . $article['id'], 'article:' . $article['id']))) {
         $_REQUEST['message'] .= $file;
     }
     // make a new comment out of received message, if any
     if (isset($_REQUEST['message']) && trim($_REQUEST['message'])) {
         $comment = array();
         $comment['anchor'] = 'article:' . $article['id'];
         $comment['description'] = strip_tags($_REQUEST['message']);
         Comments::post($comment);
     }
Пример #9
0
 /**
  * process one handx entry
  *
  * This function actually creates an article out an entry
  *
  * @param string entry content
  * @param time stamp
  */
 public static function process_handx_entry($text, $stamp = NULL)
 {
     global $context;
     // parse article content
     include_once $context['path_to_root'] . 'articles/article.php';
     $article = new Article();
     $fields = $article->parse($text);
     // if no title, use the first line
     if (!$fields['title']) {
         list($fields['title'], $fields['description']) = preg_split("/\n/", $fields['description'], 2);
     }
     // if we have a time stamp, use it
     if ($stamp) {
         $fields['create_date'] = $stamp;
         $fields['publish_date'] = $stamp;
         $fields['edit_date'] = $stamp;
     }
     // load parameters for uploads
     Safe::load('parameters/agents.include.php');
     // user information
     if ($context['uploads_nick_name']) {
         if ($user = Users::get($context['uploads_nick_name'])) {
             if (!$fields['create_name']) {
                 $fields['create_name'] = $user['nick_name'];
             }
             if (!$fields['create_id']) {
                 $fields['create_id'] = $user['id'];
             }
             if (!$fields['create_address']) {
                 $fields['create_address'] = $user['email'];
             }
             if (!$fields['publish_name']) {
                 $fields['publish_name'] = $user['nick_name'];
             }
             if (!$fields['publish_id']) {
                 $fields['publish_id'] = $user['id'];
             }
             if (!$fields['publish_address']) {
                 $fields['publish_address'] = $user['email'];
             }
             if (!$fields['edit_name']) {
                 $fields['edit_name'] = $user['nick_name'];
             }
             if (!$fields['edit_id']) {
                 $fields['edit_id'] = $user['id'];
             }
             if (!$fields['edit_address']) {
                 $fields['edit_address'] = $user['email'];
             }
         }
     }
     // the anchor
     if (!$fields['anchor'] && $context['uploads_anchor']) {
         $fields['anchor'] = $context['uploads_anchor'];
     }
     $anchor = Anchors::get($fields['anchor']);
     // post a page
     $fields['id'] = Articles::post($fields);
     // increment the post counter of the surfer
     Users::increment_posts($user['id']);
     // do whatever is necessary on page publication
     if (isset($fields['publish_date']) && $fields['publish_date'] > NULL_DATE) {
         Articles::finalize_publication($anchor, $fields);
     }
 }
Пример #10
0
 function parse_tag_close($parser, $tag)
 {
     global $context;
     global $in_overlay, $overlay_class, $overlay_parameters;
     global $parsed_cdata, $parsed_item, $parsed_overlay, $parsing_report;
     // save gathered data if necessary
     switch ($tag) {
         case 'article':
             // end of article
             // transcode owner id
             $parsed_item['owner_id'] = Surfer::get_id();
             if (isset($parsed_item['owner_nick_name']) && ($user = Users::get($parsed_item['owner_nick_name']))) {
                 $parsed_item['owner_id'] = $user['id'];
             }
             // transcode creator id
             $parsed_item['create_id'] = Surfer::get_id();
             if (isset($parsed_item['create_nick_name']) && ($user = Users::get($parsed_item['create_nick_name']))) {
                 $parsed_item['create_id'] = $user['id'];
             }
             // transcode editor id
             $parsed_item['edit_id'] = Surfer::get_id();
             if (isset($parsed_item['edit_nick_name']) && ($user = Users::get($parsed_item['edit_nick_name']))) {
                 $parsed_item['edit_id'] = $user['id'];
             }
             // transcode publisher id
             $parsed_item['publish_id'] = Surfer::get_id();
             if (isset($parsed_item['publish_nick_name']) && ($user = Users::get($parsed_item['publish_nick_name']))) {
                 $parsed_item['publish_id'] = $user['id'];
             }
             // bind to given overlay
             $overlay = NULL;
             if ($overlay_class) {
                 $overlay = Overlay::bind($overlay_class . ' ' . $overlay_parameters);
             }
             // when the page has been overlaid
             if (is_object($overlay)) {
                 // update the overlay from content
                 foreach ($parsed_overlay as $label => $value) {
                     $overlay->attributes[$label] = $value;
                 }
                 // save content of the overlay in this item
                 $parsed_item['overlay'] = $overlay->save();
                 $parsed_item['overlay_id'] = $overlay->get_id();
             }
             // find anchor from handle
             if (isset($parsed_item['anchor_handle']) && ($reference = Sections::lookup($parsed_item['anchor_handle']))) {
                 $parsed_item['anchor'] = $reference;
             }
             // update an existing page
             if (isset($parsed_item['handle']) && ($item = Articles::get($parsed_item['handle']))) {
                 // transcode page id
                 $parsed_item['id'] = $item['id'];
                 // stop on error
                 if (!Articles::put($parsed_item) || is_object($overlay) && !$overlay->remember('update', $parsed_item, 'article:' . $item['id'])) {
                     Logger::error(sprintf('Unable to save article %s', $parsed_item['title'] . ' (' . $parsed_item['id'] . ')'));
                 }
                 // create a new page
             } else {
                 unset($parsed_item['id']);
                 // stop on error
                 if (!($parsed_item['id'] = Articles::post($parsed_item))) {
                     Logger::error(sprintf('Unable to save article %s', $parsed_item['title']));
                 } else {
                     // save overlay content
                     if (is_object($overlay)) {
                         $overlay->remember('insert', $parsed_item, 'article:' . $parsed_item['id']);
                     }
                 }
             }
             // report to surfer
             $parsing_report .= '<li>' . Skin::build_link(Articles::get_permalink($parsed_item), $parsed_item['title']) . "</li>\n";
             // ready for next item
             $overlay_class = NULL;
             $overlay_parameters = '';
             $parsed_overlay = array();
             $parsed_item = array();
             Safe::set_time_limit(30);
             break;
         case 'overlay':
             // end of overlay data
             $in_overlay = FALSE;
             break;
         case 'section':
             // end of section
             // transcode owner id
             $parsed_item['owner_id'] = Surfer::get_id();
             if (isset($parsed_item['owner_nick_name']) && ($user = Users::get($parsed_item['owner_nick_name']))) {
                 $parsed_item['owner_id'] = $user['id'];
             }
             // transcode creator id
             $parsed_item['create_id'] = Surfer::get_id();
             if (isset($parsed_item['create_nick_name']) && ($user = Users::get($parsed_item['create_nick_name']))) {
                 $parsed_item['create_id'] = $user['id'];
             }
             // transcode editor id
             $parsed_item['edit_id'] = Surfer::get_id();
             if (isset($parsed_item['edit_nick_name']) && ($user = Users::get($parsed_item['edit_nick_name']))) {
                 $parsed_item['edit_id'] = $user['id'];
             }
             // bind to given overlay
             $overlay = NULL;
             if ($overlay_class) {
                 $overlay = Overlay::bind($overlay_class . ' ' . $overlay_parameters);
             }
             // when the page has been overlaid
             if (is_object($overlay)) {
                 // update the overlay from content
                 foreach ($parsed_overlay as $label => $value) {
                     $overlay->attributes[$label] = $value;
                 }
                 // save content of the overlay in this item
                 $parsed_item['overlay'] = $overlay->save();
                 $parsed_item['overlay_id'] = $overlay->get_id();
             }
             // find anchor from handle
             if (isset($parsed_item['anchor_handle']) && ($reference = Sections::lookup($parsed_item['anchor_handle']))) {
                 $parsed_item['anchor'] = $reference;
             }
             // update an existing section
             if (isset($parsed_item['handle']) && ($item = Sections::get($parsed_item['handle']))) {
                 // transcode section id
                 $parsed_item['id'] = $item['id'];
                 // stop on error
                 if (!Sections::put($parsed_item) || is_object($overlay) && !$overlay->remember('update', $parsed_item, 'section:' . $item['id'])) {
                     Logger::error(sprintf('Unable to save section %s', $parsed_item['title'] . ' (' . $parsed_item['id'] . ')'));
                 }
                 // create a new page
             } else {
                 unset($parsed_item['id']);
                 // stop on error
                 if (!($parsed_item['id'] = Sections::post($parsed_item))) {
                     Logger::error(sprintf('Unable to save section %s', $parsed_item['title']));
                 } else {
                     // save overlay content
                     if (is_object($overlay)) {
                         $overlay->remember('insert', $parsed_item, 'section:' . $parsed_item['id']);
                     }
                 }
             }
             // report to surfer
             $parsing_report .= '<li>' . Skin::build_link(Sections::get_permalink($parsed_item), $parsed_item['title']) . "</li>\n";
             // ready for next item
             $overlay_class = NULL;
             $overlay_parameters = '';
             $parsed_overlay = array();
             $parsed_item = array();
             Safe::set_time_limit(30);
             break;
         default:
             // just another attribute
             // decode cdata
             $parsed_cdata = trim(preg_replace(array('/&lt;/', '/&gt;/'), array('<', '>'), $parsed_cdata));
             // feeding the overlay or the item itself
             if ($in_overlay) {
                 $parsed_overlay[$tag] = $parsed_cdata;
             } else {
                 $parsed_item[$tag] = $parsed_cdata;
             }
             // ready for next attribute
             $parsed_cdata = '';
             break;
     }
 }
Пример #11
0
    // get an anchor
    $fields['anchor'] = $anchor->get_reference();
    if (!preg_match('/^section/i', $fields['anchor'])) {
        $fields['anchor'] = $anchor->get_parent();
    }
    // a title
    $fields['title'] = Skin::strip($item['description'], 10, NULL, '');
    // a body
    $fields['description'] = $item['description'];
    // initial poster
    $fields['create_name'] = $item['create_name'];
    $fields['create_id'] = $item['create_id'];
    $fields['create_address'] = $item['create_address'];
    $fields['create_date'] = $item['create_date'];
    // make an article
    if (!($fields['id'] = Articles::post($fields))) {
        Logger::error(i18n::s('Impossible to add a page.'));
    } elseif (Comments::delete($item['id'])) {
        Comments::clear($item);
        Safe::redirect(Articles::get_permalink($fields));
    }
    // promotion has to be confirmed
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    Logger::error(i18n::s('The action has not been confirmed.'));
    // ask for confirmation
} else {
    // the submit button
    $label = '';
    if (is_object($anchor) && is_object($anchor->overlay)) {
        $label = $anchor->overlay->get_label('promote_confirmation', 'comments');
    }