Jump to content

Wanze

PW-Moderators
  • Posts

    1,116
  • Joined

  • Last visited

  • Days Won

    10

Everything posted by Wanze

  1. Are you talking about the permission to access the module? Or different behavior based on roles? The first one could be solved pretty simple like this: public static function getModuleInfo() { $permission = (wire('page')->parent->name == 'setup') ? 'role-a' : 'role-b'; return array( 'title' => 'Foo', 'summary' => 'Bar', 'permission' => $permission, ); }
  2. You have to use textdomains. The translations strings are parsed statically from the source code and are bound to a file. From the docs: echo __('Save', '/site/templates/common.php'); Cheers
  3. Do you need to know if a member page already exists or is this always the case? If the member page already exists: $member_page = $pages->get("template=member,name={$user->name}"); if ($member_page->id) { $member_page->of(false); $member_page->profiel = $sanitizer->text($input->post->profiel); // .. $member_page->save(); // Better to a redirect here after saving stuff $session->redirect('./'); } else { // Member page not found... strange. How to handle this case? } Cheers
  4. I guess you have a javascript error somewhere. Check the js console for errors for example with chrome's devtools or firebug. Also I noticed that you include jquery two times. Cheers
  5. As Martijn said, $this can never be used in a static context (ok in PHP actually it's possible but very dangerous). You could move the initialization with the translations into the constructor, it should work: class SomeModuleName extends WireData implements Module, ConfigurableModule { /** * Returns gender type * * @static * @return string */ private static $gender = array(); public function __construct() { self::$gender = array( 1 => $this->_("Male"), 2 => $this->_("Female"), ); } }
  6. Hi wilsea, Try adding a trailing slash to the url /processMaths/admin/adduser/ Pw does a redirect if there is no slash, I guess that's why you loose your $_POST data.
  7. You're welcome. I just realized that this module needs some love from me soon And sorry, you're right. It won't trigger the download unless page A does call the render method somewhere in the template. But it should work then if you call it. I'll test this evening. On page A, if you don't want to output the a link but still make the download work, you could call the method without echoing out its output, like this: $modules->get('Pages2Pdf')->render();
  8. Hi pwFoo Assuming I understand what you need, I think this should work. At your page B, you can append ?pdf=1 to the link which points at page A. Example: <a href="<?= $pages->get('pageA')->url . '?pdf=1' ?>">Download PDF from page A</a>
  9. You're welcome But I think this module is not very helpful for your task. It's mainly useful if you want to provide one corresponding PDF per page. It does also store the PDFs under /site/assets/files/ for caching purposes - not what you want actually if I understand you correctly. In your case, I guess i would be easier to use for example mpdf to create your PDFs dynamically on the fly. About security: If your booking is somehow linked to the user in ProcessWire, this could be as easy as creating a new template with a corresponding page. This template, let's call it confirmation_downloads first checks if the user is logged in, otherwise throws a 404. Then you can pass along a get parameter with the booking ID. Next, the important check would be if the user of the given ID is the user who booked. If this is the case, you could use mpdf to generate a nice PDF and directly download it. I'm planning to improve this module by switching from TCPDF to mpdf and write a wrapper class which helps to generate PDFs. I think this will be a separate module. Pages2Pdf itself then uses the new class only to generate the PDFs.
  10. Thanks sounds nice! Just had a quick look at the code: I think that it does not need to be a Process module. Process modules are only needed if you have a module that runs in the Pw backend. In your case, you could just extend WireData instead of Process. Anyway, thanks again for writing this! Cheers
  11. Hi JasonS, Hmm it looks like the wire method is missing. What version of ProcessWire are you using? With version 1.2.1 I used the wire method two times: https://github.com/wanze/ProcessGoogleAnalytics/commit/81cb793eb7870226389b3609ab78f6af27602344 Can you try to change the two lines where this method is called like this: Edit: In the file /site/modules/ProcessGoogleAnalytics/ProcessGoogleAnalytics.module // $this->wire('breadcrumbs')->append(new Breadcrumb($this->page->url, $this->page->title)); wire('breadcrumbs')->append(new Breadcrumb($this->page->url, $this->page->title)); // $this->wire('processHeadline', $startDate . " - " . $endDate); Wire::setFuel('processHeadline', $startDate . " - " . $endDate); Does this solve the issue?
  12. Well a blank page usually means a PHP error you're not seeing for some reason. Or a blank template? Try enabling debug mode by setting $config->debug = true; in /site/config.php Maybe you get some useful error messages. Otherwise, you could also check your error log in /site/assets/logs/. Cheers
  13. $product->save; $product->save(); First is a field, second is a method
  14. I like this. I think a nice object oriented implementation in the background combined with pure php functions for the template context would be great I would go as short as possible: <div class="foo"><?= ul( li($pages->find('template=foo,limit=25') ) ) ?></div> <?= ul( li('Home') . li($pages->get('/') ) ?> <?= a($page) ?> // Produces a standard link to a page with href, <?= ul( li( a( img($page->images) ) ) ) ?>
  15. Hi Can, Yep, that's the correct behavior. Hidden will exclude a page from $pages->find() calls, unless you specify "include=hidden" in your selector. Think of a hidden page like a page that should not be visible in your navigation or lists, but still accessible when one knows the direct URL. Unpublished really means that the page is not yet ready/published for the public, here a 404 is displayed. The same goes for pages with templates that do not have a physical template file associated. Be careful when logged in as superuser, if I remember correctly you'll see unpublished pages. In order to simulate the website for a guest visitor, you could use another browser or the private/incognito mode $pages->get() is an explicit call to retrieve a page. ProcessWire assumes that you want to get it, no matter if it's hidden or not Pw is throwing an 404 if you enter a path that does not exist. Or if a page you want to visit is unpublished or does not have a template file (because Pw does not know what markup to render). You can also throw a 404 anytime yourself, though that is already more advanced stuff. Could you maybe describe us what you want to do? Why would you want to prevent showing a 404? Cheers
  16. Hi reno, I think it is doable with two hooks. One hook would return false for Page::viewable() for the ProcessPageList page. Another Hook can be used to redirect your users to a custom admin page after login. I've only used the second one in a project, but I think something like this should work: // This needs to be an autoload module public function init() { $this->addHookBefore('ProcessHome::execute', $this, 'rootPage'); $this->addHookAfter('Page::viewable', $this, 'viewable'); } /** * Redirect users with custom-role to another page after login */ public function rootPage(HookEvent $event) { if ($this->user->hasRole('custom-role')) { $this->session->redirect('custom-admin-page/'); } } /** * Don't give users with custom-role access to Pages page */ public function viewable(HookEvent $event) { $page = $event->object; $user = $this->user; if ($page->id == 3 && $user->hasRole('custom-role') { $event->return = false; } }
  17. I think there is no general answer possible It very much depends on your configuration of MySQL, assuming you're not using another database. If the query is simple and you have indexes or query for the primary key, it will probably be very fast Maybe you can do some performance testing for both possibilities? Cheers
  18. I'm not sure I understand your structure, but I think the query could be optimized. Couldn't you get all the listings with one query, something like this: $listings = wire('pages')->find("template=listing,parent=/listings/"); // Then pass the page directly in your function, no need to call find() again in the function foreach ($listings as $listing) { echo generateListing($listing); }
  19. I don't have a migration script, because I've implemented this before starting the project But should not be hard, I would do a command line script, bootstrap ProcessWire and then code something like this: <?php // Bootstrap Pw // Make function wireMove, function mostly copied from wireCopy function function wireMove($src, $dst) { if(substr($src, -1) != '/') $src .= '/'; if(substr($dst, -1) != '/') $dst .= '/'; $dir = opendir($src); if(!$dir) return false; if(!wireMkdir($dst, true)) return false; while(false !== ($file = readdir($dir))) { if($file == '.' || $file == '..') continue; rename($src . $file, $dst . $file); $chmodFile = wire('config')->chmodFile; if($chmodFile) @chmod($dst . $file, octdec($chmodFile)); } closedir($dir); return true; } // Start migration - Loop your pages // You could split by templates and use limit/start to get this done in multiple iterations. // Limit depends on your server memory $pages = wire('pages')->find('template=shibby,limit=2000'); foreach ($pages as $page) { $old_path = wire('config')->paths->files . $page->id . '/'; $new_path = PagefilesManager::makeCustomPath($page); if (wireMove($old_path, $new_path)) { @unlink($old_path); } } Please only use on a copy of your installation, there will for sure be bugs as I've written it in the browser. You will need to make some modifications, but maybe it helps you as a starting point. Cheers
  20. Sorry I really should try out things first before proposing features that are already implemented I can accomplish this by setting min/max value of row/column to the same value. Nice! This would be great. When setting default columns, the first row (Header) should be protected. I tried to enter only one row with three values: Column1, Column2, Column3 After saving, I get the three columns. But when choosing "Insert row below", the new row is inserted above. When entering data and hitting enter, it swaps the rows again but overrides the header value. But works fine with more than two rows
  21. I meant to restrict those possibilities (e.g. as checkbox). If the client should not add new columns, then the item in the context menu in Handsontable should not be active or visible at all. Sorry was not that clear
  22. Idea for features Define columns already in the config. The module then displays the handsontable-grid but without data. This way, I can control the data which is entered more precisely. Maybe add some more options like:Enable creation of additional columns Enable to insert additional rows ... These two settings would be very useful for situations where you already know the schema of the data and want to restrict the client from messing up things. Great module anyway, I just thought to write it down before I forget Cheers!
  23. This is awesome! Thank you very much
  24. FYI: https://github.com/ryancramerdesign/ProcessWire/issues/432
  25. Hi Sevarf2, Here are my notes to the two files that were patched. The PagefilesManager::url() method is hookable so theoretically there is no patch needed. But since I needed to hack that file anyway, I did not use a hook. Just ask here if you have any questions. I think it would be nice if the developer could define a specific strategy for saving the files (with Hooks). I will open an Issue on GitHub and provide a proposal to ryan. Edit: I do not use pagefileSecure feature, and actually have no idea if it would work with those "hacks" Patches: /wire/core/functions.php function wireMkdir($path, $recursive = false) { //if(!is_dir($path)) return false; $chmodDir = wire('config')->chmodDir; if ($recursive && $chmodDir) { return @mkdir($path, octdec($chmodDir), true); } if(!@mkdir($path)) return false; if($chmodDir) chmod($path, octdec($chmodDir)); return true; } /wire/core/PagefilesManager.php static public function makeCustomPath(Page $page) { // Make subfolders per ID - always two digits (or one per folder) // Example: ID=1780, path = /site/assets/files/17/80/ // ID=19814, path = /site/assets/files/19/81/4/ // ID=205478, path = /site/assets/files/20/54/78/ $tmpPath = ''; $digits = str_split("{$page->id}"); foreach ($digits as $k => $digit) { $tmpPath .= $digit; if (($k+1) % 2 == 0) $tmpPath .= '/'; } if (substr($tmpPath, -1) != '/') $tmpPath .= '/'; return $tmpPath; } === protected function _createPath($path) { if(is_dir($path)) return true; return wireMkdir($path, true); } === static public function _path(Page $page) { $config = wire('config'); $path = $config->paths->files; //$publicPath = $path . ((int) $page->id) . '/'; $tmpPath = self::makeCustomPath($page); $publicPath = $path . $tmpPath; $securePrefix = $config->pagefileSecurePathPrefix; if(!strlen($securePrefix)) $securePrefix = self::defaultSecurePathPrefix; // securePath has the page ID preceded with a prefix which PW's htaccess blocks http requests to //$securePath = $path . $securePrefix . ((int) $page->id) . '/'; $securePath = $path . $securePrefix . $tmpPath; // we track this just in case the prefix was newly added to config.php, this prevents // losing track of the original directories //$securePath2 = $path . self::defaultSecurePathPrefix . ((int) $page->id) . '/'; $securePath2 = $path . self::defaultSecurePathPrefix . $tmpPath; [.. continue method...] } === public function ___url() { return $this->config->urls->files . self::makeCustomPath($this->page); }
×
×
  • Create New...