📜 ⬆️ ⬇️

Xaraya CMS - Chapter One, "Introduction"

Xaraya (read "Zaray") - not just another CMS. It provides a thoughtful site administrator who is ready to spend some time on mastering the architecture and understanding the internal structure, in fact, a ready-made framework that allows you to do anything.
The entry threshold for Xaraya is slightly higher than other CMS I know, but, firstly, not much, and secondly, believe me, it's worth it.
In this article I will try to simplify the beginning of work with Xaraya as much as possible, and at the same time I will talk about how to tie all sorts of librarians and chess to the site. All of the following applies to branch 1. * (the latest version at the moment is 1.2.3 , it makes sense to download it immediately, so that you don’t look for modules). Vetka 2. * somehow did not impress me, a lot was redone, there is no backward compatibility, many modules are not yet adapted - in general, it is damp for stable operation.
Xaraya Logo

Installation


Installing Xaraya is very simple - you need to download the distribution kit, unpack the contents of the html folder, for example, to the root of the site (or not to the root), prepare an empty database and go to the browser at XARAYA_HOME/install.php . The installer will guide you through the whole process and soon you will have a working site (do not forget to delete the install.php and upgrade.php after that.

Key points of architecture


Xaraya is a modular MVC application. The basic package includes everything needed to deploy a regular site. The unit of information in Xaraya is “publication.” The publication consists of a set of "fields" (for example, "Title", "Introduction", "Text", "Picture"). Each type of publication has several output templates (for example: “in the ribbon”, “on a separate page”). You can look at the pre-installed types of publications in (here and below: XARAYA_HOME is something like mybestsite.ru mybestsite.ru ) XARAYA_HOME/index.php?module=articles&type=admin&func=pubtypes .
A set of output templates is called a theme (“theme”) and is located in the themes folder. Management is carried out through XARAYA_HOME/index.php?module=themes&type=admin&func=list . You may notice that the RSS and the “print version” are also made through themes, which makes it easier to edit the output for different “devices”.

Xaraya themes


Creating your own theme - the process is initially non-trivial, but exciting.
The template language is XML with additional whistles (about them later). Xaraya will search for the template first in the appropriate directory of your theme, then - if it does not appear there - in the xartemplates folder of the corresponding module. The search is carried out by the name of the template . For example, trying to display a blog entry ( articles module, news publication type, display type - display ), Xaraya will first look in the /themes/YOUR_THEME/modules/ articles folder and look for the user-display-news.xt file there. If it does not find it, take the standard one from the delivery (/ /modules/articles/xartemplates/user-display-news.xd ). Thus cascading is ensured - you will have to rewrite only those templates that do not suit you in the standard representation.
The main templates — page templates — are in the /themes/YOUR_THEME/pages folder. There are three main ones:
Here is a more or less standard view of the default.xt file:
 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE blocklayout PUBLIC "-//XAR//DTD BL 1.0 Strict//EN" "http://xaraya.com/bl1/DTD/bl1-strict.dtd"> <?xar type="page" ?> <xar:blocklayout version="1.0" content="text/html" xmlns:xar="http://xaraya.com/2004/blocklayout" dtd="xhtml1-strict"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <xar:set name="topnavblocksgroup"><xar:blockgroup name="topnav" id="topnav" /></xar:set> <xar:set name="rightblocksgroup"><xar:blockgroup name="right" id="right" /></xar:set> <xar:set name="leftblocksgroup"><xar:blockgroup name="left" id="left" /></xar:set> <xar:set name="centerblocksgroup"><xar:blockgroup name="center" id="center" /></xar:set> <xar:set name="themedir">#xarTplGetThemeDir()#</xar:set> <xar:set name="sitename"><xar:var scope="module" module="themes" name="SiteName" /></xar:set> <xar:template file="headtagcontent" type="theme" /> </head> <body> <div id="xc-outer-wrapper"> <xar:if condition="!empty($topnavblocksgroup)"> <xar:var name="topnavblocksgroup" /> </xar:if> <xar:template file="pageheader" type="theme" /> <xar:template file="pageblockgroups" type="theme" /> <xar:template file="pagefooter" type="theme" /> </div> <xar:base-render-javascript position="body" /> </body> </html> </xar:blocklayout> 

Blocks can be grouped (see xar:blockgroup name="*" id="*" ). The variables and functions of the controller can be accessed through the #PHP_CODE# construct. Variables are transferred from the controller, which lies in /modules/MODULE_NAME/xaruser . The model is located in /modules/MODULE_NAME/xaruserapi . In Xaraya, almost everything is organized through naming conventions; for example, the output controller of a separate publication lives in / /modules/articles/xaruser/display.php / articles_user_display($args) /modules/articles/xaruser/display.php , in the articles_user_display($args) function articles_user_display($args) and transmits the data to the template like this ( $data and $template , of course, prepared in the function code itself):
 return xarTplModule('articles', 'user', 'display', $data, $template); 

At the time of writing and debugging templates - I recommend enabling the option “Show template filenames in HTML comments” on the Admin ⇒ Themes ⇒ Modify Config XARAYA_HOME/index.php?module=themes&type=admin&func=modifyconfig ( XARAYA_HOME/index.php?module=themes&type=admin&func=modifyconfig ). By the way, the CNC can be separately enabled for each module in the settings, and the Russian localization can be downloaded and unpacked into the /var/locales/ folder.

Practice


Actually, it would be time to write some kind of template. I recommend creating a new “news” type publication to make it easier to debug a template. Here is the code from the topic of my blog:
 <xar:template file="user-display-title" type="module"/> <xar:if condition="!empty($data['summary'])"> <div class="summary">#$data['summary']#</div> </xar:if> <xar:if condition="!empty($data['body'])"> <div class="body">#$data['body']#</div> </xar:if> <xar:if condition="!empty($data['notes'])"> <div class="notes"><p><em>#$data['notes']#</em></p></div> </xar:if> <xar:block module="base" type="html" instance="disqus" /> <xar:if condition="!empty($data['hooks'])"> <xar:foreach in="$data['hooks']" key="$hookmodule"> <xar:if condition="!empty($data['hooks'][$hookmodule])"> <xar:template file="schild" type="module" subdata="array( 'contentfile'=>'prevart-hooks', 'hookmodule'=>$hookmodule, 'data'=>$data )" /> </xar:if> </xar:foreach> </xar:if> 

At first I “connect” the header output template - I have it the same for all types of publications, and I don’t like to duplicate the code. Then I display the recording fields (if they are not empty). Then I output the comment block (I use DISQUS for this, in the called block, just the snippet that they gave me). Then I call the conversion hooks (you need to write about the hooks separately, but for the time being I’ll limit myself to what they are; tags, for example, are displayed here through the corresponding hook, because the articles module does not know anything about the tags). Here is what it looks like as a result:
Xaraya rendering
Please note: comments are displayed through your template, tags through yours, and they can all be different.

The summing up


For the introduction, it seems to me enough. I got a slightly confused note, but I honestly tried to tell about the main architecture, to give, perhaps, an introduction.
If the topic turns out to be interesting - I can continue (for example, tell about the creation of a topic from zero to the “working version”, or carry out through the procedure of “creating a module”). Its modules are what turns Xaraya into a framework. Well, let alone its own theme - it is so easily customizable in the smallest details that, often, it becomes simply impossible to “recognize” the engine.
If I missed something important to understand the mechanism of the work of this CMS - be sure to ask in the comments. Updates to articles are still allowed.

Upd : I'm shocked. I was asked to tell me what I know about Xaraya - and now I can’t post a link because of 22 fallen minuses in karma.
Well, sit without a link ;-)

')

Source: https://habr.com/ru/post/115052/


All Articles