-
Posts
6,798 -
Joined
-
Last visited
-
Days Won
158
Everything posted by Soma
-
You don't want to give access to the trash, it's a dark and dangerous stinky place.
-
What is $childSchild ? Don't think this even exists. How did you get to this?
-
Barry, using my MarkupSimpleNavigation module you could simply do: $nav = $modules->get("MarkupSimpleNavigation"); echo $nav->render(array( "max_levels" => 2, "show_root" => true, "current_class" => "on" )); Just in case. Edit: Ok the checkbox thing is not possible. But it would be possible using page "hidden" for page you don't want in mainnav. But your code is also nice and flexible if you need it.
-
sinnut is right, although it's using ksort and krsort. Don't know if there's a way around it. How about if you use the page name for sorting?
-
Cool, nice work. Glad you found ajax search module useful. Though I would add some float clearing in the content of the results, first entry get's floated because of the close button. Where is the ajax loader? It would help recognizing that it's searching.
-
I would choose ProcessWire. Sorry I'm too biased.
-
Your 2 examples are the same, so I don't understand what's going on on your side. BTW I recommend not using "$user" variable as it is a template variable which holds the current user so you overwrite it, but it should work anyway.
-
Thanks Dave for the report. Yes it returns the user. Well it's like this on http://processwire.c...iables/session/ that's from where the cheatsheet has its content originally. So it's wrong there already or Ryan changed it and forgot to change it in the docs. Anyway your code example both works... Not sure why it wouldn't work. If returned something else than null, false, 0 etc. it will be true even if it's a object... If conditions doesn't require to be "true" to work. if($loggeduser = $session->login($username, $pass)) { // if logged in succesful echo $loggeduser->name; } else { // failed }
-
Create new child as top sibling rather than bottom?
Soma replied to MarcC's topic in General Support
There is a way. // first get parent and it's first child $parent = $pages->get(1001); $first = $parent->child; // create new page with same sort as first child $p = new Page(); $p->template = $templates->get("basic-page"); $p->parent = $parent; $p->title = "Make me first"; $p->sort = $first->sort; $p->save(); // move first child to second position $first->sort++; $first->save(); Now your new page is at first position. However this only work if you got manual sorting on parent of course. -
Thanks sinnut for the report. It's not there because it's also not on API docs. But will gladly add it. I'm not sure why it's missing in the docs, is there any reason Ryan? Edit: well my guess is that is is not really reliable.
-
Absolute URLs / relative links to media, Embedded flash players
Soma replied to Chad's topic in General Support
I'm not sure I understand anything after "Example of what I'd like to happen:". I'm no sure what or even why you would want to "redirect" to another non PW page. But I don't see any problems referencing or linking media in your template files as you usually would in any website, PW only protects system files. If a file exists and isn't protected there should be no 404. Hard to really make any assumptions on how to best set it up or help without knowing or understanding your required project structure and needs in the full scope. -
I've "never" seen kB, looks wrong to me. Either KB or kb. Edit: Funny but looking at "dB", it looks right to me because I remember it from electronics and making music (amps etc)
-
It seems to be working good in my local install so far. Another question I wondered. How could I disable default language fallback when using in frontend? So I can output a field value as usual and it would return null if the current language field isn't populated, without setting outputformatting on an off. Edit: now trying even the suggested way to use of(false) and getLanguageValue doesn't work on language fields (image in this case) Error Exception: Method Pageimages::getLanguageValue does not exist or is not callable in this context (in /Applications/XAMPP/xamppfiles/htdocs/pw-dev/wire/core/Wire.php line 231) with this code $page->of(false); $lang = $languages->get("de"); $img = $page->image->getLanguageValue($lang); $page->of(true);
-
Now I'm very confused. Is this supposed to work like this for non and even text fields? How would I then use it, because in my case it wasn't working, the "header_image" wasn't returning anything? EDIT: Now it dawns on me, reading the docu again I remember reading something about it but forgot. Hmm will have to make another test, maybe something else went wrong, because the language was set to the default, yet nothing was returned for the image... even though other fields were working normal.
-
Inputfieldmodule doesn't autoload their js/css
Soma replied to apeisa's topic in Module/Plugin Development
Ah my colorpicker example isn't what I thought.. I decided to leave colorpicker js files in a subfolder as is. Sorry for the false example. But it really confused me in other modules I've done for sure. Just spoted something I didn't knew, thanks Ryan -
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.
-
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.
-
Module HelperFieldLinks - field and template edit shortcuts
Soma replied to Soma's topic in Modules/Plugins
Thanks recyclerobot! Just fixed the link, thanks for mention it. -
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.
-
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.
-
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)
-
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>"; }
-
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.
-
Inputfieldmodule doesn't autoload their js/css
Soma replied to apeisa's topic in Module/Plugin Development
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; } } -
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; }