function myApp_welcome_response_content($params) { // Do controller stuff here. Prepare variables $tabs = array("foo" => "bar"); $description = "this is a description"; return Pie::view('myApp/content/welcome.php', compact('tabs', 'description')); }
/** * 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')); }
/** * Default pie/dir handler. * Just displays a simple directory listing, * and prevents further processing by returning true. */ function pie_dir() { $filename = Pie_Request::filename(); // TODO: show directory listing echo Pie::view('pie/dir.php', compact('filename')); return true; }
/** * @param string $subject * The subject. May contain variable references to memebrs * of the $fields array. * @param string $view * The name of a view * @param array $fields * The fields referenced in the subject and/or view * @param array $optoins * Array of options. Can include: * "html" => Defaults to false. Whether to send as HTML email. * "name" => A human-readable name in addition to the address. * "from" => An array of email_address => human_readable_name */ function sendMessage($subject, $view, $fields = array(), $options = array()) { if (!isset($options['from'])) { $url_parts = parse_url(Pie_Request::baseUrl()); $domain = $url_parts['host']; $options['from'] = array("email_bot@" . $domain => $domain); } else { if (!is_array($options['from'])) { throw new Pie_Exception_WrongType(array('field' => '$options["from"]', 'type' => 'array')); } } // Set up the default mail transport $tr = new Zend_Mail_Transport_Sendmail('-f' . $this->address); Zend_Mail::setDefaultTransport($tr); $mail = new Zend_Mail(); $from_name = reset($options['from']); $mail->setFrom(key($options['from']), $from_name); if (isset($options['name'])) { $mail->addTo($this->address, $options['name']); } else { $mail->addTo($this->address); } $subject = Pie::expandString($subject, $fields); $body = Pie::view($view, $fields); $mail->setSubject($subject); if (empty($options['html'])) { $mail->setBodyText($body); } else { $mail->setBodyHtml($body); } $mail->send(); return true; }
/** * 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')); }
/** * The default implementation. */ function pie_errors($params) { extract($params); /** * @var Exception $exception */ if (!empty($exception)) { Pie_Response::addError($exception); $errors = Pie_Response::getErrors(); } $errors_array = Pie_Exception::toArray($errors); $exception_array = Pie_Exception::toArray($exception); // Simply return the errors, if this was an AJAX request if ($is_ajax = Pie_Request::isAjax()) { switch (strtolower($is_ajax)) { case 'json': default: $json = json_encode(array('errors' => $errors_array, 'exception' => $exception_array)); $callback = Pie_Request::callback(); echo $callback ? "{$callback}({$json})" : $json; } return; } // Forward internally, if it was requested if (isset($_REQUEST['_pie']['onErrors'])) { $uri = Pie_Dispatcher::uri(); $uri2 = Pie_Uri::from($_REQUEST['_pie']['onErrors']); if ($uri !== $uri2) { Pie_Dispatcher::forward($uri2); return; // we don't really need this, but it's here anyway } } if (Pie::eventStack('pie/response')) { // Errors happened while rendering response. Just render errors view. return Pie::view('pie/errors.php', $params); } try { // Try rendering the response, expecting it to // display the errors along with the rest. $ob = new Pie_OutputBuffer(); Pie::event('pie/response', compact('errors', 'exception', 'errors_array', 'exception_array')); $ob->endFlush(); } catch (Exception $exception) { $output = $ob->getClean(); return Pie::event('pie/exception', compact('exception')); } }
function users_activate_response_content() { $uri = Pie_Dispatcher::uri(); $email_address = $uri->email_address; $mobile_number = $uri->mobile_number; if ($uri->email_address) { $type = 'email address'; } else { if ($uri->mobile_number) { $type = 'mobile_number'; } else { $type = ''; } } $user = Pie::ifset(Users::$cache['user'], false); return Pie::view('users/content/activate.php', compact('email_address', 'mobile_number', 'type', 'user')); }
function pie_response_dashboard() { return Pie::view('pie/dashboard.php'); }
function pie_response_content() { return Pie::view('pie/content.php'); }
/** * 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 pie_tool_zoomer($fields) { Pie_Response::addScript('plugins/pie/js/PieTools.js'); Pie_Response::addStylesheet('plugins/pie/css/Pie.css'); return Pie::view('pie/tool/zoomer.php'); }
function pie_response_dashboard() { $app = Pie_Config::expect('pie', 'app'); $slogan = "Powered by PHP ON PIE."; return Pie::view("{$app}/dashboard.php", compact('slogan')); }
/** * Default pie/response handler. * 1. Gets some slots, depending on what was requested. * 2. Renders them in a layout * The layout expects "title", "dashboard" and "contents" slots to be filled. */ function pie_response($params) { extract($params); /** * @var Exception $exception * @var array $errors */ // Redirect to success page, if requested. $is_ajax = Pie_Request::isAjax(); if (empty($errors) and empty($exception)) { if (!$is_ajax and isset($_REQUEST['_pie']['onSuccess'])) { $on_success = $_REQUEST['_pie']['onSuccess']; if (Pie_Config::get('pie', 'response', 'onSuccessShowFrom', true)) { $on_success = Pie_Uri::url($on_success . '?_pie[fromSuccess]=' . Pie_Dispatcher::uri()); } Pie_Response::redirect($on_success); return; } } // Get the requested module $uri = Pie_Dispatcher::uri(); if (!isset($module)) { $module = $uri->module; if (!isset($module)) { $module = 'pie'; Pie_Dispatcher::uri()->module = 'pie'; } } // Get the main module (the app) $app = Pie_Config::expect('pie', 'app'); // Add some javascript to inform the front end of important URLs Pie::event('pie/addScriptLines'); // What to do if this is an AJAX request if ($is_ajax) { $slot_names = Pie_Request::slotNames(); if (!isset($slot_names)) { $slot_names = Pie_Config::get($module, 'response', 'slotNames', array('content' => null, 'dashboard' => null, 'title' => null, 'notices' => null)); } $slots = array(); $stylesheets = array(); $stylesInline = array(); $scripts = array(); $scriptLines = array(); if (is_array($slot_names)) { foreach ($slot_names as $slot_name => $v) { $slots[$slot_name] = Pie_Response::fillSlot($slot_name, 'default'); $stylesheets[$slot_name] = Pie_Response::stylesheetsArray($slot_name); $stylesInline[$slot_name] = Pie_Response::stylesInline($slot_name); $scripts[$slot_name] = Pie_Response::scriptsArray($slot_name); $scriptLines[$slot_name] = Pie_Response::scriptLines($slot_name); } } $timestamp = microtime(true); $echo = Pie_Request::contentToEcho(); // Render a JSON layout for ajax $to_encode = compact('slots', 'stylesheets', 'stylesInline', 'scripts', 'scriptLines', 'timestamp', 'echo'); // Cut down on the response size foreach (array('slots', 'stylesheets', 'stylesInline', 'scripts', 'scriptLines') as $f) { $is_empty = true; if (is_array($to_encode[$f])) { foreach ($to_encode[$f] as $k => $v) { if (isset($v)) { $is_empty = false; } else { unset($to_encode[$f][$k]); } } } else { if (!empty($to_encode[$f])) { $is_empty = false; } } if ($is_empty) { unset($to_encode[$f]); } } switch (strtolower($is_ajax)) { case 'json': default: $json = json_encode($to_encode); $callback = Pie_Request::callback(); echo $callback ? "{$callback}({$json})" : $json; } return; } // If this is a request for a regular webpage, // fill the usual slots and render a layout. // Attach stylesheets and scripts if (Pie_Request::accepts('text/fbml')) { Pie_Response::addStylesheet("css/fbml.css"); Pie_Response::addScript('plugins/pie/fbjs/Pie.fb.js'); } else { Pie_Response::addStylesheet("css/html.css"); Pie_Response::addScript('plugins/pie/js/Pie.js'); } // Get all the usual slots for a webpage $slot_names = Pie_Config::get($module, 'response', 'slotNames', array('content' => null, 'dashboard' => null, 'title' => null, 'notices' => null)); $slots = array(); foreach ($slot_names as $sn => $v) { $slots[$sn] = Pie_Response::fillSlot($sn, 'default'); } $output = Pie_Response::output(); if (isset($output)) { if ($output === true) { return; } if (is_string($output)) { echo $output; } return; } if (Pie_Request::accepts('text/fbml')) { // Render a full FBML layout $layout_view = Pie_Config::get($app, 'response', 'layout_fbml', "{$app}/layout/fbml.php"); echo Pie::view($layout_view, $slots); } else { // Render a full HTML layout $layout_view = Pie_Config::get($app, 'response', 'layout_html', "{$app}/layout/html.php"); echo Pie::view($layout_view, $slots); } }
<?php echo Pie_Html::label('albums'); ?> Choose an album:</label> <?php echo Pie_Html::select('albums', array('id' => 'albums')); ?> <?php echo Pie_Html::options($albums); ?> </select> <?php echo Pie_Html::div('photos', 'items_addPhoto_tool_photos'); ?> <?php echo Pie::view('items/tool/addPhotoList.php', compact('photos')); ?> </div> <?php if (Pie_Request::accepts('text/fbml')) { ?> <fb:js-string var="fbml.<?php echo Pie_Html::getIdPrefix(); ?> throbber"> <div class="items_addPhoto_tool_throbber"> <img src="<?php echo $throbber_url; ?> " alt="loading..." /> </div>
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')); }
protected static function errors($exception, $module, $partial_response = null) { // In the handlers below, you can get errors with: // $errors = Pie_Response::getErrors(); try { if (self::$handling_errors) { // We need to handle errors, but we // have already tried to do it. // Just show the errors view. echo Pie::view('pie/errors.php', compact('errors')); return; } self::$handling_errors = true; if (Pie::canHandle("{$module}/errors")) { Pie::event("{$module}/errors", compact('errors', 'exception', 'partial_response')); } else { Pie::event("pie/errors", compact('errors', 'exception', 'partial_response')); } } catch (Exception $e) { Pie::event('pie/exception', array('exception' => $e)); } }