/** * list files * * @param resource the SQL result * @return array of resulting items, or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of ($url => $attributes) $items = array(); // empty list if (!SQL::count($result)) { return $items; } // sanity check if (!isset($this->layout_variant)) { $this->layout_variant = 'full'; } // process all items in the list while ($item = SQL::fetch($result)) { // get the main anchor $anchor = Anchors::get($item['anchor']); // download the file directly $url = Files::get_url($item['id'], 'fetch', $item['file_name']); // initialize variables $prefix = $suffix = ''; // flag files that are dead, or created or updated very recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // signal restricted and private files if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // file title or file name $label = Codes::beautify_title($item['title']); if (!$label) { $label = ucfirst(str_replace(array('%20', '-', '_'), ' ', $item['file_name'])); } // the main anchor link, except on user profiles if (is_object($anchor) && $anchor->get_reference() != $this->focus) { $suffix .= ' - <span class="details">' . sprintf(i18n::s('in %s'), Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()))) . '</span>'; } // list all components for this item $items[$url] = array($prefix, $label, $suffix, 'basic', NULL); } // end of processing SQL::free($result); return $items; }
/** * list files * * @param resource the SQL result * @return array of resulting items, or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of ($url => $attributes) $items = array(); // empty list if (!SQL::count($result)) { return $items; } // process all items in the list while ($item = SQL::fetch($result)) { // download the file directly $url = Files::get_url($item['id'], 'fetch', $item['file_name']); // initialize variables $prefix = $suffix = ''; // flag files that are dead, or created or updated very recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // signal restricted and private files if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // file title or file name $label = Codes::beautify_title($item['title']); if (!$label) { $label = ucfirst(str_replace(array('%20', '-', '_'), ' ', $item['file_name'])); } // with hits if ($item['hits'] > 1) { $suffix .= ' <span class="details">- ' . Skin::build_number($item['hits'], i18n::s('downloads')) . '</span>'; } // list all components for this item $items[$url] = array($prefix, $label, $suffix, 'basic', NULL); } // end of processing SQL::free($result); return $items; }
/** * list files * * @param resource the SQL result * @return array of resulting items, or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of ($url => $attributes) $items = array(); // empty list if (!SQL::count($result)) { return $items; } // process all items in the list while ($item = SQL::fetch($result)) { // download the file directly $url = Files::get_url($item['id'], 'fetch', $item['file_name']); // file title or file name $label = Codes::beautify_title($item['title']); if (!$label) { $label = ucfirst(str_replace(array('%20', '-', '_'), ' ', $item['file_name'])); } // initialize variables $prefix = $suffix = ''; $contributor = Users::get_link($item['create_name'], $item['create_address'], $item['create_id']); $flag = ''; if ($item['create_date'] >= $context['fresh']) { $flag = NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $flag = UPDATED_FLAG; } $suffix .= '<span class="details"> - ' . sprintf(i18n::s('By %s'), $contributor) . ' ' . Skin::build_date($item['create_date']) . $flag . '</span>'; // signal restricted and private files if ($item['active'] == 'N' && defined('PRIVATE_FLAG')) { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R' && defined('RESTRICTED_FLAG')) { $prefix .= RESTRICTED_FLAG; } // list all components for this item $items[$url] = array($prefix, $label, $suffix, 'file', NULL); } // end of processing SQL::free($result); return $items; }
/** * list files * * @param resource the SQL result * @return array of resulting items, or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of ($url => $attributes) $items = array(); // empty list if (!SQL::count($result)) { return $items; } // process all items in the list while ($item = SQL::fetch($result)) { // play freemind maps and flash files in separate windows if (preg_match('/\\.(mm|swf)$/i', $item['file_name'])) { $url = Files::get_url($item['id'], 'stream', $item['file_name']); } else { $url = Files::get_url($item['id'], 'fetch', $item['file_name']); } // provide absolute links because these could be put in a mail $url = $context['url_to_home'] . $context['url_to_root'] . $url; // initialize variables $prefix = $suffix = ''; // signal restricted and private files if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // file title or file name $label = Codes::beautify_title($item['title']); if (!$label) { $label = ucfirst(str_replace(array('%20', '-', '_'), ' ', $item['file_name'])); } // list all components for this item $items[$url] = array($prefix, $label, $suffix, 'basic', NULL); } // end of processing SQL::free($result); return $items; }
$label = i18n::s('Stop notifications'); } else { $label = i18n::s('Watch this page'); } Skin::define_img('TOOLS_WATCH_IMG', 'tools/watch.gif'); $lines[] = Skin::build_link($link, TOOLS_WATCH_IMG . $label, 'basic', i18n::s('Manage your watch list')); } // allow to leave the page if ($cur_article->is_assigned() && !$cur_article->is_owned(null, false)) { Skin::define_img('ARTICLES_ASSIGN_IMG', 'articles/assign.gif'); $lines[] = Skin::build_link(Users::get_url('article:' . $item['id'], 'leave'), ARTICLES_ASSIGN_IMG . i18n::s('Leave this page')); } // get news from rss if (isset($item['id']) && (!isset($context['skins_general_without_feed']) || $context['skins_general_without_feed'] != 'Y')) { // list of attached files $lines[] = Skin::build_link($context['url_to_home'] . $context['url_to_root'] . Files::get_url('article:' . $item['id'], 'feed'), i18n::s('Recent files'), 'xml'); // comments are allowed if ($cur_article->allows('creation', 'comment')) { $lines[] = Skin::build_link($context['url_to_home'] . $context['url_to_root'] . Comments::get_url('article:' . $item['id'], 'feed'), i18n::s('Recent comments'), 'xml'); } } // in a side box if (count($lines)) { $context['components']['channels'] = Skin::build_box(i18n::s('Monitor'), join(BR, $lines), 'channels', 'feeds'); } // twin pages if (isset($item['nick_name']) && $item['nick_name']) { // build a complete box $box['text'] = ''; // list pages with same name $items =& Articles::list_for_name($item['nick_name'], $item['id'], 'compact');
/** * list files * * @param resource the SQL result * @return array of resulting items, or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of ($url => $attributes) $items = array(); // empty list if (!SQL::count($result)) { return $items; } // sanity check if (!isset($this->layout_variant)) { $this->layout_variant = ''; } // process all items in the list while ($item = SQL::fetch($result)) { // get the main anchor $anchor = Anchors::get($item['anchor']); // initialize variables $prefix = $suffix = $icon = ''; // more details $url = Files::get_permalink($item); // codes $codes = array(); // files that can be embedded if (preg_match('/\\.(3gp|flv|gan|m4v|mm|mov|mp4|swf)$/i', $item['file_name'])) { $codes[] = '[embed=' . $item['id'] . ']'; } // link for direct download $codes[] = '[file=' . $item['id'] . ']'; $codes[] = '[download=' . $item['id'] . ']'; // integrate codes if (!isset($_SESSION['surfer_editor']) || $_SESSION['surfer_editor'] == 'yacs') { foreach ($codes as $code) { $suffix .= '<a onclick="edit_insert(\'\', \' ' . $code . '\');return false;" title="insert" tabindex="2000">' . $code . '</a> '; } } else { $suffix .= join(' ', $codes); } $suffix .= BR . '<span class="details">'; // signal restricted and private files if ($item['active'] == 'N') { $suffix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $suffix .= RESTRICTED_FLAG; } // file title or file name $label = Codes::beautify_title($item['title']); if (!$label) { $label = ucfirst(str_replace(array('%20', '-', '_'), ' ', $item['file_name'])); } $suffix .= $label; // flag files uploaded recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } $suffix .= '</span>'; // details $details = array(); if (Surfer::is_logged() && $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'])); } // the menu bar for associates and poster if (Surfer::is_empowered()) { $details[] = Skin::build_link($url, i18n::s('details'), 'basic'); $details[] = Skin::build_link(Files::get_url($item['id'], 'edit'), i18n::s('edit'), 'basic'); $details[] = Skin::build_link(Files::get_url($item['id'], 'delete'), i18n::s('delete'), 'basic'); } // append details if (count($details)) { $suffix .= BR . Skin::finalize_list($details, 'menu'); } // explicit icon if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } else { $icon = $context['url_to_root'] . Files::get_icon_url($item['file_name']); } // list all components for this item $items[$url] = array($prefix, '_', $suffix, 'file', $icon); } // end of processing SQL::free($result); return $items; }
// when the file has been overlaid if (is_object($overlay)) { // allow for change detection $overlay->snapshot(); // update the overlay from form content $overlay->parse_fields($_REQUEST); // save content of the overlay in this item $_REQUEST['overlay'] = $overlay->save(); $_REQUEST['overlay_id'] = $overlay->get_id(); } // save in the database Files::post($_REQUEST); // log record creation if (!$item['id']) { $label = sprintf(i18n::c('New file in %s'), strip_tags($anchor->get_title())); $link = $context['url_to_home'] . $context['url_to_root'] . Files::get_url($_REQUEST['id']); $description = sprintf(i18n::c('%s at %s'), $_REQUEST['file_name'], '<a href="' . $link . '">' . $link . '</a>'); Logger::notify('files/edit.php: ' . $label, $description); } // a file has been uploaded } elseif (Files::get_uploaded('upload', 'name')) { $file_path = Files::get_path($_REQUEST['anchor']); // update an existing file record if (isset($item['id'])) { Files::set_uploaded('upload', 'id', $item['id']); } // attach some file if ($uploaded = Files::upload(Files::get_uploaded('upload'), $file_path, $anchor->get_reference(), $overlay)) { // actually, a new file if (!isset($item['id'])) { $action = 'file:create';
/** * 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; } }
/** * embed an interactive object * * The id designates the target file. * It can also include width and height of the target canvas, as in: '12, 100%, 250px' * * @param string id of the target file * @return string the rendered string **/ public static function render_embed($id) { global $context; // split parameters $attributes = preg_split("/\\s*,\\s*/", $id, 4); $id = $attributes[0]; // get the file if (!($item = Files::get($id))) { $output = '[embed=' . $id . ']'; return $output; } // stream in a separate page if (isset($attributes[1]) && preg_match('/window/i', $attributes[1])) { if (!isset($attributes[2])) { $attributes[2] = i18n::s('Play in a separate window'); } $output = '<a href="' . $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'stream', $item['file_name']) . '" onclick="window.open(this.href); return false;" class="button"><span>' . $attributes[2] . '</span></a>'; return $output; } // file extension $extension = strtolower(substr($item['file_name'], -3)); // set a default size if (!isset($attributes[1])) { if (!strcmp($extension, 'gan')) { $attributes[1] = '98%'; } elseif (!strcmp($extension, 'mm') && isset($context['skins_freemind_canvas_width'])) { $attributes[1] = $context['skins_freemind_canvas_width']; } else { $attributes[1] = 480; } } if (!isset($attributes[2])) { if (!strcmp($extension, 'gan')) { $attributes[2] = '300px'; } elseif (!strcmp($extension, 'mm') && isset($context['skins_freemind_canvas_height'])) { $attributes[2] = $context['skins_freemind_canvas_height']; } else { $attributes[2] = 360; } } // object attributes $width = $attributes[1]; $height = $attributes[2]; $flashvars = ''; if (isset($attributes[3])) { $flashvars = $attributes[3]; } // rendering depends on file extension switch ($extension) { // stream a video case '3gp': case 'flv': case 'm4v': case 'mov': case 'mp4': // a flash player to stream a flash video $flvplayer_url = $context['url_to_home'] . $context['url_to_root'] . 'included/browser/player_flv_maxi.swf'; // file is elsewhere if (isset($item['file_href']) && $item['file_href']) { $url = $item['file_href']; } else { $url = $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'fetch', $item['file_name']); } // pass parameters to the player if ($flashvars) { $flashvars = str_replace('autostart=true', 'autoplay=1', $flashvars) . '&'; } $flashvars .= 'width=' . $width . '&height=' . $height; // if there is a static image for this video, use it if (isset($item['icon_url']) && $item['icon_url']) { $flashvars .= '&startimage=' . urlencode($item['icon_url']); } // if there is a subtitle file for this video, use it if (isset($item['file_name']) && ($srt = 'files/' . str_replace(':', '/', $item['anchor']) . '/' . str_replace('.' . $extension, '.srt', $item['file_name'])) && file_exists($context['path_to_root'] . $srt)) { $flashvars .= '&srt=1&srturl=' . urlencode($context['url_to_home'] . $context['url_to_root'] . $srt); } // if there is a logo file in the skin, use it Skin::define_img_href('FLV_IMG_HREF', 'codes/flvplayer_logo.png', ''); if (FLV_IMG_HREF) { $flashvars .= '&top1=' . urlencode(FLV_IMG_HREF . '|10|10'); } // rely on Flash if (Surfer::has_flash()) { // the full object is built in Javascript --see parameters at http://flv-player.net/players/maxi/documentation/ $output = '<div id="flv_' . $item['id'] . '" class="no_print">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n"; Page::insert_script('var flashvars = { flv:"' . $url . '", ' . str_replace(array('&', '='), array('", ', ':"'), $flashvars) . '", autoload:0, margin:1, showiconplay:1, playeralpha:50, iconplaybgalpha:30, showfullscreen:1, showloading:"always", ondoubleclick:"fullscreen" }' . "\n" . 'var params = { allowfullscreen: "true", allowscriptaccess: "always" }' . "\n" . 'var attributes = { id: "file_' . $item['id'] . '", name: "file_' . $item['id'] . '"}' . "\n" . 'swfobject.embedSWF("' . $flvplayer_url . '", "flv_' . $item['id'] . '", "' . $width . '", "' . $height . '", "9", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", flashvars, params);' . "\n"); // native support } else { // <video> is HTML5, <object> is legacy $output = '<video width="' . $width . '" height="' . $height . '" autoplay="" controls="" src="' . $url . '" >' . "\n" . ' <object width="' . $width . '" height="' . $height . '" data="' . $url . '" type="' . Files::get_mime_type($item['file_name']) . '">' . "\n" . ' <param value="' . $url . '" name="movie" />' . "\n" . ' <param value="true" name="allowFullScreen" />' . "\n" . ' <param value="always" name="allowscriptaccess" />' . "\n" . ' <a href="' . $url . '">No video playback capabilities, please download the file</a>' . "\n" . ' </object>' . "\n" . '</video>' . "\n"; } // job done return $output; // a ganttproject timeline // a ganttproject timeline case 'gan': // where the file is $path = Files::get_path($item['anchor']) . '/' . rawurlencode($item['file_name']); // we actually use a transformed version of the file $cache_id = Cache::hash($path) . '.xml'; // apply the transformation if (!file_exists($context['path_to_root'] . $cache_id) || filemtime($context['path_to_root'] . $cache_id) < filemtime($context['path_to_root'] . $path) || !($text = Safe::file_get_contents($context['path_to_root'] . $cache_id))) { // transform from GanttProject to SIMILE Timeline $text = Files::transform_gan_to_simile($path); // put in cache Safe::file_put_contents($cache_id, $text); } // load the SIMILE Timeline javascript library in shared/global.php $context['javascript']['timeline'] = TRUE; // cache would kill the loading of the library cache::poison(); // 1 week ago $now = gmdate('M d Y H:i:s', time() - 7 * 24 * 60 * 60); // load the right file $output = '<div id="gantt" style="height: ' . $height . '; width: ' . $width . '; border: 1px solid #aaa; font-family: Trebuchet MS, Helvetica, Arial, sans serif; font-size: 8pt"></div>' . "\n"; Page::insert_script('var simile_handle;' . "\n" . 'function onLoad() {' . "\n" . ' var eventSource = new Timeline.DefaultEventSource();' . "\n" . ' var theme = Timeline.ClassicTheme.create();' . "\n" . ' theme.event.bubble.width = 350;' . "\n" . ' theme.event.bubble.height = 300;' . "\n" . ' var bandInfos = [' . "\n" . ' Timeline.createBandInfo({' . "\n" . ' eventSource: eventSource,' . "\n" . ' date: "' . $now . '",' . "\n" . ' width: "80%",' . "\n" . ' intervalUnit: Timeline.DateTime.WEEK,' . "\n" . ' intervalPixels: 200,' . "\n" . ' theme: theme,' . "\n" . ' layout: "original" // original, overview, detailed' . "\n" . ' }),' . "\n" . ' Timeline.createBandInfo({' . "\n" . ' showEventText: false,' . "\n" . ' trackHeight: 0.5,' . "\n" . ' trackGap: 0.2,' . "\n" . ' eventSource: eventSource,' . "\n" . ' date: "' . $now . '",' . "\n" . ' width: "20%",' . "\n" . ' intervalUnit: Timeline.DateTime.MONTH,' . "\n" . ' intervalPixels: 50' . "\n" . ' })' . "\n" . ' ];' . "\n" . ' bandInfos[1].syncWith = 0;' . "\n" . ' bandInfos[1].highlight = true;' . "\n" . ' bandInfos[1].eventPainter.setLayout(bandInfos[0].eventPainter.getLayout());' . "\n" . ' simile_handle = Timeline.create(document.getElementById("gantt"), bandInfos, Timeline.HORIZONTAL);' . "\n" . ' simile_handle.showLoadingMessage();' . "\n" . ' Timeline.loadXML("' . $context['url_to_home'] . $context['url_to_root'] . $cache_id . '", function(xml, url) { eventSource.loadXML(xml, url); });' . "\n" . ' simile_handle.hideLoadingMessage();' . "\n" . '}' . "\n" . "\n" . 'var resizeTimerID = null;' . "\n" . 'function onResize() {' . "\n" . ' if (resizeTimerID == null) {' . "\n" . ' resizeTimerID = window.setTimeout(function() {' . "\n" . ' resizeTimerID = null;' . "\n" . ' simile_handle.layout();' . "\n" . ' }, 500);' . "\n" . ' }' . "\n" . '}' . "\n" . "\n" . '// observe page major events' . "\n" . '$(document).ready( onLoad);' . "\n" . '$(window).resize(onResize);' . "\n"); // job done return $output; // a Freemind map // a Freemind map case 'mm': // if we have an external reference, use it if (isset($item['file_href']) && $item['file_href']) { $target_href = $item['file_href']; // else redirect to ourself } else { // ensure a valid file name $file_name = utf8::to_ascii($item['file_name']); // where the file is $path = Files::get_path($item['anchor']) . '/' . rawurlencode($item['file_name']); // map the file on the regular web space $url_prefix = $context['url_to_home'] . $context['url_to_root']; // redirect to the actual file $target_href = $url_prefix . $path; } // allow several viewers to co-exist in the same page static $freemind_viewer_index; if (!isset($freemind_viewer_index)) { $freemind_viewer_index = 1; } else { $freemind_viewer_index++; } // load flash player $url = $context['url_to_home'] . $context['url_to_root'] . 'included/browser/visorFreemind.swf'; // variables $flashvars = 'initLoadFile=' . $target_href . '&openUrl=_self'; $output = '<div id="freemind_viewer_' . $freemind_viewer_index . '">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n"; Page::insert_script('var params = {};' . "\n" . 'params.base = "' . dirname($url) . '/";' . "\n" . 'params.quality = "high";' . "\n" . 'params.wmode = "transparent";' . "\n" . 'params.menu = "false";' . "\n" . 'params.flashvars = "' . $flashvars . '";' . "\n" . 'swfobject.embedSWF("' . $url . '", "freemind_viewer_' . $freemind_viewer_index . '", "' . $width . '", "' . $height . '", "6", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", false, params);' . "\n"); // offer to download a copy of the map $menu = array($target_href => i18n::s('Browse this map with Freemind')); // display menu commands below the viewer $output .= Skin::build_list($menu, 'menu_bar'); // job done return $output; // native flash // native flash case 'swf': // where to get the file if (isset($item['file_href']) && $item['file_href']) { $url = $item['file_href']; } else { $url = $context['url_to_home'] . $context['url_to_root'] . 'files/' . str_replace(':', '/', $item['anchor']) . '/' . rawurlencode($item['file_name']); } $output = '<div id="swf_' . $item['id'] . '" class="no_print">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n"; Page::insert_script('var params = {};' . "\n" . 'params.base = "' . dirname($url) . '/";' . "\n" . 'params.quality = "high";' . "\n" . 'params.wmode = "transparent";' . "\n" . 'params.allowfullscreen = "true";' . "\n" . 'params.allowscriptaccess = "always";' . "\n" . 'params.flashvars = "' . $flashvars . '";' . "\n" . 'swfobject.embedSWF("' . $url . '", "swf_' . $item['id'] . '", "' . $width . '", "' . $height . '", "6", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", false, params);' . "\n"); return $output; // link to file page // link to file page default: // link label $text = Skin::strip($item['title'] ? $item['title'] : str_replace('_', ' ', $item['file_name'])); // make a link to the target page $url = Files::get_permalink($item); // return a complete anchor $output =& Skin::build_link($url, $text); return $output; } }
/** * list files * * Recognize following variants: * - 'section:123' to list items attached to one particular anchor * - 'no_author' to list items attached to one user profile * * @param resource the SQL result * @return string HTML text to be displayed, or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // sanity check if (!isset($this->focus)) { $this->focus = ''; } // process all items in the list $items = array(); while ($item = SQL::fetch($result)) { // one box at a time $box = ''; // get the main anchor $anchor = Anchors::get($item['anchor']); // we feature only the head of the list, if we are at the origin page if (!count($items) && $anchor && is_string($this->focus) && $this->focus == $anchor->get_reference()) { $box .= Codes::render_object('file', $item['id']); // no side icon $icon = ''; // we are listing various files from various places } else { $prefix = $suffix = ''; // stream the file if (Files::is_stream($item['file_name'])) { $url = Files::get_url($item['id'], 'stream', $item['file_name']); } else { $url = Files::get_url($item['id'], 'fetch', $item['file_name']); } // absolute url $url = $context['url_to_home'] . $context['url_to_root'] . $url; // signal restricted and private files if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // file title or file name $label = Codes::beautify_title($item['title']); if (!$label) { $label = ucfirst(str_replace(array('%20', '-', '_'), ' ', $item['file_name'])); } // show a reference to the file for members $hover = i18n::s('Get the file'); if (Surfer::is_member()) { $hover .= ' [file=' . $item['id'] . ']'; } // flag files uploaded recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // one line of text $box .= $prefix . Skin::build_link($url, $label, 'basic', $hover) . $suffix; // side icon if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } else { $icon = $context['url_to_root'] . Files::get_icon_url($item['file_name']); } // build the complete HTML element $icon = '<img src="' . $icon . '" alt="" title="' . encode_field(strip_tags($label)) . '" />'; // make it a clickable link $icon = Skin::build_link($url, $icon, 'basic'); } // first line of details $details = array(); // file poster and last action if ($this->layout_variant != 'no_author') { $details[] = sprintf(i18n::s('shared by %s %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date'])); } else { $details[] = Skin::build_date($item['edit_date']); } // downloads if ($item['hits'] > 1) { $details[] = Skin::build_number($item['hits'], i18n::s('downloads')); } // file size if ($item['file_size'] > 1) { $details[] = Skin::build_number($item['file_size'], i18n::s('bytes')); } // anchor link if ($anchor && is_string($this->focus) && $this->focus != $anchor->get_reference()) { $anchor_url = $anchor->get_url(); $anchor_label = ucfirst($anchor->get_title()); $details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor_url, $anchor_label, 'article')); } $box .= '<p class="details">' . Skin::finalize_list($details, 'menu') . '</p>'; // append details $details = array(); // view the file $details[] = Skin::build_link(Files::get_permalink($item), i18n::s('details'), 'basic'); // file has been detached if (isset($item['assign_id']) && $item['assign_id']) { // who has been assigned? if (Surfer::is($item['assign_id'])) { $details[] = DRAFT_FLAG . sprintf(i18n::s('reserved by you %s'), Skin::build_date($item['assign_date'])); } else { $details[] = DRAFT_FLAG . sprintf(i18n::s('reserved by %s %s'), Users::get_link($item['assign_name'], $item['assign_address'], $item['assign_id']), Skin::build_date($item['assign_date'])); } } // detach or edit the file if (Files::allow_modification($item, $anchor)) { if (!isset($item['assign_id']) || !$item['assign_id']) { $details[] = Skin::build_link(Files::get_url($item['id'], 'reserve'), i18n::s('reserve'), 'basic', i18n::s('Prevent other persons from changing this file until you update it')); } // release reservation if (isset($item['assign_id']) && $item['assign_id'] && (Surfer::is($item['assign_id']) || is_object($anchor) && $anchor->is_owned())) { $details[] = Skin::build_link(Files::get_url($item['id'], 'release'), i18n::s('release reservation'), 'basic', i18n::s('Allow other persons to update this file')); } if (!isset($item['assign_id']) || !$item['assign_id'] || Surfer::is($item['assign_id']) || is_object($anchor) && $anchor->is_owned()) { $details[] = Skin::build_link(Files::get_url($item['id'], 'edit'), i18n::s('update'), 'basic', i18n::s('Share a new version of this file, or change details')); } } // delete the file if (Files::allow_deletion($item, $anchor)) { $details[] = Skin::build_link(Files::get_url($item['id'], 'delete'), i18n::s('delete'), 'basic'); } // append details if (count($details)) { $box .= '<p class="details">' . Skin::finalize_list($details, 'menu') . '</p>'; } // insert item icon if ($icon) { $list = array(array($box, $icon)); $items[] = Skin::finalize_list($list, 'decorated'); // put the item in a division } else { $items[] = '<div style="margin: 0 0 1em 0">' . $box . '</div>'; } } // stack all items in a single column $text = Skin::finalize_list($items, 'rows'); // end of processing SQL::free($result); return $text; }
// help the surfer } else { Logger::error(i18n::s('Operation has failed.')); } // follow-up commands $context['text'] .= Skin::build_block(Skin::build_link($anchor->get_url('files'), i18n::s('Done'), 'button'), 'bottom'); // file has been reserved, and surfer is not owner } elseif ($action != 'confirm' && isset($item['assign_id']) && $item['assign_id'] && !Surfer::is($item['assign_id'])) { // inform surfer $context['text'] .= Skin::build_block(sprintf(i18n::s('This file has been assigned to %s %s, and it is likely that an updated version will be made available soon.'), Users::get_link($item['assign_name'], $item['assign_address'], $item['assign_id']), Skin::build_date($item['assign_date'])), 'caution'); // commands $menu = array(); $menu[] = Skin::build_submit_button(i18n::s('Download this file'), NULL, NULL, 'confirmed', 'no_spin_on_click'); $menu[] = Skin::build_link($anchor->get_url('files'), i18n::s('Cancel'), 'span'); // to get the actual file $target_href = $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'fetch', $item['file_name']); // render commands $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" id="main_form"><div>' . "\n" . Skin::finalize_list($menu, 'assistant_bar') . '<input type="hidden" name="id" value="' . $item['id'] . '" />' . "\n" . '<input type="hidden" name="action" value="confirm" />' . "\n" . '</div></form>' . "\n"; // set the focus Page::insert_script('$("#confirmed").focus();'); //actual transfer } elseif ($item['id'] && $item['anchor']) { // increment the count of downloads if (!Surfer::is_crawler()) { Files::increment_hits($item['id']); } // record surfer activity Activities::post('file:' . $item['id'], 'fetch'); $anchor->touch('file:fetch', 'file:' . $item['id'], true); // if we have an external reference, use it if (isset($item['file_href']) && $item['file_href']) {
if (Files::allow_creation($item, $anchor, 'article')) { Skin::define_img('FILES_UPLOAD_IMG', 'files/upload.gif'); $link = 'files/edit.php?anchor=' . urlencode('article:' . $item['id']); $invite = Skin::build_link($link, FILES_UPLOAD_IMG . i18n::s('Add a file'), 'basic') . BR; } // list files by date (default) or by title (option files_by_title) if (Articles::has_option('files_by', $anchor, $item) == 'title') { $items = Files::list_by_title_for_anchor('article:' . $item['id'], 0, 20, 'compact'); } else { $items = Files::list_by_date_for_anchor('article:' . $item['id'], 0, 20, 'compact'); } // actually render the html if (is_array($items)) { // the command to list all files if (count($items)) { $items = array_merge($items, array(Files::get_url('article:' . $item['id'], 'list') => i18n::s('All files'))); } $items = Skin::build_list($items, 'compact'); } // display this aside the thread if ($items || $invite) { $text .= Skin::build_box(i18n::s('Files'), '<div id="thread_files_panel">' . $items . '</div>' . $invite, 'boxes', 'files'); } // links // // new links are allowed $invite = ''; if (Links::allow_creation($item, $anchor)) { Skin::define_img('LINKS_ADD_IMG', 'links/add.gif'); $link = 'links/edit.php?anchor=' . urlencode('article:' . $item['id']); $invite = Skin::build_link($link, LINKS_ADD_IMG . i18n::s('Add a link'));
} 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); } $file_from = Files::get_path($row['anchor']); if (!file_exists($context['path_to_root'] . $file_from . '/' . $row['file_name'])) { $errors_count++; $anchor = Anchors::get($row['anchor']); $context['text'] .= sprintf(i18n::s('Missing: %s'), 'file ' . Skin::build_link(Files::get_url($row['id']), $row['id'] . ' ' . $row['file_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
/** * list files for search requests * * @param resource the SQL result * @return array of resulting items ($score, $summary), or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of array($score, $summary) $items = array(); // empty list if (!SQL::count($result)) { return $items; } // process all items in the list while ($item = SQL::fetch($result)) { // one box at a time $box = ''; // get the main anchor $anchor = Anchors::get($item['anchor']); $prefix = $suffix = ''; // stream the file if (Files::is_stream($item['file_name'])) { $url = Files::get_url($item['id'], 'stream', $item['file_name']); } else { $url = Files::get_url($item['id'], 'fetch', $item['file_name']); } // absolute url $url = $context['url_to_home'] . $context['url_to_root'] . $url; // signal restricted and private files if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // file title or file name $label = Codes::beautify_title($item['title']); if (!$label) { $label = ucfirst(str_replace(array('%20', '-', '_'), ' ', $item['file_name'])); } // show a reference to the file for members $hover = i18n::s('Get the file'); if (Surfer::is_member()) { $hover .= ' [file=' . $item['id'] . ']'; } // flag files uploaded recently if ($item['create_date'] >= $context['fresh']) { $suffix .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= UPDATED_FLAG; } // one line of text $box .= $prefix . Skin::build_link($url, $label, 'basic', $hover) . $suffix; // side icon if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } else { $icon = $context['url_to_root'] . Files::get_icon_url($item['file_name']); } // build the complete HTML element $icon = '<img src="' . $icon . '" alt="" title="' . encode_field(strip_tags($label)) . '" />'; // make it a clickable link $icon = Skin::build_link($url, $icon, 'basic'); // first line of details $details = array(); // file poster and last action $details[] = sprintf(i18n::s('shared by %s %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date'])); // downloads if ($item['hits'] > 1) { $details[] = Skin::build_number($item['hits'], i18n::s('downloads')); } // file size if ($item['file_size'] > 1) { $details[] = Skin::build_number($item['file_size'], i18n::s('bytes')); } // file has been detached if (isset($item['assign_id']) && $item['assign_id']) { // who has been assigned? if (Surfer::is($item['assign_id'])) { $details[] = DRAFT_FLAG . sprintf(i18n::s('reserved by you %s'), Skin::build_date($item['assign_date'])); } else { $details[] = DRAFT_FLAG . sprintf(i18n::s('reserved by %s %s'), Users::get_link($item['assign_name'], $item['assign_address'], $item['assign_id']), Skin::build_date($item['assign_date'])); } } // the main anchor link if (is_object($anchor)) { $details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()), 'article')); } // append details if (count($details)) { $box .= '<p class="details">' . Skin::finalize_list($details, 'menu') . '</p>'; } // layout this item if ($icon) { $list = array(array($box, $icon)); $items[] = array($item['score'], Skin::finalize_list($list, 'decorated')); // put the item in a division } else { $items[] = array($item['score'], '<div style="margin: 0 0 1em 0">' . $box . '</div>'); } } // end of processing SQL::free($result); return $items; }
} // not found if (!isset($item['id'])) { include '../error.php'; // permission denied } elseif (!$permitted) { Safe::header('Status: 401 Unauthorized', TRUE, 401); Logger::error(i18n::s('You are not allowed to perform this operation.')); // file has been reserved } elseif (isset($item['assign_id']) && $item['assign_id'] && !Surfer::is($item['assign_id'])) { // prevent updates $context['text'] .= Skin::build_block(sprintf(i18n::s('This file has been reserved by %s %s, and it is likely that an updated version will be made available soon.'), Users::get_link($item['assign_name'], $item['assign_address'], $item['assign_id']), Skin::build_date($item['assign_date'])), 'caution'); // follow-up commands $menu = array(); $menu[] = Skin::build_link($anchor->get_url('files'), i18n::s('Done'), 'button'); $menu[] = Skin::build_link(Files::get_url($item['id'], 'release'), i18n::s('Release reservation'), 'span'); $context['text'] .= Skin::build_block(Skin::finalize_list($menu, 'menu_bar'), 'bottom'); // deletion is confirmed } elseif (isset($_REQUEST['confirm']) && $_REQUEST['confirm'] == 'yes') { // touch the related anchor before actual deletion, since the file has to be accessible at that time if (is_object($anchor)) { $anchor->touch('file:delete', $item['id']); } // if no error, back to the anchor or to the index page if (Files::delete($item['id'])) { // log item deletion $label = sprintf(i18n::c('Deletion: %s'), strip_tags($item['title'])); $description = Files::get_permalink($item); Logger::remember('files/delete.php: ' . $label, $description); Files::clear($item); if ($render_overlaid) {
/** * list files * * @param resource the SQL result * @return array of resulting items, or NULL * * @see layouts/layout.php **/ function layout($result) { global $context; // we return an array of ($url => $attributes) $items = array(); // empty list if (!SQL::count($result)) { return $items; } // process all items in the list while ($item = SQL::fetch($result)) { // get the anchor for this file if ($item['anchor']) { $anchor = Anchors::get($item['anchor']); } // download the file directly $url = $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'fetch', $item['file_name']); // time of last update $time = SQL::strtotime($item['edit_date']); // the title as the label if ($item['title']) { $label = Codes::beautify_title($item['title']) . ' (' . str_replace(array('%20', '-', '_'), ' ', $item['file_name']) . ')'; } else { $label = str_replace(array('%20', '-', '_'), ' ', $item['file_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); // always add a link to container if (is_object($anchor)) { if ($description) { $description .= BR; } $description .= sprintf(i18n::s('in %s'), Skin::build_link($anchor->get_url(), $anchor->get_title(), 'basic')); } // 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['file_name']); $extensions[] = '<enclosure url="' . $context['url_to_home'] . $context['url_to_root'] . Files::get_path($item['anchor']) . '/' . $item['file_name'] . '"' . ' length="' . $item['file_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; }
/** * integrate some player for the file, if any * * @param array the file to look at * @param int width for video player * @param int height of video player * @return string tags to be put in the HTML flow, or an empty string */ public static function interact($item, $width = 320, $height = 240, $flashvars = '', $with_icon = TRUE) { global $context; static $counter; if (!isset($counter)) { $counter = 1; } else { $counter++; } // display explicit title, if any $title = ''; if ($item['title']) { $title = '<p>' . Skin::strip($item['title']) . '</p>'; } // several ways to play flash switch (strtolower(substr($item['file_name'], -3))) { // audio file handled by dewplayer case 'mp3': // only if the player is available if (file_exists($context['path_to_root'] . 'included/browser/dewplayer.swf')) { // the player $dewplayer_url = $context['url_to_root'] . 'included/browser/dewplayer.swf'; // the mp3 file if (isset($item['file_href']) && $item['file_href']) { $mp3_url = $item['file_href']; } else { $mp3_url = $context['url_to_root'] . Files::get_url($item['id'], 'fetch', $item['file_name']); } $flashvars = 'son=' . $mp3_url; // combine the two in a single object $output = '<div id="interact_' . $counter . '" class="no_print">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n" . $title; Page::insert_script('var params = {};' . "\n" . 'params.base = "' . dirname($mp3_url) . '/";' . "\n" . 'params.quality = "high";' . "\n" . 'params.wmode = "transparent";' . "\n" . 'params.menu = "false";' . "\n" . 'params.flashvars = "' . $flashvars . '";' . "\n" . 'swfobject.embedSWF("' . $dewplayer_url . '", "interact_' . $counter . '", "200", "20", "6", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", false, params);' . "\n"); return $output; } // native flash // native flash case 'swf': // where to get the file if (isset($item['file_href']) && $item['file_href']) { $url = $item['file_href']; } else { $url = $context['url_to_home'] . $context['url_to_root'] . 'files/' . str_replace(':', '/', $item['anchor']) . '/' . rawurlencode($item['file_name']); } $output = '<div id="interact_' . $counter . '" class="no_print">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div><br />' . "\n" . $title; Page::insert_script('var params = {};' . "\n" . 'params.base = "' . dirname($url) . '/";' . "\n" . 'params.quality = "high";' . "\n" . 'params.wmode = "transparent";' . "\n" . 'params.allowfullscreen = "true";' . "\n" . 'params.allowscriptaccess = "always";' . "\n" . 'params.flashvars = "' . $flashvars . '";' . "\n" . 'swfobject.embedSWF("' . $url . '", "interact_' . $counter . '", "' . $width . '", "' . $height . '", "6", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", false, params);' . "\n"); return $output; // stream a video // stream a video case '3gp': case 'flv': case 'm4v': case 'mov': case 'mp4': // a flash player to stream a flash video $flvplayer_url = $context['url_to_home'] . $context['url_to_root'] . 'included/browser/player_flv_maxi.swf'; // file is elsewhere if (isset($item['file_href']) && $item['file_href']) { $url = $item['file_href']; } else { $url = $context['url_to_home'] . $context['url_to_root'] . Files::get_url($item['id'], 'fetch', $item['file_name']); } // pass parameters to the player if ($flashvars) { $flashvars = str_replace('autostart=true', 'autoplay=1', $flashvars) . '&'; } $flashvars .= 'width=' . $width . '&height=' . $height; // rely on Flash if (Surfer::has_flash()) { // the full object is built in Javascript --see parameters at http://flv-player.net/players/maxi/documentation/ $output = '<div id="interact_' . $counter . '" class="no_print">Flash plugin or Javascript are turned off. Activate both and reload to view the object</div>' . "\n" . $title; Page::insert_script('var flashvars = { flv:"' . $url . '", ' . str_replace(array('&', '='), array('", ', ':"'), $flashvars) . '", autoload:0, margin:1, showiconplay:1, playeralpha:50, iconplaybgalpha:30, showloading:"always", ondoubleclick:"fullscreen" }' . "\n" . 'var params = { allowfullscreen: "true", allowscriptaccess: "always" }' . "\n" . 'var attributes = { id: "interact_' . $counter . '", name: "file_' . $item['id'] . '"}' . "\n" . 'swfobject.embedSWF("' . $flvplayer_url . '", "interact_' . $counter . '", "' . $width . '", "' . $height . '", "9", "' . $context['url_to_home'] . $context['url_to_root'] . 'included/browser/expressinstall.swf", flashvars, params);' . "\n"); // native support } else { $output = '<object width="' . $width . '" height="' . $height . '" data="' . $url . '" type="' . Files::get_mime_type($item['file_name']) . '">' . "\n" . ' <param value="' . $url . '" name="movie" />' . "\n" . ' <param value="true" name="allowFullScreen" />' . "\n" . ' <param value="always" name="allowscriptaccess" />' . "\n" . ' <a href="' . $url . '">No video playback capabilities, please download the file</a>' . "\n" . '</object>' . "\n" . $title; } return $output; } if (!$with_icon) { return ''; } // this is a reasonably large image if (Files::is_image($item['file_name']) && ($image_information = Safe::GetImageSize($context['path_to_root'] . 'files/' . str_replace(':', '/', $item['anchor']) . '/' . $item['file_name'])) && $image_information[0] <= 600) { // provide a direct link to it! $src = $context['url_to_home'] . $context['url_to_root'] . 'files/' . str_replace(':', '/', $item['anchor']) . '/' . rawurlencode($item['file_name']); $icon = '<img src="' . $src . '" width="' . $image_information[0] . '" height="' . $image_information[1] . '" alt="" style="padding: 3px"/>' . BR; return Skin::build_link(Files::get_download_url($item), $icon, 'basic') . $title; } // explicit icon if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } else { $icon = $context['url_to_root'] . Files::get_icon_url($item['file_name']); } // a clickable image to access the file if ($icon) { $icon = '<img src="' . $icon . '" alt="" style="padding: 3px"/>'; // label for this file $text = ''; // signal restricted and private files if ($item['active'] == 'N') { $text .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $text .= RESTRICTED_FLAG; } // use file name, or regular title $text .= Skin::strip($item['title'] ? $item['title'] : str_replace('_', ' ', $item['file_name'])); // flag files uploaded recently if ($item['create_date'] >= $context['fresh']) { $text .= NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $text .= UPDATED_FLAG; } // make a link to the target page $url = Files::get_download_url($item); return Skin::build_link($url, $icon, 'basic') . BR . Skin::build_link($url, $text, 'basic'); } // nothing special return ''; }
// insert anchor suffix if (is_object($anchor)) { $context['text'] .= $anchor->get_suffix(); } // page menu // // get parent of the anchor too $parent = NULL; if (is_object($anchor) && ($parent = $anchor->get_parent())) { $parent =& Anchors::get($parent); } // the command to post a new file, if this is allowed if (is_object($anchor) && Files::allow_creation($anchor->get_values(), $parent, $anchor->get_type())) { Skin::define_img('FILES_UPLOAD_IMG', 'files/upload.gif'); $context['page_menu'][] = Skin::build_link(Files::get_url($anchor->get_reference(), 'file'), FILES_UPLOAD_IMG . i18n::s('Add a file')); } // command to go back if (is_object($anchor) && $anchor->is_viewable()) { $context['page_menu'][] = Skin::build_link($anchor->get_url(), i18n::s('Back to main page'), 'basic'); } // side tools // // the command to post a new file, if this is allowed if (is_object($anchor) && Files::allow_creation($anchor->get_values(), $parent, $anchor->get_type())) { $context['page_tools'][] = Skin::build_link(Files::get_url($anchor->get_reference(), 'file'), i18n::s('Add a file')); } // back to main page $context['page_tools'][] = Skin::build_link($anchor->get_url(), i18n::s('Back to main page')); } // render the skin render_skin();
/** * get the url to display the main page for this anchor * * @param string the targeted action ('view', 'print', 'edit', 'delete', ...) * @return an anchor to the viewing script * * @see shared/anchor.php */ function get_url($action = 'view') { if (isset($this->item['id'])) { return Files::get_url($this->item['id'], $action, $this->item['file_name']); } return NULL; }
/** * the URL to start and to join the meeting * * @see overlays/events/start.php * * @return string the URL to redirect the user to the meeting, or NULL on error */ function get_start_url() { global $context; // almost random passwords $this->initialize_passwords(); // parameters to create a meeting $parameters = array(); // use page id as meeting id $parameters[] = 'name=' . urlencode($this->attributes['id']); $parameters[] = 'meetingID=' . urlencode($this->attributes['id']); // surfer name, as authenticated by yacs $parameters[] = 'fullName=' . urlencode(Surfer::get_name()); // moderator password $parameters[] = 'moderatorPW=' . urlencode($this->moderator_password); // participant password $parameters[] = 'attendeePW=' . urlencode($this->attendee_password); // ensure that the bridge number fits in the dialing plan $parameters[] = 'voiceBridge=' . urlencode(substr('7' . $this->attributes['id'] . '1234', 0, 5)); // message displayed within the BigBlueButton session $welcome = ''; // meeting title if (is_object($this->anchor)) { $welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Title'), $this->anchor->get_title()) . "\n"; } // meeting date if (isset($this->attributes['date_stamp'])) { $welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Date'), Skin::build_date($this->attributes['date_stamp'], 'standalone')) . "\n"; } // meeting duration if (isset($this->attributes['duration'])) { $welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Duration'), $this->attributes['duration'] . ' ' . i18n::s('minutes')) . "\n"; } // build a link to the owner page, if any if (is_object($this->anchor) && ($user = Users::get($this->anchor->get_value('owner_id')))) { $welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Chairman'), $user['full_name']) . "\n"; } // welcome message $parameters[] = 'welcome=' . urlencode($welcome); // return URL if (is_callable(array($this->anchor, 'get_url'))) { $parameters[] = 'logoutURL=' . urlencode($context['url_to_home'] . $context['url_to_root'] . $this->anchor->get_url()); } // should we record this session? if ($this->with_session_recording()) { $parameters[] = 'record=true'; $parameters[] = 'duration=125'; // 2 hours max per recording } // link to create the meeting $url = $this->build_link('create', $parameters); // list most recent files that have been attached to this page $headers = NULL; $body = NULL; if (is_object($this->anchor) && ($files = Files::list_by_date_for_anchor($this->anchor->get_reference(), 0, 5, 'raw'))) { $headers = array("Content-Type: text/xml"); // instruct the presentation module to pre-load these files $body = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<modules>' . "\n" . ' <module name="presentation">' . "\n"; // list web address of each file foreach ($files as $file) { $body .= "\t\t" . '<document' . ' url="' . $context['url_to_home'] . $context['url_to_root'] . utf8::to_xml(Files::get_url($file['id'], 'fetch', $file['file_name'])) . '"' . ' name="' . utf8::to_xml($file['file_name']) . '"' . ' />' . "\n"; } // end of the list of files $body .= ' </module>' . "\n" . '</modules>' . "\n"; } // do create the meeting if (($response = http::proceed_natively($url, $headers, $body)) && ($xml = simplexml_load_string($response)) && $xml->returncode == 'SUCCESS') { // parameters to join the meeting $parameters = array(); // use page id as meeting id $parameters[] = 'meetingID=' . urlencode($xml->meetingID); // surfer name, as authenticated by yacs $parameters[] = 'fullName=' . urlencode(Surfer::get_name()); // moderator password $parameters[] = 'password='******'join', $parameters); return $url; } // problem, darling! return NULL; }
if (Images::allow_creation($item, $anchor, 'file')) { Skin::define_img('IMAGES_ADD_IMG', 'images/add.gif'); $context['page_tools'][] = Skin::build_link('images/edit.php?anchor=' . urlencode('file:' . $item['id']), IMAGES_ADD_IMG . i18n::s('Add an image'), 'basic'); } } // restore a previous version, if any if (is_object($anchor) && $anchor->is_owned() && Versions::count_for_anchor('file:' . $item['id'])) { Skin::define_img('FILES_VERSIONS_IMG', 'files/versions.gif'); $context['page_tools'][] = Skin::build_link(Versions::get_url('file:' . $item['id'], 'list'), FILES_VERSIONS_IMG . i18n::s('Versions')); } // delete command provided to associates and owners if (is_object($anchor) && $anchor->is_owned() || Surfer::is_associate()) { Skin::define_img('FILES_DELETE_IMG', 'files/delete.gif'); $context['page_tools'][] = Skin::build_link(Files::get_url($item['id'], 'delete'), FILES_DELETE_IMG . i18n::s('Delete this file')); } // the navigation sidebar $text = ''; if (is_object($anchor)) { $neighbours = $anchor->get_neighbours('file', $item); $text .= Skin::neighbours($neighbours, 'sidebar'); } // build a nice sidebar box if ($text) { $text =& Skin::build_box(i18n::s('Navigation'), $text, 'neighbours', 'neighbours'); } $context['components']['neighbours'] = $text; // referrals, if any $context['components']['referrals'] =& Skin::build_referrals(Files::get_url($item['id'])); } // render the skin render_skin();
/** * 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, ''); }
Safe::header('Status: 401 Unauthorized', TRUE, 401); 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.')); // provide updated information for this anchor } else { // list files by date (default) or by title (option files_by_title) if ($anchor->has_option('files_by') == 'title') { $output = Files::list_by_title_for_anchor($anchor->get_reference(), 0, 20, 'compact'); } else { $output = Files::list_by_date_for_anchor($anchor->get_reference(), 0, 20, 'compact'); } // ensure we are producing some text if (is_array($output)) { // the command to list all files if (count($output)) { $output = array_merge($output, array(Files::get_url($anchor->get_reference(), 'list') => i18n::s('All files'))); } $output =& Skin::build_list($output, 'compact'); } // actual transmission except on a HEAD request if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') { echo $output; } // the post-processing hook, then exit finalize_page(TRUE); } // render the skin on error render_skin();