-
Posts
2,236 -
Joined
-
Last visited
-
Days Won
47
Everything posted by netcarver
-
@Alxndre' Excellent! Really enjoyed reading this. Congratulations to you and the team there. Thank you for posting.
-
// This might work... $page->set('visitCounter', ((int) $page->visitCounter) + 1); // If not, try this... $page->set('visitCounter', (($page->visitCounter) ? ($page->visitCounter) :0) +1); // Personally, I don't like this style of code - I see too many smileys in there.
-
@fbg13 Could you make it so that the edit page is only provided to superusers and maybe users with a certain role such as 'file-editor'? This would allow people like Sephiroth to use your module while keeping other users well away from the files.
-
This is resolved now. It was a problem with the underlying repeater, not the CroppableImage3 field in it. I had earlier used the API to migrate a new field into the template used by the repeater but forgot to reflect the change in the field data (specifically, the repeaterFields settings on the field.) Now I have the repeater and its template in sync, all works well.
-
Anyone successfully using CroppableImage3 in a repeater field? I just converted a CropImage field (used in a repeater) over to CroppableImage3 and get an error every time I try to edit any page with the repeater on now (the front end is working fine.) It's possible this is a problem with the repeater code though.
-
@Sérgio There's nothing wrong with that approach, \d{4} should work fine. I guess it also comes down to where you want to codify the rules - in the regex, or in the PHP, or some combination of both.
-
Upgrading from Thumbnails module to Croppable Image 3
netcarver replied to jacmaes's topic in General Support
I also have a copy of the script that optionally handles deletion of the source variations too. I'll post that when its had some more testing. -
Upgrading from Thumbnails module to Croppable Image 3
netcarver replied to jacmaes's topic in General Support
Here's an updated version of the script from @horst and @jacmaes This version; Is PW3 compatible (but not 2.7/2.8) Fixes a bug that prevented the $debugIteration flag from working as described Tweaks the output formatting somewhat Adds some stats on pages/images/variations visited (and variations copied successfully) <?php // for PW3+ // (UPDATES by @jacmaes bugfix for $new filename from below post!) // (UPDATES by @netcarver debugIteration bugfix, PW3 compatibility & formatting tweaks) $debugIteration = true; // true to iterate only over the first page with a desired field, false to iterate over all pages $doFilecopy = false; // true to really copy variation files, false for debug purposes $oldFieldtype = 'CropImage'; // CropImage $newFieldtype = 'CroppableImage3'; $timelimit = 120; // per single page // bootstrap PW include(dirname(__FILE__) . '/index.php'); // collect fields and cropsetting names $collection = array(); echo "<ul>"; foreach($fields as $f) { if($f->type != 'Fieldtype' . $oldFieldtype) continue; $collection[$f->name] = array(); echo "<li>{$f->type} : {$f->name}</li>"; $thumbSettings = preg_match_all('#(.*?),.*?\n#msi' , trim($f->thumbSetting) . "\n", $matches, PREG_PATTERN_ORDER); if(!$thumbSettings) continue; $collection[$f->name] = $matches[1]; echo "<ul>"; foreach($collection[$f->name] as $suffix) { echo "<li>{$suffix}</li>"; } echo "</ul>"; } echo "</ul>"; echo "<hr />"; $pages_visited = 0; $images_visited = 0; $variations_visited = 0; $variations_copied = 0; // now iterate over all pages and rename or copy the crop variations echo "<ul>"; foreach($pages->find("include=all") as $p) { set_time_limit($timelimit); // reset the timelimit for this page foreach($collection as $fName => $suffixes) { if(!$p->$fName instanceof \ProcessWire\Pageimages) { continue; } $images = $p->$fName; if(0 == $images->count()) { continue; } echo "<li>Page \"<strong>{$p->title}</strong>\" <em>directory \"site/assets/files/{$p->id}/\"</em><ol>"; foreach($images as $image) { echo "Image \"<strong>{$image->name}</strong>\"<ul>"; $images_visited++; foreach($suffixes as $suffix) { $variations_visited++; $errors = array(); $dispold = "{$suffix}_" . $image->name; $dispnew = str_replace(".", ".-{$suffix}.", $image->name); $dir = dirname($image->filename).'/'; $old = $dir . $dispold; $new = $dir . $dispnew; $old_present = file_exists($old); $new_present = file_exists($new); if (!$old_present) $dispold = "<strike style='background-color:#F33'>$dispold</strike>"; if ( $new_present) $dispnew = "<u style='background-color:#3F3'>$dispnew</u>"; echo "<li><em>Variation: $suffix</em> — $dispold ⇒ $dispnew"; if($doFilecopy && $old_present && !$new_present) { $res = @copy($old, $new); if ($res) { $variations_copied++; $res = "<span style='background-color:#3F3'>Success</span>"; } else { $res = "<span style='background-color:#F33'>FAILED</span>"; } echo " <strong>Filecopy: $res</strong>"; } echo "</li>"; } echo "</ul>"; } echo "</ol></li>"; if($debugIteration) break; } $pages->uncache($p); // just in case we need the memory $pages_visited++; if($debugIteration) break; } echo "</ul><p>Visited $pages_visited pages.</p>"; echo "<p>Visited $images_visited images.</p>"; echo "<p>Visited $variations_visited variations.</p>"; echo "<p>Copied $variations_copied variations.</p>"; exit(); Looks like this now... Thanks Horst for the detailed instructions and script - and to jacmaes for the testing and update! -
I agree with Adrian: the regex101 site is very useful!
-
Payment base class + PaymentStripe + PaymentPaypal
netcarver replied to apeisa's topic in Module/Plugin Development
For what it's worth, I'm successfully running the base payment class and the Stripe class on a 3.0.33 installation. Not tried the Paypal module. -
Hi @cb2004 That's a fine start However, it will also match "-", "--", "---", "-2000", "-0", "-1000-1", "1---", "31415926" etc. If you are expecting a 4 digit start and end year separated with a single dash then you will need to use a more restrictive/specific regular expression. Assuming the start year is in the 1900 to 2099 range, and the end year in the 1900 to 2999 range, you'd need something more like this; Also, if you are going to be splitting this string up into the start and end year, you might want to use a urlSegment for the start and a separate one for the end year. If that is the case, you'd use ^(19|20)[0-9]{2}$ for the start urlSegment and ^(19|2[0-9])[0-9]{2}$ for the end urlSegment. Hope that helps!
-
Module Wire Queue, basic implementation of simple queues
netcarver replied to horst's topic in Modules/Plugins
Could you try replacing addItem() and getItem() with the following... public function addItem($arrayData) { if(!$this->_addItem()) return false; if(2 != $this->getState()) return false; if(!$fp = @fopen($this->getFilename(), 'ab')) return false; if(flock($fp, LOCK_EX)) { $arrayData = serialize($arrayData); $data = str_replace("\r\n", '\r\n', $arrayData) . "\n"; $res = fwrite($fp, $data); fflush($fp); flock($fp, LOCK_UN); fclose($fp); return $res == strlen($data); } fclose($fp); return false; } public function getItem($worker = null) { if(!$this->_getItem()) return false; if(2 != $this->getState()) return false; if(!$fp = @fopen($this->getFilename(), 'rb+')) return false; if(flock($fp, LOCK_EX)) { $line = trim(fgets($fp)); if(!$line) { flock($fp, LOCK_UN); fclose($fp); if(0 == $this->itemCount()) return null; return false; } // we have the first entry, now write all following data into a buffer $fpTmp = @fopen('php://temp/maxmemory:' . intval(1024 * 1024 * 5), 'rb+'); while(!feof($fp)) fwrite($fpTmp, fread($fp, 4096)); fseek($fp, 0, SEEK_SET); ftruncate($fp, 0); fseek($fpTmp, 0, SEEK_SET); // write back buffer into file while(!feof($fpTmp)) fwrite($fp, fread($fpTmp, 4096)); fclose($fpTmp); fflush($fp); flock($fp, LOCK_UN); fclose($fp); } return unserialize(str_replace('\r\n', "\r\n", $line)); } Untested - YMMV! -
Hmm, something in one of the recent minor revisions is messing up bootstrap styles of some buttons on a form page of mine - not sure which revision introduced it though. I'm on 3.2.8 now, but it happened with the previous version too. Inspecting in the browser shows tracy using a style... #tracy-debug input[type="submit"], .btn {...} ...which is stomping on bootstrap's own button style.
-
@fbg13 Please do add this to the PW modules repository!
-
Module FrontendUser: login, logout and register users / members
netcarver replied to pwFoo's topic in Modules/Plugins
Hello pwFoo, Thank you for this suite of modules - I've just been trying them out for the first time and they look very useful. I particularly like the email validation portion of this. One small observation though, when registering a new user and using a name or email that already exists, all the entered values are lost on unsuccessful form submission. I think it would be helpful to keep the value of any field that is not in error. So, if a user typed an in-use name, but the email was OK, then we should keep the email field and only clear the name field. Thank you! -
As a possible alternative, take a look at using PHP's flock() call with the LOCK_EX flag (either in blocking or non-blocking mode.) I've done that before - it's portable - and it works well. Take a look at the examples and comments on that page, you might spot something that fits your needs.
-
Hi SteveB, I'm pretty sure the code you posted above will not solve your problem. What happens if... We start off with page P not having a locked status. Thread A then gets scheduled, and runs the code in claimPage(P). It gets halted just before the line $page->save(); gets executed. Execution is then passed to thread B which is also trying to claim the page - so, it too, runs the claimPage(P) method - but this time to completion (saving P with the flag) and gets page P back. Eventually B is halted and focus switched back to thread A which picks up where it left off, and saves P again (with the locked flag) and gets page P back from the routine. Both threads will think they have successfully claimed the page, yet neither of them had to waitForPage(P);
-
Thanks for the update Ferdi! Any chance you could include the PW modules repository link (http://modules.processwire.com/modules/publish-to-twitter/) in your opening post?
-
@jaro @LostKobrakai <dream mode> Not sure if this is a good idea or not, but could this module be made to automatically export migrations that are compatible with Benjamin's migrations module? This would allow his module's interface to be used on the importing side to select which migrations to import. </dream mode> Edited to add: Now I've actually tried this module, I think the dream outlined above is more of a delusion. As it stands, the module does seem like a very neat way to keep the state of the fields and templates under version control along with the template files; nice work, @jaro!
-
You do realise that if you (and Adrian with Tracy) keep developing your modules at this rate, they will become sentient before I do.
-
Custom namespace in modules
netcarver replied to design-a-point's topic in Module/Plugin Development
I think you might have missed a leading '\' on the 'Processwire' name. Try this... use \ProcessWire\Process; Not 100% sure though. -
You might need to do this after the foreach loop... $pageNew->save();
-
Add Image from input type="file" possible - or must it be WireUpload?
netcarver replied to simonGG's topic in General Support
Slight tweak - probably never be needed... if (false !== file_put_contents($file, $data)) { $p->item_images->add($file); unlink($file); } Might save you an error if a file save ever fails. -
@jploch I've never used this in a repeater setup and I'm unsure of your field/template structure from that snippet. How have you actually structured things? What's the field called that holds the map markers? Regarding the backend, the address is normally a read-only field that is set either by clicking on the magnifying glass in the top-right corner of the map and entering a description or by simply dragging the marker around. Have you tried moving the marker or using the search feature? If they don't work, it is possible there is a problem with some of the JS not loading properly. Please could you launch you browser dev tools and see if any of the JS assets are not loading.