Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/10/2014 in all areas

  1. You don't really have to hook page not found... just check for ajax and a POST var in the init() of a autload module as I wrote before ... public function init(){ if(!$this->config->ajax) return; if($this->input->webservice){ $id = $this->input->id; echo json_encode(array("status" => "ok", "data" => $id)); exit; } } and you would call a url like your root http://domain.com/?mywebservice&id=10 or using post works with same code
    3 points
  2. I absolutely get your point, Soma. I’ve always been a trial-and-error kind of coder, so I tried a lot, built a lot of stuff the way I thought was right. I hated how bad my code was structured and how hard it was to maintain. So I experimented with ways to separate things, tried approaches like your “delegate” one but didn’t really arrive at a point of happiness. As I said I have been experimenting with other languages and frameworks like Ember, Rails etc. and I really fell in love with the burden of defining a meaningful and comprehensible structure being taken off me. Of course, the thing that brought me to PW was its freedom. But for me as a designer it was especially the freedom of how to build templates (as data containers) and how to present them easiy with PWs API at hand in your template files. But as soon as you want your PW site to do more than render web pages it (at least in my semi-semi-pro-dev experience) gets messy pretty fast when you try to wire things up to make a page do more than one thing. So I really think it’s justifiable to use PWs modular base to build a MVCish layer upon it. Especially when you think of the fact that native page rendering has been a module itself from the start. Of course it’s not ideal to have a dozen of concepts around. I’ve kept an eye on earlier modules/concepts going in a similar direction but they mostly just dealt with a certain part of my issue. So I started experimenting (again) to create kind of a proof of concept and I wanted to share this with the community. If there is a real MVCish approach that is/will be supported by PW Core Team I’d be more than happy to support it. Did I miss something here?
    3 points
  3. Often times, creating a side project is first and foremost scratching your own itch Or to start differently: Currently, I'm developing a site where I need CKeditor (and later jQueryUI Datepicker) outside of the admin, in frontend. I searched Google and the forums and found an approach to follow - but during the research the site laravel-recipes.com came into my mind (since I'm currently also looking into this framework). It's content consists of small, spot-on bits of information, for example: http://laravel-recipes.com/recipes/269 Just to think out loudly here, wouldn't it be nice to have a ProcessWire counterpart of such a site? processwire-recipes.com for example? Target group: Developers, from beginner to advanced Difference to these forums: Stripping the discussion part, concentrating on the info; and if done properly: bypassing the mediocre forum search, better tagging Difference to the official tutorial section: Focusing on not creating a whole site, but modular parts of it. Single solutions. For example: First child redirects (shameless plug, but this is the format of information pieces I'm having in mind) Difference to the API documentation: Situation-based ("I need this and that") instead of architecture-based Laravel.io (forum), laravel.com (official, and doc) and laravel-recipies.com possibly prove that these type of sites can coexist in a framework ecosystem, so I guess a recipes site would not cannibalize this forum here nor the doc section. A recipe site like this would live and die with its content, of course. I would be ready to share all the small pieces of information I encounter that would make a good "recipe". But that alone wouldn't be enough so this project won't survive without contribution of the community. What's your opinion on this? Yea or nay? Update: ...it just took, erm, nearly three months,... but here it is: https://processwire-recipes.com/
    2 points
  4. Just wanted to let you guys know that I have submitted a PR to Ryan to fix this issue: https://github.com/ryancramerdesign/ProcessWire/pull/823 Along with this, I wanted to note somewhere (for now here, although I will probably write a PW SVG tutorial sometime soon) that if you want to embed SVGs into CkEditor RTE fields and be able to drag to resize them, you need to add the following to the "Extra Allowed Content" section on the Input tab of the field: img[alt,!src,width,height] This allows the img tags to have width and height attributes, which allows you to resize the image to a fixed number of pixels.
    2 points
  5. It works. You might haven't configured all correct. This in the init() method public function init() { if($this->config->ajax && $this->input->it == "webservice/"){ if(!$this->input->action) return; $out = array( "it" => $this->input->it, "action" => $this->input->action, "pageid" => $this->input->pageid, ); header('Content-type: application/json'); echo json_encode($out); exit(); } } and then this jquery ajax call work just fine <script> $(function(){ $.ajax({url:'/webservice/', data: {action: 'getPage', pageid: 1001}, method: 'post'}).success(function(data){ console.log("page", data); }); }); Nothing wrong with the PageNotFound as far as I can tell I'm using both approaches
    2 points
  6. Hi Led, What if you change "localhost" to "127.0.0.1"? And make sure PDO is enabled.
    2 points
  7. Thanks Oliver for sharing, just I can't really try it out for various reasons. I'm really digging people share their "MVC" approaches, but with this one more, it would be around 5 different ones now around. I'm not sure what to think about the impact on PW new and old users, support etc as it will split and create burdens for one to help someone using x-mvc approach. I have nothing against many ways to setup PW projects and while that's a strength it may even more is a weakness at the same time with its consequences. Really not against you and your approach, it just turns out by chance that I write this here. I'm not sure its worth of discussion. Wouldn't it be better to settle on one "MVC" ish setup that PW maybe even supports, it could help to keep focus on it and maybe even have official docs for it. Often it doesn't help telling a dev hey look there's this this and this but you can also use this and this, but that is not for PW 2.5 while that is only for php 5.5 and the other you can't use if you use multisite and those are not multilanguageable. Hard for me to explain well but I think one get the idea where I'm heading.
    2 points
  8. I just tested it and I think this is what you want. Here’s a complete demo module: class NotFoundIntercept extends Wire implements Module { public static function getModuleInfo() { return array( 'title' => 'Not Found Intercept ', 'version' => 001, 'summary' => 'Hooks into pageNotFound so you can handle URLs that don’t belong to any page.', 'href' => 'https://processwire.com/talk/topic/8510-module-intercept-ajax-call/', 'autoload' => true, ); } public function init() { wire()->addHook('ProcessPageView::pageNotFound', $this, 'intercept404'); } protected function intercept404($event) { $url = $event->arguments('url'); if ($url != '/my_pseudo_page/') return; //Let pageNotFound() handle it header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK', true, 200); $name = $_GET['name']; if ($name) die("Hola $name! Como estas?"); else die("Sup, guest?"); } } Now you can open ejemplo.es/my_pseudo_page/?name=Manol and – provided that page doesn’t exist in PW – it will greet you. Of course, if the front page has urlSegments enabled, it will just accept that instead, and your module won’t be triggered...
    2 points
  9. I like GET because it’s associative and order independent and doesn’t care about missing values. They’re different tools for different jobs ¯\(ツ)/¯
    2 points
  10. Hi prototype and welcome to PW! What you are looking for is the PageTable fieldtype. It is in the core, but not installed by default, so go to Modules > Core and scroll down to ProFields: Page Table and install it. Even though it is tagged as a ProField, it is free and included by default with PW. Unfortunately we don't have any proper docs for this new fieldtype yet, but there are some good snippets of info throughout the forums: https://processwire.com/talk/topic/6546-pagetable-documentation/ https://processwire.com/talk/topic/8177-page-table-howto/ You should also take a look at the excellent extended version of it: http://modules.processwire.com/modules/fieldtype-page-table-extended/ Really opens up lots of great opportunities. Dive in and let us know if you need any specific bits of help.
    2 points
  11. I noticed that although there's an InputfieldSelect module, there wasn't a FieldtypeSelect that would produce a drop down list (via a "select" input) that would allow you to define a list of options in the field's configuration. (Somewhere in this forum, I saw that the "Page" fieldtype was suggested to do this - and it works - but it didn't seem as easy as it should be.) So, I went ahead and created a module to do it! After installing, you'll have a new "Select" fieldtype that will allow you to define the items you'd like in the drop down. You'll be able to define these options in a text box on the field's configuration screen. Just put each option on it's own line. Hope this helps someone out! Let me know if you experience any issues with it, find any bugs or if you have some ideas on improvement. EDIT: The module is now on github: https://github.com/Hani79/Processwire_FieldType_Select_Drop_Down (Thanks for the prompt to put it up there, Soma.)
    1 point
  12. TemplateEngineFactory The main idea of this module is to support the developer separating logic from markup. This is achieved by turning ProcessWire templates into controllers which interact over a new API variable to template engines like Smarty or Twig. The TemplateEngineFactory ships with a default engine "ProcessWire" that uses the internal TemplateFile class to render the templates (some of you may already be familiar with this concept). However, the module is constructed in a way that any template engine can be used, implemented as separate modules. Please check out the readme on GitHub for more details how it works: https://github.com/wanze/TemplateEngineFactory ... or in the modules directory: http://modules.processwire.com/modules/template-engine-factory/ Implementation of Smarty: https://github.com/wanze/TemplateEngineSmarty Implementation of Twig: https://github.com/wanze/TemplateEngineTwig Implementation of Jade (by dreerr, thanks!): https://github.com/dreerr/TemplateEngineJade How does it work? A controller (aka ProcessWire template) can have an associated template file which contains the markup to render. The folder where those templates are stored is configurable for each installed engine. If the Factory finds a template file with the same name as the controller, an instance to access the template is provided with a new API variable (called "view" by default). Over this API variable, you can set the dynamic variables that should be rendered. Hopefully the following example makes things clearer: // In controller file: /site/templates/home.php if ($input->post->form) { // Do some processing, send mail, save data... $session->redirect('./'); } // Pass variable to the template $view->set('foo', 'bar'); $view->set('show_nav', true); $view->set('nav_pages', $pages->get('/')->children()); As you can see, there is no markup echoed out. The corresponding template file is responsible for this task: // In template file: /site/templates/view/home.php <h1><?= $page->title ?></h1> <p>Foo: <?= $foo ?></p> <?php if ($show_nav): ?> <ul> <?php foreach ($nav_pages as $p): ?> <li><a href="<?= $p->url ?>"><?= $p->title ?></a></li> <?php endforeach; ?> </ul> <?php endif; ?> In the example above, "ProcessWire" is used as engine. If Smarty is the active template engine, the corresponding template file could look like this: // In template file: /site/templates/smarty/home.tpl <h1>{$page->title}</h1> <p>Foo: {$foo}</p> {if $show_nav} <ul> {foreach $nav_pages as $p} <li><a href="{$p->url}">{$p->title}</a></li> {/foreach} </ul> {/if} Note that the API variable acts as a gateway which connects you to the activated template engine. We can switch the engine behind without changing the controller logic! (I know that this is probably not a very common need, but it's a cool thing anyway ) For further information, please check out the readmes on GitHub. Please ask questions if anything makes no sense - sometimes it's hard to get my explanations Cheers
    1 point
  13. New Module which adds 1 more, but very tiny green buttons to the page list. It saves minimum 3 klicks to change page status from hidden to visible. Edit: update 11.12.14 Module provides up to 3 (more) buttons in page list to toggle status (hidden/visible, published/unpublished and locked/unlocked). Enable/Disable the buttons in the settings (screenshot) ProcessPageStatusToggler.module
    1 point
  14. Introducing PVC PvcCore: https://github.com/oliverwehn/PvcCore/ PvcRendererTwig: https://github.com/oliverwehn/PvcRendererTwig/ (coming soon) PvcGenerator: https://github.com/oliverwehn/PvcGenerator/ (coming soon) Each time I’ve built a ProcessWire page I’ve struggled with organizing (and separating) code, markup and stuff. Playing around with frameworks (backend as well as frontend) like Rails, Ember and stuff I really liked having a given structure, knowing where to put what piece of code. Therefor I started working on a MVCish way to deal with templates in PW that considers the $page object kind of the data/model layer and adds View and Controller upon it. First by just catching everything via a small processor file added to all PW templates as altFilename. I’ve digged a bit deeper since then and hooked into the native rendering process, have been refactoring my code base more than a dozen times. Now I got a first version that seem to work and I’d love some of you guys to try it out! PVC (instead of MVC) stands for Page-View-Controller, as it considers PW’s $page var the model/data layer. I’m still working on the README.md on GitHub to document the basics. So have a look for more detailed infos there. I’ll give you a short overview here: Code separation: PVC introduces views and controllers to your PW templates as well as multiple action templates. Controllers, as most of you already know, keep all the business logic. Controllers execute actions wired to routes (urlSegment patterns). Even routes with dynamic segements (e.g. /edit/:id/) can be defined and assigned to an action, providing input through $this->input->route. Values can be set on the controller to be accessable in your templates later on. It’s also possible to set dynamic values as closures to be calculated (e.g. using field values of the current page) on render. Also controllers allow you to set layouts, styles and scripts to be available in your layout or template. Logic can be shared through inheritance between controllers. Views introduce view helpers. Helpers are functions that are made available to you (only) within your template context. There are predefined ones like embed(), snippet(), styles() or scripts(). But you can implement your own helpers easily and share them among your view classes through inheritance. Action templates contain the actual markup. Every action defined in a controller uses its own template. So the same page can display content accordingly to the action that was addressed via urlSegments/route. Within templates you can access all field values and values set on your controller like globals (e.g. <?=$title?>). Modular renderers: PVC implements rendering through separate renderer modules. PvcCore comes with PvcRendererNative that gives you template syntax the good ol’ PW/PHP way. A Twig renderer is in the making. And maybe you want to build your own renderer for the template syntax of your choice? I consider the module an early Beta version. So make sure to try it within a save environment! Would love to get some feedback (and error reports). I’m no professional developer, so code quality may suck here and there. So I’m glad for inputs on that, too. Also there is some old stuff in there yet, I still have to get rid of.
    1 point
  15. What others should you do? "Powered by Awesomeness" maybe?
    1 point
  16. 1 point
  17. Hi there, I'm still facing a little issue with the new updated version of this module. If I set NO limit when fetching data, I have an automatic limit set to 25, although my maximum amount in the configuration page is set to 50. If I set 'limit=0' in my request, it 'works', it fetches ALL data (event though I set my maximum amount to 5, for example). So it's not a big problem since I can manage my limit manually so it is consistent, but I wonder if that's the expected behavior... To me, the maximum amount should override any manually set limit, and if no limit is set, then the maximum should be the limit. I mention it since it caused me a little trouble on my site. Maybe someone will find this useful
    1 point
  18. Worked it out... <?php $tag = $page->name; ?> <?php $matches = $pages->find("tags=$tag"); ?> <?php foreach ($matches as $match) : ?>
    1 point
  19. (On mobile, haven’t tested) Maybe try hooking into ___PageNotFound() in ProcessPageView. It gives you the requested URL, so you can check if that’s what your module expects and process it. That way your module could remain self-contained. If $input isn’t populated at that point, you should always be able to go through $_POST.
    1 point
  20. I'm I was (solution below) experiencing the same as below on PW 2.5.2, after installing via softaculus(which uses minimal site profile) on a cpanel based hosting: except, When I try to reach www.seconddomain.com it displays as if I'm using www.maindomain.com Also, http://www.seconddomain.com/www.seconddomain.com/ redirects to http://www.seconddomain.com/ SOLVED: needed to add www.seconddomain.com to $config->httpHosts in /site/config.php
    1 point
  21. Whoops, sorry, I’m embarrassed. I only skimmed the code samples. @Manol: if I understand correctly, you want to create this “pseudo page” (web-accessible, but not any distinct file or PW page) from within your module?
    1 point
  22. @Jan....minus the urlSegments bit, that's exactly one of the answers I provided in my post above (#2)...which @Manol didn't consider as the solution
    1 point
  23. You can create a web-accessible php file anywhere on your server and bootstrap ProcessWire from there, without creating a page as far as PW is concerned. An example: <?php /* This file is nowhere in particular and not a template or anything. */ require_once("./cms/processwire/index.php"); $name = $wire->input->post->name; if ($wire->input->post->name == 'manol') { $m = $wire->modules->get('CoolModule') die($m->welcome($name)); } die('Hello anyway.'); I have no experience with this, so I can’t tell you about potential drawbacks, if there are any. Another way to avoid creating a “page” would be to allow urlSegments for your root page and handle the input there. It would look like any other page but it won’t disturb anyone’s aesthetic sensibilities in the admin backend.
    1 point
  24. No, although you could use the parent pages you already have: Bassisten, Fluitisten, and Trombonisten. In your example, the groups only go up to C. If you’re only dealing with a few items, it might be fine to do all filtering with Javascript. You could add an id attribute with the group’s name to your <ul> element, and simply hide all the others if the user selects a filter. Sorting could be implemented this way as well. However, that’s not a ProcessWire solution. To do the filtering server-side with PW, you will want to accept GET parameters in your page template. GET parameters are those values that sometimes appear at the end of URLs. On your page, it could look something like this: http://www.deliciousthoothpaste.nl/muzikanten/?filter=bassisten or http://www.deliciousthoothpaste.nl/muzikanten/?sort=descending or even http://www.deliciousthoothpaste.nl/muzikanten/?filter=bassisten&sort=descending Now the page /muzikanten/ has these variables built in and you can use them in your template. They are in the $input->get API variable. $sort = 'title'; if ($input->get->sort === 'descending') $sort = '-title'; //Put a - in front to sort Z-A $muzikanten = $item->children("sort=$sort, sort=id"); //always sort by id to break ties consistently foreach($muzikanten as $muzikant) { ... } Now you just need to get the user to visit your page with the GET parameter in the URL. As soon as he selects a sorting option, you send him to it using Javascript: window.location = '/?sort=' + selection; As you can see, Javascript is sort of required if you want the changes to apply (i. e. to reload the page) immediately. You can however avoid this by setting up a form with a submit button. The downside is, of course, that the user has to press the button in addition to selecting a value from your dropdown. <form method="GET"> <!-- If you leave out the action attribute, it will just reload the page, but with the added parameters --> <select name="sort"> <!-- this is the parameter name that will be in $input->get --> <option value="ascending">A-Z</option> <option value="descending">Z-A</option> </select> <input type="submit" value="Apply Filters" /> <!-- gotta click here to do stuff --> </form> (Not too firm on the HTML syntax here, best read up on it yourself)
    1 point
  25. Hi Richard, If you use the pageField method, then every "tag" creates a page that has a unique name. Example (green-energy, shark-sandwiches, turtle-soup). The autocomplete field presents the user with the page title, so they would select tags like (Green Energy, Shark Sandwiches, Turtle Soup). Same applies for adding new tags. Now you can use UrlSegments to find pages with your multi-word tags because they will be in a format like /domain/tags/green-energy/
    1 point
  26. Christian, thanks a lot for this very useful template! The JSON output seems to skip my image field though. My field is named "imagenes", maximum files allowed is set to "0" (not limit), formatted value to "automatic", and the Inputield Type to "Image". Is there something that I need to change? Edit: I see that the function "getImageFieldInfo" only takes into account a single image. Edit 2: I've managed to get it to show various images by changing lines 175 to 178 to: foreach ($images as $key => $image) { $data['data'][$trim_field_name]['path'][$key] = $host . $url . $id . "/" . $image['data']; } (Note: I've removed the description field as I don't need it).
    1 point
  27. Have you seen these posts: https://processwire.com/talk/topic/7441-using-git-instead-of-ftp-in-shared-hostings/ https://processwire.com/talk/topic/2885-what-filesfolders-should-be-added-to-gitignore-for-regular-development/ https://processwire.com/talk/topic/5417-using-git-with-a-cms-for-version-control-and-deployment-on-multiple-machines/ Might get you started.
    1 point
  28. So, let's launch this finally! › https://processwire-recipes.com/ ‹ As you can see, it's a work in progress. The design is going to change, Nico at the helm, and once we got a "critical mass" of recipes, another way of structuring recipes (the "table of contents") will also go online. To contribute, you can post your recipes either in this thread and we'll pick it up, or - codey - via Pull Request on GitHub of this repo here. Frankly, that's the favoured way, simple and a good start dive in to GitHub and this form of Open Source contribution. As always, feedback (and of course, contribution) is really welcome. We're always eager to learn - and helping to learn new stuff and create a place to spread some PW knowledge, that's what PWR was about in the first place Big big thanks to my partner in crime owzim who, among other things, contributed the - imho - heart of this tiny project: a textfile-to-page-importer. Finding an elegant way to contribute was one of the reasons this took so long, and during Beyond Tellerrand conference, it finally clicked into place.
    1 point
  29. Ok, I have committed a new version that supports protection via the API. You can now do: // all optional, except "page_protected", which must be set to true/false // if setting it to false, the other options are not relevant $options = array( "page_protected" => true, "children_protected" => true, "allowed_roles" => array("role1", "role2"), "message_override" => "My custom login message", "prohibited_message" => "My custom prohibited access message" ); $page->protect($options); Let me know if you have any problems. EDIT: I am wondering if in your case dedicated code might be a better solution. This module stores the protection info in the module's data DB field. While this works great because there is no need for special fields to be added to the templates of a pages to be protected, I am worried you might come across some scaling issues if you have thousands or potentially millions of users, all wanting to protect various pages. I have no idea on the scale of your social network, but this is definitely something to consider.
    1 point
  30. This gets you the label in the context of the entered template. $templates->get("template_name")->fieldgroup->getField('body', true)->label; You could also do this to get for the template of the current page: $templates->get($page->template->name)->fieldgroup->getField('body', true)->label;
    1 point
  31. Template files, by default, need to be in the templates directory, not a subdirectory. But that does not mean you cannot include files from other directories. I don't know what design differences you will make, but assuming that you have detected what device you are on (kiosk or other would be the best starting point), then just serve up the portion of the template that you need. You could either use php to include another page (which could be in any directory for your organisational purposes - there is no technical reason for it to be anywhere particular) or just divide the page up and serve up only a portion. For simplicity, I would probably go for the first. So, for the home page, for instance, you have a template called home.php The only code in this template would effectively say <?php // some detection stuff resulting in getting a $kiosk value - I have no idea what! if($kiosk){ include(./kiosk/home.inc); } else { include(./web/home.inc); All your templates would basically have the same code. The .inc files would then contain everything your normal template file would. Something like that.
    1 point
  32. Have this in my bookmarks, never used it, but looks like it might come in handy for your needs. http://fontello.com/ It lets you pick the icons you need and export it as a web-font, you can even upload your or other icon fonts and use those
    1 point
  33. Thanks! You’re right apeisa, think it would be better to rename it?
    1 point
  34. Resurrecting this slightly, but I did something along these lines just now with help from this thread (actually approached it netcarver's suggested way from the first post). It's one where I wanted to skip the first page of adding a name (for events in a calendar) but didn't want to use a repeater - which would achieve the same, but I wanted separate pages. Code as follows: In init function: $this->pages->addHookBefore('ProcessPageAdd::execute', $this, 'generateName'); The function that does the work (specific to my case): public function generateName() { if ($this->input->get->parent_id == 1019) { // 1019 = some page where we want to auto-generate child page names $page = new Page(); $page->parent = $this->input->get->parent_id; $page->name = $this->pages->get($this->input->get->parent_id)->count()+1; $page->template = 'child-template-name'; $page->addStatus(Page::statusUnpublished); $page->save(); $this->session->redirect("../edit/?id=$page"); } } So it checks we're creating a page under a certain parent, sets the right template, creates a page using an integer as the name based on the count of pages under the parent page and then takes you to the edit form for that page. The beauty of it is that since there has been no title entered so far, the user has to fill out the page fields - well title at least - to continue. So why did I do something so convoluted here? Because for what I'm using the title field for I needed to allow duplicate titles, so different names is key to this. The individual pages themselves will never be visited - they're just being pulled into a table into the parent page. Of course I could have used repeaters, but on this occasion I didn't want to. I think that with a little work, and the addition of multiple config lines like in my ProcessEmailToPage module you could expand this to monitor certain parent pages, hook into new page creation and create the page with a specific child template nice and neatly instead of hardcoding it as above. When I get time I might just do that... which might not be any time soon For now the above code works though for anyone wanting to adapt it to do something similar.
    1 point
  35. All fields are assumed to have at least a "data" field, so you can also query it just by specifying the field name without "data", i.e. $p = $pages->get("images%=mode");
    1 point
×
×
  • Create New...