Binders: twitter

If you are looking for a quick way to integrate a Twitter feed into your project, look no more! The {{twitter… }} binder allows you to bind a Twitter feed to your page.

 

/**
 * @param {array} $params 
 *                  $params['screen_name'] Twitter "username" (e.g. appcropolis)
 *                  $params['assign_to'] Variable within the template engine to which the content has to be assigned.
 *
 *                  $params['consumer_key'] = '',
 *                  $params['consumer_secret'] = '',
 *                  $params['access_token'] = '',
 *                  $params['access_token_secret'] = '',
 *                  $params['twitter_screen_name'] = '',
 *                  $params['cache_file'] = dirname(__FILE__) . '/cache/twitter.txt', // Where on the server to save the cached formatted tweets
 *                  $params['cache_file_raw'] = dirname(__FILE__) . '/cache/twitter-array.txt', // Where on the server to save the cached raw tweets
 *                  $params['cachetime'] = 60 * 60, // Seconds to cache feed (1 hour).
 *                  $params['tweets_to_retrieve'] = 25, // Specifies the number of tweets to try and fetch, up to a maximum of 200
 *                  $params['tweets_to_display'] = 10, // Number of tweets to display
 *                  $params['ignore_replies'] = true, // Ignore @replies
 *                  $params['ignore_retweets'] = true, // Ignore retweets
 *                  $params['twitter_style_dates'] = false, // Use twitter style dates e.g. 2 hours ago
 *                  $params['twitter_date_text'] = array('seconds', 'minutes', 'about', 'hour', 'ago'),
 *                  $params['date_format'] = '%I:%M %p %b %e%O', // The defult date format e.g. 12:08 PM Jun 12th. See: http://php.net/manual/en/function.strftime.php
 *                  $params['date_lang'] = null, // Language for date e.g. 'fr_FR'. See: http://php.net/manual/en/function.setlocale.php
 *                  $params['format'] = 'html', // Can be 'html' or 'array'
 *                  $params['twitter_wrap_open'] = '<h2>Latest tweets</h2><ul id="twitter">',
 *                  $params['twitter_wrap_close'] = '</ul>',
 *                  $params['tweet_wrap_open'] = '<li><span class="status">',
 *                  $params['meta_wrap_open'] = '</span><span class="meta"> ',
 *                  $params['meta_wrap_close'] = '</span>',
 *                  $params['tweet_wrap_close'] = '</li>',
 *                  $params['error_message'] = 'Oops, our twitter feed is unavailable right now.',
 *                  $params['error_link_text'] = 'Follow us on Twitter',
 *                  $params['nolink'] = Whether or not to replace URL link in tweet text with an actual link (anchor tag). Value can be anything
 *                  $params['debug'] = false
 * 
 * 
 * @return {array} An array of Tweets. Each tweet will contain:
 * 
 * $tweet['text'] 			// the actual tweet text
 * $tweet['id']				// the tweet ID
 * $tweet['created_at'] 	// the tweet time stamp (Thu Nov 06 14:01:08 +0000 2014)
 * $tweet['url']			// the tweet URL (https://twitter.com/appcropolis/status/530359228834525185)
 * $tweet['user']			// user info object
 * $tweet['user']['name'] 	// user friendly name
 * $tweet['user']['screen_name'] 	// user twitter screen_name
 * $tweet['user']['id'] 			// user ID
 * $tweet['user']['profile_image_url'] 
 * $tweet['user']['profile_image_url_https'] 
 * $tweet['user']['profile_background_image_url']
 * $tweet['user']['profile_background_image_url_https']
 * $tweet['urls']
 * $tweet['urls']['short_url']
 * $tweet['urls']['expanded_url']
 * $tweet['urls']['display_url']
 * 
 * 
 * @example
 * 
 * // EXAMPLE #1: Display a list of 4 most recent tweets
 * 
 * {twitter assign_to="tweets" screen_name="appcropolis" tweets_to_display="4"}
 * <ul>
 * {foreach $tweets.data as $tweet}
 * 	<li>
 * 		<h2>{$tweet.text}</h2>	
 * 		<i>{$tweet.created_at}</i>
 * 		<p>{$tweet.user.name} @{$tweet.user.screen_name}</p>
 * 		<a href="{$tweet.urls.expanded_url}">{$tweet.urls.display_url}</a>
 * 	</li>
 * {/foreach}
 * </ul>
 * 
 * // EXAMPLE #2: Out twitter original data
 * {twitter
 * 		twitter_screen_name="appcropolis" 
 * 		tweets_to_retrieve="10" 
 * 		tweets_to_display="5" 
 * 		assign_to="tw"
 * 		format="raw"}
 * 
 * {dump var="tw"}
 * 
 * @link https://github.com/jnicol/tweet-php
 *
 */

 

 

Example:

<ul class="appc-dynamic" id="appc-tweets">
    {{twitter assign_to="tweets" screen_name="appcropolis" tweets_to_display="4"}}
    {{foreach $tweets.data as $tweet}}
    <li>
        <a href="#"> @{{$tweet.user.screen_name}}</a>
        <div class="comment-date">
            <!-- make date more user friendly -->
            <span>{{$tweet.created_at}}</span>
        </div>
        <!-- open links in a popup window -->
        <p >{{$tweet.text|replace:"href":"target='_blank' href"}}</p>
    </li>
    {{foreachelse}}
        <p>No tweets.</p>
    {{/foreach}}
</ul>

 

Binders: products

TODO:

 

/**
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.bind.php
 * Type:     function
 * Name:     bind
 * Purpose:  includes template content
 * -------------------------------------------------------------
 *
 * @param {array} $params 
 *                  $params['show'] What to show (e.g. categories, tags, featured, category) 
 *                  $params['hide_empty'] Hides empty categories when showing a list of categories. Possible values are 0 or 1
 *                  $params['assign_to'] Variable within the template engine to which the content has to be assigned.
 *
 * 
 * # EXAMPLE
 * 
 * 
 * 
 * @example
 * 
 * # EXAMPLE 1: show products in the specified category
 * {products cat_slug="featured-items" size="3" assign_to="featured"}
 * 
 * 
 * # EXAMPLE 2: shows a list of product categories
 * {products show="categories" assign_to="categories"}
 * 
 * <h3 class="sidebar-title">Product Categories </h3>
 * <ul class="product-categories">
 * 	    {foreach $categories.data as $cat}
 * 	        <li class="cat-item cat-item-{$cat.term_id}">
 * 	            <a href="{$cat.permalink}">{$cat.name} ({$cat.count})</a>
 * 	        </li>
 * 	    {/foreach}
 * </ul>
 * 
 * 
 * #EXAMPLE 3
 * {products show="featured" assign_to="featured_products"}
 * 
 * 
 * # EXAMPLE 4: Get a list of all available product tags
 * 
 * {{products show="tags" assign_to="tags"}}
 * 
 *
 * 
 * # EXAMPLE 5: show products in the specified tag
 * 
 * {{products tag="my-tag" size="4" assign_to="products_by_tag"}}
 *
 * <h3>Product By Tag: My Tag </h3>
 * <ul class="product-categories">
 * 	    {{foreach $products_by_tag.data as $product}}
 * 	        <li class="item">
 * 	            <a href="{$product.permalink}">{{$product.post_title}}</a>
 * 	        </li>
 * 	    {{/foreach}}
 * </ul>
 * 
 *
 * 
 * #EXAMPLE 6: shows current category name
 * {products show="category" assign_to="current_cat"}
 * 
 * <h1>Category: {$current_cat}</h1>
 *
 */

 

Binders: product

TODO:

 

/**
 * Get product information
 *
 * @example 
 * 
 * {product post_id="{$post.ID}" assign_to="product_info"}
 * 
 * <h1 itemprop="name" class="product_title entry-title">{$post.post_title}</h1>
 * <p class="price"><span class="amount">${$post.price}</span></p>
 * 
 * <div class="product_meta">
 *     <span class="posted_in">Categories: 
 *     {foreach $product_info.data.categories as $cat}
 *         <a href="{$cat.permalink}" rel="tag">{$cat.name}</a>{if !$cat@last}, {/if}
 *    {/foreach}</span>
 * </div>
 * 
 */

 

Binders: posts

TODO:

 

/**
 * @param {array} $params 
 *                  $params['show'] What to show (e.g. category, related, tag, all)
 *                  $params['name'] Name of the part (e.g. content-main.html)
 *                  $params['assign_to'] Variable withing the template engine to which the content has to be assinged.
 *
 * 
 * # EXAMPLE 1
 *  
 * {posts assign_to="posts"}
 * {posts show="all" assign_to="posts"}
 * 
 * 
 *
 * # EXAMPLE 2
 * 
 * {posts show="category" name="news" assign_to="posts"}
 * 
 * 
 * # EXAMPLE 3
 * 
 * {posts show="related" size="3" post_id="{$post.ID}" assign_to="related"}
 * 
 *
 * # EXAMPLE 4
 * 
 * {posts show="tag" name="news" assign_to="tags"}
 * 
 * 
 */

 

Binders: paginate

TODO:

 

/**
 *
 * @param {array} $params 
 *            $params['type'] {string} Data format. Valid values are: plain, list, array
 *            $params['collection'] The action response that is used to query posts, pages of categories.
 *            $params['assign_to'] Variable within the template engine to which the content has to be assigned. 
 *
 * 
 * @example
 * 
 * # EXAMPLE 1
 * 
 * {paginate type="plain"}
 * <!-- this will output: -->
 * <span class='page-numbers current'>1</span>
 * <a class='page-numbers' href='http://yourdomain.com/blog/page/2/'>2</a>
 * <a class="next page-numbers" href="http://yourdomain.com/blog/page/2/">Next ยป</a> 
 * 
 * 
 * 
 * # EXAMPLE 2
 * 
 * {paginate type="array" assign_to="pagination"}
 * {if $pagination.total > 1}
 * <div class="pagination">
 *     <ul>
 *     {foreach $pagination.data as $page}
 *         <li>{$page}</li>
 *     {/foreach}
 *     </ul>
 * </div>
 * {/if}
 * 
 * 
 * @link http://codex.wordpress.org/Function_Reference/paginate_links
 *
 */