/** * 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); } }
// 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:'******'article:' . $item['id'], TRUE); $context['page_title'] = i18n::s('Thank you for your contribution'); // the page has been duplicated $context['text'] .= '<p>' . i18n::s('The page has been duplicated.') . '</p>'; // 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'))); $menu = array_merge($menu, array($article->get_url('edit') => i18n::s('Edit the page'))); if (Surfer::may_upload()) { $menu = array_merge($menu, array('images/edit.php?anchor=' . urlencode($article->get_reference()) => i18n::s('Add an image'))); $menu = array_merge($menu, array('files/edit.php?anchor=' . urlencode($article->get_reference()) => i18n::s('Add a file'))); }
/** * post a new section * * This function populates the error context, where applicable. * * @param array an array of fields * @param boolean TRUE to update the watch list of the poster * @return the id of the new article, or FALSE on error * * @see sections/edit.php * @see sections/populate.php * @see letters/new.php * @see links/links.php * @see query.php **/ public static function post(&$fields, $watch = TRUE) { global $context; // title cannot be empty if (!isset($fields['title']) || !trim($fields['title'])) { Logger::error(i18n::s('No title has been provided.')); return FALSE; } // sanity filter $fields['title'] = strip_tags($fields['title'], '<br>'); // protect from hackers if (isset($fields['icon_url'])) { $fields['icon_url'] = encode_link($fields['icon_url']); } if (isset($fields['thumbnail_url'])) { $fields['thumbnail_url'] = encode_link($fields['thumbnail_url']); } // set default values for this editor Surfer::check_default_editor($fields); // reinforce date formats if (!isset($fields['activation_date']) || $fields['activation_date'] <= NULL_DATE) { $fields['activation_date'] = NULL_DATE; } if (!isset($fields['create_date']) || $fields['create_date'] <= NULL_DATE) { $fields['create_date'] = $fields['edit_date']; } if (!isset($fields['expiry_date']) || $fields['expiry_date'] <= NULL_DATE) { $fields['expiry_date'] = NULL_DATE; } if (!isset($fields['publish_date']) || $fields['publish_date'] <= NULL_DATE) { $fields['publish_date'] = NULL_DATE; } // set conservative default values if (!isset($fields['active_set'])) { $fields['active_set'] = 'Y'; } if (isset($fields['edit_action'])) { $fields['edit_action'] = preg_replace('/import$/i', 'update', $fields['edit_action']); } if (!isset($fields['home_panel']) || !$fields['home_panel']) { $fields['home_panel'] = 'main'; } if (!isset($fields['index_map']) || !$fields['index_map']) { $fields['index_map'] = 'Y'; } if (!isset($fields['index_news']) || !$fields['index_news']) { $fields['index_news'] = 'none'; } // save on requests if (!isset($fields['rank']) || !$fields['rank']) { $fields['rank'] = 10000; } // set layout for sections if (!isset($fields['sections_layout']) || !$fields['sections_layout'] || !preg_match('/^(accordion|carrousel|compact|custom|decorated|directory|folded|inline|jive|map|slashdot|tabs|titles|yabb|none)$/', $fields['sections_layout'])) { $fields['sections_layout'] = 'none'; } elseif ($fields['sections_layout'] == 'custom') { if (isset($fields['sections_custom_layout']) && $fields['sections_custom_layout']) { $fields['sections_layout'] = $fields['sections_custom_layout']; } else { $fields['sections_layout'] = 'none'; } } // set layout for articles if (!isset($fields['articles_layout']) || !$fields['articles_layout'] || !preg_match('/^(accordion|alistapart|carrousel|custom|compact|daily|decorated|digg|directory|hardboiled|jive|map|newspaper|none|simile|slashdot|table|tabs|tagged|threads|titles|yabb)$/', $fields['articles_layout'])) { $fields['articles_layout'] = 'decorated'; } elseif ($fields['articles_layout'] == 'custom') { if (isset($fields['articles_custom_layout']) && $fields['articles_custom_layout']) { $fields['articles_layout'] = $fields['articles_custom_layout']; } else { $fields['articles_layout'] = 'decorated'; } } // set canvas for articles if (!isset($fields['articles_canvas']) || !$fields['articles_canvas']) { $fields['articles_canvas'] = 'standard'; } // clean provided tags if (isset($fields['tags'])) { $fields['tags'] = trim($fields['tags'], " \t.:,!?"); } // cascade anchor access rights if (isset($fields['anchor']) && ($anchor = Anchors::get($fields['anchor']))) { $fields['active'] = $anchor->ceil_rights($fields['active_set']); } else { $fields['active'] = $fields['active_set']; } // always create a random handle for this section if (!isset($fields['handle']) || strlen($fields['handle']) < 32) { $fields['handle'] = md5(mt_rand()); } $handle = "handle='" . SQL::escape($fields['handle']) . "',"; // allow anonymous surfer to access this section during his session if (!Surfer::get_id()) { Surfer::add_handle($fields['handle']); } // insert a new record $query = "INSERT INTO " . SQL::table_name('sections') . " SET "; // on import if (isset($fields['id'])) { $query .= "id='" . SQL::escape($fields['id']) . "',"; } // all fields should be visible $query .= "anchor='" . SQL::escape(isset($fields['anchor']) ? $fields['anchor'] : '') . "'," . "activation_date='" . SQL::escape($fields['activation_date']) . "'," . "active='" . SQL::escape($fields['active']) . "'," . "active_set='" . SQL::escape($fields['active_set']) . "'," . "articles_canvas='" . SQL::escape(isset($fields['articles_canvas']) ? $fields['articles_canvas'] : 'null') . "'," . "articles_layout='" . SQL::escape(isset($fields['articles_layout']) ? $fields['articles_layout'] : 'decorated') . "'," . "articles_templates='" . SQL::escape(isset($fields['articles_templates']) ? $fields['articles_templates'] : '') . "'," . "behaviors='" . SQL::escape(isset($fields['behaviors']) ? $fields['behaviors'] : '') . "'," . "content_options='" . SQL::escape(isset($fields['content_options']) ? $fields['content_options'] : '') . "'," . "content_overlay='" . SQL::escape(isset($fields['content_overlay']) ? $fields['content_overlay'] : '') . "'," . "create_address='" . SQL::escape(isset($fields['create_address']) ? $fields['create_address'] : $fields['edit_address']) . "', " . "create_date='" . SQL::escape($fields['create_date']) . "'," . "create_id=" . SQL::escape(isset($fields['create_id']) ? $fields['create_id'] : $fields['edit_id']) . ", " . "create_name='" . SQL::escape(isset($fields['create_name']) ? $fields['create_name'] : $fields['edit_name']) . "', " . "description='" . SQL::escape(isset($fields['description']) ? $fields['description'] : '') . "'," . "edit_action='" . SQL::escape(isset($fields['edit_action']) ? $fields['edit_action'] : 'section:create') . "', " . "edit_address='" . SQL::escape($fields['edit_address']) . "', " . "edit_date='" . SQL::escape($fields['edit_date']) . "'," . "edit_id=" . SQL::escape($fields['edit_id']) . ", " . "edit_name='" . SQL::escape($fields['edit_name']) . "', " . "expiry_date='" . SQL::escape($fields['expiry_date']) . "'," . "extra='" . SQL::escape(isset($fields['extra']) ? $fields['extra'] : '') . "'," . "family='" . SQL::escape(isset($fields['family']) ? $fields['family'] : '') . "'," . "file_overlay='" . SQL::escape(isset($fields['file_overlay']) ? $fields['file_overlay'] : '') . "'," . $handle . "hits=" . SQL::escape(isset($fields['hits']) ? $fields['hits'] : 0) . "," . "home_panel='" . SQL::escape(isset($fields['home_panel']) ? $fields['home_panel'] : 'main') . "'," . "icon_url='" . SQL::escape(isset($fields['icon_url']) ? $fields['icon_url'] : '') . "'," . "index_map='" . SQL::escape(isset($fields['index_map']) ? $fields['index_map'] : 'Y') . "'," . "index_news='" . SQL::escape(isset($fields['index_news']) ? $fields['index_news'] : 'static') . "'," . "index_news_count=" . SQL::escape(isset($fields['index_news_count']) ? $fields['index_news_count'] : 5) . "," . "index_title='" . SQL::escape(isset($fields['index_title']) ? $fields['index_title'] : '') . "'," . "introduction='" . SQL::escape(isset($fields['introduction']) ? $fields['introduction'] : '') . "'," . "language='" . SQL::escape(isset($fields['language']) ? $fields['language'] : '') . "'," . "locked='" . SQL::escape(isset($fields['locked']) ? $fields['locked'] : 'N') . "'," . "meta='" . SQL::escape(isset($fields['meta']) ? $fields['meta'] : '') . "'," . "nick_name='" . SQL::escape(isset($fields['nick_name']) ? $fields['nick_name'] : '') . "'," . "options='" . SQL::escape(isset($fields['options']) ? $fields['options'] : '') . "'," . "overlay='" . SQL::escape(isset($fields['overlay']) ? $fields['overlay'] : '') . "'," . "overlay_id='" . SQL::escape(isset($fields['overlay_id']) ? $fields['overlay_id'] : '') . "'," . "owner_id=" . SQL::escape(isset($fields['create_id']) ? $fields['create_id'] : $fields['edit_id']) . ", " . "prefix='" . SQL::escape(isset($fields['prefix']) ? $fields['prefix'] : '') . "'," . "rank='" . SQL::escape(isset($fields['rank']) ? $fields['rank'] : 10000) . "'," . "section_overlay='" . SQL::escape(isset($fields['section_overlay']) ? $fields['section_overlay'] : '') . "'," . "sections_layout='" . SQL::escape(isset($fields['sections_layout']) ? $fields['sections_layout'] : 'map') . "'," . "suffix='" . SQL::escape(isset($fields['suffix']) ? $fields['suffix'] : '') . "'," . "tags='" . SQL::escape(isset($fields['tags']) ? $fields['tags'] : '') . "'," . "template='" . SQL::escape(isset($fields['template']) ? $fields['template'] : '') . "'," . "thumbnail_url='" . SQL::escape(isset($fields['thumbnail_url']) ? $fields['thumbnail_url'] : '') . "'," . "title='" . SQL::escape(isset($fields['title']) ? $fields['title'] : '') . "'," . "trailer='" . SQL::escape(isset($fields['trailer']) ? $fields['trailer'] : '') . "'"; // actual insert if (SQL::query($query) === FALSE) { return FALSE; } // remember the id of the new item $fields['id'] = SQL::get_last_id($context['connection']); // assign the page to related categories Categories::remember('section:' . $fields['id'], NULL_DATE, isset($fields['tags']) ? $fields['tags'] : ''); // turn author to page editor and update author's watch list if ($watch && isset($fields['edit_id']) && $fields['edit_id']) { Members::assign('user:'******'edit_id'], 'section:' . $fields['id']); Members::assign('section:' . $fields['id'], 'user:'******'edit_id']); } // clear the cache Sections::clear($fields); // return the id of the new item return $fields['id']; }
/** * remember that surfer is joining a meeting * */ function join_meeting() { global $context; // sanity check if (!is_callable(array($this->anchor, 'get_reference'))) { return; } // create a comment only on first join, and if not a robot, and if comments are allowed if (!isset($_SESSION['event_' . $this->anchor->get_reference()]) && !Surfer::is_crawler() && !$this->anchor->has_option('no_comments')) { // track the new participant include_once $context['path_to_root'] . 'comments/comments.php'; $fields = array(); $fields['anchor'] = $this->anchor->get_reference(); $fields['description'] = sprintf(i18n::s('%s has joined the meeting'), Surfer::get_name()); $fields['type'] = 'notification'; Comments::post($fields); } // remember that you joined the event $_SESSION['event_' . $this->anchor->get_reference()] = TRUE; // additional steps only for authenticated users if (!Surfer::get_id()) { return; } // add this page to the watching list of this surfer Members::assign($this->anchor->get_reference(), 'user:'******'path_to_root'] . 'shared/enrolments.php'; enrolments::confirm($this->anchor->get_reference()); }
$fields['create_name'] = $user['full_name']; $fields['edit_id'] = $user['id']; $fields['edit_name'] = $user['full_name']; $fields['owner_id'] = $user['id']; } if ($id = Articles::post($fields)) { $text .= sprintf(i18n::s('A page "%s" has been created.'), $fields['nick_name']) . BR . "\n"; // assign aeditor if ($user = Users::get('aeditor')) { Members::assign('user:'******'id'], 'article:' . $id); Members::assign('article:' . $id, 'user:'******'id']); } // assign areader if ($user = Users::get('areader')) { Members::assign('user:'******'id'], 'article:' . $id); Members::assign('article:' . $id, 'user:'******'id']); } } else { $text .= Logger::error_pop() . BR . "\n"; } } // sections // $text .= Skin::build_block(i18n::s('Sections'), 'subtitle'); // 'files' section if (Sections::get('files')) { $text .= sprintf(i18n::s('A section "%s" already exists.'), 'files') . BR . "\n"; } else { $fields = array(); $fields['nick_name'] = 'files'; $fields['title'] = i18n::c('Files');
$section->load_by_content($anchor); $anchor = $section; $_REQUEST['anchor'] = $anchor->get_reference(); $_REQUEST['active_set'] = $_REQUEST['active']; // do not break home page layout $_REQUEST['index_map'] = 'N'; // display the form on error if (!($_REQUEST['id'] = Sections::post($_REQUEST))) { $item = $_REQUEST; $with_form = TRUE; // post-processing } else { // make the surfer an editor of this section Members::assign('user:'******'section:' . $_REQUEST['id']); // also update its watch list Members::assign('section:' . $_REQUEST['id'], 'user:'******'section:create', $_REQUEST['id'], isset($_REQUEST['active']) && $_REQUEST['active'] != 'Y'); } // add content to the new group if ($_REQUEST['space_type'] == 'group') { // a sticky page to define group rules $fields = array(); $fields['anchor'] = 'section:' . $_REQUEST['id']; $fields['description'] = i18n::c('This is the right place to describe ways of working in this group.'); $fields['locked'] = 'Y'; // no direct contributions $fields['index_map'] = 'N'; // not mentioned at the home page $fields['publish_date'] = gmstrftime('%Y-%m-%d %H:%M:%S');
$query = "DELETE FROM " . SQL::table_name('enrolments') . " WHERE id = " . SQL::escape($_REQUEST['target']); SQL::query($query); } // validate an application if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'validate' && isset($_REQUEST['target']) && $_REQUEST['target']) { // update enrolment record $query = "UPDATE " . SQL::table_name('enrolments') . " SET approved = 'Y' WHERE id = " . SQL::escape($_REQUEST['target']); SQL::query($query); // list enrolment for this meeting $query = "SELECT * FROM " . SQL::table_name('enrolments') . " WHERE id = " . SQL::escape($_REQUEST['target']); if (($result = SQL::query_first($query)) && ($user = Users::get($result['user_id']))) { // add the page to the watch list Members::assign($anchor->get_reference(), 'user:'******'id']); // ensure that the enrolled person can access private pages if ($anchor->is_hidden()) { Members::assign('user:'******'id'], $anchor->get_reference()); } // confirm enrolment by e-mail if ($user['email'] && preg_match(VALID_RECIPIENT, $user['email'])) { // use this email address if ($user['full_name']) { $recipient = Mailer::encode_recipient($user['email'], $user['full_name']); } else { $recipient = Mailer::encode_recipient($user['email'], $user['nick_name']); } // mail subject $subject = sprintf(i18n::c('%s: %s'), i18n::c('Meeting'), strip_tags($anchor->get_title())); // headline $headline = sprintf(i18n::c('%s has confirmed your participation to %s'), Surfer::get_link(), '<a href="' . $context['url_to_home'] . $context['url_to_root'] . $anchor->get_url() . '">' . $anchor->get_title() . '</a>'); // message confirmation $message = $overlay->get_invite_default_message('PUBLISH');
$way = isset($_REQUEST['way']) ? $_REQUEST['way'] : 'assign'; // get object interface $anchor = Anchors::get($_REQUEST['anchor']); $cat = Anchors::get($_REQUEST['cat']); // check existance if (!is_object($anchor) && !is_object($cat) && $cat->get_type() != 'category') { $output['success'] = false; break; } // check surfer's rights if (!$cat->allows('categorization', $anchor)) { $output['success'] = false; break; } if ($way == 'assign') { $output['success'] = Members::assign($cat->get_reference(), $anchor->get_reference()); } else { $output['success'] = Members::free($cat->get_reference(), $anchor->get_reference()); } break; // create a new object under a given anchor, same kind as anchor // this means to build a hierarchy, eg sections or categories // create a new object under a given anchor, same kind as anchor // this means to build a hierarchy, eg sections or categories case 'create': // reference to anchor and new title are mandatory if (!isset($_REQUEST['anchor']) || !$_REQUEST['anchor'] || !isset($_REQUEST['title']) || !$_REQUEST['title']) { die_on_invalid(); } // get type of anchor from given reference list($type, $anchor_id) = explode(":", $_REQUEST['anchor']);
// permission denied to authenticated user Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // do the job } elseif (!count($context['error'])) { // look for the user through his nick name if (isset($_REQUEST['assigned_name']) && ($user = Users::get($_REQUEST['assigned_name']))) { $_REQUEST['anchor'] = 'user:'******'id']; } // transfer ownership if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'set' && isset($_REQUEST['anchor'])) { // assign a user, and also update his watch list $attributes = array('id' => $item['id'], 'owner_id' => $user['id']); Sections::put_attributes($attributes); Members::assign($_REQUEST['anchor'], 'section:' . $item['id']); Members::assign('section:' . $item['id'], $_REQUEST['anchor']); $context['text'] .= '<p>' . sprintf(i18n::s('Current owner is %s'), Users::get_link($user['full_name'], $user['email'], $user['id'])) . '</p>'; // name current owner } elseif (isset($item['owner_id']) && ($owner = Users::get($item['owner_id']))) { $context['text'] .= '<p>' . sprintf(i18n::s('Current owner is %s'), Users::get_link($owner['full_name'], $owner['email'], $owner['id'])) . '</p>'; } // delegate to another person $context['text'] .= '<p style="margin-top: 2em;">' . i18n::s('To transfer ownership to another person, type some letters of the name you are looking for.') . '</p>'; // the form to link additional users $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><p>' . '<input type="text" name="assigned_name" id="assigned_name" size="45" maxlength="255" />' . '<input type="hidden" name="id" value="' . encode_field($item['id']) . '" />' . '<input type="hidden" name="action" value="set" />' . ' <input type="submit" id="submit_button" value="' . i18n::s('Submit') . '" style="display: none;" />' . '</p></form>' . "\n"; // enable autocompletion Page::insert_script('$(function() {' . "\n" . ' $("#name").focus();' . "\n" . ' Yacs.autocomplete_names("assigned_name",true, "", function(data) { $("#submit_button").show().click(); });' . "\n" . '});' . "\n"); // back to the anchor page $links = array(); $links[] = Skin::build_link(Sections::get_permalink($item) . '#_users', i18n::s('Done'), 'button'); $context['text'] .= Skin::finalize_list($links, 'assistant_bar');
// feed-back to surfer // $context['text'] .= '<p>'.i18n::s('A new thread has been created, and it will be listed in profiles of the persons that you have involved. You can invite additional people later on if you wish.').'</p>'; // increment the post counter of the surfer Users::increment_posts(Surfer::get_id()); // make editors of the new page Members::assign('user:'******'article:' . $article['id']); foreach ($items as $item) { if (isset($item['id'])) { 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;
} elseif (!($articles = Articles::search($search, 1.0, 50, 'raw'))) { Logger::error(i18n::s('No item has been found.')); // create a category for this keyword if none exists yet } elseif (!($category =& Categories::get_by_keyword($search))) { $fields = array(); $fields['keywords'] = $search; $fields['anchor'] = $root_category; $fields['title'] = ucfirst($search); if ($fields['id'] = Categories::post($fields)) { Categories::clear($fields); $category = Categories::get($fields['id']); } } // ensure we have a valid category for found articles if (isset($articles) && (!isset($category) || !$category)) { Logger::error(i18n::s('No item has been found.')); } elseif (isset($articles) && is_array($articles)) { foreach ($articles as $id => $not_used) { if (!Members::assign('category:' . $category['id'], 'article:' . $id)) { break; } } // redirect to the updated category, if no error has happened if (!count($context['error'])) { Safe::redirect(Categories::get_permalink($category)); } } // failed operation $context['text'] .= '<p>' . i18n::s('Impossible to update the item.') . '</p>'; // render the skin render_skin();
} // report on results $context['text'] .= '<p>' . sprintf(i18n::ns('%d page has been associated with %s.', '%d pages have been associated with %s.', $count), $count, Skin::build_link($destination->get_url(), $destination->get_title(), 'category')) . '</p>'; // follow-up commands $follow_up = i18n::s('What do you want to do now?'); $menu = array(); $menu[] = Skin::build_link(Sections::get_permalink($item), i18n::s('View the section'), 'span'); $menu[] = Skin::build_link(Sections::get_url($item['id'], 'manage'), i18n::s('Manage it'), 'span'); $follow_up .= Skin::finalize_list($menu, 'menu_bar'); $context['text'] .= Skin::build_block($follow_up, 'bottom'); // sections } elseif (isset($_REQUEST['selected_sections'])) { // do it, and clear the cache $count = 0; foreach ($_REQUEST['selected_sections'] as $dummy => $id) { if (Members::assign($_REQUEST['associate_to'], 'section:' . $id)) { $count++; } } // report on results $context['text'] .= '<p>' . sprintf(i18n::ns('%d section has been associated with %s.', '%d sections have been associated with %s.', $count), $count, Skin::build_link($destination->get_url(), $destination->get_title(), 'category')) . '</p>'; // follow-up commands $follow_up = i18n::s('What do you want to do now?'); $menu = array(); $menu[] = Skin::build_link(Sections::get_permalink($item), i18n::s('View the section'), 'span'); $menu[] = Skin::build_link(Sections::get_url($item['id'], 'manage'), i18n::s('Manage it'), 'span'); $follow_up .= Skin::finalize_list($menu, 'menu_bar'); $context['text'] .= Skin::build_block($follow_up, 'bottom'); // nothing to do } else { Logger::error(i18n::s('No page has been selected.'));
// permission denied to authenticated user Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // do the job } elseif (!count($context['error'])) { // look for the user through his nick name if (isset($_REQUEST['assigned_name']) && ($user = Users::get($_REQUEST['assigned_name']))) { $_REQUEST['anchor'] = 'user:'******'id']; } // transfer ownership if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'set' && isset($_REQUEST['anchor'])) { // assign a user, and also update his watch list $attributes = array('id' => $item['id'], 'owner_id' => $user['id']); Articles::put_attributes($attributes); Members::assign($_REQUEST['anchor'], 'article:' . $item['id']); Members::assign('article:' . $item['id'], $_REQUEST['anchor']); $context['text'] .= '<p>' . sprintf(i18n::s('Current owner is %s'), Users::get_link($user['full_name'], $user['email'], $user['id'])) . '</p>'; // name current owner } elseif (isset($item['owner_id']) && ($owner = Users::get($item['owner_id']))) { $context['text'] .= '<p>' . sprintf(i18n::s('Current owner is %s'), Users::get_link($owner['full_name'], $owner['email'], $owner['id'])) . '</p>'; } // delegate to another person $context['text'] .= '<p style="margin-top: 2em;">' . i18n::s('To transfer ownership to another person, type some letters of the name you are looking for.') . '</p>'; // the form to link additional users $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><p>' . '<input type="text" name="assigned_name" id="assigned_name" size="45" maxlength="255" />' . '<input type="hidden" name="id" value="' . encode_field($item['id']) . '" />' . '<input type="hidden" name="action" value="set" />' . ' <input type="submit" id="submit_button" value="' . i18n::s('Submit') . '" style="display: none;" />' . '</p></form>' . "\n"; // enable autocompletion Page::insert_script('$(function() {' . "\n" . ' $("#name").focus();' . "\n" . ' Yacs.autocomplete_names("assigned_name",true, "", function(data) { $("#submit_button").show().click(); });' . "\n" . '});' . "\n"); // back to the anchor page $links = array(); $links[] = Skin::build_link(articles::get_permalink($item) . '#_users', i18n::s('Done'), 'button'); $context['text'] .= Skin::finalize_list($links, 'assistant_bar');
// create a new page if ($item['id'] = Sections::post($item, FALSE)) { // also duplicate the provided overlay, if any -- re-use 'overlay_type' only $overlay = Overlay::load($item, 'section:' . $item['id']); // post an overlay, with the new section id if (is_object($overlay)) { $overlay->remember('insert', $item, 'section:' . $item['id']); } // duplicate all related items, images, etc. Anchors::duplicate_related_to($original_anchor, 'section:' . $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('section:' . $item['id'], 'user:'******'section:' . $item['id'], TRUE); $context['page_title'] = i18n::s('Thank you for your contribution'); // the page has been duplicated $context['text'] .= '<p>' . i18n::s('The section has been duplicated.') . '</p>'; // follow-up commands $follow_up = i18n::s('What do you want to do now?'); $menu = array(); $menu = array_merge($menu, array($section->get_url() => i18n::s('View the section'))); $menu = array_merge($menu, array($section->get_url('edit') => i18n::s('Edit this section'))); $follow_up .= Skin::build_list($menu, 'menu_bar'); $context['text'] .= Skin::build_block($follow_up, 'bottom'); // log the creation of a new section $label = sprintf(i18n::c('Section copy: %s'), strip_tags($section->get_title()));
Members::assign($_REQUEST['anchor'], $_REQUEST['member']); } } // set editor } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'set' && isset($_REQUEST['editor']) && isset($_REQUEST['member'])) { Members::assign($_REQUEST['editor'], $_REQUEST['member']); // reset editor } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'reset' && isset($_REQUEST['editor']) && isset($_REQUEST['member'])) { Members::free($_REQUEST['editor'], $_REQUEST['member']); // purge watch list too if ($anchor->is_hidden()) { Members::free($_REQUEST['member'], $_REQUEST['editor']); } // set watcher } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'set' && isset($_REQUEST['watcher']) && isset($_REQUEST['member'])) { Members::assign($_REQUEST['member'], $_REQUEST['watcher']); // reset watcher } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'reset' && isset($_REQUEST['watcher']) && isset($_REQUEST['member'])) { Members::free($_REQUEST['member'], $_REQUEST['watcher']); // break an assignment } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'reset' && isset($_REQUEST['anchor']) && isset($_REQUEST['member'])) { Members::free($_REQUEST['anchor'], $_REQUEST['member']); // following links between users are not symmetrical if (!preg_match('/^user:/', $_REQUEST['member'])) { Members::free($_REQUEST['member'], $_REQUEST['anchor']); } } // the form to link additional users $form = '<form method="post" action="' . $context['script_url'] . '" id="main_form">'; // horizontal layout $cells = array();
/** * remember an action once it's done * * This function saves data into the table [code]yacs_issues[/code]. * * @see overlays/overlay.php * * @param string the action 'insert', 'update' or 'delete' * @param array the hosting record * @param string reference of the hosting record (e.g., 'article:123') * @return FALSE on error, TRUE otherwise */ function remember($action, $host, $reference) { global $context; // locate anchor on 'insert' if ($reference) { $this->anchor = Anchors::get($reference); } // remember data from the anchor $this->attributes['anchor_reference'] = ''; $this->attributes['anchor_title'] = ''; $this->attributes['anchor_url'] = ''; if (is_callable(array($this->anchor, 'get_url'))) { $this->attributes['anchor_reference'] = $this->anchor->get_reference(); $this->attributes['anchor_title'] = $this->anchor->get_title(); $this->attributes['anchor_url'] = $this->anchor->get_url(); } // set default values for this editor Surfer::check_default_editor($this->attributes); // default date values if (!isset($this->attributes['create_date']) || $this->attributes['create_date'] <= NULL_DATE) { $this->attributes['create_date'] = $this->attributes['edit_date']; } if (!isset($this->attributes['qualification_date']) || $this->attributes['qualification_date'] <= NULL_DATE) { $this->attributes['qualification_date'] = NULL_DATE; } if (!isset($this->attributes['analysis_date']) || $this->attributes['analysis_date'] <= NULL_DATE) { $this->attributes['analysis_date'] = NULL_DATE; } if (!isset($this->attributes['resolution_date']) || $this->attributes['resolution_date'] <= NULL_DATE) { $this->attributes['resolution_date'] = NULL_DATE; } if (!isset($this->attributes['close_date']) || $this->attributes['close_date'] <= NULL_DATE) { $this->attributes['close_date'] = NULL_DATE; } // add a notification to the anchor page $comments = array(); // build the update query switch ($action) { case 'delete': $query = "DELETE FROM " . SQL::table_name('issues') . " WHERE anchor LIKE '" . $this->attributes['anchor_reference'] . "'"; break; case 'insert': $comments[] = i18n::s('Page has been created'); // set host owner, if any if (isset($this->attributes['owner']) && ($user = Users::get($this->attributes['owner'])) && $user['id'] != Surfer::get_id()) { $fields = array(); $fields['owner_id'] = $user['id']; $this->anchor->set_values($fields); Members::assign('user:'******'id'], $this->anchor->get_reference()); Members::assign($this->anchor->get_reference(), 'user:'******'id']); $comments[] = sprintf(i18n::s('Owner has been changed to %s'), Skin::build_link(Users::get_permalink($user), $user['full_name'])); } $query = "INSERT INTO " . SQL::table_name('issues') . " SET \n" . "anchor='" . SQL::escape($this->attributes['anchor_reference']) . "', \n" . "anchor_url='" . SQL::escape($this->attributes['anchor_url']) . "', \n" . "color='" . SQL::escape(isset($this->attributes['color']) ? $this->attributes['color'] : 'green') . "', \n" . "status='" . SQL::escape(isset($this->attributes['status']) ? $this->attributes['status'] : 'on-going:suspect') . "', \n" . "title='" . SQL::escape($this->attributes['anchor_title']) . "', \n" . "type='" . SQL::escape(isset($this->attributes['type']) ? $this->attributes['type'] : 'incident') . "', \n" . "create_name='" . SQL::escape(isset($this->attributes['create_name']) ? $this->attributes['create_name'] : $this->attributes['edit_name']) . "', \n" . "create_id=" . SQL::escape(isset($this->attributes['create_id']) ? $this->attributes['create_id'] : $this->attributes['edit_id']) . ", \n" . "create_address='" . SQL::escape(isset($this->attributes['create_address']) ? $this->attributes['create_address'] : $this->attributes['edit_address']) . "', \n" . "create_date='" . SQL::escape(isset($this->attributes['create_date']) ? $this->attributes['create_date'] : $this->attributes['edit_date']) . "', \n" . "edit_name='" . SQL::escape($this->attributes['edit_name']) . "', \n" . "edit_id=" . SQL::escape($this->attributes['edit_id']) . ", \n" . "edit_address='" . SQL::escape($this->attributes['edit_address']) . "', \n" . "edit_action='create', \n" . "edit_date='" . SQL::escape($this->attributes['edit_date']) . "', \n" . "qualification_date='" . SQL::escape(isset($this->attributes['qualification_date']) ? $this->attributes['qualification_date'] : NULL_DATE) . "', \n" . "analysis_date='" . SQL::escape(isset($this->attributes['analysis_date']) ? $this->attributes['analysis_date'] : NULL_DATE) . "', \n" . "resolution_date='" . SQL::escape(isset($this->attributes['resolution_date']) ? $this->attributes['resolution_date'] : NULL_DATE) . "', \n" . "close_date='" . SQL::escape(isset($this->attributes['close_date']) ? $this->attributes['close_date'] : NULL_DATE) . "'"; break; case 'update': // only associates and page owners can update the record if (is_callable(array($this->anchor, 'is_owned')) && $this->anchor->is_owned()) { // detect type modification if ($this->attributes['type'] != $this->snapshot['type']) { $comments[] = sprintf(i18n::s('Workflow has been changed to "%s"'), $this->get_type_label($this->attributes['type'])); } // detect color modification if ($this->attributes['color'] != $this->snapshot['color']) { $comments[] = $this->get_color_label($this->attributes['color']); } // change host owner, if any if ($this->attributes['owner'] && ($user = Users::get($this->attributes['owner'])) && $user['id'] != $this->anchor->get_value('owner_id')) { $fields = array(); $fields['owner_id'] = $user['id']; $this->anchor->set_values($fields); Members::assign('user:'******'id'], $this->anchor->get_reference()); Members::assign($this->anchor->get_reference(), 'user:'******'id']); $comments[] = sprintf(i18n::s('Owner has been changed to %s'), Skin::build_link(Users::get_permalink($user), $user['full_name'])); } // update the table of issues $query = "UPDATE " . SQL::table_name('issues') . " SET \n" . "anchor='" . SQL::escape($this->attributes['anchor_reference']) . "', \n" . "anchor_url='" . SQL::escape($this->attributes['anchor_url']) . "', \n" . "color='" . SQL::escape($this->attributes['color']) . "', \n" . "status='" . SQL::escape($this->attributes['status']) . "', \n" . "title='" . SQL::escape($this->attributes['anchor_title']) . "', \n" . "type='" . SQL::escape($this->attributes['type']) . "', \n" . "create_date='" . SQL::escape(isset($this->attributes['create_date']) ? $this->attributes['create_date'] : $this->attributes['edit_date']) . "', \n" . "qualification_date='" . SQL::escape(isset($this->attributes['qualification_date']) ? $this->attributes['qualification_date'] : NULL_DATE) . "', \n" . "analysis_date='" . SQL::escape(isset($this->attributes['analysis_date']) ? $this->attributes['analysis_date'] : NULL_DATE) . "', \n" . "resolution_date='" . SQL::escape(isset($this->attributes['resolution_date']) ? $this->attributes['resolution_date'] : NULL_DATE) . "', \n" . "close_date='" . SQL::escape(isset($this->attributes['close_date']) ? $this->attributes['close_date'] : NULL_DATE) . "', \n"; // detect status modification if ($this->attributes['status'] != $this->snapshot['status']) { $comments[] = $this->get_status_label($this->attributes['status']); // depending of new status switch ($this->attributes['status']) { // case has been recorded --should not happen case 'on-going:suspect': $query .= "create_name='" . SQL::escape($this->attributes['edit_name']) . "', \n" . "create_id=" . SQL::escape($this->attributes['edit_id']) . ", \n" . "create_address='" . SQL::escape($this->attributes['edit_address']) . "', \n"; break; // problem has been validated // problem has been validated case 'cancelled:suspect': case 'on-going:problem': $query .= "qualification_name='" . SQL::escape($this->attributes['edit_name']) . "', \n" . "qualification_id='" . SQL::escape($this->attributes['edit_id']) . "', \n" . "qualification_address='" . SQL::escape($this->attributes['edit_address']) . "', \n"; break; // cause has been identified // cause has been identified case 'cancelled:problem': case 'on-going:issue': $query .= "analysis_name='" . SQL::escape($this->attributes['edit_name']) . "', \n" . "analysis_id='" . SQL::escape($this->attributes['edit_id']) . "', \n" . "analysis_address='" . SQL::escape($this->attributes['edit_address']) . "', \n"; break; // solution has been achieved // solution has been achieved case 'cancelled:issue': case 'on-going:solution': $query .= "resolution_name='" . SQL::escape($this->attributes['edit_name']) . "', \n" . "resolution_id='" . SQL::escape($this->attributes['edit_id']) . "', \n" . "resolution_address='" . SQL::escape($this->attributes['edit_address']) . "', \n"; break; // ending the issue // ending the issue case 'cancelled:solution': case 'completed:solution': $query .= "close_name='" . SQL::escape($this->attributes['edit_name']) . "', \n" . "close_id='" . SQL::escape($this->attributes['edit_id']) . "', \n" . "close_address='" . SQL::escape($this->attributes['edit_address']) . "', \n"; break; } } // track the person who modifies the record $query .= "edit_name='" . SQL::escape($this->attributes['edit_name']) . "', \n" . "edit_id=" . SQL::escape($this->attributes['edit_id']) . ", \n" . "edit_address='" . SQL::escape($this->attributes['edit_address']) . "', \n" . "edit_action='update', \n" . "edit_date='" . SQL::escape($this->attributes['edit_date'] ? $this->attributes['edit_date'] : $this->attributes['edit_date']) . "' \n" . " WHERE anchor LIKE '" . SQL::escape($this->attributes['anchor_reference']) . "'"; } // ensure that this change has been recorded if (!$comments) { $comments[] = i18n::s('Page has been edited'); } break; } // execute the query --don't stop on error if (isset($query) && $query) { SQL::query($query); } // add a comment if ($comments && !$this->anchor->has_option('no_comments')) { include_once $context['path_to_root'] . 'comments/comments.php'; $fields = array(); $fields['anchor'] = $this->attributes['anchor_reference']; $fields['description'] = join(BR, $comments); $fields['type'] = 'notification'; Comments::post($fields); } // job done return TRUE; }
// clean the provided string $recipient = trim(str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $recipient)); // look for a user with this nick name if (!($user = Users::lookup($recipient))) { // skip this recipient if ($recipient) { Logger::error(sprintf(i18n::s('Error while sending the message to %s'), $recipient)); } continue; } // make this user an editor of the target item if ($item['active'] == 'N' || Sections::is_owned($item, $anchor, TRUE) && isset($_REQUEST['provide_credentials']) && $_REQUEST['provide_credentials'] == 'Y') { Members::assign('user:'******'id'], 'section:' . $item['id']); } // always add the item to the watch list Members::assign('section:' . $item['id'], 'user:'******'id']); // propagate the invitation to the overlay, if applicable if (is_callable(array($overlay, 'invite'))) { $overlay->invite($user['id']); } // this person has no valid email address if (!$user['email'] || !preg_match(VALID_RECIPIENT, $user['email'])) { continue; } // use this email address if ($user['full_name']) { $recipient = Mailer::encode_recipient($user['email'], $user['full_name']); } else { $recipient = Mailer::encode_recipient($user['email'], $user['nick_name']); } // headline
/** * put an updated article in the database * * @param array an array of fields * @return TRUE on success, or FALSE on error * * @see articles/edit.php * @see services/blog.php **/ public static function put(&$fields) { global $context; // id cannot be empty if (!isset($fields['id']) || !is_numeric($fields['id'])) { Logger::error(i18n::s('No item has the provided id.')); return FALSE; } // title cannot be empty if (!isset($fields['title']) || !$fields['title']) { Logger::error(i18n::s('No title has been provided.')); return FALSE; } // sanity filter $fields['title'] = strip_tags($fields['title'], '<br>'); // anchor cannot be empty if (!isset($fields['anchor']) || !$fields['anchor'] || !($anchor = Anchors::get($fields['anchor']))) { Logger::error(i18n::s('No anchor has been found.')); return FALSE; } // protect from hackers if (isset($fields['icon_url'])) { $fields['icon_url'] = preg_replace('/[^\\w\\/\\.,:%&\\?=-]+/', '_', $fields['icon_url']); } if (isset($fields['thumbnail_url'])) { $fields['thumbnail_url'] = preg_replace('/[^\\w\\/\\.,:%&\\?=-]+/', '_', $fields['thumbnail_url']); } // set default values for this editor Surfer::check_default_editor($fields); // reinforce date formats if (!isset($fields['publish_date']) || $fields['publish_date'] <= NULL_DATE) { $fields['publish_date'] = NULL_DATE; } // set conservative default values if (!isset($fields['active_set'])) { $fields['active_set'] = 'Y'; } if (!isset($fields['rank'])) { $fields['rank'] = 10000; } // set canvas default value if (!isset($fields['canvas']) || !$fields['canvas']) { $fields['canvas'] = 'standard'; } // clean provided tags if (isset($fields['tags'])) { $fields['tags'] = trim($fields['tags'], " \t.:,!?"); } // cascade anchor access rights $fields['active'] = $anchor->ceil_rights($fields['active_set']); // columns updated $query = array(); // fields that are visible only to associates -- see articles/edit.php if (Surfer::is_associate()) { $query[] = "prefix='" . SQL::escape(isset($fields['prefix']) ? $fields['prefix'] : '') . "'"; $query[] = "suffix='" . SQL::escape(isset($fields['suffix']) ? $fields['suffix'] : '') . "'"; $query[] = "canvas='" . SQL::escape(isset($fields['canvas']) ? $fields['canvas'] : '') . "'"; } // fields that are visible only to associates and to editors -- see articles/edit.php if (Surfer::is_empowered() && Surfer::is_member()) { $query[] = "nick_name='" . SQL::escape(isset($fields['nick_name']) ? $fields['nick_name'] : '') . "'"; $query[] = "behaviors='" . SQL::escape(isset($fields['behaviors']) ? $fields['behaviors'] : '') . "'"; $query[] = "extra='" . SQL::escape(isset($fields['extra']) ? $fields['extra'] : '') . "'"; $query[] = "file_overlay='" . SQL::escape(isset($fields['file_overlay']) ? $fields['file_overlay'] : '') . "'"; $query[] = "icon_url='" . SQL::escape(isset($fields['icon_url']) ? $fields['icon_url'] : '') . "'"; $query[] = "thumbnail_url='" . SQL::escape(isset($fields['thumbnail_url']) ? $fields['thumbnail_url'] : '') . "'"; $query[] = "rank='" . SQL::escape($fields['rank']) . "'"; $query[] = "locked='" . SQL::escape(isset($fields['locked']) ? $fields['locked'] : 'N') . "'"; $query[] = "meta='" . SQL::escape(isset($fields['meta']) ? $fields['meta'] : '') . "'"; $query[] = "options='" . SQL::escape(isset($fields['options']) ? $fields['options'] : '') . "'"; $query[] = "trailer='" . SQL::escape(isset($fields['trailer']) ? $fields['trailer'] : '') . "'"; $query[] = "active='" . SQL::escape($fields['active']) . "'"; $query[] = "active_set='" . SQL::escape($fields['active_set']) . "'"; } // fields visible to authorized member $query[] = "anchor='" . SQL::escape($fields['anchor']) . "'"; $query[] = "anchor_type=SUBSTRING_INDEX('" . SQL::escape($fields['anchor']) . "', ':', 1)"; $query[] = "anchor_id=SUBSTRING_INDEX('" . SQL::escape($fields['anchor']) . "', ':', -1)"; $query[] = "title='" . SQL::escape($fields['title']) . "'"; $query[] = "source='" . SQL::escape(isset($fields['source']) ? $fields['source'] : '') . "'"; $query[] = "introduction='" . SQL::escape(isset($fields['introduction']) ? $fields['introduction'] : '') . "'"; $query[] = "description='" . SQL::escape(isset($fields['description']) ? $fields['description'] : '') . "'"; $query[] = "language='" . SQL::escape(isset($fields['language']) ? $fields['language'] : '') . "'"; $query[] = "overlay='" . SQL::escape(isset($fields['overlay']) ? $fields['overlay'] : '') . "'"; $query[] = "overlay_id='" . SQL::escape(isset($fields['overlay_id']) ? $fields['overlay_id'] : '') . "'"; $query[] = "tags='" . SQL::escape(isset($fields['tags']) ? $fields['tags'] : '') . "'"; // set or change the publication date if (isset($fields['publish_date']) && $fields['publish_date'] > NULL_DATE) { $query[] = "publish_name='" . SQL::escape(isset($fields['publish_name']) ? $fields['publish_name'] : $fields['edit_name']) . "'"; if (isset($fields['publish_id']) || isset($fields['edit_id'])) { $query[] = "publish_id=" . SQL::escape(isset($fields['publish_id']) ? $fields['publish_id'] : $fields['edit_id']); } $query[] = "publish_address='" . SQL::escape(isset($fields['publish_address']) ? $fields['publish_address'] : $fields['edit_address']) . "'"; $query[] = "publish_date='" . SQL::escape($fields['publish_date']) . "'"; } // maybe a silent update if (!isset($fields['silent']) || $fields['silent'] != 'Y' || !Surfer::is_empowered()) { $query[] = "edit_name='" . SQL::escape($fields['edit_name']) . "'"; $query[] = "edit_id=" . SQL::escape(isset($fields['edit_id']) ? $fields['edit_id'] : '0'); $query[] = "edit_address='" . SQL::escape($fields['edit_address']) . "'"; $query[] = "edit_action='article:update'"; $query[] = "edit_date='" . SQL::escape($fields['edit_date']) . "'"; } // reset user assignment, if any $query[] = "assign_name=''"; $query[] = "assign_id=0"; $query[] = "assign_address=''"; $query[] = "assign_date='" . SQL::escape(NULL_DATE) . "'"; $query[] = "rating_count='" . SQL::escape(isset($fields['rating_count']) ? $fields['rating_count'] : '0') . "'"; // update an existing record $query = "UPDATE " . SQL::table_name('articles') . " SET " . implode(', ', $query) . " WHERE id = " . SQL::escape($fields['id']); if (SQL::query($query) === FALSE) { return FALSE; } // list the article in categories Categories::remember('article:' . $fields['id'], isset($fields['publish_date']) ? $fields['publish_date'] : NULL_DATE, isset($fields['tags']) ? $fields['tags'] : ''); // add this page to surfer watch list if (Surfer::get_id()) { Members::assign('article:' . $fields['id'], 'user:' . Surfer::get_id()); } // clear the cache Articles::clear($fields); // end of job return TRUE; }
Logger::error(i18n::s('You are not allowed to perform this operation.')); // an anchor is mandatory } elseif (!is_object($anchor)) { Safe::header('Status: 404 Not Found', TRUE, 404); Logger::error(i18n::s('No anchor has been found.')); // security screening } elseif (!Surfer::is_associate()) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // build a form to assign some sections to this item } else { // assign a section, and add it to the watch list if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'set' && isset($_REQUEST['member'])) { Members::assign($_REQUEST['anchor'], $_REQUEST['member']); if (preg_match('/^user:/', $_REQUEST['anchor'])) { Members::assign($_REQUEST['member'], $_REQUEST['anchor']); } // break an assignment, and also purge the watch list } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'reset' && isset($_REQUEST['member'])) { Members::free($_REQUEST['anchor'], $_REQUEST['member']); if (preg_match('/^user:/', $_REQUEST['anchor'])) { Members::free($_REQUEST['member'], $_REQUEST['anchor']); } } // insert anchor prefix if (is_object($anchor)) { $context['text'] .= $anchor->get_prefix(); } // the current list of linked sections $sections =& Members::list_sections_by_title_for_anchor($anchor->get_reference(), 0, SECTIONS_LIST_SIZE, 'raw'); // the form to link additional sections
/** * remember publications and tags * * This function links the provided reference to categories, based * on publication time and tags. * * The reference is linked to weekly and monthly categories, except if the * global parameter 'users_without_archiving' has been set to 'Y'. * * @see users/configure.php * * Tags can be provided either as a string of keywords separated by commas, * or as an array of strings. * * @param string a reference to the published material (e.g., 'article:12') * @param string the publication date and time, if any * @param mixed a list of related tags, if any * * @see articles/articles.php * @see categories/check.php * @see services/blog.php */ public static function remember($reference, $stamp = NULL, $tags = NULL) { global $context; // if automatic archiving has not been disabled if (!isset($context['users_without_archiving']) || $context['users_without_archiving'] != 'Y') { // if the stamp has a value, this is a valid publication if (is_string($stamp) && $stamp > NULL_DATE && ($stamp = strtotime($stamp)) && ($stamp = getdate($stamp))) { // weeks are starting on Monday $week = mktime(0, 0, 0, $stamp['mon'], $stamp['mday'] - $stamp['wday'] + 1, $stamp['year']); // create the category for this week if it does not exist if (!($category = Categories::lookup('week ' . date('y/m/d', $week))) && ($anchor = Categories::get(i18n::c('weekly')))) { $fields = array(); $fields['anchor'] = 'category:' . $anchor['id']; $fields['nick_name'] = 'week ' . date('y/m/d', $week); $fields['create_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', $week); $fields['edit_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', $week); $fields['title'] = sprintf(i18n::c('Week of %s'), date(i18n::c('m/d/y'), $week)); $fields['options'] = 'no_links'; if ($fields['id'] = Categories::post($fields)) { Categories::clear($fields); $category = 'category:' . $fields['id']; } } // link the reference to this weekly category if ($category) { Members::assign($category, $reference); } // months are starting on day 1 $month = mktime(0, 0, 0, $stamp['mon'], 1, $stamp['year']); // create the category for this month if it does not exist if (!($category = Categories::lookup('month ' . date('M Y', $month))) && ($anchor = Categories::get(i18n::c('monthly')))) { $fields = array(); $fields['anchor'] = 'category:' . $anchor['id']; $fields['nick_name'] = 'month ' . date('M Y', $month); $fields['create_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', $month); $fields['edit_date'] = gmstrftime('%Y-%m-%d %H:%M:%S', $month); $fields['title'] = Skin::build_date($month, 'month', $context['preferred_language']); $fields['options'] = 'no_links'; if ($fields['id'] = Categories::post($fields)) { Categories::clear($fields); $category = 'category:' . $fields['id']; } } // link the reference to this monthly category if ($category) { Members::assign($category, $reference); } } } // link to selected categories --do not accept ; as separator, because this conflicts with UTF-8 encoding if (is_string($tags) && $tags) { $tags = preg_split('/[ \\t]*,\\s*/', $tags); } if (is_array($tags) && count($tags)) { // create a category to host keywords, if none exists if (!($root_category = Categories::lookup('keywords'))) { $fields = array(); $fields['nick_name'] = 'keywords'; $fields['title'] = i18n::c('Keywords'); $fields['introduction'] = i18n::c('Classified pages'); $fields['description'] = i18n::c('This category is a specialized glossary of terms, made out of tags added to pages, and out of search requests.'); $fields['rank'] = 29000; $fields['options'] = 'no_links'; if ($fields['id'] = Categories::post($fields)) { Categories::clear($fields); $root_category = 'category:' . $fields['id']; } } // one category per tag $assigned = array(); foreach ($tags as $title) { // create a category if tag is unknown if (!($category =& Categories::get_by_keyword($title))) { $fields = array(); $fields['title'] = ucfirst($title); $fields['keywords'] = $title; if ($root_category) { $fields['anchor'] = $root_category; } if ($fields['id'] = Categories::post($fields)) { Categories::clear($fields); $category = 'category:' . $fields['id']; } } else { $category = 'category:' . $category['id']; } // link page to the category if ($category) { Members::assign($category, $reference); $assigned[] = $category; } } // back to a string representation $tags = join(', ', $tags); // clean assignments for removed tags // the list of members $query = "SELECT anchor FROM " . SQL::table_name('members') . " WHERE (member LIKE '" . SQL::escape($reference) . "') AND (anchor LIKE 'category:%')" . " LIMIT 0, 500"; if ($result = SQL::query($query)) { while ($row = SQL::fetch($result)) { if (in_array($row['anchor'], $assigned)) { continue; } // assigned, and a keyword exists, but not in the string of tags if (($category = Anchors::get($row['anchor'])) && ($keywords = $category->get_value('keywords')) && stripos($tags, $keywords) === FALSE) { Members::free($row['anchor'], $reference); } } } } }