/** * list images * * @param resource the SQL result * @return string the rendered text * * @see layouts/layout.php **/ function layout($result) { global $context; // empty list if (!SQL::count($result)) { $output = array(); return $output; } // we return an array of ($url => $attributes) $items = array(); // process all items in the list while ($item = SQL::fetch($result)) { // url to view the image $url = Images::get_url($item['id']); // initialize variables $prefix = $suffix = ''; // flag new images if ($item['edit_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } // image title or image name $label = Skin::strip($item['title'], 10); if (!$label) { $name_as_title = TRUE; $label = ucfirst($item['image_name']); } $label = str_replace('_', ' ', str_replace('%20', ' ', $label)); // list all components for this item $items[$url] = array($prefix, $label, $suffix, 'basic', NULL); } // end of processing SQL::free($result); return $items; }
/** * list images * * @param resource the SQL result * @return string the rendered text * * @see layouts/layout.php **/ function layout($result) { global $context; // empty list if (!SQL::count($result)) { $output = array(); return $output; } // we return an array of ($url => $attributes) $items = array(); // process all items in the list while ($item = SQL::fetch($result)) { // get the anchor for this image if ($item['anchor']) { $anchor = Anchors::get($item['anchor']); } // url to view the image $url = $context['url_to_home'] . $context['url_to_root'] . Images::get_url($item['id']); // time of last update $time = SQL::strtotime($item['edit_date']); // the title as the label if ($item['title']) { $label = ucfirst($item['title']) . ' (' . $item['image_name'] . ')'; } else { $label = $item['image_name']; } // the section $section = ''; if (is_object($anchor)) { $section = ucfirst($anchor->get_title()); } // the author(s) is an e-mail address, according to rss 2.0 spec $author = $item['create_address'] . ' (' . $item['create_name'] . ')'; if ($item['create_address'] != $item['edit_address']) { if ($author) { $author .= ', '; } $author .= $item['edit_address'] . ' (' . $item['edit_name'] . ')'; } // the description $description = Codes::beautify($item['description']); // cap the number of words $description = Skin::cap($description, 300); // fix image references $description = preg_replace('#"/([^">]+?)"#', '"' . $context['url_to_home'] . '/$1"', $description); $introduction = $description; // other rss fields $extensions = array(); // url for enclosure $type = Files::get_mime_type($item['image_name']); $extensions[] = '<enclosure url="' . $context['url_to_home'] . $context['url_to_root'] . Files::get_path($item['anchor'], 'images') . '/' . $item['image_name'] . '"' . ' length="' . $item['image_size'] . '"' . ' type="' . $type . '" />'; // list all components for this item $items[$url] = array($time, $label, $author, $section, NULL, $introduction, $description, $extensions); } // end of processing SQL::free($result); return $items; }
/** * get next and previous items, if any * * @param string the item type (eg, 'image', 'file', etc.) * @param array the anchored item asking for neighbours * @return an array($previous_url, $previous_label, $next_url, $next_label, $option_url, $option_label), or NULL * * @see shared/anchor.php */ function get_neighbours($type, $item) { global $context; // no item bound if (!isset($this->item['id'])) { return NULL; } // initialize components $previous_url = $previous_label = $next_url = $next_label = $option_url = $option_label = ''; // previous and next images if ($type == 'image') { // load the adequate library include_once $context['path_to_root'] . 'images/images.php'; // extract all images references from the description preg_match_all('/\\[image=(\\d+)/', $this->item['description'], $matches); // locate the previous image, if any $previous = NULL; reset($matches[1]); $index = 0; while (list($key, $value) = each($matches[1])) { $index++; if ($item['id'] == $value) { break; } $previous = $value; } // make a link to the previous image if ($previous) { $previous_url = Images::get_url($previous); $previous_label = i18n::s('Previous image'); } // locate the next image, if any if (!(list($key, $next) = each($matches[1]))) { $next = NULL; } else { $next_url = Images::get_url($next); $next_label = i18n::s('Next image'); } // add a label $option_label = sprintf(i18n::s('Image %d of %d'), $index, count($matches[1])); } // return navigation info return array($previous_url, $previous_label, $next_url, $next_label, $option_url, $option_label); }
/** * reference another page at this site * * The function transforms a local reference (e.g;, [code][user=2][/code]) * to an actual link relative to the YACS directory (e.g., [code]users/view.php/2[/code]), * adds a title and, sometimes, set a description as well. * * @param string any string, maybe with a local reference in it * @return an array($url, $title, $description) or NULL * * @see images/view.php * @see links/edit.php * @see shared/codes.php */ public static function transform_reference($text) { global $context; // translate this reference to an internal link if (preg_match("/^\\[(article|section|file|image|category|user)=(.+?)\\]/i", $text, $matches)) { switch ($matches[1]) { // article link case 'article': if ($item = Articles::get($matches[2])) { return array(Articles::get_permalink($item), $item['title'], $item['introduction']); } return array('', $text, ''); // section link // section link case 'section': if ($item = Sections::get($matches[2])) { return array(Sections::get_permalink($item), $item['title'], $item['introduction']); } return array('', $text, ''); // file link // file link case 'file': if ($item = Files::get($matches[2])) { return array(Files::get_url($matches[2]), $item['title'] ? $item['title'] : str_replace('_', ' ', ucfirst($item['file_name']))); } return array('', $text, ''); // image link // image link case 'image': include_once $context['path_to_root'] . 'images/images.php'; if ($item = Images::get($matches[2])) { return array(Images::get_url($matches[2]), $item['title'] ? $item['title'] : str_replace('_', ' ', ucfirst($item['image_name']))); } return array('', $text, ''); // category link // category link case 'category': if ($item = Categories::get($matches[2])) { return array(Categories::get_permalink($item), $item['title'], $item['introduction']); } return array('', $text, ''); // user link // user link case 'user': if ($item = Users::get($matches[2])) { return array(Users::get_permalink($item), $item['full_name'] ? $item['full_name'] : $item['nick_name']); } return array('', $text, ''); } } return array('', $text, ''); }
/** * get next and previous items, if any * * @see shared/anchor.php * * @param string the item type (eg, 'image', 'file', etc.) * @param array the anchored item asking for neighbours * @return an array($previous_url, $previous_label, $next_url, $next_label, $option_url, $option_label), or NULL */ function get_neighbours($type, $item) { global $context; // no item bound if (!isset($this->item['id'])) { return NULL; } // initialize components $previous_url = $previous_label = $next_url = $next_label = $option_url = $option_label = ''; // previous and next comments if ($type == 'comment') { // load the adequate library include_once $context['path_to_root'] . 'comments/comments.php'; $order = 'date'; // get previous url if ($previous_url = Comments::get_previous_url($item, 'article:' . $this->item['id'], $order)) { $previous_label = i18n::s('Previous'); } // get next url if ($next_url = Comments::get_next_url($item, 'article:' . $this->item['id'], $order)) { $next_label = i18n::s('Next'); } // previous and next files } elseif ($type == 'file') { // select appropriate order if (preg_match('/\\bfiles_by_title\\b/', $this->item['options'])) { $order = 'title'; } else { $order = 'date'; } // get previous url if ($previous_url = Files::get_previous_url($item, 'article:' . $this->item['id'], $order)) { $previous_label = i18n::s('Previous'); } // get next url if ($next_url = Files::get_next_url($item, 'article:' . $this->item['id'], $order)) { $next_label = i18n::s('Next'); } // previous and next images } elseif ($type == 'image') { // load the adequate library include_once $context['path_to_root'] . 'images/images.php'; // extract all images references from the introduction and from the description preg_match_all('/\\[image=(\\d+)/', $this->item['introduction'] . $this->item['description'], $matches); // locate the previous image, if any $previous = NULL; reset($matches[1]); $index = 0; while (list($key, $value) = each($matches[1])) { $index++; if ($item['id'] == $value) { break; } $previous = $value; } // make a link to the previous image if ($previous) { $previous_url = Images::get_url($previous); $previous_label = i18n::s('Previous'); } // locate the next image, if any if (!(list($key, $next) = each($matches[1]))) { $next = NULL; } else { $next_url = Images::get_url($next); $next_label = i18n::s('Next'); } // add a label $option_label = sprintf(i18n::s('Image %d of %d'), $index, count($matches[1])); // previous and next location } elseif ($type == 'location') { // load the adequate library include_once $context['path_to_root'] . 'locations/locations.php'; // extract all location references from the introduction and from the description preg_match_all('/\\[location=(\\d+)/', $this->item['introduction'] . $this->item['description'], $matches); // locate the previous location, if any $previous = NULL; reset($matches[1]); $index = 0; while (list($key, $value) = each($matches[1])) { $index++; if ($item['id'] == $value) { break; } $previous = $value; } // make a link to the previous location if ($previous) { $previous_url = Locations::get_url($previous); $previous_label = i18n::s('Previous'); } // locate the next location, if any if (!(list($key, $next) = each($matches[1]))) { $next = NULL; } else { $next_url = Locations::get_url($next); $next_label = i18n::s('Next'); } // add a label $option_label = sprintf(i18n::s('Location %d of %d'), $index, count($matches[1])); } // return navigation info return array($previous_url, $previous_label, $next_url, $next_label, $option_url, $option_label); }
/** * build tags for an image * * @link http://realworldstyle.com/thumb_float.html Floating Thumbnails * @link http://www.hypergurl.com/span.html spans with titles * * Accept following variants: * - 'center' for an image with a centered label * - 'inline' for in-line images; caption is only displayed in hovering pop-up * - 'left' for a left-aligned image * - 'right' for a right-aligned image * - 'thumbnail' for aligned thumbnail images * - any other value is translated to css style * * Any of previous variants can be prefixed with the keyword 'large', like in 'large inline'. * This may be used by web designers to trigger specific features, such as frames around large images. * * If a title has been given to the image, it is provided as a hovering label. * It is also added as caption in following situations: * - variant does not have the keyword 'thumbnail' * - or global parameter 'thumbnails_without_caption' has not been set to 'Y' * * @param string the image variant * @param string the image href * @param string the image title * @param string a link to make a clickable image, if any * @param string id of image, to display edition direct link, if desired * @return the HTML to display * */ public static function &build_image($variant, $href, $title, $link = '', $id = '') { global $context; // sanity check if (!$variant) { $variant = 'inline'; } // sanity check if (!$href) { $output = ''; return $output; } // provide absolute references if ($href && $href[0] == '/') { $href = $context['url_to_home'] . $href; } if ($link && $link[0] == '/') { $link = $context['url_to_home'] . $link; } // always display captions aside large images if (preg_match('/\\blarge\\b/i', $variant)) { $with_caption = TRUE; } elseif (isset($context['thumbnails_without_caption']) && $context['thumbnails_without_caption'] == 'Y') { $with_caption = FALSE; } else { $with_caption = TRUE; } // document the image if ($title) { $hover = $title; } else { $hover = ''; } // remove YACS codes from alternate label and hovering title if (is_callable(array('Codes', 'strip'))) { $hover = Codes::strip($hover, FALSE); } // split components of the variant if ($position = strpos($variant, ' ')) { $complement = substr($variant, 0, $position); $variant = substr($variant, $position + 1); } else { $complement = ''; } // wrapper begins --don't use div, because of surrounding link $tag_wrapper = SKIN_HTML5 ? 'figure' : 'span'; $text = "\n" . '<' . $tag_wrapper . ' class="' . encode_field($variant) . '_image">'; // styling freedom --outside anchor, which is inline if ($complement) { $text .= '<span class="' . $complement . '">'; } // configured styles $more_styles = ''; if ($complement == 'large' && isset($context['classes_for_large_images']) && $context['classes_for_large_images']) { $more_styles = ' class="' . encode_field($context['classes_for_large_images']) . '"'; } elseif ($variant == 'thumbnail' && isset($context['classes_for_thumbnail_images']) && $context['classes_for_thumbnail_images']) { $more_styles = ' class="' . encode_field($context['classes_for_thumbnail_images']) . '"'; } elseif ($variant == 'avatar' && isset($context['classes_for_avatar_images']) && $context['classes_for_avatar_images']) { $more_styles = ' class="' . encode_field($context['classes_for_avatar_images']) . '"'; } // the image itself $image = '<img src="' . $href . '" alt="" title="' . encode_field(strip_tags($hover)) . '"' . $more_styles . ' />'; // add a link if ($link && preg_match('/\\.(gif|jpeg|jpg|png)$/i', $link) && !preg_match('/\\blarge\\b/', $variant)) { $text .= '<a href="' . $link . '" class="image_show">' . $image . '</a>'; } elseif ($link) { $external = FALSE; if (!strncmp($link, 'http:', 5) && strncmp($link, 'http://' . $context['host_name'], strlen('http://' . $context['host_name']))) { $external = TRUE; } elseif (!strncmp($link, 'https:', 6) && strncmp($link, 'https://' . $context['host_name'], strlen('https://' . $context['host_name']))) { $external = TRUE; } if ($external) { $text .= '<a href="' . $link . '" onclick="window.open(this.href); return false;">' . $image . '</a>'; } else { $text .= '<a href="' . $link . '">' . $image . '</a>'; } } else { $text .= $image; } // make the title visible as a caption $tag_caption = SKIN_HTML5 ? 'figcaption' : 'span'; if ($title && $with_caption) { $text .= '<' . $tag_caption . ' class="image_caption">' . ucfirst($title) . '</' . $tag_caption . '>'; } // end of freedom if ($complement) { $text .= '</span>'; } //edit image direct access if (($variant == 'center' || $variant == 'right' || $variant == 'left' || $variant == 'thumbnail' || $complement == 'large') && $id) { Skin::define_img('IMAGES_EDIT_IMG', 'images/edit.gif'); $text .= '<span class="image_edit">' . Skin::build_link(Images::get_url($id, 'edit'), IMAGES_EDIT_IMG, NULL, i18n::s('Update this image') . ' [' . $id . ']') . '</span>'; } // end of wrapper $text .= '</' . $tag_wrapper . '>'; // job done return $text; }
// back to the anchor page if (is_object($anchor) && $anchor->is_viewable()) { $context['text'] .= Skin::build_block(Skin::build_link($anchor->get_url(), i18n::s('Back to main page'), 'button'), 'bottom'); } // page tools // if ($editable) { Skin::define_img('IMAGES_EDIT_IMG', 'images/edit.gif'); $context['page_tools'][] = Skin::build_link(Images::get_url($item['id'], 'edit'), IMAGES_EDIT_IMG . i18n::s('Update this image'), 'basic', i18n::s('Press [e] to edit'), FALSE, 'e'); } // the delete command is available to associates and editors if ($item['id'] && (Surfer::is_associate() || is_object($anchor) && $anchor->is_assigned())) { Skin::define_img('IMAGES_DELETE_IMG', 'images/delete.gif'); $context['page_tools'][] = Skin::build_link(Images::get_url($item['id'], 'delete'), IMAGES_DELETE_IMG . i18n::s('Delete this image')); } // general help on this page // $help = '<p>' . i18n::s('To save this image on your hard drive, drag the mouse above the image and use the right button. A contextual pop-up menu should appear. Select the adequate command depending on the browser used.') . '</p>'; $context['components']['boxes'] = Skin::build_box(i18n::s('Help'), $help, 'boxes', 'help'); // thumbnail, in an extra box // if (Surfer::is_associate() && $item['thumbnail_name'] && $item['thumbnail_name'] != $item['image_name']) { $url = $context['url_to_root'] . Files::get_path($item['anchor'], 'images') . '/' . $item['thumbnail_name']; $context['components']['boxes'] .= Skin::build_box(i18n::s('Thumbnail'), '<img src="' . $url . '" />', 'boxes'); } // referrals, if any // $context['components']['referrals'] =& Skin::build_referrals(Images::get_url($item['id'])); } // render the skin render_skin();
// parse the whole list } else { // fetch one anchor and the linked member $errors_count = 0; while ($row = SQL::fetch($result)) { // animate user screen and take care of time $count++; if (!($count % 100)) { $context['text'] .= sprintf(i18n::s('%d records have been processed'), $count) . BR . "\n"; // ensure enough execution time Safe::set_time_limit(30); } if (!Images::get_icon_href($row)) { $errors_count++; $anchor = Anchors::get($row['anchor']); $context['text'] .= sprintf(i18n::s('Missing: %s'), 'image ' . Skin::build_link(Images::get_url($row['id']), $row['id'] . ' ' . $row['image_name'])) . ' ' . i18n::s('in') . ' ' . (is_object($anchor) ? Skin::build_link($anchor->get_url(), $row['anchor']) : '') . BR . "\n"; } } } // ending message $context['text'] .= sprintf(i18n::s('%d records have been processed'), $count) . BR . "\n"; $context['text'] .= sprintf(i18n::s('%d missing files'), $errors_count) . BR . "\n"; // display the execution time $time = round(get_micro_time() - $context['start_time'], 2); $context['text'] .= '<p>' . sprintf(i18n::s('Script terminated in %.2f seconds.'), $time) . '</p>'; // forward to the index page $menu = array('images/' => i18n::s('Images')); $context['text'] .= Skin::build_list($menu, 'menu_bar'); // which check? } else { // the splash message
$action = 'image:set_as_icon'; } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'set_as_avatar') { $action = 'image:set_as_avatar'; } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'set_as_thumbnail') { $action = 'image:set_as_thumbnail'; } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'set_as_both') { $action = 'image:set_as_both'; } else { $action = 'image:update'; } // touch the related anchor $anchor->touch($action, $_REQUEST['id'], isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y'); // clear cache Images::clear($_REQUEST); // forward to the view page Safe::redirect($context['url_to_home'] . $context['url_to_root'] . Images::get_url($_REQUEST['id'])); } // display the form on GET } else { $with_form = TRUE; } // display the form if ($with_form) { // the form to edit an image $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form" enctype="multipart/form-data"><div>'; $fields = array(); // the section if ($anchor) { $context['text'] .= '<input type="hidden" name="anchor" value="' . $anchor->get_reference() . '" />'; } // the image
Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'images/'); } } // deletion has to be confirmed } elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') { Logger::error(i18n::s('The action has not been confirmed.')); } else { // commands $menu = array(); $class_submit = $render_overlaid ? 'submit-overlaid' : 'button'; $menu[] = Skin::build_submit_button(i18n::s('Yes, I want to delete this image'), NULL, NULL, 'confirmed', $class_submit); if (isset($item['id'])) { if ($render_overlaid) { $menu[] = Skin::build_link($anchor->get_permalink(), i18n::s('Cancel'), 'overlaid'); } else { $menu[] = Skin::build_link(Images::get_url($item['id']), i18n::s('Cancel'), 'span'); } } // the submit button $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><p>' . "\n" . Skin::finalize_list($menu, 'menu_bar') . '<input type="hidden" name="id" value="' . $item['id'] . '" />' . "\n" . '<input type="hidden" name="confirm" value="yes" />' . "\n"; // transmit the follow_up param if any if (isset($_REQUEST['follow_up'])) { $context['text'] .= '<input type="hidden" name="follow_up" value="' . $_REQUEST['follow_up'] . '" />' . "\n"; } $context['text'] .= '</p></form>' . "\n"; // set the focus Page::insert_script('$("#confirmed").focus();'); // the title of the image if ($item['title']) { $context['text'] .= Skin::build_block($item['title'], 'title'); } else {
/** * render a link to an object * * Following types are supported: * - article - link to an article page * - category - link to a category page * - comment - link to a comment page * - download - link to a download page * - file - link to a file page * - flash - display a file as a native flash object, or play a flash video * - go * - image - display an in-line image * - next - link to an article page * - previous - link to an article page * - section - link to a section page * - server - link to a server page * - user - link to a user page * * @param string the type * @param string the id, with possible options or variant * @return string the rendered text **/ public static function render_object($type, $id) { global $context; $id = Codes::fix_tags($id); // depending on type switch ($type) { // link to an article case 'article': // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database if (!($item = Articles::get($id))) { $output = '[article=' . $id . ']'; } else { // ensure we have a label for this link if (isset($attributes[1])) { $text = $attributes[1]; $type = 'basic'; } else { $text = Skin::strip($item['title']); } // make a link to the target page $url = Articles::get_permalink($item); // return a complete anchor $output =& Skin::build_link($url, $text, $type); } return $output; // insert article description // insert article description case 'article.description': // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database if (!($item = Articles::get($id))) { $output = '[article.description=' . $id . ']'; } else { // ensure we have a label for this link if (isset($attributes[1])) { $text = $attributes[1]; $type = 'basic'; } else { $text = Skin::strip($item['title']); } // make a link to the target page $url = Articles::get_permalink($item); // return a complete anchor $output =& Skin::build_link($url, $text, 'article'); // the introduction text, if any $output .= BR . Codes::beautify($item['introduction']); // load overlay, if any if (isset($item['overlay']) && $item['overlay']) { $overlay = Overlay::load($item, 'article:' . $item['id']); // get text related to the overlay, if any if (is_object($overlay)) { $output .= $overlay->get_text('view', $item); } } // the description, which is the actual page body $output .= '<div>' . Codes::beautify($item['description']) . '</div>'; } return $output; // link to a category // link to a category case 'category': // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database if (!($item = Categories::get($id))) { $output = '[category=' . $id . ']'; } else { // ensure we have a label for this link if (isset($attributes[1])) { $text = $attributes[1]; $type = 'basic'; } else { $text = Skin::strip($item['title']); } // make a link to the target page $url = Categories::get_permalink($item); // return a complete anchor $output =& Skin::build_link($url, $text, $type); } return $output; // insert category description // insert category description case 'category.description': // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database if (!($item = Categories::get($id))) { $output = '[category.description=' . $id . ']'; } else { // ensure we have a label for this link if (isset($attributes[1])) { $text = $attributes[1]; $type = 'basic'; } else { $text = Skin::strip($item['title']); } // make a link to the target page $url = Categories::get_permalink($item); // return a complete anchor $output =& Skin::build_link($url, $text, 'category'); // the introduction text, if any $output .= BR . Codes::beautify($item['introduction']); // load overlay, if any if (isset($item['overlay']) && $item['overlay']) { $overlay = Overlay::load($item, 'category:' . $item['id']); // get text related to the overlay, if any if (is_object($overlay)) { $output .= $overlay->get_text('view', $item); } } // the description, which is the actual page body $output .= '<div>' . Codes::beautify($item['description']) . '</div>'; } return $output; // link to a comment // link to a comment case 'comment': include_once $context['path_to_root'] . 'comments/comments.php'; // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database if (!($item = Comments::get($id))) { $output = '[comment=' . $id . ']'; } else { // ensure we have a label for this link if (isset($attributes[1])) { $text = $attributes[1]; } else { $text = i18n::s('View this comment'); } // make a link to the target page $url = $context['url_to_home'] . $context['url_to_root'] . Comments::get_url($item['id']); // return a complete anchor $output =& Skin::build_link($url, $text, 'basic'); } return $output; // link to a download // link to a download case 'download': // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database if (!($item = Files::get($id))) { // file does not exist anymore if (isset($attributes[1]) && $attributes[1]) { $output = $attributes[1] . '<p class="details">' . i18n::s('[this file has been deleted]') . '</p>'; } else { $output = '[download=' . $id . ']'; } } else { // label for this file $prefix = $text = $suffix = ''; // signal restricted and private files if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // ensure we have a label for this link if (isset($attributes[1]) && $attributes[1]) { $text .= $attributes[1]; // this may describe a previous file, which has been replaced if ($item['edit_action'] != 'file:create' && $attributes[1] != $item['file_name']) { $text .= ' <p class="details">' . i18n::s('[this file has been replaced]') . '</p>'; $output = $prefix . $text . $suffix; return $output; } } else { $text = Skin::strip($item['title'] ? $item['title'] : str_replace('_', ' ', $item['file_name'])); } // flag files uploaded recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // always download the file $url = $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'fetch', $item['file_name']); // return a complete anchor $output = $prefix . Skin::build_link($url, $text, 'file') . $suffix; } return $output; // link to a file // link to a file case 'file': // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database --ensure we get a fresh copy of the record, not a cached one if (!($item = Files::get($id, TRUE))) { // file does not exist anymore if (isset($attributes[1]) && $attributes[1]) { $output = $attributes[1] . '<p class="details">' . i18n::s('[this file has been deleted]') . '</p>'; } else { $output = '[file=' . $id . ']'; } } else { // maybe we want to illustrate this file if ($item['edit_action'] != 'file:create' && isset($attributes[1]) && $attributes[1] || !($output = Files::interact($item))) { // label for this file $output = $prefix = $text = $suffix = ''; // signal restricted and private files if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // ensure we have a label for this link if (isset($attributes[1]) && $attributes[1]) { $text .= $attributes[1]; // this may describe a previous file, which has been replaced if ($item['edit_action'] != 'file:create' && $attributes[1] != $item['file_name']) { $text .= '<p class="details">' . i18n::s('[this file has been replaced]') . '</p>'; $output = $prefix . $text . $suffix; return $output; } } else { $text .= Skin::strip($item['title'] ? $item['title'] : str_replace('_', ' ', $item['file_name'])); } // flag files uploaded recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // make a link to the target page $url = Files::get_download_url($item); // return a complete anchor $output .= $prefix . Skin::build_link($url, $text, 'basic') . $suffix; } } return $output; // invoke the selector // invoke the selector case 'go': // extract the label, if any $attributes = preg_split("/\\s*,\\s*/", $id, 2); $name = $attributes[0]; // ensure we have a label for this link if (isset($attributes[1])) { $text = $attributes[1]; } else { $text = $name; } // return a complete anchor $output = Skin::build_link($context['url_to_home'] . $context['url_to_root'] . normalize_shortcut($name), $text, 'basic'); return $output; // embed an image // embed an image case 'image': include_once $context['path_to_root'] . 'images/images.php'; // get the variant, if any $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; if (isset($attributes[1])) { $variant = $attributes[1]; } else { $variant = 'inline'; } // get the image record if (!($image = Images::get($id))) { $output = '[image=' . $id . ']'; return $output; } // a title for the image --do not force a title if (isset($image['title'])) { $title = $image['title']; } else { $title = ''; } // provide thumbnail if not defined, or forced, or for large images if (!$image['use_thumbnail'] || $image['use_thumbnail'] == 'A' || $image['use_thumbnail'] == 'Y' && $image['image_size'] > $context['thumbnail_threshold']) { // not inline anymore, but thumbnail --preserve other variants if ($variant == 'inline') { $variant = 'thumbnail'; } // where to fetch the image file $href = Images::get_thumbnail_href($image); // to drive to plain image $link = Images::get_icon_href($image); // add an url, if any } elseif ($image['link_url']) { // flag large images if ($image['image_size'] > $context['thumbnail_threshold']) { $variant = rtrim('large ' . $variant); } // where to fetch the image file $href = Images::get_icon_href($image); // transform local references, if any include_once $context['path_to_root'] . '/links/links.php'; $attributes = Links::transform_reference($image['link_url']); if ($attributes[0]) { $link = $context['url_to_root'] . $attributes[0]; } else { $link = $image['link_url']; } // get the <img ... /> element } else { // do not append poor titles to inline images if ($variant == 'inline') { $title = ''; } // flag large images if ($image['image_size'] > $context['thumbnail_threshold']) { $variant = rtrim('large ' . $variant); } // where to fetch the image file $href = Images::get_icon_href($image); // no link $link = ''; } // use the skin if (Images::allow_modification($image['anchor'], $id)) { // build editable image $output =& Skin::build_image($variant, $href, $title, $link, $id); } else { $output =& Skin::build_image($variant, $href, $title, $link); } return $output; // embed a stack of images // embed a stack of images case 'images': include_once $context['path_to_root'] . 'images/images.php'; // get the list of ids $ids = preg_split("/\\s*,\\s*/", $id); if (!count($ids)) { $output = '[images=id1, id2, ...]'; return $output; } // build the list of images $items = array(); foreach ($ids as $id) { // get the image record if ($image = Images::get($id)) { // a title for the image --do not force a title if (isset($image['title'])) { $title = $image['title']; } else { $title = ''; } // provide thumbnail if not defined, or forced, or for large images $variant = 'inline'; if (!$image['use_thumbnail'] || $image['use_thumbnail'] == 'A' || $image['use_thumbnail'] == 'Y' && $image['image_size'] > $context['thumbnail_threshold']) { // not inline anymore, but thumbnail $variant = 'thumbnail'; // where to fetch the image file $href = Images::get_thumbnail_href($image); // to drive to plain image $link = $context['url_to_root'] . Images::get_url($id); // add an url, if any } elseif ($image['link_url']) { // flag large images if ($image['image_size'] > $context['thumbnail_threshold']) { $variant = rtrim('large ' . $variant); } // where to fetch the image file $href = Images::get_icon_href($image); // transform local references, if any include_once $context['path_to_root'] . '/links/links.php'; $attributes = Links::transform_reference($image['link_url']); if ($attributes[0]) { $link = $context['url_to_root'] . $attributes[0]; } else { $link = $image['link_url']; } // get the <img ... /> element } else { // flag large images if ($image['image_size'] > $context['thumbnail_threshold']) { $variant = rtrim('large ' . $variant); } // where to fetch the image file $href = Images::get_icon_href($image); // no link $link = ''; } // use the skin $label =& Skin::build_image($variant, $href, $title, $link); // add item to the stack $items[] = $label; } } // format the list $output = ''; if (count($items)) { // stack items $output = Skin::finalize_list($items, 'stack'); // rotate items $output = Skin::rotate($output); } // done return $output; // link to the next article // link to the next article case 'next': // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database if (!($item = Articles::get($id))) { $output = '[next=' . $id . ']'; } else { // ensure we have a label for this link if (isset($attributes[1])) { $text = $attributes[1]; } else { $text = Skin::strip($item['title']); } // make a link to the target page $url = Articles::get_permalink($item); // return a complete anchor $output =& Skin::build_link($url, $text, 'next'); } return $output; // link to the previous article // link to the previous article case 'previous': // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database if (!($item = Articles::get($id))) { $output = '[previous=' . $id . ']'; } else { // ensure we have a label for this link if (isset($attributes[1])) { $text = $attributes[1]; } else { $text = Skin::strip($item['title']); } // make a link to the target page $url = Articles::get_permalink($item); // return a complete anchor $output =& Skin::build_link($url, $text, 'previous'); } return $output; // link to a section // link to a section case 'section': // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database if (!($item = Sections::get($id))) { $output = '[section=' . $id . ']'; } else { // ensure we have a label for this link if (isset($attributes[1])) { $text = $attributes[1]; $type = 'basic'; } else { $text = Skin::strip($item['title']); } // make a link to the target page $url = Sections::get_permalink($item); // return a complete anchor $output =& Skin::build_link($url, $text, $type); } return $output; // link to a server // link to a server case 'server': include_once $context['path_to_root'] . 'servers/servers.php'; // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database if (!($item = Servers::get($id))) { $output = '[server=' . $id . ']'; } else { // ensure we have a label for this link if (isset($attributes[1])) { $text = $attributes[1]; $type = 'basic'; } else { $text = Skin::strip($item['title']); } // make a link to the target page $url = $context['url_to_home'] . $context['url_to_root'] . Servers::get_url($id); // return a complete anchor $output =& Skin::build_link($url, $text, $type); } return $output; // link to a user // link to a user case 'user': // maybe an alternate title has been provided $attributes = preg_split("/\\s*,\\s*/", $id, 2); $id = $attributes[0]; // load the record from the database if (!($item = Users::get($id))) { $output = '[user='******']'; } else { // ensure we have a label for this link if (isset($attributes[1])) { $text = $attributes[1]; $type = 'basic'; } elseif (isset($item['full_name']) && $item['full_name']) { $text = ucfirst($item['full_name']); } else { $text = ucfirst($item['nick_name']); } // make a link to the target page $url = Users::get_permalink($item); // return a complete anchor $output =& Skin::build_link($url, $text, $type); } return $output; // invalid type // invalid type default: $output = '[' . $type . ']'; return $output; } }
/** * list images * * Recognize following variants: * - 'compact' - to build short lists in boxes and sidebars * - '<a valid anchor>' - example: 'section:123' - to list images attached to an anchor page * * @param resource the SQL result * @return array one item per image * * @see layouts/layout.php **/ function layout($result) { global $context; // empty list if (!SQL::count($result)) { $output = array(); return $output; } if (!isset($this->layout_variant)) { $this->layout_variant = ''; } // we return an array of ($url => $attributes) $items = array(); // process all items in the list while ($item = SQL::fetch($result)) { // initialize variables $prefix = $suffix = $icon = ''; // the url to view this item $url = Images::get_url($item['id']); $label = '_'; // the title if ($item['title']) { $suffix .= Skin::strip($item['title'], 10) . BR; } // there is an anchor if ($item['anchor'] && ($anchor = Anchors::get($item['anchor']))) { // codes to embed this image if ($this->focus == $anchor->get_reference()) { // help to insert in textarea // if(!isset($_SESSION['surfer_editor']) || ($_SESSION['surfer_editor'] == 'yacs')) // $suffix .= '<a onclick="edit_insert(\'\', \' [image='.$item['id'].']\');return false;" title="insert" tabindex="2000">[image='.$item['id'].']</a>' // .' <a onclick="edit_insert(\'\', \' [image='.$item['id'].', left]\');return false;" title="insert" tabindex="2000">[image='.$item['id'].',left]</a>' // .' <a onclick="edit_insert(\'\', \' [image='.$item['id'].', right]\');return false;" title="insert" tabindex="2000">[image='.$item['id'].',right]</a>' // .' <a onclick="edit_insert(\'\', \' [image='.$item['id'].', center]\');return false;" title="insert" tabindex="2000">[image='.$item['id'].',center]</a>'; // // else $suffix .= '[image=' . $item['id'] . ']' . ' [image=' . $item['id'] . ',left]' . ' [image=' . $item['id'] . ',right]' . ' [image=' . $item['id'] . ',center]'; $suffix .= BR; // show an anchor link } else { $anchor_url = $anchor->get_url(); $anchor_label = ucfirst($anchor->get_title()); $suffix .= sprintf(i18n::s('In %s'), Skin::build_link($anchor_url, $anchor_label)) . BR; } } // details $details = array(); // file name if ($item['image_name']) { $details[] = $item['image_name']; } // file size if ($item['image_size'] > 1) { $details[] = number_format($item['image_size']) . ' ' . i18n::s('bytes'); } // poster if ($item['edit_name']) { $details[] = sprintf(i18n::s('edited by %s %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date'])); } // append details if (count($details)) { $suffix .= '<span class="details">' . ucfirst(implode(', ', $details)) . '</span>' . BR; } // the menu bar $menu = array(); // change the image if (Surfer::is_empowered() || Surfer::is($item['edit_id'])) { $menu = array_merge($menu, array(Images::get_url($item['id'], 'edit') => i18n::s('Update this image'))); } // use the image if (Surfer::is_empowered() && Surfer::is_member()) { if (preg_match('/\\buser\\b/', $this->layout_variant)) { $menu = array_merge($menu, array(Images::get_url($item['id'], 'set_as_thumbnail') => i18n::s('Set as profile picture'))); } elseif (preg_match('/\\b(article|category|section)\\b/', $this->layout_variant)) { $menu = array_merge($menu, array(Images::get_url($item['id'], 'set_as_icon') => i18n::s('Set as page image'))); $menu = array_merge($menu, array(Images::get_url($item['id'], 'set_as_thumbnail') => i18n::s('Set as page thumbnail'))); } } // delete the image if (Surfer::is_empowered() || Surfer::is($item['edit_id'])) { $menu = array_merge($menu, array(Images::get_url($item['id'], 'delete') => i18n::s('Delete this image'))); } if (count($menu)) { $suffix .= Skin::build_list($menu, 'menu'); } // link to the thumbnail image, if any $icon = '<span class="small_image"><img src="' . Images::get_thumbnail_href($item) . '" title="' . encode_field(strip_tags($item['title'])) . '" alt="" /></span>'; // list all components for this item $items[$url] = array($prefix, $label, $suffix, 'image', $icon); } // end of processing SQL::free($result); return $items; }