Jump to content

landitus

Members
  • Posts

    181
  • Joined

  • Last visited

Everything posted by landitus

  1. Thanks Ryan! I'm applying your recommendations to the project and so far it's looking good! Thank you very much for all your input and code examples. Can't thank you enough!
  2. I guess then everything is working as it should, then. I'm glad that these custom validations can be accomplished! Thanks!!
  3. Not really, but thanks @kongondo. I've tried the default example for theme_advanced_styles and it didn't have any effect. Check out this screenshot of my settings. I guess it's not the same setting as described in the TinyMCE docs. Anyhow, I can't get any new element to show up in the format's dropdown.
  4. I was wondering if it's possible to add new formats to TinyMCE via the field's configuration. I'm trying to add a new format in the format's dropdown (the one with h2, blockquote, etc). I think it's possible natively with this setting: http://www.tinymce.com/wiki.php/Configuration:style_formats or this one: http://www.tinymce.com/wiki.php/Configuration:formats. This way, I can mark some text with the "note" format and it will render a paragraph with a class of "note", for example. Take a look at this example: http://www.tinymce.com/tryit/custom_formats.php
  5. @Pete, I was looking to do something similar for an events and news pages. I was wondering how would you deal with the URLs, since these are generated from the real title and not the user's generated title. Maybe this was not meant to work with URLs, but maybe it is.
  6. Hi adrian! Great module! I'm trying to use this field with FormBuilder and I'm having weird errors. When submiting the form I get an error: Notice: Trying to get property of non-object in [route]/www/site/modules/FieldtypePhone/InputfieldPhone.module on line 140 Have you tested it with Form builder? Is it compatible?
  7. 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"); } } }
  8. 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"); } }
  9. @teppo Thanks a lot for this example! I'm getting into learning hooks and this kind of examples are a lifesaver!! I think that you missed an "@" before the mail function. Also, shouldn't this mail fire only when a new user is created? If new user ... fire the email. How would this be translated into code here?
  10. Hi Ryan, I've been looking into this in more depth and I have an issue in the way the mobile app is going to check the webservice to look for modified/deleted items. It might be very special and unique to this very app, so the solution might not be ideal or close to your answer. The thing is: checking all items to see if they exist was ruled out by the mobile app developer (memory reasons or something like that). My first idea was to flag each product to "is_deleted" if they reside in the trash. This way, if the product is modified or deleted, it will always show up in the query. Deleted items are in the trash, and won't be seen or count in the tree. I didn't feel right to unpublish or set a field in a visible product instead of deleting in, a they would be seen in the tree. For me and the client, the tree what is visible on the site. This approach has the disadvantages you describe above, and it feels "wrong", but I still have not found a middle ground in which the app works and the CMS/webservice is bullet proof. I've told somethings about virtual deletion (which sounds like the trash), but it won't be ever deleted. I thinks is in Drupal. Anyhow, I was wondering if maybe there's another creative way to approach this with the limitations I've described. For know, my webservice checks all products (including the trash) and tags deleted products if they reside in the trash. // ... $new_query_string = "template=".$params['template'].", sort=".$params['sort'].", ".$modified." include=all"; // Find $q = $pages->find($new_query_string); //... I still have to sanitise the inputs! // Is deleted if($i->parent->url == '/trash/'){ $is_deleted = true; } else { $is_deleted = false; } Maybe I should post the whole code (it's long as it builds a custom json feed!)
  11. I was able to calculate the correct amount of repeaters by passing a ->value to the field. So this worked pretty well. The curious thing I'm getting the form saved even thought the validation is not passing. I'm getting a session page saved notification no matter what. Is this supposed to happen with this code? or I have to prevent the validation manually? <?php class ProcessValidateCalculator 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( 'title' => 'Validate Calculator', 'version' => 101, 'summary' => '', 'href' => '', 'singular' => true, 'autoload' => true, ); } public function init() { $this->addHookAfter('ProcessPageEdit::processInput', $this, 'checkRepeaterQuantity'); } public function checkRepeaterQuantity($event) { $form = $event->arguments(0); // ProcessPageEdit's processInput function may go recursive, so we want to skip // the instances where it does that by checking the second argument named "level" $level = $event->arguments(1); if($level > 0) return; $calculadora = $form->get("calculadora")->attr('value'); if(!$calculadora) return; // Datos // ========================================= $qty_datos = $calculadora->cant_datos; $datos = $form->get("calculadora_datos"); if(!$datos) return; // Validación: Datos if(count($datos->value) > $qty_datos) { $datos->error("El campo $datos->label tiene más items de los permitidos. $datos->label permitidos: $qty_datos"); } else if(count($datos->value) < $qty_datos) { $datos->error("El campo $datos->label no tiene la cantidad de items necesarios. $datos->label necesarios: $qty_datos"); } } }
  12. Thanks Ryan for the answer. I'm closer to understand how this could work. I chose to put the code inside a module, as I found it easier to test. I'm getting blocked by the following: No matter how many items the repeater has, the count always equals "1". I tried to use a $form->get("calculadora_inputs")->count(), or children but I get a huge error that this is not allowed. Let me post the code: <?php class ProcessValidateCalculator 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( 'title' => 'Validate Calculator', 'version' => 101, 'summary' => '', 'href' => '', 'singular' => true, 'autoload' => true, ); } public function init() { $this->addHookAfter('ProcessPageEdit::processInput', $this, 'checkRepeaterQuantity'); } public function checkRepeaterQuantity($event) { $form = $event->arguments(0); // ProcessPageEdit's processInput function may go recursive, so we want to skip // the instances where it does that by checking the second argument named "level" $level = $event->arguments(1); if($level > 0) return; // Simplified this part to test a simple quantity. $quantity = 1; $repeater = $form->get("calculadora_datos"); if(!$repeater) return; if(count($repeater) > $quantity) { $repeater->error("You have specified more than $quantity items"); } } }
  13. That's great Ryan! I'm going to check it out. Is it an alternative to check for products in the trash, with "include=all"? Do you see any downsides?
  14. I've been trying to do the following: I have 2 repeaters in a template and a I want to limit those repeaters to a number stored in another page. That number is then called in the template via a Select field (which is a Page relation). So when the user is editing the page, if the select says 3, then there are only 3 items allowed in the repeater. Should the user create 4, then a validation error should show up. How difficult is this to achieve? I've been reading this related thread but I still don't get it.
  15. Oh! I had the old plugin in the modules directory. I deleted the old plugin and now it works!!
  16. I've been able to move forward by re-thinking the code. This time, I've set a custom parameter "modified_since" which when set will filter the query with that date. I have not be able to solve how to notify the web-service when a product is deleted. One option would be to hide the product, following this thread, but that would clutter the page tree. How would you solve this problem?
  17. I'm getting the following error after updating to the latest version of the plugin. I've got it working in my local machine but in the server it shows the following error (image attached). The server has PHP version 5.3.20 installed.
  18. I'm building a custom web service to service a mobile app from a PW site. I'm very exited to extend the site's functionality with PW's flexibility. I would like to check if what I'm doing is 'safe' and I'm not overexposing the site to vulnerabilities. 1. The site should serve a json file when accessing a specific URL. I like to keep my site's URLs with a /json to keep everything mirrored in my template files. products.php ?php /** * Productos template * */ if ($page->name == 'productos' AND $input->urlSegment(1) == 'json' ) { include("./productos.json.php"); die(); } if ($page->name == 'categorias' AND $input->urlSegment(1) == 'json' ) { include("./categorias.json.php"); die(); } include("./head.inc"); ?> // ... GOES ON 2. The template in charge of generating the JSON output. Loosely based in Ryan's web service plugin. Is there something dangerous in here? products.json.php <?php /** * Productos JSON * */ // $_GET Variables from URL $types = array( 'limit' => $input->get->limit, 'sort' => $input->get->sort ); $params = array(); foreach($types as $name => $type) { $value = $input->get->$name; if($value === null) continue; // not specified, skip over if(is_string($type)) $params[$name] = $sanitizer->text($value); // sanitize as string else $params[$name] = (int) $value; // sanitizer as int } // Set defaults if(empty($params['sort'])) $params['sort'] = '-modified'; // set a default if(empty($params['limit'])) $params['limit'] = 10; // set a default $params['template'] = 'producto'; // Build query string to search $new_query_string = http_build_query($params, '', ','); // Find $q = $pages->find($new_query_string); // Results $result = array( 'selector' => $new_query_string, 'total' => $q->count(), 'limit' => (int)$params['limit'], 'start' => 0, 'matches' => array() ); $categorias = $pages->get("/categorias/"); $soluciones = $pages->get("/soluciones/"); foreach ($q as $i) { // ... // PREPARING some variables // ... $result[matches][] = array( 'id' => $i->id, 'template' => $i->template->name, 'name' => $i->name, 'created' => $i->created, 'modified' => $i->modified, 'url' => $i->url, 'producto_thumb' => $product_thumb, 'producto_imagen' => $product_images, 'producto_packaging'=> $product_pack, 'producto_ficha' => $product_sheet, 'title' => $i->title, 'producto_bajada' => $i->producto_bajada, 'body' => $i->body, 'categorias' => $product_categories, 'soluciones' => $product_solutions, 'calc' => $i->calc, 'rendimiento_min' => $i->rendimiento_min, 'rendimiento_max' => $i->rendimiento_max ); } // JSON header('Content-Type: application/json'); echo(json_encode($result)); 3. Finally, this seems to be working ok, but I was wondering: a. How can I check for products modified since date X? b. How can I notify the web service that a product has been deleted since date X? PW moves files to the trash and I would like to keep it that way but I can't imagine how to notify the webservice!
  19. I'm trying out the module to use it as a web-service for a mobile app. I'm querying pages that have images and attachments and the returning JSON output lists the "basename" but no URL or any other way to find the asset. Is there something missing? Should I need to query something else?
  20. Recently, Craft CMS added the Matrix field. Looks quite nice! Check it out here
  21. I'm exited to hear that Ryan! I hope you are able to release it soon!! Do you think it would be able to show images in the table? Like a thumbnail to represent a gallery or an user? This table list view would be be very useful to represent a list of image galleries, or even something more custom like pages created by the current user. That wouldn't necessary be in he plugin, but the elements and hooks could be in place, don't you think?
  22. This looks awesome! I can't wait to try it out in my next project! Thank you so much for posting this.
  23. That's a good workaround, indeed! I'll keep it in mind. Though I am very close to pulling off a custom table. I just don't want to give up!
  24. Ryan, I would like to know if this feature is still planed or if it was discarded. I am having the need to display pages in a table-like view in a new admin tab, and I've been playing around with a plugin to so. It looks like a lot of the functionality for this is already in place (ex. search results). I haven't been able to place a pagination, still. Like you said, I feel a table view is very useful in many cases: like displaying a list of pages with the author and tags, etc. I will try to post my code later.
  25. I would like to suggest Lato or Source sans pro, from google fonts: http://www.google.com/fonts/specimen/Source+Sans+Pro
×
×
  • Create New...