function pie_response_content() { $serve_fbml = Pie_Request::accepts('text/fbml'); if ($serve_fbml) { // add more fbjs files here } else { // the js files for your app Pie_Response::addScript('plugins/pie/js/Pie.js'); Pie_Response::addScript("http://cdn.jquerytools.org/1.2.3/jquery.tools.min.js"); Pie_Response::addScript('plugins/users/js/Users.js'); // See views/layout/html.php for a facebook script at the top of the <body> } Pie_Response::addStylesheet('plugins/pie/css/Ui.css'); $app = Pie_Config::expect('pie', 'app'); $url = Pie_Request::url(); $module = Pie_Dispatcher::uri()->module; if (empty($module)) { return Pie::event("{$app}/notFound/response/content"); } $action = Pie_Dispatcher::uri()->action; $event = "{$module}/{$action}/response/content"; if (!Pie::canHandle($event)) { return Pie::event("{$app}/notFound/response/content"); } // Go ahead and fire the event, returning the result. return Pie::event($event); }
/** * Default pie/notFound handler. * Just displays pie/notFound.php view. */ function pie_notFound($params) { header("HTTP/1.0 404 Not Found"); Pie_Dispatcher::result("Nothing found"); $url = Pie_Request::url(); echo Pie::view('pie/notFound.php', compact('url')); }
static function execute() { // Fixes for different platforms: if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { // ISAPI 3.0 $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; } // Define a constant if (!defined('PIE_CONTROLLER')) { define('PIE_CONTROLLER', 'Pie_WebController'); } try { Pie::log("Request for " . Pie_Request::url(true)); Pie_Dispatcher::dispatch(); $dispatch_result = Pie_Dispatcher::result(); if (!isset($dispatch_result)) { $dispatch_result = 'Ran dispatcher'; } $uri = Pie_Dispatcher::uri(); $module = $uri->module; $action = $uri->action; if ($module and $action) { $slot_names = Pie_Request::slotNames(); $requested_slots = empty($slot_names) ? '' : implode(',', array_keys($slot_names)); Pie::log("~" . ceil(Pie::microtime()) . 'ms+' . ceil(memory_get_peak_usage() / 1000) . 'kb.' . " {$dispatch_result} for {$module}/{$action}" . " ({$requested_slots})"); } else { Pie::log("~" . ceil(Pie::microtime()) . 'ms+' . ceil(memory_get_peak_usage() / 1000) . 'kb.' . " No route for " . $_SERVER['REQUEST_URI']); } } catch (Exception $exception) { Pie::event('pie/exception', compact('exception')); } }
/** * This is a tool for selecting photos (to possibly add) * @param $facebook * Optional. You can provide instance of the Facebook class. * @param $upload * Defaults to false. If true, shows an option to upload, as well. * @param $action_uri * Defaults to 'items/addPhoto'. The URI to submit the form to. * @param $filter_visible * Optional string. Set to 'everyone' to only display albums visible to everyone. * @param $on_success * Optional string. The url to redirect to after a photo is added or uploaded. */ function items_addPhoto_tool($params) { if (isset(Users::$facebook)) { $facebook = Users::$facebook; } else { $app = Pie_Config::expect('pie', 'app'); if (!isset(Users::$facebooks[$app])) { throw new Pie_Exception_MissingObject(array('name' => 'Users::$facebooks[' . $app . ']')); } $facebook = Users::$facebooks[$app]; } $defaults = array('facebook' => $facebook, 'upload' => false, 'action_uri' => 'items/addPhoto', 'on_success' => Pie_Request::url()); extract(array_merge($defaults, $params)); if (!$facebook instanceof Facebook) { throw new Pie_Exception_WrongType(array('field' => '$facebook', 'type' => 'Facebook')); } if (isset($_REQUEST['_pie']['onSuccess'])) { $on_success = $_REQUEST['_pie']['onSuccess']; } $sn = Pie_Session::name(); $sid = Pie_Session::id(); $photos = array(); if (isset($aid)) { $photos = Items::facebookPhotos($facebook, $aid); return Pie::view('items/tool/addPhotoList.php', compact('photos')); } $facebook->require_login(); $album_rows = Items::facebookAlbums($facebook); $albums = array(); foreach ($album_rows as $ar) { if (isset($filter_visible) and $ar['visible'] != $filter_visible) { continue; } $albums[$ar['aid']] = $ar['name']; } $albums = $albums; if (count($album_rows)) { $row = reset($album_rows); $photos = Items::facebookPhotos($facebook, $row['aid']); } $throbber_url = Pie_Html::themedUrl('plugins/items/img/anim/throbber.gif'); $url_json = json_encode(Pie_Uri::url($action_uri)); Pie_Response::addStylesheet('plugins/items/css/Items.css'); if (Pie_Request::accepts('text/fbml')) { Pie_Response::addScript('plugins/items/fbjs/Items.fb.js'); } else { Pie_Response::addScript('plugins/items/js/Items.js'); } if (is_bool($upload)) { $upload = uniqid('up.', false); } $addPhoto_url_json = json_encode(Pie_Uri::url('items/addPhoto')); Pie_Response::addScriptLine("\tPie.Items.urls['items/addPhoto'] = {$addPhoto_url_json};"); return Pie::view('items/tool/addPhoto.php', compact('action_uri', 'on_success', 'on_added', 'albums', 'photos', 'throbber_url', 'upload')); }
function users_contact_tool($params) { $defaults = array('uri' => 'users/contact', 'omit' => array(), 'fields' => array(), 'title' => "Contact Info", 'collapsed' => false, 'toggle' => false, 'editing' => true, 'complete' => true, 'inProcess' => false, 'prompt' => "In order for things to work, we must be able to reach you.", 'button_content' => 'OK'); extract(array_merge($defaults, $params)); $default_fields = array('first_name' => array('type' => 'text', 'label' => 'First Name'), 'last_name' => array('type' => 'text', 'label' => 'Last Name'), 'email_address' => array('type' => 'text', 'label' => 'Email')); $fields = array_merge($default_fields, $fields); $user = Users::loggedInUser(); if (!$user) { throw new Users_Exception_NotLoggedIn(); } $email = null; $missing_fields = Users::accountStatus($email); if (isset($user->first_name)) { $fields['first_name']['value'] = $user->first_name; } if (isset($user->last_name)) { $fields['last_name']['value'] = $user->last_name; } if (isset($user->email_address)) { $fields['email_address']['value'] = $user->email_address; } else { if ($email) { $link = Pie_Html::a('#resend', array('class' => 'users_contact_tool_resend'), "You can re-send the activation email"); switch ($email->state) { case 'active': if ($email->user_id == $user->id) { $message = "Please confirm this email address.<br>{$link}"; } else { $message = "This email seems to belong to another user"; } break; case 'suspended': $message = "This address has been suspended."; break; case 'unsubscribed': $message = "The owner of this address has unsubscribed"; break; case 'unverified': default: $message = "Not verified yet.<br>{$link}"; break; } $fields['email_address']['value'] = $email->address; $fields['email_address']['message'] = $message; } } $on_success = isset($_REQUEST['_pie']['onSuccess']) ? $_REQUEST['_pie']['onSuccess'] : Pie_Request::url(); Pie_Response::addScript('plugins/users/js/Users.js'); $form = $static = compact('fields'); return Pie::tool('pie/panel', compact('uri', 'on_success', 'form', 'static', 'title', 'collapsed', 'toggle', 'complete', 'editing', 'inProcess', '_form_static')); }
function users_account_tool($params) { $defaults = array('uri' => 'users/account', 'omit' => array(), 'fields' => array(), 'title' => "Basic Info", 'editing' => true, 'complete' => true, 'inProcess' => false, 'collapsed' => false, 'toggle' => false); extract(array_merge($defaults, $params)); $default_fields = array('username' => array('type' => 'text', 'label' => 'Choose Username'), 'gender' => array('type' => 'select', 'label' => 'I am', 'options' => array('male' => 'a man', 'female' => 'a woman')), 'orientation' => array('type' => 'select', 'label' => 'Orientation', 'options' => array('straight' => 'straight', 'gay' => 'gay', 'bi' => 'bi')), 'relationship_status' => array('type' => 'select', 'label' => 'Status', 'options' => array('single' => "I'm single", 'open' => "I'm in an open relationship", 'relationship' => "I'm in a relationship", 'engaged' => "I'm engaged", 'married' => "I'm married", 'complicated' => "It's complicated", 'widowed' => "I'm widowed")), 'birthday' => array('type' => 'date', 'label' => 'My Birthday', 'options' => array('year_from' => '1920', 'year_to' => date('Y') - 16)), 'zipcode' => array('type' => 'text', 'label' => 'Zipcode', 'attributes' => array('maxlength' => 5))); $fields = array_merge($default_fields, $fields); $user = Users::loggedInUser(); if (!$user) { throw new Users_Exception_NotLoggedIn(); } if (isset($user->gender)) { $fields['gender']['value'] = $user->gender; } if (isset($user->desired_gender)) { if ($user->desired_gender == 'either') { $fields['orientation']['value'] = 'bi'; } else { if (isset($user->gender)) { $fields['orientation']['value'] = $user->gender != $user->desired_gender ? 'straight' : 'gay'; } } } if (isset($user->relationship_status)) { $fields['relationship_status']['value'] = $user->relationship_status; } if (isset($user->birthday)) { $fields['birthday']['value'] = date("Y-m-d", Users::db()->fromDate($user->birthday)); } if (isset($user->zipcode)) { $fields['zipcode']['value'] = $user->zipcode; } if (isset($user->username)) { $fields['username']['value'] = $user->username; } foreach ($omit as $v) { unset($fields[$v]); } $on_success = isset($_REQUEST['_pie']['onSuccess']) ? $_REQUEST['_pie']['onSuccess'] : Pie_Request::url(); Pie_Response::addScript('plugins/users/js/Users.js'); $form = $static = compact('fields'); return Pie::tool('pie/panel', compact('uri', 'title', 'form', 'static', 'on_success', 'complete', 'collapsed', 'toggle', 'editing', 'inProcess', '_form_static')); }
function pie_addScriptLines() { $app = Pie_Config::expect('pie', 'app'); $uri = Pie_Dispatcher::uri(); $proxies_json = json_encode(Pie_Config::get('pie', 'proxies', array())); $uri_json = json_encode($uri->toArray()); $url = Pie_Request::url(); $url_json = json_encode($url); $proxy_url_json = json_encode(Pie_Uri::url($url)); $base_url = json_encode(Pie_Request::baseUrl()); Pie_Response::addScriptLine(<<<EOT // pie {{ \t\tPie.info = { \t\t\t"proxies": {$proxies_json}, \t\t\t"uri": {$uri_json}, \t\t\t"url": {$url_json}, \t\t\t"proxyUrl": {$proxy_url_json}, \t\t\t"baseUrl": {$base_url} \t\t}; EOT ); $uris = Pie_Config::get('pie', 'javascript', 'uris', array()); $urls = array(); foreach ($uris as $u) { $urls["{$u}"] = Pie_Uri::url("{$u}"); } $urls_json = json_encode($urls); Pie_Response::addScriptLine("\t\tPie.urls = {$urls_json};"); // Export more variables to inline js $app = Pie_Config::expect('pie', 'app'); $app_json = json_encode($app); Pie_Response::addScriptLine("\t\tPie.app = {$app_json};\n" . "// }} pie"); $snf = Pie_Config::get('pie', 'session', 'nonceField', 'nonce'); $nonce = isset($_SESSION[$snf]) ? $_SESSION[$snf] : null; if ($nonce) { $nonce_json = json_encode($nonce); Pie_Response::addScriptLine("\t\tPie.nonce = {$nonce_json};"); } }
/** * Get the URL that was requested, possibly with a querystring * @param mixed $query_fields * If true, includes the entire querystring as requested. * If a string, appends the querystring correctly to the current URL. * If an associative array, adds these fields, with their values * to the existing querystring, while subtracting the fields corresponding * to null values in $query. Then generates a querystring and * includes it with the URL. * @return string * Returns the URL that was requested, possibly with a querystring. */ static function url($query_fields = array()) { if (!isset($_SERVER['REQUEST_URI'])) { // this was not requested from the web return null; } $request_uri = $_SERVER['REQUEST_URI']; // Deal with the querystring $r_parts = explode('?', $request_uri); $request_uri = $r_parts[0]; $request_querystring = isset($r_parts[1]) ? $r_parts[1] : ''; // Extract the URL if (!isset(self::$url)) { self::$url = sprintf('http%s://%s%s%s%s%s%s', isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == TRUE ? 's' : '', isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '', isset($_SERVER['PHP_AUTH_PW']) ? ':' . $_SERVER['PHP_AUTH_PW'] : '', isset($_SERVER['PHP_AUTH_USER']) ? '@' : '', $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'] != (isset($_SERVER['HTTPS']) ? 443 : 80) ? ':' . $_SERVER['SERVER_PORT'] : '', $request_uri); } if (!$query_fields) { return self::$url; } $query = array(); if ($request_querystring) { parse_str($request_querystring, $query); } if (is_string($query_fields)) { parse_str($query_fields, $qf_array); $query = array_merge($query, $qf_array); } else { if (is_array($query_fields)) { foreach ($query_fields as $key => $value) { if (isset($value)) { $query[$key] = $value; } else { unset($query[$key]); } } } } if (!empty($query)) { return self::$url . '?' . http_build_query($query); } return self::$url; }
/** * Default pie/noModule handler. * Just displays pie/notFound.php view. */ function pie_noModule($params) { header("HTTP/1.0 404 Not Found"); $url = Pie_Request::url(); echo Pie::view('pie/notFound.php', compact('url')); }
function myApp_notFound_response_content($params) { header("HTTP/1.0 404 Not Found"); $url = Pie_Request::url(); return Pie::view("myApp/content/notFound.php", compact('url')); }