本文整理汇总了PHP中jsSafe函数的典型用法代码示例。如果您正苦于以下问题:PHP jsSafe函数的具体用法?PHP jsSafe怎么用?PHP jsSafe使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了jsSafe函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mm_changeFieldHelp
/**
* 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: mm_renameSection
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: mm_renameTab
/**
* 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: mm_renameTab
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: mm_renameField
/**
* 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: mm_renameField
/**
* 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);
}
}
}
示例7: mm_renameSection
/**
* 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: mm_renameTab
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: jsSafe
$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 & Roles', 'rolestemplates', '', '', '<p>These are the IDs for current templates,tvs and roles in your site.</p>' . $template_table . ' ' . $tvs_table . ' ' . $roles_table);
$e->output('</script>');
$e->output('<!-- End ManagerManager output -->' . "\n");
示例10: mm_ddSetFieldValue
/**
* 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;
//.........这里部分代码省略.........
示例11: mm_inherit
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: mm_widget_tags
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: mm_changeFieldHelp
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: mm_widget_tags
/**
* 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: mm_default
/**
* 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) {
//.........这里部分代码省略.........