Leaderboard
Popular Content
Showing content with the highest reputation on 01/31/2017 in all areas
-
Is this it? http://stackoverflow.com/questions/19073270/stop-caching-for-php-5-5-3-in-mamp OPcache is enabled by default is some version of MAMP.8 points
-
You are completely right. I can't argue that "enabled-by-default" approach can lead to lots of security issues. That's why I am limiting the exposable pages only to selected templates. While the selector option is quite simple to implement I don't want to enable this kind of option because I believe it should not be this module's concern. The way I see it, if this module stays consistent and retrieves data only through $pages->find() api (or it's equivalent like $page->children(), $page->siblings() etc) that should give the user any type of control with the security. For example what you suggest could be achieved with a single hook. Say this is your template file where you expose your GraphQL api (something like /site/templates/graphql.php). <?php echo $modules->get('ProcessGraphQL')->executeGraphQL(); What you suggest could be achieved like this. <?php wire()->addHookAfter('Pages::find', function($event) { $event->return = $event->return->filter($mySecuritySelector); }); echo $modules->get('ProcessGraphQL')->executeGraphQL(); I would prefer users to approach security this way. This strategy to security gives full control for the user while allowing me to stick to a single rule when concerned about security and makes the code of the module much easier to reason about. I do realize that I could just insert the above code in the module and that's basically an implementation of what you suggest. But I don't want to encourage the user to solve security problems via module settings because no matter how hard I try, I won't be able to make this module dummy proof without limiting it's capabilities. Another thing I wanted to mention is that I see this module as a GraphQL representation of ProcessWire api. Like @Ivan Gretsky mentioned, if done right, this could allow us to build lot's of useful developer tools on top of this module. Even a mobile app that gives you limited site administration capabilities. But only if module is consistent with how ProcessWire behaves. And that includes the security of course. Oh no sir, not at all. I value your opinion very much. That's exactly what I wanted to hear from the community, opinions. I am thankful to you for mentioning this aspect of the module in it's early stage, before I started to implement other features that depend on it, like authentication or others that I might not think of right now.5 points
-
Just a thought, since this is what I try to do with my own modules: could you add hookable methods in ProcessGraphQL that allow implementing custom restrictions? These hookables could be no-ops if not hooked and receive all information about the query at the time of calling, enabling users to filter or reject queries before or after they've run. It's an intriguing module in any case. Thanks for sharing it with us!4 points
-
I'd suggest you to not waste your time and use srcset/picture element. If you really need to worry about browser support add picturefil to your page as well. Selection of best image size is simply best left to the browser and anything else probably isn't better than the picturefil polyfill.3 points
-
If funny things are going on when saving pages, it's also always worth looking if Apache's mod_security is active. If the answer is yes, I'd starting digging there (and disable it to test if it is the culprit). It wouldn't be the first time that changes between 2.7 and 2.8 trigger some filter mechanism there. I don't think there's anything wrong with the database if you don't see an error message.3 points
-
Something like this in your /site/init.php $this->addHookAfter('ProcessPageListActions::getActions', null, function(HookEvent $event) { $p = $event->arguments[0]; $actions = $event->return; if($p->template->name == 'aaa') { unset($actions['edit']); } $event->return = $actions; }); Just replace the $p->template->name with your condition - whether it's a real template name, or change to $p->parent->id to get the parent of the page table items - whatever works best for you.3 points
-
Pretty cool. I especially like the shortcuts of logs/sessions/cache3 points
-
3 points
-
Brilliant! Keeping up with the theme of learning....I can't stress enough the importance of debugging and testing your code. We have 2 great utilities in ProcessWire (besides PHP itself) to help us with these, namely $config->debug = true and Tracy Debugger. If you were testing with Tracy, she would have shown you where the error was, to be precise, these 2 PHP notices. Undefined variable config Trying to get property of non-object in... Why is this happening? Remember, you are including your *.inc files within the context of a function headerSwap(). Regarding the first notice, this takes us back to what I stated earlier; headerSwap() does not know what $config is. That variable is out of scope. In respect of the second notice, you are then saying give me the properties 'urls' and 'templates' of this variable $config. That will obviously fail, since notice 1# has already told us headerSwap() does not know what $config is. The solution, is as before. In fact, the hint was in your statement: ProcessWire 'cant' access. So, we give it access. As simple as this in your *.inc files: <?php echo wire('config')->urls->templates?>/main.css ?> Now you can call your function (see the suggested code in my edited post above): headerSwap($page->url);2 points
-
Maybe you should do a full mysqldump and do a search/replace in your code editor and import everything back in - should be much quicker given all those variations.2 points
-
2 points
-
I'd evaluate if the image really should be a background image in the first place. Otherwise this is the only way to have dynamic css backgrounds. I've added a bit more flexible version of yours below. <style type="text/css"> <?php // Selectors overwrite each other (by order) so no need for different mq selectors // Eg. xlarge (true) -> large (false by mq) -> medium (false by mq) => xlarge image // Eg. xlarte (true) -> large (true by mq) -> medium (true by mq) => medium image // Reverse order (default still first) when using min-width mqs foreach (['xlarge' => "", 'large' => "1499px", 'medium' => "849px"] as $imgSize => $mq) { if(strlen($mq)) echo "@media screen and (max-width: $mq) {"; echo ".image-$item->id { background-image: url('" . getImage($item, $imgSize) . "'); }";; if(strlen($mq)) echo "}"; } ?> </style>2 points
-
Sorry, I meant "new" whenever I wrote "edit". I spaced for a minute there This starts getting a little more complicated. Have a read here: You can probably cobble something together from that thread and some of my linked gists.2 points
-
Do you use the forum's search or Google? I recommend Google: $session site:processwire.com/talk2 points
-
Another quick update. Both the new "Copy Repeater Items To Other Page" and "Copy Table Field Rows To Other Page" actions now include an optional selector so you can define what repeater items / table rows will be copied.2 points
-
Just added a new "Copy Repeater Items To Other Page" action. It lets you append or overwrite items from a repeater on one page to one on another.2 points
-
Excellent! Glad you got it working. Edit: If you can mark this as solved then, by editing the title of this thread to [Solved]....rest of title...2 points
-
Welcome to the forums @timop_mug. A couple of questions: What version of 2.x exactly was that? Older than 2.4 for instance? Do you have $config->debug set to true? Any errors? Errors in the logs?2 points
-
You pass $page to the render method in the $options array. From the post I linked to above:2 points
-
2 points
-
Hi Jon, nearly a year ago you asked a $session related question. There were some hints in the answers, weren't they?2 points
-
I hear what Teppo is saying, but choosing templates would pretty much nail that concern. Developer has chosen to show those templates through API, so leaves no place for confusion in my opinion. I will definitely give this one a good ride.2 points
-
NOTE: This thread originally started in the Pub section of the forum. Since we moved it into the Plugin/Modules section I edited this post to meet the guidelines but also left the original content so that the replies can make sense. ProcessGraphQL ProcessGraphQL seamlessly integrates to your ProcessWire web app and allows you to serve the GraphQL api of your existing content. You don't need to apply changes to your content or it's structure. Just choose what you want to serve via GraphQL and your API is ready. Warning: The module supports PHP version >= 5.5 and ProcessWire version >= 3. Links: Zip Download Github Repo ScreenCast PW modules Page Please refer to the Readme to learn more about how to use the module. Original post starts here... Hi Everyone! I became very interested in this GraphQL thing lately and decided to learn a bit about it. And what is the better way of learning a new thing than making a ProcessWire module out of it! For those who are wondering what GraphQL is, in short, it is an alternative to REST. I couldn't find the thread but I remember that Ryan was not very happy with the REST and did not see much value in it. He offered his own AJAX API instead, but it doesn't seem to be supported much by him, and was never published to official modules directory. While ProcessWire's API is already amazing and allows you to quickly serve your content in any format with less than ten lines of code, I think it might be convenient to install a module and have JSON access to all of your content instantly. Especially this could be useful for developers that use ProcessWire as a framework instead of CMS. GraphQL is much more flexible than REST. In fact you can build queries in GraphQL with the same patterns you do with ProcessWire API. Ok, Ok. Enough talk. Here is what the module does after just installing it into skyscrapers profile. It supports filtering via ProcessWire selectors and complex fields like FieldtypeImage or FieldtypePage. See more demo here The module is ready to be used, but there are lots of things could be added to it. Like supporting any type of fields via third party modules, authentication, permissions on field level, optimization and so on. I would love to continue to develop it further if I would only know that there is an interest in it. It would be great to hear some feedback from you. I did not open a thread in modules section of the forum because I wanted to be sure there is interest in it first. You can install and learn about it more from it's repository. It should work with PHP >=5.5 and ProcessWire 3.x.x. The support for 2.x.x version is not planned yet. Please open an issue if you find bugs or you want some features added in issue tracker. Or you can share your experience with the module here in this thread.1 point
-
I can't believe I had never installed TracyDebugger, it is amazing. I did notice via the module, that all the variables I had declared in the _init.php file are now undefined (if I have my function called on the home template (I had $title = $page->get('headline|title'); and a few others). Removing the call removes the error, but at least I have a starting point and start trying to whittle down to the core issue.1 point
-
1 point
-
I figured it out. I changed this function: public function afterBuildForm(HookEvent $event){ if($this->user->isSuperuser()) return; $form = $event->return; foreach($this->data['viewTabs'] as $tab) { if(!$this->user->hasPermission("tab-".strtolower($tab)."-view")) { $this->removeTabs($tab, $event); } } foreach($this->data['hideTabs'] as $tab) { if($this->user->hasPermission("tab-".strtolower($tab)."-hide")) { $this->removeTabs($tab, $event); } } $event->return = $form; } to this: public function afterBuildForm(HookEvent $event){ if($this->user->isSuperuser()) return; $form = $event->return; $p = $event->object->getPage(); foreach($this->data['viewTabs'] as $tab) { if(!$this->user->hasPermission("tab-".strtolower($tab)."-view")) { $this->removeTabs($tab, $event); } } foreach($this->data['hideTabs'] as $tab) { if($this->user->hasPermission("tab-".strtolower($tab)."-hide") && $p->template->name == 'mytemplatename') { $this->removeTabs($tab, $event); } } $event->return = $form; }1 point
-
I doubt that's necessary in this case. He wants the current URL. @louisstephens, if all you want is the URL, then this should do it.. $homepage = wire('page')->url; Edit...but maybe easier just to pass the URL to the headerSwap() as a parameter like this: // Include New Header function headerSwap($url){ switch($url){ case "/page-link-one/"; include('headerone.inc'); break; case "/page-link-two/"; include('headertwo.inc'); break; default: include('default.inc'); } } You would then call the function like this: headerSwap($page->url);1 point
-
Seems to me that you need something like a PHP var: $_SERVER['REQUEST_URI'] instead of: $config->httpHost;1 point
-
$config->httpHost; This does not return a URL. It returns the Current HTTP host name. E.g. processwire.com, hence doesn't match your cases. Edit: In addition, since you are in a function, your headerSwap() function does not know what $config is. You will need wire('config').1 point
-
Currently no, the module is designed for site-wide use, but you could extend it to have a template selector in the module config, or just steal the relevant code from the module and add it as a hook in your /site/ready.php file.1 point
-
Just be aware that this doesn't prevent someone from editing it if they manually enter the edit url. To prevent that you would need to hook into: Page::editable, but keep in mind that this will cause problems with the PageTable field being able to edit this pages (unless you also account for that), so I think what you have is likely the best compromise.1 point
-
1 point
-
@Robin S and @kongondo -- THANK YOU! Both of your posts were super helpful. I guess I missed the part about needing to enable URL Segments on the correct template - so that was one of the issues I was having. Then after reading both of your posts, I think @kongondo's solution was the one I was originally after - but @Robin S' post illuminated a way of handling this problem I hadn't thought of. I will try them both and let you know, but I think that @kongondo's code should be usable right out of the box. POST-TINKERING EDIT: The need for URL Segments and mapping them to a new URL turned out to be the primary needed solution. I tried the Process Module Listing Solution, and while I think there's a lot of promise there, it would take some unnecessary work to create a fake folder for the pages in question. Thanks again!1 point
-
Yep, you'd need to translate each string on it's own. And keep in mind that translatable strings need all to be on a separate line for parsing reasons.1 point
-
Maybe if you explained exactly what you would like to achieve? Creating fields only to store unordered lists might be an overkill. Welcome to the forums btw..1 point
-
I think you got the wrong forum @alinamikecake. This is the ProcessWire forum. I see nothing regarding ProcessWire in your post, unless I am mistaken.1 point
-
I think the best option might have been the link abstraction feature in the textarea field, although I agree that Page Path History should also have taken care of it - is it definitely installed? Are there entries for the changed pages in the "page_path_history" db table? One possible way to fix this now would be to use the "Field Set Or Search And Replace" action from the AdminActions module. That will allow you to easily search and replace the old link with the new link in the required textarea fields.1 point
-
You could truncate the tables using phpMyAdmin or similar. See this, for instance:1 point
-
Hey @sreeb, I can't see what your issue is, but have you tried MarkupSimpleNavigation? I haven't ever ran into a menu I couldn't build with this module. Please read the entire thread since I know there are some other mega menu's mentioned in the thread of this module.1 point
-
So rather than specifying each field, this is why I suggested looping through them. This seems like a perfect idea for an action for the AdminActions module (https://processwire.com/talk/topic/14921-admin-actions/) action. Are you interested in putting one together, or would you like me to?1 point
-
You're completely right. Thanks for the hint, I'll change it. `core/Sanitizer.php` function textarea: /** * Sanitize input string as multi-line text without no HTML tags * * - This sanitizer is useful for user-submitted text from a plain-text `<textarea>` field, * or any other kind of string value that might have multiple-lines. * * - Don't use this sanitizer for values where you want to allow HTML (like rich text fields). * For those values you should instead use the `$sanitizer->purify()` method. [...] */1 point
-
Upvoted! Hopefully there'll be a solution to this soon.1 point
-
I can't recall asking that! my memory is rubbish, Yes that is exactly what I was looking for. Didn't show up in my search to save me looking like a spoon!1 point
-
Oh well, plenty of mistakes I made this morning... But at least I made you laugh1 point
-
Just a bit of an explanation for the next guy....: This will retrieve the pages, return a PageArray (PHP Object), which might end up using a lot of memory. Instead what you want is just the count of pages... Which brings us to this. This is very efficient. It will only count these pages and return an integer, not only doing its job very quickly but using next-to-nothing memory.1 point
-
1 point
-
@ethfun, You are missing some code. See a fuller example here (the original CMS Critic case study). What you need: Create your Hook. Have that run as early as possible, preferably in a file that is prepended to templates, for instance _init.php Enable URL segments in home.php. Note that this depends on how you want the URL to be rewritten. If you want to rewrite directly off root, then 'home' is where to go. For instance, if you want /blog/post/ to be rewritten to /post/, you will need to enable URL segments for the template file home.php since that is where ProcessWire will be looking. If you want /blog/posts/post-a/ to be rewritten to /blog/post-a/ you will have to enable URL segments on the template used by blog. The reason you are hitting 404s is that you haven't instructed ProcessWire to accept a URL Segment for that template, in your case, 'home'. Tell ProcessWire what to do when it hits that URL Segment enabled in #2 Mapping the above to code: In these examples, we want to rewrite /posts/post-a/ to /post-a/ 1# Hook: We have this code in _init.php. Any prepended file will do. //wire()->addHookBefore('Page::path', function($event) { @note: this or below, both work. $pages->addHookBefore('Page::path', function($event) { $page = $event->object; if($page->template == 'post') {// template used by 'post-a' // ensure that pages with template 'post' live off the root rather than '/posts/' $event->replace = true; $event->return = "/$page->name/"; } }); 2#. Allow URL segments in the template: Do this in the URLs tab when editing the template. In our case, that is the template 'home'. 3#. Handling URL Segments: in home.php Note that here I haven't taken into account situations where we have more than 1 URL Segment. See CMS Critic case study link above for the full example, specifically under the sub-section /site/templates/home.php. // check if we have a URL Segment if(strlen($input->urlSegment1)) { // render the blog post named in urlSegment1 $name = $sanitizer->pageName($input->urlSegment1); $post = $pages->get("/posts/")->child("name=$name"); if($post->id) echo $post->render();// render the post using its template file else throw new Wire404Exception(); } Just in case you are not sure how to have ProcessWire automatically prepend a file like _init.php, you add this to your /site/config.php/ $config->prependTemplateFile = '_init.php'; It should work as expected, without 404s. ps: I haven't completely digested earlier posts but I am guessing this is what you were after.1 point
-
Yes, I am aware of field permissions, thank you for reminding. I have not added support for them yet. Though it is definitely in my todo list for this module.1 point
-
"How about a simple button "Backup Now" to do it ?" - Sure "I am looking for a good solution to name the packages files." - Normally I name them like this: 2017-01-28_13-55-17-anything-i-find-descriptive.zip Since you dubbed the module "Duplicator" you also implied that it will also be able to help in installing so I just wanted to make sure I got that right. Thanks again for the awesome work!1 point
-
Good point. How about a simple button "Backup Now" to do it ? This is a thing in which I have to brainstorm; But definitely yes. I am looking for a good solution to name the packages files. Thanks here. It was stipulated on my first post, this will be the best part of the module This one is the hardest part to implement in my point of view so it will come in a second time but ASAP! What I mean by ASAP - I will finish to implement Amazon upload and the s/FTP as this last feature is required to jump to the installer one.1 point