• This repository has been archived on 02/Dec/2019
  • Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

AngularJS + Bootstrap Version of https://github.com/LeonardoCardoso/Facebook-Link-Preview

Link Preview

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.

Right Left
Preview Left
Bottom Top
Bottom Top
Gallery Video
Preview Gallery Preview Video

=======

HTTP Server

  • Apache (must support mod_php)

How to add it to your project

1 • Stylesheets

	<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    	
	<link rel="stylesheet" type="text/css" href="src/link-preview/css/link-preview.css" />

2 • Scripts

	<script src="https://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js" type="text/javascript"></script>
        
	<script src="src/link-preview/js/link-preview.js" type="text/javascript"></script>
	
    <!-- Include this script below if you want to retrieve the posts inserted to database -->
    <script src="src/link-preview/js/link-preview-database.js" type="text/javascript"></script>

3 • Configuration

Add the link preview module as a dependency to your application module:

	var app = angular.module('App', ['linkpreview'])

Add the directive inside your controller html:

	<link-preview placeholder="What's in your mind?" />

Attributes

att var default value possible values
type type right right, left, bottom, top (text position)
amount imageAmount -1 any integer
btext buttonText Post any string
bclass buttonClass primary default, primary, success, info, warning, danger, link
cbtext cancelButtonText Cancel any string
cbclass cancelButtonClass danger default, primary, success, info, warning, danger, link
ltext loadingText Loading any string
limage loadingImage empty.png any image url
placeholder placeholder an empty string any string
ttext thumbnailText Choose a thumbnail any string
nttext noThumbnailText No thumbnail any string
tpage thumbnailPagination %N of %N any string, %N is the number reference of pagination
dtitle defaultTitle Enter a title any string
ddescription defaultDescription Enter a description any string
	<link-preview 
			type="" 
			ttext="" 
			tpage="" 
			placeholder="" 
			amount="" 
			limage="" 
			ltext="" 
			btext="" 
			bclass=""
			ctext="" 
			cclass=""
			dtitle="" 
			ddescription="" />

4 • Database

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

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

Additionally, the way I used to retrieve the data was creating a controller link-preview-database.js which you can include the file somehow in your project or you can its content to yours.

	app.controller('MyControllerDatabase', ['$scope', '$http', function ($scope, $http) {
    
        $scope.databasePosts = [];
            $scope.retrieveFromDatabase = function () {
        
                // You must insert in your page a div with the posts retrieved from database. Just like the posts div
                // on template html files
        
                var url = 'src/link-preview/php/retrieve.php';
                $http({
                    url: url,
                    method: "GET",
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
                }).success(function (data, status, headers, config) {
        
                    for (var i = 0; i < data.length; i++) {
                        data[i].video = data[i].videoIframe !== "";
                        data[i].showIframe = false;
                        data[i].textHTML = $sce.trustAsHtml(data[i].text);
                        data[i].descriptionHTML = $sce.trustAsHtml(data[i].description);
                        data[i].videoIframeHTML = $sce.trustAsHtml(data[i].videoIframe);
                        console.log(data[i]);
                    }
        
                    $scope.databasePosts = data;
        
                });
        
            };
        
            $scope.deletePosted = function (post, $index) {
                $scope.posts.splice($index, 1);
            };
        
            $scope.imageAction = function (post) {
        
                if (post.video == false) {
                    window.open(post.pageUrl, '_blank');
                } else {
                    post.showIframe = true;
                }
        
            };
        
            $scope.hidePlay = function (post) {
                return post.video == false || post.showIframe == true;
            };
        
            $scope.layoutWithoutImage = function (post) {
                return post.image == '' || post.showIframe == true;
            };
        
            $scope.layoutWithImage = function (post) {
                return post.image != '' || (post.video == true && post.showIframe == false);
            };

    
    }]);

Also, check the file database-template.php to see an example of how to display the data retrieved from database.

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

Result Format

	{  
	   "title":"title",
	   "url":"original url",
	   "pageUrl":"page url",
	   "canonicalUrl":"canonical url",
	   "description":"description",
	   "images": ["array of images"],
	   "image": "first image of images",
	   "video":"true|false",
	   "videoIframe":"video iframe, if it is a video"
	}

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

Also where there is 'src/link-preview/' as part of a path of a Javascript, CSS or image file, you must change to the path on your server.

Information and Contact

Developed by @LeonardoCardoso.

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

Related Projects

License

MIT

More Repositories

1

SwiftLinkPreview

It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.
Swift
1,372
star
2

NFDownloadButton

Revamped Download Button. It's kinda a reverse engineering of Netflix's app download button.
Swift
434
star
3

Android-Link-Preview

It makes a preview from an url, grabbing all the information such as title, relevant texts and images. This a version for Android of my web link preview https://github.com/LeonardoCardoso/Link-Preview
Java
420
star
4

SectionedSlider

iOS 11 Control Center Slider
Swift
369
star
5

AudioIndicatorBars

AIB indicates for your app users which audio is playing. Just like the Podcasts app.
Swift
288
star
6

Facebook-Link-Preview

Go to >> https://github.com/LeonardoCardoso/Link-Preview
PHP
131
star
7

Animated-Expanding-ListView

Animated Expanding ListView provides a fancy animation on expanding or collapsing the content of a listview item.
Java
130
star
8

SendIndicator

Yet another task indicator
Swift
62
star
9

InitMacro

Swift
41
star
10

BLE

Swift
28
star
11

gsrd

GitHub Starred Repos Downloader
Ruby
26
star
12

Colorblinding

An extension for Google Chrome (and Chromium) that simulates the website as a color vision impaired person would see.
JavaScript
25
star
13

Multitouch-Test

A simple app to test the touch of your device. It measures and shows how accurate is the touch of your device, how many touches it supports, and there are some options to personalize the exhibition.
Java
17
star
14

BedtimeClock

Swift
14
star
15

RevealTextField

Simple extension to add a reveal button to your boring UITextField
Swift
14
star
16

Sorting-Algorithms

Quick set of sorting algorithms using Java.
Java
11
star
17

UILabelSearchHighlighter

Swift
9
star
18

Unshorten-It

A simple, beautiful, fast and useful url unshortener with link preview.
Java
7
star
19

Multiple-Layout-ListView

Multiple Layout ListView
Java
7
star
20

UITableViewFiltering

Swift
6
star
21

Android-Audio-Recorder

A simple Android app to record an audio.
Java
6
star
22

Silence-Please

Control the ambient sound by a sound level limit. When it is exceeded, the "Silence Please" will alert!
Java
5
star
23

GitAliases

Some useful Git aliases to optimise your time
Shell
5
star
24

Genetic-Algorithm

This project is about the functionality of a genetic algorithm.
Java
5
star
25

Xcode-Snippets

4
star
26

Folder

Shell
3
star
27

Clipboarded

Have you ever copied an image but couldn't find a way to save it to the Camera Roll?! That's why!
Swift
3
star
28

Movement

A funny way to interact with the mouse
JavaScript
3
star
29

AnnotationsOff

An extension for Google Chrome (and Chromium) that removes all unwanted annotations in Youtube videos.
JavaScript
3
star
30

mvn-repo

A simple maven repository
3
star
31

Trees

Set of many algorithms related to Trees with lexicographical ordering.
Java
3
star
32

What-coding-style-is-Leo-Using

For everyone who wants to know more about how I'm structuring my projects.
3
star
33

Separate-Compilation-Unit

Single Compilation Unit, also known as Separate Compilation.
C++
3
star
34

i18n-PHP-AngularJS

Easy i18n localization with PHP and AngularJS
PHP
2
star
35

Hashing-Algorithms

It's designed to keep insertion, deletion and search with O(1) complexity.
Java
2
star
36

Rotate-and-Scale-jQuery

A mix of Rotate and Scale.
JavaScript
2
star
37

dotfiles

My .files
Shell
2
star
38

Pix-Color-Analyzer

Image pixel color analyzer
Java
2
star
39

Priority-Queue

Set of many algorithms related to Priority Queues.
Java
2
star
40

gitcase

Share your complete GitHub contribution graph
CSS
2
star
41

Scale-jQuery

Scale whatever elements you want with jQuery
JavaScript
2
star
42

Rotate-jQuery

Rotate whatever elements you want with jQuery
HTML
2
star
43

Android-Audio-Preview

A simple app to stream a song by url for pre(view|listen)ing it.
Java
2
star
44

Android-Custom-Font

Two ways to use custom fonts without memory leak, even if you use in a ListView.
Java
2
star
45

What-terminal-is-Leo-using

For everyone who wants to know more about the terminal I'm using
2
star
46

Font-Awesomed-Android

Example code of how to use Font Awesome on Android native and programatically
Java
1
star
47

Primitive-Recursive-Functions

A class with the common Math operations using recursion.
Java
1
star
48

LeonardoCardoso

1
star