Giter VIP home page Giter VIP logo

shares-counter's Introduction

Social Counter (v.1.0.4)

This simple PHP function allows the user to display the amount of times that an URL have been shared on different social networks. Right now it supports Facebook, Twitter, Google Plus and LinkedIn.

This repository contains the open source PHP and is licensed under the Apache Licence, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html).

The same source if offered in two versions:

  • Functional Programming (sharescounter.php)
  • OOP Programming (class_sharecounter.php)

If you are using Wordpress, you should use the WPShare-Counter that was created based on this code.: https://github.com/phalkmin/WPShare-Counter

Usage (Functional Version)

First you need to add the function into your PHP code, then you just need to call the function directly into the code:

<?php sharesCounter(); ?>

You can pass some parameters on the function if you don't want to get counts from any specific network or if you want to pass an url that is not the current page.

The parameters are (in order of usage):

  • $url (string): defaults to current url.
  • $echo (bool): if false it will just return the sum as a variable, if true it echoes the results. Defaults to true.
  • $facebook (bool): defaults to true.
  • $twitter (bool): defaults to true.
  • $gplus (bool): defaults to true.
  • $linkedin (bool): defaults to true.
  • $vk (bool): defaults to true.

For example, if you want to remove linkedin from the list, you can:

<?php sharesCounter('', true, true, true, true, false, true); ?>

To use the code in Wordpress for any specific post, you can simply add (within the loop):

<?php sharesCounter( get_permalink() ); ?>

You can also return the result as a variable instead of echoing the number:

<?php $variable = sharesCounter('', false); ?>

Usage (OOP Version)

First you need to add the function into your PHP code, then you just need to call the function directly into the code:

<?php 
	$the_counter = new ShareCounter();
	$the_counter->echoAllSharesCount();
?>

You can use some methods of the class if you don't want to get counts from any specific network or if you want to pass an url that is not the current page.

The methods are:

  • setURL($url (string)): Set the URL used with the object, if empty, get automatically the URL of the requested page.
  • getURL() (string): Return the URL used with the object
  • getFacebookSharesCount() (int): Return the number of shares of the URL in Facebook.
  • getTwitterSharesCount() (int): Return the number of shares of the URL in Twitter.
  • getGooglePlusSharesCount() (int): Return the number of shares of the URL in Google Plus.
  • getLinkedinSharesCount() (int): Return the number of shares of the URL in Linkedin.
  • getSharesCount($services) (int): Return the number of shares of the URL in services specified by the array $services.
  • getAllSharesCount(): Return the sum of number of shares of the URL in all services supported by this script
  • echoAllSharesCount(): Just echo the sum of number of shares of the URL in all services supported by this script

For example, if you want to remove linkedin from the list, you can:

<?php 
	$count = new SharesCounter();
	echo $count->getSharesCount(array("facebook", "twitter","google plus"));
?>

To use the code in Wordpress for any specific post, you can simply add (within the loop):

<?php 
	$count = new SharesCounter( get_permalink() );
	$count->echoAllSharesCount();
?>

You can also return the result as a variable instead of echoing the number:

<?php 
	$the_counter = new SharesCounter( '' );
	$count = $the_counter->getAllSharesCount();
?>

Contributing

When commiting, keep all lines to less than 80 characters, and try to follow the existing style.

Before creating a pull request, squash your commits into a single commit.

Add the comments where needed, and provide ample explanation in the commit message.

shares-counter's People

Contributors

fjorgemota avatar syncxplus avatar gusfune avatar kosolapov avatar

Stargazers

Kasparas avatar Yehezkiel Sentosa avatar svngit avatar Angus H. avatar  avatar Ionel Rohneanu avatar JT5D avatar Joel Garcia Jr avatar  avatar Sebastian Ortiz avatar Clint Landrum avatar Mustafa Uysal avatar  avatar

Watchers

Paulo H. avatar Clint Landrum avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.