public function valueChanged(Element $element, $params) { // do nothing until the model is assigned (bound) if (!$this->form->modelAssigned()) { return; } $this->form->updateModel($element->name, $element->val()); // if value on the model has been transformed in some way, assign it back to element $modelValue = $this->form->getModel()->{$element->name}; if ($modelValue != $element->val()) { $element->val($modelValue); } }
/** * Save a new or existing album * * @static * @param Form $form * @return mixed */ public static function SaveAlbum(Form $form) { /** @var GalleryAlbumModel $model */ $model = $form->getModel('model'); /** @var $page PageModel */ $page = $form->getModel('page'); $page->set('fuzzy', 1); if ($page->get('rewriteurl') == '/' || $page->get('rewriteurl') == '') { Core::SetMessage('Galleries cannot be installed on the root of your site! Please change the URL to something other than "/".', 'error'); return false; } // Update the model cache data $model->set('title', $page->get('title')); //var_dump($model); die(); $model->save(); // Make sure the directory exists. $dir = \Core\Filestore\Factory::Directory($model->getFullUploadDirectory()); $dir->mkdir(); // w00t return $page->getResolvedURL(); }
/** * @param Form $form * @return false|string */ public static function SaveBlacklistIp(Form $form) { try { $ban = $form->getModel('model'); // First thing... check and make sure that this directive won't block out the current user! $longip = ip2long(REMOTE_IP); for ($i = 32; $i > 0; $i--) { $mask = ~((1 << 32 - $i) - 1); $join = long2ip($longip & $mask) . '/' . $i; if ($join == $ban->get('ip_addr')) { \Core\set_message('Corwardly refusing to ban an IP range that will blacklist your current connection!', 'error'); return false; } } // The expires value will probably come in as a date string :/ if ($ban->get('expires')) { $date = new CoreDateTime($ban->get('expires')); $ban->set('expires', $date->getFormatted('U', Time::TIMEZONE_GMT)); } $ban->save(); \Core\set_message('Banned IP range ' . $ban->get('ip_addr'), 'success'); return 'back'; } catch (Exception $e) { \Core\set_message($e->getMessage()); return false; } }
<?php require_once 'Form.php'; require_once 'FormValidator.php'; require_once 'Validators/NotBlank.php'; require_once 'Validators/Length.php'; require_once 'Validators/InList.php'; require_once 'Validators/Numeric.php'; $f = new Form('test', ['submit' => ['type' => 'submit', 'value' => 'Submit'], 'email' => ['validators' => [new NotBlank()], 'attr' => ['style' => 'border: 2px solid black', 'class' => 'no-class']], 'collection' => ['collection' => true, 'validators' => [new NotBlank()]]]); if ($f->validate()) { var_dump($f->getModel()); } echo $f->render();
public static function _SaveLicense(Form $form) { try { $model = $form->getModel(); $msg = $model->exists() ? 'Updated' : 'Created'; $model->save(); } catch (ModelValidationException $e) { Core::SetMessage($e->getMessage(), 'error'); return false; } catch (Exception $e) { \Core\ErrorManagement\exception_handler($e); Core::SetMessage($e->getMessage(), 'error'); return false; } Core::SetMessage($msg . ' license successfully!', 'success'); return '/packagerepositorylicense/admin'; }
public static function _SaveHandler(Form $form) { // Save the model $m = $form->getModel(); $m->save(); // Save the widget too $widget = $m->getLink('Widget'); $widget->set('title', $m->get('name')); $widget->set('editurl', '/navigation/edit/' . $m->get('id')); $widget->set('deleteurl', '/navigation/delete/' . $m->get('id')); $widget->save(); // Save all the entries $counter = 0; if (!isset($_POST['entries'])) { $_POST['entries'] = array(); } foreach ($_POST['entries'] as $id => $dat) { // New entries get an incremented counter and a new model. if (strpos($id, 'new') !== false) { ++$counter; $entry = new NavigationEntryModel(); } elseif (strpos($id, 'del-') !== false) { $entry = new NavigationEntryModel(substr($id, 4)); $entry->delete(); continue; } else { ++$counter; $entry = new NavigationEntryModel($id); } // Set the weight, based on the counter... $entry->set('weight', $counter); // Make sure it links up to the right navigation... $entry->set('navigationid', $m->get('id')); // Set the correct parent... $entry->set('parentid', $dat['parent']); // And the data from the regular form... $entry->set('type', $dat['type']); $entry->set('baseurl', $dat['url']); $entry->set('title', $dat['title']); $entry->set('target', $dat['target']); $entry->save(); // I need to update the link of any other element with this as the parent. if (strpos($id, 'new') !== false) { foreach ($_POST['entries'] as $sk => $sdat) { if ($sdat['parent'] == $id) { $_POST['entries'][$sk]['parent'] = $entry->get('id'); } } } } \Core\set_message('Updated/Created navigation successfully!', 'success'); return '/widget/admin'; }
public static function _SaveRepo(Form $form) { try{ $model = $form->getModel(); $model->save(); } catch(Exception $e){ \Core\set_message($e->getMessage(), 'error'); return false; } \Core\set_message('Updated repository successfully', 'success'); return '/updater/repos'; }
/** * Save just the gallery listing page itself. This doesn't actually have any administrable data * associated to it, other than the page. * * @static * @param Form $form */ public static function UpdateListingSave(Form $form) { $model = $form->getModel(); $model->save(); // w00t return $model->getResolvedURL(); }
public static function _UpdateFormHandler(Form $form){ try{ /** @var UserGroupModel $model */ $model = $form->getModel(); if(\Core\user()->checkAccess('p:/user/permissions/manage')){ // hehe... this is kind of a hack that works. // it's a hack because "getElement" returns only 1 element, but it works // because all those elements share the same POST name. // As such, the value from all permission[] checkboxes actually get transposed to all // form elements with that same base name. $model->setPermissions($form->getElement('permissions[]')->get('value')); } if($model->get('context') != ''){ // Non-global context groups can never be default! $model->set('default', 0); } $model->save(); } catch(ModelValidationException $e){ \Core\set_message($e->getMessage(), 'error'); return false; } catch(Exception $e){ \Core\set_message($e->getMessage(), 'error'); return false; } return '/usergroupadmin'; }
public static function _SaveEditorHandler(Form $form) { $newmodel = $form->getModel(); $file = $form->getElement('file')->get('value'); $activefile = $form->getElement('filetype')->get('value'); // The inbound file types depends on how to read the file. switch ($activefile) { case 'template': $filename = \Core\Templates\Template::ResolveFile($file); $customfilename = ROOT_PDIR . 'themes/custom/' . $file; break; case 'file': $filename = $file; // It'll get transposed. $customfilename = ROOT_PDIR . 'themes/custom/' . $file; break; default: \Core\set_message('Unsupported file type: ' . $activefile, 'error'); return false; } $customfh = \Core\Filestore\Factory::File($customfilename); if ($customfh->exists()) { // If the custom one exists... this will be the source file too! $sourcefh = $customfh; } else { $sourcefh = \Core\Filestore\Factory::File($filename); } // Check and see if they're the same, ie: no change. I don't want to create a bunch of moot revisions. if ($newmodel->get('content') == $sourcefh->getContents()) { \Core\set_message('No changes performed.', 'info'); return '/theme'; } // Before I overwrite this file, check and see if the original has been snapshot first! $c = ThemeTemplateChangeModel::Count(['filename = ' . $file]); if (!$c) { $original = new ThemeTemplateChangeModel(); $original->setFromArray(['comment' => 'Original File', 'filename' => $file, 'content' => $sourcefh->getContents(), 'content_md5' => $sourcefh->getHash(), 'updated' => $sourcefh->getMTime()]); $original->save(); } // All destination files get written to the custom directory! $customfh->putContents($newmodel->get('content')); $hash = $customfh->getHash(); /* // What happens now is based on the type of the inbound file. switch($activefile){ case 'skin': // Just replace the contents of that file. $fh->putContents($newmodel->get('content')); $hash = $fh->getHash(); break; case 'template': // This gets written into the current theme directory. $themefh = \Core\Filestore\Factory::File(ROOT_PDIR . 'themes/' . ConfigHandler::Get('/theme/selected') . '/' . $file); $themefh->putContents($newmodel->get('content')); $hash = $themefh->getHash(); break; case 'style': case 'file': // This gets written into the current theme directory. $themefh = \Core\Filestore\Factory::File(ROOT_PDIR . 'themes/' . ConfigHandler::Get('/theme/selected') . '/' . $file); $themefh->putContents($newmodel->get('content')); $hash = $themefh->getHash(); // This is required to get assets updated to the CDN correctly. $theme = ThemeHandler::GetTheme(); $hash = $themefh->getHash(); $theme->addAssetFile(array('file' => $file, 'md5' => $hash)); $theme->save(); $theme->reinstall(); default: } */ // Make a record of this change too! $change = new ThemeTemplateChangeModel(); $change->setFromArray(['comment' => $newmodel->get('comment'), 'filename' => $file, 'content' => $newmodel->get('content'), 'content_md5' => $hash]); $change->save(); if ($activefile == 'file') { // Reinstall all assets too! foreach (Core::GetComponents() as $component) { $component->reinstall(); } // And the current theme. ThemeHandler::GetTheme(ConfigHandler::Get('/theme/selected'))->reinstall(); } \Core\set_message('Updated file successfully', 'success'); return '/theme'; }
public static function _InstanceHandler(Form $form){ $form->getModel()->save(); return 'back'; }
public static function _SaveHandler(Form $form) { /** @var $model ContentModel */ $model = $form->getModel('model'); /** @var $page PageModel Page object for this model, already linked up! */ $page = $form->getModel('page'); $isnew = $model->isnew(); // The content nickname is derived from the page title. $model->set('nickname', $page->get('title')); if ($page->exists() && $page->changed('site')) { $model->set('site', $page->get('site')); } $model->save(); $page->set('editurl', '/content/edit/' . $model->get('id')); $page->set('deleteurl', '/content/delete/' . $model->get('id')); $page->set('component', 'content'); $page->save(); // Clear the page cache $page->purgePageCache(); // w00t $msg = $isnew ? 'Added' : 'Updated'; $link = \Core\resolve_link($page->get('baseurl')); \Core\set_message('<a href="' . $link . '">' . $msg . ' page successfully!</a>', 'success'); return 'back'; }
/** * Save handler for the index edit form. * * This form just manages the page data for the /blog listing. * @param Form $form * * @return bool|mixed|null */ public static function BlogIndexFormHandler(Form $form) { try { /** @var PageModel $page */ $page = $form->getModel('page'); $page->save(); // Clear the page cache $page->purgePageCache(); Core::SetMessage('Updated Listing Information', 'success'); return 'back'; } catch (Exception $e) { \Core\ErrorManagement\exception_handler($e); Core::SetMessage($e->getMessage(), 'error'); return false; } }
/** * Save new and existing listings. * * @static * * @param Form $form * * @return mixed */ public static function _SaveHandler(Form $form) { $model = $form->getModel('page'); $exists = $model->exists(); $model->save(); \Core\set_message('t:MESSAGE_SUCCESS_' . ($exists ? 'UPDATED_MARKDOWNBROWSER_PAGE' : 'REGISTERED_MARKDOWNBROWSER_PAGE')); // w00t return $model->getResolvedURL(); }