<repo_name>karliuka/m1.Share<file_sep>/app/code/community/Faonni/Share/Model/Resource/Pinterest.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Faonni_Share_Model_Resource_Pinterest
	extends Faonni_Share_Model_Resource_Abstract
{
    /**
     * The token URL
	 *
     * @var string
     */
	protected $_shareUrl = 'http://pinterest.com/pin/create/link/';
	
    /**
     * The count URL
	 *
     * @var string
     */
	protected $_countUrl = 'http://api.pinterest.com/v1/urls/count.json?callback=count&url=';
	
    /**
     * The URL used when authenticating a user after the question mark ?
	 *
     * @var array
     */	
	protected $_shareQuery = array(
	
    /**
     * The URL of the page to share. This value should be url encoded
	 *
     * @var string
     */	
	'url' => '',
	
    /**
     * The image of the page to share. This value should be url encoded
	 *
     * @var string
     */	
	'media' => '',	
	
    /**
     * The description of the page to share. This value should be url encoded
	 *
     * @var string
     */	
	'description' => '',		
	);

    /**
     * Get Full Share URL
	 *
     * @return string
     */	
	public function getShareUrl()
	{	
		$this->_shareQuery = array_merge(
			$this->_shareQuery, array(
				'url' => $this->getShareObject()->getUrl(),
				'media' => htmlspecialchars($this->getShareObject()->getImage()),
				'description' => $this->getShareObject()->getTitle()
			)
		);
		return $this->_shareUrl . '?' . http_build_query($this->_shareQuery);
	}
	
    /**
     * Get count
	 *
     * @return int
     */	
	public function loadCount($url)
	{	
		$response = $this->request($this->_countUrl . urlencode($url));
		if ($response->isSuccessful()){
			$data = preg_replace('#^count\((.*)\)$#si', '\\1', $response->getBody());
			$json = json_decode($data, true);
			if(isset($json['count'])) return intval($json['count']);
		}
		return null;	
	}
}<file_sep>/app/code/community/Faonni/Share/Model/Resource/Provider/Collection.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Faonni_Share_Model_Resource_Provider_Collection 
	extends Varien_Data_Collection
{
    /**
     * Social share setting path
	 *
     * @var string
     */
	const XML_PROVIDER_DATA = 'faonni_share';
	
    /**
     * Load data
	 *
     * @param bool $printQuery
     * @param bool $logQuery
     * @return Faonni_Share_Model_Resource_Provider_Collection
     */
    public function load($printQuery=false, $logQuery=false)
    {
        if(empty($this->_items)){
			$items = Mage::getStoreConfig(self::XML_PROVIDER_DATA);
            foreach ($items as $group => $item){ 
				if('common' == $group) continue;
				$provider = Mage::getModel('faonni_share/provider', $item);
				if($provider->isAvailable()) $this->addItem($provider);
            }
        }
		usort($this->_items, array($this, 'uSort'));		
        return $this;
    }
	
	/**
	 * usort array
	 *
	 * @param string $a
	 * @param string $b 
	 * @return int
	 */		
	public function uSort($a, $b)
    {
		if (!isset( $a['sort']) || !isset( $b['sort'])) return 0;
		if ($a['sort'] == $b['sort']) return 0;
		return ($a['sort'] < $b['sort']) ? -1 : 1;
    }
	
    /**
     * Convert items array to array for select options
	 *
     * @param string $valueField
     * @param string $labelField
     * @return array
     */
    protected function _toOptionArray($valueField='id', $labelField='title', $additional=array())
    {
        $res = array();
        $additional['value'] = $valueField;
        $additional['label'] = $labelField;

        foreach ($this as $item) {
            foreach ($additional as $code => $field) {
                $data[$code] = $item->getData($field);
            }
            $res[] = $data;
        }
        return $res;
    }	
}
<file_sep>/README.md
Magento. 
Let your users share via their accounts on popular social networks such as Facebook, Twitter and etc.
<file_sep>/app/code/community/Faonni/Share/Model/Provider.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Faonni_Share_Model_Provider
	extends Varien_Object
{
    /**
     * Resource model
	 *
     * @var Faonni_Share_Model_Resource_Abstract
     */
    protected $_resource;

    /**
     * Collection model
	 *
     * @var Faonni_Share_Model_Resource_Provider_Collection
     */
    protected $_collection;

    /**
     * Check whether provider can be used
	 *
     * @return bool
     */
    public function isAvailable()
    {
		return (bool)$this->getActive();
    }
	
    /**
     * Get count
	 *
     * @return int
     */
    public function getCount()
    {
        return $this->hasData('count') 
				? (int)$this->getData('count') 
				: 0;
    }
	
    /**
     * Get Provider resource model
	 *
     * @return Faonni_Share_Model_Resource_Abstract
     */
    public function getResource()
    {
        if (null === $this->_resource){
            $this->_resource = Mage::getResourceModel('faonni_share/' . $this->getId());
        }
        return $this->_resource;
    }
	
    /**
     * Get Full Share URL
	 *
     * @return string
     */	
	public function getShareUrl()
	{
		return $this->getResource()->getShareUrl();
	}	
	
    /**
     * Load count
	 *
     * @return int|bool
     */	
	public function loadCount($url)
	{
		return $this->getResource()->loadCount($url);
	}	
	
    /**
     * Get collection instance
	 *
     * @return Faonni_Share_Model_Resource_Collection
     */
    public function getCollection()
    {
        if (null === $this->_collection){
			$this->_collection = Mage::getResourceModel('faonni_share/provider_collection');
		}
		return $this->_collection;
    }

    /**
     * Load Provider data
	 *
     * @param string $id
     * @return Faonni_Share_Model_Provider
     */
    public function load($id)
    {
        return $this->getCollection()->getItemByColumnValue('id', $id);
    }	
}<file_sep>/app/code/community/Faonni/Share/Model/Resource/Summary/Collection.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Faonni_Share_Model_Resource_Summary_Collection 
	extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
    /**
     * Set model name for collection items
	 *
     * @return void
     */
	public function _construct()
	{
		$this->_init('faonni_share/summary');
	}
	
    /**
     * Add collection filters by share entity id
	 *
     * @param mixed $entityId
     * @return Faonni_Share_Model_Resource_Summary_Collection
     */
    public function addEntityIdFilter($entityId)
    {
        if ($entityId && is_numeric($entityId)){
			$this->getSelect()->where('main_table.share_entity_id = ?', $entityId);
		}       
        return $this;
    }
	
    /**
     * Add collection filters by share entity type id
	 *
     * @param mixed $entityTypeId
     * @return Faonni_Share_Model_Resource_Summary_Collection
     */
    public function addEntityTypeIdFilter($entityTypeId)
    {
        if ($entityTypeId && is_numeric($entityTypeId)){
			$this->getSelect()->where('main_table.entity_type_id = ?', $entityTypeId);
		}       
        return $this;
    }
	
    /**
     * Add collection filters by store id
	 *
     * @param int $storeId
     * @return Faonni_Share_Model_Resource_Summary_Collection
     */
    public function addStoreIdFilter($storeId)
    {
        if ($storeId && is_numeric($storeId)){
			$this->getSelect()->where('main_table.store_id = ?', $storeId);
		}
        return $this;
    }	
}<file_sep>/app/code/community/Faonni/Share/Model/Summary.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Faonni_Share_Model_Summary 
	extends Mage_Core_Model_Abstract
{
    /**
     * Set resource names
	 *
     * @return void
     */
    protected function _construct()
	{
       $this->_init('faonni_share/summary');
    }
	
    /**
     * Load an object by field
	 *
     * @return Faonni_Share_Model_Summary
     */	
	public function loadByFields($fields)
    {
        $this->getResource()->loadByFields($this, $fields);
		return $this;
    }
	
    /**
     * Load Unite count group by provider
	 *
     * @param int $entityTypeId
     * @param int $entityId
     * @param int $providerId	 
     * @return int
     */		
	public function getUniteCount($entityTypeId, $entityId, $providerId)
    {
        return $this->getResource()->getUniteCount($entityTypeId, $entityId, $providerId);
    }
	
    /**
     * Load Summary count
	 *
     * @param int $entityTypeId
     * @param int $entityId 
     * @return int
     */		
	public function getSummaryCount($entityTypeId, $entityId)
    {
        return $this->getResource()->getSummaryCount($entityTypeId, $entityId);
    }	
}<file_sep>/app/code/community/Faonni/Share/sql/faonni_share_setup/install-1.0.2.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
$installer = $this;
$installer->startSetup();

/**
 * Create table 'faonni_share/summary'
 */
$table = $installer->getConnection()
    ->newTable($installer->getTable('faonni_share/summary'))
	->addColumn('entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
		'identity'  => true,
		'unsigned'  => true,
		'nullable'  => false,
		'primary'   => true,
		), 'Entity Id')	
    ->addColumn('entity_type_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
		'unsigned'  => true,
		'nullable'  => false,
        ), 'Entity Type Id')
    ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
        'nullable'  => false,
		'unsigned'  => true,
        ), 'Store Id')		
    ->addColumn('share_entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
		'unsigned'  => true,
		'nullable'  => false,
        ), 'Entity Id')			
    ->addColumn('provider_id', Varien_Db_Ddl_Table::TYPE_TEXT, 50, array(
        'nullable'  => false,
        ), 'Provider Id')	
    ->addColumn('count', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
		'unsigned'  => true,
		'nullable'  => false,
        ), 'Share Count')
		
	->addIndex($installer->getIdxName('faonni_share/summary', array('entity_type_id')),
        array('entity_type_id'))
	->addIndex($installer->getIdxName('faonni_share/summary', array('store_id')),
        array('store_id'))			
	->addIndex($installer->getIdxName('faonni_share/summary', array('provider_id')),
        array('provider_id'))
	->addIndex($installer->getIdxName('faonni_share/summary', array('share_entity_id')),
        array('share_entity_id'))			

	->addIndex($installer->getIdxName('faonni_share/summary', array('entity_type_id', 'store_id', 'share_entity_id', 'provider_id'), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE),
        array('entity_type_id', 'store_id', 'share_entity_id', 'provider_id'), array('type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE))	
		
    ->addForeignKey($installer->getFkName('faonni_share/summary', 'entity_type_id', 'eav/entity_type', 'entity_type_id'),
        'entity_type_id', $installer->getTable('eav/entity_type'), 'entity_type_id',
        Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
		
	->addForeignKey($installer->getFkName('faonni_share/summary', 'store_id', 'core/store', 'store_id'),
        'store_id', $installer->getTable('core/store'), 'store_id',
        Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE);	

$installer->getConnection()->createTable($table);
$installer->endSetup();<file_sep>/app/code/community/Faonni/Share/controllers/SummaryController.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Faonni_Share_SummaryController 
	extends Mage_Core_Controller_Front_Action
{
    /**
     * update action
     */
    public function updateAction()
    {
		$result = array('error' => true);
		
		$id = $this->getRequest()->getPost('id', false);
		$type = $this->getRequest()->getPost('type', false);
		$entityId = (int)$this->getRequest()->getPost('entity', false);
		
		if($id && $type && $entityId){
			
			$shareObject = new Varien_Object(array('id' => $entityId, 'type' => $type));
			Mage::dispatchEvent('faonni_share_summary_update_before', array('share_object' => $shareObject));
			
			if($shareObject->getEntityTypeId()){
				$provider = Mage::getModel('faonni_share/provider')->load($id);
				if($provider && $provider->isAvailable()){
					$count = (int)$provider->loadCount($shareObject->getUrl());
					
					$data = array(
						'entity_type_id'  => $shareObject->getEntityTypeId(),
						'store_id'        => Mage::app()->getStore()->getId(),
						'share_entity_id' => $entityId,
						'provider_id'     => $provider->getId()
					);
					
					$summary = Mage::getModel('faonni_share/summary')->loadByFields($data);
					if(!$summary->getId()){
						$summary = Mage::getModel('faonni_share/summary');
						$summary->addData($data);
					}
					
					$summary->setCount($count);
					$summary->save();
					
					if(Mage::helper('faonni_share')->isSummaryCount()){
						$id = 'summary';
						$count = (int)$summary->getSummaryCount($shareObject->getEntityTypeId(), $entityId);
					}elseif(Mage::helper('faonni_share')->isUniteCount()){
						$count = (int)$summary->getUniteCount($shareObject->getEntityTypeId(), $entityId, $id);
					}
					
					$result = array('error' => false, 'count' => $count, 'id' => $id);
				}
			}
		}
		$this->getResponse()->setBody(json_encode($result));
    }	
}<file_sep>/app/code/community/Faonni/Share/Block/Button.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Faonni_Share_Block_Button
	extends Mage_Core_Block_Template
{
    /**
     * Collection model
	 *
     * @var Faonni_Share_Model_Resource_Provider_Collection
     */
    protected $_collection;
	
	/**
	 * Check unite counts
	 *
	 * @return bool
	 */		
	public function isSummaryCount()
	{
		return Mage::helper('faonni_share')->isSummaryCount();
	}	
	
    /**
     * Get provider collection
	 *
     * @return Faonni_Share_Model_Resource_Collection
     */
    public function getCollection()
    {
        if (null === $this->_collection){
			$this->_collection = Mage::getResourceModel('faonni_share/provider_collection');
			$summary = Mage::registry('share_summary');
			
			foreach($this->_collection as $provider){
				$id = $provider->getId();
				if (isset($summary[$id])) $provider->setCount($summary[$id]);
			}
			//print_r($summary);
		}
		return $this->_collection;
    }
	
    /**
     * Get Share object 
	 *
     * @return object
     */	
	public function getShareObject()
	{
		$object = Mage::registry('faonni_share');
		if(!$object){
			Mage::throwException($this->__('Empty share object.'));
		}
		return $object;
	}	
	
	/**
	 * Return Js Config active providers
	 *
	 * @return array
	 */		
	public function getJsConfig()
	{
		foreach($this->_collection as $provider){
			$provider->setUrl($provider->getShareUrl());
		}
		$config = $this->getCollection()->toArray(array('id', 'url', 'width', 'height'));
		$config['url'] = Mage::getUrl('share/summary/update');
		
		return json_encode($config);
	}
	
    /**
     * Render block HTML
     *
     * @return string
     */
    protected function _toHtml()
    {
        if (!Mage::helper('faonni_share')->isEnabled()) {
            return '';
        }
        return parent::_toHtml();
    }	
}<file_sep>/app/code/community/Faonni/Share/Model/Observer.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Faonni_Share_Model_Observer
{
    /**
     * Set share object
	 *
     * @param Varien_Event_Observer $observer
     * @return Faonni_Share_Model_Observer
     */
    public function setShareObject($observer)
    {
		$product = $observer->getEvent()->getProduct();
		$helper = Mage::helper('faonni_share');
		
		if($product && $helper->isEnabled()){

			if(false !== ($size = $helper->getSize())){
				$image = Mage::helper('catalog/image')->init($product, 'image')
					->resize($size['width'], $size['heigth']);
			} else $image = Mage::helper('catalog/image')->init($product, 'image');

			$object = new Varien_Object(array(
				'id'          => $product->getId(),
				'title'       => $product->getName(),
				'url'         => $product->getUrlModel()->getUrl($product, array('_ignore_category' => true)),
				'image'       => $image,
				'description' => $product->getShortDescription(),
				'type'        => 'product'
			));
			
			Mage::register('faonni_share', $object);
		}
        return $this;
    }
	
    /**
     * Set Summary Collection
	 *
     * @param Varien_Event_Observer $observer
     * @return Faonni_Share_Model_Observer
     */
    public function setSummaryCollection($observer)
    {
		if(!Mage::helper('faonni_share')->isEnabled()){
			return $this;
		}
		
		$product = $observer->getEvent()->getProduct();
		if($product){
			$store = Mage::app()->getStore();
			$unite = Mage::helper('faonni_share')->isUniteCount();
			
			$collection = Mage::getResourceModel('faonni_share/summary_collection')
				->addEntityTypeIdFilter($product->getResource()->getTypeId())
				->addEntityIdFilter($product->getId());

			if($unite){
				$collection
					->addExpressionFieldToSelect('unite', 'SUM({{main_table.count}})', 'main_table.count')
					->getSelect()->group('main_table.provider_id');
			} else {
				$collection->addStoreIdFilter($store->getId());
			}

			$summary = array();
			foreach($collection as $share){
				$count = $unite ? $share->getUnite() : $share->getCount();
				$summary[$share->getProviderId()] = $count;
			}
			Mage::register('share_summary', $summary);
			//print_r(Mage::app()->getStore()->getConfig('faonni_share'));
		}
        return $this;
    }
	
    /**
     * get Entity Type
	 *
     * @param Varien_Event_Observer $observer
     * @return Faonni_Share_Model_Observer
     */
    public function getEntityType($observer)
    {
		if(!Mage::helper('faonni_share')->isEnabled()){
			return $this;
		}
		
		$object = $observer->getEvent()->getShareObject();
		if($object && 'product' == $object->getType() && $object->getId()){
			$product = Mage::getModel('catalog/product')->load($object->getId());
			$object->setEntityTypeId(
				$product->getResource()->getTypeId()
			);
			$object->setUrl(
				$product->getUrlModel()->getUrl($product, array('_ignore_category' => true))
			);
		}
        return $this;
    }	
}<file_sep>/app/code/community/Faonni/Share/Helper/Data.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Faonni_Share_Helper_Data 
	extends Mage_Core_Helper_Abstract
{
    /**
     * Social share active setting path
	 *
     * @var string
     */
	const XML_SHARE_ACTIVE = 'faonni_share/common/active';
	
    /**
     * Social share image size setting path
	 *
     * @var string
     */
	const XML_SHARE_IMAGE_SIZE = 'faonni_share/common/size';
	
    /**
     * Social share unite count setting path
	 *
     * @var string
     */
	const XML_SHARE_UNITE = 'faonni_share/common/unite';
	
    /**
     * Social share summary count setting path
	 *
     * @var string
     */
	const XML_SHARE_SUMMARY = 'faonni_share/common/summary';
	
	/**
	 * Check whether Share can be used
	 *
	 * @return bool
	 */	
 	public function isEnabled()
	{
		return (bool)Mage::getStoreConfig(self::XML_SHARE_ACTIVE);
	}
	
	/**
	 * Check unite counts
	 *
	 * @return bool
	 */	
 	public function isUniteCount()
	{
		return (bool)Mage::getStoreConfig(self::XML_SHARE_UNITE);
	}
	
	/**
	 * Check unite counts
	 *
	 * @return bool
	 */		
	public function isSummaryCount()
	{
		return (bool)Mage::getStoreConfig(self::XML_SHARE_SUMMARY);
	}
	
    /**
     * Retrieve image size
	 *
     * @return array|bool
     */
    public function getSize()
    {
        $size = explode('x', strtolower(Mage::getStoreConfig(self::XML_SHARE_IMAGE_SIZE)));
		
        if(sizeof($size) == 2){
            return array(
                'width'  => ($size[0] > 0) ? $size[0] : null,
                'heigth' => ($size[1] > 0) ? $size[1] : null,
            );
        }
        return false;
    }	
}<file_sep>/app/code/community/Faonni/Share/Model/Resource/Abstract.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
abstract class Faonni_Share_Model_Resource_Abstract
	extends Varien_Object
{
    /**
     * The share URL
	 *
     * @var string
     */
	protected $_shareUrl;

	/**
     * The count URL
	 *
     * @var string
     */
	protected $_countUrl;
	
    /**
     * Get Share Provider URL
	 *
     * @return string
     */	
	abstract public function getShareUrl();
	
    /**
     * Get Share object
	 *
     * @return object
     */	
	public function getShareObject()
	{
		$object = Mage::registry('faonni_share');
		if(!$object){
			Mage::throwException(Mage::helper('faonni_share')->__('Empty share object.'));
		}
		return $object;
	}
	
    /**
     * request
	 *
     * @return object
     */	
	public function request($url)
	{
		$client = new Zend_Http_Client($url, array(  
			'adapter'     => 'Zend_Http_Client_Adapter_Curl',  
			'curloptions' => array(CURLOPT_SSL_VERIFYPEER => false),  
		));
		return $client->request(Zend_Http_Client::GET);
	}		
}<file_sep>/app/code/community/Faonni/Share/Model/Resource/Summary.php
<?php
/**
 * Faonni
 *  
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade module to newer
 * versions in the future.
 * 
 * @package     Faonni_Share
 * @copyright   Copyright (c) 2015 <NAME>(<EMAIL>) 
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
class Faonni_Share_Model_Resource_Summary 
	extends Mage_Core_Model_Resource_Db_Abstract
{
    /**
     * Set main entity table name and primary key field name
	 *
     * @return void
     */
    protected function _construct()
    {
        $this->_init('faonni_share/summary', 'entity_id');
    }
	
    /**
     * Load an object by multiple fields
	 *
     * @param object $summary Faonni_Share_Model_Summary
     * @param array $fields should be array('column_name'=>'value', 'colum_name'=>'value')
     * @return Faonni_Share_Model_Resource_Summary
     */	
	public function loadByFields(Faonni_Share_Model_Summary $summary, $fields)
    {
        $read = $this->_getReadAdapter();
		
		if ($read && is_array($fields)) 
		{
			$where = array();
			foreach ($fields as $field => $value) {
				$where[] = sprintf('%s=:%s', $field, $field);
			}
			
			$select = $read->select()
				->from($this->getMainTable())
				->where(implode(' AND ', $where));
				
			$data = $read->fetchRow($select, $fields);	
			
		    if ($data) {
                $summary->setData($data);
            }
		}
        $this->unserializeFields($summary);
        $this->_afterLoad($summary);

        return $this;
    }
	
    /**
     * Load Unite count group by provider
	 *
     * @param int $entityTypeId
     * @param int $entityId
     * @param int $providerId	 
     * @return int
     */	
    public function getUniteCount($entityTypeId, $entityId, $providerId)
    {
        $read = $this->_getReadAdapter();
		
        $select = $read->select()
            ->from($this->getMainTable(), array('count' => new Zend_Db_Expr('SUM(count)')))
			->where('entity_type_id = ?', $entityTypeId, Zend_Db::INT_TYPE)
            ->where('share_entity_id = ?', $entityId, Zend_Db::INT_TYPE)
			->where('provider_id = ?', $providerId, Zend_Db::INT_TYPE)
			->group('provider_id');
			
        return $read->fetchOne($select);
    }
	
    /**
     * Load Summary count
	 *
     * @param int $entityTypeId
     * @param int $entityId	 
     * @return int
     */	
    public function getSummaryCount($entityTypeId, $entityId)
    {
        $read = $this->_getReadAdapter();
		
        $select = $read->select()
            ->from($this->getMainTable(), array('count' => new Zend_Db_Expr('SUM(count)')))
			->where('entity_type_id = ?', $entityTypeId, Zend_Db::INT_TYPE)
            ->where('share_entity_id = ?', $entityId, Zend_Db::INT_TYPE)
			->group('share_entity_id');
			
        return $read->fetchOne($select);
    }	
}