removed java photo uploader from mainline. Photo uploaders are now plugins, but a single item upload is available by default.

This commit is contained in:
Friendika 2011-01-27 18:45:19 -08:00
parent ebba294189
commit 33037754d8
13 changed files with 186 additions and 101 deletions

View File

@ -1,12 +1,43 @@
<?php
/**
*
* Java photo uploader, uses Jumploader
*
* WARNING: This module currently has privacy issues.
* The java package does not pass the permissions array intact and could lead to
* photos being seen by people that were excluded from seeing them.
*
*/
function java_upload_install() {
register_hook('photo_upload_form', 'addon/java_upload/java_upload.php', 'java_upload_form');
register_hook('photo_post_init', 'addon/java_upload/java_upload.php', 'java_upload_post_init');
register_hook('photo_post_end', 'addon/java_upload/java_upload.php', 'java_upload_post_end');
}
function java_upload_uninstall() {
unregister_hook('photo_upload_form', 'addon/java_upload/java_upload.php', 'java_upload_form');
unregister_hook('photo_post_init', 'addon/java_upload/java_upload.php', 'java_upload_post_init');
unregister_hook('photo_post_end', 'addon/java_upload/java_upload.php', 'java_upload_post_end');
}
function java_upload_form(&$a,&$b) {
$uploadurl = $b['post_url'];
$sessid = session_id();
$archive = $a->get_baseurl() . '/addon/java_upload/jumploader_z.jar';
$filestext = t('Select files to upload: ');
$b .= <<< EOT;
$nojava = t('Use the following controls only if the Java uploader [above] fails to launch.');
$b['default_upload'] = true;
$b['addon_text'] .= <<< EOT
<div id="photos-upload-select-files-text">$filestext</div>

Binary file not shown.

View File

@ -105,7 +105,7 @@ function js_upload_post_init(&$a,&$b) {
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload('uploads/');
$result = $uploader->handleUpload();
// to pass data through iframe you will need to encode all html tags
@ -124,11 +124,10 @@ function js_upload_post_file(&$a,&$b) {
$result = $a->data['upload_result'];
$b['src'] = 'uploads/' . $result['filename'];
$b['src'] = $result['path'];
$b['filename'] = $result['filename'];
$b['filesize'] = filesize($b['src']);
logger('post_file' . print_r($b, true));
}
@ -147,28 +146,32 @@ logger('upload_post_end');
* Handle file uploads via XMLHttpRequest
*/
class qqUploadedFileXhr {
private $pathnm = '';
/**
* Save the file to the specified path
* Save the file in the temp dir.
* @return boolean TRUE on success
*/
function save($path) {
function save() {
$input = fopen("php://input", "r");
$temp = tmpfile();
$this->pathnm = tempnam(sys_get_temp_dir(),'frn');
$temp = fopen($this->pathnm,"w");
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);
fclose($temp);
if ($realSize != $this->getSize()){
return false;
}
$target = fopen($path, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
return true;
}
function getPath() {
return $this->pathnm;
}
function getName() {
return $_GET['qqfile'];
}
@ -187,16 +190,22 @@ class qqUploadedFileXhr {
*/
class qqUploadedFileForm {
/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
function save($path) {
if(!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)){
return false;
}
function save() {
return true;
}
function getPath() {
return $_FILES['qqfile']['tmp_name'];
}
function getName() {
return $_FILES['qqfile']['name'];
}
@ -225,6 +234,7 @@ class qqFileUploader {
} else {
$this->file = false;
}
}
private function checkServerSettings(){
@ -251,10 +261,7 @@ class qqFileUploader {
/**
* Returns array('success'=>true) or array('error'=>'error message')
*/
function handleUpload($uploadDirectory, $replaceOldFile = FALSE){
if (!is_writable($uploadDirectory)){
return array('error' => t('Server error. Upload directory isn\'t writable.'));
}
function handleUpload(){
if (!$this->file){
return array('error' => t('No files were uploaded.'));
@ -289,18 +296,18 @@ class qqFileUploader {
return array('error' => t('File has an invalid extension, it should be one of ') . $these . '.');
}
if(!$replaceOldFile){
/// don't overwrite previous files that were uploaded
while (file_exists($uploadDirectory . $filename . '.' . $ext)) {
$filename .= rand(10, 99);
}
}
if ($this->file->save($uploadDirectory . $filename . '.' . $ext)){
return array('success'=>true,'filename' => $filename . '.' . $ext);
if ($this->file->save()){
return array(
'success'=>true,
'path' => $this->file->getPath(),
'filename' => $filename . '.' . $ext
);
} else {
return array('error'=> t('Could not save uploaded file.') .
t('The upload was cancelled, or server error encountered'),'filename' => $filename . '.' . $ext);
return array(
'error'=> t('Upload was cancelled, or server error encountered'),
'path' => $this->file->getPath(),
'filename' => $filename . '.' . $ext
);
}
}

View File

@ -3,7 +3,7 @@
set_time_limit(0);
define ( 'BUILD_ID', 1033 );
define ( 'FRIENDIKA_VERSION', '2.10.0901' );
define ( 'FRIENDIKA_VERSION', '2.10.0902' );
define ( 'DFRN_PROTOCOL_VERSION', '2.0' );
define ( 'EOL', "<br />\r\n" );

View File

@ -65,3 +65,11 @@ $a->config['system']['huburl'] = 'http://pubsubhubbub.appspot.com';
$a->config['system']['rino_encrypt'] = true;
// Addons or plugins are configured here.
// This is a comma seperated list of addons to enable. Example:
// $a->config['system']['addon'] = 'js_upload,randplace,oembed';
$a->config['system']['addon'] = 'js_upload';

Binary file not shown.

View File

@ -1,5 +1,4 @@
<?php
require_once('include/Photo.php');
require_once('include/items.php');
require_once('include/acl_selectors.php');
@ -49,9 +48,18 @@ function photos_init(&$a) {
function photos_post(&$a) {
logger('mod/photos.php: photos_post(): begin' , 'LOGGER_DEBUG');
foreach($_REQUEST AS $key => $val) {
logger('mod/photos.php: photos_post(): $_REQUEST key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
}
foreach($_FILES AS $key => $val) {
logger('mod/photos.php: photos_post(): $_FILES key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
}
$can_post = false;
$visitor = 0;
@ -466,18 +474,20 @@ function photos_post(&$a) {
}
// default post action - upload a photo
/**
* default post action - upload a photo
*/
if(! x($_FILES,'userfile'))
killme();
call_hooks('photo_post_init', $_POST);
if($_POST['partitionCount'])
$java_upload = true;
else
$java_upload = false;
/**
* Determine the album to use
*/
$album = notags(trim($_POST['album']));
$newalbum = notags(trim($_POST['newalbum']));
$album = notags(trim($_REQUEST['album']));
$newalbum = notags(trim($_REQUEST['newalbum']));
logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
if(! strlen($album)) {
if(strlen($newalbum))
@ -486,6 +496,16 @@ function photos_post(&$a) {
$album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
}
/**
*
* We create a wall item for every photo, but we don't want to
* overwhelm the data stream with a hundred newly uploaded photos.
* So we will make one photo (the first one uploaded to this album)
* visible by default, the rest will become visible over time when and if
* they acquire comments, likes, dislikes, and/or tags
*
*/
$r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
dbesc($album),
intval($page_owner_uid)
@ -495,15 +515,25 @@ function photos_post(&$a) {
else
$visible = 0;
$str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
$str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
$str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
$str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
$str_group_allow = perms2str($_POST['group_allow']);
$str_contact_allow = perms2str($_POST['contact_allow']);
$str_group_deny = perms2str($_POST['group_deny']);
$str_contact_deny = perms2str($_POST['contact_deny']);
$ret = array('src' => '', 'filename' => '', 'filesize' => 0);
$src = $_FILES['userfile']['tmp_name'];
$filename = basename($_FILES['userfile']['name']);
$filesize = intval($_FILES['userfile']['size']);
call_hooks('photo_post_file',$ret);
if(x($ret,'src') && x($ret,'filesize')) {
$src = $ret['src'];
$filename = $ret['filename'];
$filesize = $ret['filesize'];
}
else {
$src = $_FILES['userfile']['tmp_name'];
$filename = basename($_FILES['userfile']['name']);
$filesize = intval($_FILES['userfile']['size']);
}
$maximagesize = get_config('system','maximagesize');
@ -513,10 +543,13 @@ function photos_post(&$a) {
return;
}
logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
$imagedata = @file_get_contents($src);
$ph = new Photo($imagedata);
if(! $ph->is_valid()) {
logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
notice( t('Unable to process image.') . EOL );
@unlink($src);
killme();
@ -524,7 +557,7 @@ function photos_post(&$a) {
@unlink($src);
$width = $ph->getWidth();
$width = $ph->getWidth();
$height = $ph->getHeight();
$smallest = 0;
@ -534,6 +567,7 @@ function photos_post(&$a) {
$r = $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
if(! $r) {
logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
notice( t('Image upload failed.') . EOL );
killme();
}
@ -555,7 +589,6 @@ function photos_post(&$a) {
// Create item container
$arr = array();
$arr['uid'] = $page_owner_uid;
@ -584,14 +617,13 @@ function photos_post(&$a) {
$item_id = item_store($arr);
if(! $java_upload) {
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
return; // NOTREACHED
}
call_hooks('photo_post_end',intval($item_id));
killme();
return; // NOTREACHED
// addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
// if they do not wish to be redirected
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
// NOTREACHED
}
@ -737,6 +769,22 @@ function photos_content(&$a) {
$celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
$albumselect .= '</select>';
$uploader = '';
$ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
'addon_text' => $uploader,
'default_upload' => true);
call_hooks('photo_upload_form',$ret);
$default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
<input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
$tpl = load_view_file('view/photos_upload.tpl');
$o .= replace_macros($tpl,array(
'$pagename' => t('Upload Photos'),
@ -744,14 +792,13 @@ function photos_content(&$a) {
'$nickname' => $a->data['user']['nickname'],
'$newalbum' => t('New album name: '),
'$existalbumtext' => t('or existing album name: '),
'$filestext' => t('Select files to upload: '),
'$albumselect' => $albumselect,
'$permissions' => t('Permissions'),
'$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
'$archive' => $a->get_baseurl() . '/jumploader_z.jar',
'$nojava' => t('Use the following controls only if the Java uploader [above] fails to launch.'),
'$uploadurl' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
'$submit' => t('Submit')
'$uploader' => $ret['addon_text'],
'$default' => (($ret['default_upload']) ? $default_upload : ''),
'$uploadurl' => $ret['post_url']
));
return $o;
@ -1154,3 +1201,4 @@ function photos_content(&$a) {
$o .= paginate($a);
return $o;
}

View File

@ -3,7 +3,7 @@
$arr = array();
$files = array('index.php','boot.php');
$files = array_merge($files,glob('mod/*'),glob('include/*'));
$files = array_merge($files,glob('mod/*'),glob('include/*'),glob('addon/*/*'));
foreach($files as $file) {

View File

@ -163,6 +163,7 @@ $a->strings['Private Message'] = 'Private Message';
$a->strings['This is you'] = 'This is you';
$a->strings['View $name\'s profile'] = 'View $name\'s profile';
$a->strings['Item has been removed.'] = 'Item has been removed.';
$a->strings['Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.'] = 'Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.';
$a->strings['The profile address specified does not provide adequate information.'] = 'The profile address specified does not provide adequate information.';
$a->strings['Limited profile. This person will be unable to receive direct/personal notifications from you.'] = 'Limited profile. This person will be unable to receive direct/personal notifications from you.';
$a->strings['Unable to retrieve contact information.'] = 'Unable to retrieve contact information.';
@ -211,7 +212,6 @@ $a->strings['Send invitations'] = 'Send invitations';
$a->strings['Enter email addresses, one per line:'] = 'Enter email addresses, one per line:';
$a->strings['Your message:'] = 'Your message:';
$a->strings['Please join my social network on '] = 'Please join my social network on ';
$a->strings["\r\n"] = "\r\n";
$a->strings['To accept this invitation, please visit:'] = 'To accept this invitation, please visit:';
$a->strings['Once you have registered, please connect with me via my profile page at:'] = 'Once you have registered, please connect with me via my profile page at:';
$a->strings['Unable to locate original post.'] = 'Unable to locate original post.';
@ -287,9 +287,7 @@ $a->strings['No photos selected'] = 'No photos selected';
$a->strings['Upload Photos'] = 'Upload Photos';
$a->strings['New album name: '] = 'New album name: ';
$a->strings['or existing album name: '] = 'or existing album name: ';
$a->strings['Select files to upload: '] = 'Select files to upload: ';
$a->strings['Permissions'] = 'Permissions';
$a->strings['Use the following controls only if the Java uploader [above] fails to launch.'] = 'Use the following controls only if the Java uploader [above] fails to launch.';
$a->strings['Edit Album'] = 'Edit Album';
$a->strings['View Photo'] = 'View Photo';
$a->strings['Photo not available'] = 'Photo not available';
@ -340,7 +338,6 @@ $a->strings['Your registration is pending approval by the site owner.'] = 'Your
$a->strings["You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'."] = "You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.";
$a->strings['If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.'] = 'If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.';
$a->strings["Your OpenID \x28optional\x29: "] = "Your OpenID \x28optional\x29: ";
$a->strings['Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.'] = 'Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.';
$a->strings['Registration'] = 'Registration';
$a->strings['Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': '] = 'Your Full Name ' . "\x28" . 'e.g. Joe Smith' . "\x29" . ': ';
$a->strings['Your Email Address: '] = 'Your Email Address: ';
@ -467,6 +464,16 @@ $a->strings['Uncertain'] = 'Uncertain';
$a->strings['Complicated'] = 'Complicated';
$a->strings['Don\'t care'] = 'Don\'t care';
$a->strings['Ask me'] = 'Ask me';
$a->strings['Facebook status update failed.'] = 'Facebook status update failed.';
$a->strings['Select files to upload: '] = 'Select files to upload: ';
$a->strings['Use the following controls only if the Java uploader [above] fails to launch.'] = 'Use the following controls only if the Java uploader [above] fails to launch.';
$a->strings['No files were uploaded.'] = 'No files were uploaded.';
$a->strings['Uploaded file is empty'] = 'Uploaded file is empty';
$a->strings['Uploaded file is too large'] = 'Uploaded file is too large';
$a->strings['File has an invalid extension, it should be one of '] = 'File has an invalid extension, it should be one of ';
$a->strings['Upload was cancelled, or server error encountered'] = 'Upload was cancelled, or server error encountered';
$a->strings['Randplace Settings'] = 'Randplace Settings';
$a->strings['Enable Randplace Plugin'] = 'Enable Randplace Plugin';
$a->strings['Africa/Abidjan'] = 'Africa/Abidjan';
$a->strings['Africa/Accra'] = 'Africa/Accra';
$a->strings['Africa/Addis_Ababa'] = 'Africa/Addis_Ababa';

View File

@ -62,3 +62,9 @@ $a->config['system']['huburl'] = 'http://pubsubhubbub.appspot.com';
$a->config['system']['rino_encrypt'] = true;
// Addons or plugins are configured here.
// This is a comma seperated list of addons to enable. Example:
// $a->config['system']['addon'] = 'js_upload,randplace,oembed';
$a->config['system']['addon'] = 'js_upload';

View File

@ -23,41 +23,12 @@
</div>
<div id="photos-upload-select-files-text">$filestext</div>
<div id="photos-upload-spacer"></div>
<div id="photos_upload_applet_wrapper">
<applet name="jumpLoaderApplet"
code="jmaster.jumploader.app.JumpLoaderApplet.class"
archive="$archive"
width="700"
height="600"
mayscript >
<param name="uc_uploadUrl" value="$uploadurl" />
<param name="uc_uploadFormName" value="photos-upload-form" />
<param name="gc_loggingLeveL" value="FATAL" />
<param name="uc_fileParameterName" value="userfile" />
<param name="uc_cookie" value="PHPSESSID=$sessid; path=/;" />
<param name="vc_disableLocalFileSystem" value="false" />
<param name="vc_uploadViewMenuBarVisible" value="false" />
<param name="vc_mainViewFileListViewVisible" value="true" />
<param name="vc_mainViewFileListViewHeightPercent" value="50" />
<param name="vc_mainViewFileTreeViewVisible" value="true" />
<param name="vc_mainViewFileTreeViewWidthPercent" value="35" />
<param name="vc_lookAndFeel" value="system" />
$uploader
</applet>
$default
</div>
<div id="photos-upload-no-java-message" >
$nojava
</div>
<input type="file" name="userfile" />
<div class="photos-upload-submit-wrapper" >
<input type="submit" name="submit" value="$submit" id="photos-upload-submit" />
</div>
<div class="photos-upload-end" ></div>
</form>

View File

@ -1727,6 +1727,9 @@ a.mail-list-link {
#photos-upload-album-select {
float: left;
}
#photos-upload-spacer {
margin-top: 25px;
}
#photos-upload-new-end, #photos-upload-exist-end {
clear: both;
}

View File

@ -1600,6 +1600,10 @@ a.mail-list-link {
#photos-upload-album-select {
float: left;
}
#photos-upload-spacer {
margin-top: 25px;
}
#photos-upload-new-end, #photos-upload-exist-end {
clear: both;
}