Code style

This commit is contained in:
Thomas Tanghus 2012-07-19 23:48:17 +02:00
parent 616f2f336e
commit 1cbddcf211
23 changed files with 152 additions and 105 deletions

View File

@ -16,8 +16,12 @@ $bookid = $_POST['bookid'];
$book = OC_Contacts_App::getAddressbook($bookid);// is owner access check
if(!OC_Contacts_Addressbook::setActive($bookid, $_POST['active'])) {
OCP\Util::writeLog('contacts','ajax/activation.php: Error activating addressbook: '.$bookid, OCP\Util::ERROR);
OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error (de)activating addressbook.'))));
OCP\Util::writeLog('contacts',
'ajax/activation.php: Error activating addressbook: '. $bookid,
OCP\Util::ERROR);
OCP\JSON::error(array(
'data' => array(
'message' => OC_Contacts_App::$l10n->t('Error (de)activating addressbook.'))));
exit();
}

View File

@ -12,13 +12,15 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once('loghandler.php');
require_once 'loghandler.php';
debug('name: '.$_POST['name']);
$userid = OCP\USER::getUser();
$name = isset($_POST['name'])?trim(strip_tags($_POST['name'])):null;
$description = isset($_POST['description'])?trim(strip_tags($_POST['description'])):null;
$description = isset($_POST['description'])
? trim(strip_tags($_POST['description']))
: null;
if(is_null($name)) {
bailOut('Cannot add addressbook with an empty name.');

View File

@ -37,13 +37,15 @@ $n = trim($_POST['n']);
$vcard = new OC_VObject('VCARD');
$vcard->setUID();
$vcard->setString('FN',$fn);
$vcard->setString('N',$n);
$vcard->setString('FN', $fn);
$vcard->setString('N', $n);
$id = OC_Contacts_VCard::add($aid, $vcard, null, $isnew);
if(!$id) {
OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('There was an error adding the contact.'))));
OCP\Util::writeLog('contacts','ajax/addcontact.php: Recieved non-positive ID on adding card: '.$id, OCP\Util::ERROR);
OCP\JSON::error(array(
'data' => array(
'message' => OC_Contacts_App::$l10n->t('There was an error adding the contact.'))));
OCP\Util::writeLog('contacts', 'ajax/addcontact.php: Recieved non-positive ID on adding card: '.$id, OCP\Util::ERROR);
exit();
}

View File

@ -25,7 +25,7 @@ OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once('loghandler.php');
require_once 'loghandler.php';
$id = isset($_POST['id'])?$_POST['id']:null;
$name = isset($_POST['name'])?$_POST['name']:null;
@ -33,22 +33,26 @@ $value = isset($_POST['value'])?$_POST['value']:null;
$parameters = isset($_POST['parameters'])?$_POST['parameters']:array();
$vcard = OC_Contacts_App::getContactVCard($id);
$l10n = OC_Contacts_App::$l10n;
if(!$name) {
bailOut(OC_Contacts_App::$l10n->t('element name is not set.'));
bailOut($l10n->t('element name is not set.'));
}
if(!$id) {
bailOut(OC_Contacts_App::$l10n->t('id is not set.'));
bailOut($l10n->t('id is not set.'));
}
if(!$vcard) {
bailOut(OC_Contacts_App::$l10n->t('Could not parse contact: ').$id);
bailOut($l10n->t('Could not parse contact: ').$id);
}
if(!is_array($value)){
if(!is_array($value)) {
$value = trim($value);
if(!$value && in_array($name, array('TEL', 'EMAIL', 'ORG', 'BDAY', 'URL', 'NICKNAME', 'NOTE'))) {
bailOut(OC_Contacts_App::$l10n->t('Cannot add empty property.'));
if(!$value && in_array(
$name,
array('TEL', 'EMAIL', 'ORG', 'BDAY', 'URL', 'NICKNAME', 'NOTE'))
) {
bailOut($l10n->t('Cannot add empty property.'));
}
} elseif($name === 'ADR') { // only add if non-empty elements.
$empty = true;
@ -59,7 +63,7 @@ if(!is_array($value)){
}
}
if($empty) {
bailOut(OC_Contacts_App::$l10n->t('At least one of the address fields has to be filled out.'));
bailOut($l10n->t('At least one of the address fields has to be filled out.'));
}
}
@ -68,12 +72,14 @@ $current = $vcard->select($name);
foreach($current as $item) {
$tmpvalue = (is_array($value)?implode(';', $value):$value);
if($tmpvalue == $item->value) {
bailOut(OC_Contacts_App::$l10n->t('Trying to add duplicate property: '.$name.': '.$tmpvalue));
bailOut($l10n->t('Trying to add duplicate property: '.$name.': '.$tmpvalue));
}
}
if(is_array($value)) {
ksort($value); // NOTE: Important, otherwise the compound value will be set in the order the fields appear in the form!
// NOTE: Important, otherwise the compound value will
// be set in the order the fields appear in the form!
ksort($value);
$value = array_map('strip_tags', $value);
} else {
$value = strip_tags($value);
@ -116,24 +122,25 @@ switch($name) {
$line = count($vcard->children) - 1;
// Apparently Sabre_VObject_Parameter doesn't do well with multiple values or I don't know how to do it. Tanghus.
// Apparently Sabre_VObject_Parameter doesn't do well with
// multiple values or I don't know how to do it. Tanghus.
foreach ($parameters as $key=>$element) {
if(is_array($element) && strtoupper($key) == 'TYPE') {
// NOTE: Maybe this doesn't only apply for TYPE?
// And it probably shouldn't be done here anyways :-/
foreach($element as $e){
foreach($element as $e) {
if($e != '' && !is_null($e)){
$vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key,$e);
$vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key, $e);
}
}
} else {
$vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key,$element);
$vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key, $element);
}
}
$checksum = md5($vcard->children[$line]->serialize());
if(!OC_Contacts_VCard::edit($id,$vcard)) {
bailOut(OC_Contacts_App::$l10n->t('Error adding contact property: '.$name));
if(!OC_Contacts_VCard::edit($id, $vcard)) {
bailOut($l10n->t('Error adding contact property: '.$name));
}
OCP\JSON::success(array('data' => array( 'checksum' => $checksum )));

View File

@ -12,16 +12,23 @@ OCP\JSON::checkAppEnabled('contacts');
$id = isset($_GET['id'])?$_GET['id']:null;
if(is_null($id)) {
OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('No ID provided'))));
OCP\JSON::error(array(
'data' => array(
'message' => OC_Contacts_App::$l10n->t('No ID provided'))));
exit();
}
$vcard = OC_Contacts_App::getContactVCard( $id );
foreach($vcard->children as $property){
//OCP\Util::writeLog('contacts','ajax/categories/checksumfor.php: '.$property->name, OCP\Util::DEBUG);
if($property->name == 'CATEGORIES') {
$checksum = md5($property->serialize());
OCP\JSON::success(array('data' => array('value'=>$property->value, 'checksum'=>$checksum)));
OCP\JSON::success(array(
'data' => array(
'value' => $property->value,
'checksum' => $checksum,
)));
exit();
}
}
OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error setting checksum.'))));
OCP\JSON::error(array(
'data' => array(
'message' => OC_Contacts_App::$l10n->t('Error setting checksum.'))));

View File

@ -11,7 +11,7 @@ OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once(__DIR__.'/../loghandler.php');
require_once __DIR__.'/../loghandler.php';
$categories = isset($_POST['categories'])?$_POST['categories']:null;

View File

@ -20,7 +20,7 @@
*
*/
require_once('loghandler.php');
require_once 'loghandler.php';
// Check if we are a user
OCP\JSON::checkLoggedIn();

View File

@ -12,7 +12,7 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once('loghandler.php');
require_once 'loghandler.php';
$userid = OCP\USER::getUser();
$name = trim(strip_tags($_POST['name']));

View File

@ -24,7 +24,7 @@
OCP\JSON::setContentTypeHeader('text/plain');
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
require_once('loghandler.php');
require_once 'loghandler.php';
if (!isset($_GET['id'])) {
bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));

View File

@ -23,17 +23,7 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once('loghandler.php');
// foreach($_SERVER as $key=>$value) {
// OCP\Util::writeLog('contacts','ajax/saveproperty.php: _SERVER: '.$key.'=>'.$value, OCP\Util::DEBUG);
// }
// foreach($_POST as $key=>$value) {
// debug($key.'=>'.print_r($value, true));
// }
// foreach($_GET as $key=>$value) {
// debug($key.'=>'.print_r($value, true));
// }
require_once 'loghandler.php';
$id = isset($_POST['id'])?$_POST['id']:null;
if(!$id) {

View File

@ -24,22 +24,23 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once('loghandler.php');
require_once 'loghandler.php';
$id = $_POST['id'];
$checksum = $_POST['checksum'];
$l10n = OC_Contacts_App::$l10n
$vcard = OC_Contacts_App::getContactVCard( $id );
$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
if(is_null($line)){
bailOut(OC_Contacts_App::$l10n->t('Information about vCard is incorrect. Please reload the page.'));
if(is_null($line)) {
bailOut($l10n->t('Information about vCard is incorrect. Please reload the page.'));
exit();
}
unset($vcard->children[$line]);
if(!OC_Contacts_VCard::edit($id,$vcard)) {
bailOut(OC_Contacts_App::$l10n->t('Error deleting contact property.'));
if(!OC_Contacts_VCard::edit($id, $vcard)) {
bailOut($l10n->t('Error deleting contact property.'));
}
OCP\JSON::success(array('data' => array( 'id' => $id )));

View File

@ -34,8 +34,8 @@ if($checksum) {
$tmpl->assign('adr', $adr, false);
}
$tmpl->assign('id',$id);
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('id', $id);
$tmpl->assign('adr_types', $adr_types);
$page = $tmpl->fetchPage();
OCP\JSON::success(array('data' => array('page'=>$page, 'checksum'=>$checksum)));

View File

@ -9,7 +9,7 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
require_once('loghandler.php');
require_once 'loghandler.php';
$tmpl = new OCP\Template("contacts", "part.edit_name_dialog");
@ -25,8 +25,8 @@ if($id) {
}
}
$name = array_map('htmlspecialchars', $name['value']);
$tmpl->assign('name',$name, false);
$tmpl->assign('id',$id, false);
$tmpl->assign('name', $name, false);
$tmpl->assign('id', $id, false);
} else {
bailOut(OC_Contacts_App::$l10n->t('Contact ID is missing.'));
}

View File

@ -30,20 +30,20 @@ $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
$requesttoken = $_GET['requesttoken'];
$freeSpace=OC_Filesystem::free_space('/');
$freeSpace=max($freeSpace,0);
$maxUploadFilesize = min($maxUploadFilesize ,$freeSpace);
$freeSpace=max($freeSpace, 0);
$maxUploadFilesize = min($maxUploadFilesize, $freeSpace);
$adr_types = OC_Contacts_App::getTypesOfProperty('ADR');
$phone_types = OC_Contacts_App::getTypesOfProperty('TEL');
$email_types = OC_Contacts_App::getTypesOfProperty('EMAIL');
$tmpl = new OCP\Template('contacts','part.contact');
$tmpl = new OCP\Template('contacts', 'part.contact');
$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
$tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
$tmpl->assign('adr_types',$adr_types);
$tmpl->assign('phone_types',$phone_types);
$tmpl->assign('email_types',$email_types);
$tmpl->assign('adr_types', $adr_types);
$tmpl->assign('phone_types', $phone_types);
$tmpl->assign('email_types', $email_types);
$tmpl->assign('requesttoken', $requesttoken);
$tmpl->assign('id','');
$tmpl->assign('id', '');
$page = $tmpl->fetchPage();
OCP\JSON::success(array('data' => array( 'page' => $page )));

View File

@ -25,7 +25,7 @@ OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$tmpl = new OCP\Template('contacts','part.no_contacts');
$tmpl = new OCP\Template('contacts', 'part.no_contacts');
$page = $tmpl->fetchPage();
OCP\JSON::success(array('data' => array( 'page' => $page )));

View File

@ -24,7 +24,7 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
require_once('loghandler.php');
require_once 'loghandler.php';
$id = isset($_GET['id']) ? $_GET['id'] : '';
$refresh = isset($_GET['refresh']) ? true : false;

View File

@ -20,13 +20,15 @@
*
*/
function bailOut($msg, $tracelevel=1, $debuglevel=OCP\Util::ERROR) {
function bailOut($msg, $tracelevel=1, $debuglevel=OCP\Util::ERROR)
{
OCP\JSON::error(array('data' => array('message' => $msg)));
debug($msg, $tracelevel, $debuglevel);
exit();
}
function debug($msg, $tracelevel=0, $debuglevel=OCP\Util::DEBUG) {
function debug($msg, $tracelevel=0, $debuglevel=OCP\Util::DEBUG)
{
if(PHP_VERSION >= "5.4") {
$call = debug_backtrace(false, $tracelevel+1);
} else {
@ -35,6 +37,8 @@ function debug($msg, $tracelevel=0, $debuglevel=OCP\Util::DEBUG) {
error_log('trace: '.print_r($call, true));
$call = $call[$tracelevel];
if($debuglevel !== false) {
OCP\Util::writeLog('contacts', $call['file'].'. Line: '.$call['line'].': '.$msg, $debuglevel);
OCP\Util::writeLog('contacts',
$call['file'].'. Line: '.$call['line'].': '.$msg,
$debuglevel);
}
}

View File

@ -22,7 +22,7 @@
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
require_once('loghandler.php');
require_once 'loghandler.php';
if(!isset($_GET['id'])) {
bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));
@ -50,7 +50,9 @@ if($image->width() > 400 || $image->height() > 400) {
$image->resize(400); // Prettier resizing than with browser and saves bandwidth.
}
if(!$image->fixOrientation()) { // No fatal error so we don't bail out.
OCP\Util::writeLog('contacts','ajax/oc_photo.php: Couldn\'t save correct image orientation: '.$localpath, OCP\Util::DEBUG);
OCP\Util::writeLog('contacts',
'ajax/oc_photo.php: Couldn\'t save correct image orientation: '.$localpath,
OCP\Util::DEBUG);
}
if(OC_Cache::set($tmpkey, $image->data(), 600)) {
OCP\JSON::success(array('data' => array('id'=>$_GET['id'], 'tmp'=>$tmpkey)));

View File

@ -27,7 +27,7 @@ OCP\JSON::callCheck();
// Firefox and Konqueror tries to download application/json for me. --Arthur
OCP\JSON::setContentTypeHeader('text/plain');
require_once('loghandler.php');
require_once 'loghandler.php';
$image = null;
@ -48,7 +48,7 @@ if($id == '') {
bailOut('Missing contact id.');
}
OCP\Util::writeLog('contacts','savecrop.php: key: '.$tmpkey, OCP\Util::DEBUG);
OCP\Util::writeLog('contacts', 'savecrop.php: key: '.$tmpkey, OCP\Util::DEBUG);
$data = OC_Cache::get($tmpkey);
if($data) {
@ -56,7 +56,9 @@ if($data) {
if($image->loadFromdata($data)) {
$w = ($w != -1 ? $w : $image->width());
$h = ($h != -1 ? $h : $image->height());
OCP\Util::writeLog('contacts','savecrop.php, x: '.$x1.' y: '.$y1.' w: '.$w.' h: '.$h, OCP\Util::DEBUG);
OCP\Util::writeLog('contacts',
'savecrop.php, x: '.$x1.' y: '.$y1.' w: '.$w.' h: '.$h,
OCP\Util::DEBUG);
if($image->crop($x1, $y1, $w, $h)) {
if(($image->width() <= 200 && $image->height() <= 200) || $image->resize(200)) {
$card = OC_Contacts_App::getContactVCard($id);
@ -65,7 +67,9 @@ if($data) {
bailOut(OC_Contacts_App::$l10n->t('Error getting contact object.'));
}
if($card->__isset('PHOTO')) {
OCP\Util::writeLog('contacts','savecrop.php: PHOTO property exists.', OCP\Util::DEBUG);
OCP\Util::writeLog('contacts',
'savecrop.php: PHOTO property exists.',
OCP\Util::DEBUG);
$property = $card->__get('PHOTO');
if(!$property) {
OC_Cache::remove($tmpkey);
@ -76,8 +80,12 @@ if($data) {
$property->parameters[] = new Sabre_VObject_Parameter('TYPE', $image->mimeType());
$card->__set('PHOTO', $property);
} else {
OCP\Util::writeLog('contacts','savecrop.php: files: Adding PHOTO property.', OCP\Util::DEBUG);
$card->addProperty('PHOTO', $image->__toString(), array('ENCODING' => 'b', 'TYPE' => $image->mimeType()));
OCP\Util::writeLog('contacts',
'savecrop.php: files: Adding PHOTO property.',
OCP\Util::DEBUG);
$card->addProperty('PHOTO',
$image->__toString(), array('ENCODING' => 'b',
'TYPE' => $image->mimeType()));
}
$now = new DateTime;
$card->setString('REV', $now->format(DateTime::W3C));

View File

@ -19,7 +19,7 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
require_once('loghandler.php');
require_once 'loghandler.php';
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
@ -39,9 +39,11 @@ if(!$id) {
if(!$checksum) {
bailOut(OC_Contacts_App::$l10n->t('checksum is not set.'));
}
if(is_array($value)){
if(is_array($value)) {
$value = array_map('strip_tags', $value);
ksort($value); // NOTE: Important, otherwise the compound value will be set in the order the fields appear in the form!
// NOTE: Important, otherwise the compound value will be
// set in the order the fields appear in the form!
ksort($value);
//if($name == 'CATEGORIES') {
// $value = OC_Contacts_VCard::escapeDelimiters($value, ',');
//} else {

View File

@ -11,7 +11,7 @@
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
require_once('loghandler.php');
require_once 'loghandler.php';
$bookid = $_POST['id'];
OC_Contacts_App::getAddressbook($bookid); // is owner access check

View File

@ -24,7 +24,9 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
require_once('loghandler.php');
require_once 'loghandler.php';
$l10n = OC_Contacts_App::$l10n
$view = OCP\Files::getStorage('contacts');
if(!$view->file_exists('imports')) {
@ -39,25 +41,29 @@ if($fn) {
OCP\JSON::success(array('data' => array('file'=>$tmpfile, 'name'=>$fn)));
exit();
} else {
bailOut(OC_Contacts_App::$l10n->t('Error uploading contacts to storage.'));
bailOut($l10n->t('Error uploading contacts to storage.'));
}
}
// File input transfers are handled here
if (!isset($_FILES['importfile'])) {
OCP\Util::writeLog('contacts','ajax/uploadphoto.php: No file was uploaded. Unknown error.', OCP\Util::DEBUG);
OCP\JSON::error(array('data' => array( 'message' => 'No file was uploaded. Unknown error' )));
OCP\Util::writeLog('contacts',
'ajax/uploadphoto.php: No file was uploaded. Unknown error.',
OCP\Util::DEBUG);
OCP\JSON::error(array('
data' => array(
'message' => 'No file was uploaded. Unknown error' )));
exit();
}
$error = $_FILES['importfile']['error'];
if($error !== UPLOAD_ERR_OK) {
$errors = array(
0=>OC_Contacts_App::$l10n->t("There is no error, the file uploaded with success"),
1=>OC_Contacts_App::$l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini").ini_get('upload_max_filesize'),
2=>OC_Contacts_App::$l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
3=>OC_Contacts_App::$l10n->t("The uploaded file was only partially uploaded"),
4=>OC_Contacts_App::$l10n->t("No file was uploaded"),
6=>OC_Contacts_App::$l10n->t("Missing a temporary folder")
0=>$l10n->t("There is no error, the file uploaded with success"),
1=>$l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini").ini_get('upload_max_filesize'),
2=>$l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
3=>$l10n->t("The uploaded file was only partially uploaded"),
4=>$l10n->t("No file was uploaded"),
6=>$l10n->t("Missing a temporary folder")
);
bailOut($errors[$error]);
}
@ -67,7 +73,7 @@ if(file_exists($file['tmp_name'])) {
if($view->file_put_contents('/imports/'.$file['name'], file_get_contents($file['tmp_name']))) {
OCP\JSON::success(array('data' => array('file'=>$file['name'], 'name'=>$file['name'])));
} else {
bailOut(OC_Contacts_App::$l10n->t('Error uploading contacts to storage.'));
bailOut($l10n->t('Error uploading contacts to storage.'));
}
} else {
bailOut('Temporary file: \''.$file['tmp_name'].'\' has gone AWOL?');

View File

@ -27,13 +27,13 @@ OCP\JSON::callCheck();
// Firefox and Konqueror tries to download application/json for me. --Arthur
OCP\JSON::setContentTypeHeader('text/plain');
require_once('loghandler.php');
require_once 'loghandler.php';
$l10n = OC_Contacts_App::$l10n;
// If it is a Drag'n'Drop transfer it's handled here.
$fn = (isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : false);
if ($fn) {
if (!isset($_GET['id'])) {
bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));
bailOut($l10n->t('No contact ID was submitted.'));
}
$id = $_GET['id'];
$tmpkey = 'contact-photo-'.md5($fn);
@ -48,33 +48,38 @@ if ($fn) {
debug('Couldn\'t save correct image orientation: '.$tmpkey);
}
if(OC_Cache::set($tmpkey, $image->data(), 600)) {
OCP\JSON::success(array('data' => array('mime'=>$_SERVER['CONTENT_TYPE'], 'name'=>$fn, 'id'=>$id, 'tmp'=>$tmpkey)));
OCP\JSON::success(array(
'data' => array(
'mime'=>$_SERVER['CONTENT_TYPE'],
'name'=>$fn,
'id'=>$id,
'tmp'=>$tmpkey)));
exit();
} else {
bailOut(OC_Contacts_App::$l10n->t('Couldn\'t save temporary image: ').$tmpkey);
bailOut($l10n->t('Couldn\'t save temporary image: ').$tmpkey);
}
} else {
bailOut(OC_Contacts_App::$l10n->t('Couldn\'t load temporary image: ').$tmpkey);
bailOut($l10n->t('Couldn\'t load temporary image: ').$tmpkey);
}
}
// Uploads from file dialog are handled here.
if (!isset($_POST['id'])) {
bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));
bailOut($l10n->t('No contact ID was submitted.'));
}
if (!isset($_FILES['imagefile'])) {
bailOut(OC_Contacts_App::$l10n->t('No file was uploaded. Unknown error'));
bailOut($l10n->t('No file was uploaded. Unknown error'));
}
$error = $_FILES['imagefile']['error'];
if($error !== UPLOAD_ERR_OK) {
$errors = array(
0=>OC_Contacts_App::$l10n->t("There is no error, the file uploaded with success"),
1=>OC_Contacts_App::$l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini").ini_get('upload_max_filesize'),
2=>OC_Contacts_App::$l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
3=>OC_Contacts_App::$l10n->t("The uploaded file was only partially uploaded"),
4=>OC_Contacts_App::$l10n->t("No file was uploaded"),
6=>OC_Contacts_App::$l10n->t("Missing a temporary folder")
0=>$l10n->t("There is no error, the file uploaded with success"),
1=>$l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini").ini_get('upload_max_filesize'),
2=>$l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
3=>$l10n->t("The uploaded file was only partially uploaded"),
4=>$l10n->t("No file was uploaded"),
6=>$l10n->t("Missing a temporary folder")
);
bailOut($errors[$error]);
}
@ -91,13 +96,20 @@ if(file_exists($file['tmp_name'])) {
debug('Couldn\'t save correct image orientation: '.$tmpkey);
}
if(OC_Cache::set($tmpkey, $image->data(), 600)) {
OCP\JSON::success(array('data' => array('mime'=>$file['type'],'size'=>$file['size'],'name'=>$file['name'], 'id'=>$_POST['id'], 'tmp'=>$tmpkey)));
OCP\JSON::success(array(
'data' => array(
'mime'=>$file['type'],
'size'=>$file['size'],
'name'=>$file['name'],
'id'=>$_POST['id'],
'tmp'=>$tmpkey,
)));
exit();
} else {
bailOut(OC_Contacts_App::$l10n->t('Couldn\'t save temporary image: ').$tmpkey);
bailOut($l10n->t('Couldn\'t save temporary image: ').$tmpkey);
}
} else {
bailOut(OC_Contacts_App::$l10n->t('Couldn\'t load temporary image: ').$file['tmp_name']);
bailOut($l10n->t('Couldn\'t load temporary image: ').$file['tmp_name']);
}
} else {
bailOut('Temporary file: \''.$file['tmp_name'].'\' has gone AWOL?');