Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/06/2016 in all areas

  1. $tmpDir = new WireTempDir('someName'); // add files $fileBasename = 'basename.ext'; $filename = $tmpDir->get() . $fileBasename; file_put_contents($filename, base64_decode($b64Data)); $page->files->add($filename); // repeat for all files ... // optionally, at the end call $tmpDir->removeAll(); EDIT: Ah, you already know / found WireTempdir() EDIT2: If one use WireTempDir for very timeconsuming tasks, one optionally can define a maxAge for it, different than the default 120 seconds: $tmpDir = new WireTempDir('someName', array('maxAge' => 300));
    6 points
  2. new version 0.2.0 brings in some new features: supports multiple instances allows usage of full ProcessWire API in options allows to render more than one contact form on a page allows to send more than one email makes validation hookable read on
    4 points
  3. I'm not sure if setting the timezone for php is really the most sane way to go about it. I'd rather keep php's timezone to be consistent and just use a library like carbon to handle the timezone differences for the frontend. Edit: Just read that you need it for the backend as well, so that's not so much an option.
    4 points
  4. I just found this flexbox polyfill. It hasn't been around for very long. This will enable you to use flexbox in projects where IE8 and/or IE9 support is required. Looks promising. https://github.com/10up/flexibility
    3 points
  5. I have to hop in on this and portray my thanks to LostKobraKai and everyone else on this forum! Everyone is so helpful and (and luckily for me) ignores my dumb/simple questions to help me out. As someone still learning php and processwire, it can be overwhelming trying to achieve what is in my head with the limited knowledge that I have thus far.
    3 points
  6. Note: $tmpDir = wireTempDir('someName'); Should be: $tmpDir = new WireTempDir('someName');
    3 points
  7. Yes, best way would be only to dynamically change all date reading, but not to alter date writing.
    3 points
  8. Yes, I had a few fckeditors as well. As I said, if those are the files that intruders are looking for to find vulnerabilities, it is a warning list of files and locations of files that you should probably avoid!
    2 points
  9. For now griddle serves me very well. It's maybe less flexible as flexbox, but more flexible as 'normal grids'. Normal grids need rows even if it doesn't make sense markup wise. Inline-block grids can be make compatible ie7 and up. So no polyfill needed.
    2 points
  10. Set the format to a sensible default and use this in the frontend to get the timestamp for other formatting purposes: // 1452082822 $timestamp = $page->getUnformatted("dateField"); // 01/06/2016 12:20 $defaultFormat = $page->dateField;
    2 points
  11. One more thing to add. Yesterday I decided to utilize clsource's class: https://processwire.com/talk/topic/4550-debugging-tips/?p=108300 I added namespace ProcessWire; to it and modified it a tiny bit so that I can also log the class/type name of the logged variable, and the file and line number of the caller. Recommending an easy to use method for debugging (that even works in production, on whatever server this site might be running) seems to be a good idea to include.
    2 points
  12. Found it via pw3.0 (in seperate class) Looked for it in 2.7 and mentioned to Raymond.
    2 points
  13. @Horst thanks for the working example. Saves me from typing
    2 points
  14. Save the base64 data as decoded file to a temporary place (e.g. /assets/cache/) and then just add it to the file field and it will be copied to the correct path.
    2 points
  15. This thread is already quite old, but I just stumbled upon the same problem and wanted to add my solution to this thread. When you install the LanguageSupportPageNames module, you also get the Page::localName($language) method to easily retrieve the page name in different languages. This has been added in 2.3.0. So, to get the page name in a the language (or any other), you could do something around these lines and be done: // Get default language $defaultLanguage = $languages->getDefault(); // Get default page name $defaultName = $page->localName($defaultLanguage);
    2 points
  16. Maybe not exactly a use-case for adding additional pages, but I'm using two separate pagetables to hold applications and fully accepted applications. The pages are just moved from one to another when a application is accepted and applications can only be added to the pagetable holding the non accepted ones.
    2 points
  17. This ProcessWire module allows you to import and parse XML files (using xpath) to create or update pages. [detailed instructions at github] Settings After successfull installation go to Setup > Import Pages From XML to start using the XML Importer. This module does not support all available field types. Nevertheless, I've refrained from restricting the supported field types because many of them should work by default. Xpath Mappings If you want to take advantage of references between fields in your xpath mapping then make sure the fields you're relating to are placed before the ones which need the relations. You can access and use any values/fields that you placed earlier in your file. Use $field_<fieldname> to match the desired value. Example: <?xml version="1.0" encoding="UTF-8"?> <songs> <song track="2"> <title contact_id="1">Some song title</title> </song> <song track="7"> <title contact_id="2">Just another song title</title> </song> <contact id="1" name="Sesmallbos" mail="info@test.org"/> <contact id="2" name="Sebigbos" mail="info@exam.ple"/> </songs> context: //song field order: title, track, contact_id, contact_name, contact_mail contact_id must be placed before contact_name and contact_mail first get contact_id : title/@contact_id then use that value as relation : //contact[@id=$field_artist_id]/@name as well as //contact[@id=$field_artist_id]/@mail
    1 point
  18. I'd like to thank LostKobrakai for this excellent tutorial included in the Dec 25, 2015 blog post regarding custom page types. If you haven't read it yet, please do so. It is contributions like this by the senior members that prove selecting ProcessWire was the correct decision for this ProcessWire-Newbie. I am impressed at what I have learned within the functionality of ProcessWire, and discovering avenues I hadn't yet thought about. It is indeed a merry Christmas. I also want to thank all staff members. They deserve our gratitude for the time they dedicate to helping us learn ProcessWire, and the many avenues available with each project. For example, kongondo contribution is another great example of the team in place here. My hat is off to Ryan and his team for giving of their time and sharing their knowledge. In addition to the regular staff, there are many members, such as Kixe, Tom, (and too many others to name them all here) that also deserve recognition for their contributions and assistance. It is greatly appreciated. I am certainly looking forward to ProcessWire 2016 ;-)
    1 point
  19. I have some more different in my collection
    1 point
  20. Just been having a peak at my 404 logs. Various Wordpress files are featuring very highly, but also many attempts to find my jquery.js file. Another one that comes up a lot is /utility/convert/data/config.inc.php and variations. What is that from? But by far the most popular are wp-XX files. It shows that if you have a WordPress site, you WILL get hundreds of attempts to take it down each day, even on your little-visited blog. How comforting ...
    1 point
  21. I'm currently short on time, but I noticed my date selection code in there and I've seen a better selector for that from ryan some time ago: // select anything overlapping the range of $start - $end $selector = "enddate>=$start, (enddate<=$end), (startdate<=$end)";
    1 point
  22. SIX AND ONE => ALTI VE BIR => https://en.wikipedia.org/wiki/Trabzon_Province (I was born here) Vehicle registration code is : 61 and my company name. Living here : https://en.wikipedia.org/wiki/Marmaris since 1988
    1 point
  23. one line when using http://modules.processwire.com/modules/markup-simple-navigation/ 'show_root' => true just in case you don't know somas great module
    1 point
  24. Repeaters (can) create pages before you need them. This is for convenience. The default value is set to 3. You also can setup a repeater field to only create pages on demand. If I remember right, this would need one additional save click for every repeater item you add in the edit process. 1) check delete trash 2) set the repeater fields to NOT create temp pages, the default is set to 3 (!) 3) look under Admin -> Pages -> ... for a hidden folder with the repeater children and delete them
    1 point
  25. i installed it on my DigitalOcean VPS and run it in --certonly mode (as I run nginx). Worked like a charm, instantly.
    1 point
  26. Edit: an updated version of the the following class can be found here: https://processwire....-tips/?p=110290 <?php namespace ProcessWire; /** * Helps with the debugging log */ class Flog { protected static $name = 'flog'; protected static $firstSave = true; public static function init() { if(!file_exists(self::filename())) { self::log('f-log debug file created...'); } } public static function log($param, $file = '', $line = '') { $prepend = ''; if (gettype($param) != "object") { $prepend = gettype($param); } else { $prepend = get_class($param); } if (is_array($param)) { $param = json_encode($param); } if (self::$firstSave) { self::$firstSave = false; wire('log')->save(self::$name, "________________________ Flog log _______________________"); } if ($file) { $file = basename($file, '.php'); $line = $line . ' '; } wire('log')->save(self::$name, "$file $line"."[$prepend] $param"); } public static function filename() { return wire('log')->getFilename(self::$name); } public static function name() { return self::$name; } } The original class was dubbed Debug, which is used in the ProcessWire namespace, so I had to rename it. The "Flog log" line helps me quickly identify the various "logging sessions". File and line number can be used to identify the states of the same variable and later on to clean up (delete) all the temporary log method calls. I use a shortcut to quickly insert Flog::log($var, __FILE__, __LINE__); into the code, I just have to overwrite the variable name, and save+refresh the browser (using a shortcut in this case too). A code editor is used to keep the log file(s) open, which refreshes the open files whenever they change. I can delete lines from the log at will, since it is an actual editor. Simple but effective, I got used to this a debug workflow, since it can be used in any environment.
    1 point
  27. I would add a field to the user template and set its timezone for every user page. as you did. then using horst´s example hooks and session public function init() { $this->pages->addHookAfter('Session::logout', $this, 'timezoneLogout'); $this->pages->addHookAfter('Session::login', $this, 'timezoneLogin'); } public function timezoneLogin(HookEvent $event) { $user = $event->object; $session = wire('session'); $session->timezone = $user->timezone; } public function timezoneLogout(HookEvent $event) { $session = wire('session'); $session->remove('timezone'); } Now you can use the session var across the backend and the frontend without querying the user
    1 point
  28. Thanks Raymond. Have updated it in the code example above.
    1 point
  29. It's really useful for that exact use-case, but sometimes it can also be nice when you need to get a field value without textformatters being applied or other kinds of output formatters.
    1 point
  30. I found wireTempDir myself a few days ago, so memory fingerprint was fresh.
    1 point
  31. @LostKobrakai thanks for the tip. Martijn also mentioned this method. To be sure the temp file gets removed properly after a certain amount of time, i will use the WireTempDir class to create a tmp folder which will be removed automaticly after a X amount of time. Create the file (from base64) in there with fwrite and assign the file path of the tmp file to my image field.
    1 point
  32. I'm not very familiar with (user) timezones. A quick search through PWs wire files shows that timezone is used in ProcessWire::config with ini_set('date.timezone', $config->timezone); So I would change $config->timezone and PHPs date.timezone. But haven't worked / tested with that! In regard of getting the original / default value and not a runtime-changed value from $config, there is this possible workaround: function getDefaultValuefromConfig($key) { $config = new stdClass(); include( wire-config.php ); include( site-config.php ); // now we have merged default settings of $config in local scope of this function // and can return the requested one return $config->$key; }
    1 point
  33. Thanks for making the video but I'm sorry, from what I see, I cannot explain the behaviour.
    1 point
  34. I built a menu using Pages to let the translation handle itself through PW multi language page title fields. Though, while trying some click menu and scroll to element with class gimmicky, I decided to try to place a data attribute inside the clicked link so that I can later use it for the javascript class selection. $navigationPages = $pages->get("/navigation/")->children(); $spanish = $user->language->id; foreach ($navigationPages as $navigationItem){ echo "<li><a data-scroll='{$navigationItem->name}'>{$navigationItem->title} </a></li>"; } So while trying this, as you can see I used the name property to echo the data attribute value, I stupidly kept trying to echo the name in the non default language (spanish), until I decided to not break my brain and just use the one given by default (english). Could I have actually output the name in the non default language? For example I tried: $navigationItem->name->getLanguageValue($spanish) But didn't work, and I'm just wondering why. And I am also wondering, is this and this the only documentation available for using the language support through the API? I was just a bit surprised I didn't quite find any reference of this on the cheatsheet, is this because $languages or $user->language have to do with the language modules? Should I start reading source code to find out about this?
    1 point
  35. Because it depends on login / logout, my first thought is: $this->pages->addHookAfter('Session::logout', $this, 'yourFunction'); $this->pages->addHookAfter('Session::login', $this, 'yourFunction'); If this doesn't fit well, there is also $this->pages->addHookBefore('ProcessLogin::execute', $this, 'yourFunction'); $this->pages->addHookBefore('ProcessLogin::executeLogout', $this, 'yourFunction'); // or $this->pages->addHookAfter('ProcessLogin::execute', $this, 'yourFunction'); $this->pages->addHookAfter('ProcessLogin::executeLogout', $this, 'yourFunction');
    1 point
  36. Quick shot. not tested function renderList($items, $wrap = true) { if($items instanceof Page) $items = array($items); $out = ''; foreach($items as $item) { $out .= "<li><a href='$item->url'>$item->title</a></li>"; if ($item->hasChildren()) { $out .= renderList($item->children, false); } } if ($wrap) $out = "<ul>$out</ul>\n"; return $out; }
    1 point
  37. I think clsource and rick are right; even a tutorial for those new to ProcessWire should assume a general understanding of entity relationships, procedural programming, html and css, and it should concentrate on the methods and design patterns that beginners can easily implement to craft a site with typical components such as general pages, blog posts with categories and tags, a simple contact form and maybe a simple user management to protect a given page (and its children) on the frontend ("customer area"). By choosing a css framework, you can skip the design process altogether.
    1 point
  38. To get the old value(s), you can call the getChanges method like this: // If you need the old value(s) also $u->getChanges(true); Looking at your code, I see that you are assigning input from POST directly, without sanitizing. Check out ProcessWire's $sanitizer API variable. Cheers
    1 point
  39. ProcessWire tracks changes on properties, so you could do something this: // After submitting your form with POST, set the new values to your user object $u = $users->get('myUser'); $u->of(false); $u->set('field1', $sanitizer->text($input->post->field1)); $u->set('field2', $sanitizer->text($input->post->field2)); $u->set('field3', $sanitizer->text($input->post->field3)); // Now assume only field2 and field3 changed $u->getChanges(); // --> Returns you array('field2', 'field3'); // If you need the old value(s) also $u->getChanges(true); $u->save(); Hope it helps! Cheers
    1 point
  40. i'm sorry for that! you should have done the screencast before developing your module than i could have told you earlier
    1 point
  41. Updated module with a magic method. Now you can pass element name directly to class. Some Examples : // Working With ProcessWire $ul = html::ul()->addClass('list'); foreach($page->children as $p) { $ul->child( html::li() ->addClass('list-item') ->data('id', $p->id) ->child( html::a($p->title) ->addClass('list-item-link') ->attr('href', $p->url) ->data('id', $p->id)->r() )->r() ); } $ul->o(true); /* output : <ul class='list'> <li class='list-item' data-id='1057'> <a class='list-item-link' href='/en/villas/' data-id='1057'> Villas </a> </li> <li class='list-item' data-id='1001'> <a class='list-item-link' href='/en/location/' data-id='1001'> Location </a> </li> <li class='list-item' data-id='1090'> <a class='list-item-link' href='/en/guestbook/' data-id='1090'> Guestbook </a> </li> <li class='list-item' data-id='1055'> <a class='list-item-link' href='/en/contact/' data-id='1055'> Contact </a> </li> <li class='list-item' data-id='1005'> <a class='list-item-link' href='/en/site-map/' data-id='1005'> Site Map </a> </li> </ul> */ html::div("Hey !") ->addClass('container') ->addClass('container-center') ->id('centered-container') ->output(true); /* output :: <div id='centered-container' class='container container-center'> Hey ! </div> */ html::ul()->addClass('list')->children(array( html::li('Li element value 1')->addClass('list-item')->r(), html::li('Li element value 2')->addClass('list-item')->r(), html::li('Li element value 3')->addClass('list-item')->r(), html::li('Li element value 4')->addClass('list-item')->r(), html::li('Li element value 5')->addClass('list-item')->r() ))->o(true); /* output :: <ul class='list'> <li class='list-item'> Li element value 1 </li> <li class='list-item'> Li element value 2 </li> <li class='list-item'> Li element value 3 </li> <li class='list-item'> Li element value 4 </li> <li class='list-item'> Li element value 5 </li> </ul> */ html::hr(null, "/>")->o(); /* output : <hr /> */
    1 point
  42. Hey all, I'm on this. I actually never noticed it worked that way because my installs had the page set to published, so it showed in the list of children. For now, the temp fix is to un-hide the tree page.
    1 point
  43. Since we have a new security forum, why not post a topic containing the IPs and related files there, where we can all benefit from a pseudo- 'blacklist'?
    1 point
  44. Just for interest, I wonder how many PW users rename their admin? I always do, normally something relating to the site. So, if I had joss.com (which I don't!) I would create jsadmin or something. I vary the system quite a lot, but useful to keep it vaguely memorable for client sites. The ability to rename admin I think is a particularly neat security feature in PW. It might not be uber-powerful, but is so simple and just creates a nice little hurdle for bots to trip over.
    1 point
  45. Greetings, Hmm... Everyone run a check. After reading this, I took a look at some logs on a few of my own projects, and what do you know -- several hits on /[domain]/wp-admin. Joss may have stumbled onto a poke-wp opportunity. Maybe we could start a movement among all non-wp CMSs to redirect such requests to a particular WordPress page. That would be mean, of course -- potentially increasing their site visits overnight by millions of hits. Thanks, Matthew
    1 point
  46. This is a helper class to using debug log. require_once 'Debug.php'; Debug::init(); Debug::log($myVar); Debug::log($myArray); <?php /** * Helps with the debugging log */ class Debug { protected static $name = 'debug'; public static function init() { if(!file_exists(self::filename())) { self::log('Debug File Init'); } } public static function log($param) { if (is_array($param)) { $param = json_encode($param); } wire('log')->save(self::$name, $param); } public static function filename() { return wire('log')->getFilename(self::$name); } public static function name() { return self::$name; } }
    1 point
  47. Thanks bitpoet. Must have overlooked the clone function. And yes you understood it correctly that I wanted to create those virtual instance only on rendering. In the end I however decided to create real pages kind of like MuchDev suggested via module by hooking into the save function of the single-event pages. The admin for the single-event template now looks like this: https://monosnap.com/file/t187kaF2xI7WxF79blA3D982uMT1ko The code for the module is as follows. Adapt it for your needs <?php class recurringEvents extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Recurring Events', 'summary' => 'Adds a function to create recurring events and add pages to Processwire when a checkbox is checked on page save', 'version' => 1, 'autoload' => true, ); } public function init() { $this->pages->addHookBefore('save', $this, 'hookSave'); } public function hookSave($event) { $page = $event->arguments[0]; # check if recurring is checked on the page beeing saved. if ($page->recurring==1) { $intervallString=$page->intervall->title; for ($i=1; $i <= $page->n_repeats; $i++) { // create new page $k= new Page(); $k->template = 'single-event'; // set template $k->parent = wire('pages')->get('/events/'); // set the parent $intervall='+'.$i.' '.$intervallString; // construct the $intervall selector for strtotimestamp +1 week or +1day, increase with iteration by 1 $k->setOutputFormatting(false); // Copy page fields from current page to newly created one $k->title=$page->title; $k->organisation=$page->organisation; $k->type=$page->type; $k->location->address=$page->location->address; $k->body=$page->body; $k->recurring=0; $k->dateStart= strtotime($intervall, $page->dateStart); $k->dateEnd = strtotime($intervall, $page->dateEnd); $k->save(); } $this->message("Sucessfully created ".($i-1)." copies of recurring event {$k->title}"); // on the current page set recurring to 0 again, no page->save() needed because the page will be saved after the hook automatically $page->recurring=0; } } }?>
    1 point
×
×
  • Create New...