-
Posts
1,554 -
Joined
-
Last visited
-
Days Won
48
Everything posted by gebeer
-
As far as I know, there is no limit on the API side. You can create 100s or 1000s of pages. I think what happens in your case is that the max execution time for your script is reached at some point in your loop. This max value depends on your server settings. But you can change it runtime by using ini_set('max_execution_time', 300); ( would be 300 seconds for each iteration, which is just an example value) inside your loop and this will reset the execution time for each iteration in your loop. See here for more info.
-
When processing your form, you need to upload the image to a temporary folder first, before you can add it. Here and here are working examples. The important parts in that code is WireUpload, which saves the images to the temporary $upload_path. From the examples you can also learn how to utilize the PW form API to do error handling etc. Hope this helps.
-
@iNoize To make a call, you need to have the module installed and gone through the process of generating your access token (which is desribed in the module howto). Then you can make calls from anywhere in yoru templates: $instagram = $modules->get('InstagramFeed'); // load the module $userMedia = $instagram->getRecentMedia(); // get media of your user Then you should have a look at the PHP example to see how you can access values inside $userMedia. $userMedia is just an example name. You can call that whatever you want. in the PHP example it is called $feed. $feed is an array of the media for that instagram user. You need to loop through that array in a foreach to access the contained media items and extract their properties for display.
-
To retrieve tagged media with $media = $modules->get('InstagramFeed)->getRecentMediaByTag('mytag') I had to add scope=public_content to the url for getting the code in the getCode() method: $request = array( 'client_id' => $this->clientId, 'redirect_uri' => $redirect, 'response_type' => 'code', 'scope' => 'public_content' ); After that I had to click the 'get Access Token' link again and renew the permissions for the app. Otherwise I always received an empty result. In the Instagram API docs they state that the public_content scope is required. With the module as is now, it only gets the basic permissions in the getCode() method by omitting the scope parameter. (more about scopes in the API docs) Can anyone confirm that they have successfully received results for the getRecentMediaByTag() call without adding scope=public_content to the 'get Access Token' link url?
-
I think, PW is not just using strtotime() to convert the relative date to a timestring. You can take a look at wire/core/WireDateTime.php, to see how strings are converted to timestamps. It is also worth looking into the $datetime class and see how you could utilize that. But, this doesn't really answer your question why it is that you are getting different results. I would also expect to get the same results. Only thing I can think of is time zone conflict. Maybe your strtotime() operation is using a different time zone than the internal PW calculations? But this is just a wild guess. To see if this is the case, you could try and use date_default_timezone_set() before using strtotime() and getting the pages.
-
My app is kind of a social wall that is running for days/weeks on end and I would like to automate the retrieval of a new access token. Problem: we never know when Instagram might decide to revoke the access token. Once the old one has been revoked, the Instagram API will return error_type=OAuthAccessTokenError. Whenever the response contains this, I would like to generate a new one automatically and save it to the module settings. Looking at the getCode() method, it requires superuser priviliges to get the access token because the redirect URL for getting the code from Instagram lies within the PW admin. So I tink I need to provide a publicly accessible redirect URL to handle the process of aquiring the new access token. Am I heading in the right direction here? (Sorry if this may sound like a silly question. But it is the first time for me working with the Instagram API). EDIT: Sorry, I should have read through the module code more carefully. I think, all it takes to automate retrieval of new access token is modifications to 1. sendRequest method to handle authorization failure and get the new accesstoken 2. getCode method to allow handing back the URL for code retrieval when not logged in as superuser 3. have a module setting to cater for automatic update of access token I will give it a shot and report back here how it goes. 2nd EDIT: After doing quite some digging and reading carefully through the Instagram API docs and usage policy, I found that the API is not supposed to be used for automated aquisition of access tokens the way I was originally planning it and the way I can do it eg with Twitter API. Instagram is pretty restrictive and they clearly state in their Platform Policy Various sources state that their access token has been working for quite a long time (up to 3 years). So I don't worry too much about the access token being revoked during the time my social wall will be up. Anyways, I will cater for the rare case that the access token is invalid at some point in time. I will extend this great module so that the superuser gets notified by email when authentication problems occur during requests to the API. Then they can do a manual refresh of the access token through the link in the module admin interface.
-
Output pure JSON for ajax calls in process module
gebeer replied to gebeer's topic in Module/Plugin Development
Thanks, Martijn, for looking into this. It was a really stupid mistake on my side that caused the problem. Code in #2 is working fine. -
Output pure JSON for ajax calls in process module
gebeer replied to gebeer's topic in Module/Plugin Development
The code in #2 works fine on a 3.0.12 install. But the same code in a 2.7.2 install returns not only json_encode($out) but the whole page markup. So I am back at where I was when I originally posted this. How can I get back only what I return from my function in #2 without all the markup of the admin theme? Forget about it - Its getting late here. All working fine. -
Hello, I installed this module on a 3.0.12 devns site despite the fact that it is officially not compatible (yet?). And it broke my backend theme which is a custom admin theme based on the default theme with only very slight changes to the theme header and the content width. I needed to manually delete my custom admin theme from the modules table in the DB to get a working backend again. Finally, I downgraded the site to 2.7.2 so I can use the twitter markup module. Site is still under development and I don't really need all the new features from devns branch. Has anyone else experienced problems with this module on 3.0.x?
-
@SiNNuT thanks for the input. I just ran into this while testing and set the limit value to 100, 200 and 300 just to see what happens. I will definitely limit the pages for the life site.
-
I just tested and it is doing exactly what you imagined and I need. Thanks again! EDIT: forgot to mention that it also is much faster
-
Thank you for the suggestion. With something like $oldPosts = wire('pages')->find('template=post, shown=1, limit=16, sort=random') would PW get the first 16 pages it finds and then sort them randomly or would it go through all post pages and get 16 randomly selected pages? I'd need the latter.
-
Hello, Getting random pages with $oldPosts = wire('pages')->find('template=post, shown=1, limit=100')->findRandom(16); works fairly good. About 500ms But without the limit=100 it takes more than 6 seconds. There are only 60 pages with template post but it will be thousands when the app is live. Is there a more efficient way of getting random pages?
-
Output pure JSON for ajax calls in process module
gebeer replied to gebeer's topic in Module/Plugin Development
It turns out that there is no need for special setup except for setting the right header type. My execute function looks like this and returns pure JSON: public function ___executeAjaxControl() { // handle banword saving if($this->input->get->banword) { $banword = wire('sanitizer')->text($this->input->get->banword); if(wire('pages')->get("template=banword,title={$banword}")->id) { $out = "Stoppwort existiert schon"; } else { $b = new Page(); $b->template = 'banword'; $b->parent = wire('pages')->get('template=banwords'); $b->title = $banword; $b->name = wire('sanitizer')->pageName($banword); try { $b->save(); } catch (Exception $e) { $out = "Es trat ein Fehler auf:{$e->getMessage()}.Bitte erneut speichern."; } if($b->id) $out = "Stoppwort {$b->title} wurde gespeichert"; } } header('Content-Type: application/json'); return json_encode($out); } @admin: I can't mark this as solved -
Output pure JSON for ajax calls in process module
gebeer posted a topic in Module/Plugin Development
Hello all, I'm pretty new to Process module development and couldn't find much related to my scenario. In my custom process module I have an execute function that returns data for AJAX requests. I would like to output pure JSON. Thus I need to alter the header to be 'Content-Type: application/json' and also not render all the admin theme output. How would I achieve that from within a process module? Or do I need to take care of that on the admin theme level? I have a custom admin theme running. Thank you. -
Where did you read that? The limit selector is specifically designed for $page->find calls so I would not know why it shouldn't work. Your best bet is to give it a try and see what happens $items = $pages->find("template=item, sort=-created, limit=x"); ...
-
Not sure if you can achieve this all with one $pages->find operation. You'd have to loop through the items and separate them into 2 page arrays (viewed yes and viewed no). $items = $pages->find("template=item, sort=-created"); $notViewed = new PageArray(); foreach($items as $item) { if ($item->children("viewed_by!={$user}")->count()) { $notViewed->add($item); $items->remove($item); } } The $notViewed PageArray should hold all items where at least one note has not been viewed yet. $items should only contain the items where notes have been viewed by the user since we removed the other ones inside the loop. Now you can loop through $notViewed and $items to display them.
-
My pleasure. If you set a page field to multiple pages and you only have one value you could get that with <?=$program->computer->first()->title?>
-
In the field settings for your computer page field, is this field set to hold multiple pages or a single page?
-
Thank you all for your help on this one. @szabesz I would rather not like to install Trasy Debugger if there was a simpler method through the API @LostKobrakai the suggested code returned null. But this version (with parentheses appended to the getQuery method) works: wire('pages')->getPageFinder()->find(new Selectors($selector), array('returnQuery' => true))->getQuery(); It returned exactly the query I was looking for SQL_CALC_FOUND_ROWS pages.id,pages.parent_id,pages.templates_id FROM `pages` JOIN field_id_gc AS field_id_gc ON field_id_gc.pages_id=pages.id AND (((field_id_gc.data='16800' ) )) JOIN field_timestamp AS field_timestamp ON field_timestamp.pages_id=pages.id AND (((field_timestamp.data>='2016-01-28 15:00:42' ) )) JOIN field_timestamp AS field_timestamp1 ON field_timestamp1.pages_id=pages.id AND (((field_timestamp1.data<='2016-02-16 00:19:53' ) )) LEFT JOIN field_timestamp AS _sort_timestamp ON _sort_timestamp.pages_id=pages.id WHERE (pages.templates_id=44) AND (pages.status<1024) GROUP BY pages.id ORDER BY _sort_timestamp.data LIMIT 0,100 @kongondo $queries = $database->getQueryLog(); returns an array of queries with a lot more info than LostKobrakai's code and the specific query is not included. The querie here look somewhat like the output of Debog Mode Tools in backend.
-
Hi, you can find some basic search logic in the search.php of the default site profile: https://github.com/ryancramerdesign/ProcessWire/blob/master/site-default/templates/search.php In https://github.com/ryancramerdesign/ProcessWire/blob/master/site-default/templates/_main.php#L61 you find the code for the search form. This should get you started. EDIT: If you should later decide to use AJAX, there is Soma's module: https://github.com/somatonic/AjaxSearch
-
Another way could be: When automatically creating the userpage in your hook, you can set wire('page')->created_users_id = wire('user')->id Now the page is owned by that user. When the user logs in to lets say .../userpages, in the template.php for userpages you can get the user's page with $pages->get("template=userpagetemplate, created_users_id={$user->id}") To be able to change the user of a page, you need to enable this in the template settings for the userpage-template in the Advanced tab towards the bottom.
-
If 'user' is the name of your page field that holds the users, try <?=$device->user->name?> or <?=$device->user->title?> // if you have a title field in the user template This works only if the user page field is set to hold only one page.
-
Hello, How would I get the DB query that is used to gather the data for something like wire('pages')->find("template=log, id_gc={$serverId}, timestamp>={$dateStart}, timestamp<={$dateEnd}, sort=timestamp"); Tried using the Debug Mode Tools in the backend on a lister with similar selector. But I couldn't make out the right query in there. I'd like to use that query directly to dump data from the DB to a csv via SELECT INTO. Processing 10.000s of pages in chunks of 100 via the API into a csv. This is quite time consuming (several minutes for ~20.000 pages that result in a ~13MB csv file). Any help would be much appreciated.
-
Thank you nik, for that code. I am using it and it works quite well. Only thing that needs to be changed is the while from while (count($results) > $limit); to while (count($results) = $limit); Otherwise it loops 1 more time than it should.