Requesting Picture for Event - events

I've been trying to grab event pictures for a few days now, with no luck. I'm making a normal request just like all the other event elements:
https://graph.facebook.com/eventid/picture
Here's a non-functioning example (in explorer):
https://developers.facebook.com/tools/explorer/?method=GET&path=107798885938238%2Fpicture
However parent, attending, declined, all work..
Thank you!

I've had the same problem as you have.
After some looking into it, I found the solution.
Use http://graph.facebook.com/eventid/?fields=picture&type=large
You can choose small, normal, large or square as type.
You can call this as a separate api call,
$event = $facebook->api('/'.$event['id']);
$picture = $facebook->api('/'.$event['id'].'?fields=picture&type=large');
$picture = $picture['picture'];
echo '<img src="'.$picture.'">';
echo $event['name'];
echo $event['end_time']; // will work, no need to call
or call for other fields at the same time. But then you'll have to define every field you want to call.
$event = $facebook->api('/'.$event['id'].'?fields=name,start_time,picture&type=large');
echo '<img src="'.$event['picture'].'">';
echo $event['name'];
echo $event['end_time']; // will not work, end_time hasn't been called

Related

Subtract 2 random numbers, unable to compare

I'm new to coding so it's probably a stupid mistake but I just can't figur out what is going wrong. I made an email form with a function to check if it's a human sending the message.
They have to answer a simple math question generated with random numbers.
But when I try to check if the input is correct, something goes wrong.
The relevant parts of the code I'm using:
First I generate two random numbers, calculate the correct outcome and turn the answer into a variable:
$number = array( mt_rand(1,5), mt_rand(6,10) );
$outcome = $number[1] - $number[0];
$human = $_POST['message_human'];
The part where to put the answer:
<label for="message_human">
<input type="text" style="width: 44px;" placeholder="…" name="message_human"> + <?php echo $number[0];?> = <?php echo $number[1];?>
</label>
The part to check if the answer is correct, and perform action:
if(!$human == 0){
if($human != $outcome) my_contact_form_generate_response("error", $not_human); //not human!
else { //validate presence of name and message
if(empty($message)){
my_contact_form_generate_response("error", $missing_content);
} else { //ready to go!
$message = "http://url.com" . $url . "\n\n" . $message;
$sent = wp_mail($to, $subject, strip_tags($message), $headers);
if($sent) my_contact_form_generate_response("success", $message_sent);
else my_contact_form_generate_response("error", $message_unsent);
}
}
} else if ($_POST['submitted']) my_contact_form_generate_response("error", $missing_content);
I keep getting the "not human error".
I tried making $outcome an array and all kind of operators but nothing works.
When I give the $outcome a fixed value like = "2"; everything works fine, but I want it to be a random number. Some help would be much appreciated.
If I understand your code right, you are not saving those random numbers, right?
So how could you get the correct comperison, when you send the answer to a previous generated set of random numbers when you just generate new ones?
A possible solution may be to save those values in a session variable.
session_start();
$_SESSION['outcome'] = $outcome;
and compare it later with this variable, but make sure it is not overwritten by a new generated set of random numbers.
if($_POST['message_human'] == $_SESSION['outcome']){
//correct
}

Filling web form via PowerShell does not recognize the values entered

Working as a QA I need to fill in a lot of applications through a web form.
Idea is to have the personal data in some xls/txt/whatever file, read the file and use Powershell to feed data to the browser.
When I use the code below to fill in the form in IE, even though it seems to work fine, I get an error when submitting the form that no data was entered.
Any ideas or suggestions how to get past this would be much appreciated
Sadly my resources are limited to Powershell 2.0. Selenium or any other "more sophisticated" tools are out of question at least for now.
validation error here
$ie = New-Object -com InternetExplorer.Application
$ie.Navigate("MyURL")
$ie.visible = $true
while ($ie.ReadyState -ne 4){sleep -m 100}
Function ClickById($id) {
$ie.document.getElementById($id).Click()
}
### Základní údaje
$FnId = 'personalData.firstName'
$LnId = 'personalData.lastName'
$PhoneId = 'personalData.mobilePhone'
$EmailId = 'personalData.email'
$DataAgreementCheckBox = 'application.personalDataAgreement'
$SubmitfwdId = 'forward'
$Values = "Ublala", "Pung", "222333444", "ublala#pung.com"
$Ds1Elements = $FnId, $LnId, $PhoneId, $EmailId
$j = 0
foreach ($El in $Ds1Elements) {
$ie.document.getElementById($El).value = $values[$j]
$j++
}
ClickById $DataAgreementCheckBox
ClickById $SubmitfwdId
Thanks for the suggestion but it did not work as the form seemes to be stupid in many ways.
Anyway I used your advice for the focus when going with SendKeys method and it did the trick.
At the beginning I needed to load this assembly
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
and then changed the loop accordingly to use the SendKeys method
$j = 0
foreach ($El in $Ds1Elements) {
$ie.document.getElementById($El).focus()
[System.Windows.Forms.SendKeys]::Sendwait($values[$j]);
$j++
}
And tradaaaa the form is filled and nobody is complaining :)
Sometimes website forms will wait until the input box has lost focus to pre-validate the value before submitting the form. The text boxes may never get focus if you are manually setting the values in the background so the form believes that you haven't actually entered any values.
You may be able to get around this by manually focusing each text box in turn, and then focusing the submit button before clicking it. Each element in the $ie.Document should have a focus() method you can use.

WordPress Pagination not working with AJAX

I'm loading some posts though AJAX and my WordPress pagination is using the following function to calculate paging:
get_pagenum_link($paged - 1)
The issue is that the pagination is getting created through AJAX so it's making this link look like: http://localhost:1234/vendor_new/wp-admin/admin-ajax.php
However the actual URL that I'm trying to achieve is for this:
http://localhost:1234/vendor_new/display-vendor-results
Is there a way to use this function with AJAX and still get the correct URL for paging?
I can think of three options for you:
To write your own version of get_pagenum_link() that would allow you to specify the base URL
To overwrite the $_SERVER['REQUEST_URI'] variable while you call get_pagenum_link()
To call the paginate_links() function, return the whole pagination's HTML and then process that with JS to only take the prev/next links.
#1 Custom version of get_pagenum_link()
Pros: you would have to change a small amount of your current code - basically just change the name of the function you're calling and pass an extra argument.
Cons: if the function changes in the future(unlikely, but possible), you'd have to adjust your function as well.
I will only post the relevant code of the custom function - you can assume everything else can be left the way it's in the core version.
function my_get_pagenum_link( $pagenum = 1, $escape = true, $base = null ) {
global $wp_rewrite;
$pagenum = (int) $pagenum;
$request = $base ? remove_query_arg( 'paged', $base ) : remove_query_arg( 'paged' );
So in this case, we have one more argument that allows us to specify a base URL - it would be up to you to either hard-code the URL(not a good idea), or dynamically generate it. Here's how your code that handles the AJAX request would change:
my_get_pagenum_link( $paged - 1, true, 'http://localhost:1234/vendor_new/display-vendor-results' );
And that's about it for this solution.
#2 overwrite the $_SERVER['REQUEST_URI'] variable
Pros: Rather easy to implement, should be future-proof.
Cons: Might have side effects(in theory it shouldn't, but you never know); you might have to edit your JS code.
You can overwrite it with a value that you get on the back-end, or with a value that you pass with your AJAX request(so in your AJAX request, you can have a parameter for instance base that would be something like window.location.pathname + window.location.search). Difference is that in the second case, your JS would work from any page(if in the future you end-up having multiple locations use the same AJAX handler).
I will post the code that overwrites the variable and then restores it.
// Static base - making it dynamic is highly recommended
$base = '/vendor_new/display-vendor-results';
$orig_req_uri = $_SERVER['REQUEST_URI'];
// Overwrite the REQUEST_URI variable
$_SERVER['REQUEST_URI'] = $base;
// Get the pagination link
get_pagenum_link( $paged - 1 );
// Restore the original REQUEST_URI - in case anything else would resort on it
$_SERVER['REQUEST_URI'] = $orig_req_uri;
What happens here is that we simply override the REQUEST_URI variable with our own - this way we fool the add_query_arg function into thinking, that we're on the /vendor_new/display-vendor-results page and not on /wp-admin/admin-ajax.php
#3 Use paginate_links() and manipulate the HTML with JS
Pros: Can't really think of any at the moment.
Cons: You would have to adjust both your PHP and your JavaScript code.
Here is the idea: you use paginate_links() with it's arguments to create all of the pagination links(well - at least four of them - prev/next and first/last). Then you pass all of that HTML as an argument in your response(if you're using JSON - or as part of the response if you're just returning the HTML).
PHP code:
global $wp_rewrite, $wp_query;
// Again - hard coded, you should make it dynamic though
$base = trailingslashit( 'http://localhost:1234/vendor_new/display-vendor-results' ) . "{$wp_rewrite->pagination_base}/%#%/";
$html = '<div class="mypagination">' . paginate_links( array(
'base' => $base,
'format' => '?paged=%#%',
'current' => max( 1, $paged ),
'total' => $wp_query->max_num_pages,
'mid_size' => 0,
'end_size' => 1,
) ) . '</div>';
JS code(it's supposed to be inside of your AJAX success callback):
// the html variable is supposed to hold the AJAX response
// either just the pagination or the whole response
jQuery( html ).find('.mypagination > *:not(.page-numbers.next,.page-numbers.prev)').remove();
What happens here is that we find all elements that are inside the <div class="mypagination">, except the prev/next links and we remove them.
To wrap it up:
The easiest solution is probably #2, but if someone for some reason needs to know that the current page is admin-ajax.php while you are generating the links, then you might have an issue. The chances are that no one would even notice, since it would be your code that is running and any functions that could be attached to filters should also think that they are on the page you need(otherwise they might mess something up).
PS: If it was up to me, I was going to always use the paginate_links() function and display the page numbers on the front-end. I would then use the same function to generate the updated HTML in the AJAX handler.
This is actually hard to answer without specific details of what and how is being called. I bet you want to implement that in some kind of endless-sroll website, right?
Your best bet is to get via AJAX the paginated page itself, and grab the related markup.
Assume you have a post http://www.yourdomain.com/post-1/
I guess you want to grab the pagination of the next page, therefore you need something like this:
$( "#pagination" ).load( "http://www.yourdomain.com/post-1/page/2 #pagination" );
This can easily work with get_next_posts_link() instead of get_pagenum_link().
Now, in order for your AJAX call to be dynamic, you could something like:
$( "#pagination" ).load( $("#pagination a").attr('href') + " #pagination" );
This will grab the next page's link from your current page, and load its pagination markup in place of the old.
It's also doable with get_pagenum_link() however you'd need to change the $("#pagination a").attr('href') selector appropriately, in order to get the next page (since you'd have more than one a elements inside #pagination

Passing parameters through URL in CodeIgniter

I'm having a problem regarding passing parameter from url. The function I use sometimes give the correct result and sometimes not.
here is my controller functions:
public function link_gen(){
$text = "i have lost my password please help me";
$encrypted_text = $this->encrypt->encode($text);
$encrypted_url = urlencode($encrypted_text);
echo $encrypted_url. br();
echo br(). $this->retrive(urldecode($encrypted_url));
echo anchor('encryption/ret_back?username='.$encrypted_url, 'click me');
// echo anchor('encryption/ret_back/'.$encrypted_url, 'click me');
}
public function ret_back(){
// echo br(). $this->retrive(urldecode($str));
$user = $this->input->get('username');
echo br(). $this->retrive(urldecode($user));
echo $user. br();
echo "hellooooo". br();
}
For the sake of testing I'm encrypting a text then encode it in URL using urlencode(), then I pass this string to another function using URL, and then decode in the string in URL using urldecode() and then decode the text. But when I run this, sometimes the decoded text appears and sometimes it does not.
Can anybody tell me the reason and solution for this?
I want to use this in a 'forgot password' module.
It depends on how you create your links and how do you retrieve the data from url.
Anyway these are simple examples to get url data:
get from $_GET[] (http://site.com/?q=hello+world)
in this case you get the param q with echo $this->input->get('q',true);
get data from uri segments (http://site.com/id/230)
in this case you get id value via echo $this->uri->segment(2);
Then, if data in url exists it is not possible that the system didn't get that, so be sure data is in your url when opening url.

My FormIt hook gets cached and it's screwing up every run after the 1st

I have the following snippet code hooked up to a FormIt email form:
$tv = "taken" . (int)$hook->getValue('datetime');
$docID = $modx->resource->get('id'); //get the page id
$page = $modx->getObject('modResource', $docID);
$current = (int)$page->getTVValue($tv);
if (!$page->setTVValue($tv, $current + 1)) {
$modx->log(xPDO::LOG_LEVEL_ERROR, 'There was a problem saving your TV...');
}
$modx->setPlaceholder('successMessage','<h2 class="success">'.$current.'</h2>');
return true;`
It increments a template variable every time it is run and outputs a success message (although right now I'm using that functionality to output a debug message instead). The problem is, it only increments the TV once after saving the snippet, thereby refreshing the cache. Normally I would call the snippet without cache by appending ! to its name, but that doesn't appear to work for FormIt hooks. How can I get this code to work? Right now I'm running the entire page as uncacheable, but that is obviously suboptimal. Perhaps, there's a way to hook a snippet in an uncached manner? Call a snippet from within a snippet as uncached?
I'm doing something similar - but to count page loads, it looks to me like you are missing the last little bit: $current->save();
<?php
$docID = $modx->resource->get('id');
$tvIdm = 32;
$tvm = $modx->getObject('modTemplateVar',$tvIdm );
$tvm->setValue($docID, $tvm->getValue($docID) + 1 );
$tvm->save();
Try add this before you save $tv object
$tv->_processed = false;
It's derived from modElement's property it extends.

Resources