public static function current() { if (self::$current !== '') { return self::$current; } return self::$current = ($id = Session::getData('user_id')) ? User::find_by_id($id) : null; }
public function validateRequestParams() { $loggedIn = Session::getData(REQUEST_PARAMETER_LOGGEDIN); $this->user = Session::getData(REQUEST_PARAMETER_USER_NAME); if (!$loggedIn || !isset($this->user['UserName']) || !isset($this->user['Email'])) { ErrorHandler::error(E_ERROR, 'This action is not allowed'); } }
/** * Retrieve messages * * @param string|null $group * @param bool $clear * @return Collection */ public function getMessages($clear = false, $group = null) { $group = $this->prepareGroup($group); if (!$this->session->getData($group)) { $this->session->setData($group, $this->messagesFactory->create()); } if ($clear) { $messages = clone $this->session->getData($group); $this->session->getData($group)->clear(); $this->eventManager->dispatch('session_abstract_clear_messages'); return $messages; } return $this->session->getData($group); }
public function validateRequestParams() { $loggedIn = Session::getData(REQUEST_PARAMETER_LOGGEDIN); $this->user = Session::getData(REQUEST_PARAMETER_USER_NAME); if (!$loggedIn || !isset($this->user['UserName']) || !isset($this->user['Email'])) { ErrorHandler::error(E_ERROR, 'This action is not allowed'); } $this->visualization = $this->getVisualization(); if (!isset($this->visualization[REQUEST_PARAMETER_VIZ_ID]) || !$this->visualization[REQUEST_PARAMETER_VIZ_ID]) { ErrorHandler::error(E_ERROR, 'An invalid visualization was requested'); } if (!$this->visualization[REQUEST_PARAMETER_MYMAP]) { ErrorHandler::error(E_ERROR, 'Only My Maps are allowed'); } }
public function validateRequestParams() { $loggedIn = Session::getData(REQUEST_PARAMETER_LOGGEDIN); $this->user = Session::getData(REQUEST_PARAMETER_USER_NAME); if (!$loggedIn || !isset($this->user['UserName']) || !isset($this->user['Email'])) { ErrorHandler::error(E_ERROR, 'This action is not allowed'); } $this->visualization = $this->getVisualization(); if (!isset($this->visualization[REQUEST_PARAMETER_VIZ_ID]) || !$this->visualization[REQUEST_PARAMETER_VIZ_ID] || !$this->visualization[REQUEST_PARAMETER_MYMAP] && (!$this->visualization['map_enabled'] || !$this->visualization['edit_enabled'])) { ErrorHandler::error(E_ERROR, 'An invalid visualization was requested'); } $this->featureId = $this->getParam('featureId'); $this->layerId = $this->getParam('layerId'); if (!$this->featureId || !$this->layerId) { ErrorHandler::error(E_ERROR, 'No feature data was given'); } }
public function validateRequestParams() { $loggedIn = Session::getData(REQUEST_PARAMETER_LOGGEDIN); $this->user = Session::getData(REQUEST_PARAMETER_USER_NAME); if (!$loggedIn || !isset($this->user['UserName']) || !isset($this->user['Email'])) { ErrorHandler::error(E_ERROR, 'This action is not allowed'); } $this->visualization = $this->getVisualization(); if (!isset($this->visualization[REQUEST_PARAMETER_VIZ_ID]) || !$this->visualization[REQUEST_PARAMETER_VIZ_ID] || !$this->visualization[REQUEST_PARAMETER_MYMAP] && (!$this->visualization['map_enabled'] || !$this->visualization['edit_enabled'])) { ErrorHandler::error(E_ERROR, 'An invalid visualization was requested'); } $this->action = $this->getParam('featureAction') ? $this->getParam('featureAction') : null; $this->featureId = $this->getParam('featureId') ? (int) $this->getParam('featureId') : null; $this->layerId = $this->getParam('layerId') ? $this->getParam('layerId') : null; $this->the_geom = $this->getParam('the_geom') ? (array) json_decode($this->getParam('the_geom')) : null; $this->geom_type = in_array($this->getParam('geom_type'), [EDITOR_POINT, EDITOR_LINE, EDITOR_POLYGON]) ? $this->getParam('geom_type') : null; $this->featureStyle = $this->getParam('featureStyle') ? $this->getParam('featureStyle') : []; switch ($this->action) { case EDITOR_ACTION_NEW_FEATURE: if (!$this->the_geom || !$this->geom_type || !$this->featureStyle || !$this->getParam('name') || strcmp($this->getParam('name'), '') === 0) { ErrorHandler::error(E_ERROR, 'Feature data missing: expected the_geom, geom_type, featureStyle and name'); } break; case EDITOR_ACTION_EDIT_DATA: if (!$this->featureId || !$this->layerId || !$this->geom_type || !$this->featureStyle || !$this->getParam('name') || strcmp($this->getParam('name'), '') === 0) { ErrorHandler::error(E_ERROR, 'Feature data missing: expected featureId, layerId, geom_type, featureStyle and name'); } break; case EDITOR_ACTION_EDIT_GEOM: if (!$this->featureId || !$this->layerId || !$this->the_geom || !$this->geom_type) { ErrorHandler::error(E_ERROR, 'Feature data missing: expected featureId, layerId, the_geom and geom_type'); } break; case EDITOR_ACTION_DELETE: if (!$this->featureId || !$this->layerId) { ErrorHandler::error(E_ERROR, 'Feature data missing: expected featureId and layerId'); } break; default: ErrorHandler::error(E_ERROR, String::prepare("Action '%s' not permitted", $this->action)); } }
protected function getVisualization() { $loggedIn = Session::getData(REQUEST_PARAMETER_LOGGEDIN); $vizUrl = $this->getParam(REQUEST_PARAMETER_VIZ_URL); $inspectResult = array(REQUEST_PARAMETER_MYMAP => false, 'map_privacy' => 'private', 'map_privacy_users' => '', 'map_enabled' => false, 'edit_privacy' => 'private', 'edit_privacy_users' => '', 'edit_enabled' => false, 'edit_mode' => false); if ($vizUrl) { $sessionUser = Session::getData(REQUEST_PARAMETER_USER_NAME); $inspectResult[REQUEST_PARAMETER_VIZ_URL] = $vizUrl; $urlUser = substr($vizUrl, strpos($vizUrl, '://') + 3); $inspectResult[REQUEST_PARAMETER_USER_NAME] = substr($urlUser, 0, strpos($urlUser, '.')); if ($loggedIn && $vizUrl !== VISUALIZATION_DEFAULT && $inspectResult[REQUEST_PARAMETER_USER_NAME] === $sessionUser['UserName']) { $inspectResult[REQUEST_PARAMETER_MYMAP] = true; } $vizId = substr($vizUrl, strpos($vizUrl, '/viz/') + 5); $inspectResult[REQUEST_PARAMETER_VIZ_ID] = substr($vizId, 0, strpos($vizId, '/')); $vizJSON = $this->getVisualizationJSON(); if (isset($vizJSON['map_options']) && $vizJSON['map_options']) { $mapOptions = json_decode($vizJSON['map_options'], true); if ($mapOptions) { if ($mapOptions['map_privacy'] !== 'private') { $restrictedMapUsers = explode(',', $mapOptions['map_privacy_users']); array_walk($restrictedMapUsers, function (&$value) { $value = trim($value); }); $mapOptions['map_enabled'] = $inspectResult[REQUEST_PARAMETER_MYMAP] || $mapOptions['map_privacy'] === 'public' || in_array($sessionUser['UserName'], $restrictedMapUsers); } if ($mapOptions['edit_privacy'] !== 'private') { $restrictedEditUsers = explode(',', $mapOptions['edit_privacy_users']); array_walk($restrictedEditUsers, function (&$value) { $value = trim($value); }); $mapOptions['edit_enabled'] = $inspectResult[REQUEST_PARAMETER_MYMAP] || $mapOptions['edit_privacy'] === 'public' || in_array($sessionUser['UserName'], $restrictedEditUsers); } $inspectResult = array_merge($inspectResult, $mapOptions); } } else { // @todo: use visualization privacy setting } } return $inspectResult; }
public function validateRequestParams() { $loggedIn = Session::getData(REQUEST_PARAMETER_LOGGEDIN); $this->user = Session::getData(REQUEST_PARAMETER_USER_NAME); if (!$loggedIn || !isset($this->user['UserName']) || !isset($this->user['Email'])) { ErrorHandler::error(E_ERROR, 'This action is not allowed'); } // @todo: update so this class can deal with other update fields like email $passwordOld = $this->getParam('passwordOld'); $passwordNew = $this->getParam('passwordNew'); $passwordConfirm = $this->getParam('passwordConfirm'); if (!$passwordOld || !$passwordNew || !$passwordConfirm) { ErrorHandler::error(E_ERROR, 'Invalid password input'); } $passwordHashOld = mcrypt_encrypt(MCRYPT_RIJNDAEL_192, VISUALIZATION_KEY, $passwordOld, MCRYPT_MODE_ECB); $this->passwordOld = urlencode($passwordHashOld); $passwordHashNew = mcrypt_encrypt(MCRYPT_RIJNDAEL_192, VISUALIZATION_KEY, $passwordNew, MCRYPT_MODE_ECB); $this->passwordNew = urlencode($passwordHashNew); $passwordHashConfirm = mcrypt_encrypt(MCRYPT_RIJNDAEL_192, VISUALIZATION_KEY, $passwordConfirm, MCRYPT_MODE_ECB); $this->passwordConfirm = urlencode($passwordHashConfirm); }
/** * * @return string */ protected function prepareVisualization() { $loggedIn = Session::getData(REQUEST_PARAMETER_LOGGEDIN); $sessionViz = Session::getData(REQUEST_PARAMETER_VIZ); $user = Session::getData(REQUEST_PARAMETER_USER_NAME); $visualization = array('communityMaps' => array(), 'myMaps' => array()); // Community maps $webserviceUrl = String::prepare('%svisualization/wo/community?user=%s&password=%s&userName=%s&userKey=%s&format=application/json', WEBSERVICE_URL, WEBSERVICE_USER, WEBSERVICE_PASSWORD, $user['UserName'], $user['ApiKey']); $requestContents = Connectivity::runCurl($webserviceUrl); if ($requestContents) { $jsonOutput = json_decode($requestContents, true); if (isset($jsonOutput['response']['community'])) { $visualization['communityMaps'] = $jsonOutput['response']['community']; } } // My maps if ($loggedIn) { $webserviceUrl = String::prepare('%svisualization/wo/visualization?user=%s&password=%s&userName=%s&userKey=%s&format=application/json', WEBSERVICE_URL, WEBSERVICE_USER, WEBSERVICE_PASSWORD, $user['UserName'], $user['ApiKey']); $requestContents = Connectivity::runCurl($webserviceUrl); if ($requestContents) { $jsonOutput = json_decode($requestContents, true); if (isset($jsonOutput['response']['visualization'])) { $visualization['myMaps'] = $jsonOutput['response']['visualization']; } } } // Set the default visualization $vizUrl = isset($sessionViz[REQUEST_PARAMETER_VIZ_URL]) ? $sessionViz[REQUEST_PARAMETER_VIZ_URL] : ''; // Fallback for the default visualization if (empty($visualization['defaultVisualization'])) { if (!$vizUrl) { $vizUrl = $loggedIn && isset($sessionViz[REQUEST_PARAMETER_VIZ_URL]) ? $sessionViz[REQUEST_PARAMETER_VIZ_URL] : null; } $visualization['defaultVisualization'] = array('Url' => $vizUrl ? $vizUrl : VISUALIZATION_DEFAULT); if (!$vizUrl) { $this->visualizationSet = false; } } $this->visualization = $visualization; }
public function testDataManger() { $this->assertNull($this->object->getData('x')); $this->assertEquals(1, $this->object->getData('x', 1)); $this->object->setData('x', 2); $this->assertEquals(2, $this->object->getData('x')); $this->assertEquals(2, $this->object->getData('x', 1)); $this->object->removeData('x'); $this->assertNull($this->object->getData('x')); $this->object->setData('y', 'hello'); $this->object->removeData('Y'); $this->assertEquals('hello', $this->object->getData('y')); $this->assertFalse($this->object->isLogged()); $this->object->setData('_logged', true); $this->assertNull($this->object->getData('_logged')); $this->assertFalse($this->object->isLogged()); $this->object->setCurrentUser(1, 'test', array('teste'), array('a' => 1234)); $this->assertTrue($this->object->isLogged()); $this->assertNull($this->object->getData('_logged')); $this->object->removeData('_logged'); $this->assertTrue($this->object->isLogged()); $this->assertEquals(1234, $this->object->getData('a')); }
/** * Validate a request. * * @return boolean True on success */ public function validateRequest() { // In case of a missing request, throw an exception if (empty($this->request)) { ErrorHandler::error(E_ERROR, 'No request object was found for validation'); } // Validate the endpoint $service = $this->validateEndpoint(); // In case of an invalid endpoint, throw an exception if (!$service) { ErrorHandler::error(E_ERROR, 'Invalid endpoint specified'); } $this->setLocale(REQUEST_LOCALE_DEFAULT); if (Session::getData(REQUEST_PARAMETER_LOGGEDIN)) { $user = Session::getData(REQUEST_PARAMETER_USER_NAME); if (!isset($user['UserName'])) { $this->clearSession(); } $this->setParam('freshLogin', (bool) Session::getData('freshLogin')); Session::clearData('freshLogin'); } // Return the validation result return true; }
<nav> <h1>聯絡我們</h1> </nav> <?php if ($_flash_message = Session::getData('_flash_message', true)) { ?> <div class='<?php echo $posts ? 'd' : 'i'; ?> '><?php echo $_flash_message; ?> </div> <?php } ?> <div class='b1'> <aside> <p>有設計相關問題嗎?</p> <p>歡迎聯繫我們。</p> <br/> <h2>公司地址</h2> <p>235 新北市中和區興南路一段85巷43號7樓</p> <p>7F., No.43, Ln. 85, Sec. 1, Xingnan Rd., Zhonghe Dist., New Taipei City 235, Taiwan(R.O.C.)</p> <br/> <h2>聯絡電話</h2> <p>TEL 02 2941 6737</p> <p>FAX 02 2941 6737</p> <br/>
public function update() { if (!$this->has_post()) { return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。')); } $posts = OAInput::post(); $posts['content'] = OAInput::post('content', false); $cover = OAInput::file('cover'); if (!((string) $this->article->cover || $cover)) { return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => '請選擇圖片(gif、jpg、png)檔案!', 'posts' => $posts)); } if ($msg = $this->_validation_posts($posts)) { return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => $msg, 'posts' => $posts)); } if ($columns = array_intersect_key($posts, $this->article->table()->columns)) { foreach ($columns as $column => $value) { $this->article->{$column} = $value; } } $article = $this->article; $update = ArticleTag::transaction(function () use($article, $cover) { if (!$article->save()) { return false; } if ($cover && !$article->cover->put($cover)) { return false; } return true; }); if (!$update) { return redirect_message(array('admin', $this->get_class(), $this->article->id, 'edit'), array('_flash_message' => '更新失敗!', 'posts' => $posts)); } $ori_ids = column_array($article->mappings, 'article_tag_id'); if (($del_ids = array_diff($ori_ids, $posts['tag_ids'])) && ($mappings = ArticleTagMapping::find('all', array('select' => 'id, article_tag_id', 'conditions' => array('article_id = ? AND article_tag_id IN (?)', $article->id, $del_ids))))) { foreach ($mappings as $mapping) { ArticleTagMapping::transaction(function () use($mapping) { return $mapping->destroy(); }); } } if (($add_ids = array_diff($posts['tag_ids'], $ori_ids)) && ($tags = ArticleTag::find('all', array('select' => 'id', 'conditions' => array('id IN (?)', $add_ids))))) { foreach ($tags as $tag) { ArticleTagMapping::transaction(function () use($tag, $article) { return verifyCreateOrm(ArticleTagMapping::create(Array_intersect_key(array('article_tag_id' => $tag->id, 'article_id' => $article->id), ArticleTagMapping::table()->columns))); }); } } if ($article->sources) { foreach ($article->sources as $source) { ArticleSource::transaction(function () use($source) { return $source->destroy(); }); } } if ($posts['sources']) { foreach ($posts['sources'] as $i => $source) { ArticleSource::transaction(function () use($i, $source, $article) { return verifyCreateOrm(ArticleSource::create(array_intersect_key(array_merge($source, array('article_id' => $article->id, 'sort' => $i)), ArticleSource::table()->columns))); }); } } $this->_clean_cell($article); return redirect_message(($url = Session::getData('admin_articles_index_url')) ? $url : array('admin', $this->get_class()), array('_flash_message' => '更新成功!')); }
/** * The generated session code by the last login * @return string */ public function getFacebookSessionCode() { return $this->session->getData("_facebookSessionCode"); }
public function index() { $posts = Session::getData('posts', true); $this->set_title('聯絡我們' . ' - ' . Cfg::setting('site', 'site', 'title'))->add_param('_method', $this->get_class())->add_js(resource_url('resource', 'javascript', 'jquery.validate_v1.9.0', 'jquery.validate.min.js'))->add_js(resource_url('resource', 'javascript', 'jquery.validate_v1.9.0', 'jquery.validate.lang.js'))->load_view(array('posts' => $posts)); }
public function status() { $sessionValid = Session::getData(REQUEST_PARAMETER_LOGGEDIN) && Session::getData(REQUEST_PARAMETER_USER_NAME); // Return the status result return array(REQUEST_RESULT => $sessionValid); }
public function edit() { $posts = Session::getData('posts', true); return $this->add_tab('編輯作品', array('href' => base_url('admin', 'work_tags', $this->tag->id, 'works', $this->work->id, 'edit'), 'index' => 4))->set_tab_index(4)->set_subtitle('編輯作品')->load_view(array('posts' => $posts, 'tag' => $this->tag, 'work' => $this->work)); }
public function edit() { $posts = Session::getData('posts', true); return $this->add_tab('編輯Promo', array('href' => base_url('admin', $this->get_class(), $this->promo->id, 'edit'), 'index' => 3))->set_tab_index(3)->set_subtitle('編輯Promo')->load_view(array('posts' => $posts, 'promo' => $this->promo)); }
public function edit() { $posts = Session::getData('posts', true); return $this->add_tab('編輯 ' . $this->user->name . '', array('href' => base_url('admin', $this->get_class(), $this->user->id, 'edit'), 'index' => 2))->set_tab_index(2)->set_subtitle('編輯 ' . $this->user->name . '')->load_view(array('posts' => $posts, 'user' => $this->user)); }
public function edit() { $posts = Session::getData('posts', true); return $this->add_tab('編輯類別', array('href' => base_url('admin', $this->get_class(), 'edit', $this->tag->id), 'index' => 3))->set_tab_index(3)->set_subtitle('編輯文章類別')->load_view(array('posts' => $posts, 'tag' => $this->tag)); }
public function update() { if (!$this->has_post()) { return redirect_message(array('admin', $this->get_class(), $this->work->id, 'edit'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。')); } $posts = OAInput::post(); $cover = OAInput::file('cover'); if (!((string) $this->work->cover || $cover)) { return redirect_message(array('admin', $this->get_class(), $this->work->id, 'edit'), array('_flash_message' => '請選擇圖片(gif、jpg、png)檔案!', 'posts' => $posts)); } if ($msg = $this->_validation_posts($posts)) { return redirect_message(array('admin', $this->get_class(), $this->work->id, 'edit'), array('_flash_message' => $msg, 'posts' => $posts)); } if ($columns = array_intersect_key($posts, $this->work->table()->columns)) { foreach ($columns as $column => $value) { $this->work->{$column} = $value; } } $work = $this->work; $update = WorkTag::transaction(function () use($work, $cover) { if (!$work->save()) { return false; } if ($cover && !$work->cover->put($cover)) { return false; } return true; }); if (!$update) { return redirect_message(array('admin', $this->get_class(), $this->work->id, 'edit'), array('_flash_message' => '更新失敗!', 'posts' => $posts)); } if (($del_ids = array_diff(column_array($work->pictures, 'id'), $posts['pic_ids'])) && ($pictures = WorkPicture::find('all', array('select' => 'id, name', 'conditions' => array('id IN (?)', $del_ids))))) { foreach ($pictures as $picture) { WorkPicture::transaction(function () use($picture) { return $picture->destroy(); }); } } if ($pictures = OAInput::file('pictures[]')) { foreach ($pictures as $picture) { WorkPicture::transaction(function () use($picture, $work) { return verifyCreateOrm($pic = WorkPicture::create(array_intersect_key(array_merge($picture, array('work_id' => $work->id)), WorkPicture::table()->columns))) && $pic->name->put($picture); }); } } $ori_ids = column_array($work->mappings, 'work_tag_id'); if (($del_ids = array_diff($ori_ids, $posts['tag_ids'])) && ($mappings = WorkTagMapping::find('all', array('select' => 'id, work_tag_id', 'conditions' => array('work_id = ? AND work_tag_id IN (?)', $work->id, $del_ids))))) { foreach ($mappings as $mapping) { WorkTagMapping::transaction(function () use($mapping) { return $mapping->destroy(); }); } } if (($add_ids = array_diff($posts['tag_ids'], $ori_ids)) && ($tags = WorkTag::find('all', array('select' => 'id', 'conditions' => array('id IN (?)', $add_ids))))) { foreach ($tags as $tag) { WorkTagMapping::transaction(function () use($tag, $work) { return verifyCreateOrm(WorkTagMapping::create(array_intersect_key(array('work_tag_id' => $tag->id, 'work_id' => $work->id), WorkTagMapping::table()->columns))); }); } } $clean_blocks = WorkBlock::transaction(function () use($work) { foreach ($work->blocks as $block) { if (!$block->destroy()) { return false; } } return true; }); if ($blocks = $posts['blocks']) { foreach ($blocks as $block) { if (!($b = null) && WorkBlock::transaction(function () use($block, $work, &$b) { return verifyCreateOrm($b = WorkBlock::create(array_intersect_key(array_merge($block, array('work_id' => $work->id)), WorkBlock::table()->columns))); })) { if (($items = $block['items']) && $b) { foreach ($items as $item) { WorkBlockItem::transaction(function () use($item, $b) { return verifyCreateOrm(WorkBlockItem::create(array_intersect_key(array_merge($item, array('work_block_id' => $b->id)), WorkBlockItem::table()->columns))); }); } } } } } $this->_clean_cell($work); return redirect_message(($url = Session::getData('admin_works_index_url')) ? $url : array('admin', $this->get_class()), array('_flash_message' => '更新成功!')); }
<?php // User related variables $loggedIn = Session::getData(REQUEST_PARAMETER_LOGGEDIN); $user = Session::getData(REQUEST_PARAMETER_USER_NAME); // Map/data parameters $x = $this->getParam(REQUEST_PARAMETER_X); $y = $this->getParam(REQUEST_PARAMETER_Y); $xyPresent = is_numeric($x) && is_numeric($y); $zoom = $this->getParam(REQUEST_PARAMETER_ZOOM); ?> <script> var visualization, map, mapLayers, mapLayer, propositionLayer, updateScheduler; $(document).ready(function() { $('.noSelect').attr('unselectable', 'on'); $('input.select').click(function() { this.select(); }); // Content var options = {}; var x = <?php if ($xyPresent) { echo $x; } else { ?> $.localStorage.getItem('<?php echo REQUEST_PARAMETER_X; ?> ')<?php