Adding live data sources

motherlamentationInternet and Web Development

Dec 7, 2013 (3 years and 11 months ago)

112 views



Adding live data sources
to your content
By Jaime Schmidt
Ginger Robot Website Development

Email :
jaime@gingerrobot.com

Web:
Http://gingerrobot.com


Live Data Sources


DRUPAL 7


Plant Profiles
- Plant Name
- Date
- Notes
http://www.flickr.com/photos/ruthbruin2002/630922037/


Custom Content Type
Date (
http://drupal.org/project/date
)


CREATE A VIEW
http://drupal.org/project/views






Live Data Ideas:
- Wikipedia info
- Twitter mentions
- Latin Plant Names
- Flickr Pictures
- Google News articles





Adding

Blog
Posts




Feeds
http://drupal.org/project/feeds


http://drupal.org/project/feeds


Blogs View


ZEN Sub Theme
http://drupal.org/project/zen


Plant Profiles
/node--plant-profile.tpl.php
print render($content);
print "<B> Table of Related Articles </B>";

$view = views_get_view('blogs');

$view->set_display('block_1');
$view->set_arguments(array($title));

print $view->preview('block_1');


FEEDS Module

- Extensions

- API

http://drupal.org/node/622700


Search
Twitter
For

Basil



<script language="javascript" src="jquery.tweet.js" type="text/javascript"></script>
<script type='text/javascript'>
jQuery(function() {

var whatToSearch = "<?php print $title?>";

Jquery('twittersearch').tweet({

avatar_size: 48,

count: 40,

query: whatToSearch,

loading_text: "loading...",


scrolling: true,

});
});
</script>
<div class="twittersearch" id="twittersearch"> </div>


Search
Flickr
For

Basil
http://www.newmediacampaigns.com/page/jquery-flickr-plugin


<script src="jflickrfeed.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.flickrarea').jflickrfeed({
limit: 5,
qstrings: {
// id: '44802888@N04'
tags: '<?php print $title ?>'
},
itemTemplate: '<li>' +
'<a href="{{image_b}}"><img src="{{image_s}}"
alt="{{title}}" /></a>' +
'</li>'
});
});
</script>

<div class="flickrarea" id="flickrarea"> </div>


Search

Google
News

For

Basil
http://www.malsup.com/jquery/gfeed/


<!-- include Google Feed API -->
<script type="text/javascript"
src="http://www.google.com/jsapi?key=ABQIAjZXXXX"></script>
<script language="javascript" src="/jquery.gfeed.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {

// add a feed manually

jQuery('#playernewssearch').gFeed({

url: '
http://news.google.com/news
?
pz=1&cf=all&ned=au&hl=en&
q=<?php print addslashes($title); ?>
&cf=all&output=rss',

title: 'Google News'

});
});
</script>
<div class="playernewssearch" id="playernewssearch"> </div>




Search
Wikipedia
for

Basil



jQuery.getJSON('
http://en.wikipedia.org/w/api.php
?
action=parse&
page=<?php print $title;?>&prop=text&format=json&
callback=?', function(json) {

jQuery('#wikiInfo').html(json.parse.text.*);

jQuery("#wikiInfo").find("a:not(.references a)").attr("href", function( {
return "http://www.wikipedia.org" + jQuery(this).attr("href");

}

);

jQuery("#wikiInfo").find("a").attr("target", "_blank");
});
<div id="wikiInfo">&nbsp;</div>
http://www.bauer-power.net/2010/09/use-jquery-to-add-wikipedia-content-to.html
http://en.wikipedia.org/w/api.php



Plant
Latin

Names
http://www.scientificname.net/plants/




- Latin Name Table

- Download and parse HTML


- Import Names with PHP
http://botanical.com/botanical/mgmh/c/corian99-l.jpg




The Plants Page
page—plants.tpl.php


Latin Name in the table
/views-view-table--plants.tpl.php


/sites/all/themes/plantprofile/templates/findLatin.inc.php
<?php
function getLatinName($plantname) {
// open database:
$dbhost = 'localhost';
$dbuser = 'plantprofiles';
$dbpass = password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'plantprofiles';
mysql_select_db($dbname);
$query = "SELECT * FROM plantnames WHERE textname LIKE '%$plantname%' LIMIT 1";
$results = mysql_query($query);
$row = mysql_fetch_assoc($results);
return $row['latinname'];
}
?>
function getLatinName


/sites/all/themes/plantprofile/templates/views-view-table--plants.tpl.php
<?php
include_once("findLatin.inc.php");
?>
<table class="<?php print $classes; ?>"<?php print $attributes; ?>>

<?php if (!empty($title)) : ?>

<caption><?php print $title; ?></caption>

<?php endif; ?>

<thead>

<tr>

<?php foreach ($header as $field => $label): ?>

<th class="<?php print $header_classes[$field]; ?>">

<?php print $label; ?>

</th>

<?php endforeach; ?>

</tr>

</thead>
--- TO BE CONTINUED


/sites/all/themes/plantprofile/templates/views-view-table--plants.tpl.php
<tbody>

<?php foreach ($rows as $count => $row): ?>

<tr class="<?php print implode(' ', $row_classes[$count]); ?>">

<?php foreach ($row as $field => $content): ?>

<td class="<?php print $field_classes[$field][$count]; ?>">
<?php if ($field == "title_1") {
$content = getLatinName($content);
}
?>

<?php print $content; ?>

</td>

<?php endforeach; ?>

</tr>

<?php endforeach; ?>

</tbody>
</table>


VOILA!!!


APIS
Twitter:
http://dev.twitter.com/doc
Wikipedia:
http://www.mediawiki.org/wiki/API
Flickr:
http://dev.twitter.com/doc
Google:
http://code.google.com/more/
Facebook:
http://developers.facebook.com/docs/
LinkedIn:
http://developer.linkedin.com/community/apis



Thanks!
Jaime Schmidt
Ginger Robot
Http://gingerrobot.com/
jaime@gingerrobot.com
PHP Developer
Jquery, MySQL