Merge branch 'master' of https://github.com/redmatrix/redmatrix
Conflicts: util/messages.po
This commit is contained in:
commit
3269d4632f
@ -90,6 +90,7 @@ function format_event_ical($ev) {
|
||||
$o .= "\nLOCATION:" . format_ical_text($ev['location']);
|
||||
if($ev['description'])
|
||||
$o .= "\nDESCRIPTION:" . format_ical_text($ev['description']);
|
||||
$o .= "\nUID:" . $ev['event_hash'] ;
|
||||
$o .= "\nEND:VEVENT\n";
|
||||
|
||||
return $o;
|
||||
@ -208,6 +209,7 @@ function event_store_event($arr) {
|
||||
$arr['type'] = (($arr['type']) ? $arr['type'] : 'event' );
|
||||
$arr['event_xchan'] = (($arr['event_xchan']) ? $arr['event_xchan'] : '');
|
||||
|
||||
|
||||
// Existing event being modified
|
||||
|
||||
if($arr['id'] || $arr['event_hash']) {
|
||||
@ -275,7 +277,11 @@ function event_store_event($arr) {
|
||||
|
||||
// New event. Store it.
|
||||
|
||||
$hash = random_string();
|
||||
|
||||
if(array_key_exists('external_id',$arr))
|
||||
$hash = $arr['external_id'];
|
||||
else
|
||||
$hash = random_string();
|
||||
|
||||
$r = q("INSERT INTO event ( uid,aid,event_xchan,event_hash,created,edited,start,finish,summary,description,location,type,
|
||||
adjust,nofinish,allow_cid,allow_gid,deny_cid,deny_gid)
|
||||
@ -364,6 +370,84 @@ function event_addtocal($item_id, $uid) {
|
||||
}
|
||||
|
||||
|
||||
function parse_ical_file($f,$uid) {
|
||||
require_once('library/ical.php');
|
||||
$ical = new ICal($f);
|
||||
if($ical) {
|
||||
$events = $ical->events();
|
||||
if($events) {
|
||||
foreach($events as $ev) {
|
||||
logger('event parsed: ' . print_r($ev,true), LOGGER_ALL);
|
||||
event_import_ical($ev,$uid);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function event_import_ical($ical, $uid) {
|
||||
|
||||
$c = q("select * from channel where channel_id = %d limit 1",
|
||||
intval($uid)
|
||||
);
|
||||
|
||||
if(! $c)
|
||||
return false;
|
||||
|
||||
$channel = $c[0];
|
||||
$ev = array();
|
||||
|
||||
if($ical['CREATED'])
|
||||
$ev['created'] = datetime_convert('UTC','UTC',$ical['CREATED']);
|
||||
if($ical['LAST-MODIFIED'])
|
||||
$ev['edited'] = datetime_convert('UTC','UTC',$ical['LAST-MODIFIED']);
|
||||
if($ical['LOCATION'])
|
||||
$ev['location'] = $ical['LOCATION'];
|
||||
if($ical['DESCRIPTION'])
|
||||
$ev['description'] = $ical['DESCRIPTION'];
|
||||
if($ical['SUMMARY'])
|
||||
$ev['summary'] = $ical['SUMMARY'];
|
||||
if($ical['DTEND'])
|
||||
$ev['finish'] = datetime_convert('UTC','UTC', $ical['DTEND']);
|
||||
else
|
||||
$ev['nofinish'] = 1;
|
||||
$ev['start'] = datetime_convert('UTC','UTC',$ical['DTSTART']);
|
||||
if(substr($ical['DTSTART'],-1) === 'Z')
|
||||
$ev['adjust'] = 1;
|
||||
|
||||
if($ical['UID']) {
|
||||
$r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
|
||||
dbesc($ical['UID']),
|
||||
intval($arr['uid'])
|
||||
);
|
||||
if($r)
|
||||
$ev['event_hash'] = $ical['UID'];
|
||||
else
|
||||
$ev['external_id'] = $ical['UID'];
|
||||
}
|
||||
|
||||
if($ical['SUMMARY'] && $ical['DTSTART']) {
|
||||
$ev['event_xchan'] = $channel['channel_hash'];
|
||||
$ev['uid'] = $channel['channel_id'];
|
||||
$ev['account'] = $channel['channel_account_id'];
|
||||
$ev['private'] = 1;
|
||||
|
||||
logger('storing event: ' . print_r($ev,true), LOGGER_ALL);
|
||||
$event = event_store_event($ev);
|
||||
if($event) {
|
||||
$item_id = event_store_item($ev,$event);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function event_store_item($arr, $event) {
|
||||
|
||||
require_once('include/datetime.php');
|
||||
|
@ -3376,19 +3376,18 @@ function post_is_importable($item,$abook) {
|
||||
if(! $item)
|
||||
return false;
|
||||
|
||||
if((! $abook['abook_incl']) && (! $abook['abook_excl']))
|
||||
if(! ($abook['abook_incl'] || $abook['abook_excl']))
|
||||
return true;
|
||||
|
||||
|
||||
require_once('include/html2plain.php');
|
||||
$text = prepare_text($item['body'],$item['mimetype']);
|
||||
$text = html2plain($text);
|
||||
|
||||
$lang = null;
|
||||
|
||||
if((strpos($abook['abook_incl'],'lang=') !== false) || (strpos($abook['abook_excl'],'lang=') !== false))
|
||||
if((strpos($abook['abook_incl'],'lang=') !== false) || (strpos($abook['abook_excl'],'lang=') !== false)) {
|
||||
$lang = detect_language($text);
|
||||
|
||||
}
|
||||
$tags = ((count($item['term'])) ? $item['term'] : false);
|
||||
|
||||
// exclude always has priority
|
||||
|
@ -13,6 +13,20 @@ function events_post(&$a) {
|
||||
if(! local_channel())
|
||||
return;
|
||||
|
||||
if(($_FILES) && array_key_exists('userfile',$_FILES) && intval($_FILES['userfile']['size'])) {
|
||||
$src = $_FILES['userfile']['tmp_name'];
|
||||
if($src) {
|
||||
$result = parse_ical_file($src,local_channel());
|
||||
if($result)
|
||||
info( t('Calendar entries imported.') . EOL);
|
||||
else
|
||||
notice( t('No calendar entries found.') . EOL);
|
||||
@unlink($src);
|
||||
}
|
||||
goaway(z_root() . '/events');
|
||||
}
|
||||
|
||||
|
||||
$event_id = ((x($_POST,'event_id')) ? intval($_POST['event_id']) : 0);
|
||||
$event_hash = ((x($_POST,'event_hash')) ? $_POST['event_hash'] : '');
|
||||
|
||||
@ -477,8 +491,8 @@ function events_content(&$a) {
|
||||
'$export' => array($a->get_baseurl()."/events/$y/$m/export",t('Export'),'',''),
|
||||
'$calendar' => cal($y,$m,$links, ' eventcal'),
|
||||
'$events' => $events,
|
||||
|
||||
|
||||
'$upload' => t('Upload'),
|
||||
'$submit' => t('Submit')
|
||||
));
|
||||
|
||||
if (x($_GET,'id')){ echo $o; killme(); }
|
||||
|
@ -1 +1 @@
|
||||
2015-07-23.1102
|
||||
2015-07-27.1106
|
||||
|
@ -3,6 +3,19 @@
|
||||
<h2>{{$title}}</h2>
|
||||
|
||||
|
||||
<button class="btn btn-xs btn-success btn-xs pull-right" title="{{$usage}}" onclick="openClose('event-upload-form');"><i class="icon-upload"></i> {{$upload}}</button>
|
||||
|
||||
<div id="event-upload-form" style="display:none;">
|
||||
<div class="section-content-tools-wrapper">
|
||||
<form action="events" enctype="multipart/form-data" method="post" name="event-upload-form" id="event-upload-form">
|
||||
<div class="form-group">
|
||||
<input id="event-upload-choose" type="file" name="userfile" />
|
||||
</div>
|
||||
<button id="dbtn-submit" class="btn btn-primary btn-sm" type="submit" name="submit" >{{$submit}}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="export-event-link"><button class="btn btn-default btn-sm" onclick="exportDate(); return false;" >{{$export.1}}</button></div>
|
||||
<div id="new-event-link"><button class="btn btn-default btn-sm" onclick="window.location.href='{{$new_event.0}}'; return false;" >{{$new_event.1}}</button></div>
|
||||
|
||||
|
Reference in New Issue
Block a user