Пример #1
0
 /**
  * ACT method for Stand Alone Entry Form Javascript
  */
 function saef_filebrowser()
 {
     if (!class_exists('Channel_standalone')) {
         require PATH_MOD . 'channel/mod.channel_standalone.php';
     }
     $channel_js = new Channel_standalone();
     return $channel_js->saef_javascript();
 }
Пример #2
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 (!class_exists('Channel')) {
         require PATH_MOD . '/channel/mod.channel.php';
     }
     $channel = new Channel();
     //need to remove limit here so huge amounts of events work
     $channel->limit = 1000000;
     // --------------------------------------------
     //  Invoke Pagination for EE 2.4 and Above
     // --------------------------------------------
     $channel = $this->add_pag_to_channel($channel);
     // -------------------------------------
     //  Prepare parameters
     // -------------------------------------
     ee()->TMPL->tagparams['entry_id'] = $event_id;
     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
         // -------------------------------------
         if (version_compare($this->ee_version, '2.6.0', '<')) {
             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
         // -------------------------------------
         $channel->fetch_custom_channel_fields();
         $channel->fetch_custom_member_fields();
         // --------------------------------------------
         //  Pagination Tags Parsed Out
         // --------------------------------------------
         $channel = $this->fetch_pagination_data($channel);
         // -------------------------------------
         //  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
         // --------------------------------------------
         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.
         //	----------------------------------------
         $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');
         $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
         // -------------------------------------
         $channel = $this->add_pagination_data($channel);
         // -------------------------------------
         //  Related entries
         // -------------------------------------
         if (version_compare($this->ee_version, '2.6.0', '<')) {
             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
         // -------------------------------------
         //EE 2.6 compat
         $func = is_callable(array(ee()->localize, 'format_date')) ? 'format_date' : 'decode_date';
         $date = ee()->localize->{$func}('%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
         // -------------------------------------
         $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 (!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;
 }