Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2011-09-24 00:22:59 +0400
committerBart Visscher <bartv@thisnet.nl>2011-09-26 00:19:28 +0400
commit17e631bc5e327514596ce8761fe7f93d414a8717 (patch)
treea2e6bed923a493988028adafaaebcab5b9bfbd39 /apps/calendar
parentdbddec9160338818009ec7020cec5a2b298aae7e (diff)
Use OC_JSON for json responses
Create OC_JSON class, for single point of creating json responses. No real logic change, this just cleans up the code a bit.
Diffstat (limited to 'apps/calendar')
-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
8 files changed, 21 insertions, 41 deletions
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);
?>