web hosting
build a website
Browsing articles from "August, 2015"

Magento restrict IP addresses to admin

Aug 20, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

Recently with the shoplift bug I have had a couple of Magento sites that have become compromised. So I installed the fixes suggested and then newer fixes came out and I ignored them and then the site got compromised again so I installed the new fix. Each time I installed the fix I went to the site https://shoplift.byte.nl/ and it always said that my site was still vulnerable so I thought best bet was to restrict IP addresses to the admin on my magento sites.

To do this I added in my .htaccess file the following under #RewriteBase /magento/

############################################
# Restrict access to admin and only allow the following ips

RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteCond %{REQUEST_URI} admin [NC]
RewriteRule ^(.*)$ / [F,L]

The 2 lines of 123.123.123.123 you change to the IP addresses that you want to whitelist for your admin and you can add as many lines as you wish.

Now I have added this in the site https://shoplift.byte.nl/ says that my sites are secure.

I will be updating this post if this fix does not stop the sites from being compromised.

Css make grid boxes the same height that align next to each other

Aug 16, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments
.obj-wrapper {
    width:50.7%;
  height:0;
  padding-bottom: 26%; /*acts as fluid height*/
  overflow:hidden;
  position:relative;
  background:grey;
}
.content {
    position:absolute;
  width:100%;
  height:100%;
  background:#DAAE1A;
}

Manually add facebook share into page when linking to another page as it stop the title and description messing up with the redirect

Aug 16, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments
<a href="http://www.facebook.com/sharer.php?s=100&p[title]=urlgoeshere%21&p[url]=http://www.urlgoeshere/&p[summary]=This+is+your+summary&p[images][0]=https://imageurl/images/SS15/fbshare.jpg"><img src="https://imageurl/images/SS15/fbshare.jpg" alt="Facebook share" /></a>

Magento find what current page you are on to target with code PHP

Aug 16, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

Find what current page you are on i.e. checkout/basket page put the following code in the head of the site. This will popup with the name of the page.

<?php $current_page = Mage::app()->getFrontController()->getRequest()->getRouteName(); ?>
<script>alert("<?php echo $current_page; ?>");</script>

Then when you find the page you want to target add this in your header:

<?php $current_page = Mage::app()->getFrontController()->getRequest()->getRouteName(); ?>
if(!$current_page=="checkout"){

code for all meta tags

}

Magento change head content in specific page including OG: tags

Aug 16, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

To change content in a Magento page. Open up the page and on the left hand side click Design and then in the Layout Update XML you can add in the following reference code:

<reference name="head">
  <block type="core/text" name="foo">
    <action method="setText">
      <value><![CDATA[
<meta property="og:title" content="CONTENT" />
<meta property="og:type" content="website" />
<meta property="og:image" content="https://SITE.COM/IMAGE_URL.jpg" />
<meta property="og:url" content="http://SITE.COM" />
<meta property="og:site_name" content="SITE_NAME" />
<meta property="og:description" content="SITE CONTENT" /> 
    ]]>
      </value>
    </action>
  </block>
</reference>

inside the

 <value> </value> 
tags you can add any code you wish and it will add it into the head of your site. This makes it a lot easier if you wish to just add tracking code to one of your pages onto your Magento site.

JQuery Script to force certain og:image

Aug 16, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

If you have multiple Facebook og:images on a page that you cant alter here is a script to attempt to force Facebook to use a certain one.

<script>
jQuery(document).ready(function() {
jQuery("meta[property='og\\:image']").attr("content", "http://imagelink/commons/thumb/8/82/Dell_Logo.png/1027px-Dell_Logo.png");
});
</script>

JQuery social share buttons

Aug 16, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

Below is code for JQuery Facebook, Google+ and Twitter social share buttons

<script>
jQuery(document).ready(function() {
var pathname = document.URL;
var summary = document.title;
var facebook = "http://www.facebook.com/sharer/sharer.php?u=" + pathname;
var google = "https://plus.google.com/share?url=" + pathname;
var twitter = "https://twitter.com/intent/tweet?text=" + summary + "&url=" + pathname;
jQuery("#twittershare").attr("href", twitter);
jQuery("#fbshare").attr("href", facebook);
jQuery("#googleshare").attr("href", google);
});
</script>
<div class="socialshare">
<a target="_blank" href="#" id="twittershare"><img src="https://imagelink/AW13/MISC/shareTweet.png" /></a>
            
<a target="_blank" href="#" id="fbshare"><img src="https://imagelink/AW13/MISC/shareFacebook.png" /></a>

<a target="_blank" href="#" id="googleshare"><img src="https://imagelink/AW13/MISC/shareGoog.png" /></a>
</div>

Jquery explode to change image URL

Aug 16, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

The following is a snippet of code from a site I built and some of it may not make sense however it demonstrates how to explode an image URL in jquery and output it to how you want. So the below URL exploded on the / and on the . and then we can replace the last / and . with var first and .jpg

$j( '.MagicThumb-swap' ).click( function( ) {
            var myString = $j(this).attr( 'rev' );
            var myArray = myString.split('/');
            var myString = myArray.last();
            var myArray = myString.split('.');
            var first = myArray.first();
            var urlImage = "https://imagelink/folder/folder2/folder3/" + first + ".jpg";
            $j(this).attr( "src", urlImage );
            $j( '.MagicBoxShadow img, .MagicThumb-expanded img, .MagicZoomBigImageCont div img' ).attr( "src", urlImage );
            $j( '.MagicToolboxContainer a.MagicZoomPlus img, .MagicToolboxContainer a.MagicZoomPlus' ).attr( "href", urlImage  );
            setTimeout(function() {
                $j( '.MagicBoxShadow img, .MagicThumb-expanded img, .MagicZoomBigImageCont div img' ).attr( "src", urlImage );
                $j( '.MagicToolboxContainer a.MagicZoomPlus img, .MagicToolboxContainer a.MagicZoomPlus' ).attr( "href", urlImage  );
            },500);
    } );

Target domain name for specific code in PHP template

Aug 16, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

If your site uses 1 template for multiple domains such a foreign sites you may need some things to be different such as tracking codes. One way to do that is by using the following PHP code in the head of your site. This says if your server uses any of the following domain then do the following in the { }

<?php

                    if($_SERVER['HTTP_HOST'] == "www.domain.com" ||
                    $_SERVER['HTTP_HOST'] == "www.domain.co.uk" ||
                    $_SERVER['HTTP_HOST'] == "domain.com" ||
                    $_SERVER['HTTP_HOST'] == "domain.co.uk" ||
                    $_SERVER['HTTP_HOST'] == "test.domain.co.uk" ||
                    $_SERVER['HTTP_HOST'] == "www.test.domain.co.uk" ||
                    $_SERVER['HTTP_HOST'] == "test.domain.com" ||
                    $_SERVER['HTTP_HOST'] == "www.test.domain.com"){
                        ?>
<?php   }  ?>

Magento Facebook Open Graph dynamic code

Aug 16, 2015   //   by Anthony Devine   //   Website Development tips  //  No Comments

The below should be added to the head of your Magento site, it specifies what image, description, title etc.. Facebook should use for a static page, a category, product page, checkout page and default page.

<?php /* Open Graph Protocol for Facebook and SEO START */ ?>
<?php if(Mage::registry('current_product')): ?>
 <?php $product = Mage::registry('current_product'); ?>
 <meta property="og:title" content="<?php echo ($product->getName()); ?>" />
 <meta property="og:type" content="product" />
 <meta property="og:image" content="<?php $imageproducturl = Mage::helper('catalog/image')->init($product, 'small_image')->resize(285,285); $newimageproducturl = str_replace('https://', 'http://', $imageproducturl ); echo $newimageproducturl; ?>" />
 <meta property="og:image:secure_url" content="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(285,285);?>" />
 <meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
 <meta property="og:url" content="<?php echo Mage::registry('product')->getProductUrl(); ?>" />
 <meta property="og:description" content="<?php echo strip_tags(($product->getShortDescription())); ?>" />
 
<?php elseif(Mage::registry('current_category')): ?>
 <meta property="og:title" content="<?php echo $this->getTitle() ?>" />
 <meta property="og:type" content="product.group" />
 <meta property="og:image" content="http://imagelink/facebookshare/header-logofb.jpg" />
 <meta property="og:image:secure_url" content="https://imagelink/facebookshare/header-logofb.jpg" />
 <meta property="og:image:type" content="image/jpg">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
 <meta property="og:url" content="<?php echo $this->helper('core/url')->getCurrentUrl();?>" />
 <meta property="og:description" content="<?php echo strip_tags($this->getDescription()) ?>" />

<?php elseif((Mage::getSingleton('cms/page')->getIdentifier() == 'home' &&
 Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')) : ?>
 <meta property="og:title" content="<?php echo $this->getTitle() ?>" />
 <meta property="og:type" content="website" />
 <meta property="og:image" content="http://imagelink/facebookshare/header-logofb.jpg" />
 <meta property="og:image:secure_url" content="https://imagelink/facebookshare/header-logofb.jpg" />
 <meta property="og:image:type" content="image/jpg">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
 <meta property="og:url" content="<?php echo $this->helper('core/url')->getCurrentUrl();?>" />
 <meta property="og:description" content="<?php echo strip_tags($this->getDescription()) ?>" />

 <?php elseif(Mage::app()->getFrontController()->getRequest()->getRouteName() == "checkout") : ?>
 <meta property="og:image:secure_url" content="https://imagelink/facebookshare/hawkheads_logofb.jpg" />

<?php else: ?>
 <meta property="og:title" content="<?php echo $this->getTitle() ?>" />
 <meta property="og:type" content="article" />
 <meta property="og:image" content="http://imagelink/facebookshare/header-logofb.jpg" />
 <meta property="og:image:secure_url" content="https://imagelink/facebookshare/header-logofb.jpg" />
 <meta property="og:image:type" content="image/jpg">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
 <meta property="og:url" content="<?php echo $this->helper('core/url')->getCurrentUrl();?>" />
 <meta property="og:description" content="<?php echo strip_tags($this->getDescription()) ?>" />

<?php endif; ?>
<?php /* Open Graph Protocol for Facebook and SEO END */ ?>
Pages:12»