Latest 100 public snipts »
robertbanh's
snipts
showing 1-20 of 81 snipts
-
∞ JS: onfocus and onblur
$("#email").focus(function() { if ($(this).val() == $(this).attr('rel')) $(this).val(''); }); $("#email").blur(function() { if ($(this).val() == '') $(this).val($(this).attr("rel")); });
-
∞ JW Player tips
<?php // jw player tips // // http://www.longtailvideo.com/support/jw-player-setup-wizard // // http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/12536/configuration-options // build flashvars in case the user doesn't have js enabled $flash_vars = "&autostart=true&dock=false&file=".urlencode('blah.flv')."&image=".urlencode('blah.jpg')."&plugins=captions-1&captions.file=".urlencode('blah.xml'); ?> <h3></h3> <p id='preview'> <embed src='http://www.blah.com/video/player.swf' height='360' width='640' allowscriptaccess='always' allowfullscreen='true' flashvars='<?php echo $flash_vars; ?>'/> </p> <script type='text/javascript' src='/video/swfobject.js'></script> <script type='text/javascript'> var s1 = new SWFObject('/video/player.swf','player','640','360','9'); s1.addParam('allowfullscreen','true'); s1.addParam('allowscriptaccess','always'); s1.addVariable('file', 'blah.flv'); s1.addVariable('autostart','true'); s1.addVariable('dock','false'); s1.addVariable('image','blah.jpg'); s1.addVariable('captions.file', 'blah.xml'); s1.addVariable('author','Me'); s1.addVariable('description','Video of Me'); s1.addVariable('title','Title'); s1.addVariable('plugins','viral-2d,captions-1'); s1.write('preview'); </script>
-
∞ Magento: custom advance search
<form id="customsearch" method="get" action="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); ?>catalogsearch/advanced/result?"> <?php $advanceSearch = array( array( 'attrib' => 'color', 'selectName' => 'color[]', 'labelName' => 'Color' ), array( 'attrib' => 'style', 'selectName' => 'style[]', 'labelName' => 'Style' ) ); $html = ''; $attributes = Mage::getModel('catalogsearch/advanced')->getAttributes(); foreach ($advanceSearch as $as) { $html .= " <label for='as-" . $as['labelName'] . "'></label> <select id='as-" . $as['attrib'] . "' name='" . $as['selectName'] . "'><option value=''>All</option>"; foreach ($attributes as $a) { if ($a->getAttributeCode() == $as['attrib']) { foreach ($a->getSource()->getAllOptions(false) as $option) { $html .= "<option value='" . $option['value'] . "'>" . $option['label'] ."</option>"; } } } $html .= "</select> "; } echo $html; ?> <input type="submit" value="search">
-
∞ Magento: update custom product attrib
<?php // update a custom attribute in 1 product: // $product = Mage::getModel('catalog/product') ->setCurrentStore(1) ->load($entity_id); // note: the 3rd param is the store id $product->addAttributeUpdate('rbanh_custom_attrib', $value, 1);
-
∞ Magento: extract data from 1 product
<?php // Sometimes you don't need a collection, just 1 product. // $product = Mage::getSingleton('catalog/product') ->load($entity_id) ->getData(); var_export($product); die();
-
∞ JS: onload fix for resetting when back button is used
<script> // reset fix for selectbox when the back button is used // place this code in the body, not the head. window.onload = function(){ $('#selectbox1').val(''); $('#selectobx2').val(''); }; </script>
-
∞ Magento: SQL filter by custom product attrib
<?php // SQL call where custom product attrib 'promo' == 1 $pcollection = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') //->addAttributeToFilter('sku',array('like' => '%ABC%')) ->addAttributeToFilter('promo', '1'); foreach($pcollection as $pp) { // method 1 $_promoProduct = $pp->_data; Zend_Debug::dump($_promoProduct); die(); // method 2 $url = $pp->getProductUrl(); $name = $this->htmlEscape($pp->getName()); $img_src = $pp->getThumbnailUrl(325, 215); $price = number_format($pp->getPrice(), 2); // etc }
-
∞ EE: .htaccess file
DirectoryIndex index.php index.html Options -Indexes <FilesMatch "_CHANGELOG"> deny from all </FilesMatch> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L] # Increase mem for EE - large data sets php_value memory_limit 64M
-
∞ Magento: extract category info given product obj
<?php // fetch the category if we have the product object // record the category info for this product $category = array(); $cat_ids = $_product->getCategoryIds(); $cat = new Mage_Catalog_Model_Category(); foreach ($cat_ids as $cid) { $cat->load($cid); // var_export($cat); $cat_data = $cat->_data; $category[] = array( 'name' => $cat_data['name'], 'url_key' => $cat_data['url_key'] ); }
-
∞ Magento: add extra attribs to product collection
<?php // sometimes you need to add extra attribs $_products = $this->getProductCollection() ->addAttributeToSelect('description'); Zend_Debug::dump($_product->getData());
-
∞ Magento: debug
<?php // debug in magento Zend_Debug::dump($_product->getData());
-
∞ .htaccess: Allow only from IP
# Allow only from these 2 IPs Order Deny,Allow Deny from all Allow from 311.311.311 322.322.322.322 -
∞ EE: ngen and imgsizer
<?php // EE - ngen + imgsizer // // http://www.lumis.com/page/imgsizer/ {exp:weblog:entries ...} // ngen - display filename only {customFieldNamePhoto show='filename'} // ngen - display full path {customFieldNamePhoto} // ngen + imgsizer {exp:imgsizer:size src="{customFieldNamePhoto}" width="98" alt="profile pic"} {/exp:weblog:entries}
-
∞ EE: getting php segment vars
<?php global $IN; $segment_2 = $IN->fetch_uri_segment('2'); // get array of segments $seg_array = $IN->SEGS; // get the last segment $entry_id = $IN->QSTR; ?>
-
∞ Rewrite URL
# rbanh add for soft linking old dir RewriteEngine On Options +FollowSymlinks RewriteRule ^aaa/(.*)$ /bbb/$1 [L]
-
∞ EE: clean vars
<?php global $IN, $REGX; $str = $REGX->xss_clean($_POST['abc']); ?>
-
∞ EE: plugin - return var pairs
<?php // EE plugin - returning as tag paired // // usage: // // {exp:blah} // {aaa} // {bbb} // {ccc} // {/aaa} // {/exp:blah} // // now we build the return data structured for EE $tagdata = ""; foreach ($returnArray as $entry_id => $obj) { // start the tagdata $temp = $TMPL->tagdata; if (preg_match('/{aaa}/', $temp)) { // remove tag pairs $temp = str_replace('{aaa}', '', $temp); $temp = str_replace("{".SLASH."aaa}", '', $temp); $temp = str_replace('{bbb}', $obj['entry_id'], $temp); $temp = str_replace('{ccc}', $obj['title'], $temp); // store the tagdata $tagdata .= $temp; } } $this->return_data = $tagdata;
-
∞ JS: prepend ajax text to url
function addAjax(origHref) { //var origHref = $('.add-student').attr('href'); var urlArray = origHref.split(/[\/]/); if (urlArray.length > 1) { var filename = urlArray.pop(); // if there's a trailing slash, get the next iteration if (filename.length < 1) filename = urlArray.pop(); filename = "/ajax-" + filename; return urlArray.join("/") + filename; } return origHref; }
-
∞ EE: commenting blocks of code
<?php // When using EE, you can comment out a section of code using // the following: {!-- <p>Blah</p> --} ?>
-
∞ EE: set and return vars in plugin
<?php // for custom plugin in EE, setting variables $tagdata = $TMPL->tagdata; //var_export($TMPL->var_single); $tagdata = $TMPL->swap_var_single("rbanh_var","hello", $tagdata); $this->return_data .= $tagdata; // usage: // {plugin_name} // {rbanh_var} // {/plugin_name} ?>


