Leaderboard
Popular Content
Showing content with the highest reputation on 02/04/2015 in all areas
-
Here is very simple abstract class that I hope would get ideas and contribution from community, so that different PW projects could use same payments methods in generic way: https://github.com/apeisa/Payment Currently Payment modules just assume it's found from /site/modules/Payment/Payment.php, but I would love to get it autoloaded somehow (I went with PW module dependencies and transformed the base class into PW module also). Also I have tried to keep this as minimum as possible - hopefully I have not left anything too important out. I have also created one two payment modules, that use this base class: https://github.com/apeisa/PaymentStripe/ https://github.com/apeisa/PaymentPaypal/ Please visit their repos for examples.3 points
-
I you're searching for a more flexible way to include snippets / not always whole sites, maybe this is a more appropriate function: // returns the output of snippets/contactform.php // the second argument is optional and will be passed to // the called file as multiple variables with the name of the key // also all api varables are available by default wireRenderFile("snippets/contactform", array("stuff" => $something ));3 points
-
Regarding frameworks I found this video. Are CSS Frameworks Bad? I agree with a lot of what he says. Also the point of Speed Speed Speed...3 points
-
Warning: You should not use the function iever($compare=false, $to=NULL) {} suggested by Joe because it has a big security issue. Visitors could change their HTTP_USER_AGENT in order to make $m contain malicious PHP code that will be executed by eval()3 points
-
If the field your settings a value for is not reserved or found in the templates fields it's just added to the object as runtime property. $page->notAAssingedField = "Hello"; echo $page->notAAssingedField; // outputs: Hello If you'd need more specific additions you could also use hooks to extend the page object or even make a own object, extending the existing page object. This new object can then be assinged to specific templates in the backend. Edit: As you've said you'll export it to JSON: A page object has lots of properties, which I don't know if you need all of them. So I would suggest taking a look at the json so it's not bloated with stuff you're not using, especially if it's for something like ajax.2 points
-
This is such a cool feature and beautifully implemented. I'd love to eventually see something like this where you can check multiple templates field could be applied to ...which reveals the list of fields incl. sorting I guess its a mix of @Ryan current work and @LostKobraKai idea earlier in the thread.2 points
-
Easily insert any complex HTML, Javascript or PHP output in your ProcessWire content by creating your own Hanna code tags. This module is based loosely on the WordPress Hana Code Insert plugin. A Hanna code tag looks like [[hello_world]]. A Hanna code tag with attributes looks like [[hello_world foo=bar" bar="foo]] using HTML style attributes or [[hello_world foo=bar, bar=foo]] using ProcessWire selector style attributes. After installing the module, you define your Hanna codes in Setup > Hanna Code. These Hanna codes that you define can then be entered within your body copy (or other text where you allow) and they will be replaced with the values defined or generated by your Hanna code. A common use case is to embed scripts or other bits of HTML or codes that would usually be stripped out by an editor like TinyMCE. However, Hanna codes can be more than just static snippets--they can be dynamic PHP or Javascript that outputs different things according to the request. PHP-based Hanna codes have access to the entire ProcessWire API. Hanna code accepts named attributes in the tag that can be passed as variables to PHP and Javascript Hanna codes. These attributes can be specified either in HTML attribute format or ProcessWire selector format. In either case, quotes should be used around the attribute value when the value contains whitespace or a comma. How to install Place the module files in /site/modules/TextformatterHannaCode/ In your admin, click Modules > Check for new modules Click install for TextformatterHannaCode Now to go Setup > Fields and locate the Textarea field(s) that you want to use Hanna codes with ("body" for instance). When editing the field, click the details tab, and select "Hanna Code" as the Textformatter. Save. Now go to Setup > Hanna Code and start defining your Hanna Codes! You may want to use one of the examples from this document to get started. Tag format Below is a Hanna code tag named hello_world with no attributes. If you pasted this into your body copy, you would get whatever the replacement value is that you defined. [[hello_world]] Below is a Hanna code tag named hello_world being passed attributes of foo, bar and foobar. If this were a PHP-based Hanna code, it would receive the variables $foo, $bar and $foobar: [[hello_world foo="bar" bar="foo" foobar="foo bar"]] Below is the same Hanna code tag as above, but with attributes more like ProcessWire selectors. You can use whatever format you prefer. Just note that unlike regular ProcessWire selectors, quotes (single or double) are required around any value that has whitespace. [[hello_world, foo=bar, bar=foo, foobar="foo bar"]] How to use Please make sure that you have completed the How to install section first. Then in your admin, go to Setup > Hanna Codes. Each Hanna code that you add has a type of either: Text/HTML, Javascript or PHP. The Text/HTML type is literally self explanatory in that your [[custom-tag]] is replaced with exactly the text you paste in. Anywhere that you type your [[custom-tag]] in your body copy will be replaced with exactly the static text you defined. More power opens up with the Javascript and/or PHP types of codes. These codes execute at runtime and thus can contain specific logic to produce different results. In fact, PHP Hanna codes have access to the entire ProcessWire API and are executed in the same manner as template files. Your PHP-based Hanna code should simply "echo" or "print" the replacement value. PHP example Create a new Hanna code with the name "children". Select "PHP" as the type. Paste in the following for the code: foreach($page->children as $child) { echo "<p><a href='$child->url'>$child->title</a>"; } Now go and edit a page that has children. In the body copy, enter [[children]] in the place where you want the output to appear. View the page, and you should see the rendered list of links to children. PHP example, part 2 Now lets take the above example further... Go back and edit your "children" Hanna code, as we are going to modify it to respond to a "parent" attribute. Change the code to this: if(isset($parent)) { // If $parent is an ID or path, lets convert it to a Page $parent = $pages->get($parent); } else { // otherwise lets assume the current page is the parent $parent = $page; } foreach($parent->children as $child) { echo "<p><a href='$child->url'>$child->title</a>"; } Go back and edit the page where you previously inserted the [[children]] tag, and change it to: [[children, parent=1]] (specifying the homepage) or [[children, parent=/path/to/some/parent/]] if you want to try something else. View the page and you should now see it showing the children of the homepage (or of another parent you specified). Please see the Javascript and PHP usage notes on the Hanna code entry screen. Security There are major security implications with a tool that will let you enter unfiltered text and code from your web browser. As a result, Hanna codes are meant for definition only by superusers and we recommend keeping it that way. Download Download the Hanna Code module from the ProcessWire modules page or from GitHub.1 point
-
You shall not objectify people, but you could objectify Textfields!!! Github: https://github.com/owzim/pw-fieldtype-yaml Module page: http://modules.processwire.com/modules/fieldtype-yaml/ Summary Field that stores YAML data and formats it as an object, when requested. Setup After installation create a new field, let's say called "people" and assign it to a template, or just edit an existing text-based field and choose Yaml for the type, save! In the Details-Tab you have an additional option, the Texformatter option is removed, because it does not make sense in this case. Parse as Default is WireArray/WireData, the data can also be parsed as Object or Associative Array. Associative Array is the fastest and the default output by the used Spyc parser, WireArray/WireData might be the slowest, but it's also the most feature rich. You can access properties like you are used to with pages or fields, like $page->person->get('title|name') or $page->people->find('age>30'). Usage Now, in your just created field you can put in some YAML like this: - name: Jane Doe occupation: Product Manager age: 33 hobbies: - running - movies - name: John Doe occupation: Service Worker age: 28 hobbies: - cycling - fishing In your template, or wherever you are accessing the page, you would use it like any other ProcesssWire data (if you set the parse option to either WireData or Object): $out = ''; foreach ($page->people as $person) { $out .= "Name: {$person->name} <br>"; $out .= "Occupation: {$person->occupation} <br>"; $out .= "Age: {$person->age} <br>"; $out .= "Hobbies: <br>"; foreach ($person->hobbies as $hobby) { $out .= "- {$hobby} <br>"; } $out .= "--- <br>"; } echo $out; More info about YAML: Complete idiot's introduction to YAML Specification Wikipedia Acknowledgements I've used a namespaced version of the Autoloader class from Template Data Providers The YAML parser is a namespaced version of Spyc Edit: updated the repo link1 point
-
Inputfield Page Source Display a string with the rendered output of the Page (per it's Template) in an Inputfield. The markup could be copied with a button click (flash enabled browsers) and/or copied manually from the Inputfield. The rendered output is a runtime only value which is not stored in the database. Potential Use Provide an easy way for editors to copy the sourcecode of the page for the use in newsletter services and such. Note ! This Inputfield should not be used in the page template directly. (could give some “funky” results ) Download on GitHub1 point
-
Hey, The Form API has CSRF protection build in, but if you for some reason don't want to use the API you can however use the CSRF protection. Its very simple but it took some time for me to find out, so i figured i share my findings with the rest. What is CSRF? First you need to create a token and a token name you do that as following: $tokenName = $this->session->CSRF->getTokenName(); $tokenValue = $this->session->CSRF->getTokenValue(); Very simple. Now what you want to do is create a hidden input field like this: $html .= '<input type="hidden" id="_post_token" name="' . $tokenName . '" value="' . $tokenValue . '"/>'; Now this will generate something that will look like this: You are done on the form side. You can now go to the part where you are receiving the post. Then use: $session->CSRF->validate(); This will return true (1) on a valid request and an exception on a bad request. You can test this out to open up your Firebug/Chrome debug console and change the value of the textbox to something else. Basicly what this does is set a session variable with a name (getTokenName) and gives it a hashed value. If a request has a token in it it has to have the same value or it is not send from the correct form. Well I hope I helped someone.1 point
-
Hey all I make a lot of HTML/CSS presentations (currently using an adapted version of this). I'm using Emmet to lazily write html tags, but I want to raise/lower (?) the lazy bar. In my mission to make my process as lazy as possible, I plan to build a PW template to help me construct future HTML presentations. I wonder if this would be helpful to others. Would anyone else be interested in HTML-based presentations as a PW module?1 point
-
Glad you like it Alan. For some more fun, keep one of those often-updated log files open in your browser, and watch it update automatically to show you the new log entries every time something gets added to it.1 point
-
I just submitted a PR to extend Ryan's new "Send to Templates" functionality on the Action tab to be an "Add/Remove fields from templates" function. Not sure if he will go for it as is - he might have something grander planned, but it was a quick addition: https://github.com/ryancramerdesign/ProcessWire/pull/902 There are some screenshots in one of the comments that shows how it works. Would be curious what others think of how it works if you feel like trying it out!1 point
-
Fields and templates have export and import utilities, that are usable from UI and API.1 point
-
I will probably be able to test it on the weekend throughly, but so far it looks stable and works like a charm.1 point
-
Okay, so after all those fixes, my testing seems to show that everything is stable. Everyone agree? I'd like to set this to stable in GH and in the directory.1 point
-
To be honest ProcessWire is the first system i've come across where requests have to be routed specifically to a GET param, but i guess it's just a code design decision. It does bring up some issues though with using PHP 5.4's local -S test server.1 point
-
There's many different options, so there's also a option to overwrite it in the render options. $p->render("template", array("prependFile" => ""));1 point
-
That’s in the module settings for the core module ProcessField /processwire/module/edit?name=ProcessField1 point
-
@mike1: thanks for finding that. I have removed this line with eval() in @joes code example.1 point
-
In CoreUpgrade you can always click on the name in the first column to "redownload" the current installed version.1 point
-
I got another little issue. If someone uses the quickpost function and fills out quickpost_body all line breaks will be removed. I don't think that is it necessary to use a rich text area here but maybe you can wrap it in a simple nl2br function? //@todo - SHOULD THIS BE A RICH TEXT AREA? - $p->blog_body = $this->sanitizer->textarea($this->input->post->quickpost_body); + $p->blog_body = nl2br($this->sanitizer->textarea($this->input->post->quickpost_body1 point
-
1 point
-
The date picker thing was confirmed by Ryan to be a bug, it'll be fixed in the next dev release.1 point
-
I usually use this approach for Hanna Code. A few initial lines in pure PHP code to init vars and prepare data enclosed in a <?php ... ?> tag and then follows the HTML "view" using PHP's alternative syntax to fill in variables and control structures like loops. <?php $images = wire()->page->images->findTag($tag); ?> <?foreach ($images as $image):?> <p><img src="<?=$image->url?>" alt="<?=$image->description?>"></p> <?if ($image->description):?> <small><?=$image->description?></small> <?endif?> <?endforeach?> This approach allows separation of logic from presentation but still encapsulates both within a Hanna Code component.1 point
-
Just crafted PayPal module also: https://github.com/apeisa/PaymentPaypal1 point
-
1 point
-
Craig, have a look at: https://github.com/conclurer/ProcessWire-AIOM-All-In-One-Minify/issues/17#issuecomment-474020401 point
-
@Joe: I think this should be doable without "eval". I think you should never use eval if possible... Why don't you just use: return $m[1].$compare.$to;1 point
-
Thanks Pete/colleagues for the work setting this up. Very cool and typically efficient.1 point
-
I missed that part about creating a JPG/PDF. pages2Pdf modules works great.1 point
-
you can create a PDF from a PW page, using the PDF module... it works great1 point
-
pankaspe, Welcome. You might want to look at the Repeaters field type , ProFields:Table, or ProFields: Multiplier (if it's a simple field), or there is also ProFields: PageTable that is free and part of the core, but I don't know if there is any documentation yet.1 point
-
1 point
-
owzim, I can't believe this exists, and that I missed it before now! I though, "Hmm, let me see if anyone has anything out there about using YAML with ProcessWire". ….and lo and behold, I find this awesomeness. Much appreciated.1 point
-
@renobird Thanks for the link. Pinegrow looks interesting. @pwired Trying new things lead me to PW. I will not apologize! @soma YES.1 point
-
Hi kathep, I haven't tried Blocs, but it looks nice. I've been keeping my eye on Pinegrow. I think with either of those it would be pretty easy to design your static pages and then hook the HTML/CSS/JS up to ProcessWire.1 point
-
The first (maybe naive) structure that come my ming is as seen on the screenshot below You may also want to look at the blog module here.1 point
-
Hello everybody, We've just updated AIOM to Version 3.1.4. This is a minor update including the following changes: Bugfix: CacheFiles for Pages are now deleted when a new minimized file is created Bugfix: An error is thrown if the document root is different to ProcessWire's base path If you find additional bugs or have some feature wishes, please open up a ticket at our GitHub repository. Thank you! Marvin1 point
-
Hi David, I'd be glad to take care of AIOM. I'm coming from the South of Germany. I work together with @phil at Conclurer, a web development company. If you want to, I can send you my personal mail address so that we can talk about AIOM. Thanks in advance, Marvin1 point
-
Hello, is there any way for AIOM to accept a FilenameArray object for minifying or do I need to convert the object to an array manually first?1 point
-
A few new/minor additions on the dev branch: You can now paginate with "limit=1" selectors. Previously ProcessWire didn't build the pagination information when a limit of 1 was specified. Now it does. ProcessWire now preloads pages that it knows it's going to need on every request. This speeds up everything slightly, as what was previously done in 6-7 queries is now done in one shot. Should you want to, you can also specify additional preloaded pages, though I don't think many (any?) would need to. Several optimizations to the PageFinder engine which improves the speed of certain types of queries. One of them is a $pages->count("selector") query, which is now even faster than before. Selector Grouping Added support for selector grouping to change the behavior of how they match. This is best explained by example. Lets say we're building a big news site, and we have a template called news-item that represents each news article. Each news-item page has a field called cats that is a multi-page reference to one or more category pages. This is a pretty common scenario in ProcessWire. The site has a lot of categories, so want to designate some categories as featured so that we can display featured categories on the homepage and elsewhere, with accompanying news items. Rather than just adding a featured checkbox, we add two fields to represent the date range that we want them featured: featured_from and featured_to. On our homepage, we want to display articles from all the current featured categories, so we build a selector like this: $items = $pages->find("cats.featured_from<today, cats.featured_to>=today, sort=-date"); ...but we end up with more news-items than we expect, including some that have categories that aren't actually featured right now. Why? Because each news-item can have multiple categories, and that selector above is saying this: The keywords there are "at least one", as "categories.featured_from" and "categories.featured_to" may not be referring to the same category. The only way to solve it was this: $categories = $pages->find("template=category, featured_from<today, featured_to>=today"); $items = $pages->find("categories=$categories, sort=-date"); That's easy enough... but now you can also do it like this, by prepending an @ to identify a group: $items = $pages->find("@cats.featured_from<today, @cats.featured_to>=today, sort=-date"); The "@" symbol at the beginning of "cats" is telling ProcessWire those are grouped together and "these must match the same exact page". This was added because there are situations where you need to perform your query with 1 selector rather than breaking it up. An example would be when used with the new InputfieldSelector module and Lister, among others. We will likely be adding more ways to perform complex matching scenarios with a single selector as well. Currently this "@" grouping applies only to multi-page reference fields, as I'm not sure yet where else it might be useful. It is only supported by selectors that hit the database at present (though will be completing it for in memory selectors as well). Not planning to extend it into that area at this time, but good ideas to think about for the future or for modules. It should already be fixed. If we're talking about the same thing, someone recently posted this to the GitHub issues list and I added their fix on dev. Adrian already knows this because we've been chatting in the GitHub issues queue, but for anyone else reading this, it has also been fixed.1 point
-
I'm in the process of building a complicated module and was thinking that being able to create the fields in the admin quickly, then export as a JSON string to use in the installer function would be much quicker than what I'm faced with at the moment - manually typing out the code for all the fields I need to add is taking a long time, so aside from the uses when copying fields/templates to other PW installations it would be fantastic to be able to generate the JSON and in a module's installer just do something like this if we wanted to change some template details or add some additional fields: $templatedata = json_decode($jsonstring); $fieldgroup = new Fieldgroup($templatedata->fields); $template = new Template(); $template->name = "template-name"; $template->fieldgroup = $fieldgroup; $template->save(); Or if we were happy with the template name we'd exported and all the fields, then this: // Adding template "template name" $templatedata = json_decode($jsonstring); $template = new Template($templatedata); // $templatedata contains template and field information $template->save(); The second option means you won't even know what the template is called unless you know how to read a JSON string, but I like its simplicity, and we can just put a comment above it as in my example Just a thought.1 point
-
$my_page->numChildren does also count hidden (maybe unpublished) pages, while $my_page->children does not include them by default. If you use count($my_page->children("include=hidden")), it's the same number Edit: Too late again1 point