Jump to content

a-ok

Members
  • Posts

    812
  • Joined

  • Last visited

Everything posted by a-ok

  1. Folks. Hope everyone is well. I'm attempting to move some Tumblr content to PW using the API. I have the below, which seems to work fine, except even though the images are uploaded (they appear in the appropriate assets/files/** folder), when I go to edit the page the images are all removed with the message Pageimages: Removed 'images' temp file(s) for page... Any thoughts where I'm going wrong? $url = $config->paths->templates . "tumblr/posts/posts.xml"; $xml = simplexml_load_file($url); $i = 0; foreach ($xml->posts->post as $post) { bdb($post); $attributes = $post->attributes(); $date = $sanitizer->date($attributes["unix-timestamp"]); $text = str_replace('</p>', '', $post->{"photo-caption"}); $text = explode('<p>', $text); $title = $sanitizer->text($text[2]); $description = array_slice($text, 3); $p = new Page(); $p->template = "blogSingle"; $p->parent = "/blog/"; $p->of(false); $p->title = $title; $p->date = $date; $descriptionString = ''; foreach ($description as $d) { $descriptionString .= "<p>" . $d . "</p>"; } $p->textarea = $descriptionString; $p->save(); if (count($post->photoset) > 0) { foreach ($post->{"photoset"}->{"photo"} as $images) { $image = $sanitizer->url($images->{"photo-url"}[0]); $p->images->add($image); $p->save(); } } else { $image = $sanitizer->url($post->{"photo-url"}[0]); $p->images->add($image); $p->save(); } $p->save(); $i++; if ($i == 2) break; }
  2. I ended up just doing foreach ($testimonials as $t) { if ($t->type == "testimonial") { $t->title = $t->getForPage()->title . ' — ' . $event->sanitizer->truncate($t->global_textarea, 40); $testimonialsNew->add($t); } } Which seemed to work fine but I would've though I could've queried by the repeater matrix type within the selector... but maybe not?
  3. I'm looking to return repeater matrix rows (pages) where the type is equal to testimonial $testimonials = $event->pages->find("template=repeater_modules, modules.type=testimonial, include=all"); This seems to return all repeater pages and simply ignores the `modules.type=testimonial` selector. Have I got this wrong? If I barDump out `$testimonials->explode('type')`, one of the entries returned is "testimonial" so I'm a bit confused.
  4. Question. Is there a way to see all the available properties on a module? I use RepeaterMatrix quite a bit and use the 'type' property within the loop but I also want to return the name/label of each type and I wondered if there was any way to see what else is available other than $row->type? This is just one example, of course...
  5. Any thoughts about SASS/CSS variable names? My guess would be to follow CSS naming convention but then they look like class names rather than variables (but maybe that is also okay). This hole is deep...
  6. YES! What about assets? symbol__arrow--next.svg? symbol-arrow-next.svg?
  7. This answer. Perfect. What about template and field names within PW? Thoughts?
  8. Go on... I wonder if Atom does this...
  9. Not sure if this has been brought up before (probably not because it's a bit mental) but do you have any specific file name conventions? I struggle between matching the file extension language (phpFile.php, jsFile.php, appWtf-dunno__v1.scss) and just OS naming (hyphen only). Am I overthinking this? Does the consistency matter? I've noticed the ProcessWire filenames vary (sometimes even PascalCase) and wondered if there was a pattern I was missing?
  10. Is it possible to get this working for a repeater? I seem to get the error Exception: Method RepeaterPageArray::chunk does not exist or is not callable in this context
  11. Apologies to bring this back up but I'm curious to know why this doesn't work for standard repeaters? They use a separate template, for example 'repeater_about', so even if I change this by editing the template by showing the system templates it still doesn't work. Considering repeater rows are 'pages' and use their own template... you would think it would work?
  12. Any thoughts? Even a manual fix for now (hook or otherwise?)
  13. When I add a new user, even if the 'UIkit' theme is selected (by default), upon creating the user then logging in as said user the theme is the default theme. If I go to the profile, no options are selected. If I select 'UIkit' here and save it's all fine. Any thoughts? I'm on Processwire 3.0.123 but I've had this issue since using v3. *UPDATE* I actually just uninstalled the default theme but it's just the 'non' theme that it seems to use even though UIkit is selected on creation.
  14. $submissions = $pages->get("template=home")->submissions; foreach ($submissions as $s) { $s->delete(); $s->save(); } $pages->get("template=home")->save(); This worked! But so many saves? I never know.
  15. Thanks. This doesn't seem to work either, weirdly. $submissions = $pages->get("template=home")->submissions; foreach($submissions as $s) { $s->delete(); } $submissions->save();
  16. Sorry, I'm confused. I'd like to remove all rows but keep the repeater. Upon removing the ->of(false) it still doesn't delete all the rows.
  17. No, sorry. I haven't set up the cronjob yet... just testing the code. It returns: Exception: Method RepeaterPageArray::of does not exist or is not callable in this context
  18. Does anyone know why the following doesn't work? The page would be called via a cronjob... if ($input->get->run) { // Reset submissions if ($input->get->run == "resetSubmissions") { $submissions = $pages->get("template=home")->submissions; $submissions->of(false); $submissions->removeAll(); $submissions->save(); bdb('resetSubmissions has been run'); } }
  19. This is very cool. Much appreciated. @BitPoet Many thanks for your help. I ended up using your example and doing something like so.. $submissionsNames = array(); foreach ($page->submissions as $submission) { $name = ucwords(strtolower($submission->submissions_firstname . " " . $submission->submissions_lastname)); array_push($submissionsNames, $name); } $submissionsNames = array_count_values($submissionsNames); ksort($submissionsNames); arsort($submissionsNames); $submissionsNames = array_slice($submissionsNames, 0, 5); Let me know if you think I've missed a trick?
  20. Is there any reason why the CPU on my server would spike to above 70% and crashing (effectively) when entering a really long title for a page? The title in question is: Arts Facades: incorporating Duke of York’s Theatre, Harold Pinter Theatre, Phoenix Theatre, Fortune Theatre This has never happened to me before so any advice/debugging you can suggest would be appreciated.
  21. I've got a basic AJAX submission form set up for a poll – the user enters a first and last name or a person they'd like to nominate and upon submission it stores the first and last name, as well as IP address and timestamp within a repeater row. The user can only submit, using the same IP address, once within a 24 hour period (done by cross-checking their IP with entries in the repeater as well as the difference between timestamps). I now want to return a 'live top 5' – like a leaderboard – (taking all first and last name entries and doing a 'count'). This is where I'm stuck at the most efficient way to do this. Counts need to be case-insensitive (michael jordan and MICHAEL JORDAN and miCHAel joRdaN would total three, not one each) and then should, ideally, sentence-case the returned top 5 along with the count What do you think? Thanks in advance for any advice.
  22. Ahh. Your example was fine though; it was my original that wasn't. Who knows. Hate that! Thanks for all the help, you too @bernhard
  23. Now I'm confused. That didn't work but that made it almost 100% like your example. I commented mine out and put back yours and it worked. Bizarre. I even put wire()-> back in instead of $this and it still worked – maybe a hidden glyph or something?
  24. Brilliant. That does work. Why would the first code work, but not the second? if ($this->page->template == 'admin') { function customPageName(HookEvent $event) { $dummy = 'hook-generated'; $page = $event->arguments(0); if ($page->template->name == 'work-detail') { if ($page->global_text) { $pageName = wire()->sanitizer->pageName($page->title . '-' . $page->global_text, true); } else { $pageName = wire()->sanitizer->pageName($page->title, true); } $page->setOutputFormatting(false); $page->name = $pageName; } } $this->addHookAfter('Pages::saveReady', null, 'customPageName'); }; function myHook(HookEvent $event) { $page = $event->arguments(0); if ($page->template->name == 'work-detail') { if ($page->global_text) { $pageName = wire()->sanitizer->pageName($page->title . '-' . $page->global_text, true); } else { $pageName = wire()->sanitizer->pageName($page->title, true); } $page->setOutputFormatting(false); $page->name = $pageName; } } wire()->addHookAfter('Pages::saveReady', null, 'myHook');
  25. Many thanks for this. I haven't tried it yet but what's the fundamental difference here? The "$page->name =" rather than "setAndSave"?
×
×
  • Create New...