Esempio n. 1
0
 function safecracker_submit_entry_end($obj)
 {
     $this->site_pages = $this->sql->get_site_pages(TRUE);
     $this->EE->load->helper('url');
     // The constants in this safecracker game.
     $channel_id = $obj->channel['channel_id'];
     $channel_type = $this->sql->get_channel_type($channel_id);
     if ($channel_type == NULL) {
         return;
     }
     // If we're not working with Structure data, let's kill this quickly.
     if (!isset($obj->entry['entry_id']) || $channel_type != 'page' && $channel_type != 'listing') {
         return;
     }
     // These may not always be available so putting them *after* the conditional
     $entry_id = $obj->entry['entry_id'];
     // This defaults to false if not a listing entry
     $listing_entry = $this->sql->get_listing_entry($entry_id);
     /*
     |-------------------------------------------------------------------------
     | Template ID
     |-------------------------------------------------------------------------
     */
     $default_template = $listing_entry ? $listing_entry['template_id'] : $this->sql->get_default_template($channel_id);
     $template_id = pick(structure_array_get($obj->EE->api_sc_channel_entries->data, 'structure_template_id'), structure_array_get($this->site_pages['templates'], $entry_id));
     if (!$this->sql->is_valid_template($template_id)) {
         $template_id = $default_template;
     }
     /*
     |-------------------------------------------------------------------------
     | URI
     |-------------------------------------------------------------------------
     */
     $default_uri = $listing_entry ? structure_array_get($listing_entry, 'uri') : structure_array_get($this->site_pages['uris'], $entry_id);
     $uri = Structure_Helper::tidy_url(pick(structure_array_get($obj->EE->api_sc_channel_entries->data, 'structure_uri'), Structure_Helper::get_slug($default_uri), $obj->entry['url_title']));
     /*
     |-------------------------------------------------------------------------
     | Parent ID
     |-------------------------------------------------------------------------
     */
     $default_parent_id = $channel_type == 'listing' ? $this->sql->get_listing_parent($channel_id) : 0;
     $parent_id = pick(structure_array_get($obj->EE->api_sc_channel_entries->data, 'structure_parent_id'), $this->sql->get_parent_id($entry_id, null), $default_parent_id);
     /*
     |-------------------------------------------------------------------------
     | Parent URI
     |-------------------------------------------------------------------------
     */
     $parent_uri = structure_array_get($this->site_pages['uris'], $parent_id, '/');
     /*
     |-------------------------------------------------------------------------
     | URL
     |-------------------------------------------------------------------------
     */
     $url = $channel_type == 'listing' ? $uri : $this->sql->create_full_uri($parent_uri, $uri);
     /*
     |-------------------------------------------------------------------------
     | Listing Channel ID
     |-------------------------------------------------------------------------
     */
     $listing_cid = $this->sql->get_listing_channel($parent_id);
     /*
     |-------------------------------------------------------------------------
     | Hidden State
     |-------------------------------------------------------------------------
     */
     $hidden = pick(structure_array_get($obj->EE->api_sc_channel_entries->data, 'structure_hidden'), $this->sql->get_hidden_state($entry_id), 'n');
     /*
     |-------------------------------------------------------------------------
     | Entry data to be processed and saved
     |-------------------------------------------------------------------------
     */
     $entry_data = array('channel_id' => $channel_id, 'entry_id' => $entry_id, 'uri' => $url, 'parent_uri' => $parent_uri, 'template_id' => $template_id, 'parent_id' => $parent_id, 'listing_cid' => $listing_cid, 'hidden' => $hidden);
     if ($channel_type == 'listing') {
         $this->sql->set_listing_data($entry_data);
     } else {
         require_once PATH_THIRD . 'structure/mod.structure.php';
         $this->structure = new Structure();
         $this->structure->set_data($entry_data);
     }
 }
 function _get_dropdown($data)
 {
     $selected = structure_array_get($data, 'structure_list_type', null);
     $rows = array();
     $listing_channels = $this->sql->get_structure_channels('listing');
     $dropdown_options = array('pages' => 'Pages Tree');
     if ($listing_channels) {
         foreach ($listing_channels as $id => $channel) {
             $dropdown_options[$id] = 'Listing Channel: ' . $channel['channel_title'];
         }
     }
     return form_dropdown('structure_list_type', $dropdown_options, $selected);
 }