Exemplo n.º 1
0
 function _parse_tag_url_for($m)
 {
     $url = array_key_exists($m[1], $this->site_pages['uris']) ? Structure_Helper::remove_double_slashes($this->site_pages['url'] . $this->site_pages['uris'][$m[1]]) : NULL;
     return $url;
 }
 function replace_tag($data, $params = '', $tagdata = '')
 {
     if ($data != "" && is_numeric($data)) {
         $uri = isset($this->site_pages['uris'][$data]) ? $this->site_pages['uris'][$data] : NULL;
         return Structure_Helper::remove_double_slashes(trim($this->EE->functions->fetch_site_index(0, 0), '/') . $uri);
     }
     return FALSE;
 }
Exemplo n.º 3
0
 function set_data($data, $cache_bust = false)
 {
     $site_id = $this->EE->config->item('site_id');
     $site_pages = $this->sql->get_site_pages($cache_bust, true);
     extract($data);
     // channel_id, entry_id, uri, template_id, listing_cid, parent_id, hidden
     $structure_channels = $this->get_structure_channels();
     $channel_type = $structure_channels[$data['channel_id']]['type'];
     if ($channel_type == 'page') {
         // get existing node if any out of the database
         $node = $this->nset->getNode($entry_id);
         $parentNode = $this->nset->getNode($parent_id);
         if ($node === FALSE) {
             // all fields except left and right which is handled by the nestedset library
             $extra = array('site_id' => $site_id, 'entry_id' => $entry_id, 'parent_id' => $parent_id, 'channel_id' => $channel_id, 'listing_cid' => $listing_cid, 'hidden' => $hidden, 'dead' => '');
             // create new node
             $this->nset->newLastChild($parentNode['right'], $extra);
             // fetch newly created node to keep working with
             $node = $this->nset->getNode($entry_id);
         }
         // set uri entries
         $node['uri'] = array_key_exists($entry_id, $site_pages['uris']) ? $site_pages['uris'][$entry_id] : $uri;
         $parentNode['uri'] = $parent_id ? $site_pages['uris'][$parent_id] : '';
         // existing node
         $changed = $this->has_changed($node, $data);
         if ($changed) {
             // Stay connected
             $this->EE->db->reconnect();
             // Retrieve previous listing channel id
             $prev_lcid_result = $this->EE->db->query("SELECT * FROM exp_structure WHERE entry_id = " . $entry_id);
             $prev_lcid = $prev_lcid_result->row('listing_cid');
             $listing = "";
             $lcid = $listing_cid ? $listing_cid : 0;
             // Update Structure
             $this->EE->db->query("UPDATE exp_structure SET parent_id = {$parent_id}, listing_cid = {$lcid}, hidden = '{$hidden}' WHERE entry_id = {$entry_id}");
             // Listing Channel option in tab was changed TO "Unmanaged"
             if ($prev_lcid != 0 && $lcid == 0) {
                 // Retrieve all entries for channel
                 $listing_entries = $this->EE->db->query("SELECT * FROM exp_channel_titles WHERE channel_id = " . $prev_lcid);
                 // Go through list of entries to be removed from Structure
                 foreach ($listing_entries->result_array() as $listing_entry) {
                     $listing_id = $listing_entry['entry_id'];
                     // Remove from site_pages
                     if (isset($site_pages['uris'][$listing_id])) {
                         unset($site_pages['uris'][$listing_id]);
                         unset($site_pages['templates'][$listing_id]);
                     }
                 }
                 // Remove from our table too
                 $this->EE->db->delete('structure_listings', array('channel_id' => $prev_lcid));
             } else {
                 if ($lcid != 0) {
                     $listing_channel = $lcid;
                     // Retrieve all entries for channel
                     $listing_entries = $this->sql->get_channel_listing_entries($listing_channel);
                     $channel_entries = $this->EE->db->query("SELECT entry_id, url_title FROM exp_channel_titles WHERE channel_id = {$listing_channel} AND site_id = {$site_id}");
                     $structure_channels = $this->get_structure_channels();
                     $default_template = $structure_channels[$listing_channel]['template_id'];
                     $listing_data = array();
                     // $site_pages['uris'][$node['id']] = $node['uri'];
                     // $site_pages['templates'][$data['entry_id']] = $data['template_id'];
                     foreach ($channel_entries->result_array() as $c_entry) {
                         $listing_data[] = array('site_id' => $site_id, 'channel_id' => $listing_channel, 'parent_id' => $node['id'], 'entry_id' => $c_entry['entry_id'], 'template_id' => $listing_entries[$c_entry['entry_id']]['template_id'] ? $listing_entries[$c_entry['entry_id']]['template_id'] : $default_template, 'parent_uri' => $node['uri'], 'uri' => $listing_entries[$c_entry['entry_id']]['uri'] ? $listing_entries[$c_entry['entry_id']]['uri'] : $c_entry['url_title']);
                         $site_pages['uris'][$c_entry['entry_id']] = $this->create_full_uri($node['uri'], $listing_entries[$c_entry['entry_id']]['uri'] ? $listing_entries[$c_entry['entry_id']]['uri'] : $c_entry['url_title']);
                         $site_pages['templates'][$c_entry['entry_id']] = $listing_entries[$c_entry['entry_id']]['template_id'] ? $listing_entries[$c_entry['entry_id']]['template_id'] : $default_template;
                     }
                     // Stay connected
                     $this->EE->db->reconnect();
                     // Update structure_listings table, and site_pages array with proper data
                     $this->set_listings($listing_data);
                     // Fetch newly updated site_pages array
                     // $site_pages = $this->sql->get_site_pages();
                 }
             }
             if ($changed !== TRUE) {
                 $prevUri = $node['uri'];
                 // Modify only if previous URI is root slash, allows to only affect the single page and it's entries & children
                 if ($prevUri == "/") {
                     $site_pages['uris'][$entry_id] = $uri;
                     // find out if there are children by retrieving the tree
                     // if has children then modify those and their children if they exist
                     $tree = $this->nset->getTree($entry_id);
                     if (count($tree) > 1) {
                         foreach ($tree as $child) {
                             $child_id = $child['entry_id'];
                             // replaces only first occurrence of $prevUri, makes sure only initial slash is replaced
                             $site_pages['uris'][$child_id] = Structure_Helper::remove_double_slashes(preg_replace("#" . $prevUri . "#", $uri . '/', $site_pages['uris'][$child_id], 1));
                         }
                     }
                     // if has entries then modify those as well
                     if ($listing_cid != 0) {
                         // TODO: UPDATE?
                         $listings = $this->EE->db->query("SELECT entry_id FROM exp_channel_data WHERE channel_id = {$listing_cid}");
                         foreach ($listings->result_array() as $listing) {
                             $listing_id = $listing['entry_id'];
                             // replaces only first occurrence of $prevUri, makes sure only initial slash is replaced
                             $site_pages['uris'][$listing_id] = Structure_Helper::remove_double_slashes(preg_replace("#" . $prevUri . "#", $uri . '/', $site_pages['uris'][$listing_id], 1));
                         }
                     }
                 } else {
                     if (isset($site_pages['uris'])) {
                         // @todo - refactor
                         if (array_key_exists($entry_id, $site_pages['uris']) && $site_pages['uris'][$entry_id] != "/") {
                             $local_tree = $this->nset->getTree($entry_id);
                             $adjusted_tree = array();
                             $tree_string = '';
                             foreach ($local_tree as $row) {
                                 $adjusted_tree[$row['entry_id']] = '';
                                 $tree_string .= $row['entry_id'] . ',';
                             }
                             $tree_string = rtrim($tree_string, ",");
                             $sql = "SELECT entry_id FROM exp_structure_listings WHERE parent_id IN ({$tree_string})";
                             $result = $this->EE->db->query($sql);
                             $listings = array();
                             foreach ($result->result_array() as $row) {
                                 $adjusted_tree[$row['entry_id']] = '';
                             }
                             foreach ($site_pages['uris'] as $key => &$path) {
                                 // if path is not root slash then modify as usual
                                 if (array_key_exists($key, $adjusted_tree)) {
                                     $site_pages['uris'][$key] = Structure_Helper::remove_double_slashes(str_replace($prevUri, $uri . '/', $site_pages['uris'][$key]));
                                 }
                             }
                         }
                     }
                 }
                 if ($changed === 'parent') {
                     $this->nset->moveToLastChild($node, $parentNode);
                 }
                 if ($changed === 'hidden') {
                     $this->EE->db->query("UPDATE exp_structure SET hidden = '{$hidden}' WHERE entry_id = {$entry_id} AND site_id = {$site_id}");
                 }
             }
         } else {
             // create urls for all entries when assigning a new listing channel
             if ($node['listing_cid'] != 0 && is_numeric($node['listing_cid'])) {
                 $listing_channel = $node['listing_cid'];
                 // Retrieve all entries for channel
                 $listing_entries = $this->sql->get_channel_listing_entries($listing_channel);
                 $channel_entries = $this->EE->db->query("SELECT entry_id, url_title FROM exp_channel_titles WHERE channel_id = {$listing_channel} AND site_id = {$site_id}");
                 $structure_channels = $this->get_structure_channels();
                 $default_template = $structure_channels[$listing_channel]['template_id'];
                 $listing_data = array();
                 foreach ($channel_entries->result_array() as $c_entry) {
                     $listing_data[] = array('site_id' => $site_id, 'channel_id' => $listing_channel, 'parent_id' => $node['id'], 'entry_id' => $c_entry['entry_id'], 'template_id' => $listing_entries[$c_entry['entry_id']]['template_id'] ? $listing_entries[$c_entry['entry_id']]['template_id'] : $default_template, 'parent_uri' => $node['uri'], 'uri' => $listing_entries[$c_entry['entry_id']]['uri'] ? $listing_entries[$c_entry['entry_id']]['uri'] : $c_entry['url_title']);
                     $site_pages['uris'][$c_entry['entry_id']] = $this->create_full_uri($node['uri'], $listing_entries[$c_entry['entry_id']]['uri'] ? $listing_entries[$c_entry['entry_id']]['uri'] : $c_entry['url_title']);
                     $site_pages['templates'][$c_entry['entry_id']] = $listing_entries[$c_entry['entry_id']]['template_id'] ? $listing_entries[$c_entry['entry_id']]['template_id'] : $default_template;
                 }
                 // Stay connected
                 $this->EE->db->reconnect();
                 // Update structure_listings table, and site_pages array with proper data
                 $this->set_listings($listing_data);
             }
         }
     }
     // set site_pages to be compatible with EE core
     $site_pages['uris'][$entry_id] = $uri;
     $site_pages['templates'][$entry_id] = $template_id;
     $settings = $this->sql->get_settings();
     $trailing_slash = isset($settings['add_trailing_slash']) && $settings['add_trailing_slash'] === 'y';
     if ($trailing_slash !== FALSE) {
         foreach ($site_pages['uris'] as $e_id => $uri) {
             $site_pages['uris'][$e_id] = $uri . '/';
         }
     }
     // Stay connected
     $this->EE->db->reconnect();
     $this->set_site_pages($site_id, $site_pages);
     $this->sql->update_root_node();
 }
Exemplo n.º 4
0
 function get_uri()
 {
     $settings = $this->get_settings();
     $trailing_slash = isset($settings['add_trailing_slash']) && $settings['add_trailing_slash'] === 'y' ? '/' : null;
     $uri = preg_replace("/(\\/P\\d*)/", '', Structure_Helper::remove_double_slashes('/' . $this->EE->uri->uri_string() . $trailing_slash));
     if ($uri == '') {
         $uri = '/';
         # e.g. pagination segment off homepage
     }
     return $uri;
 }