aliroHTML.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*******************************************************************************
00004  * Aliro - the modern, accessible content management system
00005  *
00006  * Aliro is open source software, free to use, and licensed under GPL.
00007  * You can find the full licence at http://www.gnu.org/copyleft/gpl.html GNU/GPL
00008  *
00009  * The author freely draws attention to the fact that Aliro derives from Mambo,
00010  * software that is controlled by the Mambo Foundation.  However, this section
00011  * of code is totally new.  If it should contain any fragments that are similar
00012  * to Mambo, please bear in mind (1) there are only so many ways to do things
00013  * and (2) the author of Aliro is also the author and copyright owner for large
00014  * parts of Mambo 4.6.
00015  *
00016  * Tribute should be paid to all the developers who took Mambo to the stage
00017  * it had reached at the time Aliro was created.  It is a feature rich system
00018  * that contains a good deal of innovation.
00019  *
00020  * Your attention is also drawn to the fact that Aliro relies on other items of
00021  * open source software, which is very much in the spirit of open source.  Aliro
00022  * wishes to give credit to those items of code.  Please refer to
00023  * http://aliro.org/credits for details.  The credits are not included within
00024  * the Aliro package simply to avoid providing a marker that allows hackers to
00025  * identify the system.
00026  *
00027  * Copyright in this code is strictly reserved by its author, Martin Brampton.
00028  * If it seems appropriate, the copyright will be vested in the Aliro Organisation
00029  * at a suitable time.
00030  *
00031  * Copyright (c) 2007 Martin Brampton
00032  *
00033  * http://aliro.org
00034  *
00035  * counterpoint@aliro.org
00036  *
00037  * aliroHTML is progressively taking over from mosHTML.  It is a singleton rather
00038  * than a set of static methods, for both style and efficiency reasons.  The
00039  * mosHTML interface still exists, but makes calls to aliroHTML.
00040  *
00041  */
00042 
00043 class aliroHTML {
00044     private static $instance = __CLASS__;
00045 
00046     public static function getInstance () {
00047         return is_object(self::$instance) ? self::$instance : (self::$instance = new self::$instance());
00048     }
00049 
00050     public function makeOption ($value, $text='', $selected=false, $valuename='value', $textname='text') {
00051         $obj = new stdClass;
00052         $obj->$valuename = $value;
00053         $obj->$textname = trim($text) ? $text : $value;
00054         $obj->selected = $selected;
00055         return $obj;
00056     }
00057 
00058     // Takes an array of objects and uses it to create a select list
00059     public function selectList ($selections, $tag_name, $tag_attribs='', $key='value', $text='text', $selected=NULL ) {
00060         if (!is_array($selections)) return '';
00061         $selectproperties = array();
00062         if (is_array($selected)) foreach ($selected as $select) {
00063             if (is_object($select)) $selectproperties[] = $select->$key;
00064             else $selectproperties[] = $select;
00065         }
00066         else $selectproperties = array($selected);
00067         $selecthtml = '';
00068         foreach ($selections as $selection) {
00069             $select = ((isset($selection->selected) AND $selection->selected) OR in_array($selection->$key, $selectproperties, true)) ? 'selected="selected"' : '';
00070             $selecthtml .= <<<AN_OPTION
00071             <option value="{$selection->$key}" $select>
00072                 {$selection->$text}
00073             </option>
00074 AN_OPTION;
00075         }
00076         return <<<THE_SELECT
00077         <select name="$tag_name" $tag_attribs>
00078             $selecthtml
00079         </select>
00080 THE_SELECT;
00081     }
00082 
00083     public function radioList ($arr, $tag_name, $tag_attribs, $selected=null, $key='value', $text='text') {
00084         $html = '';
00085         foreach ($arr as $choice) {
00086             $extra = @$choice->id ? " id=\"$choice->id\"" : '';
00087             if (is_array($selected)) foreach ($selected as $obj) {
00088                 if ($choice->$key == $obj->$key) {
00089                     $extra .= ' selected="selected"';
00090                     break;
00091                 }
00092             }
00093             else $extra .= ($choice->$key == $selected ? " checked=\"checked\"" : '');
00094             $html .= <<<RADIO
00095             <input type="radio" name="$tag_name" value="{$choice->$key}" $extra $tag_attribs />
00096             {$choice->$text}
00097 RADIO;
00098         }
00099         return $html;
00100     }
00101 
00102     public function yesnoRadioList ($tag_name, $tag_attribs, $selected, $yes=_CMN_YES, $no=_CMN_NO ) {
00103         $arr = array(
00104         $this->makeOption( '0', $no, true ),
00105         $this->makeOption( '1', $yes, true )
00106         );
00107         return $this->radioList ($arr, $tag_name, $tag_attribs, $selected);
00108     }
00109 
00110     public function idBox ($rowNum, $recId, $checkedOut=false, $name='cid') {
00111         return $checkedOut ? '' : <<<IDBOX
00112         <input type="checkbox" id="cb$rowNum" name="{$name}[]" value="$recId" onclick="isChecked(this.checked);" />
00113 IDBOX;
00114     }
00115 
00116     public function toolTip ($tooltip, $title='', $width='', $image='tooltip.png', $text='', $href='#') {
00117         if ($width) $width = ', WIDTH, \''.$width .'\'';
00118         if ($title) $title = ', CAPTION, \''.$title .'\'';
00119         if (!$text) {
00120             $image = aliroCore::getInstance()->getCfg('live_site').'/includes/js/ThemeOffice/'.$image;
00121             $text = '<img src="'.$image.'" alt="Tool Tip" />';
00122         }
00123         // $style = $href ? '' : 'style="text-decoration: none; color: #333;"';
00124         return <<<CTOOLTIP
00125         <a href="$href"> $text <span class="tooltip">$tooltip</span></a>
00126 CTOOLTIP;
00127         return <<<TOOLTIP
00128         <a href="$href" onmouseover="return overlib('$tooltip' $title, BELOW, RIGHT $width );" onmouseout="return nd();" $style > $text </a>
00129 TOOLTIP;
00130     }
00131 
00132     private function checkedOut($row, $overlib=1) {
00133         if ($overlib) {
00134             if (!isset($row->editor)) {
00135                 $user = new mosUser();
00136                 $user->load($row->checked_out);
00137                 $row->editor = $user->name;
00138             }
00139             $date = $this->formatDate( $row->checked_out_time, '%A, %d %B %Y' );
00140             $time = $this->formatDate( $row->checked_out_time, '%H:%M' );
00141             $checked_out_text   = <<<CHECKED_OUT
00142 <table><tr><td>$row->editor</td></tr><tr><td>$date</td></tr><tr><td>$time</td></tr></table>
00143 CHECKED_OUT;
00144             $hover = 'onmouseover="return overlib(\''. $checked_out_text .'\', CAPTION, \'Checked Out\', BELOW, RIGHT);" onMouseOut="return nd();"';
00145         }
00146         else $hover = '';
00147         return '<img src="images/checked_out.png" '. $hover .' alt="Checked Out"/>';
00148     }
00149 
00150     public function formatDate ($date, $format='', $offset=''){
00151         $core = aliroCore::getInstance();
00152         // Format was originally set to %Y-%m-%d %H:%M:%S
00153         if (!$offset) $offset = $core->getCfg('offset');
00154         if ($date AND ereg( "([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})", $date, $regs ) ) {
00155             $date = mktime( $regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1] );
00156             $date = $date > -1 ? aliroLanguage::getInstance()->getDate($format, $date + ($offset*60*60)) : '-';
00157         }
00158         return $date;
00159     }
00160 
00161     public function checkedOutProcessing ($row, $i) {
00162         if ($row->checked_out) $checked = $this->checkedOut ($row);
00163         else $checked = $this->idBox ($i, $row->id, ($row->checked_out AND $row->checked_out != aliroUser::getInstance()->id));
00164         return $checked;
00165     }
00166 
00167     public function publishedProcessing ($row, $i) {
00168         $img    = $row->published ? 'publish_g.png' : 'publish_x.png';
00169         $task   = $row->published ? 'unpublish' : 'publish';
00170         $alt    = $row->published ? T_('Published') : T_('Unpublished');
00171         $action = $row->published ? T_('Unpublish Item') : T_('Publish item');
00172         return <<<PUBLISH_LINK
00173         <a href="javascript: void(0);" onclick="return listItemTask('cb$i','$task')" title="$action">
00174         <img src="images/$img" border="0" alt="$alt" />
00175         </a>
00176 PUBLISH_LINK;
00177 
00178     }
00179 
00180     public function loadCalendar() {
00181         $live_site = aliroCore::getInstance()->getCfg('live_site');
00182         $tags = <<<END_TAGS
00183         <link rel="stylesheet" type="text/css" media="all" href="$live_site/extclasses/js/calendar/calendar-mos.css" title="green" />
00184         <!-- import the calendar script -->
00185         <script type="text/javascript" src="$live_site/extclasses/js/calendar/calendar.js"></script>
00186         <!-- import the language module -->
00187         <script type="text/javascript" src="$live_site/extclasses/js/calendar/lang/calendar-en.js"></script>
00188 END_TAGS;
00189         aliroRequest::getInstance()->addCustomHeadTag ($tags);
00190     }
00191 
00192 }

Generated on Thu Apr 17 13:03:26 2008 for ALIRO by  doxygen 1.5.5