php

warning: Creating default object from empty value in /data/web/1/000/027/003/273448/htdocs/panticz.de/modules/taxonomy/taxonomy.pages.inc on line 33.

Magento: Update custom core config data and refresh cache to view the changes

#!/usr/bin/php
<?php
require '/var/www/app/Mage.php';
Mage::app(0);

if(count($_SERVER['argv']) == 2) {
  $value = $_SERVER['argv'][1];

  # update magento core config data
  $config = new Mage_Core_Model_Config();
  $config->saveConfig('stocklist/number', $value, 'default', 0);

  # refresh magento configuration cache
  Mage::app()->getCacheInstance()->cleanType('config');
} else {
  echo "Usage: " . $_SERVER['argv'][0] . " LIST_ID\n";
}
?>

Links
http://inchoo.net/ecommerce/magento/how-to-programmatically-change-magentos-core-config-data/
http://makandracards.com/magento/8277-cache-clearing-and-general-information

Magento: Add upload field to contact form

wget -q http://dl.panticz.de/magento/contact_attachment/form.phtml.diff -O - | patch -p2 \
/var/www/app/design/frontend/default/default/template/contacts/form.phtml

--- /var/www/app/design/frontend/default/default/template/contacts/form.phtml.org	2013-11-11 17:35:28.000000000 +0100
+++ /var/www/app/design/frontend/default/default/template/contacts/form.phtml	2013-11-12 16:20:06.000000000 +0100
@@ -28,7 +28,7 @@
 <div class="page-title">
     <h1><?php echo Mage::helper('contacts')->__('Contact Us Form') ?></h1>
 </div>
-<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post">
+<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post" enctype="multipart/form-data"> 
     <div class="fieldset">
         <h2 class="legend"><?php echo Mage::helper('contacts')->__('Contact Information') ?></h2>
         <ul class="form-list">
@@ -68,6 +68,13 @@
                     <textarea name="comment" id="comment" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class="required-entry input-text" cols="5" rows="3"><?php echo $this->getRequest()->getParam('message');?></textarea>
                 </div>
             </li>
+            <li>
+                <label for="attachment"><?php echo Mage::helper('contacts')->__('Attachment') ?></label>
+                <div class="input-box">
+                    <input name="MAX_FILE_SIZE" type="hidden" value="2000000" />
+                    <input name="attachment" id="attachment" class="input-text" type="file" />
+                </div>
+            </li>
         </ul>
     </div>
     <div class="buttons-set">

wget -q http://dl.panticz.de/magento/contact_attachment/IndexController.php.diff -O - | patch -p2 \
/var/www/app/code/core/Mage/Contacts/controllers/IndexController.php

--- /var/www/app/code/core/Mage/Contacts/controllers/IndexController.php.org	2013-11-11 17:44:06.000000000 +0100
+++ /var/www/app/code/core/Mage/Contacts/controllers/IndexController.php	2013-11-13 11:34:56.000000000 +0100
@@ -91,7 +91,40 @@
                 if ($error) {
                     throw new Exception();
                 }
+
+                $fileName = '';
+                if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') {
+                    try {
+                        $fileName       = $_FILES['attachment']['name'];
+                        $fileExt        = strtolower(substr(strrchr($fileName, "."), 1));
+                        $fileNamewoe    = rtrim($fileName, $fileExt);
+                        $fileName       = preg_replace('/\s+', '', $fileNamewoe) . time() . '.' . $fileExt;
+ 
+                        $uploader       = new Varien_File_Uploader('attachment');
+                        $uploader->setAllowedExtensions(array('jpg', 'png', 'bmp', 'gif', 'pdf', 'zip', 'rar'));
+                        $uploader->setAllowRenameFiles(false);
+                        $uploader->setFilesDispersion(false);
+                        $path = Mage::getBaseDir('media') . DS . 'contacts';
+                        if(!is_dir($path)){
+                            mkdir($path, 0777, true);
+                        }
+                        $uploader->save($path . DS, $fileName);
+ 
+                    } catch (Exception $e) {
+                        $error = true;
+                    }
+                }
+
                 $mailTemplate = Mage::getModel('core/email_template');
+                if($fileName != '') {
+                    $attachmentFilePath = Mage::getBaseDir('media'). DS . 'contacts' . DS . $fileName;
+                    if(file_exists($attachmentFilePath)){
+                        $fileContents = file_get_contents($attachmentFilePath);
+                        $attachment   = $mailTemplate->getMail()->createAttachment($fileContents);
+                        $attachment->filename = $fileName;
+                    }
+                }
+
                 /* @var $mailTemplate Mage_Core_Model_Email_Template */
                 $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                     ->setReplyTo($post['email'])

wget -q http://dl.panticz.de/magento/contact_attachment/Mage_Contacts.csv.diff -O - | patch -p2 \
/var/www/app/locale/de_DE/Mage_Contacts.csv

--- /var/www/app/locale/de_DE/Mage_Contacts.csv.org	2013-11-13 15:57:34.000000000 +0100
+++ /var/www/app/locale/de_DE/Mage_Contacts.csv	2013-11-13 11:40:11.000000000 +0100
@@ -15,5 +15,6 @@
 "Send Emails To","Sende E-Mails an"
 "Submit","Absenden"
 "Telephone","Telefon"
+"Attachment","Anhang"
 "Unable to submit your request. Please, try again later","Fehler beim Übertragen der Anfrage. Bitte versuchen Sie es später noch einmal."
 "Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.","Ihre Anfrage wurde übertragen. Wir werden diese umgehend bearbeiten und uns gegebenenfalls mit Ihnen in Verbindung setzen. Vielen Dank!"

Links
http://www.blog.magepsycho.com/adding-upload-field-in-contact-form-and-send-as-attachment/
http://www.magentocommerce.com/boards/viewthread/440759/

Puppet: PHP5 module

create module structure
mkdir -p /etc/puppet/modules/php5/manifests
mkdir -p /etc/puppet/modules/php5/files

download module definiction
wget -q https://raw.githubusercontent.com/panticz/puppet/master/modules/php5/init.pp -O /etc/puppet/modules/php5/manifests/init.pp

class php5 {
    case $::osfamily {
        default: {
            $pkg = 'php5'
        }
    }

    # install PHP and restarts apache to load the module
    #package { ['php54', 'php54-apc', 'php54-mod-php']:
    package { "$pkg":
        ensure  => installed,
        notify  => Service['apache2'],
        #require => [ Package['php5-mysql'], Package['apache'] ],
        require => Package["apache"],
    }

    exec { "/bin/date -I > /tmp/debug": }
#cat /etc/apache2/mods-enabled/php5.conf
#<FilesMatch ".+\.ph(p[345]?|t|tml)|.htm([l]*)$">
}

add include to your client in /etc/puppet/manifests/site.pp
node "client1.local" inherits default {
...
include php5
...
}

Example: index.html

Links

PHP

Supported Versions
http://php.net/supported-versions.php

show PHP information
php -i

list loaded PHP modules
php -m

enable PHP Module
php5enmod amqp
/etc/init.d/apache2 reload

Show includes
php --ini

Run PHP built-in web server
php -S 192.168.1.100:8080 -t /var/www/

PHP syntax check
php -l FILE.php

# define parameter
php -d date.timezone="Europe/Berlin" -f

Error reporting
# report all errors except notices

Extend Magento Product Attribute Api

# OPTIONAL, install patch
apt-get install -y patch
 
# patch on command line
cd /var/www/
wget http://www.panticz.de/sites/default/files/api.xml_.diff -O /tmp/api.xml.diff
patch -p2 ./app/code/core/Mage/Catalog/etc/api.xml < /tmp/api.xml.diff
 
wget http://www.panticz.de/sites/default/files/Api.php_.diff -O /tmp/Api.php.diff
patch -p2 ./app/code/core/Mage/Catalog/Model/Product/Attribute/Api.php < /tmp/Api.php.diff
 
 
1. go to magento installation folder, for example /var/www/magento
 
2.

convertToUtf.php

<?php
function convertToUtf($string) {
	$string = str_replace("ü", "ü", $string);
	$string = str_replace("Ãœ", "Ü", $string);
	$string = str_replace("ö", "ö", $string);
	$string = str_replace("Ö", "Ö", $string);
	$string = str_replace("ä", "ä", $string);
	$string = str_replace("Ä", "Ä", $string);
	$string = str_replace("ß", "ß", $string);
 
	return $string;
}
?>

Useful PHP configuration parameter (php.ini)

# create automaticly a session
session.auto_start = ON
 
# disable global variables
register_globals = OFF
 
# increase upload limit
upload_max_filesize = 50M

HTML / PHP / CMS

Links
https://subgraph.com/vega/download/index.en.html - Vega Vulnerability Scanner
http://popuri.us/ - PageRank / link popularity check
http://validator.w3.org/ - W3C Markup Validation Service
Bluefish - HTML / PHP editor for Linux, supports direct edit on FTP
http://ckeditor.com/demo - Online WYSIWYG Editor
SELFHTML - HTML / PHP reference
seitwert.de - shows Google PageRank and statistics for a URL

Syndicate content