Exemplo n.º 1
0
 function hookSaveEventFromPost($post_id)
 {
     global $fsCalendar;
     @session_start();
     // Check autosave
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // Store the postdata in the session, because all data gets lost on the
     // frontend, when a error occurs!
     $_SESSION['fse_postdata'] = $_POST;
     // Check nonce
     if (isset($_POST['eventid']) && $action != 'view') {
         $nonce = $_POST['_fseevent'];
         if (!wp_verify_nonce($nonce, 'event')) {
             $_SESSION['fse_error'] = __('Security check failed', fsCalendar::$plugin_textdom);
             return;
         }
     }
     $active = isset($_POST['fseventactive']) && $_POST['fseventactive'] == true;
     $sync = isset($_POST['fseventsync']) && $_POST['fseventsync'] == true;
     $synconce = isset($_POST['fseventupdate']) && $_POST['fseventupdate'] == true;
     // WP Calender event active?
     if (!$active) {
         return;
     }
     // Only use the main post (nut the revisions)
     if (wp_is_post_revision($post_id) !== false) {
         return;
     }
     // Check if an event exists
     $evt = new fsEvent(0, '', true, $post_id);
     // Neuer Event
     if (empty($evt->eventid)) {
         if (!$fsCalendar->userCanAddEvents()) {
             $_SESSION['fse_error'] = __('You do not have the permission to create events', fsCalendar::$plugin_textdom);
             return;
         }
     } else {
         // Check if needs to be updated!
         //if (!$sync && !$synconce)
         //	return;
         // Check authority to edit
         if (!$evt->userCanEditEvent()) {
             $_SESSION['fse_error'] = __('No permission to edit event', fsCalendar::$plugin_textdom);
             return;
         }
     }
     // Now add all the data
     $evt->postid = $post_id;
     $evt->updatedbypost = $sync;
     // Some date are only updated when requestet
     if ($sync || $synconce) {
         $post = get_post($post_id);
         $cats = wp_get_post_categories($post_id);
         $evt->subject = $post->post_title;
         $evt->description = $post->post_content;
         $evt->categories = array();
         foreach ($cats as $c) {
             $evt->categories[] = $c;
         }
     }
     $evt->allday = isset($_POST['event_allday']) ? true : false;
     $evt->date_admin_from = $_POST['event_from'];
     $evt->date_admin_to = $_POST['event_to'];
     $evt->time_admin_from = $_POST['event_tfrom'];
     $evt->time_admin_to = $_POST['event_tto'];
     $evt->location = $_POST['event_location'];
     if (($ret = $evt->saveToDataBase()) === true) {
         $_SESSION['fse_success'] = 'Successfully saved';
     } else {
         $_SESSION['fse_error'] = $ret;
     }
     return $post_id;
 }
Exemplo n.º 2
0
    $evt->description = $_POST['content'];
    $evt->subject = $_POST['event_subject'];
    $evt->state = $_POST['event_state'];
    $evt->categories = $_POST['post_category'];
    $evt->allday = isset($_POST['event_allday']) ? 1 : 0;
    foreach ($evt as $k => $v) {
        if (is_string($v)) {
            $evt->{$k} = stripslashes($v);
        }
    }
    $referer = $_POST['referer'];
} else {
    if (isset($_GET['event'])) {
        $evt = new fsEvent(intval($_GET['event']));
    } else {
        $evt = new fsEvent(0);
    }
}
$copy = false;
if ($action == 'copy') {
    // Behave like a new one
    unset($evt->eventid);
    $action = 'new';
    $copy = true;
}
if ($action == 'new') {
    if ($evt->eventid > 0) {
        $action = 'edit';
    } else {
        if (!$fsCalendar->userCanAddEvents()) {
            $fatal[] = __('No permission to create event', fsCalendar::$plugin_textdom);
Exemplo n.º 3
0
 /**
  * Filters all {event*} tags
  * @param $content Content to filter
  * @param $evt Event Object (optional)
  * @return String Filtered content
  */
 function filterContent($content, $evt = NULL)
 {
     // Match all tags, but make sure that no escaped {} are selected!
     preg_match_all('/[^\\\\]?(\\{event[s]?_(.+?[^\\\\])\\})/is', $content, $matches, PREG_SET_ORDER);
     foreach ($matches as $k => $m) {
         $matches[$k][0] = $m[1];
         $matches[$k][1] = $m[2];
         unset($matches[$k][2]);
     }
     if (count($matches) == 0) {
         return $content;
     }
     // Get Page url if any
     $page_id = intval(get_option('fse_page'));
     if (!empty($page_id)) {
         $page_url = get_permalink($page_id);
         if (!empty($page_url)) {
             if (strpos($page_url, '?') === false) {
                 $page_url .= '?event=';
             } else {
                 $page_url .= '&event=';
             }
         }
     }
     $showenddate = get_option('fse_show_enddate') == true ? true : false;
     $hideifallday = get_option('fse_allday_hide_time') == true ? true : false;
     if (!empty($evt)) {
         // We just create an event object, if it does no exist, all var are empty!
     } elseif (isset($_GET['event'])) {
         $evt = new fsEvent(intval($_GET['event']), 'publish');
     } else {
         // Load an empty event, to get all attributes in the correct format
         $evt = new fsEvent(-1);
     }
     // Calculate duration
     $start = floor($evt->tsfrom / 60);
     $end = floor($evt->tsto / 60);
     $diff = $end - $start;
     if ($evt->allday == true) {
         $dur_days = floor($diff / 1440) + 1;
         // Add 1 day
     } else {
         $dur_days = floor($diff / 1440);
         $diff -= $dur_days * 1440;
         $dur_hours = floor($diff / 60);
         $diff -= $dur_hours * 60;
         $dur_minutes = $diff;
     }
     foreach ($matches as $m) {
         //$token = explode(';', $m[1]);
         $token = array();
         $qopen = false;
         $esc = false;
         $temp = '';
         // Covert URL Encodings
         $m[1] = html_entity_decode($m[1]);
         $m[1] = str_replace(array('”', '″', '“'), array('"', '"', '"'), $m[1]);
         /*$m[1] = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $m[1]);
         		$m[1] = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $m[1]);*/
         for ($i = 0; $i < strlen($m[1]); $i++) {
             if ($m[1][$i] == '"' && $esc == false) {
                 $qopen = !$qopen;
                 $esc = false;
                 $temp .= '"';
             } elseif ($m[1][$i] == "\\") {
                 // Maybe already escaped, just add it as well
                 if ($esc == true) {
                     $temp .= '\\';
                     // Make 2!
                     $esc = false;
                 } else {
                     $esc = true;
                 }
             } elseif ($m[1][$i] == ';' && $qopen == false) {
                 $token[] = trim($temp);
                 $temp = '';
                 $esc = false;
             } else {
                 $temp .= $m[1][$i];
                 $esc = false;
             }
         }
         if (!empty($temp)) {
             $token[] = $temp;
         }
         $opts = array();
         $opts_orig = array();
         if (count($token) > 1) {
             for ($i = 1; $i < count($token); $i++) {
                 list($opt_orig, $val) = explode('=', $token[$i], 2);
                 $val = trim($val);
                 $opt_orig = trim($opt_orig);
                 $opt = strtolower($opt_orig);
                 // Remove " "
                 preg_match('/^"(.*)"$/s', $val, $matches);
                 if (count($matches) > 0) {
                     $val = $matches[1];
                 }
                 $opts[$opt] = $val;
                 $opts_orig[$opt_orig] = $val;
             }
         }
         $tag = strtolower(trim($token[0]));
         // Reset!
         $rep = '';
         switch ($tag) {
             case 'id':
                 if (isset($opts['id'])) {
                     unset($evt);
                     $evt = new fsEvent(intval($opts['id']), 'publish');
                     $rep = '';
                 } else {
                     $rep = $evt->eventid;
                 }
                 break;
             case 'subject':
                 if (empty($evt->subject)) {
                     $rep = __('Event not found');
                 } else {
                     $rep = $evt->subject;
                 }
                 break;
             case 'location':
                 $rep = $evt->location;
                 break;
             case 'description':
                 $rep = $evt->getDescription();
                 break;
             case 'author':
                 $rep = $evt->author_t;
                 break;
             case 'publisher':
                 $rep = $evt->publishauthor_t;
                 break;
             case 'authorid':
                 $rep = $evt->author;
                 break;
             case 'publisherid':
                 $rep = $evt->publishauthor;
                 break;
             case 'startdate':
                 if (!empty($evt->tsfrom)) {
                     if (isset($opts['fmt'])) {
                         $rep = $evt->getStart($opts['fmt'], 2);
                     } else {
                         $rep = $evt->getStart('', 2);
                     }
                 } else {
                     $rep = '';
                 }
                 break;
             case 'enddate':
                 if (!empty($evt->tsto)) {
                     if (isset($opts['alwaysshowenddate'])) {
                         $l_sed = $opts['alwaysshowenddate'] == true ? true : false;
                     } else {
                         $l_sed = $showenddate;
                     }
                     // Do not display if date AND time is the same
                     if ($l_sed == false && (fsCalendar::date('d', $evt->tsto) == fsCalendar::date('d', $evt->tsfrom) && fsCalendar::date('m', $evt->tsto) == fsCalendar::date('m', $evt->tsfrom) && fsCalendar::date('Y', $evt->tsto) == fsCalendar::date('Y', $evt->tsfrom))) {
                         $rep = '';
                     } else {
                         if (isset($opts['before'])) {
                             $rep = $opts['before'];
                         } else {
                             $rep = '';
                         }
                         if (isset($opts['fmt'])) {
                             $rep .= $evt->getEnd($opts['fmt'], 2);
                         } else {
                             $rep .= $evt->getEnd('', 2);
                         }
                     }
                 } else {
                     $rep = '';
                 }
                 break;
             case 'starttime':
                 if (!empty($evt->tsfrom)) {
                     if (isset($opts['hideifallday'])) {
                         $l_hide = $opts['hideifallday'] == true ? true : false;
                     } else {
                         $l_hide = $hideifallday;
                     }
                     if ($evt->allday == true && $l_hide == true) {
                         $rep = '';
                     } else {
                         // Do not display if date AND time is the same
                         if (isset($opts['fmt'])) {
                             $rep = $evt->getStart($opts['fmt'], 3);
                         } else {
                             $rep = $evt->getStart('', 3);
                         }
                     }
                 } else {
                     $rep = '';
                 }
                 break;
             case 'endtime':
                 if (!empty($evt->tsto)) {
                     if (isset($opts['hideifallday'])) {
                         $l_hide = $opts['hideifallday'] == true ? true : false;
                     } else {
                         $l_hide = $hideifallday;
                     }
                     // Do not display if date AND time is the same
                     if (isset($opts['alwaysshowenddate'])) {
                         $l_sed = $opts['alwaysshowenddate'] == true ? true : false;
                     } else {
                         $l_sed = $showenddate;
                     }
                     if ($evt->allday == true && $l_hide == true || $l_sed == false && $evt->tsfrom == $evt->tsto) {
                         $rep = '';
                     } else {
                         if (isset($opts['before'])) {
                             $rep = $opts['before'];
                         } else {
                             $rep = '';
                         }
                         if (isset($opts['fmt'])) {
                             $rep .= $evt->getEnd($opts['fmt'], 3);
                         } else {
                             $rep .= $evt->getEnd('', 3);
                         }
                     }
                 } else {
                     $rep = '';
                 }
                 break;
             case 'duration':
                 $t = $opts['type'];
                 $a = $opts['suffix'];
                 $e = isset($opts['empty']) ? $opts['empty'] : 0;
                 if (in_array($t, array('d', 'h', 'm'))) {
                     if ($evt->allday == true) {
                         if ($t == 'd') {
                             $rep = $dur_days . $a;
                         } else {
                             $rep = '';
                         }
                     } else {
                         switch ($t) {
                             case 'd':
                                 $rep = $dur_days;
                                 break;
                             case 'h':
                                 $rep = $dur_hours;
                                 break;
                             case 'm':
                                 $rep = $dur_minutes;
                                 break;
                         }
                         if (empty($rep) && $e != 1) {
                             $rep = '';
                         } else {
                             $rep .= $a;
                         }
                     }
                 } else {
                     $rep = '';
                 }
                 break;
             case 'allday':
                 if ($evt->allday == true && isset($opts['text'])) {
                     $rep = $opts['text'];
                 } else {
                     $rep = '';
                 }
                 break;
             case 'publishdate':
                 if (!empty($evt->publishdate)) {
                     if (isset($opts['fmt'])) {
                         $rep = fsCalendar::date_i18n($opts['fmt'], $evt->publishdate);
                     } else {
                         $rep = fsCalendar::date_i18n('d.m.Y', $evt->publishdate);
                     }
                 } else {
                     $rep = '';
                 }
                 break;
             case 'publishtime':
                 if (!empty($evt->publishdate)) {
                     if (isset($opts['fmt'])) {
                         $rep = fsCalendar::date_i18n($opts['fmt'], $evt->publishdate);
                     } else {
                         $rep = fsCalendar::date_i18n('H:i', $evt->publishdate);
                     }
                 } else {
                     $rep = '';
                 }
                 break;
             case 'categories':
                 $excl = array();
                 if (isset($opts['exclude'])) {
                     $excl = explode(',', $opts['exclude']);
                 }
                 if (isset($opts['sep'])) {
                     $sep = $opts['sep'];
                 } else {
                     $sep = ', ';
                 }
                 $rep = '';
                 $first = true;
                 foreach ($evt->categories_t as $k => $c) {
                     if (!in_array($k, $excl)) {
                         if ($first == true) {
                             $first = false;
                         } else {
                             if ($sep != 'list') {
                                 $rep .= $sep;
                             }
                         }
                         if ($sep == 'list') {
                             $rep .= '<li>' . $c . '</li>';
                         } else {
                             $rep .= $c;
                         }
                     }
                 }
                 if ($sep == 'list') {
                     $rep = '<ul class="eventcategories">' . $rep . '</ul>';
                 }
                 break;
             case 'url':
                 if ($opts['linktopost'] == true && !empty($evt->postid)) {
                     $rep = get_permalink($evt->postid);
                 } elseif (!empty($page_url) && !empty($evt->eventid)) {
                     $rep = $page_url . $evt->eventid;
                 } else {
                     $rep = '';
                 }
                 break;
             case 'print':
                 $opts['echo'] = false;
                 // No echo!
                 $rep = $this->printEvents($opts);
                 break;
             case 'printlist':
                 $opts['echo'] = false;
                 // No echo!
                 $rep = $this->printEventsList($opts);
                 break;
             case 'calendar':
                 $uniqueId = substr(uniqid('fscal-'), 0, 12);
                 $rep = '<div id="' . $uniqueId . '"></div>';
                 $rep .= "<script type=\"text/javascript\">jQuery(document).ready(function() {jQuery('#{$uniqueId}').fullCalendar({";
                 // Convert hierarchical options
                 if (is_array($opts_orig)) {
                     foreach ($opts_orig as $key => $val) {
                         $keys = explode('->', $key);
                         // Process from the last to the second
                         for ($i = count($keys) - 1; $i > 0; $i--) {
                             $tmp[trim($keys[$i])] = $val;
                             $val = $tmp;
                         }
                         if (trim($keys[0]) != $key) {
                             unset($opts_orig[$key]);
                         }
                         $opts_orig[trim($keys[0])] = $val;
                     }
                 }
                 // First day of week
                 if (!isset($opts_orig['firstDay'])) {
                     if (get_option('fse_ws_wp') == true) {
                         $weekstart = get_option('start_of_week');
                     } else {
                         $weekstart = get_option('fse_ws');
                     }
                     $rep .= "firstDay: {$weekstart},";
                 }
                 // Date formats
                 if (!isset($opts_orig['timeFormat'])) {
                     $fmt = $this->convertDateFmt(get_option('time_format'));
                     $rep .= "timeFormat: \"{$fmt}\",";
                 }
                 // Translation of month and day names
                 if (!isset($opts_orig['monthNames'])) {
                     $rep .= 'monthNames: ["' . implode('","', $GLOBALS['month']) . '"],';
                 }
                 if (!isset($opts_orig['monthNamesShort'])) {
                     $rep .= 'monthNamesShort: ["' . implode('","', $GLOBALS['month_abbrev']) . '"],';
                 }
                 if (!isset($opts_orig['dayNames'])) {
                     $rep .= 'dayNames: ["' . implode('","', $GLOBALS['weekday']) . '"],';
                 }
                 if (!isset($opts_orig['dayNamesShort'])) {
                     $rep .= 'dayNamesShort: ["' . implode('","', $GLOBALS['weekday_abbrev']) . '"],';
                 }
                 if (!isset($opts_orig['titleFormat'])) {
                     $rep .= 'titleFormat: {' . 'month: "' . addslashes($this->convertDateFmt(get_option('fse_fc_tit_month_fmt'))) . '",' . 'week: "' . addslashes($this->convertDateFmt(get_option('fse_fc_tit_week_fmt'))) . '",' . 'day: "' . addslashes($this->convertDateFmt(get_option('fse_fc_tit_day_fmt'))) . '"' . '},';
                 }
                 if (!isset($opts_orig['columnFormat'])) {
                     $rep .= 'columnFormat: {' . "month: '" . addslashes($this->convertDateFmt(get_option('fse_fc_col_month_fmt'))) . "'," . "week: '" . addslashes($this->convertDateFmt(get_option('fse_fc_col_week_fmt'))) . "'," . "day: '" . addslashes($this->convertDateFmt(get_option('fse_fc_col_day_fmt'))) . "'" . '},';
                 }
                 // Button Texts
                 if (!isset($opts_orig['buttonText'])) {
                     $rep .= 'buttonText: {' . "prev: '" . __('&nbsp;&#9668;&nbsp;', self::$plugin_textdom) . "'," . "next: '" . __('&nbsp;&#9658;&nbsp;', self::$plugin_textdom) . "'," . "prevYear: '" . __('&nbsp;&lt;&lt;&nbsp;', self::$plugin_textdom) . "'," . "nextYear: '" . __('&nbsp;&gt;&gt;&nbsp;', self::$plugin_textdom) . "'," . "today: '" . __('today', self::$plugin_textdom) . "'," . "month: '" . __('month', self::$plugin_textdom) . "'," . "week: '" . __('week', self::$plugin_textdom) . "'," . "day: '" . __('day', self::$plugin_textdom) . "'},";
                 }
                 //Add all original options
                 if (is_array($opts_orig)) {
                     foreach ($opts_orig as $key => $val) {
                         $rep .= $this->filterContentProcessCalOpts($key, $val);
                     }
                 }
                 // Link Click
                 $postlink = isset($opts_orig['linktopost']) && $opts_orig['linktopost'] == true;
                 if ($postlink || isset($page_url)) {
                     $rep .= "eventClick: function(calEvent, jsEvent, view) {";
                     if ($postlink) {
                         $rep .= "if (calEvent.post_url != '') { document.location.href=calEvent.post_url; return; }";
                     }
                     if (!empty($page_url)) {
                         $rep .= "document.location.href='{$page_url}'+calEvent.id;";
                     }
                     $rep .= "},";
                 }
                 $rep .= "events: function(start, end, callback) {\n\t\t\t\t\t    \tjQuery.post(\n\t\t\t\t\t    \t\tWPCalendar.ajaxUrl,\n\t\t\t\t\t    \t\t{\n\t\t\t\t\t    \t\t\taction: 'wpcal-getevents',\n\t\t\t\t\t                start: Math.round(start.getTime() / 1000),\n\t\t\t\t\t                end: Math.round(end.getTime() / 1000)" . (isset($opts['include']) ? ",include:'" . $opts['include'] . "'" : '') . (isset($opts['exclude']) ? ",exclude:'" . $opts['exclude'] . "'" : '') . (isset($opts['categories']) ? ",categories:'" . $opts['categories'] . "'" : '') . (isset($opts['state']) ? ",state:'" . $opts['state'] . "'" : '') . (isset($opts['author']) ? ",author:'" . $opts['author'] . "'" : '') . "},\n\t\t\t\t\t    \t\tfunction(events) {\n\t\t\t\t\t    \t\t\tvar evt = eval(events);\n\t\t\t\t\t    \t\t\tcallback(evt);\n\t\t\t\t\t    \t\t}\n\t\t\t\t\t    \t);\n\t\t\t\t\t    },";
                 if ($rep[strlen($rep) - 1] == ',') {
                     $rep = substr($rep, 0, strlen($rep) - 1);
                 }
                 $rep .= '})});';
                 $rep .= '</script>';
                 break;
         }
         $content = preg_replace('/' . preg_quote($m[0], '/') . '/', str_replace('$', '\\$', $rep), $content, 1);
     }
     return $content;
 }
Exemplo n.º 4
0
    ?>
</th>
			</tr>
		</tfoot>
		<tbody>
			<?php 
    if (!is_array($events) || count($events) == 0) {
        ?>
				<tr><td colspan="8"><?php 
        _e('No events found', fsCalendar::$plugin_textdom);
        ?>
</td></tr>
				<?php 
    } else {
        foreach ($events as $e) {
            $e = new fsEvent($e);
            ?>
				<tr id="event-<?php 
            echo $e->eventid;
            ?>
" class="alternate status-<?php 
            echo esc_attr($e->state);
            ?>
 iedit" valign="top">
					<th class="check-column" scope="row">
						<input type="checkbox" value="<?php 
            echo esc_attr($e->eventid);
            ?>
" name="events[]"/>
					</th>
					<td>