Jump to content

picarica

Members
  • Posts

    66
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

picarica's Achievements

Full Member

Full Member (4/6)

7

Reputation

  1. Hello so i am working on a hook and this hook should include setup, 1. have one or multiple zip files in one file field, Run 1. let hook unzip each file and input the unziped files into newly created page the problem, i wanted to use $files->tempDir() method in hook but i guess it't not hookalbe so i get error Undefined variable: files in at line $page->title = $files->tempDir(); i did this as test and it doesnt work, i whole setup looks like this $this->addHookAfter('Pages::saveReady', function(HookEvent $event) { // Get the object the event occurred on, if needed $pages = $event->object; // An 'after' hook can retrieve and/or modify the return value $return = $event->return; // Get values of arguments sent to hook (if needed) $page = $event->arguments(0); if(empty($page->id)) return; if($page->template == "generator") { foreach($page->multi_gen as $gen){ wireUnzipFile($gen->url, "my-file/"); if($this->pages->get("parent={$page->name}, name={$gen->basename}")->id) continue; $np = new Page(); $np->of(false); $np->template = $this->templates->get("hry_home"); // I changed the template name here too //$np->title = $tatel; $np->name = $np->title; // I wanted the page name to match the title $np->parent = $page; $np->save(); //$np->image->add($image->filename); //$np->image->last()->description = $image->description; //$np->save(); //// These lines work to remove the image from the parent page ////$page->images->remove($image); $page->save(); } } $event->return = $return; }); and i still haven passed the frist line containint wireunzipfile, is there any other way to do this? i ran out of ideas, now i know of that i can check in a file field that automaticaly unzipes files, the problem will be that when there will be alot of zip files, its gonna be confusing nad it will be harder to move exact files to the newly created page
  2. tried it maybe my processwire instalation broken? or it doesnt work when its in ready.php but this is all i have and it's not working <?php $this->addHookAfter('Pages::saveReady', function(HookEvent $event) { // Get the object the event occurred on, if needed $pages = $event->object; // An 'after' hook can retrieve and/or modify the return value $return = $event->return; // Get values of arguments sent to hook (if needed) $page = $event->arguments(0); $page->title = "test?"; // Populate back return value, if you have modified it $event->return = $return; }); ?>
  3. well u can check ill put all hooks i have, and the behavies is still the same, i crea page with temporary title ex. "ss" i upload .xml file then save, name update but title remains "ss" here is my whole hook <?php $this->addHookAfter('Pages::saveReady', function(HookEvent $event) { // Get the object the event occurred on, if needed $pages = $event->object; // An 'after' hook can retrieve and/or modify the return value $return = $event->return; // Get values of arguments sent to hook (if needed) $page = $event->arguments(0); // tento hook pojde len na jeden template if($page->template != 'hry_home') return; // pokail stranka este neni vytvorena (Nema ID) tak nepokracuj zo scriptom if(empty($page->id)) return; if(count($page->subor_hry) < 1) return; if (count($page->subor_hry) > 1) { // TENTO HOOK VHADZUJE TITLE URL A DESSCRIPTION Z XMLka VELMI NEBEZPECNE $page->size = strlen($page->body); if(strlen($page->body)){ //not empty } else { $meta = "meta.xml"; foreach($page->subor_hry as $file) { if(strpos($file, $meta) !== false){ $xmlmeta = file_get_contents($file->filename()); } } $desc = new SimpleXMLElement($xmlmeta); $page->body = $desc->description; // $page->size = '222'; } $meta = "meta.xml"; foreach($page->subor_hry as $file) { if(strpos($file, $meta) !== false){ $xmlmeta = file_get_contents($file->filename()); } } $desc = new SimpleXMLElement($xmlmeta); // Provides: Hll Wrld f PHP $onlyconsonants = str_replace($vowels, "", "Hello World of PHP"); $badstring = array(" (Flash Game)", "(Flash Game)", "(flash game)", " (flash game)", "flash game", " flash game"); $newtitle = str_replace($badstring, "", $desc->title); $page->title = $newtitle; $page->name = $newtitle; // TENTO HOOK VHADZUJE TITLE URL A DESSCRIPTION Z XMLka VELMI NEBEZPECNE // Zobrat obrazok zo file fieldu a hodit do imagetype fieldu $word = ".png"; foreach($page->subor_hry as $file) { if(strpos($file, $word) !== false){ $png = new Pageimage($page->images_thumb, $file->filename()); } } $word = ".jpg"; foreach($page->subor_hry as $file) { if(strpos($file, $word) !== false){ $jpg = new Pageimage($page->images_thumb, $file->filename()); } } if(empty($png)){ $page->images_thumb = $jpg; } else { $page->images_thumb = $png; } } // Populate back return value, if you have modified it $event->return = $return; }); ?> i have no idea too why it happens i tried putting the title rewrite out of if statements but remains same, i only have condiditon if body isnt empty dont rewrite it but that' it
  4. yes the title updates everything else updates but title only updates if its empty before saving, thats the issue
  5. so i started recently working on hooks i makde hook that after page create i upload .xml file and from that i get title into variable and i paste it into name(url) and title, the name(url) is replaced but title isnt? why is that i have it like this $page->title = $newtitle; $page->name = $newtitle; and i have that in $this->addHookAfter('Pages::saveReady', function(HookEvent $event) { // Get the object the event occurred on, if needed $pages = $event->object; // An 'after' hook can retrieve and/or modify the return value $return = $event->return; // Get values of arguments sent to hook (if needed) $page = $event->arguments(0); // tento hook pojde len na jeden template if($page->template != 'hry_home') return; // pokail stranka este neni vytvorena (Nema ID) tak nepokracuj zo scriptom if(empty($page->id)) return; these are also my if statements so that it doesnt run off when it shouldn't, also this is in my ready.php file so question is how ca ni force to overwrite my title field ? after save
  6. wow that worked, but why, i kinda dont get it? root of children dont get change when on child url, why did it worked?
  7. Hello so i managed to implement pagination to my site, i have navigation rendering done like so $out = ''; $root = $pages->get("/"); $children = $root->children("limit=150"); // $children->prepend($root); foreach($children as $child) { if($child->numChildren && $child->id !== 1) {// @note: you could do some more checks here; $out .= "<li>"; $out .= "<a class='dropdown' href='javascript:void(0);'>{$child->title}</a>"; $out .= "<ul>"; foreach($child->children as $level1) { if ($level1->hasChildren()) { $out .= "<li>"; /* if ($level1->numChildren()) { $out .= "<a href='{$level1->url}'>{$level1->title}</a>"; $out .= "<ul>"; foreach($level1->children as $level2) { $out .= "<li>"; $out .= "<a href='$level2->url'>$level2->title</a>"; $out .= "</li>"; } $out .= "</ul>"; } else { */ $out .= "<a href='{$level1->url}'>{$level1->title}</a>"; /* } */ $out .= "</li>"; } } $out .= "</ul>"; $out .= "</li>"; } else { $out .= "<li><a href='{$child->url}'>{$child->title}</a></li>"; } } echo $out; echo "<li><a href='{$root->url}'>{$root->title}</a></li>"; which works flawlessy for my page withing children any page, except when i enter pagination the whole menu entry dissapears as i click link to page2 in pagination, idk why but when my url is www.page.sk/page2/ my navigation dissapears except the last entry which is echo "<li><a href='{$root->url}'>{$root->title}</a></li>"; i tried debugging it and i found out that variable $children is just empty like why would $root->children("limit=150"); wouldn't work in url segment? is this some sort of bug ?
  8. no i wasnt aware of -> not() functinon this works fine i found out one workaround by myself i checked if field which as every page isnt empty but this is very good solution thanks $kat = $pages->find("subor_hry>1, $limiter");
  9. so i want to $pages->find find pages only that dont have children i didnt see any options for this so i tried this $kate = $pages->find("template=hry_home"); foreach ($kate as $bruh) { if($bruh->hasChildren()) { $kate->remove($bruh); } } this works incredibly good but i need it for pagination so i still need to limit it and thats where i got stuck simply $kat = $pages->find("$kate ,limit=5"); doesnt work, how do you work around this problem? every page has the same template, so i cannot use just different selector in find command are there any other quirsk i could use ?
  10. i have been trying this for a while and what even is imageSizer? is it like a hook ? if so i get error everytime i try ti save it ProcessPageEdit: Unable to read: /site-hry/assets/files/1027/flash_fishy_screenshot.png and when i put it into template i get different error do i understand it incorrectly ? i have this setup $word = ".png"; foreach($page->subor_hry as $file) { if(strpos($file, $word) !== false){ $image = new Pageimage($page->images_thumb, $file->url); } }
  11. So hello i am trying to get a .png file from file field and put it automatically to image field, why png image is in the file field is because i already have a hook that extracts .zip and uploads all content into file field, but i just realizes i cant use size() function on image in file field so i am tryin got reupload it to images field i already have something like this in ready.php $word = ".png"; foreach($page->subor_hry as $file) { if(strpos($file, $word) !== false){ $page->images_thumb = $file->url; } } by my logic it should work but it dosnt i get error ProcessPageEdit: Unable to read: /site-hry/assets/files/1027/flash_fishy_screenshot.png when i remove url from $file->url i just get ProcessPageEdit: Item added to ProcessWire\Pageimages is not an allowed type so what am i doing wrong? is there some other way to do this ? also can i have all this in $this->addHookAfter('Pages::saveReady', function(HookEvent $event) { whats the correct function to have it apply on all pages ?
  12. ye welp, its still an image, so ill probably have to make some sort of hook to put image into image field and then output them, well thanks for confirmation
  13. so hello there i have fiel field type i have lots of stuff there, and also an image i can easily get image from that field using $options = array('quality' => 85, 'upscaling' => true, 'cropping' => 'north', 'sharpening' => 'medium'); $word = ".png"; // Test if string contains the word foreach($childgames->subor_hry as $file) { if(strpos($file, $word) !== false){ /* $imger = $file->size(473, 266, $options); */ echo $file; /* echo $file->url; */ } } so i get the fiel i tried invoking size on it like the commented out part and it doesnt work i get error Oh snizzle… Error: Exception: Method Pagefile::size does not exist or is not callable in this context (in what am i doing wrong? can you guys help me by all logic this should work
  14. so what i am trying to do is that i uploded some files into file field, and then i want hook to get MD5sum and other stuff from .xml and put it into text field into it coresponding pages, pages like this are gonna be many, for each one i want it to output it into its fields
  15. oh nevermind i gues this works ? if($media->r_soc->title == 'facebook') { $soc = 'facebook'; } elseif($media->r_soc->title == 'twitter') { $soc = 'twitter';
×
×
  • Create New...