/**
 * mm_changeFieldHelp
 * @version 1.1.1 (2013-05-20)
 *
 * Change the help text of a field.
 * 
 * @uses ManagerManager plugin 0.5.
 * 
 * @param $field {string} - The name of the document field (or TV) this should apply to. @required
 * @param $helptext {string} - The new help text. @required
 * @param $roles {comma separated string} - The roles that the widget is applied to (when this parameter is empty then widget is applied to the all roles). Default: ''.
 * @param $templates {comma separated string} - Id of the templates to which this widget is applied (when this parameter is empty then widget is applied to the all templates). Default: ''.
 * 
 * @link http://code.divandesign.biz/modx/mm_changefieldhelp/1.1.1
 * 
 * @copyright 2013
 */
function mm_changeFieldHelp($field, $helptext = '', $roles = '', $templates = '')
{
    global $mm_fields, $modx;
    $e =& $modx->Event;
    if ($helptext == '') {
        return;
    }
    // if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        $output = "//  -------------- mm_changeFieldHelp :: Begin ------------- \n";
        // What type is this field?
        if (isset($mm_fields[$field])) {
            $fieldtype = $mm_fields[$field]['fieldtype'];
            $fieldname = $mm_fields[$field]['fieldname'];
            //Is this TV?
            if ($mm_fields[$field]['tv']) {
                $output .= '$j("' . $fieldtype . '[name=' . $fieldname . ']").parents("td:first").prev("td").children("span.comment").html("' . jsSafe($helptext) . '");';
                //Or document field
            } else {
                // Give the help button an ID, and modify the alt/title text
                $output .= '$j("' . $fieldtype . '[name=' . $fieldname . ']").siblings("img[style*=\'cursor:help\']").attr("id", "' . $fieldname . '-help").attr("alt", "' . jsSafe($helptext) . '").attr("title", "' . jsSafe($helptext) . '"); ';
            }
        }
        $output .= "//  -------------- mm_changeFieldHelp :: End ------------- \n";
        $e->output($output . "\n");
    }
}
示例#2
0
function mm_renameSection($section, $newname, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    // if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
    if (useThisRule($roles, $templates)) {
        $output = " // ----------- Rename section -------------- \n";
        switch ($section) {
            case 'content':
                $output .= '$j("div#content_header").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
            case 'tvs':
                $output .= '
						$j("div#tv_header").empty().prepend("' . jsSafe($newname) . '");	
					';
                break;
            case 'access':
                // These have moved to tabs in 1.0.1
                $output .= '$j("div#sectionAccessHeader").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
        }
        // end switch
        $e->output($output . "\n");
    }
    // end if
}
示例#3
0
/**
 * mm_renameTab
 * @version 1.1 (2012-11-13)
 * 
 * Rename a tab.
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @link http://code.divandesign.biz/modx/mm_renametab/1.1
 * 
 * @copyright 2012
 */
function mm_renameTab($tab, $newname, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->event;
    // if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        $output = "//  -------------- mm_renameTab :: Begin ------------- \n";
        switch ($tab) {
            case 'general':
                $output .= '$j("div#documentPane h2:nth-child(1) span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
            case 'settings':
                $output .= '$j("div#documentPane h2:nth-child(2) span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
                // This is =<1.0.0 only
            // This is =<1.0.0 only
            case 'meta':
                if ($modx->hasPermission('edit_doc_metatags') && $modx->config['show_meta'] != "0") {
                    $output .= '$j("div#documentPane h2:nth-child(3) span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                }
                break;
                // This is 1.0.1 specific
            // This is 1.0.1 specific
            case 'access':
                $access_index = $modx->config['show_meta'] == "0" ? 3 : 4;
                $output .= '$j("div#documentPane h2:nth-child(' . $access_index . ') span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
        }
        $output .= "//  -------------- mm_renameTab :: End ------------- \n";
        $e->output($output . "\n");
    }
}
示例#4
0
function mm_renameTab($tab, $newname, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    // if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
    if (useThisRule($roles, $templates)) {
        $output = " // ----------- Rename tab -------------- \n";
        switch ($tab) {
            case 'general':
                $output .= '$j("div#documentPane h2:nth-child(1) span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
            case 'settings':
                $output .= '$j("div#documentPane h2:nth-child(2) span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
                // This is 1.0.0 only
            // This is 1.0.0 only
            case 'meta':
                if ($modx->hasPermission('edit_doc_metatags')) {
                    $output .= '$j("div#documentPane h2:nth-child(3) span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                }
                break;
                // This is 1.0.1 specific
            // This is 1.0.1 specific
            case 'access':
                $output .= '$j("div#documentPane h2:nth-child(3) span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
        }
        // end switch
        $e->output($output . "\n");
    }
    // end if
}
示例#5
0
/**
 * mm_renameField
 * @version 1.2 (2013-05-16)
 *
 * Change the label for an element.
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @param fields {comma separated string} - The name(s) of the document fields (or TVs) this should apply to. @required
 * @param newlabel {string} - The new text for the label. @required
 * @param roles {comma separated string} - The roles that the widget is applied to (when this parameter is empty then widget is applied to the all roles).
 * @param templates {comma separated string} - Id of the templates to which this widget is applied (when this parameter is empty then widget is applied to the all templates).
 * @param newhelp {string} - New text for the help icon with this field or for comment with TV. The same restriction apply as when using mm_changeFieldHelp directly.
 * 
 * @link http://code.divandesign.biz/modx/mm_renamefield/1.2
 * 
 * @copyright 2013
 */
function mm_renameField($fields, $newlabel, $roles = '', $templates = '', $newhelp = '')
{
    global $mm_fields, $modx;
    $e =& $modx->Event;
    // if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        $fields = makeArray($fields);
        if (count($fields) == 0) {
            return;
        }
        $output = "//  -------------- mm_renameField :: Begin ------------- \n";
        foreach ($fields as $field) {
            $element = '';
            switch ($field) {
                // Exceptions
                case 'keywords':
                    $element = '$j("select[name*=keywords]").siblings("span.warning")';
                    break;
                case 'metatags':
                    $element = '$j("select[name*=metatags]").siblings("span.warning")';
                    break;
                case 'hidemenu':
                case 'show_in_menu':
                    $element = '$j("input[name=\'hidemenucheck\']").siblings("span.warning")';
                    break;
                case 'which_editor':
                    $element = '$j("#which_editor").prev("span.warning")';
                    break;
                case 'content':
                    $element = '$j("#content_header")';
                    break;
                case 'menuindex':
                    $element = '$j("input[name=\'menuindex\']").parents("table:first").parents("td:first").prev("td").find("span.warning")';
                    break;
                    // Ones that follow the regular pattern
                // Ones that follow the regular pattern
                default:
                    if (isset($mm_fields[$field])) {
                        $fieldtype = $mm_fields[$field]['fieldtype'];
                        $fieldname = $mm_fields[$field]['fieldname'];
                        $element = '$j("' . $fieldtype . '[name=\'' . $fieldname . '\']").parents("td:first").prev("td").children("span.warning")';
                    }
                    break;
            }
            if ($element != '') {
                $output .= $element . '.contents().filter(function(){return this.nodeType === 3;}).replaceWith("' . jsSafe($newlabel) . '");';
            }
            // If new help has been supplied, do that too
            if ($newhelp != '') {
                mm_changeFieldHelp($field, $newhelp, $roles, $templates);
            }
        }
        $output .= "//  -------------- mm_renameField :: End ------------- \n";
        $e->output($output . "\n");
    }
}
示例#6
0
/**
 * mm_renameField
 * @version 1.1 (2012-11-13)
 *
 * Change the label for an element.
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @link http://code.divandesign.biz/modx/mm_renamefield/1.1
 * 
 * @copyright 2012
 */
function mm_renameField($field, $newlabel, $roles = '', $templates = '', $newhelp = '')
{
    global $mm_fields, $modx;
    $e =& $modx->event;
    // if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        $output = "//  -------------- mm_renameField :: Begin ------------- \n";
        switch ($field) {
            // Exceptions
            case 'keywords':
                $output .= '$j("select[name*=keywords]").siblings("span.warning").html("' . jsSafe($newlabel) . '");';
                break;
            case 'metatags':
                $output .= '$j("select[name*=metatags]").siblings("span.warning").html("' . jsSafe($newlabel) . '");';
                break;
            case 'hidemenu':
            case 'show_in_menu':
                $output .= '$j("input[name=hidemenucheck]").siblings("span.warning").html("' . jsSafe($newlabel) . '");';
                break;
            case 'which_editor':
                $output .= '$j("#which_editor").prev("span.warning").html("' . jsSafe($newlabel) . '");';
                break;
            case 'content':
                $output .= '$j("#content_header").html("' . jsSafe($newlabel) . '")';
                break;
            case 'menuindex':
                $output .= '$j("input[name=menuindex]").parents().parents("td:first").prev("td").children("span.warning").empty().prepend("' . jsSafe($newlabel) . '");';
                break;
                // Ones that follow the regular pattern
            // Ones that follow the regular pattern
            default:
                if (isset($mm_fields[$field])) {
                    $fieldtype = $mm_fields[$field]['fieldtype'];
                    $fieldname = $mm_fields[$field]['fieldname'];
                    $output .= '$j("' . $fieldtype . '[name=' . $fieldname . ']").parents("td:first").prev("td").children("span.warning").empty().prepend("' . jsSafe($newlabel) . '");';
                }
                break;
        }
        $output .= "//  -------------- mm_renameField :: End ------------- \n";
        $e->output($output . "\n");
        // If new help has been supplied, do that too
        if ($newhelp != '') {
            mm_changeFieldHelp($field, $newhelp, $roles, $templates);
        }
    }
}
/**
 * mm_renameSection
 * @version 1.2.1 (2014-05-26)
 * 
 * @desc A widget for ManagerManager plugin that allows sections to be renamed.
 * 
 * @uses ManagerManager plugin 0.6.2.
 * 
 * @param $section {string; 'content'; 'tvs'} - The name of the section this should apply to. @required
 * @param $newname {string} - The new text for the label. @required
 * @param $roles {comma separated string} - The roles that the widget is applied to (when this parameter is empty then widget is applied to the all roles). Default: ''.
 * @param $templates {comma separated string} - Id of the templates to which this widget is applied (when this parameter is empty then widget is applied to the all templates). Default: ''.
 * 
 * @event OnDocFormRender
 * 
 * @link http://code.divandesign.biz/modx/mm_renamesection/1.2.1
 * 
 * @copyright 2014
 */
function mm_renameSection($section, $newname, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    // if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        $output = "//---------- mm_renameSection :: Begin -----\n";
        switch ($section) {
            case 'access':
                // These have moved to tabs in 1.0.1
                $output .= '$j("div#sectionAccessHeader").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
            default:
                $output .= '$j("#' . prepareSectionId($section) . '_header").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
        }
        $output .= "//---------- mm_renameSection :: End -----\n";
        $e->output($output);
    }
}
示例#8
0
function mm_renameTab($tab, $newname, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    // if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
    if (useThisRule($roles, $templates)) {
        $output = " // ----------- Rename tab -------------- \n";
        switch ($tab) {
            case 'general':
                $output .= '$j("div#documentPane h2:nth-child(1) span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
            case 'settings':
                $output .= '$j("div#documentPane h2:nth-child(2) span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
                // This is =<1.0.0 only
            // This is =<1.0.0 only
            case 'meta':
                if ($modx->hasPermission('edit_doc_metatags') && $modx->config['show_meta'] != "0") {
                    $output .= '$j("div#documentPane h2:nth-child(3) span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                }
                break;
                // This is 1.0.1 specific
            // This is 1.0.1 specific
            case 'access':
                $access_index = $modx->config['show_meta'] == "0" ? 3 : 4;
                $output .= '$j("div#documentPane h2:nth-child(' . $access_index . ') span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
                // for installations that have tv_categorized_tabs plugin installed ni system
            // for installations that have tv_categorized_tabs plugin installed ni system
            case 'tvs':
                $output .= '$j("div#documentPane h2#tabTV-header span").empty().prepend("' . jsSafe($newname) . '");' . "\n";
                break;
        }
        // end switch
        $e->output($output . "\n");
    }
    // end if
}
示例#9
0
     $tvs_table .= '<tr>';
     $tvs_table .= '<td class="' . $class . '">' . jsSafe($tv['name']) . '</td>';
     $tvs_table .= '<td class="' . $class . '">' . jsSafe($tv['caption']) . '</td>';
     $tvs_table .= '<td class="' . $class . '">' . $tv['id'] . '</td>';
     $tvs_table .= '</tr>';
 }
 $tvs_table .= '</table>';
 // Get all roles
 $result = $modx->db->select("name, id", $modx->db->config['table_prefix'] . "user_roles", '', 'name ASC');
 $all_roles = $modx->db->makeArray($result);
 $roles_table = '<table>';
 $roles_table .= '<tr><th class="gridHeader">Role name</th><th class="gridHeader">ID</th></tr>';
 foreach ($all_roles as $count => $role) {
     $class = $count % 2 ? 'gridItem' : 'gridAltItem';
     $roles_table .= '<tr>';
     $roles_table .= '<td class="' . $class . '">' . jsSafe($role['name']) . '</td>';
     $roles_table .= '<td class="' . $class . '">' . $role['id'] . '</td>';
     $roles_table .= '</tr>';
 }
 $roles_table .= '</table>';
 // Load the jquery library
 $output = '<!-- Begin ManagerManager output -->' . "\n";
 $output .= includeJs($js_url, 'html');
 $output .= '<script type="text/javascript">' . "\n";
 $output .= "var \$j = jQuery.noConflict(); \n";
 //produces var  $j = jQuery.noConflict();
 $output .= "mm_lastTab = 'tabEvents'; \n";
 $e->output($output);
 mm_createTab('Templates, TVs &amp; Roles', 'rolestemplates', '', '', '<p>These are the IDs for current templates,tvs and roles in your site.</p>' . $template_table . '&nbsp;' . $tvs_table . '&nbsp;' . $roles_table);
 $e->output('</script>');
 $e->output('<!-- End ManagerManager output -->' . "\n");
示例#10
0
/** 
 * ddSetFieldValue
 * @version 1.1 (2014-03-27)
 * 
 * Widget for ManagerManager plugin allowing ducument fields values (or TV fields values) to be strongly defined (reminds of mm_default but field value assignment is permanent).
 * 
 * @uses ManagerManager plugin 0.6.1.
 * 
 * @param $fields {comma separated string} - The name(s) of the document fields (or TVs) for which value setting is required. @required
 * @param $value {string} - Required value. Default: ''.
 * @param $roles {comma separated string} - The roles that the widget is applied to (when this parameter is empty then widget is applied to the all roles). Default: ''.
 * @param $templates {comma separated string} - Id of the templates to which this widget is applied. Default: ''.
 * 
 * @link http://code.divandesign.biz/modx/mm_ddsetfieldvalue/1.1
 * 
 * @copyright 2014, DivanDesign
 * http://www.DivanDesign.biz
 */
function mm_ddSetFieldValue($fields, $value = '', $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        global $mm_current_page, $mm_fields;
        $output = "//---------- mm_ddSetFieldValue :: Begin -----\n";
        //Подбираем правильный формат даты в соответствии с конфигурацией
        switch ($modx->config['datetime_format']) {
            case 'dd-mm-YYYY':
                $date_format = 'd-m-Y';
                break;
            case 'mm/dd/YYYY':
                $date_format = 'm/d/Y';
                break;
            case 'YYYY/mm/dd':
                $date_format = 'Y/m/d';
                break;
        }
        $fields = getTplMatchedFields($fields);
        if ($fields == false) {
            return;
        }
        foreach ($fields as $field) {
            //Результирующее значение для выставления через $.fn.val
            $setValue = $value;
            //Значение для чекбоксов
            $checkValue = (bool) $value;
            //Селектор для выставления через $.fn.val
            $setSelector = $mm_fields[$field]['fieldtype'] . '[name=\'' . $mm_fields[$field]['fieldname'] . '\']';
            //Селектор для чекбоксов
            $checkSelector = false;
            //Некоторые поля документа требуют дополнительной обработки
            switch ($field) {
                //Дата публикации
                case 'pub_date':
                    //Дата отмены публикации
                //Дата отмены публикации
                case 'unpub_date':
                    $setValue = $setValue == '' ? jsSafe(date("{$date_format} H:i:s")) : jsSafe($setValue);
                    break;
                    //Аттрибуты ссылки
                //Аттрибуты ссылки
                case 'link_attributes':
                    //Обработаем кавычки
                    $setValue = str_replace(array("'", '"'), '\\"', $setValue);
                    break;
                    //Признак папки
                //Признак папки
                case 'is_folder':
                    $checkSelector = $setSelector;
                    $setSelector = false;
                    break;
                    //Чекбоксы с прямой логикой
                    //Признак публикации
                //Чекбоксы с прямой логикой
                //Признак публикации
                case 'published':
                    //Признак доступности для поиска
                //Признак доступности для поиска
                case 'searchable':
                    //Признак кэширования
                //Признак кэширования
                case 'cacheable':
                    //Признак очистки кэша
                //Признак очистки кэша
                case 'clear_cache':
                    //Участвует в URL
                //Участвует в URL
                case 'alias_visible':
                    //Если не 1, значит 0, другого не быть не может
                    if ($setValue != '1') {
                        $setValue = '0';
                    }
                    $checkSelector = $setSelector;
                    //Не очень красиво if внутри case, ровно так же, как и 'clear_cache' == 'syncsite', что поделать
                    if ($field == 'clear_cache') {
                        $setSelector = 'input[name=\'syncsite\']';
                    } else {
                        $setSelector = 'input[name=\'' . $field . '\']';
                    }
                    break;
                    //Признак отображения в меню
                //Признак отображения в меню
                case 'show_in_menu':
                    // Note these are reversed from what you'd think
                    $setValue = $setValue == '1' ? '0' : '1';
                    $checkSelector = $setSelector;
                    $setSelector = 'input[name=\'hidemenu\']';
                    break;
                    //Признак скрытия из меню (аналогично show_in_menu, только наоборот)
                //Признак скрытия из меню (аналогично show_in_menu, только наоборот)
                case 'hide_menu':
                    if ($setValue != '0') {
                        $setValue = '1';
                    }
                    $checkValue = !$checkValue;
                    $checkSelector = $setSelector;
                    $setSelector = 'input[name=\'hidemenu\']';
                    break;
                    //Признак использованшия визуального редактора
                //Признак использованшия визуального редактора
                case 'is_richtext':
                    $output .= 'var originalRichtextValue = $j("#which_editor:first").val();' . "\n";
                    if ($setValue != '1') {
                        $setValue = '0';
                        $output .= '
							// Make the RTE displayed match the default value that has been set here
							if (originalRichtextValue != "none"){
								$j("#which_editor").val("none");
								changeRTE();
							}
						';
                        $output .= "\n";
                    }
                    $checkSelector = $setSelector;
                    $setSelector = 'input[name=\'richtext\']';
                    break;
                    //Признак логирования
                //Признак логирования
                case 'log':
                    //Note these are reversed from what you'd think
                    $setValue = $setValue == '1' ? '0' : '1';
                    $checkValue = !$checkValue;
                    $checkSelector = $setSelector;
                    $setSelector = 'input[name=\'donthit\']';
                    break;
            }
            //Если это чекбокс
            if ($checkSelector !== false) {
                if ($checkValue) {
                    $output .= '$j("' . $checkSelector . '").attr("checked", "checked");' . "\n";
                } else {
                    $output .= '$j("' . $checkSelector . '").removeAttr("checked");' . "\n";
                }
            }
            //Если нужно задавать значение
            if ($setSelector !== false) {
                $output .= '$j("' . $setSelector . '").val("' . $setValue . '");' . "\n";
            }
        }
        $output .= "//---------- mm_ddSetFieldValue :: End -----\n";
        $e->output($output);
    }
}
function mm_inherit($fields, $roles = '', $templates = '')
{
    global $mm_fields, $modx;
    $e =& $modx->Event;
    // if we've been supplied with a string, convert it into an array
    $fields = makeArray($fields);
    // if we aren't creating a new document or folder, we don't want to do this
    if (!($modx->manager->action == "85" || $modx->manager->action == "4")) {
        return;
    }
    // Are we using this rule?
    if (useThisRule($roles, $templates)) {
        // Get the parent info
        if (isset($_REQUEST['pid']) && is_numeric($_REQUEST['pid'])) {
            $parentID = intval($_REQUEST['pid']);
        } else {
            if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) {
                $parentID = intval($_REQUEST['parent']);
            } else {
                $parentID = 0;
            }
        }
        $output = " // ----------- Inherit (from page {$parentID})-------------- \n";
        foreach ($fields as $field) {
            // get some info about the field we are being asked to use
            if (isset($mm_fields[$field]['dbname'])) {
                $fieldtype = $mm_fields[$field]['fieldtype'];
                $fieldname = $mm_fields[$field]['fieldname'];
                $dbname = $mm_fields[$field]['dbname'];
                // Get this field data from the parent
                $newArray = $modx->getDocument($parentID, $dbname);
                if (empty($newArray)) {
                    // If no results, check if there is an unpublished doc
                    $newArray = $modx->getDocument($parentID, $dbname, 0);
                }
                $newvalue = $newArray[$dbname];
            } else {
                break;
                // If it's not something stored in the database, don't get the value
            }
            $output .= "// fieldtype {$fieldtype}\t\t\n\t\t\t// fieldname {$fieldname}\t\t\t\n\t\t\t// dbname {$dbname}\t\t\t\n\t\t\t// newvalue {$newvalue} \t\n\t\t\t\t";
            switch ($field) {
                case 'log':
                case 'hide_menu':
                case 'show_in_menu':
                    $output .= '$j("input[name=' . $fieldname . ']").attr("checked", "' . ($newvalue ? '' : 'checked') . '"); ';
                    break;
                case 'is_folder':
                case 'is_richtext':
                case 'searchable':
                case 'cacheable':
                case 'published':
                    $output .= '$j("input[name=' . $fieldname . ']").attr("checked", "' . ($newvalue ? 'checked' : '') . '"); ';
                    break;
                case 'pub_date':
                case 'unpub_date':
                    $output .= '$j("input[name=' . $fieldname . ']").val("' . date('d-m-Y H:i:s', $newvalue) . '"); ';
                    break;
                default:
                    switch ($fieldtype) {
                        case 'textarea':
                            $output .= '$j("textarea[name=' . $fieldname . ']").html("' . jsSafe($newvalue) . '"); ';
                            break;
                        default:
                            $output .= '$j("' . $fieldtype . '[name=' . $fieldname . ']").val("' . jsSafe($newvalue) . '"); ';
                            break;
                    }
                    break;
            }
        }
        $e->output($output . "\n");
    }
}
示例#12
0
function mm_widget_tags($fields, $delimiter = ',', $source = '', $display_count = false, $roles = '', $templates = '')
{
    global $modx, $content, $mm_fields;
    $e =& $modx->Event;
    if (useThisRule($roles, $templates)) {
        $output = '';
        // if we've been supplied with a string, convert it into an array
        $fields = makeArray($fields);
        // And likewise for the data source (if supplied)
        $source = empty($source) ? $fields : makeArray($source);
        // Which template is this page using?
        if (isset($content['template'])) {
            $page_template = $content['template'];
        } else {
            // If no content is set, it's likely we're adding a new page at top level.
            // So use the site default template. This may need some work as it might interfere with a default template set by MM?
            $page_template = $modx->config['default_template'];
        }
        // Does this page's template use any of these TVs? If not, quit.
        $field_tvs = tplUseTvs($page_template, $fields);
        if ($field_tvs == false) {
            return;
        }
        $source_tvs = tplUseTvs($page_template, $source);
        if ($source_tvs == false) {
            return;
        }
        // Insert some JS  and a style sheet into the head
        $output .= "//  -------------- Tag widget include ------------- \n";
        $output .= includeJs($modx->config['base_url'] . 'assets/plugins/managermanager/widgets/tags/tags.js');
        $output .= includeCss($modx->config['base_url'] . 'assets/plugins/managermanager/widgets/tags/tags.css');
        // Go through each of the fields supplied
        foreach ($fields as $targetTv) {
            $tv_id = $mm_fields[$targetTv]['fieldname'];
            // Make an SQL friendly list of fields to look at:
            //$escaped_sources = array();
            //foreach ($source as $s) {
            //$s=substr($s,2,1);
            //	$escaped_sources[] = "'".$s."'";
            //}
            $sql_sources = implode(',', $source_tvs[0]);
            // Get the list of current values for this TV
            $sql = "SELECT `value` FROM " . $modx->getFullTableName('site_tmplvar_contentvalues') . " WHERE tmplvarid IN (" . $sql_sources . ")";
            $result = $modx->dbQuery($sql);
            $all_docs = $modx->db->makeArray($result);
            $foundTags = array();
            foreach ($all_docs as $theDoc) {
                $theTags = explode($delimiter, $theDoc['value']);
                foreach ($theTags as $t) {
                    $foundTags[trim($t)]++;
                }
            }
            // Sort the TV values (case insensitively)
            uksort($foundTags, 'strcasecmp');
            $lis = '';
            foreach ($foundTags as $t => $c) {
                $lis .= '<li title="Used ' . $c . ' times">' . jsSafe($t) . ($display_count ? ' (' . $c . ')' : '') . '</li>';
            }
            $html_list = '<ul class="mmTagList" id="' . $tv_id . '_tagList">' . $lis . '</ul>';
            // Insert the list of tags after the field
            $output .= '
				//  -------------- Tag widget for ' . $targetTv . ' (' . $tv_id . ') --------------
				$j("#' . $tv_id . '").after(\'' . $html_list . '\');
				';
            // Initiate the tagCompleter class for this field
            $output .= 'var ' . $tv_id . '_tags = new TagCompleter("' . $tv_id . '", "' . $tv_id . '_tagList", "' . $delimiter . '"); ';
        }
    }
    $e->output($output . "\n");
}
示例#13
0
function mm_changeFieldHelp($field, $helptext = '', $roles = '', $templates = '')
{
    global $mm_fields, $modx;
    $e =& $modx->Event;
    if ($helptext == '') {
        return;
    }
    // if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
    if (useThisRule($roles, $templates)) {
        $output = " // ----------- Change field help -------------- \n";
        switch ($field) {
            // Ones that follow the regular pattern
            default:
                // What type is this field?
                if (isset($mm_fields[$field])) {
                    $fieldtype = $mm_fields[$field]['fieldtype'];
                    $fieldname = $mm_fields[$field]['fieldname'];
                    // Give the help button an ID, and modify the alt/title text
                    $output .= '$j("' . $fieldtype . '[name=' . $fieldname . ']").siblings("img[style:contains(\'cursor:help\')]").attr("id", "' . $fieldname . '-help").attr("alt", "' . jsSafe($helptext) . '").attr("title", "' . jsSafe($helptext) . '"); ';
                } else {
                    break;
                }
                break;
        }
        // end switch
        $e->output($output . "\n");
    }
    // end if
}
示例#14
0
/**
 * mm_widget_tags
 * @version 1.1.2 (2013-12-11)
 * 
 * Adds a tag selection widget to the specified TVs.
 * 
 * @uses ManagerManager plugin 0.6.
 * 
 * @param $fields {comma separated string} - The name(s) of the template variables this should apply to. @required
 * @param $delimiter {string} - The sign that separates tags in the field. Default: ','.
 * @param $source {comma separated string} - The names(s) of the template variables the list of tags should come from. This allows the list of tags to come from a different field than the widget. By default it uses all the TVs listed in “fields” parameter. Default: =$fields.
 * @param $display_count {boolean} - Display the number of documents using each tag (in brackets after it). Default: false.
 * @param $roles {comma separated string} - The roles that the widget is applied to (when this parameter is empty then widget is applied to the all roles). Default: ''.
 * @param $templates {comma separated string} - The templates that the widget is applied to (when this parameter is empty then widget is applied to the all templates). Default: ''.
 * 
 * @event OnDocFormPrerender
 * @event OnDocFormRender
 * 
 * @link http://code.divandesign.biz/modx/mm_widget_tags/1.1.2
 * 
 * @copyright 2013
 */
function mm_widget_tags($fields, $delimiter = ',', $source = '', $display_count = false, $roles = '', $templates = '')
{
    if (!useThisRule($roles, $templates)) {
        return;
    }
    global $modx;
    $e =& $modx->Event;
    $output = '';
    if ($e->name == 'OnDocFormPrerender') {
        $output .= includeJsCss($modx->config['base_url'] . 'assets/plugins/managermanager/widgets/tags/tags.js', 'html', 'mm_widget_tags', '1.0');
        $output .= includeJsCss($modx->config['base_url'] . 'assets/plugins/managermanager/widgets/tags/tags.css', 'html');
        $e->output($output);
    } else {
        if ($e->name == 'OnDocFormRender') {
            global $mm_current_page, $mm_fields;
            // if we've been supplied with a string, convert it into an array
            $fields = makeArray($fields);
            // And likewise for the data source (if supplied)
            $source = empty($source) ? $fields : makeArray($source);
            // Does this page's template use any of these TVs? If not, quit.
            $field_tvs = tplUseTvs($mm_current_page['template'], $fields);
            if ($field_tvs == false) {
                return;
            }
            $source_tvs = tplUseTvs($mm_current_page['template'], $source);
            if ($source_tvs == false) {
                return;
            }
            $output .= "//---------- mm_widget_tags :: Begin -----\n";
            // Go through each of the fields supplied
            foreach ($fields as $targetTv) {
                $tv_id = $mm_fields[$targetTv]['fieldname'];
                // Make an SQL friendly list of fields to look at:
                //$escaped_sources = array();
                //foreach ($source as $s){
                //	$s=substr($s,2,1);
                //	$escaped_sources[] = "'".$s."'";
                //}
                $sql_sources = implode(',', $source_tvs[0]);
                // Get the list of current values for this TV
                $sql = 'SELECT `value` FROM ' . $modx->getFullTableName('site_tmplvar_contentvalues') . ' WHERE tmplvarid IN (' . $sql_sources . ')';
                $result = $modx->db->query($sql);
                $all_docs = $modx->db->makeArray($result);
                $foundTags = array();
                foreach ($all_docs as $theDoc) {
                    $theTags = explode($delimiter, $theDoc['value']);
                    foreach ($theTags as $t) {
                        $foundTags[trim($t)]++;
                    }
                }
                // Sort the TV values (case insensitively)
                uksort($foundTags, 'strcasecmp');
                $lis = '';
                foreach ($foundTags as $t => $c) {
                    $lis .= '<li title="Used ' . $c . ' times">' . jsSafe($t) . ($display_count ? ' (' . $c . ')' : '') . '</li>';
                }
                $html_list = '<ul class="mmTagList" id="' . $tv_id . '_tagList">' . $lis . '</ul>';
                // Insert the list of tags after the field
                $output .= '
//mm_widget_tags for “' . $targetTv . '” (' . $tv_id . ')
$j("#' . $tv_id . '").after(\'' . $html_list . '\');
';
                // Initiate the tagCompleter class for this field
                $output .= 'var ' . $tv_id . '_tags = new TagCompleter("' . $tv_id . '", "' . $tv_id . '_tagList", "' . $delimiter . '");' . "\n";
            }
            $output .= "//---------- mm_widget_tags :: End -----\n";
            $e->output($output);
        }
    }
}
示例#15
0
/**
 * mm_default
 * @version 1.1 (2012-11-13)
 * 
 * Sets a default value for a field when creating a new document.
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @link http://code.divandesign.biz/modx/mm_default/1.1
 * 
 * @copyright 2012
 */
function mm_default($field, $value = '', $roles = '', $templates = '', $eval = false)
{
    global $mm_fields, $modx;
    $e =& $modx->event;
    // if we aren't creating a new document or folder, we don't want to do this
    // Which action IDs so we want to do this for?
    // 85 =
    // 4  =
    // 72 = Create new weblink
    $allowed_actions = array('85', '4', '72');
    if (!in_array($modx->manager->action, $allowed_actions)) {
        return;
    }
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        // What's the new value, and does it include PHP?
        $new_value = $eval ? eval($value) : $value;
        $output = "//  -------------- mm_default :: Begin ------------- \n";
        // Work out the correct date time format based on the config setting
        $date_format = $modx->toDateFormat(null, 'formatOnly');
        switch ($field) {
            case 'pub_date':
                $new_value = $new_value == '' ? strftime($date_format . ' %H:%M:%S') : $new_value;
                $output .= '$j("input[name=pub_date]").val("' . jsSafe($new_value) . '"); ' . "\n";
                break;
            case 'unpub_date':
                $new_value = $new_value == '' ? strftime($date_format . ' %H:%M:%S') : $new_value;
                $output .= '$j("input[name=unpub_date]").val("' . jsSafe($new_value) . '"); ' . "\n";
                break;
            case 'published':
                $new_value = $value ? '1' : '0';
                $output .= '$j("input[name=published]").val("' . $new_value . '"); ' . "\n";
                if ($value) {
                    $output .= '$j("input[name=publishedcheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $output .= '$j("input[name=publishedcheck]").removeAttr("checked"); ' . "\n";
                }
                break;
            case 'hide_menu':
                $new_value = $value ? '1' : '0';
                $output .= '$j("input[name=hidemenu]").val("' . $new_value . '"); ' . "\n";
                if (!$value) {
                    $output .= '$j("input[name=hidemenucheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $output .= '$j("input[name=hidemenucheck]").removeAttr("checked"); ' . "\n";
                }
                break;
            case 'show_in_menu':
                $new_value = $value ? '0' : '1';
                // Note these are reversed from what you'd think
                $output .= '$j("input[name=hidemenu]").val("' . $new_value . '"); ' . "\n";
                if ($value) {
                    $output .= '$j("input[name=hidemenucheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $output .= '$j("input[name=hidemenucheck]").removeAttr("checked"); ' . "\n";
                }
                break;
            case 'searchable':
                $new_value = $value ? '1' : '0';
                $output .= '$j("input[name=searchable]").val("' . $new_value . '"); ' . "\n";
                if ($value) {
                    $output .= '$j("input[name=searchablecheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $output .= '$j("input[name=searchablecheck]").removeAttr("checked"); ' . "\n";
                }
                break;
            case 'cacheable':
                $new_value = $value ? '1' : '0';
                $output .= '$j("input[name=cacheable]").val("' . $new_value . '"); ' . "\n";
                if ($value) {
                    $output .= '$j("input[name=cacheablecheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $output .= '$j("input[name=cacheablecheck]").removeAttr("checked"); ' . "\n";
                }
                break;
            case 'clear_cache':
                $new_value = $value ? '1' : '0';
                $output .= '$j("input[name=syncsite]").val("' . $new_value . '"); ' . "\n";
                if ($value) {
                    $output .= '$j("input[name=syncsitecheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $output .= '$j("input[name=syncsitecheck]").removeAttr("checked"); ' . "\n";
                }
                break;
            case 'container':
            case 'is_folder':
                $new_value = $value ? '1' : '0';
                $output .= '$j("input[name=isfolder]").val("' . $new_value . '"); ' . "\n";
                if ($value) {
                    $output .= '$j("input[name=isfoldercheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $output .= '$j("input[name=isfoldercheck]").removeAttr("checked"); ' . "\n";
                }
                break;
            case 'is_richtext':
            case 'richtext':
                $new_value = $value ? '1' : '0';
                $output .= 'var originalRichtextValue = $j("#which_editor:first").val(); ' . "\n";
                $output .= '$j("input[name=richtext]").val("' . $new_value . '"); ' . "\n";
                if ($value) {
                    $output .= '$j("input[name=richtextcheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $output .= '
					$j("input[name=richtextcheck]").removeAttr("checked");
					// Make the RTE displayed match the default value that has been set here
					if (originalRichtextValue != "none") {
						$j("#which_editor").val("none");
						changeRTE();
					}				
					
					';
                    $output .= '' . "\n";
                }
                break;
            case 'log':
                $new_value = $value ? '0' : '1';
                // Note these are reversed from what you'd think
                $output .= '$j("input[name=donthit]").val("' . $new_value . '"); ' . "\n";
                if ($value) {
                    $output .= '$j("input[name=donthitcheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $output .= '$j("input[name=donthitcheck]").removeAttr("checked"); ' . "\n";
                }
                break;
            case 'content_type':
                $output .= '$j("select[name=contentType]").val("' . $new_value . '");' . "\n";
                break;
            default:
                $output .= '$j("*[name=' . $field . ']").val("' . $new_value . '");' . "\n";
                //return;
                break;
        }
        $output .= "//  -------------- mm_default :: End ------------- \n";
        $e->output($output . "\n");
    }
}
示例#16
0
    function run()
    {
        global $modx;
        extract($modx->event->params);
        $mm_version = '0.4';
        $pluginDir = $modx->config['base_path'] . 'assets/plugins/managermanager';
        //Include Utilites
        include_once $pluginDir . '/utilities.inc.php';
        // When loading widgets, ignore folders / files beginning with these chars
        $ignore_first_chars = array('.', '_', '!');
        // Include widgets
        // We look for a PHP file with the same name as the directory - e.g.
        // /widgets/widgetname/widgetname.php
        $widget_dir = $pluginDir . '/widgets';
        if ($handle = opendir($widget_dir)) {
            while (false !== ($file = readdir($handle))) {
                if (!in_array(substr($file, 0, 1), $ignore_first_chars) && $file != ".." && is_dir($widget_dir . '/' . $file)) {
                    include_once "{$widget_dir}/{$file}/{$file}.php";
                }
            }
            closedir($handle);
        }
        // Set variables
        global $content, $default_template, $mm_current_page, $mm_fields, $splitter;
        $mm_current_page = array();
        if (isset($_POST['template'])) {
            $mm_current_page['template'] = $_POST['template'];
        } elseif (isset($_GET['newtemplate'])) {
            $mm_current_page['template'] = $_GET['newtemplate'];
        } elseif (isset($content['template'])) {
            $mm_current_page['template'] = $content['template'];
        } else {
            $mm_current_page['template'] = $default_template;
        }
        $mm_current_page['role'] = $_SESSION['mgrRole'];
        // What are the fields we can change, and what types are they?
        $field['pagetitle'] = array('input', 'pagetitle', 'pagetitle');
        $field['longtitle'] = array('input', 'longtitle', 'longtitle');
        $field['description'] = array('textarea', 'description', 'description');
        $field['alias'] = array('input', 'alias', 'alias');
        $field['link_attributes'] = array('input', 'link_attributes', 'link_attributes');
        $field['menutitle'] = array('input', 'menutitle', 'menutitle');
        $field['menuindex'] = array('input', 'menuindex', 'menuindex');
        $field['show_in_menu'] = array('input', 'hidemenucheck', 'hidemenu');
        $field['hide_menu'] = array('input', 'hidemenucheck', 'hidemenu');
        // synonym for show_in_menu
        $field['parent'] = array('input', 'parent', 'parent');
        $field['is_folder'] = array('input', 'isfoldercheck', 'isfolder');
        $field['is_richtext'] = array('input', 'richtextcheck', 'richtext');
        $field['log'] = array('input', 'donthitcheck', 'donthit');
        $field['published'] = array('input', 'publishedcheck', 'published');
        $field['pub_date'] = array('input', 'pub_date', 'pub_date');
        $field['unpub_date'] = array('input', 'unpub_date', 'unpub_date');
        $field['searchable'] = array('input', 'searchablecheck', 'searchable');
        $field['cacheable'] = array('input', 'cacheablecheck', 'cacheable');
        $field['clear_cache'] = array('input', 'syncsitecheck', '');
        $field['weblink'] = array('input', 'ta', 'content');
        $field['introtext'] = array('textarea', 'introtext', 'introtext');
        $field['content'] = array('textarea', 'ta', 'content');
        $field['template'] = array('select', 'template', 'template');
        $field['content_type'] = array('select', 'contentType', 'contentType');
        $field['content_dispo'] = array('select', 'content_dispo', 'content_dispo');
        $field['keywords'] = array('select', 'keywords[]', '');
        $field['metatags'] = array('select', 'metatags[]', '');
        $field['which_editor'] = array('select', 'which_editor', '');
        $field['resource_type'] = array('select', 'type', 'isfolder');
        foreach ($field as $k => $a) {
            $mm_fields[$k]['fieldtype'] = $a[0];
            $mm_fields[$k]['fieldname'] = $a[1];
            $mm_fields[$k]['dbname'] = $a[2];
            $mm_fields[$k]['tv'] = false;
        }
        unset($field);
        // Add in TVs to the list of available fields
        $all_tvs = $modx->db->makeArray($modx->db->select('name,type,id,elements', $modx->getFullTableName('site_tmplvars'), '', 'name ASC'));
        foreach ($all_tvs as $thisTv) {
            $n = $thisTv['name'];
            // What is the field name?
            // Checkboxes place an underscore in the ID, so accommodate this...
            $fieldname_suffix = '';
            switch ($thisTv['type']) {
                // What fieldtype is this TV type?
                case 'textarea':
                case 'rawtextarea':
                case 'textareamini':
                case 'richtext':
                    $t = 'textarea';
                    break;
                case 'dropdown':
                case 'listbox':
                    $t = 'select';
                    break;
                case 'listbox-multiple':
                    $t = 'select';
                    $fieldname_suffix = '[]';
                    break;
                case 'checkbox':
                    $t = 'input';
                    $fieldname_suffix = '[]';
                    break;
                case 'custom_tv':
                    if (strpos($thisTv['elements'], 'tvtype="text"') !== false) {
                        $t = 'input';
                    } elseif (strpos($thisTv['elements'], 'tvtype="textarea"') !== false) {
                        $t = 'textarea';
                    } elseif (strpos($thisTv['elements'], 'tvtype="select"') !== false) {
                        $t = 'select';
                    } elseif (strpos($thisTv['elements'], 'tvtype="checkbox"') !== false) {
                        $t = 'input';
                        $fieldname_suffix = '[]';
                    } elseif (strpos($thisTv['elements'], '<textarea') !== false) {
                        $t = 'textarea';
                    } elseif (strpos($thisTv['elements'], '<select') !== false) {
                        $t = 'select';
                    } elseif (strpos($thisTv['elements'], '"checkbox"') !== false) {
                        $t = 'input';
                        $fieldname_suffix = '[]';
                    } else {
                        $t = 'input';
                    }
                    break;
                default:
                    $t = 'input';
                    break;
            }
            // check if there are any name clashes between TVs and default field names? If there is, preserve the default field
            if (!isset($mm_fields[$n])) {
                $mm_fields[$n] = array('fieldtype' => $t, 'fieldname' => 'tv' . $thisTv['id'] . $fieldname_suffix, 'dbname' => '', 'tv' => true);
            }
            $mm_fields['tv' . $n] = array('fieldtype' => $t, 'fieldname' => 'tv' . $thisTv['id'] . $fieldname_suffix, 'dbname' => '', 'tv' => true);
        }
        // Check the current event
        global $e;
        $e =& $modx->event;
        // The start of adding or editing a document (before the main form)
        switch ($e->name) {
            // if it's the plugin config form, give us a copy of all the relevant values
            case 'OnPluginFormRender':
                $plugin_id_editing = $e->params['id'];
                // The ID of the plugin we're editing
                $result = $modx->db->select('name, id', $modx->getFullTableName('site_plugins'), "id='{$plugin_id_editing}'");
                $plugin_editing_name = $modx->db->getValue($result);
                // if it's the right plugin
                if (strtolower($plugin_editing_name) == 'managermanager') {
                    // Get all templates
                    $result = $modx->db->select('templatename, id, description', $modx->getFullTableName('site_templates'), '', 'templatename ASC');
                    $all_templates = $modx->db->makeArray($result);
                    $template_table = '<table>';
                    $template_table .= '<tr><th class="gridHeader">ID</th><th class="gridHeader">Template name</th><th class="gridHeader">Template description</th></tr>';
                    $template_table .= '<tr><td class="gridItem">0</td><td class="gridItem">(blank)</td><td class="gridItem">Blank</td></tr>';
                    foreach ($all_templates as $count => $tpl) {
                        $class = $count % 2 ? 'gridItem' : 'gridAltItem';
                        $template_table .= '<tr>';
                        $template_table .= '<td class="' . $class . '">' . $tpl['id'] . '</td>';
                        $template_table .= '<td class="' . $class . '">' . jsSafe($tpl['templatename']) . '</td>';
                        $template_table .= '<td class="' . $class . '">' . jsSafe($tpl['description']) . '</td>';
                        $template_table .= '</tr>';
                    }
                    $template_table .= '</table>';
                    // Get all tvs
                    $result = $modx->db->select('name,caption,id', $modx->getFullTableName('site_tmplvars'), '', 'name ASC');
                    $all_tvs = $modx->db->makeArray($result);
                    $tvs_table = '<table>';
                    $tvs_table .= '<tr><th class="gridHeader">ID</th><th class="gridHeader">TV name</th><th class="gridHeader">TV caption</th></tr>';
                    foreach ($all_tvs as $count => $tv) {
                        $class = $count % 2 ? 'gridItem' : 'gridAltItem';
                        $tvs_table .= '<tr>';
                        $tvs_table .= '<td class="' . $class . '">' . $tv['id'] . '</td>';
                        $tvs_table .= '<td class="' . $class . '">' . jsSafe($tv['name']) . '</td>';
                        $tvs_table .= '<td class="' . $class . '">' . jsSafe($tv['caption']) . '</td>';
                        $tvs_table .= '</tr>';
                    }
                    $tvs_table .= '</table>';
                    // Get all roles
                    $result = $modx->db->select('name, id', $modx->getFullTableName('user_roles'), '', 'name ASC');
                    $all_roles = $modx->db->makeArray($result);
                    $roles_table = '<table>';
                    $roles_table .= '<tr><th class="gridHeader">ID</th><th class="gridHeader">Role name</th></tr>';
                    foreach ($all_roles as $count => $role) {
                        $class = $count % 2 ? 'gridItem' : 'gridAltItem';
                        $roles_table .= '<tr>';
                        $roles_table .= '<td class="' . $class . '">' . $role['id'] . '</td>';
                        $roles_table .= '<td class="' . $class . '">' . jsSafe($role['name']) . '</td>';
                        $roles_table .= '</tr>';
                    }
                    $roles_table .= '</table>';
                    // Load the jquery library
                    $output = '<!-- Begin ManagerManager output -->' . "\n";
                    $output .= '<script type="text/javascript">' . "\n";
                    $output .= "mm_lastTab = 'tabEvents'; \n";
                    $e->output($output);
                    mm_createTab('Templates, TVs &amp; Roles', 'rolestemplates', '', '', '<p>These are the IDs for current templates,tvs and roles in your site.</p>' . $template_table . '&nbsp;' . $tvs_table . '&nbsp;' . $roles_table);
                    $e->output('</script>');
                    $e->output('<!-- End ManagerManager output -->' . "\n");
                }
                break;
            case 'OnDocFormPrerender':
                // Load the jquery library
                echo '<!-- Begin ManagerManager output -->' . "\n";
                // Create a mask to cover the page while the fields are being rearranged
                echo '
				<div id="loadingmask">&nbsp;</div>
				<script type="text/javascript">
					$j("#loadingmask").css( {width: "100%", height: $j("body").height(), position: "absolute", zIndex: "1000", backgroundColor: "#ffffff"} );
				</script>
			';
                echo '<!-- End ManagerManager output -->';
                break;
                // The main document editing form
            // The main document editing form
            case 'OnDocFormRender':
                // Include the JQuery call
                $e->output('
		<!-- ManagerManager Plugin :: ' . $mm_version . ' -->
		<!-- This document is using template: ' . $mm_current_page['template'] . ' -->
		<!-- You are logged into the following role: ' . $mm_current_page['role'] . ' -->
				
		<script type="text/javascript" charset="' . $modx->config['modx_charset'] . '">
		var mm_lastTab = "tabGeneral";
		var mm_sync_field_count = 0;
		var synch_field = new Array();
		
	$j(document).ready(function(){
			// Lets handle errors nicely...
		try {
			// Change section index depending on Content History running or not
			var sidx = ($j("div.sectionBody:eq(1)").attr("id") == "ch-body")?1:0;  //ch-body is the CH id name (currently at least)
			
			// Give IDs to the sections of the form
			// This assumes they appear in a certain order
			$j("div.sectionHeader:eq(sidx)").attr("id", "sectionContentHeader");
			$j("div.sectionHeader:eq(sidx+1)").attr("id", "sectionTVsHeader");
		  	
			$j("div.sectionBody:eq(sidx+1)").attr("id", "sectionContentBody");
			$j("div.sectionBody:eq(sidx+2)").attr("id", "sectionTVsBody");
		');
                // Get the JS for the changes & display the status
                $e->output($this->make_changes($config_chunk));
                // Close it off
                $e->output('
				// Misc tidying up
				
				// General tab table container is too narrow for receiving TVs -- make it a bit wider
				$j("div#tabGeneral table").attr("width", "100%");
				
				// if template variables containers are empty, remove their section
			if ($j("div.tmplvars :input").length == 0){
					$j("div.tmplvars").hide();	// Still contains an empty table and some dividers
					$j("div.tmplvars").prev("div").hide();	// Still contains an empty table and some dividers
					//$j("#sectionTVsHeader").hide();
				}
				
				// If template category is empty, hide the optgroup
			$j("#template optgroup").each( function(){
					var $this = $j(this),
					visibleOptions = 0;
					$this.find("option").each( function() {
						if ($j(this).css("display") != "none") 	visibleOptions++ ;
					});
					if (visibleOptions == 0) $this.hide();
				});
				
		}catch(e){
				// If theres an error, fail nicely
				alert("ManagerManager: An error has occurred: " + e.name + " - " + e.message);
		}finally{
				// Whatever happens, hide the loading mask
				$j("#loadingmask").hide();
			}
		});
		</script>
		<!-- ManagerManager Plugin :: End -->
				');
                break;
            case 'OnBeforeDocFormSave':
                global $template;
                $mm_current_page['template'] = $template;
                $this->make_changes($config_chunk);
                break;
            case 'OnManagerMainFrameHeaderHTMLBlock':
                global $action;
                if (empty($action) && isset($_GET['a'])) {
                    $action = $_GET['a'];
                }
                switch ($action) {
                    case '4':
                    case '27':
                    case '72':
                    case '73':
                    case '76':
                    case '300':
                    case '301':
                        $output = '<!-- Begin ManagerManager output -->' . "\n";
                        $e->output($output);
                        break;
                    default:
                        return;
                }
                break;
        }
        // end switch
    }
示例#17
0
/**
 * mm_inherit
 * @version 1.2 (2013-05-16)
 * 
 * Inherit values from a parent.
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @link http://code.divandesign.biz/modx/mm_inherit/1.2
 * 
 * @copyright 2013
 */
function mm_inherit($fields, $roles = '', $templates = '')
{
    global $mm_fields, $modx;
    $e =& $modx->Event;
    // if we've been supplied with a string, convert it into an array
    $fields = makeArray($fields);
    // if we aren't creating a new document or folder, we don't want to do this
    if (!($modx->manager->action == '85' || $modx->manager->action == '4')) {
        return;
    }
    // Are we using this rule?
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        // Get the parent info
        if (isset($_REQUEST['pid'])) {
            $parentID = $modx->getPageInfo($_REQUEST['pid'], 0, 'id');
            $parentID = $parentID['id'];
        } else {
            $parentID = 0;
        }
        $output = "//  -------------- mm_inherit (from page {$parentID}) :: Begin ------------- \n";
        foreach ($fields as $field) {
            // get some info about the field we are being asked to use
            if (isset($mm_fields[$field]['dbname'])) {
                $fieldtype = $mm_fields[$field]['fieldtype'];
                $fieldname = $mm_fields[$field]['fieldname'];
                if (!empty($mm_fields[$field]['tv'])) {
                    $dbname = $field;
                } else {
                    $dbname = $mm_fields[$field]['dbname'];
                }
                // Get this field data from the parent
                if (!empty($parentID)) {
                    $newArray = $modx->getTemplateVarOutput($dbname, $parentID);
                    $newvalue = $newArray[$dbname];
                } else {
                    $newArray = false;
                    $newvalue = '';
                }
            } else {
                break;
                // If it's not something stored in the database, don't get the value
            }
            $output .= "\n\t\t\t// fieldtype {$fieldtype}\n\t\t\t// fieldname {$fieldname}\n\t\t\t// dbname {$dbname}\n\t\t\t// newvalue {$newvalue}\n\t\t\t";
            switch ($field) {
                case 'log':
                case 'hide_menu':
                case 'show_in_menu':
                    $output .= '$j("input[name=' . $fieldname . ']").attr("checked", "' . ($newvalue ? '' : 'checked') . '"); ';
                    break;
                case 'is_folder':
                case 'is_richtext':
                case 'searchable':
                case 'cacheable':
                case 'published':
                    $output .= '$j("input[name=' . $fieldname . ']").attr("checked", "' . ($newvalue ? 'checked' : '') . '"); ';
                    break;
                case 'pub_date':
                case 'unpub_date':
                    $output .= '$j("input[name=' . $fieldname . ']").val("' . date('d-m-Y H:i:s', $newvalue) . '"); ';
                    break;
                default:
                    switch ($fieldtype) {
                        case 'textarea':
                            $output .= '$j("textarea[name=' . $fieldname . ']").html("' . jsSafe($newvalue) . '"); ';
                            break;
                        default:
                            if (!empty($newvalue)) {
                                $output .= '$j("' . $fieldtype . '[name=' . $fieldname . ']").val("' . jsSafe($newvalue) . '"); ';
                            }
                            break;
                    }
                    break;
            }
        }
        $output .= "//  -------------- mm_inherit (from page {$parentID}) :: End ------------- \n";
        $e->output($output . "\n");
    }
}
示例#18
0
/** 
 * ddSetFieldValue
 * @version 1.0.3 (2012-11-13)
 * 
 * Жёстко выставляет необходимые значения заданному полю
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @todo Основан на mm_default
 * 
 * @param field {string} - Имя поля, для которого необходимо установить значение.
 * @param value {string} - Значение, которое необходимо установить.
 * @param roles {comma separated string} - Id ролей. По умолчанию: для всех ролей.
 * @param templates {comma separated string} - Id шаблонов. По умолчанию: для всех шаблонов.
 * 
 * @link http://code.divandesign.biz/modx/mm_ddsetfieldvalue/1.0.3
 * 
 * @copyright 2012, DivanDesign
 * http://www.DivanDesign.biz
 */
function mm_ddSetFieldValue($field, $value = '', $roles = '', $templates = '')
{
    global $modx, $content, $mm_fields, $mm_current_page;
    $e =& $modx->event;
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        $output = " // ----------- mm_ddSetFieldValue :: Begin -------------- \n";
        //Подбираем правильный формат даты в соответствии с конфигурацией
        switch ($modx->config['datetime_format']) {
            case 'dd-mm-YYYY':
                $date_format = 'd-m-Y';
                break;
            case 'mm/dd/YYYY':
                $date_format = 'm/d/Y';
                break;
            case 'YYYY/mm/dd':
                $date_format = 'Y/m/d';
                break;
        }
        //Смотрим, что за поле надо изменить
        switch ($field) {
            //Дата публикации
            case 'pub_date':
                $value = $value == '' ? date("{$date_format} H:i:s") : $value;
                $output .= '$j("input[name=pub_date]").val("' . jsSafe($value) . '"); ' . "\n";
                break;
                //Дата отмены публикации
            //Дата отмены публикации
            case 'unpub_date':
                $value = $value == '' ? date("{$date_format} H:i:s") : $value;
                $output .= '$j("input[name=unpub_date]").val("' . jsSafe($value) . '"); ' . "\n";
                break;
                //Признак публикации
            //Признак публикации
            case 'published':
                if ($value == '1') {
                    $output .= '$j("input[name=publishedcheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $value = '0';
                    $output .= '$j("input[name=publishedcheck]").removeAttr("checked"); ' . "\n";
                }
                $output .= '$j("input[name=published]").val("' . $value . '"); ' . "\n";
                break;
                //Признак отображения в меню
            //Признак отображения в меню
            case 'show_in_menu':
                if ($value == '1') {
                    $output .= '$j("input[name=hidemenucheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $value = '0';
                    $output .= '$j("input[name=hidemenucheck]").removeAttr("checked"); ' . "\n";
                }
                $output .= '$j("input[name=hidemenu]").val("' . ($value == '1' ? '0' : '1') . '"); ' . "\n";
                // Note these are reversed from what you'd think
                break;
                //Признак скрытия из меню (аналогично show_in_menu, только наоборот)
            //Признак скрытия из меню (аналогично show_in_menu, только наоборот)
            case 'hide_menu':
                if ($value == '0') {
                    $output .= '$j("input[name=hidemenucheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $value = '1';
                    $output .= '$j("input[name=hidemenucheck]").removeAttr("checked"); ' . "\n";
                }
                $output .= '$j("input[name=hidemenu]").val("' . $value . '"); ' . "\n";
                break;
                //Признак доступности для поиска
            //Признак доступности для поиска
            case 'searchable':
                if ($value == '1') {
                    $output .= '$j("input[name=searchablecheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $value = '0';
                    $output .= '$j("input[name=searchablecheck]").removeAttr("checked"); ' . "\n";
                }
                $output .= '$j("input[name=searchable]").val("' . $value . '"); ' . "\n";
                break;
                //Признак кэширования
            //Признак кэширования
            case 'cacheable':
                if ($value == '1') {
                    $output .= '$j("input[name=cacheablecheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $value = '0';
                    $output .= '$j("input[name=cacheablecheck]").removeAttr("checked"); ' . "\n";
                }
                $output .= '$j("input[name=cacheable]").val("' . $value . '"); ' . "\n";
                break;
                //Признак очистки кэша
            //Признак очистки кэша
            case 'clear_cache':
                if ($value == '1') {
                    $output .= '$j("input[name=syncsitecheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $value = '0';
                    $output .= '$j("input[name=syncsitecheck]").removeAttr("checked"); ' . "\n";
                }
                $output .= '$j("input[name=syncsite]").val("' . $value . '"); ' . "\n";
                break;
                //Признак папки
            //Признак папки
            case 'is_folder':
                if ($value == '1') {
                    $output .= '$j("input[name=isfoldercheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $value = '0';
                    $output .= '$j("input[name=isfoldercheck]").removeAttr("checked"); ' . "\n";
                }
                break;
                //Признак использованшия визуального редактора
            //Признак использованшия визуального редактора
            case 'is_richtext':
                $output .= 'var originalRichtextValue = $j("#which_editor:first").val(); ' . "\n";
                if ($value == '1') {
                    $output .= '$j("input[name=richtextcheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $value = '0';
                    $output .= '
								$j("input[name=richtextcheck]").removeAttr("checked");
								// Make the RTE displayed match the default value that has been set here
								if (originalRichtextValue != "none"){
									$j("#which_editor").val("none");
									changeRTE();
								}
										
								';
                    $output .= '' . "\n";
                }
                $output .= '$j("input[name=richtext]").val("' . $value . '"); ' . "\n";
                break;
                //Признак логирования
            //Признак логирования
            case 'log':
                //Note these are reversed from what you'd think
                $value = $value ? '0' : '1';
                if ($value == '1') {
                    $output .= '$j("input[name=donthitcheck]").attr("checked", "checked"); ' . "\n";
                } else {
                    $output .= '$j("input[name=donthitcheck]").removeAttr("checked"); ' . "\n";
                }
                $output .= '$j("input[name=donthit]").val("' . $value . '"); ' . "\n";
                break;
                //Тип содержимого
            //Тип содержимого
            case 'content_type':
                $output .= '$j("select[name=contentType]").val("' . $value . '");' . "\n";
                break;
                //TV
            //TV
            default:
                // Which template is this page using?
                $tvsMas = tplUseTvs($mm_current_page['template'], $field);
                if ($tvsMas) {
                    $output .= '$j("#tv' . $tvsMas[0]['id'] . '").val("' . $value . '");' . "\n";
                }
                break;
        }
        $output .= "\n// ---------------- mm_ddSetFieldValue :: End -------------";
        $e->output($output . "\n");
    }
}