pwFoo
Members-
Posts
708 -
Joined
-
Last visited
Everything posted by pwFoo
-
Good to know! Thanks! Backend plugins (like ldap, external apis,...) could be implemented via a hook... Maybe I replace my login function with that code. Because user profiles could be build with user pages (not pw own userprofiles) the final part would be extend the own register function with additional features (email activation, password reset). At the moment I use a template (without file) with username and password fields and generate a login form via form api / template to form helper module. That works fine, but with reuse the existing module I haven't care about sanitizing input and code security, because it should be updated via PW core
-
I think I'll try it with (child) pages instead of repeater or table fields...
-
Hi, during work on some own modules (frontend content manager, frontend users) I noticed my need of a helper module. Template2Form (working title) is a module to build a form based on fields get from a page object or a template file (tmp fake page object). During build process each field could be hooked in to modify it. Also it's possible to modifiy form, submit button and form fields via function params. It's my first (basic / dev state) module I post here... If it will be useable I have to clean up and comment the code well... template2form class <?php /** * Processwire 'template2form' module * * template2form - generate form from page / template fields * * @author pwFoo * @since 2014-07-18 * * ProcessWire 2.x * Copyright (C) 2011 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com */ class Template2Form extends WireData implements Module { /** * @var object $form generated form object */ public $form; /** * @var array $option multidimensional array with options */ private $option; /** * getModuleInfo is a module required by all modules to tell ProcessWire about them * @return array */ public static function getModuleInfo() { return array( 'title' => 'Template2Form', 'summary' => 'Generate form from template fields', 'version' => '0.0.1', ); } /** * Default module and form options * @var array $defaultOptions static mutlidimensional array with default options */ public static $defaultOptions = array( 'page' => null, 'template' => null, 'prefillFormFields' => null, 'jquery' => null, 'form' => array('method' => 'post', 'action' => '', 'id' => 'login', 'name' => 'login'), 'formSubmit' => array('id' => 'submit', 'name' => 'submit', 'value' => 'Submit'), 'formFields' => null, ); public function init() { $this->addHookAfter('Template2Form::buildField', $this, 'hookingFormField', array('priority'=>20)); } /** * Set / merge module and form options * @param array $options Array with given options * @return null */ private function setOptions (array $options = null) { if($options != null && is_array($options)) { $this->option = array_replace_recursive(self::$defaultOptions, $options); // Use template instead of page if given if ($this->option['template] !== null) { $this->option['page'] = $this->fakePage($this->option['template']); } // No template or page? Use current page... elseif ($this->option['template'] === null) { $this->option['page'] = $this->page; } if ($this->option['jquery']) { $this->modules->get('JqueryCore'); } } else { $this->option = self::$defaultOptions; } } /** * Generate the form object * @param array $options Set of optional and needed settings * @return object Generated form */ public function getForm (array $options = null) { $this->setOptions($options); $this->form = $this->buildForm (); return $this->form; } /** * Generate the form object from given fields * @return object Generated form */ private function buildForm () { $form = $this->modules->get('InputfieldForm'); $form = $this->setFormAttr($form); // Get fields to build the form $fields = $this->templates->get($this->option['page']->template)->fields; foreach ($fields as $field) { $f = $this->buildField ($field); // Get Inputfield object if ($f !== NULL) $form->append($f); // Remove NULLed fields from from... } $form->append($this->addSubmitButton()); return $form; } /** * Set form attributes and return the object * @param object $form * @return object Form with added attributes */ protected function ___setFormAttr($form) { $form->id = $this->option['form']['id']; $form->name = $this->option['form']['name']; $form->action = $this->option['form']['action']; $form->method = $this->option['form']['method']; return $form; } /** * Generate Inputfield object from given field object * @param object $field Page field object * @return object */ protected function ___buildField ($field) { return $field->getInputfield($this->option['page']); } /** * Modify the current field object by hook in after buildField function * @param object $event */ protected function ___hookingFormField ($event) { $field = $event->return; $hook = $this->option['formFields'][$field->name]; // Remove selected field... if ($hook['remove'] == true) { $event->return = NULL; } // prefill form fields from page value... elseif ($this->option['prefillFormFields'] && $event->page->get($field->name)) { $hook['set']['value'] = $event->page->get($field->name); } if (!isset($hook)) return; // nothing to do with this field... // Set form field values... elseif (is_array($hook['set'])) { foreach ($hook['set'] as $key => $value) { $field->set($key, $value); } $event->return = $field; } } /** * Build the form submit button * @return object form submit Inputfield */ protected function ___addSubmitButton() { $btn = $this->modules->get('InputfieldSubmit'); $btn->attr('id', $this->option['formSubmit']['id']); $btn->attr('name', $this->option['formSubmit']['name']); $btn->attr('value', $this->option['formSubmit']['value']); return $btn; } /** * Rendering the current form * @return string Rendered form as html code */ public function ___formRender() { return $this->form->render(); } /** * Process form data if send * @return object Processed form data */ public function ___formProcess() { $submit = $this->option['formSubmit']['id']; if(!$this->input->post->$submit) return NULL; // form NOT submitted... $processedForm = $this->form->processInput($this->input->post); // form api process form values if(!$this->form->getErrors()) return $processedForm; // form processed: OK else return false; // form send with errors } /** * Make fake page and assign needed template * @param string $tpl Template to assign * @return object Generated fake page to work with */ private function fakePage($tpl) { $fakePage = new Page(); $fakePage->template = $tpl; return $fakePage; } /** * jsConfig settings needed by wysiwyg editor * @return string Basic JavaScript config */ public function ___jsConfig () { $jsConfig = $this->config->js(); $jsConfig['debug'] = $this->config->debug; $jsConfig['urls'] = array( 'root' => $this->config->urls->root, 'admin' => $this->config->urls->admin, 'modules' => $this->config->urls->modules, 'core' => $this->config->urls->core, 'files' => $this->config->urls->files, 'templates' => $this->config->urls->templates, 'adminTemplates' => $this->config->urls->adminTemplates, ); return '<script type="text/javascript">var config = ' . json_encode($jsConfig) . '</script>'; } } Usage examples $t2f = $modules->get('Template2Form'); // Remove field 'headline' and 'body' from form $hookFormFields['headline'] = array('remove' => true); $hookFormFields['body'] = array('remove' => true); // Set / Overwrite field attributes / values like you could do with form api $hookFormFields['title'] = array('set' => array('value' => 'CustomTitle...', 'type' => 'password')); $hookFormFields['summary'] = array('set' => array('value' => 'My overwritten summary...')); // Overwrite submit button attributes (default: id, name, value) $hookFormSubmit = array('value' => 'Speichern'); /* * Build the multidemensional array * page (object) or template (string) -- to build the form from * prefillFormFields -- prefill fields (for example to build a frontend edit page * jquery -- Load JqueryCore module (during getForm() call) * form -- set form attributes / values * formFields -- array to set field values / attributes, take a look at form api examples * formSubmit -- set form submit button attributes / values */ $formOptions = array('page' => $page, 'template' => null, 'prefillFormFields' => true, 'jquery' => true 'formFields' => $hookFormFields, 'formSubmit' => $hookFormSubmit); // Generate the form and set options above $t2f->getForm($formOptions); // process form and return processed form date $process = $t2f->formProcess(); if ($process === NULL) // form not sent elseif ($process === false) // form sent, but with errors elseif ($process == true) // form sent without errors // Render form... $form = $t2f->formRender(); echo '<html><head>'; // jsConfig needed by ckeditor echo $t2f->jsConfig() . "\n"; // outpunt needed scripts for inputfield modules, ... foreach ($config->scripts as $file) { echo "<script type='text/javascript' src='$file'></script>\n"; } foreach ($config->styles as $file) { echo "<link type='text/css' href='$file' rel='stylesheet' />\n"; } echo '</head><body>'; echo $form; // output form echo '</body></html>';
-
Hi, I know it. But maybe I need it more flexible to modify the database structure (add/remove fields). Are comments searchable via api?
-
Because of some tests I think about custom comments / answers solution. I should be scalable to manage a huge number of comments / posts and ideally is useable via PW API. Comments / posts belong to one PW page. Structure (example, maybe extended) pageID post belongs to content / text created by creation date How could / should it be done? Simple child pages? table field module? ?
-
Bootstrapping Processwire to my Websocket server problem
pwFoo replied to Harmster's topic in API & Templates
Hello Harmster, nice to see a websocket example here. require 'class.PHPWebSocket.php'; Is it a self written class? Or which one did you use? -
Strange... First thought I have to load the modules (InputfieldTinyMCE, CKEditor) because editor wasn't loaded with via form api created form... But now it works without a $modules->get('CKEditor'); or $modules->get('InputfieldTinyMCE'); So... take the form api care about loading such modules or not?! Or is it some kind of browser / PW cache?
-
Yes, right... I don't use bootstrap at all. But it works at desktop. Also no toolbar at mobile. Best editor (also works fine at mobile) is Froala, but it isn't free. jQuery notepad needs improvements.
-
Finished first version of my helper module. Generate a frontend form based on page template fields. Additional load inputfield modules (like ckeditor or tinymce) and prefill form fields with page field values (to build a edit form) via a hook (default loaded at the moment). Sure some bug fixes and improvements needed, but first version renders a form with page field values prefilled and ckeditor loaded. Two unfinished modules will be rewritten and based on template2form(? don't know how to call it *g*) module...
-
Fixed... Needed code <script type="text/javascript"> <?php $jsConfig = $config->js(); $jsConfig['debug'] = $config->debug; $jsConfig['urls'] = array( 'root' => $config->urls->root, 'admin' => $config->urls->admin, 'modules' => $config->urls->modules, 'core' => $config->urls->core, 'files' => $config->urls->files, 'templates' => $config->urls->templates, 'adminTemplates' => $config->urls->adminTemplates, ); ?> var config = <?php echo json_encode($jsConfig); ?>; </script>
-
Debugged and also changed to ckeditor for more tests... Both have a problem with the config variable ReferenceError: config is not defined ckeditor generates... <textarea id="Inputfield_body" class="FieldtypeTextarea InputfieldMaxWidth" name="body" rows="5">Test</textarea><script>CKEDITOR.replace('body', config.InputfieldCKEditor_body);</script> Comparable error with tinymce. So were should config.Inputfield<EDITOR> ... set?
-
Yes, head output was generated that way
-
Hello Apeisa, see summernote or jq notebook link. Toolbar appears after text selection in place. Should be better as a fixed toolbar for mobile text writing.
-
TinyMCE module loaded $modules->get('InputfieldTinyMCE'); But form fields are unstyled and without TinyMCE. scripts and styles also loaded <head> <script type="text/javascript" src="/pwProfile/wire/modules/Jquery/JqueryCore/JqueryCore.js?v=183"></script> <script type="text/javascript" src="/pwProfile/wire/modules/Jquery/JqueryUI/JqueryUI.js?v=193"></script> <script type="text/javascript" src="/pwProfile/wire/modules/Inputfield/InputfieldTinyMCE/InputfieldTinyMCE.js?v=358"></script> <script type="text/javascript" src="/pwProfile/wire/modules/Inputfield/InputfieldTinyMCE/tinymce-3.5.8/tiny_mce.js"></script> <link type="text/css" href="/pwProfile/wire/modules/Inputfield/InputfieldTinyMCE/InputfieldTinyMCE.css?v=358" rel="stylesheet" </head> TinyMCE should be initialized at InputfieldTinyMCE.js? But it's loaded before InputfieldTinyMCE/tinymce-3.5.8/tiny_mce.js? Changed it for testing but no editor loaded...
-
Froala and Redactor are similar in features, but Froala seems to be cheaper (299$, DL & license information) to integrate with PW as a module... Because I like the editor toolbar "air mode" and license cost of Froala and Redactor I'm searching for an alternative... Found Summernote. Based on bootstrap and font-awesome. But air mode doesn't work at mobile... could be a nice mobile feature. Also with air mode (not at mobile at the moment): jQuery Notebook
-
Hi I try to build a frontend form with from template fields. No problem to generate the form and detect the field type like InputfieldTinyMCE. But how could I load the InputfieldTinyMCE module to use it in the frontend? Tried to load the module with module get and print the scripts and styles inside the html head. But I think editor have to be initialized? Any module method to call?
-
Thanks for all your answers and hints. I prefer PW because of simple module development (it's easy to understand), great api and additional proCache and other options should do it... Some modules planned to build with PW. I'll see how it compares to others
-
That's right and I know there is no simple answer to give And each framework will have pros and cons depending on requirements. I try to specify the questing. Is there a significant design difference why PW should be faster or slower than other frameworks? For example database structure or whatever? @apeisa I like Drupal, but not because it's lightning fast performance *g* By now I prefer PW And PW api / module development is essential easier!
-
Hello community, I love PW and it's powerful api. PW is more a framework than a cms, but it can be used as both. After testing some cms and forum software many try to move to frameworks (Drupal CMS -> Symfony, EsoTalk Forum -> Laravel, ...). It's easier to build an application based an a solid base framework... PW itself is a framework and so no need to use yet another framework (ok, depeding on the planned application...). But how PW compares to other (php) frameworks like Laravel, Zend or Symfony? How fast is the PW api and field based data storage?
-
Tested some forum software in the last weeks. Just to see what's out there... Some are interesting, but don't know how easy could a integration done... NodeBB (Demo, nodejs based!) EsoTalk (Demo, php, fresh look and features! Bugfixes only because the future is Flarum) Codoforum (Demo, php, sso plugin)
-
There's also a blog comments plugin available. See a demo at nodebb development blog. SSO could maybe done with oauth or after the writeable api is released... I'll keep an eye on NodeBB and the further development...
-
Today I found a Froala Editor and it's really interesting. image handling / positioning, inline editing, mobile support and many options (imageUploadURL, initOnClick, inlineMode, saveURL). Maybe a great PW module, but also take a look at licensing. Free for Personal and non-profit projects
-
NodeBB forum use Pushbullet notifications...
-
Sounds good. Would be glad to read a feature list Have to build a shop with invoice, paypal payment gateways. Also file download could be a needed feature... Would be great to separating design / template for easy styling.
-
Hi Wanze, global template works with following example. $factory = $modules->get('TemplateEngineFactory'); $subtpl = $factory->load('basic-page'); // current page template / view basic-page.tpl $subtpl->set('subtplvar', $page->body); // global template / view $view->set('title', $page->title); $view->set('subtpl', $subtpl->render()); // render sub template to global template variable I think that's how it should be used? How did it work with smarty / twig? Was it a include inside a template to load a sub template? If I'm right template engine can't simply switched between Processwire and Smarty/Twig because template variables seems to be handled different? PW -> load sub template & fill it like your chunk example Twig/ Smarty -> include sub templates and fill all the template and sub template variables via api variable? Don't know I'm right or if it's possible. But would be nice to get it filled the same way At the moment I'm only working with pw template class, but maybe I'll could be switch it later... So it would be a great feature have template parser independent code