Jump to content

Module for Google Fonts


alexidro

Recommended Posts

Hi, I'm trying to do a module (I'll post for free download if it works) for helping people to include a Google Fonts html tag in the <head> of the header.tpl, but when I move it to modules folder it give me the following message and won't show/install: "Parse error: syntax error, unexpected '{' in C:\Program Files (x86)\EasyPHP5.2.10\www\cosecosi\classes\Module.php(547) : eval()'d code on line 80"

I'm not an expert, I'm only trying to do some usefull tips for me and the other users, if anyone can help here is the code:

class GoogleFonts extends Module
{
   /* @var boolean error */
   protected $error = false;


   /**
   * Module constructor
   */    
   public function __construct()
   {
        $this->name = 'googlefonts';
        $this->tab = 'GoogleFonts';
        $this->version = '1.0';

        parent::__construct();

           $this->displayName = $this->l('Google Fonts');
           $this->description = $this->l('Adds your preferred Google Fonts to the header of your shop');
       $this->confirmUninstall = $this->l('Are you sure that you want to remove your Google fonts?');
   }


   /**
   * Module installer
   * Create tables
   */    
   public function install()
   {
        if (parent::install() == false OR $this->registerHook('Header') == false)
            return false;
       $query = 'CREATE TABLE '._DB_PREFIX_.'googlefonts (`content` text NOT NULL, PRIMARY KEY(`content`)) ENGINE=MyISAM default CHARSET=utf8';
        if (!Db::getInstance()->Execute($query))
            return false;
        return true;
   }

   /**
   * Module uninstaller
   * Drops tables
   */    
   public function uninstall()
   {
        if (parent::uninstall() == false)
            return false;
        if (!Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'googlefonts'))
            return false;
        return true;
   }

   /**
   * Header hook
   */    
   public function hookHeader($params)
   {
       return $this->display(__FILE__, 'googlefonts.tpl');
   }

   /**
   * Adds Google fonts in db or update
   */    
   public function addGooglefonts()
   {
        /* Multilingual googlefonts */
             if ((!empty($_POST['content_']))
             {         if (!Db::getInstance()->Execute('REPLACE INTO '._DB_PREFIX_.'googlefonts VALUES ($_POST['content_']).'\')'))
                     return false;
             }
        return true;
   }

   /**
   * Displays Google Fonts help
   */
   private function _displayGooglefontsHelp()
   {
       $this->_html .= ''.$this->l('This module allows you to insert a tag in the header to call the desired Google fonts.').'


       '.$this->l('Just copy/paste your Google fonts HTML tag in the content area, and add a inline style or modify CSS of your page to have your preferred Google fonts displayed on your site.').'

       '.$this->l('Hints:').'

       '.$this->l('- To substitute only the fonts of your homepage just add an inline style, to substitute the fonts on different pages or whole site just open your theme CSS an modify your styles').'

       '.$this->l('- If you remove the Goggle fonts feature from your site, remember to revert all the adjustment made in your CSS').'

';
   }


   /**
   * Back office control panel for Google Fonts
   */    
   public function getContent()
      {
            $this->_html = ''.$this->displayName.'';

            /* Add a free block */
            if (isset($_POST['submitGooglefontsAdd']))
            {
                      if ($this->addGooglefonts())
                          $this->_html .= $this->displayConfirmation($this->l('The Google fonts has been added successfully'));
                      else
                         $this->_html .= $this->displayError($this->l('An error occured during the Google fonts tag submission'));
            }

       $this->_displayGooglefontsHelp();
            $this->_displayForm();

           return $this->_html;
       }

   /**
   * Displays the Google Fonts and title management form
   */    
   private function _displayForm()
   {
        global $cookie;

       /* Form */
        $this->_html .= '

_path.'logo.gif" alt="" title="" /> '.$this->l('Manage your Google Fonts').'
           <form method="post" action="'.$_SERVER['REQUEST_URI'].'">

                       /* Grab free block content */
                       $googlefonts = $this->getGooglefonts);                        
                       $this->_html .= '

                       <textarea name="content_" id="contentInput_" cols="100" rows="20">'.$googlefonts['content'].'</textarea>
';
                   }
                   $this->_html .= '


';
                   $this->_html .= '<input type="submit" class="button" name="submitGooglefontsAdd" value="'.$this->l('Save this free block').'" id="submitGooglefontsAdd" />';
                   $this->_html .= '                    

           </form>
';
   }
}

Link to comment
Share on other sites

  • 1 year later...
  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...