10 Secrets that will make you a master of Opencart Events

10 Secrets that will make you a master of Opencart Events

If you are an Opencart Developer, you have probably heard about events. If you come from wordpress like me, you would definitely relate this to their hooks API and when Opencart Events first arrived in opencart 2.0.0.0 they were very similar in terms of the naming approach. This changed in the version 2.2.0.0 when the Opencart team changed the way events where triggered and this we believe will revolutionize Opencart forever.

What are events?

First of all, what are ¨events〃 in the opencart core understanding? Events are methods that are called when an action takes place. In other words, you can define specifically the moment when you want your custom function to run in the opencart store.

You can find more information here and here

10 Secrets that will make you a master of Opencart Events?

Why not use VQMOD/OCMOD?

Before ¨events〃 for a long time we have been using VQMOD, a modification system that uses an XML file to add changes to files of opencart. It would run in the beginning, creating vqmod cache files with the modifications and then the opencart core system would use those new files to make the changes. In other words, you would change the codebase, but the changes would be added on the fly.

The idea was great at that moment and it really boosted opencart since it allowed for the developer to create any kind of modification without altering the actually core files, making installation of modules and the future opencart upgrade easier.

As good as it sounds, it created a whole level of conflicts between custom modules, leading to hours and even days of work to fix. Mostly, due to poorly created modifications.

Still, even with this drawback, VQMOD, and further OCMOD, a native implementation of VQMOD concept directly in Opencart, gives us, developers, a great tool.

So how can Events help me better then VQMOD/OCMOD?

Events are simple functions that execute at a specific moment in your opencart runtime and modify the output  not the codebase. For example, if you want to run a function before the common/header controller is loaded, you can do that. Or if you want to add some html to the output of the common/header view  you can do that as well. There is no file manipulation so you wonˇt need to worry about creating conflicts by altering the code  the code base stays the same.

Sound interesting, but how do I actually use it?

Lets try an example. Say, you have another tpl file for the header and you need the header controller to load my_custom_header.tpl.

VQMOD/OCMOD solution:

Create a modification that would edit the $this->load->view method in the controller.

  1. <file name="catalog/controller/common/header.php">
  2.   <operation>
  3.     <search position="replace"><![CDATA return $this->load->view('common/header', $data);]]></search>
  4.     <add><![CDATA return $this->load->view('common/my_custom_header', $data);]]></add>
  5.   </operation>
  6. </file>

This works perfectly until another extension comes along and needs this line of code to work. Now you have a conflict.

Eventˇs Solution:

With events you will not alter the code, you will change the $route parameter, that is passed into the $this-load->view($route, $data) like so.

Create a file (use descriptive names  saves the time of finding the right event file):
catalog/event/change_view_common_header.php

Code:

  1. <?php
  2.   class ControllerEventChangeViewCommonHeader extends Controller {
  3.     public function before_view(&$route, &$data, &$output){
  4.       $route = str_replace('common/header', 'common/my_custom_header', $route);
  5.     }
  6.   }

Now add the trigger:

  1. $this->load->model('extension/event');
  2. $this->model_extension_event->addEvent(ˉmy_custom_header', 'catalog/view/common/header/beforeˇ,ˇ event/change_view_common_header/before_viewˇ);

You would need to add the trigger yourself during the installation of your module or use the Event Manager to do it manually

10 Secrets that will make you a master of Opencart Events?

Of course there could be an extension that also wants to change the tpl file and load its second_custom_header.tpl  so there are always a possibility of conflicts, yet with events the chances are dramatically reduced.

You can find more information in the documentation here

10 Tips that will make you events rock!

There are some rules you should know about events and trigger naming before diving into events.

1. The trigger name starts with admin or catalog. Even if you are calling a config file,which is in systemfolder, you will call it either in admin or catalog.Ex: trigger: admin/config/admin/after

2. Actions are defined only in the controllers. So even if you want to trigger them for a model, you still must define them in a controller. Ex: file location will be admin/controller/event/admin_config_modification.php

3. The Catalog View trigger before and after are different. This is not necessarily a bug, yet is not obvious from the start. Ex: before trigger: catalog/view/common/header/before Ex: after trigger: catalog/view/default/template/common/header/after

The reason this happens, is that the controller passes the $route value of ‘common/header’ yet opencart builds up the $route with the theme settings using an event action located in catalog/controller/event/theme.php. This only happens in the

catalog (frontend) and not in the admin since admin does not have a theme option.

4. You can use the wildcard symbol (*) in your trigger. This will save you the time creatingalmost the same triggers for different paths.

5. You will need to set the events upfront in your admin using the event model from your admin/model/extension/event.php. The perfect way of adding is when someone is installing your extension.

6. You can not create events from the catalog, only admin. There is no method in the catalog/model for that. Well, why would you, right?

7. Remember, that the $this-&gt;load- &gt;config does not return anything, so you can’t actually modify the $output of the config file, yet you can still add modify with $this-&gt;config-&gt;set() method.

8. Same goes for Language files, the only difference is the language $output is returned and you can evaluate it. But you still need $this-&gt;language- &gt;set() method to modify.

9. To avoid theme conflicts, you can alter the html $output of the view with simple html DOM library. You can also move the selectors to the module config and allow edit in the admin panel for the user to set it in case the custom theme differs from the default.

10. Remember that your event action is not he only one in the loop. Try to return the$output that the next action can safely use. This is probably the most important rule of them all.

view display as html in drupal 7

view display as html in drupal 7

<?php
print views_embed_view(‘search’, ‘page_1’, array(23,44,100));
?>

<?php
$output = views_embed_view(“content_link”,”block_3″);
if ($output){
print $output;
}

?>

<?php
if (views_embed_view(“content_link”,”block_3″)->result):
print views_embed_view(“content_link”,”block_3″);
endif;
?>

<div class=”container”>
<div class=”row”>

<?php
$my_view_name = ‘real_estate’;
$my_display_name = ‘Grid Properties with Pager’;
$output = views_embed_view($my_view_name,”block_6″);
if ($output){
print $output;
}

?>
</div>

</div>

Advantages and Drawbacks of Inline Styles in CSS

Advantages and Drawbacks of Inline Styles in CSS

CSS, or Cascading Style Sheets, are what is used in modern website design to apply the visual look to a page. While HTML creates the structure of the page and Javascript can handle behaviors, the look and feel of a website is the domain of CSS. When it comes to these styles, they are most often applied using external style sheets, but you can also apply CSS styles to a single, specific element by using what are known as “inline styles.”

Inline styles are CSS styles that are applied directly in the page’s HTML. There are both advantages and disadvantages to this approach. First, let’s look at exactly how these styles are written.

How to Write an Inline Style

To create an inline CSS style, you begin by writing your style property similar to how you would in a style sheet, but it needs to be all one line. Separate multiple properties with a semicolon just as you would in a style sheet.

background:#ccc; color:#fff; border: solid black 1px;

Place that line of styles inside the style attribute of the element you want to be styled. For example, if you wanted to apply this style to a paragraph in your HTML, that element would look like this:

<p style="background:#ccc; color:#000; border: solid black 1px;">

In this example, this particular paragraph would appear with a light grey background (that is what #ccc would render), black text (from the #000 color), and with a 1-pixel solid black border around all four sides of the paragraph.

Advantages of Inline Styles

Thanks to the cascade of Cascading Style Sheet inline styles have the highest precedence or specificity in a document. This means they are going to be applied no matter what else is dictated in your external stylesheet (with the one exception being any styles that are given the !important declaration that sheet, but this is not something that should be done in production sites if it can be avoided). The only styles that have higher precedence than inline styles are user styles applied by the readers themselves. If you are having trouble getting your changes to apply, you can try setting an inline style on the element. If you styles still do not display using an inline style, you know there’s something else going on.

Inline styles are easy and quick to add and you do not need to worry about writing the proper CSS selector since you are adding the styles directly to the element you want to change (that element essentially replaces the selector you would write in an external style sheet). You don’t need to create a whole new document (as with external style sheets) or edit a new element in the head of your document (as with internal style sheets). You just add the style attribute that is valid on nearly every HTML element. These are all reasons why you may be tempted to use inline styles, but you must also be aware of some very significant disadvantages to this approach.

Disadvantages of Inline Styles

Because inline styles they are the most specific in the cascade, they can over-ride things you didn’t intend them to. They also negate one of the most powerful aspects of CSS – the ability to style lots and lots of web pages from one central CSS file to make future updates and style changes much easier to manage.

If you had to only use inline styles, your documents would quickly become bloated and very hard to maintain. This is because inline styles must be applied to every element you want them on. So if you want all your paragraphs to have the font family“Arial”, you have to add an inline style to each <p> tag in your document. This adds both maintenance work for the designer and download time for the reader since you would need to change this across every page in your site to change that font-family. Alternatively, if you use a separate stylesheet, you may be able to change it in one spot and have every page receive that update. Truthfully, this is a step backward in web design – back the days of the <font> tag!

Another drawback to inline styles is that it’s impossible to style pseudo-elements and -classes with them. For example, with external style sheets, you can style the visited, hover, active, and link color of an anchor tag, but with an inline style, all you can style is the link itself, because that’s what the style attribute is attached to.

Ultimately, we recommend not using inline styles for your web pages because they cause problems and make the pages a lot more work to maintain. The only time we use them is when we want to check a style quickly during development. Once we’ve got it looking right for that one element, we move it to our external style sheet.

Heading Tags SEO: Tips for Using H1 to H6 Right Way

Heading Tags SEO: Tips for Using H1 to H6 Right Way

As we know, heading tags are imperative for every web document to structure the content. By using Heading Tags, we differentiate our web page content. Use heading tags for headings only not for making Text Large or Bold.  

Note: At the end of the article I have outlined 2 common heading tags mistakes by bloggers. Don’t miss reading it!

Definition of Heading Tags

Heading Tags are well-defined by W3Schools that:

<h1> to <h6> tags are used to define Heading on a web document.

“According to W3Schools – <h1> </h1> is the first heading which is critical for any web document and <h6></h6> is the least important heading that holds very less importance in a web document as compared to other heading tags. ”

Defined Heading Tags are:

<h1>some text here</h1>

<h2> some text here </h2>

<h3> some text here </h3>

<h4> some text here </h4>

<h5> some text here </h5>

<h6> some text here </h6>

h1 tag should be main headings which if followed by further h2, h3 and so on. The h1 is usually the boldest one whereas h6 font size is smallest.

Don’t get confuse yourself and stop thinking that Heading Tags as merely formatting for the web pages and Search Engines Heading Tags are for just categorization of content on web page.

Heading Tags come with various attributes to make user-friendly websites but Search Engines use these defined headings solely to index the structure and content of web documents including blog posts.

In other words, you can say that Heading Tags are used to show the web document structure.

How to use Heading Tags for SEO?

Apart from the web designing point of view, there are a few more things that you should know about Heading Tags.

– Purpose of using Heading Tags

The main purpose of categorizing your content with different headings so that your design become more user-friendly and people will get a notion about your website more easily by just reading the Sub-headings.

Now we know H1 tag is most important tag so whenever you going to use it for your webpage heading just try to make it like that people get an idea about your website just reading your heading. So that h1 tag should be in that way which describes everything about your web page just in one shot.

– Hierarchy

Hierarchy on your web page should be like <h1> comes first which is followed by <h2>, <h2> followed by <h3>, <h3> followed by <h4>, <h4> followed by <h5> and <h5> followed by <h6>.  For better SEO of your web page, one should have to follow the hierarchy in this way.

– Headings Tags with Keywords

Keywords are first and foremost priority of any SEO Expert. In the matter, we first do the research of best keywords according to the web page and then categorize these keywords into focus keyword, primary keyword, secondary keyword and tertiary keyword. Focus Keyword is always one for the web page. It’s better to include your focus keyword into the title, Meta tags, and h1 of the webpage.

– Frequency of Using the Heading Tags especially h1 tag

It is recommended that one should have to use h1 tag per web page because h1 tag should be like a newspaper heading and other content should be structured with subheadings by following the hierarchy of heading tags. Using of subheadings depend on the way your content is structured.

H1 Tag In Latest HTML5

In the previous versions of HTML, only one H1 tag is allowed to designers to use per web document and what people do that time – they just used H1 tag to wrap the business logoon the web page which is important for any business web page and start the main heading of the web page with the H2 tag. But with the help of updated version of Html i.e. HTML5 which allows the designer to have multiple h1 tags on a web page according to the requirements of the web page design.

Ex: Single page websites.

Well, Heading tags are crucial for the proper On page SEO of your blog posts. One mistake which is common among newbie bloggers is excessive use of H2 or H3 tags & at times skipping H2 tags & only using H3 tags.

how can access yahoo notepad in yahoo app

how can access yahoo notepad in yahoo app

Either I solved my own problem by using this URL to get to yahoo notepad…

https://calendar.yahoo.com/?view=notepad#

OR…

Yahoo Notepad is now back up and running after having been down for two or three days. Who knows?

I’m happy about this but I’m not pleased that Yahoo has no tech support or help desk that I can send

email to or call or chat with in the event of problems or to inquire about changes. I DO pay Yahoo $19.95 for premium service every year but evidently that does not include help or tech support from a human.
Yahoo Help Community was not useful for me in finding the solution or answer to my problem either.

Enable apache mod_rewrite in Ubuntu 14.04 LTS

Enable apache mod_rewrite in Ubuntu 14.04 LTS

Ubuntu 14.04 LTS comes with Apache 2.4. This new version introduced different default config filenames and in general some differences. (DocumentRoot /var/www/html)

Activate the mod_rewrite module with

sudo a2enmod rewrite

and restart the apache

sudo service apache2 restart

To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with

sudo nano /etc/apache2/sites-available/000-default.conf

Below “DocumentRoot /var/www/html” add the following lines:

<Directory “/var/www/html”>
AllowOverride All
</Directory>

Restart the server again:

sudo service apache2 restart

PHP: Easily create PDF on the fly

PHP: Easily create PDF on the fly

Here, I will be writing about two pdf creation PHP Classes. They are FPDF and TCPDF. With these classes, you can quickly, easily and effectively generate PDF files.

FPDF is smaller in size compared to TCPDF. But, in functionalities, TCPDF wins. TCPDF has lots of features and functionalities.

If you want very advanced features in PDF creation then TCPDF is for you. And, if you want just minimal features of PDF creation and want a smaller in size class then FPDF is for you.

FPDF Library: The PDF generator

Here is what the FPDF website has to say about itself:-

FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.

FPDF has other advantages: high level functions. Here is a list of its main features:

– Choice of measure unit, page format and margins
– Page header and footer management
– Automatic page break
– Automatic line break and text justification
– Image support (JPEG, PNG and GIF)
– Colors
– Links
– TrueType, Type1 and encoding support
– Page compression

FPDF requires no extension (except zlib to activate compression and GD for GIF support). It works with PHP 4 and PHP 5

Example code to create PDF file

<?phprequire('fpdf.php');classPDFextendsFPDF{//Page headerfunctionHeader(){    //Logo    $this->Image('logo_pb.png',10,8,33);    //Arial bold 15    $this->SetFont('Arial','B',15);    //Move to the right    $this->Cell(80);    //Title    $this->Cell(30,10,'Title',1,0,'C');    //Line break    $this->Ln(20);}//Page footerfunctionFooter(){    //Position at 1.5 cm from bottom    $this->SetY(-15);    //Arial italic 8    $this->SetFont('Arial','I',8);    //Page number    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');}}//Instanciation of inherited class$pdf=newPDF();$pdf->AliasNbPages();$pdf->AddPage();$pdf->SetFont('Times','',12);for($i=1;$i<=40;$i++)    $pdf->Cell(0,10,'Printing line number '.$i,0,1);$pdf->Output();?>

DEMO OF THE CODE ABOVE

DOWNLOAD FPDF || MORE TUTORIALS AND EXAMPLES

TCPDF – PHP class for PDF

Here is the introduction and main features of TCPDF:-

Started in 2002, TCPDF is now one of the world’s most active Open Source projects, used daily by millions o users and included in thousands of CMS and Web applications. TCPDF is a PHP class for generating PDF documents without requiring external extensions. TCPDF Supports UTF-8, Unicode, RTL languages, XHTML, Javascript, digital signatures, barcodes and much more.

Main Features

– no external libraries are required for the basic functions;
– all standard page formats, custom page formats, custom margins and units of measure;
– UTF-8 Unicode and Right-To-Left languages;
– TrueTypeUnicode, OpenTypeUnicode, TrueType, OpenType, Type1 and CID-0 fonts;
– font subsetting;
– methods to publish some XHTML + CSS code, Javascript and Forms;
– images, graphic (geometric figures) and transformation methods;
– supports JPEG, PNG and SVG images natively, all images supported by GD and all images supported via ImagMagick;
– 1D and 2D barcodes;
– Grayscale, RGB, CMYK, Spot Colors and Transparencies;
– automatic page header and footer management;
– document encryption up to 256 bit and digital signature certifications;
– transactions to UNDO commands;
– PDF annotations, including links, text and file attachments;
– text rendering modes (fill, stroke and clipping);
– multiple columns mode;
– no-write page regions;
– bookmarks and table of content;
– text hyphenation;
– text stretching and spacing (tracking/kerning);
– automatic page break, line break and text alignments including justification;
– automatic page numbering and page groups;
– move and delete pages;
– page compression (requires php-zlib extension);
– XOBject templates;

Example code to create PDF file

<?phprequire_once('../config/lang/eng.php');require_once('../tcpdf.php');// create new PDF document$pdf=newTCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,'UTF-8',false);// set document information$pdf->SetCreator(PDF_CREATOR);$pdf->SetAuthor('Nicola Asuni');$pdf->SetTitle('TCPDF Example 001');$pdf->SetSubject('TCPDF Tutorial');$pdf->SetKeywords('TCPDF, PDF, example, test, guide');// set default header data$pdf->SetHeaderData(PDF_HEADER_LOGO,PDF_HEADER_LOGO_WIDTH,PDF_HEADER_TITLE.' 001',PDF_HEADER_STRING);// set header and footer fonts$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN,'',PDF_FONT_SIZE_MAIN));$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA,'',PDF_FONT_SIZE_DATA));// set default monospaced font$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);//set margins$pdf->SetMargins(PDF_MARGIN_LEFT,PDF_MARGIN_TOP,PDF_MARGIN_RIGHT);$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);//set auto page breaks$pdf->SetAutoPageBreak(TRUE,PDF_MARGIN_BOTTOM);//set image scale factor$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);//set some language-dependent strings$pdf->setLanguageArray($l);// ---------------------------------------------------------// set default font subsetting mode$pdf->setFontSubsetting(true);// Set font// dejavusans is a UTF-8 Unicode font, if you only need to// print standard ASCII chars, you can use core fonts like// helvetica or times to reduce file size.$pdf->SetFont('dejavusans','',14,'',true);// Add a page// This method has several options, check the source code documentation for more information.$pdf->AddPage();// Set some content to print$html=<<<EOD<h1>Welcome to<ahref="http://www.tcpdf.org"style="text-decoration:none;background-color:#CC0000;color:black;">&nbsp;<span style="color:black;">TC</span><span style="color:white;">PDF</span>&nbsp;</a>!</h1><i>Thisisthe first example of TCPDF library.</i><p>Thistext isprinted using the<i>writeHTMLCell()</i>method but you can also use:<i>Multicell(),writeHTML(),Write(),Cell()andText()</i>.</p><p>Please check the source code documentation andother examples forfurther information.</p><pstyle="color:#CC0000;">TOIMPROVE ANDEXPAND TCPDFINEED YOUR SUPPORT,PLEASE<ahref="http://sourceforge.net/donate/index.php?group_id=128076">MAKEADONATION!</a></p>EOD;// Print text using writeHTMLCell()$pdf->writeHTMLCell($w=0,$h=0,$x='',$y='',$html,$border=0,$ln=1,$fill=0,$reseth=true,$align='',$autopadding=true);// ---------------------------------------------------------// Close and output PDF document// This method has several options, check the source code documentation for more information.$pdf->Output('example_001.pdf','I');?>

DEMO OF THE CODE ABOVE

DOWNLOAD TCPDF || MORE TUTORIALS AND EXAMPLES

You can use any one or both of them based on your requirements.

Thanks.

change password of phpmyadmin in ubuntu

change password of phpmyadmin in ubuntu

If you know your current password, you don’t have to stop mysql server. Open the ubuntu terminal. Login to mysql using:

mysql -u username -p

Then type your password. This will take you into the mysql console. Inside the console, type:

> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Then flush privileges using:

> flush privileges;

Attach SSL certificate of domain on apache server ubuntu

Attach SSL certificate of domain on apache server ubuntu

Follow these instructions to generate a certificate signing request (CSR) for your Apache Web server. When you have completed generating your CSR, cut/copy and paste it into the CSR field on the SSL certificate-request page.

To Generate a Certificate Signing Request for Apache 2.x

  1. Log in to your server’s terminal (SSH).
  2. At the prompt, type the following command: openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr  Note: Replace yourdomainwith the domain name you’re securing. For example, if your domain name is coolexample.com, you would type coolexample.key and coolexample.csr.
  3. Enter the requested information:
    • Common Name: The fully-qualified domain name, or URL, you’re securing.
      If you are requesting a Wildcard certificate, add an asterisk (*) to the left of the common name where you want the wildcard, for example *.coolexample.com.
    • Organization: The legally-registered name for your business. If you are enrolling as an individual, enter the certificate requestor’s name.
    • Organization Unit: If applicable, enter the DBA (doing business as) name.
    • City or Locality: Name of the city where your organization is registered/located. Do not abbreviate.
    • State or Province: Name of the state or province where your organization is located. Do not abbreviate.
    • Country: The two-letter International Organization for Standardization (ISO) format country code for where your organization is legally registered.  Note: If you do not want to enter a password for this SSL, you can leave the Passphrase field blank. However, please understand there might be additional risks.
  4. Open the CSR in a text editor and copy all of the text.
  5. Paste the full CSR into the SSL enrollment form in your account.

After That

  1. Goto ssl certificate in your Godaddy Account
  2. Create New Certificate
    1. Paste your CSR text into CSR text box in your account
    2. Accept and Confirm
  3. if Your certificate is already generated for prev domain or server
    1. Select Re-Key
    2. Paste your CSR text into CSR text box in your account
    3. Accept and Confirm
  4. After waiting few minutes
  5. Download Generated file
  6. Save it on your server
  7. Goto /etc/apache2/sites-available/
  8. open file with sudo in nano editor file name –  default-ssl.conf
  9. type these two lines into this file
  10. SSLCertificateFile /var/www/html/cert/a64995d1bdfa903a.crt
    SSLCertificateKeyFile /var/www/html/cert/authorizedtech.pro.key
  11. as per your crt and key file path

Useful command for apache2 for http and https

Useful command for apache2 for http and https

Disable the default Apache virtual host:

sudo a2dissite 000-default.conf

Enable the site:

sudo a2ensite example.com.conf

Restart Apache:

sudo service apache2 restart