Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/18/2017 in all areas

  1. Are all podcasts in MP3 format? If 'Content-Type' => 'audio/mp3 header and mime type of podcasts do not match, you'd get the error. Try removing 'Content-Type' => 'audio/mp3' from $headers array. In case it doesnt work, https://gist.github.com/benrolfe/5453074 claims to solve iTunes byte range problem. Changing the $file_path at line 2 to $page->mp3->filename should be enough.
    3 points
  2. It's not for regeneration, but reading caches from DB together (by using preloadFor or by giving an array of cache names) into $cache instance (that was created at boot). This way no further calls are done to DB, they will be served from memory directly. I hope this part from the core makes it clear <?php // /wire/core/WireCache.php // Preloaded cache values, indexed by cache name protected $preloads = array(); /** * Preload the given caches, so that they will be returned without query on the next get() call * After a preloaded cache is returned from a get() call, it is removed from local storage. */ public function preload(array $names, $expire = null) { if(!is_array($names)) $names = array($names); $this->preloads = array_merge($this->preloads, $this->get($names, $expire)); } where $this->get() builds SQL query and fetches caches from database. So, if you're fetching caches once, it makes no difference to use $cache->get(['name', 'another']) or $cache->preload(['this', 'that']) then $cache->get(), but for multiple calls, it does. What you should be using to regenerate caches is just calling $cache->save() and it will regenerate and override previous caches. Edit: Considering the second sentence of the function documentation, the preloaded caches are flushed from the memory once they are requested with get(), so it's just useful for reducing DB calls to one.
    3 points
  3. Yeah, that might be confusing somewhat. To summarize the changes: The part starting with $file = open($page->mp3->httpUrl, 'r'); should be <?php $filePath = $page->mp3->filename; $file = fopen($filePath, 'r'); fseek($filePath, $offset); $data = fread($filePath, $length); fclose($filePath); to read parts of the file client requested directly from the disk. While sending the file to the client, you should replace this part <?php // send partial file wireSendFile($page->mp3->filename, $options, $headers); } else { // send file wireSendFile($page->mp3->filename, $options); } with print($data); like so <?php // send partial file print($data); } else { // send file print($data); } Because you've set headers earlier, you dont need to set them again. With these changes, hopefully, you'll have saved server from wasting some precious bandwidth. Good luck
    3 points
  4. I'm in the opposite camp recently. I've been writing my own CSS for about a decade (I don't like using 'grid-4-is-4-columns' and all that in my HTML, I prefer class names that describe the contained content, then style them out in the CSS). However, this is becoming too time consuming for exactly the reasons you mention above, want some parallax, I have to go find a jquery library, then some custom css, the bootstrap guys are already having a tea break Maybe the grass isn't always greener, but I have to try at least one proper framework to make a fair decision! Currently looking at uikit and bootstrap 4 (yes, I know this means adding a bunch of dumb sounding classes all over my HTML).
    2 points
  5. Something like this works with Process type modules. First you create a submit button, change its name to your action <?php $submit = $this->modules->get('InputfieldSubmit'); $submit->name = 'action_name'; $submit->value = 'Action Title'; $submit->icon = 'save'; $form->add($submit); Then inside <?php public function execute() // or ready() or init() { $out = ''; // ... if($this->input->post('action_name')) { // do your thing $this->message('Did my thing'); $out .= 'Here are the results'; // ... } return $out; } To achieve the same thing inside plain modules, you need to check if($this->input->post('action_name')) inside ready() / init() function. However, Process modules are more suitable for these types of tasks. You get custom urlSegments that you can redirect to and process using execute[Segment] functions. Like so <?php namespace ProcessWire; class ProcessMyAction extends Process implements Module { public static function getModuleInfo() { return [ 'title' => 'My Action', 'summary' => 'Does my action when you need to', 'version' => '0.0.1', 'permission' => 'page-edit', 'icon' => 'cogs' ]; } public function execute() { /** @var InputfieldForm $form */ $form = $this->buildForm(); $out = $form->render(); if($this->input->post('action_name')) { $out .= 'Just did my thing'; } return $out; } public function executeHi() { // intercepts `./hi` url segment $this->message("Well hello"); return "<p>You clicked hi!</p>"; } public function executeBye() { // intercepts `./bye` url segment $this->setFuel('processHeadline', 'Goodbye?'); $this->error('Not so fast!'); return "<p>You clicked bye!</p>"; } public function ___install() { // set up process page that is reachable from dropdown menu try { $p = new Page(); $p->template = 'admin'; $p->parent = $this->pages->get($this->config->adminRootPageID)->child('name=setup'); // under /admin/setup $p->name = 'my-action'; $p->process = $this; // when clicked from dropdown menu, execute() function runs $p->title = 'My Action'; $p->save(); $this->message("Created action page at $p->path."); } catch (WireException $e) { $this->error('Cannot create action page'); $this->error($e->getMessage()); } } public function ___uninstall() { // delete admin page $p = $this->pages->get('name=my-action, has_parent=2'); if($p->id) { $p->delete(); $this->message("Removed Action page at $p->path"); } } protected function buildForm() { /** @var InputfieldForm $form */ $form = $this->modules->get('InputfieldForm'); /** @var InputfieldName $fName */ $fName = $this->modules->get('InputfieldName'); // ... $form->add($fName); $submit = $this->modules->get('InputfieldSubmit'); $submit->name = 'action_name'; // ... $form->add($submit); return $form; } }
    2 points
  6. // Page > Page > Page > PageArray > children() // There's no PageArray::children() method $result = $page->parent()->parent()->children('template=event-tickets')->children(); // Use this: $result = $page->parent()->parent()->child('template=event-tickets')->children(); // Or even $event = $page->closest('template=event'); $tickets = $pages->find('has_parent=$event, parent.template=event-tickets');
    2 points
  7. Dear @flydev! Just wanted to let you know that this module is eagerly awaited. Just in case you had a doubt)) Any news?
    2 points
  8. @ryanC, have you set field to accept single file, or with no limits? If you've set (or didn't change anything) Max files allowed as 0, then $match->result_pic is a WireArray, if it's 1, then it's a single Pagefile. Something like this should work. <?php foreach($matches as $match) { echo "<li><a href='$match->url'>$match->title</a>"; echo "<div class='summary'>$match->summary</div></li>"; // this should work no matter what // check if result_pic is a WireArray if($match->result_pic->count) { $url = $match->result_pic->first()->url; } else { // it's a Pageimage $url = $match->result_pic->url; } echo "<img src='$url'>"; If you know what type of image field this is, then you can remove checks with if statement, and use one or the other $url and echo directly. The reason it wasn't working is that PHP expects simple expressions inside double quoted string "" for string interpolation, so only $a, or $a->b works, the remaining parts are echoed as strings. This would mean echo "<img src='$match->result_pic->first()->url'>"; would only interpolate the first $match->result_pic part, and replace it (with presumably the id of the image). For more info http://php.net/manual/en/language.types.string.php#language.types.string.parsing
    2 points
  9. High Performance Browser Networking © Ilya Grigorik the complete book is online now for free reading: https://hpbn.co/
    1 point
  10. My "uk-margin-almostlikeyouwantit" filled divs are looking at your comment and laughing at me haha.
    1 point
  11. Glad to help, @ryanC You do not have to set it to 1, you can also get the first image ($match->result_pic->first()->url) or use tags ($match->result_pic->getTag('some-tag')). And if you rename your field to a more generic name, you can reuse it across many templates, reducing the work DB engine has to do.
    1 point
  12. Thanks abdus! That really helped me out. Originally I did not change the maximum files allowed, it was at the default 0. But since I only want one image for this field, I decided to change the limit to 1, and simplified the code to: Nice and simple.
    1 point
  13. For user generated content, I use textarea fields with Parsedown (a flavor of Markdown) module in tandem with this module for images. This provides a simple syntax for semantic HTML (accepts raw HTML as well). For the parts that that are not open to user modification, I simply write HTML inside PHP files, and sprinkle PHP echo (<?= $var ?>), foreach, if constructs etc here and there. While starting out, I put everything in one PHP file, and as I build the layout and styles, I gradually refactor some parts into their own partial templates. I heavily utilize partial templates with wireRenderFile() and region() functions (you'll need to enable Functions API inside config.php as $config->useFunctionsAPI = true). I renamed wireRenderFile as partial(), (you can go even shorter with p()) like this. <?php /** * Renders partial with given data and returns generated markup * * @param string $template template to use. must be located in templates/partial * @param array $data associative array to pass to template * @return bool|string generated markup */ function partial(string $template, $data = []) { return wireRenderFile($template, $data, [ 'defaultPath' => paths()->templates . 'partial' ]); } and employ it inside template files and other partial templates as <?php // /site/templates/blog.php $posts = pages("template=post, parent=$page, sort=-published"); region('header+', partial('page-header', ['class' => 'header--large wrap'])); region('content+', partial('post-list', ['posts' => $posts])); include_once('layouts/basic.php'); For navigation, I use a custom template called nav, which only has a YAML field like this, and switch to other navigations (specified using other pages with nav template) on different contexts. - title: Blog url: /blog/ - title: Somewhere url: https://google.com external: true
    1 point
  14. $this->input->post is not populated for AJAX requests (caused by PHP, see this). I use something like this. <?php $raw = file_get_contents('php://input'); // optionally check for Content-Type headers if(is_array($parsed = json_decode($raw, true))) { $this->wire->input->post->setArray($parsed); $this->config->ajax = true; } // use $this->input->post->varName as usual
    1 point
  15. yep that gist solves it. I just kept the wireSendFile() if the file isn't a partial content reponse and works well. Thanks @abdus! new games podcast with my friends www.threepointspodcast.com/
    1 point
  16. Hi @Naz Possibly it's done via hooks or with a custom module. Try to look in these files site/init.php site/ready.php site/finished.php
    1 point
  17. Thanks for the reply. Definitely pointed me in a much better direction. Got it figured out now. Cheers!
    1 point
  18. Hi, Does anyone know if it's possible to set the "Email Body" in multiple languages?
    1 point
  19. My favourite books are "Thinking, Fast and Slow" and "Rework". I would strongly recomend them for those people who care about their business and team building. Luckily, they are not ones of those who try to proclaim their business in a hidden oe even open way; they are more practical.
    1 point
  20. Why not use an IDE instead of a text editor? Any IDE (at least PHPStorm) should analyze and index the core, your code and autocomplete to correct members of classes with close to zero configuration. PHPStorm, combined with functions api (set $config->useFunctionsApi = true inside config.php), is a godsend in this regard. Since Atom is just an advanced text editor, it (presumably) does not analyze your code, so it just autocompletes depending on what you write inside that file, (and not even inside the project). Using Atom to do an IDE's job is way over its head. Please correct me if I'm wrong, I'm extrapolating from my experiences with VS Code and Sublime Text, both of which are nowhere near an IDE.
    1 point
  21. I always have those same conflicts when I do a project in which the main language is another and English is secondary. Otherwise it works perfectly. It seems to be a conceptual issue that has not yet been resolved for a while. I think it would be useful during the installation of PW to be able to indicate the default language for the Front-End, to get "www.domain.com/" in that language. The Back-End language could be set or change in the admin as needed.
    1 point
  22. @SamC - definitely use those methods for installing, but as an FYI, your issue did remind me that I used a poor approach to setting the paths to those resources which I just improved in 4.3.3, so thanks for the report.
    1 point
  23. Just to clarify the bd($json) issue in case you didn't realize what is going on there. You could dump the entire json string if you wanted by using bdl() - which is a shortcut for barDumpLive(), or you could specify bd($json, 'JSON, array('maxLength' => 877) which would make the string length displayed match the length of the actual string. Note the defaults for maxLength and maxDepth are configurable in the module config setting, but these can dramatically slow down rendering, so generally recommended to leave as is and supply in the bd() statement when you need to override. Regarding the console panel - please open your browser console and let us know if you have any errors there - looks like the JS isn't being loaded.
    1 point
  24. for some reason the 'include theme based files' stopped working, so i added AdminCustomFiles/AdminThemeReno.css to the dependencies, and it works.. @Peejay that might solve your problem...
    1 point
  25. HI @nabo It looks like you can use subfield selectors: https://processwire.com/api/selectors/#subfield $pages->find("template=store, repeater_fied.hours=10");
    1 point
  26. Uikit is only used in the admin, on the front end you can use anything you want. Think of PW as a data source, all the rest - markup, styles, scripts - is up to you.
    1 point
  27. Hee PeeJay, I will see if I have time soon and if I can reproduce and fix it. Thanks for the report.
    1 point
  28. PW does not pull any CSS or Js to your frontend unless you tell him so.
    1 point
  29. For reference here's a simple mutation field implementation <?php wire()->addHookAfter('ProcessGraphQL::getMutation', function ($event) { $query = $event->return; $query->addField('log', [ // define return object under type 'type' => new ObjectType([ 'name' => 'Log', 'fields' => [ 'result' => [ 'type' => new StringType() ] ] ]), // available arguments for the query 'args' => [ 'text' => new StringType() ], // what to do with the request 'resolve' => function ($value, $args) { // process given input // return object outline should be same as 'type' return [ 'result' => 'done. ' . $args['text'] ]; } ]); }); When you refresh GraphiQL console, you get your new field!
    1 point
  30. Hi @flydev, any news on the release? Thanks!
    1 point
  31. easy peasy lemon squeezy
    1 point
  32. my favourite: http://appvswebsite.com/ is your budget < 10.000$ ? ---> build a website
    1 point
  33. Which cache? Template cache you would go to the PageRender module settings and delete cache.
    1 point
×
×
  • Create New...