/** * remember the last action for this article * * This function is called by related items. What does it do? * - On image creation, the adequate code is added to the description field to let the image be displayed inline * - On icon selection, the icon field is updated * - On thumbnail image selection, the thumbnail image field is updated * - On location creation, some code is inserted in the description field to display location name inline * - On table creation, some code is inserted in the description field to display the table inline * * @see articles/article.php * @see articles/edit.php * @see shared/anchor.php * * @param string one of the pre-defined action code * @param string the id of the item related to this update * @param boolean TRUE to not change the edit date of this anchor, default is FALSE */ function touch($action, $origin = NULL, $silently = FALSE) { global $context; // we make extensive use of comments below include_once $context['path_to_root'] . 'comments/comments.php'; // don't go further on import if (preg_match('/import$/i', $action)) { return; } // no article bound if (!isset($this->item['id'])) { return; } // delegate to overlay if (is_object($this->overlay) && $this->overlay->touch($action, $origin, $silently) === false) { return; // stop on false } // clear floating objects if ($action == 'clear') { $this->item['description'] .= ' [clear]'; $query = "UPDATE " . SQL::table_name('articles') . " SET description='" . SQL::escape($this->item['description']) . "'" . " WHERE id = " . SQL::escape($this->item['id']); SQL::query($query); return; } // get the related overlay, if any if (!isset($this->overlay)) { $this->overlay = NULL; if (isset($this->item['overlay'])) { $this->overlay = Overlay::load($this->item, 'article:' . $this->item['id']); } } // components of the query $query = array(); // a new comment has been posted if ($action == 'comment:create') { // purge oldest comments Comments::purge_for_anchor('article:' . $this->item['id']); // file upload } elseif ($action == 'file:create' || $action == 'file:upload') { // actually, several files have been added $label = ''; if (!$origin) { // only when comments are allowed if (!Articles::has_option('no_comments', $this->anchor, $this->item)) { // remember this as an automatic notification $fields = array(); $fields['anchor'] = 'article:' . $this->item['id']; $fields['description'] = i18n::s('Several files have been added'); $fields['type'] = 'notification'; Comments::post($fields); } // one file has been added } elseif (!Codes::check_embedded($this->item['description'], 'embed', $origin) && ($item = Files::get($origin, TRUE))) { // this file is eligible for being embedded in the page if (isset($item['file_name']) && Files::is_embeddable($item['file_name'])) { // the overlay may prevent embedding if (is_object($this->overlay) && !$this->overlay->should_embed_files()) { } else { $label = '[embed=' . $origin . ']'; } // else add a comment to take note of the upload } else { // only when comments are allowed if (!Articles::has_option('no_comments', $this->anchor, $this->item)) { // remember this as an automatic notification $fields = array(); $fields['anchor'] = 'article:' . $this->item['id']; if ($action == 'file:create') { $fields['description'] = '[file=' . $item['id'] . ',' . $item['file_name'] . ']'; } else { $fields['description'] = '[download=' . $item['id'] . ',' . $item['file_name'] . ']'; } Comments::post($fields); } } } // we are in some interactive thread if ($origin && $this->has_option('view_as_chat')) { // default is to download the file if (!$label) { $label = '[download=' . $origin . ']'; } // this is the first contribution to the thread if (!($comment = Comments::get_newest_for_anchor('article:' . $this->item['id']))) { $fields = array(); $fields['anchor'] = 'article:' . $this->item['id']; $fields['description'] = $label; // this is a continuated contribution from this authenticated surfer } elseif ($comment['type'] != 'notification' && Surfer::get_id() && (isset($comment['create_id']) && Surfer::get_id() == $comment['create_id'])) { $comment['description'] .= BR . $label; $fields = $comment; // else process the contribution as a new comment } else { $fields = array(); $fields['anchor'] = 'article:' . $this->item['id']; $fields['description'] = $label; } // only when comments are allowed if (!Articles::has_option('no_comments', $this->anchor, $this->item)) { Comments::post($fields); } // include flash videos in a regular page } elseif ($origin && $label) { $query[] = "description = '" . SQL::escape($this->item['description'] . ' ' . $label) . "'"; } // suppress references to a deleted file } elseif ($action == 'file:delete' && $origin) { // suppress reference in main description field $text = Codes::delete_embedded($this->item['description'], 'download', $origin); $text = Codes::delete_embedded($text, 'embed', $origin); $text = Codes::delete_embedded($text, 'file', $origin); // save changes $query[] = "description = '" . SQL::escape($text) . "'"; // append a reference to a new image to the description } elseif ($action == 'image:create' && $origin) { if (!Codes::check_embedded($this->item['description'], 'image', $origin)) { // the overlay may prevent embedding if (is_object($this->overlay) && !$this->overlay->should_embed_files()) { } else { // list has already started if (preg_match('/\\[image=[^\\]]+?\\]\\s*$/', $this->item['description'])) { $this->item['description'] .= ' [image=' . $origin . ']'; } else { $this->item['description'] .= "\n\n" . '[image=' . $origin . ']'; } $query[] = "description = '" . SQL::escape($this->item['description']) . "'"; } } // also use it as thumnail if none has been defined yet if (!isset($this->item['thumbnail_url']) || !trim($this->item['thumbnail_url'])) { include_once $context['path_to_root'] . 'images/images.php'; if (($image = Images::get($origin)) && ($url = Images::get_thumbnail_href($image))) { $query[] = "thumbnail_url = '" . SQL::escape($url) . "'"; } } // refresh stamp only if image update occurs within 6 hours after last edition if (SQL::strtotime($this->item['edit_date']) + 6 * 60 * 60 < time()) { $silently = TRUE; } // suppress a reference to an image that has been deleted } elseif ($action == 'image:delete' && $origin) { // suppress reference in main description field $query[] = "description = '" . SQL::escape(Codes::delete_embedded($this->item['description'], 'image', $origin)) . "'"; // suppress references as icon and thumbnail as well include_once $context['path_to_root'] . 'images/images.php'; if ($image = Images::get($origin)) { if ($url = Images::get_icon_href($image)) { if ($this->item['icon_url'] == $url) { $query[] = "icon_url = ''"; } if ($this->item['thumbnail_url'] == $url) { $query[] = "thumbnail_url = ''"; } } if ($url = Images::get_thumbnail_href($image)) { if ($this->item['icon_url'] == $url) { $query[] = "icon_url = ''"; } if ($this->item['thumbnail_url'] == $url) { $query[] = "thumbnail_url = ''"; } } } // set an existing image as the article icon } elseif ($action == 'image:set_as_icon' && $origin) { include_once $context['path_to_root'] . 'images/images.php'; if ($image = Images::get($origin)) { if ($url = Images::get_icon_href($image)) { $query[] = "icon_url = '" . SQL::escape($url) . "'"; } // also use it as thumnail if none has been defined yet if (!(isset($this->item['thumbnail_url']) && trim($this->item['thumbnail_url'])) && ($url = Images::get_thumbnail_href($image))) { $query[] = "thumbnail_url = '" . SQL::escape($url) . "'"; } } // set an existing image as the article thumbnail } elseif ($action == 'image:set_as_thumbnail' && $origin) { include_once $context['path_to_root'] . 'images/images.php'; if ($image = Images::get($origin)) { // use the thumbnail for large files, or the image itself for smaller files if ($image['image_size'] > $context['thumbnail_threshold']) { $url = Images::get_thumbnail_href($image); } else { $url = Images::get_icon_href($image); } $query[] = "thumbnail_url = '" . SQL::escape($url) . "'"; } elseif ($origin) { $query[] = "thumbnail_url = '" . SQL::escape($origin) . "'"; } // do not remember minor changes $silently = TRUE; // append a new image, and set it as the article thumbnail } elseif ($action == 'image:set_as_both' && $origin) { if (!Codes::check_embedded($this->item['description'], 'image', $origin)) { $query[] = "description = '" . SQL::escape($this->item['description'] . ' [image=' . $origin . ']') . "'"; } include_once $context['path_to_root'] . 'images/images.php'; if ($image = Images::get($origin)) { // use the thumbnail for large files, or the image itself for smaller files if ($image['image_size'] > $context['thumbnail_threshold']) { $url = Images::get_thumbnail_href($image); } else { $url = Images::get_icon_href($image); } $query[] = "thumbnail_url = '" . SQL::escape($url) . "'"; } elseif ($origin) { $query[] = "thumbnail_url = '" . SQL::escape($origin) . "'"; } // do not remember minor changes $silently = TRUE; // add a reference to a location in the article description } elseif ($action == 'location:create' && $origin) { if (!Codes::check_embedded($this->item['description'], 'location', $origin)) { $query[] = "description = '" . SQL::escape($this->item['description'] . ' [location=' . $origin . ']') . "'"; } // suppress a reference to a location that has been deleted } elseif ($action == 'location:delete' && $origin) { $query[] = "description = '" . SQL::escape(Codes::delete_embedded($this->item['description'], 'location', $origin)) . "'"; // add a reference to a new table in the article description } elseif ($action == 'table:create' && $origin) { if (!Codes::check_embedded($this->item['description'], 'table', $origin)) { $query[] = "description = '" . SQL::escape($this->item['description'] . "\n" . '[table=' . $origin . ']' . "\n") . "'"; } // suppress a reference to a table that has been deleted } elseif ($action == 'table:delete' && $origin) { $query[] = "description = '" . SQL::escape(Codes::delete_embedded($this->item['description'], 'table', $origin)) . "'"; } // stamp the update if (!$silently) { $query[] = "edit_name='" . SQL::escape(Surfer::get_name()) . "'," . "edit_id=" . SQL::escape(Surfer::get_id()) . "," . "edit_address='" . SQL::escape(Surfer::get_email_address()) . "'," . "edit_action='" . SQL::escape($action) . "'," . "edit_date='" . gmstrftime('%Y-%m-%d %H:%M:%S') . "'"; } // update the database if (count($query)) { $query = "UPDATE " . SQL::table_name('articles') . " SET " . implode(', ', $query) . " WHERE id = " . SQL::escape($this->item['id']); SQL::query($query); } // add this page to the watch list of the contributor, on any action if (Surfer::get_id()) { Members::assign('article:' . $this->item['id'], 'user:'******'article:' . $this->item['id'], $this->item['active']); // always clear the cache, even on no update Articles::clear($this->item); // get the parent if (!$this->anchor) { $this->anchor = Anchors::get($this->item['anchor']); } // propagate the touch upwards if (is_object($this->anchor)) { $this->anchor->touch('article:update', $this->item['id'], TRUE); } }
$context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><div>' . Users::list_for_ids($owners, 'request') . Skin::finalize_list(array(Skin::build_submit_button(i18n::s('Submit a request to get access'))), 'menu_bar') . '<input type="hidden" name="id" value="' . $item['id'] . '">' . '</div></form>'; } } // re-enforce the canonical link } elseif (!$zoom_type && $page == 1 && $context['self_url'] && $whole_rendering && strncmp($context['self_url'], $context['page_link'], strlen($context['page_link']))) { Safe::header('Status: 301 Moved Permanently', TRUE, 301); Safe::header('Location: ' . $context['page_link']); Logger::error(Skin::build_link($context['page_link'])); // display the article } else { // behaviors can change page menu if (is_object($behaviors)) { $context['page_menu'] = $behaviors->add_commands('articles/view.php', 'article:' . $item['id'], $context['page_menu']); } // remember surfer visit Surfer::is_visiting(Articles::get_permalink($item), Codes::beautify_title($item['title']), 'article:' . $item['id'], $item['active']); // increment silently the hits counter if not robot, nor associate, nor owner, nor at follow-up page if (Surfer::is_crawler() || Surfer::is_associate()) { } elseif (isset($item['owner_id']) && Surfer::is($item['owner_id'])) { } elseif (!$zoom_type) { $item['hits'] = isset($item['hits']) ? $item['hits'] + 1 : 1; Articles::increment_hits($item['id']); } // initialize the rendering engine Codes::initialize(Articles::get_permalink($item)); // neighbours information $neighbours = NULL; if (Articles::has_option('with_neighbours', $anchor, $item) && is_object($anchor)) { $neighbours = $anchor->get_neighbours('article', $item); } //
if (!Surfer::is_logged()) { Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode(Users::get_permalink($item))); } // permission denied to authenticated user Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // re-enforce the canonical link } elseif (!$zoom_type && $context['self_url'] && ($canonical = Users::get_permalink($item)) && strncmp($context['self_url'], $canonical, strlen($canonical))) { Safe::header('Status: 301 Moved Permanently', TRUE, 301); Safe::header('Location: ' . $canonical); Logger::error(Skin::build_link($canonical)); // display the user profile } else { if ($whole_rendering) { // remember surfer visit Surfer::is_visiting(Users::get_permalink($item), $item['full_name'] ? $item['full_name'] : $item['nick_name'], 'user:'******'id'], $item['active']); // initialize the rendering engine Codes::initialize(Users::get_permalink($item)); // // meta-information -- $context['page_header'], etc. // // prevent search engines to present cache versions of this page if ($item['active'] != 'Y') { $context['page_header'] .= "\n" . '<meta name="robots" content="noarchive" />'; } // add canonical link if (!$zoom_type) { $context['page_header'] .= "\n" . '<link rel="canonical" href="' . Users::get_permalink($item) . '" />'; } // a meta link to a feeding page $context['page_header'] .= "\n" . '<link rel="alternate" href="' . $context['url_to_root'] . Users::get_url($item['id'], 'feed') . '" title="RSS" type="application/rss+xml" />';
$context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><div>' . Users::list_for_ids($owners, 'request') . Skin::finalize_list(array(Skin::build_submit_button(i18n::s('Submit a request to get access'))), 'menu_bar') . '<input type="hidden" name="id" value="' . $item['id'] . '">' . '</div></form>'; } } // re-enforce the canonical link } elseif (defined('NOT_INCLUDED') && !$zoom_type && $page == 1 && $context['self_url'] && strncmp($context['self_url'], $context['page_link'], strlen($context['page_link']))) { Safe::header('Status: 301 Moved Permanently', TRUE, 301); Safe::header('Location: ' . $context['page_link']); Logger::error(Skin::build_link($context['page_link'])); // display the section } else { // behaviors can change page menu if (is_object($behaviors)) { $context['page_menu'] = $behaviors->add_commands('sections/view.php', 'section:' . $item['id'], $context['page_menu']); } // remember surfer visit Surfer::is_visiting(Sections::get_permalink($item), Codes::beautify_title($item['title']), 'section:' . $item['id'], $item['active']); // increment silently the hits counter if not robot, nor associate, nor owner, nor at follow-up page if (Surfer::is_crawler() || Surfer::is_associate()) { } elseif (isset($item['owner_id']) && Surfer::is($item['owner_id'])) { } elseif (!$zoom_type) { $item['hits'] = isset($item['hits']) ? $item['hits'] + 1 : 1; Sections::increment_hits($item['id']); } // initialize the rendering engine Codes::initialize($cur_section->get_permalink()); // neighbours information $neighbours = NULL; if (Sections::has_option('with_neighbours', $anchor, $item) && is_object($anchor)) { $neighbours = $anchor->get_neighbours('section', $item); } //
// anonymous users are invited to log in or to register if (!Surfer::is_logged()) { Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode(Categories::get_permalink($item))); } // permission denied to authenticated user Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // re-enforce the canonical link } elseif (!$zoom_type && $context['self_url'] && ($canonical = Categories::get_permalink($item)) && strncmp($context['self_url'], $canonical, strlen($canonical))) { Safe::header('Status: 301 Moved Permanently', TRUE, 301); Safe::header('Location: ' . $canonical); Logger::error(Skin::build_link($canonical)); // display the category } else { // remember surfer visit Surfer::is_visiting(Categories::get_permalink($item), Codes::beautify_title($item['title']), 'category:' . $item['id'], $item['active']); // increment silently the hits counter if not robot, nor associate, nor creator, nor at follow-up page if (Surfer::is_crawler() || Surfer::is_associate()) { } elseif (Surfer::get_id() && isset($item['create_id']) && Surfer::get_id() == $item['create_id']) { } elseif (!$zoom_type) { $item['hits'] = isset($item['hits']) ? $item['hits'] + 1 : 1; Categories::increment_hits($item['id']); } // initialize the rendering engine Codes::initialize(Categories::get_permalink($item)); // // page image -- $context['page_image'] // // the category or the anchor icon, if any if (isset($item['icon_url']) && $item['icon_url']) { $context['page_image'] = $item['icon_url'];