Powered By

Powered by Blogger

Tampilkan postingan dengan label php. Tampilkan semua postingan
Tampilkan postingan dengan label php. Tampilkan semua postingan

Rabu, 06 Januari 2010

iAddressBook Shares Email vCard Records On A LAMP (PHP) Web Server

iAddressBook shares email vCard records on a LAMP (PHP) web server. You don't need to know PHP, but you should know basic MySQL. See the demo, HERE.

iAddressBook only imports vCards, but exports:

- vCard (Evolution) http://en.wikipedia.org/wiki/VCard
- CSV (OpenOffice Calc) http://en.wikipedia.org/wiki/Comma-separated_values
- LDIF (Mozilla Thunderbird) http://en.wikipedia.org/wiki/LDIF


INSTALL


Either choose sqlite, or create an empty database. The README.txt file explains how to edit the conf/config.php file. Extract the code from http://iaddressbook.org/ to your web directory, and run it, by opening its root directory in your browser.

If you use Mozilla Thunderbird, you should export your address book to LDIF. You can then use Gnome Evolution to convert LDIF to vCard format, which iAddressBook can import. Some data cleanup will be necessary.

TIPS AND TRICKS


iAddressBook allows for typical authorization. However, I like to use it for a Wiki-styled intranet.

I've not gotten a response from the author, and I've not seen activity, since v1.0 was released 1.5 years ago. That said, iAddressBook is stable, complete, and avoids bloat with clean code. I posted a bug fix for handling birthdays at the end of the year, and Thunderbird LDIF import at http://iaddressbook.org/wiki/bugs

If you don't have a camera handy, MeMaker (Ubuntu, Fedora and source code available) easily creates avatars of your friends or co-workers.


This is a guest post from Bruce, a New York City programmer, the author of http://emacro.sf.net/. Also see "Searching For Text? `egrep -r foo $*` Too Slow?", another great post by Bruce.

Sabtu, 02 Januari 2010

Display Google Analytics Stats On Your Website [Public Stats]

We use GAPI (gapi-google-analytics-php-interface) to display Google Analytics page views and visits to everyone, without requiring a password - it's all done by using the Google Analytics API.

To make some Google Analytics stats public, you need a PHP5 web host but it you don't have one, there are lots of free alternatives out there and you can then embed the stats using in iframe (very easy).

I have modified the example report which comes with GAPI to display the month, year, number of page views, visits and so on, and sort it by year and then month. It basically looks like this:

google analitycs public stats.

You can view a demo right here, on Web Upd8. As you can see, Google Analytics public stats can be easily integrated into Blogger too (I saw lots of requests of using this in Blogger blogs).

Download GAPI + my Google Analytics public stats example


To use GAPI, simply download the archive and extract it to your web host, then save the following file under any name you want (let's say gapistats.php) and place it in the same folder as GAPI:
<?php
define('ga_email','google_analytics_google_email@address.com');
define('ga_password','your_Google_Analytics_password');
define('ga_profile_id','YOUR GOOGLE ANALYTICS PROFILE ID');

require 'gapi.class.php';

$ga = new gapi(ga_email,ga_password);

$today = date('Y-m-d');
$search = array("2009","2010","01","02","03","04","05","06","07","08","09","10","11","12");
$replace = array("","","January","February","March","April","May","June","July","August","September","October","November","December");
$search2 = array ("<");
$replace2 = array ("");

$ga->requestReportData(ga_profile_id,array('month','year'),array('pageviews','visits','bounces','entrances'),array('-year','-month') ,$filter=null,$start_date='2009-03-01',$end_date=$today,$start_index=1,$max_results=1000);
?>
<table width="99%" align="center">
<tr>
<th>Month</th>
<th>Year</th>
<th>Pageviews</th>
<th>Visits</th>
</tr>
<?php
foreach($ga->getResults() as $result):
?>
<tr valign="center" align="center">
<td width="25%"><?php echo str_replace($search,$replace,$result) ?></td>
<td width="20%"><?php echo $result->getYear(str_replace($search2,$replace2,$result)) ?>
<td width="30%"><?php echo $result->getPageviews() ?></td>
<td width="25%"><?php echo $result->getVisits() ?></td>
</tr>
<?php
endforeach
?>
</table>
<br/><br/>
<table>
<tr>
<th>Total Months:</th>
<td><?php echo $ga->getTotalResults() ?></td>
</tr>
<tr>
<th>Total Pageviews</th>
<td><?php echo $ga->getPageviews() ?>
</tr>
<tr>
<th>Total Visits</th>
<td><?php echo $ga->getVisits() ?></td>
</tr>
<tr>
<th>Results Updated</th>
<td><?php echo $ga->getUpdated() ?></td>
</tr>
</table>


Then simply link to this page, or embed it in an iframe. Example:
<iframe allowtransparency="true" scrolling="no" frameborder="0" style="border: none; width: 550px; height:600px;" src="http://path.to/gapistats.php"></iframe>


What you can change in this script:

a) Obviously, enter your Google Analytics email address (GMAIL), password and Google Analytics profile ID on top of the page, as suggested. To find out your Google Analytics profile ID, select a profile, then click "Edit" and you will see the profile ID in the top left corner:

google analytics profile id

b)
requestReportData(ga_profile_id,array('month','year'),array('pageviews','visits','bounces','entrances'),array('-year','-month') ,$filter=null,$start_date='2009-03-01',$end_date=$today,$start_index=1,$max_results=1000)

This part basically contains all the variables. Edit the start date, replace 'pageviews' and 'visits' with another variable if you want to display some other stats, etc. Or leave it as is. You can find more info on the Google Analytics API docs.

Rabu, 02 Desember 2009

Tiny Tiny RSS Is A Highly Configurable Web-Based Feed Reader

tiny tiny rss

Tiny Tiny RSS is a web-based, PHP and Ajax news feed (RSS/Atom) reader, designed to allow you to read news from any location which resembles somewhat to Google Reader but it's much more customizable. You can choose to either install it on your own computer (it requires PHP, MySQL, etc), on a server, or use some already set up Tiny Tiny RSS servers. Read on!


Tiny Tiny RSS Features:

* Server-side application, user only needs a web browser
* Supports RSS, RDF, Atom feeds using Magpie library
* Supports OPML import/export
* Easy setup and configuration
* Streamlined interface using XmlHttpRequest (or AJAX for laypeople)
* Free software, licensed under GPL
* Support for generation of aggregated feeds
* Supports full-text searching
* Works with two major free databases - PostgreSQL and MySQL
* Supports Technorati-style tags
* Supports flexible content filtering
* Supports multiuser operation
* Supports feed categories
* Supports authentication for reading protected feeds (e.g. LiveJournal friend-only posts)
* Support keyboard shortcuts
* Supports interface translations (work in progress)
* Supports feed enclosures (podcasts)
* Supports XML-RPC API
* Supports article scoring
* Supports inline XSPF MP3 player for podcasts
* Themes

You can even set it to send you daily digest of new (and unread) headlines on your configured e-mail address or use your own stylesheet to override default style.

You can download Tiny Tiny RSS from HERE (also see the installation instructions - it's pretty easy).

There is also a DEMO you can try before actually installing Tiny Tiny RSS, but the demo doesn't come with all the features.

If you don't wish / can't install Tiny Tiny RSS on your own computer or server, you can use the following servers:

-Unofficial:
http://tt-rss.co.cc
http://ttrss.co.cc

-Official:
http://online.tt-rss.org/register.php

Please note that all the three above servers use free hosts and because of that, none of them comes with any guarantees!

Rabu, 23 September 2009

Twitter Auto-Follow Script To Run On Your Own Server

In the 10 code snippets to interact with Twitter by CatsWhoCode, I found an interesting PHP script which can be used to auto-follow people on Twitter, based on a certain term.

The script runs out of the box with no need of PHP knowledge, and all you have to do is edit the $user, $pass and $term variables. Obviously, the first 2 are for your username and password and $term is the term to search in the users timeline and whoever mentions this term, will be followed by you.

Here is the script:

<?php
// Twitter Auto-follow Script by Dave Stevens - http://davestevens.co.uk

$user = "enter_your_twitter_username_here";
$pass = "enter_your_twitter_password_here";

$term = "enter_the_search_term_to_follow_here";


$userApiUrl = "http://twitter.com/statuses/friends.json";

$ch = curl_init($userApiUrl);
curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$apiresponse = curl_exec($ch);
curl_close($ch);
$followed = array();

if ($apiresponse) {
$json = json_decode($apiresponse);
if ($json != null) {
foreach ($json as $u) {
$followed[] = $u->name;
}
}
}

$userApiUrl = "http://search.twitter.com/search.json?q=" . $term . "&rpp=100";
$ch = curl_init($userApiUrl);
curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$apiresponse = curl_exec($ch);
curl_close($ch);

if ($apiresponse) {
$results = json_decode($apiresponse);
$count = 20;
if ($results != null) {
$resultsArr = $results->results;
if (is_array($resultsArr)) {
foreach ($resultsArr as $result) {
$from_user = $result->from_user;
if (!in_array($from_user,$followed)) {
$ch = curl_init("http://twitter.com/friendships/create/" . $from_user . ".json");
curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"follow=true");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$apiresponse = curl_exec($ch);

if ($apiresponse) {
$response = json_decode($apiresponse);
if ($response != null) {
if (property_exists($response,"following")) {
if ($response->following === true) {
echo "Now following " . $response->screen_name . "\n";
} else {
echo "Couldn't follow " . $response->screen_name . "\n";
}
} else {
echo "Follow limit exceeded, skipped " . $from_user . "\n";
}
}
}
curl_close($ch);
} else {
echo "Already following " . $from_user . "\n";
}
}
}
}
}
?>



All you have to do is copy/paste the code to a text file, rename it to .php and upload it to a web hosting which supports PHP. Then just to go the web address where you uploaded the script and it will run, doing what it's supposed to. Alternatively, you could set up a PHP server on your own computer and run it there.