Skip to content
Browse files

Keep track of all uncommitted files

  • Loading branch information...
1 parent 79c7eb5 commit b238cad11fc4bccf45103ac646d48c4cb2843824 @quincykwende quincykwende committed Apr 12, 2013
Showing with 9,179 additions and 0 deletions.
  1. +3 −0 classes/cms/associator.php
  2. +3 −0 classes/cms/associator/checkboxes.php
  3. +3 −0 classes/cms/associator/radios.php
  4. +3 −0 classes/cms/controller/registration.php
  5. +3 −0 classes/cms/core.php
  6. +3 −0 classes/cms/navigation.php
  7. +3 −0 classes/cms/ui.php
  8. +3 −0 classes/cms/util.php
  9. +3 −0 classes/cms/view/csv.php
  10. +3 −0 classes/cms/view/csv/container.php
  11. +17 −0 classes/core/controller/html.php
  12. +188 −0 classes/core/controller/lattice.php
  13. +89 −0 classes/core/controller/layout.php
  14. +308 −0 classes/core/lattice.php
  15. +3 −0 classes/core/url.php
  16. +3 −0 classes/core/utility/auth.php
  17. +3 −0 classes/core/view.php
  18. +3 −0 classes/frontend/core.php
  19. +3 −0 classes/initializer/auth.php
  20. +3 −0 classes/lattice/auth/registration.php
  21. +353 −0 classes/lattice/builder/frontend.php
  22. +285 −0 classes/lattice/cms/associator.php
  23. +259 −0 classes/lattice/cms/associator/checkboxes.php
  24. +36 −0 classes/lattice/cms/associator/radios.php
  25. +134 −0 classes/lattice/cms/controller/registration.php
  26. +424 −0 classes/lattice/cms/core.php
  27. +70 −0 classes/lattice/cms/navigation.php
  28. +238 −0 classes/lattice/cms/ui.php
  29. +181 −0 classes/lattice/cms/util.php
  30. +153 −0 classes/lattice/cms/view/csv.php
  31. +27 −0 classes/lattice/cms/view/csv/container.php
  32. +13 −0 classes/lattice/controller/accessdenied.php
  33. +192 −0 classes/lattice/controller/ajax.php
  34. +191 −0 classes/lattice/controller/auth.php
  35. +21 −0 classes/lattice/controller/authstatus.php
  36. +349 −0 classes/lattice/controller/builder.php
  37. +43 −0 classes/lattice/controller/cms.php
  38. +328 −0 classes/lattice/controller/csv.php
  39. +50 −0 classes/lattice/controller/csvimports.php
  40. +383 −0 classes/lattice/controller/customreel.php
  41. +307 −0 classes/lattice/controller/export.php
  42. +78 −0 classes/lattice/controller/file.php
  43. +12 −0 classes/lattice/controller/footer.php
  44. +37 −0 classes/lattice/controller/graph.php
  45. +12 −0 classes/lattice/controller/header.php
  46. +12 −0 classes/lattice/controller/headerfooter.php
  47. +17 −0 classes/lattice/controller/initializer.php
  48. +14 −0 classes/lattice/controller/keepalive.php
  49. +25 −0 classes/lattice/controller/language.php
  50. +128 −0 classes/lattice/controller/latticeviews.php
  51. +244 −0 classes/lattice/controller/list.php
  52. +231 −0 classes/lattice/controller/navigation.php
  53. +9 −0 classes/lattice/controller/preview.php
  54. +75 −0 classes/lattice/controller/publicmenu.php
  55. +5 −0 classes/lattice/controller/registration.php
  56. +6 −0 classes/lattice/controller/rest.php
  57. +25 −0 classes/lattice/controller/setup.php
  58. +403 −0 classes/lattice/controller/usermanagement.php
  59. +18 −0 classes/lattice/controller/views.php
  60. +6 −0 classes/lattice/controller/xml.php
  61. +283 −0 classes/lattice/core/cms.php
  62. +379 −0 classes/lattice/core/cmsinterface.php
  63. +129 −0 classes/lattice/core/initializer.php
  64. +10 −0 classes/lattice/core/url.php
  65. +42 −0 classes/lattice/core/utility/auth.php
  66. +403 −0 classes/lattice/core/view.php
  67. +259 −0 classes/lattice/frontend/associator/checkboxes.php
  68. +36 −0 classes/lattice/frontend/associator/radios.php
  69. +79 −0 classes/lattice/frontend/controller/associator.php
  70. +47 −0 classes/lattice/frontend/core.php
  71. +257 −0 classes/lattice/graph.php
  72. +82 −0 classes/lattice/graph/objectquery.php
  73. +62 −0 classes/lattice/initializer/auth.php
  74. +16 −0 classes/lattice/initializer/cms.php
  75. +33 −0 classes/lattice/initializer/lattice.php
  76. +108 −0 classes/model/file/image.php
  77. +15 −0 cookbook/dumpDataTables/dataTables.txt
  78. +5 −0 cookbook/dumpDataTables/dumpLatticeDataTables.sh
  79. +714 −0 cookbook/dumpDataTables/latticeData.sql
  80. +42 −0 cookbook/lattice.htaccess
  81. +17 −0 lattice/cms_modules.dtd
  82. +8 −0 lattice/cms_modules.xml
  83. +21 −0 views/initialization_messages.php
  84. +8 −0 views/lattice_installed.php
  85. +8 −0 views/lattice_not_installed.php
  86. +7 −0 views/move_controls.php
  87. +17 −0 views/navigation_node.php
  88. +6 −0 views/navigation_tier.php
  89. +13 −0 views/tier_methods_drawer.php
  90. +7 −0 views/ui/item.php
  91. +12 −0 views/ui/multi_select.php
  92. +10 −0 views/ui/radio_group.php
View
3 classes/cms/associator.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Cms_Associator extends Lattice_Cms_Associator { }
View
3 classes/cms/associator/checkboxes.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Cms_Associator_Checkboxes extends Lattice_Cms_Associator_Checkboxes { }
View
3 classes/cms/associator/radios.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Cms_Associator_Radios extends Lattice_Cms_Associator_Radios { }
View
3 classes/cms/controller/registration.php
@@ -0,0 +1,3 @@
+<?php
+
+Class Cms_Controller_Registration extends Lattice_Cms_Controller_Registration { }
View
3 classes/cms/core.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+abstract class Cms_Core extends Lattice_Cms_Core { }
View
3 classes/cms/navigation.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Cms_Navigation extends Lattice_Cms_Navigation { }
View
3 classes/cms/ui.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Cms_Ui extends Lattice_Cms_Ui { }
View
3 classes/cms/util.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+abstract class Cms_Util extends Lattice_Cms_Util { }
View
3 classes/cms/view/csv.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Cms_View_Csv extends Lattice_Cms_View_Csv { }
View
3 classes/cms/view/csv/container.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Cms_View_Csv_Container extends Lattice_Cms_View_Csv_Container { }
View
17 classes/core/controller/html.php
@@ -0,0 +1,17 @@
+<?php
+/*
+ * Class: Core_Controller_Html
+ * This controller provides a simple manual override to the auto layout wrapping
+ * implemented in Core_Controller_Layout subclasses.
+ */
+
+Class Core_Controller_Html extends Core_Controller_Lattice {
+
+ public function action_html($uri)
+ {
+
+ $sub_request = Request::Factory($uri)->execute();
+ $this->response->body($sub_request->body());
+ }
+
+}
View
188 classes/core/controller/lattice.php
@@ -0,0 +1,188 @@
+<?php
+
+class Core_Controller_Lattice extends Controller {
+
+ public static $top_controller;
+
+ public $resources = array(
+ 'js'=>array(),
+ 'libraryjs'=>array(),
+ 'css'=>array(),
+ 'librarycss'=>array(),
+ );
+
+ public $controller_name;
+
+
+ // constructor
+ public function __construct($request, $response)
+ {
+ parent::__construct($request, $response);
+
+ // set the language requirements
+
+ $language_code = NULL;
+ if ( ! Session::instance()->get('language_code') )
+ {
+ $language_code = Kohana::config('lattice.default_language');
+ Session::instance()->set('language_code', $language_code );
+ }else{
+ $language_code = Session::instance()->get('language_code');
+ }
+ if ( ! $language_code)
+ {
+ throw new Kohana_Exception('No language code found');
+ }
+ i18n::lang( $language_code );
+
+
+ $this->controller_name = strtolower(substr(get_class($this), 11));
+ $this->check_access();
+
+ if ($request->is_initial())
+ {
+ self::$top_controller = $this;
+ }
+ // look up all matching js and css based off controller name
+
+ $this->load_resources();
+
+ }
+
+ /*
+ * Function: check_access()
+ * Default function for acccess checking for a controller. Can be overridden in child classes
+ * Checks logged in user against authrole array in config file for controller
+ * Parameters:nothing, except config file
+ * Returns: nothing
+ */
+ public function check_access()
+ {
+ // Authentication check
+ $roles = Kohana::config(strtolower($this->controller_name).'.authrole', FALSE, FALSE);
+
+ // checked if logged in
+ if ($roles AND ! Auth::instance()->logged_in())
+ {
+ Request::current()->redirect(url::site('auth/login/',Request::current()->protocol(),FALSE).'/'.Request::initial()->uri());
+ exit;
+ }
+ if (is_array($roles))
+ {
+ $access_granted = FALSE;
+ foreach ($roles as $a_role)
+ {
+ if ($a_role=='admin')
+ {
+ if (Kohana::config('lattice.staging_enabled') AND ! Kohana::config('lattice.staging'))
+ {
+ $redirect = 'staging/'. Router::$current_uri;
+ Request::current()->redirect(url::site($redirect,Request::current()->protocol(),FALSE));
+ }
+ }
+
+ if (cms_util::check_role_access($a_role))
+ {
+ $access_granted = TRUE;
+ }
+ }
+ } else {
+ if ($roles=='admin')
+ {
+ if (Kohana::config('lattice.staging_enabled') AND ! Kohana::config('lattice.staging'))
+ {
+ $redirect = 'staging/'. Router::$current_uri;
+ Request::current()->redirect(url::site($redirect,Request::current()->protocol(),FALSE));
+ }
+ }
+
+ $access_granted = cms_util::check_role_access($roles);
+ }
+
+ if ( ! $access_granted)
+ {
+ $redirect = 'accessdenied';
+ Request::current()->redirect(url::site($redirect,Request::current()->protocol(),FALSE));
+ exit;
+ }
+
+ }
+
+ protected function load_resources()
+ {
+ $this->load_resources_for_key(strtolower($this->controller_name));
+
+ $parents = array_reverse($this->get_parents());
+ foreach ($parents as $parent)
+ {
+ if (strpos($parent, 'Controller')===0)
+ {
+ $parent_key = substr($parent, 11);
+ } else {
+ $parent_key = $parent;
+ }
+ $this->load_resources_for_key(strtolower($parent_key));
+ }
+ }
+
+ protected function load_resources_for_key($key)
+ {
+
+ // Kohana::$log->add( Kohana_Log::INFO, "application/config/lattice_cms.php " . print_r( $config['resources']['libraryjs'], 1 ) );
+
+ if (self::$top_controller == NULL)
+ {
+ return;
+ // self::$top_controller should not be NULL, in order to use load_resources_for_key you must extend Core_Controller_Lattice in the controller of your initial route
+ }
+
+ // should add to self, then merge into top_controller
+ if ($css = Kohana::find_file('resources', 'css/'.$key, 'css'))
+ {
+ $this->resources['css'][$css] = core_lattice::convert_full_path_to_web_path($css);
+ }
+ if ($js = Kohana::find_file('resources', 'js/'.$key, 'js'))
+ {
+ $this->resources['js'][$js] = core_lattice::convert_full_path_to_web_path($js);
+ }
+
+ $config = Kohana::config($key);
+ // look up all matching js and css configured in the config file
+ if ( is_array(Kohana::config($key.'.resources') ) )
+ {
+ foreach (Kohana::config($key.'.resources') as $key => $paths)
+ {
+ foreach ($paths as $path)
+ {
+ $this->resources[$key][$path] = $path;
+ }
+ }
+ }
+
+ // and merge into the top controller
+ if ($this != self::$top_controller)
+ {
+ foreach (array_keys($this->resources) as $key)
+ {
+ self::$top_controller->resources[$key] = array_merge(self::$top_controller->resources[$key], $this->resources[$key]);
+ }
+ }
+
+ }
+
+ public function get_parents($class=NULL, $plist=array())
+ {
+ $class = $class ? $class : $this;
+ $parent = get_parent_class($class);
+ if ($parent)
+ {
+ $plist[] = $parent;
+ /*Do not use $this. Use 'self' here instead, or you
+ * * will get an infinite loop. */
+ $plist = self::get_parents($parent, $plist);
+ }
+ return $plist;
+ }
+
+
+}
View
89 classes/core/controller/layout.php
@@ -0,0 +1,89 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+/*
+ * Class: Core_Controller_Layout
+ * Extension of Core_Controller_Lattice which handles automatic wrapping of the main request in header and footer layout.
+ * Extend this class and set $_aactions_that_get_layout with actions that should always be wraped with the layout specified in their config.
+ * In the future, config could have a mapping of actions to layouts, if necessary.
+ * Auto wrapping can be manually bypassed by calling the html action as html/controller/action/etc.
+ */
+
+class Core_Controller_Layout extends Core_Controller_Lattice {
+
+ protected $_actions_that_get_layout = array();
+
+ protected $sub_request;
+
+ public function after()
+ {
+ if ($this->request == Request::initial() )
+ {
+ if (in_array($this->request->action(), $this->_actions_that_get_layout))
+ {
+ $this->wrap_with_layout();
+ }
+ }
+ }
+
+ /*
+ * Function: output_layout
+ * Wrap the response in its configured layout
+ */
+ public function wrap_with_layout($layout=NULL)
+ {
+ if ($layout==NULL)
+ {
+ // set layout - read from config file
+ $layout = Kohana::config(strtolower($this->request->controller()) . '.layout');
+ if ( ! $layout)
+ {
+ throw new Kohana_Exception("Layout controller subclass :controller configured to layout action :action, but no layout set in configuration",
+ array(
+ ':controller'=>$this->request->controller(),
+ ':action'=>$this->request->action()
+ ));
+
+ }
+ }
+ $layout_view = View::Factory($layout);
+
+ if (is_array(Kohana::config($layout.'.resources') ) )
+ {
+ foreach (Kohana::config($layout.'.resources') as $key => $paths)
+ {
+ foreach ($paths as $path)
+ {
+ $this->resources[$key][$path] = $path;
+ }
+ }
+ }
+
+ // build js and css
+ $stylesheet = '';
+ foreach ($this->resources['librarycss'] as $css)
+ {
+ $stylesheet .= HTML::style($css)."\n ";
+ }
+ foreach ($this->resources['css'] as $css)
+ {
+ $stylesheet .= HTML::style($css)."\n ";
+ }
+ $layout_view->stylesheet = $stylesheet;
+
+ $javascript = '';
+ foreach ($this->resources['libraryjs'] as $js)
+ {
+ $javascript .= HTML::script($js)."\n ";
+ }
+ foreach ($this->resources['js'] as $js)
+ {
+ $javascript .= HTML::script($js)."\n ";
+ }
+ $layout_view->javascript = $javascript;
+
+ $layout_view->body = $this->response->body();
+ $this->response->body($layout_view->render());
+ }
+
+
+} // End Welcome
View
308 classes/core/lattice.php
@@ -0,0 +1,308 @@
+<?php
+/* @package Lattice */
+
+class MyDOMDocument {
+ public $_delegate;
+ private $_validation_errors;
+
+ public function __construct (DOMDocument $p_document)
+ {
+ $this->_delegate = $p_document;
+ $this->_validation_errors = array();
+ }
+
+ public function __call ($p_method_name, $p_args)
+ {
+ if ($p_method_name == "validate")
+ {
+ $eh = set_error_handler(array($this, "on_validate_error"));
+ $rv = $this->_delegate->validate();
+ if ($eh)
+ {
+ set_error_handler($eh);
+ }
+ return $rv;
+ }
+ else {
+ return call_user_func_array(array($this->_delegate, $p_method_name), $p_args);
+ }
+ }
+ public function __get ($p_member_name)
+ {
+ if ($p_member_name == "errors")
+ {
+ return $this->_validation_errors;
+ }
+ else {
+ return $this->_delegate->$p_member_name;
+ }
+ }
+ public function __set ($p_member_name, $p_value)
+ {
+ $this->_delegate->$p_member_name = $p_value;
+ }
+ public function on_validate_error ($p_no, $p_string, $p_file = NULL, $p_line = NULL, $p_context = NULL)
+ {
+ $this->_validation_errors[] = preg_replace("/^.+: */", "", $p_string).$p_line;
+ }
+}
+
+
+Class Core_Lattice {
+
+ private static $config;
+
+
+ public static function config($arena, $xpath, $context_node=NULL)
+ {
+
+ // var_dump(Kohana::config('lattice.active_configuration')); exit;
+
+ if ( ! is_array(self::$config))
+ {
+ self::$config = array();
+ }
+
+ if ($active_config = Kohana::config('lattice.active_configuration'))
+ {
+ if ($configurations = Kohana::config('lattice.configurations'))
+ {
+ if ($active = $configurations[$active_config])
+ {
+ if (isset($active[$arena]) AND $new_name = $active[$arena])
+ {
+ $arena = $new_name;
+ }
+ }
+ }
+ }
+
+ if ( ! isset(self::$config[$arena]))
+ {
+
+ $dom = new DOMDocument();
+ $dom->preserve_white_space = FALSE;
+ $dom = new MyDOMDocument($dom);
+
+ // check for arena mappings
+ if ($custom_path = Kohana::config('lattice.paths.'.$arena))
+ {
+ $arena_path = $custom_path;
+ } else {
+ $arena_path = $arena;
+ }
+
+ $request = NULL;
+ $response = NULL;
+ try{
+ $request = Request::Factory($arena_path);
+ $response = $request->execute();
+
+ } catch(Exception $e)
+ {
+ // checking for existence of xml controller
+ if (get_class($e) != 'HTTP_Exception_404')
+ {
+ throw $e;
+ }
+ // else continue on
+ }
+
+ if ($response)
+ {
+ $dom->loadXML($response->body());
+
+ } else {
+
+ if (file_exists($arena_path))
+ {
+ // if the argument is actually a path to a file
+ $arena_path = getcwd() . '/' . $arena_path;
+ } else {
+ $arena_file_path = Kohana::find_file('lattice', $arena_path, 'xml', TRUE);
+ if ( ! count($arena_file_path))
+ {
+ throw new Kohana_Exception('Could not locate xml :file', array(':file' => $arena_path));
+ }
+ $arena_path = $arena_file_path[count($arena_file_path) - 1];
+ }
+ $dom->load($arena_path);
+ }
+ if ( ! $dom->validate())
+ {
+ throw new Kohana_Exception("Validation failed on :arena_path \n :xml_error_trace", array(
+ ':arena_path' => $arena_path,
+ ':xml_error_trace' => var_export($dom->errors, TRUE)
+ ));
+ }
+
+ if ($arena == 'objects')
+ {
+ $clusters = new DOMDocument();
+ $clusters = new MYDOMDocument($clusters);
+ $path = Kohana::find_file('lattice', 'clusters', 'xml', TRUE);
+ if ( ! count($path))
+ {
+ throw new Kohana_Exception('Could not locate xml clusters');
+ }
+ $clusters->load( $path[0] );
+ // echo $clusters->_delegate->saveXML();
+ $clusters = new DOMXPath($clusters->_delegate);
+ $cluster_nodes = $clusters->evaluate('//objectType');
+ foreach ($cluster_nodes as $node)
+ {
+ $node = $dom->_delegate->importNode($node, TRUE);
+ $object_types_node = $dom->_delegate->getElementsByTagName('objectTypes')->item(0);
+ $object_types_node->appendChild($node);
+ // $dom->_delegate->insert_before($node, $ref_node);
+ }
+ // recreate Xpath object
+ // $dom->format_output;
+ // echo $dom->_delegate->saveXML();
+ }
+
+ $xpath_object = new DOMXPath($dom->_delegate);
+
+
+ self::$config[$arena] = $xpath_object;
+ }
+ if ($context_node)
+ {
+ $xml_nodes = self::$config[$arena]->evaluate($xpath, $context_node);
+ } else {
+ $xml_nodes = self::$config[$arena]->evaluate($xpath);
+ }
+ return $xml_nodes;
+ }
+
+ /*
+ * Function: build_module
+ This is the same function as in Display_Controller..
+ Obviously these classes should share a parent class or this is a static helper
+ Parameters:
+ $module - module configuration parameters
+ $constructor_arguments - module arguments to constructor
+ */
+ public static function build_module($module, $constructor_arguments=array() )
+ {
+ // need to look into this, these should be converged or interoperable
+ if (isset($module['elementname']))
+ {
+ $module['modulename'] = $module['elementname'];
+ }
+
+ if ( ! Kohana::find_file('controllers', $module['modulename'] ) )
+ {
+ if ( ! isset($module['controllertype']))
+ {
+ $view = new View($module['modulename']);
+ $object = Graph::object($module['modulename']);
+ if ($object->loaded())
+ { // in this case it's a slug for a specific object
+ foreach (core_views::get_view_content($object->id, $object->objecttype->objecttypename) as $key=>$content)
+ {
+ $view->$key = $content;
+ }
+ }
+ return $view->render();
+ }
+ try {
+ if ( ! class_exists($module['modulename'].'_Controller'))
+ {
+ $includeclass = 'class '.$module['modulename'].'_Controller extends '.$module['controllertype'].'_Controller { } ';
+ eval($includeclass);
+ }
+ } catch (Exception $e)
+ {
+ throw new Kohana_User_Exception('Redeclared Virtual Class', 'Redeclared Virtual Class '. 'class '.$module['modulename'].'_Controller ');
+ }
+ }
+
+ $fullname = $module['modulename'].'_Controller';
+ $module = new $fullname; // this needs to be called with fargs
+ call_user_func_array(array($module, '__construct'), $constructor_arguments);
+
+ $module->create_index_view();
+ $module->view->load_resources();
+
+ // and load resources for it's possible parents
+ $parentclass = get_parent_class($module);
+ $parentname = str_replace('_Controller', '', $parentclass);
+ $module->view->load_resources(strtolower($parentname));
+
+ // build submodules of this module (if any)
+ $module->build_modules();
+
+ return $module->view->render();
+
+ // render some html
+ //
+ // BELOW HERE NEEDS TO BE FIXED IN ALL CHILDREN OF Lattice_CONTROLLER
+ // CONTROLERS SHOULD JUST ASSIGN TEMPLATE VARS THEN AND THERE
+ if ($object_typevar==NULL)
+ {
+ $this->view->$module['modulename'] = $module->view->render();
+ } else {
+ $this->view->$object_typevar = $module->view->render();
+ }
+ }
+
+ public static function set_current_language($language_code)
+ {
+ Session::instance()->set('language_code', $language_code);
+ }
+
+ public static function get_current_language()
+ {
+ $language_code = Session::instance()->get('language_code');
+ if ( ! $language_code)
+ {
+ $language_code = Kohana::config('lattice.default_language');
+ }
+ return $language_code;
+ }
+
+ // takes Exception as argument
+ public static function get_one_line_error_report(Exception $e)
+ {
+ switch(get_class($e))
+ {
+ case 'Lattice_Api_exception':
+ // echo get_class($e);
+ // die();
+ return $e->get_one_line_error_report();
+ break;
+ default:
+ $message = $e->get_message();
+ foreach ( $e->get_trace() as $trace)
+ {
+ if (isset($trace['file']))
+ {
+ $message .= " ::::: ".$trace['file'].':'.$trace['line']."\n;";
+ }
+ }
+ return $message;
+ break;
+ }
+ }
+
+ public static $web_root = NULL;
+
+ public static function convert_full_path_to_web_path($full_path)
+ {
+
+
+ if (self::$web_root == NULL)
+ {
+ self::$web_root = getcwd().'/';
+ }
+ $webpath = str_replace(self::$web_root, '', $full_path);
+
+ return $webpath;
+ }
+
+
+}
+
+
+
View
3 classes/core/url.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+abstract class Core_Url extends Lattice_Core_Url { }
View
3 classes/core/utility/auth.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Core_Utility_Auth extends Lattice_Core_Utility_Auth { }
View
3 classes/core/view.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Core_View extends Lattice_Core_View { }
View
3 classes/frontend/core.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+abstract class Frontend_Core extends Lattice_Frontend_Core { }
View
3 classes/initializer/auth.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Initializer_Auth extends Lattice_Initializer_Auth { }
View
3 classes/lattice/auth/registration.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Cms_Controller_Registration extends Kohana_Cms_Controller_Registration { }
View
353 classes/lattice/builder/frontend.php
@@ -0,0 +1,353 @@
+<?php
+
+Class Lattice_Builder_Frontend {
+
+ private $base_path = 'application/views/generated/';
+
+ public function __construct()
+ {
+ if ( ! is_writable($this->base_path))
+ {
+ die($this->base_path.' must be writable');
+ }
+ }
+
+ public function index()
+ {
+ echo "Configuring Frontend\n";
+ echo "Reading application/config/frontend.xml\n";
+
+ core_lattice::config('objects', '//objectTypes');
+
+ cms_util::flush_ob();
+
+ $created_views = array();
+ foreach (core_lattice::config('objects', '//objectType') as $object_type)
+ {
+ $view = core_lattice::config('frontend', '//view[@name="'.$object_type->getAttribute('name').'"]');
+ if (count($view))
+ {
+ $view = $view->item(0);
+ }
+
+ if ($view)
+ {
+ $view_name = $view->getAttribute('name');
+ } else {
+ $view_name = $object_type->getAttribute('name');
+ }
+ echo $view_name."\n";
+
+ cms_util::flush_ob();
+
+ ob_start();
+ if ( ! $view OR ($view AND $view->getAttribute('load_page')=='TRUE'))
+ {
+ echo "<h1><?php echo \$content['main']['title'];?></h1>\n\n";
+ // this also implies that name is a objecttypename
+ foreach (core_lattice::config('objects',
+ sprintf('//objectType[@name="%s"]/elements/*', $view_name )) as $element)
+ {
+
+ switch($element->tagName)
+ {
+ case 'list':
+ $this->make_list_data_html($element, "\$content['main']");
+ break;
+ case 'associator':
+ $this->make_associator_data_html($element, "\$content['main']");
+ break;
+ default:
+ frontend_core::make_html_element($element, "\$content['main']");
+ break;
+ }
+
+ }
+
+ if ($view AND $view->getAttribute('load_page')=='TRUE')
+ {
+
+ // Now the include_data
+ if ($i_data_nodes = core_lattice::config('frontend',"//view[@name=\"".$view->getAttribute('name')."\"]/includeData"))
+ {
+ foreach ($i_data_nodes as $i_data_config)
+ {
+ $prefix = "\$content";
+ $this->make_include_data_html($i_data_config, $prefix, NULL);
+ }
+ }
+
+ if ($subviews = core_lattice::config('frontend',"//view[@name=\"".$view->getAttribute('name')."\"]/subview"))
+ {
+ foreach ($subviews as $subview_config)
+ {
+ echo "\n<?php echo \$".$subview_config->getAttribute('label')."; ?>\n";
+ }
+ }
+
+ }
+
+
+
+ $html = ob_get_contents();
+ ob_end_clean();
+ $file = fopen($this->base_path.$view_name.'.php', 'w');
+ fwrite($file, $html);
+ fclose($file);
+
+ $created_views[] = $view_name;
+ }
+ }
+
+ echo 'Completed all basic object views' . "\n";
+ cms_util::flush_ob();
+
+ // and any virtual views
+ foreach (core_lattice::config('frontend', '//view') as $view_config)
+ {
+ $view_name = $view_config->getAttribute('name');
+
+ if ( in_array($view_name, $created_views))
+ {
+ continue;
+ }
+ echo 'Virtual View: '.$view_name . "\n";
+ touch($this->base_path.$view_name.'.php');
+
+ cms_util::flush_ob();
+ ob_start();
+
+
+ // Now the include_data
+ if ($i_data_nodes = core_lattice::config('frontend',"//view[@name=\"".$view_name."\"]/includeData"))
+ {
+ foreach ($i_data_nodes as $i_data_config)
+ {
+ $prefix = "\$content";
+ $this->make_include_data_html($i_data_config, $prefix, NULL);
+ }
+ }
+
+ if ($subviews = core_lattice::config('frontend',"//view[@name=\"".$view_name."\"]/subview"))
+ {
+ foreach ($subviews as $subview_config)
+ {
+ echo "\n<?php echo \$".$subview_config->getAttribute('label')."; ?>\n";
+ }
+ }
+
+
+ $html = ob_get_contents();
+ ob_end_clean();
+ $file = fopen($this->base_path.$view_name.'.php', 'w');
+ fwrite($file, $html);
+ fclose($file);
+ }
+
+
+
+ echo "Done\n";
+ }
+
+ public function make_list_data_html($list_data_config, $prefix, $indent = '')
+ {
+ $object_types = array();
+ foreach (core_lattice::config('objects', 'addable_object', $list_data_config) as $addable)
+ {
+ $objectTypeName = $addable->getAttribute('objectTypeName');
+ $object_types[$objectTypeName] = $objectTypeName;
+ }
+
+ $this->make_multi_object_type_loop($object_types, $list_data_config->getAttribute('name'), $prefix, $indent);
+
+ }
+
+ // TODO: This doesn't currently support filter types that don't declare objec_type_names or
+ // nor with multiple objectTypeNames per filter
+ public function make_associator_data_html($associator_data_config, $prefix, $indent = '')
+ {
+ $object_types = array();
+ $filters = core_lattice::config('objects', 'filter', $associator_data_config);
+ foreach ($filters as $filter)
+ {
+ if ($filter->getAttribute('objectTypeName'))
+ {
+ $object_types[] = $filter->getAttribute('objectTypeName');
+ }
+ }
+
+ $this->make_multi_object_type_loop($object_types, $associator_data_config->getAttribute('name'), $prefix, $indent);
+ }
+
+
+ public function make_include_data_html($i_data_config, $prefix, $parent_template, $indent='')
+ {
+ $label = $i_data_config->getAttribute('label');
+
+
+ $object_types = array();
+ // if slug defined, get object_type from slug
+ if ($slug = $i_data_config->getAttribute('slug'))
+ {
+ $object = Graph::object($slug);
+ if ( ! $object->loaded())
+ {
+ // error out,
+ // object must be loaded from data.xml for this type of include conf
+ }
+ $object_types[] = $object->objecttype->objecttypename;
+ }
+ if ( ! count($object_types))
+ {
+ $object_types = $i_data_config->getAttribute('object_type_filter');
+ if ($object_types!='all')
+ {
+ $object_types = explode(',', $object_types);
+ } else {
+ $object_types = array();
+ }
+ }
+
+ if ( ! count($object_types))
+ {
+ // no where for object_types
+ // assume that we'll have to make a good guess based off 'from' parent
+ $from=$i_data_config->getAttribute('from');
+ if ($from=="parent")
+ {
+
+ // get the info from addable_objects of the current
+ foreach (core_lattice::config('objects', sprintf('//objectType[@name="%s"]/addable_object', $parent_template)) as $addable)
+ {
+ $objectTypeName = $addable->getAttribute('objectTypeName');
+ $object_types[$objectTypeName] = $objectTypeName;
+ }
+
+ // and we can also check all the existing data to see if it has any other object_types
+ $parent_objects = Graph::object()->objecttype_filter($parent_template)->published_filter()->find_all();
+ foreach ($parent_objects as $parent)
+ {
+ $children = $parent->get_published_children();
+ foreach ($children as $child)
+ {
+ $objectTypeName = $child->objecttype->objecttypename;
+ $object_types[$objectTypeName] = $objectTypeName;
+ }
+ }
+ } else {
+ // see if from is a slug
+ $object_types_from_parent = $this->get_children_object_types(Graph::object($from));
+ $object_types = array_merge($object_types, $object_types_from_parent);
+
+
+ }
+ }
+
+ // now $object_types contains all the needed object_types in the view
+
+
+ $this->make_multi_object_type_loop($object_types, $label, $prefix, $indent, $i_data_config);
+ }
+
+ protected function make_multi_object_type_loop($object_types, $label, $prefix, $indent='', $frontend_node=NULL )
+ {
+ echo $indent."<h2>$label</h2>\n\n";
+ echo $indent."<ul id=\"$label\" >\n";
+ $do_switch = FALSE;
+
+
+ if (count($object_types)>1)
+ {
+ $do_switch = TRUE;
+ }
+
+ echo $indent."<?php foreach ({$prefix}['$label'] as \${$label}Item):?>\n";
+ if ($do_switch)
+ {
+ echo $indent." <?php switch(\${$label}Item['objectTypeName'])
+ {\n";
+ }
+
+ if (count($object_types) == 0)
+ {
+ echo $indent." <?php echo core_view::Factory(\${$label}Item)->view()->render(); ?>\n";
+ }
+
+ $i=0;
+ foreach ($object_types as $objectTypeName)
+ {
+ if ($do_switch)
+ {
+ echo $indent;
+ if ($i==0)
+ echo " case '$objectTypeName':?>\n";
+ else
+ echo " <?php case '$objectTypeName':?>\n";
+ }
+ echo $indent . " <li class=\"$objectTypeName\">\n";
+ echo $indent . " " . "<h2><?php echo \${$label}Item['title'];?></h2>\n\n";
+ foreach (core_lattice::config('objects', sprintf('//objectType[@name="%s"]/elements/*', $objectTypeName)) as $element)
+ {
+ switch($element->tagName)
+ {
+ case 'list':
+ $this->make_list_data_html($element, "\${$label}Item", $indent);
+ break;
+ case 'associator':
+ $this->make_associator_data_html($element, "\${$label}Item", $indent);
+ break;
+ default:
+ frontend_core::make_html_element($element, "\${$label}Item", $indent . " ");
+ break;
+ }
+ }
+
+ // handle lower levels
+ if ($frontend_node)
+ {
+ foreach (core_lattice::config('frontend', 'includeData', $frontend_node) as $next_level)
+ {
+ $this->make_include_data_html($next_level, "\${$label}Item", $objectTypeName, $indent . " ");
+ }
+ }
+
+ echo $indent . " </li>\n";
+ if ($do_switch)
+ {
+ echo $indent . " <?php break; ?>\n";
+ }
+ $i++;
+ }
+ if ($do_switch)
+ {
+ echo $indent . "<?php } ?>\n";
+ }
+
+
+ echo $indent . "<?php endforeach; ?>\n" .
+ $indent . "</ul>\n\n";
+ }
+
+ protected function get_children_object_types($object)
+ {
+ $object_types = array();
+ if ($object->loaded())
+ {
+ // find its addable objects
+ foreach (core_lattice::config('objects', sprintf('//objectType[@name="%s"]/addable_object', $object->objecttype->objecttypename)) as $addable)
+ {
+ $objectTypeName = $addable->getAttribute('objectTypeName');
+ $object_types[$objectTypeName] = $objectTypeName;
+ }
+ // and follow up with any existing data
+ $children = $object->get_published_children();
+ foreach ($children as $child)
+ {
+ $objectTypeName = $child->objecttype->objecttypename;
+ $object_types[$objectTypeName] = $objectTypeName;
+ }
+ }
+ return $object_types;
+
+ }
+ }
View
285 classes/lattice/cms/associator.php
@@ -0,0 +1,285 @@
+<?php
+/* @package Lattice */
+
+Class Lattice_Cms_Associator {
+ public $parent_id = NULL;
+ public $parent = NULL;
+ public $lattice = NULL;
+ public $filters = NULL;
+ public $pool = array();
+ public $associated = array();
+ // set this as needed when calling paged results
+ // right now this is set on an instance, by actions that pre load $this->pool
+ public $num_pages = 2;
+
+ protected $label;
+ protected $pool_label;
+ protected $page_length;
+ // this is page size for paginator
+ // this doesn't matter anymore because we're paginating
+ private $max_pool_size = 80;
+ private $page_num = 1;
+ public static function get_filters_from_dom_node($node)
+ {
+ $filters_node_list = core_lattice::config('objects', 'filter', $node);
+ $filters = array();
+ foreach ($filters_node_list as $filter)
+ {
+ $setting = array();
+ $setting['from'] = $filter->getAttribute('from');
+ $setting['objectTypeName'] = $filter->getAttribute('objectTypeName');
+ $setting['tagged'] = $filter->getAttribute('tagged');
+ $setting['function'] = $filter->getAttribute('function');
+ $filters[] = $setting;
+ }
+ return $filters;
+
+ }
+
+ // TODO
+ // to support multi-lattice single custom view
+ public function set_view_name($view_name)
+ {
+ throw new Kohana_Exception('Not Implemented');
+ }
+
+ // to support mutli-instance single lattice
+ public function set_associator_name($associator_name)
+ {
+ throw new Kohana_Exception('Not Implemented');
+ }
+
+ public function __construct($parent_id, $lattice, $filters=NULL, $load_pool=NULL)
+ {
+ $this->parent_id = $parent_id;
+ $this->parent = Graph::object($this->parent_id);
+ $this->lattice = $lattice;
+ $this->filters = $filters;
+ $this->page_length = Kohana::config('cms.associator_page_length');
+
+ foreach ($this->parent->get_lattice_children_paged($this->lattice) as $child)
+ {
+ $this->associated[] = $child;
+ }
+
+ if (is_array($load_pool))
+ {
+ $this->pool = $load_pool;
+ }
+ $load_pool = array();
+
+ if (is_array($load_pool))
+ {
+ foreach ($load_pool as $l)
+ {
+ $load_pool[] = $l->id;
+ }
+
+ }
+ // load pool
+ if ($filters)
+ {
+
+ $objects = Graph::object();
+
+ foreach ($filters as $filter)
+ {
+
+ if (isset($filter['from']) AND $filter['from'])
+ {
+ $from = Graph::object($filter['from']);
+ ($filter['lattice']) ? $lattice = $filter['lattice'] : ( $lattice = 'lattice' );
+ $objects = $from->lattice_children_query($lattice);
+ }
+
+ if (isset($filter['tagged']) AND $filter['tagged'])
+ {
+ $objects->tagged_filter($filter['tagged']);
+ }
+
+ if (isset($filter['objectTypeName']) AND $filter['objectTypeName'])
+ {
+ $t = ORM::Factory('objecttype', $filter['objectTypeName']);
+ if ( ! $t->loaded())
+ {
+ Graph::configure_object_type($filter['objectTypeName']);
+ $t = ORM::Factory('objecttype', $filter['objectTypeName']);
+ if ( ! $t->loaded())
+ {
+ throw new Kohana_Exception($filter['objectTypeName'] .' Not Found');
+ }
+ }
+ $objects->where('objecttype_id', '=', $t->id);
+ }
+
+ if (isset($filter['match']) AND $filter['match'])
+ {
+ $match_fields = explode(',',$filter['match_fields']);
+ $wheres = array();
+ foreach ($match_fields as $match_field)
+ {
+ $wheres[] = array($match_field, 'LIKE', '%'.$filter['match'].'%');
+ }
+ $objects->content_filter($wheres);
+
+ }
+
+ if (isset($filter['function']) AND $filter['function'])
+ {
+ $callback = explode('::', $filter['function']);
+
+ $options = NULL;
+ $objects = call_user_func($callback, $objects, $parent_id, $options);
+ }
+
+
+ $objects->where('objects.language_id', '=', Graph::default_language());
+ $objects->published_filter();
+ // just return an array of id's then load the pool object
+ $results = $objects->find_all()->as_array(NULL, 'id');
+ // check our filtered objects are correct
+ // compact the array to remove redundant keys
+ $res = array();
+ foreach ($results as $id)
+ {
+ $object = Graph::object($id);
+ if ( ! $this->parent->check_lattice_relationship($lattice, $object))
+ {
+ $res[$id] = $id;
+ }
+ }
+ $results = $res;
+ $this->num_pages = ceil(count($results)/$this->page_length);
+ // get slice the first page, then load the objects from their id's
+ $params = explode("/",$_SERVER["REQUEST_URI"]);
+ // print_r($params);
+ // @TODO this is a kludge. Oh well.
+ if (isset($params[7]) AND $params[6]=="posting_videos_associator")
+ {
+ // we're passing a page number - so slice the object ids
+ $results = array_slice($results,($params[7]-1)*16,16);
+ } else {
+ $results = array_slice($results,0,$this->page_length);
+ }
+
+ foreach ($results as $id)
+ {
+ $object = Graph::object($id);
+ $this->pool[$id] =$object;
+ }
+ }
+
+ } elseif ( ! is_array($load_pool))
+ {
+
+ $objects = Graph::object()
+ ->where( 'id', '!=', $parent_id )
+ ->where( 'objects.language_id', '=', Graph::default_language() )
+ ->published_filter()
+ ->limit( $this->max_pool_size )
+ ->find_all();
+ $this->pool = $objects;
+
+ }
+
+ }
+
+ public function set_label($label)
+ {
+ $this->label = $label;
+ }
+ public function set_page_length($page_length)
+ {
+ $this->page_length = $page_length;
+ }
+
+ public function set_pool_label($pool_label)
+ {
+ $this->pool_label = $pool_label;
+ }
+
+ public function render($view_name = NULL)
+ {
+ if ($view_name AND ($view = Kohana::find_file('views', 'lattice/associator/'.$view_name) ))
+ {
+ $view = new View('lattice/associator/'.$view_name);
+ } else {
+ $view = new View('lattice/associator');
+ }
+
+
+ $view->pool = $this->pool_item_views($view_name);
+
+ $view->associated = array();
+ foreach ($this->associated as $associated_item)
+ {
+ $view->associated[] = $this->get_item_view($associated_item, $view_name, TRUE );
+ }
+
+ $view->parent_id = $this->parent_id;
+ $view->lattice = $this->lattice;
+ $view->label = $this->label;
+ $view->pool_label = $this->pool_label;
+ $view->page_length = $this->page_length;
+ $view->num_pages = $this->num_pages;
+
+
+ /*
+ paginator vars- probably should be its own func
+ these are messy too
+
+ */
+
+ $view->url_prepend = "ajax/html";
+ // echo strpos($original_uri,$action);
+ // pass our paginator params to the view
+ // $view->controller_name = $this->request->controller();
+ // $view->action = $action;
+ // $view->params = $this->request->param();
+ // $view->current_page = $view->params["param4"];
+
+ /* end paginator vars*/
+ return $view->render();
+ }
+
+ public function render_pool_items()
+ {
+ return( implode("\n",$this->pool_item_views($this->lattice) ) );
+ }
+
+ private function pool_item_views($view_name = NULL)
+ {
+ $pool_item_views = array();
+ foreach ($this->pool as $pool_item)
+ {
+ $pool_item_views[] = $this->get_item_view($pool_item, $view_name, FALSE );
+ }
+ return $pool_item_views;
+ }
+
+ private function get_item_view($item, $view_name, $associated )
+ {
+
+ if ($view_name AND $view = Kohana::find_file('views/lattice/associator/'.$view_name, $item->objecttype->objecttypename))
+ {
+ $view = new View('lattice/associator/'.$view_name.'/'.$item->objecttype->objecttypename);
+ } elseif ($view_name AND $view = Kohana::find_file('views/lattice/associator/'.$view_name, 'item'))
+ {
+ $view = new View('lattice/associator/'.$view_name.'/'.'item');
+ } elseif ($view = Kohana::find_file('views/lattice/associator/', $item->objecttype->objecttypename))
+ {
+ $view = new View('lattice/associator/'.$item->objecttype->objecttypename);
+ } else {
+ $view = new View('lattice/associator/item');
+ }
+ $view->object = $item;
+
+ $view->associated = $associated;
+
+ return $view;
+
+ }
+
+
+
+}
View
259 classes/lattice/cms/associator/checkboxes.php
@@ -0,0 +1,259 @@
+<?php
+/* @package Lattice */
+
+Class Lattice_Cms_Associator_Checkboxes {
+
+ public $parent_id = NULL;
+ public $parent = NULL;
+ public $lattice = NULL;
+ public $filters = NULL;
+ public $pool = array();
+ public $associated = array();
+
+ protected $label;
+ protected $pool_label;
+
+ private $max_pool_size = 350;
+
+ public static function get_filters_from_dom_node($node)
+ {
+ $filters_node_list = core_lattice::config('objects', 'filter', $node);
+ $filters = array();
+ foreach ($filters_node_list as $filter)
+ {
+ $setting = array();
+ $setting['from'] = $filter->getAttribute('from');
+ $setting['objectTypeName'] = $filter->getAttribute('objectTypeName');
+ $setting['tagged'] = $filter->getAttribute('tagged');
+ $setting['function'] = $filter->getAttribute('function');
+ $filters[] = $setting;
+ }
+ return $filters;
+
+ }
+
+
+ // TODO
+ public function set_view_name($view_name)
+ {
+ throw new Kohana_Exception('Not Implemented');
+ } // to support multi-lattice single custom view
+
+ public function set_associator_name($associator_name)
+ {
+ throw new Kohana_Exception('Not Implemented');
+ } // to support mutli-instance single lattice
+
+
+
+ public function __construct($parent_id, $lattice, $filters=NULL, $load_pool=NULL)
+ {
+ $this->parent_id = $parent_id;
+ $this->parent = Graph::object($this->parent_id);
+ $this->lattice = $lattice;
+ $this->filters = $filters;
+
+ foreach ($this->parent->get_lattice_children($this->lattice) as $child)
+ {
+ $this->associated[] = $child;
+ }
+
+ if (is_array($load_pool))
+ {
+ $this->pool = $load_pool;
+ }
+
+ // load pool
+ if ($filters)
+ {
+ foreach ($filters as $filter)
+ {
+ $objects = Graph::object();
+
+ if (isset($filter['from']) AND $filter['from'])
+ {
+ $from = Graph::object($filter['from']);
+ ($filter['lattice']) ? $lattice = $filter['lattice'] : $lattice = 'lattice';
+ $objects = $from->lattice_children_query($lattice);
+ }
+
+ if (isset($filter['tagged']) AND $filter['tagged'])
+ {
+ $objects->tagged_filter($filter['tagged']);
+ }
+
+
+
+ if (isset($filter['objectTypeName']) AND $filter['objectTypeName'])
+ {
+ $t = ORM::Factory('objecttype', $filter['objectTypeName']);
+ if ( ! $t->loaded())
+ {
+ Graph::configure_object_type($filter['objectTypeName']);
+ $t = ORM::Factory('objecttype', $filter['objectTypeName']);
+ if ( ! $t->loaded())
+ {
+ throw new Kohana_Exception($filter['objectTypeName'] .' Not Found');
+ }
+ }
+ $objects->where('objecttype_id', '=', $t->id);
+ }
+ if (isset($filter['match']) AND $filter['match'])
+ {
+ $match_fields = explode(',',$filter['match_fields']);
+ $wheres = array();
+ foreach ($match_fields as $match_field)
+ {
+ $wheres[] = array($match_field, 'LIKE', '%'.$filter['match'].'%');
+ }
+ $objects->content_filter($wheres);
+
+ }
+
+ if (isset($filter['function']) AND $filter['function'])
+ {
+ $callback = explode('::', $filter['function']);
+ $objects = call_user_func($callback, $objects, $parent_id);
+ }
+
+ $objects->where('objects.language_id', '=', Graph::default_language());
+ $objects->published_filter();
+ $objects->limit($this->max_pool_size);
+
+ $results = $objects->find_all();
+ foreach ($results as $object)
+ {
+ if ( ! $this->parent->check_lattice_relationship($lattice, $object))
+ {
+ $this->pool[$object->id] = $object; // scalability problem
+ }
+ }
+ }
+ } elseif ( ! is_array($load_pool))
+ {
+
+ $objects = Graph::object()
+ ->where('id', '!=', $parent_id)
+ ->where('objects.language_id', '=', Graph::default_language())
+ ->published_filter()
+ ->limit($this->max_pool_size)
+ ->find_all();
+ $this->pool = $objects;
+ }
+
+ }
+
+ public function set_label($label)
+ {
+ $this->label = $label;
+ }
+
+ public function set_pool_label($pool_label)
+ {
+ $this->pool_label = $pool_label;
+ }
+
+ public function render($view_name = NULL)
+ {
+ if ($view_name AND ($view = Kohana::find_file('views', 'lattice/associator/'.$view_name) ))
+ {
+ $view = new View('lattice/associator/'.$view_name);
+ } else {
+ $view = new View('lattice/associator');
+ }
+
+ $view->pool = $this->pool_item_views($view_name);
+
+ $view->associated = array();
+ foreach ($this->associated as $associated_item)
+ {
+ $view->associated[] = $this->get_item_view($associated_item, $view_name);
+ }
+
+ $view->parent_id = $this->parent_id;
+ $view->lattice = $this->lattice;
+
+ $view->label = $this->label;
+ $view->pool_label = $this->pool_label;
+ return $view->render();
+ }
+
+ public function render_pool_items()
+ {
+ return(implode("\n",$this->pool_item_views($this->lattice)));
+ }
+
+ private function pool_item_views($view_name = NULL)
+ {
+ $pool_item_views = array();
+ foreach ($this->pool as $pool_item)
+ {
+ $pool_item_views[] = $this->get_item_view($pool_item, $view_name);
+ }
+ return $pool_item_views;
+ }
+
+ private function get_item_view($item, $view_name)
+ {
+
+ if ($view_name AND $view = Kohana::find_file('views/lattice/associator/'.$view_name, $item->objecttype->objecttypename))
+ {
+ $view = new View('lattice/associator/'.$view_name.'/'.$item->objecttype->objecttypename);
+ // Kohana::$log->add(Log::ERROR, "A")->write();
+ } elseif ($view_name AND $view = Kohana::find_file('views/lattice/associator/'.$view_name, 'item'))
+ {
+ $view = new View('lattice/associator/'.$view_name.'/'.'item');
+ // Kohana::$log->add(Log::ERROR, "B")->write();
+ } elseif ($view = Kohana::find_file('views/lattice/associator/', $item->objecttype->objecttypename))
+ {
+ $view = new View('lattice/associator/'.$item->objecttype->objecttypename);
+ // Kohana::$log->add(Log::ERROR, "C " . $item . ", " . $view_name )->write();
+ } else {
+ // Kohana::$log->add(Log::ERROR, "D " . $item . ", " . $view_name )->write();
+ $view = new View('lattice/associator/item');
+ }
+ $view->object = $item;
+
+ $view->selected = FALSE;
+
+ return $view;
+
+ }
+
+}
+
+/*
+Class Cms_Associator_Checkboxes {
+
+ public static function make_pool($associated_views, $pool_views)
+{
+ if (count($associated_views))
+{
+ $keys = array_map(array('Cms_Associator_Checkboxes','title_index'), $associated_views);
+ $associated_views = array_combine($keys, $associated_views);
+ }
+ $pool_views = array_combine( array_map(array('Cms_Associator_Checkboxes','title_index'), $pool_views), $pool_views);
+ foreach ($associated_views as $key => $view)
+{
+ $view->selected = TRUE;
+ $pool_views[$key] = $view;
+ }
+
+ array_walk($pool_views, array('Cms_Associator_Checkboxes', 'set_unique_element_id'));
+
+ ksort($pool_views);
+
+ return $pool_views;
+ }
+
+ private static function title_index($view)
+{
+ return $view->object->title;
+ }
+
+ private static function set_unique_element_id($view)
+{
+ $view->unique_element_id = Lattice_cms::unique_element_id();
+ }
+
+}*/
View
36 classes/lattice/cms/associator/radios.php
@@ -0,0 +1,36 @@
+<?php
+
+Class Lattice_Cms_Associator_Radios {
+
+ public static function make_pool($associated_views, $pool_views)
+ {
+ if (count($associated_views))
+ {
+ $keys = array_map(array('Cms_Associator_Radios','title_index'), $associated_views);
+ $associated_views = array_combine($keys, $associated_views);
+ }
+ $pool_views = array_combine( array_map(array('Cms_Associator_Radios','title_index'), $pool_views), $pool_views);
+ foreach ($associated_views as $key => $view)
+ {
+ $view->selected = TRUE;
+ $pool_views[$key] = $view;
+ }
+
+ array_walk($pool_views, array('Cms_Associator_Radios', 'set_unique_element_id'));
+
+ ksort($pool_views);
+
+ return $pool_views;
+ }
+
+ private static function title_index($view)
+ {
+ return $view->object->title;
+ }
+
+ private static function set_unique_element_id($view)
+ {
+ $view->unique_element_id = Lattice_cms::unique_element_id();
+ }
+
+}
View
134 classes/lattice/cms/controller/registration.php
@@ -0,0 +1,134 @@
+<?php
+
+Class Lattice_Cms_Controller_Registration extends Core_Controller_Layout {
+
+ protected $_actions_that_get_layout = array(
+ 'index',
+ 'create',
+ 'confirmed',
+ );
+
+ protected $errors = array();
+ protected $user_id = NULL;
+
+ public function action_index()
+ {
+ $this->registration_view();
+ }
+
+ public function action_create()
+ {
+ // run form validation
+
+ $validation = Validation::factory($_POST)
+ ->rule('password', 'not_empty')
+ ->rule('password', 'min_length', array(':value', 8))
+ ->rule('password', 'matches', array($_POST, 'password', 'passwordconfirm'))
+ ->rule('username', 'not_empty')
+ ->rule('username', 'min_length', array(':value', 4))
+ ->rule('email', 'not_empty')
+ ->rule('email', 'min_length', array(':value', 4))
+ ->rule('email', 'email')
+ ->rule('firstname', 'not_empty')
+ ->rule('firstname', 'min_length', array(':value', 3))
+ ->rule('lastname', 'not_empty')
+ ->rule('lastname', 'min_length', array(':value', 3));
+
+
+ if ($validation->check() AND ! count($this->errors))
+ {
+ $user = $this->create_user($_POST['username'], $_POST['password'], $_POST['firstname'], $_POST['lastname'], $_POST['email']);
+ } else {
+ $this->errors = array_merge($this->errors, $validation->errors('validation/registration'));
+ }
+
+
+ if (count($this->errors))
+ {
+ $this->registration_view($this->errors);
+ } else {
+ $confirmation = new Confirmation('registration'
+ , $_POST['email'],
+ 'registration',
+ 'confirmed',
+ array($this->user_id)
+ );
+ $confirmation->send();
+
+ $view = new View('confirmation_required');
+ $this->response->body($view->render());
+ }
+ }
+
+ public function action_confirmed($user_id)
+ {
+ $user = ORM::Factory('user',$user_id);
+ if ( ! $user->loaded())
+ {
+ $this->response->body('Invalid Confirmation - User Does Not Exist');
+ return;
+ }
+ $user->status = 'ACTIVE';
+ $user->save();
+
+ $view = new View('registration_confirmed');
+ $this->response->body($view->render());
+ }
+
+ protected function registration_view($errors=NULL)
+ {
+ $view = new View('registration');
+ $view->errors = $this->errors;
+ isset( $_POST['username'] ) ? $view->username = $_POST['username'] : $view->username = '';
+ isset( $_POST['password'] ) ? $view->password = $_POST['password'] : $view->password = '';
+ isset( $_POST['passwordconfirm'] ) ? $view->passwordconfirm = $_POST['passwordconfirm'] : $view->passwordconfirm = '';
+ isset( $_POST['email'] ) ? $view->email = $_POST['email'] : $view->email = '';
+ isset( $_POST['firstname'] ) ? $view->firstname = $_POST['firstname'] : $view->firstname = '';
+ isset( $_POST['lastname'] ) ? $view->lastname = $_POST['lastname'] : $view->lastname = '';
+ $this->response->body($view->render());
+ }
+
+ protected function create_user($username, $password, $firstname, $lastname, $email)
+ {
+
+ try {
+ $user = ORM::factory('user');
+ $user->status = 'NEEDSCONFIRMATION'; // TODO: This is the problem..
+ $user->username = $username;
+ $user->password = $password;
+ $user->firstname = $firstname;
+ $user->lastname = $lastname;
+ $user->email = $email;
+ $user->save();
+ $this->user_id = $user->id;
+ }
+ /**/ catch (Exception $e)
+ {
+ $errors = array();
+ $model_errors = $e->errors('validation');
+ if (isset($model_errors['_external']))
+ {
+ $model_errors = array_values($model_errors['_external']);
+ }
+ $this->user_id = NULL;
+ $this->errors = array_merge($errors, $model_errors);
+ return FALSE;
+ }
+ /**/
+
+ // add the login role
+ $user->add('roles', ORM::Factory('role', array('name'=>'login')));
+ if (is_array(Kohana::config('registration.default.roles')))
+ {
+ foreach (Kohana::config('registration.default.roles') as $role)
+ {
+ $user->add('roles', ORM::Factory('role', array('name'=>$role)));
+ }
+ }
+ // //Other roles from config
+ $user->save();
+
+ return $user;
+
+ }
+}
View
424 classes/lattice/cms/core.php
@@ -0,0 +1,424 @@
+<?php
+
+/* Class: CMS helper
+ * Contains utility function for CMS
+ */
+/* @package Lattice */
+
+class Lattice_Cms_Core {
+
+ private static $unique = 0;
+
+ public static function unique_element_id()
+ {
+ return self::$unique++;
+ }
+
+ /*
+ * Function: buildUIHtml_chunks
+ * This function builds the html for the UI elements specified in an object type's paramters
+ * Parameters:
+ * $parameters - the parameters array from an object type configuration
+ * Returns: Associative array of html, one entry for each ui element
+ */
+
+ public static function buildUIHtml_chunks($elements, $object = NULL)
+ {
+ $view = new View();
+ $html_chunks = array();
+ if (is_array($elements))
+ {
+ foreach ($elements as $element)
+ {
+
+ // check if this element type is in fact a object_type
+ $x_path = sprintf('//objectType[@name="%s"]', $element['type']);
+ $t_config = core_lattice::config('objects', $x_path)->item(0);
+
+ if ($t_config)
+ {
+
+ $field = $element['name'];
+ $cluster_object = $object->$field;
+ if ( ! $cluster_object)
+ {
+ throw new Kohana_Exception('Cluster Object did not load for '.$object->id.': '.$field);
+ }
+
+ $cluster_html_chunks = cms_core::buildUIHtml_chunks_for_object($cluster_object);
+
+
+ $customview = 'lattice/object_types/' . $cluster_object->objecttype->objecttypename; // check for custom view for this object_type
+ $usecustomview = FALSE;
+ if (Kohana::find_file('views', $customview))
+ {
+ $usecustomview = TRUE;
+ }
+ if ( ! $usecustomview)
+ {
+ $html = implode($cluster_html_chunks);
+ $view = new View('ui/clusters_wrapper');
+ $view->label = $element['label'];
+ $view->html = $html;
+ $view->objectTypeName = $cluster_object->objecttype->objecttypename;
+ $view->object_id = $cluster_object->id;
+ $html = $view->render();
+ } else {
+ $view = new View($customview);
+ // $view->load_resources();
+ $view->label = $element['label'];
+ $view->objectTypeName = $cluster_object->objecttype->objecttypename;
+ $view->object_id = $cluster_object->id;
+ foreach ($cluster_html_chunks as $key => $value)
+ {
+ $view->$key = $value;
+ }
+ $html = $view->render();
+ }
+ $html_chunks[$element['type'] . '_' . $element['name']] = $html;
+ continue;
+ }
+
+ /*
+ * Set up UI arguments to support uniquely generated field names when
+ * multiple items being displayed have the same field names
+ */
+ $ui_arguments = $element;
+ if (isset($element['field_id']))
+ {
+ $ui_arguments['name'] = $element['field_id'];
+ }
+
+ switch ($element['type'])
+ {
+
+
+ case 'element': // this should not be called 'element' as element has a different meaning
+ if (isset($element['arguments']))
+ {
+ $html = core_lattice::build_module($element, $element['elementname'], $element['arguments']);
+ } else {
+ $html = core_lattice::build_module($element, $element['elementname']);
+ }
+ $html_chunks[$element['modulename']] = $html;
+ break;
+ case 'list':
+ if (isset($element['display']) AND $element['display'] != 'inline')
+ {
+ break; // element is being displayed via navi, skip
+ }
+ $element['elementname'] = $element['name'];
+ $element['controllertype'] = 'list';
+
+ /* HERE! */
+
+ $requestURI = 'list/get_list/' . $object->id . '/' . $element['name'];
+ $html_chunks[$element['name']] = Request::factory($requestURI)->execute()->body();
+ break;
+
+ case 'associator':
+ $associator = new Cms_Associator($object->id, $element['lattice'],$element['filters']);
+ $associator->set_label($element['label']);
+ $associator->set_pool_label($element['pool_label']);
+ $associator->set_page_length(Kohana::config('cms.associator_page_length'));
+ $key = $element['type'] . '_' . $ui_arguments['name'];
+ $html_chunks[$key] = $associator->render($element['associator_type']);
+ break;
+
+ case 'tags':
+ $tags = $object->get_tag_strings();
+ $element_html = cms_ui::tags($tags);
+ $key = $element['type'] . '_tags';
+ $html_chunks[$key] = $element_html;
+
+ break;
+
+ case 'password':
+ $key = $element['type'] . '_' . $ui_arguments['name'];
+ $html = self::build_ui_element($element, $ui_arguments, NULL);
+ $html_chunks[$key] = $html;
+ break;
+
+ default:
+ // deal with html object_type elements
+ $key = $element['type'] . '_' . $ui_arguments['name'];
+ $html = self::build_ui_element($element, $ui_arguments, $object->{$element['name']});
+ $html_chunks[$key] = $html;
+ break;
+ }
+ }
+ }
+
+
+ // print_r($html_chunks);
+ return $html_chunks;
+ }
+
+ private static function build_ui_element($element, $ui_arguments, $value)
+ {
+
+ $html = NULL;
+ if ( ! isset($element['name']))
+ {
+ $element['name'] = LatticeCMS::unique_element_id();
+ $html = cms_ui::build_ui_element($element, NULL);
+ } elseif ( ! $html = cms_ui::build_ui_element($ui_arguments, $value))
+ {
+ throw new Kohana_Exception('bad config in cms: bad ui element');
+ }
+ return $html;
+ }
+
+ public static function get_element_config($object, $element_name)
+ {
+ latticecms::get_element_dom_node($object, $element_name);
+