Created
April 6, 2012 15:40
-
-
Save litzinger/2320892 to your computer and use it in GitHub Desktop.
Custom StructureFrame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* Structure Fieldtype | |
* | |
* This file must be in your /system/third_party/structure directory of your ExpressionEngine installation | |
* | |
* @package StructureFrame for EE2 | |
* @author Jack McDade ([email protected]) | |
* @copyright Copyright (c) 2012 Travis Schmeisser | |
* @link http://buildwithstructure.com | |
*/ | |
require_once PATH_THIRD.'structure/config.php'; | |
require_once PATH_THIRD.'structure/sql.structure.php'; | |
class Structure_ft extends EE_Fieldtype { | |
var $info = array( | |
'name' => 'StructureFrame', | |
'version' => STRUCTURE_VERSION | |
); | |
var $structure; | |
var $sql; | |
/** | |
* Constructor | |
* | |
* @access public | |
*/ | |
function Structure_ft() | |
{ | |
parent::EE_Fieldtype(); | |
$this->sql = new Sql_structure(); | |
$this->site_pages = $this->sql->get_site_pages(); | |
$this->site_id = $this->EE->config->item('site_id'); | |
} | |
// -------------------------------------------------------------------- | |
/** | |
* Normal Fieldtype Display | |
*/ | |
function display_field($data) | |
{ | |
return $this->_pages_select($data, $this->field_name, $this->field_id); | |
} | |
/** | |
* Matrix Cell Display | |
*/ | |
function display_cell($data) | |
{ | |
return $this->_pages_select($data, $this->cell_name, $this->field_id); | |
} | |
/** | |
* Low Variables Fieldtype Display | |
* | |
* @return int entry_id of selected URL | |
*/ | |
function display_var_field($data) | |
{ | |
return $this->_pages_select($data, $this->field_name); | |
} | |
/** | |
* Low Variables Fieldtype Var Tag | |
* | |
* @return string url | |
*/ | |
function display_var_tag($var_data, $tagparams, $tagdata) | |
{ | |
return $this->EE->functions->create_page_url($this->site_pages['url'], $this->site_pages['uris'][$var_data]); | |
} | |
// -------------------------------------------------------------------- | |
/** | |
* Structure Pages Select | |
* | |
* @return string select HTML | |
* @access private | |
*/ | |
private function _pages_select($data, $name, $field_id = false) | |
{ | |
$structure_data = $this->sql->get_data(); | |
$exclude_status_list[] = "closed"; | |
$closed_parents = array(); | |
foreach ($structure_data as $key => $entry_data) | |
{ | |
if (in_array(strtolower($entry_data['status']), $exclude_status_list) || in_array($entry_data['parent_id'], $closed_parents)) | |
{ | |
$closed_parents[] = $entry_data['entry_id']; | |
unset($structure_data[$key]); | |
} | |
} | |
$structure_data = array_values($structure_data); | |
$site_pages = $this->sql->get_site_pages(); | |
$options = array(); | |
$options[''] = "-- None --"; | |
foreach ($structure_data as $page) | |
{ | |
$options['Structure Pages'][$page['entry_id']] = str_repeat('--', $page['depth']) .' '. $page['title']; | |
if ($page['listing_cid']) | |
{ | |
// Is there a listings method I can use here instead? | |
$qry = $this->EE->db->select('t.title AS title, t.entry_id AS entry_id, t.channel_id') | |
->from('structure_listings AS sl') | |
->join('channel_titles AS t', 't.entry_id = sl.entry_id') | |
->where('parent_id', $page['entry_id']) | |
->get(); | |
foreach($qry->result_array() as $listing) | |
{ | |
$url = isset($site_pages['uris'][$listing['entry_id']]) ? substr($site_pages['uris'][$listing['entry_id']], 1) : ''; | |
$options['Structure Pages'][$listing['entry_id']] = str_repeat('--', $page['depth']+1) .' '. $listing['title']; | |
} | |
} | |
} | |
/* | |
$asset_data = $this->sql->get_structure_channels('asset', '', 'alpha'); | |
if ($asset_data !== FALSE) | |
{ | |
foreach ($asset_data as $channel_id => $channel_data) | |
{ | |
$entries = $this->sql->get_entry_titles_by_channel($channel_id); | |
foreach ($entries as $entry_data) | |
{ | |
$options[$channel_data['channel_title']][$entry_data['entry_id']] = $entry_data['title']; | |
} | |
} | |
} | |
*/ | |
return form_dropdown($name, $options, $data); | |
} | |
// -------------------------------------------------------------------- | |
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 $this->EE->functions->remove_double_slashes(trim($this->EE->functions->fetch_site_index(0, 0), '/') . $uri); | |
} | |
return FALSE; | |
} | |
} | |
// END Structure_ft class | |
/* End of file ft.structure.php */ | |
/* Location: ./system/expressionengine/third_party/structure/ft.structure.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment