summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/bookmarks/ajax/addBookmark.php10
-rw-r--r--apps/bookmarks/ajax/delBookmark.php10
-rw-r--r--apps/bookmarks/ajax/editBookmark.php8
-rw-r--r--apps/bookmarks/ajax/getMeta.php10
-rw-r--r--apps/bookmarks/ajax/recordClick.php6
-rw-r--r--apps/bookmarks/ajax/updateList.php10
-rw-r--r--apps/calendar/ajax/createcalendar.php10
-rw-r--r--apps/calendar/ajax/deletecalendar.php6
-rw-r--r--apps/calendar/ajax/deleteevent.php6
-rw-r--r--apps/calendar/ajax/editevent.php11
-rw-r--r--apps/calendar/ajax/newevent.php5
-rw-r--r--apps/calendar/ajax/settimezone.php12
-rw-r--r--apps/calendar/ajax/updatecalendar.php10
-rw-r--r--apps/calendar/templates/part.getcal.php2
-rw-r--r--apps/contacts/ajax/addcard.php9
-rw-r--r--apps/contacts/ajax/addproperty.php13
-rw-r--r--apps/contacts/ajax/deletebook.php9
-rw-r--r--apps/contacts/ajax/deletecard.php12
-rw-r--r--apps/contacts/ajax/deleteproperty.php16
-rw-r--r--apps/contacts/ajax/getdetails.php13
-rw-r--r--apps/contacts/ajax/setproperty.php15
-rw-r--r--apps/contacts/ajax/showaddcard.php7
-rw-r--r--apps/contacts/ajax/showaddproperty.php11
-rw-r--r--apps/contacts/ajax/showsetproperty.php15
-rw-r--r--apps/files_sharing/ajax/getitem.php4
-rw-r--r--apps/files_sharing/ajax/userautocomplete.php8
-rw-r--r--apps/media/ajax/api.php12
-rw-r--r--apps/media/ajax/autoupdate.php4
-rw-r--r--apps/media/tomahawk.php4
29 files changed, 90 insertions, 178 deletions
diff --git a/apps/bookmarks/ajax/addBookmark.php b/apps/bookmarks/ajax/addBookmark.php
index 7cf5baa4a6e..9b0beb388a0 100644
--- a/apps/bookmarks/ajax/addBookmark.php
+++ b/apps/bookmarks/ajax/addBookmark.php
@@ -26,14 +26,8 @@ $RUNTIME_NOSETUPFS=true;
require_once('../../../lib/base.php');
-// We send json data
-header( "Content-Type: application/jsonrequest" );
-
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
- exit();
-}
+OC_JSON::checkLoggedIn();
$CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
@@ -76,6 +70,6 @@ if($b_id !== false) {
$query->execute($params);
}
- echo json_encode( array( 'status' => 'success', 'data' => $b_id));
+ OC_JSON::success(array('data' => $b_id));
}
diff --git a/apps/bookmarks/ajax/delBookmark.php b/apps/bookmarks/ajax/delBookmark.php
index bf1611fe5c1..afe60f7d1bf 100644
--- a/apps/bookmarks/ajax/delBookmark.php
+++ b/apps/bookmarks/ajax/delBookmark.php
@@ -26,14 +26,8 @@ $RUNTIME_NOSETUPFS=true;
require_once('../../../lib/base.php');
-// We send json data
-header( "Content-Type: application/jsonrequest" );
-
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
- exit();
-}
+OC_JSON::checkLoggedIn();
$params=array(
htmlspecialchars_decode($_GET["url"]),
@@ -64,4 +58,4 @@ $query = OC_DB::prepare("
$result = $query->execute();
// var_dump($params);
-echo json_encode( array( "status" => "success", "data" => array()));
+OC_JSON::success(array('data' => array()));
diff --git a/apps/bookmarks/ajax/editBookmark.php b/apps/bookmarks/ajax/editBookmark.php
index 1bd2fc08bca..5125f9ce898 100644
--- a/apps/bookmarks/ajax/editBookmark.php
+++ b/apps/bookmarks/ajax/editBookmark.php
@@ -26,14 +26,8 @@ $RUNTIME_NOSETUPFS=true;
require_once('../../../lib/base.php');
-// We send json data
-header( 'Content-Type: application/jsonrequest' );
-
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => 'Authentication error' )));
- exit();
-}
+OC_JSON::checkLoggedIn();
$CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
diff --git a/apps/bookmarks/ajax/getMeta.php b/apps/bookmarks/ajax/getMeta.php
index e9fe0d684dc..4583ef204b4 100644
--- a/apps/bookmarks/ajax/getMeta.php
+++ b/apps/bookmarks/ajax/getMeta.php
@@ -26,14 +26,8 @@ $RUNTIME_NOSETUPFS=true;
require_once('../../../lib/base.php');
-// We send json data
-header( 'Content-Type: application/jsonrequest' );
-
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => 'Authentication error' )));
- exit();
-}
+OC_JSON::checkLoggedIn();
// $metadata = array();
@@ -41,4 +35,4 @@ require '../bookmarksHelper.php';
$metadata = getURLMetadata(htmlspecialchars_decode($_GET["url"]));
-echo json_encode( array( 'status' => 'success', 'data' => $metadata));
+OC_JSON::success(array('data' => $metadata));
diff --git a/apps/bookmarks/ajax/recordClick.php b/apps/bookmarks/ajax/recordClick.php
index 116daea8bbb..f5f7c20c6a0 100644
--- a/apps/bookmarks/ajax/recordClick.php
+++ b/apps/bookmarks/ajax/recordClick.php
@@ -27,11 +27,7 @@ $RUNTIME_NOSETUPFS=true;
require_once('../../../lib/base.php');
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- header( "Content-Type: application/jsonrequest" );
- echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
- exit();
-}
+OC_JSON::checkLoggedIn();
$query = OC_DB::prepare("
UPDATE *PREFIX*bookmarks
diff --git a/apps/bookmarks/ajax/updateList.php b/apps/bookmarks/ajax/updateList.php
index e9051a8dbfa..de3480d6c3a 100644
--- a/apps/bookmarks/ajax/updateList.php
+++ b/apps/bookmarks/ajax/updateList.php
@@ -26,14 +26,8 @@ $RUNTIME_NOSETUPFS=true;
require_once('../../../lib/base.php');
-// We send json data
-header( 'Content-Type: application/jsonrequest' );
-
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => 'Authentication error' )));
- exit();
-}
+OC_JSON::checkLoggedIn();
$params=array(OC_User::getUser());
$CONFIG_DBTYPE = OC_Config::getValue( 'dbtype', 'sqlite' );
@@ -85,4 +79,4 @@ $query = OC_DB::prepare('
$bookmarks = $query->execute($params)->fetchAll();
-echo json_encode( array( 'status' => 'success', 'data' => $bookmarks));
+OC_JSON::success(array('data' => $bookmarks));
diff --git a/apps/calendar/ajax/createcalendar.php b/apps/calendar/ajax/createcalendar.php
index 64c6513f53f..7d80333b258 100644
--- a/apps/calendar/ajax/createcalendar.php
+++ b/apps/calendar/ajax/createcalendar.php
@@ -10,14 +10,8 @@ require_once('../../../lib/base.php');
$l10n = new OC_L10N('calendar');
-// We send json data
-header( "Content-Type: application/jsonrequest" );
-
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Authentication error") )));
- exit();
-}
+OC_JSON::checkLoggedIn();
$userid = OC_User::getUser();
$calendarid = OC_Calendar_Calendar::addCalendar($userid, $_POST['name'], $_POST['description'], 'VEVENT,VTODO,VJOURNAL', null, 0, $_POST['color']);
@@ -25,4 +19,4 @@ OC_Calendar_Calendar::setCalendarActive($calendarid, 1);
$calendar = OC_Calendar_Calendar::findCalendar($calendarid);
$tmpl = new OC_Template('calendar', 'part.choosecalendar.rowfields');
$tmpl->assign('calendar', $calendar);
-echo json_encode( array( "status" => "error", "data" => $tmpl->fetchPage().'' ));
+OC_JSON::success(array('data' => $tmpl->fetchPage()));
diff --git a/apps/calendar/ajax/deletecalendar.php b/apps/calendar/ajax/deletecalendar.php
index 71129f2c040..30607b92e6f 100644
--- a/apps/calendar/ajax/deletecalendar.php
+++ b/apps/calendar/ajax/deletecalendar.php
@@ -16,13 +16,13 @@ if(!OC_USER::isLoggedIn()) {
$cal = $_POST["calendarid"];
$calendar = OC_Calendar_Calendar::findCalendar($cal);
if($calendar["userid"] != OC_User::getUser()){
- echo json_encode(array('status'=>'error','error'=>'permission_denied'));
+ OC_JSON::error(array('error'=>'permission_denied'));
exit;
}
$del = OC_Calendar_Calendar::deleteCalendar($cal);
if($del == true){
- echo json_encode(array('status' => 'success'));
+ OC_JSON::success();
}else{
- echo json_encode(array('status'=>'error', 'error'=>'dberror'));
+ OC_JSON::error(array('error'=>'dberror'));
}
?>
diff --git a/apps/calendar/ajax/deleteevent.php b/apps/calendar/ajax/deleteevent.php
index 08a0e1a1e26..a6750267bd2 100644
--- a/apps/calendar/ajax/deleteevent.php
+++ b/apps/calendar/ajax/deleteevent.php
@@ -17,14 +17,14 @@ $id = $_POST['id'];
$data = OC_Calendar_Object::find($id);
if (!$data)
{
- echo json_encode(array('status'=>'error'));
+ OC_JSON::error();
exit;
}
$calendar = OC_Calendar_Calendar::findCalendar($data['calendarid']);
if($calendar['userid'] != OC_User::getUser()){
- echo json_encode(array('status'=>'error'));
+ OC_JSON::error();
exit;
}
$result = OC_Calendar_Object::delete($id);
-echo json_encode(array('status' => 'success'));
+OC_JSON::success();
?>
diff --git a/apps/calendar/ajax/editevent.php b/apps/calendar/ajax/editevent.php
index 5659e7e3c1c..7187e05d56f 100644
--- a/apps/calendar/ajax/editevent.php
+++ b/apps/calendar/ajax/editevent.php
@@ -17,8 +17,7 @@ if(!OC_USER::isLoggedIn()) {
$errarr = OC_Calendar_Object::validateRequest($_POST);
if($errarr){
//show validate errors
- $errarr['status'] = 'error';
- echo json_encode($errarr);
+ OC_JSON::error($errarr);
exit;
}else{
$id = $_POST['id'];
@@ -26,12 +25,12 @@ if($errarr){
$data = OC_Calendar_Object::find($id);
if (!$data)
{
- echo json_encode(array('status'=>'error'));
+ OC_JSON::error();
exit;
}
$calendar = OC_Calendar_Calendar::findCalendar($data['calendarid']);
if($calendar['userid'] != OC_User::getUser()){
- echo json_encode(array('status'=>'error'));
+ OC_JSON::error();
exit;
}
$vcalendar = Sabre_VObject_Reader::read($data['calendardata']);
@@ -40,6 +39,6 @@ if($errarr){
if ($data['calendarid'] != $cal) {
OC_Calendar_Object::moveToCalendar($id, $cal);
}
- echo json_encode(array('status' => 'success'));
+ OC_JSON::success();
}
-?>
+?>
diff --git a/apps/calendar/ajax/newevent.php b/apps/calendar/ajax/newevent.php
index f3cca1cee46..9ac3b0aaff6 100644
--- a/apps/calendar/ajax/newevent.php
+++ b/apps/calendar/ajax/newevent.php
@@ -17,13 +17,12 @@ if(!OC_USER::isLoggedIn()) {
$errarr = OC_Calendar_Object::validateRequest($_POST);
if($errarr){
//show validate errors
- $errarr['status'] = 'error';
- echo json_encode($errarr);
+ OC_JSON::error($errarr);
exit;
}else{
$cal = $_POST['calendar'];
$vcalendar = OC_Calendar_Object::createVCalendarFromRequest($_POST);
$result = OC_Calendar_Object::add($cal, $vcalendar->serialize());
- echo json_encode(array('status'=>'success'));
+ OC_JSON::success();
}
?>
diff --git a/apps/calendar/ajax/settimezone.php b/apps/calendar/ajax/settimezone.php
index a07b56ee9ae..2b82bc8e4bc 100644
--- a/apps/calendar/ajax/settimezone.php
+++ b/apps/calendar/ajax/settimezone.php
@@ -11,22 +11,16 @@ require_once('../../../lib/base.php');
$l=new OC_L10N('calendar');
-// We send json data
-header( "Content-Type: application/jsonrequest" );
-
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Authentication error") )));
- exit();
-}
+OC_JSON::checkLoggedIn();
// Get data
if( isset( $_POST['timezone'] ) ){
$timezone=$_POST['timezone'];
OC_Preferences::setValue( OC_User::getUser(), 'calendar', 'timezone', $timezone );
- echo json_encode( array( "status" => "success", "data" => array( "message" => $l->t("Timezone changed") )));
+ OC_JSON::success(array('data' => array( 'message' => $l->t('Timezone changed') )));
}else{
- echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Invalid request") )));
+ OC_JSON::error(array('data' => array( 'message' => $l->t('Invalid request') )));
}
?>
diff --git a/apps/calendar/ajax/updatecalendar.php b/apps/calendar/ajax/updatecalendar.php
index efb0b99bad7..d53515d0deb 100644
--- a/apps/calendar/ajax/updatecalendar.php
+++ b/apps/calendar/ajax/updatecalendar.php
@@ -10,14 +10,8 @@ require_once('../../../lib/base.php');
$l10n = new OC_L10N('calendar');
-// We send json data
-header( "Content-Type: application/jsonrequest" );
-
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Authentication error") )));
- exit();
-}
+OC_JSON::checkLoggedIn();
$calendarid = $_POST['id'];
OC_Calendar_Calendar::editCalendar($calendarid, $_POST['name'], $_POST['description'], null, null, null, $_POST['color']);
@@ -25,4 +19,4 @@ OC_Calendar_Calendar::setCalendarActive($calendarid, $_POST['active']);
$calendar = OC_Calendar_Calendar::findCalendar($calendarid);
$tmpl = new OC_Template('calendar', 'part.choosecalendar.rowfields');
$tmpl->assign('calendar', $calendar);
-echo json_encode( array( "status" => "success", "data" => $tmpl->fetchPage() ));
+OC_JSON::success(array('data' => $tmpl->fetchPage()));
diff --git a/apps/calendar/templates/part.getcal.php b/apps/calendar/templates/part.getcal.php
index 35d08c85b3a..900a43b3df2 100644
--- a/apps/calendar/templates/part.getcal.php
+++ b/apps/calendar/templates/part.getcal.php
@@ -53,5 +53,5 @@ foreach($events as $event)
$return_events[$year][$month][$day][$hour] = array(1 => $return_event);
}
}
-echo json_encode($return_events);
+OC_JSON::encodedPrint($return_events);
?>
diff --git a/apps/contacts/ajax/addcard.php b/apps/contacts/ajax/addcard.php
index 6005d74d144..cfae3327f56 100644
--- a/apps/contacts/ajax/addcard.php
+++ b/apps/contacts/ajax/addcard.php
@@ -27,14 +27,11 @@ $aid = $_POST['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in.'))));
- exit();
-}
+OC_JSON::checkLoggedIn();
$addressbook = OC_Contacts_Addressbook::find( $aid );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved?
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your addressbook.')))); // Same here (as with the contact error). Could this error be improved?
exit();
}
@@ -51,4 +48,4 @@ $tmpl->assign('details',$details);
$tmpl->assign('id',$id);
$page = $tmpl->fetchPage();
-echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id, 'page' => $page )));
+OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page )));
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/addproperty.php
index a311bba6e26..5a37f77f858 100644
--- a/apps/contacts/ajax/addproperty.php
+++ b/apps/contacts/ajax/addproperty.php
@@ -27,27 +27,24 @@ $id = $_POST['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in.'))));
- exit();
-}
+OC_JSON::checkLoggedIn();
$card = OC_Contacts_VCard::find( $id );
if( $card === false ){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Contact could not be found.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
$vcard = OC_Contacts_VCard::parse($card['carddata']);
// Check if the card is valid
if(is_null($vcard)){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('vCard could not be read.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
exit();
}
@@ -75,4 +72,4 @@ $tmpl = new OC_Template('contacts','part.property');
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($property,$line));
$page = $tmpl->fetchPage();
-echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));
+OC_JSON::success(array('data' => array( 'page' => $page )));
diff --git a/apps/contacts/ajax/deletebook.php b/apps/contacts/ajax/deletebook.php
index 38322f5c109..13be33eb5a9 100644
--- a/apps/contacts/ajax/deletebook.php
+++ b/apps/contacts/ajax/deletebook.php
@@ -28,16 +28,13 @@ $id = $_GET['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in.'))));
- exit();
-}
+OC_JSON::checkLoggedIn();
$addressbook = OC_Contacts_Addressbook::find( $id );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
OC_Contacts_Addressbook::delete($id);
-echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id )));
+OC_JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/deletecard.php b/apps/contacts/ajax/deletecard.php
index 7dde7d30a52..c69638320ed 100644
--- a/apps/contacts/ajax/deletecard.php
+++ b/apps/contacts/ajax/deletecard.php
@@ -28,23 +28,19 @@ $id = $_GET['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in.'))));
- exit();
-}
-
+OC_JSON::checkLoggedIn();
$card = OC_Contacts_VCard::find( $id );
if( $card === false ){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Contact could not be found.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
OC_Contacts_VCard::delete($id);
-echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id )));
+OC_JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/deleteproperty.php b/apps/contacts/ajax/deleteproperty.php
index 07cea0b53e1..40b765cf845 100644
--- a/apps/contacts/ajax/deleteproperty.php
+++ b/apps/contacts/ajax/deleteproperty.php
@@ -30,28 +30,24 @@ $checksum = $_GET['checksum'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in.'))));
- exit();
-}
-
+OC_JSON::checkLoggedIn();
$card = OC_Contacts_VCard::find( $id );
if( $card === false ){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Contact could not be found.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
$vcard = OC_Contacts_VCard::parse($card['carddata']);
// Check if the card is valid
if(is_null($vcard)){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('vCard could not be read.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
exit();
}
@@ -62,11 +58,11 @@ for($i=0;$i<count($vcard->children);$i++){
}
}
if(is_null($line)){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
exit();
}
unset($vcard->children[$line]);
OC_Contacts_VCard::edit($id,$vcard->serialize());
-echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id )));
+OC_JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/getdetails.php b/apps/contacts/ajax/getdetails.php
index ab1f1d66f5e..47d88a771e6 100644
--- a/apps/contacts/ajax/getdetails.php
+++ b/apps/contacts/ajax/getdetails.php
@@ -28,28 +28,25 @@ $id = $_GET['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in.'))));
- exit();
-}
+OC_JSON::checkLoggedIn();
$card = OC_Contacts_VCard::find( $id );
if( $card === false ){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Contact could not be found.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
$vcard = OC_Contacts_VCard::parse($card['carddata']);
// Check if the card is valid
if(is_null($vcard)){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('vCard could not be read.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
exit();
}
@@ -59,4 +56,4 @@ $tmpl->assign('details',$details);
$tmpl->assign('id',$id);
$page = $tmpl->fetchPage();
-echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id, 'page' => $page )));
+OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page )));
diff --git a/apps/contacts/ajax/setproperty.php b/apps/contacts/ajax/setproperty.php
index 9178a6aac9f..b4fc2162d90 100644
--- a/apps/contacts/ajax/setproperty.php
+++ b/apps/contacts/ajax/setproperty.php
@@ -28,27 +28,24 @@ $checksum = $_POST['checksum'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in.'))));
- exit();
-}
+OC_JSON::checkLoggedIn();
$card = OC_Contacts_VCard::find( $id );
if( $card === false ){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Contact could not be found.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
$vcard = OC_Contacts_VCard::parse($card['carddata']);
// Check if the card is valid
if(is_null($vcard)){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('vCard could not be read.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
exit();
}
@@ -59,7 +56,7 @@ for($i=0;$i<count($vcard->children);$i++){
}
}
if(is_null($line)){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
exit();
}
@@ -100,4 +97,4 @@ $tmpl = new OC_Template('contacts','part.property');
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line],$line));
$page = $tmpl->fetchPage();
-echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page, 'line' => $line, 'oldchecksum' => $_POST['checksum'] )));
+OC_JSON::success(array('data' => array( 'page' => $page, 'line' => $line, 'oldchecksum' => $_POST['checksum'] )));
diff --git a/apps/contacts/ajax/showaddcard.php b/apps/contacts/ajax/showaddcard.php
index 89c78fcdf54..58567392d7c 100644
--- a/apps/contacts/ajax/showaddcard.php
+++ b/apps/contacts/ajax/showaddcard.php
@@ -26,14 +26,11 @@ require_once('../../../lib/base.php');
$l10n = new OC_L10N('contacts');
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in.'))));
- exit();
-}
+OC_JSON::checkLoggedIn();
$addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser());
$tmpl = new OC_Template('contacts','part.addcardform');
$tmpl->assign('addressbooks',$addressbooks);
$page = $tmpl->fetchPage();
-echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));
+OC_JSON::success(array('data' => array( 'page' => $page )));
diff --git a/apps/contacts/ajax/showaddproperty.php b/apps/contacts/ajax/showaddproperty.php
index 718478d42bf..0d01b37d8ef 100644
--- a/apps/contacts/ajax/showaddproperty.php
+++ b/apps/contacts/ajax/showaddproperty.php
@@ -27,20 +27,17 @@ $id = $_GET['id'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in.'))));
- exit();
-}
+OC_JSON::checkLoggedIn();
$card = OC_Contacts_VCard::find( $id );
if( $card === false ){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Contact could not be found.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
@@ -48,4 +45,4 @@ $tmpl = new OC_Template('contacts','part.addpropertyform');
$tmpl->assign('id',$id);
$page = $tmpl->fetchPage();
-echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));
+OC_JSON::success(array('data' => array( 'page' => $page )));
diff --git a/apps/contacts/ajax/showsetproperty.php b/apps/contacts/ajax/showsetproperty.php
index 77b90ea8cc4..0b30a8e68ec 100644
--- a/apps/contacts/ajax/showsetproperty.php
+++ b/apps/contacts/ajax/showsetproperty.php
@@ -28,27 +28,24 @@ $checksum = $_GET['checksum'];
$l10n = new OC_L10N('contacts');
// Check if we are a user
-if( !OC_User::isLoggedIn()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in.'))));
- exit();
-}
+OC_JSON::checkLoggedIn();
$card = OC_Contacts_VCard::find( $id );
if( $card === false ){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Contact could not be found.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Contact could not be found.'))));
exit();
}
$addressbook = OC_Contacts_Addressbook::find( $card['addressbookid'] );
if( $addressbook === false || $addressbook['userid'] != OC_USER::getUser()){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your contact.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your contact.'))));
exit();
}
$vcard = OC_Contacts_VCard::parse($card['carddata']);
// Check if the card is valid
if(is_null($vcard)){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('vCard could not be read.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('vCard could not be read.'))));
exit();
}
@@ -59,7 +56,7 @@ for($i=0;$i<count($vcard->children);$i++){
}
}
if(is_null($line)){
- echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
+ OC_JSON::error(array('data' => array( 'message' => $l10n->t('Information about vCard is incorrect. Please reload the page.'))));
exit();
}
@@ -70,4 +67,4 @@ $tmpl->assign('checksum',$checksum);
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line]));
$page = $tmpl->fetchPage();
-echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));
+OC_JSON::success(array('data' => array( 'page' => $page )));
diff --git a/apps/files_sharing/ajax/getitem.php b/apps/files_sharing/ajax/getitem.php
index 249af6cfa31..e7bda0f6144 100644
--- a/apps/files_sharing/ajax/getitem.php
+++ b/apps/files_sharing/ajax/getitem.php
@@ -30,7 +30,7 @@ while ($source != "" && $source != "/" && $source != "." && $source != $userDire
$source = dirname($source);
}
if (!empty($users)) {
- echo json_encode($users);
+ OC_JSON::encodedPrint($users);
}
-?> \ No newline at end of file
+?>
diff --git a/apps/files_sharing/ajax/userautocomplete.php b/apps/files_sharing/ajax/userautocomplete.php
index 6da7afb659c..a3158cf72d6 100644
--- a/apps/files_sharing/ajax/userautocomplete.php
+++ b/apps/files_sharing/ajax/userautocomplete.php
@@ -3,10 +3,8 @@ $RUNTIME_NOAPPS = true;
require_once('../../../lib/base.php');
-if (!OC_User::isLoggedIn()) {
- echo json_encode(array("status" => "error", "data" => array("message" => "Authentication error")));
- exit();
-}
+OC_JSON::checkLoggedIn();
+
$users = array();
$ocusers = OC_User::getUsers();
$self = OC_User::getUser();
@@ -23,6 +21,6 @@ foreach ($groups as $group) {
$users[] = "<option value='".$group."'>".$group."</option>";
}
$users[] = "</optgroup>";
-echo json_encode($users);
+OC_JSON::encodedPrint($users);
?>
diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php
index c5909e4c78b..84ee6334463 100644
--- a/apps/media/ajax/api.php
+++ b/apps/media/ajax/api.php
@@ -67,7 +67,7 @@ if($arguments['action']){
$data['artists']=OC_MEDIA_COLLECTION::getArtists();
$data['albums']=OC_MEDIA_COLLECTION::getAlbums();
$data['songs']=OC_MEDIA_COLLECTION::getSongs();
- echo json_encode($data);
+ OC_JSON::encodedPrint($data);
break;
case 'scan':
OC_DB::beginTransaction();
@@ -81,13 +81,13 @@ if($arguments['action']){
echo (OC_MEDIA_SCANNER::scanFile($arguments['path']))?'true':'false';
break;
case 'get_artists':
- echo json_encode(OC_MEDIA_COLLECTION::getArtists($arguments['search']));
+ OC_JSON::encodedPrint(OC_MEDIA_COLLECTION::getArtists($arguments['search']));
break;
case 'get_albums':
- echo json_encode(OC_MEDIA_COLLECTION::getAlbums($arguments['artist'],$arguments['search']));
+ OC_JSON::encodedPrint(OC_MEDIA_COLLECTION::getAlbums($arguments['artist'],$arguments['search']));
break;
case 'get_songs':
- echo json_encode(OC_MEDIA_COLLECTION::getSongs($arguments['artist'],$arguments['album'],$arguments['search']));
+ OC_JSON::encodedPrint(OC_MEDIA_COLLECTION::getSongs($arguments['artist'],$arguments['album'],$arguments['search']));
break;
case 'get_path_info':
if(OC_Filesystem::file_exists($arguments['path'])){
@@ -100,7 +100,7 @@ if($arguments['action']){
$song=OC_MEDIA_COLLECTION::getSong($songId);
$song['artist']=OC_MEDIA_COLLECTION::getArtistName($song['song_artist']);
$song['album']=OC_MEDIA_COLLECTION::getAlbumName($song['song_album']);
- echo json_encode($song);
+ OC_JSON::encodedPrint($song);
}
}
break;
@@ -129,7 +129,7 @@ if($arguments['action']){
OC_Filesystem::readfile($arguments['path']);
exit;
case 'find_music':
- echo json_encode(findMusic());
+ OC_JSON::encodedPrint(findMusic());
exit;
}
}
diff --git a/apps/media/ajax/autoupdate.php b/apps/media/ajax/autoupdate.php
index ac3d0650b4b..ad103d1c39b 100644
--- a/apps/media/ajax/autoupdate.php
+++ b/apps/media/ajax/autoupdate.php
@@ -35,5 +35,5 @@ if(defined("DEBUG") && DEBUG) {error_log((integer)$autoUpdate);}
OC_Preferences::setValue(OC_User::getUser(),'media','autoupdate',(integer)$autoUpdate);
-echo json_encode( array( "status" => "success", "data" => $autoUpdate));
-?> \ No newline at end of file
+OC_JSON::success(array('data' => $autoUpdate));
+?>
diff --git a/apps/media/tomahawk.php b/apps/media/tomahawk.php
index bf0c2c2a756..1db982a3504 100644
--- a/apps/media/tomahawk.php
+++ b/apps/media/tomahawk.php
@@ -77,5 +77,5 @@ foreach($songs as $song) {
'score' => (float)1.0
);
}
-echo json_encode($results);
-?> \ No newline at end of file
+OC_JSON::encodedPrint($results);
+?>