Archive for December, 2012

The first thing you need to do is create an account with MailChimp.

The following steps will walk you through the set up for your automatic emails:

Create an account with MailChimp

  1. Click here to go to MailChimp
  2. Click the button ‘Sign up free
  3. Enter your email, username and password and press ‘Create my account‘ – This will send you an email
  4. Go to your email and press ‘activate your account
  5. This will open another web page with a Captcha (jumbled letters) – Enter the Captcha and press ‘Confirm Signup
  6. Sign in to MailChimp
  7. Fill in as many fields on this page as possible as it will automatically generate the content within the footer of your emails
  8. When you are finished press ‘Save And Get Started
  9. Click ‘Let’s Go

You are now set up with MailChimp – Congratulations!

Create your list

The next step is to create a list. When someone signs up to your mailing list, they get entered into a list.

You can have as many lists as you like, but for now we will just create one.

  1. Click ‘Create A List
  2. Enter all of the required fields and press ‘Save‘ – I would suggest naming the list something like ‘Weekly blog posts’ so you know what it’s for
  3. You will now be taken to an overview of all your lists
  4. Click ‘Add people
  5. Enter in your email and details
  6. Press ‘Subscribe

Steps 4 – 6 are to add yourself to your mailing list. This is so you will receive a copy of your email whenever one is sent.

Create your automatic campaign

  1. Click ‘Campaigns‘ in the top navigation
  2. On the left, hover over ‘Create Campaign‘ and click ‘RSS-Driven Campaign
  3. You will now need to enter the URL to your website’s RSS feed. If you have a WordPress website, you can find this at http://www.yourdomain.com/feed
  4. Enter the frequency and time that you would like to send your campaign
  5. Click ‘Next‘ at the top right
  6. You should now see your lists on this page. Select the list you would like to send the automatic emails to, and click ‘Next

From this point on, you will need to use RSS values. These look like *|RSSFEED:TITLE|*. If you want to use a different value from your RSS feed, then please refer to this document

  1. You will now be on the ‘Campaign Info‘ page. Enter values into all of the required fields.

For the title, I used – [*|RSSFEED:TITLE|*] *|RSSFEED:DATE|* – *|RSSITEM:TITLE|* – This will come out as ‘[StuffedWeb] 04/05/2012 – Title of post here’

  1. Click ‘Next
  2. We now need to add a template. For this tutorial, please click ‘Select‘ under ‘Basic Layouts‘ – However you can use your own.
  3. On the left, click ‘Simple‘ then click on the template named ‘Basic
  4. On this section, you edit the content of your email. You need to use the RSS tags mentioned earlier.
    1. Hover of the title and click ‘Use Text‘ then add *|RSSITEM:TITLE|* – This will pull the title of your latest post
    2. Click on the main content and add *|RSSITEM:CONTENT_FULL|* – This will pull the content from your RSS feed
    3. You can preview your email by clicking ‘Popup Preview’ at the bottom
  5. When you are happy with your HTML email, click ‘Next
  6. Your plain text email should automatically be created, however click ‘Popup Preview‘ to double check and edit as necessary
  7. Click ‘Next
  8. Before you click ‘Start your RSS Campaign‘ make sure you send yourself a test email. If you are happy, then go for it!
  9. Click ‘Start Campaign‘ in the popup box
  10. Click ‘Go To Campaign Dashboard‘ to return

That’s it! Your email campaign is now set up and will automatically send out your latest post at the time you specified.

How to add it to your WordPress website

Now that you have your automatic emails set up and ready to send, you need to add the form to your website so people can subscribe to the emails.

Here are the steps to add the MailChimp sign up to your WordPress website:

  1. Click ‘Lists‘ in the main navigation
  2. On the list that you would like people to subscribe to, click ‘Forms
  3. On the navigation near the top, hover over ‘For Your Website’ and click ‘Signup Form Embed Code
  4. On the left, click ‘Classic Form
  5. Hover over the ‘Options‘ button next to ‘Classic Form‘ and update the details
  6. When you are happy with your form, click ‘Create Embed Code
  7. Under the ‘Create Embed Code‘, you will see the generated code, copy all of the code
  8. Sign in to your website’s WordPress admin
  9. Click ‘Appearance‘ > ‘Widgets
  10. Drag and drop the ‘Text‘ widget into your sidebar
  11. Paste your code into the text widget and press ‘Save

That’s it. You should now have a newsletter signup box within the sidebar of your website. Anyone who enters their email address will be added to the list you created, and will automatically receive emails with your latest posts attached.

Now you need to tell people to sign up to your newsletter and everything will happen automatically.

If you enjoyed this article, please sign up to my newsletter by filling in the form in the sidebar.

Did this article help you? Did you get stuck anywhere? If so, let me know in the comments below!

Advertisements

 

 

Folks like me are using free web hosting for personal website. And one of the main headaches for free hosting is that, it does not provide SMTP server for free. I am using bytehost for my wordpress blog hosting. Everything seems fine so far, but the problem is always the SMTP server. For example I am using a contact form, and user can leave messages to me through email. the original code reads:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$email_to = trim($_POST['your_email']);
$your_web_site_name = trim($_POST['your_web_site_name']);

$headers = 'From: ' . $your_web_site_name . ' <' . $email_to . '>' . "\r\n" . 'Reply-To: ' . $email;

if (mail($email_to, $subject, $message, $headers)) {
    echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent..      
} else {
    echo 'failed'; // ... or this one to tell it that it wasn't sent    
}

but, we can not use PHP’s mail function if it is not enabled by the hosting provider. Fortunately enough, Google’s Gmail is coming to save us. It is totally free, and more stable than any other providers. And overall, it is very easy to setup.
1. use phpmailer class to send email.
2. use smtp configuration for email.

the changed file is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
include ('../../../wp-includes/class-phpmailer.php'); 		
include ('../../../wp-includes/class-smtp.php'); 
    //we need to get our variables first
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$email_to = trim($_POST['your_email']);
$your_web_site_name = trim($_POST['your_web_site_name']);

    $mail=new PHPMailer();  		
    // Let PHPMailer use remote SMTP Server to send Email 		
    $mail->IsSMTP();  		
    // Set the charactor set. The default is 'UTF-8' 		
    $mail->CharSet='UTF-8';  		
    // Add an recipients. You can add more recipients 		// by using this method repeatedly. 		
    $mail->AddAddress($email_to);  		
    // Set the body of the Email. 		
    $mail->Body=$message;  		
    // Set "From" segment of header. 		
    $mail->From=$email;  		
    $mail->AddReplyTo($email, $email);  		
    // Set addresser's name 		
    $mail->FromName=$name;  		
    // Set the title 		
    $mail->Subject=$subject;  		
    // Set the SMTP server. 		
    $mail->Host='smtp.gmail.com'; 		
    $mail->Port= 465; 		
    $mail->SMTPAuth = true; 		
    $mail->SMTPSecure = "ssl";   		
    $mail->Username='youraccount@gmail.com'; 		
    $mail->Password='yourpassword'; 		 		
    // Send Email. 		
    if($mail->Send()){
        echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent..      
    } else {
        echo 'failed'; // ... or this one to tell it that it wasn't sent    
    }

The following settings specify using gmail’s smtp.

// Set the SMTP server.
$mail->Host=’smtp.gmail.com’;
$mail->Port= 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = “ssl”;
$mail->Username=’youraccount@gmail.com’;
$mail->Password=’yourpassword’;

Now you can send me messages through the contact form in the contact page!!

And if you are using my Aurelius theme, you can replace the send_mail.php with the code above to send email.

Thanks for reading.

the end!!

<?php
// Include WordPress 
define('WP_USE_THEMES', false);
require('blog/wp-blog-header.php');
query_posts('showposts=3');

?>  	
<?php while (have_posts()): the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php endwhile; ?>

Posted: December 28, 2012 in google
Tags:

 

How to create simple map using google map javascript api v3

Start to create google maps using api

Simple way to start develop the Google Maps API is to see a simple example.people familiar with JavaScript programming and object-oriented programming concepts can easily capture

<html>
  <head>

    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body, #map_canvas {
        margin: 0;
        padding: 0;
        height: 100%;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

    <script>
      var map;
      function initialize() {
        var mapOptions = {
          zoom: 8,
          center: new google.maps.LatLng(8.560058,76.881108),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('map_canvas'),
            mapOptions);
      }

      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <div id="map_canvas"></div>
  </body>
</html>

Declared our applications as HTML5 using the simple HTML5 DOCTYPE

<!DOCTYPE html>

Loading the Google Maps API script

 <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

Initialize the google map on window.onload to show map on our page

 function initialize() {
  var mapOptions = {
    zoom: 8,
    center: new google.maps.LatLng(8.560058,76.881108),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
}

function loadScript() {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "http://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=TRUE_OR_FALSE&callback=initialize";
  document.body.appendChild(script);
}

window.onload = loadScript;

Setting the map options

var mapOptions = {
  center: new google.maps.LatLng(8.560058,76.881108),
  zoom: 8,
  mapTypeId: google.maps.MapTypeId.ROADMAP
};
    • center

center the map on a specific point, we create a LatLng object to hold this location by passing the location’s coordinates in the order { latitude, longitude }:

center: new google.maps.LatLng(8.560058,76.881108),
    • Zoom Levels

The initial resolution at which to display the map is set by the zoom property, where zoom 0 corresponds to a map of the Earth fully zoomed out, and higher zoom levels zoom in at a higher resolution.

zoom: 8
    • Map Types

The following map types are supported:.

      • ROADMAP displays the normal, default 2D tiles of Google

        Maps.

      • SATELLITE displays photographic tiles.
      • HYBRID displays a mix of photographic tiles and a tile layer

        for prominent features (roads, city names).

      • TERRAIN displays physical relief tiles for displaying

        elevation and water features (mountains, rivers, etc.).

mapTypeId: google.maps.MapTypeId.ROADMAP

Create map object

var map = new google.maps.Map(document.getElementById("map_canvas"),
    mapOptions);

Loading Google Map

 <body onload="initialize()">

Facebook Query Language( FQL)

Posted: December 28, 2012 in Facebook
Tags:

The FQL object enables running FQL queries using the Graph API. Facebook Query Language, or FQL, enables you to use a SQL-style interface to query the data exposed by the Graph API. It provides for some advanced features not available in the Graph API, including batching multiple queries into a single call.

You can execute FQL queries by fetching https://api.facebook.com/method/fql.query?query=QUERY. You can specify a response format as either XML or JSON with the format query parameter.

Queries are of the form SELECT [fields] FROM [table] WHERE [conditions]. Unlike SQL, the FQL FROM clause can contain only a single table. You can use the IN keyword in SELECT or WHERE clauses to do subqueries, but the subqueries cannot reference variables in the outer query’s scope. Your query must also be indexable, meaning that it queries properties that are marked as indexable in the documentation below.

For any query that takes a uid, you can pass me() to return the logged-in user. For example:

FQL to get details of the current logged in user by me() function

SELECT name FROM user WHERE uid = me() 
SELECT uid, name, pic_square FROM user WHERE uid = me()
OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

Fql to get album id and details by album name

function get_album_id_by_album_name($album_name){//return array of data
        $fql            =   'SELECT aid, owner, name, object_id FROM album WHERE owner=me() and name="'.$album_name.'"';

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql,
                'callback'  => ''
            );
            $fqlResult   =   $this->facebook->api($param);
	return $fqlResult;
}

FQL to get facebook user profile details

function get_user_profile_details($user_facebook_id){

		$fql    =   "SELECT name,pic_square,pic,uid 
FROM user  where	
 uid  =".$user_facebook_id;

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}

FQL to check the user is facebook application user

function check_is_app_user($facebook_user_id){//return 1 if the user is using the current application
	try{
	$user=$facebook_user_id;
        $fql    =   "select is_app_user from user where uid=" . $user;
            $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql,
                'callback'  => ''
            );

            $fqlResult   =   $this->facebook->api($param);

	if($fqlResult)
		return $fqlResult['0']['is_app_user'];
       else
                return 0;
        }
	 catch(Exception $o){
            d($o);
        }

}

FQL to get the tagged photos of facebook user and tag details,tag co-ordinates of user photos

function get_user_tagged_photos_details($user_facebook_id){

		$fql    =   "SELECT pid,text,xcoord,ycoord,created FROM photo_tag WHERE subject =".$user_facebook_id;

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}
function get_tagged_users_id_by_photoid($photo_id){

		$fql    =   "SELECT text FROM photo_tag WHERE pid =".$photo_id;

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}

pid-The ID of the photo being queried.
xcoord-The center of the tag’s horizontal position, measured as a floating-point percentage from 0 to 100, from the left edge of the photo.
ycoord-The center of the tag’s vertical position, measured as a floating-point percentage from 0 to 100, from the top edge of the photo.

FQL query to get user facebook notification filter by unread

function get_fb_notification_by_uid($user_id){

		$fql    =   "SELECT notification_id, sender_id,app_id,icon_url, title_html, body_html, href
FROM notification
WHERE recipient_id=".$user_id."
AND is_unread = 1
AND is_hidden = 0";
                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}

sender_id-The user ID of the sender of the notification.
href-The URL associated with the notification. This is usually a location where the user can interact with the subject of the notification.
app_id-The ID of the application associated with the notification. This may be a third-party application or a Facebook application (for example, Wall).
is_unread-Indicates whether the notification has been marked as read. Use notifications.markRead to mark a notification as read.

FQL to get photos of my friends posted by date or week

function get_friends_photo_details($date){

		$fql    =   "SELECT pid, caption, aid, owner, link, src_big, src_small, created, modified FROM photo WHERE aid IN 
   (SELECT aid FROM album WHERE owner IN 
      (SELECT uid2 FROM friend WHERE uid1=me()) 
   ) 
AND created ."$date;

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}

function get_friends_photo_details_last_week(){

		$fql    =   "SELECT pid, caption, aid, owner, link, src_big, src_small, created, modified FROM photo WHERE aid IN 
   (SELECT aid FROM album WHERE owner IN 
      (SELECT uid2 FROM friend WHERE uid1=me()) 
   ) 
AND created > One_week_ago_in_unix_time ORDER BY created DESC";

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}

FQL to get photos by facebook albums

function get_photos_by_album_id($album_id){

if($album_id)
        $fql            =   'SELECT pid,src_big,owner,link,position,created,caption,src FROM photo WHERE aid="'.$album_id.'" ORDER BY created DESC LIMIT 0,6';

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql,
                'callback'  => ''
            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult;

}