Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Another commit to the trunk.
[kiriwrite/.git] / cgi-files / Modules / Output / Normal.pm
1 #################################################################################
2 # Kiriwrite Output Module - Normal Output Module.                               #
3 # Outputs the pages exactly as previous versions of Kiriwrite (before 0.5.0).   #
4 #                                                                               #
5 # Copyright (C) 2007 Steve Brokenshire <sbrokenshire@xestia.co.uk>              #
6 #                                                                               #
7 # This module is licensed under the same license as Kiriwrite which is the GPL. #
8 #                                                                               #
9 # This program is free software; you can redistribute it and/or modify it under #
10 # the terms of the GNU General Public License as published by the Free          #
11 # Software Foundation; as version 2 of the License.                             #
12 #                                                                               #
13 # This program is distributed in the hope that it will be useful, but WITHOUT   #
14 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
15 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.#
16 #                                                                               #
17 # You should have received a copy of the GNU General Public License along with  #
18 # this program; if not, write to the Free Software Foundation, Inc., 51         #
19 # Franklin St, Fifth Floor, Boston, MA 02110-1301 USA                           #
20 ################################################################################# 
22 # Define the package (perl module) name.
24 package Modules::Output::Normal;
26 # Enable strict and use warnings.
28 use strict;
29 use warnings;
30 use Encode qw(decode_utf8);
31 use Tie::IxHash;
32 use Modules::System::Common;
34 # Set the following values.
36 our $VERSION = "0.5.0";
37 my ($pages, %pages);
38 my $error_flag = 0;
39 my $error_message = "";
40 my $language_name = "";
41 my %optionshash = ();
43 tie(%pages, "Tie::IxHash");
45 sub new{
46 #################################################################################
47 # new: Create an instance of Modules::Output::Normal                            #
48 #                                                                               #
49 # Usage:                                                                        #
50 #                                                                               #
51 # $dbmodule = Modules::Output::Normal->new();                                   #
52 #################################################################################
53         
54         # Get the perl module name.
56         my $class = shift;
57         my $self = {};
59         return bless($self, $class);
61 }
63 sub initialise{
64 #################################################################################
65 # initialise: Initialises the output module.                                    #
66 #                                                                               #
67 # Usage:                                                                        #
68 #                                                                               #
69 # $outputmodule->initialise();                                                  #
70 #################################################################################
72 }
74 sub loadsettings{
75 #################################################################################
76 # loadsettings: Loads some settings for the output module.                      #
77 #                                                                               #
78 # Usage:                                                                        #
79 #                                                                               #
80 # $outputmodule->loadsettings(language, optionshash);                           #
81 #                                                                               #
82 # language      Specifies the language to use.                                  #
83 # datetime      Specifies the date and time format.                             #               
84 # optionshash   Specifies the hash that contains the options for the module.    #
85 #################################################################################
87         my $class = shift;
88         my $passed_lang = shift;
90         (%optionshash) = @_;
92         $language_name = $passed_lang;
94         # Check for any blank variables.
96         $optionshash{outputmodule_seperatedirdatabase} = "off" if !$optionshash{outputmodule_seperatedirdatabase};
98 }
100 sub getoptions{
101 #################################################################################
102 # getoptions: Gets the options that will be used.                               #
103 #                                                                               #
104 # Usage:                                                                        #
105 #                                                                               #
106 # %options = $outputmodule->getoptions();                                       #
107 #################################################################################
109         my (%options, $options);
110         tie(%options, "Tie::IxHash");
112         $options{seperatedirdatabase}{type} = "checkbox";
113         $options{seperatedirdatabase}{string} = languagestrings("seperatedirdatabase");
114         return %options;
118 sub addpage{
119 #################################################################################
120 # addpage: Adds a page.                                                         #
121 #                                                                               #
122 # Usage:                                                                        #
123 #                                                                               #
124 # $outputmodule->addpage({ Page => "index.html", Data => $pagedata,             #
125 #                               Title => $title, Section => $section,           #
126 #                               LastModified => $lastmodified,                  #
127 #                               Database => $database });                       #       
128 #                                                                               #
129 # Page          Specifies the page name to use.                                 #
130 # Data          Specifies the data of the page.                                 #
131 # Title         Specifies the title of the page.                                #
132 # Section       Specifies the section of the page.                              #
133 # LastModified  Specifies when the page was last modified.                      #
134 # Database      Specifies the name of the database it came from.                #
135 #################################################################################
137         # Not needed for this module.
139         return;
143 sub outputpage{
144 #################################################################################
145 # outputpage: Outputs a page.                                                   #
146 #                                                                               #
147 # Usage:                                                                        #
148 #                                                                               #
149 # $outputmodule->outputpage({ Page => "index.html", Data => $pagedata,          #
150 #                               Title => $title, Section => $section,           #
151 #                               LastModified => $lastmodified,                  #
152 #                               Database => $database });                       #       
153 #                                                                               #
154 # Page          Specifies the page name to use.                                 #
155 # Data          Specifies the data of the page.                                 #
156 # Title         Specifies the title of the page.                                #
157 # Section       Specifies the section of the page.                              #
158 # LastModified  Specifies when the page was last modified.                      #
159 # Database      Specifies the name of the database it came from.                #
160 #################################################################################
162         my $class = shift;
163         my ($options) = @_;
165         my $page_filename       = $options->{"Page"};
166         my $page_data           = $options->{"Data"};
167         my $page_database       = $options->{"Database"};
169         my $page_filename_length        = 0;
170         my $page_filename_seek          = 0;
171         my $page_filename_dircount      = 0;
172         my $page_filename_permissions   = 0;
173         my $page_filename_directory     = "";
174         my $page_filename_char          = "";
175         my $page_filename_exists        = "";
176         my $page_directory_name         = "";
177         my $page_directory_path         = "";
178         my @pagedirectories;
179         my $filehandle_page;
181         # Check if the use seperate directory option is enabled and add the
182         # database name to the start of the filename.
184         if ($optionshash{outputmodule_seperatedirdatabase} eq "on"){
185                 ($page_database) = $page_database =~ m/^(.*)$/g;
186                 $page_filename = $page_database . "/" . $page_filename;
187         }
189         # Process the page filename and check what directories
190         # need to be created.
192         $page_filename_length = int(length($page_filename));
194         do {
196                 $page_filename_char = substr($page_filename, $page_filename_seek, 1);
198                 # Check if a forward slash appears and add it to
199                 # the list of directories array.
201                 if ($page_filename_char eq '/'){
203                         # Append the directory name to the list of
204                         # directories array.
206                         $pagedirectories[$page_filename_dircount] = $page_filename_directory;
207                         $page_filename_directory        = "";
208                         $page_filename_char             = "";
209                         $page_filename_dircount++;
211                 } else {
213                         # Append the character to the directory/filename.
215                         $page_filename_directory = $page_filename_directory . $page_filename_char;
217                 }
219                 $page_filename_seek++;
221         } until ($page_filename_length eq $page_filename_seek);
223         foreach $page_directory_name (@pagedirectories){
225                 # Check if the directory name is undefined and if it
226                 # is then set it blank.
228                 if (!$page_directory_name){
229                         $page_directory_name = "";
230                 }
232                 if (!$page_directory_path){
233                         $page_directory_path = "";
234                 }
236                 # Check if the directory exists and create 
237                 # the directory if it doesn't exist.
239                 $page_directory_path = $page_directory_path . '/' . $page_directory_name;
241                 mkdir($main::kiriwrite_config{"directory_data_output"} . '/' . $page_directory_path);
243         }
245         # Check if the file already exists and if it does then check
246         # the permissions of the file and return an error if the
247         # permissions set are invalid.
249         $page_filename_exists = kiriwrite_fileexists($main::kiriwrite_config{"directory_data_output"} . '/' . $page_filename);  
251         if ($page_filename_exists eq 0){
253                 # The page filename exists, so check if the permissions given are
254                 # valid.
256                 $page_filename_permissions = kiriwrite_filepermissions($main::kiriwrite_config{"directory_data_output"} . '/' . $page_filename, 1, 1);
258                 if ($page_filename_permissions eq 1){
260                         # The file has invalid permissions set.
262                         $error_flag = 1;
263                         $error_message = languagestrings("invalidpermissionset");
264                         return;
266                 }
268         }
270         # Write the file to the output directory.
272         ($page_filename) = $page_filename =~ m/^(.*)$/g;
273         ($main::kiriwrite_config{"directory_data_output"}) = $main::kiriwrite_config{"directory_data_output"} =~ m/^(.*)$/g;
275         open($filehandle_page, "> ",  $main::kiriwrite_config{"directory_data_output"} . '/' . $page_filename) or ($error_flag = 1, $error_message = $!, return);
277         binmode $filehandle_page, ':utf8';
278         print $filehandle_page $page_data;
279         close($filehandle_page);
281         if (!$page_data){
283                 $page_data = "";
285         }
287         return;
291 sub outputall{
292 #################################################################################
293 # outputall: Outputs all pages.                                                 #
294 #                                                                               #
295 # Usage:                                                                        #
296 #                                                                               #
297 # $outputmodule->outputall({ FinishedProcessing => 1 });                        #
298 #                                                                               #
299 # FinishedProcessing    Indicate that this should be the last time outputall is #
300 #                       going to be called.                                     #
301 #################################################################################
303         # Not needed for this module.
305         return;
306         
309 sub clearpages{
310 #################################################################################
311 # clearpages: Clears all of the pages.                                          #
312 #                                                                               #
313 # Usage:                                                                        #
314 #                                                                               #
315 # $outputmodule->clearpages();                                                  #
316 #################################################################################
319 sub errorflag{
320 #################################################################################
321 # errorflag: Returns an error flag (if any).                                    #
322 #                                                                               #
323 # Usage:                                                                        #
324 #                                                                               #
325 # $errorflag    = $outputmodule->errorflag();                                   #
326 #################################################################################
327         
328         return $error_flag;
332 sub errormessage{
333 #################################################################################
334 # errormessage: Returns an error message (if any).                              #
335 #                                                                               #
336 # Usage:                                                                        #
337 #                                                                               #
338 # $errormessage = $outputmodule->errormessage();                                #
339 #################################################################################
341         return $error_message;
345 sub clearflag{
346 #################################################################################
347 # clearflag: Clears the error message flag and the error message itself.        #
348 #                                                                               #
349 # Usage:                                                                        #
350 #                                                                               #
351 # $outputmodule->clearflag();                                                   #
352 #################################################################################
354         $error_flag     = 0;
355         $error_message  = "";
359 sub languagestrings{
360 #################################################################################
361 # languagestrings: Language strings that are used in this module.               #
362 #                                                                               #
363 # Usage:                                                                        #
364 #                                                                               #
365 # $string = $outputmodule->languagestrings("langstring");                       #
366 #################################################################################
368         my $langstring = shift;
370         my $language_string;
371         my ($language_strings, %language_strings);
372         my $item;
374         if ($language_name eq "en-GB" or !$language_name){
376                 # Language strings for English (British) language.
378                 $language_strings{seperatedirdatabase} = "Seperate directory for each database.";
379                 $language_strings{invalidpermissionset} = "Invalid file permissions set.";
381         } else {
383                 # Invalid language so use English (British) as default.
385                 $language_strings{seperatedirdatabase} = "Seperate directory for each database.";
386                 $language_strings{invalidpermissionset} = "Invalid file permissions set.";
388         }
390         $language_string = $language_strings{$langstring};
391         
392         foreach $item (@_){
394                 $language_string =~ s/%s/$item/;
396         }
398         return $language_string;
402 sub finish{
403 #################################################################################
404 # finish: Close anything that was open.                                         #
405 #                                                                               #
406 # Usage:                                                                        #
407 #                                                                               #
408 # $outputmodule->finish();                                                      #
409 #################################################################################
412 1;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy