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')); }
/** * Renders pie-specific information for a form * @param string $on_success * The URI or URL to redirect to in case of success * If you put "true" here, it uses $_REQUEST['_pie']['onSuccess'], * or if it's not there, then Pie_Dispatcher::uri() * @param string $on_errors * Optional. The URI or URL to redirect to in case of errors * If you put "true" here, it uses $_REQUEST['_pie']['onSuccess'], * or if it's not there, then Pie_Dispatcher::uri() * @param string $session_nonce_field * Optional. The name of the nonce field to use in the session. * If the config parameter "pie"/"session"/"nonceField" is set, uses that. * @return string * The generated markup */ static function formInfo($on_success, $on_errors = null, $session_nonce_field = null) { $uri = Pie_Dispatcher::uri(); if ($on_success === true) { $on_success = Pie::ifset($_REQUEST['_pie']['onSuccess'], $uri); } if ($on_errors === true) { $on_errors = Pie::ifset($_REQUEST['_pie']['onSuccess'], $uri); } $hidden_fields = array(); if (isset($on_success)) { $hidden_fields['_pie[onSuccess]'] = Pie_Uri::url($on_success); } if (isset($on_errors)) { $hidden_fields['_pie[onErrors]'] = Pie_Uri::url($on_errors); } if (!isset($session_nonce_field)) { $session_nonce_field = Pie_Config::get('pie', 'session', 'nonceField', 'nonce'); } if (isset($session_nonce_field)) { if (!isset($_SESSION['pie'][$session_nonce_field])) { $_SESSION['pie'][$session_nonce_field] = uniqid(); } $hidden_fields['_pie[nonce]'] = $_SESSION['pie'][$session_nonce_field]; } return self::hidden($hidden_fields); }
function users_register_response_json() { $user = Pie::ifset(Users::$cache['user']); unset($user->password_hash); return compact('user'); }
function items_addPhoto_post() { if (Pie_Dispatcher::uri()->facebook) { return; } if (isset($_POST['fb_sig_app_id'])) { $app_id = $_POST['fb_sig_app_id']; } else { $app = Pie_Config::expect('pie', 'app'); $app_id = Pie_Config::expect('users', 'facebookApps', $app, 'appId'); } Users::authenticate('facebook', $app_id); /* if (!isset($_REQUEST['content'])) { Pie_Response::addError(new Pie_Exception_RequiredField(array( 'field' => 'content' ))); Pie_Dispatcher::showErrors(); return; } */ $user = Users::loggedInUser(); if (!$user) { throw new Users_Exception_NotLoggedIn(); } // TODO: download a backup copy into a special place for facebook photos // TODO: handle uploads // Facebook photo if (!empty($_POST['src_big'])) { if (!is_array($_POST['src_big'])) { throw new Exception("src_big must be an array"); } // First, we download the photo to store on our site foreach ($_POST['src_big'] as $pid => $src_big) { $src_small = Pie::ifset($_POST['src_small'][$pid], $src_big); $parts = explode('/', $src_big); $parts = explode('.', end($parts)); $ext = end($parts); $filename = 'photos' . DS . 'facebook' . DS . "pid{$pid}.{$ext}"; $abs_filename = ITEMS_PLUGIN_FILES_DIR . DS . $filename; if (file_exists($abs_filename)) { // A photo was already copied to this filename Pie_Config::set('items', 'addPhoto', 'result', 'exists'); $photo = new Items_Photo(); $photo->filename = $filename; if ($photo = $photo->retrieve()) { $item = new Items_Item(); $item->id = $photo->item_id; $item = $item->retrieve(); // relies on DB consistency Pie_Config::set('items', 'addPhoto', 'item_id', $item->id); Pie_Config::set('items', 'addPhoto', 'state', $item->state); } return; } copy($src_big, $abs_filename); $item = new Items_Item(); $item->by_user_id = $user->id; $item->thumb_url = $src_small; $item->share_count = 0; $item->state = 'pending'; Pie::event('items/addPhoto/saveItem', compact('item'), 'before'); $item->save(); $photo = new Items_Photo(); $photo->src_url = $src_big; $photo->filename = $filename; $photo->item_id = $item->id; Pie::event('items/addPhoto/savePhoto', compact('photo'), 'before'); $photo->save(); } } else { if (isset($_FILES['upload'])) { // TODO: maybe add checks for size, mime type, etc. if ($errcode = $_FILES['upload']['error']) { $code = $_FILES['upload']['error']; throw new Pie_Exception_UploadError(compact('code')); } $parts = explode('.', $_FILES['upload']['name']); $ext = end($parts); $uniqid = isset($_POST['uniqid']) ? $_POST['uniqid'] : uniqid('up.', false); $md5 = md5($_FILES['upload']['name']); $dirname = 'photos' . DS . 'user' . $user->id; $abs_dirname = ITEMS_PLUGIN_FILES_DIR . DS . $dirname; if (!file_exists($abs_dirname)) { mkdir($abs_dirname, 0777, true); } $filename = $dirname . DS . "{$uniqid}.{$md5}.{$ext}"; $abs_filename = ITEMS_PLUGIN_FILES_DIR . DS . $filename; if (file_exists($abs_filename)) { // A file was already uploaded via this uniqid Pie_Config::set('items', 'addPhoto', 'result', 'exists'); $photo = new Items_Photo(); $photo->filename = $filename; if ($photo = $photo->retrieve()) { $item = new Items_Item(); $item->id = $photo->item_id; $item = $item->retrieve(); // relies on DB consistency Pie_Config::set('items', 'addPhoto', 'item_id', $item->id); Pie_Config::set('items', 'addPhoto', 'state', $item->state); } return; } move_uploaded_file($_FILES['upload']['tmp_name'], $abs_filename); $src_big = 'plugins/items/photos/user' . $user->id . "/{$uniqid}.{$md5}.{$ext}"; $src_small = $src_big; // TODO: make small version!!!! AND PUT INTO thumb_url // Try different functions if they exist, from graphics libs $item = new Items_Item(); $item->by_user_id = $user->id; $item->thumb_url = $src_small; $item->share_count = 0; $item->state = 'pending'; Pie::event('items/addPhoto/saveItem', compact('item'), 'before'); $item->save(); $photo = new Items_Photo(); $photo->src_url = $src_big; $photo->filename = $filename; $photo->item_id = $item->id; Pie::event('items/addPhoto/savePhoto', compact('photo'), 'before'); $photo->save(); } } // Report as added if (!empty($item)) { Pie_Config::set('items', 'addPhoto', 'result', 'added'); Pie_Config::set('items', 'addPhoto', 'item_id', $item->id); Pie_Config::set('items', 'addPhoto', 'state', $item->state); } }
/** * This tool generates a panel with a <form> tag inside it * @param array $params * An associative array of parameters, containing: * "uri" => the uri or url the form should post to * "title" => the title of the panel * "complete" => boolean, indicating whether the data on the server is in a complete state * "editing" => boolean, indicating whether to show the form in the "editing" state * "form" => string containing the contents of the form portion of the panel * which is normally generated by a "pie/form" tool * "static" => string containing the contents of the "static" portion * "collapsed" => defaults to false. Whether the panel is shown as collapsed into just the header * "toggle" => defaults to false. The events that cause toggling of collapsed state. * If the string is 'click' then toggles the panel on clicks. * If the string is 'move' then toggles the panel on mouseenter/mouseleave. * "edit_button" => optional, to override the edit button * "save_button" => optional, to override the save button * "cancel_button" => optional, to override the cancel button * "panel_classes" => optional, additional classes for the panel * "snf" => optional. The name of the nonce field in the session * "on_success" => optional. The URI to redirect to on success * "on_errors" => optional. The URI to display if errors occur * "inProcess" => optional. Causes the panel to appear as if it's a step in a process. */ function pie_panel_tool($params) { foreach (array('title', 'complete', 'editing', 'static', 'form') as $f) { if (!array_key_exists($f, $params)) { throw new Pie_Exception_RequiredField(array('field' => '$' . $f)); } } $defaults = array('edit_button' => "<button type='submit' class='basic16 basic16_edit pie_panel_tool_edit'>edit</button>", 'save_button' => "<button type='submit' class='basic16 basic16_check pie_panel_tool_save'>save</button>", 'cancel_button' => "<button type='reset' class='basic16 basic16_cancel pie_panel_tool_cancel'>cancel</button>", 'panel_classes' => '', 'uri' => null, 'collapsed' => false, 'toggle' => false, 'inProcess' => false, 'on_success' => null, 'on_errors' => null, 'snf' => null); extract(array_merge($defaults, $params)); $more_class = $params['complete'] ? 'pie_panel_tool_complete' : 'pie_panel_tool_incomplete'; $panel_classes = "{$more_class} {$panel_classes}"; $title_div = "<div class='pie_panel_tool_title'>{$title}</div>"; if ($uri) { $header = "<div class='pie_panel_tool_buttons'>{$save_button}{$cancel_button}{$edit_button}</div>{$title_div}"; } else { $header = $title_div; } // Whether to display the panel one way or the other if ($inProcess) { $header = $title_div; if (is_array($form)) { $form['fields']['_pie_buttons'] = array('type' => 'buttons', 'label' => '', 'options' => array('continue' => 'Continue'), 'attributes' => array('class' => 'basic32 basic32_right', 'type' => 'submit')); } else { $form .= "<div class='pie_panel_tool_formbuttons'><button type='submit' class='pie_panel_tool_continue basic32 basic32_right' value='continue'>Continue</button></div>"; } } // Turn the static into a string, if it's an array // This currently doesn't work well, because it causes // a bug where the outer form is submitted twice. if (is_array($static)) { foreach ($static['fields'] as $k => $f) { if (Pie::ifset($static['fields'][$k]['type'])) { switch ($static['fields'][$k]['type']) { case 'textarea': $static['fields'][$k]['value'] = str_replace("\n", "<br>", $static['fields'][$k]['value']); break; case 'date': if (!isset($static['fields'][$k]['options']['date'])) { $static['fields'][$k]['options']['date'] = "M j, Y"; } break; case 'buttons': unset($static['fields'][$k]); } } $static['fields'][$k]['type'] = 'static'; } $static = Pie::tool('pie/form', $static, array('id' => 'static')); } // Turn the form into a form if (is_array($form)) { $form = Pie::tool('pie/form', $form); } // Build the panel $panel = "<div class='pie_panel_tool_header'>{$header}</div>" . "<div class='pie_panel_tool_form'>{$form}</div>"; if (isset($snf) or isset($on_success) or isset($on_errors)) { $panel .= "<div>" . Pie_Html::formInfo($on_success, $on_errors, $snf) . "</div>"; } if ($uri) { $panel = Pie_Html::form($uri, 'post', array('class' => "pie_panel_tool_panel"), $panel); } $panel .= "<div class='pie_panel_tool_static'>{$static}</div>"; if ($editing) { $panel_classes .= ' pie_editing'; } if ($complete) { $panel_classes .= ' pie_complete'; } if ($collapsed) { $panel_classes .= ' pie_collapsed'; } if ($toggle === 'click') { $panel_classes .= ' pie_panel_tool_toggle_onclick'; } if ($toggle === 'move') { $panel_classes .= ' pie_panel_tool_toggle_move'; } Pie_Response::addScript('plugins/pie/js/PieTools.js'); Pie_Response::addStylesheet('plugins/pie/css/Ui.css'); if (isset($_form_static)) { Pie_Response::setSlot('form', $form); Pie_Response::setSlot('static', $static); } return "<div class='pie_panel_tool_container {$panel_classes}'>{$panel}</div>"; }