Skip to content

Instantly share code, notes, and snippets.

View azharisubroto's full-sized avatar
😁
santuy

Azhari Subroto azharisubroto

😁
santuy
View GitHub Profile
<?php
/**
* Slideshow shortcode usage: [gallery type="slideshow"] or the older [slideshow]
*/
if(!class_exists('zl_add_jetPack_slideshow')){
class zl_add_jetPack_slideshow {
public $instance_count = 0;
function __construct() {
<?php
/**
* Register widget areas.
*/
function _action_theme_widgets_init() {
if( function_exists('fw_get_db_settings_option') ){
$sections = fw_get_db_settings_option('footer_section');
if(!empty($sections)){
foreach ($sections as $section) {
$footer_widgets = $section['footer_widgets'];
@azharisubroto
azharisubroto / php-html-css-js-minifier.php
Created January 28, 2016 15:50 — forked from taufik-nurrohman/php-html-css-js-minifier.php
PHP Function to Minify HTML, CSS and JavaScript
<?php
/**
* -----------------------------------------------------------------------------------------
* Based on `https://github.com/mecha-cms/mecha-cms/blob/master/system/kernel/converter.php`
* -----------------------------------------------------------------------------------------
*/
// HTML Minifier
function minify_html($input) {
@azharisubroto
azharisubroto / SimplePhpFlickr.php
Created February 1, 2016 16:23
The final result from hours of googling, finally I can find this snippet.
<?php
// Read more API Documentation @ https://www.flickr.com/services/api/
$xml = simplexml_load_file("https://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&user_id={YOUR USER ID}&per_page=[NUMBER OF PHOTOS TO FETCH]&api_key={REQUIRED!!! YOUR API KEY}&&format=rest");
$output = "<div>";
foreach($xml->children()->children() as $child) {
$imgsrc = "http://farm" . $child['farm'] . ".static.flickr.com/" . $child['server']. "/" . $child['id'] . "_" . $child['secret'] . "_s.jpg"; // More about image size suffixes: https://www.flickr.com/services/api/misc.urls.html
$fullsize = "http://farm" . $child['farm'] . ".static.flickr.com/" . $child['server']. "/" . $child['id'] . "_" . $child['secret'] . "_o.(jpg|gif|png)";
$output .= "<a href='".$imgsrc."'>";
$output .= "<img src='".$imgsrc."' />";
$output .= "</a>";
@azharisubroto
azharisubroto / grabfile.php
Created August 3, 2016 10:51
This code snippet is useful to copy a large file from other server and store it to your server.
<?php
set_time_limit(0);
//This is the file where we save the information
$fp = fopen (dirname(__FILE__) . '/filename.rar', 'w+');
//Here is the file we are downloading, replace spaces with %20
$ch = curl_init(str_replace(" ","%20", 'http://someserver.crot/filename.rar'));
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
@azharisubroto
azharisubroto / instagram_scrape.php
Created August 4, 2016 14:54 — forked from cosmocatalano/instagram_scrape.php
Quick-and-dirty Instagram web scrape, just in case you don't think you should have to make your users log in to deliver them public photos.
<?php
//returns a big old hunk of JSON from a non-private IG account page.
function scrape_insta($username) {
$insta_source = file_get_contents('http://instagram.com/'.$username);
$shards = explode('window._sharedData = ', $insta_source);
$insta_json = explode(';</script>', $shards[1]);
$insta_array = json_decode($insta_json[0], TRUE);
return $insta_array;
}
@azharisubroto
azharisubroto / wp-instagram.php
Last active August 5, 2016 09:37
easy instagram scraper.
<?php
$instagramusername = 'azhari.subroto';
$args = array(
'timeout' => 360,
'httpversion' => '1.1'
);
$response = wp_remote_get('http://instagram.com/'.$instagramusername, $args);
// Check for error
if ( is_wp_error( $response ) ) {
@azharisubroto
azharisubroto / php simple unzip
Created September 4, 2016 17:31
Thanks to rdlowrey at stackoverflow. http://stackoverflow.com/a/8889126
<?php
// assuming file.zip is in the same directory as the executing script.
$file = 'file.zip';
// get the absolute path to $file
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
@azharisubroto
azharisubroto / fancynumber.php
Created September 8, 2016 09:23
fancy number
<?php
function zl_fancy_number($n, $precision = 1) {
if ($n < 1000) {
// Anything less than a thousand
$n_format = number_format($n);
} elseif ($n > 1000 && $n < 10000) {
$n_format = number_format($n / 1000, $precision) . 'K';
} elseif ($n < 1000000000) {
// Anything less than a billion
$n_format = number_format($n / 1000000, $precision) . 'M';
@azharisubroto
azharisubroto / functions.php
Created September 13, 2016 10:53 — forked from anonymous/functions.php
Query Args
<?php
function themeslug_query_vars( $qvars ) {
$vars[] = 'headertype';
return $vars;
}
add_filter( 'query_vars', 'themeslug_query_vars' , 10, 1 );