Skip to content

Commit 546a041

Browse files
author
Ted Kulp
committed
Merge branch 'gregfroese/master'
Conflicts: classes/class.silk_request.php classes/class.silk_route.php
2 parents becec96 + af8dc13 commit 546a041

6 files changed

+73
-95
lines changed

classes/class.silk_form.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ static public function create_end_tag($name)
750750
* a single object of the class being autoform'd
751751
* if an array of results is passed, the first record will be used to populate the form.
752752
*/
753-
public function auto_form($obj, $params, $extra_fields, $start_form = true, $submit = true, $end_form = true) {
753+
public function auto_form($obj, $params, $extra_fields = array(), $start_form = true, $submit = true, $end_form = true) {
754754

755755
$default_params = array("div" => get_class($this), "submitValue" => "Submit");
756756

@@ -774,6 +774,11 @@ public function auto_form($obj, $params, $extra_fields, $start_form = true, $sub
774774
"label" => humanize($field->name),
775775
"label_extra" => "class='block'"
776776
);
777+
if( strtolower($field->name) == "password" ) {
778+
$input_params["password"] = true;
779+
} else {
780+
$input_params["password"] = false;
781+
}
777782

778783
if( isset($params["fields"]["$field->name"]["label"]) ) $input_params["label"] = $params["fields"][$field->name]["label"];
779784

classes/class.silk_object.php

-42
Original file line numberDiff line numberDiff line change
@@ -50,47 +50,5 @@ public function __toString()
5050
{
5151
return "Object(".get_class($this).")";
5252
}
53-
54-
function autoform( $override_fieldtypes=null ){
55-
56-
return;
57-
global $cfg;
58-
if( isset( $this->_fieldtypes ) ){
59-
//allow ability to override the field types to be used.
60-
$fieldtypes = &$this->_fieldtypes;
61-
if( !is_null( $override_fieldtypes ) )
62-
$fieldtypes = $override_fieldtypes;
63-
64-
$fieldnames = get_object_vars( $this );
65-
$classname = get_class( $this );
66-
require_once( "$cfg->abspath/includes/common.html.php" );
67-
echo "<div class='autoform autoform_$classname'>";
68-
$i=0;
69-
$commonHTML = new commonHTML(); //needed because method_exists dosn't seem to be able to handle a static method.
70-
foreach( $fieldnames as $fieldname=>$fieldvalue ) {
71-
if( strpos( $fieldname, "_" ) !== 0 ) {
72-
if( key_exists( $fieldname, $fieldtypes ) ) //added May 19, 2008
73-
@list( $type, $class ) = split( "_", $fieldtypes[$fieldname] );
74-
else
75-
@list( $type, $class ) = split( "_", $fieldtypes[$i] );
76-
if( $type == 'method' ) {
77-
$this->$class();
78-
}else{
79-
if( $type == 'review' )
80-
$method = $type;
81-
else
82-
$method = "input_".$type;
83-
84-
if( method_exists( $commonHTML, $method ) )
85-
commonHTML::$method( $fieldname, $fieldvalue, $class );
86-
else
87-
commonHTML::input_hidden( $fieldname, $fieldvalue, $class );
88-
}
89-
}
90-
$i++;
91-
}
92-
echo '</div>';
93-
}
94-
}
9553
}
9654
?>

classes/class.silk_request.php

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public static function handle_request()
8888
}
8989
echo $controller->run_action($params['action'], $params);
9090
}
91-
}
9291
catch (SilkAccessException $ex)
9392
{
9493
die('access problem: ' . $ex);

classes/class.silk_route.php

+59-45
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,52 @@ public function register_route_callback($route_string, $method, $defaults = arra
6868
$route->callback = $method;
6969
self::$routes[] = $route;
7070
}
71+
72+
public function register_split_route($params) {
73+
74+
$component = isset($params["component"]) ? $params["component"] : "";
75+
$controllers = isset($params["controllers"]) ? $params["controllers"] : array($component);
76+
$action = isset($params["action"]) ? $params["action"] : "index";
77+
$extra = isset($params["extra"]) ? $params["extra"] : array();
78+
79+
if(!$component || count($controllers) == 0) { return; }
80+
// untested
81+
// foreach($extra as $key => $value) {
82+
// $route = "/$component/:controller/:action";
83+
// SilkRoute::register_route($route, $defaults);
84+
// }
85+
86+
if( count($controllers) > 1) {
87+
88+
$defaults = array( "component" => $component, "action" => $action );
89+
90+
foreach($controllers as $one_controller) {
91+
$defaults["controller"] = $one_controller;
92+
93+
$route = "/$component/$one_controller/:action";
94+
SilkRoute::register_route($route, $defaults);
95+
96+
$route = "/$component/$one_controller";
97+
SilkRoute::register_route($route, $defaults);
98+
99+
if( $component != $one_controller ) {
100+
$route = "/$one_controller/:action";
101+
SilkRoute::register_route($route, $defaults);
102+
103+
$route = "/$one_controller";
104+
SilkRoute::register_route($route, $defaults);
105+
}
106+
}
107+
} else {
108+
$defaults = array( "component" => $component, "controller" => $controllers[0], "action" => $action );
109+
110+
$route = "/$controllers[0]/:action";
111+
SilkRoute::register_route($route, $defaults);
112+
113+
$route = "/$controllers[0]";
114+
SilkRoute::register_route($route, $defaults);
115+
}
116+
}
71117

72118
public static function match_route($uri, $route_shortening = true)
73119
{
@@ -82,11 +128,7 @@ public static function match_route($uri, $route_shortening = true)
82128

83129
foreach(self::$routes as $one_route)
84130
{
85-
$route_string = $one_route->route_string;
86-
if ($route_shortening === true)
87-
$route_string = self::rebuild_route($route_string, $uri);
88-
89-
$regex = self::create_regex_from_route($route_string);
131+
$regex = self::create_regex_from_route($one_route->route_string);
90132
if (preg_match($regex, $uri, $matches))
91133
{
92134
$defaults = $one_route->defaults;
@@ -169,47 +211,19 @@ public static function build_default_component_routes()
169211

170212
foreach($components as $component=>$controllers)
171213
{
172-
$count = 0;
173-
foreach($controllers as $one_controller)
174-
{
175-
$count++;
176-
$class_name = str_replace("class.", "", str_replace(".php", "", str_replace("_controller", "", $one_controller)));
177-
178-
if( count( $controllers ) > 1 ) {
179-
//create component route first so /component matches properly
180-
$key = "/$component/$component/:action/:id";
181-
if( !array_key_exists($key, $route)) {
182-
$route[$key] = array(
183-
"component" => $component,
184-
"controller" => $component,
185-
"action" => "index",
186-
"id" => ""
187-
);
188-
}
189-
190-
$key = "/$component/$class_name/:action/:id";
191-
if( !array_key_exists($key, $route)) {
192-
$route[$key] = array(
193-
"component" => $component,
194-
"controller" => $class_name,
195-
"action" => "index",
196-
"id" => ""
197-
);
198-
}
199-
200-
$key = "/$class_name/:action/:id";
201-
if( !array_key_exists($key, $route)) {
202-
$route[$key] = array(
203-
"component" => $component,
204-
"controller" => $class_name,
205-
"action" => "index",
206-
"id" => ""
207-
);
208-
}
209-
}
214+
if( file_exists( join_path( ROOT_DIR, "components", $component , "routes.php" ) ) ) {
215+
include_once( join_path( ROOT_DIR, "components", $component , "routes.php" ) );
216+
}
217+
$class_names = array();
218+
foreach( $controllers as $one_controller ) {
219+
$class_names[] = str_replace("class.","", str_replace("_controller.php", "", $one_controller));
210220
}
221+
self::register_split_route(array( "component" => $component, "controllers" => $class_names));
222+
211223
}
212-
$route["/:controller/:action/:id"] = array("component" => $component, "action" => "index");
224+
$route["/:controller/:action/:id"] = array("action" => "index");
225+
$route["/:controller/:action"] = array("action" => "index");
226+
$route["/:controller"] = array("action" => "index");
213227
foreach( $route as $route_string => $params ) {
214228
SilkRoute::register_route($route_string, $params);
215229
}
@@ -221,4 +235,4 @@ class SilkRouteNotMatchedException extends Exception
221235
}
222236

223237
# vim:ts=4 sw=4 noet
224-
?>
238+
?>

classes/class.silk_user.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ public function __construct()
4343

4444
public function validate()
4545
{
46-
$this->validate_not_blank('name', lang('nofieldgiven',array(lang('username'))));
4746

4847
// Username validation
49-
if ($this->name != '')
48+
if ($this->username != '')
5049
{
5150
// Make sure the name is unique
52-
$result = $this->find_by_name($this->name);
51+
$result = $this->find_by_username($this->username);
5352
if ($result)
5453
{
5554
if ($result->id != $this->id)
@@ -59,7 +58,7 @@ public function validate()
5958
}
6059

6160
// Make sure the name has no illegal characters
62-
if ( !preg_match("/^[a-zA-Z0-9\.]+$/", $this->name) )
61+
if ( !preg_match("/^[a-zA-Z0-9\.]+$/", $this->username) )
6362
{
6463
$this->add_validation_error(lang('illegalcharacters', array(lang('username'))));
6564
}
@@ -68,7 +67,7 @@ public function validate()
6867
// the min_username_length member may not exist
6968
if( $this->min_username_length != null)
7069
{
71-
if( strlen($this->name) < $this->min_username_length )
70+
if( strlen($this->username) < $this->min_username_length )
7271
{
7372
$this->add_validation_error(lang('The username is too short'));
7473
}

classes/class.silk_user_session.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function __construct($params = array())
4545

4646
function login()
4747
{
48+
if( !isset($_REQUSET['openid_mode'])) { $_REQUEST['openid_mode'] = false; }
4849
if ($_REQUEST['openid_mode']) //Coming back from an openid redirect -- just hit $_REQUEST directly
4950
{
5051
$consumer = $this->get_consumer();
@@ -130,7 +131,9 @@ static public function get_current_user()
130131

131132
static private function get_current_user_from_session()
132133
{
133-
self::$current_user = $_SESSION['silk_user'];
134+
if( isset($_SESSION['silk_user'])) {
135+
self::$current_user = $_SESSION['silk_user'];
136+
}
134137
}
135138

136139
static public function include_openid()

0 commit comments

Comments
 (0)