bytesource
Members-
Posts
220 -
Joined
-
Last visited
Everything posted by bytesource
-
Host, The rewrite rule from Oliver should match, but as it just seems responsive-images.php doesn't get called, I am tending to assume it does not match. I also tried the alternative rewrite rule you suggested, but I still get the same 404 error messages for each image. I still have got one question: Why do I need to add /processwire/ to the rule? It does not appear in any of the other rules. Cheers, Stefan
-
I added the line, copied the image address into the address bar, and loaded the page. But all I got back was the 404 error page of my site. Unfortunately there wasn't anything else.
-
For some reason responsive-images.php never gets called. That's why Processwire tries to handle these images but cannot find them: I assume the problem lies in my htaccess file (please see attachment). I removed the directives at the top for mod_expires, mod_headers, and mod_deflate, but nothing worked. I am getting out of options, but clearly I overlooked something. Cheers, Stefan htaccess.txt
-
I replaced the current .htaccess directive with the one you just posted, as it was different from the previous one. All other settings were already as you suggested. However, it is still not working. I am also using ProCache, but judging from how the plugin is implemented, should work anyway. Also, I am currently logged in the admin, so ProCache is off. Cheers, Stefan
-
I just added $log->error("responsive-images.php got called"), but there did not appear a respective entry in the PW log file.
-
On opening the file directly in Firefox as localhost/processwire/responsive-images.php I received the following error message: Cheers, Stefan
-
I placed you code at the top of responsive-images.php, reloaded the page and checked /site/assets/logs/errors.txt - but there was no new entry. So I guess the file never got called. Now I wonder why that is. Cheers, Stefan EDIT: Sorry, I only just realized you meant the Apache error_log file. I looked there, too, but there was not such entry, either.
-
Could it be that responsive-images.php never gets called? I placed an echo statement at the top of the file, but there is no output.
-
I changed the path as you said: * SITE_PATH: Document root file system path * SITE_URI: URI from document root */ define('SITE_PATH', rtrim(dirname($_SERVER['SCRIPT_FILENAME']),'/')); define('SITE_URI', rtrim(dirname($_SERVER['SCRIPT_NAME']), '/')); /** * PATH_CACHE: directory where resized image versions are stored * file system path */ define('PATH_CACHE', dirname(__FILE__) . '/site/assets/cache/images_cache'); Unfortunately, I still get the same error messages. Also, there is not folder images_cache created in /site/assets/cache. I checked the permissions, owner and group have create and delete rights. .htaccess and responsive-images.php both are located at the root. Why is it that Processwire is looking for these images in /site/assets/files? Cheers, Stefan
-
I moved the folder sample inside the templates folder and referenced it as follows: /responsive-images.php define('PATH_CACHE', dirname(__FILE__) . '/site/templates/sample/images_cache'); /** * PATH_PLACEHOLDER: placeholder image to be delivered before replacement * url */ define('URL_PLACEHOLDER', SITE_URI . '/site/templates/sample/images/transparent.gif'); However, it still doesn't work. I also noticed that Processwire is looking for the images in the assets folder, whereas I thought they would be placed inside the images_cache folder of this plugin: I hope this information might be helpful. Cheers, Stefan
-
Oliver, Thanks a lot for your detailed description. After adding the function call to responsiveImages inside the <head> section, the following happens: The images do not load Each image tag gets a class 'image-loading' attached, and the src attribute is not there anymore. I get 404 (page not found) errors for every image. The image names in the error message are given with layout-specific image dimensions that were attached by the plugin, such as <original image name>s1366.p1300.r1.jpg?141050308 I did not delete the folder named sample that was part of the code on Github, which means it is still located in the root folder (same level as .htaccess). Permissions seem to be correct, with read and write access for owner and group, so I suppose Processwire does not allow access to that folder, but I am not sure. I attached my complete .htaccess file. Maybe you can find something interesting there. Cheers, Stefan htaccess.txt
-
I placed the different files and code snippets as follows: responsive-images.php: /site/ 'sample' folder: /site/ .htaccess <IfModule mod_rewrite.c> RewriteEngine On AddDefaultCharset UTF-8 # ====================================================== # https://github.com/oliverwehn/Responsive-Images # START ================================================ RewriteRule \.(?:jpe?g|png|gif)$ responsive-images.php [QSA,L] # ====================================================== # https://github.com/oliverwehn/Responsive-Images # END ================================================== Javascript: <?php // Path to javascript files. $jsPath = $config->urls->templates . 'styles/js/'; ?> <script> document.cookie='responsive=1'; </script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="<?= $jsPath . 'jquery.responsiveimages.min.js' ?>"></script> However, the plugin does not seem to do anything. The cache folder is also empty. I remember Processwire not allowing the execution of php files outside the site folder. Could that be the issue here? I like the idea behind this plugin and I really want to see it in action. Any suggestions are highly appreciated! Cheers, Stefan EDIT: I would love to see an implementation of this plugin in the wild. Can anyone send me a link?
-
Problem with Path in @font-face src: url(...)
bytesource replied to bytesource's topic in General Support
@cstevensjr Thanks for this article. That was an interesting read! @adrian I have heard people say that base64 encoded fonts would load pretty fast, so I am really interested to hear about your personal experience when this tasks pops off of your list. @Fokke You saved me from my misery! After removing the alternative font (and changing $config->paths->templates to $config->urls->templates) the fonts finally loaded. For every font I also had to specify the font-style as either 'normal' or 'italic'. Otherwise all fonts would be displayed in italics. Just removing the font-style property from @font-face did not work. This is the final implementation: <?php // Import font based on the user language. $currentLanguage = $user->language->name; $fontPath = $config->urls->templates . "styles/my-fonts/open-sans/"; $css = ""; $fonts = array( 'Open Sans' => array( 'OpenSans-Light' => ['normal', 300], 'OpenSans-LightItalic' => ['italic', 300], 'OpenSans-Regular' => ['normal', 400], 'OpenSans-Italic' => ['italic', 400], 'OpenSans-Semibold' => ['normal', 600], 'OpenSans-SemiboldItalic' => ['italic', 600], 'OpenSans-Bold' => ['normal', 700], 'OpenSans-BoldItalic' => ['italic', 700] ), 'Open Sans Condensed' => array( 'OpenSans-CondLight' => ['normal', 300] ) ); switch ($currentLanguage) { case "default": // English case "ru": // Russian case "es": // Spanish foreach ($fonts as $font => $variations) { foreach ($variations as $variation => $properties) { // Target path: // site/templates/styles/my-fonts/open-sans/<user language>/<font name>-webfont.woff $url = $fontPath . $currentLanguage . "/" . $variation . "-webfont.woff"; $style = $properties[0]; $weight = $properties[1]; $css .= <<<CSS @font-face { font-family: '$font'; src: url('$url') format('woff'); font-weight: $weight; font-style: $style; } \n CSS; } }; break; default: echo "<h2>No CSS Font found!</h2>"; } echo $css; Sample output: @font-face { font-family: 'Open Sans'; src: url('/processwire/site/templates/styles/my-fonts/open-sans/default/OpenSans-Light-webfont.woff') format('woff'); font-weight: 300; font-style: normal; } @font-face { font-family: 'Open Sans'; src: url('/processwire/site/templates/styles/my-fonts/open-sans/default/OpenSans-LightItalic-webfont.woff') format('woff'); font-weight: 300; font-style: italic; } @font-face [...] I wanted to thank you all again for your help! As I am not a web developer by trade, I often get stuck at things that "just should work". Luckily, there is always some great people on the Processwire forum who point me in the right direction. Cheers, Stefan -
Problem with Path in @font-face src: url(...)
bytesource replied to bytesource's topic in General Support
@cstevensjr Normally I would do the same, but in this case I need to output the font-face in the <head> section. I assume a relative path to the font file in my case would have to start at the page root, but then again the following did not work, either: $path = "site/templates/styles/my-fonts/open-sans/" . "default/OpenSans-LightItalic-webfont.woff"; // site/templates/styles/my-fonts/open-sans/default/OpenSans-Light-webfont.woff $path = "/site/templates/styles/my-fonts/open-sans/" . "default/OpenSans-LightItalic-webfont.woff"; // /site/templates/styles/my-fonts/open-sans/default/OpenSans-Light-webfont.woff @Martjin I checked the file permissions, they seem to be OK: Owner: Read and write Group: Read and write Other: Read-only @Fokke I tried both. Currently the @font-face rules are placed before any other CSS rules. ================== This is the code in question. Maybe someone will find something I haven't seen yet: // site/templates/includes/partials/fonts/open-sans.php <?php // Import font based on the user language. $currentLanguage = $user->language->name; $fontPath = $config->paths->templates . "styles/my-fonts/open-sans/"; $css = ""; $fonts = array( 'Open Sans' => array( 'OpenSans-Light' => '300', 'OpenSans-LightItalic' => '300', 'OpenSans-Regular' => '400', 'OpenSans-Italic' => '400', 'OpenSans-Semibold' => '600', 'OpenSans-SemiboldItalic' => '600', 'OpenSans-Bold' => '700', 'OpenSans-BoldItalic' => '700' ), 'Open Sans Condensed' => array( 'OpenSans-CondLight' => '300' ) ); switch ($currentLanguage) { case "default": // English case "ru": // Russian case "es": // Spanish foreach ($fonts as $font => $styles) { foreach ($styles as $style => $weight) { // Target path: // site/templates/styles/my-fonts/open-sans/<user language>/<font name>-webfont.woff $url = $fontPath . $currentLanguage . "/" . $style . "-webfont.woff"; $css .= <<<CSS @font-face { font-family: '$font', sans-serif; src: url('$url') format('woff'); font-weight: $weight; font-style: normal; } \n CSS; } }; break; default: echo "<h2>No CSS Font found!</h2>"; } echo $css; // site/templates/_init.php <?php $partialsPath = $config->paths->templates . 'includes/partials/'; ?> // site/templates/_done.php <head> <style media="screen" type="text/css"> <?php include($partialsPath . "fonts/open-sans.php"); ?> </style> </head> Output: <head> <style media="screen" type="text/css"> @font-face { font-family: 'Open Sans', sans-serif; src: url('/<home path>/htdocs/site/templates/styles/my-fonts/open-sans/default/OpenSans-Light-webfont.woff') format('woff'); font-weight: 300; font-style: normal; } @font-face { font-family: 'Open Sans', sans-serif; src: url('/<home path>/htdocs/site/templates/styles/my-fonts/open-sans/default/OpenSans-LightItalic-webfont.woff') format('woff'); font-weight: 300; font-style: normal; } @font-face [...] </style> </head> Cheers, Stefan -
Hi, I downloaded the font Open Sans from FontSquirrel and want to include if using @font-face in the <head> section. The problem I haven't been able to get the path to the font file right. The actual path to one of the files is as follows: In the <head> of my my main template the following code gets output: // _done.php <style media="screen" type="text/css"> @font-face { font-family: 'Open Sans', sans-serif; src: url('<?php echo $path ?>') format('woff'); font-weight: 400; font-style: normal; } </style> Neither of the following has been working: $path = $config->urls->templates . "styles/my-fonts/open-sans/default/OpenSans-Regular-webfont.woff"; // /processwire/site/templates/styles/my-fonts/open-sans/default/OpenSans-Regular-webfont.woff $path = $config->paths->templates> "styles/my-fonts/open-sans/default/OpenSans-Regular-webfont.woff"; // /...home path.../htdocs/site/templates/styles/my-fonts/open-sans/default/OpenSans-LightItalic-webfont.woff I am therefore thinking the problem might be something different, but I have not been able to figure that out. The reason I am not using Google Fonts to import my fonts are because: Google Fonts is extremely slow within China, and sometimes seems to be blocked completely. In general, load times for sites located outside of China long, and I want to minimize this delay. Cheers, Stefan Edit: Normally I would just import the CSS in a separate file, but here I placed it inside <style> tags as the fonts to be used are chosen dynamically based on the current language. This is to reduce the total file size, which was quite high before.
-
@reems Thanks to your suggestions I solved the puzzle! Your mentioning that I was not using repeater_[fieldname] made me recall that I was using a symlink on this template. Turns out symlinks are not followed/not allowed on my web host, Hosteurope. So after copying the code from the destination of the symlink into the original file, everything was working again. Thanks again for your help! Cheers, Stefan
-
Hi, After uploading the /site/ folder to my web host and importing the database, I realized that a single repeater was not output correctly. Instead of rendering the content, only the path to the repeater's template is shown, and this is the path on my local machine: This is the code in question: home.php (page->advantages contains 3 items) <!-- ADVANTAGES BOXES - START --> <div class="row text-center"> <?php foreach ($page->advantages as $a): ?> <?php echo $a->render(); ?> <?php endforeach; ?> </div> <!-- ADVANTAGES BOXES - END --> repeater_services.php <div class="col-md-4 col"> <div class="icon-border bm10"> <i class="<?= $page->icon ?>"></i> </div> <h5 class="upper colored"><?= $page->subject ?></h5> <?= $page->summary ?> </div> The strange thing is that there is a second repeater on the same page using nearly exactly the same code, and this one is output correctly. I already emptied the cache, sessions, and ProCache folders, but that did not the trick, either. This is the site in questions: http://staging.sovonex.com The section "WHAT WE PROVIDE" is rendered correctly by a similar repeater, the section "YOUR ADVANTAGES" below is the result of the repeater I am having problems with. It would be great if someone could give me a hint as to where the error is. Cheers, Stefan
-
delete orphaned files/images from site/assets/files
bytesource replied to interrobang's topic in General Support
A quick update. Not adding image variations to the $valid array will get them removed. Although this includes variations that are still in use, these will be created again dynamically on the next page view. This is acceptable for me as I am using ProCache. As an example of the result, here is again the folder from above: 1) AFTER running the script with $valid[] = $f-basename commented out, but BEFORE page view: 19 images: 9 original size images 9 auto created "0x100" images 1 image I am not sure why it is there) 2) AFTER running the script and AFTER a page view: 37 images: 19 images from above: 9 thumbnails 9 PIM images with watermark Cheers, Stefan -
delete orphaned files/images from site/assets/files
bytesource replied to interrobang's topic in General Support
@horst I also believed orphaned images to be images not used any more, even if being a variation of an image that is still in use. I might be wrong, but to me it seems the following code prevents variations from being removed as they are all put into the $valid array: foreach ($file->getVariations() as $f) { $valid[] = $f->basename; } I made a backup, uncommented the line // $valid[] = $f->basename; and ran the script again. This time 579 images were removed. However, I am not sure if I also deleted those cropped images still acting as a thumbnail. Unfortunately I won't be able to test until tomorrow. Cheers, Stefan -
delete orphaned files/images from site/assets/files
bytesource replied to interrobang's topic in General Support
Hi, I ran this script and it successfully deleted 302 images. However, many other orphaned images where not deleted. For example, on one page I have a total number of 9 full-size images with a watermark (file names shown in blue below). Each of these images also has a cropped version acting as a thumbnail. This makes a total of 18 images, but the folder contains 77: The large number of orphaned files resulted in an assets folder of 120MB. The problem is that my shared hosting provider does not allow uploading zip files larger than 50MB. I went through the code, but could not find out why only some of the orphaned files were deleted. It therefore would be great if someone could give me a hint. I am running Processwire version 2.4.3 at the moment. I also set $keepPimVariations to false. Cheers, Stefan -
Understanding FieldtypeTextareaLanguage::wakeupValue
bytesource replied to bytesource's topic in Module/Plugin Development
Ryan, Thank you so much for this explanation! This helps me a lot in getting a better understanding of how all the pieces work together. Cheers, Stefan -
Understanding FieldtypeTextareaLanguage::wakeupValue
bytesource replied to bytesource's topic in Module/Plugin Development
@LostKobrakai I am often not sure which method to hook into as I don't know which methods are called - and in which order - before saving a page or when generating a page's output. If this kind of interaction between methods has been described somewhere before, I would be glad to hear about it! As for placing the error handling in a different module, this is a good idea as I already made a textformatter transforming link markup into HTML links. Of course, I'd still prefer to have both implementations - the transformation and error handling - inside a single module. @host To be honest, I haven't paid much attention to the Hanna Code module before, but looking at the module description now I see whole lot of possibilities. You are right, using Hanna Code to add the link transformation functionality would have been a good choice. I understand that Hanna Code is used as a textformatter, so I still would need to implement the error handling in a separate module. Cheers, Stefan -
Understanding FieldtypeTextareaLanguage::wakeupValue
bytesource replied to bytesource's topic in Module/Plugin Development
@Wanze autoload => true did the trick! Thank a lot for this suggestion. However, now I get the following warning: In fact, var_dump($value) shows that $value is an array and not a string as I expected: But most of all I realized that the HTML links this module produces get inserted back into the textarea field, instead of just being output on page load. What I want to accomplish is to dynamically transform the link markup into HTML links without altering the original markup. Otherwise the advantages of using the page ID for identification of a page would get lost. Is there another method I could hook into, or should I just implement this functionality by extending Textformatter? But then again I like the ability of showing error messages right in the admin if a page does not exists or is in the trash, and if I am not mistaken this is not possible when using a text formatter. Cheers, Stefan -
Hi, I am am working on a little module that converts markup such as =(123:link text) to the respective hyperlink. 123 in the example is the page ID. The following code was mainly taken from Ryan's Page Link Abstractor, with only a few changes to the regex. I am also hooking into FieldtypeTextareaLanguage::wakeupValue as this is the field type I use for all textareas: class HyperlinkMarkup extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Hyperlink Markup', 'version' => 1, 'summary' => "Adds Hyperlinks based on the ID of a page using special markup \n Example: =(123:link text)" ); } /** * Initialize the module * */ public function init() { $this->addHookBefore('FieldtypeTextarea::wakeupValue', $this, 'wakeupValue'); $this->addHookBefore('FieldtypeTextareaLanguage::wakeupValue', $this, 'wakeupValue'); } /** * Hook into FieldtypeTextarea::wakeupValue to convert abstract URL representations to actual URLs * * Page URLs are represented by =(123:link text) where "123" is the Page's ID. * */ public function wakeupValue($event) { // Adapted wakeupValue() from the Page Link Abstractor module: // https://github.com/ryancramerdesign/PW2-PageLinkAbstractor/blob/master/PageLinkAbstractor.module#L104 $arguments = $event->arguments; // // $page, $field, $value $value = $arguments[2]; if(empty($value)) return; $changes = 0; $errors = array(); /** * Hook into FieldtypeTextarea::wakeupValue to convert abstract URL representations to actual URLs * * Page URLs are represented by =(123:link text) where "123" is the Page's ID. * */ if(strpos($value, '=(') !== false) { if(preg_match_all('/=\((\d+)[^)]+)\)/', $value, $matches)) { // $matches[0] => whole string // $matches[1] => first bracket match // $matches[2] => second bracket match foreach($matches[1] as $key => $id) { $p = $this->pages->get((int) $id); // Link to non-existend page if (!$p->id) { $errors[] = "links to page ID $id that does not exist"; continue; } // Link to page in trash if ($p->isTrash()) { $errors[] = "links to page ID $id that is in the trash"; continue; } $url = $p->url; $linktext = $matches[2][$key]; $hyperlink = "<a href='$url'>$linktext</a>"; $value = str_replace($matches[0][$key], $hyperlink, $value); $changes++; } if ($changes) { $arguments[2] = $value; $event->arguments = $arguments; } if (count($errors)) { foreach($errors as $error) $this->error("Page {$page->path} $error"); } } } } } The problem is that this module does not seem to get called. For example, inserting an echo statement at the beginning of wakeupValue() doesn't get output. I already implemented the module as a Textformatter and this one is working, so I assume wakeupValue() might not be the correct function to hook into here. The reason I am also working on this implementation, is because I want to take advantage of the function $this->error(), and I think this not available with a Textformatter. So it would be great if anybody could give me a hint as to how to get this module working. Cheers, Stefan
-
Hi Pete, In the end I only needed the two textarea fields headline and summary, so I did not try out the image field. Cheers, Stefan