Пример #1
0
 /**
  * For stand-alone entry forms
  *
  * @return	string
  */
 public function form($return_form = FALSE, $captcha = '')
 {
     // -------------------------------------
     //  Load 'em up
     // -------------------------------------
     $this->load_calendar_datetime();
     $this->load_calendar_parameters();
     $output = '';
     $event_id = '';
     $event_data = array();
     $edit = FALSE;
     // -------------------------------------
     //  Prep the parameters
     // -------------------------------------
     $params = array(array('name' => 'event_name', 'required' => FALSE, 'type' => 'bool', 'multi' => FALSE), array('name' => 'event_id', 'required' => FALSE, 'type' => 'integer', 'multi' => FALSE), array('name' => 'occurrence_id', 'required' => FALSE, 'type' => 'integer', 'multi' => FALSE), array('name' => 'occurrence_date', 'required' => FALSE, 'type' => 'date'), array('name' => 'ignore_field', 'required' => FALSE, 'type' => 'string', 'multi' => TRUE));
     //ee()->TMPL->log_item('Calendar: Processing parameters');
     $this->add_parameters($params);
     // -------------------------------------
     //  Has an event_name been provided?
     // -------------------------------------
     if ($this->P->value('event_name') !== FALSE) {
         $ids = $this->data->get_event_id_from_name($this->P->value('event_name'));
         if (!empty($ids)) {
             $event_id = $ids[0];
             $event_data = $this->data->fetch_event_data_for_view($event_id);
             if (!empty($event_data)) {
                 $edit = TRUE;
             }
         }
     } elseif ($this->P->value('event_id') !== FALSE) {
         $event_data = $this->data->fetch_event_data_for_view($this->P->value('event_id'));
         $event_id = $this->P->value('event_id');
         if (!empty($event_data)) {
             $edit = TRUE;
         }
     } elseif ($this->P->value('occurrence_id') !== FALSE) {
         $event_id = $this->data->fetch_entry_id_by_occurrence_id($this->P->value('occurrence_id'));
         if (!empty($event_id)) {
             $event_id = $event_id[0];
             $edit = TRUE;
         }
     }
     // -------------------------------------
     //  Ignore fields?
     // -------------------------------------
     $ignore_fields = array();
     if ($this->P->value('ignore_field') !== FALSE) {
         $ignore_fields = explode('|', $this->P->value('ignore_field'));
     }
     // -------------------------------------
     //  Add some hidden values if we're creating a new edited occurrence
     // -------------------------------------
     $event_data['edit_occurrence'] = FALSE;
     if ($this->P->value('occurrence_date') !== FALSE and ($this->P->value('event_name') !== FALSE or $this->P->value('event_id') !== FALSE)) {
         //ee()->TMPL->log_item('Calendar: This is an edited occurrence');
         ee()->TMPL->tagdata .= '<input type="hidden" name="entry_id" value="" />' . "\n";
         ee()->TMPL->tagdata .= '<input type="hidden" name="calendar_parent_entry_id" value="{entry_id}" />' . "\n";
         ee()->TMPL->tagdata .= '<input type="hidden" name="event_id" value="' . $event_data['event_id'] . '" />' . "\n";
         ee()->TMPL->tagdata .= '<input type="hidden" name="start_date" value="' . $this->P->value('occurrence_date', 'ymd') . '" />' . "\n";
         ee()->TMPL->tagdata .= '<input type="hidden" name="start_time" value="' . $event_data['start_time'] . '" />' . "\n";
         ee()->TMPL->tagdata .= '<input type="hidden" name="end_time" value="' . $event_data['end_time'] . '" />' . "\n";
         ee()->TMPL->var_single['entry_id'] = 'entry_id';
         $event_data['edit_occurrence'] = TRUE;
         $event_data['new_occurrence'] = TRUE;
         $event_data['occurrence_id'] = '';
         $event_data['ymd'] = $this->P->value('occurrence_date', 'ymd');
     }
     // -------------------------------------
     //  Add date widget
     // -------------------------------------
     if (strpos(ee()->TMPL->tagdata, LD . 'calendar_date_widget' . RD) !== FALSE) {
         ee()->TMPL->tagdata = str_replace(LD . 'calendar_date_widget' . RD, $this->date_widget($event_data), ee()->TMPL->tagdata);
     }
     //	----------------------------------------
     //	Invoke Channel class
     //	----------------------------------------
     if (APP_VER < 2.0) {
         if (!class_exists('Weblog')) {
             require PATH_MOD . '/weblog/mod.weblog' . EXT;
         }
         $channel = new Weblog();
     } else {
         if (!class_exists('Channel')) {
             require PATH_MOD . '/channel/mod.channel' . EXT;
         }
         $channel = new Channel();
     }
     //default is 100 and that could limit events when there are very many to be shown
     $channel->limit = 500;
     // --------------------------------------------
     //  Invoke Pagination for EE 2.4 and Above
     // --------------------------------------------
     if (APP_VER >= '2.4.0') {
         ee()->load->library('pagination');
         $channel->pagination = new Pagination_object('Channel');
         // Used by pagination to determine whether we're coming from the cache
         $channel->pagination->dynamic_sql = FALSE;
     }
     // -------------------------------------
     //  Prepare parameters
     // -------------------------------------
     ee()->TMPL->tagparams['entry_id'] = $event_id;
     ee()->TMPL->tagparams['weblog'] = CALENDAR_EVENTS_CHANNEL_NAME;
     ee()->TMPL->tagparams['channel'] = CALENDAR_EVENTS_CHANNEL_NAME;
     // -------------------------------------
     //  Editing?
     // -------------------------------------
     if ($edit === TRUE) {
         //ee()->TMPL->log_item('Calendar: Editing, so doing Weblog module tasks');
         // -------------------------------------
         //  Pre-process related data
         // -------------------------------------
         ee()->TMPL->tagdata = ee()->TMPL->assign_relationship_data(ee()->TMPL->tagdata);
         ee()->TMPL->var_single = array_merge(ee()->TMPL->var_single, ee()->TMPL->related_markers);
         // -------------------------------------
         //  Execute needed methods
         // -------------------------------------
         if (APP_VER < 2.0) {
             $channel->fetch_custom_weblog_fields();
         } else {
             $channel->fetch_custom_channel_fields();
         }
         $channel->fetch_custom_member_fields();
         // --------------------------------------------
         //  Pagination Tags Parsed Out
         // --------------------------------------------
         if (APP_VER >= '2.4.0') {
             $channel->pagination->get_template();
         } else {
             $channel->fetch_pagination_data();
         }
         // -------------------------------------
         //  Querification
         // -------------------------------------
         $channel->build_sql_query();
         if ($channel->sql == '') {
             return $this->no_results();
         }
         $channel->query = ee()->db->query($channel->sql);
         if ($channel->query->num_rows() == 0) {
             //ee()->TMPL->log_item('Calendar: Channel module says no results, bailing');
             return $this->no_results();
         }
         $channel->query->result = $channel->query->result_array();
         // --------------------------------------------
         //  Typography
         // --------------------------------------------
         if (APP_VER < 2.0) {
             if (!class_exists('Typography')) {
                 require PATH_CORE . 'core.typography' . EXT;
             }
             $channel->TYPE = new Typography();
             $channel->TYPE->text_format = 'none';
             $channel->TYPE->convert_curly = FALSE;
         } else {
             ee()->load->library('typography');
             ee()->typography->initialize();
             ee()->typography->text_format = 'none';
             ee()->typography->convert_curly = FALSE;
         }
         $no_parse = array('xhtml', 'br', 'none', 'lite');
         // -------------------------------------
         //  Add _field_name and _field_format variables
         // -------------------------------------
         foreach ($channel->query->result as $r => $row) {
             $channel->query->result[$r]['author'] = $row['screen_name'] != '' ? $row['screen_name'] : $row['username'];
             foreach ($channel->cfields[$row['site_id']] as $k => $v) {
                 if (in_array($k, $ignore_fields)) {
                     continue;
                 }
                 $channel->query->result[$r][$k . '_field_name'] = 'field_id_' . $v;
                 $channel->query->result[$r][$k . '_format_name'] = 'field_ft_' . $v;
                 $channel->query->result[$r][$k . '_format_value'] = $row['field_ft_' . $v] === NULL ? '' : $row['field_ft_' . $v];
                 // -------------------------------------
                 //  Don't apply any text formatting
                 // -------------------------------------
                 if (in_array($channel->query->result[$r]['field_ft_' . $v], $no_parse)) {
                     $channel->query->result[$r]['field_ft_' . $v] = '';
                 }
             }
         }
         //	----------------------------------------
         //	Redeclare
         //	----------------------------------------
         //	We will reassign the $channel->query->result with our
         //	reordered array of values. Thank you PHP for being so fast with array loops.
         //	----------------------------------------
         if (APP_VER < 2.0) {
             $channel->query->result = $channel->query->result;
             $super_temp_fake = $channel->query->result[0];
         } else {
             $super_temp_fake = $channel->query->result_array = $channel->query->result;
             $super_temp_fake = $channel->query->row_array();
         }
         $channel->fetch_categories();
         // -------------------------------------
         //  Prep ignored fields to be ignored
         // -------------------------------------
         $gibberish = 'e46b98f8a2a06d1ac6069e8980693dc0';
         foreach ($ignore_fields as $field) {
             ee()->TMPL->tagdata = str_replace(LD . $field, LD . $gibberish . $field, ee()->TMPL->tagdata);
         }
         // -------------------------------------
         //  Parse
         // -------------------------------------
         //ee()->TMPL->log_item('Calendar: Parsing, via channel module');
         if (APP_VER < 2.0) {
             $channel->parse_weblog_entries();
         } else {
             $channel->parse_channel_entries();
         }
         // -------------------------------------
         //  De-prep ignored fields
         // -------------------------------------
         foreach ($ignore_fields as $field) {
             $channel->return_data = str_replace(LD . $gibberish . $field, LD . $field, $channel->return_data);
         }
         // -------------------------------------
         //  Paginate
         // -------------------------------------
         if (APP_VER >= '2.4.0') {
             $channel->return_data = $this->channel->pagination->render($this->channel->return_data);
         } else {
             $channel->add_pagination_data();
         }
         // -------------------------------------
         //  Related entries
         // -------------------------------------
         if (count(ee()->TMPL->related_data) > 0 and count($channel->related_entries) > 0) {
             $channel->parse_related_entries();
         }
         if (count(ee()->TMPL->reverse_related_data) > 0 and count($channel->reverse_related_entries) > 0) {
             $channel->parse_reverse_related_entries();
         }
         // -------------------------------------
         //  Grab the goods
         // -------------------------------------
         ee()->TMPL->tagdata = $channel->return_data;
         // -------------------------------------
         //  Add some hidden variables
         // -------------------------------------
         $date = ee()->localize->decode_date('%Y-%m-%d %g:%i %A', $super_temp_fake['entry_date']);
         $more = "<input type='hidden' name='entry_date' value='{$date}' />\n";
         if ($this->P->value('occurrence_date') === FALSE or $this->P->value('event_name') === FALSE or $this->P->value('event_id') === FALSE) {
             $more .= "<input type='hidden' name='entry_id' value='{$event_id}' />\n";
         }
         ee()->TMPL->tagdata .= $more;
     } else {
         // -------------------------------------
         //  Add _field_name and _field_format variables
         // -------------------------------------
         if (APP_VER < 2.0) {
             $channel->fetch_custom_weblog_fields();
         } else {
             $channel->fetch_custom_channel_fields();
         }
         $fields = array();
         foreach ($channel->cfields[$this->data->get_site_id()] as $k => $v) {
             $fields[LD . $k . '_field_name' . RD] = 'field_id_' . $v;
             $fields[LD . $k . '_format_name' . RD] = 'field_ft_' . $v;
             $fields[LD . $k . '_format_value' . RD] = '';
         }
         ee()->TMPL->tagdata = str_replace(array_keys($fields), $fields, ee()->TMPL->tagdata);
     }
     // -------------------------------------
     //  Remove any leftover {event_ or {calendar_ variables
     // -------------------------------------
     if (strpos(ee()->TMPL->tagdata, LD . 'calendar_') !== FALSE) {
         preg_match_all('#' . LD . 'calendar_(.*?)' . RD . '#', ee()->TMPL->tagdata, $matches);
         if (!empty($matches)) {
             foreach ($matches[0] as $k => $match) {
                 ee()->TMPL->tagdata = str_replace($match, '', ee()->TMPL->tagdata);
             }
         }
     }
     if (strpos(ee()->TMPL->tagdata, LD . 'event_') !== FALSE) {
         preg_match_all('#' . LD . '(event_.*?)' . RD . '#', ee()->TMPL->tagdata, $matches);
         if (!empty($matches)) {
             foreach ($matches[0] as $k => $match) {
                 if (!in_array($matches[1][$k], $ignore_fields)) {
                     ee()->TMPL->tagdata = str_replace($match, '', ee()->TMPL->tagdata);
                 }
             }
         }
     }
     //	----------------------------------------
     //	Invoke Channel standalone class
     //	----------------------------------------
     if (APP_VER < 2.0) {
         if (!class_exists('Weblog_standalone')) {
             require_once PATH_MOD . 'weblog/mod.weblog_standalone.php';
         }
         $WS = new Weblog_standalone();
         $output = $WS->entry_form($return_form, $captcha);
     } else {
         if (!class_exists('Channel_standalone')) {
             require_once PATH_MOD . 'channel/mod.channel_standalone.php';
         }
         $CS = new Channel_standalone();
         $output = $CS->entry_form($return_form, $captcha);
     }
     //ee()->TMPL->log_item('Calendar: Done!');
     return $output;
 }
Пример #2
0
 /** ----------------------------------------
     /**  Stand-alone version of the entry form
     /** ----------------------------------------*/
 function entry_form($return_form = FALSE, $captcha = '')
 {
     if (!class_exists('Weblog_standalone')) {
         require PATH_MOD . 'weblog/mod.weblog_standalone.php';
     }
     $WS = new Weblog_standalone();
     return $WS->entry_form($return_form, $captcha);
 }