Jump to content

thomas

Members
  • Posts

    189
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by thomas

  1. Hi, I'd like to have an "edit" option for pages in the frontend. I thought I could append an urlSegment to the page url and (instead of coding show and edit functions into one template) simply switch templates: if($input->urlSegments[1] == 'edit') $page->template=$templates->get('page_edit'); This code doesn't work ... Is this even possible or do I need to redirect or put all code in one template? Thanks! thomas
  2. It's working now ... I wasn't aware $event->return holds what the name implies Thanks!
  3. Got it. I'm slowly understanding the hooks
  4. Hello, I'm trying to build a very simple Translator Plugin and somehow managed to get what I want on a "simple" page, meaning one that's straight from the admin. Now I'm trying to build the same functionality into my overview pages. The idea is to put the language into the session and then use $page->body or $page->body_en (and a few other fields) accordingly. Is there a way I can hook into $pages->find, iterate over the array, swap the content of the containing pages and return the array? For style and comfort I'd like to do this in a module, so a hook is needed. I tried addHookAfter('Pages::find,'','') but could make no sense out of it. I hope my explanation makes sense. Thanks for any hints, thomas
  5. So far I never had problems with checking the url. But just noticed it also throws a warning so I'll just be strict from now on Thanks
  6. Alright. For some reason it all works if I put <?php if(count($user->image)>0):?> instead of <?php if($user->image->url):?> weird, but glad I found it ...
  7. Thanks for the hints. I actually check if the user exists, sorry for not posting it: if(!$profile->id) $session->redirect('/'); The thing I don't understand is: <h1 class="blue"><?=$profile->displayname;?></h1> <?php if($profile->image->url):?> <img src="<?=$profile->image->first()->size(100,100)->url;?>" style="float:left;margin-right:10px;"> <?php else:? This displays the displayname correctly and then exits with "Exception: Method Pageimage::first does not exist or is not callable in this context" even though I'm sure there is an image AND <?php if($profile->image->url):?> works on all other sites and occasions for me. Another mystery: If I go to the profile page without being logged into the admin, everything shows up fine. I open another tab, log into the admin, reload the profile page, and my profile image throws an error again. Confused ...
  8. Hello, I have a strange problem here. Long story: - I added an Image field to my user template - On my page I have a little login box in a sidebar, which is displayed whenever the current user isn't guest. It the checks if the user has an image uploaded: <?php if($user->image->url):?> <img src="<?=$user->image->size(60,60)->url;?>" style="float:right;"> <?php endif;?> This works. Now to the strange part: In the main content of the page I want to display a profile page for any givven user registered. I took this approach from Ryan's BlogProfile: $name = $sanitizer->pageName($input->urlSegment1); $profile = $users->get($name); <?php if($profile->image->url):?> <img src="<?=$profile->image->size(100,100)->url;?>" style="float:left;margin-right:10px;"> <?php endif;?> This is on the same page as the login box. Now I'm getting very strange results. Checking if a file is uploaded constantly fails, so I get errors when there's no image. It's hard to explain and my only two explanations are I'm either stupid or there's something I need to know about images in a user object, or getting info from $users. Sorry for the weak explanation, can someone help me out? Thanks, thomas
  9. Cool. I just updated and now it works. Cheers.
  10. Hm ... I remember trying it (that is "advanced", right?) but it didn't work for fieldtypes Pages and Image, which is what I needed. I'll try again, although on my sites unpublishing a page is better than publishing one without a teaser image, for instance. And as I said, my editors won't learn. Thanks! t
  11. Yeah, I thought about that but these people don't learn unless there's consequences. I did have to built a rather dirty hack to get through the "add page" dialogue, though. So my method isn't too sophisticated.
  12. I just built a module that adds a "addHookBefore('save' ...) Hook and the checks the inputs I want to be required. If the requirements aren't met, there's an error and I set $page->addStatus(Page::statusUnpublished); ... This seems to work great so far. Is there anything I'm missing? (since this method isn't mentioned here ...)
  13. Hello, This is a tiny thing that's easily changed but I thought I'll post it here anyways: I'm having a hard time explaining to the editors that clicking "view" in the backend while editing a page will pretty much delete all the changes made if you don't save the page first. It would be great if "view" opened the page in a new window or would save the changes first (while leaving unpublished). Thanks, thomas
  14. Thanks for the info, Ryan! This is a one time import but I'll need to do it for several sites so your tips are really appreciated.
  15. There's already a bunch defined in there even though I had no idea this existed. Cool. Since PW uses this to create new pages it is obvious why my script didn't catch some of the duplicates ...
  16. I have no idea what this even does but adding "Sanitizer::translate" to my $sanitizer call solved the problem ...
  17. I' m not really seeing big problems other than the duplicate error which keeps me from importing the whole DB. I just don't know how to catch it! Other than that, there's a few special characters gone missing (like „these quotes“) but I can live with that ...
  18. Hello, i need to import a large number of articles from an old site into my PW project. So I wrote an import script which gets the data and for each row, creates a new page in PW and inserts it. So far, so easy. Problems arise because the old DB is latin-1 encoded and I keep getting strange results which are probably due to character encoding. $con = mysql_connect("localhost","yes","also"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_set_charset("latin1", $con); mysql_select_db("mtb", $con); $result = mysql_query('SELECT * FROM stuff'); while($row = mysql_fetch_array($result)) { $new = new Page(); $new->of(false); $new->template = wire('templates')->get('article'); $new->parent = wire('pages')->get('/news/'); $name = wire('sanitizer')->pageName(utf8_encode($row['HEADLINE'])); [*]$new_name = $name; $i = 1; while(isset($found{$new_name})) { error_log('DOPPLER! '.$new_name); $new_name = $name.'-'.$i; $i++; } $found{$new_name} = 1; } Even though I check for double page names, I keep getting the 'Duplicate entry' error. I also tried while(wire('pages')->get("name=$new_name,template=article")->id) {} to find duplicates but it stops with 'Duplicate entry' at a different data set ...I'm confused ... can anyone help? Thanks, thomas
  19. Hi Soma, I just included your module in a page i'm working on, which already has over 400 videos complete with tags imported from the old site. It works great! I only changed the SQL query to "ORDER BY score DESC, modified, ASC" since that makes more sense in my case. Thanks for your work! - thomas
  20. Cool apeisa, not sure what went wrong the first time but this works great! Now I've got the next problem (it never stops, does it?) http://processwire.com/talk/topic/1730-find-on-my-own-little-pagearray/
  21. Hello, I have a function that creates a PageArray, throws a bunch of pages into it and returns it. Now I'd like to use all the PageArray methids on it but for some reason, everything after the first selector is ignored. The function: function getRelated($pageTags,$template,$limit=1000) { $pages = wire('pages'); foreach($pageTags as $tags) { $tag = wire('sanitizer')->selectorValue($tags->title); if($template) $templateQ = ",template=$template"; $related_pages = $pages->find("tags.title=$tag,id!=".wire('page')->id.$templateQ); foreach($related_pages as $related) { $related_id[$related->id]++; } } $rp = new PageArray(); foreach($related_id as $key => $val) if($tmp++ < $limit) { $rel_page = $pages->get($key); $rel_page->rank = $related_id[$key]; $rp->add($rel_page); } return $rp; } How I'd like to use it: $rel = getRelated($page->tags); $start = $input->urlSegment1 | 0; $related = $rel->find("sort=-rank,sort=-created,start=$start,limit=3"); This returns all the elements in $rel, sorted by rank, everything else is ignored. Is this a bug I built or a bug I found? Thanks, thomas
  22. Hi apeisa, that's great. I also played around with this and return a PageArray now. I also tried to use the "weight" as a temporary field in my PageArray so I can sort by weight (like $related->find("sort=weight,sort=-created,limit=3")) but I couldn't get the temporary field to work. $rp = new PageArray(); foreach($related_id as $key => $val) if($tmp++ < $limit) { $rp->add($pages->get($key)); } Does anyone know a way to add a temporary field to each page I add to the PageArray $rp, which I can use to sort after I return $rp? Thanks, thomas
  23. Hi, I'm gonna try and build an ajax powered comments system and was planning to build the whole thing on a one comment == one page basis. The comment page having a textfield for the actual comment, a page field with the user page of the commenter (it will require registration) and a page field for the page that was commented on. Since Ryan's comments module uses simple DB entries I was wondering if this is a good plan and what the benefits of not having one page per comment are? Will I experience problems if a million people comment stuff on my site? Thanks for hints an ideas! thomas
  24. Hi Marc, I used output buffering to avoid echo lines. This way I can include a bunch of reaccuring html snippets (news.inc, videos.inc ...) which are almost straight HTML (with little <?=$something;?> in it) and put it all into the $page->body variable. At the end, I include main.php where $page->body displays the page content. I found the code a lot easier to read this way.
×
×
  • Create New...