/** * @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; }
/** * 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')); }
function pie_init() { //Db::connect('users')->generateModels(PIE_DIR.DS.'plugins'.DS.'users'.DS.'classes'); //Db::connect('games')->generateModels(PIE_DIR.DS.'plugins'.DS.'games'.DS.'classes'); Pie::log('To stop logging database queries, change pie/init.php'); Pie_Config::set('pie', 'handlersBeforeEvent', 'db/query/execute', 'temp_query'); }
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); }
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')); } }
function users_contact_post() { Pie_Session::start(); Pie_Valid::nonce(true); extract($_REQUEST); $user = Users::loggedInUser(); if (!$user) { throw new Users_Exception_NotLoggedIn(); } $app = Pie_Config::expect('pie', 'app'); $subject = "Welcome! Activate your email."; $view = "{$app}/email/setEmail.php"; $fields = array(); $p = array(); $p['subject'] =& $subject; $p['view'] =& $view; $p['fields'] =& $fields; Pie::event('users/setEmail', $p, 'before'); // may change the fields if (isset($first_name)) { $user->first_name = $first_name; } if (isset($last_name)) { $user->last_name = $last_name; } $user->addEmail($_REQUEST['email_address'], $subject, $view, true, $fields); // If no exceptions were throw, save this user row if (isset($first_name) or isset($last_name)) { $user->save(); } }
/** * 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; }
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')); }
/** * Override pie/noModule handler. * just goes on to render our app's response, * which will echo a 404 view. */ function pie_noModule($params) { if (!Pie_Request::accepts('text/fbml')) { header("HTTP/1.0 404 Not Found"); } Pie_Dispatcher::uri()->module = Pie_Config::expect('pie', 'app'); Pie_Dispatcher::uri()->action = ''; Pie::event('pie/response', $params); }
/** * Override pie/notFound handler. * just goes on to render our app's response, * which will echo a 404 view. */ function pie_notFound($params) { if (!Pie_Dispatcher::uri()->facebook) { header("HTTP/1.0 404 Not Found"); } Pie_Dispatcher::uri()->module = Pie_Config::expect('pie', 'app'); Pie_Dispatcher::uri()->action = 'notFound'; Pie::event('pie/response', $params); }
function users_after_pie_reroute($params, &$stop_dispatch) { $uri = Pie_Dispatcher::uri(); $app = Pie_Config::expect('pie', 'app'); $ma = $uri->module . '/' . $uri->action; $requireComplete = Pie_Config::get('users', 'requireComplete', array()); if (isset($requireComplete[$ma])) { $redirect_action = is_string($requireComplete[$ma]) ? $requireComplete[$ma] : "{$app}/login"; $test_complete = true; } else { $requireLogin = Pie_Config::get('users', 'requireLogin', array()); if (!isset($requireLogin[$ma])) { // We don't have to require complete or login here return; } $redirect_action = is_string($requireLogin[$ma]) ? $requireLogin[$ma] : "{$app}/login"; } // First, try to get the user $user = Users::loggedInUser(); if (!$user) { // Try authenticating with facebook $module = Pie_Dispatcher::uri()->module; $app_id = Pie_Config::expect('users', 'facebookApps', $module, 'appId'); $user = Users::authenticate('facebook', $app_id); } if (!$user) { $uri->onSuccess = $uri->module . '/' . $uri->action; $uri->onCancel = "{$app}/welcome"; if ($uri->onSuccess === $redirect_action) { // avoid a redirect loop $uri->onSuccess = "{$app}/home"; } $parts = explode('/', $redirect_action); $uri->action = $parts[0]; $uri->action = $parts[1]; } // If have requireLogin but not requireComplete, then // simply change the underlying URI without redirecting if (empty($test_complete)) { return; } // If we are here, we should check if the user account is complete $complete = Pie::event('users/account/complete'); if ($complete) { // good, nothing else to complete return; } // redirect to account page $account_action = Pie_Config::expect('users', 'accountAction', $uri->module); if ($ma != $account_action) { // Make the user launch into setting up their account. // If they want to return to this URL later, they can do it on their own. Pie_Response::redirect($account_action); $stop_dispatch = true; return; } }
function pie_post($params) { $uri = Pie_Dispatcher::uri(); $module = $uri->module; $action = $uri->action; if (!Pie::canHandle("{$module}/{$action}/post")) { return null; } return Pie::event("{$module}/{$action}/post", $params); }
/** * 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')); }
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_ActionController'); } try { $parts = explode('/', Pie_Request::tail()); $parts_len = count($parts); if ($parts_len >= 1) { $module = $parts[0]; } if ($parts_len >= 2) { $action = $parts[1]; } // Make sure the 'pie'/'web' config fields are set, // otherwise URLs will be formed pointing to the wrong // controller script. $ar = Pie_Config::get('pie', 'web', 'appRootUrl', null); if (!isset($ar)) { throw new Pie_Exception_MissingConfig(array('fieldpath' => 'pie/web/appRootUrl')); } $cs = Pie_Config::get('pie', 'web', 'controllerSuffix', null); if (!isset($cs)) { throw new Pie_Exception_MissingConfig(array('fieldpath' => 'pie/web/controllerSuffix')); } // Dispatch the request $uri = Pie_Uri::from(compact('module', 'action')); Pie_Dispatcher::dispatch($uri); $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')); } }
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 pie_error($params) { extract($params); while (ob_get_level() > 1) { ob_end_flush(); } if (ob_get_level() == 1) { $response = ob_get_clean(); } $errstr = preg_replace("/href='(.+)'/", "href='http://php.net/\$1'", $errstr); $fixTrace = true; $exception = new Pie_Exception_PhpError(compact('errstr', 'errfile', 'errline', 'fixTrace'), array()); Pie::event('pie/exception', compact('exception')); exit; }
/** * 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 createPie($values, $title, $x, $y) { $plot = new Pie($values, PIE_EARTH); $plot->title->set($title); $plot->title->setFont(new TuffyBold(8)); $plot->title->move(NULL, -12); $plot->label->setFont(new Tuffy(7)); $plot->legend->hide(TRUE); $plot->setLabelPosition(5); $plot->setSize(0.45, 0.45); $plot->setCenter($x, $y); $plot->set3D(10); $plot->setBorderColor(new Color(230, 230, 230)); return $plot; }
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_default($params) { if (!isset($params['slot_name'])) { throw new Pie_Exception_RequiredField(array('field' => '$slot_name')); } $slot_name = $params['slot_name']; $uri = Pie_Dispatcher::uri(); $module = $uri->module; $action = $uri->action; if (Pie::canHandle("{$module}/{$action}")) { Pie::event("{$module}/{$action}"); } $event = "{$module}/{$action}/response/{$slot_name}"; if (Pie::canHandle($event)) { return Pie::event($event); } return "Need to define {$event}"; }
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 users_register_post_download($url, $folder, $size = 80) { $url_parts = parse_url($url); if (substr($url_parts['host'], -12) != 'gravatar.com') { return false; } $dir = Pie_Config::get('users', 'paths', 'icons', 'files/users/icons'); $ch = curl_init(Pie_Uri::url($_REQUEST['icon'] . '?s=' . $size)); $dir2 = Pie::realPath($dir) . DS . $folder; if (!file_exists($dir2)) { mkdir($dir2, 0777); chmod($dir2, 0777); } $fp = fopen($dir2 . DS . "{$size}.png", 'wb'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); return true; }
function pie_exception($params) { extract($params); /** * @var Exception $exception */ $message = $exception->getMessage(); $file = $exception->getFile(); $line = $exception->getLine(); if ($is_ajax = Pie_Request::isAjax()) { // Render a JSON layout for ajax switch (strtolower($is_ajax)) { case 'json': default: $json = json_encode(array('errors' => Pie_Exception::toArray(array($exception)))); $callback = Pie_Request::callback(); echo "{$callback}({$json})"; } } else { if (is_callable(array($exception, 'getTraceAsStringEx'))) { $trace_string = $exception->getTraceAsStringEx(); } else { $trace_string = $exception->getTraceAsString(); } if (Pie::textMode()) { $result = "{$message}\n" . "in {$file} ({$line})\n" . $trace_string; } else { if ($exception instanceof Pie_Exception_PhpError or !empty($exception->messageIsHtml)) { // do not sanitize $message } else { $message = Pie_Html::text($message); } $result = "<h1>{$message}</h1>" . "<h3>in {$file} ({$line})</h3>" . "<pre>" . $trace_string . "</pre>"; } echo $result; } $app = Pie_Config::get('pie', 'app', null); Pie::log("{$app}: Exception in " . ceil(Pie::microtime()) . "ms\n"); Pie::log("{$message}\n in {$file} ({$line})"); }
function users_account_validate() { $birthday_year = $birthday_month = $birthday_day = null; extract($_REQUEST); /* $field_names = array( 'first_name' => 'First name', 'last_name' => 'Last name', 'username' => 'Username', 'gender' => 'Your gender', 'desired_gender' => 'Gender preference', 'orientation' => 'Orientation', 'relationship_status' => 'Status', 'zipcode' => 'Zipcode' ); foreach ($field_names as $name => $label) { if (isset($_POST[$name]) and !($_POST[$name])) { Pie_Response::addError( new Pie_Exception_RequiredField(array('field' => $label), $name) ); } }; */ if (isset($birthday_year)) { if (!checkdate($birthday_month, $birthday_day, $birthday_year)) { $field = 'Birthday'; $range = 'a valid date'; Pie_Response::addError(new Pie_Exception_WrongValue(compact('field', 'range'), 'birthday')); } } if (isset($username)) { try { Pie::event('users/validate/username', compact('username')); } catch (Exception $e) { Pie_Response::addError($e); } } }
/** * Creates an exception * @param array $params * Optional. Array of parameters for the exception. * Used in the exception message, etc. * To access them later, call $e->params() * You can also provide a string here, which will * then be the exception message. * @param array $input_fields * Optional. Array of names of input fields * to which the exception applies. */ function __construct($params = array(), $input_fields = array()) { if (is_string($input_fields)) { $input_fields = array($input_fields => null); } $this->inputFields = $input_fields; if (is_string($params)) { parent::__construct($params, 0); return; } $this->params = is_array($params) ? $params : array(); $class_name = get_class($this); if (isset(self::$messages[$class_name])) { $t_message = Pie::expandString(self::$messages[$class_name], $this->params); } else { $t_message = $class_name; } if (isset(self::$messages[$class_name])) { $t_code = self::$codes[$class_name]; } else { $t_code = 0; } parent::__construct($t_message, $t_code); }
<?php /* * This work is hereby released into the Public Domain. * To view a copy of the public domain dedication, * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. * */ require_once "../../Pie.class.php"; $graph = new Graph(300, 175); $graph->setBackgroundGradient(new LinearGradient(new White(), new VeryLightGray(40), 0)); $graph->title->set("Horses"); $graph->shadow->setSize(5); $graph->shadow->smooth(TRUE); $graph->shadow->setPosition(SHADOW_LEFT_BOTTOM); $graph->shadow->setColor(new DarkGray()); $values = array(8, 4, 6, 2, 5); $plot = new Pie($values); $plot->setCenter(0.35, 0.55); $plot->setSize(0.7, 0.6); $plot->set3D(10); $plot->setLabelPosition(10); $plot->setLegend(array('France', 'Spain', 'Italy', 'Germany', 'England')); $plot->legend->setPosition(1.4); $plot->legend->shadow->setSize(0); $plot->legend->setBackgroundColor(new VeryLightGray(30)); $graph->add($plot); $graph->draw();
function pie_response_dashboard() { return Pie::view('pie/dashboard.php'); }
<?php Pie::var_dump($errors);
function users_account_response_content() { Pie_Session::start(); return Pie::tool('users/account'); }
$x1 = round($this->imageWidth / 4 + $this->imageWidth / 3 * cos(($angle + $angles[$x] / 2) * pi() / 180) / 4); $y1 = round($this->imageHeight / 2 + $this->imageHeight / 3 * sin(($angle + $angles[$x] / 2) * pi() / 180) / 4); ImageFill($image, $x1, $y1, $sliceColors[$x]); $angle = $angle + $angles[$x]; } // put the desc strings ImageString($image, 5, $this->imageWidth / 2, 60, "Legend", $black); for ($x = 0; $x < $num; $x++) { $fl = sprintf("%.2f", $varValues[$x] * 100 / $total); $str = $varDesc[$x] . " (" . $fl . "%)"; ImageString($image, 3, $this->imageWidth / 2, ($x + 5) * 20, $str, $sliceColors[$x]); } // put the title ImageString($image, 5, 20, 20, $this->title, $black); ImagePng($image); ImageDestroy($image); } } $pie = new Pie(); if (isset($width)) { $pie->imageWidth = $width; } if (isset($height)) { $pie->imageHeight = $height; } if (isset($title)) { $pie->title = $title; } $varDesc = explode(",", $desc); $varValues = explode(",", $values); $pie->create($varDesc, $varValues);