/** * Update the current walk with passed in form data */ public function updateWeekend(array $formData) { $this->loadWeekend($formData['id']); // Update all basic fields // Fields that can't be saved are just ignored // Invalid fields throw an exception - display this to the user and continue foreach ($formData as $name => $value) { try { $this->weekend->{$name} = $value; } catch (UnexpectedValueException $e) { // TODO: Error message echo "<p>"; var_dump($name); var_dump($value); var_dump($e->getMessage()); echo "</p>"; } } // Date fields need to be converted if (!empty($formData['startdate'])) { $this->weekend->start = strtotime($formData['startdate']); } else { $this->weekend->start = null; } if (!empty($formData['enddate'])) { $this->weekend->endDate = strtotime($formData['enddate']); } else { $this->weekend->endDate = null; } // Alterations $this->weekend->alterations->incrementVersion(); $this->weekend->alterations->setDetails(!empty($formData['alterations_details'])); $this->weekend->alterations->setCancelled(!empty($formData['alterations_cancelled'])); $this->weekend->alterations->setOrganiser(!empty($formData['alterations_organiser'])); $this->weekend->alterations->setDate(!empty($formData['alterations_date'])); if ($this->weekend->isValid()) { $this->weekend->save(); // Redirect to the list page $itemid = JRequest::getInt('returnPage'); if (empty($itemid)) { return false; } $item = JFactory::getApplication()->getMenu()->getItem($itemid); $link = new JURI("/" . $item->route); // Jump to the event? if (JRequest::getBool('jumpToEvent')) { $link->setFragment("weekend_" . $this->weekend->id); } JFactory::getApplication()->redirect($link, "Weekend saved"); } }
/** * Update the current walk with passed in form data */ public function updateWI(array $formData) { // Load an existing walk instance (if any) if (!empty($formData['id'])) { $factory = SWG::walkInstanceFactory(); $this->wi = $factory->getSingle($formData['id']); } else { $this->wi = new WalkInstance(); } // Update all basic fields // Fields that can't be saved are just ignored // Invalid fields throw an exception - display this to the user and continue foreach ($formData as $name => $value) { try { $this->wi->{$name} = $value; } catch (UnexpectedValueException $e) { echo "<p>"; var_dump($name); var_dump($value); var_dump($e->getMessage()); echo "</p>"; } } // Now do the fields that have to be done separately // Date & time $this->wi->start = strtotime($formData['date'] . " " . $formData['meetTime']); // Alterations $this->wi->alterations->incrementVersion(); $this->wi->alterations->setDetails($formData['alterations_details']); $this->wi->alterations->setCancelled($formData['alterations_cancelled']); $this->wi->alterations->setPlaceTime($formData['alterations_placeTime']); $this->wi->alterations->setOrganiser($formData['alterations_organiser']); $this->wi->alterations->setDate($formData['alterations_date']); if ($this->wi->isValid()) { $this->wi->save(); // Redirect to the list page $itemid = JRequest::getInt('returnPage'); if (empty($itemid)) { return false; } $item = JFactory::getApplication()->getMenu()->getItem($itemid); $link = new JURI("/" . $item->route); // Jump to the event? if (JRequest::getBool('jumpToEvent')) { $link->setFragment("walk_" . $this->wi->id); } JFactory::getApplication()->redirect($link, "Walk scheduled"); } else { } }
public function testSetFragment() { $this->object->setFragment('someFragment'); $this->assertThat( $this->object->getFragment(), $this->equalTo('someFragment') ); }
/** * Update the current walk with passed in form data * This also handles GPX data */ public function updateSocial(array $formData) { $this->loadSocial($formData['id']); // Update all basic fields // Fields that can't be saved are just ignored // Invalid fields throw an exception - display this to the user and continue foreach ($formData as $name => $value) { try { $this->social->{$name} = $value; } catch (UnexpectedValueException $e) { echo "<p>"; var_dump($name); var_dump($value); var_dump($e->getMessage()); echo "</p>"; } } // Empty checkboxes... if (empty($formData['showNormal'])) { $this->social->showNormal = false; } if (empty($formData['showNewMember'])) { $this->social->showNewMember = false; } // Time fields need to be built up (they combine date & time internally) if (!empty($formData['date'])) { if (!empty($formData['starttime'])) { $this->social->start = strtotime($formData['date'] . " " . $formData['starttime']); } else { $this->social->start = strtotime($formData['date']); } if (!empty($formData['endtime'])) { $this->social->end = strtotime($formData['date'] . " " . $formData['endtime']); } else { if ($formData['endtime'] == "") { $this->social->end = null; } } } if (!empty($formData['newMemberStart'])) { $this->social->newMemberStart = strtotime($formData['date'] . " " . $formData['newMemberStart']); } if (!empty($formData['newMemberEnd'])) { $this->social->newMemberEnd = strtotime($formData['date'] . " " . $formData['newMemberEnd']); } // Alterations $this->social->alterations->incrementVersion(); $this->social->alterations->setDetails($formData['alterations_details']); $this->social->alterations->setCancelled($formData['alterations_cancelled']); $this->social->alterations->setPlaceTime($formData['alterations_placeTime']); $this->social->alterations->setOrganiser($formData['alterations_organiser']); $this->social->alterations->setDate($formData['alterations_date']); if ($this->social->isValid()) { $this->social->save(); // Redirect to the list page $itemid = JRequest::getInt('returnPage'); if (empty($itemid)) { return false; } $item = JFactory::getApplication()->getMenu()->getItem($itemid); $link = new JURI("/" . $item->route); // Jump to the event? if (JRequest::getBool('jumpToEvent')) { $link->setFragment("social_" . $this->social->id); } JFactory::getApplication()->redirect($link, "Social saved"); } else { // Find out why it's invalid. // All other errors should be caught by JS - just check it's either a normal social or a new members one. if (!$this->social->showNormal && !$this->social->showNewMember) { } } }
static function append_sid($hook, $url, $params = false, $is_amp = true, $session_id = false) { global $_SID, $_EXTRA_URL; $arrParams = array(); $arrExtra = array(); $anchor = ''; JForumHook::fixPage(); $config =& JFactory::getConfig(); if ($url == '.php') { $url = '/' . $config->getValue('config.phpbb_path') . '/index.php'; } // Assign sid if session id is not specified if ($session_id === false) { $session_id = $_SID; } //Clean the url and the params first if ($is_amp) { $url = str_replace('&', '&', $url); if (!is_array($params)) { $params = str_replace('&', '&', $params); } } $amp_delim = $is_amp ? '&' : '&'; $url_delim = strpos($url, '?') === false ? '?' : $amp_delim; // Process the parameters array if (is_array($params)) { foreach ($params as $key => $item) { if ($item === NULL) { continue; } if ($key == '#') { $anchor = '#' . $item; continue; } $arrParams[$key] = $item; } } else { if (strpos($params, '#') !== false) { list($params, $anchor) = explode('#', $params, 2); $anchor = '#' . $anchor; } parse_str($params, $arrParams); } //Process the extra array if (!empty($_EXTRA_URL)) { $extra = implode('&', $_EXTRA_URL); parse_str($extra, $arrExtra); } //Create the URL $uri = new JURI($url); $query = $uri->getQuery(true); $query = $query + $arrParams + $arrExtra; $uri->setQuery($query); //Set session id variable if ($session_id) { $uri->setVar('sid', $session_id); } //Set fragment if ($anchor) { $uri->setFragment($anchor); } $view = basename($uri->getPath(), '.php'); if (!$uri->getVar('rb_v') && $view != "style") { if (JRequest::getVar('rb_v') == 'adm') { if (strpos($url, $config->getValue('config.phpbb_path')) === false) { $view = 'adm'; } } if (stripos($url, $config->getValue('config.phpbb_path') . '/adm') !== false) { $view = 'adm'; } if ($view != 'index') { $uri->setVar('rb_v', $view); } } if ($view != 'style') { $url = 'index.php' . $uri->toString(array('query', 'fragment')); // {} getting lost in encoding $url = str_replace(array('%7B', '%7D'), array('{', '}'), $url); return urldecode(JURI::base() . JRoute::_($url, $is_amp)); } else { $url = 'style.php' . $uri->toString(array('query', 'fragment')); $url = str_replace(array('%7B', '%7D'), array('{', '}'), $url); return urldecode(JPATH_ROOT . '/' . $config->getValue('config.phpbb_path') . '/' . $url); } }
public function upload() { // Check for request forgeries. JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $this->errors = array(); // Initialise variables. $app = JFactory::getApplication(); $model = $this->getModel('uploadtrack'); $view = $this->getView('uploadtrack', 'html'); $view->setModel($model, true); $wi = $model->getWalkInstance(); // Are we uploading a track, or saving the track we've already uploaded? $file = JRequest::getVar('file', array(), 'FILES', 'array'); if (!empty($file) && $file['error'] == UPLOAD_ERR_OK) { // We've been given a GPX file. Try to parse it. $gpx = DOMDocument::load($file['tmp_name']); if ($gpx && $gpx->getElementsByTagName("gpx")->length == 1) { $route = new Route(); $wi = $model->getWalkInstance(); if ($wi != null) { $route->setWalk($wi); } $route->readGPX($gpx); $route->uploadedBy = JFactory::getUser()->id; $route->uploadedDateTime = time(); $route->type = Route::Type_Logged; if ($wi != null) { // Check that this route matches the walk if ($route->checkAgainstWalk($model->getWalkInstance(), $message, $details)) { // Store this route for later requests JFactory::getApplication()->setUserState("uploadedroute", serialize($route)); } else { throw new UserException("Can't upload this track", 0, "This track doesn't match that walk", $message . ": " . $details); } } else { // Try to find a matching walk $wi = $route->findMatchingWalk(); if (isset($wi)) { $route->setWalk($wi); // Store this route for later requests JFactory::getApplication()->setUserState("uploadedroute", serialize($route)); $model->setWalkInstance($wi); } else { throw new Exception("That track doesn't match any walks. Check that it doesn't contain anything other than the walk."); } } } else { throw new Exception("The track you uploaded is not a valid GPX file. If your track is in another format, please convert it to GPX first, then upload it again."); } $view->display(); } else { $route = unserialize(JFactory::getApplication()->getUserState("uploadedroute")); if ($route) { $route->save(); // Set the distance on the WalkInstance, if it's not already set if (empty($wi->distance)) { $wi->distance = $route->getDistance(); $wi->save(); } } else { throw new Exception("There was an error while saving your track. You can try again in a while, or email us if that doesn't work."); } // Redirect to the specified page after saving $itemid = JRequest::getInt('returnPage'); if (empty($itemid)) { return false; } $item = JFactory::getApplication()->getMenu()->getItem($itemid); $link = new JURI("/" . $item->route); // Jump to the event? if (JRequest::getBool('jumpToEvent')) { $link->setFragment("walk_" . $wi->id); } JFactory::getApplication()->redirect($link, "Track saved"); } }