/** * 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; }
$compact_list = Skin::build_list(Files::list_for_anchor_and_name($anchor->get_reference(), $uploaded, 'compact'), 'compact'); $context['text'] .= '<p>' . i18n::s('Following files have been added:') . '</p>' . $compact_list; // log multiple upload $label = sprintf(i18n::c('New files in %s'), strip_tags($anchor->get_title())); Logger::notify('files/edit.php: ' . $label, $compact_list); // push the list of uploaded files to the notification $attributes = array(); $attributes['message'] = '<p>' . i18n::s('Following files have been added:') . '</p>' . $compact_list; $attributes['anchor'] = $anchor->get_reference(); // notification to send by e-mail $mail = array(); $mail['subject'] = sprintf(i18n::c('%s: %s'), i18n::c('Contribution'), strip_tags($anchor->get_title())); $mail['notification'] = Files::build_notification('multiple', $attributes); // one file has been added } elseif ($item =& Files::get_by_anchor_and_name($anchor->get_reference(), $uploaded)) { $context['text'] .= '<p>' . i18n::s('Following file has been added:') . '</p>' . Codes::render_object('file', $item['id']); // use this file record $_REQUEST['id'] = $item['id']; // log single upload $label = sprintf(i18n::c('New file in %s'), strip_tags($anchor->get_title())); $link = Files::get_permalink($item); $description = sprintf(i18n::c('%s at %s'), $item['file_name'], '<a href="' . $link . '">' . $link . '</a>'); Logger::notify('files/edit.php: ' . $label, $description); // notification to send by e-mail $mail = array(); $mail['subject'] = sprintf(i18n::c('%s: %s'), i18n::c('Contribution'), strip_tags($anchor->get_title())); $mail['notification'] = Files::build_notification('upload', $item); } // send to anchor watchers if (isset($_REQUEST['notify_watchers']) && $_REQUEST['notify_watchers'] == 'Y') { $anchor->alert_watchers($mail, $action, isset($_REQUEST['active']) && $_REQUEST['active'] == 'N');
} elseif (isset($context['users_with_auto_publish']) && $context['users_with_auto_publish'] == 'Y' || is_object($anchor) && $anchor->has_option('auto_publish')) { $context['text'] .= i18n::s('<p>Don\'t forget to publish the new page someday. Review the page, enhance it and then click on the Publish command to make it publicly available.</p>'); } else { $context['text'] .= i18n::s('<p>The new page will now be reviewed before its publication. It is likely that this will be done within the next 24 hours at the latest.</p>'); } if (!isset($_REQUEST['first_comment'])) { $_REQUEST['first_comment'] = ''; } // attach some file $file_path = Files::get_path('article:' . $_REQUEST['id']); if (isset($_FILES['upload']) && ($uploaded = Files::upload($_FILES['upload'], $file_path, 'article:' . $_REQUEST['id']))) { // several files have been added if (is_array($uploaded)) { $_REQUEST['first_comment'] .= '<div>' . Skin::build_list(Files::list_for_anchor_and_name('article:' . $_REQUEST['id'], $uploaded, 'compact'), 'compact') . '</div>'; } elseif ($file =& Files::get_by_anchor_and_name('article:' . $_REQUEST['id'], $uploaded)) { $_REQUEST['first_comment'] .= '<div>' . Codes::render_object('file', $file['id']) . '</div>'; // silently delete the previous file if the name has changed if (isset($file['file_name']) && $file['file_name'] != $uploaded) { Safe::unlink($file_path . '/' . $file['file_name']); } } } // capture first comment too if (isset($_REQUEST['first_comment']) && $_REQUEST['first_comment']) { include_once $context['path_to_root'] . 'comments/comments.php'; $fields = array(); $fields['anchor'] = 'article:' . $_REQUEST['id']; $fields['description'] = $_REQUEST['first_comment']; Comments::post($fields); } // post an overlay, with the new article id --don't stop on error
/** * upload a file as a image attach to a given anchor * to be used in custom "edit_as" script * * @global string $context * @param object $anchor * @param array $file (from $_FILES) * @param bool $set_as_thumb * @param bool $put */ public static function upload_to($anchor, $file, $set_as_thumb = false, $put = false) { global $context; // attach some image $path = Files::get_path($anchor->get_reference(), 'images'); // $_REQUEST['action'] = 'set_as_icon'; // instruction for image::upload if (isset($file) && ($uploaded = Files::upload($file, $path, array('Image', 'upload')))) { // prepare image informations $image = array(); $image['image_name'] = $uploaded; $image['image_size'] = $file['size']; $image['thumbnail_name'] = 'thumbs/' . $uploaded; $image['anchor'] = $anchor->get_reference(); //$combined = array_merge($image, $_FILES); // post the image which was uploaded if ($image['id'] = Images::post($image)) { // successfull post $context['text'] .= '<p>' . i18n::s('Following image has been added:') . '</p>' . Codes::render_object('image', $image['id']) . '<br style="clear:left;" />' . "\n"; // set image as icon and thumbnail if ($set_as_thumb) { // delete former icon if any /*if(isset($anchor->item['icon_url']) && $anchor->item['icon_url'] && $match = Images::get_by_anchor_and_name($anchor->get_reference(), pathinfo($anchor->item['icon_url'],PATHINFO_BASENAME))) { if($match['id'] != $image['id']) Images::delete($match['id']); }*/ $fields = array('thumbnail_url' => Images::get_thumbnail_href($image), 'icon_url' => Images::get_icon_href($image)); if ($put) { $fields['id'] = $_REQUEST['id']; $class = $anchor->get_static_group_class(); $class::put_attributes($fields); } else { $_REQUEST = array_merge($_REQUEST, $fields); } } } } }