Пример #1
0
 /**
  * return the value of a POSTed TV
  * TV may be used to override the default or hard-configured transliteration table
  *
  * @param string $tv name of Template Variable
  * @return value of TV in current POST operation or false if TV not found in POST
  */
 function getTVValue($tv)
 {
     global $modx;
     $additionalEncodings = array('-' => '%2D', '.' => '%2E', '_' => '%5F');
     $tvname = str_replace(array_keys($additionalEncodings), array_values($additionalEncodings), rawurlencode($tv));
     if (array_key_exists('tv' . $tvname, $_POST)) {
         include_once MODX_MANAGER_PATH . 'includes/tmplvars.commands.inc.php';
         $val = $_POST['tv' . $tvname];
         $id = $_POST['id'];
         if ($val == '@INHERIT' && empty($_POST['id']) && !empty($_POST['parent'])) {
             // we have to look at parent directly
             $id = $_POST['parent'];
             $ptv = $modx->getTemplateVar($tv, '*', $id, 'all');
             $val = $ptv['value'];
         }
         $return = ProcessTVCommand($val, $tv, $id);
         return $return;
     } else {
         return false;
     }
 }
Пример #2
0
 /**
  * return the value of a POSTed TV
  * TV may be used to override the default or hard-configured transliteration table
  *
  * @param string $tv name of Template Variable
  * @return value of TV in current POST operation or false if TV not found in POST
  */
 function getTVValue($tv)
 {
     $modx =& $GLOBALS['modx'];
     $additionalEncodings = array('-' => '%2D', '.' => '%2E', '_' => '%5F');
     $tvname = str_replace(array_keys($additionalEncodings), array_values($additionalEncodings), rawurlencode($tv));
     if (array_key_exists('tv' . $tvname, $_POST)) {
         include_once $GLOBALS['modx']->config['base_path'] . 'manager/includes/tmplvars.commands.inc.php';
         $val = $_POST['tv' . $tvname];
         $id = $_POST['id'];
         if ($val == '@INHERIT' && empty($_POST['id']) && !empty($_POST['parent'])) {
             // we have to look at parent directly
             $id = $_POST['parent'];
             $parent = $modx->getPageInfo($_POST['parent'], 0, 'id,parent,published');
             $ptv = $modx->getTemplateVar($tv, '*', $parent['id'], $parent['published']);
             $val = $ptv['value'];
         }
         $return = ProcessTVCommand($val, $tv, $id);
         return $return;
     } else {
         return false;
     }
 }
Пример #3
0
function renderFormElement($field_type, $field_id, $default_text, $field_elements, $field_value, $field_style = '')
{
    global $modx;
    global $base_url;
    global $rb_base_url;
    global $manager_theme;
    $field_html = '';
    $field_value = $field_value != "" ? $field_value : $default_text;
    switch ($field_type) {
        case "text":
            // handler for regular text boxes
        // handler for regular text boxes
        case "rawtext":
            // non-htmlentity converted text boxes
        // non-htmlentity converted text boxes
        case "email":
            // handles email input fields
        // handles email input fields
        case "number":
            // handles the input of numbers
            $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" onchange="documentDirty=true;" style="width:100%" />';
            break;
        case "textareamini":
            // handler for textarea mini boxes
            $field_html .= '<textarea id="tv' . $field_id . '" name="tv' . $field_id . '" cols="40" rows="5" onchange="documentDirty=true;" style="width:100%">' . htmlspecialchars($field_value) . '</textarea>';
            break;
        case "textarea":
            // handler for textarea boxes
        // handler for textarea boxes
        case "rawtextarea":
            // non-htmlentity convertex textarea boxes
        // non-htmlentity convertex textarea boxes
        case "htmlarea":
            // handler for textarea boxes (deprecated)
        // handler for textarea boxes (deprecated)
        case "richtext":
            // handler for textarea boxes
            $field_html .= '<textarea id="tv' . $field_id . '" name="tv' . $field_id . '" cols="40" rows="15" onchange="documentDirty=true;" style="width:100%;">' . htmlspecialchars($field_value) . '</textarea>';
            break;
        case "date":
            $field_id = str_replace(array('-', '.'), '_', urldecode($field_id));
            if ($field_value == '') {
                $field_value = 0;
            }
            $field_html .= '<input id="tv' . $field_id . '" name="tv' . $field_id . '" class="DatePicker" type="text" value="' . ($field_value == 0 || !isset($field_value) ? "" : $field_value) . '" onblur="documentDirty=true;" />';
            $field_html .= ' <a onclick="document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].value=\'\';document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].onblur(); return true;" onmouseover="window.status=\'clear the date\'; return true;" onmouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img src="media/style/' . ($manager_theme ? "{$manager_theme}/" : "") . 'images/icons/cal_nodate.gif" width="16" height="16" border="0" alt="No date"></a>';
            $field_html .= '<script type="text/javascript">';
            $field_html .= '	window.addEvent(\'domready\', function() {';
            $field_html .= '   	new DatePicker($(\'tv' . $field_id . '\'), {\'yearOffset\' : ' . $modx->config['datepicker_offset'] . ", 'format' : " . "'" . $modx->config['datetime_format'] . ' hh:mm:00\'' . '});';
            $field_html .= '});';
            $field_html .= '</script>';
            break;
        case "dropdown":
            // handler for select boxes
            $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" size="1" onchange="documentDirty=true;">';
            $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id));
            while (list($item, $itemvalue) = each($index_list)) {
                list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                if (strlen($itemvalue) == 0) {
                    $itemvalue = $item;
                }
                $field_html .= '<option value="' . htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . htmlspecialchars($item) . '</option>';
            }
            $field_html .= "</select>";
            break;
        case "listbox":
            // handler for select boxes
            $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" onchange="documentDirty=true;" size="8">';
            $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id));
            while (list($item, $itemvalue) = each($index_list)) {
                list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                if (strlen($itemvalue) == 0) {
                    $itemvalue = $item;
                }
                $field_html .= '<option value="' . htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . htmlspecialchars($item) . '</option>';
            }
            $field_html .= "</select>";
            break;
        case "listbox-multiple":
            // handler for select boxes where you can choose multiple items
            $field_value = explode("||", $field_value);
            $field_html .= '<select id="tv' . $field_id . '[]" name="tv' . $field_id . '[]" multiple="multiple" onchange="documentDirty=true;" size="8">';
            $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id));
            while (list($item, $itemvalue) = each($index_list)) {
                list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                if (strlen($itemvalue) == 0) {
                    $itemvalue = $item;
                }
                $field_html .= '<option value="' . htmlspecialchars($itemvalue) . '"' . (in_array($itemvalue, $field_value) ? ' selected="selected"' : '') . '>' . htmlspecialchars($item) . '</option>';
            }
            $field_html .= "</select>";
            break;
        case "url":
            // handles url input fields
            $urls = array('' => '--', 'http://' => 'http://', 'https://' => 'https://', 'ftp://' => 'ftp://', 'mailto:' => 'mailto:');
            $field_html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><select id="tv' . $field_id . '_prefix" name="tv' . $field_id . '_prefix" onchange="documentDirty=true;">';
            foreach ($urls as $k => $v) {
                if (strpos($field_value, $v) === false) {
                    $field_html .= '<option value="' . $v . '">' . $k . '</option>';
                } else {
                    $field_value = str_replace($v, '', $field_value);
                    $field_html .= '<option value="' . $v . '" selected="selected">' . $k . '</option>';
                }
            }
            $field_html .= '</select></td><td>';
            $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . htmlspecialchars($field_value) . '" width="100" ' . $field_style . ' onchange="documentDirty=true;" /></td></tr></table>';
            break;
        case "checkbox":
            // handles check boxes
            $field_value = !is_array($field_value) ? explode("||", $field_value) : $field_value;
            $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id));
            static $i = 0;
            while (list($item, $itemvalue) = each($index_list)) {
                list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                if (strlen($itemvalue) == 0) {
                    $itemvalue = $item;
                }
                $field_html .= '<input type="checkbox" value="' . htmlspecialchars($itemvalue) . '" id="tv_' . $i . '" name="tv' . $field_id . '[]" ' . (in_array($itemvalue, $field_value) ? " checked='checked'" : "") . ' onchange="documentDirty=true;" /><label for="tv_' . $i . '">' . $item . '</label><br />';
                $i++;
            }
            break;
        case "option":
            // handles radio buttons
            $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id));
            while (list($item, $itemvalue) = each($index_list)) {
                list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                if (strlen($itemvalue) == 0) {
                    $itemvalue = $item;
                }
                $field_html .= '<input type="radio" value="' . htmlspecialchars($itemvalue) . '" name="tv' . $field_id . '" ' . ($itemvalue == $field_value ? 'checked="checked"' : '') . ' onchange="documentDirty=true;" />' . $item . '<br />';
            }
            break;
        case "image":
            // handles image fields using htmlarea image manager
            global $_lang;
            global $ResourceManagerLoaded;
            global $content, $use_editor, $which_editor;
            if (!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $_GET['a'] == 4) && $use_editor == 1 && $which_editor == 3)) {
                $field_html .= "\n\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\tvar lastImageCtrl;\n\t\t\t\t\t\t\tvar lastFileCtrl;\n\t\t\t\t\t\t\tfunction OpenServerBrowser(url, width, height ) {\n\t\t\t\t\t\t\t\tvar iLeft = (screen.width  - width) / 2 ;\n\t\t\t\t\t\t\t\tvar iTop  = (screen.height - height) / 2 ;\n\n\t\t\t\t\t\t\t\tvar sOptions = 'toolbar=no,status=no,resizable=yes,dependent=yes' ;\n\t\t\t\t\t\t\t\tsOptions += ',width=' + width ;\n\t\t\t\t\t\t\t\tsOptions += ',height=' + height ;\n\t\t\t\t\t\t\t\tsOptions += ',left=' + iLeft ;\n\t\t\t\t\t\t\t\tsOptions += ',top=' + iTop ;\n\n\t\t\t\t\t\t\t\tvar oWindow = window.open( url, 'FCKBrowseWindow', sOptions ) ;\n\t\t\t\t\t\t\t}\t\t\t\n\t\t\t\t\t\t\tfunction BrowseServer(ctrl) {\n\t\t\t\t\t\t\t\tlastImageCtrl = ctrl;\n\t\t\t\t\t\t\t\tvar w = screen.width * 0.7;\n\t\t\t\t\t\t\t\tvar h = screen.height * 0.7;\n\t\t\t\t\t\t\t\tOpenServerBrowser('" . $base_url . "manager/media/browser/mcpuk/browser.html?Type=images&Connector=" . $base_url . "manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath=" . $base_url . "', w, h);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfunction BrowseFileServer(ctrl) {\n\t\t\t\t\t\t\t\tlastFileCtrl = ctrl;\n\t\t\t\t\t\t\t\tvar w = screen.width * 0.7;\n\t\t\t\t\t\t\t\tvar h = screen.height * 0.7;\n\t\t\t\t\t\t\t\tOpenServerBrowser('" . $base_url . "manager/media/browser/mcpuk/browser.html?Type=files&Connector=" . $base_url . "manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath=" . $base_url . "', w, h);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfunction SetUrl(url, width, height, alt){\n\t\t\t\t\t\t\t\tif(lastFileCtrl) {\n\t\t\t\t\t\t\t\t\tvar c = document.mutate[lastFileCtrl];\n\t\t\t\t\t\t\t\t\tif(c) c.value = url;\n\t\t\t\t\t\t\t\t\tlastFileCtrl = '';\n\t\t\t\t\t\t\t\t} else if(lastImageCtrl) {\n\t\t\t\t\t\t\t\t\tvar c = document.mutate[lastImageCtrl];\n\t\t\t\t\t\t\t\t\tif(c) c.value = url;\n\t\t\t\t\t\t\t\t\tlastImageCtrl = '';\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t</script>";
                $ResourceManagerLoaded = true;
            }
            $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '"  value="' . $field_value . '" ' . $field_style . ' onchange="documentDirty=true;" />&nbsp;<input type="button" value="' . $_lang['insert'] . '" onclick="BrowseServer(\'tv' . $field_id . '\')" />';
            break;
        case "file":
            // handles the input of file uploads
            /* Modified by Timon for use with resource browser */
            global $_lang;
            global $ResourceManagerLoaded;
            global $content, $use_editor, $which_editor;
            if (!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $_GET['a'] == 4) && $use_editor == 1 && $which_editor == 3)) {
                /* I didn't understand the meaning of the condition above, so I left it untouched ;-) */
                $field_html .= "\n\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\tvar lastImageCtrl;\n\t\t\t\t\t\t\tvar lastFileCtrl;\n\t\t\t\t\t\t\tfunction OpenServerBrowser(url, width, height ) {\n\t\t\t\t\t\t\t\tvar iLeft = (screen.width  - width) / 2 ;\n\t\t\t\t\t\t\t\tvar iTop  = (screen.height - height) / 2 ;\n\n\t\t\t\t\t\t\t\tvar sOptions = 'toolbar=no,status=no,resizable=yes,dependent=yes' ;\n\t\t\t\t\t\t\t\tsOptions += ',width=' + width ;\n\t\t\t\t\t\t\t\tsOptions += ',height=' + height ;\n\t\t\t\t\t\t\t\tsOptions += ',left=' + iLeft ;\n\t\t\t\t\t\t\t\tsOptions += ',top=' + iTop ;\n\n\t\t\t\t\t\t\t\tvar oWindow = window.open( url, 'FCKBrowseWindow', sOptions ) ;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tfunction BrowseServer(ctrl) {\n\t\t\t\t\t\t\t\tlastImageCtrl = ctrl;\n\t\t\t\t\t\t\t\tvar w = screen.width * 0.7;\n\t\t\t\t\t\t\t\tvar h = screen.height * 0.7;\n\t\t\t\t\t\t\t\tOpenServerBrowser('" . $base_url . "manager/media/browser/mcpuk/browser.html?Type=images&Connector=" . $base_url . "manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath=" . $base_url . "', w, h);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfunction BrowseFileServer(ctrl) {\n\t\t\t\t\t\t\t\tlastFileCtrl = ctrl;\n\t\t\t\t\t\t\t\tvar w = screen.width * 0.7;\n\t\t\t\t\t\t\t\tvar h = screen.height * 0.7;\n\t\t\t\t\t\t\t\tOpenServerBrowser('" . $base_url . "manager/media/browser/mcpuk/browser.html?Type=files&Connector=" . $base_url . "manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath=" . $base_url . "', w, h);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfunction SetUrl(url, width, height, alt){\n\t\t\t\t\t\t\t\tif(lastFileCtrl) {\n\t\t\t\t\t\t\t\t\tvar c = document.mutate[lastFileCtrl];\n\t\t\t\t\t\t\t\t\tif(c) c.value = url;\n\t\t\t\t\t\t\t\t\tlastFileCtrl = '';\n\t\t\t\t\t\t\t\t} else if(lastImageCtrl) {\n\t\t\t\t\t\t\t\t\tvar c = document.mutate[lastImageCtrl];\n\t\t\t\t\t\t\t\t\tif(c) c.value = url;\n\t\t\t\t\t\t\t\t\tlastImageCtrl = '';\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t</script>";
                $ResourceManagerLoaded = true;
            }
            $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '"  value="' . $field_value . '" ' . $field_style . ' onchange="documentDirty=true;" />&nbsp;<input type="button" value="' . $_lang['insert'] . '" onclick="BrowseFileServer(\'tv' . $field_id . '\')" />';
            break;
        default:
            // the default handler -- for errors, mostly
            $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . htmlspecialchars($field_value) . '" ' . $field_style . ' onchange="documentDirty=true;" />';
    }
    // end switch statement
    return $field_html;
}
Пример #4
0
function getTVDisplayFormat($name, $value, $format, $paramstring = "", $tvtype = "", $docid = "", $sep = '')
{
    global $modx;
    // process any TV commands in value
    $docid = intval($docid) ? intval($docid) : $modx->documentIdentifier;
    $value = ProcessTVCommand($value, $name, $docid);
    $params = array();
    if ($paramstring) {
        $cp = explode("&", $paramstring);
        foreach ($cp as $p => $v) {
            $v = trim($v);
            // trim
            $ar = explode("=", $v);
            if (is_array($ar) && count($ar) == 2) {
                $params[$ar[0]] = decodeParamValue($ar[1]);
            }
        }
    }
    $id = "tv{$name}";
    switch ($format) {
        case 'image':
            $images = parseInput($value, '||', 'array');
            $o = '';
            foreach ($images as $image) {
                if (!is_array($image)) {
                    $image = explode('==', $image);
                }
                $src = $image[0];
                if ($src) {
                    // We have a valid source
                    $attributes = '';
                    $attr = array('class' => $params['class'], 'src' => $src, 'id' => $params['id'] ? $params['id'] : '', 'alt' => htmlspecialchars($params['alttext']), 'style' => $params['style']);
                    if (isset($params['align']) && $params['align'] != 'none') {
                        $attr['align'] = $params['align'];
                    }
                    foreach ($attr as $k => $v) {
                        $attributes .= $v ? ' ' . $k . '="' . $v . '"' : '';
                    }
                    $attributes .= ' ' . $params['attrib'];
                    // Output the image with attributes
                    $o .= '<img' . rtrim($attributes) . ' />';
                }
            }
            break;
        case "delim":
            // display as delimitted list
            $value = parseInput($value, "||");
            $p = $params['format'] ? $params['format'] : " ";
            if ($p == "\\n") {
                $p = "\n";
            }
            $o = str_replace("||", $p, $value);
            break;
        case "string":
            $value = parseInput($value);
            $format = strtolower($params['format']);
            if ($format == 'upper case') {
                $o = strtoupper($value);
            } else {
                if ($format == 'lower case') {
                    $o = strtolower($value);
                } else {
                    if ($format == 'sentence case') {
                        $o = ucfirst($value);
                    } else {
                        if ($format == 'capitalize') {
                            $o = ucwords($value);
                        } else {
                            $o = $value;
                        }
                    }
                }
            }
            break;
        case "date":
            if ($value != '' || $params['default'] == 'Yes') {
                $timestamp = getUnixtimeFromDateString($value);
                $p = $params['format'] ? $params['format'] : "%A %d, %B %Y";
                $o = strftime($p, $timestamp);
            } else {
                $value = '';
            }
            break;
        case "floater":
            $value = parseInput($value, " ");
            $modx->regClientStartupScript(MODX_MANAGER_URL . "media/script/mootools/mootools.js", array('name' => 'mootools', 'version' => '1.1.1', 'plaintext' => false));
            $modx->regClientStartupScript(MODX_MANAGER_URL . "media/script/mootools/moodx.js", array('name' => 'moodx', 'version' => '0', 'plaintext' => false));
            $class = !empty($params['class']) ? " class=\"" . $params['class'] . "\"" : "";
            $style = !empty($params['style']) ? " style=\"" . $params['style'] . "\"" : "";
            $o .= "\n<div id=\"" . $id . "\"" . $class . $style . ">" . $value . "</div>\n";
            $o .= "<script type=\"text/javascript\">\n";
            $o .= "\twindow.addEvent('domready', function(){\n";
            $o .= "\t\tvar modxFloat = new MooFloater(\$(\"" . $id . "\"),{\n";
            $o .= "\t\t\twidth: '" . $params['width'] . "',\n";
            $o .= "\t\t\theight: '" . $params['height'] . "',\n";
            $o .= "\t\t\tposition: '" . $params['pos'] . "',\n";
            $o .= "\t\t\tglidespeed: " . $params['gs'] . ",\n";
            $o .= "\t\t\toffsetx: " . intval($params['x']) . ",\n";
            $o .= "\t\t\toffsety: " . intval($params['y']) . "\n";
            $o .= "\t\t});\n";
            $o .= "\t});\n";
            $o .= "</script>\n";
            break;
        case "marquee":
            $value = parseInput($value, " ");
            $modx->regClientStartupScript(MODX_MANAGER_URL . "media/script/mootools/mootools.js", array('name' => 'mootools', 'version' => '1.1.1', 'plaintext' => false));
            $modx->regClientStartupScript(MODX_MANAGER_URL . "media/script/mootools/moodx.js", array('name' => 'moodx', 'version' => '0', 'plaintext' => false));
            $class = !empty($params['class']) ? " class=\"" . $params['class'] . "\"" : "";
            $style = !empty($params['style']) ? " style=\"" . $params['style'] . "\"" : "";
            $o .= "\n<div id=\"" . $id . "\"" . $class . $style . "><div id=\"marqueeContent\">" . $value . "</div></div>\n";
            $o .= "<script type=\"text/javascript\">\n";
            $o .= "\twindow.addEvent('domready', function(){\n";
            $o .= "\t\tvar modxMarquee = new MooMarquee(\$(\"" . $id . "\"),{\n";
            $o .= "\t\t\twidth: '" . $params['width'] . "',\n";
            $o .= "\t\t\theight: '" . $params['height'] . "',\n";
            $o .= "\t\t\tspeed: " . $params['speed'] . ",\n";
            $o .= "\t\t\tmodifier: " . $params['modifier'] . ",\n";
            $o .= "\t\t\tmousepause: '" . $params['pause'] . "',\n";
            $o .= "\t\t\tdirection: '" . $params['tfx'] . "'\n";
            $o .= "\t\t});\n";
            $o .= "\t});\n";
            $o .= "</script>\n";
            break;
        case "ticker":
            $modx->regClientStartupScript(MODX_MANAGER_URL . "media/script/mootools/mootools.js", array('name' => 'mootools', 'version' => '1.1.1', 'plaintext' => false));
            $modx->regClientStartupScript(MODX_MANAGER_URL . "media/script/mootools/moostick.js?init=false", array('name' => 'moostick', 'version' => '0', 'plaintext' => false));
            $class = !empty($params['class']) ? " class=\"" . $params['class'] . "\"" : "";
            $style = !empty($params['style']) ? " style=\"" . $params['style'] . "\"" : "";
            $o .= "\n<div id=\"" . $id . "\"" . $class . $style . ">\n";
            if (!empty($value)) {
                $delim = $params['delim'] ? $params['delim'] : "||";
                if ($delim == "\\n") {
                    $delim = "\n";
                }
                $val = parseInput($value, $delim, "array", false);
                if (count($val) > 0) {
                    $o .= "    <ul id=\"" . $id . "Ticker\">\n";
                    for ($i = 0; $i < count($val); $i++) {
                        $o .= "        <li id=\"tickerItem{$i}\">" . $val[$i] . "</li>\n";
                    }
                    $o .= "    </ul>\n";
                }
            }
            $o .= "</div>\n";
            $o .= "<script type=\"text/javascript\">\n";
            $o .= "\twindow.addEvent('domready', function(){\n";
            $o .= "\t\tvar modxTicker = new Moostick(\$(\"" . $id . "Ticker\"), true, " . (!empty($params['delay']) ? $params['delay'] : "true") . ")\n";
            $o .= "\t\t\$(\"" . $id . "Ticker\").setStyle('width','" . $params['width'] . "');\n";
            $o .= "\t\t\$(\"" . $id . "Ticker\").setStyle('height','" . $params['height'] . "');\n";
            $o .= "\t});\n";
            $o .= "</script>\n";
            break;
        case "hyperlink":
            $value = parseInput($value, "||", "array");
            for ($i = 0; $i < count($value); $i++) {
                list($name, $url) = is_array($value[$i]) ? $value[$i] : explode("==", $value[$i]);
                if (!$url) {
                    $url = $name;
                }
                if ($url) {
                    if ($o) {
                        $o .= '<br />';
                    }
                    $attributes = '';
                    // setup the link attributes
                    $attr = array('href' => $url, 'title' => $params['title'] ? htmlspecialchars($params['title']) : $name, 'class' => $params['class'], 'style' => $params['style'], 'target' => $params['target']);
                    foreach ($attr as $k => $v) {
                        $attributes .= $v ? ' ' . $k . '="' . $v . '"' : '';
                    }
                    $attributes .= ' ' . $params['attrib'];
                    // add extra
                    // Output the link
                    $o .= '<a' . rtrim($attributes) . '>' . ($params['text'] ? htmlspecialchars($params['text']) : $name) . '</a>';
                }
            }
            break;
        case "htmltag":
            $value = parseInput($value, "||", "array");
            $tagid = $params['tagid'];
            $tagname = $params['tagname'] ? $params['tagname'] : 'div';
            // Loop through a list of tags
            for ($i = 0; $i < count($value); $i++) {
                $tagvalue = is_array($value[$i]) ? implode(' ', $value[$i]) : $value[$i];
                if (!$tagvalue) {
                    continue;
                }
                $attributes = '';
                $attr = array('id' => $tagid ? $tagid : $id, 'class' => $params['class'], 'style' => $params['style']);
                foreach ($attr as $k => $v) {
                    $attributes .= $v ? ' ' . $k . '="' . $v . '"' : '';
                }
                $attributes .= ' ' . $params['attrib'];
                // add extra
                // Output the HTML Tag
                $o .= '<' . $tagname . rtrim($attributes) . '>' . $tagvalue . '</' . $tagname . '>';
            }
            break;
        case "richtext":
            $value = parseInput($value);
            $w = $params['w'] ? $params['w'] : '100%';
            $h = $params['h'] ? $params['h'] : '400px';
            $richtexteditor = $params['edt'] ? $params['edt'] : "";
            $o = '<div class="MODX_RichTextWidget"><textarea id="' . $id . '" name="' . $id . '" style="width:' . $w . '; height:' . $h . ';">';
            $o .= htmlspecialchars($value);
            $o .= '</textarea></div>';
            $replace_richtext = array($id);
            // setup editors
            if (!empty($replace_richtext) && !empty($richtexteditor)) {
                // invoke OnRichTextEditorInit event
                $evtOut = $modx->invokeEvent("OnRichTextEditorInit", array('editor' => $richtexteditor, 'elements' => $replace_richtext, 'forfrontend' => 1, 'width' => $w, 'height' => $h));
                if (is_array($evtOut)) {
                    $o .= implode("", $evtOut);
                }
            }
            break;
        case "unixtime":
            $value = parseInput($value);
            $o = getUnixtimeFromDateString($value);
            break;
        case "viewport":
            $value = parseInput($value);
            $id = '_' . time();
            if (!$params['vpid']) {
                $params['vpid'] = $id;
            }
            $sTag = "<iframe";
            $eTag = "</iframe>";
            $autoMode = "0";
            $w = $params['width'];
            $h = $params['height'];
            if ($params['stretch'] == 'Yes') {
                $w = "100%";
                $h = "100%";
            }
            if ($params['asize'] == 'Yes' || $params['awidth'] == 'Yes' && $params['aheight'] == 'Yes') {
                $autoMode = "3";
                //both
            } else {
                if ($params['awidth'] == 'Yes') {
                    $autoMode = "1";
                    //width only
                } else {
                    if ($params['aheight'] == 'Yes') {
                        $autoMode = "2";
                        //height only
                    }
                }
            }
            $modx->regClientStartupScript(MODX_MANAGER_URL . "media/script/bin/viewport.js", array('name' => 'viewport', 'version' => '0', 'plaintext' => false));
            $o = $sTag . " id='" . $params['vpid'] . "' name='" . $params['vpid'] . "' ";
            if ($params['class']) {
                $o .= " class='" . $params['class'] . "' ";
            }
            if ($params['style']) {
                $o .= " style='" . $params['style'] . "' ";
            }
            if ($params['attrib']) {
                $o .= $params['attrib'] . " ";
            }
            $o .= "scrolling='" . ($params['sbar'] == 'No' ? "no" : ($params['sbar'] == 'Yes' ? "yes" : "auto")) . "' ";
            $o .= "src='" . $value . "' frameborder='" . $params['borsize'] . "' ";
            $o .= "onload=\"window.setTimeout('ResizeViewPort(\\'" . $params['vpid'] . "\\'," . $autoMode . ")',100);\" width='" . $w . "' height='" . $h . "' ";
            $o .= ">";
            $o .= $eTag;
            break;
        case "datagrid":
            include_once MODX_MANAGER_PATH . "includes/controls/datagrid.class.php";
            $grd = new DataGrid('', $value);
            $grd->noRecordMsg = $params['egmsg'];
            $grd->columnHeaderClass = $params['chdrc'];
            $grd->cssClass = $params['tblc'];
            $grd->itemClass = $params['itmc'];
            $grd->altItemClass = $params['aitmc'];
            $grd->columnHeaderStyle = $params['chdrs'];
            $grd->cssStyle = $params['tbls'];
            $grd->itemStyle = $params['itms'];
            $grd->altItemStyle = $params['aitms'];
            $grd->columns = $params['cols'];
            $grd->fields = $params['flds'];
            $grd->colWidths = $params['cwidth'];
            $grd->colAligns = $params['calign'];
            $grd->colColors = $params['ccolor'];
            $grd->colTypes = $params['ctype'];
            $grd->cellPadding = $params['cpad'];
            $grd->cellSpacing = $params['cspace'];
            $grd->header = $params['head'];
            $grd->footer = $params['foot'];
            $grd->pageSize = $params['psize'];
            $grd->pagerLocation = $params['ploc'];
            $grd->pagerClass = $params['pclass'];
            $grd->pagerStyle = $params['pstyle'];
            $o = $grd->render();
            break;
        case 'htmlentities':
            $value = parseInput($value);
            if ($tvtype == 'checkbox' || $tvtype == 'listbox-multiple') {
                // remove delimiter from checkbox and listbox-multiple TVs
                $value = str_replace('||', '', $value);
            }
            $o = htmlentities($value, ENT_NOQUOTES, $modx->config['modx_charset']);
            break;
        case 'custom_widget':
            $widget_output = '';
            $o = '';
            /* If we are loading a file */
            if (substr($params['output'], 0, 5) == "@FILE") {
                $file_name = MODX_BASE_PATH . trim(substr($params['output'], 6));
                if (!file_exists($file_name)) {
                    $widget_output = $file_name . ' does not exist';
                } else {
                    $widget_output = file_get_contents($file_name);
                }
            } elseif (substr($params['output'], 0, 8) == '@INCLUDE') {
                $file_name = MODX_BASE_PATH . trim(substr($params['output'], 9));
                if (!file_exists($file_name)) {
                    $widget_output = $file_name . ' does not exist';
                } else {
                    /* The included file needs to set $widget_output. Can be string, array, object */
                    include $file_name;
                }
            } elseif (substr($params['output'], 0, 6) == '@CHUNK' && $value !== '') {
                $chunk_name = trim(substr($params['output'], 7));
                $widget_output = $modx->getChunk($chunk_name);
            } elseif (substr($params['output'], 0, 5) == '@EVAL' && $value !== '') {
                $eval_str = trim(substr($params['output'], 6));
                $widget_output = eval($eval_str);
            } elseif ($value !== '') {
                $widget_output = $params['output'];
            } else {
                $widget_output = '';
            }
            if (is_string($widget_output)) {
                $widget_output = str_replace('[+value+]', $value, $widget_output);
                $o = $modx->parseDocumentSource($widget_output);
            } else {
                $o = $widget_output;
            }
            break;
        default:
            $value = parseInput($value);
            if ($tvtype == 'checkbox' || $tvtype == 'listbox-multiple') {
                // add separator
                $value = explode('||', $value);
                $value = implode($sep, $value);
            }
            $o = $value;
            break;
    }
    return $o;
}
Пример #5
0
function ProcessTVCommand($value, $name = '', $docid = '')
{
    global $modx;
    $etomite =& $modx;
    $docid = intval($docid) ? intval($docid) : $modx->documentIdentifier;
    $nvalue = trim($value);
    if (substr($nvalue, 0, 1) != '@') {
        return $value;
    } else {
        list($cmd, $param) = ParseCommand($nvalue);
        $cmd = trim($cmd);
        switch ($cmd) {
            case "FILE":
                $output = ProcessFile(trim($param));
                $output = str_replace('@FILE ' . $param, $output, $nvalue);
                break;
            case "CHUNK":
                // retrieve a chunk and process it's content
                $chunk = $modx->getChunk($param);
                $output = $chunk;
                break;
            case "DOCUMENT":
                // retrieve a document and process it's content
                $rs = $modx->getDocument($param);
                if (is_array($rs)) {
                    $output = $rs['content'];
                } else {
                    $output = "Unable to locate document {$param}";
                }
                break;
            case "SELECT":
                // selects a record from the cms database
                $rt = array();
                $replacementVars = array('DBASE' => $modx->db->config['dbase'], 'PREFIX' => $modx->db->config['table_prefix']);
                foreach ($replacementVars as $rvKey => $rvValue) {
                    $modx->setPlaceholder($rvKey, $rvValue);
                }
                $param = $modx->mergePlaceholderContent($param);
                $rs = $modx->db->query("SELECT {$param};");
                $output = $rs;
                break;
            case "EVAL":
                // evaluates text as php codes return the results
                $output = eval($param);
                break;
            case "INHERIT":
                $output = $param;
                // Default to param value if no content from parents
                $doc = $modx->getPageInfo($docid, 0, 'id,parent');
                while ($doc['parent'] != 0) {
                    $parent_id = $doc['parent'];
                    // Grab document regardless of publish status
                    $doc = $modx->getPageInfo($parent_id, 0, 'id,parent,published');
                    if ($doc['parent'] != 0 && !$doc['published']) {
                        continue;
                    }
                    // hide unpublished docs if we're not at the top
                    $tv = $modx->getTemplateVar($name, '*', $doc['id'], $doc['published']);
                    // Modified @INHERIT binding to allow for @FILE bindings (and others) to be inherited,
                    // as well as allowing content after the @INHERITed values
                    if ((string) $tv['value'] !== '' && !preg_match('%^@INHERIT[\\s\\n\\r]*$%im', $tv['value'])) {
                        $output = (string) $tv['value'];
                        $output = str_replace('@INHERIT', $output, $nvalue);
                        break 2;
                    }
                }
                break;
            case 'DIRECTORY':
                $files = array();
                $path = $modx->config['base_path'] . $param;
                if (substr($path, -1, 1) != '/') {
                    $path .= '/';
                }
                if (!is_dir($path)) {
                    die($path);
                    break;
                }
                $dir = dir($path);
                while (($file = $dir->read()) !== false) {
                    if (substr($file, 0, 1) != '.') {
                        $files[] = "{$file}=={$param}{$file}";
                    }
                }
                asort($files);
                $output = implode('||', $files);
                break;
            default:
                $output = $value;
                break;
        }
        // support for nested bindings
        return is_string($output) && $output != $value ? ProcessTVCommand($output, $name, $docid) : $output;
    }
}
Пример #6
0
 function renderFormElement($field_type, $field_name, $default_text, $field_elements, $field_value, $field_style = '', $attributes = '', $classnames = array())
 {
     global $base_url;
     global $rb_base_url;
     global $manager_theme;
     $field_html = '';
     $field_value = $field_value != "" ? $field_value : $default_text;
     if ($field_type == "richtext") {
         $classnames[] = 'richtext';
     }
     if ($field_type == "image" || $field_type == "file") {
         $classnames[] = 'filemanager';
     }
     $class = count($classnames) > 0 ? 'class="' . implode(' ', $classnames) . '"' : '';
     switch ($field_type) {
         case "text":
             // handler for regular text boxes
         // handler for regular text boxes
         case "rawtext":
             // non-htmlentity converted text boxes
         // non-htmlentity converted text boxes
         case "email":
             // handles email input fields
         // handles email input fields
         case "number":
             // handles the input of numbers
             $field_html .= '<input ' . $class . $attributes . ' type="text" id="tv' . $field_name . '" name="tv' . $field_name . '" value="' . htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" onchange="documentDirty=true;" style="width:100%" />';
             break;
         case "textareamini":
             // handler for textarea mini boxes
             $field_html .= '<textarea ' . $class . $attributes . ' id="tv' . $field_name . '" name="tv' . $field_name . '" cols="40" rows="5" onchange="documentDirty=true;" style="width:100%">' . htmlspecialchars($field_value) . '</textarea>';
             break;
         case "textarea":
             // handler for textarea boxes
         // handler for textarea boxes
         case "rawtextarea":
             // non-htmlentity convertex textarea boxes
         // non-htmlentity convertex textarea boxes
         case "htmlarea":
             // handler for textarea boxes (deprecated)
         // handler for textarea boxes (deprecated)
         case "richtext":
             // handler for textarea boxes
             $field_html .= '<textarea ' . $class . $attributes . ' id="tv' . $field_name . '" name="tv' . $field_name . '" cols="40" rows="15" onchange="documentDirty=true;" style="width:100%;">' . htmlspecialchars($field_value) . '</textarea>';
             break;
         case "date":
             if ($field_value == '') {
                 $field_value = 0;
             }
             $cal = 'cal' . str_replace('-', '_', $field_name);
             $field_html .= '<input ' . $class . $attributes . ' id="tv' . $field_name . '" name="tv' . $field_name . '" type="hidden" value="' . ($field_value == 0 || !isset($field_value) ? "" : $field_value) . '" onblur="documentDirty=true;">';
             $field_html .= '	<table width="250" border="0" cellspacing="0" cellpadding="0">';
             $field_html .= '	  <tr>';
             $field_html .= '		<td width="160" style="border: 1px solid #808080;"><span id="tv' . $field_name . '_show" class="inputBox"> ' . ($field_value == 0 || !isset($field_value) ? '(not set)' : $field_value) . '</span> </td>';
             $field_html .= '		<td>&nbsp;';
             $field_html .= '			<a onClick="documentDirty=false; ' . $cal . '.popup();" onMouseover="window.status=\'Select a date\'; return true;" onMouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img src="media/style/' . ($manager_theme ? "{$manager_theme}/" : "") . 'images/icons/cal.gif" width="16" height="16" border="0"></a>';
             $field_html .= '			<a onClick="document.forms[\'mutate\'].elements[\'tv' . $field_name . '\'].value=\'\';document.forms[\'mutate\'].elements[\'tv' . $field_name . '\'].onblur();document.getElementById(\'tv' . $field_name . '_show\').innerHTML=\'(not set)\'; return true;" onMouseover="window.status=\'clear the date\'; return true;" onMouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img src="media/style/' . ($manager_theme ? "{$manager_theme}/" : "") . 'images/icons/cal_nodate.gif" width="16" height="16" border="0" alt="No date"></a>';
             $field_html .= '		</td>';
             $field_html .= '	  </tr>';
             $field_html .= '    </table>';
             $field_html .= '<script type="text/javascript">';
             $field_html .= '	var ' . $cal . ' = new calendar1(document.forms[\'mutate\'].elements[\'tv' . $field_name . '\'], document.getElementById("tv' . $field_name . '_show"));';
             $field_html .= '   ' . $cal . '.path="' . MODX_MANAGER_URL . 'media/";';
             $field_html .= '	' . $cal . '.year_scroll = true;';
             $field_html .= '   ' . $cal . '.time_comp = true;';
             $field_html .= '</script>';
             break;
         case "dropdown":
             // handler for select boxes
             $field_html .= '<select ' . $class . $attributes . ' id="tv' . $field_name . '" name="tv' . $field_name . '" size="1" onchange="documentDirty=true;">';
             $index_list = $this->ParseIntputOptions(ProcessTVCommand($field_elements, $field_name));
             while (list($item, $itemvalue) = each($index_list)) {
                 list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                 if (strlen($itemvalue) == 0) {
                     $itemvalue = $item;
                 }
                 $field_html .= '<option value="' . htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . htmlspecialchars($item) . '</option>';
             }
             $field_html .= "</select>";
             break;
         case "listbox":
             // handler for select boxes
             $field_html .= '<select ' . $class . $attributes . ' id="tv' . $field_name . '" name="tv' . $field_name . '" onchange="documentDirty=true;" size="8">';
             $index_list = $this->ParseIntputOptions(ProcessTVCommand($field_elements, $field_name));
             while (list($item, $itemvalue) = each($index_list)) {
                 list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                 if (strlen($itemvalue) == 0) {
                     $itemvalue = $item;
                 }
                 $field_html .= '<option value="' . htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . htmlspecialchars($item) . '</option>';
             }
             $field_html .= "</select>";
             break;
         case "listbox-multiple":
             // handler for select boxes where you can choose multiple items
             $field_value = explode("||", $field_value);
             $field_html .= '<select  ' . $class . $attributes . ' id="tv' . $field_name . '[]" name="tv' . $field_name . '[]" multiple="multiple" onchange="documentDirty=true;" size="8">';
             $index_list = $this->ParseIntputOptions(ProcessTVCommand($field_elements, $field_name));
             while (list($item, $itemvalue) = each($index_list)) {
                 list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                 if (strlen($itemvalue) == 0) {
                     $itemvalue = $item;
                 }
                 $field_html .= '<option value="' . htmlspecialchars($itemvalue) . '"' . (in_array($itemvalue, $field_value) ? ' selected="selected"' : '') . '>' . htmlspecialchars($item) . '</option>';
             }
             $field_html .= "</select>";
             break;
         case "url":
             // handles url input fields
             $urls = array('' => '--', 'http://' => 'http://', 'https://' => 'https://', 'ftp://' => 'ftp://', 'mailto:' => 'mailto:');
             $field_html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><select ' . $class . $attributes . ' id="tv' . $field_name . '_prefix" name="tv' . $field_name . '_prefix" onchange="documentDirty=true;">';
             foreach ($urls as $k => $v) {
                 if (strpos($field_value, $v) === false) {
                     $field_html .= '<option value="' . $v . '">' . $k . '</option>';
                 } else {
                     $field_value = str_replace($v, '', $field_value);
                     $field_html .= '<option value="' . $v . '" selected="selected">' . $k . '</option>';
                 }
             }
             $field_html .= '</select></td><td>';
             $field_html .= '<input ' . $class . $attributes . ' type="text" id="tv' . $field_name . '" name="tv' . $field_name . '" value="' . htmlspecialchars($field_value) . '" width="100" ' . $field_style . ' onchange="documentDirty=true;" /></td></tr></table>';
             break;
         case "checkbox":
             // handles check boxes
             $field_value = explode("||", $field_value);
             $index_list = $this->ParseIntputOptions($this->ProcessTVCommand($field_elements, $field_name));
             static $i = 0;
             while (list($item, $itemvalue) = each($index_list)) {
                 list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                 if (strlen($itemvalue) == 0) {
                     $itemvalue = $item;
                 }
                 $field_html .= '<input ' . $class . $attributes . ' type="checkbox" value="' . htmlspecialchars($itemvalue) . '" id="tv_' . $i . '" name="tv' . $field_name . '[]" ' . (in_array($itemvalue, $field_value) ? " checked='checked'" : "") . ' onchange="documentDirty=true;" /><span class="label">' . $item . '</span>';
                 $i++;
             }
             break;
         case "option":
             // handles radio buttons
             $index_list = $this->ParseIntputOptions($this->ProcessTVCommand($field_elements, $field_name));
             while (list($item, $itemvalue) = each($index_list)) {
                 list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                 if (strlen($itemvalue) == 0) {
                     $itemvalue = $item;
                 }
                 $field_html .= '<input ' . $class . $attributes . ' type="radio" value="' . htmlspecialchars($itemvalue) . '" name="tv' . $field_name . '" ' . ($itemvalue == $field_value ? 'checked="checked"' : '') . ' onchange="documentDirty=true;" /><span class="label">' . $item . '</span>';
             }
             break;
         case "image":
             // handles image fields using htmlarea image manager
             global $_lang;
             global $ResourceManagerLoaded;
             global $content, $use_editor, $which_editor;
             if (!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $_GET['a'] == 4) && $use_editor == 1 && $which_editor == 3)) {
                 $field_html .= "\n\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\tvar lastImageCtrl;\n\t\t\t\t\t\t\tvar lastFileCtrl;\n\t\t\t\t\t\t\tfunction OpenServerBrowser(url, width, height ) {\n\t\t\t\t\t\t\t\tvar iLeft = (screen.width  - width) / 2 ;\n\t\t\t\t\t\t\t\tvar iTop  = (screen.height - height) / 2 ;\n\n\t\t\t\t\t\t\t\tvar sOptions = 'toolbar=no,status=no,resizable=yes,dependent=yes' ;\n\t\t\t\t\t\t\t\tsOptions += ',width=' + width ;\n\t\t\t\t\t\t\t\tsOptions += ',height=' + height ;\n\t\t\t\t\t\t\t\tsOptions += ',left=' + iLeft ;\n\t\t\t\t\t\t\t\tsOptions += ',top=' + iTop ;\n\n\t\t\t\t\t\t\t\tvar oWindow = window.open( url, 'FCKBrowseWindow', sOptions ) ;\n\t\t\t\t\t\t\t}\t\t\t\n\t\t\t\t\t\t\tfunction BrowseServer(ctrl) {\n\t\t\t\t\t\t\t\tlastImageCtrl = ctrl;\n\t\t\t\t\t\t\t\tvar w = screen.width * 0.7;\n\t\t\t\t\t\t\t\tvar h = screen.height * 0.7;\n\t\t\t\t\t\t\t\tOpenServerBrowser('" . $base_url . "manager/media/browser/mcpuk/browser.html?Type=images&Connector=" . $base_url . "manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath=" . $base_url . "', w, h);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfunction BrowseFileServer(ctrl) {\n\t\t\t\t\t\t\t\tlastFileCtrl = ctrl;\n\t\t\t\t\t\t\t\tvar w = screen.width * 0.7;\n\t\t\t\t\t\t\t\tvar h = screen.height * 0.7;\n\t\t\t\t\t\t\t\tOpenServerBrowser('" . $base_url . "manager/media/browser/mcpuk/browser.html?Type=files&Connector=" . $base_url . "manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath=" . $base_url . "', w, h);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfunction SetUrl(url, width, height, alt){\n\t\t\t\t\t\t\t\tif(lastFileCtrl) {\n\t\t\t\t\t\t\t\t\tvar c = document.mutate[lastFileCtrl];\n\t\t\t\t\t\t\t\t\tif(c) c.value = url;\n\t\t\t\t\t\t\t\t\tlastFileCtrl = '';\n\t\t\t\t\t\t\t\t} else if(lastImageCtrl) {\n\t\t\t\t\t\t\t\t\tvar c = document.mutate[lastImageCtrl];\n\t\t\t\t\t\t\t\t\tif(c) c.value = url;\n\t\t\t\t\t\t\t\t\tlastImageCtrl = '';\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t</script>";
                 $ResourceManagerLoaded = true;
             }
             $field_html .= '<input ' . $class . $attributes . ' type="text" fieldtype="' . $field_type . '" id="tv' . $field_name . '" name="tv' . $field_name . '"  value="' . $field_value . '" ' . $field_style . ' onchange="documentDirty=true;" />&nbsp;<input type="button" value="' . $_lang['insert'] . '" id="button_tv' . $field_name . '" />';
             break;
         case "file":
             // handles the input of file uploads
             /* Modified by Timon for use with resource browser */
             global $_lang;
             global $ResourceManagerLoaded;
             global $content, $use_editor, $which_editor;
             if (!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $_GET['a'] == 4) && $use_editor == 1 && $which_editor == 3)) {
                 /* I didn't understand the meaning of the condition above, so I left it untouched ;-) */
                 $field_html .= "\n\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\tvar lastImageCtrl;\n\t\t\t\t\t\t\tvar lastFileCtrl;\n\t\t\t\t\t\t\tfunction OpenServerBrowser(url, width, height ) {\n\t\t\t\t\t\t\t\tvar iLeft = (screen.width  - width) / 2 ;\n\t\t\t\t\t\t\t\tvar iTop  = (screen.height - height) / 2 ;\n\n\t\t\t\t\t\t\t\tvar sOptions = 'toolbar=no,status=no,resizable=yes,dependent=yes' ;\n\t\t\t\t\t\t\t\tsOptions += ',width=' + width ;\n\t\t\t\t\t\t\t\tsOptions += ',height=' + height ;\n\t\t\t\t\t\t\t\tsOptions += ',left=' + iLeft ;\n\t\t\t\t\t\t\t\tsOptions += ',top=' + iTop ;\n\n\t\t\t\t\t\t\t\tvar oWindow = window.open( url, 'FCKBrowseWindow', sOptions ) ;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tfunction BrowseServer(ctrl) {\n\t\t\t\t\t\t\t\tlastImageCtrl = ctrl;\n\t\t\t\t\t\t\t\tvar w = screen.width * 0.7;\n\t\t\t\t\t\t\t\tvar h = screen.height * 0.7;\n\t\t\t\t\t\t\t\tOpenServerBrowser('" . $base_url . "manager/media/browser/mcpuk/browser.html?Type=images&Connector=" . $base_url . "manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath=" . $base_url . "', w, h);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfunction BrowseFileServer(ctrl) {\n\t\t\t\t\t\t\t\tlastFileCtrl = ctrl;\n\t\t\t\t\t\t\t\tvar w = screen.width * 0.7;\n\t\t\t\t\t\t\t\tvar h = screen.height * 0.7;\n\t\t\t\t\t\t\t\tOpenServerBrowser('" . $base_url . "manager/media/browser/mcpuk/browser.html?Type=files&Connector=" . $base_url . "manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath=" . $base_url . "', w, h);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfunction SetUrl(url, width, height, alt){\n\t\t\t\t\t\t\t\tif(lastFileCtrl) {\n\t\t\t\t\t\t\t\t\tvar c = document.mutate[lastFileCtrl];\n\t\t\t\t\t\t\t\t\tif(c) c.value = url;\n\t\t\t\t\t\t\t\t\tlastFileCtrl = '';\n\t\t\t\t\t\t\t\t} else if(lastImageCtrl) {\n\t\t\t\t\t\t\t\t\tvar c = document.mutate[lastImageCtrl];\n\t\t\t\t\t\t\t\t\tif(c) c.value = url;\n\t\t\t\t\t\t\t\t\tlastImageCtrl = '';\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t</script>";
                 $ResourceManagerLoaded = true;
             }
             //$field_html .='<input '.$class.$attributes.' type="text" id="tv'.$field_name.'" name="tv'.$field_name.'"  value="'.$field_value .'" '.$field_style.' onchange="documentDirty=true;" />&nbsp;<input type="button" value="'.$_lang['insert'].'" onclick="BrowseFileServer(\'tv'.$field_name.'\')" />';
             $field_html .= '<input ' . $class . $attributes . ' type="text" fieldtype="' . $field_type . '" id="tv' . $field_name . '" name="tv' . $field_name . '"  value="' . $field_value . '" ' . $field_style . ' onchange="documentDirty=true;" />&nbsp;<input type="button" value="' . $_lang['insert'] . '" id="button_tv' . $field_name . '" />';
             break;
         default:
             // the default handler -- for errors, mostly
             $field_html .= '<input ' . $class . $attributes . ' type="text" id="tv' . $field_name . '" name="tv' . $field_name . '" value="' . htmlspecialchars($field_value) . '" ' . $field_style . ' onchange="documentDirty=true;" />';
     }
     // end switch statement
     return $field_html;
 }
Пример #7
0
function renderFormElement($field_type, $field_id, $default_text = '', $field_elements = '', $field_value = '', $field_style = '', $row = array())
{
    global $modx;
    global $_style;
    global $_lang;
    global $content;
    if (substr($default_text, 0, 6) === '@@EVAL' && $field_value === $default_text) {
        $eval_str = trim(substr($default_text, 7));
        $default_text = eval($eval_str);
    }
    $field_value = $field_value != '' ? $field_value : $default_text;
    $field_html = '';
    $cimode = strpos($field_type, ':');
    if ($cimode === false) {
        switch ($field_type) {
            case "text":
                // handler for regular text boxes
            // handler for regular text boxes
            case "rawtext":
                // non-htmlentity converted text boxes
                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" onchange="documentDirty=true;" style="width:100%" />';
                break;
            case "email":
                // handles email input fields
                $field_html .= '<input type="email" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" onchange="documentDirty=true;" style="width:100%"/>';
                break;
            case "number":
                // handles the input of numbers
                $field_html .= '<input type="number" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" onchange="documentDirty=true;" style="width:100%" onkeyup="this.value=this.value.replace(/[^\\d-,.+]/,\'\')"/>';
                break;
            case "textareamini":
                // handler for textarea mini boxes
                $field_html .= '<textarea id="tv' . $field_id . '" name="tv' . $field_id . '" cols="40" rows="5" onchange="documentDirty=true;" style="width:100%">' . $modx->htmlspecialchars($field_value) . '</textarea>';
                break;
            case "textarea":
                // handler for textarea boxes
            // handler for textarea boxes
            case "rawtextarea":
                // non-htmlentity convertex textarea boxes
            // non-htmlentity convertex textarea boxes
            case "htmlarea":
                // handler for textarea boxes (deprecated)
            // handler for textarea boxes (deprecated)
            case "richtext":
                // handler for textarea boxes
                $field_html .= '<textarea id="tv' . $field_id . '" name="tv' . $field_id . '" cols="40" rows="15" onchange="documentDirty=true;" style="width:100%">' . $modx->htmlspecialchars($field_value) . '</textarea>';
                break;
            case "date":
                $field_id = str_replace(array('-', '.'), '_', urldecode($field_id));
                if ($field_value == '') {
                    $field_value = 0;
                }
                $field_html .= '<input id="tv' . $field_id . '" name="tv' . $field_id . '" class="DatePicker" type="text" value="' . ($field_value == 0 || !isset($field_value) ? "" : $field_value) . '" onblur="documentDirty=true;" />';
                $field_html .= ' <a onclick="document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].value=\'\';document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].onblur(); return true;" onmouseover="window.status=\'clear the date\'; return true;" onmouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img src="' . $_style["icons_cal_nodate"] . '" border="0" alt="No date" /></a>';
                $field_html .= '<script type="text/javascript">';
                $field_html .= '	window.addEvent(\'domready\', function() {';
                $field_html .= '	  	new DatePicker($(\'tv' . $field_id . '\'), {\'dayNames\' : ' . $_lang['dp_dayNames'] . ', \'startDay\' : ' . $_lang['dp_startDay'] . ', \'yearOffset\' : ' . $modx->config['datepicker_offset'] . ", 'format' : " . "'" . $modx->config['datetime_format'] . ' hh:mm:00\'' . '});';
                $field_html .= '});';
                $field_html .= '</script>';
                break;
            case "dropdown":
                // handler for select boxes
                $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" size="1" onchange="documentDirty=true;">';
                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform'));
                while (list($item, $itemvalue) = each($index_list)) {
                    list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                    if (strlen($itemvalue) == 0) {
                        $itemvalue = $item;
                    }
                    $field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
                }
                $field_html .= "</select>";
                break;
            case "listbox":
                // handler for select boxes
                $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" onchange="documentDirty=true;" size="8">';
                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform'));
                while (list($item, $itemvalue) = each($index_list)) {
                    list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                    if (strlen($itemvalue) == 0) {
                        $itemvalue = $item;
                    }
                    $field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . ($itemvalue == $field_value ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
                }
                $field_html .= "</select>";
                break;
            case "listbox-multiple":
                // handler for select boxes where you can choose multiple items
                $field_value = explode("||", $field_value);
                $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '[]" multiple="multiple" onchange="documentDirty=true;" size="8">';
                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform'));
                while (list($item, $itemvalue) = each($index_list)) {
                    list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                    if (strlen($itemvalue) == 0) {
                        $itemvalue = $item;
                    }
                    $field_html .= '<option value="' . $modx->htmlspecialchars($itemvalue) . '"' . (in_array($itemvalue, $field_value) ? ' selected="selected"' : '') . '>' . $modx->htmlspecialchars($item) . '</option>';
                }
                $field_html .= "</select>";
                break;
            case "url":
                // handles url input fields
                $urls = array('' => '--', 'http://' => 'http://', 'https://' => 'https://', 'ftp://' => 'ftp://', 'mailto:' => 'mailto:');
                $field_html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><select id="tv' . $field_id . '_prefix" name="tv' . $field_id . '_prefix" onchange="documentDirty=true;">';
                foreach ($urls as $k => $v) {
                    if (strpos($field_value, $v) === false) {
                        $field_html .= '<option value="' . $v . '">' . $k . '</option>';
                    } else {
                        $field_value = str_replace($v, '', $field_value);
                        $field_html .= '<option value="' . $v . '" selected="selected">' . $k . '</option>';
                    }
                }
                $field_html .= '</select></td><td>';
                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" width="100" ' . $field_style . ' onchange="documentDirty=true;" /></td></tr></table>';
                break;
            case "checkbox":
                // handles check boxes
                $field_value = !is_array($field_value) ? explode("||", $field_value) : $field_value;
                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform'));
                static $i = 0;
                while (list($item, $itemvalue) = each($index_list)) {
                    list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                    if (strlen($itemvalue) == 0) {
                        $itemvalue = $item;
                    }
                    $field_html .= '<input type="checkbox" value="' . $modx->htmlspecialchars($itemvalue) . '" id="tv_' . $i . '" name="tv' . $field_id . '[]" ' . (in_array($itemvalue, $field_value) ? " checked='checked'" : "") . ' onchange="documentDirty=true;" /><label for="tv_' . $i . '">' . $item . '</label><br />';
                    $i++;
                }
                break;
            case "option":
                // handles radio buttons
                $index_list = ParseIntputOptions(ProcessTVCommand($field_elements, $field_id, '', 'tvform'));
                static $i = 0;
                while (list($item, $itemvalue) = each($index_list)) {
                    list($item, $itemvalue) = is_array($itemvalue) ? $itemvalue : explode("==", $itemvalue);
                    if (strlen($itemvalue) == 0) {
                        $itemvalue = $item;
                    }
                    $field_html .= '<input type="radio" value="' . $modx->htmlspecialchars($itemvalue) . '" id="tv_' . $i . '" name="tv' . $field_id . '" ' . ($itemvalue == $field_value ? 'checked="checked"' : '') . ' onchange="documentDirty=true;" /><label for="tv_' . $i . '">' . $item . '</label><br />';
                    $i++;
                }
                break;
            case "image":
                // handles image fields using htmlarea image manager
                global $_lang;
                global $ResourceManagerLoaded;
                global $content, $use_editor, $which_editor;
                if (!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $_GET['a'] == 4) && $use_editor == 1 && $which_editor == 3)) {
                    $field_html .= "\n\t\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\t/* <![CDATA[ */\n\t\t\t\t\t\t\t\tvar lastImageCtrl;\n\t\t\t\t\t\t\t\tvar lastFileCtrl;\n\t\t\t\t\t\t\t\tfunction OpenServerBrowser(url, width, height ) {\n\t\t\t\t\t\t\t\t\tvar iLeft = (screen.width  - width) / 2 ;\n\t\t\t\t\t\t\t\t\tvar iTop  = (screen.height - height) / 2 ;\n\n\t\t\t\t\t\t\t\t\tvar sOptions = 'toolbar=no,status=no,resizable=yes,dependent=yes' ;\n\t\t\t\t\t\t\t\t\tsOptions += ',width=' + width ;\n\t\t\t\t\t\t\t\t\tsOptions += ',height=' + height ;\n\t\t\t\t\t\t\t\t\tsOptions += ',left=' + iLeft ;\n\t\t\t\t\t\t\t\t\tsOptions += ',top=' + iTop ;\n\n\t\t\t\t\t\t\t\t\tvar oWindow = window.open( url, 'FCKBrowseWindow', sOptions ) ;\n\t\t\t\t\t\t\t\t}\t\t\t\n\t\t\t\t\t\t\t\tfunction BrowseServer(ctrl) {\n\t\t\t\t\t\t\t\t\tlastImageCtrl = ctrl;\n\t\t\t\t\t\t\t\t\tvar w = screen.width * 0.5;\n\t\t\t\t\t\t\t\t\tvar h = screen.height * 0.5;\n\t\t\t\t\t\t\t\t\tOpenServerBrowser('" . MODX_MANAGER_URL . "media/browser/mcpuk/browser.php?Type=images', w, h);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfunction BrowseFileServer(ctrl) {\n\t\t\t\t\t\t\t\t\tlastFileCtrl = ctrl;\n\t\t\t\t\t\t\t\t\tvar w = screen.width * 0.5;\n\t\t\t\t\t\t\t\t\tvar h = screen.height * 0.5;\n\t\t\t\t\t\t\t\t\tOpenServerBrowser('" . MODX_MANAGER_URL . "media/browser/mcpuk/browser.php?Type=files', w, h);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfunction SetUrlChange(el) {\n\t\t\t\t\t\t\t\t\tif ('createEvent' in document) {\n\t\t\t\t\t\t\t\t\t\tvar evt = document.createEvent('HTMLEvents');\n\t\t\t\t\t\t\t\t\t\tevt.initEvent('change', false, true);\n\t\t\t\t\t\t\t\t\t\tel.dispatchEvent(evt);\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tel.fireEvent('onchange');\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfunction SetUrl(url, width, height, alt) {\n\t\t\t\t\t\t\t\t\tif(lastFileCtrl) {\n\t\t\t\t\t\t\t\t\t\tvar c = document.getElementById(lastFileCtrl);\n\t\t\t\t\t\t\t\t\t\tif(c && c.value != url) {\n\t\t\t\t\t\t\t\t\t\t    c.value = url;\n\t\t\t\t\t\t\t\t\t\t\tSetUrlChange(c);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tlastFileCtrl = '';\n\t\t\t\t\t\t\t\t\t} else if(lastImageCtrl) {\n\t\t\t\t\t\t\t\t\t\tvar c = document.getElementById(lastImageCtrl);\n\t\t\t\t\t\t\t\t\t\tif(c && c.value != url) {\n\t\t\t\t\t\t\t\t\t\t    c.value = url;\n\t\t\t\t\t\t\t\t\t\t\tSetUrlChange(c);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tlastImageCtrl = '';\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/* ]]> */\n\t\t\t\t\t\t</script>";
                    $ResourceManagerLoaded = true;
                }
                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '"  value="' . $field_value . '" ' . $field_style . ' onchange="documentDirty=true;" />&nbsp;<input type="button" value="' . $_lang['insert'] . '" onclick="BrowseServer(\'tv' . $field_id . '\')" />';
                break;
            case "file":
                // handles the input of file uploads
                /* Modified by Timon for use with resource browser */
                global $_lang;
                global $ResourceManagerLoaded;
                global $content, $use_editor, $which_editor;
                if (!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $_GET['a'] == 4) && $use_editor == 1 && $which_editor == 3)) {
                    /* I didn't understand the meaning of the condition above, so I left it untouched ;-) */
                    $field_html .= "\n\t\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\t\t/* <![CDATA[ */\n\t\t\t\t\t\t\t\tvar lastImageCtrl;\n\t\t\t\t\t\t\t\tvar lastFileCtrl;\n\t\t\t\t\t\t\t\tfunction OpenServerBrowser(url, width, height ) {\n\t\t\t\t\t\t\t\t\tvar iLeft = (screen.width  - width) / 2 ;\n\t\t\t\t\t\t\t\t\tvar iTop  = (screen.height - height) / 2 ;\n\n\t\t\t\t\t\t\t\t\tvar sOptions = 'toolbar=no,status=no,resizable=yes,dependent=yes' ;\n\t\t\t\t\t\t\t\t\tsOptions += ',width=' + width ;\n\t\t\t\t\t\t\t\t\tsOptions += ',height=' + height ;\n\t\t\t\t\t\t\t\t\tsOptions += ',left=' + iLeft ;\n\t\t\t\t\t\t\t\t\tsOptions += ',top=' + iTop ;\n\n\t\t\t\t\t\t\t\t\tvar oWindow = window.open( url, 'FCKBrowseWindow', sOptions ) ;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfunction BrowseServer(ctrl) {\n\t\t\t\t\t\t\t\t\tlastImageCtrl = ctrl;\n\t\t\t\t\t\t\t\t\tvar w = screen.width * 0.5;\n\t\t\t\t\t\t\t\t\tvar h = screen.height * 0.5;\n\t\t\t\t\t\t\t\t\tOpenServerBrowser('" . MODX_MANAGER_URL . "media/browser/mcpuk/browser.php?Type=images', w, h);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfunction BrowseFileServer(ctrl) {\n\t\t\t\t\t\t\t\t\tlastFileCtrl = ctrl;\n\t\t\t\t\t\t\t\t\tvar w = screen.width * 0.5;\n\t\t\t\t\t\t\t\t\tvar h = screen.height * 0.5;\n\t\t\t\t\t\t\t\t\tOpenServerBrowser('" . MODX_MANAGER_URL . "media/browser/mcpuk/browser.php?Type=files', w, h);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfunction SetUrlChange(el) {\n\t\t\t\t\t\t\t\t\tif ('createEvent' in document) {\n\t\t\t\t\t\t\t\t\t\tvar evt = document.createEvent('HTMLEvents');\n\t\t\t\t\t\t\t\t\t\tevt.initEvent('change', false, true);\n\t\t\t\t\t\t\t\t\t\tel.dispatchEvent(evt);\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tel.fireEvent('onchange');\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfunction SetUrl(url, width, height, alt) {\n\t\t\t\t\t\t\t\t\tif(lastFileCtrl) {\n\t\t\t\t\t\t\t\t\t\tvar c = document.getElementById(lastFileCtrl);\n\t\t\t\t\t\t\t\t\t\tif(c && c.value != url) {\n\t\t\t\t\t\t\t\t\t\t    c.value = url;\n\t\t\t\t\t\t\t\t\t\t\tSetUrlChange(c);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tlastFileCtrl = '';\n\t\t\t\t\t\t\t\t\t} else if(lastImageCtrl) {\n\t\t\t\t\t\t\t\t\t\tvar c = document.getElementById(lastImageCtrl);\n\t\t\t\t\t\t\t\t\t\tif(c && c.value != url) {\n\t\t\t\t\t\t\t\t\t\t    c.value = url;\n\t\t\t\t\t\t\t\t\t\t\tSetUrlChange(c);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tlastImageCtrl = '';\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t/* ]]> */\n\t\t\t\t\t\t</script>";
                    $ResourceManagerLoaded = true;
                }
                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '"  value="' . $field_value . '" ' . $field_style . ' onchange="documentDirty=true;" />&nbsp;<input type="button" value="' . $_lang['insert'] . '" onclick="BrowseFileServer(\'tv' . $field_id . '\')" />';
                break;
            case 'custom_tv':
                $custom_output = '';
                /* If we are loading a file */
                if (substr($field_elements, 0, 5) == "@FILE") {
                    $file_name = MODX_BASE_PATH . trim(substr($field_elements, 6));
                    if (!file_exists($file_name)) {
                        $custom_output = $file_name . ' does not exist';
                    } else {
                        $custom_output = file_get_contents($file_name);
                    }
                } elseif (substr($field_elements, 0, 8) == '@INCLUDE') {
                    $file_name = MODX_BASE_PATH . trim(substr($field_elements, 9));
                    if (!file_exists($file_name)) {
                        $custom_output = $file_name . ' does not exist';
                    } else {
                        ob_start();
                        include $file_name;
                        $custom_output = ob_get_contents();
                        ob_end_clean();
                    }
                } elseif (substr($field_elements, 0, 6) == "@CHUNK") {
                    $chunk_name = trim(substr($field_elements, 7));
                    $chunk_body = $modx->getChunk($chunk_name);
                    if ($chunk_body == false) {
                        $custom_output = $_lang['chunk_no_exist'] . '(' . $_lang['htmlsnippet_name'] . ':' . $chunk_name . ')';
                    } else {
                        $custom_output = $chunk_body;
                    }
                } elseif (substr($field_elements, 0, 5) == "@EVAL") {
                    $eval_str = trim(substr($field_elements, 6));
                    $custom_output = eval($eval_str);
                } else {
                    $custom_output = $field_elements;
                }
                $replacements = array('[+field_type+]' => $field_type, '[+field_id+]' => $field_id, '[+default_text+]' => $default_text, '[+field_value+]' => $modx->htmlspecialchars($field_value), '[+field_style+]' => $field_style);
                $custom_output = str_replace(array_keys($replacements), $replacements, $custom_output);
                $modx->documentObject = $content;
                $custom_output = $modx->parseDocumentSource($custom_output);
                $field_html .= $custom_output;
                break;
            default:
                // the default handler -- for errors, mostly
                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . $modx->htmlspecialchars($field_value) . '" ' . $field_style . ' onchange="documentDirty=true;" />';
        }
        // end switch statement
    } else {
        $custom = explode(":", $field_type);
        $custom_output = '';
        $file_name = MODX_BASE_PATH . 'assets/tvs/' . $custom['1'] . '/' . $custom['1'] . '.customtv.php';
        if (!file_exists($file_name)) {
            $custom_output = $file_name . ' does not exist';
        } else {
            ob_start();
            include $file_name;
            $custom_output = ob_get_contents();
            ob_end_clean();
        }
        $replacements = array('[+field_type+]' => $field_type, '[+field_id+]' => $field_id, '[+default_text+]' => $default_text, '[+field_value+]' => $modx->htmlspecialchars($field_value), '[+field_style+]' => $field_style);
        $custom_output = str_replace(array_keys($replacements), $replacements, $custom_output);
        $modx->documentObject = $content;
        $custom_output = $modx->parseDocumentSource($custom_output);
        $field_html .= $custom_output;
    }
    return $field_html;
}
Пример #8
0
 }
 $counter = 0;
 if (count($filterFieldValues) > 0) {
     $filters = array();
     if ($xdb->xdbconfig['filters_arr'] > 0) {
         foreach ($xdb->xdbconfig['filters_arr'] as $filter) {
             $filter = explode('(', $filter);
             $filterBy = $filter[0];
             $filterValues = str_replace(')', '', $filter[1]);
             $filters[$filterBy] = $filterValues;
         }
     }
     if (strpos($filterField, "tv") === 0) {
         // get tv list elements
         if (isset($tvElements[$filterField])) {
             $elements = ProcessTVCommand($tvElements[$filterField]);
             $elements = explode("||", $elements);
             for ($i = 0, $count = count($elements); $i < $count; ++$i) {
                 list($optionName, $optionValue) = explode("==", $elements[$i]);
                 $elements[$i] = isset($optionValue) ? $optionValue : $optionName;
                 $optionNames[$i] = $optionName;
             }
             // sort option list
             $new = array();
             foreach ($filterFieldValues as $val) {
                 $val = ($pos = strpos($val, "||")) === false ? $val : substr($val, 0, $pos);
                 if (($pos = array_search($val, $elements)) !== false) {
                     $new[$pos] = array('value' => $val, 'name' => $optionNames[$pos]);
                 }
             }
             ksort($new);
Пример #9
0
function renderFormElement($field_type, $field_id, $default_text, $field_elements, $field_value, $field_style = '', $row = array())
{
    global $modx;
    global $base_url;
    global $rb_base_url;
    global $manager_theme;
    global $_lang;
    global $content;
    if (!isset($modx->config['imanager_url'])) {
        $modx->config['imanager_url'] = "{$base_url}manager/media/browser/mcpuk/browser.html?Type=images&Connector={$base_url}manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath={$base_url}";
    }
    if (!isset($modx->config['fmanager_url'])) {
        $modx->config['fmanager_url'] = "{$base_url}manager/media/browser/mcpuk/browser.html?Type=files&Connector={$base_url}manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath={$base_url}";
    }
    $field_html = '';
    $field_value = $field_value != "" ? $field_value : $default_text;
    switch (strtolower($field_type)) {
        case "text":
            // handler for regular text boxes
        // handler for regular text boxes
        case "rawtext":
            // non-htmlentity converted text boxes
        // non-htmlentity converted text boxes
        case "email":
            // handles email input fields
        // handles email input fields
        case "number":
            // handles the input of numbers
            if ($field_type == 'text') {
                $field_type = '';
            } elseif ($field_type == 'number') {
                $field_type .= ' imeoff';
            }
            $field_html .= '<input type="text" class="text ' . $field_type . '" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . htmlspecialchars($field_value) . '" ' . $field_style . ' tvtype="' . $field_type . '" />';
            break;
        case "textareamini":
            // handler for textarea mini boxes
            $field_type .= " phptextarea";
            $field_html .= '<textarea class="' . $field_type . '" id="tv' . $field_id . '" name="tv' . $field_id . '" cols="40" rows="5">' . htmlspecialchars($field_value) . '</textarea>';
            break;
        case "textarea":
            // handler for textarea boxes
        // handler for textarea boxes
        case "rawtextarea":
            // non-htmlentity convertex textarea boxes
        // non-htmlentity convertex textarea boxes
        case "htmlarea":
            // handler for textarea boxes (deprecated)
        // handler for textarea boxes (deprecated)
        case "richtext":
            // handler for textarea boxes
            $field_type .= " phptextarea";
            $field_html .= '<textarea class="' . $field_type . '" id="tv' . $field_id . '" name="tv' . $field_id . '" cols="40" rows="15">' . htmlspecialchars($field_value) . '</textarea>';
            break;
        case "date":
            $field_id = str_replace(array('-', '.'), '_', urldecode($field_id));
            if ($field_value == '') {
                $field_value = 0;
            }
            $field_html .= '<input id="tv' . $field_id . '" name="tv' . $field_id . '" class="DatePicker" type="text" value="' . ($field_value == 0 || !isset($field_value) ? "" : $field_value) . '" onblur="documentDirty=true;" />';
            $field_html .= ' <a onclick="document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].value=\'\';document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].onblur(); return true;" style="cursor:pointer; cursor:hand"><img src="media/style/' . $manager_theme . '/images/icons/cal_nodate.gif" border="0" alt="No date"></a>';
            $field_html .= '<script type="text/javascript">';
            $field_html .= '	window.addEvent(\'domready\', function() {';
            $field_html .= '   	new DatePicker($(\'tv' . $field_id . '\'), {\'yearOffset\' : ' . $modx->config['datepicker_offset'] . ", 'format' : " . "'" . $modx->config['datetime_format'] . ' hh:mm:00\'' . '});';
            $field_html .= '});';
            $field_html .= '</script>';
            break;
        case "dateonly":
            $field_id = str_replace(array('-', '.'), '_', urldecode($field_id));
            if ($field_value == '') {
                $field_value = 0;
            }
            $field_html .= '<input id="tv' . $field_id . '" name="tv' . $field_id . '" class="DatePicker" type="text" value="' . ($field_value == 0 || !isset($field_value) ? "" : $field_value) . '" onblur="documentDirty=true;" />';
            $field_html .= ' <a onclick="document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].value=\'\';document.forms[\'mutate\'].elements[\'tv' . $field_id . '\'].onblur(); return true;" style="cursor:pointer; cursor:hand"><img src="media/style/' . $manager_theme . '/images/icons/cal_nodate.gif" border="0" alt="No date"></a>';
            $field_html .= '<script type="text/javascript">';
            $field_html .= '	window.addEvent(\'domready\', function() {';
            $field_html .= '   	new DatePicker($(\'tv' . $field_id . '\'), {\'yearOffset\' : ' . $modx->config['datepicker_offset'] . ", 'format' : " . "'" . $modx->config['datetime_format'] . "'" . '});';
            $field_html .= '});';
            $field_html .= '</script>';
            break;
        case "dropdown":
            // handler for select boxes
            $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" size="1">';
            $rs = ProcessTVCommand($field_elements, $field_id, '', 'tvform');
            $index_list = ParseIntputOptions($rs);
            while (list($label, $item) = each($index_list)) {
                list($label, $value) = splitOption($item);
                $selected = $value == $field_value ? ' selected="selected"' : '';
                $field_html .= '<option value="' . htmlspecialchars($value) . '"' . $selected . '>' . htmlspecialchars($label) . '</option>';
            }
            $field_html .= "</select>";
            break;
        case "listbox":
            // handler for select boxes
            $rs = ProcessTVCommand($field_elements, $field_id, '', 'tvform');
            $index_list = ParseIntputOptions($rs);
            $count = count($index_list) < 8 ? count($index_list) : 8;
            $field_html .= '<select id="tv' . $field_id . '" name="tv' . $field_id . '" size="' . $count . '">';
            while (list($label, $item) = each($index_list)) {
                list($label, $value) = splitOption($item);
                $selected = isSelected($label, $value, $item, $field_value) ? ' selected="selected"' : '';
                $field_html .= '<option value="' . htmlspecialchars($value) . '"' . $selected . '>' . htmlspecialchars($label) . '</option>';
            }
            $field_html .= "</select>";
            break;
        case "listbox-multiple":
            // handler for select boxes where you can choose multiple items
            $rs = ProcessTVCommand($field_elements, $field_id, '', 'tvform');
            $index_list = ParseIntputOptions($rs);
            $count = count($index_list) < 8 ? count($index_list) : 8;
            $field_value = explode("||", $field_value);
            $field_html .= '<select id="tv' . $field_id . '[]" name="tv' . $field_id . '[]" multiple="multiple" size="' . $count . '">';
            while (list($label, $item) = each($index_list)) {
                list($label, $value) = splitOption($item);
                $selected = isSelected($label, $value, $item, $field_value) ? ' selected="selected"' : '';
                $field_html .= '<option value="' . htmlspecialchars($value) . '"' . $selected . '>' . htmlspecialchars($label) . '</option>';
            }
            $field_html .= "</select>";
            break;
        case "url":
            // handles url input fields
            $urls = array('' => '--', 'http://' => 'http://', 'https://' => 'https://', 'ftp://' => 'ftp://', 'mailto:' => 'mailto:');
            $field_html = '<table border="0" cellspacing="0" cellpadding="0"><tr><td><select id="tv' . $field_id . '_prefix" name="tv' . $field_id . '_prefix">';
            foreach ($urls as $k => $v) {
                if (strpos($field_value, $v) === false) {
                    $field_html .= '<option value="' . $v . '">' . $k . '</option>';
                } else {
                    $field_value = str_replace($v, '', $field_value);
                    $field_html .= '<option value="' . $v . '" selected="selected">' . $k . '</option>';
                }
            }
            $field_html .= '</select></td><td>';
            $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . htmlspecialchars($field_value) . '" width="100" ' . $field_style . ' /></td></tr></table>';
            break;
        case "checkbox":
            // handles check boxes
            if (!is_array($field_value)) {
                $field_value = explode('||', $field_value);
            }
            $rs = ProcessTVCommand($field_elements, $field_id, '', 'tvform');
            $index_list = ParseIntputOptions($rs);
            static $i = 0;
            foreach ($index_list as $item) {
                list($label, $value) = splitOption($item);
                $checked = isSelected($label, $value, $item, $field_value) ? ' checked="checked"' : '';
                $value = htmlspecialchars($value);
                $field_html .= '<label for="tv_' . $i . '"><input type="checkbox" value="' . $value . '" id="tv_' . $i . '" name="tv' . $field_id . '[]" ' . $checked . ' />' . $label . '</label>';
                $i++;
            }
            break;
        case "option":
            // handles radio buttons
            $rs = ProcessTVCommand($field_elements, $field_id, '', 'tvform');
            $index_list = ParseIntputOptions($rs);
            static $i = 0;
            while (list($label, $item) = each($index_list)) {
                list($label, $value) = splitOption($item);
                $checked = isSelected($label, $value, $item, $field_value) ? 'checked="checked"' : '';
                $value = htmlspecialchars($value);
                $field_html .= '<label for="tv_' . $i . '"><input type="radio" value="' . $value . '" id="tv_' . $i . '" name="tv' . $field_id . '" ' . $checked . ' />' . $label . '</label>';
                $i++;
            }
            break;
        case "image":
            // handles image fields using htmlarea image manager
            global $_lang;
            global $ResourceManagerLoaded;
            global $content, $use_editor, $which_editor;
            $url_convert = get_js_trim_path_pattern();
            if (!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $_GET['a'] == 4) && $use_editor == 1 && $which_editor == 3)) {
                $field_html .= tplFileBrowser();
                $ResourceManagerLoaded = true;
            }
            $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '"  value="' . $field_value . '" ' . $field_style . ' />&nbsp;<input type="button" value="' . $_lang['insert'] . '" onclick="BrowseServer(\'tv' . $field_id . '\')" />';
            break;
        case "file":
            // handles the input of file uploads
            /* Modified by Timon for use with resource browser */
            global $_lang;
            global $ResourceManagerLoaded;
            global $content, $use_editor, $which_editor;
            $url_convert = get_js_trim_path_pattern();
            if (!$ResourceManagerLoaded && !(($content['richtext'] == 1 || $_GET['a'] == 4) && $use_editor == 1 && $which_editor == 3)) {
                /* I didn't understand the meaning of the condition above, so I left it untouched ;-) */
                $field_html .= tplFileBrowser();
                $ResourceManagerLoaded = true;
            }
            $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '"  value="' . $field_value . '" ' . $field_style . ' />&nbsp;<input type="button" value="' . $_lang['insert'] . '" onclick="BrowseFileServer(\'tv' . $field_id . '\')" />';
            break;
        case "hidden":
            $field_type = 'hidden';
            $field_html .= '<input type="hidden" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . htmlspecialchars($field_value) . '" tvtype="' . $field_type . '" />';
            break;
        case 'custom_tv':
            $custom_output = '';
            /* If we are loading a file */
            if (substr($field_elements, 0, 5) == "@FILE") {
                $file_name = MODX_BASE_PATH . trim(substr($field_elements, 6));
                if (!file_exists($file_name)) {
                    $custom_output = $file_name . ' does not exist';
                } else {
                    $custom_output = file_get_contents($file_name);
                }
            } elseif (substr($field_elements, 0, 8) == '@INCLUDE') {
                $file_name = MODX_BASE_PATH . trim(substr($field_elements, 9));
                if (!file_exists($file_name)) {
                    $custom_output = $file_name . ' does not exist';
                } else {
                    ob_start();
                    include $file_name;
                    $custom_output = ob_get_contents();
                    ob_end_clean();
                }
            } elseif (substr($field_elements, 0, 6) == "@CHUNK") {
                $chunk_name = trim(substr($field_elements, 7));
                $chunk_body = $modx->getChunk($chunk_name);
                if ($chunk_body == false) {
                    $custom_output = $_lang['chunk_no_exist'] . '(' . $_lang['htmlsnippet_name'] . ':' . $chunk_name . ')';
                } else {
                    $custom_output = $chunk_body;
                }
            } elseif (substr($field_elements, 0, 5) == "@EVAL") {
                $eval_str = trim(substr($field_elements, 6));
                $custom_output = eval($eval_str);
            } else {
                $custom_output = $field_elements;
            }
            $replacements = array('[+field_type+]' => $field_type, '[+field_id+]' => $field_id, '[+default_text+]' => $default_text, '[+field_value+]' => htmlspecialchars($field_value), '[+field_style+]' => $field_style);
            $custom_output = str_replace(array_keys($replacements), $replacements, $custom_output);
            $modx->documentObject = $content;
            $custom_output = $modx->parseDocumentSource($custom_output);
            $field_html .= $custom_output;
            break;
        default:
            // the default handler -- for errors, mostly
            $sname = strtolower($field_type);
            $result = $modx->db->select('snippet', '[+prefix+]site_snippets', "name='input:{$field_type}'");
            if ($modx->db->getRecordCount($result) == 1) {
                $field_html .= eval($modx->db->getValue($result));
            } else {
                $field_html .= '<input type="text" id="tv' . $field_id . '" name="tv' . $field_id . '" value="' . htmlspecialchars($field_value) . '" ' . $field_style . ' />';
            }
    }
    // end switch statement
    return $field_html;
}
function ProcessTVCommand($value, $name = '', $docid = '', $src = 'docform')
{
    global $modx;
    $etomite =& $modx;
    $docid = intval($docid) ? intval($docid) : $modx->documentIdentifier;
    $nvalue = trim($value);
    if (substr($nvalue, 0, 1) != '@') {
        return $value;
    } elseif ($modx->config['enable_bindings'] != 1 && $src === 'docform') {
        return '@Bindings is disabled.';
    } else {
        list($cmd, $param) = ParseCommand($nvalue);
        $cmd = trim($cmd);
        $param = trim($param);
        switch ($cmd) {
            case "FILE":
                $output = ProcessFile(trim($param));
                $output = str_replace('@FILE ' . $param, $output, $nvalue);
                break;
            case "CHUNK":
                // retrieve a chunk and process it's content
                $chunk = $modx->getChunk($param);
                $output = $chunk;
                break;
            case "DOCUMENT":
                // retrieve a document and process it's content
                $rs = $modx->getDocument($param);
                if (is_array($rs)) {
                    $output = $rs['content'];
                } else {
                    $output = "Unable to locate document {$param}";
                }
                break;
            case "SELECT":
                // selects a record from the cms database
                $rt = array();
                $replacementVars = array('dbase' => $modx->db->config['dbase'], 'DBASE' => $modx->db->config['dbase'], 'prefix' => $modx->db->config['table_prefix'], 'PREFIX' => $modx->db->config['table_prefix']);
                foreach ($replacementVars as $rvKey => $rvValue) {
                    $modx->setPlaceholder($rvKey, $rvValue);
                }
                $param = $modx->mergePlaceholderContent($param);
                $rs = $modx->db->query("SELECT {$param}");
                $output = $rs;
                break;
            case "EVAL":
                // evaluates text as php codes return the results
                $output = eval($param);
                break;
            case "INHERIT":
                $output = $param;
                // Default to param value if no content from parents
                if (empty($docid) && isset($_REQUEST['pid'])) {
                    $doc['parent'] = $_REQUEST['pid'];
                } else {
                    $doc = $modx->getPageInfo($docid, 0, 'id,parent');
                }
                while ($doc['parent'] != 0) {
                    $parent_id = $doc['parent'];
                    // Grab document regardless of publish status
                    $doc = $modx->getPageInfo($parent_id, 0, 'id,parent');
                    $tv = $modx->getTemplateVar($name, '*', $doc['id'], null);
                    // inheritance allows other @ bindings to be inherited
                    // if no value is inherited and there is content following the @INHERIT binding,
                    // that content will be used as the output
                    // @todo consider reimplementing *appending* the output the follows an @INHERIT as opposed
                    //       to using it as a default/fallback value; perhaps allow choice in behavior with
                    //       system setting
                    if ((string) $tv['value'] !== '' && !preg_match('%^@INHERIT[\\s\\n\\r]*$%im', $tv['value'])) {
                        $output = (string) $tv['value'];
                        //$output = str_replace('@INHERIT', $output, $nvalue);
                        break 2;
                    }
                }
                break;
            case 'DIRECTORY':
                $files = array();
                $path = $modx->config['base_path'] . $param;
                if (substr($path, -1, 1) != '/') {
                    $path .= '/';
                }
                if (!is_dir($path)) {
                    die($path);
                    break;
                }
                $dir = dir($path);
                while (($file = $dir->read()) !== false) {
                    if (substr($file, 0, 1) != '.') {
                        $files[] = "{$file}=={$param}{$file}";
                    }
                }
                asort($files);
                $output = implode('||', $files);
                break;
            case 'NULL':
            case 'NONE':
                $output = '';
                break;
            default:
                $output = $value;
                break;
        }
        // support for nested bindings
        return is_string($output) && $output != $value ? ProcessTVCommand($output, $name, $docid, $src) : $output;
    }
}