/** * Check method, used when saving * * @return bool */ public function check() { // verify name $this->name = trim($this->name); if ($this->name == '') { $this->setError(Lang::txt('COM_DEVELOPER_API_APPLICATION_MISSING_NAME')); return false; } // verify description $this->description = trim($this->description); if ($this->description == '') { $this->setError(Lang::txt('COM_DEVELOPER_API_APPLICATION_MISSING_DESCRIPTION')); return false; } // verify redirect URIs $uris = array_map('trim', explode(PHP_EOL, $this->redirect_uri)); // must have one if (empty($uris)) { $this->setError(Lang::txt('COM_DEVELOPER_API_APPLICATION_MISSING_REDIRECT_URI')); return false; } // validate each one $invalid = array(); foreach ($uris as $uri) { if (!Validate::url($uri)) { $invalid[] = $uri; } } // if we have any invalid URIs lets inform the user if (!empty($invalid)) { $this->setError(Lang::txt('COM_DEVELOPER_API_APPLICATION_INVALID_REDIRECT_URI', implode('<br />', $invalid))); return false; } // turn back into string for saving $this->redirect_uri = implode(' ', $uris); // if we dont have a created by add one if (!$this->created_by) { $this->created_by = User::get('id'); } // if this is a new record if (!$this->id) { $this->created = with(new Date('now'))->toSql(); if (!$this->hub_account) { // Allow the 3 main grantypes // // authorization code = 3 legged oauth // password = users username/password // refresh_token = allow refreshing of access_tokens to require less logins $this->grant_types = 'authorization_code password refresh_token'; } // generate unique client id & secret list($this->client_id, $this->client_secret) = $this->generateUniqueClientIdAndSecret(); } return true; }
/** * Save an entry * * @return string */ private function save() { Request::checkToken(); //get request vars $event = Request::getVar('event', array(), 'post'); $event['time_zone'] = Request::getVar('time_zone', -5); $event['params'] = Request::getVar('params', array()); $event['content'] = Request::getVar('content', '', 'post', 'STRING', JREQUEST_ALLOWRAW); $registration = Request::getVar('include-registration', 0); //set vars for saving $event['catid'] = '-1'; $event['state'] = 1; $event['scope'] = 'group'; $event['scope_id'] = $this->group->get('gidNumber'); $event['modified'] = Date::toSql(); $event['modified_by'] = $this->user->get('id'); // repeating rule $event['repeating_rule'] = $this->_buildRepeatingRule(); //if we are updating set modified time and actor if (!isset($event['id']) || $event['id'] == 0) { $event['created'] = Date::toSql(); $event['created_by'] = $this->user->get('id'); } // timezone $timezone = new DateTimezone(Config::get('offset')); //parse publish up date/time if (isset($event['publish_up']) && $event['publish_up'] != '') { // combine date & time if (isset($event['publish_up_time'])) { $event['publish_up'] = $event['publish_up'] . ' ' . $event['publish_up_time']; } $event['publish_up'] = Date::of($event['publish_up'], $timezone)->format("Y-m-d H:i:s"); unset($event['publish_up_time']); } //parse publish down date/time if (isset($event['publish_down']) && $event['publish_down'] != '') { // combine date & time if (isset($event['publish_down_time'])) { $event['publish_down'] = $event['publish_down'] . ' ' . $event['publish_down_time']; } $event['publish_down'] = Date::of($event['publish_down'], $timezone)->format("Y-m-d H:i:s"); unset($event['publish_down_time']); } //parse register by date/time if (isset($event['registerby']) && $event['registerby'] != '') { //remove @ symbol $event['registerby'] = str_replace("@", "", $event['registerby']); $event['registerby'] = Date::of($event['registerby'], $timezone)->format("Y-m-d H:i:s"); } //stringify params if (isset($event['params']) && count($event['params']) > 0) { $params = new \Hubzero\Config\Registry($event['params']); $event['params'] = $params->toString(); } //did we want to turn off registration? if (!$registration) { $event['registerby'] = '0000-00-00 00:00:00'; } //instantiate new event object $eventsModelEvent = new \Components\Events\Models\Event(); // attempt to bind if (!$eventsModelEvent->bind($event)) { $this->setError($eventsModelEvent->getError()); $this->event = $eventsModelEvent; return $this->edit(); } if (isset($event['content']) && $event['content']) { $event['content'] = \Hubzero\Utility\Sanitize::clean($event['content']); } if (isset($event['extra_info']) && $event['extra_info'] && !\Hubzero\Utility\Validate::url($event['extra_info'])) { $this->setError('Website entered does not appear to be a valid URL.'); $this->event = $eventsModelEvent; return $this->edit(); } //make sure we have both start and end time if ($event['publish_up'] == '') { $this->setError('You must enter an event start, an end date is optional.'); $this->event = $eventsModelEvent; return $this->edit(); } //check to make sure end time is greater than start time if (isset($event['publish_down']) && $event['publish_down'] != '0000-00-00 00:00:00' && $event['publish_down'] != '') { $up = strtotime($event['publish_up']); $down = strtotime($event['publish_down']); $allday = isset($event['allday']) && $event['allday'] == 1 ? true : false; // make sure up greater than down when not all day // when all day event up can equal down if ($up >= $down && !$allday || $allday && $up > $down) { $this->setError('You must an event end date greater than the start date.'); $this->event = $eventsModelEvent; return $this->edit(); } } //make sure registration email is valid if ($registration && isset($event['email']) && $event['email'] != '' && !filter_var($event['email'], FILTER_VALIDATE_EMAIL)) { $this->setError('You must enter a valid email address for the events registration admin email.'); $this->event = $eventsModelEvent; return $this->edit(); } //make sure registration email is valid if ($registration && (!isset($event['registerby']) || $event['registerby'] == '')) { $this->setError('You must enter a valid event registration deadline to require registration.'); Request::setVar('includeRegistration', 1); $this->event = $eventsModelEvent; return $this->edit(); } //check to make sure we have valid info if (!$eventsModelEvent->store(true)) { $this->setError('An error occurred when trying to edit the event. Please try again.'); $this->event = $eventsModelEvent; return $this->edit(); } //get the year and month for this event //so we can jump to that spot $year = Date::of(strtotime($event['publish_up']))->format("Y"); $month = Date::of(strtotime($event['publish_up']))->format("m"); //build message $message = Lang::txt('You have successfully created a new group event.'); if (isset($event['id']) && $event['id'] != 0) { $message = Lang::txt('You have successfully edited the group event.'); } //inform user and redirect App::redirect(Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&action=details&event_id=' . $eventsModelEvent->get('id')), $message, 'passed'); }
/** * Sets up additional custom rules * * @return void **/ public function setup() { $this->addRule('redirect_uri', function ($data) { if (!isset($data['redirect_uri']) || !$data['redirect_uri']) { return Lang::txt('COM_DEVELOPER_API_APPLICATION_MISSING_REDIRECT_URI'); } $uris = array_map('trim', explode(PHP_EOL, $data['redirect_uri'])); // must have one if (empty($uris)) { return Lang::txt('COM_DEVELOPER_API_APPLICATION_MISSING_REDIRECT_URI'); } // validate each one $invalid = array(); foreach ($uris as $uri) { if (!Validate::url($uri)) { $invalid[] = $uri; } } // if we have any invalid URIs lets inform the user if (!empty($invalid)) { return Lang::txt('COM_DEVELOPER_API_APPLICATION_INVALID_REDIRECT_URI', implode('<br />', $invalid)); } return false; }); }
/** * Upload a file to the wiki via AJAX * * @return string */ public function ajaxCreateTask() { // Check if they're logged in if (User::isGuest()) { echo json_encode(array('error' => Lang::txt('Must be logged in.'))); return; } // Ensure we have an ID to work with $pid = strtolower(Request::getInt('pid', 0)); if (!$pid) { echo json_encode(array('error' => Lang::txt('COM_RESOURCES_NO_ID'))); return; } // Create database entry $asset = new Resource($this->database); $asset->title = 'A link'; $asset->introtext = $asset->title; $asset->created = Date::toSql(); $asset->created_by = User::get('id'); $asset->published = 1; $asset->publish_up = Date::toSql(); $asset->publish_down = '0000-00-00 00:00:00'; $asset->standalone = 0; $asset->access = 0; $asset->path = Request::getVar('url', 'http://'); $asset->type = 11; $asset->path = str_replace(array('|', '\\', '{', '}', '^'), array('%7C', '%5C', '%7B', '%7D', '%5E'), $asset->path); if (!Validate::url($asset->path)) { echo json_encode(array('success' => false, 'errors' => array(Lang::txt('Link provided is not a valid URL.')), 'file' => $asset->path, 'directory' => '', 'parent' => $pid, 'id' => 0)); return; } if (!$asset->check()) { echo json_encode(array('success' => false, 'errors' => $asset->getErrors(), 'file' => $asset->path, 'directory' => '', 'parent' => $pid, 'id' => 0)); return; } if (!$asset->store()) { echo json_encode(array('success' => false, 'errors' => $asset->getErrors(), 'file' => 'http://', 'directory' => '', 'parent' => $pid, 'id' => 0)); return; } // Instantiate a Resources Assoc object $assoc = new Assoc($this->database); // Get the last child in the ordering $assoc->ordering = $assoc->getLastOrder($pid); $assoc->ordering = $assoc->ordering ? $assoc->ordering : 0; // Increase the ordering - new items are always last $assoc->ordering++; // Create new parent/child association $assoc->parent_id = $pid; $assoc->child_id = $asset->id; $assoc->grouping = 0; if (!$assoc->check()) { echo json_encode(array('success' => false, 'errors' => $assoc->getErrors(), 'file' => $asset->path, 'directory' => '', 'parent' => $pid, 'id' => $asset->id)); return; } if (!$assoc->store(true)) { echo json_encode(array('success' => false, 'errors' => $assoc->getErrors(), 'file' => $asset->path, 'directory' => '', 'parent' => $pid, 'id' => $asset->id)); return; } //echo result echo json_encode(array('success' => true, 'errors' => array(), 'file' => $asset->path, 'directory' => '', 'parent' => $pid, 'id' => $asset->id)); }
/** * Create a URL attachment via AJAX * * @return void */ public function ajaxCreateTask() { // Ensure we have an ID to work with $pid = strtolower(Request::getInt('pid', 0)); if (!$pid) { echo json_encode(array('error' => Lang::txt('COM_RESOURCES_NO_ID'))); return; } // Create new record $resource = Resource::blank()->set(array('title' => 'A link', 'introtext' => 'A link', 'created' => Date::toSql(), 'created_by' => User::get('id'), 'published' => 1, 'publish_up' => Date::toSql(), 'publish_down' => '0000-00-00 00:00:00', 'standalone' => 0, 'access' => 0, 'path' => Request::getVar('url', 'http://'), 'type' => 11)); // Clean and validate path $resource->path = str_replace(array('|', '\\', '{', '}', '^'), array('%7C', '%5C', '%7B', '%7D', '%5E'), $resource->path); if (!Validate::url($resource->path)) { echo json_encode(array('success' => false, 'errors' => array(Lang::txt('Link provided is not a valid URL.')), 'file' => $resource->path, 'directory' => '', 'parent' => $pid, 'id' => 0)); return; } // Save record if (!$resource->save()) { echo json_encode(array('success' => false, 'errors' => $resource->getErrors(), 'file' => 'http://', 'directory' => '', 'parent' => $pid, 'id' => 0)); return; } // Create new parent/child association if (!$resource->makeChildOf($pid)) { echo json_encode(array('success' => false, 'errors' => $resource->getErrors(), 'file' => $resource->path, 'directory' => '', 'parent' => $pid, 'id' => $resource->id)); return; } // Output results echo json_encode(array('success' => true, 'errors' => array(), 'file' => $resource->path, 'directory' => '', 'parent' => $pid, 'id' => $resource->id)); }