<?php
/**
 * Created by PhpStorm.
 * User: IOAN
 * Date: 8/21/2016
 * Time: 9:56 PM
 */



class SocialShare
{
    public $social_networks = array(
        'facebook' => 'Facebook',
        'google' => 'Google+',
        'twitter' => 'Twitter',
        'linkedin' => 'LinkedIn',
        'pinterest' => 'Pinterest',
    );

    protected $attr;


    public function __construct($attr) {
        $this->attr = $attr;
    }

    public function get_share_links() {
        $links  = array();

        foreach($this->social_networks as $network => $network_name) {
            $network_info = $this->$network();
            //$link [] = $network_info['url'] . '?';
            $link_params = array();
            $params = $network_info['params'];
            foreach($params as $qs=>$attr) {
                if(is_numeric($attr)) {
                    $link_params [] = $qs . '=true';
                }
                else {
                    $link_params [] = $qs . '=' . urlencode($this->attr[$attr]);
                }
            }

            $link = $network_info['url'] . '?' . (implode('&', $link_params));
            $links [$network] = array(
                'url' => $link,
                'name' => $network_name
            );
        }

        return $links;
    }

    public function facebook() {
        return array(
            'url' => 'https://www.facebook.com/sharer/sharer.php',
            'params' => array(
                'u' => 'url'
            )
        );
    }

    public function google() {
        return array(
            'url' => 'https://plus.google.com/share',
            'params' => array(
                'url' => 'url'
            )
        );
    }

    public function linkedin() {
        return array(
            'url' => 'https://www.linkedin.com/shareArticle',
            'params' => array(
                'mini' => 1,
                'url' => 'url',
                'title' => 'title'
            )
        );
    }

    public function pinterest() {
        return array(
            'url' => 'https://www.pinterest.com/pin/create/button/',
            'params' => array(
                'url' => 'url',
                'description' => 'description'
            )
        );
    }

    public function twitter() {
        return array(
            'url' => 'https://twitter.com/intent/tweet/',
            'params' => array(
                'url' => 'url',
                'text' => 'title'
            )
        );
    }


}