Sync plugins from current page
Signed-off-by: Adrian Nöthlich <git@promasu.tech>
This commit is contained in:
@@ -0,0 +1,229 @@
|
||||
<?php
|
||||
function amr_ical_list_tools() {
|
||||
|
||||
amr_list_export_form();
|
||||
|
||||
echo ausers_form_end();
|
||||
|
||||
amr_list_import_form(); // different form
|
||||
|
||||
}
|
||||
|
||||
function amr_ical_list_import_form () {
|
||||
global $aicaladminurl;
|
||||
|
||||
echo PHP_EOL.'<br /><br />';
|
||||
echo PHP_EOL.'<div id="icon-tools" class="icon32"><br/></div>'.PHP_EOL;
|
||||
echo PHP_EOL.'<h3>'.__('Import a list\'s settings','amr-ical-events-list').'</h3>';
|
||||
|
||||
// 201602 check if we are allowed to upload text file types
|
||||
$mimes = get_allowed_mime_types();
|
||||
$filetypeok = false;
|
||||
foreach ($mimes as $type => $mime) {
|
||||
if (strpos($type, 'txt') !== false) {
|
||||
$filetypeok = true;
|
||||
}
|
||||
}
|
||||
if (!$filetypeok) {
|
||||
echo '<p><b>!! '.__('This site does not allow filetype .txt to be uploaded.','amr-ical-events-list'). '</b> '
|
||||
.__('Please contact your wordpress administrator to request that it be added.','amr-ical-events-list').' '
|
||||
.__('Alternatively, change the file suffix to an allowed type eg: .odt in order to upload it.','amr-ical-events-list').'</p>';
|
||||
|
||||
}
|
||||
|
||||
|
||||
echo '<p><em>'.__('Imported settings must be from a compatible system.','amr-ical-events-list');
|
||||
echo ' '.__('Ensure any fields used by the list are in your database and have been "found".','amr-ical-events-list').'</em></p>';
|
||||
echo '<p id="async-upload-wrap">
|
||||
<form enctype="multipart/form-data" action="'.$ausersadminurl.'?page=ameta-admin-overview.php'.'" method="POST"'
|
||||
.' class="media-upload-form type-form validate html-uploader" id="file-form">'
|
||||
.'<input type="file" class="button" name="importfile">'
|
||||
.' <input type="submit" value="'.__('Import','amr-ical-events-list').'" name="import-list" class="button-primary">
|
||||
</form><!-- end import form -->
|
||||
</p>';
|
||||
|
||||
if (WP_DEBUG and !$filetypeok) {
|
||||
echo '<h3>'.__('Allowed mimetypes: ', 'amr-ical-events-list').'</h3>';
|
||||
echo '<p>';
|
||||
foreach ($mimes as $type => $mime) {
|
||||
echo $type.', ';
|
||||
}
|
||||
echo '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function amr_ical_list_export_form () {
|
||||
global $amain;
|
||||
global $aopt;
|
||||
global $ausersadminurl;
|
||||
|
||||
if (isset ($amain['names'])) {
|
||||
|
||||
echo PHP_EOL.'<br /><br />';
|
||||
echo PHP_EOL.'<div id="icon-tools" class="icon32"><br/></div>'.PHP_EOL;
|
||||
echo '<h3>';
|
||||
_e("Export a list's settings", 'amr-ical-events-list');
|
||||
echo '</h3>';
|
||||
|
||||
echo PHP_EOL.'<form id="export_list" action="'
|
||||
.$ausersadminurl.'?page=ameta-admin-overview.php'.'" method="POST"';
|
||||
echo PHP_EOL.'<input type="hidden" name="action" value="save" />';
|
||||
echo PHP_EOL.wp_nonce_field('amr-meta','amr-meta',true,false);
|
||||
|
||||
echo PHP_EOL."<p><select name='export-list-text'>";
|
||||
|
||||
foreach ($amain['names'] as $i => $name) {
|
||||
$export_text = htmlspecialchars(amr_ical_build_export($i));
|
||||
echo PHP_EOL.'<option value="'.$export_text.'">'.$i.' '.$name.'</option>';
|
||||
}
|
||||
echo PHP_EOL."</select>".PHP_EOL;
|
||||
echo '<input type="submit" value="'.__('Export','amr-ical-events-list').'" name="export-list" class="button-primary"></p> ';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function amr_ical_main_to_export () { // define the list of overview settings to export
|
||||
return array(
|
||||
// we have a historically weird structure so we have to do it this way until we risk updating
|
||||
'sortable',
|
||||
'names',
|
||||
'html_type',
|
||||
'public' ,
|
||||
'list_avatar_size',
|
||||
'list_rows_per_page',
|
||||
'show_search',
|
||||
'show_perpage',
|
||||
'show_pagination',
|
||||
'show_headings',
|
||||
'show_csv',
|
||||
'filterable',
|
||||
'show_refresh',
|
||||
'customnav' );
|
||||
}
|
||||
|
||||
function amr_ical_build_export($list) {
|
||||
global $amain, $aopt;
|
||||
|
||||
if (empty ($aopt)) $aopt = ausers_get_option('amr-ical-events-list');
|
||||
|
||||
$data = array();
|
||||
$data ['version'] = $amain['version']; //
|
||||
$toexport = amr_main_to_export ();
|
||||
foreach ($toexport as $text) {
|
||||
if (isset($amain[$text][$list]))
|
||||
$data[$text] = $amain[$text][$list];
|
||||
}
|
||||
|
||||
if (isset ($aopt['list']))
|
||||
$data['list'] = $aopt['list'][$list];
|
||||
|
||||
$content = serialize($data);
|
||||
return($content);
|
||||
|
||||
}
|
||||
|
||||
function amr_ical_handle_export() {
|
||||
|
||||
|
||||
if ( isset( $_POST['export-list'] ) and isset( $_POST['export-list-text'] ) ) {
|
||||
check_admin_referer('amr-meta','amr-meta');
|
||||
|
||||
$filename = sanitize_title(get_bloginfo('name'))."-amr-users-list.txt";
|
||||
if (amr_is_network_admin()) $filename = 'network-'.$filename;
|
||||
$content = htmlspecialchars_decode($_POST['export-list-text']);
|
||||
header("Content-Description: File Transfer");
|
||||
header("Content-type: application/txt");
|
||||
header('Content-Disposition: attachment; filename="'.$filename.'"');
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: 0");
|
||||
|
||||
echo $content;
|
||||
die();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function amr_ical_handle_import() {
|
||||
global $amain, $aopt;
|
||||
|
||||
if ( isset( $_POST['import-list'] ) ) {
|
||||
// require_once(ABSPATH . 'wp-admin/includes/admin.php');
|
||||
if (empty($_FILES) ) {
|
||||
amr_users_message('No file specified','amr-ical-events-list');
|
||||
return;
|
||||
}
|
||||
if (empty($_FILES['importfile'])) {
|
||||
amr_users_message('Problem in upload','amr-ical-events-list');
|
||||
return;
|
||||
}
|
||||
|
||||
$file = $_FILES['importfile'];
|
||||
|
||||
$uploaded = wp_handle_upload($file, array('test_form' => FALSE));
|
||||
|
||||
|
||||
if ( is_wp_error($uploaded) ) {
|
||||
$errors['upload_error'] = $uploaded['error'];
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
amr_users_message('There was an error uploading your file.','amr-ical-events-list');
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($uploaded['file'])) {
|
||||
amr_users_message('There was an error uploading your file.','amr-ical-events-list'); // could be file mime type is not allowed 20160207
|
||||
return;
|
||||
}
|
||||
|
||||
$content = file_get_contents($uploaded['file']);
|
||||
|
||||
$data = unserialize(stripslashes($content));
|
||||
|
||||
//$data = unserialize($content);
|
||||
|
||||
if ((!is_array($data)) or (!isset($data['version']) )) {
|
||||
echo '<div class="error"><p>';
|
||||
_e('Invalid data in settings file','amr-ical-events-list');
|
||||
echo '</p></div';
|
||||
die;
|
||||
}
|
||||
if (version_compare($data['version'], $amain['version'], '==') ) {
|
||||
amr_users_message(sprintf(__('Your plugin version is %s. Imported settings are from plugin version: %s' ,'amr-ical-events-list'),
|
||||
$amain['version'],
|
||||
$data['version'])
|
||||
.' Yay!');
|
||||
}
|
||||
else {
|
||||
amr_users_message(sprintf(__('Your plugin version is %s, BUT imported settings are from plugin version: %s','amr-ical-events-list' ),
|
||||
$amain['version'],
|
||||
$data['version'])
|
||||
.' '.__('Please test thoroughly.','amr-ical-events-list'));
|
||||
}
|
||||
|
||||
|
||||
$toimport = amr_main_to_export(); // get the list of overview settings
|
||||
|
||||
$amain['names'][] = 'justimported';
|
||||
foreach ($amain['names'] as $index => $name) {
|
||||
if ($name == 'justimported' ) {
|
||||
$thisindex = $index;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($toimport as $setting) {
|
||||
if (isset($data[$setting]))
|
||||
$amain[$setting][$thisindex] = $data[$setting];
|
||||
}
|
||||
|
||||
if (isset($data['list'])) $aopt ['list'][$thisindex] = $data['list']; // do we need this??
|
||||
|
||||
ausers_update_option('amr-ical-events-list',$aopt);
|
||||
ausers_update_option('amr-users-main',$amain);
|
||||
|
||||
amr_users_message(sprintf(__('List %s will be saved with imported data','amr-ical-events-list'),$thisindex));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,806 @@
|
||||
<?php
|
||||
/**
|
||||
* Display calendar with days that have posts as links.
|
||||
*
|
||||
* The calendar is cached, which will be retrieved, if it exists. If there are
|
||||
* no posts for the month, then it will not be displayed.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param bool $initial Optional, default is true. Use initial calendar names.
|
||||
* @param bool $echo Optional, default is true. Set to false for return.
|
||||
*/
|
||||
|
||||
function amr_get_events_in_months_format ($events, $months, $start) {
|
||||
|
||||
$bunchesofevents= array();
|
||||
// prepare the months array so we show a calendar even if no events
|
||||
$dummydate = new Datetime(); //if cloning dont need tz
|
||||
$dummydate = clone $start ;
|
||||
// prepare the containers one per day
|
||||
for ($i = 1; $i <= $months; $i++) {
|
||||
$yearmonth = $dummydate->format('Ym'); //numerical so do not need amr_date_format
|
||||
$bunchesofevents[$yearmonth] = array();
|
||||
date_modify($dummydate, '+1 month');
|
||||
}
|
||||
|
||||
// assign events to the box of their year and month
|
||||
if (!empty ($events)) {
|
||||
foreach ($events as $event) {
|
||||
|
||||
//$yearmonth = $event['EventDate']->format('Ym'); //numerical so do not need amr_date_format
|
||||
if (empty ($event['dummyYMD'])) {
|
||||
if (ICAL_EVENTS_DEBUG) {
|
||||
echo '<br />Error in dummy YMD for multi day event'; var_dump($event);
|
||||
}
|
||||
}
|
||||
else $yearmonth = substr($event['dummyYMD'],0,6); // quicker?
|
||||
if (isset($bunchesofevents[$yearmonth])) // then we have generated dummy events past our end date, so stop
|
||||
$bunchesofevents[$yearmonth][] = $event;
|
||||
}
|
||||
}
|
||||
return ($bunchesofevents);
|
||||
}
|
||||
|
||||
function amr_prepare_day_titles ($titles, $liststyle) {
|
||||
|
||||
// if it is a largecalendar, then show info only
|
||||
$daylinktext = __('Go to events for this day only','amr-ical-events-list');
|
||||
|
||||
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false
|
||||
|| stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false
|
||||
|| stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
|
||||
$ak_title_separator = "\n";
|
||||
else
|
||||
$ak_title_separator = ', ';
|
||||
// if small calendar
|
||||
if ( $titles ) {
|
||||
foreach ( $titles as $day => $daywithtitles_array ) {
|
||||
if ($liststyle == 'largecalendar')
|
||||
$daytitles[$day] = $daylinktext;
|
||||
else {
|
||||
if (is_array($daywithtitles_array) )
|
||||
//$string = implode(',',$daywithtitles_array);
|
||||
$string = implode($ak_title_separator,$daywithtitles_array);
|
||||
else
|
||||
$string = $daywithtitles_array;
|
||||
|
||||
$daytitles[$day] = ($string );
|
||||
}
|
||||
}
|
||||
}
|
||||
else return;
|
||||
|
||||
return ($daytitles);
|
||||
}
|
||||
|
||||
function amr_get_events_in_weeks_format ($events, $weeks, $start) { // should be using dummmyYMD?
|
||||
global $amr_globaltz;
|
||||
$wkst = ical_get_weekstart(); // get the wp start of week
|
||||
|
||||
if (isset($_GET['debugwks'])) { echo '<br />Separate '.count($events).' events into weeks for '.$weeks.' weeks using wkst: '.$wkst;}
|
||||
|
||||
$weeksofevents= array();
|
||||
// prepare the months array so we show a calendar even if no events
|
||||
$dummydate = new Datetime(); //if cloning dont need tz
|
||||
$dummydate = clone $start ;
|
||||
$dummydate = amr_get_human_start_of_week($dummydate,$wkst);
|
||||
for ($i = 0; $i < $weeks; $i++) {
|
||||
$weekbeginning = $dummydate->format('Ymj'); //numerical so do not need amr_date_format
|
||||
if (empty ($firstweekbeginning) )
|
||||
$firstweekbeginning = $weekbeginning;
|
||||
if (isset($_GET['debugwks'])) {echo '<br />weekbeginning'.$weekbeginning; }
|
||||
$weeksofevents[$weekbeginning] = array();
|
||||
date_modify($dummydate, '+7 days');
|
||||
}
|
||||
|
||||
// assign events to the box of their year and month
|
||||
if (!empty ($events)) {
|
||||
foreach ($events as $event) {
|
||||
if (!empty($event['dummyYMD']) ) { // ahh need the dummy date, not the Event Date
|
||||
date_date_set( $dummydate,
|
||||
substr($event['dummyYMD'],0,4),
|
||||
substr($event['dummyYMD'],4,2),
|
||||
substr($event['dummyYMD'],6,2)
|
||||
);
|
||||
if (isset($_GET['debugwks'])) {echo '<br />date:'.$event['dummyYMD'];}
|
||||
$dummydate = amr_get_human_start_of_week ($dummydate , $wkst);
|
||||
$weekbeginning = $dummydate->format('Ymj');
|
||||
if (isset($_GET['debugwks'])) {echo '<br />start of week:'.$weekbeginning;}
|
||||
if (isset($weeksofevents[$weekbeginning])) {
|
||||
$weeksofevents[$weekbeginning][] = $event;
|
||||
}
|
||||
else { // the week beginning is not in our current set - might be a multi day that started the previous week or even earlier
|
||||
if (isset($_GET['debugwks'])) {
|
||||
echo '<br />No week begin of '.$weekbeginning.' for ? '.$dummydate->format('c').' '.$event['SUMMARY'];
|
||||
//$weeksofevents[$weekbeginning][] = $event; // assign our multi day to first week
|
||||
//var_dump($event);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if (isset($_GET['debugwks'])) {echo '<br />event with no dummy date'; var_dump($event);}
|
||||
}
|
||||
}
|
||||
if (isset($_GET['debugwks'])) {
|
||||
echo '<br />Have dates for:'.count($weeksofevents).' weeks';
|
||||
foreach ($weeksofevents as $i => $bunchevents) {
|
||||
echo '<br />'.$i.' '.count($bunchevents);
|
||||
foreach($bunchevents as $i => $e) {
|
||||
echo '<br /> '.$e['EventDate']->format('Ymd'); //numerical so do not need amr_date_format
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ($weeksofevents);
|
||||
}
|
||||
|
||||
function amr_events_as_calendar($liststyle, $events, $id, $class='', $initial = true) { /* startingpoint was wp calendar */
|
||||
|
||||
global $amr_options, $amr_listtype, $amr_limits, $amrW;
|
||||
global $amr_globaltz;
|
||||
global $change_view_allowed;
|
||||
global $wpdb, $wp_locale;
|
||||
global $amr_calendar_url;
|
||||
global $amr_event_columns; //20151018
|
||||
|
||||
$empty = ' ';
|
||||
|
||||
$link = amr_get_day_link_stem(); // get the daylink stem
|
||||
|
||||
|
||||
// --- Note that if months set, then events will have started from beg of month */
|
||||
|
||||
$months = 1;
|
||||
$weeks = 2; // as default
|
||||
if (isset ($amr_limits['months'])) {
|
||||
$months = $amr_limits['months']; //may need later on if we are going to show multiple boxes on one page
|
||||
$weeks = 0;
|
||||
}
|
||||
else if (isset ($amr_limits['weeks'])) {
|
||||
$weeks = $amr_limits['weeks'];
|
||||
$months=0;
|
||||
}
|
||||
|
||||
// testing
|
||||
//$weeks = 2; // need weeks =2 else miss early ones
|
||||
// Let's figure out when we are
|
||||
|
||||
$start = amr_newDateTime();
|
||||
$today_day = $start->format('j');
|
||||
$today_month = $start->format('m');
|
||||
$today_year = $start->format('Y');
|
||||
|
||||
$start = clone $amr_limits['start'];
|
||||
$thismonth = $start->format('m');
|
||||
$thisyear = $start->format('Y');
|
||||
|
||||
if (!($liststyle === 'weekscalendar') )
|
||||
$start->setDate($thisyear, $thismonth, 1);
|
||||
else
|
||||
$start->setDate($thisyear, $thismonth, $start->format('j'));
|
||||
|
||||
// what was asked for in url (in case using small calendar as a selector )
|
||||
|
||||
if (!empty($_GET['start']) and is_numeric($_GET['start'] )) {
|
||||
$selected_day = substr($_GET['start'],6,2);
|
||||
$selected_month = substr($_GET['start'],4,2);
|
||||
$selected_year = substr($_GET['start'],0,4);
|
||||
}
|
||||
else {
|
||||
$selected_day = $today_day;
|
||||
$selected_month = $today_month ;
|
||||
$selected_year = $today_year;
|
||||
}
|
||||
|
||||
$events = amr_check_for_multiday_events ($events); // now have dummy multi day events added and field dummyYMD to use
|
||||
|
||||
|
||||
if (!($liststyle === 'weekscalendar'))
|
||||
$bunchesofevents = amr_get_events_in_months_format ($events, $months, $start);
|
||||
else
|
||||
$bunchesofevents = amr_get_events_in_weeks_format ($events, $weeks, $start);
|
||||
|
||||
if ($liststyle === 'weekscalendar') {
|
||||
if (!empty($amr_options['listtypes'][$amr_listtype]['format']['Day']))
|
||||
$caption_format = $amr_options['listtypes'][$amr_listtype]['format']['Day'];
|
||||
else
|
||||
$caption_format = 'j M';
|
||||
}
|
||||
else {
|
||||
if (!empty($amr_options['listtypes'][$amr_listtype]['format']['Month']))
|
||||
$caption_format = $amr_options['listtypes'][$amr_listtype]['format']['Month'];
|
||||
else $caption_format = 'F,Y';
|
||||
}
|
||||
|
||||
|
||||
// if ( isset($_GET['w']) ) $w = ''.intval($_GET['w']); /* what sthis for ?*/
|
||||
// week_begins = 0 stands for Sunday
|
||||
$week_begins= intval(get_option('start_of_week'));
|
||||
|
||||
if (($liststyle == 'smallcalendar') ) // for compatibility with wordpress default
|
||||
$class = ' widget_calendar ';
|
||||
if (empty($class))
|
||||
$class = $liststyle;
|
||||
else
|
||||
$class = $class.' '.$liststyle.' ';
|
||||
|
||||
if (!empty($amr_limits['show_views']) and $change_view_allowed)
|
||||
$views = amrical_calendar_views();
|
||||
else $views = '';
|
||||
$html = $views;
|
||||
$calendar_output = '';
|
||||
$multi_output = '';
|
||||
|
||||
if (empty($amr_limits['show_month_nav'])) {
|
||||
$navigation ='';
|
||||
$tfoot = '';
|
||||
}
|
||||
else {
|
||||
$navigation = amr_calendar_navigation($start, $months, $weeks, $liststyle); // include month year dropdown with links
|
||||
|
||||
if (($liststyle == 'smallcalendar' ) and ($months < 2)) {
|
||||
$tfoot = '<tfoot><tr><td class="calendar_navigation" colspan="7">'.$navigation.'</td></tr></tfoot>';
|
||||
}
|
||||
else {
|
||||
$tfoot = '';
|
||||
$html .= '<div class="calendar_navigation">'.$navigation.'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
$columns = $amr_event_columns; // 20151018 add so we can use easily//prepare_order_and_sequence ($amr_options['listtypes'][$amr_listtype]['compprop']);
|
||||
|
||||
//var_dump($columns);
|
||||
if (empty($columns)) return;
|
||||
|
||||
// now do for each month or week-------------------------------------------------------------------------------------------------------
|
||||
|
||||
if (isset($_GET['debugwks'])) echo '<br />Bunches of events = '.count($bunchesofevents).'<br />';
|
||||
foreach ($bunchesofevents as $ym => $bunchevents) { //also for weeks
|
||||
$thismonth= substr($ym,4,2);
|
||||
$thisyear = substr($ym,0,4);
|
||||
if (!($liststyle === 'weekscalendar'))
|
||||
$start->setDate($thisyear, $thismonth, 1);
|
||||
else
|
||||
$start->setDate($thisyear, $thismonth, $start->format('j'));
|
||||
|
||||
|
||||
if (isset($_GET['debugwks'])) echo '<br />weeks = '.$weeks.' '.$start->format('c');
|
||||
|
||||
$dayheaders = '<tr class="dayheaders">'.amr_calendar_colheaders($liststyle, $start).'</tr>';
|
||||
|
||||
if ($liststyle === 'weekscalendar') { // then cannot use thead as can only have one thead per table- else is data
|
||||
$calendar_caption = apply_filters('amr_events_table_caption',amr_weeks_caption($start));
|
||||
if (!empty($calendar_caption) )
|
||||
$calendar_caption = '<tr class="caption"><th colspan="7">'.$calendar_caption.'</th></tr>';
|
||||
$calendar_output .= '<tbody>';
|
||||
$calendar_output .= $dayheaders;
|
||||
}
|
||||
else {
|
||||
$calendar_caption = apply_filters('amr_events_table_caption',amr_date_i18n ($caption_format, $start));
|
||||
if (!empty($calendar_caption) )
|
||||
$calendar_caption = '<caption>' .$calendar_caption.'</caption>';
|
||||
$calendar_output .= '<table '.$id.' class="'.$class.'" >' . $calendar_caption;
|
||||
$calendar_output .= '<thead>'.$dayheaders.'</thead>'.$tfoot.'<tbody>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Get days with events
|
||||
|
||||
$titles = array();
|
||||
$eventsfortheday = array();
|
||||
$dayswithevents = array();
|
||||
|
||||
|
||||
if (ICAL_EVENTS_DEBUG) echo '<br />Bunch events count='.count($bunchevents);
|
||||
if (!empty ($bunchevents)) { // NOTE SINGULAR month
|
||||
// get the titles and events for each day
|
||||
$bunchevents = amr_sort_by_two_cols ('dummytime','MultiDay', $bunchevents); //20140805
|
||||
|
||||
foreach ($bunchevents as $event) {
|
||||
// convert eventdate to display timezone now for day of month assignment, other dates will be
|
||||
// converted to display timezone at display time.
|
||||
if (empty($event['EventDate'])) continue; // if no date, we cannot display anywhere
|
||||
if (isset($event['dummyYMD']) ) {
|
||||
|
||||
//$month = $event['EventDate']->format('m');
|
||||
//$month = substr($event['dummyYMD'],4,2); // quicker?
|
||||
//if (isset($_GET['debugwks'])) {echo '<br />Do we need monts=thismonth check?'.$month.' '.$thismonth;}
|
||||
|
||||
//if ($month == $thismonth) {
|
||||
// this allows to have agenda with more months and events cached
|
||||
//$day = $event['dummyYMD']->format('j');
|
||||
$day = ltrim(substr($event['dummyYMD'],6,2),'0'); // quicker?
|
||||
$dayswithevents[] = $day;
|
||||
// replace with listtype format
|
||||
$title = '';
|
||||
if (isset ($event['SUMMARY']) )
|
||||
$title = $event['SUMMARY'];
|
||||
if (is_array($title))
|
||||
$title = implode($title);
|
||||
$titles[$day][] = $title;
|
||||
//
|
||||
$eventsfortheday[$day][] = $event;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($dayswithevents))
|
||||
$dayswithevents = array_unique ($dayswithevents);
|
||||
|
||||
|
||||
if (!($liststyle === 'smallcalendar') or !function_exists('amr_events_customisable_small_calendar_daytitles') )
|
||||
$daytitles = amr_prepare_day_titles ($titles, $liststyle); // for large hover?
|
||||
|
||||
unset ($titles);
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
|
||||
if (!empty($eventsfortheday)) {
|
||||
if (ICAL_EVENTS_DEBUG) echo ' we have '.count($eventsfortheday).' days of events';
|
||||
foreach ( $eventsfortheday as $day => $devents ) {
|
||||
if (ICAL_EVENTS_DEBUG) echo '<br />Day ='.$day. ' with '.count($devents).' events ';
|
||||
$dayhtml[$day] = amr_list_one_days_events($devents, $columns);
|
||||
if (function_exists('amr_events_customisable_small_calendar_daytitles') and ($liststyle === 'smallcalendar') )
|
||||
$daytitles[$day] = amr_events_customisable_small_calendar_daytitles($devents, $columns);
|
||||
//if (isset($_GET['debugwks'])) echo '<br />Day: '.$day.' '.$dayhtml[$day];
|
||||
}
|
||||
}
|
||||
unset($eventsfortheday);
|
||||
// else echo 'EMPTY events forday';
|
||||
|
||||
/* ------See how much we should pad in the beginning */
|
||||
$week = 1;
|
||||
$calendar_output .= "\n\t".'<tr class="week week1">';
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
if ($liststyle === 'weekscalendar') {
|
||||
//if (isset ($weeks)) {
|
||||
$day1 = $start->format('j'); // set to start of week //The day of the month without leading zeros (1 to 31)
|
||||
//$daysinbunch = $day1+6;
|
||||
$daysinbunch = 7;
|
||||
}
|
||||
else {
|
||||
$pad = calendar_week_mod($start->format('w')-$week_begins);
|
||||
if ( 0 != $pad ) {
|
||||
$calendar_output .=
|
||||
"\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">'
|
||||
//.' '
|
||||
.$empty
|
||||
.'</td>';
|
||||
}
|
||||
$day1 = 1;
|
||||
$daysinbunch = $start->format('t'); //The number of days in the given month
|
||||
}
|
||||
if (isset($_GET['debugwks'])) echo '<br />Day 1= '.$day1;
|
||||
|
||||
$newrow = false;
|
||||
$nextdate = new Datetime(); //if cloning dont need tz
|
||||
$nextdate = clone $start;
|
||||
|
||||
// for ( $day = $day1; $day <= $daysinbunch; ++$day ) {
|
||||
for ( $i = 1; $i <= $daysinbunch; $i+=1 ) {
|
||||
if (isset($_GET['debugwks'])) echo '<br />i = '.$i;
|
||||
|
||||
// $calendar_output .= amr_handle_each_day ($thisyear, $thismonth, $day, $daytitles, $dayswithevents,$dayhtml);
|
||||
if ( isset($newrow) && $newrow ) {
|
||||
if ($week > 1) { // then we need to end the previous row
|
||||
$calendar_output .= AMR_NL.'</tr>';
|
||||
$calendar_output .= AMR_NL.'<tr class="week week'.$week.'">'.AMR_NL;
|
||||
}
|
||||
//else echo 'new row but $week = '.$week;
|
||||
}
|
||||
|
||||
$newrow = false;
|
||||
$lastinrow = '';
|
||||
// check if after this we need a new row eg if month calendar//
|
||||
// if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) {
|
||||
if ( 6 == calendar_week_mod($nextdate->format('w')-$week_begins) ) {
|
||||
$newrow = true;
|
||||
$lastinrow = ' endweek';
|
||||
$week = $week+1; // helps to balance out the multi month view
|
||||
}
|
||||
|
||||
/* wp code - can't we do better ? */
|
||||
//$datestring = $day.'-'.$thismonth.'-'.$thisyear; // must use hyphens for uk english dates, else it goes US
|
||||
//$dow = date('N',strtotime($datestring)); // does not like dates earlier than 1902
|
||||
$dow = $nextdate->format('N');
|
||||
$thisyear = $nextdate->format('Y');
|
||||
$thismonth = $nextdate->format('m');
|
||||
$day = $nextdate->format('j');
|
||||
|
||||
$hasevents = ' noevents ';
|
||||
if ((!empty ($amr_limits['day_links'])) and ($amr_limits['day_links']) and
|
||||
(!empty($daytitles[$day]) )) { // then we have events for that day, so can link to it
|
||||
$hasevents = ' hasevents ';
|
||||
$daylink = '<a class="daylink" href="'.
|
||||
htmlentities(amr_get_day_link($thisyear, $thismonth, $day, $link))
|
||||
. '" title="' . ($daytitles[$day]) . '">'.$day.'</a>';
|
||||
}
|
||||
else {
|
||||
$daylink = $day;
|
||||
}
|
||||
|
||||
if ( ($day == $today_day) &&
|
||||
($thismonth == $today_month) &&
|
||||
($thisyear == $today_year) )
|
||||
$today = ' today ';
|
||||
else $today = '';
|
||||
|
||||
if ( ($day == $selected_day) &&
|
||||
($thismonth == $selected_month) &&
|
||||
($thisyear == $selected_year) )
|
||||
$selected = ' selected ';
|
||||
else $selected = '';
|
||||
|
||||
$calendar_output .= '<td class="day'.$dow.$today.$selected.$hasevents.$lastinrow.'">';
|
||||
if (!($liststyle === 'weekscalendar') )
|
||||
$calendar_output .= '<div class="day">'.$daylink.'</div>';
|
||||
if ((!empty($dayswithevents) ) and ( in_array($day, $dayswithevents) )) {// any posts today?
|
||||
if (isset($_GET['debugwks'])) {echo '<br />Day='.$day;}
|
||||
// if (($liststyle == 'largecalendar')
|
||||
if (in_array ($liststyle, array('largecalendar','weekscalendar'))
|
||||
and (!empty($dayhtml[$day])))
|
||||
$calendar_output .= AMR_NL.$dayhtml[$day];
|
||||
}
|
||||
else {
|
||||
$calendar_output .= $empty; //' ';
|
||||
}
|
||||
$calendar_output .= '</td>';
|
||||
date_modify($nextdate, '+1 day');
|
||||
}
|
||||
|
||||
// now check if we need to pad to the end of the week
|
||||
// $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
|
||||
$pad = 6 - calendar_week_mod($dow - $week_begins) ;
|
||||
if ( $pad != 0 && $pad != 7 ) {
|
||||
$calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'"> '
|
||||
//.$dow.' '.$week_begins
|
||||
.'</td>';
|
||||
}
|
||||
else
|
||||
$week=$week-1;
|
||||
|
||||
if (($months > 1) and ($liststyle == 'smallcalendar')) { // pad so that they will all line up nicely in the multiview
|
||||
for ($w=$week; $week <=5; ++$week) {
|
||||
$calendar_output .=
|
||||
"\n\t".'</tr><tr><td class="pad" colspan="7" > </td>'
|
||||
."\n\t";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($liststyle === 'weekscalendar')
|
||||
$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t";
|
||||
else
|
||||
$calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
|
||||
$multi_output .= $calendar_output;
|
||||
$calendar_output = '';
|
||||
if (isset ($weeks)) date_modify($start, '+7 days');
|
||||
else date_modify($start, '+1 month');
|
||||
|
||||
} // for each bunch (eg month?)
|
||||
|
||||
if ($liststyle === 'weekscalendar') // if we are doing weekly, we want only one table so all will line up
|
||||
$multi_output = '<table '.$id.' class="'.$class.'" >'.$multi_output.'</table><!-- end weekly table -->';
|
||||
|
||||
$html .= $multi_output;
|
||||
return($html);
|
||||
}
|
||||
|
||||
function amr_list_one_days_events($events, $columns) { /* for the large calendar */
|
||||
global $amr_options,
|
||||
$amr_limits,
|
||||
$amr_listtype,
|
||||
$amrW,
|
||||
$amrtotalevents;
|
||||
|
||||
if (empty($events)) return;
|
||||
$html = '';
|
||||
|
||||
$no_cols = 1;
|
||||
/* --- setup the html tags ------need to have divs if want to allow html else must strip---------------------------------------- */
|
||||
$ev = AMR_NL.'<div class="event';
|
||||
$evc = '</div> ';
|
||||
|
||||
/* -- body code ------------------------------------------*/
|
||||
$groupedhtml = '';
|
||||
|
||||
// need to resort in case we have messed the timing up, keep the multi days to the top, hopefully in the order that they were in before.
|
||||
// done earlier // $events = amr_sort_by_two_cols ('dummytime','MultiDay', $events); //20140805
|
||||
|
||||
foreach ($events as $i => $e) { /* for each event, loop through the properties and see if we should display */
|
||||
|
||||
amr_derive_component_further ($e);
|
||||
if (!empty($e['Classes']))
|
||||
$classes = strtolower($e['Classes']);
|
||||
else $classes = '';
|
||||
$eventhtml = ''; /* each event on a new list */
|
||||
$colhtml = array();
|
||||
|
||||
|
||||
foreach ($columns as $col => $order) {
|
||||
$colhtml[$col] = '';
|
||||
foreach ($order as $field => $fieldconfig) { /* ie for one event, check how to order the bits */
|
||||
/* Now check if we should print the component or not, we may have an array of empty string - check our event has that value */
|
||||
if (isset($e[$field]))
|
||||
$v = amr_check_flatten_array ($e[$field]);
|
||||
else
|
||||
$v =null;
|
||||
if (!empty($v)) {
|
||||
// $col = $fieldconfig['Column'];
|
||||
$colhtml[$col] .=
|
||||
amr_format_value($v, $field, $e,
|
||||
$fieldconfig['Before'],
|
||||
$fieldconfig['After'] ); /* amr any special formating here */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($colhtml as $col => $chtml) {
|
||||
$eventhtml .= (empty($chtml)) ? AMR_NL : AMR_NL.'<div class="details'.$col.'">'.$chtml.'</div>';
|
||||
}
|
||||
if (!($eventhtml === '')) { /* ------------------------------- if we have some event data to list */
|
||||
$eventhtml = $ev.$classes.'">'.$eventhtml.$evc;
|
||||
}
|
||||
$html .= AMR_NL.$eventhtml;
|
||||
}
|
||||
//if (!empty($html)) $html = $html.$ulc;
|
||||
return ($html);
|
||||
}
|
||||
|
||||
function amr_get_day_link_stem() {
|
||||
global $amr_calendar_url, $amr_limits;
|
||||
|
||||
if (!empty($amr_calendar_url))
|
||||
// if they have defined a url to use for these sorts of links, then use it
|
||||
$link = $amr_calendar_url;
|
||||
else
|
||||
// else get a clean version of the current url
|
||||
$link = amr_clean_link();
|
||||
|
||||
// how do we know whether to force a listtype or not ?
|
||||
// we must if in large calendar or small calendar
|
||||
// and it should be the agenda one
|
||||
// If they have specified a url, then that page should either already be
|
||||
// in a suitable listtype, or the url should have a listtype passed to it.
|
||||
|
||||
if (!empty ($amr_limits['agenda'])) {
|
||||
// do not want listtype unless requested?
|
||||
$agenda = $amr_limits['agenda'];
|
||||
}
|
||||
else
|
||||
$agenda = 1;
|
||||
|
||||
$link = add_query_arg( 'listtype', $agenda ,$link);
|
||||
|
||||
return ($link);
|
||||
}
|
||||
|
||||
function amr_get_day_link($thisyear, $thismonth, $thisday, &$link) { /* the start date object and the months to show */
|
||||
|
||||
// old comment as to why the linktype add in was commented out : what does it mean?:
|
||||
//no ? - they must just do something sensible when they set up the page
|
||||
|
||||
$link = add_query_arg( 'days', '1' ,$link);
|
||||
$link = add_query_arg( 'months', '0' ,$link); // else existing months will override days
|
||||
$link = add_query_arg( 'start',
|
||||
$thisyear.str_pad($thismonth,2,'0',STR_PAD_LEFT).str_pad($thisday,2,'0',STR_PAD_LEFT),
|
||||
$link );
|
||||
$link = amr_check_for_wpml_lang_parameter ($link);
|
||||
return ($link);
|
||||
|
||||
}
|
||||
|
||||
function amrical_get_month_link($start, $months, $link) { /* the start date object and the months to show */
|
||||
$link = (add_query_arg( 'start', $start, $link ));
|
||||
$link = (add_query_arg( 'months', $months, $link ));
|
||||
$link = amr_check_for_wpml_lang_parameter ($link);
|
||||
return ($link);
|
||||
|
||||
}
|
||||
|
||||
function amr_calendar_colheaders ($liststyle, $start) {
|
||||
global $wp_locale,
|
||||
$amr_options,
|
||||
$amr_globaltz,
|
||||
$amr_listtype;
|
||||
// week_begins = 0 stands for Sunday
|
||||
$week_begins= intval(get_option('start_of_week'));
|
||||
$format = $amr_options['listtypes'][$amr_listtype]['format']['Day'];
|
||||
$dummydate = new Datetime(); //if cloning dont need tz
|
||||
$dummydate = clone $start ;// so as not to overwrite start
|
||||
|
||||
$myweek = array();
|
||||
$calendar_output = '';
|
||||
for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
|
||||
$dayofweek = ($wdcount+$week_begins)%7;
|
||||
|
||||
$myweek[] = $wp_locale->get_weekday($dayofweek);
|
||||
// make a note of which number is saturday and sunday so we can add css classes for the weekend
|
||||
if ($dayofweek == 0) $sunday = $wdcount;
|
||||
if ($dayofweek == 6) $satday = $wdcount;
|
||||
}
|
||||
|
||||
foreach ( $myweek as $dayofweek => $wd ) {
|
||||
|
||||
switch ($liststyle) {
|
||||
case "smallcalendar" : {
|
||||
$day_name = $wp_locale->get_weekday_initial($wd);
|
||||
break;
|
||||
}
|
||||
case "weekscalendar" : {//else weekscalendar
|
||||
$day_name = amr_format_date($format,$dummydate); // v 4.0.9
|
||||
|
||||
break;
|
||||
}
|
||||
default: { //else large calendar
|
||||
$day_name = $wp_locale->get_weekday_abbrev($wd);
|
||||
}
|
||||
|
||||
}
|
||||
date_modify($dummydate, '+1 day'); //must increment the day
|
||||
|
||||
// $day_name = ($liststyle=="smallcalendar") ?
|
||||
// $wp_locale->get_weekday_initial($wd) :
|
||||
// $wp_locale->get_weekday_abbrev($wd);
|
||||
$wd = esc_attr($wd);
|
||||
if ($dayofweek === $sunday)
|
||||
$class= ' class="sunday" ';
|
||||
elseif ($dayofweek === $satday)
|
||||
$class= ' class="saturday" ';
|
||||
else $class='';
|
||||
|
||||
$calendar_output .= "\n\t\t<th ".$class." scope=\"col\" title=\"$wd\">$day_name</th>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $calendar_output;
|
||||
}
|
||||
|
||||
function amr_event_is_multiday($event) { //determine if event is a multi day event
|
||||
|
||||
if (empty($event['DURATION'])) {
|
||||
if (empty($event['EndDate'])) return false; // no duration at all, just a date
|
||||
else $duration = amr_calc_duration ( $event['EventDate'], $event['EndDate']);
|
||||
}
|
||||
else $duration = $event['DURATION'];
|
||||
if (isset($_GET['debugmulti'])) {echo '<br /> duration = '; var_dump($duration);}
|
||||
$days = 0;
|
||||
if (!empty($duration['days']) and ($duration['days'] >= 1 )) {
|
||||
$days=$duration['days'];
|
||||
}
|
||||
if ( (!empty($duration['hours']) and ($duration['hours'] >= 1 )) or
|
||||
(!empty($duration['minutes']) and ($duration['minutes'] >= 1 )) or
|
||||
(!empty($duration['seconds']) and ($duration['seconds'] >= 1 )) ) {
|
||||
// then we go over 1 day into the next
|
||||
$days = $days + 1;
|
||||
}
|
||||
|
||||
if (!empty($duration['weeks']) and ($duration['weeks'] >= 1 ))
|
||||
$days = $days + (7*$duration['weeks']);
|
||||
if (isset($_GET['debugmulti'])) echo '<br /> The number of days over which to show event '.$event['SUMMARY'].' is = '.$days;
|
||||
return $days;
|
||||
}
|
||||
|
||||
function amr_sort_by_two_cols ($col1, $col2, &$data) { // sorts by two columns ascending
|
||||
// Obtain a list of columns
|
||||
|
||||
foreach ($data as $key => $row) {
|
||||
// if col1 is an object ?
|
||||
if (!empty($row[$col1]))
|
||||
$column1[$key] = $row[$col1];
|
||||
else
|
||||
$column1[$key] = '-1';//will never happen
|
||||
if (!empty($row[$col2]))
|
||||
$column2[$key] = $row[$col2];
|
||||
else
|
||||
$column2[$key] = '-999';
|
||||
|
||||
}
|
||||
|
||||
if (empty ($column1) or empty ($column2)) return $data;
|
||||
|
||||
array_multisort($column1, SORT_ASC, $column2, SORT_DESC, $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function amr_sort_by_three_cols ($col1, $col2, $col3, &$data) { // sorts by two columns ascending
|
||||
global $amr_globaltz;
|
||||
|
||||
// Obtain a list of columns
|
||||
foreach ($data as $key => $row) {
|
||||
// if col1 is an object ?
|
||||
if (!empty($row[$col1]))
|
||||
$column1[$key] = $row[$col1];
|
||||
else
|
||||
$column1[$key] = '-1';//will never happen
|
||||
if (!empty($row[$col2]))
|
||||
$column2[$key] = $row[$col2];
|
||||
else
|
||||
$column2[$key] = '-999';
|
||||
if (!empty($row[$col3]))
|
||||
$column3[$key] = $row[$col3];
|
||||
else
|
||||
$column3[$key] = '-999';
|
||||
|
||||
}
|
||||
array_multisort($column1, SORT_ASC, $column2, SORT_DESC, $column2, SORT_ASC, $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function amr_check_for_multiday_events (&$events) { //for each event passed, chcek whiether it is a multi day, and if so add dummy days
|
||||
global $amr_globaltz;
|
||||
|
||||
if (!empty ($events)) {
|
||||
foreach ($events as $m => $event) {
|
||||
if (empty($event['EventDate'])) {
|
||||
if (ICAL_EVENTS_DEBUG) {
|
||||
echo 'Unexpected empty event date for event ';
|
||||
print_r($event, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
date_timezone_set($event['EventDate'], $amr_globaltz); // may do this earlier (after recurrence though), no harm in twice
|
||||
$days = amr_event_is_multiday($event);
|
||||
if (isset($_GET['debugmulti'])) echo '<br />Doing '.$event['id'].' <b>multiday = '.$days.' </b>';
|
||||
if ($days > 1 ) {
|
||||
$day = 1;
|
||||
if (empty ($events[$m]['Classes'])) $events[$m]['Classes'] = '';
|
||||
$events[$m]['Classes'] .= ' firstday '; // already have first day
|
||||
$events[$m]['dummyYMD'] = $event['EventDate']->format('Ymd'); //numerical so do not need amr_date_format
|
||||
$events[$m]['MultiDay'] = $day;
|
||||
//$tempdate = amr_newDateTime(); // create new obect so we do not update the same object
|
||||
while ($day < ($days)) { // must not be <= because we are plus one anyway - and original is first anyway
|
||||
if (isset($_GET['debugmulti'])) echo '<br /> Do day = '.$day;
|
||||
$tempdate = new Datetime(); //if cloning dont need tz
|
||||
$tempdate = clone $event['EventDate']; // copy the current event date
|
||||
date_modify ($tempdate,'+'.$day.' days'); // adjust days to currenmt midddle date if necessary
|
||||
// must do like above in case we go over a month
|
||||
$day = $day+1;
|
||||
$dummy[$m][$day] = $events[$m]; // copy event data over , but use dumy so we do not reprocess the additions
|
||||
$dummy[$m][$day]['dummyYMD'] = $tempdate->format('Ymd');; // now set the date for this dummy event //numerical so do not need amr_date_format
|
||||
$dummy[$m][$day]['MultiDay'] = $day; // flag it as a multi day
|
||||
// set the classes so we can style multi days
|
||||
if (isset($_GET['debugmulti'])) echo ' dummyymd= '.$dummy[$m][$day]['dummyYMD'];
|
||||
if ($day >= $days) {
|
||||
$dummy[$m][$day]['Classes'] .= ' lastday ';
|
||||
$dummy[$m][$day]['Classes'] = str_replace ('firstday', '', $dummy[$m][$day]['Classes']);
|
||||
}
|
||||
else {
|
||||
$dummy[$m][$day]['Classes'] = str_replace ('firstday', '', $dummy[$m][$day]['Classes']);
|
||||
$dummy[$m][$day]['Classes'] .= ' middleday ';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$events[$m]['dummyYMD'] = $event['EventDate']->format('Ymd'); //numerical so do not need amr_date_format
|
||||
$events[$m]['MultiDay'] = '0'; // to force non multidays to bottom
|
||||
}
|
||||
$events[$m]['dummytime'] = $event['EventDate']->format('His'); //for sorting according to time
|
||||
}
|
||||
}
|
||||
//once we have processed all the events, THEN we can add the dummies in, so we do not reprocess them!
|
||||
if (!empty($dummy )) {
|
||||
foreach ($dummy as $m => $dummydays) {
|
||||
foreach ($dummydays as $k => $event) {
|
||||
$events[] = $event;
|
||||
}
|
||||
}
|
||||
}
|
||||
//$events = amr_sort_by_three_cols ('dummyYMD', 'MultiDay', 'dummytime', $events);
|
||||
$events = amr_sort_by_two_cols ('dummyYMD', 'MultiDay', $events);
|
||||
if (isset($_GET['debugmulti'])) {
|
||||
foreach ($events as $i => $e) {
|
||||
echo '<br />'.$e['id'].' '.$e['EventDate']->format('Ymd').' '.$e['dummyYMD'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return ($events);
|
||||
}
|
||||
1264
wp-content/plugins/amr-ical-events-list/includes/amr-ical-config.php
Normal file
1264
wp-content/plugins/amr-ical-events-list/includes/amr-ical-config.php
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
/* field admin */
|
||||
|
||||
function amr_whats_in_use() {
|
||||
global $amr_options;
|
||||
|
||||
amr_set_defaults(); // $amr_options will be set, don't fetch other options yet
|
||||
$defaults = $amr_options;
|
||||
$desc = amr_set_helpful_descriptions ();
|
||||
$amr_options = amr_getset_options(false);
|
||||
$inuse = get_option('amr-event-fields-in-use'); // overlay any existing
|
||||
// get all fields that have a column
|
||||
if (empty($inuse)) {
|
||||
$inuse = amr_default_fields_to_use ();
|
||||
}
|
||||
|
||||
foreach ($amr_options['listtypes'] as $i=> $l) { // foreach list
|
||||
if (isset($l['compprop'])) {
|
||||
foreach ($l['compprop'] as $f => $opt) {
|
||||
if (empty($opt['Column'])) {
|
||||
if (empty($allfieldsinuse[$f]))
|
||||
$allfieldsinuse[$f] = 0;
|
||||
}
|
||||
else
|
||||
if (empty($allfieldsinuse[$f]))
|
||||
$allfieldsinuse[$f] = 1;
|
||||
else
|
||||
$allfieldsinuse[$f] ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// any new defaults ?
|
||||
foreach ($defaults['listtypes'] as $i=> $l) {
|
||||
if (isset($l['compprop'])) {
|
||||
foreach ($l['compprop'] as $f => $opt) {
|
||||
if (!isset($allfieldsinuse[$f]))
|
||||
$allfieldsinuse[$f] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// check descriptions just in case ? - no also has componemts
|
||||
/* foreach ($desc as $i=> $l) {
|
||||
if (empty($allfieldsinuse[$i]))
|
||||
$allfieldsinuse[$i] = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
if (!empty($inuse)) { // we already got somethingstored
|
||||
foreach ($inuse as $i=> $l) {
|
||||
if (!isset($allfieldsinuse[$i])) // its no longer possible, delete it
|
||||
unset($inuse[$i]);
|
||||
}
|
||||
}
|
||||
else $inuse = array(); // no option yet
|
||||
|
||||
foreach ($allfieldsinuse as $i=> $l) { // for all the fields we know about
|
||||
if (!isset($inuse[$i])) // is maybe new? - not empty because thats just what we set before
|
||||
$inuse[$i] = $allfieldsinuse[$i];
|
||||
}
|
||||
|
||||
// var_dump($inuse);
|
||||
array_multisort(array_values($inuse), SORT_DESC, array_keys($inuse), SORT_ASC, $inuse);
|
||||
return ($inuse);
|
||||
}
|
||||
|
||||
|
||||
function amrical_choose_fields() {
|
||||
global $amr_options;
|
||||
//$nonce = wp_create_nonce('amr-ical-events-list'); /* used for security to verify that any action request comes from this plugin's forms */
|
||||
|
||||
amrical_admin_heading(__('Choose event and calendar fields ', 'amr-ical-events-list'));
|
||||
|
||||
$inuse = amr_whats_in_use();
|
||||
$desc = amr_set_helpful_descriptions ();
|
||||
if (isset ($_POST['action']) and ($_POST['action'] == "save")) {
|
||||
$nonce = $_REQUEST['_wpnonce'];
|
||||
if (! wp_verify_nonce($nonce, 'amr-ical-events-list'))
|
||||
die ("Cancelled due to failed security check");
|
||||
/* Validate the input and save */
|
||||
if (isset($_POST['reset'])) {
|
||||
echo '<div class="updated"><p>';
|
||||
_e('Resetting....','amr-ical-events-list');
|
||||
delete_option('amr-event-fields-in-use');
|
||||
echo '</p></div>';
|
||||
$inuse = amr_whats_in_use();
|
||||
}
|
||||
/* Validate the input and save */
|
||||
else
|
||||
$inuse = amr_ical_validate_fields($inuse);
|
||||
}
|
||||
|
||||
array_multisort(array_values($inuse), SORT_DESC, array_keys($inuse), SORT_ASC, $inuse);
|
||||
//$fields - an array of fields used in a column
|
||||
echo '<p>'.__('To simplify choose a subset of fields to work with:' , 'amr-ical-events-list').'</p>';
|
||||
echo '<div style="columns: 300px 2;">';
|
||||
foreach ($inuse as $f => $bool) {
|
||||
|
||||
echo '<p><lable><input type="checkbox" name="inuse['.$f.']" ';
|
||||
if ($bool)
|
||||
echo ' checked="checked" >';
|
||||
else
|
||||
echo '>';
|
||||
echo '<b>'.$f.'</b> ('.$bool.'x)';
|
||||
if (!empty($desc[$f])) echo ' - <em>'.$desc[$f].'</em>';
|
||||
echo '</lable></p>';
|
||||
|
||||
}
|
||||
|
||||
amr_ical_submit_buttons (__('Reset','amr-ical-events-list'));
|
||||
|
||||
echo '</div></form></div>';
|
||||
} //end amrical_option_page
|
||||
|
||||
|
||||
function amr_ical_validate_fields($inuse) {
|
||||
global $amr_options;
|
||||
|
||||
if (isset($_POST['inuse'])) {
|
||||
foreach ($inuse as $f => $bool) {
|
||||
//echo $f; var_dump($bool);
|
||||
if (!empty($bool) and (!isset($_POST['inuse'][$f]))) {
|
||||
$inuse[$f] = 0;
|
||||
echo 'Unsetting '.$f.'<br />';
|
||||
}
|
||||
}
|
||||
foreach ($_POST['inuse'] as $f => $bool) {
|
||||
//echo $f; var_dump($bool);
|
||||
if (isset($bool) and (empty($inuse[$f]))) {
|
||||
$inuse[$f] = 1;
|
||||
echo 'Adding '.$f.'<br />';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
echo '<div class="updated"><p>';
|
||||
_e('Saving....','amr-ical-events-list');
|
||||
update_option('amr-event-fields-in-use', $inuse);
|
||||
echo '</p></div>';
|
||||
return($inuse);
|
||||
|
||||
}
|
||||
410
wp-content/plugins/amr-ical-events-list/includes/amr-ical-groupings.php
Executable file
410
wp-content/plugins/amr-ical-events-list/includes/amr-ical-groupings.php
Executable file
@@ -0,0 +1,410 @@
|
||||
<?php
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------*/
|
||||
function amr_expand_all ($atts) {
|
||||
$html = '<div id="calendar_toggle"><a href="#" id="expandall" >'.__('Show all', 'amr-ical-events-list').'</a>'
|
||||
.' <a href="#" id="hideall" class="inactive" >'.__('Hide all', 'amr-ical-events-list').'</a></div>';
|
||||
return($html);
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_list_event_subset ($htm, $columns, $subset, $events) { // now a flat array of ids
|
||||
$html = '';
|
||||
$alt = false;
|
||||
if ((!is_array($events)) or (count($events) < 1 )) return ('');
|
||||
if ((!is_array($subset)) or (count($subset) < 1 )) return ('');
|
||||
$no_cols = count($columns);
|
||||
// foreach ($events as $i => $e) { /* for each event, loop through the properties and see if we should display */
|
||||
foreach ($subset as $i => $eventindex) { /* for each event, loop through the properties and see if we should display */
|
||||
$e = $events[$eventindex];
|
||||
amr_derive_component_further ($e);
|
||||
amr_decide_display_timezone($e); // determine timezone that this event should be shown in
|
||||
if (!empty($e['Classes']))
|
||||
$classes = strtolower($e['Classes']);
|
||||
else
|
||||
$classes = '';
|
||||
|
||||
$eprop = ''; /* each event on a new list */
|
||||
$prevcol = 0;
|
||||
$colcount = 0;
|
||||
$col = 1; /* reset where we are with columns */
|
||||
|
||||
$rowhtml = '';
|
||||
foreach ($columns as $col => $order) { // prepare the row
|
||||
$eprop = '';
|
||||
foreach ($order as $k => $kv) { /* ie for one column in event, check how to order the bits */
|
||||
|
||||
/* Now check if we should print the component or not, we may have an array of empty string */
|
||||
if (isset($e[$k])) {
|
||||
$v = amr_check_flatten_array ($e[$k]); // *** huh? shoudl we do this here?
|
||||
|
||||
}
|
||||
else
|
||||
$v =null;
|
||||
|
||||
$selector = $htm['li'];
|
||||
$selectorend = $htm['lic'];
|
||||
if (!empty($selector)) $selector .=' class="'.strtolower($k).'">';
|
||||
|
||||
if (!empty($v)) { // some custom eg: TRUMBA fields may have empty or no values
|
||||
|
||||
$eprop .= $selector
|
||||
.amr_format_value($v, $k, $e,$kv['Before'],$kv['After'] )
|
||||
.$selectorend;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($eprop)) $eprop = ' '; // a value for a dummytable cell if tere were no values in the column
|
||||
|
||||
// annoying but only way to pass variables by reference is through an array, must return array to then.
|
||||
// so to allow filter of column and pass which column it is, thsi is how we do it
|
||||
$tmp = apply_filters('amr_events_column_html',
|
||||
array('colhtml'=>$eprop, 'col'=>$col));
|
||||
|
||||
$eprop = $tmp['colhtml'];
|
||||
|
||||
if (!empty($ul)) // will phase the ul's out eventually
|
||||
$eprop = $ul.' class="amrcol'.$col.' amrcol">'
|
||||
.$eprop
|
||||
.$htm['ulc'];
|
||||
|
||||
/* each column in a cell or list */
|
||||
$cellclasses = '';
|
||||
if (!empty($htm['cell']) ) { // if we have a selector that surounds each property , then add classes.
|
||||
$cellclasses .= ' amrcol'.$col;
|
||||
if ($col == $no_cols) {
|
||||
$cellclasses .= ' lastcol'; /* only want the cell to be lastcol, not the row */
|
||||
}
|
||||
$thiscolumn = $htm['cell'].' class="'.$cellclasses.'">' .$eprop. (empty($htm['cellc']) ? '' : $htm['cellc']);
|
||||
}
|
||||
else $thiscolumn = $eprop;
|
||||
|
||||
$rowhtml .= $thiscolumn; // build up the row with each column
|
||||
} // end row
|
||||
|
||||
// so now we have finished that group, start next
|
||||
// save the event or row, for next group
|
||||
if (!empty($rowhtml)) {
|
||||
$tmp = apply_filters('amr_events_event_html', array('rowhtml'=>$rowhtml, 'event'=>$e));
|
||||
$rowhtml = $tmp['rowhtml'];
|
||||
$rowhtml = (!empty($htm['row']) ? ($htm['row'].($alt ? ' class="odd alt':' class="').$classes.' event"> ') : '')
|
||||
.$rowhtml
|
||||
.$htm['rowc'];
|
||||
|
||||
if ($alt) $alt=false;
|
||||
else $alt=true;
|
||||
|
||||
$html .= $rowhtml; /* build the group of events , adding on eprop */
|
||||
$rowhtml = '';
|
||||
}
|
||||
|
||||
}
|
||||
//end of row or event
|
||||
return $html;
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_list_events_in_groupings ($htm, $id='', $columns, $groupedevents, $events) { // 2 levels of grouping only at moment
|
||||
|
||||
if (empty($events)) return;
|
||||
$html = '';
|
||||
if (empty($groupedevents)) {
|
||||
$all= array_keys($events);
|
||||
$html .= $htm['body'].'>'.amr_list_event_subset ($htm, $columns, $all, $events).$htm['bodyc'];
|
||||
return $html;
|
||||
}
|
||||
|
||||
$prevtitle = '';
|
||||
|
||||
foreach ($groupedevents as $g => $nextlevel) {
|
||||
|
||||
if (!empty($nextlevel['title'])) { // there are titles
|
||||
//echo
|
||||
if (is_array($nextlevel['title'])) {
|
||||
$hhtml = '';
|
||||
foreach ($nextlevel['title'] as $i => $titlestring) { //if (isset($_GET['debugg'])) {echo '<br />Title='.$titlestring;}
|
||||
if ($i == 0 ) { // for first title only
|
||||
if ($titlestring == $prevtitle ) continue; // only show the outer title once
|
||||
else $prevtitle = $titlestring;
|
||||
if (!empty($nextlevel['parent'])) {
|
||||
$id = get_term_by('id',$nextlevel['parent'],$nextlevel['grouping'] );
|
||||
$id = 'id="'.$id->slug.'" ';
|
||||
}
|
||||
}
|
||||
else $id='';
|
||||
|
||||
$hhtml .= amr_do_grouping_html($htm,$id, 'level'.$i.' '.$nextlevel['grouping'], $titlestring);
|
||||
}
|
||||
$html .= $htm['body'].' class="toggle_container" >'.$hhtml; // cannot have multiple thead
|
||||
}
|
||||
|
||||
$html = $html.amr_list_event_subset ($htm, $columns, $nextlevel['events'], $events).$htm['bodyc'];
|
||||
}
|
||||
else {
|
||||
|
||||
$html .= amr_list_events_in_groupings ($htm, $id, $columns, $nextlevel, $events);
|
||||
}
|
||||
|
||||
// check next level ??
|
||||
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_produce_tree_from_array ($terms, $parent=0) {
|
||||
// get all where parent = 0, unset
|
||||
// then for eah parent get children,unset
|
||||
//repeat till none left
|
||||
$tree = array();
|
||||
// get all that match parent
|
||||
if (!empty($terms)) {
|
||||
foreach($terms as $i=>$term) {
|
||||
if ($term->parent == $parent) {
|
||||
$tree[$term->term_id] = $term->term_id; // create top level
|
||||
unset ($terms[$i]);
|
||||
if (!empty($terms)) {
|
||||
echo '<br />'.$term->term_id.' '.$term->name.' terms left:'.count($terms);
|
||||
$tree[$term->term_id] = amr_produce_tree_from_array ($terms, $term->term_id); // any children ?
|
||||
}
|
||||
}
|
||||
else echo '<br /> not a child '.$term->term_id.' has parent '.$term->parent;
|
||||
|
||||
}
|
||||
}
|
||||
//if (WP_DEBUG) {echo '<br /> The tree: '; var_dump($tree);}
|
||||
return ($tree);
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_assign_events_to_dategrouping ($dategrouping, $eventsubset, $events) {
|
||||
|
||||
foreach ($eventsubset['events'] as $i => $index) {
|
||||
//if (WP_DEBUG) echo '<br />dategrouping = '.$dategrouping;
|
||||
if (empty($events[$index]['EventDate']))
|
||||
$datetouse = $events[$index]['DTSTART'];
|
||||
else
|
||||
$datetouse = $events[$index]['EventDate'];
|
||||
$groupstring = amr_format_grouping($dategrouping, $datetouse);
|
||||
$groupsubset[$groupstring]['events'][] = $index;
|
||||
}
|
||||
$first = true;
|
||||
foreach ($groupsubset as $groupstring => $garray) {
|
||||
|
||||
if (is_array($eventsubset['title']))
|
||||
$groupsubset[$groupstring]['title'] = $eventsubset['title']; // the top level title
|
||||
else
|
||||
$groupsubset[$groupstring]['title'][] = $eventsubset['title']; // the top level title
|
||||
$groupsubset[$groupstring]['title'][] = $groupstring;
|
||||
$groupsubset[$groupstring]['grouping'] = $dategrouping; // remember it
|
||||
//echo '<br />Date: '.$groupstring; var_dump($groupsubset[$groupstring]); echo '<hr/>';
|
||||
}
|
||||
return $groupsubset; // subarray of events eg: [Jan2001] = array(id1,id2)
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_assign_events_to_taxogrouping ($taxonomy_groupby, $eventsubset, $events) { // still in flat taxonomy
|
||||
|
||||
foreach ($eventsubset['events'] as $i => $index) {
|
||||
if (!empty($events[$index][$taxonomy_groupby])) { //ie the event has a taxonomy term
|
||||
if (is_array($events[$index][$taxonomy_groupby])) { // it probably will be
|
||||
foreach ($events[$index][$taxonomy_groupby] as $j => $taxoterm) {
|
||||
$groupsubset[$taxoterm]['events'][] = $index;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isset($_GET['debugg'])) echo ' ** Taxonomy terms not an array'; var_dump($event[$taxonomy_groupby]);
|
||||
}
|
||||
}
|
||||
else { if (isset($_GET['debugg'])) {echo '<br />*** No value for '.$taxonomy_groupby.' in event '.$events[$index]['id']; }
|
||||
}
|
||||
}
|
||||
if (isset($_GET['debugg'])) {echo '<br />Grouped events by taxo grouping: '.$taxonomy_groupby.'<br />'; var_dump($groupsubset);}
|
||||
if (empty($groupsubset)) return false;
|
||||
// now check all the groups identified
|
||||
foreach ($groupsubset as $taxoterm => $garray) { // garray = array [events]
|
||||
$term = get_term_by('id', $taxoterm, $taxonomy_groupby);
|
||||
$terms[] = $term;
|
||||
if (is_array($eventsubset['title']))
|
||||
$groupsubset[$taxoterm]['title'] = $eventsubset['title'];
|
||||
else
|
||||
$groupsubset[$taxoterm]['title'][] = $eventsubset['title'];
|
||||
// now add to the titles
|
||||
$groupsubset[$taxoterm]['title'][] = amr_prepare_term_title($taxoterm, $taxonomy_groupby);
|
||||
$groupsubset[$taxoterm]['grouping'] = $taxonomy_groupby; // remember it for later
|
||||
|
||||
//if (isset($_GET['debugg'])) {echo '<br />Checking for parent:<br /> '; var_dump($term);}
|
||||
if (isset($term->parent)) $groupsubset[$taxoterm]['parent'] = $term->parent; // remember it for later
|
||||
//build up levels of titlle relative to nesting
|
||||
//echo '<br />After taxo groupings: '.$taxoterm; var_dump($groupsubset[$taxoterm]); echo '<hr/>';
|
||||
}
|
||||
//if (WP_DEBUG) {echo '<br />*** Terms'; VAR_DUMP($terms);}
|
||||
|
||||
$taxo = get_taxonomy($taxonomy_groupby);
|
||||
//echo '<hr />TAXO: ';var_dump($taxo);
|
||||
if ($taxo->hierarchical) { // if a hierarchical taxonomy , do some funky footwork !!!*** MAYBE CHECK IF WANT TO DO HIERARCHICALLY
|
||||
if (isset($_GET['debugg'])) echo '<hr />It is hierarchical, so handle it: <br />';
|
||||
$groupsubset = amr_handle_taxonomy_hierarchy($taxonomy_groupby, $groupsubset);
|
||||
}
|
||||
// now we want to reorder by the nesting / tree structure and add title ?
|
||||
return $groupsubset; // subarray of events eg: [cat1] = array(id1,id2), [cat2]= array(id2,id4)
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_handle_taxonomy_hierarchy ($taxonomy_groupby, $groupsubset) {
|
||||
// need to sort by parents , so they will appear in correct order hierarchically (add a class ?)
|
||||
$newset = amr_sort_by_key($groupsubset, 'parent');
|
||||
//if (isset($_GET['debugg'])) {echo '<br />sorted by parent ';foreach ($newset as $t => $arr){ echo '<br />'.$t.'<br />'; var_dump($arr);} ;}
|
||||
// then for each parent, if it has not appeared, we need to 'add it' before the child - will have no events
|
||||
|
||||
$args = array(
|
||||
'orderby' => 'term_group', // id, count, name - Default, slug, term_group, none
|
||||
//'order' => 'ASC', // DESC
|
||||
'hide_empty' => 1,
|
||||
'fields' => 'all', //default
|
||||
'hierarchical' => true // pass even if empty, if child not empty
|
||||
);
|
||||
|
||||
// get the terms for that taxonomy ? how to sort ????
|
||||
$terms = get_terms ($taxonomy_groupby, $args);
|
||||
foreach ($newset as $termname => $garray) { // for our newly sorted array
|
||||
if (!empty($garray['parent'])) {
|
||||
//if (isset($_GET['debugg'])) {echo '<br />Term = '.$termname.' Parent = '.$garray['parent'];}
|
||||
$parentterm = get_term($garray['parent'],$taxonomy_groupby );
|
||||
if (isset($_GET['debugg'])) {echo '<br />ParentTerm = '; var_dump($parentterm->name);}
|
||||
if (!isset($newset[$parentterm->name])) {// then it hasn't appeared
|
||||
//if (isset($_GET['debugg'])) {echo '<br />Title to add:'.$parentterm->name;}
|
||||
$grptitle_to_add = amr_prepare_term_title($parentterm->name, $taxonomy_groupby);
|
||||
if (isset($_GET['debugg'])) {echo '<br />Existing title ='; var_dump($newset[$termname]['title']); echo '<br />Title to add:'.$grptitle_to_add;}
|
||||
array_unshift($newset[$termname]['title'],$grptitle_to_add );
|
||||
if (isset($_GET['debugg'])) {echo '<br /> New set of titles: <br />'; var_dump($newset[$termname]['title']);}
|
||||
}
|
||||
else {if (isset($_GET['debugg'])) echo '<br />already have in this parent '.$parentterm->name;}
|
||||
}
|
||||
|
||||
}
|
||||
return ($newset);
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_assign_events_to_a_grouping ($grouping, $eventsubset, $events) {
|
||||
if (in_array($grouping, array(
|
||||
'Year',
|
||||
'Month',
|
||||
'Day',
|
||||
'Week',
|
||||
'Quarter',
|
||||
'Astronomical Season',
|
||||
'Traditional Season',
|
||||
'Western Zodiac',
|
||||
'Solar Term' ), true)) {
|
||||
$groupsubset = amr_assign_events_to_dategrouping ($grouping, $eventsubset, $events);
|
||||
// returns array[grouping][events]
|
||||
// [title]
|
||||
}
|
||||
elseif (taxonomy_exists( $grouping )) { // ie it is a taxonomy
|
||||
|
||||
$groupsubset = amr_assign_events_to_taxogrouping ($grouping, $eventsubset, $events);
|
||||
|
||||
}
|
||||
else { // as yet unknown - maybe grouping by location ? - depends how stored then, maybe save places as taxo terms ?
|
||||
if (WP_DEBUG) echo '<br />Unknown grouping: '.$grouping;
|
||||
$groupsubset = array();
|
||||
}
|
||||
return ($groupsubset);
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_assign_events_to_groupings ($groupings, $events) {
|
||||
// assign events to first level of grouping, handling hierarchical
|
||||
// then assign that subset to next level ?
|
||||
if (empty($groupings)) return false;
|
||||
// chcek / convert grupings
|
||||
foreach ($groupings as $i => $g) {
|
||||
if (is_bool($g)) {
|
||||
if (!$g) unset ($groupings[$i]);
|
||||
else $groupings[$i] = $i;
|
||||
}
|
||||
}
|
||||
if (isset($_GET['debugg'])) {echo '<br />Groupings requested: '; var_dump($groupings);}
|
||||
$grouping = array_shift($groupings); // get the first
|
||||
// setup initial 'subset' which is actually all
|
||||
//if (WP_DEBUG) {echo '<br />Start with grouping '.$grouping;}
|
||||
|
||||
foreach ($events as $i => $event) {
|
||||
$eventsubset['events'][] = $i;
|
||||
}
|
||||
$eventsubset['title'] = array();
|
||||
|
||||
$groupsubset = amr_assign_events_to_a_grouping ($grouping, $eventsubset, $events);
|
||||
if (empty ($groupsubset) ) return false;
|
||||
//should now have ? array [$taxo][events]
|
||||
// ............................[title]
|
||||
|
||||
//if (isset($_GET['debugg'])) { echo '<hr/>First Pass *************<br/>';
|
||||
//foreach ($groupsubset as $g => $arr ) {echo '<br />***'.$g.'<br />'; var_dump($arr); echo '<hr/>';}}
|
||||
|
||||
if (!empty($groupings)) { // only allows two levels for now
|
||||
|
||||
$grouping = array_shift($groupings); // get the 2nd grouping
|
||||
//if (WP_DEBUG) {echo '<br />And then with grouping '.$grouping;}
|
||||
foreach ($groupsubset as $grp => $garray) { // overwrite the curremt subset with the next level tree
|
||||
if (isset($_GET['debugg'])) echo '<hr />Doing grp = '.$grp; //.' with'; var_dump($garray);
|
||||
$groupsubset[$grp] = amr_assign_events_to_a_grouping ($grouping, $garray, $events);
|
||||
//should now have ? array [$taxo or date ][events]
|
||||
// ............................[title]
|
||||
//echo '<br />Then have '; var_dump($groupsubset[$grp]); echo '<hr/>';
|
||||
|
||||
}
|
||||
}
|
||||
return $groupsubset;
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_do_grouping_html($htm, $id, $class, $titlestring) {
|
||||
|
||||
$html =
|
||||
((!empty($htm['grow'])) ? $htm['grow'].$id.' class="trigger group '.$class.'">' : '')
|
||||
.((!empty($htm['ghcell'])) ? $htm['ghcell'].' class="group '.$class. '" >' : '')
|
||||
.$titlestring
|
||||
.$htm['ghcellc']
|
||||
.$htm['growc'];
|
||||
return $html;
|
||||
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_prepare_term_title($term, $taxo) { // this is a term
|
||||
global $amr_options,$amr_listtype;
|
||||
|
||||
if (is_int($term)) $termdata = get_term_by('id', $term, $taxo, ARRAY_A);
|
||||
else $termdata = get_term_by('name', $term, $taxo, ARRAY_A);
|
||||
$termstring = '<a class="term" href="#">'.$termdata['name'].'</a>'; // to facilitate collapsability
|
||||
|
||||
if (true or !empty ($amr_options['listtypes'][$amr_listtype]['grouping_settings']['show_description'])) { //***
|
||||
if (!empty($termdata['description']))
|
||||
$termstring .=' <span class="termdesc" >'.$termdata['description'].'</span>';
|
||||
// allow own definition of how taxonomy term should look
|
||||
}
|
||||
$termstring = apply_filters('amr_term_grouping_title',$termstring,$term);
|
||||
return $termstring;
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_get_groupings_requested () {
|
||||
global $amr_options,
|
||||
$amr_listtype,
|
||||
$amr_groupings;
|
||||
|
||||
if (isset ($amr_options['listtypes'][$amr_listtype]['grouping'])) {
|
||||
foreach (($amr_options['listtypes'][$amr_listtype]['grouping']) as $i => $level)
|
||||
{ if ($level) { $g[$level] = $i; } }
|
||||
}
|
||||
|
||||
if (!empty($g)) return ($g);
|
||||
else return false;
|
||||
}
|
||||
/* -------------------------------------------------------------------------------------------*/
|
||||
function amr_do_a_grouping($htm, $gi, $ghtml) {
|
||||
/* we have a new group */
|
||||
$id = amr_string($gi.$new[$gi]);
|
||||
$html =
|
||||
((!empty($htm['grow'])) ? $htm['grow'].'class="group '.$gi.'">' : '')
|
||||
.((!empty($htm['ghcell'])) ? $htm['ghcell'].' class="group '.$gi. '" >' : '')
|
||||
.$grouping
|
||||
.$htm['ghcellc']
|
||||
.$htm['growc'];
|
||||
return $html;
|
||||
}
|
||||
/* -------------------------------------------------------------------------------------------*/
|
||||
File diff suppressed because it is too large
Load Diff
189
wp-content/plugins/amr-ical-events-list/includes/amr-ical-plugin-form-html.php
Executable file
189
wp-content/plugins/amr-ical-events-list/includes/amr-ical-plugin-form-html.php
Executable file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/**
|
||||
* Backend Class for use in all amr plugins
|
||||
* Version 0.1
|
||||
*/
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
if (!class_exists('amrical_plugin_admin')) {
|
||||
class amrical_Plugin_Admin {
|
||||
var $hook = '';
|
||||
var $filename = '';
|
||||
var $longname = '';
|
||||
var $shortname = '';
|
||||
var $optionname = '';
|
||||
var $homepage = '';
|
||||
var $parent_slug = 'plugin_listings_menu';
|
||||
var $accesslvl = 'manage_options';
|
||||
|
||||
function amr_Plugin_Admin() {
|
||||
add_action('admin_menu', array(&$this, 'register_settings_page') );
|
||||
add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
|
||||
add_action('admin_print_scripts', array(&$this,'config_page_scripts'));
|
||||
add_action('admin_print_styles', array(&$this,'config_page_styles'));
|
||||
// add_action('wp_dashboard_setup', array(&$this,'widget_setup'));
|
||||
}
|
||||
|
||||
function config_page_styles() {
|
||||
if (isset($_GET['page']) && $_GET['page'] == $this->hook) {
|
||||
wp_enqueue_style('dashboard');
|
||||
wp_enqueue_style('thickbox');
|
||||
wp_enqueue_style('global');
|
||||
wp_enqueue_style('wp-admin');
|
||||
wp_enqueue_style('blogicons-admin-css', WP_CONTENT_URL . '/plugins/' . plugin_basename(dirname(__FILE__)). '/amr_plugin_tools.css');
|
||||
}
|
||||
}
|
||||
function register_settings_page() {
|
||||
add_submenu_page( $this->parent_slug, $this->shortname, $this->shortname, $this->accesslvl, $this->hook, array(&$this,'config_page'));
|
||||
}
|
||||
function plugin_options_url() {
|
||||
return admin_url( 'options-general.php?page='.$this->hook );
|
||||
}
|
||||
/**
|
||||
* Add a link to the settings page to the plugins list
|
||||
*/
|
||||
function add_action_link( $links, $file ) {
|
||||
static $this_plugin;
|
||||
if( empty($this_plugin) ) $this_plugin = $this->filename;
|
||||
if ( $file == $this_plugin ) {
|
||||
$settings_link = '<a href="' . $this->plugin_options_url() . '">' . __('Settings') . '</a>';
|
||||
array_unshift( $links, $settings_link );
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
function config_page() {
|
||||
|
||||
}
|
||||
function config_page_scripts() {
|
||||
if (isset($_GET['page']) && $_GET['page'] == $this->hook) {
|
||||
wp_enqueue_script('postbox');
|
||||
wp_enqueue_script('dashboard');
|
||||
wp_enqueue_script('thickbox');
|
||||
wp_enqueue_script('media-upload');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create a Checkbox input field
|
||||
*/
|
||||
function radiobutton($id, $label, $value, $selected) {
|
||||
$sel = checked($value,$selected, false);
|
||||
return "<input type='radio' id='".$id."' name='".$id."' value='".$value."'"
|
||||
. $sel."/> ".$label."<br />";
|
||||
}
|
||||
/**
|
||||
* Create a Checkbox input field
|
||||
*/
|
||||
function checkbox($id, $label, $value) {
|
||||
return '<input type="checkbox" id="'.$id.'" name="'.$id.'"'. checked($value,true,false).'/> <label for="'.$id.'">'.$label.'</label><br/>';
|
||||
}
|
||||
/**
|
||||
* Create a Dropdown input field
|
||||
*/
|
||||
function dropdown($id, $label, $options, $selected) {
|
||||
//
|
||||
$html = '<label for="'.$id.'">'.$label.':</label><br/>'
|
||||
.'<select id=\''.$id.'\' name=\''.$id.'\'>';
|
||||
foreach ($options as $i => $option) {
|
||||
//
|
||||
$sel = selected($i, $selected, false); //wordpress function returns with single quotes, not double
|
||||
$html .= '<OPTION '.$sel.' label=\''.$option.'\' value=\''.$i.'\'>'.$option.'</OPTION>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
return ($html);
|
||||
}
|
||||
/**
|
||||
* Create a Text input field
|
||||
*/
|
||||
function textinput($id, $label, $value, $length='45') {
|
||||
return '<label for="'.$id.'">'.$label.':</label><br/><input size="'
|
||||
.$length.'" type="text" id="'.$id.'" name="'.$id.'" value="'.$value.'"/><br/><br/>';
|
||||
}
|
||||
/**
|
||||
* Create a Text area field
|
||||
*/
|
||||
function textarea($id, $label, $value, $cols='45', $rows='10') {
|
||||
return '<label for="'.$id.'">'.$label.':</label><br/>'
|
||||
.'<textarea rows="'.$rows.'" cols="'.$cols
|
||||
.'" id="'.$id.'" name="'.$id.'"/>'.$value.'</TEXTAREA><br/><br/>';
|
||||
}
|
||||
/**
|
||||
* Create a postbox widget
|
||||
*/
|
||||
function postbox($id, $title, $content) {
|
||||
?>
|
||||
<div id="<?php echo $id; ?>" class="postbox">
|
||||
<div class="handlediv" title="Click to toggle"><br /></div>
|
||||
<h3 class="hndle"><span><?php echo $title; ?></span></h3>
|
||||
<div class="inside">
|
||||
<?php echo $content; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
/**
|
||||
* Create a form table from an array of rows
|
||||
*/
|
||||
function form_table($rows) { // array of rows () id, label, desc, content
|
||||
$content = '<table class="form-table">';
|
||||
foreach ($rows as $row) {
|
||||
$content .= '<tr><th valign="top" scrope="row">';
|
||||
if (isset($row['id']) && $row['id'] != '')
|
||||
$content .= '<label for="'.$row['id'].'">'.$row['label'].':</label>';
|
||||
else
|
||||
$content .= $row['label'];
|
||||
if (isset($row['desc']) && $row['desc'] != '')
|
||||
$content .= '<br/><small>'.$row['desc'].'</small>';
|
||||
$content .= '</th><td valign="top">';
|
||||
$content .= $row['content'];
|
||||
$content .= '</td></tr>';
|
||||
}
|
||||
$content .= '</table>';
|
||||
return $content;
|
||||
}
|
||||
/**
|
||||
* Create a "plugin like" box.
|
||||
*/
|
||||
function plugin_like() {
|
||||
$content = '<p>'.__('Why not do any or all of the following:','amr-ical-events-list').'</p>';
|
||||
$content .= '<ul>';
|
||||
$content .= '<li><a href="'.$this->homepage.'">'.__('Link to it so other folks can find out about it.','amr-ical-events-list').'</a></li>';
|
||||
$content .= '</ul>';
|
||||
$this->postbox($this->hook.'like', 'Like this plugin?', $content);
|
||||
}
|
||||
/**
|
||||
* Info box with link to the support forums.
|
||||
*/
|
||||
function plugin_support() {
|
||||
$content = '<p>'.__('If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the','amr-ical-events-list').' <a href="http://wordpress.org/tags/'.$this->hook.'">'.__("Support forums",'amr-ical-events-list').'</a>.</p>';
|
||||
$this->postbox($this->hook.'support', 'Need support?', $content);
|
||||
}
|
||||
/**
|
||||
* Box with latest news from amr.com
|
||||
*/
|
||||
function news() {
|
||||
require_once(ABSPATH.WPINC.'/rss.php');
|
||||
if ( $rss = fetch_rss( 'http://icalevents.com/feed' ) ) {
|
||||
$content = '<ul>';
|
||||
$rss->items = array_slice( $rss->items, 0, 3 );
|
||||
foreach ( (array) $rss->items as $item ) {
|
||||
$content .= '<li class="amr">';
|
||||
$content .= '<a class="rsswidget" href="'.clean_url( $item['link'], $protocolls=null, 'display' ).'">'. htmlentities($item['title']) .'</a> ';
|
||||
$content .= '</li>';
|
||||
}
|
||||
$content .= '<li class="rss"><a href="http://icalevents.com/feed/">Subscribe with RSS</a></li>';
|
||||
$content .= '<li class="email"><a href="http://icalevents.com/">Subscribe by email</a></li>';
|
||||
$this->postbox('amrlatest', 'Latest news', $content);
|
||||
} else {
|
||||
$this->postbox('amrlatest', 'Latest news', 'Nothing to say...');
|
||||
}
|
||||
}
|
||||
function text_limit( $text, $limit, $finish = ' […]') {
|
||||
if( strlen( $text ) > $limit ) {
|
||||
$text = substr( $text, 0, $limit );
|
||||
$text = substr( $text, 0, - ( strlen( strrchr( $text,' ') ) ) );
|
||||
$text .= $finish;
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
if (!function_exists('amr_ical_register_post_type')) { // let the amr-events one override
|
||||
function amr_ical_register_post_type() {
|
||||
global $amr_event_post_type, $amr_event_post_type_plural;
|
||||
|
||||
$amr_event_post_type = 'event';
|
||||
$amr_event_post_type_plural = 'events';
|
||||
|
||||
$labels = array( // dummy for translation string pickup
|
||||
'name' => _x('Events', 'post type general name','amr-events'),
|
||||
'singular_name' => _x('Event', 'post type singular name','amr-events'),
|
||||
'add_new' => _x('Add New', 'event','amr-events'),
|
||||
'add_new_item' => __('Add New Event', 'amr-events'),
|
||||
'edit_item' => __('Edit Event', 'amr-events'),
|
||||
'new_item' => __('New Event', 'amr-events'),
|
||||
'view' => __('View Event', 'amr-events'),
|
||||
'view_item' => __('View Event', 'amr-events'),
|
||||
'search_items' => __('Search Events', 'amr-events'),
|
||||
'not_found' => __('No events found', 'amr-events'),
|
||||
'not_found_in_trash' => __('No events found in trash', 'amr-events'),
|
||||
'parent' => __('Related Event','amr-events' ));
|
||||
|
||||
// now overwrite
|
||||
$elabel = 'Event'; //ucfirst($amr_event_post_type);
|
||||
$elabelplural = 'Events'; //ucfirst($amr_event_post_type_plural);
|
||||
$labels = array(
|
||||
'name' => _x($elabelplural, 'post type general name','amr-events'),
|
||||
'singular_name' => _x($elabel, 'post type singular name','amr-events'),
|
||||
'add_new' => _x('Add New ', $elabel,'amr-events'),
|
||||
'add_new_item' => __('Add New ').__( $elabel, 'amr-events'),
|
||||
'edit_item' => __('Edit ').__( $elabel, 'amr-events'),
|
||||
'new_item' => __('New ').__($elabel, 'amr-events'),
|
||||
'view' => __('View ').__( $elabelplural, 'amr-events'),
|
||||
'view_item' => __('View ').__( $elabel, 'amr-events'),
|
||||
'search_items' => __('Search ').__( $elabelplural, 'amr-events'),
|
||||
'not_found' => __('No events found', 'amr-events'),
|
||||
'not_found_in_trash' => __('No events found in trash', 'amr-events'),
|
||||
'parent' => sprintf(__('Related %s', 'amr-events'),__( $elabel, 'amr-events')));
|
||||
|
||||
|
||||
$args = array(
|
||||
'label' => $amr_event_post_type,
|
||||
'labels' => $labels,
|
||||
'singular_label' => __('Event','amr-events'), // keep as dummy for translation, then overwrite
|
||||
'public' => true,
|
||||
'publicly_queryable' => true,
|
||||
'show_ui' => true,
|
||||
'capability_type' => 'post', // special capabilities only in amr-events
|
||||
//'hierarchical' => true,
|
||||
'supports' => array('title', 'editor', 'author',
|
||||
//'revisions', 'thumbnail',
|
||||
// 'excerpt','page-attributes','custom-fields','wpgeo','comments', 'trackbacks','sticky'
|
||||
),
|
||||
//'taxonomies' => array( 'post_tag', 'category'),
|
||||
'show_in_menu' => true,
|
||||
'show_in_nav_menus' => true,
|
||||
'menu_position' => 4, /* so will come after posts */
|
||||
'has_archive' => true,
|
||||
// 'menu_icon' => WP_PLUGIN. '/article16.png'
|
||||
'_builtin' => false, // It's a custom post type, not built in!
|
||||
'query_var' => true,
|
||||
'capability_type' => 'post', // only need array if plural is different
|
||||
'map_meta_cap' => true, // bad news for editing in menu?
|
||||
'rewrite' => array("slug" => $amr_event_post_type /*,'with_front' => true*/ ) // Permalinks format
|
||||
|
||||
);
|
||||
|
||||
$args['singular_label'] = __($amr_event_post_type,'amr-events');// overwrite with chosen name
|
||||
register_post_type($amr_event_post_type,$args );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
add_action('init', 'amr_ical_register_post_type',1); // only in init not before
|
||||
228
wp-content/plugins/amr-ical-events-list/includes/amr-ical-pretty-print.php
Executable file
228
wp-content/plugins/amr-ical-events-list/includes/amr-ical-pretty-print.php
Executable file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
function amr_prettyprint_weekst ($wkst) {
|
||||
global $amr_day_of_week_no, $wp_locale,
|
||||
$amr_day_of_week_from_no,
|
||||
$amr_day_of_week;
|
||||
if (empty($wkst)) return '';
|
||||
|
||||
return ('<em>'.sprintf(__('Weeks start on %s','amr-ical-events-list'),
|
||||
$amr_day_of_week[$wkst]
|
||||
).'</em> '.$wkst);
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_prettyprint_r_ex_date ($rdate) { /* rrule or exrule */
|
||||
global $amr_formats; /* amr check that this get set to the chosen list type */
|
||||
// 201407 nor rdates include dtstart - should dtstart be reversed out here, or the text changed ?
|
||||
|
||||
// $df = pref_date_entry_format_string();
|
||||
if (is_array($rdate)) {
|
||||
// 20140709 resort the array
|
||||
sort($rdate);
|
||||
foreach ($rdate as $i => $d) {
|
||||
if (is_object($d))
|
||||
$html[] = amr_format_date ($amr_formats['Day'], $d);
|
||||
// = $d->format($df); /* *** is it already in the right timezone or not ? If just doing 'date' for now, is okay? */
|
||||
else $html[] = $d;
|
||||
}
|
||||
}
|
||||
return (implode(', ', $html));
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_prettyprint_byday ($b) {
|
||||
$fulldayofweek = amr_fulldaytext(); /* MO, TU= etsc*/
|
||||
$h = array();
|
||||
$html = '';
|
||||
if (is_array($b)) {
|
||||
foreach ($b as $d => $n) {
|
||||
if (is_array($n)) { /* must be n bydays */
|
||||
foreach ($n as $i => $n2) {
|
||||
$temp[] = ical_ordinalize_words($n2);
|
||||
}
|
||||
if (count($temp) == 2) $h[] = implode (__(' and ','amr-ical-events-list'),$temp).' '.$fulldayofweek[$d];
|
||||
else $h[] = implode (', ',$temp).' '.$fulldayofweek[$d];
|
||||
$temp = array();
|
||||
}
|
||||
else { /* normal bydays */
|
||||
$h[] = $fulldayofweek[$d];
|
||||
|
||||
}
|
||||
if (count($h) == 2) $html = implode(__(' and ','amr-ical-events-list'),$h);
|
||||
else $html = implode (', ',$h);
|
||||
if (!is_array($n)) $html = __('every ','amr-ical-events-list').$html;
|
||||
}
|
||||
return($html);
|
||||
}
|
||||
else return ($b); /* who knows what is in if it is not an array? */
|
||||
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_prettyprint_byordinal ($b) {
|
||||
$h = array();
|
||||
if (is_array($b)) {
|
||||
foreach ($b as $i => $d) {
|
||||
$h[] = ical_ordinalize_words($d);
|
||||
};
|
||||
if (count($h) == 2) $html = implode(__(' and ','amr-ical-events-list'),$h);
|
||||
else $html = implode (', ',$h);
|
||||
return($html);
|
||||
}
|
||||
else return ($b);
|
||||
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_prettyprint_bymonth ($b) {
|
||||
global $wp_locale;
|
||||
$h = array();
|
||||
if (is_array($b)) {
|
||||
foreach ($b as $i => $d) {
|
||||
$h[] = $wp_locale->get_month($d);
|
||||
};
|
||||
if (count($h) == 2) $html = implode(__(' or ','amr-ical-events-list'),$h);
|
||||
else $html = implode (', ',$h);
|
||||
return($html);
|
||||
}
|
||||
else return ($b);
|
||||
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_prettyprint_duration ($duration) {
|
||||
if (empty($duration)) return;
|
||||
if (!is_array($duration)) echo $duration;
|
||||
else { $h = array();
|
||||
foreach ($duration as $i => $v) {
|
||||
$h[] = sprintf( _n( '%u '.rtrim($i,'s') /* singular */
|
||||
, '%u '.$i /* plural */
|
||||
,$v // number
|
||||
,'amr-ical-events-list'),// domain
|
||||
$v);
|
||||
}
|
||||
$html = implode (', ',$h);
|
||||
}
|
||||
echo $html;
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_prettyprint_rule ($rule) { /* rrule or exrule */
|
||||
/* Receive an array of prepared fields and combine it into a suitable descriptive string */
|
||||
global $amr_freq,
|
||||
$amr_freq_unit,
|
||||
$amr_day_of_week_no,
|
||||
$wp_locale;
|
||||
$sep = ' ';
|
||||
$c = '';
|
||||
|
||||
if (isset($rule['FREQ'])) {
|
||||
$nicefrequnit = $amr_freq_unit[$rule['FREQ']]; /* already translated value */
|
||||
if (isset($rule['INTERVAL'])) {/* the freq as it is repetitive */
|
||||
$interval = ' '
|
||||
.sprintf(__('Every %s %s','amr-ical-events-list'),
|
||||
ical_ordinalize($rule['INTERVAL']),
|
||||
$nicefrequnit).$sep;
|
||||
}
|
||||
// else $interval = ' '.sprintf( __('every %s','amr-ical-events-list'), $nicefrequnit).$sep; // sounds funny to have daily every day, only have if every 2nd etc
|
||||
// $nicefreq = $amr_freq[$rule['FREQ']].$interval; /* already translated value */
|
||||
|
||||
else $interval = $amr_freq[$rule['FREQ']]; /* already translated value */
|
||||
|
||||
if (isset($rule['BYSETPOS'])) $c .= ' '.
|
||||
sprintf(__('On %s instance within %s', 'amr-ical-events-list')
|
||||
,amr_prettyprint_byordinal($rule['BYSETPOS'])
|
||||
,$interval);
|
||||
// else $c .= $nicefreq;
|
||||
else $c .= $interval;
|
||||
if (isset($rule['COUNT'])) $c .= ' '.sprintf(__('%s times','amr-ical-events-list'), $rule['COUNT']).$sep;
|
||||
if (isset($rule['UNTIL'])) {
|
||||
if ($rule['UNTIL-TIME'] === '00:00') $rule['UNTIL-TIME'] = '';
|
||||
else if (strtolower($rule['UNTIL-TIME']) === '12:00 am') $rule['UNTIL-TIME'] = '';
|
||||
|
||||
$c .= ' '.sprintf(__('until %s %s','amr-ical-events-list'), $rule['UNTIL-DATE'], $rule['UNTIL-TIME']).$sep;
|
||||
}
|
||||
if (isset($rule['MONTH'])) $c .= sprintf(__(' if month is %s','amr-ical-events-list'),amr_prettyprint_bymonth($rule['MONTH']));
|
||||
// if (isset($rule['BYWEEKNO'])) $c .= ' '.sprintf(__(' in weeks %s','amr-ical-events-list'),implode(',',$rule['BYWEEKNO']));
|
||||
if (isset($rule['BYWEEKNO'])) $c .= ' ' .sprintf(__(' in %s weeks of the year','amr-ical-events-list'),amr_prettyprint_byordinal($rule['BYWEEKNO']));
|
||||
// if (isset($rule['BYYEARDAY'])) $c .= ' '.sprintf(__('on the %s day of year','amr-ical-events-list'),implode(',',$rule['BYYEARDAY']));
|
||||
if (isset($rule['BYYEARDAY'])) $c .= ' '.sprintf(__('on %s day of the year','amr-ical-events-list'),amr_prettyprint_byordinal($rule['BYYEARDAY']));
|
||||
if (isset($rule['DAY'])) $c .= ' '.sprintf(__('on %s day of each month', 'amr-ical-events-list'),amr_prettyprint_byordinal($rule['DAY']));
|
||||
if (isset($rule['NBYDAY'])) $nbyday = ' '.sprintf(__('on %s ', 'amr-ical-events-list'),amr_prettyprint_byday($rule['NBYDAY']));
|
||||
if (isset($rule['BYDAY'])) $byday = ' '.sprintf(__('on %s ', 'amr-ical-events-list'),amr_prettyprint_byday($rule['BYDAY']));
|
||||
$ofthefreq = '';
|
||||
// change to accomodate dutch having different artcles for month and year de or het
|
||||
if ($rule['FREQ'] == 'MONTHLY')
|
||||
$ofthefreq = _x(' of the month','eg: last day of the month', 'amr-ical-events-list');
|
||||
else if ($rule['FREQ'] == 'YEARLY')
|
||||
$ofthefreq = _x(' of the year','eg: last day of the year','amr-ical-events-list');
|
||||
if (isset ($nbyday) and isset ($byday)) $c .= $nbyday.__(' and ','amr-ical-events-list').$byday.$ofthefreq;
|
||||
else { if (isset ($byday)) $c .= $byday.$ofthefreq;
|
||||
if (isset ($nbyday)) $c .= $nbyday.$ofthefreq;
|
||||
}
|
||||
if (isset($rule['BYHOUR'])) $c .= ' '.sprintf(__('at the %s hour', 'amr-ical-events-list'),implode(',',$rule['BYHOUR']));
|
||||
if (isset($rule['BYMINUTE'])) $c .= ' '.sprintf(__('at the %s minute', 'amr-ical-events-list'),implode(',',$rule['BYMINUTE']));
|
||||
if (isset($rule['BYSECOND'])) $c .= ' '.sprintf(__('at the %s second', 'amr-ical-events-list'),implode(',',$rule['BYSECOND']));
|
||||
if (isset($rule['WKST'])) $c .= '; '.amr_prettyprint_weekst($rule['WKST']);
|
||||
}
|
||||
return (rtrim($c,','));
|
||||
}
|
||||
/* -------------------------------------------------- */
|
||||
function amr_prepare_pretty_rrule ($rule) {
|
||||
|
||||
global $ical_timezone, $amr_formats;
|
||||
|
||||
/* take the event and it's parsed rrule or exrule and convert some aspects for people use. Used by both edit event and event info */
|
||||
|
||||
$df = $amr_formats['Day'];
|
||||
|
||||
$tf = $amr_formats['Time'];
|
||||
|
||||
$rule['UNTIL-DATE'] = '';
|
||||
|
||||
$rule['UNTIL-TIME'] = '';
|
||||
|
||||
if (isset($_GET['wpmldebug'])) {echo '<hr> inprep pretty';var_dump($rule);}
|
||||
|
||||
foreach ($rule as $i=>$r) { $rule[strtoupper($i)] = $r;}
|
||||
|
||||
if (isset($rule['UNTIL']) and is_object($rule['UNTIL'])) { /* until is possibly in Z time, move to our time first */
|
||||
|
||||
date_timezone_set($rule['UNTIL'], $ical_timezone);
|
||||
|
||||
// $rule['UNTIL-DATE'] = $rule['UNTIL']->format($df);
|
||||
$rule['UNTIL-DATE'] = amr_format_date($df, $rule['UNTIL']);
|
||||
$rule['UNTIL-TIME'] = amr_format_date($tf, $rule['UNTIL']);
|
||||
|
||||
}
|
||||
|
||||
else if (!(isset($rule['COUNT']))) $rule['forever'] = 'forever';
|
||||
|
||||
if (isset ($rule['NOMOWEBYDAY'])) { /* what the F?? */
|
||||
foreach ($rule['BYDAY'] as $j => $k) {
|
||||
$l = strlen($k);
|
||||
if ($l > 2) { /* special treatment required - we have a numeric byday */
|
||||
$d = substr($k, $l-2, $l);
|
||||
|
||||
$rule['NBYDAY'][$d][substr ($k, 0, $l-2)] = true;
|
||||
$rule['BYDAY'][$d] = true;
|
||||
}
|
||||
else {
|
||||
|
||||
$rule['BYDAY'][$k] = true; /* ie recurs every one of those days of week */
|
||||
$rule['NBYDAY'][$k]['0'] = true;
|
||||
|
||||
}
|
||||
unset($rule['BYDAY'][$j]);
|
||||
}
|
||||
}
|
||||
return ($rule);
|
||||
|
||||
}
|
||||
/* --------------------------------------------------------- */
|
||||
function amr_format_bookmark ($text) {
|
||||
return ('<a id="'.$text.'"></a>'); /* ***/
|
||||
}
|
||||
/* --------------------------------------------------------- */
|
||||
function amr_format_rrule ($rule) {
|
||||
if (isset($rule[0])) /* we have an array of rules, is this still valid or is it just one now *** if multiple valid, then code change required */
|
||||
$rule = $rule[0];
|
||||
if (is_string($rule)) $rule = amr_parseRRULE($rule);
|
||||
$rule2 = amr_prepare_pretty_rrule ($rule);
|
||||
$rule3 = amr_prettyprint_rule ($rule2);
|
||||
return ($rule3);
|
||||
}
|
||||
1288
wp-content/plugins/amr-ical-events-list/includes/amr-import-ical.php
Normal file
1288
wp-content/plugins/amr-ical-events-list/includes/amr-import-ical.php
Normal file
File diff suppressed because it is too large
Load Diff
2050
wp-content/plugins/amr-ical-events-list/includes/amr-pluggable.php
Normal file
2050
wp-content/plugins/amr-ical-events-list/includes/amr-pluggable.php
Normal file
File diff suppressed because it is too large
Load Diff
1168
wp-content/plugins/amr-ical-events-list/includes/amr-rrule.php
Normal file
1168
wp-content/plugins/amr-ical-events-list/includes/amr-rrule.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,321 @@
|
||||
<?php
|
||||
/*
|
||||
Description: Display a sweet, concise list of events from iCal sources, using a list type from the amr iCal plugin <a href="options-general.php?page=manage_amr_ical">Manage Settings Page</a> and <a href="widgets.php">Manage Widget</a>
|
||||
|
||||
*/
|
||||
class amr_ical_widget extends WP_Widget {
|
||||
/** constructor */
|
||||
public function __construct() {
|
||||
$widget_ops = array ('description'=>__('Upcoming Events', 'amr-ical-events-list' ),'classname'=>'events');
|
||||
parent::__construct('amr-ical-upe'
|
||||
, __('Upcoming Events List', 'amr-ical-events-list' )
|
||||
, $widget_ops);
|
||||
}
|
||||
/* ============================================================================================== */
|
||||
function widget ($args /* the title etc */, $instance /* the params */) { /* this is the piece that actualy does the widget display */
|
||||
global $amrW,
|
||||
$amr_options,
|
||||
$amr_limits,
|
||||
$amr_listtype,
|
||||
$amr_calendar_url,
|
||||
$amr_ical_am_doing,
|
||||
$change_view_allowed,
|
||||
$widget_icalno, /* used to give each ical widget a unique id on a page */
|
||||
$amr_been_here; /* used to detect if we are looping somehow - reset at the end of each widget or shortcode. */
|
||||
//
|
||||
if (amr_a_nested_event_shortcode ()) return (false); //someone entered an event shortcode into event content - causing a loop of events lists inside event lists
|
||||
|
||||
amr_ical_load_text(); // do we have to reload all over theplace ? wp does not always seem to have the translations
|
||||
$change_view_allowed = false;
|
||||
$amr_ical_am_doing = 'listwidget';
|
||||
extract ($args, EXTR_SKIP); /* this is for the before / after widget etc*/
|
||||
unset($args); //nb do not delete this else mucks up the args later
|
||||
extract ($instance, EXTR_SKIP); /* this is for the params etc*/
|
||||
|
||||
if (!empty ($shortcode_urls)) // get any args stored in the widget settings
|
||||
$args = shortcode_parse_atts($shortcode_urls);
|
||||
|
||||
if (empty ($args['listtype']))
|
||||
$args['listtype'] = '4';
|
||||
$amr_listtype = (int) $args['listtype'];
|
||||
|
||||
|
||||
//
|
||||
if (!empty ($externalicalonly) and $externalicalonly)
|
||||
$args['eventpoststoo'] = '0';
|
||||
else $args['eventpoststoo'] = '1';
|
||||
// $args['show_month_nav'] = '0'; // comment out, otherwise cannot have at all if requetsed?
|
||||
$args['headings'] = '1';
|
||||
$args['show_views'] = '0';
|
||||
|
||||
$amrW = 'w'; /* to maintain consistency with previous version and prevent certain actions */
|
||||
$criteria = amr_get_params ($args); /* this may update listtype, limits etc */
|
||||
|
||||
// what was this for ??
|
||||
if (isset ($criteria['event'])) unset ( $criteria['event']); //*** later may need to check for other custo posttypes
|
||||
|
||||
if (ICAL_EVENTS_DEBUG) echo '<hr>ical list widget:'.$amr_listtype.' <br />'.amr_echo_parameters();
|
||||
|
||||
if (isset($doeventsummarylink) and !($doeventsummarylink)) $amrW = 'w_no_url';
|
||||
|
||||
$moreurl = trim($moreurl," ");
|
||||
$moreurl = (empty($moreurl)) ? null : $moreurl ;
|
||||
$amr_calendar_url = esc_url($moreurl);
|
||||
if (ICAL_EVENTS_DEBUG) echo 'Calendar url = '.$amr_calendar_url;
|
||||
if (isset($_REQUEST['lang']))
|
||||
$moreurl = add_query_arg('lang',$_REQUEST['lang'],$moreurl);
|
||||
// wp 3.3.1 doesn't like html in titles anymore - why ?
|
||||
// if (!empty ($moreurl))
|
||||
// $title = '<a title="'.__('Look for more','amr-ical-events-list').'" href= "'.$moreurl.'">'.__($title,'amr-ical-events-list') .'</a>';
|
||||
|
||||
if (!(isset($widget_icalno)))
|
||||
$widget_icalno = 0;
|
||||
else
|
||||
$widget_icalno= $widget_icalno + 1;
|
||||
|
||||
$content = amr_process_icalspec($criteria,
|
||||
$amr_limits['start'], $amr_limits['end'], $amr_limits['events'], $widget_icalno);
|
||||
//output...
|
||||
|
||||
//var_dump($criteria);
|
||||
echo $before_widget;
|
||||
|
||||
// if (!empty($criteria['headings']))
|
||||
echo $before_title
|
||||
. apply_filters('widget_title',__($title,'amr-ical-events-list' ))
|
||||
. $after_title ;
|
||||
|
||||
echo $content;
|
||||
echo $after_widget;
|
||||
|
||||
/* we made it out the other end without looping ?*/
|
||||
$amr_been_here = false;
|
||||
|
||||
}
|
||||
/* ============================================================================================== */
|
||||
|
||||
function update($new_instance, $old_instance) { /* this does the update / save */
|
||||
$instance = $old_instance;
|
||||
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
$instance['moreurl'] = strip_tags($new_instance['moreurl']);
|
||||
$instance['moreurl'] = amr_make_sticky_url($instance['moreurl'] );
|
||||
$instance['doeventsummarylink']= strip_tags($new_instance['doeventsummarylink']);
|
||||
$instance['externalicalonly'] = strip_tags($new_instance['externalicalonly']);
|
||||
$instance['shortcode_urls'] = strip_tags($new_instance['shortcode_urls']);
|
||||
if (get_option('amr-ical-widget') )
|
||||
delete_option('amr-ical-widget'); /* if it exists - leave code for a while for conversion */
|
||||
|
||||
return $instance;
|
||||
|
||||
}
|
||||
|
||||
/* ============================================================================================== */
|
||||
|
||||
function form($instance) { /* this does the display form */
|
||||
global $amrW;
|
||||
|
||||
$instance = wp_parse_args( (array) $instance, array(
|
||||
'title' => __('Upcoming Events','amr-ical-events-list') ,
|
||||
'moreurl' => '',
|
||||
'doeventsummarylink' => true,
|
||||
'externalicalonly' => false,
|
||||
'shortcode_urls' => ''
|
||||
) );
|
||||
|
||||
$title = $instance['title'];
|
||||
$moreurl = $instance['moreurl'];
|
||||
$doeventsummarylink= $instance['doeventsummarylink'];
|
||||
$externalicalonly = $instance['externalicalonly'];
|
||||
$shortcode_urls = $instance['shortcode_urls'];
|
||||
|
||||
if ($opt = get_option('amr-ical-widget')) { /* delete the old option in the save */
|
||||
if (isset ($opt['urls']) ) $shortcode_urls = str_replace(',', ' ',$opt['urls']); /* in case anyone had multiple urls separate by commas - change to spaces*/
|
||||
if (isset ($opt['moreurl']) ) $moreurl = $opt['moreurl'];
|
||||
if (isset ($opt['title']) ) $title = $opt['title'];
|
||||
if (isset ($opt['listtype']) and (!($opt['listtype']===4))) $shortcode_urls = 'listtype='.$opt['listtype'].' '.$shortcode_urls;
|
||||
if (isset ($opt['limit']) and (!($opt['limit']==='5'))) $shortcode_urls = 'events='.$opt['limit'].' '.$shortcode_urls;
|
||||
}
|
||||
|
||||
$seemore = __('See plugin website for more details','amr-ical-events-list');
|
||||
// <input type="hidden" name="submit" value="1" />?>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'amr-ical-events-list');
|
||||
?><input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text"
|
||||
value="<?php echo esc_attr($title); ?>" /> </label></p>
|
||||
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('moreurl'); ?>"><b><?php
|
||||
_e('Calendar page url', 'amr-ical-events-list'); ?></b><br /><em>
|
||||
<?php _e('Calendar page url in this website', 'amr-ical-events-list');
|
||||
?></em> <a href="http://icalevents.com/1901-widgets-calendar-pages-and-event-urls/" title="<?php echo $seemore; ?>"><b>?</b></a>
|
||||
<input id="<?php echo $this->get_field_id('moreurl'); ?>" name="<?php echo $this->get_field_name('moreurl'); ?>" type="text" style="width: 200px;"
|
||||
value="<?php echo esc_attr($moreurl); ?>" /></label></p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('doeventsummarylink'); ?>"><b><?php
|
||||
_e('Hover description on Title', 'amr-ical-events-list'); ?></b><br /><em><?php
|
||||
_e('Do an event summary hyperlink with event description as title text ', 'amr-ical-events-list');
|
||||
?></em> <a href="http://icalevents.com/1908-hovers-lightboxes-or-clever-css/" title="<?php echo $seemore; ?>"><b>?</b></a>
|
||||
<input id="<?php echo $this->get_field_id('doeventsummarylink'); ?>" name="<?php
|
||||
echo $this->get_field_name('doeventsummarylink'); ?>" type="checkbox"
|
||||
value="true" <?php if ($doeventsummarylink) echo 'checked="checked"';?> /></label></p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('externalicalonly'); ?>"><b><?php
|
||||
_e('External events only', 'amr-ical-events-list'); ?></b><br /><em><?php
|
||||
_e('Show events from external ics only, do NOT pickup any internal events.', 'amr-ical-events-list');
|
||||
?></em><a href="http://icalevents.com" title="<?php _e('Else include events created internally too','amr-ical-events-list'); ?>"><b>?</b></a>
|
||||
<input id="<?php echo $this->get_field_id('externalicalonly'); ?>" name="<?php
|
||||
echo $this->get_field_name('externalicalonly'); ?>" type="checkbox"
|
||||
value="true" <?php if ($externalicalonly) echo 'checked="checked"';?> /></label></p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('shortcode_urls');?>"><b><?php
|
||||
_e('External ics urls and advanced options', 'amr-ical-events-list'); ?></b><br /><em><?php
|
||||
_e('External ics urls and/or optional shortcode parameters separated by spaces.)', 'amr-ical-events-list'); echo '<br />';
|
||||
_e(' Examples: listtype=4 events=10 days=60 start=yyyymmdd startoffset=-2... )', 'amr-ical-events-list');
|
||||
?></em> </label>
|
||||
<a href="http://icalevents.com/amr-ical-events-list/#shortcode" title="<?php _e('See more parameters','amr-ical-events-list'); ?>"><b>?</b></a>
|
||||
<textarea cols="25" rows="10" id="<?php echo $this->get_field_id('shortcode_urls');?>" name="<?php echo $this->get_field_name('shortcode_urls'); ?>" ><?php
|
||||
|
||||
echo esc_attr($shortcode_urls); ?></textarea></p>
|
||||
|
||||
<?php }
|
||||
/* ============================================================================================== */
|
||||
|
||||
}
|
||||
class amr_icalendar_widget extends WP_widget {
|
||||
/** constructor */
|
||||
|
||||
public function __construct() {
|
||||
$widget_ops = array ('description'=>__('Upcoming Events', 'amr-ical-events-list' ),
|
||||
'classname'=>'widget_calendar');
|
||||
|
||||
parent::__construct(false, __('Upcoming Events Calendar', 'amr-ical-events-list' ), $widget_ops);
|
||||
|
||||
}
|
||||
|
||||
/* ============================================================================================== */
|
||||
function widget ($args, $instance) { /* this is the piece that actualy does the widget display */
|
||||
global $amrW;
|
||||
global $amr_options;
|
||||
global $amr_limits;
|
||||
global $amr_listtype;
|
||||
global $change_view_allowed;
|
||||
global $widget_icalno; /* used to give each ical widget a unique id on a page */
|
||||
global $amr_calendar_url,
|
||||
$amr_been_here;
|
||||
|
||||
// don't check becuase it checks in the shortcode function we call
|
||||
// 20140209 redundant - done in the shortcode function too $criteria = amr_get_params ($args); /* this may update listtype, limits etc */
|
||||
amr_ical_load_text(); // do we have to reload all over theplace ? wp does not always seem to have the translations
|
||||
|
||||
$change_view_allowed = false;
|
||||
// $amr_listtype = '8'; /* default only, can be overwitten in shortcode or query string */
|
||||
|
||||
extract ($args, EXTR_SKIP); /* this is for the before / after widget etc*/
|
||||
unset($args);
|
||||
extract ($instance, EXTR_SKIP); /* the widget form fields */
|
||||
|
||||
if (isset ($moreurl) ) $moreurl = trim($moreurl," ");
|
||||
$amr_calendar_url = (empty($moreurl)) ? null : $moreurl ;
|
||||
|
||||
if (!empty ($shortcode_urls)) // from the instance
|
||||
$atts = shortcode_parse_atts($shortcode_urls);
|
||||
if (!empty ($externalicalonly) and $externalicalonly)
|
||||
$atts['eventpoststoo'] = '0';
|
||||
else
|
||||
$atts['eventpoststoo'] = '1';
|
||||
$atts['show_views'] = '0';
|
||||
$atts['ignore_query'] = 1;
|
||||
$atts['show_month_nav'] = 1;
|
||||
//
|
||||
if (!(isset($widget_icalno)))
|
||||
$widget_icalno = 0;
|
||||
else
|
||||
$widget_icalno= $widget_icalno + 1;
|
||||
$amrW = 'w'; /* to maintain consistency with previous version */
|
||||
|
||||
$content = amr_do_smallcal_shortcode($atts); // thsi will check query params etc
|
||||
|
||||
//output...
|
||||
|
||||
if (!empty($before_widget)) echo $before_widget;
|
||||
if (!empty($before_title)) echo $before_title;
|
||||
if (!empty($title)) echo apply_filters('widget_title',__($title,'amr-ical-events-list') );
|
||||
if (!empty($after_title)) echo $after_title;
|
||||
echo $content;
|
||||
if (!empty($after_widget)) echo $after_widget;
|
||||
if (isset ($savedays)) $amr_limits['days'] = $savedays;
|
||||
|
||||
/* we made it out the other end without looping ?*/
|
||||
$amr_been_here = false;
|
||||
}
|
||||
/* ============================================================================================== */
|
||||
function update($new_instance, $old_instance) { /* this does the update / save */
|
||||
$instance = $old_instance;
|
||||
|
||||
$instance['title'] = strip_tags($new_instance['title']);
|
||||
// if (!empty($instance['externalicalonly'])) // was causing it not to svae - why?
|
||||
$instance['externalicalonly'] = ($new_instance['externalicalonly']);
|
||||
|
||||
$instance['shortcode_urls'] = strip_tags($new_instance['shortcode_urls']);
|
||||
$instance['moreurl'] = strip_tags($new_instance['moreurl']);
|
||||
$instance['moreurl'] = amr_make_sticky_url($instance['moreurl'] );
|
||||
|
||||
return $instance;
|
||||
|
||||
}
|
||||
/* ============================================================================================== */
|
||||
|
||||
function form($instance) { /* this does the display form */
|
||||
|
||||
$instance = wp_parse_args( (array) $instance, array(
|
||||
'title' => __('Upcoming Events','amr-ical-events-list'),
|
||||
'externalicalonly' => false,
|
||||
'moreurl' => '',
|
||||
'shortcode_urls' => 'ignore_query=1'
|
||||
) );
|
||||
$title = $instance['title'];
|
||||
$moreurl = $instance['moreurl'];
|
||||
$externalicalonly = $instance['externalicalonly'];
|
||||
$shortcode_urls = $instance['shortcode_urls'];
|
||||
$seemore = __('See more','amr-ical-events-list');
|
||||
?><p>
|
||||
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'amr-ical-events-list');
|
||||
?><input class="widefat" id="<?php
|
||||
echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text"
|
||||
value="<?php echo esc_attr($title); ?>" /></label></p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('moreurl'); ?>"><b><?php
|
||||
_e('Calendar page url', 'amr-ical-events-list'); ?></b><br /><em>
|
||||
<?php _e('Calendar page url in this website, for links from widget', 'amr-ical-events-list');
|
||||
?></em> <a href="http://icalevents.com/1901-widgets-calendar-pages-and-event-urls/" title="<?php echo $seemore; ?>"><b>?</b></a>
|
||||
<input id="<?php echo $this->get_field_id('moreurl'); ?>" name="<?php echo $this->get_field_name('moreurl'); ?>" type="text" style="width: 200px;"
|
||||
value="<?php echo esc_attr($moreurl); ?>" /></label></p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('externalicalonly'); ?>"><b><?php
|
||||
_e('External events only', 'amr-ical-events-list'); ?></b><br /><em><?php
|
||||
_e('Show events from external ics only, do NOT pickup any internal events.', 'amr-ical-events-list');
|
||||
?></em><a href="http://icalevents.com" title="<?php _e('Else include events created internally too','amr-ical-events-list'); ?>"><b>?</b></a>
|
||||
<input id="<?php echo $this->get_field_id('externalicalonly'); ?>" name="<?php
|
||||
echo $this->get_field_name('externalicalonly'); ?>" type="checkbox"
|
||||
value="true" <?php if ($externalicalonly) echo 'checked="checked"';?> /></label></p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('shortcode_urls');?>"><b><?php
|
||||
_e('External ics urls and advanced options', 'amr-ical-events-list'); ?></b><br /><em><?php
|
||||
_e('External ics urls and/or optional shortcode parameters separated by spaces.)', 'amr-ical-events-list'); echo '<br />';
|
||||
_e(' Examples: listtype=8 events=10 days=60 start=yymmdd startoffset=-2... )', 'amr-ical-events-list');
|
||||
?></em> </label>
|
||||
<a href="http://icalevents.com/amr-ical-events-list/#shortcode" title="<?php echo $seemore; ?>"><b>?</b></a>
|
||||
<textarea cols="25" rows="10" id="<?php
|
||||
echo $this->get_field_id('shortcode_urls');?>" name="<?php
|
||||
echo $this->get_field_name('shortcode_urls'); ?>" ><?php
|
||||
echo esc_textarea($shortcode_urls); ?></textarea></p>
|
||||
|
||||
|
||||
<?php }
|
||||
/* ============================================================================================== */
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
if (!function_exists('amr_date_i18n')) {
|
||||
function amr_date_i18n( $dateformatstring, $dateobj = null) {
|
||||
global $wp_locale;
|
||||
// store original value for language with untypical grammars
|
||||
// see http://core.trac.wordpress.org/ticket/9396
|
||||
$req_format = $dateformatstring;
|
||||
//$datefunc = 'date';
|
||||
if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
|
||||
$datemonth = $wp_locale->get_month( $dateobj->format('m') );
|
||||
$datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
|
||||
$w = $dateobj->format('w');
|
||||
if ($w == '-1') {$w = get_oldweekdays($dateobj);} /* php seems to break around 1760 and google passed a zero year date */
|
||||
$dateweekday = $wp_locale->get_weekday( $w );
|
||||
$dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
|
||||
$datemeridiem = $wp_locale->get_meridiem( $dateobj->format('a') );
|
||||
$datemeridiem_capital = $wp_locale->get_meridiem( $dateobj->format( 'A') );
|
||||
$dateformatstring = ' '.$dateformatstring;
|
||||
$dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
|
||||
$dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
|
||||
$dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring );
|
||||
$dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring );
|
||||
$dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring );
|
||||
$dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring );
|
||||
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
|
||||
}
|
||||
$j = $dateobj->format( $dateformatstring );
|
||||
// allow plugins to redo this entirely for languages with untypical grammars
|
||||
$j = apply_filters('amr_date_i18n', $j, $req_format, $dateobj );
|
||||
return $j;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php //examples of functions that could be called in another plugin or in a themes function.php
|
||||
|
||||
// example of filter function that could be used.
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
function amr_limit_to_first ($count) {
|
||||
global $amr_ical_am_doing; //will contain one of: list, calendar, listwidget, smallcalendar, eventinfo
|
||||
|
||||
if ((!empty ($amr_ical_am_doing)) and ($amr_ical_am_doing === 'list')) return (1);
|
||||
else return $count;
|
||||
}
|
||||
add_filter('amr_event_repeats','amr_limit_to_first');
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function amr_semi_paginate() {
|
||||
global $amr_limits;
|
||||
return ('your own pagination code - plus lets see what is in the amr_limits. <br />'
|
||||
. print_r($amr_limits, true));
|
||||
}
|
||||
400
wp-content/plugins/amr-ical-events-list/includes/functions.php
Normal file
400
wp-content/plugins/amr-ical-events-list/includes/functions.php
Normal file
@@ -0,0 +1,400 @@
|
||||
<?php //commonly useful functions
|
||||
|
||||
function amr_need_this_field($field) { // can we do away with or replace this now - see below 20151018
|
||||
global $amr_fields_needed;
|
||||
//$amr_options; global $amr_listtype;
|
||||
|
||||
//20151018 if (!empty($amr_options['listtypes'][$amr_listtype]['compprop'][$field]['column']))
|
||||
//amr 20151012 - isset not enough, must check that column is not zero
|
||||
|
||||
if (in_array($field, $amr_fields_needed))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function amr_extract_fields($amr_event_columns) { // just get array of fields needed
|
||||
global $amr_eventinfo_settings;
|
||||
|
||||
|
||||
$amr_fields_needed = array();
|
||||
|
||||
if (!empty($amr_eventinfo_settings)) { // we are doing a single post
|
||||
|
||||
foreach($amr_eventinfo_settings['eventinfo'] as $fld=>$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 = '<br />Unable to create DateTime object from '.$datetimestring.' <br />'.$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 '<hr />Event List Execution halted - looping detected. Did some one enter an event list shortcode into event content? That will cause a loop for sure.';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function amr_convert_date_string_to_object ($a) {
|
||||
|
||||
if (checkdate(substr($a,4,2), /* month */
|
||||
substr($a,6,2), /* day*/
|
||||
substr($a,0,4)) /* year */ )
|
||||
$e = amr_newDateTime($a);
|
||||
else {
|
||||
_e('Invalid Event Date', 'amr-ical-events-list');
|
||||
}
|
||||
return ($e);
|
||||
}
|
||||
|
||||
function amr_tell_admin_the_error ($text) {
|
||||
// only report the error to admin if logged in ?
|
||||
// else report with comment
|
||||
if (function_exists('is_user_logged_in') // sometimes not yet loaded ???
|
||||
and (current_user_can('manage_options')) ) {
|
||||
echo '<br /><b>Message displayed to logged in admin only:</b><br />'.$text.'<br />';
|
||||
}
|
||||
else if (WP_DEBUG)
|
||||
echo '<br /><b>Message (only displayed if WP_DEBUG):</b><br />'.$text;
|
||||
else
|
||||
echo '<!--'.$text.'-->'; // give some notification at least rather than just failing silently
|
||||
|
||||
}
|
||||
|
||||
function amr_tell_error ($text) {
|
||||
echo '<br /><p><b>'.$text.'</b><p>';
|
||||
}
|
||||
|
||||
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 '<br />Starting tracking now after plugins loaded '.$amr_start_time_track;
|
||||
echo '<br />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 '<br />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 '<br />memory: '.amr_memory_convert($mem).' peak:'.amr_memory_convert($peak).' '.$text;
|
||||
//echo '<br />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 ('<p><br /><hr /><h2><h3><<h4><h5><h6><strong><em>');
|
||||
return (array(
|
||||
'br' => array(),
|
||||
'em' => array(),
|
||||
'span' => array(),
|
||||
'h1' => array(),
|
||||
'h2' => array(),
|
||||
'h3' => array(),
|
||||
'h4' => array(),
|
||||
'h5' => array(),
|
||||
'h6' => array(),
|
||||
'strong' => array(),
|
||||
'p' => array(),
|
||||
'abbr' => array(
|
||||
'title' => array ()),
|
||||
'acronym' => array(
|
||||
'title' => array ()),
|
||||
'b' => array(),
|
||||
'blockquote' => array(
|
||||
'cite' => array ()),
|
||||
'cite' => array (),
|
||||
'code' => array(),
|
||||
'del' => array(
|
||||
'datetime' => array ()),
|
||||
'em' => array (), 'i' => array (),
|
||||
'q' => array(
|
||||
'cite' => array ()),
|
||||
'strike' => array(),
|
||||
'div' => array(),
|
||||
'a' => array('href' => array(),'title' => array()), // maybe add - need to see if quotes will work too
|
||||
'img' => array('src' => array(),'title' => array(),'alt' => array()) // not sure whether his is a good idea - rather use a pluggable format function.
|
||||
));
|
||||
}
|
||||
|
||||
function amr_make_sticky_url($url) {
|
||||
|
||||
$page_id = url_to_postid($url); // doesnt work on homepage - returns 0;
|
||||
|
||||
if ($page_id == 0) {// must be static homepage? so force finding the id
|
||||
$page_id = get_option('page_on_front');
|
||||
}
|
||||
|
||||
if (!$page_id) return false ;
|
||||
else {
|
||||
$sticky_url = add_query_arg('p',$page_id, get_bloginfo('url'));
|
||||
//p safer than page_id - wp 'keeps' the p, but forces pageid to base home if is front page
|
||||
return( $sticky_url) ;
|
||||
}
|
||||
}
|
||||
|
||||
function amr_invalid_url() {
|
||||
?><div class="error fade"><?php _e('Invalid Url','amr-ical-events-list');?></div><?php
|
||||
}
|
||||
|
||||
function amr_invalid_file() {
|
||||
?><div class="error fade"><?php _e('Invalid Url','amr-ical-events-list');?></div><?php
|
||||
}
|
||||
|
||||
function amr_click_and_trim($text) { /* Copy code from make_clickable so we can trim the text */
|
||||
$text = make_clickable($text);
|
||||
amr_trim_url($text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
function amr_trim_url(&$ret) { /* trim urls longer than 30 chars, but not if the link text does not have http */
|
||||
$links = explode('<a', $ret);
|
||||
$countlinks = count($links);
|
||||
|
||||
for ($i = 0; $i < $countlinks; $i++) {
|
||||
$link = $links[$i];
|
||||
$link = (preg_match('#(.*)(href=")#is', $link)) ? '<a' . $link : $link;
|
||||
$begin = strpos($link, '>');
|
||||
|
||||
if ($begin) {
|
||||
|
||||
$begin = $begin + 1;
|
||||
|
||||
$end = strpos($link, '<', $begin);
|
||||
|
||||
$length = $end - $begin;
|
||||
|
||||
$urlname = substr($link, $begin, $length);
|
||||
|
||||
//$trimmed = (strlen($urlname) > 50 && preg_match('#^(http://|ftp://|www\.)#is', $urlname)) ? substr_replace($urlname, '.....', 30, -5) : $urlname;
|
||||
//$trimmed = str_replace('http://','',$trimmed);
|
||||
// 2016112016 Trim https as well
|
||||
$trimmed = (strlen($urlname) > 50 && preg_match('#^(http://|https://|ftp://|www\.)#is', $urlname)) ? substr_replace($urlname, '.....', 30, -5) : $urlname;
|
||||
$trimmed = str_replace(array('http://','https://'),'',$trimmed);
|
||||
|
||||
$ret = str_replace('>' . $urlname . '<', '>' . $trimmed . '<', $ret);
|
||||
}
|
||||
}
|
||||
return ($ret);
|
||||
}
|
||||
|
||||
if (!function_exists('amr_simpledropdown')) {
|
||||
function amr_simpledropdown($name, $options, $selected) {
|
||||
//
|
||||
$html = '<select name=\''.$name.'\'>';
|
||||
foreach ($options as $i => $option) {
|
||||
//
|
||||
$sel = selected($i, $selected, false); //wordpress function returns with single quotes, not double
|
||||
$html .= '<OPTION '.$sel.' label=\''.$option.'\' value=\''.$i.'\'>'.$option.'</OPTION>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
return ($html);
|
||||
}
|
||||
}
|
||||
|
||||
function amr_ngiyabonga() {
|
||||
/* The credit text styling is designed to be as subtle as possible (small font size with leight weight text, and right aligned, and at the bottom) and fit in within your theme as much as possible by not styling colours etc */
|
||||
/* You may however style it more gently, and/or subtly to fit in within your theme. It is good manners to donate if you remove it */
|
||||
|
||||
global $amr_options;
|
||||
if (empty($amr_options['ngiyabonga']))
|
||||
return (
|
||||
'<span class="amrical_credit" style="float:right;font-size:x-small;font-weight:lighter;font-style:italic;" >'
|
||||
.'<a title="Ical Upcoming Events List version '.AMR_ICAL_LIST_VERSION.'" '
|
||||
.'href="http://icalevents.com/">'
|
||||
// .'<img src= "http://icalevents.com/images/plugin-ical1.png" alt ="'
|
||||
.__('Events plugin by anmari','amr-ical-events-list')
|
||||
// .'"</img>'
|
||||
.'</a></span>'
|
||||
);
|
||||
}
|
||||
|
||||
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 '<div style="clear:both;" class="metabox-holder'.$h.'">';
|
||||
echo '<div class="postbox-container" style="width: 49%;">';
|
||||
echo '<div class="meta-box-sortables" style="min-height: 10px;">';
|
||||
echo '<div id="' . $id . '" class="postbox ' ;
|
||||
if ($toggleable) { echo 'if-js-closed' ;}
|
||||
echo '">' . "\n";
|
||||
echo '<div class="handlediv" title="' . __('Click to toggle','amr-ical-events-list') . '"><br /></div>';
|
||||
|
||||
echo "<h3 class='hndle'><span>".$title."</span></h3>\n";
|
||||
echo '<div class="inside">' . "\n";
|
||||
call_user_func($callback);
|
||||
echo "</div></div></div></div></div>";
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
// Silence is golden.
|
||||
?>
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php // mapping of windows zones to timezones (IANA, Ohlson, PHP etc)
|
||||
$wz["Dateline Standard Time"] = "Etc/GMT+12";
|
||||
$wz["UTC-11"] = "Etc/GMT+11";
|
||||
$wz["Hawaiian Standard Time"] = "Pacific/Honolulu";
|
||||
$wz["Alaskan Standard Time"] = "America/Anchorage";
|
||||
$wz["Pacific Standard Time (Mexico)"] = "America/Santa_Isabel";
|
||||
$wz["Pacific Standard Time"] = "America/Los_Angeles";
|
||||
$wz["US Mountain Standard Time"] = "America/Phoenix";
|
||||
$wz["Mountain Standard Time (Mexico)"] = "America/Chihuahua";
|
||||
$wz["Mountain Standard Time"] = "America/Denver";
|
||||
$wz["Central America Standard Time"] = "America/Guatemala";
|
||||
$wz["Central Standard Time"] = "America/Chicago";
|
||||
$wz["Central Standard Time (Mexico)"] = "America/Mexico_City";
|
||||
$wz["Canada Central Standard Time"] = "America/Regina";
|
||||
$wz["SA Pacific Standard Time"] = "America/Bogota";
|
||||
$wz["Eastern Standard Time"] = "America/New_York";
|
||||
$wz["US Eastern Standard Time"] = "America/Indianapolis";
|
||||
$wz["Venezuela Standard Time"] = "America/Caracas";
|
||||
$wz["Paraguay Standard Time"] = "America/Asuncion";
|
||||
$wz["Atlantic Standard Time"] = "America/Halifax";
|
||||
$wz["Central Brazilian Standard Time"] = "America/Cuiaba";
|
||||
$wz["SA Western Standard Time"] = "America/La_Paz";
|
||||
$wz["Pacific SA Standard Time"] = "America/Santiago";
|
||||
$wz["Newfoundland Standard Time"] = "America/St_Johns";
|
||||
$wz["E. South America Standard Time"] = "America/Sao_Paulo";
|
||||
$wz["Argentina Standard Time"] = "America/Buenos_Aires";
|
||||
$wz["SA Eastern Standard Time"] = "America/Cayenne";
|
||||
$wz["Greenland Standard Time"] = "America/Godthab";
|
||||
$wz["Montevideo Standard Time"] = "America/Montevideo";
|
||||
$wz["Bahia Standard Time"] = "America/Bahia";
|
||||
$wz["UTC-02"] = "Etc/GMT+2";
|
||||
$wz["Azores Standard Time"] = "Atlantic/Azores";
|
||||
$wz["Cape Verde Standard Time"] = "Atlantic/Cape_Verde";
|
||||
$wz["Morocco Standard Time"] = "Africa/Casablanca";
|
||||
$wz["UTC"] = "Etc/GMT";
|
||||
$wz["GMT Standard Time"] = "Europe/London";
|
||||
$wz["Greenwich Standard Time"] = "Atlantic/Reykjavik";
|
||||
$wz["W. Europe Standard Time"] = "Europe/Berlin";
|
||||
$wz["Central Europe Standard Time"] = "Europe/Budapest";
|
||||
$wz["Romance Standard Time"] = "Europe/Paris";
|
||||
$wz["Central European Standard Time"] = "Europe/Warsaw";
|
||||
$wz["W. Central Africa Standard Time"] = "Africa/Lagos";
|
||||
$wz["Namibia Standard Time"] = "Africa/Windhoek";
|
||||
$wz["Jordan Standard Time"] = "Asia/Amman";
|
||||
$wz["GTB Standard Time"] = "Europe/Bucharest";
|
||||
$wz["Middle East Standard Time"] = "Asia/Beirut";
|
||||
$wz["Egypt Standard Time"] = "Africa/Cairo";
|
||||
$wz["Syria Standard Time"] = "Asia/Damascus";
|
||||
$wz["South Africa Standard Time"] = "Africa/Johannesburg";
|
||||
$wz["FLE Standard Time"] = "Europe/Kiev";
|
||||
$wz["Turkey Standard Time"] = "Europe/Istanbul";
|
||||
$wz["Israel Standard Time"] = "Asia/Jerusalem";
|
||||
$wz["Libya Standard Time"] = "Africa/Tripoli";
|
||||
$wz["Arabic Standard Time"] = "Asia/Baghdad";
|
||||
$wz["Kaliningrad Standard Time"] = "Europe/Kaliningrad";
|
||||
$wz["Arab Standard Time"] = "Asia/Riyadh";
|
||||
$wz["E. Africa Standard Time"] = "Africa/Nairobi";
|
||||
$wz["Iran Standard Time"] = "Asia/Tehran";
|
||||
$wz["Arabian Standard Time"] = "Asia/Dubai";
|
||||
$wz["Azerbaijan Standard Time"] = "Asia/Baku";
|
||||
$wz["Russian Standard Time"] = "Europe/Moscow";
|
||||
$wz["Mauritius Standard Time"] = "Indian/Mauritius";
|
||||
$wz["Georgian Standard Time"] = "Asia/Tbilisi";
|
||||
$wz["Caucasus Standard Time"] = "Asia/Yerevan";
|
||||
$wz["Afghanistan Standard Time"] = "Asia/Kabul";
|
||||
$wz["West Asia Standard Time"] = "Asia/Tashkent";
|
||||
$wz["Pakistan Standard Time"] = "Asia/Karachi";
|
||||
$wz["India Standard Time"] = "Asia/Calcutta";
|
||||
$wz["Sri Lanka Standard Time"] = "Asia/Colombo";
|
||||
$wz["Nepal Standard Time"] = "Asia/Katmandu";
|
||||
$wz["Central Asia Standard Time"] = "Asia/Almaty";
|
||||
$wz["Bangladesh Standard Time"] = "Asia/Dhaka";
|
||||
$wz["Ekaterinburg Standard Time"] = "Asia/Yekaterinburg";
|
||||
$wz["Myanmar Standard Time"] = "Asia/Rangoon";
|
||||
$wz["SE Asia Standard Time"] = "Asia/Bangkok";
|
||||
$wz["N. Central Asia Standard Time"] = "Asia/Novosibirsk";
|
||||
$wz["China Standard Time"] = "Asia/Shanghai";
|
||||
$wz["North Asia Standard Time"] = "Asia/Krasnoyarsk";
|
||||
$wz["Singapore Standard Time"] = "Asia/Singapore";
|
||||
$wz["W. Australia Standard Time"] = "Australia/Perth";
|
||||
$wz["Taipei Standard Time"] = "Asia/Taipei";
|
||||
$wz["Ulaanbaatar Standard Time"] = "Asia/Ulaanbaatar";
|
||||
$wz["North Asia East Standard Time"] = "Asia/Irkutsk";
|
||||
$wz["Tokyo Standard Time"] = "Asia/Tokyo";
|
||||
$wz["Korea Standard Time"] = "Asia/Seoul";
|
||||
$wz["Cen. Australia Standard Time"] = "Australia/Adelaide";
|
||||
$wz["AUS Central Standard Time"] = "Australia/Darwin";
|
||||
$wz["E. Australia Standard Time"] = "Australia/Brisbane";
|
||||
$wz["AUS Eastern Standard Time"] = "Australia/Sydney";
|
||||
$wz["West Pacific Standard Time"] = "Pacific/Port_Moresby";
|
||||
$wz["Tasmania Standard Time"] = "Australia/Hobart";
|
||||
$wz["Yakutsk Standard Time"] = "Asia/Yakutsk";
|
||||
$wz["Central Pacific Standard Time"] = "Pacific/Guadalcanal";
|
||||
$wz["Vladivostok Standard Time"] = "Asia/Vladivostok";
|
||||
$wz["New Zealand Standard Time"] = "Pacific/Auckland";
|
||||
$wz["UTC+12"] = "Etc/GMT-12";
|
||||
$wz["Fiji Standard Time"] = "Pacific/Fiji";
|
||||
$wz["Magadan Standard Time"] = "Asia/Magadan";
|
||||
$wz["Tonga Standard Time"] = "Pacific/Tongatapu";
|
||||
$wz["Samoa Standard Time"] = "Pacific/Apia";
|
||||
$wz["Line Islands Standard Time"] = "Pacific/Kiritimati";
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// This file adds the ability to parse windows zones and map them to proper timezones
|
||||
// the timezone mapping was generated by windowszonemap.php which reads the xml file at
|
||||
// http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml and converts it to a php array
|
||||
|
||||
function amr_map_windows_to_timezone($icstzid) {
|
||||
include ('WindowsZonesToTimeZones.txt');
|
||||
|
||||
if (isset($wz[$icstzid])) {
|
||||
if (isset ($_REQUEST['tzdebug'])) echo '<br />Found a windows zone, converted it to a timezone.'.$wz[$icstzid];
|
||||
//reset($wz[$icstzid]); // we don't know the territories, so just grab first one
|
||||
//$first = current($wz[$icstzid]);
|
||||
return ($wz[$icstzid]);
|
||||
}
|
||||
else return $icstzid;
|
||||
|
||||
|
||||
}
|
||||
|
||||
//echo amr_map_windows_to_timezone('Alaskan Standard Time'); //for test
|
||||
add_filter ('amr-timezoneid-filter','amr_map_windows_to_timezone');
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
// Silence is golden.
|
||||
?>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// get the latest windows timezone xml file from unicode.org (in case they change!)
|
||||
|
||||
libxml_use_internal_errors(true);
|
||||
$url = "http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml";
|
||||
$xml = simplexml_load_file($url);
|
||||
if (!$xml)
|
||||
printf('Error accessing xml file at %s',$url); //,'amr-windows-timezones');
|
||||
|
||||
$zones = iterator_to_array( $xml->windowsZones->mapTimezones->mapZone,0);
|
||||
|
||||
foreach ($zones as $zone) {
|
||||
$wz = (string) $zone['other'];
|
||||
$terr = (string) $zone['territory'];
|
||||
$tzmapping[$wz][$terr] = (string) $zone['type'];;
|
||||
}
|
||||
//var_dump($tzmapping);
|
||||
|
||||
// produce code to set up the array for php to check values against
|
||||
$phptext = '<?php // mapping of windows zones to timezones (IANA, Ohlson, PHP etc)'.PHP_EOL;
|
||||
foreach ($tzmapping as $z=>$terr) {
|
||||
foreach ($terr as $t=>$tz) {
|
||||
//$phptext .= '$wz["'.$z.'"]["'.$t.'"] = "'.$tz.'";'.PHP_EOL; // not using territories now - keep it simpler
|
||||
$phptext .= '$wz["'.$z.'"] = "'.$tz.'";'.PHP_EOL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$filename = 'WindowsZonesToTimeZones.txt';
|
||||
// ideally if in wordpress save somewhere one has access to
|
||||
$result = file_put_contents ( $filename //string $filename
|
||||
,$phptext //mixed $data [
|
||||
, LOCK_EX //int $flags = 0 [
|
||||
//, //resource $context ]]
|
||||
);
|
||||
|
||||
if ($result) {
|
||||
?><h2>Windows zones to timezones mapping (<?php echo $result; ?>characters) written to file: <a href="<?php echo $filename; ?>"><?php echo $filename; ?></a></h2><?php
|
||||
}
|
||||
else {
|
||||
?><h2>Error writing to windows zones mapping file <?php echo $filename; ?></h2>
|
||||
<p>If permissions prevent updating the file, you can run this script on any server and/or change the filename and then move it to the plugins timezones folder.
|
||||
It only needs to be updated in the possibly unlikley event that windows or unicode.org change the mappings.</p>
|
||||
<?php }
|
||||
?><p>Full mapping loaded, but currently only using first territory of each, only the first was written.
|
||||
<?php var_dump($tzmapping);?>
|
||||
</p><?php
|
||||
Reference in New Issue
Block a user