Cursor for a site the hands. A part the second

Last time we have considered a way of the organization of "database" without actually database. Today we shall continue a subject of creation "without - mysql'nogo" sajtovogo a cursor conversation on catalogues, files and include'akh. Also will be a few{a little;little bit} theory and practice about actually job of such engine.


Main principles of the organization of job


It is simple to guess, that the organization of the device of a cursor depends on many factors changing in each concrete example of a site. It and prospective structure of the information, and feature of a hosting on which the site (presence - otstutstvie of such means as php, ssi, availability of any databases, etc. is placed), and not to a lesser degree by development of the device of the future cursor is necessary to take into account design of a site, that is structure of pages.


Actually, one of the purposes of creation of a cursor for a site is just the organization of convenient job on updating materials, and, as a precondition, practically full branch of design of a site from actually his  useful maintenance (in has bent). But in any case, the future design it is necessary uchitivat`, how - about it little bit later.


So, the word "division" means already, at least, division of page of a site into two files - with a pattern of design (which can be the general{common} for several pages) and a file with a content, that is the information.


Except for these two files to be necessary for us one more, included in all dynamic pages (are available in view of the page, containing a php-code). We shall store{keep} all general{common} functions of a cursor (actually, they can be named "nucleus") in this file, and also we shall define{determine} some useful global constants.


The primary goal of functions of a nucleus will be reading files with texts of clauses{articles}, pictures or others materilami a site, and also a conclusion of this content in the necessary form on the screen. - data input - we do not consider{examine} third function, as the way of a data storage (files with separators) allows to enter the information by means of standard means (the liked text editor, for example).


And under a phrase « to take into account design », stated little bit above, was present in view of creation of system of patterns, or, easier speaking, a set of registrations of different pages (html-files, as a matter of fact) where places under the changeable maintenance{contents} (headings, the menu, texts - everything, that is generated dynamically) are left empty. Podstavljatsja they will be "hurriedly" at the reference{manipulation} of the user to the certain page. The additional prize - among other things, umen`shaet`sja volume of files stored{kept} on the server as registration of pages does not repeat in each file turns out even, and is stored{kept} in one place. About convenience at possible{probable} desire of change of design, I think, and to speak it is not necessary.


Arrangement of files


So, we shall return to actually organization of our system. The main principle which will be used in our example is odnourovnevost` sections. But do not worry are only for simplification of examples. If for you too ser``joznoe restriction - simply it is necessary to wait for it of the following release in which we shall look for roundabout ways.


So, we have catalogues, each of which is section of a site (naturally, except for service catalogues, such, as "images").


It means, that in each such catalogue « the index file » - page which is loaded by default at such reference{manipulation} to section should lay so-called: http://site.com/razdel. The name of this file (or) to you needs to be learned{be found out} possible{probable} names from yours khostera. It is such names as "index.html", "index.php", etc. - expansion depends on used server language more often.


Means, with names of files have understood. But what to us to put in these files? Now we also pass actually to the basic part of today's conversation.


Right at the beginning of a file it is necessary to insert a code of inclusion of a nucleus of a cursor. The similar reference{manipulation} in language php looks as follows:


// Initialization of a nucleus

include ("bin/core.php");


This file contains those functions of a reading - conclusion described in last clause{article}. Thus, they now stanovjat`sja accessible to use.


In the same file it is necessary to describe still some useful functions. For example, function of direct reception of any file as a line (can it is useful):


function getinclude ($path)

{

return str_replace ("n", " ", (implode (file ($path), " ")));

}


News system


One more utility can appear function for the organization of the elementary news system. But, not looking on simplicity of realization, she has dostachno convenient features, such as a conclusion in any place of page of the block with the specified quantity{amount} of the latest news and an opportunity of the organization of archive of news.


The essence of its{her} job is reduced to sleduehhemu. There is a text file with the news divided{shared} by a symbol of translation of a line (a word, each news - in a new line). Each line is divided{shared} by a symbol of vertical feature ("|") into two fields: date and, actually, news.


Oprediliv function of news system in ours vkljuchamom a file ("nucleus"), we receive an opportunity on any page to receive the necessary quantity{amount} of the latest news. The first parameter passes the part of a way specifying accommodation of a file with news. Quantity{amount} of deduced{removed} news as you it have already guessed, set to the second, unessential, parameter.


My realization of function of news system:



function getnews ($path = "", $lim=3)

{

$news = file ($path. "news.txt");

$result = " ";


  if ($lim == 0)

  {

     $lim = count ($news);

}

 

  for ($i=0; $i <$lim ** $i <count ($news); $i ++)

  {

     $newslist = loadtemplate (" templates / _ news.tpl ");

 

     $newslist = eregi_replace (" ¤ date ¤ ",

     strtok ($news [$i], "|"), $newslist);

     $newslist = eregi_replace (" ¤ text ¤ ",

     strtok ("|"), $newslist);

 

     $result = $result. $ newslist;

}

 

  return $result;

}

// end of getnews ();


Well, for today meanwhile all. Continuation follows...