How to pass variable one page to another page in opencart - php

Please give me a ideas i have to created a variable like ($data['image2']) i want pass one page to other page how please help me.Actually,(What ever i added in product(image) for admin panel(opencart) that product image automatically should go to pinterest account i have tried but almost done i doing some miner issue i don't know please help me this.)
Here my code:controller:
if (isset($this->request->post['image'])) {
$data['image2'] = $this->request->post['image'];
//print_r($data['image']);die;
}
// print_r($data['image2']);
//--------Post image-------///
//-------------curl starting---------------//
$url = 'http://localhost/mspink_new/pintest.php';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count(0));
curl_setopt($ch,CURLOPT_POSTFIELDS, 1);
//execute post
$result = curl_exec($ch);
print_r($result);die;
curl_close($ch);
I want pass the value to pinterest.php file how.
<?php
//$get =$_get('image');die;
//$image = $_GET['image'];
//print_r($image);die;
require_once "Pinterest.class.php";
// Create the pinterest object and log in
$p = new Pinterest();
$p->login("loginid", "password");
if( $p->is_logged_in() )
echo "Success, we're logged in\n";
//$image = $p->generate_image_preview("slider-old.jpg");
// if (isset($_POST)) {
// $image ="image";
// }
// print_r($image);die;
// Set up the pin
//$p->pin_url = "http://yellow5.com";
$p->pin_url = "http://www.mspinkpanther.com/";
$p->pin_description = "My awesome pin";
$p->pin_image_preview = $p->generate_image_preview('slider.jpg');
// Get the boards
$p->get_boards();
// Pin to the board called "Items"
if( !isset($p->boards['Items']) ) {
echo "For testing, please create a board called 'Items' and try again!\n";
exit;
}
$p->pin($p->boards['Items']);
// And we're done
echo "Hooray!\n";

Related

Pass PHP variable/value from one page to another

I have been trying to send the xml response I have stored in '$kxml' variable to the 'kycresult.php' page. I want to fetch the values from that xml and just print it. I am able to fetch the values if I store the xml in txt file and then get it using 'simplexml_load_file' but I don't want to create an extra file. Please let me know if there is a way to send the $kxml on next page.
$kycch = curl_init();
curl_setopt($kycch, CURLOPT_URL, $csckua_url);
curl_setopt($kycch, CURLOPT_POSTFIELDS, $kycxml);
curl_setopt($kycch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($kycch, CURLOPT_TIMEOUT, 20);
$kycresult = curl_exec($kycch);
$curl_errno = curl_errno($kycch);
$curl_error = curl_error($kycch);
curl_close($kycch);
// echo $kycresult;
$kxml = simplexml_load_string($kycresult);
if ($kxml['ret'] == 'Y') {
// $ksuccess = 'Authentication Successful';
header('location:Kycresult.php');
} else {
$ksuccess = 'Authentication Failed';
}
As one of the possible solutions you can store the variable in session
session_start();
$_SESSION['kxml'] = $kxml;
Then on the next page it will be available through
$kxml = $_SESSION['kxml'];
But actually it still stores in the auxiliary file by default under the hood.

Get Facebook Profile URL From Facebook Profile id Using PHP

I have a list of Facebook links in xls sheet with Facebook id something like this
and when i go through these links means if i access Facebook with id www.facebook.com/7500
i get urls something like this https://www.facebook.com/davesachs/
so my question is i want to do this with PHP, i have a PHP page which read data from xls sheet
my code here:
require_once 'src/SimpleXLSX.php';
if ( $xlsx = SimpleXLSX::parse('fburl.xlsx') ) {
$rows= $xlsx->rows();
foreach($rows as $data){
echo $data[0].'<br>';
}
} else {
echo SimpleXLSX::parseError();
}
its returning all Facebook link with id same that i am passing like www.facebook.com/7500 but i want it return URL / link of profile as https://www.facebook.com/davesachs/ ,if it is possible please help me to do that.
You can do something like that, Taken reference from here
<?php
require_once 'src/SimpleXLSX.php';
if ( $xlsx = SimpleXLSX::parse('fburl.xlsx') ) {
$rows= $xlsx->rows();
foreach($rows as $data){
getRedirectedUrl($data[0]);
}
} else {
echo SimpleXLSX::parseError();
}
function getRedirectedUrl($link){
$url=$link;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Must be set to true so that PHP follows any "Location:" header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$a = curl_exec($ch); // $a will contain all headers
$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // This is what you need, it will return you the last effective URL
// Uncomment to see all headers
/*
echo "<pre>";
print_r($a);echo"<br>";
echo "</pre>";
*/
echo $url; // Voila
}
?>

Salesforce-to-Wordpress: WP Options Table not populating with json from SF

I am attempting to populate a WordPress site with data from Salesforce. Sort of similar to this question maybe except I'm going in the opposite direction. I am basing my code quite a bit on this example, which worked fine for me when I tried it on it's own but not so much once I tried it with Wordpress.
From the example, I only replaced demo_rest.php with the code below,changed that final line in oauth_callback.php to return to my options page in WordPress, made the proper changed to config.php, and replaced index.html. When I did that I see in Salesforce that I am indeed logging in from my plugin, but nothing is coming back to WordPress from there. It's not displaying in the window I want or updating the the mysql database with the json that should result. What am I doing wrong?
My code.
<?php
/*Assign global variables*/
$plugin_url = WP_PLUGIN_URL . '/my-plugin';
$options = array();
// adds plugin settings page in wordpress admin menu
function salesforce_menu(){
add_options_page( // wordpres helper function to add a settings page
'Salesforce to WordPress Integrator',
'Salesforce Integration',
'manage_options',
'salesforce-integrator',
'salesforce_options_page'
);
}
add_action('admin_menu','salesforce_menu');
function salesforce_options_page(){
if ( !current_user_can('manage_options')){
wp_die ('You do not have sifficient permissions to access this page.');
}
global $plugin_url;
global $options;
if( $access_token != '') {
$response = get_stories($instance_url, $access_token);//This is where I'm probably getting messed up. I'm trying to call the get_stories function (defined later)
$options['response'] = $response;
$options['last_updated'] =time();
update_option ('storybank_approved', $options); //wp helper function to update the options table, hopefully with the results of my call to the API.
}
$options = get_option('storybank_approved');
if ($options !=''){
$response = $options['response'];
}
var_dump ($response); //I want this to show me the json on my settings page just to ensure that I have a response, but it looks like I don't
require('includes/options-page-wrapper.php');
}
//get salesforce records
function get_stories($instance_url, $access_token) {
$query = "SELECT Id, Name from salesforce_Object__c LIMIT 100";
$url = "$instance_url/services/data/v20.0/query?q=" . urlencode($query) ;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Authorization: OAuth $access_token"));
$json_response = curl_exec($curl);
curl_close($curl);
$response =json_decode($json_response,true);
$total_size = $response['totalSize'];
echo "$total_size record(s) returned<br/><br/>";
foreach ((array) $response['records'] as $record) {
echo $record['Id'] . ", " . $record['Name']. "<br/>";
}
echo "<br/>";
}
?>
The getStories function is not returning a value.
$response = get_stories($instance_url, $access_token); // has to return something.
//for example, I deleted the rest of the code for simplicity.
function get_stories($instance_url, $access_token) {
$response =json_decode($json_response,true);
return $response;
}

Change Output of PHP Script to use POST Method

Bear with my inexperience here, but can anyone point me in the right direction for how I can change the PHP script below to output each variable that is parsed from the XML file (title, link, description, etc) as a POST method instead of just to an HTML page?
<?php
$html = "";
$url = "http://api.brightcove.com/services/library?command=search_videos&any=tag:SMGV&output=mrss&media_delivery=http&sort_by=CREATION_DATE:DESC&token= // this is where the API token goes";
$xml = simplexml_load_file($url);
$namespaces = $xml->getNamespaces(true); // get namespaces
for($i = 0; $i < 80; $i++){
$title = $xml->channel->item[$i]->video;
$link = $xml->channel->item[$i]->link;
$title = $xml->channel->item[$i]->title;
$pubDate = $xml->channel->item[$i]->pubDate;
$description = $xml->channel->item[$i]->description;
$titleid = $xml->channel->item[$i]->children($namespaces['bc'])->titleid;
$html .= "<h3>$title</h3>$description<p>$pubDate<p>$link<p>Video ID: $titleid<p>
<iframe width='480' height='270' src='http://link.brightcove.com/services/player/bcpid3742068445001?bckey=AQ~~,AAAABvaL8JE~,ufBHq_I6FnyLyOQ_A4z2-khuauywyA6P&bctid=$titleid&autoStart=false' frameborder='0'></iframe><hr/>";/* this embed code is from the youtube iframe embed code format but is actually using the embedded Ooyala player embedded on the Campus Insiders page. I replaced any specific guid (aka video ID) numbers with the "$guid" variable while keeping the Campus Insider Ooyala publisher ID, "eb3......fad" */
}
echo $html;
?>
#V.Radev Here's another PHP script using cURL that I think will work with the API I'm trying to send data to:
<?PHP
$url = 'http://api.brightcove.com/services/post';
//open connection
$ch = curl_init($url);
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, '$title,$descripton,$url' . stripslashes($_POST['$title,$description,$url']));
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
// Enable for Charles debugging
//curl_setopt($ch,CURLOPT_PROXY, '127.0.0.1:8888');
$result = curl_exec($ch);
curl_close($ch);
print $result;
?>
My question is, how can I pass the variables from my feed parsing script (title, description, URL) to this new script?
I have this code from Brightcove, can I just output the variables from my parser script and send to this PHP script so that the data goes to the API?
<?php
// This code example uses the PHP Media API wrapper
// For the PHP Media API wrapper, visit http://docs.brightcove.com/en/video-cloud/open-source/index.html
// Include the BCMAPI Wrapper
require('bc-mapi.php');
// Instantiate the class, passing it our Brightcove API tokens (read, then write)
$bc = new BCMAPI(
'[[READ_TOKEN]]',
'[[WRITE_TOKEN]]'
);
// Create an array of meta data from our form fields
$metaData = array(
'name' => $_POST['bcVideoName'],
'shortDescription' => $_POST['bcShortDescription']
);
// Move the file out of 'tmp', or rename
rename($_FILES['videoFile']['tmp_name'], '/tmp/' . $_FILES['videoFile']['name']);
$file = '/tmp/' . $_FILES['videoFile']['name'];
// Create a try/catch
try {
// Upload the video and save the video ID
$id = $bc->createMedia('video', $file, $metaData);
echo 'New video id: ';
echo $id;
} catch(Exception $error) {
// Handle our error
echo $error;
die();
}
?>
Post is a request method to access a specific page or resource. With echo you are sending data which means that you are responding. In this page you can only add response headers and access it with a request method such as post, get, put etc.
Edit for API request as mentiond in the comments:
$curl = curl_init('your api url');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $your_data_to_send);
$result_from_api = curl_exec($curl);
curl_close($curl);

How save Facebook user display picture to the disk Without using file_get_contents()`?

Hello I am trying to get the user profile picture and then merge into an existing image as per my Facebook app requirement. For that I need to check its mime time etc. But I am having difficulty in retrieving and saving the picture.
$facebook = new Facebook($config);
$user = $facebook -> getUser();
if ($user) {
$user_profile = $facebook -> api('/me');
}
//User Info. Variables:
try {
$userPpicture = $user_profile[picture];
}
Now we I have retrieved this I want to save this image on disk so I could check its mime time etc. for further processing, how can I achieve this?
p.s. due to my hosting server restrictions I can’t use the function file_get_contents(). So I need a solution except this.
Kindly help.
thank-you.
cURL try:
//Create image instances
$url = "http://graph.facebook.com/{$userId}/picture?type=large";
$dpImage = 'temp/' . $userId . '_dpImage_' . rand().'.jpg';
echo $dpImage;
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$returned_content = get_data($url);
file_put_contents($dpImage, $returned_content);
echo "Type: " . exif_imagetype($dpImage);
getting this error while checking the mime type of the image:
Notice: exif_imagetype(): Read error! in
Are you allowed to use CURL ?
If so, just follow http://phpsense.com/2007/php-curl-functions/

Categories