/** * Update setting action called through an ajax request */ public function ajaxUpdateAction() { // Disable view & layout output $this->_disableDisplay(); // Alwasy set response type to json $this->_response->setHeader('Content-Type', 'application/json', true); // Try to get the data from the request body try { $data = Zend_Json::decode($this->_request->getRawBody(), Zend_Json::TYPE_OBJECT); } catch (Zend_Json_Exception $exception) { $this->_response->setHttpResponseCode(500); $this->_response->setBody(Zend_Json::encode(array('status' => 'error', 'message' => 'data decoding failed'))); return; } // Retrieve the setting $setting = Setting::getKey($data->settingKey, $data->component); if (null === $setting) { $this->_response->setHttpResponseCode(404); $this->_response->setBody(Zend_Json::encode(array('status' => 'error', 'message' => 'setting key/component pair not found'))); return; } // Update the setting $setting->value = $data->value; $success = $setting->trySave(); if (false === $success) { $this->_response->setHttpResponseCode(500); $this->_response->setBody(Zend_Json::encode(array('status' => 'error', 'message' => 'saving failed due to validation errors'))); return; } // Return success response $this->_response->setHttpResponseCode(200); $this->_response->setBody(Zend_Json::encode(array('status' => 'success', 'message' => 'setting saved'))); }
/** * Sends the contact request to the configured contact email address. * * @throws Exception when contact email is not configured */ public function send() { $contactEmail = Setting::getKey('address', 'contact'); if (null === $contactEmail) { throw new Exception('Contact email not configured'); } $mail = new Zend_Mail(); $mail->setSubject('Contact request')->setFrom($this->email, $this->name)->setBodyText($this->body)->addTo($contactEmail)->send(); }
/** * @return void */ public function show() { $editing = false; if (Team::isSuperAdmin()) { $editing = HTMLResponse::fromGET('edit', ''); if (!$editing) { ?> <a href="<?=HTMLResponse::getRoute()?>?edit=1"> Editar página </a> <? } else { ?> <a href="<?=HTMLResponse::getRoute()?>" onclick="return confirm('Quieres descartar los cambios?')"> Descartar y volver a la página </a> <? } ?> <div style="height: 6px"></div> <? } $content = Setting::getKey('rules_content'); if (!$editing) { ?><div class="inblock" style="margin: 0 auto; max-width: 90%; text-align: justify"> <?=$content?> </div><? } else { if (!$csrf = $_SESSION['csrf']) { $_SESSION['csrf'] = $csrf = rand(1, 1000000); } if (HTMLResponse::fromGETorPOST('csrf', '') == $csrf) { $content = HTMLResponse::fromPOST('content'); Setting::setKey('rules_content', $content); HTMLResponse::exitWithRoute(HTMLResponse::getRoute()); } $this->design->addJavaScript('//cdn.ckeditor.com/4.5.7/full/ckeditor.js'); $this->design->addJavaScript(" CKEDITOR.replace( 'editor' ) ", false); ?> <form action="<?=HTMLResponse::getRoute()?>?edit=1" method="post"> <div style="width:90%; margin: 0 auto"> <textarea name="content" id="editor"><?=htmlentities($content)?></textarea> </div> <br> <input type="hidden" name="csrf" value="<?=$csrf?>"> <button type="submit">Guardar cambios</button> </form> <? } }
public function indexAction() { $form = $this->_getForm(); if ($this->_request->isPost()) { if ($form->isValid($_POST)) { $contact = new Contact(); $contact->name = $form->name->getValue(); $contact->email = $form->email->getValue(); $contact->body = $form->body->getValue(); $contact->date = date('Y/m/d H:i:s', time()); if (Setting::getKey('contact_log', 'contact')) { $contact->save(); } $contact->send(); $this->renderScript('contact/thankyou.phtml'); return; } } $this->view->form = $form; }
protected function _createNavigation() { $items = array(); // Blog $items[] = new Fizzy_Navigation_Page_Route(array('label' => 'Blogs', 'route' => 'admin_blogs', 'pages' => array(new Fizzy_Navigation_Page_Route(array('route' => 'admin_blog', 'pages' => array(new Fizzy_Navigation_Page_Route(array('label' => 'Edit Post', 'route' => 'admin_blog_post_edit')), new Fizzy_Navigation_Page_Route(array('label' => 'Add Post', 'route' => 'admin_blog_post_add')))))))); // Comments $items[] = new Fizzy_Navigation_Page_Route(array('label' => 'Comments', 'route' => 'admin_comments', 'pages' => array(new Fizzy_Navigation_Page_Route(array('label' => 'Dashboard', 'route' => 'admin_comments')), new Fizzy_Navigation_Page_Route(array('label' => 'Thread list', 'route' => 'admin_comments_list', 'pages' => array(new Fizzy_Navigation_Page_Route(array('label' => 'Show thread', 'route' => 'admin_comments_topic'))))), new Fizzy_Navigation_Page_Route(array('label' => 'Spambox', 'route' => 'admin_comments_spambox')), new Fizzy_Navigation_Page_Route(array('route' => 'admin_comments_edit'))))); // Pages $items[] = new Fizzy_Navigation_Page_Route(array('label' => 'Pages', 'route' => 'admin_pages', 'pages' => array(new Fizzy_Navigation_Page_Route(array('route' => 'admin_pages_add')), new Fizzy_Navigation_Page_Route(array('route' => 'admin_pages_edit'))))); // Media $items[] = new Fizzy_Navigation_Page_Route(array('label' => 'Media', 'route' => 'admin_media')); // Contact $contactLogSetting = Setting::getKey('log', 'contact'); if (null !== $contactLogSetting && 1 == $contactLogSetting->value) { $items[] = new Fizzy_Navigation_Page_Route(array('label' => 'Contact', 'route' => 'admin_contact', 'pages' => array(new Fizzy_Navigation_Page_Route(array('route' => 'admin_contact_show'))))); } // Users $items[] = new Fizzy_Navigation_Page_Route(array('label' => 'Users', 'route' => 'admin_users', 'pages' => array(new Fizzy_Navigation_Page_Route(array('label' => 'Add user', 'route' => 'admin_users_add')), new Fizzy_Navigation_Page_Route(array('route' => 'admin_users_edit'))))); // Settings $items[] = new Fizzy_Navigation_Page_Route(array('label' => 'Settings', 'route' => 'admin_settings')); // Logout $items[] = new Fizzy_Navigation_Page_Route(array('label' => 'Logout', 'route' => 'admin_logout')); return new Zend_Navigation($items); }
/** * @param Setting $setting * @return void */ public function addSetting(Setting $setting) { $this->_settings[$setting->getKey()] = $setting; }