Can
Members-
Posts
350 -
Joined
-
Last visited
Everything posted by Can
-
Hey friends I gotta little side project, I'm building a little bookmark management tool. For this I made a little bookmarklet, which will add the currently opened page. The opening popup lets me adjust name, url and add tags. I thought it might be nice to be able to enter not only "plain" tags, but build a structure on the fly. So when I'm entering (let's say none of them exists at that moment) Processwire>Docs>Security the script creates tag called Processwire, add Docs as child and Security as child of Docs. This part works great. The only problem I'm having, is that I already got a tag called "Docs" but it's a root tag and I want to have a new one as child of Processwire So I want the following in the end. /tags/Docs/ /tags/Processwire/ /tags/Processwire/Docs/ /tags/Processwire/Docs/Security/ but I'm getting /tags/Docs/Security/ instead, because Processwire and Docs already exist.. so this is the code where I'm stuck function processTags($tags, $tagParent = 'tags') { $vars = array('sanitizer', 'pages'); foreach ($vars as $var) ${$var} = wire("$var"); // create new PageArray to hold all tags $tagPages = new PageArray(); // sanitizer array will handle delimited (',', '|') string input for us $tagsArray = $sanitizer->array($tags); foreach ($tagsArray as $tag) { // if closing bracket found than split if (strpos($tag, '>') !== false) { $thePapas = explode('>', $tag); // for ($i=0; $i<count($thePapas); $i++) { foreach ($thePapas as $tp) { // determine parent either /tags/ or the previous tag $parentTag = ($tagPages->count()) ? $tagPages->last() : 'tags'; // and thru this same function $tagPages->add(processTags($tp, $parentTag)); } // we stop here and return to prevent duplicates // we add only the last because the others are in a parent relationship already return $tagPages->last(); } else { $tagParent = ($tagParent instanceof Page) ? $tagParent->path : "/$tagParent/"; // no parent>tag pair so look if tag exists, otherwise create $t = $pages->getByPath("{$tagParent}{$tag}/"); if (!$t->id) { $t = new Page(); $t->parent = "$tagParent"; $t->template = 'tag'; $t->title = $tag; $t->save(); } // add to PageArray $tagPages->add($t); } } return $tagPages; } I'm calling it like processTags('ProcessWire>Docs>Security') And even though I'm searching for existing tags with getByPath it's not working.. :/ For the record, this project is on PW 3.0.8 devns Hope I could explain my problem/question sufficiently? Ah, to clarify. When using all new tag names it's working great.. Saluditos Can
-
blazingly fast! Thank you!
-
Of course both work -.- I tried multiple times to add the namespace ProcessWire at the top without any luck..now it just works haha Just for the record, both of snippets work for me. Thank you teppo! Making my first namespace experiences with pw devns..
-
Hola, just tried to write a little php cli to create a bunch of pages. Whole api works (at least $sanitizer and $pages) but new Page() is failing. first file where in bin folder, second test file next to pws index.php. permission is fine. #!/Applications/MAMP/bin/php/php5.6.7/bin/php <?php include 'index.php'; var_dump(new Page()); producing "Error: Class 'Page' not found" Okay got it. Now I got a little loader script #!/Applications/MAMP/bin/php/php5.6.7/bin/php <?php require 'scraper.php'; and in scraper.php I'm starting like <?php namespace ProcessWire; include 'index.php'; now it's working Is there another way? It's everytime again fascinating how much faster and less resource hungry than running mass importer in the browser
-
Module FieldtypeKeyValueMultiple need help while developing
Can replied to Can's topic in Module/Plugin Development
Nice to hear this from you Macrura! I know your thread about delimited textareas and startet with such myself. Even though I read the thread I didn't know about TextformatterMultiValue until Martijn mentioned your thread and the Textformatter in a pm couple of hours ago. Maybe I should consider a to split key into key/label. Maybe only if desired.. When I started the module I named the db columns the same and ran into issues so I just renamed the key column to label. Maybe it's not good/allowed to call a column "key" or maybe it was about the index? Just reread and noticed that you wrote name. Of course the db column doesn't has to be called key... I will go through this thread again and see if I find more interesting/useful ideas/use cases. Thanks to you and Martijn for mentioning! Saludos Can -
Module FieldtypeKeyValueMultiple need help while developing
Can replied to Can's topic in Module/Plugin Development
Tried to get translatable config fields working, but no luck so far. I used to build them using public function ___getConfigArray() { return array( 'keyLabel' => array( 'type' => 'text', 'label' => $this->_('Label for key field'), 'value' => '', 'notes' => $this->_('Defaults to "Key"'), 'columnWidth' => $this->keyWidth, 'useLanguages' => true ) }; Thought maybe it's not yet fully supporting "useLanguages" so I switched to getConfigInputfields which other modules from Ryan are also working with languages.. public function ___getConfigInputfields() { $inputfields = $this->wire(new InputfieldWrapper()); $f1 = $this->modules->get("InputfieldText"); $f1->attr('name', 'keyLabel'); $f1->label = $this->_('Label for key field'); $f1->attr('value', ''); $f1->attr('size', 100); $f1->notes = $this->_('Defaults to "Key"'); $f1->columnWidth = $this->keyWidth; if($this->wire('languages')) { $f1->useLanguages = true; foreach($this->wire('languages') as $language) { if($language->isDefault()) continue; $f1->set("value$language", ''); } } $inputfields->add($f1); } But than nothing is getting saved at all. Before at the default language value would save.. In init() I'm having $this->set('keyLabel', 'Key'); if($this->wire('languages')) foreach($this->wire('languages') as $language) { // account for alternate formats in other languages /** @var Language $language */ if($language->isDefault()) continue; /* tried with and without underscores */ $this->set("keyLabel__$language", $this->get("keyLabel__$language")); // $this->set("keyLabel$language", $this->get("keyLabel$language"));} Still no luck. -
Hola amigos I'm quite excited about this one and really wanted to finish it myself or at least come with "bigger" problems^^ But now I need some advice as I'm stuck on some basics. The module is derived from FieldtypeEvents by Ryan. What it does It's a customizable two column table for key value pairs. Right now customization is about changing columns headings and column width. Customizing sorting of the rows is planned, and the input is already there but not yet working. Drag and drop sorting is planned for the future two. Translatable column headings are almost there, but I got the same issue like with the MarkupCookieConsent, so only default language is saving..and many more features are planned (and hopefuly will be included in the future) except those it's already working quiet nice. So when editing a page you can add/remove columns (ah they got sorted alphabetical at the moment). What it doesn't (And that's for me the most important part right now!) The API side is lacking remove of single and all rows capabillities, which I personally need right now because I build a small front end page edit screen to let users edit some data. I got the whole key/value input running adding rows on the fly like in the backend, but I'm not able to delete anything at all.. ^^ What I tried After digging and digging I realised that FieldtypeEvents is really basic and KeyValueArray.php (former EventArray.php) is missing some methods. At least I thought because some other modules are implementing there own remove() methods, even if I thought it should inherit all methods because it extends WireArray, I decided to copy some code without luck, trying to understand and alter as needed (seems really easy to understand) but still no luck at all. While writing this I thought it might be interesting to review the thread from Ryan about his FieldtypeEvents and found that someone just managed to remove an event by using remove($event) without changing Ryans code. So digging again trying some things, stumbling over public function removeQuietly($key) and finally this one deleted the row! So for now I just copied removeQuietly method into KeyValueArray.php and renamed it to remove($key) and it's working. But I would love to know why all this? Why didn't remove just work from WireArray.php? And why the copied methods still didn't worked? I tend to write and write and write haha.. Use cases What is all this useful for? Consider a contact template, you could use this field to store all contact information like so Some minutes ago I had some more examples but it's gettin late.. Ah Know that you can (like with FieldtypeEvents) not only foreach the whole table, but get them row by row: $row = $page->keyValues->get("Responsible"); $label = $row->key; $value = $row->value;Just noticed that the contact example would be even better with another sorting than alphabetical to just iterate the whole tableBut you could already get them line by line as needed ;-) Kay that's it for now.
-
Updated first post (4 screenshots now, readme and code fixes)
-
-.- haha yeah it looks nice..but actually only the default languages fields are getting saved..so I don't know what I need to do to have it save all.. Thank you And as I said, I need to test a little more, for example I don't know what it does when in single language environment. Maybe I need to make 'useLanguages' conditional.. Haven't testet privacy policy page settings yet. But after lunch I'll go and check it all out..than maybe add to module directory.
-
Your right BernhardB! Got a little stuck with the code, so making screenshot and readme felt a little wrong..but it would make the post a little more attractive I guess. Now we're having a little selfmade chocolate snack and afterwards I'm preparing something ;-) Thank you Pete, but it's actually the opposite (or your "rather than.." part ), means I want the module config fields to be translatable on the config screen. EDIT: couldn't let you guys wait any longer so I quickly added a screenshot to the repo. More is coming soon.
-
Thought might be good to reply myself to let you now there is a lot going on here
-
Still some work needed, but I just pushed the whole new version to GH and renamed it as MarkupCookieConsent. https://github.com/CanRau/MarkupCookieConsent/ (beta) It's now doing everything on it's own, means there are no externals involved. EDIT 1: Added screenshot to repo EDIT 2: Okay, I would say anything works (at least in Chrome on Mac) except the translatable config fields. Both themes are ready having each 2 available positions (top/bottom). Extended screenshots to show all 4 versions Added readme Added to module directory http://modules.processwire.com/modules/markup-cookie-consent/ EDIT 3: Lanaguage fields will work using this patch from Ryan, or you can just wait for the next PW devns release (probably on friday) Changelog 0.0.9 - Changed style injection, now prepends to first <link> in head makes it easier to add custom css tweaks without the need for !important because of the cascading order 0.1.1 - Fixed issue with cookie not being set, two strings wouldn't recognize translation, default cookie expire now 1 year, updated readme 0.1.2 - Added minified CSS & JS 0.1.3 - don't remember what changed in this version 0.1.4 - cookie bar now fully translatable, added devns branch which is meant to be used with PW 3.x devns as it adds namespaces 0.1.5 - fixed issue on single language installations Still have to test some things. For example, you can now select a page from your tree as policy page using InputfieldPageListSelect instead of entering the url, so now the link should work with multiple languages, too. Though I haven't exactly tested it yet! The language fields draw my attention. They look nice but only default language is saving at the moment. So this is how I build the config fields using MarkupCookieConsent.config.php file I kept only settings for one field.. public function getDefaults() { return array( 'messageText' => __("This website uses cookies to ensure you get the best experience on our website"), ); } public function __construct() { $this->add(array( array( 'type' => 'text', 'name' => 'messageText', 'label' => __('The message shown by the plugin'), 'useLanguages' => true, 'columnWidth' => 70 ) ) ); }); I'm not sure if/how I need to define default values for languages, too? I checked some other modules from Ryan but there he still uses the config field building ways getConfigInputfields() for example, so those are not really applicable, are they? So visually everything looks good, even when inspecting the fields the field names seem to be alright.. Or is this approach not yet multi lang capable? Everything else should work already. Ah except for the Default settings button at the bottom. It's more like to-do list for myself ;-) Ah and regarding "dependencies". When "Enable Ajax" checked, the form will be submitting using ajax (magic! haha), anyway..just to let you know it's using plain vanilla js so no jquery or anything else needed. Although it should work well, it's only tested in newest Chrome on Mac and the script is not handling errors. It's actually removing the cookie information right after the click and then making the request. So worst case would be, considering any error, the message popping up again even so the user thinks he already agreed... I figured it's probably not the kind of module which many will use, cause when you're a little into PW you now how to easily include such an information yourself. But for me it's especially practicing PHP.. So I would really love to get some hint on the language fields Side note: For everyone interested in disabling cookies at all to avoid every possible need for this plugin checkout out this blog post from Ryan http://processwire.com/blog/posts/multi-instance-pw3/#more-session-control
-
FieldtypeTextareaLanguage - set 'Text Formatters' and 'Inputfield Type'
Can replied to didhavn's topic in API & Templates
That's good to hear, glad I could help -
FieldtypeTextareaLanguage - set 'Text Formatters' and 'Inputfield Type'
Can replied to didhavn's topic in API & Templates
for "show only if.." have a look into /wire/core/Inputfield.php, there you'll find $showIf so just add $f->showIf = 'selector'; and the textformatter I'm not quite sure right now.. -
Module HappyCssClasses - let you dynamically add/remove (body)classes on the go
Can replied to Can's topic in Modules/Plugins
Thanks for your little tut kongondo! This time I created the branch using github.com, I'll dig into this a little later. So now there is a devns branch for those using PW3. master should work with PW3 too thanks to FileCompiler, but I haven't tried it yet.. -
Just stumbled upon a failing field name, too. In PW3 "files" is reserved, as not only those names from LostKobrakai's mentioned array are considered reserved, but everything in $wire too. https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Process/ProcessField/ProcessField.module#L1439 and in PW3 there's WireFileTools class which populates $files
-
Module HappyCssClasses - let you dynamically add/remove (body)classes on the go
Can replied to Can's topic in Modules/Plugins
Thanks for mentioning kongondo! Had it already installed, just forgot about it^^ But still can't figure out how to link the devns branch to the local devns folder? -
Module HappyCssClasses - let you dynamically add/remove (body)classes on the go
Can replied to Can's topic in Modules/Plugins
Okay you got me.. I changed the name to HappyCssClasses Tried to add a devns branch, but I don't know how to add the corresponding files using Github Desktop (OS X) My local folder structure is as follows /Repositories/HappyCssClasses/master/HappyCssClasses/ /Repositories/HappyCssClasses/devns/HappyCssClasses/ How to tell devns branch that the files of this branch are at another location? It's my first time setting up branches..if you got another folder structure? By the way, I'm just installing the command line dev tools, so then I would be able to use terminal instead of the gui Would be nice to get some hints, even how to google, because I got nothing on this..?! -
How to output overwritten field labels in site template
Can replied to Juergen's topic in API & Templates
Thank you Adrian, and thanks Juergen for asking, so I just got an answer already haha By the way, when you got languages enabled it could be interesting to use $field->getLabel() instead. It'll always gives you the label in the current language or you can pass the desired language as parameter like e.g. $field->getLabel($languages->get("de")) @Ryan, maybe it could be nice to have a second parameter here like true/false to get the default label or the context label? -
Module HappyCssClasses - let you dynamically add/remove (body)classes on the go
Can replied to Can's topic in Modules/Plugins
Thanks guys! Fixed it. It started as HappyClasses, as all my modules are prefixed with Happy as in HappyGaia.com ;-) Then I thought I should give it a more generic name..but that didn't feel right so I changed back but forgot in the topic here and didn't think about the name of the repo as I'm still quite new to github.. Totally Finally my code starts to get more beautiful and clean.. -
Hey guys, I finally got my first module ready to publish It's called HappyCssClasses. I know there is BodyClass module, which I used a lot, thanks to Kay Seliger! But lately I needed more flexibility. First thought about a class in prepended template file like $bodyClass = "lang{$user->language->name}"; and then could extend it in template files using $bodyClass .= " blog"; of course. But there is no fun. I want and need to learn more about classes and php so figured this could be a good use case. So what is this module doing? After installation (see readme) it will instantiate $bodyClasses variable which will be available in your template files (should work almost everywhere) Then you will be able to add/remove classes as needed Like $bodyClasses->add("className"); $bodyClasses->add("className", 'key'); // the key is only necessary to remove a class later $bodyClasses->add("className secondClass third-class"); $bodyClasses->add(array('first-class', 'secondClass')); $bodyClasses->add(array('key1' => 'first-class', 'key2' => 'secondClass')); $bodyClasses->remove('keyDos'); $bodyClasses->remove('key1 keyDos'); $bodyClasses->remove(array('key1', 'keyDos')); There are some dynamic classes build in which you can enable by just adding the key $bodyClasses->add("language") to add "lang-{langname}" $bodyClasses->add("template") = "template-{templatename}" $bodyClasses->add("published") = "published" / "unpublished" $bodyClasses->add("pageNum") = "page-1" for pages greater than 1 it also adds "not-first" or $bodyClasses->add("defaults") = adds all of the 4 above (language, template, published, pageNum) or you could define multiple like $bodyClasses->add("language template") Could be in prepended template file, e.g. _init.php, or your appended template file, or of course in specific template files lice article.php I would love to get feedback For example, I just added the possibility to get all defaults by adding "defaults" Is there a better way? Because I conditionally check if the added class is one of the 4 (or defaults) and need to cancel after one of thos got added. But because the "defaults" would add all I need to make sure only to return if not defaults.. if (in_array($class, array('language', 'defaults'))) { $this->classes['language'] = 'lang-'.$this->wire('user')->language->subtitle; if ($class !== 'defaults') return; } As I said, every hint, feedback, suggestion, request, idea or anything constructive is highly appreciated Check out on Github https://github.com/CanRau/HappyCssClasses I'm planning (like mentioned in the readme) that one can enter custom names to instantiate a second (or more) time so you could have e.g. $bodyClasses, $articleClasses, $blogClasses..thinking about implementation. And need to do some other stuff today too ;-) One question to github, I'm using the Github app for os x at the moment. I made a seperate Repositories folder for it. And then I symlinked the module into my modules folder, otherwise I would have to copy/paste everytime I change something. How'r you handling this? Are there better ways? Saludos Can CHANGELOG 0.0.6 - Changed module name from HappyClasses to HappyCssClasses - Added second parameter to $bodyClasses->add("language", "fieldname")
-
I feel maybe I could help to clarify some things, as long as I got them right myself (and maybe I can learn something..) There are two things available The function wireMail() from /wire/core/Functions.php (lowercase w) and the class WireMail() from /wire/core/WireMail.php (uppercase W) As far as I understand the code only the function will automatically check if there is a module installed extending WireMail class So if you don't want to use the function (for whatever reason) but want to use the extended class you have to call it directly like new WireMailSmtp() (for this I think the module has to be of type autoload (right?) Is it possible to call a function with new? like new function()? Aha, if it returns a class than it should work..?! And the class is what you extend or what gets extended.. Maybe I'm wrong and everyone in this thread is on the right track already. If so it maybe helps following people At least I needed some minutes to figure this out.. Saludos, Can
-
Page field - New page active url in different language
Can replied to verdeandrea's topic in Multi-Language Support
As of PW 2.5.14 you can just copy a wire module to you /site/modules/ folder, make changes and you're good to go (just mentioning ;-) blog post: https://processwire.com/blog/posts/processwire-core-updates-2.5.14/) So I copied InputfieldPage.module and added a few lines (in the code commented with "added by Can" without quotes) My tags field uses InputfieldPageAutocomplete now when entering a tag which isn't present and I'm going to create it, I just enter a colon ( after the title and enter the german one like EnglishTagTitle:DeutscherTagTitel Maybe not the best when you got more languages, but for me it works right now Feel free to copy and of cause adjust anything to fit your needs Make sure to adjust the language in Line 617 Ah, and it's of cause activating the german url as well (regardless if you enter a translation or not..) Here you go: https://gist.github.com/CanRau/e07307fbb5f8daf2c698 -
With prependet template file (_init.php) and appended tpl file (_out.php) I got my defaults in the _init.php file but can override whenever I need it but just replacing it in a specifigpc tpl file like article.php for example
-
We're actually using ckeditor with images and because on happygaia.com it's only me and my girlfriend I enabled full html, could be better but it's working okay so far