function mm_minimizablesections($sections, $roles = '', $templates = '', $minimized = '')
{
    if (!useThisRule($roles, $templates)) {
        return;
    }
    global $modx;
    $e =& $modx->Event;
    $site = $modx->config['site_url'];
    $widgetDir = $site . 'assets/plugins/managermanager/widgets/mm_minimizablesections/';
    $output = '';
    if ($e->name == 'OnDocFormPrerender') {
        $output .= includeJsCss($widgetDir . 'minimizablesections.css', 'html');
        $e->output($output);
    } else {
        if ($e->name == 'OnDocFormRender') {
            $sections = makeArray($sections);
            $minimized = makeArray($minimized);
            $sections = array_map("prepareSection", $sections);
            $minimized = array_map("prepareSection", $minimized);
            $output .= "//---------- mm_minimizablesections :: Begin -----\n";
            $output .= '$j("' . implode(",", $sections) . '","#documentPane").addClass("minimizable").on("click",function(){
     var _t = $j(this);
     _t.next().slideToggle(400,function(){_t.toggleClass("minimized");})
    });
    $j(".minimizable").filter("' . implode(",", $minimized) . '").addClass("minimized").next().hide();
  ';
            $output .= "//---------- mm_minimizablesections :: End -----\n";
            $e->output($output);
        }
    }
}
示例#2
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");
    }
}
/**
 * mm_hideSections
 * @version 1.2.1 (2014-05-25)
 * 
 * @desc A widget for ManagerManager plugin that allows one or a few sections to be hidden on the document edit page.
 * 
 * @uses ManagerManager plugin 0.6.2.
 * 
 * @param $sections {comma separated string} - The id(s) of the sections this should apply to. @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_hidesections/1.2.1
 * 
 * @copyright 2014
 */
function mm_hideSections($sections, $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)) {
        // if we've been supplied with a string, convert it into an array
        $sections = makeArray($sections);
        $output = "//---------- mm_hideSections :: Begin -----\n";
        foreach ($sections as $section) {
            switch ($section) {
                case 'access':
                    // These have moved to tabs in 1.0.1
                    $output .= '$j("#sectionAccessHeader, #sectionAccessBody").hide();' . "\n";
                    break;
                default:
                    $section = prepareSectionId($section);
                    $output .= '$j("#' . $section . '_header, #' . $section . '_body").hide();' . "\n";
                    break;
            }
        }
        $output .= "//---------- mm_hideSections :: End -----\n";
        $e->output($output);
    }
}
示例#4
0
/**
 * mm_widget_template
 * @version 1.0 (2013-01-01)
 *
 * A template for creating new widgets
 *
 * @uses ManagerManager plugin 0.4.
 *
 * @link http://
 *
 * @copyright 2013
 */
function mm_widget_template($fields, $other_param = 'defaultValue', $roles = '', $templates = '')
{
    global $modx, $mm_fields, $mm_current_page;
    $e =& $modx->event;
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        // Your output should be stored in a string, which is outputted at the end
        // It will be inserted as a Javascript block (with jQuery), which is executed on document ready
        // We always put a JS comment, which makes debugging much easier
        $output = "//  -------------- mm_widget_template :: Begin ------------- \n";
        // if we've been supplied with a string, convert it into an array
        $fields = makeArray($fields);
        // You might want to check whether the current page's template uses the TVs that have been
        // supplied, to save processing page which don't contain them
        $count = tplUseTvs($mm_current_page['template'], $fields);
        if ($count == false) {
            return;
        }
        // We have functions to include JS or CSS external files you might need
        // The standard ModX API methods don't work here
        $output .= includeJs('assets/plugins/managermanager/widgets/template/javascript.js');
        $output .= includeCss('assets/plugins/managermanager/widgets/template/styles.css');
        // Do something for each of the fields supplied
        foreach ($fields as $targetTv) {
            // If it's a TV, we may need to map the field name, to what it's ID is.
            // This can be obtained from the mm_fields array
            $tv_id = $mm_fields[$targetTv]['fieldname'];
        }
        //JS comment for end of widget
        $output .= "//  -------------- mm_widget_template :: End ------------- \n";
        // Send the output to the browser
        $e->output($output . "\n");
    }
}
/**
 * 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");
    }
}
示例#6
0
/**
 * mm_hideFields
 * @version 1.1.2 (2014-05-07)
 * 
 * @desc A widget for ManagerManager plugin that allows one or more of the default document fields or template variables to be hidden within the manager.
 * 
 * @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 $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_hidefields/1.1.2
 * 
 * @copyright 2014
 */
function mm_hideFields($fields, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    // if we've been supplied with a string, convert it into an array
    $fields = makeArray($fields);
    // 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)) {
        global $mm_fields;
        $output = "//---------- mm_hideFields :: Begin -----\n";
        foreach ($fields as $field) {
            switch ($field) {
                // Exceptions
                case 'keywords':
                    $output .= '$j("select[name*=\'keywords\']").parent("td").hide();' . "\n";
                    break;
                case 'metatags':
                    $output .= '$j("select[name*\'=metatags\']").parent("td").hide()' . "\n";
                    break;
                case 'hidemenu':
                case 'hide_menu':
                case 'show_in_menu':
                    $output .= '$j("input[name=\'hidemenucheck\']").parent("td").hide();' . "\n";
                    break;
                case 'menuindex':
                    $output .= '$j("input[name=\'menuindex\']").parents("table").parent("td").prev("td").children("span.warning").hide();' . "\n";
                    $output .= '$j("input[name=\'menuindex\']").parent("td").hide();' . "\n";
                    break;
                case 'which_editor':
                    $output .= '$j("select#which_editor").prev("span.warning").hide();' . "\n";
                    $output .= '$j("select#which_editor").hide();' . "\n";
                    break;
                case 'content':
                    $output .= '$j("#sectionContentHeader, #sectionContentBody").hide();' . "\n";
                    // For 1.0.0
                    $output .= '$j("#ta").parent("div").parent("div").hide().prev("div").hide();' . "\n";
                    // For 1.0.1
                    break;
                case 'pub_date':
                    $output .= '$j("input[name=\'pub_date\']").parents("tr").next("tr").hide();' . "\n";
                    $output .= '$j("input[name=\'pub_date\']").parents("tr").hide();' . "\n";
                    break;
                case 'unpub_date':
                    $output .= '$j("input[name=\'unpub_date\']").parents("tr").next("tr").hide();' . "\n";
                    $output .= '$j("input[name=\'unpub_date\']").parents("tr").hide();' . "\n";
                    break;
                    // Ones that follow the regular pattern
                // Ones that follow the regular pattern
                default:
                    if (isset($mm_fields[$field])) {
                        // Check the fields exist,  so we're not writing JS for elements that don't exist
                        $output .= '$j("' . $mm_fields[$field]['fieldtype'] . '[name=\'' . $mm_fields[$field]['fieldname'] . '\']").parents("tr").hide().next("tr").find("td[colspan=2]").parent("tr").hide();' . "\n";
                    }
                    break;
            }
            $output .= "//---------- mm_hideFields :: End -----\n";
            $e->output($output);
        }
    }
}
示例#7
0
/** 
 * mm_ddCreateSection
 * @version 1.0 (2013-05-22)
 * 
 * @description 
 * 
 * @uses ManagerManager 0.5.
 *
 * @param $title {string} - The display name of the new section. @required
 * @param $id {string} - A unique ID for this section. @required
 * @param $tabId {string} - The ID of the tab which the section should be inserted to. Can be one of the default tab IDs or a new custom tab created with mm_createTab. Default: 'general'.
 * @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_ddcreatesection/1.0
 * 
 * @copyright 2013, DivanDesign
 * http://www.DivanDesign.ru
 */
function mm_ddCreateSection($title, $id, $tabId = 'general', $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates) && !empty($id)) {
        // We always put a JS comment, which makes debugging much easier
        $output = "\n//  -------------- mm_ddCreateSection :: Begin ------------- \n";
        if ($title == '') {
            $title = $id;
        }
        $id = prepareSectionId($id);
        $tabId = prepareTabId($tabId);
        $section = '
<div class="sectionHeader" id="' . $id . '_header">' . $title . '</div>
<div class="sectionBody" id="' . $id . '_body"><table style="position:relative;" border="0" cellspacing="0" cellpadding="3" width="100%"></table></div>
		';
        //tabGeneral
        // Clean up for js output
        $section = str_replace(array("\n", "\t", "\r"), '', $section);
        $output .= '$j("#' . $tabId . '").append(\'' . $section . '\');';
        //JS comment for end of widget
        $output .= "\n//  -------------- mm_ddCreateSection :: End ------------- \n";
        // Send the output to the browser
        $e->output($output . "\n");
    }
}
示例#8
0
function mm_widget_evogallery($moduleid, $title = '', $roles = '', $templates = '')
{
    global $modx, $content, $mm_fields;
    $e =& $modx->Event;
    if (useThisRule($roles, $templates)) {
        //Include language file
        $langpath = $modx->config['base_path'] . "assets/modules/evogallery/lang/";
        //First include english
        if (file_exists($langpath . 'english.inc.php')) {
            include $langpath . 'english.inc.php';
        }
        //Include current manager language
        if (file_exists($langpath . $modx->config['manager_language'] . '.inc.php')) {
            include $langpath . $modx->config['manager_language'] . '.inc.php';
        }
        $title = empty($title) ? $_lang['mm_tab_name'] : $title;
        //TODO: Add iframe autoheight
        if (isset($content['id'])) {
            $iframecontent = '<iframe id="mm_evogallery" src="' . $modx->config['site_url'] . 'manager/index.php?a=112&id=' . $moduleid . '&onlygallery=1&action=view&content_id=' . $content['id'] . '" style="width:100%;height:600px;" scrolling="auto" frameborder="0"></iframe>';
        } else {
            $iframecontent = '<p class="warning">' . $_lang['mm_save_required'] . '</p>';
        }
        mm_createTab($title, 'evogallery', '', '', '<strong>' . $_lang['mm_manage_images'] . '</strong>', '100%');
        $output = "\$j('#table-evogallery').append('<tr><td>{$iframecontent}</td></tr>');";
    }
    // end if
    $e->output($output . "\n");
    // Send the output to the browser
}
/**
 * mm_hideSections
 * @version 1.1 (2012-11-13)
 * 
 * Hides sections.
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @link http://code.divandesign.biz/modx/mm_hidesections/1.1
 * 
 * @copyright 2012
 */
function mm_hideSections($sections, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->event;
    // if we've been supplied with a string, convert it into an array
    $sections = makeArray($sections);
    // 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 = "//  -------------- mm_hideSections :: Begin ------------- \n";
        foreach ($sections as $section) {
            switch ($section) {
                case 'content':
                    $output .= '
					$j("#content_header").hide();
					$j("#content_body").hide();
					';
                    break;
                case 'tvs':
                    $output .= '
					$j("#tv_header").hide();
					$j("#tv_body").hide();
					';
                    break;
                case 'access':
                    // These have moved to tabs in 1.0.1
                    $output .= '
					$j("#sectionAccessHeader").hide();
					$j("#sectionAccessBody").hide();';
                    break;
            }
            $output .= "//  -------------- mm_hideSections :: End ------------- \n";
            $e->output($output . "\n");
        }
    }
}
示例#10
0
/**
 * mm_renameSection
 * @version 1.1 (2012-11-13)
 * 
 * Rename a section.
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @link http://code.divandesign.biz/modx/mm_renamesection/1.1
 * 
 * @copyright 2012
 */
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 '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;
        }
        $output .= "//  -------------- mm_renameSection :: End ------------- \n";
        $e->output($output . "\n");
    }
}
示例#11
0
/**
 * mm_createTab
 * @version 1.1 (2012-11-13)
 * 
 * Create a new tab.
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @link http://code.divandesign.biz/modx/mm_createtab/1.1
 * 
 * @copyright 2012
 */
function mm_createTab($name, $id, $roles = '', $templates = '', $intro = '', $width = '680')
{
    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' || $e->name == 'OnPluginFormRender') && useThisRule($roles, $templates)) {
        // Plugin page tabs use a differen name for the tab object
        $js_tab_object = $e->name == 'OnPluginFormRender' ? 'tpSnippet' : 'tpSettings';
        $output = "//  -------------- mm_createTab :: Begin ------------- \n";
        $empty_tab = '
<div class="tab-page" id="tab' . $id . '">
	<h2 class="tab">' . $name . '</h2>
	<div class="tabIntro" id="tab-intro-' . $id . '">' . $intro . '</div>
	<table width="' . $width . '" border="0" cellspacing="0" cellpadding="0" id="table-' . $id . '">
	</table>
</div>
		';
        // Clean up for js output
        $empty_tab = str_replace(array("\n", "\t", "\r"), '', $empty_tab);
        $output .= '$j';
        $output .= "('div#'+mm_lastTab).after('" . $empty_tab . "'); \n";
        $output .= "mm_lastTab = 'tab" . $id . "'; \n";
        $output .= $js_tab_object . '.addTabPage( document.getElementById( "tab' . $id . '" ) ); ';
        $output .= "//  -------------- mm_createTab :: End ------------- \n";
        $e->output($output . "\n");
    }
}
示例#12
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");
    }
}
示例#13
0
/**
 * mm_hideTabs
 * @version 1.1 (2012-11-13)
 * 
 * Hide a tab.
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @link http://code.divandesign.biz/modx/mm_hidetabs/1.1
 * 
 * @copyright 2012
 */
function mm_hideTabs($tabs, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    // if we've been supplied with a string, convert it into an array
    $tabs = makeArray($tabs);
    // 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_hideTabs :: Begin ------------- \n";
        foreach ($tabs as $tab) {
            switch ($tab) {
                case 'general':
                    $output .= 'if (tpSettings.getSelectedIndex() == 0) { tpSettings.setSelectedIndex(1); } ' . "\n";
                    // if we are hiding the currently active tab, make another visible
                    $output .= '$j("div#documentPane h2:nth-child(1)").hide(); ' . "\n";
                    $output .= '$j("#tabGeneral").hide();';
                    break;
                case 'settings':
                    $output .= 'if (tpSettings.getSelectedIndex() == 1) { tpSettings.setSelectedIndex(0); } ' . "\n";
                    $output .= '$j("div#documentPane h2:nth-child(2)").hide(); ' . "\n";
                    $output .= '$j("#tabSettings").hide();';
                    break;
                    // =< v1.0.0 only
                // =< v1.0.0 only
                case 'meta':
                    if ($modx->hasPermission('edit_doc_metatags') && $modx->config['show_meta'] != "0") {
                        $output .= 'if (tpSettings.getSelectedIndex() == 2) { tpSettings.setSelectedIndex(0); } ' . "\n";
                        $output .= '$j("div#documentPane h2:nth-child(3)").hide(); ' . "\n";
                        $output .= '$j("#tabMeta").hide(); ';
                    }
                    break;
                    // Meta tags tab is removed by default in version 1.0.1+ but can still be enabled via a preference.
                    // Access tab was only added in 1.0.1
                    // Since counting the tabs is the only way of determining this, we need to know if this has been activated
                    // If meta tabs are active, the "access" tab is index 4 in the HTML; otherwise index 3.
                    // If config['show_meta'] is NULL, this is a version before this option existed, e.g. < 1.0.1
                    // For versions => 1.0.1, 0 is the default value to not show them, 1 is the option to show them.
                // Meta tags tab is removed by default in version 1.0.1+ but can still be enabled via a preference.
                // Access tab was only added in 1.0.1
                // Since counting the tabs is the only way of determining this, we need to know if this has been activated
                // If meta tabs are active, the "access" tab is index 4 in the HTML; otherwise index 3.
                // If config['show_meta'] is NULL, this is a version before this option existed, e.g. < 1.0.1
                // For versions => 1.0.1, 0 is the default value to not show them, 1 is the option to show them.
                case 'access':
                    $access_index = $modx->config['show_meta'] == "0" ? 3 : 4;
                    $output .= 'if (tpSettings.getSelectedIndex() == ' . ($access_index - 1) . ') { tpSettings.setSelectedIndex(0); } ' . "\n";
                    $output .= '$j("div#documentPane h2:nth-child(' . $access_index . ')").hide(); ' . "\n";
                    $output .= '$j("#tabAccess").hide();';
                    break;
            }
            $output .= "//  -------------- mm_hideTabs :: End ------------- \n";
            $e->output($output . "\n");
        }
    }
}
/** 
 * mm_ddMoveFieldsToSection
 * @version 1.0.2 (2013-12-10)
 * 
 * @description Widget allows document fields & TVs to be moved in an another section. However you can’t move the following fields: keywords, metatags, which_editor, show_in_menu, menuindex.
 * 
 * @uses ManagerManager 0.6.
 * 
 * @param $fields {string} - The name(s) of the document fields (or TVs) this should apply to. @required
 * @param $sectionId {string} - The ID of the section which the fields should be moved to. @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_movefieldstosection/1.0.2
 * 
 * @copyright 2013, DivanDesign
 * http://www.DivanDesign.ru
 */
function mm_ddMoveFieldsToSection($fields, $sectionId, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        $output = "//---------- mm_ddMoveFieldsToSection :: Begin -----\n";
        $output .= '$j.ddMM.moveFields("' . $fields . '", "' . prepareSectionId($sectionId) . '_body");' . "\n";
        $output .= "//---------- mm_ddMoveFieldsToSection :: End -----\n";
        $e->output($output);
    }
}
示例#15
0
function mm_galleryLink($fields, $roles = '', $templates = '', $moduleid = '')
{
    global $mm_fields, $modx, $content;
    $e =& $modx->Event;
    // if we've been supplied with a string, convert it into an array
    $fields = makeArray($fields);
    // 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 = " // ----------- Gallery Link -------------- \n";
        foreach ($fields as $field) {
            //ignore for now
            switch ($field) {
                // ignore fields that can't be converted
                case 'keywords':
                case 'metatags':
                case 'hidemenu':
                case 'which_editor':
                case 'template':
                case 'menuindex':
                case 'show_in_menu':
                case 'parent':
                case 'is_folder':
                case 'is_richtext':
                case 'log':
                case 'searchable':
                case 'cacheable':
                case 'clear_cache':
                case 'content_type':
                case 'content_dispo':
                case 'which_editor':
                    $output .= '';
                    break;
                    // default if not ignored
                // default if not ignored
                default:
                    if (isset($mm_fields[$field])) {
                        // Check the fields exist,  so we're not writing JS for elements that don't exist
                        $output .= 'var pid' . $mm_fields[$field]['fieldname'] . ' = "' . (!empty($content['id']) ? $content['id'] : 'false') . '";' . "\n";
                        $output .= 'var gl' . $mm_fields[$field]['fieldname'] . ' = $j("' . $mm_fields[$field]['fieldtype'] . '[name=' . $mm_fields[$field]['fieldname'] . ']");' . "\n";
                        $output .= 'if(pid' . $mm_fields[$field]['fieldname'] . ' != \'false\'){' . "\n";
                        $output .= '    var galleryLink = $j(\'<a href="' . $modx->config['base_url'] . MGR_DIR . '/index.php?a=112&id=' . $moduleid . '&action=view&content_id=\'+pid' . $mm_fields[$field]['fieldname'] . '+\'">Manage Photos</a>\').insertAfter(gl' . $mm_fields[$field]['fieldname'] . ');' . "\n";
                        $output .= '} else {' . "\n";
                        $output .= '    var galleryLink = $j(\'<p class="warning">You must save this page before you can manage the photos associated with it.</p>\').insertAfter(gl' . $mm_fields[$field]['fieldname'] . ');' . "\n";
                        $output .= '}' . "\n";
                        $output .= 'gl' . $mm_fields[$field]['fieldname'] . '.hide();' . "\n";
                    }
                    break;
            }
        }
        $e->output($output . "\n");
    }
    // end if
}
示例#16
0
/**
 * mm_synch_fields
 * @version 1.1 (2012-11-13)
 * 
 * Synch two fields in real time.
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @link http://code.divandesign.biz/modx/mm_synch_fields/1.1
 * 
 * @copyright 2012
 */
function mm_synch_fields($fields, $roles = '', $templates = '')
{
    global $modx, $mm_fields;
    $e =& $modx->Event;
    // if we've been supplied with a string, convert it into an array
    $fields = makeArray($fields);
    // We need at least 2 values
    if (count($fields) < 2) {
        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_synch_fields :: Begin ------------- \n";
        $output .= '
		synch_field[mm_sync_field_count] = new Array();
		';
        foreach ($fields as $field) {
            if (isset($mm_fields[$field])) {
                $fieldtype = $mm_fields[$field]['fieldtype'];
                $fieldname = $mm_fields[$field]['fieldname'];
                $valid_fieldtypes = array('input', 'textarea');
                // Make sure we're dealing with an input
                if (!in_array($fieldtype, $valid_fieldtypes)) {
                    break;
                }
                // Add this field to the array of fields being synched
                $output .= '
				synch_field[mm_sync_field_count].push($j("' . $fieldtype . '[name=' . $fieldname . ']"));
				';
                // Or we don't recognise it
            } else {
                break;
            }
        }
        // Output some javascript to sync these fields
        $output .= '
$j.each(synch_field[mm_sync_field_count], function(i, n){
	$j.each(synch_field[mm_sync_field_count], function(j, m){
		if (i != j){
			n.keyup(function(){
				m.val($j(this).val());
			});
		}
	});
});

mm_sync_field_count++;
		';
        $output .= "//  -------------- mm_synch_fields :: End ------------- \n";
        $e->output($output . "\n");
    }
}
示例#17
0
function mm_hideTemplates($tplIds, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    $tplIds = makeArray($tplIds);
    if (useThisRule($roles, $templates)) {
        $output = " // ----------- Hide templates -------------- \n";
        foreach ($tplIds as $tpl) {
            $output .= 'if ($j("select#template").val() != ' . $tpl . ') { ' . "\n";
            $output .= '$j("select#template option[value=' . $tpl . ']").hide();' . "\n";
            $output .= '}' . "\n";
        }
        $e->output($output . "\n");
    }
}
/**
 * mm_hideTemplates
 * @version 1.1 (2012-11-13)
 * 
 * Hide a template within the dropdown list of templates.
 * Based on code submitted by Metaller
 * 
 * @uses ManagerManager plugin 0.4.
 * 
 * @link http://code.divandesign.biz/modx/mm_hidetemplates/1.1
 * 
 * @copyright 2012
 */
function mm_hideTemplates($tplIds, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    $tplIds = makeArray($tplIds);
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        $output = "//  -------------- mm_hideTemplates :: Begin ------------- \n";
        foreach ($tplIds as $tpl) {
            $output .= 'if ($j("select#template").val() != ' . $tpl . '){ ' . "\n";
            $output .= '$j("select#template option[value=' . $tpl . ']").remove();' . "\n";
            $output .= '}' . "\n";
        }
        $output .= "//  -------------- mm_hideTemplates :: End ------------- \n";
        $e->output($output . "\n");
    }
}
示例#19
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_moveFieldsToTab
 * @version 1.2.2 (2013-12-10)
 * 
 * @desc A widget for ManagerManager plugin that allows document fields & TVs to be moved in an another tab.
 * 
 * @uses ManagerManager plugin 0.6.
 * 
 * @param $fields {comma separated string} - The name(s) of the document fields (or TVs) this should apply to. @required
 * @param $tabId {string} - The ID of the tab which the fields should be moved to. Can be one of the default tab IDs or a new custom tab created with mm_createTab. @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} - The Id of the templates to which this widget is applied (when this parameter is empty then widget is applied to the all templates).
 * 
 * @link http://code.divandesign.biz/modx/mm_movefieldstotab/1.2.2
 * 
 * @copyright 2013
 */
function mm_moveCategoryToTab($categoryId, $tabId, $roles = '', $templates = '')
{
    global $modx;
    $e =& $modx->Event;
    $res = $modx->db->select("name", $modx->getFullTableName('site_tmplvars'), "category='" . $categoryId . "'");
    $fieldsArr = array();
    while ($row = $modx->db->getRow($res)) {
        $fieldsArr[] = $row['name'];
    }
    $fields = implode(",", $fieldsArr);
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        $output = "//---------- mm_moveFieldsToTab :: Begin -----\n";
        $output .= '$j.ddMM.moveFields("' . $fields . '", "' . prepareTabId($tabId) . '");' . "\n";
        $output .= "//---------- mm_moveFieldsToTab :: End -----\n";
        $e->output($output);
    }
}
示例#21
0
/**
 * mm_widget_colors
 * @version 1.1 (2012-11-13)
 *
 * Adds a color selection widget to the specified TVs.
 *
 * @uses ManagerManager plugin 0.4.
 *
 * @link http://code.divandesign.biz/modx/mm_widget_colors/1.1
 *
 * @copyright 2012
 */
function mm_widget_colors($fields, $default = '#ffffff', $roles = '', $templates = '')
{
    global $modx, $mm_fields, $mm_current_page;
    $e =& $modx->event;
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        $output = '';
        // if we've been supplied with a string, convert it into an array
        $fields = makeArray($fields);
        // 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.
        $tv_count = tplUseTvs($mm_current_page['template'], $fields);
        if ($tv_count === false) {
            return;
        }
        // Insert some JS
        $output .= includeJs($modx->config['base_url'] . 'assets/plugins/managermanager/widgets/colors/farbtastic.js');
        // Insert some CSS
        $output .= includeCss($modx->config['base_url'] . 'assets/plugins/managermanager/widgets/colors/farbtastic.css');
        // Go through each of the fields supplied
        foreach ($fields as $tv) {
            $tv_id = $mm_fields[$tv]['fieldname'];
            $output .= '
				// ----------- Color widget for  ' . $tv_id . '  --------------
				$j("#' . $tv_id . '").css("background-image","none");
				$j("#' . $tv_id . '").after(\'<div id="colorpicker' . $tv_id . '"></div>\');
				if ($j("#' . $tv_id . '").val() == ""){
					$j("#' . $tv_id . '").val("' . $default . '");
				}
				$j("#colorpicker' . $tv_id . '").farbtastic("#' . $tv_id . '");
				$j("#colorpicker' . $tv_id . '").mouseup(function(){
					// mark the document as dirty, or the value wont be saved
					$j("#' . $tv_id . '").trigger("change");
				});
				';
        }
        $e->output($output . "\n");
    }
}
示例#22
0
/**
 * mm_widget_colors
 * @version 1.2 (2013-12-11)
 * 
 * A widget for ManagerManager plugin that allows text field to be turned into a color picker storing a chosen hex value in the field on the document editing page.
 * 
 * @uses ManagerManager plugin 0.6.
 * 
 * @param $fields {comma separated string} - The name(s) of the template variables this should apply to. @required
 * @param $default {string} - Which color in hex format should be selected by default in new documents. This is only used in situations where the TV does not have a default value specified in the TV definition. Default: '#ffffff'.
 * @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 OnDocFormPrerender
 * @event OnDocFormRender
 * 
 * @link http://code.divandesign.biz/modx/mm_widget_colors/1.2
 * 
 * @copyright 2013
 */
function mm_widget_colors($fields, $default = '#ffffff', $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/colors/farbtastic.js', 'html', 'farbtastic', '1.2');
        $output .= includeJsCss($modx->config['base_url'] . 'assets/plugins/managermanager/widgets/colors/farbtastic.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);
            // Does this page's template use any of these TVs? If not, quit.
            $tv_count = tplUseTvs($mm_current_page['template'], $fields);
            if ($tv_count === false) {
                return;
            }
            $output .= "//---------- mm_widget_colors :: Begin -----\n";
            // Go through each of the fields supplied
            foreach ($fields as $tv) {
                $tv_id = $mm_fields[$tv]['fieldname'];
                $output .= '
$j("#' . $tv_id . '").css("background-image","none");
$j("#' . $tv_id . '").after(\'<div id="colorpicker' . $tv_id . '"></div>\');
if ($j("#' . $tv_id . '").val() == ""){
	$j("#' . $tv_id . '").val("' . $default . '");
}
$j("#colorpicker' . $tv_id . '").farbtastic("#' . $tv_id . '");
$j("#colorpicker' . $tv_id . '").mouseup(function(){
	// mark the document as dirty, or the value wont be saved
	$j("#' . $tv_id . '").trigger("change");
});
';
            }
            $output .= "//---------- mm_widget_colors :: End -----\n";
            $e->output($output);
        }
    }
}
示例#23
0
/**
 * mm_hideTabs
 * @version 1.2 (2014-12-01)
 * 
 * @desc A widget for ManagerManager plugin that allows one or a few default tabs to be hidden on the document edit page.
 * 
 * @uses ManagerManager plugin 0.6.2.
 * 
 * @param $tabs {'general'; 'settings'; 'access'} - The id(s) of the tab(s) this should apply to. @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_hidetabs/1.2
 * 
 * @copyright 2014, DivanDesign
 * http://www.DivanDesign.biz
 */
function mm_hideTabs($tabs, $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_hideTabs :: Begin -----\n";
        // if we've been supplied with a string, convert it into an array
        $tabs = makeArray($tabs);
        foreach ($tabs as $tab) {
            //meta for =< v1.0.0 only
            if ($tab != 'meta' || $modx->hasPermission('edit_doc_metatags') && $modx->config['show_meta'] != '0') {
                $output .= '
var $mm_hideTabs_tabElement = $j("#' . prepareTabId($tab) . '");

//If the element exists
if ($mm_hideTabs_tabElement.length > 0){
	//Hide the tab element
	$mm_hideTabs_tabElement.hide();
	//Hide the tab link
	$j($mm_hideTabs_tabElement.get(0).tabPage.tab).hide();
}
';
            }
        }
        $output .= '
//All tabs
var $mm_hideTabs_allTabs = $j();

for (var i = 0; i < tpSettings.pages.length - 1; i++){
	$mm_hideTabs_allTabs = $mm_hideTabs_allTabs.add(tpSettings.pages[i].tab);
}

//If the active tab is hidden
if ($j(tpSettings.pages[tpSettings.getSelectedIndex()].tab).is(":hidden")){
	//Activate the first visible tab
	$mm_hideTabs_allTabs.filter(":visible").eq(0).trigger("click");
}
';
        $output .= "//---------- mm_hideTabs :: End -----\n";
        $e->output($output);
    }
}
示例#24
0
/**
 * mm_ddYMap
 * @version 1.4.3 (2013-12-10)
 * 
 * @desc A widget for ManagerManager plugin allowing Yandex Maps integration.
 * 
 * @uses ManagerManager plugin 0.6.
 * 
 * @param $tvs {comma separated string} - TV names to which the widget is applied. @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: ''.
 * @param $w {'auto'; integer} - Width of the map container. Default: 'auto'.
 * @param $h {integer} - Height of the map container. Default: 400.
 * @param $hideField {boolean} - Original coordinates field hiding status (true — hide, false — show). Default: true.
 * 
 * @event OnDocFormPrerender
 * @event OnDocFormRender
 * 
 * @link http://code.divandesign.biz/modx/mm_ddymap/1.4.3
 * 
 * @copyright 2013, DivanDesign
 * http://www.DivanDesign.biz
 */
function mm_ddYMap($tvs, $roles = '', $templates = '', $w = 'auto', $h = '400', $hideField = true)
{
    if (!useThisRule($roles, $templates)) {
        return;
    }
    global $modx;
    $e =& $modx->Event;
    if ($e->name == 'OnDocFormPrerender') {
        //The main js file including
        $output = includeJsCss($modx->config['site_url'] . 'assets/plugins/managermanager/widgets/ddymap/jquery.ddMM.mm_ddYMap.js', 'html', 'jquery.ddMM.mm_ddYMap', '1.0.2');
        //The Yandex.Maps library including
        $output .= includeJsCss('http://api-maps.yandex.ru/2.0/?load=package.full&lang=ru-RU&onload=mm_ddYMap_init', 'html', 'api-maps.yandex.ru', '2.0');
        $e->output($output);
    } else {
        if ($e->name == 'OnDocFormRender') {
            global $mm_current_page;
            $output = '';
            //if we've been supplied with a string, convert it into an array
            $tvs = makeArray($tvs);
            $usedTvs = tplUseTvs($mm_current_page['template'], $tvs, '', 'id', 'name');
            if ($usedTvs == false) {
                return;
            }
            $output .= "//---------- mm_ddYMap :: Begin -----\n";
            //Iterate over supplied TVs instead of doing so to the result of tplUseTvs() to maintain rendering order.
            foreach ($tvs as $tv) {
                //If this $tv is used in a current template
                if (isset($usedTvs[$tv])) {
                    $output .= '
$j("#tv' . $usedTvs[$tv]['id'] . '").mm_ddYMap({
	hideField: ' . intval($hideField) . ',
	width: "' . $w . '",
	height: "' . $h . '"
});
';
                }
            }
            $output .= "//---------- mm_ddYMap :: End -----\n";
            $e->output($output);
        }
    }
}
示例#25
0
/**
 * mm_ddGMap
 * @version 1.2b (2014-05-14)
 * 
 * @desc Widget for ManagerManager plugin allowing Google Maps integration.
 * 
 * @uses ManagerManager plugin 0.6.1.
 * 
 * @param $tvs {comma separated string} - TV names to which the widget is applied. @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: ''.
 * @param $w {'auto'; integer} - Width of the map container. Default: 'auto'.
 * @param $h {integer} - Height of the map container. Default: 400.
 * @param $hideField {0; 1} - Original coordinates field hiding status (1 — hide, 0 — show). Default: 1.
 * 
 * @link http://code.divandesign.biz/modx/mm_ddgmap/1.2b
 * 
 * @copyright 2014, DivanDesign
 * http://www.DivanDesign.biz
 */
function mm_ddGMap($tvs, $roles = '', $templates = '', $w = 'auto', $h = '400', $hideField = true)
{
    if (!useThisRule($roles, $templates)) {
        return;
    }
    global $modx;
    $e =& $modx->Event;
    if ($e->name == 'OnDocFormPrerender') {
        global $modx_lang_attribute;
        //The main js file including
        $output = includeJsCss($modx->config['site_url'] . 'assets/plugins/managermanager/widgets/ddgmap/jquery.ddMM.mm_ddGMap.js', 'html', 'jquery.ddMM.mm_ddGMap', '1.0');
        //The Google.Maps library including
        $output .= includeJsCss('http://maps.google.com/maps/api/js?sensor=false&hl=' . $modx_lang_attribute . '&callback=mm_ddGMap_init', 'html', 'maps.google.com', '0');
        $e->output($output);
    } else {
        if ($e->name == 'OnDocFormRender') {
            global $mm_current_page;
            $output = '';
            $tvs = makeArray($tvs);
            $usedTvs = tplUseTvs($mm_current_page['template'], $tvs, '', 'id', 'name');
            if ($usedTvs == false) {
                return;
            }
            $output .= "//---------- mm_ddGMap :: Begin -----\n";
            //Iterate over supplied TVs instead of doing so to the result of tplUseTvs() to maintain rendering order.
            foreach ($tvs as $tv) {
                //If this $tv is used in a current template
                if (isset($usedTvs[$tv])) {
                    $output .= '
$j("#tv' . $usedTvs[$tv]['id'] . '").mm_ddGMap({
	hideField: ' . intval($hideField) . ',
	width: "' . $w . '",
	height: "' . $h . '"
});
';
                }
            }
            $output .= "//---------- mm_ddGMap :: End -----\n";
            $e->output($output);
        }
    }
}
示例#26
0
function mm_widget_template($fields, $other_param = 'defaultValue', $roles = '', $templates = '')
{
    global $modx, $content, $mm_fields;
    $e =& $modx->Event;
    if (useThisRule($roles, $templates)) {
        // Your output should be stored in a string, which is outputted at the end
        // It will be inserted as a Javascript block (with jQuery), which is executed on document ready
        $output = '';
        // if we've been supplied with a string, convert it into an array
        $fields = makeArray($fields);
        // You might want to check whether the current page's template uses the TVs that have been
        // supplied, to save processing page which don't contain them
        // 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'];
        }
        $count = tplUseTvs($content['template'], $fields);
        if ($count == false) {
            return;
        }
        // We always put a JS comment, which makes debugging much easier
        $output .= "//  -------------- Widget name ------------- \n";
        // We have functions to include JS or CSS external files you might need
        // The standard ModX API methods don't work here
        $output .= includeJs('/assets/plugins/managermanager/widgets/template/javascript.js');
        $output .= includeCss('/assets/plugins/managermanager/widgets/template/styles.css');
        // Do something for each of the fields supplied
        foreach ($fields as $targetTv) {
            // If it's a TV, we may need to map the field name, to what it's ID is.
            // This can be obtained from the mm_fields array
            $tv_id = $mm_fields[$targetTv]['fieldname'];
        }
    }
    // end if
    $e->output($output . "\n");
    // Send the output to the browser
}
示例#27
0
/**
 * mm_widget_accessdenied
 * @version 1.1 (2012-11-13)
 *
 * Close access for some documents by ids.
 * Icon by designmagus.com
 * Originally written by Metaller
 *
 * @uses ManagerManager plugin 0.4.
 *
 * @link http://code.divandesign.biz/modx/mm_widget_accessdenied/1.1
 *
 * @copyright 2012
 */
function mm_widget_accessdenied($ids = '', $message = '', $roles = '')
{
    global $modx, $content;
    $e =& $modx->event;
    if (empty($message)) {
        $message = '<span>Access denied</span>Access to current document closed for security reasons.';
    }
    if ($e->name == 'OnDocFormRender' && useThisRule($roles)) {
        $docid = (int) $_GET[id];
        $ids = makeArray($ids);
        $output = "//  -------------- accessdenied widget include ------------- \n";
        if (in_array($docid, $ids)) {
            $output .= includeCss($modx->config['base_url'] . 'assets/plugins/managermanager/widgets/accessdenied/accessdenied.css');
            $output .= '
			$j("input, div, form[name=mutate]").remove(); // Remove all content from the page
			$j("body").prepend(\'<div id="aback"><div id="amessage">' . $message . '</div></div>\');
			$j("#aback").css({height: $j("body").height()} );';
        }
        $e->output($output . "\n");
    }
}
示例#28
0
function mm_widget_googlemap($fields, $googleApiKey = '', $default = '', $roles = '', $templates = '')
{
    global $modx, $mm_fields, $mm_current_page, $modx_lang_attribute;
    $e =& $modx->event;
    if (useThisRule($roles, $templates)) {
        $output = '';
        $fields = makeArray($fields);
        $count = tplUseTvs($mm_current_page['template'], $fields);
        if ($count == false) {
            return;
        }
        $output .= "//  -------------- googlemap widget ------------- \n";
        $output .= includeJs($modx->config['base_url'] . 'assets/plugins/managermanager/widgets/googlemap/googlemap.js');
        $output .= includeJs("http://maps.google.com/maps?file=api&sensor=false&key={$googleApiKey}&async=2&hl={$modx_lang_attribute}");
        foreach ($fields as $targetTv) {
            $tv_id = $mm_fields[$targetTv]['fieldname'];
            $output .= "googlemap('{$tv_id}','{$default}');";
        }
        $e->output($output . "\n");
        // Send the output to the browser
    }
}
示例#29
0
/**
 * mm_default
 * @version 1.2 (2014-05-06)
 * 
 * @desc A widget for ManagerManager plugin that allows field (or TV) default value for a new document/folder to be set.
 * 
 * @uses ManagerManager plugin 0.6.
 * @uses ManagerManager.mm_ddSetFieldValue 1.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} - The default value for the field. The current date/time will be used for the fields equals 'pub_date' or 'unpup_date' with empty value. A static value can be supplied as a string, or PHP code (to calculate something) can be supplied if the eval parameter is set as true. 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 (when this parameter is empty then widget is applied to the all templates). Default: ''.
 * @param $eval {bollean} - Should the value be evaluated as PHP code? Default: false.
 * 
 * @event OnDocFormRender
 * 
 * @link http://code.divandesign.biz/modx/mm_default/1.2
 * 
 * @copyright 2014
 */
function mm_default($fields, $value = '', $roles = '', $templates = '', $eval = false)
{
    global $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
    if (!in_array($modx->manager->action, array('85', '4', '72'))) {
        return;
    }
    if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)) {
        // What's the new value, and does it include PHP?
        if ($eval) {
            $value = eval($value);
        }
        $e->output("//---------- mm_default :: Begin -----\n");
        mm_ddSetFieldValue($fields, $value, $roles, $templates);
        $e->output("//---------- mm_default :: End -----\n");
    }
}
示例#30
0
/**
 * mm_ddHTMLCleaner
 * @version 1.0.4 (2014-03-14)
 * 
 * @desc A widget for the plugin ManagerManager. It removes forbidden HTML attributes and styles from document fields and TVs when required.
 * 
 * @uses ManagerManager plugin 0.6.
 * 
 * @param $fields {comma separated string} - The name(s) of the document fields (or TVs) which the widget is applied to. @required
 * @param $roles {comma separated string} - 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} - Templates IDs for which the widget is applying (empty value means the widget is applying to all templates). Default: ''.
 * @param $validAttrsForAllTags {comma separated string} - Default: 'title,class'.
 * @param $validStyles {comma separated string} - Default: 'word-spacing'.
 * @param $validAttrs {string: JSON} - Default: '{"img":"src,alt,width,height","a":"href,target"}'.
 * 
 * @event OnDocFormPrerender
 * @event OnDocFormRender
 * 
 * @link http://code.divandesign.biz/modx/mm_ddhtmlcleaner/1.0.4
 * 
 * @copyright 2014, DivanDesign
 * http://www.DivanDesign.biz
 */
function mm_ddHTMLCleaner($fields, $roles = '', $templates = '', $validAttrsForAllTags = 'title,class', $validStyles = 'word-spacing', $validAttrs = '{"img":"src,alt,width,height","a":"href,target"}')
{
    if (!useThisRule($roles, $templates)) {
        return;
    }
    global $modx;
    $e =& $modx->Event;
    if ($e->name == 'OnDocFormPrerender') {
        $widgetDir = $modx->config['site_url'] . 'assets/plugins/managermanager/widgets/mm_ddhtmlcleaner/';
        $output = includeJsCss($widgetDir . 'jquery.ddHTMLCleaner-0.2.min.js', 'html', 'jquery.ddHTMLCleaner', '0.2');
        $output .= includeJsCss($widgetDir . 'jquery.ddMM.mm_ddHTMLCleaner.js', 'html', 'jquery.ddMM.mm_ddHTMLCleaner', '1.0.1');
        $e->output($output);
    } else {
        if ($e->name == 'OnDocFormRender') {
            global $mm_fields, $content;
            if ($content['contentType'] != 'text/html') {
                return;
            }
            $fields = getTplMatchedFields($fields);
            if ($fields == false) {
                return;
            }
            $selectors = array();
            foreach ($fields as $field) {
                $selectors[] = $mm_fields[$field]['fieldtype'] . '[name=\\"' . $mm_fields[$field]['fieldname'] . '\\"]';
            }
            $output = "//---------- mm_ddHTMLCleaner :: Begin -----\n";
            $output .= '
$j.ddMM.mm_ddHTMLCleaner.addInstance("' . implode(',', $selectors) . '", {
	validAttrsForAllTags: "' . $validAttrsForAllTags . '",
	validAttrs: ' . $validAttrs . ',
	validStyles: "' . $validStyles . '"
});
';
            $output .= "//---------- mm_ddHTMLCleaner :: End -----\n";
            $e->output($output);
        }
    }
}