Nn web site building blocks

From Wiki at Neela Nurseries
Revision as of 14:55, 18 June 2018 by Ted (talk | contribs)
Jump to: navigation, search

Wiki Main Page | User Page of Ted | Google search engine



Web Site Building Blocks
first article on Neela Nurseries' wiki, 2017 June



The following tools and web and programming frameworks are all part of Ted's volunteer efforts with ASI web site, and in-progress study of how to configure and customize shopping carts, article and document management pages, and easy-to-read easy-to-adjust web page layouts using CSS and third party, open source frameworks:


  • Linux package selection for constrained systems


^ MYSQL database server and client

An important MYSQL database access recovery step is to reset the database server's root password in cases where that is lost. The following statement run in a mysqld_safe --skip-grant-tables session works, while some of the more standard and MYSQL 5.7 documented password change statements fail due to a bug in MYSQL . . .


  mysql> update mysql.user set authentication_string=password('MyNewPass') where user='root';


  • PHP set up

^ Apache2 web server configuration

When setting up apache2 on Ubuntu 16.04.3 LTS host, following messages captures from this package and some PHP enabling modules:


Excerpt x -

  .
  .
  .

Selecting previously unselected package ssl-cert.
Preparing to unpack .../ssl-cert_1.0.37_all.deb ...
Unpacking ssl-cert (1.0.37) ...
Selecting previously unselected package apache2-dbg.
Preparing to unpack .../apache2-dbg_2.4.18-2ubuntu3.5_amd64.deb ...
Unpacking apache2-dbg (2.4.18-2ubuntu3.5) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu21.1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Setting up libaprutil1-dbd-sqlite3:amd64 (1.5.4-1build1) ...
Setting up libaprutil1-ldap:amd64 (1.5.4-1build1) ...
Setting up liblua5.1-0:amd64 (5.1.5-8ubuntu1) ...
Setting up apache2-bin (2.4.18-2ubuntu3.5) ...
Setting up apache2-utils (2.4.18-2ubuntu3.5) ...
Setting up apache2-data (2.4.18-2ubuntu3.5) ...
Setting up apache2 (2.4.18-2ubuntu3.5) ...
Enabling module mpm_event.
Enabling module authz_core.
Enabling module authz_host.
Enabling module authn_core.
Enabling module auth_basic.
Enabling module access_compat.
Enabling module authn_file.
Enabling module authz_user.
Enabling module alias.
Enabling module dir.
Enabling module autoindex.
Enabling module env.
Enabling module mime.
Enabling module negotiation.
Enabling module setenvif.
Enabling module filter.
Enabling module deflate.
Enabling module status.
Enabling conf charset.
Enabling conf localized-error-pages.
Enabling conf other-vhosts-access-log.

Enabling conf security.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
Setting up apache2-doc (2.4.18-2ubuntu3.5) ...
apache2_invoke: Enable configuration apache2-doc
Setting up libapache2-mod-php7.0 (7.0.25-0ubuntu0.16.04.1) ...

Creating config file /etc/php/7.0/apache2/php.ini with new version
php_invoke: Enable module xml for apache2 SAPI
php_invoke: Enable module dom for apache2 SAPI
php_invoke: Enable module tidy for apache2 SAPI
php_invoke: Enable module simplexml for apache2 SAPI
php_invoke: Enable module shmop for apache2 SAPI
php_invoke: Enable module posix for apache2 SAPI
php_invoke: Enable module iconv for apache2 SAPI
php_invoke: Enable module ftp for apache2 SAPI
php_invoke: Enable module phar for apache2 SAPI
php_invoke: Enable module ctype for apache2 SAPI
php_invoke: Enable module sockets for apache2 SAPI
php_invoke: Enable module xsl for apache2 SAPI
php_invoke: Enable module opcache for apache2 SAPI
php_invoke: Enable module gettext for apache2 SAPI
php_invoke: Enable module tokenizer for apache2 SAPI
php_invoke: Enable module fileinfo for apache2 SAPI
php_invoke: Enable module wddx for apache2 SAPI
php_invoke: Enable module pdo for apache2 SAPI
php_invoke: Enable module mysqli for apache2 SAPI
php_invoke: Enable module exif for apache2 SAPI
php_invoke: Enable module pdo_mysql for apache2 SAPI
php_invoke: Enable module sysvshm for apache2 SAPI
php_invoke: Enable module sysvmsg for apache2 SAPI
php_invoke: Enable module mysqlnd for apache2 SAPI
php_invoke: Enable module readline for apache2 SAPI
php_invoke: Enable module xmlwriter for apache2 SAPI
php_invoke: Enable module calendar for apache2 SAPI
php_invoke: Enable module xmlreader for apache2 SAPI
php_invoke: Enable module json for apache2 SAPI
php_invoke: Enable module sysvsem for apache2 SAPI
Module mpm_event disabled.
Enabling module mpm_prefork.
apache2_switch_mpm Switch to prefork
apache2_invoke: Enable module php7.0
Setting up libapache2-mod-php (1:7.0+35ubuntu6.1) ...
Setting up libapache2-mod-svn (1.9.3-2ubuntu1.1) ...
apache2_invoke: Enable module dav_svn
apache2_invoke: Enable module authz_svn
Setting up ssl-cert (1.0.37) ...
Setting up apache2-dbg (2.4.18-2ubuntu3.5) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for systemd (229-4ubuntu21.1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Press Return to continue.


Apache2 and setting up virtual hosts, web sites:

  • https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
    SSL certificates and SSL redirection
  • SSL Self-signed certificate creation and config
  • Sub-domain creation under Ubuntu 16.04 LTS and similar Linux releases
  • Mediawiki work . . .
  • OpenCart 2.x install and config, 'Wish List' and 'To Do List' . . .

    ^ Cascading Style Sheets (CSS)

    - 2018-01-15 MON -


    ^ 2017-11-27 - Web Page Fonts


    ^ 2017-11-28 - Javascript tutorials, examples and frameworks


    These are the first topics on which Ted wants to gather together notes. Hard to remember all details regarding pitfalls encountered, solutions found, and ideas for improving the configuration and use experience of these softwares . . . - TMH


    ^ PHP Libraries

    Programmer James Heinrich has written a PHP library to thumbnail and manipulate image files in other ways. James' PHP library project is available at both GitHub and SourceForge,


    To obtain a copy of this project,

       $ git clone https://github.com/JamesHeinrich/phpThumb ./phpThumb
    

    Chosen directory for downloaded instance of phpThumb is outside of web doc root. Will see whether this works . . . running in the 'demo' directory of phpThumb find that PHP's usable memory is set to -1, a seeming default value which likely won't allow phpThumb to work properly. Have per instructions installed ImageMagick utilities as available through Ubuntu 16.04.x LTS package list. The configuration checking script phpThumb/demo/phpThumb.demo.check.php so far reports that no ImageMagick program found.

    Also noticed that config checker says phpThumb cache directory present, readable but not writable. Created a /var/cache/phpThumb directory and amended file phpThumb/phpThumb.config.php. Cache directory yet reported 'not writable'. Changed ownership on this directory from root:root to www-data:www-data. Ok now writable . . . and now ImageMagick also found! Hmm, interesting.

    Demo files are a little hard to parse at first glance, which hashes of hashes set up to hold multiple demos shown in a single web document. The following phpThumb demo file at SourceForge is also part of our download. This looks like best starting point to get started and running with basic thumb-nailing of images:

       http://phpthumb.sourceforge.net/index.php?source=phpThumb.demo.object.simple.php
    


    About phpThumb file caching, this project file has important info starting at about line 135:

       https://github.com/JamesHeinrich/phpThumb/blob/master/docs/phpthumb.readme.txt
    

    "Note: phpThumb.php is where the caching code is located, if you instantiate your own phpThumb() object that code is bypassed and it's up to you to handle the reading and writing of cached files."


    When using single object to process multiple images:

       http://phpthumb.sourceforge.net/index.php?source=phpThumb.demo.object.php
    


    Summary - phpThumb file edits to get simple demo working

    We place phpThumb project files in <web_document_root>/lib/phpThumb. Here we edit two files, those named phpthumb.config.php and phpthumb.class.php. In the config file we set phpThumb's high security password to something non-null and long, non-dictionary word string:

      45 $PHPTHUMB_CONFIG['high_security_password']      = '...';
    


    In the class file we amend line 70 to name a relative path to a cache directory for phpThumb:

       70         public $config_cache_directory                      = './cache'; // null;
    


    We still can't make work the phpThumb.demo.demo.php script. We seem unable to make a successful call to the primary script with HTTP 'get' type parameters. This is the script which manages thumbnail caching, the script named phpThumb.php . . .


    - 2018-03-06 TUE -

    Excerpt from phpThumb.config.php:

    222 // * Compatability settings
    223 $PHPTHUMB_CONFIG['disable_pathinfo_parsing']        = true;   // if true, $_SERVER[PATH_INFO] is not parsed. May be needed on some     server configurations to allow normal behavior.
    224 $PHPTHUMB_CONFIG['disable_imagecopyresampled']      = false;  // if true, imagecopyresampled is replaced with ImageCopyResampleBicu    bic. May be needed for buggy versions of PHP-GD.
    225 $PHPTHUMB_CONFIG['disable_onlycreateable_passthru'] = true;   // if true, any image that can be parsed by getimagesize() can be pas    sed through; if false, only images that can be converted to GD by ImageCreateFrom(JPEG|GIF|PNG) functions are allowed
    226 $PHPTHUMB_CONFIG['disable_realpath']                = false;  // PHP realpath() function requires that "the running script must hav    e executable permissions on all directories in the hierarchy, otherwise realpath() will return FALSE". Set config_disable_realpath=    false to enable alternate filename-parsing that does not use realpath() function (but also does not resolve symbolic links)
    227 
    228 
    


    ^ Opencart Work

    How to show item quantity on the pages where items are shown during shopping:

    Within Opencart 2p3p0p2 there are at least two scripts named 'product.php'. One of these in ~/opencart-2p3p0p2/catalog/model/catalog/ defines the following public functions, and this file is mentioned in the second reference just above:

    $ grep -n function product.php 
    3:	public function updateViewed($product_id) {
    7:	public function getProduct($product_id) {
    59:	public function getProducts($data = array()) {           <-- this function starting on line 59 looks most promising
    209:	public function getProductSpecials($data = array()) {        for showing how to later access and send to browser the
    259:	public function getLatestProducts($limit) {                  quantity of each product found in a given search.  - TMH
    275:	public function getPopularProducts($limit) {
    291:	public function getBestSellerProducts($limit) {
    309:	public function getProductAttributes($product_id) {
    337:	public function getProductOptions($product_id) {
    376:	public function getProductDiscounts($product_id) {
    382:	public function getProductImages($product_id) {
    388:	public function getProductRelated($product_id) {
    400:	public function getProductLayoutId($product_id) {
    410:	public function getCategories($product_id) {
    416:	public function getTotalProducts($data = array()) {
    518:	public function getProfile($product_id, $recurring_id) {
    524:	public function getProfiles($product_id) {
    530:	public function getTotalProductSpecials() {
    
    $
    

    The token 'quantity' appears in product.php about eight or ten times, but only two of those times is it part of an assignment to a returned result, usually an array. These assignments appear respectively in functions getProduct($product_id) and getProductOptions($product_id).

    These two functions seem to query for and return a single product yet we want to see product quantities on the pages which show search results, often multiple products. The function named getProducts() seems more promising. Calls to this function are many throughout the sources of Opencart 2p3p0p2. A list of them developed via grep is posted at,

    Among these results a promising source file which may be closer to the one we need amend to show quantities on Opencart search result pages is named search.php. The other files which call this function are named after actions such as checkout which seem less related to the action of searching for items in the on-line store:

     ./catalog/controller/product/search.php:214:			$results = $this->model_catalog_product->getProducts($filter_data);
    

    There's also mention of two files in a different part of the Opencart installation:

    ./catalog/controller/common/cart.php:64:		foreach ($this->cart->getProducts() as $product) {
    ./system/library/cart/cart.php:33:	public function getProducts() {
    ./system/library/cart/cart.php:297:		foreach ($this->getProducts() as $value) {
    ./system/library/cart/cart.php:309:		foreach ($this->getProducts() as $product) {
    ./system/library/cart/cart.php:321:		foreach ($this->getProducts() as $product) {
    ./system/library/cart/cart.php:331:		foreach ($this->getProducts() as $product) {
    ./system/library/cart/cart.php:351:		foreach ($this->getProducts() as $product) {
    ./system/library/cart/cart.php:361:		$products = $this->getProducts();
    ./system/library/cart/cart.php:371:		return count($this->getProducts());
    ./system/library/cart/cart.php:379:		foreach ($this->getProducts() as $product) {
    ./system/library/cart/cart.php:389:		foreach ($this->getProducts() as $product) {
    ./system/library/cart/cart.php:399:		foreach ($this->getProducts() as $product) {
    


    2018-06-16 SAT Promising template file of Opencart which may allow for adding quantities to search results pages of the cart:

     /var/www/domainname/public_html/opencart-2p3p0p2/catalog/view/theme/default/template/product/category.tpl
    

    ^ searching for assignment to $product array

     817 ./catalog/controller/common/cart.php:65:                        if ($product['image']) {^M
     818 ./catalog/controller/common/cart.php:66:                                $image = $this->model_tool_image->resize($product['image'], $this->config->get($this->config->ge
     819 ./catalog/controller/common/cart.php:73:                        foreach ($product['option'] as $option) {^M
     820 ./catalog/controller/common/cart.php:95:                                $unit_price = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->
     821 ./catalog/controller/common/cart.php:98:                                $total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['curre
     822 ./catalog/controller/common/cart.php:105:                               'cart_id'   => $product['cart_id'],^M
     823 ./catalog/controller/common/cart.php:107:                               'name'      => $product['name'],^M
     824 ./catalog/controller/common/cart.php:108:                               'model'     => $product['model'],^M
     825 ./catalog/controller/common/cart.php:110:                               'recurring' => ($product['recurring'] ? $product['recurring']['name'] : ''),^M
     826 ./catalog/controller/common/cart.php:111:                               'quantity'  => $product['quantity'],^M
     827 ./catalog/controller/common/cart.php:114:                               'href'      => $this->url->link('product/product', 'product_id=' . $product['product_id'])^M
    

    In file along side cart.php, that is file ./catalog/controller/common/search.php what do the structure or class members 'load' and 'view' mean? Do these call the code which runs the database search and assigns results to the $products array?

    Figure x - source of file search.php:

    <?php
    class ControllerCommonSearch extends Controller {
            public function index() {
                    $this->load->language('common/search');
    
                    $data['text_search'] = $this->language->get('text_search');
    
                    if (isset($this->request->get['search'])) {
                            $data['search'] = $this->request->get['search'];
                    } else {
                            $data['search'] = '';
                    }
    
                    return $this->load->view('common/search', $data);
            }
    }
    

    We're having a hard time finding an explicit assignment to $products array. It may be that this variable is named differently in different parts of Opencart source code . . .


    ^ searching for Opencart 'load' function

    Searching for token 'load' starting in OC root, here are some clueful findings:

    
    
    ./system/startup.php:113:require_once(modification(DIR_SYSTEM . 'engine/loader.php'));
    
    ./system/framework.php:23:$loader = new Loader($registry);
    ./system/framework.php:24:$registry->set('load', $loader);
    

    It looks like finding out the meaning of Opencart 'load' function requires us to learn about an Opencart class named 'Loader' . . .

    Some further notes on files in [oc_root_dir]/system/engine:

      • registry.php . . . defines set(), get() and has() methods, where a registry instance is like a scoreboard,
      • event.php . . . defines __construct(), register(), trigger(), unregister(), removeAction()
      • action.php . . . defines __construct(), getId(), execute()

    In file system/engine/action.php there's some magic going on in function 'execute()', which loads files and creates new instances of classes dynamically . . .


    ^ searching for OC variable $products

    Searching for token 'products' . . .

    ./library/cart/cart.php:361:            $products = $this->getProducts();
    


    zzz

    ^ searching for OC function getProducts()

    There seem to be three instances of a function named getProducts() defined in three different files:

       ./search-04--token-getProducts-in-ocr.txt:1:./admin/model/catalog/product.php:343:      public function getProducts($data = array()) {
    
       ./search-04--token-getProducts-in-ocr.txt:13:./catalog/model/catalog/product.php:59:    public function getProducts($data = array()) {
    
       ./search-04--token-getProducts-in-ocr.txt:76:./system/library/cart/cart.php:33: public function getProducts() {
    

    In file ./admin/model/catalog/product.php function getProducts() appears to capture product quantities in a database query. How these are returned in an array named $rows is not yet clear . . . - TMH

    In file ./catalog/model/catalog/product.php function getProducts() makes a complicated database query, and further along its definition appears to capture product quantity like the previous definition. Here's a code snippet which hints at this, this code starting on line 158:

                    $sort_data = array(
                            'pd.name',
                            'p.model',
                            'p.quantity',
                            'p.price',
                            'rating',
                            'p.sort_order',
                            'p.date_added'
                    );
    

    But further examination looks like this may be a sub-query, providing an intermediate result which amends an encompassing query to the database. Need to confirm or rule out this case. - TMH

    Speaking of possible database sub-queries, the last lines of function getProducts in file 2 of 3 above, holds these following lines, and here worth noting that function getProducts() calls function getProduct():

    202                 foreach ($query->rows as $result) {
    203                         $product_data[$result['product_id']] = $this->getProduct($result['product_id']);
    204                 }
    205 
    206                 return $product_data;
    207         }
    

    QUESTION: is function getProduct() ultimately where a given product's quantity is either captured or omitted?


    ^ [open_cart_root]/system/engine/loader.php renders or executes PHP dot tpl files

    QUESTION: where and how are dot tpl files referenced in Opencart sources?

    ./system/storage/logs/error--opencart-default-store.log:1226:2018-06-17 17:24:20 - PHP Notice:  Undefined index: quantity in web_doc_root/public_html/opencart-2p3p0p2/catalog/view/theme/default/template/product/category.tpl on line 117
    ./system/storage/logs/error--opencart-default-store.log:1227:2018-06-17 17:54:13 - PHP Notice:  Undefined index: quantity in web_doc_root/public_html/opencart-2p3p0p2/catalog/view/theme/default/template/product/category.tpl on line 117
    ./system/storage/logs/error--opencart-default-store.log:1228:2018-06-17 18:05:09 - PHP Notice:  Undefined index: quantity in web_doc_root/public_html/opencart-2p3p0p2/catalog/view/theme/default/template/product/category.tpl on line 120
    ./system/storage/upload/temp-ld0HvNVaFCYzYxm71hXcqNjio5t1JWbe/install.xml:194:  <file path="admin/view/template/catalog/product_list.tpl">
    ./system/storage/upload/temp-LlRRskjDwZ966LGbGtkmzfNu6RcYcIS7/install.xml:194:  <file path="admin/view/template/catalog/product_list.tpl">
    ./system/storage/upload/temp-bi7quqdndkQo3DrxVdKN2HJ1qnZiCdkH/install.xml:194:  <file path="admin/view/template/catalog/product_list.tpl">
    ./system/engine/loader.php:95:                  $output = $template->render($route . '.tpl');^M
    


    ^ What We Know So Far

    Some key things we now know about code execution of Opencart's PHP scripts and template files:

      • [oc_root]/catalog/view/theme/default/template/product/category.tpl lays out HTML for each product shown in general search results,
      • [oc_root]/system/engine/loader.php references template or .tpl files by calling its $template->render() method,
      • [oc_root]/



    References


    - - - top of page - - -