Social Media Links Yii Extension

All top social media links like - facebook, twitter, linkedin etc. with left & right alignment.

Requirements 

Tested with Yii 1.1.14

Install 

  • Download the latest release package
  • Unpack it in /protected/extensions/ folder

Usage 

Paste the code into your main.php page or also you can use this code as per your requirement.
$this->widget('application.extensions.socialLink.socialLink', array(
    'style'=>'left', //alignment - left, right
    'top'=>'30',  //in percentage
        'media' => array(
        'facebook'=>array(
            'url'=>'http://facebook.com/',
            'target'=>'_blank',
        ),
        'twitter'=>array(
            'url'=>'http://twitter.com/',
            'target'=>'_blank',
        ),
        'google-plus'=>array(
            'url'=>'https://plus.google.com/',
            'target'=>'_blank',
        ),
        'linkedin'=>array(
            'url'=>'http://linkedin.com/',
            'target'=>'_blank',
        ),
        'rss'=>array(
            'url'=>'http://rss.com/',
            'target'=>'_blank',
        ), 
      )
));


Download 

Usual parameters to be adjusted: 


  • style: social link sidebar alignment (string: left or right).
  • top: the sidebar margin from top (in percentage: 30)
  • social media: social network which you must have (facebook, twitter, googleplus, linkedin, rss );
  • url: Your social media profile page link (url: http://www.facebook.com/fb_page)
  • target: click behaviour (target: _blank, _self, _parent)

*Note - Work online.

How to show a Captcha in Yii CForm?

In this wiki I will show how could use a Captcha in yii CForm. The easy way to show captcha image is create a form using CHtml method & CActiveForm, but CForm also should be able to show a captcha.
In your components -
Create a widget MyCaptcha.php
class MyCaptcha extends CCaptcha
{
   public $model;
   public $attribute;
 
   public function run(){
 
       parent::run();
       echo CHtml::activeTextField($this->model, $this->attribute);
    }
}
Add this into your contoller, to show the captcha image.
public function actions()
 {
   return array(
      'captcha'=>array(
      'class'=>'CCaptchaAction',
      'backColor'=>0xFFFFFF,
     ),
   );
}
in view, your CForm like -
return array(
    'title'=>'Please provide your login credential',
 
    'elements'=>array(
        'username'=>array(
            'type'=>'text',
            'maxlength'=>32,
        ),
        'password'=>array(
            'type'=>'password',
            'maxlength'=>32,
        ),
        'verifyCode'=>array(
        'type'=>'MyCaptcha',   //render the captcha image & text field.
     ),
    ),
 
    'buttons'=>array(
        'login'=>array(
            'type'=>'submit',
            'label'=>'Login',
        ),
    ),
);
Try this way it's working fine :)..

How to create & call custom global function in whole application?

In this wiki I will show how to create own custom global function. It may be save the space and reduce the time.
Need to make a file like - myfunction.php and put it inside components folder.
In your main.php (config folder)
Add this line in the top of your config main.php file -
require_once( dirname(__FILE__) . '/../components/myfunction.php');
In your components (folder)
Inside the myfunction.php you can write your functions. Like -
function get_my_info() {
 
     //your code here
     //your code here
 
     return value;
 }
Now this function is accessible in whole application (controller, view etc.), Directly call the function get_my_info() any where and it will return your value. Like -
$info = get_my_info();
 
//Or
 
echo get_my_info();
Try this and reduce the time :)..

How to prevent Login from two places?

In this wiki I will show how to Disallowing login from multi places. User can login or access their account at time, only single place.
In your models (User class)
/**
     * session_validate()
     * Will check if a user has a encrypted key stored in the session array.
     * If it returns true, user is the same as before
     * If the method returns false, the session_id is regenerated
     *
     * @param {String} $email   The users email adress
     * @return {boolean} True if valid session, else false
     */
 
    public function session_validate(  )
    {
 
        // Encrypt information about this session
        $user_agent = $this->session_hash_string($_SERVER['HTTP_USER_AGENT'], $this->user_email);
 
        // Check for instance of session
        if ( session_exists() == false )
        {
            // The session does not exist, create it
            $this->session_reset($user_agent);
        }
 
        // Match the hashed key in session against the new hashed string
        if ( $this->session_match($user_agent) )
        {
            return true;
        }
 
        // The hashed string is different, reset session
        $this->session_reset($user_agent);
        return false;
    }
 
    /**
     * session_exists()
     * Will check if the needed session keys exists.
     *
     * @return {boolean} True if keys exists, else false
     */
 
    private function session_exists()
    {
        return isset($_SESSION['USER_AGENT_KEY']) && isset($_SESSION['INIT']);
    }
 
    /**
     * session_match()
     * Compares the session secret with the current generated secret.
     *
     * @param {String} $user_agent The encrypted key
     */
 
    private function session_match( $user_agent )
    {
        // Validate the agent and initiated
        return $_SESSION['USER_AGENT_KEY'] == $user_agent && $_SESSION['INIT'] == true;
    }
 
    /**
     * session_encrypt()
     * Generates a unique encrypted string
     *
     * @param {String} $user_agent      The http_user_agent constant
     * @param {String} $unique_string    Something unique for the user (email, etc)
     */
 
    private function session_hash_string( $user_agent, $unique_string )
    {
        return md5($user_agent.$unique_string);
    }
 
    /**
     * session_reset()
     * Will regenerate the session_id (the local file) and build a new
     * secret for the user.
     *
     * @param {String} $user_agent
     */
 
    private function session_reset( $user_agent )
    {
        // Create new id
        session_regenerate_id(TRUE);
        $_SESSION = array();
        $_SESSION['INIT'] = true;
 
        // Set hashed http user agent
        $_SESSION['USER_AGENT_KEY'] = $user_agent;
    }
 
    /**
     * Destroys the session
     */
 
    private function session_destroy()
    {
        // Destroy session
        session_destroy();
    }
What will do -
  1. Concatenate the user agent with their email adress and md5 it. This is their secret key, store as unique info as possible.
  2. Compare this key for each request and also just check if a session key is true.