Skip to content

Commit

Permalink
add auto refresh subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
libasys committed Sep 13, 2015
1 parent 21278d9 commit 5e1ff55
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 65 deletions.
44 changes: 34 additions & 10 deletions controller/calendarcontroller.php
Expand Up @@ -34,8 +34,10 @@
use \OCP\AppFramework\Controller;
use \OCP\AppFramework\Http\JSONResponse;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Http\DataDownloadResponse;
use \OCP\IRequest;
use \OCP\IConfig;
use \OC\Files\View;

class CalendarController extends Controller {

Expand Down Expand Up @@ -486,10 +488,10 @@ public function setActiveCalendar($calendarid, $active) {

/**
* @NoAdminRequired
*@param integer $calendarid
*/
public function refreshSubscribedCalendar() {
$calendarid = (int)$this -> params('calendarid');

public function refreshSubscribedCalendar($calendarid) {

$calendar = CalendarApp::getCalendar($calendarid, false, false);
if (!$calendar) {
$params = ['status' => 'error', 'message' => 'permission denied'];
Expand All @@ -504,6 +506,7 @@ public function refreshSubscribedCalendar() {
$opts = array($protocol => array('method' => 'POST', 'header' => "Content-Type: text/calendar\r\n", 'timeout' => 60));

$aMeta = $this -> stream_last_modified(trim($calendar['externuri']));

if ($aMeta['fileaccess'] === true) {
$context = stream_context_create($opts);
$file = file_get_contents($calendar['externuri'], false, $context);
Expand All @@ -512,27 +515,43 @@ public function refreshSubscribedCalendar() {
$import = new Import($file);
$import -> setUserID($this -> userId);
$import -> setTimeZone(CalendarApp::$tz);
$import -> setOverwrite(true);
//$import -> setOverwrite(false);
$import->setCheckModifiedDate(true);
$import->setImportFromUri(true);
$import -> setCalendarID($calendarid);
try {
$import -> import();

$importCount = $import->getCountImport();

$params = ['status' => 'success', 'refresh' => $calendarid,'count' => $importCount ];
$response = new JSONResponse($params);
return $response;

} catch (Exception $e) {
$params = ['status' => 'error', 'message' => $this -> l10n -> t('Import failed')];
$params = ['status' => 'error', 'message' => (string)$this -> l10n -> t('Import failed')];
$response = new JSONResponse($params);
return $response;

}
}else{
$params = ['status' => 'error', 'message' =>(string)$this->l10n-> t('Import failed') ];
$response = new JSONResponse($params);
return $response;
}
}else{
$this->addBirthdays($this->userId,(int)$calendarid);
$params = ['status' => 'success', 'refresh' => $calendarid, ];
$response = new JSONResponse($params);
return $response;
}

$params = ['status' => 'success', 'refresh' => $calendarid, ];
$response = new JSONResponse($params);
return $response;


}



/**
* @NoAdminRequired
* @param string $importurl
Expand Down Expand Up @@ -573,14 +592,18 @@ public function checkImportUrl($importurl){
}

}
$opts = array($protocol => array('method' => 'POST', 'header' => "Content-Type: text/calendar\r\n", 'timeout' => 60));
$opts = array($protocol => array('method' => 'GET', 'header' => "Content-Type: text/calendar\r\n", 'timeout' => 60));
$bError = false;


if ($bExistUri === true) {
$context = stream_context_create($opts);


try {
$file = file_get_contents($newUrl, false, $context);
//\OCP\Util::writeLog('calendarplus','FILE: '.$newUrl, \OCP\Util::DEBUG);

$import = new \OCA\CalendarPlus\Import($file);
$import->setUserID($this->userId);
$guessedcalendarname = \OCP\Util::sanitizeHTML($import->guessCalendarName());
Expand Down Expand Up @@ -820,9 +843,10 @@ private function stream_last_modified($url) {

}
}
//\OCP\Util::writeLog('calendarplus','CONTENTTYPE: '.$meta['wrapper_data'][$j], \OCP\Util::DEBUG);

if (strstr(strtolower($meta['wrapper_data'][$j]), 'last-modified')) {
$modtime = substr($meta['wrapper_data'][$j], 15);

}
}
fclose($fp);
Expand Down
4 changes: 4 additions & 0 deletions controller/importcontroller.php
Expand Up @@ -172,6 +172,10 @@ public function importEvents() {
$import->setTimeZone(CalendarApp::$tz);
$import->enableProgressCache();
$import->setProgresskey($pProgresskey);

$bUriImport = ($pIsSub ==='true' ? true : false);
$import->setImportFromUri($bUriImport);

if(!$import->isValid()) {
$params = [
'status' => 'error',
Expand Down
75 changes: 46 additions & 29 deletions js/alarm.js
Expand Up @@ -35,9 +35,7 @@ OC.search.resultTypes['contacts']=t('kontakte','Contacts');
})(jQuery);

$(document).ready(function(){
if($('#reminderBox').length === 0){
$('<div id="reminderBox" style="width:0;height:0;top:0;left:0;z-index:300;display:none;">').appendTo($('body')[0]);
}

liveReminderCheck();

});
Expand All @@ -61,20 +59,35 @@ function liveReminderCheck(){
if($('#fullcalendar').length === 1 && CalendarPlus.calendarConfig != null){
//calId = ctag
myRefChecker=CalendarPlus.calendarConfig['myRefreshChecker'];
//CalendarPlus.UI.loading(true);
//shows all 5 minutes
if(CalendarPlus.UI.timerRun === 5 ){
$.each(CalendarPlus.calendarConfig['mycalendars'], function(i, elem) {
if(elem.issubscribe === 1 && elem.uri !== 'bdaycpltocal_'+oc_current_user){

CalendarPlus.UI.Calendar.autoRefreshCalendar(elem.id);

}
});
CalendarPlus.UI.timerRun = 0;
if(CalendarPlus.UI.isRefresh === true) {
$('#fullcalendar').fullCalendar('refetchEvents');
CalendarPlus.UI.isRefresh = false;
}

}


}

$.post(url,{EvSource:myRefChecker},function(jasondata){

if($('#fullcalendar').length === 1){
if(jasondata.refresh !== 'onlyTimeLine'){

CalendarPlus.calendarConfig['myRefreshChecker'][jasondata.refresh.id]=jasondata.refresh.ctag;
if(CalendarPlus.UI.timerLock == false) {
$('#fullcalendar').fullCalendar('refetchEvents');
}
if(CalendarPlus.UI.timerLock == true) {
CalendarPlus.UI.timerLock=false;
}
//CalendarPlus.calendarConfig['myRefreshChecker'][jasondata.refresh.id]=jasondata.refresh.ctag;


}


Expand All @@ -90,9 +103,10 @@ function liveReminderCheck(){

if($('#fullcalendar').length === 1){
CalendarPlus.Util.setTimeline();

CalendarPlus.UI.timerRun ++;
}


}, 60000);


Expand All @@ -101,31 +115,34 @@ function liveReminderCheck(){

var openReminderDialog=function(data){
//var output='<audio autoplay="autoplay"><source src="'+OC.filePath('calendar','audio', 'ring.ogg')+'"></source><source src="'+OC.filePath('calendar','audio','ring.mp3')+'"></source></audio>';

$('body').append('<div id="reminderBox"></div>');

var output='';
$.each(data, function(i, elem) {
output+='<b>'+elem.startdate+'</b><br />';
output+='<i class="ioc ioc-'+elem.icon+'"></i> <a href="'+elem.link+'">'+elem.summary+'</a><br />';

});
$( "#reminderBox" ).html(output);
$.playSound(oc_webroot+'/apps/calendarplus/audio/ring');
$( "#reminderBox" ).dialog({
resizable: false,
title : t('calendarplus', 'Reminder Alert'),
width:350,
height:200,
modal: true,
buttons:
[ { text:t('calendarplus', 'Ready'), click: function() {
$( "#reminderBox" ).html('');
$( this ).dialog( "close" );
}
}
],

});
$.playSound(oc_webroot+'/apps/calendarplus/audio/ring');
$('#reminderBox').html(output).ocdialog({
modal: true,
closeOnEscape: true,
title : t('calendarplus', 'Reminder Alert'),
height: 'auto', width: 'auto',
buttons:
[{
text:t('calendarplus', 'Ok'), click: function() {
$(this).ocdialog("close");
},
defaultButton: true
}],
close: function(/*event, ui*/) {
$(this).ocdialog('destroy').remove();
$('#reminderBox').remove();

},
});


return false;

Expand Down
19 changes: 12 additions & 7 deletions js/loaderimport.js
Expand Up @@ -56,25 +56,29 @@ CalendarPlus.Import = {
},
close: function(){
CalendarPlus.Import.reset();
$('#calendar_import_dialog').dialog('destroy').remove();
$('#calendar_import_dialog').ocdialog('close');
$('#calendar_import_dialog').ocdialog('destroy').remove();
$('#calendar_import_dialog').remove();
},
init: function(){
//init dialog

$('#calendar_import_dialog').dialog({
width : 500,
resizable: false,
close : function() {
$('#calendar_import_dialog').ocdialog({
modal: true,
closeOnEscape: true,
height: 'auto', width:500,
close : function() {
CalendarPlus.Import.Dialog.close();
}
}
});


//init buttons
$('#calendar_import_done').click(function(){
CalendarPlus.Import.Dialog.close();
});
$('#calendar_import_submit').click(function(){
CalendarPlus.Import.Core.process();
return false;
});

if(CalendarPlus.Import.Store.isSub === true){
Expand All @@ -96,6 +100,7 @@ CalendarPlus.Import = {
$('#calendar_import_mergewarning').click(function(){
$('#calendar_import_newcalendar').attr('value', $('#calendar_import_availablename').val());
CalendarPlus.Import.Dialog.mergewarning($('#calendar_import_newcalendar').val());
return false;
});
$('#calendar_import_calendar').change(function(){
if($('#calendar_import_calendar option:selected').val() == 'newcal'){
Expand Down

0 comments on commit 5e1ff55

Please sign in to comment.