Example #1
0
 /**
  * Get the form for article creation and updating.
  *
  * @param BlogArticleModel $article
  *
  * @return Form
  */
 public static function GetArticleForm(BlogArticleModel $article)
 {
     $page = $article->getLink('Page');
     $blog = $article->getLink('Blog');
     $page->set('parenturl', $blog->get('baseurl'));
     $form = new Form();
     $form->set('callsmethod', 'BlogHelper::BlogArticleFormHandler');
     $form->addModel($page, 'page');
     $form->addModel($article, 'model');
     if (Core::IsComponentAvailable('facebook') && Core::IsLibraryAvailable('jquery')) {
         // Is this article already posted?
         if ($article->get('fb_post_id')) {
             $form->addElement('select', ['disabled' => true, 'title' => 'Post to Facebook', 'options' => ['' => 'Posted!'], 'group' => 'Publish Settings']);
         } else {
             $form->addElement('select', ['class' => 'facebook-post-to-select', 'title' => 'Post to Facebook', 'name' => 'facebook_post', 'options' => ['' => '-- Please enable javascript --'], 'group' => 'Publish Settings']);
         }
     }
     // Lock in some elements for this blog article page.
     $form->getElement('page[parenturl]')->setFromArray(array('value' => $blog->get('baseurl'), 'readonly' => 'readonly'));
     // And remove a few other elements.
     $form->removeElement('model[title]');
     return $form;
 }
 /**
  * Quick-add an IP address to the blacklist.
  */
 public function blacklistip_edit()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     $ban = new IpBlacklistModel($request->getParameter(0));
     if (!$ban->exists()) {
         return View::ERROR_NOTFOUND;
     }
     $form = new Form();
     $form->set('callsmethod', 'SecurityController::SaveBlacklistIp');
     $form->addModel($ban, 'model');
     $form->addElement('submit', ['name' => 'submit', 'value' => 'Edit Banned IP!']);
     $view->title = 'Edit Banned IP';
     $view->assign('form', $form);
 }
 public function edit()
 {
     $request = $this->getPageRequest();
     $view = $this->getView();
     $manager = \Core\user()->checkAccess('p:/package_repository/licenses/manager');
     if (!$manager) {
         return View::ERROR_ACCESSDENIED;
     }
     $model = PackageRepositoryLicenseModel::Construct($request->getParameter(0));
     if (!$model->exists()) {
         return View::ERROR_NOTFOUND;
     }
     $form = new Form();
     $form->set('callsmethod', 'PackageRepositoryLicenseController::_SaveLicense');
     $form->addModel($model);
     $form->addElement('submit', ['value' => 'Update License']);
     $view->title = 'Edit License';
     $view->assign('form', $form);
 }
 /**
  * Handles the upload of new and existing images.  Not meant to be called directly, but is used by the images page.
  */
 public function images_update()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     $albumid = $request->getParameter(0);
     $album = new GalleryAlbumModel($albumid);
     $image = new GalleryImageModel($request->getParameter('image'));
     $manager = \Core\user()->checkAccess('p:/gallery/manage_all');
     $editor = \Core\user()->checkAccess($album->get('editpermissions')) || $manager;
     $uploader = \Core\user()->checkAccess($album->get('uploadpermissions')) || $editor;
     if ($request->isAjax()) {
         // OK
         //$view->mode = View::MODE_AJAX;
         $view->mastertemplate = 'blank.tpl';
     }
     if (!$album->exists()) {
         return View::ERROR_NOTFOUND;
     }
     if (!$uploader) {
         return View::ERROR_ACCESSDENIED;
     }
     // Uploaders only can only edit their own image!
     if (!$editor && $image->get('uploaderid') != \Core\user()->get('id')) {
         return View::ERROR_ACCESSDENIED;
     }
     if ($request->isPost()) {
         // This is meant to be loaded in an iframe and rendered from there.
         $view->mode = View::MODE_NOOUTPUT;
         if (!$albumid) {
             echo '<div id="error">No album requested</div>';
             return View::ERROR_BADREQUEST;
         }
         if (!$album->exists()) {
             echo '<div id="error">Invalid album requested</div>';
             return View::ERROR_NOTFOUND;
         }
         if ($image->exists() && $image->get('albumid') != $album->get('id')) {
             echo '<div id="error">Invalid album requested</div>';
             return View::ERROR_BADREQUEST;
         }
         // Figure out the largest weight of this album.
         // Note, this is NOT the size of the images, as one or more may have been deleted after uploading.
         $last = GalleryImageModel::Find(array('albumid' => $album->get('id')), 1, 'weight DESC');
         $weight = $last ? $last->get('weight') : 0;
         // Multiple images were uploaded, (probably via one of the multi uploaders).
         // In this case, minimal data is available, but enough to save the image.
         if (isset($_POST['images']) && is_array($_POST['images'])) {
             $savecount = 0;
             foreach ($_POST['images'] as $img) {
                 // The uploader doesn't prepend the destination directory :/
                 $file = $album->getFullUploadDirectory() . $img;
                 // instead of just blindly saving this image...
                 $image = GalleryImageModel::Find(array('albumid' => $album->get('id'), 'file' => $file));
                 if ($image) {
                     continue;
                 }
                 // NO fun....
                 // Generate a moderately meaningful title
                 $title = substr($img, 0, strrpos($img, '.'));
                 $title = preg_replace('/[^a-zA-Z0-9 ]/', ' ', $title);
                 $title = trim(preg_replace('/[ ]+/', ' ', $title));
                 $title = ucwords($title);
                 $image = new GalleryImageModel();
                 $image->setFromArray(array('albumid' => $album->get('id'), 'file' => $file, 'weight' => ++$weight, 'title' => $title));
                 $image->save();
                 $savecount++;
                 // And the metadata for this element
                 $metas = new \Core\Filestore\FileMetaHelper($image->getOriginalFile());
                 $metas->setMeta('title', $title);
             }
             if ($savecount == 0) {
                 $action = 'No files uploaded';
                 $actiontype = 'info';
             } else {
                 $action = 'Added ' . $savecount . ' Files!';
                 $actiontype = 'success';
             }
             $imageid = '';
         } else {
             // This POST is only for multiple files!
             return view::ERROR_BADREQUEST;
         }
         if ($request->isAjax()) {
             // This will be rendered with jquery, so it'll be data-esque.
             echo '<div id="success">' . $action . '</div>' . '<div id="imageid">' . $imageid . '</div>';
             Core::SetMessage($action, $actiontype);
             return;
         } else {
             Core::SetMessage($action, $actiontype);
             \core\redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $album->get('rewriteurl'));
         }
     } else {
         if (!$albumid) {
             return View::ERROR_BADREQUEST;
         }
         if (!$album->exists()) {
             return View::ERROR_NOTFOUND;
         }
         if ($image->exists() && $image->get('albumid') != $album->get('id')) {
             return View::ERROR_BADREQUEST;
         }
         $file = $image->getOriginalFile();
         $meta = new \Core\Filestore\FileMetaHelper($file);
         $form = new Form();
         $form->addModel($image, 'image');
         $meta->addElementsToForm($form, 'metas');
         // If this file exists and it's not an image.... enable the preview uploader.
         if ($image->exists() && !$file->isImage()) {
             $form->switchElementType('image[previewfile]', 'file');
         }
         $form->set('callsmethod', 'GalleryController::ImagesUpdateSaveHandler');
         $form->addElement('submit', ['name' => 'submit', 'value' => t('STRING_SAVE')]);
         $view->title = 'Editing image ' . $image->get('title');
         $view->assign('image', $image);
         $view->assign('album', $album);
         $view->assign('form', $form);
         $view->assign('savetext', $image->exists() ? 'Update' : 'Upload');
     }
 }
Example #5
0
	/**
	 * Scan through a standard Model object and populate elements with the correct fields and information.
	 *
	 * @param Model $model
	 *
	 * @return Form
	 */
	public static function BuildFromModel(Model $model) {
		$f = new Form();
		$f->addModel($model);
		return $f;
	}
	/**
	 * Controller view to update any instance-specific options for a given template.
	 *
	 * Usually consists of just access permissions and display template, but more options could come in the future.
	 */
	public function instance_update(){
		$view = $this->getView();
		$request = $this->getPageRequest();

		if(!\Core\user()->checkAccess('p:/core/widgets/manage')){
			return View::ERROR_ACCESSDENIED;
		}

		$instance = WidgetInstanceModel::Construct($request->getParameter(0));
		if(!$instance->exists()){
			return View::ERROR_NOTFOUND;
		}

		$form = new Form();
		$form->set('callsmethod', 'WidgetController::_InstanceHandler');

		$form->addModel($instance);
		$form->addElement('submit', ['value' => 'Save Options']);

		$view->mastertemplate = 'admin';
		$view->addBreadcrumb('All Widgets', '/widget/admin');
		$view->title = 'Update Installed Options';
		$view->assign('form', $form);
	}
 public function create()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     if (!$this->setAccess('p:/content/manage_all')) {
         return View::ERROR_ACCESSDENIED;
     }
     $model = new ContentModel();
     $page = $model->getLink('Page');
     //$page = new PageModel('/content/view/new');
     // Allow the user to specify a parent URL to default to.
     // This is used with the "add page 'here'" option.
     if ($request->getParameter('parenturl')) {
         $page->set('parenturl', $request->getParameter('parenturl'));
     }
     if ($request->getParameter('page_template')) {
         $page->set('page_template', $request->getParameter('page_template'));
     }
     $form = new Form();
     $form->set('callsmethod', 'ContentController::_SaveHandler');
     $form->addModel($page, 'page');
     $form->addModel($model, 'model');
     // Tack on a submit button
     $form->addElement('submit', array('value' => 'Create'));
     $view->mastertemplate = 'admin';
     $view->templatename = '/pages/content/create.tpl';
     $view->title = 'New Content Page';
     $view->assignVariable('model', $model);
     $view->assignVariable('form', $form);
 }
Example #8
0
 /**
  * Update an existing blog page
  */
 public function update()
 {
     if (!$this->setAccess('p:/blog/manage_all')) {
         return View::ERROR_ACCESSDENIED;
     }
     $view = $this->getView();
     $request = $this->getPageRequest();
     $blog = new BlogModel($request->getParameter(0));
     if (!$blog->exists()) {
         return View::ERROR_NOTFOUND;
     }
     $form = new Form();
     $form->set('callsmethod', 'BlogHelper::BlogFormHandler');
     $form->addModel($blog->getLink('Page'), 'page');
     $form->addModel($blog, 'model');
     $form->addElement('submit', array('value' => 'Update'));
     // Some elements of the form need to be readonly.
     $form->getElement('model[type]')->set('disabled', true);
     $view->addBreadcrumb($blog->get('title'), $blog->get('rewriteurl'));
     $view->mastertemplate = 'admin';
     $view->title = 'Update Blog Listing';
     $view->assignVariable('form', $form);
 }
 /**
  * Add or edit an existing directory.
  *
  * @return int
  */
 public function update()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     if (!$this->setAccess('p:/content/manage_all')) {
         return View::ERROR_ACCESSDENIED;
     }
     $info = $this->_resolveInfoFromURL();
     if ($info['status'] !== 200) {
         return $info['status'];
     }
     /** @var \Core\Filestore\File $file */
     $file = $info['file'];
     /** @var PageModel $page */
     $page = $info['page'];
     $contents = $file->getContents();
     // Convert these contents from markdown to HTML.
     $processor = new \Core\MarkdownProcessor();
     $html = $processor->transform($contents);
     // Pre-populate this page with information from the rendered markdown document.
     // If this page exists, then it'll be updated and kept in sync.
     // Else, it'll still be set with what's in the document and kept in sync.
     $page->set('title', $processor->getMeta('title'));
     $page->set('body', $html);
     if (!$page->exists()) {
         $page->set('baseurl', '/markdownbrowser/view' . $info['url']);
         $page->set('rewriteurl', '/markdownbrowser/view' . $info['url']);
         $page->set('editurl', '/markdownbrowser/update' . $info['url']);
         $page->set('component', 'markdown-browser');
         $page->set('selectable', 1);
         $page->set('published', $file->getMTime());
         $page->set('updated', $file->getMTime());
         $page->set('created', $file->getMTime());
     }
     $form = new Form();
     $form->set('callsmethod', 'MarkdownBrowserController::_SaveHandler');
     $form->addModel($page, 'page');
     // Many of these elements are readonly!
     $form->getElement('page[title]')->set('readonly', true);
     $form->removeElement('page[indexable]');
     $form->removeElement('page[metas][title]');
     $form->removeElement('page[metas][image]');
     $form->removeElement('page[metas][author]');
     $form->removeElement('page[metas][keywords]');
     $form->removeElement('page[metas][description]');
     $form->removeElement('page[published_status]');
     $form->removeElement('page[published]');
     $form->removeElement('page[published_expires]');
     // Tack on a submit button
     $form->addElement('submit', ['value' => $page->exists() ? t('STRING_UPDATE') : t('STRING_REGISTER_PAGE')]);
     // Give some useful instructions on why everything on this page is disabled!
     \Core\set_message('t:MESSAGE_TUTORIAL_MARKDOWNBROWSER_REGISTER_UPDATE_PAGE_NOTICE');
     $view->templatename = '/pages/markdownbrowser/update.tpl';
     //$view->addBreadcrumb('Markdown Directory Listings', '/markdownbrowser');
     $view->title = ($page->exists() ? t('STRING_UPDATE') : t('STRING_REGISTER_PAGE')) . ' ' . $info['relative_file'];
     $view->assignVariable('page', $page);
     $view->assignVariable('form', $form);
 }