How ounziw/recently_viewed_page works
Step 1. Identify Main Components:
• Client-Side Logic – The add-on uses JavaScript (record.js, view.js) and leverages local storage to store and retrieve browsing history. This allows the client’s browser to retain data independent of server load or caching.
• Custom Templates – Under the “templates/withimage” folder, there are template files (view.php, view.js) to customize the appearance of the recently viewed items based on the theme. The integration with underscore.js (concrete5 includes this library) is used for rendering dynamic content.
Step 2. Analyze Relationships and Data Flow:
• The Frontend (Web Browser):
– Activates client-side JavaScript (record.js, view.js) that captures the page visit events and interacts with local storage.
– Uses customized templates to render the block’s UI, drawing data from local storage and possibly from the PHP controller.
• The Block (Server-Side PHP):
– Uses PHP files (controller.php, add.php, edit.php) to initialize the block and manage configuration within concrete5.
– The db.xml may be responsible for any database schema needed on installation, despite the primary storage being on the client.
• Concrete5 Core System:
– Acts as the integration framework that loads the add-on’s components through its block mechanism and its theme engine, ensuring proper rendering and configuration.
• Data Flow:
– The client’s browser loads the page with the block.
– The JavaScript code captures the user’s interactions and updates local storage.
– The PHP block controller may retrieve or send additional configuration or template data as required for rendering.
Step 3. Highlight Architectural Patterns and Technologies:
• Integration Pattern – This add-on follows a plug-in or modular approach, where its PHP components are registered as a block inside the concrete5 CMS.
• Clear Separation of Client and Server – The client handles the real-time tracking using JavaScript and local storage, minimizing server load; whereas the server-side code is mainly for integration with the CMS and providing configuration.
• Use of Concrete5’s Templating – The custom template supports theming and dynamic content rendering through underscore.js.
• Dependency on Concrete5 Core – The project relies on concrete5 (v7.5+ as noted) with its inherent architectural constraints.
– Inside this block, list the server-side components (PHP controller, configuration files like db.xml, installation scripts).
Architectural separation by grouping blocks together
– Group together all files and functionalities that belong to the server-side (PHP files, installation scripts) separately from the client-side (JS and templates).
– Highlight the customization extension point with the “withimage” template as part of the overall block’s presentation layer.
Step 5. Final Touches:
• Annotations to indicate that the main design principle is offloading history tracking to the client to reduce server load.
• Mention key dependencies (underscore.js, concrete5 versions, and local storage use).