alan
Members-
Posts
854 -
Joined
-
Last visited
-
Days Won
1
Everything posted by alan
-
Me: Ryan: → Fantastically fast and helpful post ← I'll take that as an emphatic "YES!" then Ryan THANKS again for the help; it's so appreciated. Having a smile-inducing time rattling out my own blog system based only on PW API and dollops of cleverness courtesy kind people like you and others. It's a delight working in PW even tho' my speed may be lower than some due to my PHP learning curve. Thanks again for such a generous and excellent project.
-
Soma you are a lightening-powered super-fast uber-coder. Thank you! Will try and report back. count($entry->comment) ...solved it. THANKS Soma
-
Self-solve-time: Always the same, I'm getting closer to solving now I've posted. Removing the (int) shows for a post with two comments I get "8|23" so it's clearly the ID of the actual comment. Will experiment more
-
I have this code testing if a page (blog post page) has one or more comments associated with it: if($entry->comment.count > 0) { $out .= "This post has earned "; $commentCount = $entry->comment.count; $out .= (int)$commentCount; $out .= " comments so far."; } The test works fine, but the number of comments is returning something like an ID (I guess) rather than the number of comments. For example two pages have one comment each and for one it reports: and on the other: I am pretty sure this a PHP-lite-weight issue between the chair and the keyboard. If you're less PHP lite-weight than me and care to comment on what I might need to do, I would be most grateful
-
+1 for the thanks to Ryan for that snippet. Does anyone know, for a comment, is there a field I can test to see if it is approved? If not, is there an alternative way to check, albeit might be less elegant?
-
@Ryan, thank you, apart from the 404 redirect, that new code worked a treat, I used a line from Soma in place of it and now it works perfectly. Thanks again!
-
@Soma I used a line of your code and some new code from Ryan and it works. Thank you very much indeed again for your help.
-
How to find all normal public pages — only those we'd want in sitemap.xml
alan replied to alan's topic in General Support
OK, the solution "I've" come up with (err, Soma and Ryan came up with ) is a hybrid of some of Soma's code and Ryan's: if($page->id == 1232 && $id = (int) $input->urlSegment1) { // 1232 is a page with the URL /p/ $redirect = $pages->get("id=$id"); if($redirect->id && $redirect->viewable()) { $session->redirect($redirect->url); } else { //throw new Wire404Exception(); $session->redirect($pages->get($config->http404PageID)->url); } } This is now complete and solves the short-links referred to in the opening post of this thread. I might see if I can make this into a Module. I don't know if it is a good candidate for being a Module and I don't know if I will be able to work out how to do it and I don't know when I'll get to try (just a few don't know's then ) but maybe I'll do it! Meantime, thanks again to everyone who commented, cheers, -Alan -
Ryan, that's a GOOD thing to hear, "...too many days (or drinks) at sea", there can't ever be too many of those No worries whatsoever and thank you for the new code and I understand about that degree of specificity meaning access checking is different, makes total sense. I'll take your code and also one from Soma and see where I get Thanks again!
-
@Soma Thanks Soma! I will certainly post back to let you know and thanks again for the pointers
-
@SiNNuT you're right, I certainly am trying to solve this, but I'm not hung up on it just interested in finding the answer. And I agree with you about Twitter and that perhaps this is less important now: But often I will still stick to using plain-text (not HTML) email and sometimes I want a short way to refer to a URL in an email. Although this may be an edge case it's enough to make me want to explore if I can do this easily with PW. Added to that, solving a challenge like this is not only valuable for the resulting functionality, but also it makes me learn, and as I need all the learning I can get (being a bit weak at PHP and API/jQuery style constructions) I kept trying to solve this one. I just hope one or more of the posts in the thread end up helping someone else, either directly or in some way I had not envisaged. And thanks for your comments about bit.ly etc, I ended up choosing the Google shortener extension in Chrome a while back after that outage from one of the shortening services. And yes, wherever appropriate I think using full URLs is the best way to go. Cheers!
-
OK, thanks to that code [soma, thank you] without (yet) resorting to using the "not-permalink" option (which may be the way I have to go) the only pages I seem to have problems with are ones where when I try some IDs at random (to see if I can 'break' the system) result in a URL like this and a login prompt: http://example.com.site/pw/repeaters/for-field-107/for-page-1188/ I'm now looking to see if there is an API way to detect if an ID is 'as a result of a repeater' or 'normal' (if that even makes sense).
-
WoW! Thanks Soma, I thought it should be easy with the power of PWs API but my limited and the fun of trying other ways meant I was OK to try other routes such as re-purposing your cool module. Thanks again, I will try out your code here and see what I get!
-
Soma, you are in good company if you don't understand what I am doing — I am sure a lot of people feel the same; I don't understand me sometimes Joking aside, I am trying to check if an ID is for a page that is normally publicly visible or not. I plan to show a short-version permanent link to each page so if someone wants to tweet about (or email easily) a page, they can refer to: example.com/p/1987 rather than having to refer to example.com/animals/houses/the-squirrel-house/cheeky-the-red-squirrel-eating-some-cheese My code uses a GET to check if a visitor has typed example.com/p/1987 and I want the code to then check that 1987 is a valid page I want to allow sending them too, if not I will 404 or just show a message etc. Edit: I tried your code like this: $options = array( 'outer_tpl' => '', 'inner_tpl' => '', 'list_tpl' => '{id} ', 'item_tpl' => '', 'item_current_tpl' => '' ); $array_ids = explode(" ",trim($nav->render($options))); echo $nav->render($options); but it looks like list_tpl' => '{id} ' results in {id} {id} {id} {id} {id} {id} {id} etc being output rather than the actual ID numbers — but thank you for the clues I will keep working on it and if I solve this, repost here. Edit 2: I typo'd, your code works (of course ) — thanks again for the help! If I finish this functionality off I'd like to see if I can make it into a Module(!), but I don't want to get too excited yet, it's not even working
-
Oops, serves me right for skimming instead of reading, sorry folks.
-
Would there be an easy way to use MarkupSimpleNavigation and maybe something like in_array()(?) to check if an ID (that will come from a GET so we must test it) was the same as one of the pages that the navigation would normally display? I assume one initial step would be working out if I can configure the options for MarkupSimpleNavigation so it only returns the IDs of pages (no markup) and it returns all pages one would want the public to see, the same list one would have in a sitemap.xml. I'll take a longer look at the options the very good documentation has to see how I might do this. Update: Progress, this $options = array( // 'parent_class' => '', // 'current_class' => '', // 'has_children_class' => '', 'outer_tpl' => '', 'inner_tpl' => '', 'list_tpl' => '', 'item_tpl' => '{id}', 'item_current_tpl' => '', // 'item_current' => '{title}' ); echo $nav->render($options); returns only the IDs (with whitespace, dunno if that matters as regards interpreting the o/p with something like in_array(). I'll see...
-
How to find all normal public pages — only those we'd want in sitemap.xml
alan replied to alan's topic in General Support
Soma, I totally forgot! WHAT am I like... And I had your module bookmarked from the start and watch the thread too as it's something I am sure I will need. Thanks for the suggestion, I'll check it for use in solving this, cheers! -
I understand I too love DRY (don't repeat yourself) data and would also not want duplicated images. You likely know the following but just in case not, right now with Manage Files module installed I am able to (with a second tab open, so less than ideal) scroll to find the image I want in the Files page (that's installed by Manage Files module), see the page it's on and back on my first tab as I am editing copy in a TinyMCE textarea, click the Image icon > images on page (drop down) > change the page from where I am to 'About us' > and select an image from there; then insert and re-size etc. This keeps my data/images DRY and allows me to use images from any page on the page I'm editing. This is not exactly what you were looking for I think, but just in case it helped at all I thought I'd note it.
-
How to find all normal public pages — only those we'd want in sitemap.xml
alan replied to alan's topic in General Support
Thanks diogo, that looks very useful and it may allow me to solve the more general thing I was looking for (find all pages suitable for public consumption). -
A couple of times I've thought "It would be good if I could get from the API directly all of the publicly visible pages and nothing more, or use the API to build an array that I could subsequently look in that held this set". That set of pages would be those we would want, for example, Google to know about and so would not include the login page or pages like example.com/pw/repeaters/for-field-123/for-page-1456/ In pseudo code one way I could see doing it would be: foreach(section-is-part-of-nav) { foreach(page-in-section-is-part-of-nav) { visible-pages-array[store-this-page-id] } } Two uses I can think of are to help when building a sitemap.xml file (I've not yet looked at the sitemap.php template that ships with PW, shame on me if that solves all of this) and the other use is for allowing short-links to work, but only for normal, public pages. Any thoughts on how this can be done will be received with great interest PS: What's the betting this can likely be done directly with the API and I've missed something simple and obvious...
-
@MadeMyDay I'll come clean and say I scrolled past most of the conversation there between you and Ryan. Also I know less than 1/1000th of a percent about this compared to Ryan; literally, so apologies if this is useless, but, it sounded as if this might be of some interest to you perhaps: https://github.com/NicoKnoll/ManageFiles. I modified a copy of this slightly to: # add permission 'managefiles' so this permission may be granted to user roles # re-named columns and swapped around a little # added 'description' so not just getting file name I've not uploaded it to github yet as I am a total newb, but if you want a copy then just say.
-
Ryan, FYI keeping my code and changing $page->viewable() to $redirect->viewable() results in an error. But I swapped to your new code and that works perfectly as far as it goes but I think I need to do more because although visiting example.com/p/1190 pops me straight over to the full, correct URL for that page, visiting an ID that happens to be a page in the trash gives me a 404 (probably the correct outcome) but trying another ID at random resolved to example . com /pw/repeaters/for-field-107/for-page-1188/ and I ended up at a login page (which I don't want people to stumble over). I've moved the below over to a new topic as I hope it is one that may be of some general use (not only to me!). This isn't an urgent thing, but not for the first time I have wondered how I would build/use a function that in pseudo code did: if(section-is-part-of-nav) { if(page-in-section-is-part-of-nav) { visible-pages-array[store-page] } } ...and left me able to test a page to see if it was in the visible-pages-array and hence one I want to do stuff with that the public is allowed to see.
-
@SiNNut It would resolve to that URL, that is the default one stored in the db, the permalink, but if someone typo'd and visited example.com/deep-frying/29/the-best-way-to-deep-fry-onion-family then the system would be gentle and show the correct page, not a 404. @Ryan Wow, excellent, thanks yet again Ryan for the great example, I will go edit...
-
I've long been a fan of something I first encountered in Textpattern, the ability to visit example.com/cooking/29/the-best-way-to-cook-leeks example.com/cooking/29/the-best-way-to-cook-leek example.com/cooking/29/the-best-cook-leeks example.com/cooking/29/the-best-I-cant-type and always simply see the page about cooking leeks. Effectively the URL beyond /29/ is getting ignored. For example this allows one to use example.com/cooking/29/ as a short, permanent link to a page while retaining the full URL for normal use (and healthy SEO). Now Twitter self-shortens links <- insert debate if that's good here -> what I am trying to do is perhaps less important, but I like the idea of being able to refer to a page with an alternate, ultra-short, permanent URL. To that end I used the code examples here (thank you) and came up with this: if($page->id == 1232) // the id of a utility page with the URL /p/ { $pageId = $sanitizer->selectorValue($input->urlSegment1); $redirect = $pages->get('id='.$pageId)->url; if($redirect) { if($page->viewable()) { $session->redirect($redirect); } } } The ->viewable() test is not really working, but that aside I can visit: example.com/p/1190 and get instantly directed to the page with ID 1190 at it's normal, full URL. Useful The problem is the viewable test. If someone tries to visit a page ID for a page not normally visible they are directed to Login, not ideal. If anyone sees a neat way I can identify all pages that are suitable for display (e.g. the output of the navigation) and use that as a filter to test against so if the ID is not one of those pages I can 404, I'd be most grateful for ideas.
-
I don't know Readability at all well, so I may be way off, but I get the impression Instapaper could be likened to pinboard.in where Readability would be likened to deliciou.us; that is, Instapaper is a tiny but uber-efficient one-man operation, no frills, expertly spec'd and created rather than a more commercial, 'fatter', product from a larger provider. That view may be totally wrong though! In which case apologies to whichever party I wrongly summed up