コード例 #1
0
ファイル: helper.php プロジェクト: kentonquatman/iofa
function structure_array_get($array, $key, $default = NULL)
{
    if (is_null($key)) {
        return $array;
    }
    foreach (explode(':', $key) as $segment) {
        if (!is_array($array) or !array_key_exists($segment, $array)) {
            return Structure_Helper::resolveValue($default);
        }
        $array = $array[$segment];
    }
    return $array;
}
コード例 #2
0
ファイル: ext.structure.php プロジェクト: kentonquatman/iofa
 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;
 }
コード例 #3
0
ファイル: mod.structure.php プロジェクト: kentonquatman/iofa
 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();
 }
コード例 #4
0
 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;
 }
コード例 #5
0
ファイル: sql.structure.php プロジェクト: kentonquatman/iofa
 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;
 }
コード例 #6
0
ファイル: upd.structure.php プロジェクト: kentonquatman/iofa
 function upgrade_to_ee2()
 {
     /*
     |--------------------------------------------------------------------------
     | Adios, sayonara, and farewell to "Weblogs"!
     |--------------------------------------------------------------------------
     |
     | We need to remap any references to weblogs or "wid"s to their proper
     | channel equivelants.
     |
     */
     if (!$this->EE->db->field_exists('channel_id', 'structure') && !$this->EE->db->field_exists('listing_cid', 'structure')) {
         $this->EE->dbforge->modify_column('structure', array('weblog_id' => array('name' => 'channel_id', 'type' => 'INT', 'constraint' => 6), 'listing_wid' => array('name' => 'listing_cid', 'type' => 'INT', 'constraint' => 6)));
     }
     /*
     |--------------------------------------------------------------------------
     | Table: Structure Channels
     |--------------------------------------------------------------------------
     |
     | EE1's table structure was heinous. We need to juggle data around for
     | a bit and reformat it before sticking it in the database.
     |
     */
     // Grab the EE1 settings and empty them out.
     $ee1_settings = $this->EE->db->get('structure_settings')->result_array();
     $this->EE->db->empty_table('structure_settings');
     // Prep the new table
     $this->create_table_structure_channels();
     $structure_channels = array();
     // Convert the old data format
     foreach ($ee1_settings as $setting) {
         if ($setting['var'] == "action_ajax_move" || $setting['var'] == "module_id" || $setting['var'] == "picker" || $setting['var'] == "url") {
             continue;
         }
         if (strpos($setting['var'], 'type_weblog_') !== FALSE) {
             $channel_id = str_replace('type_weblog_', '', $setting['var']);
             $structure_channels[$channel_id]['channel_id'] = $channel_id;
             $structure_channels[$channel_id]['type'] = $this->resolve_channel_type($setting['var_value']);
         } elseif (strpos($setting['var'], 'template_weblog_') !== FALSE) {
             $channel_id = str_replace('template_weblog_', '', $setting['var']);
             $structure_channels[$channel_id]['channel_id'] = $channel_id;
             $structure_channels[$channel_id]['template_id'] = $setting['var_value'];
         } else {
             // How...?
         }
         $structure_channels[$channel_id]['site_id'] = $setting['site_id'];
         $structure_channels[$channel_id]['channel_id'] = $channel_id;
         $structure_channels[$channel_id]['split_assets'] = 'n';
         $structure_channels[$channel_id]['show_in_page_selector'] = 'y';
         // @todo listing channel check
     }
     // Populate the Structure Channels table
     foreach ($structure_channels as $data) {
         $this->EE->db->insert('structure_channels', $data);
     }
     /*
     |--------------------------------------------------------------------------
     | Table: Structure Listings
     |--------------------------------------------------------------------------
     |
     | Structure for EE1 just jammed everything into two tables without respect
     | or a care in the world . Let's try to be better citizens, shall we?
     |
     */
     $this->create_table_structure_listings();
     //get all structure entries that have listings
     $structure_entries = $this->EE->db->from('structure as s')->join('structure_channels as sc', 'sc.channel_id = s.listing_cid')->where('listing_cid !=', 0)->get()->result_array();
     $site_pages = $this->EE->config->item('site_pages');
     foreach ($structure_entries as $listing_entry) {
         $data = array('site_id' => $listing_entry['site_id'], 'parent_id' => $listing_entry['channel_id'], 'channel_id' => $listing_entry['listing_cid'], 'template_id' => $listing_entry['template_id']);
         //find all the entries for this listing
         $channel_entries = $this->EE->db->from('channel_titles')->where('channel_id', $listing_entry['listing_cid'])->get()->result_array();
         foreach ($channel_entries as $channel_entry) {
             //if this entry is in site_pages get it uri and add it to the structure listings table
             if (isset($site_pages[$channel_entry['site_id']]['uris'][$channel_entry['entry_id']])) {
                 $listing_entry = array_merge($data, array('entry_id' => $channel_entry['entry_id'], 'uri' => Structure_Helper::get_slug($site_pages[$channel_entry['site_id']]['uris'][$channel_entry['entry_id']])));
                 $this->EE->db->insert('structure_listings', $listing_entry);
             }
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Extension
     |--------------------------------------------------------------------------
     |
     | We don't store any data in the extension, so it's much simpler to just
     | blow it out and reinstall it ourselves.
     |
     */
     $this->EE->db->delete('extensions', array('class' => 'Structure_ext'));
     require_once PATH_THIRD . 'structure/ext.structure.php';
     $ext = new Structure_ext();
     $ext->activate_extension();
     /*
     |--------------------------------------------------------------------------
     | Publish Tab
     |--------------------------------------------------------------------------
     |
     | We need to tell ExpressionEngine that we have a pile of useful fields to
     | add into the Publish Tab.
     |
     */
     $this->EE->load->library('layout');
     $this->EE->layout->add_layout_tabs($this->tabs(), 'structure');
     $this->EE->db->where('module_name', "Structure");
     $this->EE->db->update('modules', array('has_publish_fields' => 'y'));
 }