Jump to content

PHPSpert

Members
  • Posts

    30
  • Joined

  • Last visited

Everything posted by PHPSpert

  1. Just had the problem where I wanted all templates to be served as JSON. This is what I did: /wire/config.php $config->prependTemplateFile = '_init.php'; site/templates/_init.php: <?php header("Content-Type: application/json; charset=utf-8"); ?> and it worked fine. Now if you wanted to, you could simply create a field in Processwire for each page that allows for a custom setting, like: <?php header("Content-Type: " . $page->custom_content_type . "; charset=utf-8"); ?> in your appended file. Works like a charm.
  2. I'm trying to clone a page, it's repeater fields and other values to another page. will something like this work? $newPage = clone $page; $newPage->id = null; $newPage->name = "new-slug"; $newPage->save();
  3. I seriously didn't know this was possible. I guess if you're looking for a parent from multiple levels you could do $pages->find('created<=yesterday')->parents()->get("template=top"); // This obj exists so that means the children exist... NICE!
  4. Understood, but what if you want to get a page with children with a specific attribute? Maybe more specifically: $pages->get("template=accounts")->hasChild("created<=" . strtotime("-1 days"));
  5. It would be nice if ProcessWire had a has() selector like JQuery does. For example, so we could do this: $pages->get("template=accounts")->has("created<=" . strtotime("-1 days")); Is there something like that already or has it not been added?
  6. Web apps in PW? Hell yeah, Processwire is great for that. I love how I can map out my app before I get started into a tree. I actually built a lot of web apps on PW. One being http://collabmango.com PW saves a lot of time in building web apps. The selectors and not needing to deal with DB crap is a huge +
  7. Ok, here's another idea: let's say we're looking for "update" pages assigned to or owned by $user: function findUserPages($user, $template) { return $pages->find("template=account,user|assigned_user={$user}")->find("template={$template}"); } $pages_found = findUserPages($user, "update");
  8. I have a page architecture like this: account-data - 1010 (account, owner=clinton, assigned_users=brian) - Some update - Some project - Some task - 1020 (account, owner=jack, assigned_users=brian,clinton) - 1030 (account, owner=tom, assigned_users=clinton) - 1040 (account, owner=jordan, assigned_users=brian) What I want to do is give viewing permissions (for updates, projects and tasks) to users only if they are either assigned or own the parent account. I need to find out a clean way of doing this. For example, I could do: foreach($pages->find("template=task") as $item) { if($item->parents()->find("template=account,user|assigned_user={$user}")) ... But looping through all of the items is a pretty heavy task. Sometimes it has to go a few levels before finding the parent with the user info. Is there a better way of doing this?
  9. This is driving me crazy. I have a variable $course_page which is a repeater. I'm trying to get the next entry in the repeater. How? I've tried getNext(), next() and next.
  10. One of my clients may need to have the ability to import a csv of exam answers into PW. The exam template uses repeater fields for the questions. Is this possible?
  11. Soma, that plugin looks really good. I'm excited to try it out. I do a lot of small websites where most of the work is just creating pages, then filling out the content. So something like this will knock some time off the process. Ryan, that plugin looks good also. However, I don't see it as a huge time saver unless there's a specific use. Soma's plugin nearly takes away the need to switch back and forth between pages. The only thing is when we need to add and edit content in the body or other fields. By any rate, thanks for the contributions. You guys rock as always. There's a lot of new stuff to learn, create and improve. We don't all have the free time to dedicate our lives to these things but I like the minor additions here and there. When I get some time, I'd like to make some contributions also. I agree, sometimes little tweaks can create huge time savers. My idea might not be the best, but hopefully it gets a few minds working on how we can save more time in each of our projects and make additions down the road.
  12. So this month marks an entire year since someone opened me to the world of Processwire. Can't believe it's been that long. I have to say that without PW I would have lost many hours of coding and recoding classes, setting up basic websites and database tables. Aside from that, the API is something I would have killed for 5 years ago. PW has already given me a load of leverage of building projects fast and making way more money in less time. That said, after doing around 20+ installs since starting to use PW, I've noticed a few things about my work flow that I think could be improved. These improvements could spike productivity through the roof and save me even more hours and make me more dollars than before. There's a LOT of back and forth when setting up a website in PW. What we need is a way to reduce the amount of time creating new templates, fields and pages, as well as editing all of this stuff. Today I was thinking, wouldn't it be great if there was a way to just add a new page by typing it in a new slot below the other pages, selecting a template and clicking save. By default a template could be selected, for example the allowed child templates or the default-page template. Also, it would be cool to add and edit templates on the fly as well. Let's say we create a new page, click add new template (JQuery window pops up) and we can either add or edit the template right there as we're creating a new page. Also we could create new fields while editing the template. That way we could create a page on the fly with minimal settings, set up the template, add any additional fields we need and save it and publish it all in the same area. Now, this would not be easy to code by a long shot. Would take a lot of ajax calls and JQuery to get it to work. But having something like that would be wicked. With this, we could basically set up a page tree in 10 minutes or less. I know the obvious answer is, "well, go and code it," I seriously don't have the time for this right now. ProcessWireSexy was my planned theme but I'm still trying to find time to even start on it. Is there a theme out there like this that someone has already made? Someone has to have already thought of this.
  13. Wow - Yes, that's one way to do it. Thanks Ryan, you're a genius.
  14. Ok, this might be a little unique, not sure. Basically, I have already accomplished getting PW to use an external path to another domain to grab a directory of global templates I need for this app I'm creating. But now, I also want to allow clients to have local templates. So what I want to do is allow Processwire to search both the local templates dir and the global one on the other domain. Is there a way to do this? There's only one path, but is it possible to include from two paths without re-coding a bunch?
  15. Hey guys, Working on a new idea I've wanted to do for a long time. It's fairly simple and small but maybe you guys will be able to use it in your PW projects at some point. I'm still working on it but here's what it's all about: http://phpformbaby.skakunmedia.com It's called PHPFormBaby and I'm still not sure if it's going to be just one class or a library. But I'm going to get it out soon and get your opinions on it. Cheers!
  16. Hi Guys, ran into this topic doing a Google search. I've been working on the blog for the past few months. Basically, it's to help out the community and have a database of quick scripts, ProcessWire developers, my friends and I can use. I appreciate you guys taking a look at the blog. Also, I'm open to contributors for new posts. If you're interested, please let me know.
  17. Want to share a few things I've added for a magazine site I'm building: First of all, I think "priority" and "changefreq" are fairly important if you're going to have a sitemap at all. This post has some info on Google's guidelines: http://www.eduki.com...-are-important/ What I decided to do was quickly add two global fields to PW so I can set these values manually in each page: -sitemap_priority -changefreq And in the code: public function sitemapListPage($page) { $entry = ""; $default_priority = "0.5"; $default_changefreq = "monthly"; include $this->fuel('config')->paths->templates . "sitemap_module_defaults.inc"; if ($page->sitemap_ignore == 0 || $page->path == '/') { // $page->path part added so that it ignores hiding the homepage, else you wouldn't have ANY pages returned $modified = date ('Y-m-d', $page->modified); $entry = "\n <url>\n"; $entry .= " <loc>{$page->httpUrl}</loc>\n"; $entry .= " <lastmod>{$modified}</lastmod>\n"; if(!empty($page->sitemap_priority)) { $entry .= " <priority>{$page->sitemap_priority}</priority>\n"; } else { $entry .= " <priority>{$default_priority}</priority>\n"; } if(!empty($page->changefreq)) { $entry .= " <changefreq>{$page->changefreq}</changefreq>\n"; } else { $entry .= " <changefreq>{$default_changefreq}</changefreq>\n"; } $entry .= " </url>"; if($page->numChildren) { foreach($page->children as $child) $entry .= $this->sitemapListPage($child); } } return $entry; } The sitemap_module_defaults.inc file in the templates dir is so I can set some values on the fly without doing it manually: <?php switch($page->template->name) { case "blog_post": case "blog_topic": case "blog_topic_type": $default_priority = "0.7"; $default_changefreq = "daily"; break; } ?> That's done and works fine for me. Something I found frustrating with the sitemap module was that I couldn't add virtual pages I made. For example, if there's a page with urlSegments with some kind of page manipulation they won't show up on the sitemap, for obvious reasons. So what I did was add this method to the module: public function sitemapListVirtualPage($httpUrl, $modified = NULL, $sitemap_priority = "0.5", $changefreq = "monthly") { $entry = ""; $modified = date ('Y-m-d', $modified); $entry = "\n <url>\n"; $entry .= " <loc>{$httpUrl}</loc>\n"; if($modified) { $entry .= " <lastmod>{$modified}</lastmod>\n"; } if($sitemap_priority) { $entry .= " <priority>" . (float)$sitemap_priority . "</priority>\n"; } if($changefreq) { $entry .= " <changefreq>{$changefreq}</changefreq>\n"; } $entry .= " </url>"; return $entry; } And added this include to the init method before the output is saved to cache: public function init() { // Intercept a request for a root URL ending in sitemap.xml and output if (strpos($_SERVER['REQUEST_URI'], wire('config')->urls->root . 'sitemap.xml') !== FALSE) { // Check for the cached sitemap, else generate and cache a fresh sitemap $cache = wire('modules')->get("MarkupCache"); if(!$output = $cache->get("MarkupSitemapXML", 3600)) { $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; $output .= $this->sitemapListPage(wire('pages')->get("/")); include $this->fuel('config')->paths->templates . "sitemap_module_virtual.inc"; $output .= "\n</urlset>"; $cache->save($output); } header("Content-Type: text/xml"); echo $output; exit; } } And in my sitemap_module_virtual.inc file I did this: <?php foreach(wire('pages')->find("template=blog_topic|blog_topic_type") as $real_page) { $output .= $this->sitemapListVirtualPage("http://" . $this->fuel('config')->httpHost . $real_page->url . "archives/", wire('pages')->get("template=blog_post,sort=-created")->modified, "0.4", "daily"); } foreach(wire('pages')->find("template=blog_topic|blog_topic_type") as $real_page) { $output .= $this->sitemapListVirtualPage("http://" . $this->fuel('config')->httpHost . $real_page->url . "rss/", wire('pages')->get("template=blog_post,sort=-created")->modified, "0.4", "daily"); } ?> In this part, I have manipulated /archive/ and /rss/ sub-pages for each blog_topic and sub-topic(or blog_topic_type) using urlSegments. I wanted these to show up on the sitemap, even though they're probably not super important. Usually I wouldn't bother doing this if it was just these kinds of pages. But what if you have countless articles with manipulated urls that don't show in the sitemap? This is perfect example of why I did this for the future as well. I've been trying to understand how to do these things for a while, so I hope it helps someone out. EDIT: I have a download with all of my changes if anyone's interested in taking a look: http://clintonskakun.com/processwire-docs/posts/the-xml-sitemap-module-with-priority-and-changefreq-and-more/
  18. Trying to select pages based on the relation of the current page's children. I'm creating a magazine site. There are topics and sub topics. Each article can have more than one topic. For example: City Living (topic) - Housing (sub) - Transportation (sub) - Places to Shop (sub) - etc. Articles - Article 1 topic of Housing - Article 2 topic of Places to Shop - Article 3 topic of Transportation In the template for the topic I want to list all of the articles in the sub topics. I tried doing this: $pages->get("template=topic, sort=-created, limit=10, topic=".$page->children()); but it doesn't seem to work and throws an error. Is there a simple way of doing this? BTW, articles are just referenced by the page field and not children of the topics and sub-topics.
  19. Well the problem goes deeper than that because it's not the form template that's the problem, it's how the body content is formatted when the page is saved. I'm simply trying to quickly switch out the urls before the RSS feed parses. I could go into the HTML code when editing the page but that seems like a hassle when the search and replace does just as good a job. I was just wondering if there's a cleaner way to do it. However you do bring up a good point about using the httpHost variable. It would make the script a lot more versatile for using on multiple sites. Ok, this seems like the best fix until the release then. I didn't know you could output the buffer with the header like that. Oh well, as of now it's doing the job. Thanks to the two of you!
  20. I'm having this problem in my RSS Feeds. The images are pulled locally in the regular posts so often times the images do not appear correctly in the RSS Feeds. Here's what I'm doing to fix it now: // send the output of the RSS feed, and you are done session_start(); ob_start(); $rss->render($items); $contents = ob_get_contents(); $contents = str_replace("<img src=\"/site/assets/files/", "<img src=\"http://clintonskakun.com/site/assets/files/", $contents); ob_clean(); echo $contents; ?> I use output buffering to fix the broken URLs in the RSS Feeds. Is there a cleaner/better way to do this?
  21. Hey guys, I've got a question about setting the body and headline field from the template. I've noticed when I set one of these fields and save the page, it doesn't actually save the value I set it to. Here's the code I'm using to set a headline: $website = $pages->get("user={$user}, path=/websites/"); $website->setOutputFormatting(false); if(!$input->post->headline) { $error .= "Please add your Headline. "; } else { $website->headine = $input->post->headline; } $website->save(); Is there something special I need to do to set this field?
×
×
  • Create New...