Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/14/2012 in all areas

  1. 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;
    2 points
  2. That depends how you want or need to do it. Depends on how you proceed after the game is completed in flash. You could call a javascript from the flash game and do some simple ajax to call a php script. I remember you can simply use the trick: getURL("javascript:saveGame('game1', 2332, 109233)"); Easy enough if you know how, but there's many resources out there. More advanced would be to use some connector or comunicate back and forth with callbacks. But just some pseudo code: // on the page where the flash game is using jquery function saveGame( game, userid, score ) { $.ajax({ url: '/ajax/saveGame.php', type: 'post', data: { 'game': game, 'score': score, 'userid' : userid }, dataType: "json", onsuccess: function(data) { if( data.status == 1 ) alert( "GameSaved!" ); } }); } Then some simple php under /ajax/saveGame.php // bootstrap PW index include( "../index.php" ); // get some fuel; create PW variables as if in a template file $sanitizer = wire( "sanitizer" ); $input = wire( "input" ); $pages = wire( "pages" ); $users = wire( "users" ); $game = $sanitizer->name( $input->post->game ); $score = (int) $input->post->score; $user_id = (int) $input->post->userid; // get the user object $user = $users->get($user_id); // do some magic; // if successful echo json_encode( array( 'status' => 1 ) ); Or you could simply use a getURL to redirect to a certain page after game is completed. You could add a get var to the url, read that out in php and use it to save some informations. /some/url/?game=game1&score=42 Then in the php template script use $game = $sanitizer->name($input->get->game); $score = (int) $input->get->score; Or if you use a php file that is not connected to PW use the bootstrap, as in the previous script, to get access to PW through using "wire()". Edit: Oh and hello Chad, welcome to the forums!
    2 points
  3. PageEditSoftLock ProcessWire2+ Module There was a request for a page lock feature in PW2.1 for pages being edited by an other user already, it would lock or throw a message of along the line of: "This page is currently being edited by "username'." Thanks to Ryan for helping getting this done quickly! Download: https://github.com/s...ageEditSoftLock How it works Only the module "PageEditSoftLock" needs to be installed/uninstalled, the "ProcessPageEditSoftLock" Module will install/uninstall itself. The module creates a table and a hidden admin page under /page/edit/ for pinging in the background while editing a page. You can configure the ping interval and expiration timeout to what you think is good. Defaults - 20 seconds for pinging, - 60 seconds for expiration time (all entries in the table older than this will get deleted). ---- 27-02-2012 update https://github.com/s...1f204bc1b6c740a Fix for new repeater field throwing the lock message because of the way repeater work and this module. Thanks to Ryan for finding a quick fix.
    1 point
  4. I created a simple blank install profile for ProcessWire. I think it has been asked for a couple times, although the basic site is something really good to start with and fast to get rid of things you don't need. However in case someone wants one here it is. https://github.com/s...ireBlankInstall PROCESSWIRE 2.+ BLANK INSTALL ============================== This is a blank site profile for ProcessWire2+. It's done using the ProcessExportProfile module. There's only the following left in this profile: Fields: - title - body ProcessWire Templates - home - basic-page Template Files - admin.php (required) - home.php (required root page) - basic-page.php (404 page) INSTALLATION ============================= Get the latest ProcessWire install package. Before you install, replace the folders /basic-site/install /basic-site/templates with the ones from this blank install. Proceed with the installation as usual.
    1 point
  5. Thanks interrobang, that will be very useful and I will pass your code snippet along to the actionscript developers. Soma's example is very useful too and has given me ideas for how I could build an ajax-driven webapp with ProcessWire and jQuery.
    1 point
  6. Thanks interrobang. There's even more possibilities, but depends what AS version is used I did not make any assumptions to what would be appropriate in his situation as I don't know what flash AS version he uses. getURL will work with any actionscript version and was the simplest example to bring the concept in.
    1 point
  7. Alan the $comment->page will only point to the actual comment's page if the comment was retrieved with FieldtypeComments::findComments. Part of what that function does is populate the appropriate $page variable to all the comments it finds. However, you can still get it even if you don't have the latest PW or aren't using that findComments function: $page = wire('pages')->get($comment->pages_id);
    1 point
  8. I'm not sure if that's what you looking for and if you already know it. Since users are like pages you can just populate or assign a value to a field and then save it. Checkboxes have state 0 or 1 vor checked. Assuming the checkbox field is the "game1completed". $user->game1completed = 1; $user->save(); This should work That's ok the way you do it, though not very scaleable and flexible. This approach may work if you only have 3 games and there wont be any more ever. There's other ways of doing it without checkbox. 1. Using a page that stands for a game. So you could create a template with only the default title field and call it "game-completed". Now you create pages for each game using that template somewhere. If you now create a page field "games_completed" that allows multiple pages for that particular template and assign it to the user template. Then you use that field to save and add a reference to the game the user completed. // get game page using it's name or id or path $game = $pages->get( "template=game-completed, name=game1" ); // assign the game page to the page field on user object $user->games_completed = $game; $user->save(); To check the pages // to see if or what games the user completed foreach ( $user->games_completed as $game ) { echo "Game:" . $game->title; } // or to output users that have completed a particular game $game = $pages->get( "/games/game1/" ); $users_completed = $users->find("games_completed=$game"); foreach ( $users_completed as $u ) { echo "User:" . $u->name; } 2. You could also use a textfield to store the game informations as JSON encoded string. And read the string and decode it when needed. But this way it would not be possible to use nice selectors and not so flexible. 3. One that would allow for saving games, along with some informations like score and time, would be to create pages for each game completed as children of the user page. Create a template "game-saved" that has the fields needed for the meta information. Then create new page when saving the game using this template and the user as parent. To be able to add child pages to the user pages, you first need to allow children for the system "user" template (use filter on template list to see it and edit it) under family tab. // create new page $game = new Page(); $game->template = $templates->get( "game-saved" ); $game->title = "Game1"; // parent is the user page (user = special page) $game->parent = $user; // assign some values $game->score = $somevar; $game->time_completed = $timevar; // save it. $game->save(); Checking for games could be like this $game1 = "game1"; // get all users that have completed "game1" foreach( $users as $u ) { // check if user has a child page using the name "game1" if( count( $u->children->find( "name=$game1" ) ) ) { echo "User: " . $u->name; } } To output game informations // or cycle the completed games and output if( $user->numChildren ) ) { foreach( $user->children as $game ) { echo "Game: $game->title<br/>"; echo "Score: $game->score<br/>"; echo "Score: $game->time_completed<br/>"; } } else { echo "no games completed"; } The field is yours.
    1 point
  9. Nice work Soma. Just thinking aloud for a moment but if simplicity of installation is the goal of this, then perhaps it would be better to do a downstream distribution of ProcessWire; something like "ProcessWire-Clean"?? Not sure of the best way to do this but one approach might be to just maintain a fork of the main PW repo with all these changes applied. If Ryan were to link to it from the main site then folks would have the option of getting PW+demo site or the clean install.
    1 point
×
×
  • Create New...