Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/01/2023 in all areas

  1. I don't know your module's code so I can't be specific, but seeing it's 3000 lignes long I think the main idea would be to split responsibilities into different classes. The Single-responsibility principle says that each class should only manage a single thing. It makes code cleaner, easier to manage and to test in the future. I'm saying this without knowing the code so it's just generic ideas. If your module manage fields, templates and migrations, you could add classes FieldBuilder, TemplateBuilder, MigrationManager... The module API would be something using fluent interface like this (OK I said that changing API is not necessary and I'm changing it... ^^): $myField = $module->newField()->type(FieldType::INTEGER)->name('foo')->min(1)->max(10); $myTemplate = $module->newTemplate()->name('bar')->addField($myField); With newField() and newTemplate() methods returning a FieldBuilder and a TemplateBuilder. The benefit is to move field or template specific code in classes that manages only this. Just some thoughts... ?
    1 point
  2. Just had a look at the code and some cleanup would be nice for sure (though not necessary imho). How would that work? For example the method "addFieldToTemplate(...)". How would I move that method to another file without changing the api? I know it would be possible to add that method to $rockmigrations via API addHookMethod, but that makes it a lot more complicated to develop and to also support proper intellisense. Also I guess it would have more overhead.
    1 point
  3. Thanks @Stefanowitsch, That confirms that the issue is occurring when it tries to JSON encode the data. I'm happy for you to send the print_r() data via direct message if you want me to take a closer look. I also wonder whether trying to log serialize($data) would work, if so that output would be easier for me to work with. Cheers, Chris
    1 point
  4. This week we have ProcessWire 3.0.229 on both the dev and master/main branches. At this moment, both branches are equally up-to-date. Though I've not yet added the 3.0.229 tag just yet, as it is Friday after all. ? So I'll tag it this weekend or Monday. If you are already running the dev branch on version 3.0.228, then this version contains a few issue fixes and is worth the update. If you are running the previous master/main version 3.0.227 then this version has quite a few worthwhile fixes and I'd recommend upgrading, at least once we add the 3.0.229 tag. Here's a link to the current commit log. That's all for today, have a great weekend!
    1 point
  5. Cheers as always @ryan. Have a great weekend.
    1 point
  6. hi @nbcommunication, thanks for your quick response. yes, that's what i thought, and i was hoping that there would be an easy way to reduce the image size with processwire. i'm doing it now like this. I reduce the imagesize and do some croping to squared images via php, then save it to the temp-folder and link to this image. $instagram = $modules->get('InstagramBasicDisplayApi'); // Get 10 images $images = $instagram->getImages(10); $counter = ''; echo '<div class="start_instagram uk-grid-column-small uk-grid-row-small uk-child-width-1-2@s uk-child-width-1-5@m" uk-grid>'; foreach ($images as $image) { $counter = $counter + 1; $instagramImageUrl = $image->src; $imageData = file_get_contents($instagramImageUrl); $fileName = 'instaBild' . $counter . '.jpg'; $filePath = $config->paths->assets . "instaTemp/" . $fileName; // Verkleinere das Bild auf eine maximale Breite von 300px $maxWidth = 300; list($width, $height) = getimagesizefromstring($imageData); $aspectRatio = $width / $height; $newWidth = min($maxWidth, $width); $newHeight = $newWidth / $aspectRatio; // Erstelle ein leeres quadratisches Bild $imageResized = imagecreatetruecolor($maxWidth, $maxWidth); $imageSource = imagecreatefromstring($imageData); // Berechne die Position für das Cropping (zentriert) $cropX = 0; $cropY = 0; if ($width > $height) { // Querformat, seitlich beschnitten $cropX = ($width - $height) / 2; } elseif ($width < $height) { // Hochformat, oben und unten beschnitten $cropY = ($height - $width) / 2; } // Führe das Cropping durch imagecopyresampled($imageResized, $imageSource, 0, 0, $cropX, $cropY, $maxWidth, $maxWidth, $width - (2 * $cropX), $height - (2 * $cropY)); // Speichere das verkleinerte und beschnittene Bild imagejpeg($imageResized, $filePath); imagedestroy($imageResized); imagedestroy($imageSource); // echo $fileName . " auf " . $filePath . " gespeichert.<br>"; $tempPath = "/site/assets/instaTemp/" . $fileName; $altDesc = $image->alt; echo "<div> <a href='". $image->href ."' target='insta'> <img src='" . $tempPath . "' alt='" . $altDesc . "' title='". $altDesc ."'> </a> </div>"; } echo '</div>'; ?> i think this solution is OK, since i have proCache running and so it doesn't regenerate on every page load, or am i wrong? there are 10 images loaded which are now about 160kb in size as compared to the 3mb for the originals. suggestions for improvements are still welcome, i wanted to make sure i hadn't overlooked any major option.
    1 point
×
×
  • Create New...