Link from Wordpress site to Buddypress Profile - buddypress

I try to link from the Wordpress Page Editor to the Buddypress Profile.
I installed 'Insert PHP v1.2' to use php, but i still dont get it. Actually I do the following steps in my Wordpress page:
[kleo_h3]Füge weitere [kleo_colored_text color="#F00056"]Fotos [/kleo_colored_text]zu deinem Profil hinzu.[/kleo_h3]
[rtmedia_uploader]
[insert_php]
&var = bp_loggedin_user_domain();
echo do_shortcode('[kleo_button url=&var style="standard" size="small" round="round" icon="{fontawesome-icon,after" target="_self"] Profil [/kleo_button]');
[/insert_php]
But the programm crahes. How I get that URL into the shortcode?

Got it finally:
[kleo_h3]Füge weitere [kleo_colored_text color="#F00056"]Fotos [/kleo_colored_text]zu deinem Profil hinzu.[/kleo_h3]
[rtmedia_uploader]
[insert_php]
//$var =bp_core_get_userlink( bp_loggedin_user_id());
$id= bp_loggedin_user_id();
$name = bp_core_get_user_displayname($id);
$url = site_url()."/members/$name";
echo do_shortcode('[kleo_button url='.$url.' style="standard" size="small" round="round" icon="{fontawesome-icon,after" target="_self"] Profil [/kleo_button]');
[/insert_php]

Related

Calling Yahoo Weather API from VoiceXML

I'm trying to make a voice weather system with voiceXML and the Yahoo Weather API. To develop my program I'm using voxeo evolution.
To call the Weather API I'm using the data vxml tag with an srcexpr because I need a dynamic URL (the program asks the user for a city to check weather in).
Here is my code:
<?xml version="1.0" encoding="UTF-8"?>
<vxml version = "2.1">
<form id="mainMenu">
<field name="City">
<prompt>
Please, name a spanish city.
</prompt>
<grammar src="city.grammar"/>
</field>
<!-- code taken from the javascript example of the yahoo weather api -->
<script>
<![CDATA[
var callbackFunction = function(data) {
var wind = data.query.results.channel.wind;
alert(wind.chill);
};
]]>
</script>
<data srcexpr="https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places where text='"+City+", spain')&callback=callbackFunction"/>
</form>
</vxml>
The program doesn't work because of the data tag to connect to the weather API, but I don't know why. Do someone know why is failing?
I finally solved my problem making a php script to connect to the yahoo api and calling it using submit tag in VoiceXML.
<?php
$City = $_REQUEST["City"];
$Day = $_REQUEST["Day"];
$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="('.$City.', spain)") and u="c"';
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$yahooapi = curl_exec($session);
$weather = json_decode($yahooapi,true);
$weather_resumen = $weather['query']['results']['channel']['item']['forecast'];
$weather_today = $weather_resumen[0]['day'];
// yahoo api returns an array with the weather for the next week ordered by
// day (0 -> today, 1 -> tomorrow...). Function get_day gets the index of
// the day the user said
$index_weather = get_day($weather_today, $Day);
$condition_index = $weather_resumen[$index_weather]['code'];
$weather_condition = $cond_met[intval($condition_index)];
$min_temp = $weather_resumen[$index_weather]['low'];
$max_temp = $weather_resumen[$index_weather]['high'];
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
?>
<vxml version="2.1" xml:lang="es-ES">
<form id="form_main">
<block>
<prompt>
The weather for <?php echo $Day ?> in <?php echo $City ?> is <?php echo $weather_condition ?>. The lowest temperature will be <?php echo $min_temp ?> and the highest <?php echo $max_temp ?>.
<break/>
</prompt>
</block>
</form>
</vxml>

How to change cart for users in prestashop?

I need to create a link that change's a user's cart with one that is expired.
this is what i tried, but it doesn't work
<?php
if (!defined('_PS_ADMIN_DIR_'))
define('_PS_ADMIN_DIR_', (getcwd().'/../../') );//prima del require_once
require_once(dirname(__FILE__).'/../../config/config.inc.php');
...
$this->context->cookie->id_cart = 6;
$this->context->cart = new Cart(6);
$this->context->cookie->write();
$this->context->cookie->update();
Tools::redirect('index.php?controller=order');
what about : $this->context->cart->id = 6 ?

Video upload with Graph API from user's desktop

i am trying to upload a local video to Facebook through the Graph API.
Here is an example from Facebook:
http://developers.facebook.com/blog/post/493/
That works nice, and i get an JSON response after submitting the from.
How can I get the respone ID, for use in, e.g. Javascript or directly as an GET-parameter on my server?
I don't want to upload the video on an public accessable server and then redirect the video upload to Facebook by using curl or something like that.
Has anyone an idea or an example of how i can get this to work?
Edit:
Here is the example i used:
<?php
$app_id = "YOUR_APP_ID";
$app_secret = "YOUR_APP_SECRET";
$my_url = "YOUR_POST_LOGIN_URL";
$video_title = "YOUR_VIDEO_TITLE";
$video_desc = "YOUR_VIDEO_DESCRIPTION";
$code = $_REQUEST["code"];
if(empty($code)) {
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=publish_stream";
echo("<script>top.location.href='" . $dialog_url . "'</script>");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$access_token = file_get_contents($token_url);
$post_url = "https://graph-video.facebook.com/me/videos?"
. "title=" . $video_title. "&description=" . $video_desc
. "&". $access_token;
echo '<form enctype="multipart/form-data" action=" '.$post_url.' "
method="POST">';
echo 'Please choose a file:';
echo '<input name="file" type="file">';
echo '<input type="submit" value="Upload" />';
echo '</form>';
?>
Taken from this page: http://developers.facebook.com/blog/post/493/
This is the whole response i get from the form (JSON response):
{
"id": "xxxxx19208xxxxx"
}
The problem is that the JSON response is inline in the page.
I thought to set a target in the form to an inline iframe but then i will not be able to access the JSON code.

Youtube api get latest upload thumbnail

I am looking to returning the video-thumbnail of the latest uploaded video from my channel, and display it on my website.
Anyone know how I can do a minimal connection trough api and get only the thumbnail?
Thanks!
-Tom
REVISED!!
Using Cakephp, this is how I did it (thanks dave for suggestions using zend);
controller:
App::import('Xml');
$channel = 'Blanktv';
$url = 'https://gdata.youtube.com/feeds/api/users/'.$channel.'/uploads?v=2&max-results=1&orderby=published';
$parsed_xml =& new XML($url);
$parsed_xml = Set::reverse($parsed_xml);
//debug($parsed_xml);
$this->set('parsed_xml',$parsed_xml);
View;
$i=0;
foreach ($parsed_xml as $entry)
{
echo '<a href="/videokanalen" target="_self">
<img width="220px" src="'.$entry['Entry']['Group']['Thumbnail'][1]['url'] .'">
</a>';
}
Now the only thing remaining is to cache the feed call someway.. Any suggestions???
-Tom
here is a quick dirty way of doing it without really touching the api at all.
I'm not suggesting it's best practice or anything and I'm sure there are smarter ways but it definitely works with the current Youtube feed service.
My solution is PHP using the Zend_Feed_Reader component from Zend Framework, if you need a hand setting this up if you're not familiar with it let me know.
Essentially you can download version 1.11 from Zend.com here and then make sure the framework files are accessible on your PHP include path.
If you are already using Zend Framework in an MVC pattern you can do this in your chosen controller action:
$channel = 'Blanktv'; //change this to your channel name
$url = 'https://gdata.youtube.com/feeds/api/users/'.$channel.'/uploads';
$feed = Zend_Feed_Reader::import($url);
$this->view->feed = $feed;
Then you can do this in your view:
<h1>Latest Video</h1>
<div>
<?php
$i=0;
foreach ($this->feed as $entry)
{
$urlChop = explode ('http://gdata.youtube.com/feeds/api/videos/',$entry->getId());
$videoId = end($urlChop);
echo '<h3>' . $entry->getTitle() . '</h3>';
echo '<p>Uploaded on: '. $entry->getDateCreated() .'</p>';
echo '<a href="http://www.youtube.com/watch?v=' . $videoId .'" target="_blank">
<img src="http://img.youtube.com/vi/' . $videoId .'/hqdefault.jpg">
</a>';
$i++;
if($i==1) break;
}
?>
</div>
otherwise you can do:
<?php
$channel = 'Blanktv'; //change this to your channel
$url = 'https://gdata.youtube.com/feeds/api/users/'.$channel.'/uploads';
$feed = Zend_Feed_Reader::import($url);
?>
<h1>Latest Video</h1>
<div>
<?php
$i=0;
foreach ($feed as $entry)
{
$urlChop = explode ('http://gdata.youtube.com/feeds/api/videos/',$entry->getId());
$videoId = end($urlChop);
echo '<h3>' . $entry->getTitle() . '</h3>';
echo '<p>Uploaded on: '. $entry->getDateCreated() .'</p>';
echo '<a href="http://www.youtube.com/watch?v=' . $videoId .'" target="_blank">
<img src="http://img.youtube.com/vi/' . $videoId .'/hqdefault.jpg">
</a>';
$i++;
if($i==1) break;
}
?>
</div>
With the latter method you'll likely need to use a php require statement for the Zend_Feed_Reader files etc....
Hope this helps, like I say let me know if you need a hand.
All the best,
Dave
UPDATE: In response to your comments about caching
Hi Tom, here is another quick and dirty solution which doesn't use cache but may be very quick to implement.
The reason I didn't go with a caching component is because I figured a simple db solution would suffice under the circumstances. I also thought having to pull the feed to compare whether it was new or not wouldn't be the most economical for you.
You could automate this process to be run automatically at specified times but if you don't want to automate the process and don't mind clicking a link to update the video manually you could trigger it that way.
My solution is again based on ZF but since you were ok hacking it into something useful with cakephp you should have no problem doing the same here.
First set up a new table (assuming a MySQL db):
CREATE TABLE `yourdbname`.`latestvid` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Unique identifier',
`videoId` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Video id',
`videoTitle` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Video title',
`uploadDate` VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 'Video upload date'
) ENGINE = INNODB CHARACTER SET utf8 COLLATE utf8_general_ci;
INSERT INTO `yourdbname`.`latestvid` (`id`, `videoId`, `videoTitle`, `uploadDate`) VALUES (NULL, '--', '--', '--');
This will create a table for your latest video info for use in your template however the default values I've set up will not work with your template for obvious reasons.
You could then do something similar to this:
public function updateAction()
{
$this->_helper->viewRenderer->setNoRender(); // disable view
$this->_helper->layout()->disableLayout(); // disable layout
$user = 'Blanktv'; // insert your channel name
$url = 'https://gdata.youtube.com/feeds/api/users/'.$user.'/uploads';
$feed = Zend_Feed_Reader::import($url);
if(!$feed)
{
die("couldn't access the feed"); // Note: the Zend component will display an error if the feed is not available so this wouldn't really be necessary for ZF
}
else
{
$i=0;
foreach ($feed as $entry)
{
$urlChop = explode ('http://gdata.youtube.com/feeds/api/videos/',$entry->getId());
$videoId = end($urlChop);
$videoTitle = $entry->getTitle();
$uploadDate = $entry->getDateCreated();
// use your preferred method to update the db record where the id = 1
$i++;
if($i==1) break;
}
}
}
Maybe have a go and let me know how you get on?
You'd just need to tweak the template so you'd get the variables from the database instead of Youtube with the exception of the thumbnail.
I suppose you could always take that approach further and actually store images etc since the thumbnail is still being pulled from Youtube and may slow things down.
You could set up a script to copy the thumbnail to your own server and store the path in the db or use a standard thumbnail if you are running a series of videos for which you require standard branding - anyway hope it helps.
:-D
Dave

How to append a parameter to current page using CHtml::link?

Using Yii, and trying to append a Lang=xx to the end of the current page url and present it on the page.
I put the below code in the protected/views/layout/main.php
<?php echo CHtml::link('English', array('','lang'=>'en'), array('class'=>'en')) ?>
<?php echo CHtml::link('中文', array('','lang'=>'tw'), array('class'=>'tw')) ?>
<?php echo CHtml::link('日本語', array('','lang'=>'jp'), array('class'=>'jp')) ?>
With standard pages like "/site/index", or controller action pages like "/site/contact", they work fine. But with the standard static pages like "site/page?view=about", it's not working. The url expected should be something like "site/page?view=about&lang=tw", but instead, it gives me "site/page?lang=tw".
How can I fix that?
I ended up doing it with langhandeler extension and url rules and map [site]/[path]?lang=[language code] to [site]/[language code]/[path]
And then I coded the links like below:
<?php
$request = $_SERVER['REQUEST_URI'];
$path_a = explode("/",$request);
$haveLang = isSet($_GET["lang"]);
$uri = ($haveLang?
substr($request, strlen($path_a[1])+1) //strip language prefix and the slash
:$request); //don't process if the page is in default language
echo CHtml::link(CHtml::encode(Yii::app()->name), CHtml::normalizeUrl(($haveLang?'/'.$_GET["lang"].'/':'/')), array('id'=>'logo'));
?>
<div id="lang_switch">
<?php
echo CHtml::link('English', CHtml::normalizeUrl($uri), array('class'=>'en')); //no need to add default language prefix
echo CHtml::link('中文', CHtml::normalizeUrl('/tw'.$uri), array('class'=>'tw'));
echo CHtml::link('日本語', CHtml::normalizeUrl('/jp'.$uri), array('class'=>'jp'));
?>
</div>
that pretty much solved my problem. I hope this could help out someone else in the future.
you can give chtml link like this
$language = 'en';
CHtml::link("English", array('site/about/lang/' . $language));
site/about/lang/en = controller/action/lang/en
i hope this will help you.