📜 ⬆️ ⬇️

Creating a simple module for CMS Datalife Engine (DLE)

Hello. I want to dedicate this topic to the creation of the simplest module for the popular CMS Datalife Engine . In Russia, as well as in the CIS countries, it is quite popular, but for some reason there are still no articles about this cms in Habré. I will try to correct this misunderstanding. In this article, you will learn how to make the simplest module for this CMS, as well as get acquainted with the structure of the engine.

Introduction


I would like to note that the system is in demand among entertainment sites. It is understandable, the system is easy to use, has a sufficient number of modules and templates. Yes, and almost everything you need is out of the box. However, it happens that something is missing. We will try to solve this problem.

Why DLE?


You will certainly be interested in why I chose this particular CMS. The answer is simple: a fairly logical structure of the engine itself, the separation of templates from code, a fairly simple template engine, again, a rather logical placement of everything inside - it's easy to figure out what's what. Plus, the system remains relatively easy and convenient. It is not as functional as, for example, Drupal, but I still like it.
')

Structure


First we need to know something about the structure of the engine. You can not create a mess on the server, so we will keep everything in their folders.

Modules for engine operation are usually placed in the / engine / modules / folder.

The folder / engine / inc / contains the admin panel files.

Starting with version 8.x it appeared to connect the modules directly in the template. The template is located in the / templates / template_name / folder. This folder contains the main.tpl file. This is the root file of the template, usually it contains the main structure of the template. Usually the module can be connected like this:

{include file = "engine / modules / mod_category.php"}

Where mod_category.php is a file located in the category / engine / modules /. I think this is all clear, let's go further.

Let's make a module to display the latest comments with caching. To do this, create a file in the / engine / modules / folder and name it mod_lastcomm.php. Next, I provide a listing of the code of this file with detailed comments.

Code


<?php /*     '<i>DATALIFEENGINE</i>'.     index.php    TRUE   ,      include/require,    . */ if(!defined('DATALIFEENGINE')) { die("Hacking attempt!"); } /*   api,            . */ include ('engine/api/api.class.php'); /*   ,      lastcomm.      ,     .   <b>lastcomm</b> –     <i>/engine/cache/</i>,  <b>60</b> –      .   ,       ,  60 ,       . */ $lastcomm=$dle_api->load_from_cache( "lastcomm", 60); /*  –      .  ,    . */ if (!$lastcomm) { /*    .       $db.  PREFIX  ,    cms.     ,        .      $sql. */ $sql = $db->query("SELECT comments.post_id, comments.text, comments.autor, post.id, post.flag, post.category, post.date as newsdate, post.title, post.alt_name FROM " . PREFIX . "_comments as comments, " . PREFIX . "_post as post WHERE post.id=comments.post_id ORDER BY comments.date DESC LIMIT 0,20"); /*    get_row()  $db       .     $row       */ while ($row = $db->get_row($sql)) { /*      */ if (strlen($row['title']) > 50) { $title = substr($row['title'], 0, 50)."..."; } else { $title = $row['title']; } /*     .  */ $aname=urlencode($row['autor']); $name= "<a href=\"".$config['http_home_url']."user/".$aname."/\">". $row['autor'] .'</a>'; /*         */ $text = htmlspecialchars($row['text']); if (strlen($text) > 1024) $text= substr($text, 0, 1024)."..."; /*    .  $config    .   $config['http_home_url'] -   . */ $newslink = $config['http_home_url'].$row['post_id']."-".$row['alt_name'].".html"; $hint = "onMouseover=\"showhint('$text', this, event, '');\""; $title = "<a title=\"".$text."\" href=\"".$newslink."\">".stripslashes($title)."</a>"; /*      */ $lastcomm.=" $name  : <br /> $title <br /><br />"; } $db->free(); /*   .      ,   'engine/api/api.class.php'     */ $dle_api->save_to_cache ( "lastcomm", $lastcomm); } /*    */ echo $lastcomm; ?> 


Conclusion


This code is fully working. And of course there are flaws in it. For example, it is not checked for references whether the CNC is turned on. Or when you click on the link to the user profile, we immediately go to his profile, and not to the jQuery window with brief information. In general, there is something to modify. But all these things were not included here for one reason only - do not let the newcomer get confused. I also advise you to analyze other files, for example topnews.php. If you have any questions about writing modules or the system at all, I will be happy to answer them.

I have everything on it, if this topic seems interesting to someone, I will make a series of articles about cms Datalide Engine (DLE).

Oh yes, this is my first article on Habré, so sorry if something is wrong.

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


All Articles