/** * Process the submitted "select default blog" form * This form is displayed to user when we detect that * user has more than one blog on Blogger, in which * case user is asked to pick one blog that will * be connected to this account * * * @throws \Exception if user does not have any blogs, which * is not really possible, so this would be totally unexpected */ protected function selectBlog() { if ('POST' !== Request::getRequestMethod()) { throw new \Lampcms\Exception('POST method required'); } \Lampcms\Forms\Form::validateToken($this->Registry); $a = $this->Registry->Viewer->getBloggerBlogs(); d('$a: ' . print_r($a, 1)); if (empty($a)) { throw new \Exception('No blogs found for this user'); } $selectedID = (int) substr($this->Request->get('blog'), 4); d('$selectedID: ' . $selectedID); /** * Pull the selected blog from array of user blogs * * @var unknown_type */ $aBlog = \array_splice($a, $selectedID, 1); d('$aBlog: ' . print_r($aBlog, 1)); d('a now: ' . print_r($a, 1)); /** * Now stick this blog to the * beginning of array. It will become * the first element, pushing other blogs * down in the array * User's "Connected" blog is always * the first blog in array! * */ \array_unshift($a, $aBlog[0]); d('a after unshift: ' . print_r($a, 1)); $this->Registry->Viewer->setBloggerBlogs($a); /** * Set b_bg to true which will result * in "Post to Blogger" checkbox to * be checked. User can uncheck in later */ $this->Registry->Viewer['b_bg'] = true; $this->Registry->Viewer->save(); $this->closeWindow(); }
/** * Check Request object for required params * as well as for required form token * * @return object $this */ protected function initParams() { if ($this->bRequirePost && 'POST' !== Request::getRequestMethod()) { throw new Exception('POST method required'); } $this->Request->setRequired($this->aRequired)->checkRequired(); if (true === $this->requireToken) { \Lampcms\Forms\Form::validateToken($this->Registry); } d('cp'); return $this; }
/** * Execute the shell command that * was entered in the web form * First validate the form token * * When execution of shell is done will render either a success message * or failure. * * Result is also logged * * @throws \Lampcms\TokenException if token not valid */ protected function processShell() { $command = $this->Request['command']; \Lampcms\Forms\Form::validateToken($this->Registry); d('about to run mongo shell: ' . $command); try { $res = $this->Registry->Mongo->getDb()->execute($command); d('result of execute: ' . \json_encode($res)); if (\is_array($res) && isset($res['ok']) && $res['ok'] == 1) { $this->aPageVars['body'] = '<div id="tools">@@Mongo Update complete@@</div>'; } else { e('Failed to execute mongo command. $res: ' . \json_encode($res)); $this->aPageVars['body'] = '<div id="tools">@@Mongo Update Failed@@<br>' . \print_r($res, 1) . '</div>'; } } catch (\Exception $e) { e('Failed to run mongo command: ' . $command . ' Exception: ' . \get_class($e) . ' Message: ' . $e->getMessage() . ' file: ' . $e->getFile() . ' line: ' . $e->getLine()); $this->aPageVars['body'] = '<div id="tools">@@Mongo Update Failed@@<br>' . $e->getMessage() . '</div>'; } }