-
Posts
4,632 -
Joined
-
Last visited
-
Days Won
55
Everything posted by apeisa
-
I don't know if there is already a way to do this.. but what I need is some way to import fields & templates to new site. I try to explain: Let's say I create template "news" and it has fields: Title Datetime Summary Body Author I have created few template-snippets that like "Latest news" and "All news" etc. This is all fine and easy. But after this next client comes up with similar request: "we also want to show news on our site." (I say that 95% of our current clients have news on their site.) How can I easily give our next client these same fields & templates? Process could be import from other site or anything. Or should I create module "News" that creates needed fields & templates? And this should be easy enough, since after news we need have some formal templates for Events and maybe Forum etc... This all may sound like it is fighting "against" flexibility of ProcessWire, but I don't think it like that. After client asks "This is allmost what we need, but our News will require also Attachments and Place fields." it is trivial to extend their News-template, but leave others as is. Just some conventional ways of doing things, that we can write help docs and all people on our organization can help clients etc.
-
Thanks guys. I modified few lines on Ryan's snippet (to add level-n to class): <?php function treeMenu(Page $page = null, Page $rootPage = null) { if(is_null($page)) $page = wire('page'); if(is_null($rootPage)) $rootPage = wire('pages')->get('/'); $out = "\n<ul>"; $parents = $page->parents; foreach($rootPage->children as $child) { $class = "level-" . count($child->parents); $s = ''; if($child->numChildren && $parents->has($child)) { $class .= " on_parent"; $s = str_replace("\n", "\n\t\t", treeMenu($page, $child)); } else if($child === $page) { $class .= " on_page"; if($page->numChildren) $s = str_replace("\n", "\n\t\t", treeMenu($page, $page)); } $class = " class='$class'"; $out .= "\n\t<li>\n\t\t<a$class href='{$child->url}'>{$child->title}</a>$s\n\t</li>"; } $out .= "\n</ul>"; return $out; } Works nicely! Actually learned few new tricks from this also. Reason for this script is that I want to build generic "default site" that can be used pretty much "out of the box". Of course good only for simple and generic sites, but I need something that sales guys can demo and let clients to play with. Of course this can be useful in other cases too.
-
I wanted to try coding it, and turned out pretty simple. Of course the code could be cleaner (and I could be a better programmer ), but it is a start. There is one TODO: that I couldn't get right. Our current cms puts level-n classes for css-styling and wanted to add that into markup too, but couldn't find a way to get last item on loop. class simpleNav { /** * Holds the current page * */ public $page; /** * Root page, this won't be rendered, but pages below this will be * */ public $rootPage; /** * Keeps count of the current depth * */ public $depth; /** * Unique id for the most outer ul element * */ public $id; /** * Holds page id:s of all the pages on path * */ private $pathIdArray; public function __construct($page, $rootPage = null, $depth = 1, $id = null) { $this->page = $page; $this->pathIdArray = $this->_getPathNav($page); $this->rootPage = $page->rootParent; $this->depth = $depth; $this->id = $id; if(!$rootPage) $this->rootPage = $page->rootParent; } public function render() { if ($this->rootPage->numChildren > 0) { // Output the ul and id only if it's given echo "\n<ul class='navi level-$this->depth'"; if($this->id) { echo " id='$this->id'"; $this->id = null; // we want to give ID only for the first ul } echo ">"; $loopedPages = $this->rootPage->children; foreach($loopedPages as $child) { $class = "level-$this->depth"; // add "here" class if the current page is active if ($this->page === $child) $class .= " here"; // check if looped page is one of the parents of current page (or is current page) if (in_array($child->id, $this->pathIdArray)) $class .= " on-path"; echo "\n\t<li class='{$class}'>\n\t\t<a href='{$child->url}'>{$child->title}</a>"; if (in_array($child->id, $this->pathIdArray)) { $this->depth++; $this->rootPage = $child; $this->render(); } // TODO: If last element, $this->depth-- } echo "\n</ul>"; } } private function _getPathNav() { foreach($this->page->parents as $parent) { $this->pathIdArray[] = $parent->id; } $this->pathIdArray[] = $this->page->id; return $this->pathIdArray; } } Usage is pretty simple: $navi = new simpleNav($page); $navi->render();
-
Output could be something like this: <ul> <li><a>Products</a></li> <li><a>Services</a></li> <li class="on-path"><a>People</a> <ul> <li class="here"><a>Someone</a></li> </ul> </li> <li><a>Contact Us</a></li> </ul>
-
Yes. And nice bonus would be that it adds some classes on path.
-
Little offtopic: Just a thought, but maybe there should be an empty folder in place when you install pw? Just created blanko site and installed AdminBar (for first time actually), and I had to think for few minutes that where I put the files Qwertyeee: Welcome to the forums! Looks like a very useful fieldtype. Just quickly tested it and same ?? chars on my map also.
-
Some folks here have probably developed few different ways for recursive navigation. I was just starting to write my own, but thought that I ask from here first. Looking for something like this: - Products - Services - People -- Management -- HR ---- Matti Meikäläinen ---- Jaana Jallakkala ---- Will Ferrell -- Marketing -- Pets - Contact us
-
I know there is easy way to create tabs for content, but I would love simple setting (this could go to field settings) to place field to "right column". It could be something like 1/3 of full width. Great place for additional information.
-
It works. I only tested with allowRelative=false, but that side seems to work nicely! Thank you.
-
Big thanks! Looks great and I will test this tomorrow at work.
-
I have few additions for $sanitizier->url(). Currently it allows values like "I am url" -> "iamurl" and "www.url.com" -> "www.url.com". I made variable that allows us to drop relative urls, so these come always as: "" and "http://www.url.com" Of course this could be much better, but this suits my needs and I think many times needed: public function url($value, $allowRelative = true) { if(!strlen($value)) return ''; if(!strpos($value, '://')) { // URL is missing protocol, or is local/relative $dotPos = strpos($value, "."); $slashPos = strpos($value, "/"); if($dotPos !== false) { // something like: www.company.com/about or company.com $value = "http://$value"; } else if($dotPos === false) { if (!$allowRelative) { // We don't allow relative urls, so return blank $value = ''; } else { // relative URL like: /about/ or about/ // leave it alone } } } $value = filter_var($value, FILTER_SANITIZE_URL); return $value ? $value : ''; } Ryan, please code check this and make needed corrections. Also: what would be best way to contribute in code wise? Through GitHub? (I am posting this here now for just this reason).
-
How do I save contact form submissions as pages?
apeisa replied to Jim Yost's topic in API & Templates
Thanks Ryan. Very good post and pretty comprehensive answer again! I was thinking about using PW's image field, but not sure about it anymore. It would be just perfect in this use case. I probably end up doing both: using custom upload, doing security checks, renaming & saving to non-web accessible location and after that attaching that to PW's image field. $p->images->add("/path/to/image.jpg"); If I have image on server and on non-web accessible location, can I then use that add method? Does it accept paths also? Or do I need to transfer it to web accessible location first? -
How do I save contact form submissions as pages?
apeisa replied to Jim Yost's topic in API & Templates
Any best practices when saving images through public form? Thinking of saving those to /assets/temp/ -> saving page and getting image from /assets/imagetitle.jpg url -> removing image from temp. -
You cut Finland out of the internet? No!!! Evil plan, mr. Adam, evil!
-
We will see! (starts creating fake accounts who all like to stay in editor...)
-
I myself also prefer to see edited results again, just to be sure that everything is fine. I honestly think that ProcessWire is actually much more polished than most of the open source web apps - and not just young ones, but all apps in general. It is very polished in the outside (lot's of little details thought), but the polish that it has under the hood is amazing. Very solid foundation to build upon! Also - documentation is already in much better shape than most of the open source projects has. You really should be proud Ryan, and we are very pleased to be part of this in early stages. I am not speaking about this one, but I think Ryan you should be a little bit dictator on what comes to core features & settings. If everything is easily configurable - it just leads to larger codebase and many ways to achieve same thing. And that is very expensive in the long run: there is no clear best practices and when troubleshooting, we have to always check "what settings you use on your module x?" etc. Also, when we develop modules etc, then it is also harder if there is very little things that we can know for sure to work in certain way. People always - and I do mean everyone - want to get software in the way they like and have always done. It is understandable. But it's not bad thing to have many conventions over configuration and expect people to learn little bit of those conventions. In many cases it just makes sense.
-
Tiny update again: tooltips, two new icons & smaller hide button, fixed modal position. Works fine on: IE9, Chrome & Firefox. Haven't had possibility to test IE8 yet. EDIT: You can see tooltips in action here: http://www.screencast.com/users/apeisa/folders/Jing/media/9a10b4bb-d49c-4097-939c-824e9c729afc (I recorded this to show one bug that Ryan already fixed).
-
Sevarf: you are probably looking for this: http://processwire.com/api/include/
-
Thanks Ryan, nice to hear that it is already in good use! I pushed little fix to issue that Adam reported. AdminBar uses jQuery so it won't work nicely if there isn't jquery on templates (and many times there won't be). There is now option in module settings whether to load jQuery or not.
-
I changed fields to double and it works nicely. We actually need them to be floats rather than text since we want easily get queries like: all the events in 60km from this point, please. Interesting thing when changing to double: 24.9194 => 24.9194049835205. That cannot be real value, since my original data source (last.fm) had those with 6 decimals. Or maybe mysql have some mystical superpowers and internal location database
-
Ryan, thanks for this. Unfortunately it doesn't work (both api and admin saves with 4 decimals). I updated /wire/ with latest files and after that recorded this short screencast: http://www.screencast.com/users/apeisa/folders/Jing/media/b44e3208-f758-4103-8ecc-2c8849ac48f3
-
Outputting via simple echo, but it is also 4 digits when editing field through admin.
-
Does it work? It seems to always round with 4 decimals (saving values through api). I have tried set value of "Number of decimal digits to round to" to 2 and 6 and I always end with decimals like: 60.2311, not 60.23 or 60.231148
-
How to add multiple page references through api?
apeisa replied to apeisa's topic in API & Templates
Universally there are many bands with the same name. I'm not sure how Last.fm API handles those - their site usually outputs country in parenthesis in case of duplicates (or more). I am not worried about those: in our case it doesn't really matter that much. Good idea with md5. It will be cleaner for sure!