Pagination not getting previous cursor google app engine in php - php

Hi have implement pagination in google app engine
with this code
https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/datastore/api/src/functions/concepts.php
function cursor_paging(DatastoreClient $datastore, $pageSize, $pageCursor = '')
{
$query = $datastore->query()
->kind('Task')
->limit($pageSize)
->start($pageCursor);
$result = $datastore->runQuery($query);
$nextPageCursor = '';
$entities = [];
/* #var Entity $entity */
foreach ($result as $entity) {
$nextPageCursor = $entity->cursor();
$entities[] = $entity;
}
return array(
'nextPageCursor' => $nextPageCursor,
'entities' => $entities
);
}
geting the next Cursor but did not get the previous cursor form this

Indeed, dealing with the previous cursor is something of a problem - even in other languages, it seems to be the bigger issue, when paginating data. There isn't much data or articles in the internet as well, on how to achieve that.
I will try to explain as much as I can, the possibilities, I believe, are available to you.
As per this other question from the Community here, you can create a new cursor with the information previous page, so you can use it for your pagination. This means that you would have three cursors now: $pageCursor, $nextPageCursor and $previousPageCursor. Using like this, you should be able to maintain the actual data, before setting the one for the next page.
Besides that, there is a reverse method in PHP that might help you, in case you want to count how many pages there will be on your application and put it backwards in the previous cursor. This way, you will have the inverted order, to use in your pagination as well - I still believe that giving a try in the first option, would be the best.
I have found some other useful questions from the Community, that might help you achieve your goal - that I believe are worth taking a look at it as well.
How do appengine cursors work?
App Engine datastore paging - previous page
Let me know if the information helped you!

Related

Clickatell parseReplyCallback returning null?

I am trying to get a reply text message from Clickatell using their Rest API, when I call the parseReplyCallback function when their system posts to my page - it seems to be null or I am not sure how to get the variables it is returning. What I would like to do is have all of the variables returned insert into a SQL database so I can use it elsewhere.
I have tried quite a few things, using various styles of getting the variables such as $_POST, $results['text'], $results->text, and so forth each time I can't seem to get any information out of it. I can't just var_dump or anything because I can't see any backend or console so I am pretty much in the blind, hoping someone else is using this system and has it working fine.
require __DIR__.'/clickatell/src/Rest.php';
use clickatell\ClickatellException;
use clickatell\Rest;
$Rest = new Rest("j8VKw3sJTZuVfQGVC7jdhA");
// Incoming traffic callbacks (MO/Two Way callbacks)
$Rest->parseReplyCallback(function ($result) {
//mysqli_query($con,"INSERT INTO `SMSCHAT` (`text`) VALUES ('$result')");
$mesageId = mysqli_real_escape_string($con,$result['messageId']);
$text = mysqli_real_escape_string($con,$result['text']);
$replyMessageId = mysqli_real_escape_string($con,$result['replyMessageId']);
$to = mysqli_real_escape_string($con,$result['toNumber']);
$from = mysqli_real_escape_string($con,$result['fromNumber']);
$charset = mysqli_real_escape_string($con,$result['charset']);
$udh = mysqli_real_escape_string($con,$result['udh']);
$network = mysqli_real_escape_string($con,$result['network']);
$keyword = mysqli_real_escape_string($con,$result['keyword']);
$timestamp = mysqli_real_escape_string($con,$result['timestamp']);
//do mysqli_query
});
I'd like for it to break the result into individual variables (because I plan on doing other things such as an auto-reply, etc) and upload it to the SQL database scrubbed.
Either doesn't create the table entry or gives me a blank one altogether in that first test where I put the result in the text field.
From a Clickatell point of view, although we understand what you're asking - it's unfortunately outside the scope of support that we offer on our products.
If you would like more information on our REST API functionality, please feel free to find it here: https://www.clickatell.com/developers/api-documentation/rest-api-reply-callback/
If you don't succeed in setting up the callbacks, please feel free to log a support ticket here: https://www.clickatell.com/contact/contact-support/ and one of our team members will reach out and try to assist where possible.

Fortnite API html

I want to put my fortnite stats on my website HTML/CSS. I find this.
But I don't know php very good, so I need your help. Must I delete this: 'your_api_key' and put : your_api_key without the ' ' ?
And lines like this:
$this->auth = new Fortnite_Auth($this);
$this->challenges = new Fortnite_Challenges($this);
$this->leaderboard = new Fortnite_Leaderboard($this);
$this->items = new Fortnite_Items($this);
$this->news = new Fortnite_News($this);
$this->patchnotes = new Fortnite_PatchNotes($this);
$this->pve = new Fortnite_PVE($this);
$this->status = new Fortnite_Status($this);
$this->weapons = new Fortnite_Weapons($this);
$this->user = new Fortnite_User($this)
Must I modify something?
(here are some informations:
-user_id: 501b9f2dfda34249a2749467513172bf
-username: NoMaD_DEEPonion
-platform: pc
-windows: season 5
)
For all this code, I used xammp server (I hope it's good)
Thank you for your help
You should always quote '' your key/strings. So it would look like:
$api->setKey('123qwerty456');
$api->user->id('NoMaD_DEEPonion');
Please read their documentation. You're supposed to get an API key from them to get started. And you don't have to edit Client.php. You're supposed to include the files instead. Try including Autoloader.php, since it requires the necessary files.
XAMPP is alright for development, but not suitable for production/public. Good luck!
What #sykez wrote.
I personally use https://fortniteapi.com/ to get the data. They also have a sweet POSTMAN page with different requests https://documenter.getpostman.com/view/4499368/RWEjoGqD
At last. I am not really sure that this will be a good project to start learning PHP from. I really suggest that you get to understand the basics of PHP first before you jump into API calls, processing arrays and more.

Using Cusor for next and previous nevigation in Apache Solr

I have been trying to use Cursors(document) to make a "Next" and "Previous" pagination. I find it strange that there is no such thing as prevCursorMark as opposed to nextCursorMark in the returned data. It makes implementing next and prev pagination quite difficult.
I came up with the idea of storing the previous nextCursorMark request as the previous page pointer. However I felt that it wouldn't be as reliable as simply having a prevCursorMark.
Example Code with PHP Solr Extension
$query_response = $client->query($solrQuery);
$data = $query_response->getResponse();
$nextCursorMark = $data['nextCursorMark'];
$prevCursorMark = isset($_GET['nextResult'])?
htmlspecialchars($_GET['nextResult']):'*';
$pager = "<a href='index?1=1&nextResult=$prevCursorMark' class='page5 no_ajax'>Prev</a>
<a href='index?1=1&nextResult=$nextCursorMark' class='page5 no_ajax'>Next</a>";
So here's my question: Does Cursors in Solr provide a prevCursor Mark? Is it possible to make a next and previous pagination with Cursors?
As of the solr 5.2, it does not provide any previous cursor mark. If you want to provide the pagination in your application with next and previous links. You can reliably store and use nextCursorMark values returned by the solr. You can re-submit nextCursorMark values, changing other things like what stored fields are returned or what fields are faceted. The cursorMark parameter itself contains all the necessary state. There is no server-side state.

PHPFlickr script...could this be cleaner/leaner?

OK, here's my dilemma:
I've read all over about how many guys want to be able to display a set of images from Flickr using PHPFlickr, but lament on how the API for PhotoSets does not put individual photo descriptions. Some have tried to set up their PHP so it will pull the description on each photo as the script assembles the gallery on the page. However, the method has shown how slow and inefficient it can be.
I caught an idea elsewhere of creating a string of comma separated values with the photo ID and the description. I'd store it on the MySQL database and then call upon it when I have my script assemble the gallery on the page. I'd use explode to create an array of the photo ID and its description, then call on that to fill in the gaps...thus less API calls and a faster page.
So in the back-end admin, I have a form where I set up the information for the gallery, and I hand a Set ID. The script would then go through and make this string of separated values ("|~|" as a separation). Here's what I came up with:
include("phpFlickr.php");
$f = new phpFlickr("< api >");
$descArray = "";
// This will create an Array of Photo ID from the Set ID.
// $setFeed is the set ID brought in from the form.
$photos = $f->photosets_getPhotos($setFeed);
foreach ($photos['photoset']['photo'] as $photo) {
$returnDesc = array();
$photoID = $photo['id'];
$rsp = $f->photos_getInfo($photoID);
foreach ($rsp as $pic) {
$returnDesc[] = htmlspecialchars($pic['description'], ENT_QUOTES);
}
$descArray .= $photoID."|~|".$returnDesc[0]."|~|";
}
The string $descArray would then be placed in the MySQL string that puts it into the database with other information brought in from the form.
My first question is was I correct in using a second foreach loop to get those descriptions? I tried following other examples all over the net that didn't use that, but they never worked. When I brought on the second foreach, then it worked. Should I have done something else?
I noticed the data returned would be two entries. One being the description, and the other just an "o"...hence the array $returnDesc so I could just get the one string I wanted and not the other.
Second question is if I made this too complicated or not. I like to try to learn to write cleaner/leaner code, and was looking for opinions.
Suggestions on improvement are welcome. Thank you in advance.
I'm not 100% sure as I've just browsed the source for phpFlickr, and looked the the Flickr API for the getInfo() call. But let me have a go anyway :)
First off, it looks like you shouldn't need that loop, like you mention. What does the output of print_r($rsp); look like? It could be that $rsp is an array with 1 element, in which case you could ditch the inner loop and replace it with something like $pic = $rsp[0]; $desc = $pic['description'];
Also, I'd create a new "description" column in your database table (that has the photo id as the primary key), and store the description in their on its own. Parsing db fields like that is a bit of a nightmare. Lastly, you might want to force htmlspecialchars to work in UTF8 mode, cause I don't think it does by default. From memory, the third parameter is the content encoding.
edit: doesn't phpFlickr have its own caching system? Why not use that and make the cache size massive? Seems like you might be re-inventing the wheel here... maybe all you need to do is increase the cache size, and make a getDescription function:
function getDescription ($id)
{
$rsp = $phpFlickr->photos_getInfo ($id);
$pic = $rsp[0];
return $pic['description'];
}

Using LDAP functions to get Active Directory tokenGroups attribute in PHP

Greetings,
I already have a working connection to the AD and can search and retrieve information from it. I've even developed a recursive method by which one can retrieve all groups for a given user. However, I'd like to avoid the recursion if possible. One way to do this is to get the tokenGroups attribute from the AD for the user, which should be a list of the SIDs for the groups that the specified user has membership, whether that membership be direct or indirect.
When I run a search for a user's AD information, though, the tokenGroups attribute isn't even in it. I tried specifically requesting that information (i.e., specifying it using the fourth parameter to ldap_search) but that didn't work, either.
Thanks,
David Kees
Solved my own problem and thought I'd put the answer here so that others might find it. The issue was using the ldap_search() function. The answer was to use the ldap_read() function instead of ldap_search(). The difference is the scope of the request. The search function uses a scope of "sub" (i.e., subtree) while the read function uses "base." The tokenGroups information can only be found when using a scope of "base" so using the correct PHP function was the key.
As I mentioned above, I was working from someone else code in perl to create my solution and the perl script used a function named "search" to do it's LDAP requests which lead me down wrong path.
Thanks to those who took a peek at the question!
--
As per the requests in the comments, here's the basics of the solution in code. I'm extracting from an object that I use so this might not be 100% but it'll be close. Also, variables not declared in this snipped (e.g. $server, $user, $password) are for you to figure out; I won't know your AD credentials anyway!
$ldap = ldap_connect($server);
ldap_bind($ldap, $user, $password);
$tokengroups = ldap_read($ldap, $dn, "CN=*", array("tokengroups")));
$tokengroups = ldap_get_entries($ldap, $tokengroups);
At this point, $tokengroups is our results as an array. it should have count index as well as some other information. To extract the actual groups, you'll need to do something like this:
$groups = array();
if($tokengroups["count"] > 0) {
$groups = $tokengroups[0]["tokengroups"];
unset($groups["count"]);
// if you want the SID's for your groups, you can stop here.
// if you want to decode the SID's then you can do something like this.
// the sid_decode() here: http://www.php.net/manual/en/function.unpack.php#72591
foreach($groups as $i => &$sid) {
$sid = sid_decode($sid);
$sid_dn = ldap_read($ldap, "<SID=$sid>", "CN=*", array("dn"));
if($sid_dn !== false) {
$group = ldap_get_entries($ldap, $sid_dn);
$group = $group["count"] == 1 ? $group[0]["dn"] : NULL;
$groups[$i] = $group;
}
}
}
That's the basics. There's one caveat: you'll probably need to work with the individual or individuals who manage AD accounts at your organization. The first time I tried to get this running (a few years ago, so my memory is somewhat fuzzy) the account that I was given did not have the appropriate authorization to access the token groups information. I'm sure there are other ways to do this, but because I was porting someone else's code for this specific solution, this was how I did it.

Categories