Jump to content

flydev

Members
  • Posts

    1,366
  • Joined

  • Last visited

  • Days Won

    49

Everything posted by flydev

  1. Hi @Elchin I got them in the past but the query was to slow so I finally used a custom query to achieve that, you might be interested as I don't know the number of pages your trying to fetch - I give you a small module which could be extended, shipped with a hook function which return all pages between two dates given a fieldname and a template id :
  2. Another idea, a parent site with a Restful API to deliver content would be my way to go in this case.
  3. It works like that, just FYI this function take 2 arguments so it need to be called : $http->setHeader("Authorization", api_key=". $this->api_key); After that, the API key is reconized. So I tested the module with the field in the template and trought the API, worked like a charm ? ...
  4. On ProcessWire 3.0.124, I can't get it working. There is a weird issue with headers. The module keep saying that the API Key is invalid, I then tried with cURL on a terminal and it worked as expected. So I put a Tracy call to the core WireHttp to dump the headers set in the object : https://github.com/processwire/processwire/blob/dev/wire/core/WireHttp.php#L576-L578 [...] bd($key .' => '. $value); [...] and as a result, we can see a string ( "0 : " ) before the Authorization header : The header is treated as an array, see the index '0' ($key dumped here) : It's strange and its explain why my PulsewayPush module stopped working suddenly since some weeks after an upgrade. I just upgraded the system to ProcessWire 3.0.127, same things happen..
  5. Just testing it, look great ? I suggest a more verbose message when there is an error. I got the following message "There was a problem sending the notification" and I needed to put a bd($resultObj); on line 200 to know which error was triggered. In my case, was : I also got a notice for an undefined variable when there are error with $resultObj , the variable should be affected to false just before the if($resultObj->success) condition to avoid this notice : Thanks again for this useful module !
  6. Just a question, did you tried to unload those modules from apache and to run a new ProcessWire installation with a basic configuration to be sure that you can access the backend and login and will also confirm that the server config is ok ? If you are sure that your apache/php(fpm) configuration is green then try what @Robin S already said, first try to track down the issue with $config->sessionFingerprint Edit your /wwwroot/site/config.php, add/modify the two following config vars by referring to the PHP comments below and come back to use with your results. /** * Use session challenge? * * Should login sessions have a challenge key? (for extra security, recommended) * * @var bool * */ $config->sessionChallenge = true; // try without here (set to false) /** * Use session fingerprint? * * Should login sessions be tied to IP and user agent? * IP fingerprinting may be problematic on dynamic IPs. * Below are the possible values: * * 0 or false: Fingerprint off * 1 or true: Fingerprint on with default/recommended setting (currently 10). * 2: Fingerprint only the remote IP * 4: Fingerprint only the forwarded/client IP (can be spoofed) * 8: Fingerprint only the useragent * 10: Fingerprint the remote IP and useragent (default) * 12: Fingerprint the forwarded/client IP and useragent * 14: Fingerprint the remote IP, forwarded/client IP and useragent (all). * * If using fingerprint in an environment where the user’s * IP address may change during the session, you should * fingerprint only the useragent, or disable fingerprinting. * * If using fingerprint with an AWS load balancer, you should * use one of the options that uses the “client IP” rather than * the “remote IP”, fingerprint only the useragent, or disable * fingerprinting. * * @var int * */ $config->sessionFingerprint = 1; // try with different value here Edit: @fmgoodman Could you also adjust this directive from SessionCookieName session domain=myndtyme.com to SessionCookieName session path=/;domain=myndtyme.com;
  7. Hi @fmgoodman Please post the Apache and the PHP error logs. Also, what is the ownership of /var/www/lib/php/session|cookie ? You can also try to troubleshoot by changing the session.save_path and session.cookie_path of your php.ini file from /var/www/lib/php/session|cookie to /tmp If you can't get it working, I offer you a ninja session on your server ?
  8. For my project I need an implementation of Basic Auth, so I added a new option 'Basic Auth' available in the module config : and then, in the Router.php file, method handle(), I added the following code : // Basic HTTP Authentication if($authMethod === 'basic' && $routeNeedsAuth) { $authHeader = self::getAuthorizationHeader(); if(!$authHeader) { self::displayError('Bad Request', 400); } $hash = base64_decode(substr($_SERVER["HTTP_AUTHORIZATION"], 6)) ; $authHeader = explode(':', $hash, 2); if(!isset($authHeader[0]) || !isset($authHeader[1])) { self::displayError('No Authorization Header found', 400); } $credentials = new \StdClass(); $credentials->user = $authHeader[0]; $credentials->pass = $authHeader[1]; RestApiHelper::checkAndSanitizeRequiredParameters($credentials, ['user|selectorValue', 'pass|text']); $loggedin = wire('session')->login($credentials->user, $credentials->pass); if(!$loggedin) { self::displayError('user does not have authorization', 401); } } and in the method getAuthorizationHeader() I added : if(array_key_exists('php_auth_user', $headers)) return ['user' => $headers['php_auth_user'], 'pass' => $headers['php_auth_pw']]; It works, but does it make sense ? Edit: Pull Request : https://github.com/thomasaull/RestApi/pull/3
  9. Thanks mate ?
  10. @thomasaull I noticed something annoying in the API endpoint config field, I need to open the devtools and remove the `pattern` attribute manually in order to save the settings, look : If you are short on time, I can send a PR.
  11. Hi, The used settings (port) look not secure. try theses settings :
  12. @Steve_Stifler Just before going to tutorials, have a look at those discussions, for sure it will interest you / make you enthousiast / make you ?
  13. Hi @Zahari M. also you could read those threads to see a usecase :
  14. Hi @gottberg There is a bit of work to get images, as the way you are doing return Images Objects and not array. You can have a look at this file to see the "complexity" to retrieve those objects : https://github.com/microcipcip/processvue/blob/master/site-processvue/templates/inc/pagefields.php#L236 Or you can build your own images array before assigning it to the API answer : See updated ImageHelper.php file at the bottom of this post. /* route : 'page' => [ ['GET', '{id:\d+}', Example::class, 'getPage', ["auth" => false]] ] */ // get page route answer function public static function getPage($data) { $data = RestApiHelper::checkAndSanitizeRequiredParameters($data, ['id|int']); $response = new \StdClass(); $p = wire('pages')->get($data->id); if(!$p ->id) throw new \Exception('Page not found'); $response->id = $p->id; $response->name = $p->name; $response->title = $p->title; $response->body = $p->body; $response->sidebar = $p->sidebar; $response->summary = $p->summary; // our own images array $images = array(); foreach ($p->images as $image) { array_push($images, array( $image->name => array( 'url' => $image->url, 'filename' => $image->filename, 'width' => $image->width, 'height' => $image->height // ... ) ) ); } $response->images = $images; return $response; } Result : --- Edit : The image class helper : <?php namespace ProcessWire; /** * InputfieldImage Helper * Use for single image * * Usage : * $image is your ProcessWire PageImage * return ImageHelper::get($image, [400, 800, 1200, 2000, 2500]); */ class ImageHelper { public static function get ($image, $widths = [400, 800, 1200]) { $response = new \StdClass(); $response->focus = ["x" => $image->focus['left'], "y" => $image->focus['top']]; $response->urls = []; $response->description = $image->description; $response->name = $image->basename; $response->width = $image->width; $response->height = $image->height; foreach ($widths as $width) { $croppedImage = $image->width($width); $url = new \StdClass(); $url->url = $croppedImage->httpUrl; $url->width = $croppedImage->width; $url->height = $croppedImage->height; $url->ratio = $croppedImage->height / $croppedImage->width; array_push($response->urls, $url); } return $response; } } /** * InputfieldImage Helper * Use for multiple images * * Usage : * $images is your ProcessWire PageImages * return ImagesHelper::get($images, [400, 800, 1200, 2000, 2500]); */ class ImagesHelper { public static function get($images, $widths = [400, 800, 1200]) { $response = new \StdClass(); $response->images = []; $img = new \StdClass(); // our own images array $imagesArr = array(); foreach ($images as $image) { $img->focus = ["x" => $image->focus['left'], "y" => $image->focus['top']]; $img->urls = []; $img->description = $image->description; $img->name = $image->basename; $img->width = $image->width; $img->height = $image->height; foreach ($widths as $width) { $croppedImage = $image->width($width); $url = new \StdClass(); $url->url = $croppedImage->httpUrl; $url->width = $croppedImage->width; $url->height = $croppedImage->height; $url->ratio = $croppedImage->height / $croppedImage->width; array_push($img->urls, $url); } array_push($response->images, $img); } return $response; } }
  15. Hi Rudy, Storing a JSON array in a TextArea should works as expected without doing anything than saving the field in a standard fashion. protected static function getDefaultData() { return array( 'json_config' => '' ); } public static function getModuleConfigInputfields(array $data) { $data = array_merge(self::getDefaultData(), $data); $modules = wire('modules'); $fields = new InputfieldWrapper(); $field = $modules->get("InputfieldTextarea"); $field->label = __('JSON Config'); $field->attr('name+id', 'json_config'); $field->attr('value', $data['json_config']); $fields->append($field); return $fields; }
  16. Hey @horst It is solved ? If not, you might could try what is suggested in this answer on StackExchange : https://webmasters.stackexchange.com/questions/116301/how-to-force-ssl-and-www-for-a-subdomain-as-an-independent-domain Edit: ok, didn't read the post's update.
  17. @Pete I can build Windows desktop app only or multi-device application if needed, but I cannot start coding something before three weeks. Language used will be C++ or Pascal, so if it is not to far, let's discuss this in PM ?
  18. Okay I get your point. I made a 30 lines CSS Only switcher that should work with other theme than UiKit : https://codepen.io/flydev/pen/QYYZVL
  19. Hi Peter, It's hard to find something without the logs and the phpinfo() result, we can only make assumptions. What say the logs ? Could be something related to the PHP Garbage Collection mystery.. Hard to tell at this point and even worse with shared host. Also, it's possible that Plesk have a script run by a CRON job which delete sessions EACH HOUR, that could be the issue too! ask your host about that or look into your panel. A suggestion before starting scratching your head by modifying some values in the php.ini file would be to test the same form submission but with a different session handler configured, eg, SessionHandlerDB and SessionHandlerRedis. Setting up the last one for testing is quite simple, configure the Redis server on your computer to listen all interface (::1), open the right port (6379 by default) in your firewall/box and set the connection information in the config.php of your website, done, test it now. And as always, if you want me to have a ninja session on your server settings, ping by PM ?
  20. With this lib for example: https://github.com/zhiyul/Switch (there are multi choice on Github), load it on your module ___init() (add it to your scripts queue) and then in your module js file, call var el = document.querySelector('.checkbox-switch'); var mySwitch = new Switch(el, options); then do send your ajax request in the onChange event. Hope you get it. If you need a real example, just ask.
  21. If you are on a unix based system then you should give a try to Tasker/DataSet as @dragan said or look at the pcntl extension used in conjunction with the lib PHP League CSV. On windows (because the pcntl extension is not supported) I am used to write a custom import script with the same lib (PHP League) and calling `set_time_limit()` in the loop after importing X records. I import and create something like ~15k pages each night, it work pretty good.
  22. Very nice idea, thanks for sharing it with us ? Do not hesitate do register your modules in the modules directory.
  23. Hello guys, Which version are you using ? I just tested it with Duplicator 1.2.9 and everything works fine on my side a part an issue already reported in dev thread which is related to the "restore" procedure. Is there anything in the Duplicator logs ? Or maybe something in the ProcessWire logs (errors or exceptions) and at least in the PHP error log file ? Please, feel free to post/report things there :
  24. Hi @MarcoPLY Not really helping here, but the update about WireHttp and cURL came in ProcessWire 3.0.124 and it say : https://github.com/processwire/processwire/blob/dev/wire/core/WireHttp.php#L670 I am curious to see from where its happening. What is your registration code ? It is the LoginRegister module which is triggering this exception ? (sorry, I have trouble expressing myself, I'm sick ? )
×
×
  • Create New...