Skip to content

Instantly share code, notes, and snippets.

@Shagshag
Shagshag / gist:4458383
Created January 4, 2013 23:16
Check if a date is between two others with jockers
<?php
class checkRule
{
/**
* check if $datetime is between the start date and end date of a rule
*
* $rule has this format :
* array(
* 'date_start' => 'YYYY-MM-DD HH:MM:SS',
* 'date_end' => 'YYYY-MM-DD HH:MM:SS',
@Shagshag
Shagshag / gist:5848915
Last active July 3, 2023 21:45
Unobfuscate this type of code : "eval(gzinflate(base64_decode(strrev('AYwtRlkyv8MKXlcyNj09QdFyO30S'))));"
<?php
$obfuscated = "eval(gzinflate(base64_decode(strrev('AYwtRlkyv8MKXlcyNj09QdFyO30S'))));";
$decoder = new unobfuscate($obfuscated);
echo $decoder->decode(); // echo 'Hello world';
class unobfuscate
{
@Shagshag
Shagshag / gist:5849065
Created June 24, 2013 10:08
Do the same than parse_str without max_input_vars limitation
<?php
/**
* do the same than parse_str without max_input_vars limitation
* @param $string array string to parse
* @return array query parsed
**/
function my_parse_str($string) {
$result = array();
// find the pairs "name=value"
@Shagshag
Shagshag / gist:5849077
Created June 24, 2013 10:10
return true if the module $name is activated in apache
<?php
/**
* return true if the module $name is activated in apache
*
* @param string $name module name
* @return boolean
* @author Samdha
**/
function detect_apache_mod($name) {
@Shagshag
Shagshag / gist:5850617
Created June 24, 2013 14:52
Override example with Prestashop
<?php
class ObjectModel extends ObjectModelCore
{
public function add($autodate = true, $nullValues = false)
{
$result = parent::add($autodate, $nullValues);
if ($result) Module::hookExec('objectAdd', array('object' => $this));
return $result;
}
<?php
class Samdha_IDoSomething()
{
private $messager;
function __construct()
{
// crée le gestionnaire de message
$this->messager = new Prestashop_Messager();
}
@Shagshag
Shagshag / examplemodule.php
Last active December 19, 2015 21:59
Custom hook example with Prestashop
<?php
class ExampleModule extends Module {
public function install()
{
$done = (
parent::install()
&& $this->registerHook('displayFooter')
&& $this->registerHook('displayRandom')
);
return $done;
<?php
function test()
{
for ($i = 0; $i < 17; $i++)
if ($myArray[$i] == $value)
{
$result[] = $myArray[$i];
for ($i = 0; $i < 17; $i++)
if ($myArray[$i] == $value)
$failed++;
<?php
function test()
{
for ($i = 0; $i < 17; $i++) {
if ($myArray[$i] == $value) {
$result[] = $myArray[$i];
for ($i = 0; $i < 17; $i++) {
if ($myArray[$i] == $value) {
$failed++;
} else {
@Shagshag
Shagshag / Product.php
Last active December 22, 2015 15:39
Tags in product properties
<?php
class Product extends ProductCore{
public static function getProductProperties($id_lang, $row, Context $context = null)
{
$row = parent::getProductProperties($id_lang, $row, $context);
if (is_array($row) && isset($row['id_product'])) {
$usetax = Tax::excludeTaxeOption();
$cache_key = $row['id_product'].'-'.$row['id_product_attribute'].'-'.$id_lang.'-'.(int)$usetax;