本文整理汇总了PHP中Surfer::may_upload方法的典型用法代码示例。如果您正苦于以下问题:PHP Surfer::may_upload方法的具体用法?PHP Surfer::may_upload怎么用?PHP Surfer::may_upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Surfer
的用法示例。
在下文中一共展示了Surfer::may_upload方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_fields
/**
* build the list of fields for this overlay
*
* @see overlays/overlay.php
*
* @param the hosting attributes
* @return a list of ($label, $input, $hint)
*/
function get_fields($host, $field_pos = NULL)
{
global $context;
$fields = array();
// the file itself
$label = i18n::s('Share');
$input = '';
// a surfer is sharing something
if (!isset($host['id'])) {
// share a link
Skin::define_img('EMBED_HREF_IMG', 'thumbnails/video.gif');
$cell1 = '<div style="text-align: center"><a href="#" onclick="$(\'#share_href\').attr(\'checked\', \'checked\').trigger(\'change\'); return false;">' . EMBED_HREF_IMG . '</a>' . BR . '<input type="radio" name="embed_type" id="share_href" value="href" checked="checked" />' . i18n::s('a web address') . '</div>';
// share a file
$cell2 = '';
if (Surfer::may_upload()) {
Skin::define_img('EMBED_UPLOAD_IMG', 'thumbnails/download.gif');
$cell2 = '<div style="text-align: center"><a href="#" onclick="$(\'#share_upload\').attr(\'checked\', \'checked\').trigger(\'change\'); return false;">' . EMBED_UPLOAD_IMG . '</a>' . BR . '<input type="radio" name="embed_type" id="share_upload" value="upload" />' . i18n::s('a file') . '</div>';
}
// share an idea
Skin::define_img('EMBED_NONE_IMG', 'thumbnails/information.gif');
$cell3 = '<div style="text-align: center"><a href="#" onclick="$(\'#share_none\').attr(\'checked\', \'checked\').trigger(\'change\'); return false;">' . EMBED_NONE_IMG . '</a>' . BR . '<input type="radio" name="embed_type" id="share_none" value="none" />' . i18n::s('some information') . '</div>';
// three controls in a row
$input = Skin::layout_horizontally($cell1, $cell2, $cell3);
// sharing a web address
$input .= '<div id="embed_a_link" style="padding: 1em 0 1em 0;">' . i18n::s('Paste the address of a web page that you have visited') . BR . '<input type="text" name="embed_href" id="embed_href" size="60" width="100%" value="" maxlength="255" />' . '<p class="details">' . sprintf(i18n::s('Some sites are recognized automatically: %s'), '<span id="provider_ticker" style="">' . '<span>YouTube</span>' . '<span>DailyMotion</span>' . '<span>Vimeo</span>' . '<span>Slideshare</span>' . '<span>Scribd</span>' . '<span>Flickr</span>' . '<span>PhotoBucket</span>' . '<span>DeviantArt</span>' . '<span>blip.tv</span>' . '<span>Viddler</span>' . '<span>revision3</span>' . '<span>5min.com</span>' . '<span>dotsub</span>' . '<span>hulu</span>' . '<span>yfrog</span>' . '<span>smugmug</span>' . '<span>soundcloud</span>' . '<span>official.fm</span>' . '<span>rd.io</span>' . '</span>') . '</p>' . '</div>';
Page::insert_script('$(function() {' . "\n" . ' var obj = $("#provider_ticker");' . "\n" . ' var list = obj.children();' . "\n" . ' list.not(":first").hide();' . "\n" . ' setInterval(function(){' . "\n" . ' list = obj.children();' . "\n" . ' list.not(":first").hide();' . "\n" . ' var first_li = list.eq(0);' . "\n" . ' var second_li = list.eq(1);' . "\n" . ' first_li.fadeOut(function(){' . "\n" . ' obj.css("height",second_li.height());' . "\n" . ' second_li.fadeIn();' . "\n" . ' first_li.remove().appendTo(obj);' . "\n" . ' });' . "\n" . ' }, 2000);' . "\n" . '});' . "\n");
// uploading a file
if (Surfer::may_upload()) {
$input .= '<div id="embed_a_file" style="display: none; padding: 1em 0 1em 0;">' . '<input type="file" name="upload" id="upload" size="30" />' . '<p class="details">' . sprintf(i18n::s('Select a file of less than %s'), $context['file_maximum_size'] . i18n::s('bytes')) . '</p>' . '</div>';
}
// change the display on selection
Page::insert_script('$(function() {' . "\n" . ' $("input[name=embed_type]").change(function() {' . "\n" . ' if($("#share_href").attr("checked")) {' . "\n" . ' $("#embed_a_link").slideDown();' . "\n" . ' $("#embed_a_file").slideUp();' . "\n" . ' }' . "\n" . ' if($("#share_upload").attr("checked")) {' . "\n" . ' $("#embed_a_link").slideUp();' . "\n" . ' $("#embed_a_file").slideDown();' . "\n" . ' }' . "\n" . ' if($("#share_none").attr("checked")) {' . "\n" . ' $("#embed_a_link").slideUp();' . "\n" . ' $("#embed_a_file").slideUp();' . "\n" . ' }' . "\n" . ' });' . "\n" . '});' . "\n");
// nothing to do
} elseif (!isset($this->attributes['embed_type'])) {
} elseif ($this->attributes['embed_type'] == 'href' && trim($this->attributes['embed_href'])) {
$input .= $this->attributes['embed_href'];
}
// a complex field
if ($input) {
$fields[] = array($label, $input);
}
return $fields;
}
示例2: while
$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";
}
// build the lists
while (($image = Safe::readdir($dir)) !== FALSE) {
// skip some files
if ($image[0] == '.') {
continue;
}
if (is_dir($context['path_to_root'] . $path . '/' . $image)) {
continue;
}
// consider only images
if (!preg_match('/(\\.gif|\\.jpeg|\\.jpg|\\.png)$/i', $image)) {
continue;
}
示例3: array
// reward the poster
$context['page_title'] = i18n::s('Congratulation, you have successfully added a new web space');
// follow-up commands
$follow_up = i18n::s('What do you want to do now?');
$menu = array();
if ($_REQUEST['space_type'] == 'blog') {
$menu = array_merge($menu, array(Sections::get_permalink($_REQUEST) => i18n::s('View the new blog')));
} elseif ($_REQUEST['space_type'] == 'project') {
$menu = array_merge($menu, array(Sections::get_permalink($_REQUEST) => i18n::s('View the new project')));
} else {
$menu = array_merge($menu, array(Sections::get_permalink($_REQUEST) => i18n::s('View the new group')));
}
if (Surfer::may_upload()) {
$menu = array_merge($menu, array('images/edit.php?anchor=' . urlencode('section:' . $_REQUEST['id']) => i18n::s('Add an image')));
}
if (preg_match('/\\bwith_files\\b/i', $section->item['options']) && Surfer::may_upload()) {
$menu = array_merge($menu, array('files/edit.php?anchor=' . urlencode('section:' . $_REQUEST['id']) => i18n::s('Add a file')));
}
if (preg_match('/\\bwith_links\\b/i', $section->item['options'])) {
$menu = array_merge($menu, array('links/edit.php?anchor=' . urlencode('section:' . $_REQUEST['id']) => i18n::s('Add a link')));
}
$follow_up .= Skin::build_list($menu, 'menu_bar');
$context['text'] .= $follow_up;
}
// display the form on GET
} else {
$with_form = TRUE;
}
// display the form
if ($with_form) {
// by default it will be a group space
示例4: upload
/**
* 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);
//.........这里部分代码省略.........
示例5: allow_creation
/**
* check if new images can be added
*
* This function returns TRUE if images can be added to some place,
* and FALSE otherwise.
*
* @param object an instance of the Anchor interface, if any
* @param array a set of item attributes, if any
* @param string the type of item, e.g., 'section'
* @return TRUE or FALSE
*/
public static function allow_creation($item = NULL, $anchor = NULL, $variant = NULL)
{
global $context;
// backward compatibility, reverse parameters :
// $anchor is always a object and $item a array
if (is_object($item) || is_array($anchor)) {
$permute = $anchor;
$anchor = $item;
$item = $permute;
}
// guess the variant
if (!$variant) {
// most frequent case
if (isset($item['id'])) {
$variant = 'article';
} elseif (is_object($anchor)) {
$variant = $anchor->get_type();
} else {
return FALSE;
}
}
// only in articles
if ($variant == 'article') {
// 'no images' option
if (Articles::has_option('no_images', $anchor, $item)) {
return FALSE;
}
// other containers
} else {
// in item
if (isset($item['options']) && is_string($item['options']) && preg_match('/\\bno_images\\b/i', $item['options'])) {
return FALSE;
}
// in container
if (is_object($anchor) && $anchor->has_option('no_images', FALSE)) {
return FALSE;
}
}
// surfer is not allowed to upload a file
if (!Surfer::may_upload()) {
return FALSE;
}
// surfer is an associate
if (Surfer::is_associate()) {
return TRUE;
}
// submissions have been disallowed
if (isset($context['users_without_submission']) && $context['users_without_submission'] == 'Y') {
return FALSE;
}
// only in articles
if ($variant == 'article') {
// surfer is entitled to change content
if (Articles::allow_modification($item, $anchor)) {
return TRUE;
}
// surfer is an editor, and the page is not private
if (isset($item['active']) && $item['active'] != 'N' && Articles::is_assigned($item['id'])) {
return TRUE;
}
if (is_object($anchor) && !$anchor->is_hidden() && $anchor->is_assigned()) {
return TRUE;
}
// only in iles
} elseif ($variant == 'file') {
// surfer owns the anchor
if (is_object($anchor) && $anchor->is_owned()) {
return TRUE;
}
// only in sections
} elseif ($variant == 'section') {
// surfer is entitled to change content
if (Sections::allow_modification($item, $anchor)) {
return TRUE;
}
// only in user profiles
} elseif ($variant == 'user') {
// the item is anchored to the profile of this member
if (Surfer::get_id() && is_object($anchor) && !strcmp($anchor->get_reference(), 'user:' . Surfer::get_id())) {
return TRUE;
}
// should not happen...
if (isset($item['id']) && Surfer::is($item['id'])) {
return TRUE;
}
}
// item has been locked
if (isset($item['locked']) && $item['locked'] == 'Y') {
return FALSE;
//.........这里部分代码省略.........
示例6: substr
}
$information .= Skin::build_block($description, 'description');
// birth date, if any, and only for authenticated surfers
if (isset($item['birth_date']) && $item['birth_date'] > NULL_DATE && Surfer::is_logged()) {
$information .= '<p>' . i18n::s('Birth date') . ' ' . substr($item['birth_date'], 0, 10) . '</p>';
}
// list files
//
$items = Files::list_by_date_for_anchor('user:' . $item['id'], 0, FILES_PER_PAGE, 'no_author');
if (is_array($items)) {
$items = Skin::build_list($items, 'decorated');
}
// local menu
$menu = array();
// the command to post a new file
if ((Surfer::is($item['id']) || Surfer::is_associate()) && Surfer::may_upload()) {
Skin::define_img('FILES_UPLOAD_IMG', 'files/upload.gif');
$menu[] = Skin::build_link('files/edit.php?anchor=user:' . $item['id'], FILES_UPLOAD_IMG . i18n::s('Add a file'), 'span');
}
if (count($menu)) {
$items = Skin::finalize_list($menu, 'menu_bar') . $items;
}
if ($items) {
$information .= Skin::build_box(i18n::s('Files'), $items);
}
}
// in a separate tab
if ($information) {
$panels[] = array('information', i18n::s('Information'), 'information_panel', $information);
}
// append tabs from the overlay, if any
示例7: outputJSON
* @author Alexis Raimbault
* @reference
* @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
*/
// common definitions and initial processing
include_once '../shared/global.php';
// ensure browser always look for fresh data
http::expire(0);
// lang
i18n::bind('files');
// stop here on scripts/validate.php
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'HEAD') {
return;
}
// stop if forbidden
if (Surfer::is_crawler() || !Surfer::may_upload()) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
die(i18n::s('You are not allowed to perform this operation.'));
}
// some input is mandatory
if (!isset($_REQUEST['name'])) {
Safe::header('Status: 400 Bad Request', TRUE, 400);
outputJSON(i18n::s('Request is invalid.'));
} else {
$name = $_REQUEST['name'];
}
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
// Output JSON
function outputJSON($msg, $status = 'error', $preview = '')
{
global $context;
示例8: sprintf
// change page title too
$context['page_title'] = sprintf(i18n::s('%s: %s'), i18n::s('Approval'), $anchor->get_title());
// else select a regular type
} else {
$input = Comments::get_radio_buttons('type', $type);
$hint = i18n::s('Please carefully select a type adequate for your comment.');
}
$fields[] = array($label, $input, $hint);
}
// the description
$label = i18n::s('Your contribution');
// use the editor if possible
$input = Surfer::get_editor('description', isset($item['description']) ? $item['description'] : '', TRUE, 3, FALSE);
$fields[] = array($label, $input);
// add a file on first post, and if allowed
if (Surfer::may_upload() && (!isset($item['id']) || $action == 'quote' || $action == 'reply')) {
// attachment label
$label = i18n::s('Add a file');
// an upload entry
$input = '<input type="hidden" name="file_type" value="upload" />' . '<input type="file" name="upload" id="upload" size="30" onchange="if(/\\.zip$/i.test($(this).val())){$(\'#upload_option\').slideDown();}else{$(\'#upload_option\').slideUp();}" />' . ' (< ' . $context['file_maximum_size'] . i18n::s('bytes') . ')' . '<div id="upload_option" style="display: none;" >' . '<input type="checkbox" name="explode_files" checked="checked" /> ' . i18n::s('Extract files from the archive') . '</div>';
$fields[] = array($label, $input);
}
// build the form
$context['text'] .= Skin::build_form($fields);
// bottom commands
$menu = array();
$menu[] = Skin::build_submit_button(i18n::s('Submit'), i18n::s('Press [s] to submit data'), 's', 'submit_button');
if (!$render_overlaid) {
// preview link
$menu[] = '<a href="#" onclick="$(\'#preview_flag\').attr(\'value\', \'Y\'); $(\'#submit_button\').click(); return false;" accesskey="p" title="' . i18n::s('Press [p] for preview') . '"><span>' . i18n::s('Preview') . '</span></a>';
}
示例9: get_thread_creation_form
/**
*
* @param int $usr id of targeted profile
* @param boolean $upload to display a field to include a file
* @return string the form to start the thread
*/
public static function get_thread_creation_form($usr, $upload = FALSE)
{
global $context, $render_overlaid;
// start a new private page
//
$text = '<form method="post" id="main_form" enctype="multipart/form-data" action="' . $context['url_to_root'] . 'users/contact.php" onsubmit="return validateDocumentPost(this)" ><div>';
// on my page, engage with anybody
if (Surfer::get_id() == $usr) {
// recipients
$label = i18n::s('Who do you want to involve?');
$input = '<textarea name="id" id="id" rows="1" cols="50"></textarea><div><span class="tiny">' . i18n::s('Enter nick names, or email addresses, separated by commas.') . '</span></div>';
$text .= '<div>' . $label . BR . $input . '</div>';
// engage the browsed surfer
} else {
$text .= '<input type="hidden" name="id" value="' . $usr . '" />';
}
// thread title
// $label = i18n::s('What do you want to talk about?');
$label = '';
$input = '<input type="text" name="title" style="width: 90%" maxlength="255" placeholder = "' . i18n::s('Subject') . '" />';
$text .= '<p>' . $label . BR . $input . '</p>';
// thread first contribution
// $label = i18n::s('Provide context, and start the conversation');
$label = '';
$input = '<textarea name="message" rows="6" cols="50" placeholder = "' . i18n::s('Your message') . '"></textarea>';
$text .= '<p>' . $label . BR . $input . '</p>';
// uploads are allowed
if (Surfer::may_upload() && $upload) {
$label = sprintf(i18n::s('You may attach a file of up to %sbytes'), $context['file_maximum_size']);
$input = '<input type="file" name="upload" style="width: 30em" />';
$text .= '<p class="details">' . $label . BR . $input . '</p>';
}
// bottom commands
if (!$render_overlaid) {
$menu = array();
$menu[] = Skin::build_submit_button(i18n::s('Send'), i18n::s('Press [s] to submit data'), 's');
$text .= Skin::finalize_list($menu, 'menu_bar');
}
// end of the form
$text .= '</div></form>';
// in a folded box
/*Skin::define_img('ARTICLES_ADD_IMG', 'articles/add.gif');
if(Surfer::get_id() == $item['id'])
$box['top'] += array('_new_thread' => Skin::build_sliding_box(ARTICLES_ADD_IMG.i18n::s('Start a thread'), $text, 'new_thread', TRUE));
else
$box['top'] += array('_new_thread' => Skin::build_sliding_box(ARTICLES_ADD_IMG.sprintf(i18n::s('Start a thread with %s'), $item['full_name']?$item['full_name']:$item['nick_name']), $text, 'new_thread', TRUE));
*/
// append the script used for data checking on the browser
Page::insert_script('func' . 'tion validateDocumentPost(container) {' . "\n" . "\n" . ' if(!container.title.value) {' . "\n" . ' alert("' . i18n::s('Please provide a meaningful title.') . '");' . "\n" . ' Yacs.stopWorking();' . "\n" . ' return false;' . "\n" . ' }' . "\n" . "\n" . ' return true;' . "\n" . '}' . "\n" . (Surfer::get_id() == $usr ? '$(function() {' . "\n" . ' Yacs.autocomplete_names("id");' . "\n" . '}); ' . "\n" : ''));
return $text;
}