Giter Club home page Giter Club logo

facebook-link-preview's Introduction

Facebook-Like Link Preview (no longer maintained)

Disclaimer: I will no longer maintain this project because it's an old code and hard to maintain, but I'm exporting this logic to Angularjs and Bootstrap. I believe this a great solution for an easy comprehension of the code and will allow the project to evolve even further. You can found this new project here >> https://github.com/LeonardoCardoso/Link-Preview

Build Status

Developed by @LeonardoCardoso.

How this works

The algorithm keeps tracking what you are typing in the status field and through regular expressions identifies a url. Thereafter, the text is in the field is passed to PHP that does all the work to analyze all the source code of the url found. If you enter more than one url, it will consider that the first one is the more relevant and it will create a preview. Once the source code of the url is obtained, regular expressions begin to seek out and capture relevant information on it. This information is basically the title page, the images contained therein, and a brief description of the content covered in the page.

Link Preview

=======

HTTP Server

  • Apache (must support mod_php)

How to add it to your project

1 • Scripts

	<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>

	<script src='js/linkPreview.js' ></script>

 	<!-- 
		If you are saving and fetching results from database using FLP,
		you can customize the layout on this script
	-->
	<script src='js/linkPreviewRetrieve.js' ></script>

2 • Stylesheets

	<!-- 
		This stylesheet is provides the layout of Facebook's former textarea. 
		You can totally customize this!
	-->
	<link rel="stylesheet" type="text/css" href="css/linkPreview.css" />

3 • Configuration

Just create your own textarea (or multiple textareas) and bind it to jQuery like this:

	<script>
		$(document).ready(function() {
			$('#lp1').linkPreview();

			// changing placeholder
			$('#lp2').linkPreview({placeholder: "Second Field"});
			
			// bind to a tag the results brought from database
			$('#retrieveFromDatabase').linkPreviewRetrieve();
		});
	</script>
	

4 • Database

To custom your database configurations, you just need to change the following values in php/classes/Database.php

	$host = "localhost";
    $user = "";
    $password = "";
    $database = "linkpreview";

Make sure your columns are the same as those ones in linkpreview.sql.

Result Format

	{  
	   "title":"title",
	   "url":"original url",
	   "pageUrl":"page url",
	   "canonicalUrl":"cannonical url",
	   "description":"description",
	   "images": "img1|img2|...",
	   "video":"yes|no",
	   "videoIframe":"video iframe if it is video"
	}

Parameters

option default value possible values function
imageQuantity -1 any integer set the max amount of images to be brought (-1 for illimited)
placeholder What's in your mind any string set the placeholder of textarea

Important

Make sure the library php5-curl is installed and enabled on the server, either locally or remotely.

  • Linux
$ sudo apt-get install php5-curl
$ sudo service apache2 restart
$ sudo port install php5-curl 
$ sudo apachectl restart

Contact

Contact me either by Twitter @leocardz or emailing me to [email protected].

License

Copyright (c) 2014 Leonardo Cardoso (http://leocardz.com)
Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.

facebook-link-preview's People

Contributors

clicman avatar dragonexpert avatar jeffque avatar leonardocardoso avatar manni-s avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.