-
Posts
17,152 -
Joined
-
Days Won
1,670
Everything posted by ryan
-
Usually if I have hundreds of page references (categories) to create I use the API to create them (like from a CSV or text file) rather than doing it manually -- let me know if I can give an example of how to do that. If you are doing something with free tagging, then I would use url segments. Lets say you've got a free tagging field called "tags", and it's just a textarea with one or more tags. You might setup a template called "tags" and on a page called "/tags/". Accessing /tags/something/ in your browser should list all pages that match the tag "something". To do that, first turn on URL segments in your template (Admin > Setup > Templates > Advanced > URL Segments). Then, in your template, your code might look something like this: <?php if($tag = $sanitizer->selectorValue($input->urlSegment1)) { $matches = $pages->find("tags*=$tag"); echo $matches->render(); // or loop through and print on your own } For pre-defined categories using page referencs, I think that asmSelect is a good input field to use for selection. However, if you need to be able to select pages in a hierarchy (like category or subcategory with the same field) then I think the "page list select multiple" is a good solution, because it enables you to select pages in a hierarchy rather than in one level. You could also use any of the other multi select input fields and use the template as the base for selection rather than the parent. ProcessWire is a couple months old, and Drupal has been around since 2001, so we're not going to have the same level of features in some areas. But if you think Drupal is better at this than PW2, describe further, and more specifically, so that I can make sure we get PW2 one step ahead. When it comes to working with these kind of data relationships, I believe PW2 is better than Drupal on the back-end, so I want to make sure I provide enough front-end simplicity to provide and prove that. thanks, Ryan
-
AdminBar is really great! I will be installing it on all of my clients' sites (already started actually). ;D
-
You can get the admin URL from: $config->urls->admin Or if you want to retrieve the admin page: $admin = $pages->get($config->adminRootPageID); Btw, I don't often do it, but it is good security to change your admin page name. You do this by editing it, clicking on the 'settings' tab and changing the name.
-
I think you would want to use the sitemap strategy, like on the API "include & bootstrap" page. But if you only need one level of depth, we could do it even simpler. I'm on an iPhone right now so don't have good examples, but let me know if the sitemap strategy doesn't make sense an I can post some good examples in the morning.
-
Hi Martin, I think this is a good example: http://processwire.com/talk/index.php/topic,56.msg443.html#msg443 What we're doing there is hooking in before a page is rendered, and changing the template filename to one in the AdminBar modules directory. Let me know if this makes sense, or if I can provide another example? Thanks, Ryan
-
Sure--what I would suggest is adding a text or textarea field and calling it "tags". Then people can type whatever tags in there that they want. When you want to find all pages matching a given tag, you'd do this: $matches = $pages->find("tag*=something"); // where 'something' is a tag If you want predefined tags, then I would use a page reference fieldtype to associate a group of pages as tags. Populate the pages with their name or title field as your tag. Then use a multiple selection field like asmSelect to allow selection of the tags/categories. To find pages matching a given tag, you'd do this: $tag = $pages->get("/tags/something/"); $matches = $pages->find("title=$tag");
-
Sevarf: I forgot something on the previous commit (it wasn't allowing periods in the URL name). That is fixed, so if you grab the latest, it'll let you use ".html" with your page names (or any page name with periods in it for that matter). Regarding SEO and .html, of course listen to your expert. I don't claim to have the title of SEO expert, so take what I say with a grain of salt. But SEO is fundamentally intertwined with all the work I do, and has been for more than 10 years. I'm responsible for maintaining dozens of sites at top rankings with very competitive terms over the long term. My experience may be different from others, but what I've learned is that any time you are tweaking details with the intention of tricking (or optimizing) Google into thinking your page is something it's not, you are asking for trouble. It's arguable whether using an .html extension falls into that category since it can be purely stylistic. But your SEO expert is suggesting you do it in order to exploit some apparent weakness in Google's algorithm (which I don't believe exists). An SEO strategy that dips into these considerations it not a good long term strategy, and is focused on the wrong things, in my opinion. However, I don't claim to have all the answers, nor do I know anyone at Google, so I'm not suggesting you change your strategy. Just be wary of anything founded in quick fixes or algorithm exploits. Unless the need calls for black hat, in which case we'd probably be talking about how to use ProcessWire to automate creating thousands of Youtube and Facebook accounts. That will be a fun guide to write. Regarding this forum's use of .html -- SMF is not a good example. I love this forum software, but have a look at the SMF code sometime, and you'll see what I mean. In addition, view the source on this page and you'll see a populated meta keywords tag... they make a great forum, but I wouldn't trust them with my client's SEO. Though I do have to give them credit for adding a required, difficult-to-modify (hashed) backlink to their site in the footer. I had to use PHP's buffer functions just to change it to a rel=nofollow. Adam: I don't want a site-wide slash setting because template API code has to consider the slash setting. I want to have a site-wide expected default (of having a slash) so that there is a known playing field for code examples, prepared templates, etc. If someone wants to change it, then they can do so with the knowledge that they may have to consider it in their code on a template-by-template basis.
-
I do want to make sure people have the flexibility to do it any way they want, so I think that's what we've got now (they can set it according to their preference). I've been meaning to add this slashes setting, so figured now was the time with this most recent request. My preference for the slashes is because a page can be both a container for data (fields) and a container for pages (children). As a matter of consistency, I want to treat all pages the same (at least on my own sites) so that my site's API code doesn't always have to be looking for the presence of slashes when working with selectors, relative paths, url segments and such. I don't want to have to always consider these things when developing a site. As for adding extensions like ".html", that would kill the ability to use page URLs/paths in selectors, unless you actually named your page with the ".html" extension. So if we start adding automatic extensions, I think we start creating a lot more work for the site developers and general confusion... at least I would find it confusing. Sure there might be solutions around the issues, but if something is going to be used on less than 30% of sites then it doesn't belong in the core (which would make extensions a possible good module idea).
-
I make similar errors every day. It just goes with the territory. Glad you found the solution on that one. Regarding the hidden_path. Assuming that is used to store something automatically at some point, I would suggest not making that part of your posted fields if at all possible. The reason is that someone could manipulate that value and have you overwriting stuff you shouldn't.
-
Thanks! Let us know how it works out with the videos.
-
Adam, the page number prefix is site-wide, not template. The slash setting is by template. The default state is for it to enforce slashes, as before. Nothing has changed unless you go into a template and specifically set it to not enforce the slashes.
-
I will look at adding that option. Though this definitely falls into the court of being something I wouldn't ever use on my own sites, and I would question the value of doing it. If it's for maintaining legacy URLs, you are better off using Apache to 301 redirect them away from the legacy URLs. Also, you can always make pages end with .html by making that the page name, i.e. "mypage.html" rather than "mypage", and turning off trailing slashes.
-
$categoria = $input->post->categoria; $p->parent = $pages->get("/".$categoria."/"); That code snippet above is not safe because $categoria is not validated/sanitized. Someone could really tear up your site using this current code, since you are using that to find the parent. For instance, what if they manipulated the form so that it was '/processwire/' or some prominent page on your site. Since you are using this to save pages, they could then go in and add a million pages to your navigation. I suggest that you do this instead: $valid = array('categoria1', 'categoria2', 'categoria3'); $categoria = $sanitizer->pageName($input->post->categoria); if(!in_array($categoria, $valid)) die('abort'); $p->parent = $pages->get("/$categoria/"); ...and likewise for the other places where you are doing this. Or better yet, only deal with page IDs in your form, rather than page names. That's better because integers are very easy to validate and may be preferable here: $valid = array(10,11,12); $categoria_id = (int) $input->post->categoria; if(!in_array($categoria_id, $valid)) die('abort'); $p->parent = $pages->get($categoria_id); This is also not safe: require_once('functions.php'); The problem with that is that PHP is searching all the include paths for 'functions.php'. It may very well find the wrong one. Instead, you want to ensure it just operates in the current path, so prefix it with a "./": require_once('./functions.php'); I'm also a little concerned about what hidden_path is, and if there any security implications with that, but I just want to reiterate that you should never trust any user-submitted data. Assume that it is tainted. People will eventually exploit these issues. Don't use anything they submit in selectors, in page data, or echo anything back to the screen unless you've sanitized and validated it first. As for why it's generating the error message... I can't immediately tell what the issue is or why you are getting something from comments (there doesn't appear to be any comments code here). It is possibly the include path issue I mentioned above, though I'm not counting on it. Can you paste in the exact error message that you are receiving? Thanks, Ryan
-
I made the slash configurable by template. If you download the latest commit, you'll see it as a new advanced setting for each template. Adam, I also made the page number prefix configurable now with $config->pageNumUrlPrefix = 'your_prefix'; If not specified, then it defaults to 'page', as before, i.e. 'page1', 'page2', 'page3', ...
-
If you are wanting to support two different video sizes, I think your best bet is to just create 2 file fields to handle them (or 1 multi-file field, where you always assume the first is the largest/smallest, or something like that). Lets assume you've created 2 file fields, and named them video_hi_mp4 and video_lo_mp4, and you've added these to your template that handles it. Here's how your template code would look: <video controls> <?php if($url = $page->video_hi_mp4->url) { echo "<source src='$url' type='video/mp4; media='(min-device-width: 800px)'>"; } if($url = $page->video_lo_mp4->url) { echo "<source src='$url' type='video/mp4;'>"; } ?> </video> You'd use the same method for your other video formats.
-
I think we need to get a look at your whole template file. Chances are that your code to look for a form is just checking if there are posted values, rather than checking for posted values from a specific form. If I'm correct about that, you would want to change your form posting code to save only if it detects the name of the submit button. So here is what I'm guessing it looks like now: if($page->editable() && count($input->post)) { // save the form } What'd you want to do is change it to look like this: if($page->editable() && $input->post->submit_form) { // save the form } Replace "submit_form" the the name assigned to your submit button. If it's just "submit", then you may want to change it to something more specific in this case. If this isn't it, please post your template or email it to me and I can get a better look.
-
I'm not sure why that error was turning up, and am out of time to take an in-depth look, but I was able to fix it easily. And actually I think it's something I should have had in there in the first place (an extra check to make sure that $controller is not null), so thank you for finding it. I have fixed this in the latest commit: https://github.com/ryancramerdesign/ProcessWire/commit/99454cb68b0ccfe287ab82c68c9db7010a6f94be AdminBar is looking great! Would you mind if I tweeted a link to your screencast?
-
There is. Try this: $total = $page->children("limit=2")->getTotal(); You have to do "limit=2" (or higher) rather than "limit=1" because PW2 doesn't currently count totals on limit=1 selectors. That's just as a matter of efficiency, since all $pages->get() functions use limit=1 internally.
-
I think it might be better to just override the template rather than putting one in the /templates/ dir (unless you want to encourage them to edit it). I've modified the Template class so that you can change the target filename at runtime, so you'll want to grab the latest commit. https://github.com/ryancramerdesign/ProcessWire/commit/0c8dc7d8e62c9a6a110791e00111c463ff00b01c Next, move that template to the same directory as your module (/site/modules/AdminBar/adminbar.php). Then in your AdminBar.module, add a new "before" page render hook. It will check to see if the page template is "adminbar", and if it is, it'll change the template filename to the one in your /site/modules/AdminBar/ dir. <?php public function beforePageRender($event) { $page = $event->object; if($page->template == 'adminbar') { $page->template->filename = $this->config->paths->AdminBar . "adminbar.php"; } } Also, add this to your init() function in AdminBar.module: $this->addHookBefore('Page::render', $this, 'beforePageRender'); If you do decide you want it to check if the file is in your /site/templates/ first, then just add that check to your beforePageRender method. Now it should work exactly the same as before, except that it'll use the template file in your /site/modules/AdminBar/ dir rather than expecting one to be in /site/templates/.
-
Apeisa, I tried this out and it works great! Nice work. The site map view is very useful too. Also, I think the code looks good! Here's a few suggestions and notes I've got: The 500 error you got was thrown by ProcessWire. The problem is these lines: return $abFieldGroup->save(); return $abTemplate->save(); All the save functions return a result status, basically true if it was successful, false if not. So to fix the error, you would need to change lines like the above to: $abFieldGroup->save(); return $abFieldGroup; $abTemplate->save(); return $abTemplate; When you are developing in ProcessWire, you may want to enable debug mode, so that errors are echoed to the screen. You can turn this on in /site/config.php. Look for the line that says $config->debug = false; and change it to true. Next, I wanted to mention that the module interface provides install() and uninstall() methods, in case you want them: /** * Perform any installation procedures specific to this module, if needed. * * This method is OPTIONAL * */ public function ___install(); /** * Perform any uninstall procedures specific to this module, if needed. * * This method is OPTIONAL * */ public function ___uninstall(); There may be issues on many installations with your last function, _createAdminBarTemplateFile. The reason is that ProcessWire doesn't usually have write access to the templates dir (it depends on the server). So your installer may be want to look for this, or advise them to copy your template file in there if there isn't write access. Or, we could just make it a blank template (without a file) and then hook into it's render method so that your .module file can render the output instead. Let me know if you want to do that, and I can provide instructions. Lastly, because the site map outputs a full sitemap, it may not scale to large installations. For instance, the site I am working on now has 5k+ pages, and while it renders them all, it takes several seconds. But on large installations, it might just run out of memory too. As a result, I would recommend placing a limit to the number of subpages that the sitemap will display. Maybe a "limit=50" per branch, just to account for the possibility of large sites. And once it reaches that limit, it might have a label that says "Go to the admin to view remaining pages" or something like that. Again nice work on this, I am really enjoying using this module!
-
I agree with the usefulness of this. The only reason it's not yet implemented is because automatically creating a page is making a lot of assumptions... that's because ProcessWire doesn't have any built-in fields per se. So if we're allowing dynamic adds of pages like that, then it's got to assume that you don't have a bunch of fields on that page that also needs to be populated. But I think as long as we focus on just populating name and title, and people understand they may have to go back and make further edits to any pages they add (depending on the fields) then it'll be okay. This feature won't be particularly difficult to implement. But I'm thinking it'll go best with a auto-completion widget for page selection (which is currently in progress).
-
I didn't realize that disqus had a REST API. That's cool if it does. I also need to look into those other solutions you mentioned. But regardless of any other solutions, I figure a good built-in comments system is a priority, so I'm going to keep at it. But keep the system so that any other comments systems can be easy to implement too.
-
How do you call data from a page or pages into another page?
ryan replied to a topic in API & Templates
I don't know why, I was a little surprised that it flagged them. That's the first time I've seen false positives with Akismet. But I'm guessing you are right about the links. -
How do you call data from a page or pages into another page?
ryan replied to a topic in API & Templates
Thanks for letting me know. I found one of your messages and one of Adam's stuck in the Akismet spam filter (false positives). I identified those as false positives and hopefully they are showing up now. Do you see anything else that is missing? (i.e. you mentioned two of your messages, though I only saw one in the filter). -
Does anyone know if there is a screencast or something that demonstrates how this works in EE? I don't currently have access to an EE installation where I can play with it, but am interested in getting a better look at this functionality.