-
Posts
6,798 -
Joined
-
Last visited
-
Days Won
158
Everything posted by Soma
-
Has nothing to do with PW its in my theme. So yes.
-
Try to find if you have the session folder there if not create one in assets.
-
php doesn't work in a .js ...
-
Why relative and not absolute from root? I have no idea what your js and setup is so I can't tell.
-
To be honest I never use it cause in my teflon theme it requires only one click. :-D
-
Why not create a custom login? The only reason to not give them admin access is if they're just front-end users. I wouldn't want my front-end user loging through processwire admin login. If you give the user no edit rights in roles they can't access the admin and get a "continue" link after login Even if you want them to manage content from frontend only I would take that route as the permissions can be defined on the fly in your temlates. The other way would be as kongondo mentioned, and here's a code you could put in a autoload module (like HelloWorld.module). ready() is used because it get's you access to all API. public function ready() { if($this->page->template == "admin") { if($this->user->hasRole("editor")) { $this->session->redirect("/somapge/"); } } }
-
ProcessWire conference, Switzerland (central europe)
Soma replied to Soma's topic in News & Announcements
You can pay in EURO everywhere in Switzerland. -
Doesn't matter, I never used something else
-
Don't know if you guys already recognized that you can now open a page in the page tree by double clicking the title. It's in since a couple months and I think, including me, didn't recognize it's there. Have a nice day!
-
Yeah prev and next does only traverse inside a parent. But there's plenty traversal methods to get around it. $nav = ''; if($page->prev->id) { $nav .= "<a href='{$page->prev->url}'>prev</a> | "; } else if($page->parent->prev->id && $page->parent->prev->is("template=month") && $page->parent->prev->numChildren){ $nav .= "<a href='{$page->parent->prev->children->last->url}'>prev</a> | "; } if($page->next->id) { $nav .= "<a href='{$page->next->url}'>next</a> | "; } else if($page->parent->next->id && $page->parent->next->is("template=month") && $page->parent->next->numChildren){ $nav .= "<a href='{$page->parent->next->children->first->url}'>next</a> | "; } echo trim($nav," | "); Maybe need to adapt to your situation, but it's straight forward and everything is possible.
-
Module to Add UserID to pages and Control Edit Permissions
Soma replied to Peter Falkenberg Brown's topic in Modules/Plugins
<?php /** * Page edit per user created id * */ class PagesCreatedEdit extends WireData implements Module { /** * getModuleInfo is a module required by all modules to tell ProcessWire about them * * @return array * */ public static function getModuleInfo() { return array( 'title' => 'Pages created edit', 'version' => 1, 'summary' => 'Page edit only for created pages by user', 'href' => '', 'singular' => true, 'autoload' => true, ); } public function init() { // add edit permission hook for admin pages $this->addHookAfter('Page::editable', $this, 'editable'); } public function editable($event){ $page = $event->object; if(!$this->user->hasRole("editor")) return; if($event->return) { // only if edit rights are true if($page->created_users_id == $this->user->id){ $event->return = true; } else { $event->return = false; } } } } THis will get you there, not many different from frontend coding. -
I don't really understand as your code doesn't aswell. Ah now I get it sorry! What you're doing may a little inefficient to load all articles.
-
But it's too long and cumbersome to type.
-
Use $this or wire(). You can use fuel but Ryan once explained it's deprecated and an old artifact using it.
-
Module to Add UserID to pages and Control Edit Permissions
Soma replied to Peter Falkenberg Brown's topic in Modules/Plugins
PW already adds user id to page. You can get it with created_users_id... or something like this. -
You dont need all of these checks, the code I posted aleeady takes care of it.
-
What funny title.. I lol'd. It should be "WP got hacked need PW 2.0". I almost got a heart attack.
-
Nobody? Ok, since the tags introduced to the image field is just a plain text field, there's no other way than to loop all pages that have images loop all images to grab all tags, parse them to array and merge them. This gets you there but doesn't scale well. (Would those tags be page relations it would make it very easy to output all tags. I'm more of a fan of using page fields for tagging, but there's no image field with page tags and I use different image system if there's a lot of images with tagging and galleries. My ImageManager is one of the tools to have a page as image and you can attach as many fields to the image template to get those things done.) I often thought about what would be the best ways, with words in text fields all over the site, to collect them and I think you have two possibilities. Raw SQL query, or the above loop all pages and make that a markup cached snippet, if the amount and time to generate the list takes long, that runs every other day or hour. Also have as many restrictions, for template or parent, as you can get to make the query a little more efficient. To show what would be the API way you already got a good start and intuition with 2 foreach. The following collects all tags and makes a unique array to create a link list. EDIT: You can use url segments or GET parameter for the links. Since PW urls doesn't allow special chars there's a workaround inside the code now. /** * collect all tags * ====================================== */ $alltags = array(); // container $use_urlsegments = false; // find all pages that have images with tags $parray = $pages->find("template=basic-page|gallery, images.tags!=''"); // loop pages found and collect tags from images foreach($parray as $p) { // find all images that have no empty tags, yeah you can // also use find on Pagefiles array! $images = $p->images->find("tags!=''"); // loop them and add tags to array foreach($images as $im) { $tags = $im->tags; // convert "," and "|" to space and create array using explode if(strpos($tags, ',') !== false) $tags = str_replace(',', ' ', $tags); if(strpos($tags, '|') !== false) $tags = str_replace('|', ' ', $tags); $tags = explode(' ', $tags); // convert tag value to a page name using beautifyer, ü => ue, ö => oe // since special chars are not allowed in PW urls foreach($tags as $tag) { $alltags[$sanitizer->pageName($tag, Sanitizer::translate)] = $tag; } } } /** * generate links with tags as urlsegment * ====================================== */ // make the array unique and create a tags nav from it // add tags to the url of the page to later read it and // render a list of pages echo "<ul>"; foreach(array_unique($alltags) as $key => $tag) { if($use_urlsegments) { echo "<li><a href='{$page->url}$key'>$tag</a></li>"; } else { echo "<li><a href='{$page->url}?tag=$tag'>$tag</a></li>"; } } echo "</ul>"; /** * find all pages with the supplied tag * ====================================== */ // enable url segments on the template if using url segments if($input->urlSegment1 || $input->get->tag){ if($input->urlSegment1) { $tagvalue = $input->urlSegment1; // get the original tag value text from the cached array $tagvalue = $alltags[$tagvalue]; } if($input->get->tag) { $tagvalue = $sanitizer->selectorValue($input->get->tag); } // find pages with images having the requested tag $pa = $pages->find("images.tags~='$tagvalue'"); if(count($pa)) { echo "<h2>Pages found</h2>"; echo "<ul>"; foreach($pa as $p) echo "<li><a href='$p->url'>$p->title</a></li>"; echo "</ul>"; } } What was the other question again? And of course also found in my ever growing gist archive https://gist.github.com/somatonic/5808897 I'm too lazy to brew a SQL that does the collecting part. But there's people more clever than me that can help.
-
Why does $page->rootParent identify current section?
Soma replied to isellsoap's topic in Getting Started
Well obviously the condition isn't met so it's always false. For me I'm still trying to figure out what the heck you're doing with belongs_to.. seems redundant to me but maybe because I don't get it.- 16 replies
-
- current section
- semantics
-
(and 2 more)
Tagged with:
-
@k Without knowing further details/context, why not just build your own menu? It can be as simple as $menu = "<ul>"; foreach($pages->get("/sompath/")->children as $child) { $menu .= "<li><a href='#'>$child->title</a>"; if($child->numChildren) { $menu .= "<ul>"; foreach($child->children as $subchild) { $menu .= "<li><a href='#{$child->name}-{$subchild->name}'>$subchild->title</a></li>"; } $menu .= "</ul>"; } $menu .= "</li>"; } $menu .= "</ul>"; echo $menu; If you still want to go the module way, yes there you could make a hook to archive what you want. There's a couple examples in this thread, but there can't be enough I guess function hookTagsString($event){ $child = $event->arguments("page"); if($child->template == "form"){ // some check for template? as you like // now return your own link markup with $event->return $event->return = "<a href='#{$child->parent->name}-{$child->name}'>-$child->title</a>"; } } $nav->addHookAfter("getTagsString", null,'hookTagsString'); // render the navigation echo $nav->render(null, null, $pages->get("/somepath/"));
-
There seems to be a flood of tweets from the previous and there's a new "review" http://wpdaily.co/processwire/
-
You found the right one!
-
This can get really creative, as Ryan would now maybe come with something like: $nav = ''; foreach(array("prev","next") as $dir) { if($page->$dir->id) $nav .= "<a href='{$page->$dir->url}'>$dir</a> | "; else $nav .= "<span class='inactive'>$dir</span> | "; } echo trim($nav, " | ");
-
You need a timestamp!
-
There's an easy way to strip off chars with php method trim(). But in this case it can get tricky. Also regarding PageArray and explode doesn't really play a role here... But it sinks in better if you make faults. I think an idea would be to do: $nav = ''; if($page->prev->id) $nav .= "<a href='{$page->prev->url}'>prev</a> | "; if($page->next->id) $nav .= "<a href='{$page->next->url}'>next</a> | "; echo trim($nav," | "); Fairly easy concept. Depending on how and where you use it, this way it can get annoying as you get jumping link elements. You get sometimes "prev" sometimes "prev|next" links So maybe add some logic to show only a span when there's no next found. So you can fade it out with CSS. Now this way there's no need to trim. $nav = ''; if($page->prev->id) $nav .= "<a href='{$page->prev->url}'>prev</a> | "; else $nav .= "<span class='inactive'>prev</span> | "; if($page->next->id) $nav .= "<a href='{$page->next->url}'>next</a>"; else $nav .= "<span class='inactive'>next</span>"; echo $nav;