📜 ⬆️ ⬇️

Introduction to eZ Publish on the example of creating a site

I would like to give a small example of creating a simple website on the open source content management system eZ Publish. I will try to tell the hike the advantages, disadvantages and, of course, why it is needed.

Introduction


eZ Publish - is positioned as an Enterprise Open Source CMS. Developed by eZ Systems, under the GNU General Public License.
Written in PHP.
The main feature of eZ Publish is openness, high scalability, and flexibility of use, which in this case usually attracts corporate customers and discourages everyone else.

Advantages of the system


disadvantages


Still interesting? Then go ahead to the description. But I recommend that the newcomers beginners go straight to the practical task.

Very brief description


In general, eZ Publish is more a site development environment based on the built-in library, on top of which a great variety of related functionalities are organized.
Let's try to tell about the main elements of the system without technical details.
')
Content model

The basis for working with such a system relies on an understanding of the object-oriented content model, where a site element is an object of some type or class.
Classes are formed from a set of fields or attributes. Each attribute is responsible for its data type. For example, a string, a picture or just a file.

Each change is fixed in object versions. If you wish, you can return published and modified data. You can also save a draft for future publication.

Objects, like classes, can have translations into different languages.

Template engine

For the presentation of any data used samopisny template engine eZ Template.
Templates are used almost always when you need to show some data to the user. For example, in what form to send letters to the list or how it will look like editing class attributes.

eZ Template is a coding language more than just a presentation tool. It has its own not very simple syntax that is similar to Smarty or Smarty is similar to it (since the eZ Template has been developed since the last century).
The template language has its own control structures, operators or functions, the ability to comment, work with variables, and so on. Most of this functionality can be expanded by adding your own operators, functions, which greatly simplifies the work on the site.

Template Overrides

If the data does not have its own template, then the data will not be displayed.
In the basic delivery, eZ Publish has all the necessary templates so that any data will be displayed.
In order to create your own data view and not use an ugly standard template, you will need to override it with your own.
Since templates are used for any data, this allows you to create the design of everything and everything to your own taste without editing the base installation files.

Caching

For such a dense use of templates, it is extremely necessary to have caching facilities, otherwise the site will simply be very slow.
There are several types of caching:

Work with caches is designed to manually clean the cache as rarely as possible. But still often you need to clean it manually.

Sitetaxes

The system allows you to host several sites at once on one installation.
For this, siteaccess sites were invented.
The site-session specifies settings for a specific site, such as

Settings

System settings are stored in ini files. Almost everything that can be configured is rendered in the configuration files.
Accordingly, a system for redefining them was also implemented.
In other words, you can override any setting or create your own.

In general, you can select several levels for settings:

Extensions

In extensions, you can either override the existing functionality or add your own. It is in the extensions you need to store the code for your site.
eZ Publish also uses a number of standard useful extensions.

Modules and "good" * urls

It is worth mentioning the modules and (*) nice urls.
Each node has its own unique URL. It is of two types.
1. nice url, which is formed based on the name and position of the node in the content tree. Narpimer, if the Article object is under the Folder object, then the URL will be / Folder / Article
2. The basic module for access to objects - / content / view / full / [NodeId]
Where


Practical task


Task: Demonstrate working with Easy Publish using the example of creating a greatly simplified habrahabr.ru homepage.
Namely, the withdrawal of posts to the home, which have a positive rating.

Since we are not simple people, we will not use the standard installer, but we will try to do everything manually to better feel the brunt of the ease of Easy Publish.

  1. Here you can familiarize yourself with the requirement of the ez.no/eZPublish/Requirements system. In general, this is> = PHP 5.2, Apache 2, MySQL 5.
  2. Download eZ Publish 4.4.0
    $ wget share.ez.no/content/download/103518/477729/version/1/file/ezpublishcommunity-4.4.0-with_ezc-gpl.tar.gz
  3. Unpack the file
    $ tar xfz ezpublishcommunity-4.4.0-with_ezc-gpl.tar.gz
  4. Create a new database
    mysql> create database habr default character set utf8;
  5. Initialize the database
    $ cd ezpublishcommunity-4.4.0-with_ezc-gpl
    mysql -uroot habr < kernel/sql/mysql/kernel_schema.sql
    mysql -uroot habr < kernel/sql/common/cleandata.sql
  6. Downloading the expansion narod.ru/disk/5898167001/habr-example-ezpublish.tar.gz.html
    to the root folder of Izi Publish, then install
    $ tar xfz habr-example-ezpublish.tar.gz
  7. Initialize VirtualHost
     <VirtualHost habr: 80>
         ServerName habr: 80
         ServerAdmin root @ localhost
         DocumentRoot PATH
         <Directory PATH>
            Options FollowSymLinks Indexes ExecCGI
            AllowOverride None
            Order allow, deny
            Allow from all
         </ Directory>
         RewriteEngine On
         RewriteRule ^ / var / [^ /] + / cache / public /.* - [L]
         # For all known data directories
         RewriteRule ^ / var / storage /.* - [L]
         RewriteRule ^ / var / [^ /] + / storage /.* - [L]
         RewriteRule ^ / var / cache / texttoimage /.* - [L]
         RewriteRule ^ / var / [^ /] + / cache / texttoimage /.* - [L]
         RewriteRule ^ / design / [^ /] + / (stylesheets | images | javascript) /.* - [L]
         RewriteRule ^ / share / icons /.* - [L]
         RewriteRule ^ / extension /.* - [L]
         RewriteRule. * /Index.php
     </ Virtualhost> 

  8. Enter the admin area and add the Russian language
    Go to habr / habr_admin / content / translations and add.
    User: admin
    Password: publish
  9. Create classes
    We are going to create on the main list of posts that have a rating above zero.
    For convenience, create a group of classes Habr.
    Add here habr / habr_admin / class / grouplist
    • You need to create a Frontpage class with the frontpage identifier and one text field.
      - Name [ ]
      The object of this class will be available on the main page habr
      In this object will be chosen the posts we need.
      To do this, go to the created group Habr and click "New Class".
      Add attribute.
    • You also need to keep somewhere a list of blogs, for this we create a class Blogs with the identifier blogs, with fields:
      - Name [ ]
      - Description [ ]
      - [ ]
    • Create a class Blog (id: blog), respectively, for blogs with the same fields plus
      - Index [. ] —
      - [ ]
    • Each blog will have posts, for this we create a class Post (id: post)
      with fields
      - Name [ ]
      - Content [ ]
      - Tags [ ]
      - Raiting [ ]
    You should get the following list of classes:


    All classes are ready, now you can start organizing the content tree.
  10. We create the main object
  11. Customization
    To show the newly created object on the main page, and not which default (node ​​2)
    you need to edit the file extension/habr/settings/siteaccess/rus/site.ini.append.php
    [SiteSettings]
    IndexPage=/content/view/full/62
    DefaultPage=/content/view/full/62
    Where 62 is the node (node ​​code) of this object.
    Make sure that this yadi matches your newly created object.
  12. Create a repository for blogs
    Accordingly, on the same page we also create an object of the class Blogs .
  13. Create blogs
    Go to Blogs , and create Blog type objects.
  14. Create test posts
    In these blogs we create Post objects.
    Fill the content at your discretion.
    But some of the posts should have a negative rating, and some of them should be positive in order to filter on them.
  15. Now when you go to the main page of habr you can see the following:


Explanations how it works

  1. In the settings, the default Russian siteax is set
    settings/override/site.ini.append[SiteSettings]:DefaultAccess=rus
  2. Determined that for the site rus will be used habr design
    extension/habr/settings/siteaccess/rus/site.ini.append.php[DesignSettings]:SiteDesign=habr
    The extension/habr/design folder contains the extension/habr/design folders, in this case the habr design is used .
    Here we indicate the language that will be used, i.e. rus-RU :
     [RegionalSettings]
     Locale = rus-RU
     ContentObjectLocale = rus-RU
     ShowUntranslatedObjects = disabled
     SiteLanguageList [] = rus-RU
     SiteLanguageList [] = eng-GB
     TextTranslation = enabled
    
  3. We created the most important template that will be first parsed:
    extension/habr/design/habr/templates/pagelayout.tpl
  4. For the Russian and English parts of the site, the default templates were redefined for objects of the frontpage and post class.
    extension/habr/settings/siteaccess/rus/override.ini.append.php:
     [full_blog_section]
     Source = node / view / full.tpl
     # Overridden template
     MatchFile = full / frontpage.tpl
     Subdir = templates
     # For the frontpage class
     Match [class_identifier] = frontpage
    
     [full_post]
     Source = node / view / full.tpl
     MatchFile = full / post.tpl
     Subdir = templates
     Match [class_identifier] = post
    
     [line_post]
     Source = node / view / line.tpl
     MatchFile = line / post.tpl
     Subdir = templates
     Match [class_identifier] = post 
  5. Further in the redefined template for the frontpage extension/habr/design/habr/override/templates/full/frontpage.tpl we can write the following:
     {def $ node_array = fetch (content, list, 
                               hash (parent_node_id, 2,
                                     depth, 3, 
                                     offset, $ view_parameters.offset,
                                     limit, 10,
                                     sort_by, array ('published', false ()),
                                     class_filter_type, 'include',
                                     class_filter_array, array ('post'),
                                     attribute_filter 
                                     array (array ('post / raiting', '>', '0')))}
     {foreach $ node_array as $ node_item}
         {node_view_gui view = line content_node = $ node_item}
     {/ foreach}
    

    $ node_array will contain the first 10 posts with a rating above zero.
    {node_view_gui view=line content_node=$node_item} - determines whether to display a template for the node of the view.
    In this case, the template will be displayed.
    extension/habr/design/habr/override/templates/line/post.tpl
    To display only new posts, you can use the filter attribute:
     attribute_filter, array ('and',
                              array ('published', '> =', sub (currentdate (), 86400)),
                              array ('post / raiting', '>', '0')) 

    Zafetchit only new posts with a rating above zero.
  6. When clicking on the link from the main post, the template will be used:
    extension/habr/design/habr/override/templates/full/post.tpl

    And it will look like this:


  7. A small addition: the use of line breaks in templates
    {"New"|i18n( "habr" )}
    The translations into Russian are here:
    extension/habr/translations/rus-RU/translation.ts
    that is, when you switch a site to another language, you only need to add translations to a file.


Summary


Of course, it turned out to be an inferior site, it will still have to be greatly refined, templates must be added that allow you to add content and much more. The meaning of this example is just to show where to start doing, and then you have to smoke manuals, read bug reports, beat your head against the wall, in general, everything we love to do so much.

ez.no - Website of a company that develops eZ Publish
doc.ez.no - Online Documentation
issues.ez.no - Bug Tracker
projects.ez.no - Community Ready Solutions
share.ez.no - Community Site

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


All Articles