Jump to content

flydev

Members
  • Posts

    1,355
  • Joined

  • Last visited

  • Days Won

    48

Everything posted by flydev

  1. Under Edit field > Input > CKEditor Settings > CKEditor toolbar, you need to add the button: A11ychecker Save, then you should see the new button
  2. Checking expiration_date in the selector should do the trick. $todaysdate = date("F j, Y H:i"); $today = strtotime($todaysdate); $ads = $pages->find("parent.template=client, expiration_date<$today, sort=expiration_date"); echo count($ads);
  3. You are not incrementing $alert_count. It should be : $alert_count += 1; // not =+ 1;
  4. I understand now what you mean by no error. There is one last error, which can be seen if you dump the variable $response. You could see that SendGrid return an error code which can be something like that : statusCode => 401 body => "{"errors":[{"message":"Permission denied, wrong credentials","field":null,"help":null}]}" The reason is that the global $sgAPIKey in the function is not getting the value from the $sgAPIKey defined with the key (from some reason that someone might explain here..) To solve the issue, just set your API key in the function directly. [...] function send_email($from_email, $to_email, $subject, $body) { $sgAPIKey = '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'; // Lucy [...]
  5. And I was sure YOU will ask that ! Sure, I am already trying to get back my Gitlab server. The server was hosted in a VMware guest machine, and when plugged the hdd and put the virtual machine ON, the network simply does not work anymore. Can't ping anything, but I know how to fix it, i am just too lazy those days. Edit: Just to say, I still have the code and used the module in the last days, but it look like its not the Windows compatible version..
  6. Sorry but I do not understand, could you explain a bit more please ? Where do you first defined the send_mail () function ? (its not a ProcessWire or SendGrid function). If I assume you defined the function in, for example, _func.php, its normal you got an error of an undefined function. Just assuming... In your last code snippet, everything look fine (I would have defined the function outside the hook).
  7. @oma Call SendGrid like that : new \SendGrid(); (As Adrian said, its a namespace issue) @teppo I used WireFileTools just for the example, the bénéfit of this class is that it provide the ProcessWire API to the object. Sorry for the short answer, i am on mobile.
  8. Yes you can. $this->addHookAfter('Pages::save', function(HookEvent $event) { $arguments = $event->arguments(); $page = $event->arguments(0); if($page->template == 'user') { // Require relevent libraries $wft = new WireFileTools(); $wft->include('sendgrid-php/sendgrid-php.php'); $from = new \SendGrid\Email("Example User", "test@example.com"); $subject = "Sending with SendGrid is Fun"; $to = new \SendGrid\Email("Example User", "test@example.com"); $content = new \SendGrid\Content("text/plain", "and easy to do anywhere, even with PHP"); $mail = new \SendGrid\Mail($from, $subject, $to, $content); $apiKey = getenv('SENDGRID_API_KEY'); $sg = new \SendGrid($apiKey); $response = $sg->client->mail()->send()->post($mail); // dump SendGrid object with TracyDebugger bd($mail); } });
  9. Look like i am going to love it and its a french who made it! ♥ Will give a try soon, thanks for this post @alan
  10. Hello @Niku, sorry I am not giving you the right answer but.. You could take a look at this module : https://modules.processwire.com/modules/inputfield-select-multiple-transfer/ From the module's description it look like it could save you time
  11. The module got renamed and updated a bit as its not intended to run only on the backend, but work also on frontend side. - Now, the administrator can choose to activate or not the backend login buttons. - The providers are added "dynamically". You have to simply edit a JSON config file which once saved, will show the required fields in the module settings. For example the following JSON config will only provide Google as login provider : { "providers": { "google": { "className": "Google", "packageName": "league/oauth2-google", "helpUrl": "https://console.developers.google.com/apis/credentials" } } } Small note for pw users : If like me you did not know, there is another module that manages OAuth2 authentication. Feel free to use the one which suit your needs! more info there: @jmartsch you should create a new module thread
  12. With this markup and field options : $markup = array( 'list' => "{out}\n", 'item' => "\n\t<div class='form-group input-group'>\n{out}\n\t</div>", 'item_label' => "{out}", 'item_icon' => "<span><i class='fa fa-fw fa-{name}' aria-hidden='true'></i></span>", 'item_content' => "{out}", 'item_error' => "\n<p class='field--error--message'>{out}</p>", 'item_description' => "\n<p class='field__description'>{out}</p>", 'item_toggle' => '' //.... etc ); // field setup $field->icon = 'envelope'; $field->label = ' '; I get the following result : <div class="form-group input-group"> <span> <i class="fa fa-fw fa-envelope" aria-hidden="true"></i> </span> <input id="name" class="InputfieldMaxWidth" name="name" maxlength="2048" type="text"> </div> Another idea could be to set the markup option of the label to something like {{replaceme}} {out} {{/replaceme}} and change those tags when you render the form with a str_replace or a custom function, you see ?
  13. Edit September 2022 See this thread: --- I would have taken another way. As each photo are Page, he could create a module which work with a custom MySQL table where he update the like of a page with some informations aside, like the userID (the user who like the page), the pageID (the page being liked) , a likeStatus (like or unliked) and a timestamp. I made a small module to show the idea : then in the frontend, you can render a 'like' button on choosen templates, and finaly get the total number of likes of a page and the most liked page, see: <?php namespace ProcessWire; $likesmod = $modules->get('LikeSystem'); // render a 'like' button $content = $likesmod->render(); // total like of the page $content .= "Number of likes for this page: " . $likesmod->getTotal($page->id); // most liked page $limit = 1 $mostliked = $likesmod->getMostLikedPage($limit); $content .= "<br>Most liked page: " . $pages->get($mostliked[0]['pageId'])->title . "(" . $mostliked[0]['pageId'] . ") " . " (N likes: ". $mostliked[0]['likesCount'] . ")";
  14. hi @MilenKo you should read this post made by Ryan, and adapt it, it contain nearly all answers. Anyway your code should work if the comments/template are correct.
  15. Ok got it, you need to allow the anonymous function to "capture" local variables. Try the following ( note the use($f) ) : $byField = array_reduce($children->getArray(), function($carry, $child) use($f) { if(!is_object($child->$f) && !is_null($child->$f)) // avoid illegal offset type warning $carry[$child->$f][] = $child; // NO MORE ISSUE return $carry; echo count( $carry ); }, array());
  16. What is going on if you call it that way (minus $) ? : $carry[$child->f][] = $child; // no more ISSUE
  17. You can find more information there: https://processwire.com/docs/security/file-permissions/
  18. You could try to copy the root dir containing the site and do a chmod -R 777 on it (just for testing purpose!) - result ?
  19. Hi @adrianmak You can achieve this by using hooks and my ReCaptcha module. First install the MarkupGoogleReCaptcha module then in file ready.php, write the following code : /* * replace the LAST occurence of $search by $replace in $subject */ function str_lreplace($search, $replace, $subject) { return preg_replace('~(.*)' . preg_quote($search, '~') . '~', '$1' . $replace, $subject, 1); } /* * replace the FIRST occurence of $search by $replace in $subject */ function str_freplace($search, $replace, $subject) { $from = '/'.preg_quote($search, '/').'/'; return preg_replace($from, $replace, $subject, 1); } $captchamod = wire('modules')->get("MarkupGoogleRecaptcha"); wire()->addHookProperty('Page::captcha', function($event) use ($captchamod) { $event->return = $captchamod; }); wire()->addHookAfter('Page::render', function($event) { $template = $event->object->template; $page = $event->object; if ($template == 'admin' && !wire('user')->isLoggedin()) { $captchaScript = $page->captcha->getScript() . '</body>'; $captchaHtml = $page->captcha->render() . '</form>'; $event->return = str_freplace('</form>', $captchaHtml, $event->return); $event->return = str_lreplace('</body>', $captchaScript, $event->return); } }); wire()->addHookAfter('Session::authenticate', function($event) { $page = wire('page'); $template = $page->template; if ($template == 'admin') { if ($page->captcha->verifyResponse() == false) { wire('session')->logout(); wire('session')->redirect(wire('config')->urls->admin); } } });
  20. OAuth2Login for ProcessWire A Module which give you ability to login an existing user using your favorite thrid-party OAuth2 provider (i.e. Facebook, GitHub, Google, LinkedIn, etc.).. You can login from the backend to the backend directly or render a form on the frontend and redirect the user to a choosen page. Built on top of ThePhpLeague OAuth2-Client lib. Registration is not handled by this module but planned. Howto Install Install the module following this procedure: - http://modules.processwire.com/modules/oauth2-login/ - https://github.com/flydev-fr/OAuth2Login Next step, in order to use a provider, you need to use Composer to install each provider ie: to install Google, open a terminal, go to your root directory of pw and type the following command-line: composer require league/oauth2-google Tested providers/packages : Google : league/oauth2-google Facebook: league/oauth2-facebook Github: league/oauth2-github LinkedIn: league/oauth2-linkedin More third-party providers are available there. You should be able to add a provider by simply adding it to the JSON config file. Howto Use It First (and for testing purpose), you should create a new user in ProcessWire that reflect your real OAuth2 account information. The important informations are, Last Name, First Name and Email. The module will compare existing users by firstname, lastname and email; If the user match the informations, then he is logged in. ie, if my Google fullname is John Wick, then in ProcessWire, I create a new user Wick-John with email johnwick@mydomain.com Next step, go to your favorite provider and create an app in order to get the ClientId and ClientSecret keys. Ask on the forum if you have difficulties getting there. Once you got the keys for a provider, just paste it into the module settings and save it. One or more button should appear bellow the standard login form. The final step is to make your JSON configuration file. In this sample, the JSON config include all tested providers, you can of course edit it to suit your needs : { "providers": { "google": { "className": "Google", "packageName": "league/oauth2-google", "helpUrl": "https://console.developers.google.com/apis/credentials" }, "facebook": { "className": "Facebook", "packageName": "league/oauth2-facebook", "helpUrl": "https://developers.facebook.com/apps/", "options": { "graphApiVersion": "v2.10", "scope": "email" } }, "github": { "className": "Github", "packageName": "league/oauth2-github", "helpUrl": "https://github.com/settings/developers", "options": { "scope": "user:email" } }, "linkedin": { "className": "LinkedIn", "packageName": "league/oauth2-linkedin", "helpUrl": "https://www.linkedin.com/secure/developer" } } } Backend Usage In ready.php, call the module : if($page->template == 'admin') { $oauth2mod = $modules->get('Oauth2Login'); if($oauth2mod) $oauth2mod->hookBackend(); } Frontend Usage Small note: At this moment the render method is pretty simple. It output a InputfieldForm with InputfieldSubmit(s) into wrapped in a ul:li tag. Feedbacks and ideas welcome! For the following example, I created a page login and a template login which contain the following code : <?php namespace ProcessWire; if(!$user->isLoggedin()) { $options = array( 'buttonClass' => 'my_button_class', 'buttonValue' => 'Login with {provider}', // {{provider}} keyword 'prependMarkup' => '<div class="wrapper">', 'appendMarkup' => '</div>' ); $redirectUri = str_lreplace('//', '/', $config->urls->httpRoot . $page->url); $content = $modules->get('Oauth2Login')->config( array( 'redirect_uri' => $redirectUri, 'success_uri' => $page->url ) )->render($options); } The custom function lstr_replace() : /* * replace the last occurence of $search by $replace in $subject */ function str_lreplace($search, $replace, $subject) { return preg_replace('~(.*)' . preg_quote($search, '~') . '~', '$1' . $replace, $subject, 1); } Screenshot
  21. I feel really sorry. I have had some problems in recent months that have caused my brain to stop working .. And so I hesitated to launch the module knowing I could not give support. Anyway, I'm better and I resume the development as soon as I have my internet connection operational (should be good for monday). Sorry again guys!
  22. Hi @antpre and everyone. I lack time in recent days but the module should be available to the public the next coming week!
  23. This morning, after some adjustments and tests, the module run smoothly on ProcessWire 2.7, 2.8 and 3.x.
×
×
  • Create New...