public function executeSaveFile(dmWebRequest $request) { // modify existing media if ($mediaId = dmArray::get($request->getParameter('dm_admin_media_form'), 'id')) { $this->forward404Unless($media = dmDb::table('DmMedia')->find($mediaId)); $form = new DmAdminMediaForm($media); } else { $media = null; $this->forward404Unless($folder = dmDb::table('DmMediaFolder')->find($request->getParameter('folder_id'))); if (!$folder->isWritable()) { $this->getUser()->logAlert($this->getI18n()->__('Folder %1% is not writable', array('%1%' => $folder->fullPath))); } $form = new DmAdminMediaForm(); $form->setDefault('dm_media_folder_id', $folder->id); } if ($request->isMethod('post') && $form->bindAndValid($request)) { $redirect = $form->getValue('file') || $media->dm_media_folder_id != $form->getValue('dm_media_folder_id'); $media = $form->save(); if ($redirect) { $this->getUser()->setFlash('dm_media_open', $media->id, false); return $this->renderText($this->getRouting()->getMediaUrl(dmDb::table('DmMediaFolder')->find($media->dm_media_folder_id))); } } $action = $media ? 'dmMediaLibrary/saveFile' : 'dmMediaLibrary/saveFile?folder_id=' . $folder->id; return $this->renderText($form->render('.dm_form.list.little action="' . $action . '"')); }
/** * Allows the upload of multiple files * * @param sfWebRequest $request */ public function executeNewMultipleFile(dmWebRequest $request) { // Retrived the folder by folder_id or by object in case of usage in dmMedia/gallery module if ($request->hasParameter('folder_id')) { $folderId = $request->getParameter('folder_id'); } else { $objectModel = $request->getParameter('model'); $objectPk = $request->getParameter('pk'); $object = dmDb::table($objectModel)->find($objectPk); $folderId = $object->getDmMediaFolder()->getId(); } $this->forward404Unless($folder = dmDb::table('DmMediaFolder')->find($folderId)); if (!$folder->isWritable()) { $this->getUser()->logAlert($this->getI18n()->__('Folder %1% is not writable', array('%1%' => $folder->fullPath))); } $form = new dmMediaUploadifyForm(); $form->setDefault('dm_media_folder_id', $folder->id); if ($request->isMethod('post') && $form->bindAndValid($request)) { $media = $form->save(); if (isset($object)) { $object->addMedia($media); // In dmMedia/gallery usage, we also need to associate with the object } return $this->renderText('success'); } $action = '+/dmMediaUploadifyerAdmin/newMultipleFile?' . (isset($object) ? "&model={$objectModel}&pk={$objectPk}" : 'folder_id=' . $folder->id); return $this->renderAsync(array('html' => $form->render('.dm_form.list.little action="' . $action . '"'), 'css' => $form->getStylesheets(), 'js' => $form->getJavascripts())); }
protected function getGalleryRecord(dmWebRequest $request) { $this->forward404Unless($record = dmDb::table($request->getParameter('model'))->find($request->getParameter('pk')), 'Record not found'); $this->forward404Unless($module = $record->getDmModule(), 'Module not found'); $this->forwardSecureUnless($this->getUser()->canAccessToModule($module)); if (!$record->getTable()->hasTemplate('DmGallery')) { throw new dmException($record . ' should act as DmGallery'); } return $record; }
public function executeSaveFile(dmWebRequest $request) { try { // disable warnings because they break json response @$this->getService('code_editor')->saveFile($request->getParameter('file'), $request->getParameter('code')); } catch (Exception $e) { return $this->renderJson(array('type' => 'error', 'message' => 'Save failed: ' . $e->getMessage())); } $this->getService('cache_cleaner')->clearTemplate(); return $this->renderJson(array('type' => 'ok', 'message' => $this->getI18n()->__('Your modifications have been saved'))); }
public function executeRevert(dmWebRequest $request) { $model = $request->getParameter('model'); $pk = $request->getParameter('pk'); $version = $request->getParameter('version'); $this->forward404Unless($record = dmDb::table($model)->find($pk)); $record->revert($version); $record->save(); $this->getUser()->logInfo($this->getI18n()->__('%1% has been reverted to version %2%', array('%1%' => $record->__toString(), '%2%' => $version))); return $this->redirectBack(); }
public function executeToggleBoolean(dmWebRequest $request) { $this->forward404Unless($page = dmDb::table('DmPage')->find($request->getParameter('page_id'))); $field = $request->getParameter('field'); if ('is_active' === $field) { $page->setIsActiveManually(!$page->get($field)); } else { $page->set($field, !$page->get($field)); } $page->save(); return $this->renderText($page->{$field} ? '1' : '0'); }
public function executeLoadMediaFolder(dmWebRequest $request) { $this->folder = null; if ($request->getParameter('folder_id')) { $this->folder = dmDb::table('DmMediaFolder')->find($request->getParameter('folder_id')); } if (!$this->folder) { $this->forward404Unless($this->folder = dmDb::table('DmMediaFolder')->checkRoot()); } $this->folder->sync(); $this->getUser()->setAttribute('dm_media_browser_folder_id', $this->folder->get('id')); return $this->renderPartial('mediaBarInner'); }
public function executeModuleSpace(dmWebRequest $request) { $this->forward404Unless($this->type = $this->getModuleTypeBySlug($request->getParameter('moduleTypeName')), sprintf('%s is not a module type', $request->getParameter('moduleTypeName'))); $slug = $request->getParameter('moduleSpaceName'); foreach ($this->type->getSpaces() as $space) { if (dmString::slugify($space->getPublicName()) == $slug) { $this->space = $space; break; } } $this->forward404Unless(isset($this->space), sprintf('%s is not a module space in %s type', $request->getParameter('moduleTypeName'), $request->getParameter('moduleTypeName'))); $this->menu = $this->getService('admin_module_space_menu')->build($this->space); $this->context->getEventDispatcher()->connect('dm.bread_crumb.filter_links', array($this, 'listenToBreadCrumbFilterLinksEvent')); }
public function executeFormWidget(dmWebRequest $request) { $form = new SnippetCommentForm(); if ($request->isMethod('post')) { $captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field')); $form->bind(array_merge($request->getParameter($form->getName()), array('captcha' => $captcha))); if ($form->isValid()) { $form->save(); $this->getUser()->setFlash('form_saved', true); $this->redirectBack(); } } $this->forms['SnippetComment'] = $form; }
public function executeMove(dmWebRequest $request) { $this->forward404Unless($module = $this->context->getModuleManager()->getModuleOrNull($request->getParameter('dm_module'))); $this->forward404Unless($module instanceof dmProjectModule && $module->getTable() instanceof dmDoctrineTable && $module->getTable()->isNestedSet()); $this->forward404Unless($model = $module->getTable()->find($request->getParameter('model'))); if ($nextToModel = $module->getTable()->find($request->getParameter('previous'))) { $model->Node->moveAsNextSiblingOf($nextToModel); } elseif ($inModel = $module->getTable()->find($request->getParameter('to'))) { $model->Node->moveAsFirstChildOf($inModel); } else { $this->forward404('Bad operation'); } return $this->renderText('ok'); }
public function executeShowWidget(dmWebRequest $request) { $form = new PluginCommentForm(); if ($request->isMethod('post') && ($data = $request->getParameter($form->getName()))) { if ($form->isCaptchaEnabled()) { $data = array_merge($data, array('captcha' => array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field')))); } $form->bind($data); if ($form->isValid()) { $form->save(); $this->getUser()->setFlash('form_saved', true); $this->redirectBack(); } } $this->forms['PluginComment'] = $form; }
public function executeEdit(dmWebRequest $request) { $this->forward404Unless($this->autoSeo = dmDb::table('DmAutoSeo')->find($request->getParameter('pk'))); if (!$this->autoSeo->getTargetDmModule() instanceof dmProjectModule) { throw new dmException($this->autoSeo->getTargetDmModule() . ' is not a project module'); } $this->form = new DmAutoSeoForm($this->autoSeo); if ($request->isMethod('post')) { $this->form->setSeoSynchronizer($this->getService('seo_synchronizer')); if ($this->form->bindAndValid($request)) { if ($request->getParameter('save')) { $this->form->save(); $this->getUser()->logInfo('The item was updated successfully.'); return $this->redirectBack(); } else { $tryMode = true; } } } $this->previewRules = array(); foreach ($this->form->getRules() as $ruleKey) { $this->previewRules[$ruleKey] = isset($tryMode) ? $this->form->getValue($ruleKey) : $this->form->getDefault($ruleKey); } $this->dispatcher->notify(new sfEvent($this, 'admin.edit_object', array('object' => $this->autoSeo))); $this->autoSeos = $this->getDmAutoSeos(); }
/** * Handle dmUser/form form validation and creates the user account, then authenticates the user */ public function executeFormWidget(dmWebRequest $request) { $form = new DmUserForm(); if ($request->isMethod('post') && $request->hasParameter($form->getName())) { $data = $request->getParameter($form->getName()); if ($form->isCaptchaEnabled()) { $data = array_merge($data, array('captcha' => array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field')))); } $form->bind($data, $request->getFiles($form->getName())); if ($form->isValid()) { $user = $form->save(); $this->getUser()->signin($user); $this->redirectRegisteredUser($request); } } $this->forms['DmUser'] = $form; }
public function executeInit(dmWebRequest $request) { $this->forward404Unless($branch = dmDb::table('Branch')->findOneById($request->getParameter('pk'))); $this->forward404Unless($fromBranch = dmDb::table('Branch')->findOneById($request->getParameter('from'))); $branch->Docs->delete(); foreach ($fromBranch->Docs as $doc) { $newDoc = dmDb::table('Doc')->create(array('branch_id' => $branch->id, 'name' => $doc->name, 'type' => $doc->type, 'resume' => $doc->resume, 'is_active' => $doc->is_active))->saveGet(); $newDoc->position = $doc->position + 1000; $newDoc->save(); foreach ($doc->Pages as $docPage) { $newDocPage = dmDb::table('DocPage')->create(array('doc_id' => $newDoc->id, 'name' => $docPage->name, 'resume' => $docPage->resume, 'is_active' => $docPage->is_active, 'is_done' => $docPage->is_done, 'position' => $docPage->position + 1000))->saveGet(); $newDocPage->position = $docPage->position + 1000; $newDocPage->setTags($docPage->getTagsString())->save(); } } $this->redirectBack(); }
public function executeDelete_from_cart(dmWebRequest $request) { if ($this->hasRequestParameter('id')) { $shopping_cart = $this->getUser()->getShoppingCart(); $shopping_cart->deleteItem('Product', $request->getParameter('id')); } $this->redirectBack(); }
public function executeFormWidget(dmWebRequest $request) { $form = new DmContactForm(); if ($request->hasParameter($form->getName())) { $data = $request->getParameter($form->getName()); if ($form->isCaptchaEnabled()) { $data = array_merge($data, array('captcha' => array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field')))); } $form->bind($data, $request->getFiles($form->getName())); if ($form->isValid()) { $form->save(); $this->getUser()->setFlash('contact_form_valid', true); $this->getService('dispatcher')->notify(new sfEvent($this, 'dm_contact.saved', array('contact' => $form->getObject()))); $this->redirectBack(); } } $this->forms['DmContact'] = $form; }
public function executeCurrentVersion(dmWebRequest $request) { if ($branch = $request->getParameter('branch')) { $version = dmDb::pdo('SELECT v.number FROM version v INNER JOIN branch b ON v.branch_id = b.id AND b.number = ? WHERE v.is_active = ? ORDER BY v.position ASC LIMIT 1', array(str_replace(array('_', '-'), '.', $branch), true))->fetchColumn(); } else { $version = dmDb::pdo('SELECT v.number FROM version v WHERE v.is_active = ? ORDER BY v.position ASC LIMIT 1', array(true))->fetchColumn(); } return $this->renderText($version); }
public function executeDelete(dmWebRequest $request) { $this->forward404Unless($page = dmDb::table('DmPage')->find($request->getParameter('id')), 'no current DmPage'); $this->forward404If($page->getNode()->isRoot(), 'Can not delete root page'); $this->forward404If($page->hasRecord() && $page->getRecord(), 'Can not delete record page. Please delete record instead.'); $redirectUrl = $this->getHelper()->link($page->getNode()->getParent())->getHref(); $page->getNode()->delete(); return $this->redirect($redirectUrl); }
public function executeSave(dmWebRequest $request) { $file = dmProject::rootify($request->getParameter('file')); $this->forward404Unless(file_exists($file), $file . ' does not exists'); try { @$this->getService('file_backup')->save($file); } catch (dmException $e) { return $this->renderJson(array('type' => 'error', 'message' => 'backup failed : ' . $e->getMessage())); } @file_put_contents($file, $request->getParameter('code')); if (dmOs::getFileExtension($file, false) == 'css') { $return = array('type' => 'css', 'path' => $this->getHelper()->getStylesheetWebPath(dmOs::getFileWithoutExtension($file))); } else { $this->getService('cache_cleaner')->clearTemplate(); $return = array('type' => 'php', 'widgets' => $this->getWidgetInnersForFile($file)); } $return['message'] = $this->getI18n()->__('Your modifications have been saved'); return $this->renderJson($return); }
public function executeSignin(dmWebRequest $request) { if ($this->getUser()->isAuthenticated()) { return $this->redirect('@homepage'); } $this->setLayout(realpath(dirname(__FILE__) . '/..') . '/templates/layout'); if ($request->getParameter('skip_browser_detection')) { $this->getService('browser_check')->markAsChecked(); } elseif (!$this->getService('browser_check')->check()) { return 'Browser'; } $this->form = new DmSigninAdminForm(); if ($request->isMethod('post')) { if ($request->getReferer() != '') { if (!strpos($request->getReferer(), $request->getHost(), 0) > -1) { $this->getResponse()->setStatusCode(403); return; } } else { $this->getResponse()->setStatusCode(403); return; } $this->form->bindRequest($request); if ($this->form->isValid()) { $this->getUser()->signin($this->form->getValue('user'), $this->form->getValue('remember')); if ($this->getUser()->can('admin')) { $redirectUrl = $this->getUser()->getReferer($request->getReferer()); $this->redirect($redirectUrl ? $redirectUrl : '@homepage'); } else { try { $this->redirect($this->getService('script_name_resolver')->get('front')); } catch (dmException $e) { // user can't go in admin, and front script_name can't be found. $this->redirect('@homepage'); } } } } else { if ($request->isXmlHttpRequest()) { $this->getResponse()->setHeaderOnly(true); $this->getResponse()->setStatusCode(401); return sfView::NONE; } // if we have been forwarded, then the referer is the current URL // if not, this is the referer of the current request $this->getUser()->setReferer($this->getContext()->getActionStack()->getSize() > 1 ? $request->getUri() : $request->getReferer()); $module = sfConfig::get('sf_login_module'); if ($this->getModuleName() != $module) { return $this->redirect($module . '/' . sfConfig::get('sf_login_action')); } $this->getResponse()->setStatusCode(401); } }
/** * executes the Guestbook form * * @param dmWebRequest $request * */ public function executeFormWidget(dmWebRequest $request) { $form = $this->forms['AlGuestbook']; if ($request->hasParameter($form->getName())) { $data = $request->getParameter($form->getName()); /* recaptcha field */ if ($form->isCaptchaEnabled()) { $data = array_merge($data, array('captcha' => array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'tecaptcha_response_field' => $request->getParameter('recaptcha_response_field')))); } $form->bind($data, $request->getFiles($form->getName())); /* if the form is Valid -> save */ if ($form->isValid()) { $form->save(); /* confirmations message */ $this->getUser()->setFlash('guestbook_form_valid', true); /* set new al_guestbook.saved Event */ $this->getService('dispatcher')->notify(new sfEvent($this, 'al_guestbook.saved', array('guestbook' => $form->getObject()))); $this->redirectBack(); } } }
public function executeRefresh(dmWebRequest $request) { $data = array(); $nbEntries = array('request' => 8, 'event' => 8, 'static' => 8); foreach (array('static', 'request', 'event') as $logKey) { $log = $this->getService($logKey . '_log'); $view = $this->getServiceContainer()->setParameter('log_view.class', get_class($log) . 'ViewLittle')->setParameter('log_view.log', $log)->getService('log_view')->setMax($nbEntries[$logKey]); $hash = $view->getHash(); if ($hash != $request->getParameter($logKey[0] . 'h')) { $data[$logKey] = array('hash' => $hash, 'html' => $view->renderBody($nbEntries)); } } return $this->renderJson($data); }
public function executeDownload(dmWebRequest $request) { $this->forward404Unless($versionNumber = $request->getParameter('v')); $this->forward404Unless($version = dmDb::table('Version')->findOneByNumber($versionNumber)); $this->forward404Unless($package = $version->Package); $this->forward404Unless($package->exists()); $fileName = sprintf('diem-%s%s', $version->number, dmOs::getFileExtension($package->fullPath)); $this->getService('event_log')->setOption('enabled', false); $version->mapValue('disable_versioning', true); $version->downloads = $version->downloads + 1; $version->save(); $this->context->getEventDispatcher()->notify(new sfEvent($this, 'download.package', array('version' => $version->number))); return $this->download($package->fullPath, array('file_name' => $fileName)); }
/** * @param dmWebRequest $request * */ public function executeImport(dmWebRequest $request) { $form = new ContactImportForm(); if ($request->hasParameter($form->getName())) { $data = $request->getParameter($form->getName()); $form->bind($data, $request->getFiles($form->getName())); if ($form->isValid()) { //$form->save(); $this->getUser()->setFlash('contact_form_valid', true); $this->getService('dispatcher')->notify(new sfEvent($this, 'contact_import.saved', array('contact' => $form->getObject()))); $this->redirectBack(); } } $this->form = $this->forms['ContactImport']; }
/** * Handle dmUser/forgotPassword form validation and sends an email with a new password */ public function executeForgotPasswordWidget(dmWebRequest $request) { // step 1 if (!($forgotPasswordCode = $request->getParameter('_code'))) { $form = new DmForgotPasswordStep1Form(); if ($request->isMethod('post') && $request->hasParameter($form->getName())) { $data = $request->getParameter($form->getName()); if ($form->isCaptchaEnabled()) { $data = array_merge($data, array('captcha' => array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field')))); } $form->bind($data, $request->getFiles($form->getName())); if ($form->isValid()) { $user = $form->getUserByEmail($form->getValue('email')); $user->forgot_password_code = dmString::random(12); $user->save(); $this->getService('mail')->setTemplate('dm_user_forgot_password')->addValues(array('username' => $user->username, 'email' => $user->email, 'step2_url' => $this->getHelper()->link($this->getPage())->param('_code', $user->forgot_password_code)->getAbsoluteHref()))->send(); $this->getUser()->setFlash('dm_forgot_password_email_sent', $user->email); $this->redirectBack(); } } $this->forms['DmForgotPasswordStep1'] = $form; } else { $this->forward404Unless($user = dmDb::table('DmUser')->retrieveByForgotPasswordCode($forgotPasswordCode)); $form = new DmForgotPasswordStep2Form($user); if ($request->isMethod('post') && $request->hasParameter($form->getName())) { if ($form->bindAndValid($request)) { $user->password = $form->getValue('password'); $user->forgot_password_code = null; $user->save(); $this->getUser()->setFlash('dm_forgot_password_changed', true); $this->redirectBack(); } } $this->forms['DmForgotPasswordStep2'] = $form; } }
/** * Handle dmUser/form form validation and creates the user account, then authenticates the user */ public function executeFormWidget(dmWebRequest $request) { $form = new DmUserForm(); if ($request->isMethod('post') && $request->hasParameter($form->getName())) { $data = $request->getParameter($form->getName()); // if the form uses captcha, include the additional data if ($form->isCaptchaEnabled()) { $data = array_merge($data, array('captcha' => array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field')))); } $form->bind($data, $request->getFiles($form->getName())); if ($request->isMethod('post') && $form->bindAndValid($request)) { $form->save(); $this->getUser()->setFlash('busqueda_form_valid', true); $this->redirectBack(); } if ($form->isValid()) { $user = $form->save(); $this->getUser()->signin($user); $this->redirectRegisteredUser($request); } } // pass the form to the component $this->forms['DmUser'] = $form; }
public function executeApprove(dmWebRequest $request) { $this->forward404Unless($request->isXmlHttpRequest()); $this->topicId = $request->getParameter('topic_id'); $this->topicApproved = false; $this->topicDeleted = false; if ($request->hasParameter('approve')) { $topic = DmForumTopicTable::getInstance()->find($this->topicId); $topic->set('is_approved', true)->save(); $this->topicApproved = true; } elseif ($request->hasParameter('delete')) { $topic = DmForumTopicTable::getInstance()->find($this->topicId); $topic->delete(); $this->topicDeleted = true; } }
public function executeIndex(dmWebRequest $request) { $this->engine = $this->getService('search_engine'); $this->form = $this->getSearchForm(); if ($this->query = trim($request->getParameter('query'))) { $this->form->bind(array('query' => $this->query)); $this->pager = $this->getSearchPager($this->query); } else { $this->pager = null; } if ($this->getUser()->can('system')) { $this->shellUser = dmConfig::canSystemCall() ? exec('whoami') : 'www-data'; $this->phpCli = dmConfig::canSystemCall() ? sfToolkit::getPhpCli() : '/path/to/php'; $this->rootDir = sfConfig::get('sf_root_dir'); } }
/** * Allows the upload of multiple files * * @param sfWebRequest $request */ public function executeNewMultipleFile(dmWebRequest $request) { // create new media $media = null; $this->forward404Unless($folder = dmDb::table('DmMediaFolder')->find($request->getParameter('folder_id'))); if (!$folder->isWritable()) { $this->getUser()->logAlert($this->getI18n()->__('Folder %1% is not writable', array('%1%' => $folder->fullPath))); } $form = new dmMediaUploadifyForm(); $form->setDefault('dm_media_folder_id', $folder->id); if ($request->isMethod('post') && $form->bindAndValid($request)) { $media = $form->save(); return $this->renderText('success'); } $action = '+/dmMediaUploadifyerAdmin/newMultipleFile?folder_id=' . $folder->id; $uploadify_widget = new sfWidgetFormDmUploadify(); return $this->renderAsync(array('html' => $form->render('.dm_form.list.little action="' . $action . '"'), 'css' => $uploadify_widget->getStylesheets(), 'js' => $uploadify_widget->getJavascripts())); }
public function executeGetProcessedImageURL(dmWebRequest $request) { if (!$this->isAuthorized('media')) { return $this->forwardSecure(); } if (!($mediaId = $request->getParameter('media_id'))) { return $this->forward404(); } $media = dmDb::table('DmMedia')->findOneBy('id', $mediaId); $src = '/' . $media->getWebPath(); $width = $request->getParameter('width') ? intval($request->getParameter('width')) : null; $height = $request->getParameter('height') ? intval($request->getParameter('height')) : null; if ($width || $height) { $src = $this->getHelper()->media($media)->size($width, $height)->method($request->getParameter('method') ? $request->getParameter('method') : dmConfig::get('image_resize_method'))->getSrc(); } return $this->renderJson(array('src' => $src)); }