Changeset 20238 for events/phpframework/sabel
- Timestamp:
- 09/30/08 00:31:41 (5 years ago)
- Location:
- events/phpframework/sabel/trunk
- Files:
-
- 19 modified
-
Sabel/sabel/Functions.php (modified) (1 diff)
-
Sabel/sabel/Response.php (modified) (1 diff)
-
addon/acl/Processor.php (modified) (1 diff)
-
addon/acl/User.php (modified) (1 diff)
-
app/helpers/application.php (modified) (3 diffs)
-
app/helpers/paginator/Status.php (modified) (1 diff)
-
app/index/controllers/Index.php (modified) (3 diffs)
-
app/index/controllers/Users.php (modified) (1 diff)
-
app/models/Follower.php (modified) (2 diffs)
-
lib/Paginator.php (modified) (1 diff)
-
lib/processor/Action.php (modified) (2 diffs)
-
lib/processor/Request.php (modified) (2 diffs)
-
lib/processor/Response.php (modified) (1 diff)
-
lib/processor/View.php (modified) (5 diffs)
-
public/index.php (modified) (1 diff)
-
sabel.php (modified) (2 diffs)
-
tests/fixture/test/Status.php (modified) (1 diff)
-
tests/unit/models/Follower.php (modified) (1 diff)
-
tests/unit/paginators/Status.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
events/phpframework/sabel/trunk/Sabel/sabel/Functions.php
r20063 r20238 134 134 { 135 135 Sabel_Logger::create()->write($message, $level, $identifier); 136 }137 138 function uri($uriParameter, $secure = false, $absolute = false)139 {140 $context = Sabel_Context::getContext();141 $uriPrefix = get_uri_prefix($secure, $absolute);142 143 return $uriPrefix . "/" . $context->getCandidate()->uri($uriParameter);144 }145 146 function get_uri_prefix($secure = false, $absolute = false)147 {148 $uriPrefix = "";149 150 if ($secure || $absolute) {151 $uriPrefix = (($secure) ? "https" : "http") . "://" . $_SERVER["SERVER_NAME"];152 }153 154 if (defined("URI_IGNORE")) {155 $uriPrefix .= $_SERVER["SCRIPT_NAME"];156 } elseif (defined("NO_REWRITE")) {157 $uriPrefix .= "?" . NO_REWRITE_PREFIX . "=";158 }159 160 return $uriPrefix;161 136 } 162 137 -
events/phpframework/sabel/trunk/Sabel/sabel/Response.php
r20063 r20238 75 75 76 76 public function getLocation(); 77 public function setLocation($ to, $host = null);77 public function setLocation($location); 78 78 79 79 public function setResponse($name, $value); -
events/phpframework/sabel/trunk/addon/acl/Processor.php
r20065 r20238 68 68 $response->getStatus()->setCode(Sabel_Response::FORBIDDEN); 69 69 } else { 70 $user->login_uri = $response->getRedirector()->to($authUri);70 $user->login_uri = ltrim($response->getRedirector()->to($authUri), "/"); 71 71 } 72 72 } -
events/phpframework/sabel/trunk/addon/acl/User.php
r20065 r20238 73 73 } 74 74 75 $backUri = null; 76 $bus = Sabel_Context::getContext()->getBus(); 77 $request = $bus->get("request"); 78 $redirector = $bus->get("response")->getRedirector(); 79 80 if (is_object($request)) { 81 $backUri = $request->getValueWithMethod("back_uri"); 82 } 83 84 if ($backUri === null) { 85 $redirector->to($redirectTo); 86 } else { 87 l("ACL: back to the page before authentication.", SBL_LOG_DEBUG); 88 $redirector->uri($backUri); 75 if ($response = Sabel_Context::getResponse()) { 76 $backUri = null; 77 if ($request = Sabel_Context::getRequest()) { 78 $backUri = $request->getValueWithMethod("back_uri"); 79 } 80 81 if ($backUri === null) { 82 $response->getRedirector()->to($redirectTo); 83 } else { 84 l("ACL: back to the page before authentication.", SBL_LOG_DEBUG); 85 $response->getRedirector()->uri($backUri); 86 } 89 87 } 90 88 -
events/phpframework/sabel/trunk/app/helpers/application.php
r20065 r20238 1 1 <?php 2 3 function h($string, $charset = null) 4 { 5 return htmlescape($string, $charset); 6 } 2 7 3 8 function a($uri, $anchor, $uriQuery = "") … … 15 20 } 16 21 22 /** 23 * create uri for css, image, js, etc... 24 */ 17 25 function linkto($file) 18 26 { 19 if ( defined("URI_IGNORE")) {20 return dirname($_SERVER["SCRIPT_NAME"]) . "/" . $file;21 } else {22 return "/" . $file;27 if ($bus = Sabel_Context::getContext()->getBus()) { 28 if ($bus->get("NO_VIRTUAL_HOST")) { 29 return dirname($_SERVER["SCRIPT_NAME"]) . "/" . $file; 30 } 23 31 } 32 33 return "/" . $file; 24 34 } 25 35 26 function h($string, $charset = null)36 function get_uri_prefix($secure = false, $absolute = false) 27 37 { 28 return htmlescape($string, $charset); 38 $prefix = ""; 39 40 if ($secure || $absolute) { 41 $server = (isset($_SERVER["SERVER_NAME"])) ? $_SERVER["SERVER_NAME"] : "localhost"; 42 $prefix = (($secure) ? "https" : "http") . "://" . $server; 43 } 44 45 if ($bus = Sabel_Context::getContext()->getBus()) { 46 if ($bus->get("NO_VIRTUAL_HOST") && isset($_SERVER["SCRIPT_NAME"])) { 47 $prefix .= $_SERVER["SCRIPT_NAME"]; 48 } 49 50 if ($bus->get("NO_REWRITE_MODULE") && defined("NO_REWRITE_PREFIX")) { 51 $prefix .= "?" . NO_REWRITE_PREFIX . "="; 52 } 53 } 54 55 return $prefix; 29 56 } 30 57 31 function mb_trim($string) 58 /** 59 * create uri 60 */ 61 function uri($param, $secure = false, $absolute = false) 32 62 { 33 $string = new Sabel_Util_String($string); 34 return $string->trim()->toString(); 63 $context = Sabel_Context::getContext(); 64 $prefix = get_uri_prefix($secure, $absolute); 65 66 return $prefix . "/" . $context->getCandidate()->uri($param); 35 67 } 36 68 69 /* 37 70 function to_date($date, $format) 38 71 { 39 72 return Helpers_Date::format($date, constant("Helpers_Date::" . $format)); 40 }41 42 function datetime($date, $format = "m/d H:i")43 {44 return date($format, strtotime($date));45 73 } 46 74 … … 50 78 $requester->values($values)->withLayout($withLayout); 51 79 return $requester->request($uri)->getResult(); 80 } 81 */ 82 83 function datetime($date, $format = "m/d H:i") 84 { 85 return date($format, strtotime($date)); 86 } 87 88 function mb_trim($string) 89 { 90 $string = new Sabel_Util_String($string); 91 return $string->trim()->toString(); 52 92 } 53 93 -
events/phpframework/sabel/trunk/app/helpers/paginator/Status.php
r20153 r20238 49 49 return $paginator->build($limit, $params); 50 50 } 51 52 public function getPublicStatuses($params, $limit = null) 53 { 54 if ($limit === null) { 55 $limit = self::DEFAULT_ITEM_LIMIT; 56 } 57 58 $join = new Sabel_Db_Join("Status"); 59 $paginator = new Paginator($join->add("User")); 60 $paginator->setCondition("User.private_flag", false); 61 $paginator->setDefaultOrder("Status.created_at", "desc"); 62 63 return $paginator->build($limit, $params); 64 } 51 65 } -
events/phpframework/sabel/trunk/app/index/controllers/Index.php
r20153 r20238 16 16 . 'href="http://' . $_SERVER["SERVER_NAME"] . uri("a: rss") . '">'; 17 17 18 $this->paginator = $this->getPublicTimeline($this->GET_VARS); 18 $helper = new Helpers_Paginator_Status(); 19 $this->paginator = $helper->getPublicStatuses($this->GET_VARS); 19 20 20 21 if ($this->aclUser->isAuthenticated()) { … … 32 33 $rss = new Sabel_Rss_Writer(); 33 34 $rss->setInfo(array("title" => "Phwittr public timeline", "language" => "ja")); 34 $paginator = $this->getPublicTimeline(); 35 36 $helper = new Helpers_Paginator_Status(); 37 $paginator = $helper->getPublicStatuses(array()); 35 38 36 39 if ($paginator->results) { … … 70 73 71 74 if ($isSelf) { 72 $this->assignUserSubmenu( $aUser->id);75 $this->assignUserSubmenu(); 73 76 } else { 74 77 $this->assignOthersSubmenu($aUser->id, $aUser->name); 75 78 } 76 79 } 77 78 protected function getPublicTimeline($params = array())79 {80 $join = new Sabel_Db_Join("Status");81 $paginator = new Paginator($join->add("User"));82 $paginator->setCondition("User.private_flag", false);83 $paginator->setDefaultOrder("Status.created_at", "desc");84 85 return $paginator->build(20, $params);86 }87 80 } -
events/phpframework/sabel/trunk/app/index/controllers/Users.php
r20153 r20238 36 36 } 37 37 38 if ($protected && $authenticated) { 39 $this->isRequested = Request::isRequested($this->aclUser->id, $this->aUser->id); 38 if ($protected) { 39 if ($authenticated) { 40 $this->isRequested = Request::isRequested($this->aclUser->id, $this->aUser->id); 41 } 42 $this->view->setName("protected"); 40 43 } else { 41 44 $helper = new Helpers_Paginator_Status(); 42 45 $this->paginator = $helper->getStatuses($this->aUser->id, $this->GET_VARS, 50); 43 }44 45 if ($protected) {46 $this->view->setName("protected");47 } else {48 46 $this->view->setName("home"); 49 47 } -
events/phpframework/sabel/trunk/app/models/Follower.php
r20153 r20238 3 3 class Follower extends Sabel_Db_Model 4 4 { 5 public static function getFriends($userId, $limit = 100)5 public static function getFriends($userId, $limit) 6 6 { 7 7 $join = new Sabel_Db_Join(new self()); … … 20 20 $stmt->projection(array("follow_id")) 21 21 ->where("WHERE user_id = @user_id@") 22 ->constraints(array("order" => array("created_at" => " ASC")))22 ->constraints(array("order" => array("created_at" => "asc"))) 23 23 ->setBindValue("user_id", $userId); 24 24 -
events/phpframework/sabel/trunk/lib/Paginator.php
r20153 r20238 175 175 $attributes["results"] = $model->{$this->method}(); 176 176 177 if ($this->uri === null) { 178 if ($request = Sabel_Context::getContext()->getBus()->get("request")) { 179 $attributes["uri"] = get_uri_prefix() . "/" . $request->getUri(); 180 } 177 if ($this->uri === null && $request = Sabel_Context::getRequest()) { 178 $attributes["uri"] = get_uri_prefix() . "/" . $request->getUri(); 181 179 } 182 180 } -
events/phpframework/sabel/trunk/lib/processor/Action.php
r20073 r20238 24 24 $controller->setAction($action); 25 25 26 if ($isAjax = $bus->get(" isAjaxRequest")) {26 if ($isAjax = $bus->get("AJAX_REQUEST")) { 27 27 $controller->setAttribute("ajax", new AjaxResult()); 28 28 } … … 60 60 61 61 if ($controller->getAttribute("layout") === false) { 62 $bus->set(" noLayout", true);62 $bus->set("NO_LAYOUT", true); 63 63 } 64 64 } -
events/phpframework/sabel/trunk/lib/processor/Request.php
r20065 r20238 17 17 $request = $bus->get("request"); 18 18 } else { 19 $uri = ""; 20 if (isset($_SERVER["REQUEST_URI"])) { 21 l("REQUEST URI: " . $_SERVER["REQUEST_URI"]); 22 $uri = normalize_uri($_SERVER["REQUEST_URI"]); 23 } 24 19 $uri = $this->getRequestUri($bus); 25 20 $request = new Sabel_Request_Object($uri); 26 21 … … 48 43 } 49 44 45 l("REQUEST URI: /" . $request->getUri(true)); 46 47 // ajax request. 50 48 if ($request->getHttpHeader("X-Requested-With") === "XMLHttpRequest") { 51 $bus->set(" noLayout",true);52 $bus->set(" isAjaxRequest", true);49 $bus->set("NO_LAYOUT", true); 50 $bus->set("AJAX_REQUEST", true); 53 51 } 54 52 } 53 54 protected function getRequestUri($bus) 55 { 56 $uri = (isset($_SERVER["REQUEST_URI"])) ? $_SERVER["REQUEST_URI"] : "/"; 57 58 if (isset($_SERVER["SCRIPT_NAME"]) && strpos($_SERVER["SCRIPT_NAME"], "/index.php") >= 1) { 59 $uri = substr($uri, strlen($_SERVER["SCRIPT_NAME"])); 60 $bus->set("NO_VIRTUAL_HOST", true); 61 } 62 63 if (defined("NO_REWRITE_PREFIX") && isset($_GET[NO_REWRITE_PREFIX])) { 64 $uri = substr($uri, strlen(NO_REWRITE_PREFIX) + 2); 65 $parsed = parse_url($uri); 66 if (isset($parsed["query"])) { 67 parse_str($parsed["query"], $_GET); 68 } 69 70 unset($_GET[NO_REWRITE_PREFIX]); 71 $bus->set("NO_REWRITE_MODULE", true); 72 } 73 74 return normalize_uri($uri); 75 } 55 76 } -
events/phpframework/sabel/trunk/lib/processor/Response.php
r20067 r20238 56 56 $response->setLocation($url); 57 57 } else { 58 $session = $bus->get("session");59 58 $token = $bus->get("request")->getValueWithMethod("token"); 60 59 $hasToken = !empty($token); 61 60 $hasParams = $redirector->hasParameters(); 61 $location = $redirector->getUri(); 62 62 63 if (!$hasToken) { 64 $to = $redirector->getUri(); 65 } elseif ($hasParams) { 66 $to = $redirector->getUri() . "&token={$token}"; 67 } else { 68 $to = $redirector->getUri() . "?token={$token}"; 63 if ($hasToken) { 64 $glue = ($hasParams) ? "&" : "?"; 65 $location .= $glue . "token={$token}"; 69 66 } 70 67 68 $session = $bus->get("session"); 71 69 if ($session->isStarted() && !$session->isCookieEnabled()) { 72 70 $glue = ($hasToken || $hasParams) ? "&" : "?"; 73 $ to.= $glue . $session->getName() . "=" . $session->getId();71 $location .= $glue . $session->getName() . "=" . $session->getId(); 74 72 } 75 73 76 $response->setLocation($to, $_SERVER["SERVER_NAME"]); 74 if (function_exists("get_uri_prefix")) { 75 $location = get_uri_prefix() . "/" . ltrim($location, "/"); 76 } 77 78 $response->setLocation($location); 77 79 } 78 80 } -
events/phpframework/sabel/trunk/lib/processor/View.php
r20065 r20238 23 23 list ($m, $c, $a) = $bus->get("destination")->toArray(); 24 24 25 $controller = new Sabel_View_Location_File($m . DS . VIEW_DIR_NAME . DS . $c . DS); 26 $view = new Sabel_View_Object("controller", $controller); 25 $view = new Sabel_View_Object("controller", new Sabel_View_Location_File( 26 $m . DS . VIEW_DIR_NAME . DS . $c . DS 27 )); 27 28 28 $module = new Sabel_View_Location_File($m . DS . VIEW_DIR_NAME . DS); 29 $view->addLocation("module", $module); 30 31 $app = new Sabel_View_Location_File(VIEW_DIR_NAME . DS); 32 $view->addLocation("app", $app); 29 $view->addLocation("module", new Sabel_View_Location_File($m . DS . VIEW_DIR_NAME . DS)); 30 $view->addLocation("app", new Sabel_View_Location_File(VIEW_DIR_NAME . DS)); 33 31 34 32 if ($renderer = $bus->get("renderer")) { … … 39 37 40 38 $this->view = $view; 41 42 39 $bus->set("view", $view); 43 40 $bus->get("controller")->setAttribute("view", $view); … … 52 49 $responses = $response->getResponses(); 53 50 $contents = (isset($responses["contents"])) ? $responses["contents"] : ""; 54 $isAjax = $bus->get("isAjaxRequest");55 51 52 $isAjax = $bus->get("AJAX_REQUEST"); 53 54 // @todo... 56 55 if ($isAjax && isset($responses["ajax"])) { 57 56 return $bus->set("result", $responses["ajax"]->toString()); … … 59 58 60 59 $view = $this->getView($response->getStatus(), $bus->get("destination")->getAction(), $isAjax); 61 62 if (isset($responses["renderText"]) && $responses["renderText"]) {63 $renderer = $view->getRenderer();64 return $bus->set("result", $renderer->rendering($contents, $responses));65 }66 60 67 61 if ($contents === "") { … … 78 72 } 79 73 80 if ($bus->get(" noLayout")) {74 if ($bus->get("NO_LAYOUT")) { 81 75 $bus->set("result", $contents); 82 76 } else { -
events/phpframework/sabel/trunk/public/index.php
r20065 r20238 15 15 } 16 16 17 if (strpos($_SERVER["SCRIPT_NAME"], "/index.php") >= 1) {18 $ignore = str_replace($_SERVER["SCRIPT_NAME"], "", $_SERVER["REQUEST_URI"]);19 $_SERVER["REQUEST_URI"] = ltrim($ignore, "/");20 define("URI_IGNORE", $ignore);21 } elseif (isset($_GET[NO_REWRITE_PREFIX])) {22 $_uri = substr(ltrim($_SERVER["REQUEST_URI"], "/"), strlen(NO_REWRITE_PREFIX) + 2);23 $_SERVER["REQUEST_URI"] = $_uri;24 $parsed = parse_url($_SERVER["REQUEST_URI"]);25 if (isset($parsed["query"])) {26 parse_str($parsed["query"], $_GET);27 }28 29 unset($_GET[NO_REWRITE_PREFIX]);30 define("NO_REWRITE", true);31 }32 33 17 if ((ENVIRONMENT & PRODUCTION) > 0) { 34 18 Sabel::init(); -
events/phpframework/sabel/trunk/sabel.php
r20065 r20238 16 16 $_SERVER["HTTP_HOST"] = "localhost"; 17 17 $_SERVER["SERVER_NAME"] = "localhost"; 18 $_SERVER["REQUEST_URI"] = "/"; 18 19 19 20 if (isset($_SERVER["argv"][2])) { … … 34 35 } 35 36 } 36 } else {37 $_SERVER["REQUEST_URI"] = "/";38 37 } 39 38 -
events/phpframework/sabel/trunk/tests/fixture/test/Status.php
r20153 r20238 45 45 )); 46 46 } 47 48 for ($i = 1; $i < 10; $i++) { 49 $this->insert(array( 50 "user_id" => $user2->id, 51 "comment" => "comment{$i}", 52 "created_at" => "2008-01-0{$i} 23:59:59", 53 )); 54 } 47 55 } 48 56 -
events/phpframework/sabel/trunk/tests/unit/models/Follower.php
r20073 r20238 12 12 { 13 13 $user2 = $this->getUser("test2"); 14 $friends = Follower::getFriends($user2->id );14 $friends = Follower::getFriends($user2->id, 100); 15 15 16 16 $this->eq(2, count($friends)); -
events/phpframework/sabel/trunk/tests/unit/paginators/Status.php
r20153 r20238 130 130 $this->eq("2008-01-01 18:00:00", $items[3]->created_at); 131 131 } 132 133 /** 134 * @test 135 */ 136 public function getPublicStatuses() 137 { 138 $user1 = $this->getUser("test1"); 139 $user2 = $this->getUser("test2"); 140 $user3 = $this->getUser("test3"); 141 142 $helper = new Helpers_Paginator_Status(); 143 144 $paginator = $helper->getPublicStatuses(array(), 5); 145 $this->eq(36, $paginator->count); 146 147 $user2->private_flag = false; 148 $user2->save(); 149 150 $paginator = $helper->getPublicStatuses(array(), 5); 151 $this->eq(45, $paginator->count); 152 153 $user2->private_flag = true; 154 $user2->save(); 155 } 132 156 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)