Jump to content

JoshoB

Members
  • Posts

    115
  • Joined

  • Last visited

Everything posted by JoshoB

  1. For a client, I have to convert 4900 pictures to pages in ProcessWire. The pictures are organized into directories, and the structure has to preserved. So for the directories I want to create pages with the template "pictures", while the images will have the template "picture". There's already quite a few images that have been uploaded by hand, so these new pictures will be made children of a new page "a2" (name/url). Now, I've tried the below code (the contents of a new page with a template "conversion" that should be run inside ProcessWire), but I'm getting an error about an unknown selector. No doubt there's a problem in the function with calling $pages, but I can't see what it is. Could someone have a look, or post a better solution to what I'm trying to do? Thanks! Edit: updated function, which still doesn't work. function listFolderFiles($dir, $root) { $pages = wire('pages'); $ffs = scandir($dir); echo '<ol>'; foreach($ffs as $ff){ if($ff != '.' && $ff != '..'){ echo '<li>'.$ff; // This is a directory if(is_dir($dir.'/'.$ff)) { // Set title and template $title = $ff; $template = 'pictures'; // Set parent $parent = explode("/", $dir); $parent = end($parent); if(strlen($parent) > 30) $parent = 'a2'; $parent = trim($parent); // Set selector $selector = 'name=' . $parent . ', template=pictures, id>16521, include=all'; // Create page $pictureList = new Page(); $pictureList->template = $pages->get($template); $pictureList->parent = $pages->get($selector); $pictureList->title = $title; $pictureList->save(); // Output echo ' [DIR - title = ' . $title . ' and template = ' . $template . '; parent = ' . $parent . ']'; listFolderFiles($dir.'/'.$ff); } // This is a picture else { // Remove extension from filename for title $filebroken = explode( '.', $ff); $extension = array_pop($filebroken); $title = implode('.', $filebroken); $title = str_replace("_", "-", $title); // Set parent $parent = explode("/", $dir); $parent = end($parent); $parent = trim($parent); // Set template $template = 'picture'; // Set selector $selector = 'name=' . $parent . ', template=pictures, id>16521, include=all'; // Create page $picture = new Page(); $picture->template = $pages->get($template); $picture->parent = $pages->get($selector); $picture->title = $title; $picture->save(); // Upload picture $picture->images->add($ff); $picture->save(); // Output echo ' [FILE - title = ' . $title . ' and template = ' . $template . '; parent = ' . $parent . ']'; } echo '</li>'; } } echo '</ol>'; } // Create output echo '<pre>' . "\n"; echo '==================' . "\n"; echo 'Picture conversion' . "\n"; echo '==================' . "\n\n"; // Set directory $dir = "D:\Websites\example.org\www\photos"; // Parent (root) page $root = $pages->get("name=a2, template=pictures, include=all"); echo 'Parent is located <a href="' . $root->url . '">here</a>.' . "\n\n"; // Go through directories and files listFolderFiles($dir, $root); // Close output echo '</pre>' . "\n";
  2. Hi Wanze, Thanks for your help. Disk space is not an issue. Where do I check the permissions for the user? Test.php was dropped in the root, by the way -- I cannot get it to run in /assets/files/ (as ProcessWire intercepts it when I call it via the address bar). I know about the security issues with 777, but it cannot be helped. The server is a pain.
  3. I've been struggling with a website for a client on a scale not experienced before. We managed to get almost everything operational. The only problem now is that when I try to add a new page, the system doesn't make (or is unable to make) a new directory under /site/assets/files/. This means that when I try to upload images, the bar goes to 100% and then the picture disappears, giving an error: destinationPath is empty or does not exist. But why doesn't ProcessWire create these directories? Permissions are all set to 777 (out of desperation). The host says they cannot provide support and lay the blame at ProcessWire's feet. Never before have I had this many problems and I assume it's a problem with the server configuration. However, if anyone has any ideas where I can even start to find a solution to this problem, it would be greatly appreciated, as always. Edit: I created a test.php file and put this on the server. When I run it, it does create a folder, so I'm stumped: if(!mkdir('delete-this-test-folder')) { print_r(error_get_last()); }
  4. We solved it eventually by reinstalling ProcessWire, then copying the new stuff under /site (and importing the database). It worked, except that we have a different problem now. I'll start a new thread.
  5. Thanks for the reply. It's the latest version of ProcessWire. The charset must be the same. When I add $config->sessionName = session_name(); at the end of config.php, the error stays the same (unknown charset ''). Note that it says the charset is blank. This did not happen offline nor on my own server. The database was changed to various kinds of UTF8, all to no avail. The hosting company says it's our problem. I am, frankly, at my wit's end.
  6. This has been slowly driving me insane since yesterday evening. Have a look here, please: http://rhosonics.nl/index2.php The error message is this: Error: Exception: SQLSTATE[42000] [1115] Unknown character set: '' (in /sites/rhosonics.nl/www/wire/core/ProcessWire.php line 186) I don't know how to fix this. It worked fine on XAMPP (offline) and it worked fine on my own server. On the client's server, however (same host!), the error above pops up. I have tried everything I could think of, but cannot get it fixed. Does anyone know what the issue might be? Thanks very much!
  7. "Solved" the issue by commenting out the contents of the function in question (part of core). Image fields work now. I'll remove the comments when the site's been moved to its definitive location and see if the issue reappears. Edit: and apologies for posting three times in a row. ;-)
  8. I've read elsewhere that switching to OldSchool could work. However, where do I implement this? Edit: increased PHP memory limit via PHP (in config.php). I managed to upload one picture. All others afterwards failed with the same non-error (getting stuck at 100%). It's quite frustrating. :-/ Edit 2: Apache error logs keep referring to this: "PHP Warning: set_time_limit() has been disabled for security reasons in /sites/XYZ.com/test/wire/core/ImageSizer.php". I'm guessing that's the problem. No idea how to fix it, though. Never had this issue before.
  9. I've removed the CropImage module and am using the default Images field. I still get problems! Specifically, I get this one: "Pageimages: Removed 'images' temp file(s) for page". I'm guessing it's perhaps some kind of permissions problem? Strangely, it sometimes *does* work in Chrome. I've never experienced something like this. Edit: could be a server problem? Like I said, it worked fine on XAMPP. Just don't know where to look...
  10. I'm having the exact same problem. I'm using the CropImages modules (to get neat thumbnails). It's working on XAMPP offline, but doesn't work when the site is online on my server. I've tried the .htaccess trick, but it isn't working: the file gets uploaded (supposedly), reaches 100%, and then nothing happens. I have debugging on and I get this message: "Pageimages: Removed 'images' temp file(s) for page /applications/h2so4-oleum/ - applications-h2so4.jpg, applications-h2so4-1.jpg". I've added the temporary directory to config.php (it wasn't included there), and even manually added the directory under /assets, but no luck so far. I've changed permissions to be very lenient (for testing purposes), but that didn't seem to have any effect either. In developer tools, I'm getting this error: "Warning: set_time_limit() has been disabled for security reasons" (and I have no idea why -- I didn't specify a time limit anywhere and don't have direct access to php.ini on my host). Any ideas on how to solve this? Edit: something curious just happened -- I get the same error in Chrome, but unlike Firefox, the images do appear to get uploaded. (But only if you leave it on for a while, apparently.) Edit 2: I think the problem is in the CropImage module -- I made a test field with a regular image field type and that works as expected. I got an error about ImageSizer at one point, but haven't seen it again. So there's a problem with the module. (I'm using Apeisa's latest version).
  11. Greetings! I have what I hope is a simple question. How do I retrieve the original URL when ProcessWire throws a 404 Error? Specifically, I want to log which URLs lead to a 404, but at present it seems that URLs that cannot be found are redirected to the 404 page behind the scenes, with no obvious way (for me) to retrieve the URL that the user originally requested. Thanks in advance!
  12. Suddenly had a bright idea. The missing pages were set to "hidden". I needed to use: $results = $pages->find("url_old!='',include=hidden"); I'm leaving this page as a monument to my own stupidity.
  13. I am rebuilding a website. Templates include a field "url_old" with a href to the page's URL on the old website. By surfing to the /redirect, the system should generate a list that can be copied and pasted into a .htaccess file. In order to find all of the pages that need to be redirected, I use the following in the template "redirect" (used by a single page located at home/redirect/): $results = $pages->find("url_old!=''"); To the best of my knowledge, $results should contain ALL pages with a field "url_old" that isn't empty. However, when the data is generated, it includes only the home page and all of the home page's children that have children of their own. Let me illustrate with an example: Home |- Page 1 |- Page 2 | |- Page A | |- Page B |- Page 3 |- Page 4 Let's assume that all of these pages have the "url_old" field filled in. You would expect the system to generate a list of ALL of these pages. Instead, it only lists "Home", "Page 2", "Page A", and "Page B". Somehow, it skips "Page 1" and the others. (When I do a count() of $results, it also lists just the pages that are shown, so 4 in this example, instead of 7.) I get the idea that I'm missing something obvious, but I can't see what. Anyone care to help?
  14. I finally solved it, thanks to the module you linked to. This worked for me: class TextformatterImageCaptionWrapper extends Textformatter { // Module information public static function getModuleInfo() { return array( 'title' => 'Image Caption Wrapper', 'version' => 1, 'summary' => "Adds a wrapper to images to support the use of captions drawn from alt-texts." ); } // Formatting function use by TextFormatter public function format(&$str) { if (!preg_match_all('#<a*[^>]*><img.*? alt="(.*?)".*?></a>#si', $str, $matches)) return; // iterate over found matches foreach($matches[0] as $key => $value) { $caption = ""; if ($matches[1][$key]) $caption = "<div class='caption'>{$matches[1][$key]}</div>"; $class = "image_wrap"; if ($caption) $class .= " with_caption"; if (preg_match('# class="(.*?)"#si', $value, $match)) { $class .= " {$match[1]}"; } $image = '<div class="image">' . $value . '</div>'; $out = "<div class='{$class}'>{$image}{$caption}</div>"; // replace original tag ($line) with wrapped one ($out) $str = str_replace($value, $out, $str); } } } I'd like the A-tag to be optional, but I'll deal with that problem later. Thanks for all the help and your patience!
  15. Martijn's module would be nice, but it doesn't function on my site, either. Do you have any idea what kind of regular expression would work? I tried a DOM-like method, and while it extracted the alt texts just fine, there was no way -- that I could see -- to insert them properly back into the page.
  16. No luck; sorry, Adrian. Disabling the ImagesToPages module doesn't resolve the error that your module gives me. It also has the downside of apparently attempting to add a caption to every image, and I only need captions in the body field. I've been trying to regex my way to hacking a module together to: (a) wrap the image (and a possible a-tag) into an HTML5 "figure" tag, and; (b) to extract the alt-text and wrap that inside a "figcaption" tag beneath the image and inside the "figure" tag. I got quite far, but matching one with the other (alt text to image) and having it all play nice is turning out to be impossible for me. I finally managed to get an ugly hack together to wrap the image and a-tag in a figure-tag, but that caused problems with the p-tag that the image is in, for some reason (in Firefox). I've been going over and over this for some time now and it's getting a little frustrating. Anyway, I'll leave it for now. If someone has any idea to solve this...
  17. Hi Adrian! Thanks for the update. Unfortunately, the problem remains: the module adds a doctype-statement to every image. Not sure why. Like I said, I guess it just doesn't play nice with the ImagesToPages module. I will have a closer look at your code and see if I can find anything... Edit: by the way, all images have a properly filled-in description field.
  18. Thanks for the link Adrian. I had used that thread before, but none of the solutions work for me, including yours. When I use your module, ProcessWire adds doctype-statements before the images (which is erroneous), but doesn't add a caption. Any idea how to solve that? Edit: one problem for the JS solutions is the fact that because the images are linked, the DIVs are placed inside the A-tags, which causes problems. What I need something that checks if the image is linked yes/no and then applies the DIVs around the A-tag for the picture (but not the caption). It's a little complex at the moment.
  19. I am having some trouble finding a solution to render captions for the images that are linked in this way. I want to avoid using JavaScript, but all of the extant modules like ImageInterceptor seem either not to function correctly either or just plain overkill. Is there a way to modify the code above to also output a caption for the figure, and/or perhaps wrap the whole thing in HTML5 figure and figcaption tags? I've been trying for days, but it has got me stumped. I thought the AutoSchema module would work well, but it generates an error and I don't understand why (claims there's a reference to a method that doesn't exist, but it does).
  20. Wow, Ryan, thanks a lot! Yes, I may not have explained it very well at first. The object is to have all the pictures together (under /pictures/), so that they can be browsed and searched similar to Wikimedia Commons. Regular pages don't have an images field; instead, you select the picture page itself and then insert those images in the page. When you click on the image, it should take you to the description. This really works excellently; thanks again. I'd be interested to know more about writing your own Textformatter module.
  21. Happy New Year everyone! For a large website project, images are all separate pages that contain a bunch of data, similar to image pages on Wikimedia Commons. When you want to add an image to another page, you have to load them from the Wikimedia-like page. This all works as expected. I also enable "Link to larger version". However, when someone clicks the image, instead of just showing a larger version of the same picture, I want the user to be shown the page with all the extra data, including the name of the creator and the licence under which the picture is available. Now, I think this can be done using regular expressions, but I cannot seem to get it done. I have created a function to pass $page->body through that then searches for HREF-attributes for pictures (stored in assets). What I want is to have the "larger version"-link be replaced by a link to the picture page. I cannot wrap my head around it, however. Is there a kind soul who can help me out? Simply put, I want the function to search through $page->body, when it finds something like: '/href="\/cms\/site\/assets\/files\/(\w+)\/(\w+).(\w+)"/i' I want it to replace that with a link to the picture page, for example 'href="example-page/target/"'. Any tips?
  22. As an update, downloading a fresh ZIP-archive of ProcessWire and dropping FieldtypeComments on the server did not solve the problem, so the issue is related somehow to the templates. But the only file that was modified, as far as I can tell, was markup/comments.php. Commenting out the array inside $page->comments->renderForm doesn't seem to do anything, either; I keep getting that error. Edit: I also deleted all of the spam comments, thinking that perhaps this was what caused the problem. No luck, either. Edit 2: reverting markup/comments.php to an earlier version also seems not to have changed anything. I'm starting the think the problem is located somewhere deeper, but I cannot remember changing any other files. Could it be a problem on the server somehow? My host changing some setting somewhere? Seems unlikely.
  23. Thanks for the reply! I never make any changes to core, so the module files are all as they were. I have removed the security_field trick, so I'm not sure what's causing the problem now. The relevant part of the code, in markup/comments.php (blog profile), is this: // If we are viewing a post page, then output a comments form if($page->template == 'post') { // Add the category so we can change the colour of the submit button $id = trim($page->category); $category = $pages->get($id); $short_category = str_replace(" ", "-", $category->title); $class = (isset($short_category) && trim($short_category) != "")? "-" . strtolower($short_category) : ""; echo "<div id=\"comment-form" . $class . "\">"; // Render the form echo $page->comments->renderForm(array( 'headline' => '<h4>' . __('Post a comment') . '</h4>', // Post comment headline 'successMessage' => "<p>" . __('Thank you, your submission has been saved.') . "</p>", 'pendingMessage' => "<p>" . __('Thank you, your comment has been submitted and is pending approval.') . "</p>", 'errorMessage' => "<p>" . __('Your submission was not saved due to one or more errors. Try again.') . "</p>", 'redirectAfterPost' => true )); // Close the divs echo "</div>"; // Colour change div echo "</div>"; // Close #comments } I cannot figure out what is causing the problem now. Edit: I originally stuck 'requireSecurityField' => 'security_field' above 'redirectAfterPost', which is when the problem started to occur. Removing it did not solve the issue.
  24. In an attempt to fend off comment spam, I apparently made a change that screwed ProcessWire up in a manner that I am unable to solve. Trying to post a comment now results in the following error: === Error: Exception: Can't save field from page 1410: /blog/ancient-greeks-in-egypt/: Call $page->setOutputFormatting(false) before getting/setting values that will be modified and saved. [Page::statusCorrupted] (in /sites/netjer.nl/www/wire/core/Pages.php line 654) #0 [internal function]: Pages->___saveField(Object(Page), 'comments') #1 /sites/netjer.nl/www/wire/core/Wire.php(271): call_user_func_array(Array, Array) #2 /sites/netjer.nl/www/wire/core/Wire.php(229): Wire->runHooks('saveField', Array) #3 /sites/netjer.nl/www/wire/core/Page.php(1004): Wire->__call('saveField', Array) #4 /sites/netjer.nl/www/wire/core/Page.php(1004): Pages->saveField(Object(Page), 'comments') #5 /sites/netjer.nl/www/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php(316): Page->save('comments') #6 /sites/netjer.nl/www/wire/modules/Fieldtype/FieldtypeComments/CommentForm.php(229): CommentForm->processInput() #7 /sites/netjer.nl/www/wire/modules/Fieldtype/FieldtypeComments/CommentArray.php(63): CommentForm->render() #8 /sites/netjer. This error message was shown because you are logged in as a Superuser. Error has been logged. === I am using a modified version of the blog profile. The only thing I changed at one point was to add the security_field trick to $page->comments->renderForm that Ryan once posted on these boards as a simple way to try to block spammers (it works with hiding/showing the form using CSS and JavaScript). Removing it did not solve the problem. I looked at some other files, including the renderComments function that comes with the blog profile, but I didn't change anything there. Another possibility: I changed the status of spammed comments to "spam" before the error occurred. I don't think that's the problem, because I get these errors even on pages with zero comments. Where does one put $page->setOutputFormatting(false) in this case, and why was it not required earlier? Thanks for your help!
×
×
  • Create New...