Getting Facebook event venue latitude & longitude - php

Hello I use the following code in order to retrieve an events infoormation from facebook based on the url provided.
The code is this:
function importEvent($url)
{
$facebook = new Facebook(array(
'appId' => 'someAppId',
'secret' => 'someSecret',
'cookie' => true, // enable optional cookie support
));
if(checkLogin()==true)
{
//get rid of hash if exists
$hash = explode('#',$url);
if(!empty($hash[1]))
$array = parse_url($hash[1]);
else
$array = parse_url($hash[0]);
parse_str($array['query'],$output);
$eid = $output['eid'];
if(empty($eid))//new url think http://www.facebook.com/events/2323423423423/
{
$url = str_replace('http://www.facebook.com/events/','',$url);
$url = str_replace('https://www.facebook.com/events/','',$url);
$hash = explode('/?',$url);
if(!empty($hash[1]))
$url = $hash[0];
$eid = str_replace('?','',$url);
$eid = str_replace('/','',$url);
//print_r($eid);
}
//Calling users.getinfo legacy api call example
try{
$param = array(
'method' => 'events.get',
'eids' => $eid,
'access_token' => $_SESSION['access_token']
);
$events = $facebook->api($param);
}
catch(Exception $o){
error_log($o);
echo $o;
}
print_r($events);
return $events;
}
}
The output I'm getting is this:
Array
(
[0] => Array
(
[eid] => 410474065693887
[name] => Sunday Night Fever Vol.4 Disco Special #Legacy Rock Area
[pic_small] => http://profile.ak.fbcdn.net/hprofile-ak-snc6/276862_410474065693887_714884848_t.jpg
[pic_big] => http://profile.ak.fbcdn.net/hprofile-ak-snc6/276862_410474065693887_714884848_n.jpg
[pic] => http://profile.ak.fbcdn.net/hprofile-ak-snc6/276862_410474065693887_714884848_s.jpg
[pic_square] => http://profile.ak.fbcdn.net/hprofile-ak-snc6/276862_410474065693887_714884848_q.jpg
[has_profile_pic] => 1
[host] => Legacy Rock Area
[version] => 2
[description] => Αφου μας το ζητησατε "παρτε" το..!!!
Μετα το τελευταιο απιστευτο killer Disco Party εχουμε την ευκαιρια να κανουμε προθερμανση για τον Super Αποκριατικο Φεβρουαριο που θα ακολουθησει στο Legacy Rock Area μεμια βραδυα γεματη Disco,Dance,Pop και οπου μας βγαλει...!!
Κυριακη 20 Ιανουαριου λοιπον..Sunday Night Fever Disco Special!!!
That night the DJ saves our lives...!!!
[start_time] => 2013-01-20
[end_time] =>
[timezone] =>
[is_date_only] => 1
[creator] => 1732432279
[update_time] => 1357737066
[location] => Legacy Rock Area
[hide_guest_list] =>
[can_invite_friends] =>
[privacy] => OPEN
[venue] => Array
(
[id] => 244479685665743
)
[all_members_count] => 7175
[attending_count] => 74
[unsure_count] => 144
[declined_count] => 509
[not_replied_count] => 6957
)
)
However on the api documentation it mentions that venue contains the following:
The location of this event
generic access_token, user_events or friends_events
object containing one or more of the following fields: id, street, city, state, zip, country, latitude, and longitude fields.
But all I'm getting is the venue id.
I couldn't locate a specific piece of information on how to retrieve lat + lng of a venue place and I assume that this code is ok if I'm not mistaken.
Do I need to execute another query just for the venue info and if so could you please provide any reference or code examples? Or is there a way for this piece of code to return the lat + lng also, so I wont have to do 2 queries for 1 event?

After some research I've found that that this could be doen with fql.multiquery and it seems to work fine now. Here is the source code.
function importEventFQL($url)
{
$facebook = new Facebook(array(
'appId' => 'someApddID',
'secret' => 'someSecret',
'cookie' => true, // enable optional cookie support
));
if(checkLogin()==true)
{
list($url_static,$url_URI) = explode('/events',$url);
$url_URI = ltrim($url_URI,'/');
list($eid, $trash) = explode('/?',$url_URI);
$fql = '{';
$fql .= '"event_info":"SELECT name, description, pic_small, pic_big, eid, venue, location, start_time, end_time, host from event WHERE eid=\'' . $eid . '\'",';
$fql .= '"event_venue":"SELECT name, username, page_id, location FROM page WHERE page_id IN (SELECT venue.id FROM #event_info)"';
$fql .= '}';
$param = array(
'method' => 'fql.multiquery',
'queries' => $fql,
'callback' => ''
);
$result = $facebook->api($param);
print_r($result);
}
}

If you want just the FQL to do this:
{
"events" : "SELECT privacy, name, description, start_time, venue.id, pic_cover FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid = me())",
"venues" : "SELECT latitude, longitude, name, page_id FROM place WHERE page_id IN (SELECT venue.id FROM #events)"
}

Related

How to encode an array of data and save to a pivot table laravel

All I want here is to be able to save all the ID's of services into the pivot table associated with the given keywords/tags but at the moment all it does is that it takes the last ID of the created object and saves into the pivot table with different keywords. let's say for example I enter [id1 => service1, id2 => service2] and [id1 = > keyword1, id2 => keyword2, id3 => keyword3] instead of it saving only id2 of service2 and all the keywords I want it to save all the Ids of all of the services and the keywords. I hope it makes sense
foreach($params['service'] as $key => $value){
$service = Service::firstOrNew(['service' => $value, 'price' => $params['price'][$key], 'business_id' => $params['business_id']]);
$service->service = $value;
$service->price = $params['price'][$key];
$service->business_id = $params['business_id'];
$service->save();
}
foreach($params['keywords'] as $keyword){
$cleaned_keyword = self::cleanKeywords($keyword);
$newKeyword = Keyword::firstOrNew(['keyword' => $cleaned_keyword]);
$newKeyword->keyword = $cleaned_keyword;
$newKeyword->save();
$service->keywords()->syncWithoutDetaching([$newKeyword->id => ['business_id' => $params['business_id']]]);
}
This is something I would expect but it is tricky because a single or 2 services for example can have multiple keywords. NOTE: I had manually changed these values in the database
These are the results from a dd($params)
Based on the dd($params).attached is the result,only
"service" => array:2[
1 => "Mobile development"
]
was saved in the pivot table and got assigned all the keywords
Please correct me if this is a good approach, I managed to solve this by having an inner loop.
foreach($params['service'] as $key => $value) {
$service = Service::firstOrNew(['service' => $value, 'price' => $params['price'][$key], 'business_id' => $params['business_id']]);
$service->service = $value;
$service->price = $params['price'][$key];
$service->business_id = $params['business_id'];
$service->save();
foreach($params['keywords'] as $keyword) {
$cleaned_keyword = self::cleanKeywords($keyword);
$newKeyword = Keyword::firstOrNew(['keyword' => $cleaned_keyword]);
$newKeyword->keyword = $cleaned_keyword;
$newKeyword->save();
$service->keywords()->syncWithoutDetaching([$newKeyword->id => ['business_id' => $params['business_id']]]);
}
}

How to add array values in CHtml::activeDropDownList in Yii

I want to add $cluster1 values to CHtml::activeDropDownList
$cluster_name_models = new ClusterForm();
$records = $cluster_name_models->get_list('grade');
$cluster_details=$records['0']['grade'];
$cluster1=explode(';',$cluster_details);
$cluster1=Array ( [0] => JMC [1] => MMC [2] => SMC );
Assuming that grade is the name of the related model's attribute
$cluster_name_models = new ClusterForm();
$records = $cluster_name_models->get_list('grade');
$cluster_details=$records['0']['grade'];
$cluster1=explode(';',$cluster_details);
echo CHtml::activeDropDownList($model,
'grade',
$cluster1,
array('empty'=>'Select Option'));

adding multiple rows in mysql table based on an array

I have a form which allows people to message each other, a user can select multiple people to message, when i submit a form it gives me the name and id of people selected to message in an array. uptil here i am able to get it to work for a single recipient
I want to be able to use this array and INSERT message for each user in different rows of mysql table
this is the array that i get when i submit a form
Array (
[to_user_id] => Array
(
[0] => 54
[1] => 55
)
[subject] => aaa
[message] => bbb
[send_message] =>
this is the part of code that works for a single recipient but not multiple
$to_user_id_array = ($_POST['to_user_id']);
$params = array(
':to_user_id' => $to_user_id_array,
':subject' => $_POST['subject'],
':message' => $_POST['message'],
':sender_id' => $this->user_id,
':status' => "0",
':type' => "message",
':sender_name' => $sender_name,
':to_user_name' => $to_user_name,
':delete_received' => 'no',
':delete_sent' => 'no',
);
$sql = "INSERT INTO `messages` (`sender_id`,`subject`,`comment`,`to_user_id`,`status`,`type`,`sender_name`,`to_user_name`,`delete_received`,`delete_sent`)
VALUES (:sender_id, :subject, :message, :to_user_id, :status, :type, :sender_name,:to_user_name,:delete_received,:delete_sent);";
parent::query($sql, $params);
$this->error = "<div class='alert alert-success'>" . _('Your message has been sent.') . "</div>";
Will really appreciate any help..
This is what worked for me, i hope this helps someone else in similar position
while ($value = $stmt->fetch(PDO::FETCH_ASSOC)) {
$params = array(
':to_user_id' => $value['user_id'],
':subject' => $_POST['subject'],
':message' => $_POST['message'],
':sender_id' => $this->user_id,
':status' => "0",
':type' => "message",
':sender_name' => $sender_name,
':to_user_name' => $value['name'],
':delete_received' => 'no',
':delete_sent' => 'no',
);
$sql = "INSERT INTO `messages` (`sender_id`,`subject`,`comment`,`to_user_id`,`status`,`type`,`sender_name`,`to_user_name`,`delete_received`,`delete_sent`)
VALUES (:sender_id, :subject, :message, :to_user_id, :status, :type, :sender_name,:to_user_name,:delete_received,:delete_sent);";
parent::query($sql, $params);
}

Bibtex php preg_match_all

I have a text file with a Bibtex export.
The text file has a number of entries following the pattern below.
#article{ls_leimeister,
added-at = {2013-01-18T11:14:11.000+0100},
author = {Wegener, R. and Leimeister, J. M.},
biburl = {http://www.bibsonomy.org/bibtex/27bb26b4b4858439f81aa0ec777944ac5/ls_leimeister},
journal = {International Journal of Technology Enhanced Learning (to appear)},
keywords = {Challenges Communities: Factors Learning Success VirtualCommunity and itegpub pub_jml pub_rwe},
note = {JML_390},
title = {Virtual Learning Communities: Success Factors and Challenges},
year = 2013
}
I want to use php and considered preg_match_all
The following didnt get me anywhere:
preg_match_all('/#^.*}$/', file_get_contents($file_path),$results);
I wanted to start simple, but that didnt really work.
I am kinda new to php RegEx.
The perfect final output would be:
Array
(
[0] => Array
(
['type'] => article
['unique_name'] => ls_leimeister
['added-at'] => 2013-01-18T11:14:11.000+0100
['author'] => Wegener, R. and Leimeister, J. M.
['biburl'] => http://www.bibsonomy.org/bibtex/27bb26b4b4858439f81aa0ec777944ac5/ls_leimeister
['journal'] => International Journal of Technology Enhanced Learning (to appear)
['keywords'] => Challenges Communities: Factors Learning Success VirtualCommunity and itegpub pub_jml pub_rwe
['note'] => JML_390
['title'] => Virtual Learning Communities: Success Factors and Challenges
['year'] => 2013
)
[1] => Array
(
[...] => …
)
)
Try this : Here I have fetched only type and unique_name, by looking at it, you can fetch all others.
$str = '#article{ls_leimeister,
added-at = {2013-01-18T11:14:11.000+0100},
author = {Wegener, R. and Leimeister, J. M.},
biburl = {http://www.bibsonomy.org/bibtex/27bb26b4b4858439f81aa0ec777944ac5/ls_leimeister},
journal = {International Journal of Technology Enhanced Learning (to appear)},
keywords = {Challenges Communities: Factors Learning Success VirtualCommunity and itegpub pub_jml pub_rwe},
note = {JML_390},
title = {Virtual Learning Communities: Success Factors and Challenges},
year = 2013
}';
preg_match_all('/#(?P<type>\w+){(?P<unique_name>\w+),(.*)/',$str,$matches);
echo $matches['type'][0];
echo "<br>";
echo $matches['unique_name'][0];
echo "<br>";
echo "<pre>";
print_r($matches);
Output array format will be little different from yours, but you can change this format to yours.
Pattern: /^#([^{]+)\{([^,]+),\s*$|^\s*([^\R#=]+) = \{(.*?)}/ms (Demo)
This pattern has two alternatives; each containing two capture groups.
type and unique_name are captured and stored in elements [1] and [2].
all other key-value pairs are stored in elements [3] and [4].
This separated array storage allows reliable processing when constructing the desired output array structure.
Input:
$bibtex='#BOOK{ko,
title = {Wissenschaftlich schreiben leicht gemacht},
publisher = {Haupt},
year = {2011},
author = {Kornmeier, M.},
number = {3154},
series = {UTB},
address = {Bern},
edition = {4},
subtitle = {für Bachelor, Master und Dissertation}
}
#BOOK{nial,
title = {Wissenschaftliche Arbeiten schreiben mit Word 2010},
publisher = {Addison Wesley},
year = {2011},
author = {Nicol, N. and Albrecht, R.},
address = {München},
edition = {7}
}
#ARTICLE{shome,
author = {Scholz, S. and Menzl, S.},
title = {Alle Wege führen nach Rom},
journal = {Medizin Produkte Journal},
year = {2011},
volume = {18},
pages = {243-254},
subtitle = {ein Vergleich der regulatorischen Anforderungen und Medizinprodukte
in Europa und den USA},
issue = {4}
}
#INBOOK{shu,
author = {Schulz, C.},
title = {Corporate Finance für den Mittelstand},
booktitle = {Praxishandbuch Firmenkundengeschäft},
year = {2010},
editor = {Hilse, J. and Netzel, W and Simmert, D.B.},
booksubtitle = {Geschäftsfelder Risikomanagement Marketing},
publisher = {Gabler},
pages = {97-107},
location = {Wiesbaden}
}';
Method: (Demo)
$pattern='/^#([^{]+)\{([^,]+),\s*$|^\s*([^\R#=]+) = \{(.*?)}/ms';
if(preg_match_all($pattern,$bibtex,$out,PREG_SET_ORDER)){
foreach($out as $line){
if(isset($line[1])){
if(!isset($line[3])){ // this is the starting line of a new set
if(isset($temp)){
$result[]=$temp; // send $temp data to permanent storage
}
$temp=['type'=>$line[1],'unique_name'=>$line[2]]; // declare fresh new $temp
}else{
$temp[$line[3]]=$line[4]; // continue to store the $temp data
}
}
}
$result[]=$temp; // store the final $temp data
}
var_export($result);
Output:
array (
0 =>
array (
'type' => 'BOOK',
'unique_name' => 'ko',
'title' => 'Wissenschaftlich schreiben leicht gemacht',
'publisher' => 'Haupt',
'year' => '2011',
'author' => 'Kornmeier, M.',
'number' => '3154',
'series' => 'UTB',
'address' => 'Bern',
'edition' => '4',
'subtitle' => 'für Bachelor, Master und Dissertation',
),
1 =>
array (
'type' => 'BOOK',
'unique_name' => 'nial',
'title' => 'Wissenschaftliche Arbeiten schreiben mit Word 2010',
'publisher' => 'Addison Wesley',
'year' => '2011',
'author' => 'Nicol, N. and Albrecht, R.',
'address' => 'München',
'edition' => '7',
),
2 =>
array (
'type' => 'ARTICLE',
'unique_name' => 'shome',
'author' => 'Scholz, S. and Menzl, S.',
'title' => 'Alle Wege führen nach Rom',
'journal' => 'Medizin Produkte Journal',
'year' => '2011',
'volume' => '18',
'pages' => '243-254',
'subtitle' => 'ein Vergleich der regulatorischen Anforderungen und Medizinprodukte
in Europa und den USA',
'issue' => '4',
),
3 =>
array (
'type' => 'INBOOK',
'unique_name' => 'shu',
'author' => 'Schulz, C.',
'title' => 'Corporate Finance für den Mittelstand',
'booktitle' => 'Praxishandbuch Firmenkundengeschäft',
'year' => '2010',
'editor' => 'Hilse, J. and Netzel, W and Simmert, D.B.',
'booksubtitle' => 'Geschäftsfelder Risikomanagement Marketing',
'publisher' => 'Gabler',
'pages' => '97-107',
'location' => 'Wiesbaden',
),
)
Here is the site that I extracted new sample input strings from.

How To Fetch Facebook Activity Feed of A Particular User

Do any one know how to fetch activity feed of an user who is associated with an app id ?
I am able to fetch the list of users who are associated with an app id by using this code
<?php
require "facebook.php";
$facebook = new Facebook(array(
'appId' => '',
'secret' => '',
));
$user = $facebook->getUser();
if ($user) {
try {
$result = $facebook->api(array(
"method" => "fql.query",
"query" => "SELECT uid, name, pic_square, activities FROM user
WHERE uid IN (SELECT uid1 FROM friend WHERE uid2 = me()) and is_app_user"
));
echo "<pre>";
print_r($result);
?>
Output
Array
(
[0] => Array
(
[uid] => 14529121124
[name] => Saurabh
[pic_square] => http://profile.ak.fbcdn.net/hprofile-ak-ash4/187195_1452918224_6692287_q.jpg
[activities] =>
)
[1] => Array
(
[uid] => 100000565666371
[name] => Abhijeet
[pic_square] => http://profile.ak.fbcdn.net/hprofile-ak-prn1/157718_100000289210371_1409561577_q.jpg
[activities] =>
)
)
Now i just want to fetch activity feed of these 2 users (User Id: 14529121124 , 100000565666371) individually who are associated with this (54975723243503) app_id.
Use graph API : https://developers.facebook.com/docs/reference/api/user/
Search for "feed" in that page
You need to query the FQL stream table or the Graph API feed object:
Since you're working with FQL, I'll give an example using FQL. I did some quick testing, and the stream table doesn't allow you to use the IN keyword to select streams from multiple sources, so you'll need to make two separate calls, first to get the user_ids, second to get the stream.
Try this:
$queries = array();
$i = 0;
foreach ($result as $item) {
$queries['user_stream'.$i] =>
"SELECT source_id, created_time, message, attachment FROM stream
WHERE source_id = " . $item['uid'];
$i++;
}
$result2 = $facebook->api(array(
"method" => "fql.multiquery",
"queries" => json_encode($queries)
));

Categories