Jump to content

interrobang

Members
  • Posts

    255
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by interrobang

  1. In this thread Ryan said a history module will be part of the next major release:
  2. I would like to see some more usage of PHPDoc comments. As a quick test I modified the Page class to include @property comments for all the magic properties, and it works great so far. My IDE now doesn't show warnings for things like $page->name and even gives me autocompletion. I think it would quite useful to include something like this for all the classes also listed in the cheatsheet. What do you think about it? Btw, my IDE is PHPStorm. This is how my Page.php header now looks like: EDIT: Updated the code example to include the cheatsheet comments: /** * ProcessWire Page * * Page is the class used by all instantiated pages and it provides functionality for: * * 1. Providing get/set access to the Page's properties * 2. Accessing the related hierarchy of pages (i.e. parents, children, sibling pages) * * 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 * * @property int $id The numbered ID of the current page * @property string $name The name assigned to the page, as it appears in the URL * @property string $title The page's title (headline) text * @property string $path The page's URL path from the homepage (i.e. /about/staff/ryan/) * @property string $url The page's URL path from the server's document root (may be the same as the $page->path) * @property string $httpUrl Same as $page->url, except includes protocol (http or https) and hostname. * @property Page $parent The parent Page object or a NullPage if there is no parent. * @property int $parent_id The numbered ID of the parent page or 0 if none. * @property PageArray $parents All the parent pages down to the root (homepage). Returns a PageArray. * @property Page $rootParent The parent page closest to the homepage (typically used for identifying a section) * @property Template $template The Template object this page is using * @property FieldsArray $fields All the Fields assigned to this page (via it's template, same as $page->template->fields). Returns a FieldsArray. * @property int $numChildren The number of children (subpages) this page has. * @property PageArray $children All the children (subpages) of this page.* Returns a PageArray. See also $page->children($selector). * @property Page $child The first child of this page. Returns a Page. See also $page->child($selector). * @property PageArray $siblings All the sibling pages of this page.† Returns a PageArray. See also $page->siblings($selector). * @property Page $next This page's next sibling page, or NullPage if it is the last sibling.† See also $page->next($pageArray). * @property Page $prev This page's previous sibling page, or NullPage if it is the first sibling.† See also $page->prev($pageArray). * @property string $created Unix timestamp of when the page was created * @property string $modified Unix timestamp of when the page was last modified * @property User $createdUser The user that created this page. Returns a User or a NullUser. * @property User $modifiedUser The user that last modified this page. Returns a User or a NullUser. * @method string render() Returns rendered page markup. echo $page->render() */ class Page extends WireData { ...
  3. I think you are talking about an already existing feature:
  4. It should be quite easy to add these methods to Pageimage by a module. ImageSizer already has everything we need. I just did a quick hack and put the Pageimage->size method into my template.php, just to see whats possible with a few modifications, and it seems to work great. function resizeImage($image, $width, $height, $cropping=true, $upscaling=true) { $width = (int) $width; $height = (int) $height; $basename = basename($image->basename(), "." . $image->ext()); // i.e. myfile $basename .= '.' . $width . 'x' . $height . "." . $image->ext(); // i.e. myfile.100x100.jpg $filename = $image->pagefiles->path() . $basename; if(!is_file($filename)) { if(@copy($image->filename(), $filename)) { $sizer = new ImageSizer($filename); $sizer->setCropping($cropping); $sizer->setUpscaling($upscaling); $sizer->resize($width, $height); if($image->config->chmodFile) chmod($filename, octdec($image->config->chmodFile)); } } $pageimage = clone $image; $pageimage->setFilename($filename); $pageimage->setOriginal($image); return $pageimage; } usage like this: $neverUpdscaledImage = resizeImage ($page->image, 100,100,true,false); $uncroppedImage = resizeImage ($page->image, 100,100,false,true); echo "<img src={$neverUpdscaledImage->url} />"; Btw, I dont't recommend to do it like this. I just wanted to test whats possible.
  5. Thank you Ryan. I did not know about template->cache_time as it is missing on the cheatsheet. This looks like a nice solution for my use case!
  6. Not tested, but cant't you store your custom sortfield temporary in your pages and sort them later by this field? Something like this: foreach ($yourpagearray as $p) { $p->sortfield = toLowerCase($p->title); } $yourpagearray->sort("sortfield"); EDIT: this code should work: foreach ($yourpagearray as $p) { $p->tempsort = strtolower($p->title); } $yourpagearray->sort("tempsort");
  7. In the moment the cache clearing options only appear if you specify a cache time > 0. Is it possible to have the options always selectable? This is my use case: I build a multi-language using the "Display a different language based on URL pre-segment" approach and want my pages cached. The only pages I can enable caching are my language-gateways, otherwise the first requested language will be used for all languages. In the moment I am using a simple custom module which clears the cache of every page on any page save, which works fine, but I would prefer tu use your cache clearing options. Does this make sense or is there some logical error on my side?
  8. Hm, maybe thats the reason my colleges sometimes call me a "Typo Nazi". I always use kB, so it doesn't look like a mistake for me. But now I started to look around how my applications format "kB", I can only find the all uppercase formatting KB. Maybe this is a compromise between correct and pretty? And I couldn't find any document explaining why kB is mixed case, while the rest (MB, GB, TB,..) is all uppercase.
  9. Thank you Ryan, your idea works perfectly fine in my use case. This is even better then entering tags! I always forget these Textformatters exist. Nice to hear they will get internal support!
  10. I used $file->filesizeStr to output the filesize and noticed that the unit is all lowercase i.e. kb, but it should be kB. kb = kilobit, kB = kilobyte http://en.wikipedia.org/wiki/Byte#Unit_symbol
  11. I need to use some simple html-tags like <b> in file descriptions but they get stripped after save. Is there some option to allow html in file/image descriptions? In my case its sufficient to enter the html-tags by hand, but would it be possible to use tinymce for editing the description? I know I can use repeaters as an alternative, I just love the multi-file upload of the file-fieldtype so much..
  12. @apeisa A client complained about not seeing the whole image if it is larger then his screen. I was able to fix this simply by adding 2 lines (boxWidth and boxHeight) in ProcessCropImage2.js. Maybe you can add something like this to your official release too? Btw, this module so really great, and my customers are loving it! Thank you so much for releasing it! $(function(){ $crop = $('#jcrop_target'); if ($crop.length > 0) { var w = $('#jcrop_target').data('width'); var h = $('#jcrop_target').data('height'); $crop.Jcrop({ onChange: showCoords, onSelect: showCoords, aspectRatio: w/h, boxWidth: screen.width - 100, boxHeight: screen.height - 100 }); } $('#show_preview').click(function(){ $('#preview-container').toggleClass('hide'); }) });
  13. Sorry, I have no idea whats wrong. But maybe this works better, instead of storing the $page in the $comment: foreach($comments as $comment) { $cite = htmlentities($comment->cite); $text = htmlentities($comment->text); $date = date("j M 'y ", $comment->created); $comment_parent_id = $comment->pages_id; // Get the page_id $out .= "<dt>{$date}</dt>"; $out .= "<dd>{$cite}</dd>"; $out .= "<dd>{$text}</dd>"; $out .= "<dd>{$comment_parent_id}</dd>"; $num_comments++; if($num_comments == 3) break; }
  14. interrobang

    VetsNet

    There seems to be a problem with the Email obfuscator. The javascript Emailobfuscator.js could not be loaded, clicking on emails results in a 404. But I like the clean and plain design, and the responsive layout works well in my tests.
  15. I think you have to change the line order like in my example. Otherwise the $comment you push into your array doesnt't have the page variable set. Maybe there are other and better ways to do this, I am still new to php. Btw, echo $comment->page shows the ID, but nevertheless $comment->page should be the real page, so things like $comment->page->url should work.
  16. I think you have to store the $page in your $comment. $comment->page should now be the actual page, and not only the page_id. foreach( $blogposts as $blogpost ) { foreach($blogpost->comment as $comment) { if($comment->isApproved()) { $page = $pages->get($comment->pages_id); $comment->page = $page; array_push($comments, $comment); // Build an array of comments } } }
  17. @Soma, @Chad maybe a bit offtopic, but there is no need to call javascript via getURL, actionscript can do it too. Something like that should work for you: function saveGame(game:String, userid:String, score:int):void { var url:String = "/ajax/saveGame.php"; var request:URLRequest = new URLRequest(url); var requestVars:URLVariables = new URLVariables(); requestVars.game = game; requestVars.userid = userid; requestVars.score = score; request.data = requestVars; request.method = URLRequestMethod.POST; var urlLoader:URLLoader = new URLLoader(); urlLoader = new URLLoader(); urlLoader.dataFormat = URLLoaderDataFormat.TEXT; urlLoader.addEventListener(Event.COMPLETE, loaderCompleteHandler, false, 0, true); urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler, false, 0, true); urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler, false, 0, true); urlLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler, false, 0, true); for (var prop:String in requestVars) { //trace("Sent: " + prop + " is: " + requestVars[prop]); } try { urlLoader.load(request); } catch (e:Error) { trace(e); } } function loaderCompleteHandler(e:Event):void { var responseVars = URLVariables( e.target.data ); trace( "responseVars: " + responseVars ); } function httpStatusHandler( e:HTTPStatusEvent ):void { //trace("httpStatusHandler:" + e); } function securityErrorHandler( e:SecurityErrorEvent ):void { trace("securityErrorHandler:" + e); } function ioErrorHandler( e:IOErrorEvent ):void { trace("ioErrorHandler:" + e); }
  18. I did not test it, but I looked around in Ryans BlogProfile and saw some interesting methods in BlogTools.php: /** * Find comments from the given selector string * * @param string $selector * @return CommentArray * */ public function findComments($selector) { $comments = FieldtypeComments::findComments($this->commentsField, $selector); foreach($comments as $comment) { if(!$comment->page->viewable()) $comments->remove($comment); } return $comments; } /** * Find $limit recent comments * * @param int $limit Number of recent comments to find * @param int $start Where to start, like 0 (default: null = automatic, based on page number) * @param bool $admin Include non-approved and spam comments? (default: null = determine automatically) * @return CommentArray * */ public function findRecentComments($limit = 3, $start = null, $admin = null) { $limit = (int) $limit; $_limit = is_null($start) ? $limit : $limit+1; $out = ''; $pageNum = $this->input->pageNum; // auto-determine $start if not specified if(is_null($start)) { if($pageNum > 1) $start = $pageNum * $limit; else $start = 0; } // we show pending and spam comments when page is editable if(is_null($admin)) $admin = $this->page->editable(); // build selector to locate comments $selector = "limit=$_limit, start=$start, sort=-created, "; if($admin) $selector .= "status>=" . Comment::statusSpam . ", "; else $selector .= "status>=" . Comment::statusApproved . ", "; // find the comments we want to output $comments = $this->findComments($selector); return $comments; } I think FieldtypeComments::findComments is a new addition to PW, so you might need the lastet version from github. It looks like instead of $comment->parent()->url; you can use $comment->page;
  19. Thank you apeisa, It worked. I just changed your code to this, so that empty/waiting repeaters are not echoed: foreach ($page->repeater as $p) { if ($p->status == Page::statusOn) echo $p->renderFields(); }
  20. I am trying to output all content of all my pages on a single page to get a quick overview where some content is still missing. It doesn't have to be pretty, and the resulting output of the MarkupPageFields.module is sufficient for my purpuse, but I am missing the content of my repeater field. Is there anything simple I can do to include my repeaters fields? This is basically my code: function listPageFields($page) { echo "<h1>{$page->title}:</h1>"; echo $page->renderFields(); if($page->numChildren) { foreach($page->children as $child) listPageFields($child); } } listPageFields($pages->get('/'));
  21. What about setting a min-height in JqueryUI.css like this: .ui-widget-content { min-height: 6em }
×
×
  • Create New...