Giter Club home page Giter Club logo

trickster's Introduction

#Trickster

Why Trickster?

  • Trickster is an Laravel package that makes Laravel Fun.
  • Trickster provides tricks that makes coding with Laravel easy.
  • With Trickster inside your Laravel framework, your app will become a Gambit. :-P

##Installation Installing Trickster is easy. Just type the command: composer require secrethash/trickster

##Requirements

  • Laravel 5.x
  • cURL
  • PHP 5.4.x

##Usage To start using Trickster, you will be needed to set it up first. Follow the below steps to setup Trickster:

###1. Service Provider You will be needing to add the Trickster Service Provider in your app.php which is inside the config directory.

  • Open config\app.php
  • Find 'providers'
  • At the last of this array in Application Service Providers add Secrethash\Trickster\TricksterServiceProvider::class,

###2. Facade To use Trickster flexibly, you need to add the Facade also. Facade will let you use Trickster directly. All you will need to do is add use Trickster; at the head of the controller below namespace and use it by Trickster::trickName();

Lets Add the Trickster Facade:

  • Open config\app.php
  • Find 'aliases' array.
  • At the end of this array, add 'Trickster' => Secrethash\Trickster\Facade\Trickster::class,

###3. Configuration First of all you will need to run the following command in your console: php artisan vendor:publish --provider="Secrethash\Trickster\TricksterServiceProvider"

This command will publish the trickster.php configuration file for Trickster to your application default config directory.

From config\trickster.php you can edit the default configurations.

###4. Ready, Steady, GO! You are almost done. Now what to do when you want to use a Trickster's Trick?

Here is a sample Controller to show you how to add Trickster and Use it:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use Auth;
use Trickster; // Simply add the Facade

class TricksterDemoController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //checking if the user is Authenticated
        if (Auth::check()) {
	        $user = Auth::user();
	        // Grabbing Gravatar
	        $gravatar = Trickster::gravatar($user->email, '200');
	     }
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

}

If you want to use Trickster inside a view file, call the Trickster method directly. That is the advantage of Facade.

For example: {!! Trickster::bbcode($user->bio) !!} or {{ Trickster::truncator($blog->desc, '150', '(...summary)') }}

##Trickster's Tricks

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

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

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

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:

Trickster::emailValid('[email protected]');

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

COOL HUH?

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

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:

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

Trickster::gravatar('[email protected]', '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.

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

Finished? Not Yet!

###7. Simple Social Analytics This trick eases your life, seriously. Simple and easy way to show your social counts with Trickster. Trickster's Simple Social Analytics shows the number of Like or Tweets over a specific URL when the trick is executed.

  • Supported Social Networks:
  • Facebook
  • Twitter
  • Returned Strings
  • Facebook
    • Likes
  • Twitter
    • Tweets
$likes = Trickster::social('facebook', 'http://github.com/secrethash');
echo $likes.' Likes on Github.com/secrethash';

Output: 95457821 Likes on Github.com/secrethash

$tweets = Trickster::social('twitter', 'http://github.com/secrethash');
echo $tweets.' Tweets on Github.com/secrethash';

Output: 54859562 Tweets on Github.com/secrethash

Simple?

###8. BB Code Engine BB code engine trick is a little distinctive. It's actually amazing. It makes easy to convert the BB Code to HTML format. Easy to initialize, it makes it unique.

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

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 repo was created 2 months ago

Trick:

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.

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.

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.

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:

Trickster::wiki('github');
// Returns
/**
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:

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

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

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.

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

trickster's People

Contributors

secrethash avatar

Watchers

James Cloos avatar LuongPS 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.