$specs) {
$amr_fields_needed[] = $fld;
}
}
//else echo 'WHY EMPTY';
foreach ($amr_event_columns as $col => $fields) {
foreach ($fields as $field =>$data) {
if (!in_array($field, // these are calculated or derived fields
array(
'SUMMARY',
'DESCRIPTION',
'subscribeevent',
'subscribeseries',
'addevent',
'post_tag',
'category')))
$amr_fields_needed[] = $field;
}
}
foreach ($amr_fields_needed as $i=>$fld)
$amr_fields_needed[$i] = '_'.$fld;
if (function_exists('ical_location_values') // is in amr-events for events with locations
and (in_array('_GEO', $amr_fields_needed) or
in_array('_map', $amr_fields_needed) or
in_array('_place', $amr_fields_needed) or
in_array('_LOCATION', $amr_fields_needed )))
{
$locationfields = ical_location_values();
$amr_fields_needed = array_merge ($amr_fields_needed , $locationfields );
}
// what if using other plugin ? eg geomashup
$amr_fields_needed = array_merge ($amr_fields_needed ,
array('_VEVENT',
'_tztype',
'_timezone',
'_allday',
'_DTSTART',
'_EventDate',
'_RRULE',
'_EXDATE',
'_RDATE',
'_DURATION',
'_last'));
//var_dump($amr_fields_needed);
return $amr_fields_needed;
}
function amr_create_date_time ($datetimestring, $tzobj) { // date time create with exception trap to avoid fatal errors
try { $dt = new DateTime($datetimestring, $tzobj); }
catch(Exception $e) {
$text = '
Unable to create DateTime object from '.$datetimestring.'
'.$e->getMessage();
amr_tell_admin_the_error ($text);
return (false);
}
return ($dt);
}
function amr_newDateTime($text='') { // create new datetime object with the global timezone
// because wordpress insists that the php default must stay as UTC
global $amr_globaltz;
//$d = new DateTime($text,$amr_globaltz);
$d = amr_create_date_time($text,$amr_globaltz); // traps exceptions
return ($d);
}
function amr_a_nested_event_shortcode () { // in case we have a dummy - yes truly
global $amr_been_here;
if (empty($amr_been_here) or (!($amr_been_here))) {
$amr_been_here = true;
return false;
}
else {
echo '
'.$text.'
';
}
function amr_external_url ($url) {
// if it is an external url, then open in new window
if (stristr( $url, get_bloginfo('url'))) {
return false;
}
else return(true);
}
function amr_debug_time () { // track php runtime if debugging
global $amr_start_time_track,$amr_last_time_track;
if (isset($_GET['debugtime'])) {
$amr_start_time_track = microtime();
$amr_last_time_track = $amr_start_time_track;
echo '
Starting tracking now after plugins loaded '.$amr_start_time_track;
echo '
Note: measuring runtime may affect the runtime too, as will debug messages. if using ics file, check timing on refresh &refresh';
}
}
function amr_track_run_time ($text='') { // track php runtime if debugging
global $amr_start_time_track;
global $amr_last_time_track;
if (isset($_GET['debugtime'])) {
$end = microtime();
$startt = (float) array_sum(explode(' ',$amr_start_time_track));
$endt = (float) array_sum(explode(' ',$end));
$lastt = (float) array_sum(explode(' ',$amr_last_time_track));
$amr_last_time_track = $end;
echo '
Since start '. sprintf("%.4f", ($endt-$startt))." seconds. Since last:"
.sprintf("%.4f", ($endt-$lastt)).' seconds. In "'.$text.'"';
}
}
function amr_memory_convert($size) {
$unit=array('b','kb','mb','gb','tb','pb');
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
function amrical_mem_debug($text) {
if (isset($_GET['memdebug'])) {
$mem = memory_get_usage (true);
$peak = memory_get_peak_usage (true);
echo '
memory: '.amr_memory_convert($mem).' peak:'.amr_memory_convert($peak).' '.$text;
//echo '
memory: '.$mem.' peak:'.$peak.' '.$text;
}
if (isset($_GET['debugtime'])) { amr_track_run_time($text);}
}
if (!function_exists('esc_textarea') ) {
function esc_textarea( $text ) {
$safe_text = htmlspecialchars( $text, ENT_QUOTES );
}
}
function amr_check_for_wpml_lang_parameter ($link) {
if (isset($_REQUEST['lang'])) {
$lang = $_REQUEST['lang'];
$link = remove_query_arg( 'lang', $link ); //is there a wpml bug ? or wp bug, we are getting lang twice
$link = add_query_arg( 'lang', $lang, $link );
}
return ($link);
}
// NOT IN USE ?
/*function amr_array_merge_recursive_distinct ( array &$array1, array &$array2 ) { /* array 2 will replace array 1*/
/*
$merged = $array1;
foreach ( $array2 as $key => &$value ) {
if ( is_array ( $value ) && isset ( $merged [$key] ) && is_array ( $merged [$key] ) ) {
$merged [$key] = amr_array_merge_recursive_distinct ( $merged [$key], $value );
}
else {
$merged [$key] = $value;
}
}
return $merged;
}
*/
function amr_clean_link() { /* get cleaned up version of current url remove other parameters */
global $page_id;
global $wp;
//$link = add_query_arg( $wp->query_string, '', home_url( $wp->request ) ); this is now returning a pagename query parameter on top of the permalink, which breaks things
$link = get_permalink();
/* not sure if we still need, but some folks with main eventlist on home page with other weird stuff on frontpage had problems before, so keeping for now */
if (is_front_page() and (!empty($page_id))) { /* don't use if page_id = 0 v4.0.28*/
// use page_id not $post->id, because if have a post on home page too $post gets overwritten
$link = add_query_arg(array('page_id'=>$page_id),$link);
}
return ($link);
}
function amr_allowed_html () {
// return ('
'
.''
);
}
function amrical_mimic_meta_box($id, $title, $callback , $toggleable = true) {
global $screen_layout_columns;
// $style = 'style="display:none;"';
$h = (2 == $screen_layout_columns) ? ' has-right-sidebar' : '';
echo '";
}
function amr_check_set_debug() { // obfuscate a bit so only admin or developer can run debug
if (isset($_GET["debug"]) ) /* for debug and support - calendar data is public anyway, so no danger*/
define('ICAL_EVENTS_DEBUG', true);
else
define('ICAL_EVENTS_DEBUG', false);
}
function amr_is_trying_to_help() { // obfuscate a bit so only admin or developer can run debug, &isme=mmdd sydney time
$tz = timezone_open('Australia/Sydney');
$now = date_create('now',$tz );
if (isset($_REQUEST['isme']) and ($_REQUEST['isme']=== $now->format('md'))) return true;
else return false;
}
?>