1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169:
<?php
$plugin_is_filter = 5 | ADMIN_PLUGIN;
$plugin_description = gettext('View available <code>content macros</code>.');
$plugin_author = "Stephen Billard (sbillard)";
$plugin_category = gettext('Development');
if (OFFSET_PATH != 2 && zp_loggedin(ZENPAGE_PAGES_RIGHTS | ZENPAGE_NEWS_RIGHTS | ALBUM_RIGHTS)) {
foreach (getEnabledPlugins() as $ext => $pn) {
$loadtype = $pn['priority'];
if ($loadtype & (FEATURE_PLUGIN | THEME_PLUGIN)) {
require_once($pn['path']);
}
}
unset($ext);
unset($pn);
$macros = getMacros();
if (!empty($macros)) {
zp_register_filter('admin_tabs', 'macro_admin_tabs');
}
}
function macro_admin_tabs($tabs) {
if (zp_loggedin(ADMIN_RIGHTS)) {
if (!isset($tabs['development'])) {
$tabs['development'] = array(
'text' => gettext("development"),
'subtabs' => NULL);
}
$tabs['development']['subtabs'][gettext("macros")] = FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/macroList/macroList_tab.php?page=macros&tab=' . gettext('macros');
$named = array_flip($tabs['development']['subtabs']);
sortArray($named);
$tabs['development']['subtabs'] = $named = array_flip($named);
$tabs['development']['link'] = array_shift($named);
return $tabs;
}
}
function macroList_show($macro, $detail) {
$warned = array();
echo '<dl>';
$warn = array();
if (preg_match('/[^\w]/', $macro)) {
$warn['identifier'] = gettext('Macro identifiers may not contain special characters.');
echo '<dt class="top"><code>[<span class="error">' . $macro . '</span>';
} else {
echo '<dt class="top"><code>[' . $macro;
}
$required = $array = false;
if ($detail['class'] == 'expression') {
preg_match_all('/\$\d+/', $detail['value'], $replacements);
foreach ($replacements as $rkey => $v) {
if (empty($v))
unset($replacements[$rkey]);
}
if (count($detail['params']) != count($replacements)) {
$warn['paremeters'] = gettext('The number of macro parameters must match the number of replacement tokens in the expression.');
}
} else if ($detail['class'] == 'function' || $detail['class'] == 'procedure') {
if (!is_callable($detail['value'])) {
$warn['method'] = sprintf(gettext('<code>%s</code> is not callable'), $detail['value']);
}
}
if (!empty($detail['params'])) {
$params = '';
$brace = '{';
for ($i = 1; $i <= count($detail['params']); $i++) {
$type = rtrim($rawtype = $detail['params'][$i - 1], '*');
if ($array) {
$params .= ' <em><span class="error">' . $type . ' %' . $i . '</span></em>';
$warn['array'] = gettext('An array parameter must be the last parameter.');
} else if ($type == $rawtype) {
if ($required) {
$params .= ' <em><span class="error">' . $type . ' %' . $i . '</span></em>';
$warn['required'] = gettext('Required parameters should not follow optional ones.');
} else {
$params = $params . ' <em>' . $type . " %$i</em>";
}
} else {
if ($detail['class'] == 'expression') {
$params = $params . " <em>$brace" . '<span class="error">' . $type . " %$i</span></em>";
$warn['expression'] = gettext('Expressions may not have optional parameters.');
} else {
$params = $params . " <em>$brace" . $type . " %$i</em>";
}
$required = true;
$brace = '';
}
$array = $array || $type == 'array';
}
if ($required)
$params .= "<em>}</em>";
echo $params;
}
echo ']</code> <em>(' . @$detail['owner'] . ')</em></dt><dd class="top">' . $detail['desc'] . '</dd>';
if (count($warn)) {
echo '<div class="notebox"><strong>Warning:</strong>';
foreach ($warn as $warning) {
echo '<p>' . $warning . '</p>';
}
echo'</div>';
}
echo '</dl>';
}
?>