Page 1 of 9

s06e02 - XML Sitemaps

Posted: Wed Nov 03, 2021 4:46 am
by Dnj1964
@burt, @ecartz or a phoenixcart team member, just wondering if anyone has looked at the making the sitemap code compatible with 1.0.8.7?

Thanks, Doug

Re: s06e02 - XML Sitemaps

Posted: Wed Nov 03, 2021 6:29 am
by ecartz
Burt's position is that if people want updates (or backports), they should contract with one of the certified developers to get them. He's been busy with life outside the internet, so he hasn't been one of the certified developers this year. That may change in the future. But overall, he found supporters' code unprofitable, so he is unlikely to return to the old way of doing things even if he returns full time.

The last time I looked at it was 1.0.8.5. At that time, the categories hook needed to be renamed to catalog hooks. The major change since then was to the shopping cart, which shouldn't affect the site map. I think that just renaming the hook (both the class name and the file name) and adding the two compatibility listeners would make it work.

There's been some talk about creating a more up-to-date version of the supporters' code. I've coded most of it through 1.0.8.5 (the two template releases are the main exception). That's one of the things that I was doing between releases. I've been busy with other projects for the last couple releases, so some things need updated (I still plan to update for 1.0.8.7 this month, while 1.0.8.8 is going through its testing cycle). However, the real holdup is primarily testing and dissemination. We haven't found a good solution so far but are open to suggestions.

The basic problem is that all of myself, Burt, and Heatherbell have enough on our plate and can't add more. Also, since Burt has been busy offline, these discussions don't always move quickly. And of course, we don't have a good way to recruit people to do the leftover tasks.

Anyway, if you're in a real hurry, you could have one of the certified developers test and potentially fix what I have now.

Re: s06e02 - XML Sitemaps

Posted: Fri Nov 05, 2021 7:11 am
by Dnj1964
ecartz wrote: Wed Nov 03, 2021 6:29 am Burt's position is that if people want updates (or backports), they should contract with one of the certified developers to get them. He's been busy with life outside the internet, so he hasn't been one of the certified developers this year. That may change in the future. But overall, he found supporters' code unprofitable, so he is unlikely to return to the old way of doing things even if he returns full time.

The last time I looked at it was 1.0.8.5. At that time, the categories hook needed to be renamed to catalog hooks. The major change since then was to the shopping cart, which shouldn't affect the site map. I think that just renaming the hook (both the class name and the file name) and adding the two compatibility listeners would make it work.

There's been some talk about creating a more up-to-date version of the supporters' code. I've coded most of it through 1.0.8.5 (the two template releases are the main exception). That's one of the things that I was doing between releases. I've been busy with other projects for the last couple releases, so some things need updated (I still plan to update for 1.0.8.7 this month, while 1.0.8.8 is going through its testing cycle). However, the real holdup is primarily testing and dissemination. We haven't found a good solution so far but are open to suggestions.

The basic problem is that all of myself, Burt, and Heatherbell have enough on our plate and can't add more. Also, since Burt has been busy offline, these discussions don't always move quickly. And of course, we don't have a good way to recruit people to do the leftover tasks.

Anyway, if you're in a real hurry, you could have one of the certified developers test and potentially fix what I have now.
@ecartz I appreciate the tireless support from both yourself and @heatherbell .

As a "Pro Supporter" wish that sitemaps and SEO would keep pace with releases.

Suggestions?
If I had any coding ability may feel confident in making a suggestion or two...
Considering I have none, I will wait for the professionals to fix.

Again thanks and appreciation to @ecartz and @heatherbell for the hard work and support.

Re: s06e02 - XML Sitemaps

Posted: Fri Nov 05, 2021 10:13 am
by heatherbell
Dnj1964 wrote: Fri Nov 05, 2021 7:11 am As a "Pro Supporter" wish that sitemaps and SEO would keep pace with releases.
As a "Pro Supporter" you receive Supporters Addons for free. Very recently I also re-coded and packaged an addon for you for free. Naturally, I do not commit to giving updates and support to you for that addon in perpetuity for free! The same goes for Supporters Addons although I have always found support is given in the VIP Forum (another benefit of being a PRO Supporter).
Dnj1964 wrote: Fri Nov 05, 2021 7:11 am Suggestions?
There are suggestions in the previous post by ecartz but if you are unsure of what to do, I'm sure if you post the exact details of your issue, further free support would be offered here. Otherwise, if you are convinced that the addon is of value to your business it would be best to contact a Certified Developer to fix it for you as suggested by ecartz.

Re: s06e02 - XML Sitemaps

Posted: Wed Nov 10, 2021 7:00 pm
by Dnj1964
ecartz wrote: Wed Nov 03, 2021 6:29 am Burt's position is that if people want updates (or backports), they should contract with one of the certified developers to get them. He's been busy with life outside the internet, so he hasn't been one of the certified developers this year. That may change in the future. But overall, he found supporters' code unprofitable, so he is unlikely to return to the old way of doing things even if he returns full time.

The last time I looked at it was 1.0.8.5. At that time, the categories hook needed to be renamed to catalog hooks. The major change since then was to the shopping cart, which shouldn't affect the site map. I think that just renaming the hook (both the class name and the file name) and adding the two compatibility listeners would make it work.

There's been some talk about creating a more up-to-date version of the supporters' code. I've coded most of it through 1.0.8.5 (the two template releases are the main exception). That's one of the things that I was doing between releases. I've been busy with other projects for the last couple releases, so some things need updated (I still plan to update for 1.0.8.7 this month, while 1.0.8.8 is going through its testing cycle). However, the real holdup is primarily testing and dissemination. We haven't found a good solution so far but are open to suggestions.

The basic problem is that all of myself, Burt, and Heatherbell have enough on our plate and can't add more. Also, since Burt has been busy offline, these discussions don't always move quickly. And of course, we don't have a good way to recruit people to do the leftover tasks.

Anyway, if you're in a real hurry, you could have one of the certified developers test and potentially fix what I have now.
@ecartz Thanks.

So if I follow correctly.

/includes/hooks/admin/categories needs to be renamed /includes/hooks/admin/catalog

I just created a new folder named catalog and copied the XML_writer.php to it.

/includes/hooks/admin/catalog/XML_writer.php
Changed to

Code: Select all

<?php
/*
  Copyright (c) 2020, G Burton

  This work is licensed under a
  Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

  You should have received a copy of the license along with this work.
  If not, see <http://creativecommons.org/licenses/by-nc-nd/4.0/>.
*/

class hook_admin_catalog_XML_writer {

  public function listen_copyToConfirmAction() {
    xml_writer::do_XML('products');
  }
  public function listen_deleteProductConfirmAction() {
    xml_writer::do_XML('products');
  }
  public function listen_moveProductConfirmAction() {
    xml_writer::do_XML('products');
  }
  public function listen_productActionSave() {
    xml_writer::do_XML('products');
  }
  public function listen_setFlagAction() {
    xml_writer::do_XML('products');
  }
  public function listen_deleteCategoryConfirmAction() {
    xml_writer::do_XML('catalog');
  }
  public function listen_insertCategoryUpdateCategoryAction() {
    xml_writer::do_XML('catalog');
  }  
  public function listen_moveCategoryConfirmAction() {
    xml_writer::do_XML('catalog');
  }

}

Re: s06e02 - XML Sitemaps

Posted: Wed Nov 10, 2021 7:51 pm
by Dnj1964
Removed the module, and reinstalled in /admin/dashboard.
Deleted old xml files

Renewed on Dashboard page.

Generates same as previous:
XML_categories_1.xml
XML_manufacturers_1.xml
XML_products_1.xml

Shouldn't it now generate

Code: Select all

XML_catalog_1.xml
with the code changes

Re: s06e02 - XML Sitemaps

Posted: Wed Nov 10, 2021 8:00 pm
by ecartz
The hook needs these as well:

Code: Select all

  public function listen_updateProductAction() {
    $this->listen_productActionSave();
  }

  public function listen_insertProductAction() {
    $this->listen_productActionSave();
  }

Re: s06e02 - XML Sitemaps

Posted: Tue Nov 16, 2021 12:02 am
by Dnj1964
Can I create a manual sitemap page that reads only the Info pages I want.

so something like:

XML_infopages_1.xml

Code: Select all

<url>
    <loc>https://www.yoursite.com/info.php?pages_id=Info Page Number</loc>
    <lastmod>Add in date created</lastmod>
    <changefreq>weekly</changefreq>
    <priority>1</priority>
  </url>
  
Thanks, Doug

XML errors saving products

Posted: Thu Nov 18, 2021 6:22 pm
by Dnj1964
Fatal error: Uncaught Error: Call to undefined function listen_productActionSave() in /includes/hooks/admin/catalog/XML_writer.php:31

Stack trace: #0 /includes/system/versioned/1.0.8.1/hooks.php(150): hook_admin_catalog_XML_writer->listen_updateProductAction(Array)
#1 /admin/includes/segments/process_action.php(19): hooks->cat('updateProductAc...')
#2 /admin/catalog.php(32): require('/home/...')
#3 {main} thrown in /includes/hooks/admin/catalog/XML_writer.php on line 31
Not sure what I need to change to make it work


/includes/hooks/admin/catalog/XML_writer.php

Code: Select all

<?php
/*
  Copyright (c) 2020, G Burton

  This work is licensed under a
  Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

  You should have received a copy of the license along with this work.
  If not, see <http://creativecommons.org/licenses/by-nc-nd/4.0/>.
*/

class hook_admin_catalog_XML_writer {

  public function listen_copyToConfirmAction() {
    xml_writer::do_XML('products');
  }
  public function listen_deleteProductConfirmAction() {
    xml_writer::do_XML('products');
  }
  public function listen_moveProductConfirmAction() {
    xml_writer::do_XML('products');
  }
  public function listen_productActionSave() {
    xml_writer::do_XML('products');
  }
  public function listen_setFlagAction() {
    xml_writer::do_XML('products');
  }

  public function listen_updateProductAction() {
    listen_productActionSave();
  }

  public function listen_insertProductAction() {
    listen_productActionSave();
  }

  public function listen_deleteCategoryConfirmAction() {
    xml_writer::do_XML('catalog');
  }
  public function listen_insertCategoryUpdateCategoryAction() {
    xml_writer::do_XML('catalog');
  }  
  public function listen_moveCategoryConfirmAction() {
    xml_writer::do_XML('catalog');
  }

}
/includes/system/versioned/1.0.8.1/hooks.php

Code: Select all

<?php
/*
  $Id$

  CE Phoenix, E-Commerce made Easy
  https://phoenixcart.org

  Copyright (c) 2021 Phoenix Cart

  Released under the GNU General Public License
*/

  class hooks {

    protected $_site;
    protected $_hooks = [];
    const PREFIX = 'listen_';
    protected $prefix_length;
    protected $pipelines = [];
    protected $page;
    protected $hook_directories = [];

    public function __construct($site) {
      $this->_site = basename($site);
      $this->prefix_length = strlen(self::PREFIX);
      $this->add_directory(DIR_FS_CATALOG . 'includes/hooks/');
    }

    public function add_directory($directory) {
      $this->hook_directories[] = $directory . $this->_site . '/';
    }

    protected function sort_hooks() {
      foreach ( $this->_hooks as &$actions ) {
        foreach ( $actions as &$codes ) {
          uksort($codes, 'strnatcmp');
        }
      }
    }

    protected function build_callback($class, $method) {
      if ('' === $class) {
        return $method;
      }

      if (isset($_SESSION[$class]) && is_callable([$_SESSION[$class], $method])) {
        return [$_SESSION[$class], $method];
      }

      if (!class_exists($class)) {
        return null;
      }

      if (is_callable([$class, $method])) {
        $m = new \ReflectionMethod($class, $method);
        if ($m->isStatic()) {
          return [$class, $method];
        }
      }

      return [Guarantor::ensure_global($class), $method];
    }

    protected function load($group) {
      $hooks_query = $GLOBALS['db']->query(sprintf(<<<'EOSQL'
SELECT hooks_action, hooks_code, hooks_class, hooks_method
 FROM hooks
 WHERE hooks_site = '%s' AND hooks_group = '%s'
EOSQL
, $GLOBALS['db']->escape($this->_site), $GLOBALS['db']->escape($group)));

      while ($hook = $hooks_query->fetch_assoc()) {
        $callback = $this->build_callback($hook['hooks_class'], $hook['hooks_method']);
        if (is_callable($callback)) {
          Guarantor::guarantee_all(
            $this->_hooks,
            $this->_site,
            $hook['hooks_action']
          )[$hook['hooks_code']] = $callback;
        }
      }

      $this->sort_hooks();
    }

    protected function register_directory($directory, &$files) {
      if ( file_exists($directory) && ( $dir = @dir($directory) ) ) {
        while ( $file = $dir->read() ) {
          if ( !is_dir("$directory/$file") ) {
            $files[] = $file;
          }
        }

        $dir->close();
      }
    }

    public function register($group) {
      $group = basename($group);

      $files = [];
      foreach ($this->hook_directories as $directory) {
        $this->register_directory("$directory$group", $files);
      }

      foreach ($files as $file) {
        $pathinfo = pathinfo($file);
        if ( 'php' === $pathinfo['extension'] ) {
          $class = "hook_{$this->_site}_{$group}_{$pathinfo['filename']}";

          foreach ( get_class_methods(Guarantor::ensure_global($class)) as $method ) {
            if ( substr($method, 0, $this->prefix_length) === self::PREFIX ) {
              $action = substr($method, $this->prefix_length);
              Guarantor::guarantee_all($this->_hooks, $this->_site, $action
                )[$pathinfo['filename']] = [$GLOBALS[$class], $method];
            }
          }
        }
      }

      $this->load($group);
    }

    public function register_page() {
      $this->page = pathinfo($GLOBALS['PHP_SELF'], PATHINFO_FILENAME);
      $this->register($this->page);
      $this->register_pipeline('siteWide');
      $this->call('siteWide', 'injectAppTop');
    }

    public function register_pipeline($pipeline, &$parameters = null) {
      $this->register($pipeline);
      $this->call($this->page, "{$pipeline}Start", $parameters);
    }

    public function set($action, $code, $callable) {
      $hooks =& Guarantor::guarantee_all($this->_hooks, $this->_site, $action);
      $hooks[$code] = $callable;

      uksort($hooks, 'strnatcmp');
    }

    public function call($group, $action, $parameters = []) {
      return $this->cat($action, $parameters);
    }

    public function cat($action, $parameters = []) {
      $result = '';
      foreach ( @(array)$this->_hooks[$this->_site][$action] as $callback ) {
        $result .= call_user_func($callback, $parameters);
      }

      if ( $result ) {
        return $result;
      }
    }

    public function generate($action, $parameters = []) {
      foreach ( @(array)$this->_hooks[$this->_site][$action] as $callback ) {
        yield call_user_func($callback, $parameters);
      }
    }

    public function chain($action, $parameters = []) {
      foreach ( @(array)$this->_hooks[$this->_site][$action] as $callback ) {
        $parameters = call_user_func($callback, $parameters);
      }

      return $parameters;
    }

    public function get_hook_directories() {
      return $this->hook_directories;
    }

  }
  

/admin/includes/segments/process_action.php

Code: Select all

<?php
/*
  $Id$

  CE Phoenix, E-Commerce made Easy
  https://phoenixcart.org

  Copyright (c) 2021 Phoenix Cart

  Released under the GNU General Public License
*/

  Guarantor::ensure_global('Admin');
  $action = $_GET['action'] ?? '';
  $admin_hooks->cat('preAction');

  if ($action && ($action_file = $Admin->locate_action($action))) {
    $action_redirect = require $action_file;
    $admin_hooks->cat(Admin::camel_case($action) . 'Action');

    if (is_string($action_redirect) || ($action_redirect instanceof Href)) {
      Href::redirect($action_redirect);
    }
  }

  $admin_hooks->cat('postAction');
  if (!isset($_SESSION['sessiontoken'])) {
    Form::reset_session_token();
  }
/admin/catalog.php

Code: Select all

<?php
/*
  $Id$

  CE Phoenix, E-Commerce made Easy
  https://phoenixcart.org

  Copyright (c) 2021 Phoenix Cart

  Released under the GNU General Public License
*/

  $always_valid_actions = ['set_flag'];
  require 'includes/application_top.php';

  $currencies = new currencies();

  // calculate category path
  if (empty($_GET['cPath'])) {
    $current_category_id = 0;
    $cPath = '';
  } else {
    $cPath_array = array_unique(
      array_map('intval', explode('_', $_GET['cPath'])),
      SORT_NUMERIC);
    $cPath = implode('_', $cPath_array);
    $current_category_id = end($cPath_array);
  }

  const DIR_FS_CATALOG_IMAGES = DIR_FS_CATALOG . 'images/';

  require 'includes/segments/process_action.php';

// check if the catalog image directory exists
  if (is_dir(DIR_FS_CATALOG_IMAGES)) {
    if (!Path::is_writable(DIR_FS_CATALOG_IMAGES)) {
      $messageStack->add(sprintf(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, DIR_FS_CATALOG_IMAGES), 'error');
    }
  } else {
    $messageStack->add(sprintf(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, DIR_FS_CATALOG_IMAGES), 'error');
  }

  require 'includes/template_top.php';

  $base_url = HTTP_SERVER . DIR_WS_ADMIN;

  if ($view_file = $Admin->locate('/views', $action)) {
    require $view_file;
  }
?>

<script>
$(document).on('change', '#cImg, [id^=pImg]', function (event) { $(this).next('.custom-file-label').html(event.target.files[0].name); });
</script>


<?php
  require 'includes/template_bottom.php';
  require 'includes/application_bottom.php';
?>
Thanks, Doug

Re: XML errors saving products

Posted: Thu Nov 18, 2021 7:27 pm
by Omar_one
I changed this lines in /includes/hooks/admin/catalog/XML_writer.php (I am not sure if this right but the error not shown any more)

Code: Select all

public function listen_updateProductAction() {
    listen_productActionSave();
  }

  public function listen_insertProductAction() {
    listen_productActionSave();
  }
to this

Code: Select all

 public function listen_updateProductAction() {
     xml_writer::do_XML('products');
  }

  public function listen_insertProductAction() {
     xml_writer::do_XML('products');
       }