Skip to content

Instantly share code, notes, and snippets.

View dghaiesahmed's full-sized avatar

Dghaies Ahmed dghaiesahmed

  • Colorz
  • Paris
View GitHub Profile
@dghaiesahmed
dghaiesahmed / extract_video_thumb.php
Created March 14, 2017 16:37
Extract video thumb from youtube/viemo
<?php
function extract_thumb($video_url){
$video_platform = parse_url($video_url, PHP_URL_HOST);
if (isset($video_url) && $video_platform == 'vimeo.com') {
if (preg_match("/https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/uim", $video_url, $id)) {
$video_id = $id[3];
}
$hash = unserialize(wp_remote_fopen("http://vimeo.com/api/v2/video/$video_id.php"));
$src = $hash[0]['thumbnail_large'];
} elseif (isset($video_url) && $video_platform == 'www.youtube.com') {
@dghaiesahmed
dghaiesahmed / sortItems.js
Created March 7, 2017 15:10
Sort Items using jQuery data attribues
/**
* Sort Items depending on jQuery data
* @param {Object} $container : items container class or id
* @param {Object} $selector single item class
* @param {Object} $sortAttr single item data attribute
* @param {Object} $direction sort direction( asc by default)
*/
var itemsSort = function($container,$selector,$sortAttr,$direction='asc'){
@dghaiesahmed
dghaiesahmed / wordpress_tags_hierarchical.php
Created March 2, 2017 14:03
Convert wordpress builtin tags to hierarchical
<?php
function tags_to_hierarchical(){
// Maintain the built-in rewrite functionality of WordPress tags
global $wp_rewrite;
$rewrite = array(
'hierarchical' => false, // Maintains tag permalink structure
'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag',
'with_front' => ! get_option('tag_base') || $wp_rewrite->using_index_permalinks(),
@dghaiesahmed
dghaiesahmed / pdf_to_image_imagick.php
Created March 2, 2017 10:04
Convert pdf page to image (BLOB) using Imagick
<?php
/**
* convert pdf page to image (BLOB)
**/
function generate_pdf_image($pdf_file,$page_index) {
if(class_exists('Imagick') && file_exists($pdf_file)){
$im = new Imagick();
$im->setCompressionQuality(50);//reduce image quality*/
@dghaiesahmed
dghaiesahmed / split_pdf.php
Created March 2, 2017 09:59
Split pdf using fpdf (for Wordpress )
<?php
/**
* Split pdf file given by url (realpath)
**/
function split_pdf($pdf_url,$offset,$nbpages){
require_once(get_stylesheet_directory() .'/libs/fpdf.php');
require_once(get_stylesheet_directory() .'/libs/fpdi.php');
if( file_exists($pdf_url) :
$pdf = new FPDI();
<?php
/*
* retreive pinterest share count
*/
function getPinterestShares($url) {
$url = 'https://api.pinterest.com/v1/urls/count.json?url=' . $url;
$ch = curl_init();
@dghaiesahmed
dghaiesahmed / google_share_count.php
Created February 27, 2017 12:05
Google Share Count using PHP
<?php
/**
* get google share counts for given URL
**/
function getGoolgeShares($url) {
$data = array("method" => "pos.plusones.get", "id" => "p", "params" => array("nolog" => true, "id" => $url, "source" => "widget", "userId" => "@viewer", "groupId" => "@self"), "jsonrpc" => "2.0", "key" => "p", "apiVersion" => "v1");
$content = json_encode($data);
$curl = curl_init('https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ');
curl_setopt($curl, CURLOPT_HEADER, false);
@dghaiesahmed
dghaiesahmed / magento_order_products.php
Last active February 27, 2017 13:46
getting all products from order
<?php
foreach($order->getAllVisibleItems() as $value) {
echo $value->getName();
echo $value->getSku();   
echo $value->getPrice();   
echo $value->getQtyOrdered();
}
@dghaiesahmed
dghaiesahmed / remove_order_magento.sql
Last active February 27, 2017 13:49
Remove orders magento
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_comment`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;
TRUNCATE `sales_flat_order`;
@dghaiesahmed
dghaiesahmed / new_gist_file.xml
Last active February 27, 2017 13:50
Magento 1.9 :add account logout link to sidebar
<customer_account>
<reference name="left">
<reference name="customer_account_navigation">
<action method="addLink" translate="label" module="customer">
<name>logout</name>
<path>customer/account/logout/</path>
<label>Log Out</label>
</action>
</reference>
</reference>