Skip to content

Instantly share code, notes, and snippets.

$("form :input").each(function(index, elem) {
var eId = $(elem).attr("id");
var label = null;
if (eId && (label = $(elem).parents("form").find("label[for="+eId+"]")).length == 1) {
$(elem).attr("placeholder", $(label).text());
$(label).remove();
}
});
<?php
/*
1. Source code lines are limited to 120 characters
2. 0 space expected after first parenthesis of function
3. Opening brace should be on a new line
Ça donne un truc illisible
*/
public function getCategories($id_lang = false,
@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;
<?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 {
<?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++;
@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
class Samdha_IDoSomething()
{
private $messager;
function __construct()
{
// crée le gestionnaire de message
$this->messager = new Prestashop_Messager();
}
@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;
}
@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: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"