-
Posts
711 -
Joined
-
Last visited
-
Days Won
9
Everything posted by psy
-
Little bit chuffed with this new function. You can adapt it to create thumbnail images of external web pages. In my case, it creates a thumbnail image of the publicly viewable Eventbrite event page and attaches it to the PW event page. The $ebResponse is the json_decoded data returned from the webhook call to Eventbrite. /** * Calls the pagepeeker.com API to generate a thumbnail of the Eventbrite public page * @param $ebResponse- the json decoded response from Eventbrite * @param $options = refer pagepeeker API doc - * $options['entrypoint'] - Free 'free'. That makes it: http://free.pagepeeker.com/ * Unbranded 'api'. That makes it: http://api.pagepeeker.com/ * All paid accounts 'api'. That makes it: http://api.pagepeeker.com/ * * $options['size'] - The size of the thumbnail. Available sizes: * 't' Tiny, 90 x 68 pixels * 's' Small, 120 x 90 pixels * 'm' Medium, 200 x 150 pixels * 'l' Large, 400 x 300 pixels * 'x' Extra large, 480 x 360 pixels * * $options['code'] - Your API key. This is optional and recommended to use only for server side calls. * Client side usage does not require it, as we automatically show the thumbnails only * for the domains added in your account. * For the free branded accounts, this parameter is ignored, as we provide the free branded * service for anybody, free of charge. * * Warning * Never use this code on client side pages. We use it for counting your API calls, so having * it used by third parties will count against your monthly quota. * $option['template'] - your PW page template * $option ['field'] - your PW page template image field * $option['page'] - the page to retrieve and attach the image to * * @return mixed * @throws WireException */ public function ___pagePeeker ($ebResponse, $options) { $entrypoints = array('free', 'api'); $options['entrypoint'] = in_array($options['entrypoint'], $entrypoints) ? $options['entrypoint'] : 'free'; $options['size'] = !empty($options['size']) ? $options['size'] : 'l'; $p = $this->wire('pages')->get($options['page']->id); if (!$p->id) throw new WireException($this->className() . _(' invalid page supplied in pagePeeker options')); $templateName = $options['template']; $tpl = $this->wire('templates')->get("name=$templateName"); $imagesField = $options['field']; if (!$tpl->hasField($imagesField)) throw new WireException($this->className() . _(' the template you supplied does not have the image field as specified in pagePeeker options')); $ebLiveUrl = urlencode(str_ireplace("https://www.", "", $ebResponse['url'])); $http = $this->wire(new WireHttp()); // http://{entrypoint}.pagepeeker.com/v2/thumbs.php?size=m&refresh=1&url=wikipedia.org $peekerUrlMake = 'http://' . $options['entrypoint'] . '.pagepeeker.com/v2/thumbs.php?size=' . $options['size'] . '&url=' . $ebLiveUrl; // Get the contents of a URL $response = $http->get($peekerUrlMake); if($response !== false) { $responseObj = json_decode($response); if ($response['error'] == 1) { // error generating thumbnail throw new WireException($this->className() . _(' problem generating pagepeeker thumbnail')); } // OK no errors but thumbnail not ready. Try every pagepeeker server $response = $http->get('http://' . $options['entrypoint'] . '.pagepeeker.com/v2/thumbs_ready.php?size=' . $options['size'] . '&url=' . $ebLiveUrl); $response1 = $http->get('http://' . $options['entrypoint'] . '1.pagepeeker.com/v2/thumbs_ready.php?size=' . $options['size'] . '&url=' . $ebLiveUrl); $response2 = $http->get('http://' . $options['entrypoint'] . '2.pagepeeker.com/v2/thumbs_ready.php?size=' . $options['size'] . '&url=' . $ebLiveUrl); $response3 = $http->get('http://' . $options['entrypoint'] . '3.pagepeeker.com/v2/thumbs_ready.php?size=' . $options['size'] . '&url=' . $ebLiveUrl); $response4 = $http->get('http://' . $options['entrypoint'] . '4.pagepeeker.com/v2/thumbs_ready.php?size=' . $options['size'] . '&url=' . $ebLiveUrl); /** * Finally, thumbnail is ready * Download the image: http://{entrypoint}.pagepeeker.com/v2/thumbs.php?size=m&url=wikipedia.org * Check all the available pagepeeker servers to speed up the download **/ if ($response) { $fromUrl = "http://" . $options['entrypoint'] . ".pagepeeker.com/v2/thumbs.php?size=" . $options['size'] . "&url=" . $ebLiveUrl; } elseif ($response1) { $fromUrl = "http://" . $options['entrypoint'] . "1.pagepeeker.com/v2/thumbs.php?size=" . $options['size'] . "&url=" . $ebLiveUrl; } elseif ($response2) { $fromUrl = "http://" . $options['entrypoint'] . "2.pagepeeker.com/v2/thumbs.php?size=" . $options['size'] . "&url=" . $ebLiveUrl; } elseif ($response3) { $fromUrl = "http://" . $options['entrypoint'] . "3.pagepeeker.com/v2/thumbs.php?size=" . $options['size'] . "&url=" . $ebLiveUrl; } elseif ($response4) { $fromUrl = "http://" . $options['entrypoint'] . "4.pagepeeker.com/v2/thumbs.php?size=" . $options['size'] . "&url=" . $ebLiveUrl; } else { throw new WireException('Did not get a response from PagePeeker'); } $imgName = "eb-preview-" . $ebResponse['id']; $toFile = $this->wire('config')->paths->assets . "files/" .$p->id .'/'. $imgName . '.jpg'; $p->of(false); $img = $http->download( $fromUrl, $toFile); // OK we have the downloaded file, now add it to the page database info for the images field $imgUrl = $this->wire('config')->urls->assets . "files/" .$p->id .'/'. $imgName . '.jpg'; $pwImage = new Pageimage($p->$imagesField, $toFile); $pwImage->description = $ebResponse['name']['text']; $pwImage->tags = "eb-preview"; $p->$imagesField->add($pwImage, $imgUrl); return $img; } else { throw new WireException("HTTP request failed: " . $http->getError()); } }
-
Developing this module has definitely been a trial by fire. Getting there though and for sure, reading the PW API docs helped and not just what I thought I needed to know but other stuff as well. Was so focussed on: $eb = $modules->get('EventbriteAPIv3')->login(); in my webhook template which failed every time, I completely overlooked: $eb = wire('modules')->getModule('EventbriteAPIv3', array('noPermissionCheck' => true))->login(); Of course the webhook template/response is not a logged-in admin with permission to change stuff... Doh!
-
Channelling Thomas Edison again. Problem I've having now is not Eventbrite but PW. The module is configured to not autoload although I've tried that too. I have 2 page templates: 1. Calls my EventbriteAPIv3 module that returns data to a 'normal', viewable page template. All good there 2. Calls my EventbriteAPIv3 in the EB web hook endpoint page template. Not matter how I try to configure it, the module is never loaded. Instead I get any number of PW error messages, eg: When I use $eb = $modules->get(EventbriteAPIv3)->login() or $eb = wire('modules')->get('EventbriteAPIv3')->login() in the page template: Error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? (in /home/xxxx/xxxx.com/wire/core/Selectors.php line 378) Other error message include, depending on the method I chose to load it: Error: Uncaught Error: Call to a member function getAccessCode() on null in /home/xxxxxx/xxxxxx.com/site/templates/eventbrite-webhook.php:21 Have even tried putting the $modules->get call it in _init.php without success. Reading the PW doco, google searching and running out of ways to vary the call yielded nothing. All suggestions, help & guidance most welcome.
-
Getting closer to an initial release. Def been a learning experience using EB's self-proclaimed "easy API". Tip for other devs when implementing other vendors' API's - check the github pull requests before committing hari-kari. In my case https://github.com/eventbrite/eventbrite-sdk-php/issues/7 - wasn't me after all, just a MAJOR bug in the API. My alpha version has the suggested solution implemented and all good so far What I can say is that if you only want to pull info from your own EB stuff into PW, you won't need my module. Simply set up the necessary in EB and create a PW page/template to handle the web hooks, eg when an event is created in Eventbrite, you can pull that info into PW with: // Retrieve the request's body and parse it as JSON $eventbrite_json = @file_get_contents("php://input"); $eventbrite_obj = json_decode($eventbrite_json); /** * Eventbrite webhooks * attendee.checked_in - Triggered when an attendee’s barcode is scanned in. * attendee.checked_out - Triggered when an attendee’s barcode is scanned out. * attendee.updated - Triggered when attendee data is updated. * event.created - Triggered when an event is initially created. * event.published - Triggered when an event is published and made live. * event.updated - Triggered when event data is updated. * event.unpublished - Triggered when an event is unpublished. * order.placed - Triggers when an order is placed for an event. Generated Webhook’s API endpoint is to the Order endpoint. * order.refunded - Triggers when an order is refunded for an event. * order.updated - Triggers when order data is updated for an event. * organizer.updated - Triggers when organizer data is updated. * ticket_class.created - Triggers when a ticket class is created. * ticket_class.deleted - Triggers when a ticket class is deleted. * ticket_class.updated - Triggers when a ticket class is updated. * venue.updated - Triggers when venue data is updated. */ switch ($eventbrite_obj->config->action) { case 'event.created': $apiUrl = $eventbrite_obj->api_url; $apiUrlArr = explode('/events/', $apiUrl); $eventId = str_ireplace('/', '', $apiUrlArr[1]); $template = wire('templates')->get('name=test-eventbrite-webhook'); $p = new Page(); $p->template = $template; $p->title = $sanitizer->text($eventId); $p->name = $sanitizer->pageName($eventId); $p->parent = pages(1); $p->save(); break; default: break; } // tell eventbrite the webhook was received. http_response_code(200); // PHP 5.4 or greater
-
@rick overcame that hurdle, now onto next one. Eventbrite is a great app but unfortunately : their v3 API doco is at best minimal and often misleading/confusing, the errors it reports are correct but don't accurately describe the exact problem, and what works on their browser based debug page doesn't always translate to the actual PHP API. In the above case, the order of the $_GET vars is important and when using one $param, the doco doesn't mention you also require another. In my case above, I needed both page_size and page (page_number). All good now. Still working on getting it all into a functioning PW module.
-
Thanks @rick, feel like I'm channelling Thomas Edison - "I have not failed. I've just found 10000 ways that won't work." Tried everything combination I can think of and now very tired. Have posted in the Google EB support group but not hopeful of an answer. Maybe with a clear head tomorrow... Appreciate your suggestions
-
it's not just the 'whole number' error. If I remove the page_size var, I get a similar error on the token var and I know $eb->access_code outputs the correct value. Seems like EB doesn't recognise the end of the URL when submitted via the API. Just want to confirm it's not me doing something dumb in the module code
-
@rick Ummn, kinda, I think... put it this way, when I echo the full URL and enter it manually into the browser bar, I the correct response output on the screen:
-
More... if I remove the page_size $_GET var, I get the same error for the access code
-
Thanks @rick tried so many variations starting to get in brain-blip mode. Removed entirely the quotes around page_size and still same error. Edited original post
-
Hi, me again - queen of the ProcessWire API Wrapper. Why re-invent the wheel when there are so many great, well-supported apps out there that don't impact on the core of PW? Almost see PW as a portal. Latest endeavour is a PW module for Eventbrite v3 API https://www.eventbrite.com/developer/v3/ The EB webhooks are a easy-peasy-lemon-squeezy. Love it! Can do any of the API GET calls providing they don't include any parameters, eg: $eb = $modules('EventbriteAPI')->login(); $ebUser = $eb->client->get('/users/me/'); $ebUserId = $ebUser['id']; // /users/:id/owned_events/ $result = $eb->get("/users/$ebUserId/owned_events"); Problem I'm having is with using parameters in the actual API, eg: $eb = $modules('EventbriteAPI')->login(); $ebUser = $eb->client->get('/users/me/'); $ebUserId = $ebUser['id']; $ebPath = "/users/$ebUserId"; $token = $sanitizer->text($eb->access_code); $pageSize = $sanitizer->int(5); $expand = array(); $result = $eb->client->get( $ebPath . "/events?&token=" . $eb->access_code . "&page_size=" . $pageSize ); Every time I use a parameter, I get the EB error message for the last one, in the example below, the paging limit: "There are errors with your arguments: page_size - Enter a whole number." Even stranger is if I manually create the URL, eg https://www.eventbriteapi.com/v3/users/2425020999999/events?&token=WNU7SPIEUUUIXXXXXX&page_size=5 in the EB API test environment, I get the correct result. Fairly certain it's an EB issue but wanting to double check I've got everything right and the PW API isn't doing anything too clever with the $_GET vars. Any help/suggestions most welcome. Thanks psy
-
Example use: get a list of the logged-in user's subscriptions: <?php namespace ProcessWire; use PayWhirl; $payWhirl = $modules->get('PayWhirlAPI')->login(); $data = array('keyword' => $user->email); $userSubs = $payWhirl->getSubscriptions($payWhirl->getCustomers($data)[0]->id);
-
@prestoav, @noelboss I also wanted a PayWhirl API for ProcessWire so just went ahead a built one. It's basic - simply a PW wrapper for the PayWhirl API but should be OK. Biggest gotcha I discovered was that at present, you need a paid PayWhirl account - not the freebie one. You could ask PayWhirl to grant access to your free account for development purposes... Will let you know their answer to my request for same.
- 5 replies
-
- 3
-
-
- ecommerce
- subscription
-
(and 2 more)
Tagged with:
-
Seems I needed this at the same time as other ProcessWire devs. Timely! This module is simply a ProcessWire module wrapper for the PayWhirl API and being the initial release, may have a few unforeseen hiccoughs. Please be gentle with me when reporting any problems. As with all API's make certain your ducks are all lined up with the vendor first, in this case PayWhirl -https://app.paywhirl.com/ Download the module from GitHub at https://github.com/clipmagic/PayWhirlAPI Download the module from ProcessWire modules at http://modules.processwire.com/modules/pay-whirl-api/
-
[solved] $session incorrectly storing string from $page var
psy replied to psy's topic in General Support
@Robin S You nailed it! Thank you. Don't recall changing any template permissions but must have done at some stage. They were certainly all set to the defaults. No matter, problem solved. Cheers, psy -
[solved] $session incorrectly storing string from $page var
psy replied to psy's topic in General Support
@BitPoet yes, really curious. Nothing in init.php and very little, let alone anything I would suspect would cause an issue in ready.php. I made an autoloaded module of custom functions rather than _func.php and will check it thoroughly, but again doubt it. It mostly comprises mark-up output. Will try your suggestions and report back - but not right now, it's 10pm on Friday night here and just a bit over it. Thanks for your ideas. -
[solved] $session incorrectly storing string from $page var
psy replied to psy's topic in General Support
@BitPoet tried the double quotes... tried everything I could think of including trying with only one tab open in FF and definitely logged out. Use Chrome for dev. -
[solved] $session incorrectly storing string from $page var
psy replied to psy's topic in General Support
@BitPoet, yep tried that (proven with var_dump($page->url); die ... in _init.ph contains the current page url or id or whatever... even tried: $url = $page->url; I've read the docs at https://processwire.com/api/ref/session/ and looked at core/Session.php - I can't see anything either. It's got me stumped! What's weirdest is if I type in the page path, eg '/rants/' - it all works -
[solved] $session incorrectly storing string from $page var
psy replied to psy's topic in General Support
@BitPoet thanks for the suggestion. I have $config->useFunctionsAPI = true; in my config.php and even after trying your suggestion, it failed. There is no problem with the $session redirecting to the login page with either coding version. The problem appears to be that somewhere, $session tries & fails to evaluate $page->httpUrl, or $page->id, or $page->path, or $page->anything If it helps, I'm using: PW version: 3.0.88 PHP version: 7.0 -
I've used this code on another site (same web host) and it all works fine. When a visitor lands on a page and they're not logged, the page name/path/url/httpUrl (tried them all) is saved to a session var. Code in _init.php is: $loginPage = pages( 1085); if(!$user->isLoggedin() && $page->id != $loginPage->id) { // not for login page $session->set('returnPage', $page->path); // results in /http404/ stored in session var // $session->set('returnPage', '/rants/'); // works fine $session->redirect($loginPage->url); } Code in the LoginRegister template: if($user->isLoggedin() && !$input->get('profile') && !$input->get('logout')) { // login and go back to the previous page or go to the home page $goToUrl = $session->get('returnPage') ? $session->get('returnPage') : '/'; var_dump($session->getAll()); die; $session->redirect($goToUrl); } else { // let the LoginRegister module have control $content = $modules->get('LoginRegister')->execute(); } This var_dump shows that the returnPage session variable is stored as the path to the 404 error page ["returnPage"]=> string(9) "/http404/" I also tried $page->id with the resulting var (int) 27 which is the 404 Page id. Also tried namespace in the session var... It all worked fine when I manually typed in a valid page path, ie only weirdness when I used the $page var. Any help to explain why this is happening and how to fix greatly appreciated. tia
-
@rajo forgot to mention in my post above... welcome back to ProcessWire
-
You could look at @kongondo's Blog Module http://modules.processwire.com/modules/process-blog/ for your News site and this thread may give you some ideas on how to cut down front end development time
-
There are loads of favicon generators. I generally use https://www.favicon-generator.org/ then point the link href to the appropriate directory & file
-
Maybe make the form action '/' and then specify the actual URL in the js code rather than pulling it from the form?