Search the Community
Showing results for 'runtime'.
-
Hi sparrow, (RDFM) you will found this direct under the addonsdownload: Overwrite current page or root page Build a menu using a PageArray instead of a single root page so may you've got two menus one for the firstlevel and one for the second/subsites. In the basic theme that is shipped with the installation there is an example with the API and some if/foreach stuff that works without the addon. regards mr-fan more deeper in the added/updates section there is a good example to test/try added support for nav_selector property/field and selector_leveln (new in 1.2.1) You can now add a special property "nav_selector' to page(s) to define custom selector for rendering their children. This can be done on runtime or via a custom field added to pages to remotely control the selector. You can configure the name of the field by using the newly added option "selector_field". MarkupSimpleNavigation will look out for it and use it, otherwise it will use the "selector" option. You can now define selector on a per level basis. Simply use the _leveln suffix on the "selector" option, where n is the level number from the root parent. This is best illustrated by the following example: $pages->get(1001)->my_selector = "template=projects"; $options = array( "selector_level1" => "template=ressort", "selector_level2" => "start=0, limit=10", "selector_level3" => "template=news|events, sort=-created", "selector_field" => "my_selector" ); echo $nav->render($options); Note that "my_selector" has priority and will overwrite any other selctor or selector_leveln
-
Yeah for fields that are objects/arrays you need to turn off outputformatting. I don't really get/see why one would want or have to do this... and wonder if I miss something. If you copy all those fields content to another page including its url at runtime, why not take the page as you have it already? The url can't be overwritten like this as it is a method and not a property. You would need to hook into Page::path to modify a pages url.
-
"Continuous integration" of Field and Template changes
ryan replied to mindplay.dk's topic in General Support
I can't seem to duplicate this one. Can anyone else? I have a few work-in-progress files I've not yet committed, and don't think they should affect this, but that's my best guess. Can someone else confirm they are seeing "required: 1" regardless of the field's required state? Properties that begin with an underscore, like _dateInputFormat are for runtime use only. Previously it would blindly accept those. Now it remembers not to save them in the DB. I'll update the export function to exclude them as well. But since the property shouldn't be there in the first place, go to Fields > act_start_date > Alert. Check the box to delete that property and Save. Though if you don't see it listed as a property, you might also be able to solve this just by going to the field and saving it without doing anything else. -
I believe this is set in /wire/core/ProcessWire.php on line 80 (at least on latest dev branch) /** * Populate ProcessWire's configuration with runtime and optional variables * * $param Config $config * */ protected function config(Config $config) { $this->wire('config', $config, true); ini_set("date.timezone", $config->timezone); ini_set('default_charset','utf-8'); if(!$config->templateExtension) $config->templateExtension = 'php'; if(!$config->httpHost) $config->httpHost = $this->getHttpHost($config); $config->https = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443); $config->ajax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); $config->cli = (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || ($_SERVER['argc'] > 0 && is_numeric($_SERVER['argc'])))); $config->version = self::versionMajor . "." . self::versionMinor . "." . self::versionRevision; $this->setStatus(self::statusBoot); } Not sure if this would also be the place to add what you are planning, that is a bit beyond me. Using Sublime and i'm guessing most other editors you can very easily do a 'Find in Files...' for 'config->ajax' to see where it is used in the whole codebase. But it is defined in ProcessWire.php
-
Thanks apeisa, That works except that I want to use the resulting pages as part of a $pages->find( ) not just at run time. For example, If I have a Template and set of Pages representing Cities, and another Template and set of Pages representing Laws. I want to have a FieldTypePage in the Laws template that allows Cities as children, and use InputFieldSelector to make it easy to add page references. Then I could use Subfield Selectors to find all Laws for a given city/cities. With just the SelectorFieldType, I could output what Cities apply to a given Law at runtime in a template, but I can't access those values for searching/filtering. Make sense?
-
Well you just set the fields from the other page, and the $page will still be the same page object just with new content (on runtime). $p = $pages->get("/somepage/"); foreach($p->fields as $f){ $page->$f = $p->$f; }
-
Is this even possible? A template is tied to a page and its content is mapped to the fields attached to that template. If a page were to use another pages template these relations would be lost....I might be wrong here. Anyway, I don't really get what you are trying to do. Why would you want to use another template at runtime?
-
Thanks LostKobrakai But what is not as changing the template assigned to the page I'm invoking (at runtime)
-
This is just a notice and not an error. It still works. I just pushed a commit and upped version to 0.0.5 Fixes: - to remove that notice when rendering pages inside a page. - fix template object not showing settings and name Added: - a property "skipChromePhpLogger" you can set to a page object, at runtime before rendering, to skip logging. Example: $somepage->skipChromePhpLogger = 1 echo $somepage->render(); // will not trigger the logging for $somepage
-
Hi Nico I deleted some bits of the code, but even that bit doesn't get the user id, it just gets a 0 <?php /** * ProcessWire 'Hello world' demonstration module * * Demonstrates the Module interface and how to add hooks. * * ProcessWire 2.x * Copyright (C) 2010 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com * */ class FaceMail 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( // The module'ss title, typically a little more descriptive than the class name 'title' => 'Facebook Email Publish', // version: major, minor, revision, i.e. 100 = 1.0.0 'version' => 101, // summary is brief description of what this module is 'summary' => 'Publica noticias en Facebook y envia emails masivos', // Optional URL to more information about the module 'href' => 'http://www.processwire.com', // singular=true: indicates that only one instance of the module is allowed. // This is usually what you want for modules that attach hooks. 'singular' => true, // autoload=true: indicates the module should be started with ProcessWire. // This is necessary for any modules that attach runtime hooks, otherwise those // hooks won't get attached unless some other code calls the module on it's own. // Note that autoload modules are almost always also 'singular' (seen above). 'autoload' => true, ); } /** * Initialize the module * * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. * */ public function init() { // add a hook after the $pages->save, to issue a notice every time a page is saved $this->pages->addHookAfter('save', $this, 'publicaEnvia'); } /** * Example1 hooks into the pages->save method and displays a notice every time a page is saved * */ public function publicaEnvia($event) { $page = $event->arguments[0]; /** * 1.- sino es la pagina de noticia -> salir */ if($page->template != 'noticia') return; /** * 2.- si esta check facebook -> publicalo * @var [type] */ if($page->facebook==1) { include_once 'fb/facebook.php'; $appId = '70373825635****'; $secret = 'd30530a5dcd4e5829e6c8bc8ba72****'; // $returnurl = 'http://indinet.es/facebook/post.php'; $returnurl = 'http://casergi.com'; $permissions = 'manage_pages, publish_stream'; $fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret)); $fbuser = $fb->getUser(); $this->message("user " . $fbuser); } // facebook /** * 3.- se esta check enviar email a clientes -> envia correos * @var [type] */ if($page->enviar_a_Clientes==1) { $usuarios = wire(pages)->get("/acceso/access/users/"); $emails = $usuarios->children(); foreach ($emails as $email) { if($email->email) $this->message("enviado a: ". $email->email. ", "); mail($email->email, $page->title, $page->publicidad, "From: cassergi.com\nContent-Type: text/html"); } $this->message("enviado por correo a los clientes"); } } }
-
has_parent isn't supported for runtime filtering with a path, not("selector") is filtering the results from the returned WireArray, there "has_parent" isn't supported in the same way as in a find selector. There's a path is converted to the ID before running the query. Regarding performance and such your second example is the way to go.
- 1 reply
-
- 1
-
-
- has_parent
- not()
-
(and 2 more)
Tagged with:
-
Using ProCache With Wilcox' Adaptive Images Plugin
Martijn Geerts replied to bytesource's topic in Modules/Plugins
The Adaptive Images plug-in you've linked to is probably the best solution for small website with not many visitors and no Pro Cache. I do like the concept of your adaptive image solution the mosts. But on the same time I don't think it's possible. Say the visitor who firstly visits the page has a 27" iMac, he creates the static cache file for Pro Cache. The next visitor has an iPhone on a sloppy connection. You can't serve them the cached version. So you need to serve your page in runtime and create a new cache. And I do think you don't want to create for every width a new image. Bandwidth detection is very tricky. The solutions by SiNNut are clever, but don't cover every aspect. There's clever detection for 3g and other cellular settings that would bypass the test for the performance. Great but doesn't work if I hook my iMac to my phone as internet deliverer, then the actual test kicks in. (Logical and it does what it must do) Testing network speed shouldn't be done every image, you're losing speed over there so they take a snapshot, one test to decide which route to take. This snapshot could be to positive or to negative. A to positive result we definitely don't want. I'm not really convinced with the bandwidth at the moment. Please tell me if I'm wrong here. -
Questions using Apeisa's shopping cart for selling festival tickets
Soma replied to joe_ma's topic in Getting Started
Just want to mention that the shop module isn't a very complete solution and for anything special you will need to get your hands dirty. You won't get it working the way you need without modifying every shop module and make it your own completely. You could take it as a kickstart to your own shop. Just for clarification, using the repeater support currently in the shop module is meant for variations. Means the page the repeater is on is the product. If using this the saved item will have this format. PageTitle: RepeaterTitle There's no support for other fields than the title! But one could use the title field of a repeater to save more than just a title. Maybe a "title, date, location" that constructed on page save with hooks, or on runtime modifying the $page->title of a repeater. Note that also every repeater is a page in the back and this makes it easy for the shop to take a variation as a page with it's own ID. Repeaters can have they're own price field of not it will take the page price field. So as you might found out you can loop the repeater out and create a add to cart form for each. Since it is a repeater page, shop module recognizes it as a own product/variation. Currently you seem to use this system for events that require multiple tickets, so - EventPage - repeater: EventTickets - repeater: Event2Tickets So far so good, but it seems you even need variations for the price for each "ticket", but you already have used variations for the tickets for the event. This will get tricky as there's no support for multiple prices per item. So no way to get further with this approach unless you completely adapt the shop system. What you could try also is to add each ticket as a subpage instead of in the repeater of the event page. Then you can use repeaters to on those subpage's still to create variations for one ticket, member and nonmember. Each having their price. - EventPage - EventTicket1 (childpage) - repeater: member (item to add to cart) - repeater: nonmember - EventTicket2 (childpage) - repeater: member - repeater: nonmember This could work out better and you still can construct your event page just using childpages and their repeaters to have options (maybe as a select) Then, you "only" have to adapt cart, checkout and management module to have Productitle: repeatertitle do what you need. -
Hey adrian - quick question - what about supporting getting the video title? I used to have clients put in the youtube ID and then i could get the thumbnail and the video title from yt api at runtime, but now i'm using your module since i prefer storing the poster image locally; but now i can't get the title of the video unless i somehow regex out the video id from the URL.. tia!
-
Include & Bootstrap Processwire - How To Access Admin pages
Gazley posted a topic in General Support
Hi there, I would like to access the ProcessWire API from another PHP application at runtime and this is quite straightforward. However, I wonder if there is any guidance about URL re-writing and the general requirements for accessing the ProcessWire Admin/User pages for the loading of content which will not be done through the application consuming the ProcessWire API. Thanks. -
I m very new to Processwire, I have worked in PHP but not much experience with Processwire. I have created a template 'school_acvitity'. Now, at runtime i create a new role 'school1' and assign that role edit, create and add permission by using Processwire API. It shows the fields(edit, create , new) marked in the template Access tab for the role school1. But when the user with the role school1 login it doesnt get the option for edit new. After this if I manually deselect the permission to create new pages through admin, the user gets the option to create new pages. the code is : $editRoles = $template_->get('editRoles'); $addRoles = $template_->get('addRoles'); $createRoles = $template_->get('createRoles'); $editRoles[] = $id; $addRoles[] = $id; $createRoles[] = $id; $template_->set('editRoles',$editRoles); $template_->set('addRoles',$addRoles); $template_->set('createRoles',$createRoles); $template_->save(); Appreciate any help for the above issue.
-
Technically, the code is not the same; one if filtering by a field called "architects" the other by the parent. (i.e., the City).. Hope the below explains this: This is the function findSkyscrapers function findSkyscrapers($selector) { $validSorts = getValidSkyscraperSorts(); // check if there is a valid 'sort' var in the GET variables $sort = wire('sanitizer')->name(wire('input')->get->sort); // if no valid sort, then use 'title' as a default if(!$sort || !isset($validSorts[ltrim($sort, '-')])) $sort = 'title'; // whitelist the sort value so that it is retained in pagination if($sort != 'title') wire('input')->whitelist('sort', $sort); // expand on the provided selector to limit it to 10 sorted skyscrapers $selector = "template=skyscraper, limit=10, " . trim($selector, ", "); // check if there are any keyword searches in the selector by looking for the presence of // ~= operator. if present, then omit the 'sort' param, since ProcessWire sorts by // relevance when no sort specified. if(strpos($selector, "~=") === false) $selector .= ", sort=$sort"; // now call upon ProcessWire to find the skyscrapers for us $skyscrapers = wire('pages')->find($selector); // save skyscrapers for possible display in a map mapSkyscrapers($skyscrapers); // set this runtime variable to the page so we can show the user what selector was used // to find the skyscrapers. the renderSkyscraperList function looks for it. wire('page')->set('skyscraper_selector', $selector); return $skyscrapers; } Expanding that... For architect.php: We look in the field "architects" //the code findSkyscrapers("architects=$page") //is actually saying... $skyscrapers = wire('pages')->find($selector); //which can be expanded as... $skyscrapers = wire('pages')->find("template=skyscraper, architects=$page, limit=10");//find pages whose field "architects" == this architect (e.g. John) For city.php, we look for children pages of the page we are viewing, e.g. New York...i.e. the parent. It also says this in city.php The code... //the original code findSkyscrapers("parent=$page")); //can be expanded as such... $skyscrapers = wire('pages')->find("template=skyscraper, parent=$page, limit=10");//find pages whose parent is this page (e.g. New York) Hope it now makes sense...
-
ProcessImageMinimize - Image compression service (commercial)
apeisa replied to Philipp's topic in Modules/Plugins
thanks for the honest post. Your service definitely got me interested right from beginning. I think main reason for only one free account - there is not much to test. Your service is super helpful, but I have no rush to test it before I have need for it. I already know how it works and what it does. Also - pw community is pretty small compared to many others. I think you should offer rest api and plugins for other platforms too, if you really want to focus on your service. About your site - it definitely promotes the service well... but maybe you should focus on why page speed matters and how much images affect on that? Finally - I think service that does it on runtime (when uploaded) would be preferable, since no need for any custom template code then. -
My host tells me I have "ii librsvg2-2 2.26.3-1 SAX-based renderer library for SVG files (runtime)" installed. Is this really RSVG?
-
Exclude pages from find if there's no template file.
Soma replied to Martijn Geerts's topic in Wishlist & Roadmap
This viewable check is something done on runtime and not on db level. Here an example to do what you want: $excl_tpls = "template!="; foreach($templates as $tpl){ if($tpl->filenameExists()) continue; $excl_tpls .= "$tpl->name|"; } $excl_tpls = rtrim($excl_tpls,"|"); foreach($pages->find("parent=1, $excl_tpls") as $p){ $content .= "<p>{$p->title}</p>"; } -
Good to now! I was able to pull this off like this for now. Thanks a lot for your input! Maybe a config page will be better for a public module, off course. <?php class EmailNewUser 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( // The module's title, typically a little more descriptive than the class name 'title' => 'Email New Users', // version: major, minor, revision, i.e. 100 = 1.0.0 'version' => 101, // summary is brief description of what this module is 'summary' => 'Send New users a welcome email', // Optional URL to more information about the module 'href' => '', // singular=true: indicates that only one instance of the module is allowed. // This is usually what you want for modules that attach hooks. 'singular' => true, // autoload=true: indicates the module should be started with ProcessWire. // This is necessary for any modules that attach runtime hooks, otherwise those // hooks won't get attached unless some other code calls the module on it's own. // Note that autoload modules are almost always also 'singular' (seen above). 'autoload' => true, ); } /** * Initialize the module * * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. * */ public function init() { $this->pages->addHook('saveReady', $this, 'sendEmail'); } public function sendEmail(HookEvent $event) { $page = $event->arguments[0]; if ($page->template != "user") return; // stop here if this isn't a User // Only send an email if the User page is published (A new User goes live) if($page->isChanged('status') && !$page->is(Page::statusUnpublished)) { $body = "Welcome {$page->name}!"; $this->message("Welcome {$page->name}! A welcome email has been sent to {$page->email}."); @mail($page->email, "welcome, {$page->name}!", $body, "From:xxxxx@xxxxx.com"); } } }
-
Let me elaborate a little bit more: I've been trying to pull this module off, and I haven't found the correct way to hook it. If I'm not mistaken, hooking into 'saveReady' in this case will trigger after saving AND editing the user. So In this case, it should trigger when the user page is Published (a.k.a the user is live and should be welcomed! ). Looking into the hooks' list, I haven't found said hook or similar. So, I must be missing something, right? Note that i've tried to hook after 'added' as well, and in this case it triggers after the name is set (and the page is first saved), so the user still hasn't filled his email to begin with. <?php class EmailNewUser 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( // The module'ss title, typically a little more descriptive than the class name 'title' => 'Email New Users', // version: major, minor, revision, i.e. 100 = 1.0.0 'version' => 101, // summary is brief description of what this module is 'summary' => 'An example to email New users', // Optional URL to more information about the module 'href' => '', // singular=true: indicates that only one instance of the module is allowed. // This is usually what you want for modules that attach hooks. 'singular' => true, // autoload=true: indicates the module should be started with ProcessWire. // This is necessary for any modules that attach runtime hooks, otherwise those // hooks won't get attached unless some other code calls the module on it's own. // Note that autoload modules are almost always also 'singular' (seen above). 'autoload' => true, ); } /** * Initialize the module * * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. * */ public function init() { $this->pages->addHookAfter('added', $this, 'sendEmail'); } public function sendEmail(HookEvent $event) { $page = $event->arguments[0]; if ($page->template != "user") return; // stop here if this isn't a new user $body = "your message goes here.. or you could specify it in module settings. Hello {$page->name}!"; $this->message("Hello World! You created {$page->email}."); @mail($page->email, "welcome, {$page->name}!", $body, "From:xxxx@xxxx.com"); } }
-
Return validated & cleaned selector string.
Martijn Geerts replied to Martijn Geerts's topic in API & Templates
Cool, tnx for the response. I Can imagine I gonna build some kinds of fieldtype from this. Because you've got some valid points about this. The lastline "Technically there's also a way to add a runtime value to a pages that is used in selector on page arrays." I don't fully understand. -
Return validated & cleaned selector string.
Soma replied to Martijn Geerts's topic in API & Templates
And what is wrong with your code, why must there be a better way? I just think you may not do it in template but after saving the page, it's also not kind of validation but a cleaning. So you wouldn't end with selectors being "false" saved to DB. ProcessWire hasn't some other way to do what you want/doing here, possibly also because of performance - it doesn't attempt to check for each selector if it's really valid/field exists. Technically there's also a way to add a runtime value to a pages that is used in selector on page arrays. -
[Probably daft] performance question: _init.php Vs. config.php for vars
ryan replied to alan's topic in General Support
This is a good way to go, and exactly what I do for predefined settings like required image dimensions and such. What you set in _init.php is for runtime use of your site's template files, and probably nothing beyond that. These variables are good for initializing placeholders that you'll be outputting in your _main.php (or whatever your appendTemplateFIle is called). This sounds like overkill to me, though of course use what works best for you. But you have a couple more options to consider: Use session variables, especially when you want the value to still be present and available on not just the current request, but subsequent ones (from the same user) too: // do this $session->set('my_variable', 'my_value'); // then retrieve it from anywhere (and at any later request) like this: $my_value = $session->get('my_variable'); Set an API variable: // do this wire('my_variable', 'my_value'); // then retrieve it from anywhere like this: $my_value = wire('my_variable'); Whichever route you take there, if you've got a lot of related values to set you might want to bundle them all into an array, so that you only need to set 1 session, API or config variable.