Jump to content

Soma

Moderators
  • Posts

    6,808
  • Joined

  • Last visited

  • Days Won

    159

Everything posted by Soma

  1. Ahh thanks, then it's more or less what I thought it could be. If I understand you correctly, it thinks the "header_image" is a language field where "header_image_en" would be the "en" value? So the "header_image" would be the default? And because the image field is not really of type "LanguagesFieldtypeValue" it fails? I solved it by naming the default (baselanguage) image field "header_images_default" so the conflict doesn't happen. So one have to be cautious when naming fields having language fields enabled.
  2. I'm so waiting for this! Everytime I start a project with PW this limitation pops to my mind. Glad you'll address it soon.
  3. Thanks recyclerobot! Just fixed the link, thanks for mention it.
  4. Sent a new pull request today. Fixed the new url replacing feature in textarealanguage and improved behavior. Now if you insert a link in tinymce, it replaces urls found with the correct localized url for each language value when saving page. I changed the hook to the sleepValue() so it get's saved to db and we're done. No need to add this overhead on frontend too this way. Also added a check to prevent execution on field edit screen. When editing a language textarea with tinymce as inputfield, there were some strange error I have no idea where and why. It was finding a href="./templates/" and showed a selector error although there's no such link... I don't think it need to be executed there anyway so this should be fine.
  5. Thx mcmorry. Yes the install/deinstall I started working on is commented out, as it need more testing and refining. I'm currently running into issue with the new hook on textarealanguage when I go to edit a textarea language field in admin. Not sure what's going on but will try to fix it. Will make a pull request when I got it fixed.
  6. You're welcome. Haha, don't hurt yourself please! Just for throwing in when using php "Wire"-tag ( ) short notation the above could also be something like this. <? foreach( $pages->get("/about/")->children() as $pa ) : ?> <h2><?= $pa->title ?></h2> <? if( count( $pa->teasers ) ): ?> <ul> <? foreach( $pa->teasers as $rp ) : ?> <li><?= $rp->element_title ?></li> <? endforeach ?> </ul> <? else: ?> <p>No entries found</p> <? endif ?> <? endforeach ?> (short tags needs to be enabled on server, but only few hostings have it disabled. In near future it will always be enabled in php5.4)
  7. digitex, look at the markup and you see a somewhat 2 dimensional list. That's always done using nested foreachs. foreach( $pages->get("/someparent/")->children() as $pa ) { // $pa is the page echo "<h2>$pa->title</h2>"; echo "<ul>"; // cycle the repeater field as if they are pages (they are) foreach( $pa->repeaterfield as $rp ) { echo "<li>$rp->info</li>"; } echo "</ul>"; }
  8. I clone an image field "header_image" and rename the clone to "header_image_en", add it below the original to the template…. suddenly the original image field can't be outputed anymore via API at all. I remove the cloned image field from the template, the original imagefield works again... Also when I rename the cloned image field to something else like "header_image_another" and it suddenly works again.
  9. As you know I'm also struggling everytime I create a module with this autoadd script/css feature, sometimes it works and sometimes not. I asked several times and got told it only works for process and inputfield modules, so I stopped asking Sometimes I need to str_replace, sometimes I need to use ->scripts->add... Here just one example of my module colorpicker: <?php /** * An Inputfieldtype for handling Colors * used by the FieldtypeColorPicker * * 19.01.2012 by Philipp "Soma" Urlich * ColorPicker jQuery Plugin by http://www.eyecon.ro/colorpicker/ * */ class InputfieldColorPicker extends Inputfield { public static function getModuleInfo() { return array( 'title' => 'ColorPicker', 'version' => 100, 'summary' => 'Chose your colors the easy way.', 'href' => 'http://processwire.com/talk/topic/865-module-colorpicker/page__gopid__7340#entry7340', 'requires' => array("FieldtypeColorPicker") ); } public function __construct() { parent::__construct(); $this->setAttribute('type', 'hidden'); } public function init() { parent::init(); $this->config->styles->add($this->config->urls->InputfieldColorPicker . "colorpicker/css/colorpicker.css"); $this->config->scripts->add($this->config->urls->InputfieldColorPicker . "colorpicker/js/colorpicker.js"); } public function ___render() { $out = "\n<p><div id='ColorPicker_$this->name' style='border:2px solid #444;display:block;width:40px;height:40px;background-color:#".$this->value."'></div>"; $out .= "<input " . $this->getAttributesString() . " /></p>"; $out .= <<<_OUT <script type='text/javascript'> $('#ColorPicker_$this->name').ColorPicker({ color: '#$this->value', onShow: function (colpkr) { $(colpkr).fadeIn(500); return false; }, onHide: function (colpkr) { $(colpkr).fadeOut(500); return false; }, onChange: function (hsb, hex, rgb) { $('#ColorPicker_$this->name').css('backgroundColor', '#' + hex); $('#Inputfield_$this->name').val(hex).trigger('change'); } }); </script> _OUT; return $out; } }
  10. Using if( strpos( $_SERVER['HTTP_REFERER'], "page/link/?id" ) !== false ) return; I got it to ignore multilang url when in edit link modal. The hook for the FieldtypeTextarea::formatValue doesn't work at all. If I look at the link abstractor (which also doesn't work) and try the same to hook before FieltypeTextarea::wakeupValue it hooks in but fails completely with any code I try to parse the $value. Sometimes the $value is an array or object or something and even converting it makes no effect. The preg match or any string test fails. Any variant with hook after or other trying FieldtypeText fails. Does this have to do with it being FieltypeTextareaLanguage? Any ideas what's going on or how it could be done? I'm just running in circles. Edit: finally I got it somehow working. It's hooking before the FieldtypeTextareaLanguage wakeupValue, somehow it required completely different handling of the value because it's language field, I'm not really sure if all is correct but it works in admin and frontend. After textarea with links is saved, it shows modified urls but stored in DB is still the "real" page url. Following the code: public function init() { $this->addHookBefore('FieldtypeTextareaLanguage::wakeupValue', $this, 'hookWakeupValue'); $this->addHookAfter('Page::path', $this, 'mlUrl'); } ... public function hookWakeupValue(HookEvent $event) { $page = $event->arguments[0]; // not using, but here if you need it $field = $event->arguments[1]; // not using, but here if you need it $value = $event->arguments[2]; if(empty($value)) return; $language = wire('user')->language; if(!is_object($value)) return; if($value instanceof LanguagesPageFieldValue) { // get the language value for parsing for page urls $replaced_value = $value->getLanguageValue($language->id); } $rootUrl = rtrim(wire('config')->urls->root, '/'); // find all links if(!preg_match_all('{href=[\'"]([-_./a-z0-9]+)[\'"]}', $replaced_value, $matches)) return; foreach($matches[1] as $key => $url) { // slice off subdirectory if site is running from one, so we have a clean URL from PW-install root if($rootUrl && strpos($url, $rootUrl) === 0) $url = substr($url, strlen($rootUrl)); // see if this is a link to a PW-managed page in the site $linkPage = wire('pages')->get($url); // if not go on to the next if(!$linkPage->id) continue; // get language url $langUrl = $linkPage->url; // replace the default language URL with the language URL $replaced_value = str_replace($matches[0][$key], "href='$langUrl'", $replaced_value); } // set the modified language value $value = $value->setLanguageValue($language->id, $replaced_value); $event->return = $value; }
  11. 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.
  12. Thanks Ryan for the suggestion, I also thought about something like this, but it doesn't work as simple as this, turning off while process is "ProcessPageEditLink". The problem is the page tree select in the link edit dialog which is implement through various jsscripts/php gates... The solution I found works well, and has the nice effect that it shows the page titles in the page list select in the language of the textfield you're making the link. Though requires some modules in the core to be changed.
  13. Referencing to this. I got through it and had to implement the language id of the tinymce field in about 5 core modules to get it to work. So it does, in the link dialog of tinymce, check if it is a language text field and give the language id through various js's,php's ... so if you add a link to a "german" tinymce language field the page list select is in german and returns the german url, and so on. Edit: Of course this all isn't possible through a module or hooks at all.
  14. Next issue is also with setting links in tinymce. They will be inserted in the language the user has in PW admin. You would have to switch between languages in the admin to set them correctly for each language. That again shows, that unfortunately this module/approach is still only a "hack" with lots of drawbacks, and mixes things up that shouldn't. So it still is not the first/best option for creating multilanguage sites imho. That's why I would have prefered a core solution to frontend multilang. But since Ryan isn't in for it, it would be much better to work on the multitree approach and make it more friendly to use in the admin.
  15. I found an issue with textarea fields if "Page Link Abstractor" module by Ryan is used to: "Convert root URLs and page URLs: Prevents broken links when linked pages are moved" ... as soon as I have an image or link in the text, it's not possible to open the page anymore. Looks like that feature can't be used with this module. Haven't looked into it further, but I think since we overwrite path/url the abstractor module hangs itself up. Not sure if there's a solution.
  16. try this one pagefield.title
  17. 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!
  18. Try something like this: <?php if ($user->isLoggedin()) { $out = 'You are already logged in.'; } else { // get id var from request $requested_id = (int) $input->get->id; if ($input->post->user && $input->post->pass) { $user = $sanitizer->username($input->post->user); $pass = $input->post->pass; if ($session->login($user, $pass)) { // login successful $t = $pages->get($requested_id)->path; $session->redirect($t); } else { $out = 'Login Failed. Please try again.'; } } $out = '<form action="./?id='.$requested_id.'" method="post">'; $out .= '<input type="text" name="user" value="Username" />'; $out .= '<input type="password" name="pass" value="Password" />'; $out .= '<input type="submit" name="submit" />'; $out .= '</form>'; }
  19. 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.
  20. Thanks but the link is broken.
  21. yellowled is right, Ryan commented it out in implemented version. https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Fieldtype/FieldtypeDatetime.module#L76 "Timestamp" was in the patch Ryan provided as download.
  22. Ryan was talking about the URL when you logged in, refering to your "blank" page. Anyway, it looks to me as the id from the url isn't submited by the form. A simple debug "echo $input->get->id;" and commenting out the redirect would show that there's no id. So I'd guess, the form action should contain the id so it gets submited by the url.
  23. My favorite type of links recently are like: $p->setOutputFormatting(false|true); Simple to look on cheatsheet for reference. I recommend to have it open in your browser all the time
  24. Ah ok , have you tried to debug anything yet? For example where does the id come from? Output the path you are redirecting, is it correct?
  25. What does not work? Can you please provide more infos? Any errors? Debug enabled? As Ryan said, the session redirect doesn't work if anything is already rendered before your code. I don't think this code is the only there is. If this code is included in some or has some header.inc that already has html code it will not work.
×
×
  • Create New...