edit

Tricks

Trickster's Tricks

1. Truncator

Truncate is a Text Truncator. It Truncates the text and enable you to add ellipses and see more ...see more or desired line at the end. For example:

The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those inter (...see more)

Just call Trickster and provide it with details of the given parameters.

1
2
Trickster::truncator('Supplied text is written here, can also be given in a variable; lets leave it simple.', 30, '(read more...)');
// Output: Supplied text is written here, (read more...)

2. Email Validator

Email Validator gives you the power of validating the email address by just a simple line of code:

1
Trickster::emailValid('someone@example.com');

With Trickster by your side you will not have to write the validation code again and again. Just mention the Facade of Trickster an the validation function that's it.

3. Slug Converter

Slug Converter makes your life easy for creating search engine friendly slug for your url.

For example: Text: Are search engines friendly to search engines?

SLUGish URL: example.com/are-search-engines-friendly-to-search-engines

It is really very simple with Trickster. Just call Trickster and specify the slug function, provide in the text and Ta-DA!

1
2
3
4
    Trickster::slug('Are search engines friendly to search engines?'); // Just One Line!
//-> OR
    $slug = 'Are search engines friendly to search engines?';
    $slug = Trickster::slug($slug); // That's it!

4. YouTube Embed

YouTube Embedding can never be more easier! Embed YouTube Videos without writing lines of code just tell the Trickster about it. Call Trickster by:

1
2
3
    Trickster::youtube('VIDEO URL', 'FRAME WIDTH', 'FRAME HEIGHT', 'FRAME THEME');
    //OR LEAVE EVERYTHING ELSE FOR DEFAULT VALUES, JUST PUT THE LINK
    Trickster::youtube('VIDEO URL');

DEFAULT VALUES:

Parameters Description Required Value
Video URL URL to the YouTube video YES NO
Frame Width Width of the video Frame NO 400
Frame Height Height of the Video frame NO 250
Frame Theme dark or light theme NO dark

5. Gravatar Grabber

This amazing trick helps you to easily get the gravatar in the desired size, with desired rating. Not only that, but it also helps you to set the desired default image in case the grabbing fails. Not yet finished, two more amazing features; allows you to set the option of returning only the url of the gravatar or even the gravatar with the whole <img /> tag and in case you want Trickster to return the whole img tag then you also have the option of setting desired attributes in an array (ex. below).

1
    Trickster::gravatar('example@email.com', '200', 'monsterid', 'r', 'true', array('class'=>'img-class', 'key'=>'value'));

The Parameters Explained:

  • Email Address: Just simple email address. NO DEFAULT, REQUIRED.
  • Size: Size of image in pixels. DEFAULT: 100, NOT REQUIRED.
  • Default image: Default Image like mm(mystery man), monsterid, identicon, wavatar, 404. DEFAULT: mm, NOT REQUIRED.
  • Rating: Image Max Rating (for ex. g, pg, r, x). DEFAULT: g, NOT REQUIRED.
  • <img />: Do you want full HTML image tag? This parameter should be supplied with boolean value (TRUE/FALSE). DEFAULT: false, NOT REQUIRED.
  • Key-Value Attributes: An array is to be passed to defined any special attributes required by the html image tag, if requested. NO DEFAULT, NOT REQUIRED

6. Extension Splitter

This simple trick splits the file extension of the file supplied as the parameter and returns it. Simply call the Trickster and provide the full file name, the trick will split the file ext. from the file name and return it.

1
    Trickster::getExtension('really-funny.image.jpg');

Finished? Not Yet!

7. Simple Social Analytics

This trick eases your life, seriously. Simple and easy it is to show your social counts with Trickster. Trickster's Simple Social Analytics shows the number of Shares or Comments over a specific URL on Facebook when the trick is executed.

Note: Twitter has been deprecated and removed in v2.1.0. As of 20th November 2015 there's no Tweet count API. Know More

  • Supported Social Networks:
    • Facebook
  • Returned Strings
    • Facebook
      • Share Count
      • Comment Count
1
2
3
    $fbAnalytics = Trickster::social('facebook', 'http://github.com/secrethash');
    echo $fbAnalytics->shares.' Shares of Github.com/secrethash';
    echo $fbAnalytics->comments.' Comments on Github.com/secrethash';

Output 1: 95457821 Shares of Github.com/secrethash Output 2: 59865231 Comments on Github.com/secrethash

(Don't be bothered about the numbers, they are just random :-P )

8. BB Code Engine

BB code engine makes it easy to convert the BB Code to HTML format. Easy to initialize, makes it unique.

1
2
    // If implemented directly in the  Blade View File.
    {!! Trickster::bbcode($user->bio) !!}

The Supported BB Codes Currently are:

BB Code Description Converted HTML
[b]...[/b] Bold Text <b>...</b>
[i]...[/i] Italics Text <i>...</i>
[u]...[/u] Underlined <u>...</u>
[img=url]alt[/img] Image Implementation. Where: url is the image url & alt is alternate text. <img src="#url" alt="Alternate Text" />
[youtube]id[/youtube] Youtube Embed. Where id is the Video ID of youtube video. YouTube video frame of width 400px & height 250px
[vimeo]id[/vimeo] Vimeo Embed. Where id is the Video ID of Vimeo video. Vimeo video frame of width 400px & height 250px
[p]...[/p] Paragraph. <p>...</p>
[br/] Line Break <br/>
[url=URL]ALT[/url] Adding a URL. Where: URL is the Target Link and ALT is the URL text to be shown. <a href="#url">Google</a>

9. Tags Sweeper

Tag sweeper is a unwanted tag remover trick. It easily removes the unwanted script tags from the provided string. In accordance to the BB Code Engine, Tag Sweeper Cleans the HTML <script></script> code and leaves the BB Code making the supplied text Clean and Safe.

1
    Trickster::clean($string);

10. Time Ago

Time ago is a wonderful way of displaying the post time. You can use the Trickster's Facade Trickster to convert easily the provided Time & Date to Time Ago. The default format for this is Y-m-d H:i:s. In simple words 1996-07-30 21:52:30, Year-Month-Day Hour:Min:Sec

For example: This repository was created 2 months ago

Trick:

1
    Trickster::timeAgo('1996-07-30 21:52:30');

11. Cipher

Cipher enables you to encrypt any provided string of plain text to convert into Encrypted text form. Any PHP supported algorithm can be provided to Cipher to encrypt it. You can also encrypt a string and add a Salt to make it more secure. One will need the Salt to decrypt it.

1
    Trickster::encryptString('SHA1', 'Text to Encrypt', 'Desired Salt');

12. Vimeo Video Embed

Vimeo Video Embed, same as YouTube Video Embed. It needs the video link of Vimeo Video as an input. Same as Youtube Embed you can set custom width and height in it also.

1
2
3
    Trickster::vimeo('https://vimeo.com/30626474', '400', '250');
    //-> OR, Simple <-//
    Trickster::vimeo('https://vimeo.com/30626474');

13. Video Info Grabber

A great way of getting the video information from YouTube and Vimeo. Video Info Grabber makes it easy for you to grab the video info from link of YouTube & Vimeo video portals and return an array containing the video info. Returning as an array gives you the flexibility to use the info as you want.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
    Trickster::getVideoInfo('https://vimeo.com/30626474');

    /*
        Output:
        Array
        (
            [title] => The Official Space Ibiza Closing Party 2011 Video
            [description] => 
            [thumbnail] => http://i1.ytimg.com/vi/AL-QX0wj44A/default.jpg
            [duration] => 962
            [upload_date] => 2011-11-05 02:11:05
        )
    */

14. Wikipedia Grabber

This simple trick helps you to get the Wikipedia version definition of a particular keyword. Just pass the key word as the input to this function of Trickster and get the definition right away as return string. Remember, like the above function this one also returns an array as it returns not only definition but also the input value and the link to Wikipedia, where that definition is. The example is well explained below:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    Trickster::wiki('github');

    /*
        Output:
        Array
        (
            [0] => GitHub
            [1] => GitHub is a web-based Git repository hosting service. It offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features. 
            [2] => http://en.wikipedia.org/wiki/GitHub
        )
    */

So if you only want to display the definition of GitHub as shown in the above example:

1
2
    $trick = Trickster::wiki('github');
    echo $trick[1];

15. URL Shortener

URL shortener make your url short using the Google's goo.gl API and TinyURL API. Make your life simple with just one liner URL Shortener that can shorten the URL using 2 distinctive APIs.

1
2
3
4
5
    // Google's URL Shortener
    Trickster::shortenUrl('http://github.io', 'google');

    // TinyURL URL Shortener
    Trickster::shortenUrl('http://github.com', 'tinyurl');

16. Suggest

Suggest uses the Google Suggest API to get the keyword suggestions. Just provide the input of the keyword that you want the suggestions for as the first parameter and the results will be generated and returned as an array.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    Trickster::suggest('break');

    /*
        Output

        Array
        (
            [0] => breaking
            [1] => breaking bad
            [2] => break the glass
            [3] => break plan
            [4] => breaking bad imdb
            [5] => kitkat break
            [6] => break the bones
            [7] => breakthrough
            [8] => breaking Benjamin
            [9] => breakup
        )
    */

17. IP Grabber

Grabs the user's IP address. Simple but useful.

1
2
    Trickster::ip();
    // Output: 192.168.145.35

18. Currency Converter

With the help of CURL and Google Finance the currency is converted using the live exchange rate. Trickster's Trickster::currencyConvert() can convert currency within seconds using the Currency Codes.

Returns ErrorException if off-line and developing on localhost as connection to Google's Finance API is not Successful.

The Currency Converter excepts three Parameters with last an optional one.

Parameters & Inputs:

Parameters Description Value Default Accepts
Amount The amount to convert Integer --- Currency Amount
From Convert Currency From String --- Currency Code
To Convert Currency To String --- Currency Code

INR is the Currency Code for Indian National Rupee

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
    /**
    * Sample Code
    * @param $amount init Amount to convert
    * @param $from string Currency Code
    * @param $to string Currency Code
    * @return string - converted amount
    **/

    $amount = 100;
    $from = "USD";
    $to = "INR";
    $convert = Trickster::currencyConvert($amount, $from, $to);
    echo $convert;
1
output: 60,000 //In INR (Just an Example).