-
Posts
1,331 -
Joined
-
Last visited
-
Days Won
61
Everything posted by BitPoet
-
Output formatting before page render
BitPoet replied to bits-please's topic in Module/Plugin Development
The html entity encoding happens through the Textformatter assigned to the title field. That's something output formatting does, so you need to turn output formatting off to get the raw value with quotes from the field. There's an in-depth article in the wiki on that topic that explains the behaviour quite well. -
Okay, I think I've tracked it down. The problem vanished as soon as set PHP's user_agent, which was empty in all configurations. So either setting that in php.ini, in the .htaccess or somewhere early in the PHP code should get things running again.
-
fopen()ing that URL also fails on my local host using both PHP 5.6 and 7, so I'd tentatively point my finger towards github (allow_url_fopen is enabled and requests from the browser return the expected JSON content).
-
Okay, so I've done it. Two sets of modules, one for the server side, the other for the client side. There are still a lot of ToDos, like adding dedicated endpoints on server and client (I'm currently hooking indiscriminately into ProcessPageView::execute, but I'd like to go the route of only loading the listeners for this template) or adding some kind of challenge-response mechanism to keep nosy third parties out. The modules are up on github: Server component Client component There's also a screen cap in the readmes. Both module sets have lots of hooks, so component modules should be easily able to extend the basic functionality. Currently, the online functions arealdy built-in are the setup of the management connection on both sides and getting basic client information. I haven't really looked at the upgrade or db backup modules, so I've got no idea how complicated remoting them would be. But the sky's the limit. Comments, critiques and pull requests welcome!
- 23 replies
-
- 14
-
-
magic function name in PW Process module development
BitPoet replied to adrianmak's topic in Module/Plugin Development
These are automagically called by ProcessController when an URL segment is appended to the path of an admin page. If an admin page url is http://server/processwire/adminpage/ and that page is called, the execute method is called. But if you open, for example, http://server/processwire/adminpage/edit, the first letter of the URL segement (edit) is uppercased and it is appended to the process method, resulting in executeEdit. Process methods with multiple uppercase letters (camel case) are called by passing URL segments with hyphens. The hyphens are stripped, but each letter after a hyphen is uppercased, so http://server/processwire/adminpage/point-me-to-crocodiles will look for a method executePointMeToCrocodiles in adminpage's process module. This way, one doesn't have to set up another process module for a subtasks and create a page for it or parse even more form values in execute. For a new subtask XXX, it's sufficient to add links/form targets with an URL segment of xxx and define a matching executeXxx method. A perfect starting point to learn more about creating process modules is the source code of Ryan's ProcessHello module, which can be found at github and in the module repository. -
Yes, all these points would mean creating a monster. In terms of database backups or malware scans, those are highly platform specific and not something easily implemented in a module. A centralized overview actually makes sense to me. Showing.PW and module versions and outputting some statistical information is also quite doable. Displaying a momentary status can be done, but continuous monitoring is not something that you can build on top of PW - for this, you'd need to add some layers under or next to it. I've started tweaking together a set of modules that could serve as a base. I'll try to add the necessary hooks to allow extending it tomorrow and put an alpha release on github. If nothing else, it's an interesting conceptual challenge
-
How to use pw to create a guestbook like functionality ?
BitPoet replied to adrianmak's topic in General Support
Do file and class names match up? -
How to use pw to create a guestbook like functionality ?
BitPoet replied to adrianmak's topic in General Support
Your module is missing public static function getModuleInfo() { return array( /* title, version, summary and autoload values*/ ) }; -
any build-in function to, return a string by first number of words
BitPoet replied to adrianmak's topic in Getting Started
/* Using regular expression */ $firstTwenty = trim(preg_replace('/^\s*((?:\S+\s+){20}).*/', '$1', $inputText)); /* Using split and combine */ $firstTwenty = implode(' ', array_slice(explode(' ', $inputText), 0, 20)); -
how do u manage existing website hyperlinks?
BitPoet replied to adrianmak's topic in General Support
That depends if the new content structure matches the old one at least to some extent. If it's rather similar, it would be an option to import the old id into a field and replace the old php files with small scripts that bootstrap PW, look for a page matching the given id and redirect there with a moved permanently, or to the homepage if the id wasn't found. The same thing may work if you can identify a set of landing pages for the old pages, but you'd have to manually assign multiple old ids to some of the new pages (e.g. with a repeater). It really depends on whether you can match up old and new content. Wherever you can't, redirect to home. -
I might be misinterpreting the requirements, but at the first read, they screamed "Repeater Matrix" at me, a 3.0.5 alpha feature which would let you set up a repeater with a set of fields for external links like you already have and alternatively allow a page field in that same repeater as well. It would even be a perfect playground for the new field templates (as explained at the end of the linked blog entry) to make the code as concise as it can get. No idea if pro fields or PW 3 are valid options for this project, but I thought it worth mentioning.
-
Using $page->render() on unpublished pages return 500 Error
BitPoet replied to Lars282's topic in General Support
$page->render checks Page::viewable() for unpublished pages, so you'll likely have to hook into viewable and override the return value for your use case. -
Yay! This update has me rather excited, and I can already see an overhaul of our course booking system coming up in the near future. Nested repeaters and field templating are just the things to streamline this quite spectacularly. Dynamic Ajax loading is going to be such a treat too! Ryan, if you keep up PW's innovation speed like this, I'm sooner or later going step on my tongue while I race to make us of all these new possibilities!
-
We're using CKEdtior quite heavily in our intranet (used to be TinyMCE in the previous CMS, but that had all kinds of issues with new browsers). The tech departments write their internal data sheets and part compatibility lists with it, using nested tables (now way around that, unfortunately) and a concise set of CSS classes. Most departments also have a bunch of CKEditor-only pages for their department presentations, useful information for everyone and for anything and everything in their internal department areas. Alltogether, that's a few thousand of these pages. Not everything is as homogenous as we'd need a public-facing homepage to be, but it's not as far off as one would fear either. My experience regarding Hanna Code (or any other placeholder system) is much like teppo's, most users can't wrap their heads around the question why they should use these "magic thingies" when everything else is wysiwyg, and they keep forgetting which is which.
-
I've recently switched to IIS for development. Still a little bit of manual work (once you know what you're doing, you're up-and-running in less than an hour, though) but once it's up, it's really fast.
-
Just use PW's $db object and pass the call statement to query() or (prepare()/execute() if you want to reuse the call or use bound parameters). PW's database object is just a wrapper around PHP's PDO class.
-
The error says that $rss is not an object, so the call $modules->get doesn't return a module instance. Did you install the module after downloading it?
-
In Setup -> Languages click your default language. Click "Translate File", then select InputfieldDatetime in the "Translatable files in Wire" select - unless the language pack already contains a translation for it, then you only need to click on the title of the translation in the language itself.
-
InputfieldDatetime allows you to translate the paths for the datepicker and timepicker language files if LanguageSupport is installed. /wire/modules/Jquery/JqueryUI/i18n/jquery.ui.datepicker-xx.js => /wire/modules/Jquery/JqueryUI/i18n/jquery.ui.datepicker-nl.js timepicker/i18n/jquery-ui-timepicker-xx.js => timepicker/i18n/jquery-ui-timepicker-nl.js This might be easier than toying around with custom JS.
-
Sorry, my bad for not thinking my answer through. setlocale() has no effect on PHP's date() formatting, it only influences strftime(). Thus, you can use it to change how the formatted value of a PW field looks if it uses a percent encoded format fitting for strftime, but not the input format that is active when used as a form field. So I'm not aware of any way to make native PW date fields locale aware.
-
Bram, you need to set the locale before rendering the form. Then any output formats defined for date/time fields in that form (assuming we're talking about PW Inputfields) will be rendered according to the chosen locale. strftime() only formats unix timestamps, i.e. integer values in seconds since the first of January 1970. You can't feed it HTML snippets.
-
CKEditor like input, but saving formating in markdown?
BitPoet replied to Chris's topic in General Support
I've toyed around with a number of options to achieve that for my ongoing pw-based forum project too, but I didn't get anywhere. So I've settled on including MarkItUp as message editor in the frontend and added a preview button that retrieves the formatted HTML for the markdown through ajax and displays it in a lightbox. I guess this might be a feasible approach for you too. -
select field type who uses images for preview changes
BitPoet replied to Chris's topic in Wishlist & Roadmap
Or this: class InputfieldSelectThumbnail extends InputfieldSelect { /** * Return information about this module * */ public static function getModuleInfo() { return array( 'title' => __('InputfieldSelectThumbnail', __FILE__), // Module Title 'summary' => __('Select a page from a list that displays a thumbnail of the first image found in the page', __FILE__), // Module Summary 'version' => 101, 'autoload' => true ); } public function init() { $this->addHookBefore("InputfieldPage::getConfigInputfields", $this, "addOwnClassToSelect"); } public function addOwnClassToSelect($event) { $obj = $event->object; $classes = $obj->get("inputfieldClasses"); $classes[] = "InputfieldSelectThumbnail"; $obj->set("inputfieldClasses", $classes); $this->log->message("addOwnClassToSelect: InputfieldSelectThumbnail"); } protected function renderOptions($options, $allowBlank = true) { $out = ''; reset($options); $key = key($options); $hasBlankOption = empty($key); if($allowBlank && !$this->required && !$this->attr('multiple') && !$hasBlankOption) $out .= "<option value=''> </option>"; foreach($options as $value => $label) { $selected = $this->isOptionSelected($value) ? " selected='selected'" : ''; $attrs = $this->getOptionAttributesString($value) . " " . $this->getThumbnailAttributes($value); $out .= "\n\t<option$selected $attrs value='" . htmlspecialchars($value, ENT_QUOTES, "UTF-8") . "'>" . $this->entityEncode($label) . "</option>"; } return $out; } protected function getThumbnailAttributes($pgid) { $this->log->message("getThumbnailAttributes({$pgid})"); $pg = $this->pages->get($pgid); if( $pg instanceof NullPage ) return ""; $fields = $pg->template->fields; $imgfield = null; foreach($fields as $fld) { if( $fld->getInputfield($pg, $fld) instanceof InputfieldImage ) { $imgfield = $fld; break; } } if( $imgfield == null ) return ""; $img = $pg->get($imgfield->name); if( $img == null ) return ""; if( is_array($img) ) { if( count($img) == 0 ) return ""; $img = $img[0]; } else if( $img instanceof WireArray ) { if( $img->count() == 0 ) return ""; $img = $img->first(); } $thumb = $img->size($this->maxThumbWidth, $this->maxThumbHeight); $width = $this->maxThumbWidth + 4; $height = $this->maxThumbHeight + 4; $attrs = "style='padding-left: {$width}px; height: {$height}px; background-image: url({$thumb->url}); background-position: 2px 2px; background-repeat: no-repeat;'"; return $attrs; } public function ___getConfigInputfields() { $inputfields = parent::___getConfigInputfields(); $fieldset = $this->modules->get('InputfieldFieldset'); $fieldset->label = $this->_('Thumbnail options'); $fieldset->attr('name', 'thumboptions'); $fieldset->icon = 'image'; $field = $this->modules->get('InputfieldInteger'); $field->label = $this->_('Max. width'); $field->attr('name', 'maxThumbWidth'); $field->attr('value', $this->maxThumbWidth ?: 80); $field->columnWidth = 50; $fieldset->add($field); $field = $this->modules->get('InputfieldInteger'); $field->label = $this->_('Max. height'); $field->attr('name', 'maxThumbHeight'); $field->attr('value', $this->maxThumbHeight ?: 80); $field->columnWidth = 50; $fieldset->add($field); $inputfields->add($fieldset); return $inputfields; } } If picked as the input field type for a page field, it adds a thumbnail from the first image found in each selectable page to the dropdown (by resizing that image and setting it as the option's background image through css). -
Are there old instances of the German-only pages present in the trash folder? The number at the end gets incremented if a page with the exact same name (including the number) is already present. If you start out with completely fresh page names and no "zombies" in the trash folder, the numbers should match up for new pages.