Beispiel #1
0
 public static function administrator($file, $folder = '/images/', $altFile = null, $altFolder = '/images/', $alt = null, $attribs = null, $asTag = true)
 {
     // Deprecation warning.
     MLog::add('MImage::administrator is deprecated.', MLog::WARNING, 'deprecated');
     $app = MFactory::getApplication();
     if (is_array($attribs)) {
         $attribs = MArrayHelper::toString($attribs);
     }
     $cur_template = $app->getTemplate();
     // Strip HTML.
     $alt = html_entity_decode($alt, ENT_COMPAT, 'UTF-8');
     if ($altFile) {
         $image = $altFolder . $altFile;
     } elseif ($altFile == -1) {
         $image = '';
     } else {
         if (file_exists(MPATH_ADMINISTRATOR . '/templates/' . $cur_template . '/images/' . $file)) {
             $image = 'templates/' . $cur_template . '/images/' . $file;
         } else {
             // Compatibility with previous versions.
             if (substr($folder, 0, 14) == "/administrator") {
                 $image = substr($folder, 15) . $file;
             } else {
                 $image = $folder . $file;
             }
         }
     }
     if (substr($image, 0, 1) == "/") {
         $image = substr_replace($image, '', 0, 1);
     }
     // Prepend the base path.
     $image = MURI::base(true) . '/' . $image;
     // Outputs actual HTML <img> tag.
     if ($asTag) {
         $image = '<img src="' . $image . '" alt="' . $alt . '" ' . $attribs . ' />';
     }
     return $image;
 }
Beispiel #2
0
 public static function radiolist($data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false, $translate = false)
 {
     reset($data);
     $html = '';
     if (is_array($attribs)) {
         $attribs = MArrayHelper::toString($attribs);
     }
     $id_text = $idtag ? $idtag : $name;
     foreach ($data as $obj) {
         $k = $obj->{$optKey};
         $t = $translate ? MText::_($obj->{$optText}) : $obj->{$optText};
         $id = isset($obj->id) ? $obj->id : null;
         $extra = '';
         $extra .= $id ? ' id="' . $obj->id . '"' : '';
         if (is_array($selected)) {
             foreach ($selected as $val) {
                 $k2 = is_object($val) ? $val->{$optKey} : $val;
                 if ($k == $k2) {
                     $extra .= ' selected="selected"';
                     break;
                 }
             }
         } else {
             $extra .= (string) $k == (string) $selected ? ' checked="checked"' : '';
         }
         $html .= "\n\t" . '<input type="radio" name="' . $name . '"' . ' id="' . $id_text . $k . '" value="' . $k . '"' . ' ' . $extra . ' ' . $attribs . '/>' . "\n\t" . '<label for="' . $id_text . $k . '"' . ' id="' . $id_text . $k . '-lbl" class="radiobtn">' . $t . '</label>';
     }
     $html .= "\n";
     return $html;
 }
Beispiel #3
0
 public function fetchHead(&$document)
 {
     // Trigger the onBeforeCompileHead event (skip for installation, since it causes an error)
     $app = MFactory::getApplication();
     $app->triggerEvent('onBeforeCompileHead');
     // Get line endings
     $lnEnd = $document->_getLineEnd();
     $tab = $document->_getTab();
     $tagEnd = ' />';
     $buffer = '';
     // Generate base tag (need to happen first)
     $base = $document->getBase();
     if (!empty($base)) {
         $buffer .= $tab . '<base href="' . $document->getBase() . '" />' . $lnEnd;
     }
     // Generate META tags (needs to happen as early as possible in the head)
     foreach ($document->_metaTags as $type => $tag) {
         foreach ($tag as $name => $content) {
             if ($type == 'http-equiv') {
                 $content .= '; charset=' . $document->getCharset();
                 $buffer .= $tab . '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
             } elseif ($type == 'standard' && !empty($content)) {
                 $buffer .= $tab . '<meta name="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
             }
         }
     }
     // Don't add empty descriptions
     $documentDescription = $document->getDescription();
     if ($documentDescription) {
         $buffer .= $tab . '<meta name="description" content="' . htmlspecialchars($documentDescription) . '" />' . $lnEnd;
     }
     // Don't add empty generators
     $generator = $document->getGenerator();
     if ($generator) {
         $buffer .= $tab . '<meta name="generator" content="' . htmlspecialchars($generator) . '" />' . $lnEnd;
     }
     $buffer .= $tab . '<title>' . htmlspecialchars($document->getTitle(), ENT_COMPAT, 'UTF-8') . '</title>' . $lnEnd;
     // Generate link declarations
     foreach ($document->_links as $link => $linkAtrr) {
         $buffer .= $tab . '<link href="' . $link . '" ' . $linkAtrr['relType'] . '="' . $linkAtrr['relation'] . '"';
         if ($temp = MArrayHelper::toString($linkAtrr['attribs'])) {
             $buffer .= ' ' . $temp;
         }
         $buffer .= ' />' . $lnEnd;
     }
     // Generate stylesheet links
     foreach ($document->_styleSheets as $strSrc => $strAttr) {
         $buffer .= $tab . '<link rel="stylesheet" href="' . $strSrc . '" type="' . $strAttr['mime'] . '"';
         if (!is_null($strAttr['media'])) {
             $buffer .= ' media="' . $strAttr['media'] . '" ';
         }
         if ($temp = MArrayHelper::toString($strAttr['attribs'])) {
             $buffer .= ' ' . $temp;
         }
         $buffer .= $tagEnd . $lnEnd;
     }
     // Generate stylesheet declarations
     foreach ($document->_style as $type => $content) {
         $buffer .= $tab . '<style type="' . $type . '">' . $lnEnd;
         // This is for full XHTML support.
         if ($document->_mime != 'text/html') {
             $buffer .= $tab . $tab . '<![CDATA[' . $lnEnd;
         }
         $buffer .= $content . $lnEnd;
         // See above note
         if ($document->_mime != 'text/html') {
             $buffer .= $tab . $tab . ']]>' . $lnEnd;
         }
         $buffer .= $tab . '</style>' . $lnEnd;
     }
     // Generate script file links
     foreach ($document->_scripts as $strSrc => $strAttr) {
         $buffer .= $tab . '<script src="' . $strSrc . '"';
         if (!is_null($strAttr['mime'])) {
             $buffer .= ' type="' . $strAttr['mime'] . '"';
         }
         if ($strAttr['defer']) {
             $buffer .= ' defer="defer"';
         }
         if ($strAttr['async']) {
             $buffer .= ' async="async"';
         }
         $buffer .= '></script>' . $lnEnd;
     }
     // Generate script declarations
     foreach ($document->_script as $type => $content) {
         $buffer .= $tab . '<script type="' . $type . '">' . $lnEnd;
         // This is for full XHTML support.
         if ($document->_mime != 'text/html') {
             $buffer .= $tab . $tab . '<![CDATA[' . $lnEnd;
         }
         $buffer .= $content . $lnEnd;
         // See above note
         if ($document->_mime != 'text/html') {
             $buffer .= $tab . $tab . ']]>' . $lnEnd;
         }
         $buffer .= $tab . '</script>' . $lnEnd;
     }
     // Generate script language declarations.
     if (count(MText::script())) {
         $buffer .= $tab . '<script type="text/javascript">' . $lnEnd;
         $buffer .= $tab . $tab . '(function() {' . $lnEnd;
         $buffer .= $tab . $tab . $tab . 'var strings = ' . json_encode(MText::script()) . ';' . $lnEnd;
         $buffer .= $tab . $tab . $tab . 'if (typeof Miwi == \'undefined\') {' . $lnEnd;
         $buffer .= $tab . $tab . $tab . $tab . 'Miwi = {};' . $lnEnd;
         $buffer .= $tab . $tab . $tab . $tab . 'Miwi.MText = strings;' . $lnEnd;
         $buffer .= $tab . $tab . $tab . '}' . $lnEnd;
         $buffer .= $tab . $tab . $tab . 'else {' . $lnEnd;
         $buffer .= $tab . $tab . $tab . $tab . 'Miwi.MText.load(strings);' . $lnEnd;
         $buffer .= $tab . $tab . $tab . '}' . $lnEnd;
         $buffer .= $tab . $tab . '})();' . $lnEnd;
         $buffer .= $tab . '</script>' . $lnEnd;
     }
     foreach ($document->_custom as $custom) {
         $buffer .= $tab . $custom . $lnEnd;
     }
     return $buffer;
 }
Beispiel #4
0
 public static function calendar($value, $name, $id, $format = 'Y-m-d', $attribs = null)
 {
     static $done;
     if ($done === null) {
         $done = array();
     }
     $readonly = isset($attribs['readonly']) && $attribs['readonly'] == 'readonly';
     $disabled = isset($attribs['disabled']) && $attribs['disabled'] == 'disabled';
     if (is_array($attribs)) {
         $attribs = MArrayHelper::toString($attribs);
     }
     if (!$readonly && !$disabled) {
         // Load the calendar behavior
         self::_('behavior.calendar');
         self::_('behavior.tooltip');
         // Only display the triggers once for each control.
         if (!in_array($id, $done)) {
             $document = MFactory::getDocument();
             $document->addScriptDeclaration('jQuery(document).ready(function () {
                         Calendar.setup({
                             // Id of the input field
                             inputField: "' . $id . '",
                             // Format of the input field
                             ifFormat: "' . $format . '",
                             // Trigger for the calendar (button ID)
                             button: "' . $id . '_img",
                             // Alignment (defaults to "Bl")
                             align: "Tl",
                             singleClick: true,
                             firstDay: ' . MFactory::getLanguage()->getFirstDay() . '
                         });
                     });');
             $done[] = $id;
         }
         return '<input type="text" title="' . (0 !== (int) $value ? self::_('date', $value, null, null) : '') . '" name="' . $name . '" id="' . $id . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" ' . $attribs . ' />' . self::_('image', 'system/calendar.png', MText::_('MLIB_HTML_CALENDAR'), array('class' => 'calendar', 'id' => $id . '_img'), true);
     } else {
         return '<input type="text" title="' . (0 !== (int) $value ? self::_('date', $value, null, null) : '') . '" value="' . (0 !== (int) $value ? self::_('date', $value, 'Y-m-d H:i:s', null) : '') . '" ' . $attribs . ' /><input type="hidden" name="' . $name . '" id="' . $id . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" />';
     }
 }