Jump to content

netcarver

PW-Moderators
  • Posts

    2,241
  • Joined

  • Last visited

  • Days Won

    47

Everything posted by netcarver

  1. Just spent an hour or so learning how to set-up custom scheme handlers in Arch linux to try this feature out and it's now working fine for me after a few false leads. This will really come in handy - thanks Adrian and the Tracy devs!
  2. As promised, here's the script with delete powers. Only tested on a small subset of an installation I'm switching over to CroppableImage3 so do your own testing please!
  3. I think that's a reasonable position to take - it addresses the concern expressed by @szabesz here, and can still be used to provide folks like @Sephiroth access as described here.
  4. @Alxndre' Excellent! Really enjoyed reading this. Congratulations to you and the team there. Thank you for posting.
  5. // 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.
  6. @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.
  7. 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.
  8. 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.
  9. @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.
  10. 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.
  11. 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!
  12. I agree with Adrian: the regex101 site is very useful!
  13. 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.
  14. 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!
  15. 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!
  16. @usillos I'm not available for work at the moment but I want to say that I like the quality of your job description; really nice! Great that you include the timezone and location info too. Thanks for that - and hope you get a great bunch of devs replying to it!
  17. 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.
  18. @fbg13 Please do add this to the PW modules repository!
  19. 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!
  20. 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.
  21. 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);
  22. 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?
  23. @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!
  24. You do realise that if you (and Adrian with Tracy) keep developing your modules at this rate, they will become sentient before I do.
  25. I think you might have missed a leading '\' on the 'Processwire' name. Try this... use \ProcessWire\Process; Not 100% sure though.
×
×
  • Create New...