Jump to content

Ferdi Derksen

Members
  • Posts

    47
  • Joined

  • Last visited

Everything posted by Ferdi Derksen

  1. After searching for a way to load a JS library once when looping through multiple hanna-codes (of the same type) at a page, I came up with the following solution; if (!isset($hanna->jsloaded)) $this->config->scripts->append('myJS.js'); $hanna->jsloaded = 1; // do other stuff Is this the correct way to do such loading? Session- or normal variables cannot be used since they keep on remembering or resetting the values during the process of loading pages (ones or multiple times).
  2. Hi all, First of all - keep in mind I'm not that experienced creating modules / general ProcessWire... I'm creating a module which can be used to tweet a page when saving it. When building this module, the following issue came up; My module has multiple (text) inputfields for connecting to OAuth (http://oauth.net), so as minimal as four fields should be set before an attempt to connect will be done, so no default values can be set. Only when saving the module, I cannot test the connection directly with the new posted data, why? When tested multiple times with a lot of different settings, the first message is a succesful connection to Twitter, and a few lines later the message is failed (or vice-versa depending on posted data). What am I missing/doing wrong? edit: I'm overwriting the $data variables with post data, but in my opinion this shouldn't be the case $wp = wire()->input->post; /** * Set required fields for use of this module * * @return InputfieldWrapper */ public function getModuleConfigInputfields(array $data) { $modules = wire('modules'); $templates = wire('templates'); $fields = wire('fields'); $fieldgroups = wire('fieldgroups'); foreach(self::getDefaultConfig() as $key => $value) { if(!isset($data[$key])) $data[$key] = $value; } // Get default Twitter settings $_ck = $data['publish_to_twitter_consumerkey']; $_cs = $data['publish_to_twitter_consumersecret']; $_at = $data['publish_to_twitter_accesstoken']; $_as = $data['publish_to_twitter_accesstokensecret']; // update/check data only after post $wp = wire()->input->post; if (wire('page')->template == 'admin' && count($wp)) { $_ck = $wp->publish_to_twitter_consumerkey; $_cs = $wp->publish_to_twitter_consumersecret; $_at = $wp->publish_to_twitter_accesstoken; $_as = $wp->publish_to_twitter_accesstokensecret; if(isset($_ck) && isset($_cs) && isset($_at) && isset($_as)) { // wire('session')->message("ck = $_ck"); // wire('session')->message("cs = $_cs"); // wire('session')->message("at = $_at"); // wire('session')->message("as = $_as"); // now we try to connect to Twitter with an OAuth connection and search for hashtag processwire require 'twitteroauth/twitteroauth.php'; $query = array( "q" => '#processwire', "count" => "5", "result_type" => "recent", // "include_entities" => "true", ); $toa = new TwitterOAuth($_ck, $_cs, $_at, $_as); $results = $toa->get('search/tweets', $query); // check if we got any response if (isset($results)) { // check for errors if(isset($results->errors) && count($results->errors)) { foreach($results->errors as $error) { wire('pages')->error("Twitter response: $error->message (Error code: $error->code)"); } } else { // successful connected wire('session')->message("Connection to Twitter was successful"); } } } } $inputfields = new InputfieldWrapper(); // Twitter settings: // Twitter Consumer Key $f = $modules->get('InputfieldText'); $f->attr('name', 'publish_to_twitter_consumerkey'); $f->label = __('Twitter Consumer Key'); $f->required = true; $f->columnWidth = 50; $f->attr('value', $data['publish_to_twitter_consumerkey']); $inputfields->add($f); // Twitter Consumer Secret $f = $modules->get('InputfieldText'); $f->attr('name', 'publish_to_twitter_consumersecret'); $f->label = __('Twitter Consumer Secret'); $f->required = true; $f->columnWidth = 50; $f->attr('value', $data['publish_to_twitter_consumersecret']); $inputfields->add($f); // Twitter Access Token $f = $modules->get('InputfieldText'); $f->attr('name', 'publish_to_twitter_accesstoken'); $f->label = __('Twitter Access Token'); $f->required = true; $f->columnWidth = 50; $f->attr('value', $data['publish_to_twitter_accesstoken']); $inputfields->add($f); // Twitter Access Token Secret $f = $modules->get('InputfieldText'); $f->attr('name', 'publish_to_twitter_accesstokensecret'); $f->label = __('Twitter Access Token Secret'); $f->required = true; $f->columnWidth = 50; $f->attr('value', $data['publish_to_twitter_accesstokensecret']); $inputfields->add($f); return $inputfields; }
  3. Not sure, but is it even possible to refer to $input->post->variable without posting to a ProcessWire page? You should post the data to a ProcessWire page like /book/ (which has the book.php file as its template).
  4. Please correct me if I'm wrong, but isn't this the same as Event C ? This event is also shown in the results. FYI; the selectors from the other topic also show the same results (B,C,D and E).
  5. That's the way I like it, even less code needed Those explanations are completely understandable! Thank you - both Ryan and Diogo for the fast replies.
  6. Hi folks, First of all - I'm not sure this is a explainable result - when so please explain (working with PW for only a few weeks now) My website has a lot of events with a start- and enddate. I'm looking for a complete selector which will return the events happening between today (2015-11-06) and a week from now (2015-11-13). I'm searching trough a lot of pages which have the following dates (testcase) ; Title | Startdate | Enddate --------------------------------------------- Event A | 2015-09-21 | 2015-09-22 Event B | 2015-09-21 | 2015-11-10 Event C | 2015-09-21 | 2015-11-30 Event D | 2015-11-07 | 2015-11-08 Event E | 2015-11-07 | 2015-11-19 Event F | 2015-11-18 | 2015-11-19 My expectations are events A and F not to show as a result (they have ended before today or starting after a week from now). Given the dates my selectortest is the following; template=event,enddate>=2015-11-06,enddate<=2015-11-13|startdate<=2015-11-13 ... which results in only Event B and D Simply switching the startdate and enddate did the trick; template=event,enddate>=2015-11-06,startdate<=2015-11-13|enddate<=2015-11-13 ... which results in events B, C, D and E My question, why??
  7. Hi Martijn, Maybe you could have a look at the styling when only one row is set, the scrollbars make editing the row very difficult, especially when there is a large amount of columns set. Tnx in advance and keep up the good work, very pleased with the module! and again tnx for the headsup last Monday! ;-)
  8. Worked like a charm! Didn't know this was possible, many thanks! [edit] my initial problem is solved - the bug still stands and will be discussed further at GitHub - https://github.com/ryancramerdesign/ProcessWire/issues/1479
  9. @LostKobrakai Thanks for the feedback - but I'm only using the API in this case. I opened a new GitHub issue - https://github.com/ryancramerdesign/ProcessWire/issues/1479
  10. That's weird because when testing this on DEV 2.6.19 (also on Master 2.6.1) the following results appear; var_dump(wire('sanitizer')->url("http://")); string 'http://' (length=7) var_dump(filter_var('http://', FILTER_VALIDATE_URL)); boolean false
  11. Hi all, I'm pretty new here (working with PW for only a few weeks now) but I can't find out how the $sanitize->url() function should working. In my case the input is only "http://" and I'd expected the sanitizer to result an empty string, this isn't the case and results the exact input value. Is there a explanation for this, or are my expectations off-target? Tnx in advance!
×
×
  • Create New...