-
Posts
1,554 -
Joined
-
Last visited
-
Days Won
48
Everything posted by gebeer
-
I changed the way I organize images. Now my form doesn't contain an image field anymore. I moved image handling to it's own form because I need to have images organized per user and not per page. I modified adrian's module that I found in this post to change the rootParent for wire/modules/process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module. My ChangeImageSelectParent.module code now reads class ChangeImageSelectParent extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Change Image Select Parent', 'version' => 1, 'singular' => true, 'autoload' => true ); } public function init() { $this->addHookAfter('ProcessPageEditImageSelect::execute', $this, 'changeParent'); } public function changeParent(HookEvent $event) { $user = $this->wire("user"); if ($user->role == "frontend") { $rootPageID = wire("pages")->get("template=media, created_users_id={$user->id}")->id; $event->replace = true; $event->return = str_replace("rootPageID: 0", "rootPageID: ".$rootPageID, $event->return); } } } But I can't see if this has any effect because I still get the error from my first post: when I hit the insert image button in CKeditor. So again my question: can we use PWimage plugin in frontend forms?
- 5 replies
-
- PWimage plugin
- frontend
-
(and 2 more)
Tagged with:
-
ProcessPageEditImageSelect - hook and change default $page
gebeer replied to mr-fan's topic in Modules/Plugins
I have a special use case where I need to change the rootParent to a page owned by the logged in user that has the template "media". I think adrian's module with some modifications is exactly what I need, but I'm not quite sure how to modify it the right way. Here is what I've got so far. class ChangeImageSelectParent extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Change Image Select Parent', 'version' => 1, 'singular' => true, 'autoload' => true ); } public function init() { $this->addHookAfter('ProcessPageEditImageSelect::execute', $this, 'changeParent'); } public function changeParent(HookEvent $event) { $userID = wire("user")->id; $rootPageID = wire("pages")->get("template=media, created_users_id=$userID")->id; $event->replace = true; $event->return = str_replace("rootPageID: 0", "rootPageID: ".$rootPageID, $event->return); } } Any help would be much appreciated. -
Hello all, I have a frontend form with a CKEditor textarea and an image upload field. The image upload is working fine. But when I want to insert an image through the PWimage plugin, I get an error inside the modal window This is happening on a page that has already been saved after adding the image. A forum search for that error revealed only this post and it's related post. Nut they don't seem to offer a solution to my problem. Line 179 in ProcessPageEditImageSelect.module says $images = $this->getImages($this->page); I'm not a coder, but I guess this means that $this->page returns a nullpage and thus the error. I read quite a few posts about frontend image handling but didn't find anything related to my problem here. Is it not possible to use the PWimage plugin on frontend forms? Or could this be related to permission settings for my frontend user? EDIT: I changed the title of this post from "CKEditor..." to "PWimage plugin...", because the problem is not CKEditor specific, it seems.
- 5 replies
-
- PWimage plugin
- frontend
-
(and 2 more)
Tagged with:
-
@netcarver here are some more timepickers that I was looking at when trying to quickly implement one with your field: https://fgelinas.com/code/timepicker/ : this one is based on jQuery UI http://jdewit.github.io/bootstrap-timepicker/ : personally, I like this one best, but it relies on Bootstrap and I couldn't get it to work with BS 3 and with other date fields present in the same form http://weareoutman.github.io/clockpicker/jquery.html : funny picker looks like a clock http://amsul.ca/pickadate.js/
-
@teppo Thank you for this module. Exactly what I need. @moonwhaler There is a Trumbowyg plugin for image uploads. I'm looking into adjusting trumbowyg.upload.php to use it with PW wireUpload. Need an easy way for users to add images in a frontend form. I have read ongoing discussions about how PW implements image management and hope I can pull something together using this module.
-
Thank you for the module. I'm using it on a site in development as input for publishing times. Discovered no problems so far. All is running smoothly. Have you considered adding optional JS to the field for user friendly input through a time picker like http://jonthornton.github.io/jquery-timepicker/ ?
-
I can set the user timezone with date_default_timezone_set. It is important to set it before my form gets rendered, submitted and processed, not just before I save values. The current time in my date field gets calculated based on the set time zone. Example: set timezone Europe/Berlin, current date set timezone America/New_York, current date When PW saves publishing timestamps, I get timestamps for 2014-10-24 03:00 Europe/Berlin: 1414112400 America/New_York: 1414134000 Which is 21600 seconds or 6 hours off. Which is correct. So I think I'm on the right track now handling different timezones.
-
Hi there, can't seem to get my head around handling user timezones the right way and hope to get some feedback from people more knowledgeable than me. My scenario: Users can set publishing date/time for pages they create through a frontend form. These should be saved in the users' timezone. I have a date field for publishing time. PW saves dates as unix timestamps to the DB. For conversion of the date/time to the timestamp PW uses the default server time zone setting (in my case Europe/Berln). Now when a user in timezone America/New_York creates a page and sets the publishing date, it will be converted to a timestamp using the server timezone Europe/Berlin and saved to the DB. Later the user checks if his page is being published at the set time in New York. But it will be published at the wrong time because the user is in a different timezone. I assume it would be best to convert the publishing date/time to a timestamp using the user timezone and save that to the DB. Am I right here? How would I accomplish that? I found date_default_timezone_set. Can I simply use this to set the user timezone before I save values, like date_default_timezone_set($userTimezone); // where $userTimezone is a string like "America/New_York" $editpage->of(false); foreach($adform as $field) { // loop through all fields and save them if(in_array($field->name, $ignorefields)) continue; $editpage->set($field->name, $field->value); } $editpage->of(true); date_default_timezone_set($config->timezone); // do I have to set it back to server timezone here?
-
@sforsman Thanks, but not working. I get a JS error Uncaught Error: Syntax error, unrecognized expression: #Inputfield_ad_frequency_1082|1083|1084 Attribute data-show-if="ad_frequency=1082|1083|1084" in the field wrapper. I'm on 2.5 stable and on a frontend form where other dependencies are working fine.
-
It seems like OR in dependencies is not working for radio buttons. I want to show a field only some specific options of the radio input "ad_frequency" are checked. I tried this in field dependencies settings: ad_frequency=1082, ad_frequency=1083, ad_frequency=1084 If I set it to a single radio option like ad_frequency=1082 everything is working as expected. In the docs it says that this will be implemented. Does anyone know, when?
-
try $hassidebar = array('home','project','projects','posts','partners'); if (in_array($page->template->name, $hassidebar) { //... } EDIT: adrian was quicker. Either of it should work.
-
How do you update a page with all its field via front-end?
gebeer replied to Marc's topic in Getting Started
Take a look at Soma's gist. It loops through all the fields of your page and displays a form. Then on Submit of the form it again loops through each field and saves the value. It also includes all styles and scripts that you need for your form to work on the frontend. This is working great for my frontend form. If you need help implementing it, let us know. -
Thank you for the module. Just one suggestion: In terms of human readable URLs, wouldn't it be better to attach the time as a Datetime string like "2014-10-21-16-04-33" rather than the unix timestamp?
-
MarkupSEO - The all-in-one SEO solution for ProcessWire.
gebeer replied to Nico Knoll's topic in Modules/Plugins
I'm implementing a custom field type based on Ryan's Event field type that uses a custom table for storage. I have compared performance to other methods like using a pages field. And the custom table field is much much faster, both when saving and querying values. So I'd recommend going with the custom table field following Ryan's Event field type module. -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
@sforsman Thanks for the explanation. Very enlightening -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
@adrian Just tried your code and compared time for both methods. Deletion of 3073 timestamps. using $editpage->ad_publish_at->removeAll(); 0.2848 seconds using foreach ($editpage->ad_publish_at as $t) { //ad_publish_at is my timestamps field $editpage->ad_publish_at->remove($t); } 0.7537 So removeAll() is significantly faster and speeds up my application. Thank you! Cheers Gerhard -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
I implemented it so that the deletion of old timestamps happens only after the user submits the form and before the new timestamps get created and saved. For my scenario this is sufficient and I don't need other automation options. I'm just wondering whether there might be a faster method to delete timestamps other than my foreach loop in step #6 above (which is pretty fast already anyways ). -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
I'm wondering, too if this could be automated. When I just add new timestamps, the old ones are still there. That's why I'm deleting them before I add new ones. Deleting takes around 1.6 seconds for 3000 timestamps. So I can live with that. But if there is a way to make this faster, I would be very interested. -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
@kongondo My implementation is as follows. 1. installed the inputfield Timestamps module that you supplied. 2. created a field "ad_publish_at" of type timestamp and add it to my advertisement template 3. render the form on the frontend with code based on Soma's gist. 4. use a custom function to find recurrences from start and end dates in my advertisement template. The function uses the barely documented PHP DatePeriod class function getRecurrences($startTime,$endTime,$interval) { $format = 'Y-m-d H:i'; $start = new DateTime(); $end = new DateTime(); $start->setTimestamp($startTime); $end->setTimestamp($endTime); $end = $end->modify( '+1 minute' ); $duration = 'PT' . $interval . 'M'; //where $interval is 15, 30 or 60 $interval = new DateInterval($duration); $daterange = new DatePeriod($start, $interval ,$end); return $daterange; } 5. $daterange contains an array of DateTime objects. I loop through them, convert each into a timestamp and save that to my timestamps field $times = getRecurrences($startTime,$endTime,$interval); //this is the daterange array with DateTime objects foreach ($times as $t) { $t = $t->getTimestamp(); $timestamp = new Timestamp();//this is the Class Timestamp found in Timestamp.php. Included via FieldtypeTimestamps. $timestamp->date = $t; // note stored in column 'data' in the db of the Field $editpage->ad_publish_at->add($timestamp); } 6. when a user edits an advertisement and changes dates, I have to manually delete all previously saved timestamps, before I add the new ones with step 5 above. For deleting the "old" timestamps I use this foreach ($editpage->ad_publish_at as $t) { //ad_publish_at is my timestamps field $editpage->ad_publish_at->remove($t); } If you have any further questions on my implementation, please ask. -
I have the exact same scenario and am using page field like sforsman suggested. To make your filters work you can use URL segments. Works like a charm.
- 8 replies
-
- 2
-
-
- dependencies
- inputfield
-
(and 1 more)
Tagged with:
-
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
$answers = $pw->community("answers=awesome"); foreach ($answers as $answer) { echo "Thank you " . $answer->createdUser->name . " "; } :) -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
OK, this is solved now. The most efficient and performant method for storing multiple (even thousands) of timestamps with a page definitely is a custom input field type that stores values in an extra table in the DB which makes it really fast. Thanks to all who contributed, especially kongondo who was so kind to supply a customized input field Timestamps module derived from the input field events module. I can now save about 3000 timestamps for a page within 2 seconds which is really fast compared to other methods that I have tried. Also searching through those timestamps is pretty fast, even when it comes to hundreds of pages that need to be searched for a timestamp value. PW really is great tool and the detailed help and instructions here in the forum is absolutely awesome. I also learned a lot about PHP and the inner workings of PW during the process. Thanks again! -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
@kongondo In my foreach, the values are converted to timestamps before I send them to the Timestamps module (note the 2nd line here) foreach ($times as $t) { $t = $t->getTimestamp(); $timestamp = new Timestamp();//this is the Class Timestamp found in Timestamp.php. Included via FieldtypeTimestamps. $timestamp->date = $t; // note stored in column 'data' in the db of the Field $editpage->ad_publish_at->add($timestamp); } That's why I don't understand that PHP Notice. But my solution to convert the value again with strtotime seems to be working fine and everything behaves as expected. So no need to worry about it any further. -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
@horst I see what you mean. But in my code I already turn off output formatting. S I don't quite understand why a formatted value is being returned. $editpage->of(false); foreach($adform as $field) { if(in_array($field->name, $ignorefields)) continue; $editpage->set($field->name, $field->value); } $editpage->title = $editpageTitle->value; $editpage->name = "ad-".$sanitizer->pageName($editpage->title)."-".$uID; $deletetimer = Debug::timer(); //delete all old timestamps for that page before saving new ones $numberDeleted = iterator_count($editpage->ad_publish_at); foreach ($editpage->ad_publish_at as $t) { $editpage->ad_publish_at->remove($t); } $deletetimer = Debug::timer($deletetimer); $runtimer = Debug::timer(); $startTime = $adform->get("ad_publish_up")->value; $endTime = $adform->get("ad_publish_down")->value; $interval = $adFrequency->value->value; if ($interval == "0") { $numberCreated = 1; $timestamp = new Timestamp();//this is the Class Timestamp found in Timestamp.php. Included via FieldtypeTimestamps. $timestamp->date = $startTime; // note stored in column 'data' in the db of the Field $editpage->ad_publish_at->add($timestamp); } else { $times = getRecurrences($startTime,$endTime,$interval); $numberCreated = iterator_count($times); foreach ($times as $t) { $t = $t->getTimestamp(); $timestamp = new Timestamp();//this is the Class Timestamp found in Timestamp.php. Included via FieldtypeTimestamps. $timestamp->date = $t; // note stored in column 'data' in the db of the Field $editpage->ad_publish_at->add($timestamp); } } $runtimer = Debug::timer($runtimer); $editpage->save(); $editpage->of(true); -
Find most efficient solution for storing multiple values in a field
gebeer replied to gebeer's topic in General Support
I also found how to delete timestamps via the API here. In my case I do foreach ($editpage->ad_publish_at as $t) { $editpage->ad_publish_at->remove($t); }