Jump to content
Latest News: (loading..)
Gyakutsuki

Tuto : How to make Header Tags under app APP

Recommended Posts

Hello,

I am continuing my investigations under osc 2.4 and my learning


This tuto will help you to create a new header Tags approach inside OSC using the new concept in 2.4  App
Currently, header tags is under includes/modules/header_tags.

The goal is to include Header Tags inside the Apps. That's the goals to make.

How to do that ?

Currently, Osc 2.4 doesn't include this element. I don't know if @Harald Ponce de Leon want to include that inside OSC.

The main advantage of this approach is to develop an APPS with all inside a directory and not to have all information everywhere inside the sites.

It's  just a little modification inside template.php.

That's all to have something cool :)

@Harald Ponce de Leon is to you to decide if you want to include this element inside App.

How to do that !

=================================
Step 1 : Preparation of the elements including abstract and Interface

1-a
includes/OM/Modules create a files called HeaderTags.php

<?php
/*
 * HeaderTags.php
 * @copyright Copyright 2008 - gyakutsuki
 * @copyright Portions Copyright osCommerce
 * @license GNU Public License V2.0
*/

  namespace OSC\OM\Modules;

  use OSC\OM\Apps;

  class HeaderTags extends \OSC\OM\ModulesAbstract  {
    public function getInfo($app, $key, $data)  {
        $result = [];

        $class = $this->ns . $app . '\\' . $data;

        if (is_subclass_of($class, 'OSC\OM\Modules\\' . $this->code . 'Interface')) {
            $result[$app . '\\' . $key] = $class;
        }

        return $result;
    }

    public function getClass($module)  {

     list($vendor, $app, $code) = explode('\\', $module, 3);

      $info = Apps::getInfo($vendor . '\\' . $app);

      if (isset($info['modules'][$this->code][$code])) {
          return $this->ns . $vendor . '\\' . $app . '\\' . $info['modules'][$this->code][$code];
      }
    }
  }

2-a
includes/OM/Modules create a files called HeaderTagsAbstract.php

<?php
/*
 * HeaderTagsAbstract.php
 * @copyright Copyright 2008 - Gyakutsuki
 * @copyright Portions Copyright osCommerce
 * @license GNU Public License V2.0
*/

  namespace OSC\OM\Modules;

  use OSC\OM\Registry;

  abstract class HeaderTagsAbstract implements \OSC\OM\Modules\HeaderTagsInterface
  {
    public $code;
    public $title;
    public $description;
    public $sort_order;
    public $enabled = false;

    protected $db;

    abstract protected function init();
    abstract public function getOutput();
    abstract public function install();
    abstract public function keys();

    final public function __construct()
    {
      $this->code = (new \ReflectionClass($this))->getShortName();

      $this->db = Registry::get('Db');

      $this->init();
    }

    public function isEnabled() {
      return $this->enabled;
    }

    public function check() {
      return isset($this->sort_order);
    }

    public function remove() {
      return $this->db->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")');
    }
  }

3-a
includes/OM/Modules create a files called HeaderTagsAbstract.php

<?php
/*
 * HeaderTagsInterface.php
 * @copyright Copyright 2008 - Gyakutsuki
 * @copyright Portions Copyright osCommerce
 * @license GNU Public License V2.0
*/

  namespace OSC\OM\Modules;

  interface HeaderTagsInterface
  {
      public function getOutput();
      public function install();
      public function keys();
      public function isEnabled();
      public function check();
      public function remove();
  }

=====================================
Step 2 Call the new class element inside template

Edit includes/classes/osc_templates

1-a 
Just after

  use OSC\OM\Registry;

add

  use OSC\OM\Apps;


2-a
just before

    function addBlock($block, $group) {
      $this->_blocks[$group][] = $block;
    }

Add

    public function getAppsHeaderTags() {
      if ( defined('MODULE_HEADER_TAGS_INSTALLED') && !is_null(MODULE_HEADER_TAGS_INSTALLED) ) {
        $header_tags_array = explode(';', MODULE_HEADER_TAGS_INSTALLED);

        foreach ($header_tags_array as $header) {
          if (strpos($header, '\\') !== false) {
            $class = Apps::getModuleClass($header, 'HeaderTags');
            $ad = new $class();

            if ( $ad->isEnabled() ) {
              echo $ad->getOutput();
            }
          }
        }
      }
    }

 

=====================================
Step 3 : Called inside your app the header tag

I am supposing you have developped an app, there the main elements to include inside

3-a edit your oscommerce.json

just below  
 

"modules": {

add

  "HeaderTags": {
    "RSS":    "Module\\HeaderTags\\RSS"
  },

3-b Create a directory called
- Module
-- Headertags

3-c Create a files called RSS
An full example about the rss header tags

<?php
/**
 * RSS.php
 * @copyright Copyright 2008 - Gyakutsuki
 * @copyright Portions Copyright osCommerce
 * @license GNU Public License V2.0
*/

  namespace OSC\Apps\Communication\PageManager\Module\HeaderTags;

  use OSC\OM\Registry;
  use OSC\OM\HTTP;

  use OSC\Apps\Communication\PageManager\PageManager as PageManagerApp;

  class RSS extends \OSC\OM\Modules\HeaderTagsAbstract {

    protected $lang;
    public $group;

    protected function init() {
      if (!Registry::exists('PageManager')) {
        Registry::set('PageManager', new PageManagerApp());
      }

      $this->app = Registry::get('PageManager');
      $this->lang = Registry::get('Language');
      $this->group = 'header_tags'; // could be header_tags or footer_scripts

      $this->app->loadDefinitions('Module/Admin/header_tags/rss');

      $this->title = $this->app->getDef('module_header_tags_rss_title');
      $this->description = $this->app->getDef('module_header_tags_rss_description');

      if ( defined('MODULE_HEADER_TAGS_RSS_STATUS') ) {
        $this->sort_order = (int)MODULE_HEADER_TAGS_RSS_SORT_ORDER;
        $this->enabled = (MODULE_HEADER_TAGS_RSS_STATUS == 'True');
      }
    }

    public function isEnabled() {
      return $this->enabled;
    }

    public function getOutput() {

      $xml = $OSCOM_Template->addBlock('<link rel="alternate" type="application/rss+xml" title="' . STORE_NAME . '" href="index.php?Info&RSS'.'">', $this->group);
      $output =
<<<EOD
{$xml}
EOD;
      return $output;
    }

    public function Install() {
      $this->app->db->save('configuration', [
          'configuration_title' => 'Do you want install this module ?',
          'configuration_key' => 'MODULE_HEADER_TAGS_RSS_STATUS',
          'configuration_value' => 'True',
          'configuration_description' => 'Do you want install this module ?',
          'configuration_group_id' => '6',
          'sort_order' => '1',
          'set_function' => 'osc_cfg_set_boolean_value(array(\'True\', \'False\'))',
          'date_added' => 'now()'
        ]
      );


      $this->app->db->save('configuration', [
          'configuration_title' => 'Display sort order',
          'configuration_key' => 'MODULE_HEADER_TAGS_RSS_SORT_ORDER',
          'configuration_value' => '210',
          'configuration_description' => 'Display sort order (The lower is displayd in first)',
          'configuration_group_id' => '6',
          'sort_order' => '215',
          'set_function' => '',
          'date_added' => 'now()'
        ]
      );
    }

    public function keys() {
      return ['MODULE_HEADER_TAGS_RSS_STATUS',
               'MODULE_HEADER_TAGS_RSS_SORT_ORDER'
              ];
    }
  }

=====================================
Step 4

4-a
Edit OSC/Sites/templates/Sail

Just above (important) this code

<?php echo $oscTemplate->getBlocks('header_tags'); ?>

add
 

<?php echo $oscTemplate->getAppsHeaderTags(); ?>


I hope do not forgotten anything
That'All !!

 

Others tutos about  OSC 2.4

 

 

 

Edited by Gyakutsuki

Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

Tuto for 2.4 :
- How to Display a new page with app
- How to make Header Tags under app APP
- How to make a
boostrap modal with external element

Share this post


Link to post
Share on other sites

Just for information, a little bug I have discovered. The solution

<?php echo $oscTemplate->getAppsHeaderTags(); ?>

must be before 

<title><?php echo HTML::outputProtected($oscTemplate->getTitle()); ?></title>

 


Regards
-----------------------------------------
Loïc

Contact me by skype for business
Contact me @gyakutsuki for an answer on the forum

Tuto for 2.4 :
- How to Display a new page with app
- How to make Header Tags under app APP
- How to make a
boostrap modal with external element

Share this post


Link to post
Share on other sites

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

×