/** * 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 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)); // with hits if ($item['hits'] > 1) { $suffix .= ' ' . Skin::build_number($item['hits'], i18n::s('hits')); } // list all components for this item $items[$url] = array($prefix, $label, $suffix, 'basic', NULL); } // end of processing SQL::free($result); return $items; }
// display in a separate panel if (trim($referrals)) { $panels[] = array('referrals', i18n::s('Referrals'), 'referrals_panel', $referrals); } // // requests from search engines // $searches = ''; include_once $context['path_to_root'] . 'agents/referrals.php'; if ($result = Referrals::list_by_keywords(0, 50)) { // table row $headers = array(i18n::s('Keywords'), i18n::s('Count')); // table rows $rows = array(); while ($item = SQL::fetch($result)) { $rows[] = array('left=' . Skin::build_link($item['referer'], $item['keywords'], 'external'), 'left=' . Skin::build_number($item['hits'])); } // render the table $searches .= Skin::table($headers, $rows); } // display in a separate panel if (trim($searches)) { $panels[] = array('searches', i18n::s('Searches'), 'searches_panel', $searches); } // // assemble all tabs // $context['text'] .= Skin::build_tabs($panels); } // referrals, if any $context['components']['referrals'] = Skin::build_referrals('agents/index.php');
list($link, $title, $description) = $attributes; $item['source'] = Skin::build_link($link, $title); } } $cells = array(i18n::s('Source'), 'left=' . $item['source']); $context['text'] .= Skin::table_row($cells, $lines++); } // actual file name $cells = array(i18n::s('Actual file'), 'left=' . $item['file_name']); $context['text'] .= Skin::table_row($cells, $lines++); // file size $cells = array(i18n::s('File size'), 'left=' . sprintf(i18n::s('%d bytes'), $item['file_size'])); $context['text'] .= Skin::table_row($cells, $lines++); // hits if ($item['hits'] > 1) { $cells = array(i18n::s('Downloads'), 'left=' . Skin::build_number($item['hits'], i18n::s('downloads'))); $context['text'] .= Skin::table_row($cells, $lines++); } // the first poster if ($item['create_name']) { $cells = array(i18n::s('Posted by'), $item['create_name']); $context['text'] .= Skin::table_row($cells, $lines++); } // the last poster if ($item['edit_name'] != $item['create_name']) { $cells = array(i18n::s('Updated by'), $item['edit_name']); $context['text'] .= Skin::table_row($cells, $lines++); } // date of last action $cells = array(i18n::s('Last action'), Skin::build_date($item['edit_date'])); $context['text'] .= Skin::table_row($cells, $lines++);
} $cells[] = Skin::build_link('files/', SQL::table_name('files'), 'basic') . $size; $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . ($stats['oldest_date'] ? Skin::build_date($stats['oldest_date']) : '--'); $cells[] = 'center=' . ($stats['newest_date'] ? Skin::build_date($stats['newest_date']) : '--'); $text .= Skin::table_row($cells, $lines++); } else { $text .= Skin::table_row(array(SQL::table_name('files'), i18n::s('unknown or empty table'), ' ', ' '), $lines++); } // images include_once '../images/images.php'; if ($stats = Images::stat()) { $cells = array(); $size = ''; if ($stats['total_size']) { $size = ' (' . Skin::build_number($stats['total_size']) . ')'; } $cells[] = Skin::build_link('images/', SQL::table_name('images'), 'basic') . $size; $cells[] = 'center=' . $stats['count']; $cells[] = 'center=' . ($stats['oldest_date'] ? Skin::build_date($stats['oldest_date']) : '--'); $cells[] = 'center=' . ($stats['newest_date'] ? Skin::build_date($stats['newest_date']) : '--'); $text .= Skin::table_row($cells, $lines++); } else { $text .= Skin::table_row(array(SQL::table_name('images'), i18n::s('unknown or empty table'), ' ', ' '), $lines++); } // issues if ($row = SQL::table_stat('issues')) { $cells = array(); $cells[] = SQL::table_name('issues'); $cells[] = 'center=' . $row[0]; $cells[] = 'center=' . ($row[1] ? Skin::build_date($row[1]) : '--');
/** * list articles for manual review * * @param resource the SQL result * @return string the rendered text * * @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 include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; while ($item = SQL::fetch($result)) { // get the related overlay, if any $overlay = Overlay::load($item, 'article:' . $item['id']); // get the anchor $anchor = Anchors::get($item['anchor']); // the url to view this item $url = Articles::get_permalink($item); // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // initialize variables $prefix = $suffix = ''; // flag sticky pages if ($item['rank'] < 10000) { $prefix .= STICKY_FLAG; } // signal locked articles if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) { $suffix .= ' ' . LOCKED_FLAG; } // flag articles that are dead, or created or updated very recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } elseif ($item['create_date'] >= $context['fresh']) { $suffix .= ' ' . NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= ' ' . UPDATED_FLAG; } // signal articles to be published if ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $prefix .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // details $details = array(); // the author(s) if ($item['create_name'] != $item['edit_name']) { $details[] = sprintf(i18n::s('by %s, %s'), $item['create_name'], $item['edit_name']); } else { $details[] = sprintf(i18n::s('by %s'), $item['create_name']); } // the last action $details[] = Anchors::get_action_label($item['edit_action']) . ' ' . Skin::build_date($item['edit_date']); // the number of hits if (Surfer::is_logged() && $item['hits'] > 1) { $details[] = Skin::build_number($item['hits'], i18n::s('hits')); } // info on related files if ($count = Files::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count); } // info on related links if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count); } // info on related comments if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count); } // append details to the suffix $suffix .= ' - <span class="details">' . ucfirst(trim(implode(', ', $details))) . '</span>'; // commands to review the article $menu = array(); // read the page $menu = array_merge($menu, array($url => i18n::s('Read'))); // validate the page $menu = array_merge($menu, array('articles/stamp.php?id=' . $item['id'] . '&confirm=review' => i18n::s('Validate'))); // add a menu $suffix .= ' ' . Skin::build_list($menu, 'menu'); // list all components for this item $items[$url] = array($prefix, $title, $suffix, 'basic', NULL); } // end of processing SQL::free($result); return $items; }
$context['text'] .= '<p>' . sprintf(i18n::s('Current picture: %s'), BR . '<img src="' . $item['avatar_url'] . '" alt="" style="avatar" />') . '</p>' . "\n"; } else { $context['text'] .= '<p>' . i18n::s('No picture has been set for this profile.') . '</p>'; } // list available avatars, except on error if (!count($context['error']) && isset($item['id'])) { // upload an image // if (Images::allow_creation($item, null, 'user')) { // the form to post an image $text = '<form method="post" action="' . $context['url_to_root'] . 'images/edit.php" id="main_form" enctype="multipart/form-data"><div>' . '<input type="hidden" name="anchor" value="user:'******'id'] . '" />' . '<input type="hidden" name="action" value="set_as_avatar" />'; $fields = array(); // the image $text .= '<input type="file" name="upload" id="upload" size="30" accesskey="i" title="' . encode_field(i18n::s('Press to select a local file')) . '" />'; $text .= ' ' . Skin::build_submit_button(i18n::s('Submit'), i18n::s('Press [s] to submit data'), 's'); $text .= BR . '<span class="details">' . i18n::s('Select a .png, .gif or .jpeg image.') . ' (< ' . Skin::build_number($image_maximum_size, i18n::s('bytes')) . ')</span>'; // end of the form $text .= '</div></form>'; // the script used for form handling at the browser Page::insert_script('$("#upload").focus();'); $context['text'] .= Skin::build_content(NULL, i18n::s('Upload an image'), $text); } // use the library // // where images are $path = 'skins/_reference/avatars'; // browse the path to list directories and files if ($dir = Safe::opendir($context['path_to_root'] . $path)) { $text = ''; if (Surfer::may_upload()) { $text .= '<p>' . i18n::s('Click on one image below to make it your new picture.') . '</p>' . "\n";
/** * 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; }
/** * list articles * * @param resource the SQL result * @return string the rendered text * * @see layouts/layout.php **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // the script used to check all pages at once Page::insert_script('function cascade_selection_to_all_article_rows(handle) {' . "\n" . ' $("div#articles_panel input[type=\'checkbox\'].row_selector").each(' . "\n" . ' function() { $(this).attr("checked", $(handle).is(":checked"));}' . "\n" . ' );' . "\n" . '}' . "\n"); // table prefix $text .= Skin::table_prefix('yc-grid'); // table headers $main = '<input type="checkbox" class="row_selector" onclick="cascade_selection_to_all_article_rows(this);" />'; $cells = array($main, i18n::s('Page'), i18n::s('Rank')); $text .= Skin::table_row($cells, 'header'); // process all items in the list include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; $count = 0; while ($item = SQL::fetch($result)) { $cells = array(); // get the related overlay, if any $overlay = Overlay::load($item, 'article:' . $item['id']); // get the main anchor $anchor = Anchors::get($item['anchor']); // the url to view this item $url = Articles::get_permalink($item); // column to select the row $cells[] = '<input type="checkbox" name="selected_articles[]" id="article_selector_' . $count . '" class="row_selector" value="' . $item['id'] . '" />'; // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // initialize variables $prefix = $suffix = $icon = ''; // flag sticky pages if ($item['rank'] < 10000) { $prefix .= STICKY_FLAG; } // signal locked articles if (isset($item['locked']) && $item['locked'] == 'Y') { $suffix .= ' ' . LOCKED_FLAG; } // flag articles that are dead, or created or updated very recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } elseif ($item['create_date'] >= $context['fresh']) { $suffix .= ' ' . NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= ' ' . UPDATED_FLAG; } // signal articles to be published if ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $prefix .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // the introductory text if (is_object($overlay)) { $introduction = $overlay->get_text('introduction', $item); } else { $introduction = $item['introduction']; } if ($introduction) { $suffix .= BR . Codes::beautify_introduction($introduction); } // insert overlay data, if any if (is_object($overlay)) { $suffix .= $overlay->get_text('list', $item); } // append details to the suffix $suffix .= BR . '<span class="details">'; // details $details = array(); // the author if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') { if ($item['create_name'] != $item['edit_name']) { $details[] = sprintf(i18n::s('by %s, %s'), $item['create_name'], $item['edit_name']); } else { $details[] = sprintf(i18n::s('by %s'), $item['create_name']); } } // the last action $details[] = Anchors::get_action_label($item['edit_action']) . ' ' . Skin::build_date($item['edit_date']); // the number of hits if (Surfer::is_logged() && $item['hits'] > 1) { $details[] = Skin::build_number($item['hits'], i18n::s('hits')); } // info on related files $stats = Files::stat_for_anchor('article:' . $item['id']); if ($stats['count']) { $details[] = sprintf(i18n::ns('%d file', '%d files', $stats['count']), $stats['count']); } // info on related links $stats = Links::stat_for_anchor('article:' . $item['id']); if ($stats['count']) { $details[] = sprintf(i18n::ns('%d link', '%d links', $stats['count']), $stats['count']); } // info on related comments $stats = Comments::stat_for_anchor('article:' . $item['id']); if ($stats['count']) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $stats['count']), $stats['count']); } // rating if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) { $details[] = Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic'); } // combine in-line details if (count($details)) { $suffix .= ucfirst(trim(implode(', ', $details))); } // list up to three categories by title, if any $anchors = array(); if ($members =& Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 7, 'raw')) { foreach ($members as $id => $attributes) { // add background color to distinguish this category against others if (isset($attributes['background_color']) && $attributes['background_color']) { $attributes['title'] = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $attributes['title'] . '</span>'; } $anchors[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic'); } } if (count($anchors)) { $suffix .= BR . sprintf(i18n::s('In %s'), implode(' / ', $anchors)); } // end of details $suffix .= '</span>'; // strip empty details $suffix = str_replace(BR . '<span class="details"></span>', '', $suffix); $suffix = str_replace('<span class="details"></span>', '', $suffix); // the icon to put in the left column if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } // commands $commands = array(Skin::build_link(Articles::get_url($item['id'], 'edit'), i18n::s('edit'), 'basic'), Skin::build_link(Articles::get_url($item['id'], 'delete'), i18n::s('delete'), 'basic')); // link to this page $cells[] = $prefix . Skin::build_link($url, $title, 'article') . ' - ' . Skin::finalize_list($commands, 'menu') . $suffix; // ranking $cells[] = '<input type="text" size="5" name="article_rank_' . $item['id'] . '" value="' . $item['rank'] . '" onfocus="$(\'#article_selector_' . $count . '\').attr(\'checked\', \'checked\');" onchange="$(\'#act_on_articles\').prop(\'selectedIndex\', 9);" />'; // append the row $text .= Skin::table_row($cells, $count++); } // select all rows $cells = array('<input type="checkbox" class="row_selector" onclick="cascade_selection_to_all_article_rows(this);" />', i18n::s('Select all/none'), ''); $text .= Skin::table_row($cells, $count++); // table suffix $text .= Skin::table_suffix(); // end of processing SQL::free($result); return $text; }
/** * process uploaded file * * This function processes files from the temporary directory, and put them at their definitive * place. * * It returns FALSE if there is a disk error, or if some virus has been detected, or if * the operation fails for some other reason (e.g., file size). * * @param array usually, $_FILES['upload'] * @param string target location for the file * @param mixed reference to the target anchor, of a function to parse every file individually * @return mixed file name or array of file names or FALSE if an error has occured */ public static function upload($input, $file_path, $target = NULL, $overlay = NULL) { global $context, $_REQUEST; // size exceeds php.ini settings -- UPLOAD_ERR_INI_SIZE if (isset($input['error']) && $input['error'] == 1) { Logger::error(i18n::s('The size of this file is over limit.')); } elseif (isset($input['error']) && $input['error'] == 2) { Logger::error(i18n::s('The size of this file is over limit.')); } elseif (isset($input['error']) && $input['error'] == 3) { Logger::error(i18n::s('No file has been transmitted.')); } elseif (isset($input['error']) && $input['error'] == 4) { Logger::error(i18n::s('No file has been transmitted.')); } elseif (!$input['size']) { Logger::error(i18n::s('No file has been transmitted.')); } // do we have a file? if (!isset($input['name']) || !$input['name'] || $input['name'] == 'none') { return FALSE; } // access the temporary uploaded file $file_upload = $input['tmp_name']; // $_FILES transcoding to utf8 is not automatic $input['name'] = utf8::encode($input['name']); // enhance file name $file_name = $input['name']; $file_extension = ''; $position = strrpos($input['name'], '.'); if ($position !== FALSE) { $file_name = substr($input['name'], 0, $position); $file_extension = strtolower(substr($input['name'], $position + 1)); } $input['name'] = $file_name; if ($file_extension) { $input['name'] .= '.' . $file_extension; } // ensure we have a file name $file_name = utf8::to_ascii($input['name']); // uploads are not allowed if (!Surfer::may_upload()) { Logger::error(i18n::s('You are not allowed to perform this operation.')); } elseif (!Files::is_authorized($input['name'])) { Logger::error(i18n::s('This type of file is not allowed.')); } elseif ($file_path && !Safe::is_uploaded_file($file_upload)) { Logger::error(i18n::s('Possible file attack.')); } else { // create folders if ($file_path) { Safe::make_path($file_path); } // sanity check if ($file_path && $file_path[strlen($file_path) - 1] != '/') { $file_path .= '/'; } // move the uploaded file if ($file_path && !Safe::move_uploaded_file($file_upload, $context['path_to_root'] . $file_path . $file_name)) { Logger::error(sprintf(i18n::s('Impossible to move the upload file to %s.'), $file_path . $file_name)); } else { // process the file where it is if (!$file_path) { $file_path = str_replace($context['path_to_root'], '', dirname($file_upload)); $file_name = basename($file_upload); } // check against viruses $result = Files::has_virus($context['path_to_root'] . $file_path . '/' . $file_name); // no virus has been found in this file if ($result == 'N') { $context['text'] .= Skin::build_block(i18n::s('No virus has been found.'), 'note'); } // this file has been infected! if ($result == 'Y') { // delete this file immediately Safe::unlink($file_path . '/' . $file_name); Logger::error(i18n::s('This file has been infected by a virus and has been rejected!')); return FALSE; } // explode a .zip file include_once $context['path_to_root'] . 'shared/zipfile.php'; if (preg_match('/\\.zip$/i', $file_name) && isset($_REQUEST['explode_files'])) { $zipfile = new zipfile(); // check files extracted from the archive file function explode_callback($name) { global $context; // reject all files put in sub-folders if (($path = substr($name, strlen($context['uploaded_path'] . '/'))) && strpos($path, '/') !== FALSE) { Safe::unlink($name); } elseif (!Files::is_authorized($name)) { Safe::unlink($name); } else { // make it easy to download $ascii = utf8::to_ascii(basename($name)); Safe::rename($name, $context['uploaded_path'] . '/' . $ascii); // remember this name $context['uploaded_files'][] = $ascii; } } // extract archive components and save them in mentioned directory $context['uploaded_files'] = array(); $context['uploaded_path'] = $file_path; if (!($count = $zipfile->explode($context['path_to_root'] . $file_path . '/' . $file_name, $file_path, '', 'explode_callback'))) { Logger::error(sprintf('Nothing has been extracted from %s.', $file_name)); return FALSE; } // one single file has been uploaded } else { $context['uploaded_files'] = array($file_name); } // ensure we know the surfer Surfer::check_default_editor($_REQUEST); // post-process all uploaded files foreach ($context['uploaded_files'] as $file_name) { // this will be filtered by umask anyway Safe::chmod($context['path_to_root'] . $file_path . $file_name, $context['file_mask']); // invoke post-processing function if ($target && is_callable($target)) { call_user_func($target, $file_name, $context['path_to_root'] . $file_path); // we have to update an anchor page } elseif ($target && is_string($target)) { $fields = array(); // update a file with the same name for this anchor if ($matching =& Files::get_by_anchor_and_name($target, $file_name)) { $fields['id'] = $matching['id']; } elseif (isset($input['id']) && ($matching = Files::get($input['id']))) { $fields['id'] = $matching['id']; // silently delete the previous version of the file if (isset($matching['file_name'])) { Safe::unlink($file_path . '/' . $matching['file_name']); } } // prepare file record $fields['file_name'] = $file_name; $fields['file_size'] = filesize($context['path_to_root'] . $file_path . $file_name); $fields['file_href'] = ''; $fields['anchor'] = $target; // change title if (isset($_REQUEST['title'])) { $fields['title'] = $_REQUEST['title']; } // change has been documented if (!isset($_REQUEST['version']) || !$_REQUEST['version']) { $_REQUEST['version'] = ''; } else { $_REQUEST['version'] = ' - ' . $_REQUEST['version']; } // always remember file uploads, for traceability $_REQUEST['version'] = $fields['file_name'] . ' (' . Skin::build_number($fields['file_size'], i18n::s('bytes')) . ')' . $_REQUEST['version']; // add to file history $fields['description'] = Files::add_to_history($matching, $_REQUEST['version']); // if this is an image, maybe we can derive a thumbnail for it? if (Files::is_image($file_name)) { include_once $context['path_to_root'] . 'images/image.php'; Image::shrink($context['path_to_root'] . $file_path . $file_name, $context['path_to_root'] . $file_path . 'thumbs/' . $file_name); if (file_exists($context['path_to_root'] . $file_path . 'thumbs/' . $file_name)) { $fields['thumbnail_url'] = $context['url_to_home'] . $context['url_to_root'] . $file_path . 'thumbs/' . rawurlencode($file_name); } } // change active_set if (isset($_REQUEST['active_set'])) { $fields['active_set'] = $_REQUEST['active_set']; } // change source if (isset($_REQUEST['source'])) { $fields['source'] = $_REQUEST['source']; } // change keywords if (isset($_REQUEST['keywords'])) { $fields['keywords'] = $_REQUEST['keywords']; } // change alternate_href if (isset($_REQUEST['alternate_href'])) { $fields['alternate_href'] = $_REQUEST['alternate_href']; } // overlay, if any 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 $fields['overlay'] = $overlay->save(); $fields['overlay_id'] = $overlay->get_id(); } // create the record in the database if (!($fields['id'] = Files::post($fields))) { return FALSE; } // record surfer activity Activities::post('file:' . $fields['id'], 'upload'); } } // so far so good if (count($context['uploaded_files']) == 1) { return $context['uploaded_files'][0]; } else { return $context['uploaded_files']; } } } // some error has occured return FALSE; }
/** * list articles as topics in a forum * * @param resource the SQL result * @return string the rendered text **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // page size for comments include_once $context['path_to_root'] . 'comments/layout_comments_as_updates.php'; $layout = new Layout_comments_as_updates(); // build a list of articles $rows = array(); include_once $context['path_to_root'] . 'comments/comments.php'; while ($item = SQL::fetch($result)) { // get the related overlay $overlay = Overlay::load($item, 'article:' . $item['id']); // get the anchor $anchor = Anchors::get($item['anchor']); // the url to view this item $url = Articles::get_permalink($item); // build a title if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // reset everything $text = $prefix = $label = $suffix = $icon = ''; // signal articles to be published if (!isset($item['publish_date']) || $item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $prefix .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // flag expired articles, and articles updated recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $suffix = EXPIRED_FLAG . ' '; } elseif ($item['create_date'] >= $context['fresh']) { $suffix = NEW_FLAG . ' '; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix = UPDATED_FLAG . ' '; } // rating if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) { $suffix .= ' ' . Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic'); } // select an icon for this thread $item['comments_count'] = Comments::count_for_anchor('article:' . $item['id']); if (is_object($overlay) && $overlay->attributes['overlay_type'] == 'poll') { Skin::define_img('POLL_IMG', 'articles/poll.gif'); $icon = POLL_IMG; } elseif ($item['rank'] < 10000) { Skin::define_img('STICKY_THREAD_IMG', 'articles/sticky_thread.gif'); $icon = STICKY_THREAD_IMG; } elseif (isset($item['comments_count']) && $item['comments_count'] >= 20) { Skin::define_img('VERY_HOT_THREAD_IMG', 'articles/very_hot_thread.gif'); $icon = VERY_HOT_THREAD_IMG; } elseif (isset($item['comments_count']) && $item['comments_count'] >= 10) { $icon = HOT_THREAD_IMG; } else { $icon = THREAD_IMG; } // indicate the id in the hovering popup $hover = i18n::s('View the page'); if (Surfer::is_member()) { $hover .= ' [article=' . $item['id'] . ']'; } // use the title as a link to the page $title = $prefix . Skin::build_link($url, ucfirst($title), 'basic', $hover) . $suffix; $suffix = ''; // the introductory text $introduction = ''; if (is_object($overlay)) { $introduction = $overlay->get_text('introduction', $item); } elseif ($item['introduction']) { $introduction = $item['introduction']; } if ($introduction) { $suffix .= BR . Codes::beautify_introduction($introduction); } // insert overlay data, if any if (is_object($overlay)) { $suffix .= $overlay->get_text('list', $item); } // shortcuts to comments pages if (isset($item['comments_count']) && ($pages = (int) ceil($item['comments_count'] / $layout->items_per_page())) && $pages > 1) { $suffix .= '<p class="details">Pages '; for ($index = 1; $index <= $pages; $index++) { $suffix .= Skin::build_link('comments/list.php?id=article:' . $item['id'] . '&page=' . $index, $index, 'basic', i18n::s('One page of comments')) . ' '; } $suffix .= Skin::build_link('comments/list.php?id=article:' . $item['id'] . '&page=' . $pages, MORE_IMG, 'basic', i18n::s('Most recent comments')) . '</p>'; } // links to sections and categories $anchors = array(); // the main anchor link if (is_object($anchor) && (!isset($this->focus) || $item['anchor'] != $this->focus)) { $anchors[] = Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()), 'basic', i18n::s('In this section')); } // list categories by title, if any if ($members =& Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 7, 'raw')) { foreach ($members as $category_id => $attributes) { // add background color to distinguish this category against others if (isset($attributes['background_color']) && $attributes['background_color']) { $attributes['title'] = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $attributes['title'] . '</span>'; } if (!isset($this->focus) || $this->focus != 'category:' . $category_id) { $anchors[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic', i18n::s('Related topics')); } } } // list section and categories in the suffix if (@count($anchors)) { $suffix .= '<p class="tags">' . implode(' ', $anchors) . '</p>'; } // the creator of this article $starter = ''; if ($item['create_name']) { $starter = '<span class="details">' . Users::get_link($item['create_name'], $item['create_address'], $item['create_id']) . '</span>'; } // the last editor $details = ''; if ($item['edit_date']) { // find a name, if any $user = ''; if ($item['edit_name']) { // label the action if (isset($item['edit_action'])) { $user .= Anchors::get_action_label($item['edit_action']) . ' '; } // name of last editor $user .= sprintf(i18n::s('by %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id'])); } $details .= $user . ' ' . Skin::build_date($item['edit_date']); } // signal locked articles if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) { $details .= ', ' . LOCKED_FLAG; } // poster details if ($details) { $details = '<p class="details">' . $details . "</p>\n"; } if (!isset($item['comments_count'])) { $item['comments_count'] = 0; } // this is another row of the output $cells = array($title . $suffix, 'center=' . $starter, 'center=' . $item['comments_count'], 'center=' . Skin::build_number($item['hits']), $details); if (THREAD_IMG) { $cells = array_merge(array($icon), $cells); } $rows[] = $cells; } // end of processing SQL::free($result); // headers $headers = array(i18n::s('Topic'), 'center=' . i18n::s('Poster'), 'center=' . i18n::s('Replies'), 'center=' . i18n::s('Views'), i18n::s('Last post')); if (THREAD_IMG) { $headers = array_merge(array(''), $headers); } // make a sortable table $output = Skin::table($headers, $rows, 'yabb'); return $output; }
/** * list most popular referrals * * @param int the offset from the start of the list; usually, 0 or 1 * @param int the number of items to display */ public static function list_by_hits($offset = 0, $count = 10) { global $context; // the list of referrals $query = "SELECT referer, sum(hits) as hits FROM " . SQL::table_name('referrals') . " GROUP BY referer" . " ORDER BY hits DESC LIMIT " . $offset . ', ' . $count; if ($result = SQL::query($query, $context['connection'])) { while ($row = SQL::fetch($result)) { $url = $row['referer']; $items[$url] = Skin::build_number($row['hits']); } } return $items; }
$details[] = sprintf(i18n::s('posted by %s %s'), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id']), Skin::build_date($item['edit_date'])); } // file size if (isset($item['image_size'])) { $details[] = Skin::build_number($item['image_size'], i18n::s('bytes')); } if (count($details)) { $input .= ucfirst(implode(BR, $details)) . BR . BR; } } // the upload entry requires rights to upload if (Surfer::may_upload()) { if (isset($item['id'])) { $input .= i18n::s('Select another image to replace the current one') . BR; } $input .= '<input type="file" name="upload" id="upload" size="30" accesskey="i" title="' . encode_field(i18n::s('Press to select a local file')) . '" />' . ' (< ' . Skin::build_number($image_maximum_size, i18n::s('bytes')) . ')'; // we are updating a user profile if (is_object($anchor) && preg_match('/^user:/i', $anchor->get_reference())) { $hint = i18n::s('Select a picture to illustrate this user profile.'); } elseif ($action == 'avatar') { $hint = i18n::s('Select a picture to illustrate this user profile.'); } elseif ($action == 'thumbnail') { $hint = i18n::s('Select a thumbnail picture for this page.'); } elseif (is_object($anchor)) { $hint = i18n::s('Select a .png, .gif or .jpeg image, or a .zip file containing several images.'); } } $fields[] = array($label, $input, $hint); // not just a bare upload if ($action != 'avatar' && $action != 'icon' && $action != 'thumbnail') { // the title
/** * 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; }
$cache_id = 'categories/index.php#text#' . $page; if (!($text = Cache::get($cache_id))) { // do it the Yahoo! style $layout = Layouts::new_('yahoo', 'category'); // the list of active categories $offset = ($page - 1) * CATEGORIES_PER_PAGE; if (!($text = Categories::list_by_title_for_anchor(NULL, $offset, CATEGORIES_PER_PAGE, $layout))) { $text = '<p>' . i18n::s('No category has been created yet.') . '</p>'; } // we have an array to format if (is_array($text)) { $text =& Skin::build_list($text, '2-columns'); } // navigation commands for categories, if necessary if ($stats['count'] > CATEGORIES_PER_PAGE) { $menu = array('_count' => Skin::build_number($stats['count'], i18n::s('categories'))); $home = 'categories/'; if ($context['with_friendly_urls'] == 'Y') { $prefix = $home . 'index.php/'; } elseif ($context['with_friendly_urls'] == 'R') { $prefix = $home; } else { $prefix = $home . '?page='; } $menu = array_merge($menu, Skin::navigate($home, $prefix, $stats['count'], CATEGORIES_PER_PAGE, $page)); // add a menu at the bottom $text .= Skin::build_list($menu, 'menu_bar'); } // make a box if ($text) { $text =& Skin::build_box('', $text, 'header1', 'categories');
/** * list articles * * Accept following variants: * - 'hits', compact plus the number of hits * - 'no_author', for articles in the user page * - 'category:xxx', if the list is displayed at categories/view.php * - 'section:xxx', if the list is displayed at sections/view.php * * @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 = 'decorated'; } // process all items in the list include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; while ($item = SQL::fetch($result)) { // get the related overlay, if any $overlay = Overlay::load($item, 'article:' . $item['id']); // get the main anchor $anchor = Anchors::get($item['anchor']); // the url to view this item $url = Articles::get_permalink($item); // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // initialize variables $prefix = $suffix = $icon = ''; // flag sticky pages if ($item['rank'] < 10000) { $prefix .= STICKY_FLAG; } // signal locked articles if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) { $suffix .= ' ' . LOCKED_FLAG; } // flag articles that are dead, or created or updated very recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } elseif ($item['create_date'] >= $context['fresh']) { $suffix .= ' ' . NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= ' ' . UPDATED_FLAG; } // signal articles to be published if ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $prefix .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // the compact version if ($this->layout_variant == 'compact') { $items[$url] = array($prefix, Skin::strip($title, 30), $suffix, 'basic', NULL); continue; } // with hits if ($this->layout_variant == 'hits') { if ($item['hits'] > 1) { $suffix = ' <span class="details">- ' . Skin::build_number($item['hits'], i18n::s('hits')) . '</span>'; } $items[$url] = array($prefix, Skin::strip($title, 30), $suffix, 'basic', NULL); continue; } // introduction $introduction = ''; if (is_object($overlay)) { $introduction = $overlay->get_text('introduction', $item); } else { $introduction = $item['introduction']; } // the introductory text if ($introduction) { $suffix .= ' - ' . Codes::beautify_introduction($introduction); // link to description, if any if ($item['description']) { $suffix .= ' ' . Skin::build_link($url, MORE_IMG, 'more', i18n::s('View the page')) . ' '; } } // insert overlay data, if any if (is_object($overlay)) { $suffix .= $overlay->get_text('list', $item); } // next line, except if we already are at the beginning of a line if ($suffix && !preg_match('/<br\\s*\\/>$/', rtrim($suffix))) { $suffix .= BR; } // append details to the suffix $suffix .= '<span class="details">'; // details $details = array(); // display details only at the main index page, and also at anchor pages if (isset($this->focus) && $item['anchor'] != $this->focus) { // the author if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') { if ($item['create_name'] != $item['edit_name']) { $details[] = sprintf(i18n::s('by %s, %s'), $item['create_name'], $item['edit_name']); } else { $details[] = sprintf(i18n::s('by %s'), $item['create_name']); } } // the last action $details[] = Anchors::get_action_label($item['edit_action']) . ' ' . Skin::build_date($item['edit_date']); // the number of hits if (Surfer::is_logged() && $item['hits'] > 1) { $details[] = Skin::build_number($item['hits'], i18n::s('hits')); } // info on related files if ($count = Files::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count); } // info on related links if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count); } // info on related comments if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count); } // rating if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) { $details[] = Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic'); } // unusual ranks are signaled to associates and owners if ($item['rank'] != 10000 && Articles::is_owned($item, $anchor)) { $details[] = '{' . $item['rank'] . '}'; } } // at the user page if ($this->layout_variant == 'no_author' && Surfer::get_id()) { if (Members::check('article:' . $item['id'], 'user:'******'Stop notifications'); } else { $label = i18n::s('Watch this page'); } $menu = array('users/track.php?anchor=' . urlencode('article:' . $item['id']) => $label); $details[] = Skin::build_list($menu, 'menu'); } // the main anchor link if (is_object($anchor) && (!isset($this->focus) || $item['anchor'] != $this->focus)) { $details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()), 'section')); } // combine in-line details if (count($details)) { $suffix .= ucfirst(trim(implode(', ', $details))); } // end of details $suffix .= '</span>'; // display all tags if ($item['tags']) { $suffix .= ' <span class="tags">' . Skin::build_tags($item['tags'], 'article:' . $item['id']) . '</span>'; } // strip empty details $suffix = str_replace(BR . '<span class="details"></span>', '', $suffix); $suffix = str_replace('<span class="details"></span>', '', $suffix); // insert a suffix separator if (trim($suffix)) { $suffix = ' ' . $suffix; } // the icon to put in the left column if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } elseif (is_callable(array($anchor, 'get_bullet_url'))) { $icon = $anchor->get_bullet_url(); } // list all components for this item $items[$url] = array($prefix, $title, $suffix, 'article', $icon); } // end of processing SQL::free($result); return $items; }
// set the focus Page::insert_script('$("#confirmed").focus();'); // the title of the link if ($item['title']) { $context['text'] .= Skin::build_block($item['title'], 'title'); } else { $context['text'] .= Skin::build_block($item['link_url'], 'title'); } // the link url, if it has not already been used as title if ($item['title']) { $context['text'] .= '<p>' . $item['link_url'] . "</p>\n"; } // display the full text $context['text'] .= '<div style="margin: 1em 0;">' . Codes::beautify($item['description']) . '</div>' . "\n"; // details $details = array(); // information on uploader if (Surfer::is_member() && $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'])); } // hits if ($item['hits'] > 1) { $details[] = Skin::build_number($item['hits'], i18n::s('clicks')); } // all details if ($details) { $context['text'] .= '<p class="details">' . ucfirst(implode(', ', $details)) . "</p>\n"; } } // render the skin render_skin();
// .JS_SUFFIX."\n"; // } // // link to download the file // // download description $description = ''; // the list of people who have fetched this file, for owners and associates if (Files::allow_modification($item, $anchor) && ($users = Activities::list_users_at('file:' . $item['id'], 'fetch', 30, 'comma'))) { $count = Activities::count_users_at('file:' . $item['id'], 'fetch'); if ($count > 30) { $more = ' ...'; } else { $more = ''; } $description .= '<p>' . Skin::build_number($item['hits'], i18n::ns('download', 'downloads', $item['hits'])) . sprintf(i18n::ns(', including %d authenticated person: %s', ', including %d authenticated persons: %s', $count), $count, $users) . "</p>\n"; } // add some help depending on the file type $extension = strtolower(@array_pop(@explode('.', @basename($item['file_name'])))); switch ($extension) { case '3gp': // video/3gpp $description .= '<p>' . sprintf(i18n::s('You are about to download a small video. To take the most of it we recommend you to use %s (open source).'), Skin::build_link(i18n::s('http://www.videolan.org/vlc/'), i18n::s('VLC media player'), 'external')) . '</p>'; break; case 'ai': case 'eps': case 'ps': $description .= '<p>' . sprintf(i18n::s('You are about to download a Postscript file. %s is a popular rendering platform (free for non-commercial use).'), Skin::build_link(i18n::s('http://www.cs.wisc.edu/~ghost/'), i18n::s('Ghostscript, Ghostview and GSview'), 'external')) . '</p>'; break; case 'ace': case 'arj':
/** * list links * * Recognize following variants: * - 'no_anchor' to list items attached to one particular anchor * - 'no_author' to list items attached to one user prolink * * @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 = 'no_anchor'; } // 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 = ''; // make a label $label = Links::clean($item['title'], $item['link_url']); // flag links uploaded recently if ($item['edit_date'] >= $context['fresh']) { $prefix = NEW_FLAG . $prefix; } // the number of clicks if ($item['hits'] > 1) { $suffix .= ' (' . Skin::build_number($item['hits'], i18n::s('clicks')) . ') '; } // add a separator if ($suffix) { $suffix = ' - ' . $suffix; } // details $details = array(); // item poster if ($item['edit_name'] && $this->layout_variant != 'no_author') { if (Surfer::is_member() || (!isset($context['content_without_details']) || $context['content_without_details'] != 'Y') || is_object($anchor) && $anchor->has_option('with_details')) { $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'])); } } // show an anchor link if ($this->layout_variant != 'no_anchor' && $this->layout_variant != 'no_author' && $item['anchor'] && ($anchor = Anchors::get($item['anchor']))) { $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')); } // the menu bar for associates and poster if (Surfer::is_empowered() || Surfer::is($item['edit_id'])) { $details[] = Skin::build_link('links/edit.php?id=' . $item['id'], i18n::s('edit'), 'span'); $details[] = Skin::build_link('links/delete.php?id=' . $item['id'], i18n::s('delete'), 'span'); } // append details to the suffix if (count($details)) { $suffix .= BR . Skin::finalize_list($details, 'menu'); } // description if ($item['description']) { $suffix .= BR . Codes::beautify($item['description']); } // build the actual link to check it if ($this->layout_variant == 'review') { $icon = $item['link_url']; } // url is the link itself -- hack for xhtml compliance $url = str_replace('&', '&', $item['link_url']); // let the rendering engine guess the type of link $link_type = NULL; // except if we want to stay within this window if (isset($item['link_target']) && $item['link_target'] != 'I') { $link_type = 'external'; } // hovering title $link_title = NULL; if (isset($item['link_title']) && $item['link_title']) { $link_title = $item['link_title']; } // pack everything $items[$url] = array($prefix, $label, $suffix, $link_type, $icon, $link_title); } // end of processing SQL::free($result); return $items; }
if (Surfer::may_upload()) { // an upload entry $input = '<input type="hidden" name="file_type" value="upload" />' . '<input type="file" name="upload" id="upload" size="30" />' . ' (< ' . $context['file_maximum_size'] . i18n::s('bytes') . ')' . "\n"; } // update an existing entry } elseif (!isset($item['file_href']) || !$item['file_href']) { $details = array(); // file name $name = str_replace('_', ' ', $item['file_name']); // downloads and file size $other_details = array(); if (isset($item['hits']) && $item['hits'] > 1) { $other_details[] = Skin::build_number($item['hits'], i18n::s('downloads')); } if (isset($item['file_size']) && $item['file_size'] > 1) { $other_details[] = Skin::build_number($item['file_size'], i18n::s('bytes')); } if (count($other_details)) { $name .= ' (' . join(', ', $other_details) . ')'; } // the file itself $details[] = $name; // file uploader if (isset($item['create_name'])) { $details[] = sprintf(i18n::s('posted by %s %s'), Users::get_link($item['create_name'], $item['create_address'], $item['create_id']), Skin::build_date($item['create_date'])); } if (count($details)) { $input .= ucfirst(implode(BR, $details)) . BR . BR; } // the upload entry requires rights to upload if (Surfer::may_upload()) {
/** * list articles 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 include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; while ($item = SQL::fetch($result)) { // one box at a time $box = ''; // get the related overlay, if any $overlay = Overlay::load($item, 'article:' . $item['id']); // get the main anchor $anchor = Anchors::get($item['anchor']); // the url to view this item $url = Articles::get_permalink($item); // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // initialize variables $prefix = $suffix = $icon = ''; // flag sticky pages if ($item['rank'] < 10000) { $prefix .= STICKY_FLAG; } // signal locked articles if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) { $suffix .= ' ' . LOCKED_FLAG; } // flag articles that are dead, or created or updated very recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } elseif ($item['create_date'] >= $context['fresh']) { $suffix .= ' ' . NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= ' ' . UPDATED_FLAG; } // signal articles to be published if ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $prefix .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // introduction $introduction = ''; if (is_object($overlay)) { $introduction = $overlay->get_text('introduction', $item); } else { $introduction = $item['introduction']; } // the introductory text if ($introduction) { $suffix .= ' - ' . Codes::beautify_introduction($introduction); // link to description, if any if ($item['description']) { $suffix .= ' ' . Skin::build_link($url, MORE_IMG, 'more', i18n::s('View the page')) . ' '; } } // insert overlay data, if any if (is_object($overlay)) { $suffix .= $overlay->get_text('list', $item); } // details $details = array(); // the author if ($item['create_name'] != $item['edit_name']) { $details[] = sprintf(i18n::s('by %s, %s'), Users::get_link($item['create_name'], $item['create_address'], $item['create_id']), Users::get_link($item['edit_name'], $item['edit_address'], $item['edit_id'])); } else { $details[] = sprintf(i18n::s('by %s'), Users::get_link($item['create_name'], $item['create_address'], $item['create_id'])); } // the last action $details[] = Anchors::get_action_label($item['edit_action']) . ' ' . Skin::build_date($item['edit_date']); // the number of hits if (Surfer::is_logged() && $item['hits'] > 1) { $details[] = Skin::build_number($item['hits'], i18n::s('hits')); } // info on related files if ($count = Files::count_for_anchor('article:' . $item['id'])) { $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count); } // info on related links if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count); } // info on related comments if ($count = Comments::count_for_anchor('article:' . $item['id'])) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count); } // rating if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) { $details[] = Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic'); } // the main anchor link if (is_object($anchor)) { $details[] = sprintf(i18n::s('in %s'), Skin::build_link($anchor->get_url(), ucfirst($anchor->get_title()), 'section')); } // display all tags if ($item['tags']) { $details[] = '<span class="tags">' . Skin::build_tags($item['tags'], 'article:' . $item['id']) . '</span>'; } // combine in-line details if (count($details)) { $suffix .= '<p class="details">' . Skin::finalize_list($details, 'menu') . '</p>'; } // insert a suffix separator if (trim($suffix)) { $suffix = ' ' . $suffix; } // item summary $box .= $prefix . Skin::build_link($url, $title, 'article') . $suffix; // the icon to put in the left column if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } elseif (is_callable(array($anchor, 'get_bullet_url'))) { $icon = $anchor->get_bullet_url(); } // build the complete HTML element if ($icon) { $icon = '<img src="' . $icon . '" alt="" title="' . encode_field(strip_tags($title)) . '" />'; // make it a clickable link $icon = Skin::build_link($url, $icon, 'basic'); // default icon } else { $icon = DECORATED_IMG; } // layout this item $list = array(array($box, $icon)); $items[] = array($item['score'], Skin::finalize_list($list, 'decorated')); } // end of processing SQL::free($result); return $items; }
$label = Skin::build_link(Articles::get_url($item['id'], 'publish'), i18n::s('not published')); } else { $label = i18n::s('not published'); } $details[] = DRAFT_FLAG . ' ' . $label; } // the number of hits if ($item['hits'] > 1 && ($cur_article->is_owned() || (!isset($context['content_without_details']) || $context['content_without_details'] != 'Y' || $cur_article->has_option('with_details')))) { // flag popular pages $popular = ''; if ($item['hits'] > 100) { $popular = POPULAR_FLAG; } // show the number if ($cur_article->is_owned() || $item['hits'] < 100) { $details[] = $popular . Skin::build_number($item['hits'], i18n::s('hits')); } elseif ($popular) { $details[] = $popular; } } // rank for this article if (intval($item['rank']) != 10000 && $cur_article->is_owned()) { $details[] = '{' . $item['rank'] . '}'; } // locked article if (Surfer::is_member() && isset($item['locked']) && $item['locked'] == 'Y') { $details[] = LOCKED_FLAG . ' ' . i18n::s('page is locked.'); } // in-line details if (count($details)) { $text .= ucfirst(implode(', ', $details));
// load the layout to use $layout = Layouts::new_('yahoo', 'section'); $layout->set_variant(20); // show more elements at the site map // the list of active sections $offset = ($page - 1) * $items_per_page; if (!($items =& Sections::list_by_title_for_anchor(NULL, $offset, $items_per_page, $layout))) { $items = '<p>' . i18n::s('No regular section has been created yet.') . '</p>'; } // we have an array to format if (is_array($items)) { $items =& Skin::build_list($items, '2-columns'); } // navigation commands for sections, if necessary if ($count > 20) { $menu = array('_count' => Skin::build_number($count, i18n::s('sections'))); $home = 'sections/'; if ($context['with_friendly_urls'] == 'Y') { $prefix = $home . 'index.php/'; } elseif ($context['with_friendly_urls'] == 'R') { $prefix = $home; } else { $prefix = $home . '?page='; } $menu = array_merge($menu, Skin::navigate($home, $prefix, $count, $items_per_page, $page)); // add a menu at the bottom $text .= Skin::build_list($menu, 'menu_bar'); } // make a box if ($items) { $text .= Skin::build_box('', $items, 'header1', 'sections');
/** * list articles * * @param resource the SQL result * @return string the rendered text * * @see layouts/layout.php **/ function layout($result) { global $context; // we return some text $text = ''; // empty list if (!SQL::count($result)) { return $text; } // build a list of articles $item_count = 0; $items = array(); include_once $context['path_to_root'] . 'articles/article.php'; include_once $context['path_to_root'] . 'comments/comments.php'; include_once $context['path_to_root'] . 'links/links.php'; while ($item = SQL::fetch($result)) { // next item $item_count += 1; // get the related overlay, if any $overlay = Overlay::load($item, 'article:' . $item['id']); // get the anchor $anchor = Anchors::get($item['anchor']); // the url to view this item $url = Articles::get_permalink($item); // one box per article $prefix = $suffix = $icon = ''; // build a box around two first articles if ($item_count == 1) { $text .= '<div class="recent">' . "\n"; } elseif ($item_count == 3) { $text .= '</div><br style="clear: left;" />' . "\n"; } // layout newest articles if ($item_count < 3) { // style to apply switch ($item_count) { case 1: $text .= '<div class="left">'; break; case 2: $text .= '<div class="right">'; break; } // the icon to put aside if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } elseif (is_object($anchor)) { $icon = $anchor->get_thumbnail_url(); } if ($icon) { $text .= '<a href="' . $context['url_to_root'] . $url . '" title="' . i18n::s('View the page') . '"><img src="' . $icon . '" class="left_image" alt="" /></a>'; } $text .= $this->layout_newest($item, $anchor) . '</div>' . "\n"; // layout recent articles } else { // use the title to label the link if (is_object($overlay)) { $title = Codes::beautify_title($overlay->get_text('title', $item)); } else { $title = Codes::beautify_title($item['title']); } // flag sticky pages if ($item['rank'] < 10000) { $prefix .= STICKY_FLAG; } // signal locked articles if (isset($item['locked']) && $item['locked'] == 'Y' && Articles::is_owned($item, $anchor)) { $suffix .= ' ' . LOCKED_FLAG; } // flag articles that are dead, or created or updated very recently if ($item['expiry_date'] > NULL_DATE && $item['expiry_date'] <= $context['now']) { $prefix .= EXPIRED_FLAG; } elseif ($item['create_date'] >= $context['fresh']) { $suffix .= ' ' . NEW_FLAG; } elseif ($item['edit_date'] >= $context['fresh']) { $suffix .= ' ' . UPDATED_FLAG; } // signal articles to be published if ($item['publish_date'] <= NULL_DATE || $item['publish_date'] > gmstrftime('%Y-%m-%d %H:%M:%S')) { $prefix .= DRAFT_FLAG; } // signal restricted and private articles if ($item['active'] == 'N') { $prefix .= PRIVATE_FLAG; } elseif ($item['active'] == 'R') { $prefix .= RESTRICTED_FLAG; } // the introductory text $introduction = ''; if (is_object($overlay)) { $introduction .= Codes::beautify_introduction($overlay->get_text('introduction', $item)); } elseif ($item['introduction']) { $introduction .= Codes::beautify_introduction($item['introduction']); } else { $introduction .= Skin::cap(Codes::beautify($item['description'], $item['options']), 70); } if ($introduction) { $suffix .= ' - ' . $introduction; // link to description, if any if ($item['description']) { $suffix .= ' ' . Skin::build_link($url, MORE_IMG, 'more', i18n::s('View the page')) . ' '; } } // insert overlay data, if any if (is_object($overlay)) { $suffix .= $overlay->get_text('list', $item); } // next line, except if we already are at the beginning of a line if ($suffix && !preg_match('/<br\\s*\\/>$/', rtrim($suffix))) { $suffix .= BR; } // append details to the suffix $suffix .= '<span class="details">'; // details $details = array(); // the author if (isset($context['with_author_information']) && $context['with_author_information'] == 'Y') { if ($item['create_name'] != $item['edit_name']) { $details[] = sprintf(i18n::s('by %s, %s'), $item['create_name'], $item['edit_name']); } else { $details[] = sprintf(i18n::s('by %s'), $item['create_name']); } } // the last action $details[] = Anchors::get_action_label($item['edit_action']) . ' ' . Skin::build_date($item['edit_date']); // the number of hits if (Surfer::is_logged() && $item['hits'] > 1) { $details[] = Skin::build_number($item['hits'], i18n::s('hits')); } // info on related files if ($count = Files::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d file', '%d files', $count), $count); } // info on related links if ($count = Links::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d link', '%d links', $count), $count); } // info on related comments if ($count = Comments::count_for_anchor('article:' . $item['id'], TRUE)) { $details[] = sprintf(i18n::ns('%d comment', '%d comments', $count), $count); } // rating if ($item['rating_count'] && !(is_object($anchor) && $anchor->has_option('without_rating'))) { $details[] = Skin::build_link(Articles::get_url($item['id'], 'like'), Skin::build_rating_img((int) round($item['rating_sum'] / $item['rating_count'])), 'basic'); } // combine in-line details if (count($details)) { $suffix .= ucfirst(trim(implode(', ', $details))); } // unusual ranks are signaled to associates if ($item['rank'] != 10000 && Articles::is_owned($item, $anchor)) { $suffix .= ' {' . $item['rank'] . '} '; } // list categories by title, if any $anchors = array(); if ($members =& Members::list_categories_by_title_for_member('article:' . $item['id'], 0, 5, 'raw')) { foreach ($members as $id => $attributes) { // add background color to distinguish this category against others if (isset($attributes['background_color']) && $attributes['background_color']) { $attributes['title'] = '<span style="background-color: ' . $attributes['background_color'] . '; padding: 0 3px 0 3px;">' . $attributes['title'] . '</span>'; } if ($this->focus != 'category:' . $id) { $anchors[] = Skin::build_link(Categories::get_permalink($attributes), $attributes['title'], 'basic'); } } } // list section and categories in the suffix if (@count($anchors)) { $suffix .= BR . sprintf(i18n::s('In %s'), implode(', ', $anchors)); } // end of details $suffix .= '</span>'; // strip empty details $suffix = str_replace(BR . '<span class="details"></span>', '', $suffix); $suffix = str_replace('<span class="details"></span>', '', $suffix); // the icon to put in the left column if ($item['thumbnail_url']) { $icon = $item['thumbnail_url']; } elseif (is_callable(array($anchor, 'get_bullet_url'))) { $icon = $anchor->get_bullet_url(); } // list all components for this item $items[$url] = array($prefix, $title, $suffix, 'article', $icon); } } // extend the #home_south in case of floats if ($item_count > 1 && $item_count < 3) { $text .= '<p style="clear: left;"> </p></div>' . "\n"; } // turn the list to a string if (count($items)) { $text .= Skin::build_list($items, 'decorated'); } // end of processing SQL::free($result); return $text; }