function tagval_k($mode, $tname) { //封装 global $debugtag; $tag = read_tag($mode . 'tag', $tname); if (empty($tag) || empty($tag['tclass'])) { return $debugtag ? '{' . $mode . ' $' . $tname . '}' : ''; } $func = $mode . 'tag_val'; return $func($tname, $tag); }
function tagmap($tname, $ttype, $level = 1) { $tagsarr = array(); $tag = read_tag($ttype, $tname); if (empty($tag['template'])) { return $tagsarr; } $template = $tag['template']; $tagsarr = array_merge($tagsarr, findtags($template, 'b', $tname, $level)); $tagsarr = array_merge($tagsarr, findtags($template, 'u', $tname, $level)); $tagsarr = array_merge($tagsarr, findtags($template, 'c', $tname, $level)); return $tagsarr; }
function rtagval($tname) { global $rtags, $templatedir, $sid, $subsites; $rtag = read_tag('rtag', $tname); $sid && ($templatedir = $subsites[$sid]['templatedir']); //子站分别指定模板目录 $template = @file2str(M_ROOT . "template/{$templatedir}/" . @$rtag['template']); return $template ? $template : "{tpl\${$tname}}"; }
function add_multiplecontent_box() { //check which template is used global $post; $fileToRead = get_template_directory_uri() . '/' . $post->page_template; //read the template $fileToRead = strstr($fileToRead, '/themes/'); if (substr(strrchr($fileToRead, '/'), 1) == 'default' || substr(strrchr($fileToRead, '/'), 1) == '') { //fix for 2.9 if (substr(strrchr($fileToRead, '/'), 1)) { if ($post->post_type == 'post') { $fileToRead = substr($fileToRead, 0, -7) . 'single.php'; } else { if ($post->post_type == 'page') { $fileToRead = substr($fileToRead, 0, -7) . 'page.php'; } else { $fileToRead = substr($fileToRead, 0, -7) . 'single-' . $post->post_type . '.php'; } } } else { if ($post->post_type == 'post') { $fileToRead .= 'single.php'; } else { if ($post->post_type == 'page') { $fileToRead .= 'page.php'; } else { $fileToRead .= 'single-' . $post->post_type . '.php'; } } } } $fileToRead = validate_file_to_edit($fileToRead, $allowed_files); $fileToRead = get_real_file_to_edit($fileToRead); //first try to read the child theme, otherwise use the normal theme $themes = get_themes(); $theme = $themes[get_current_theme()]; $current_theme_url = $theme['Template']; $child_theme_url = str_replace('themes/', '', strstr(get_stylesheet_directory_uri(), 'themes/')); if (fopen(str_replace($current_theme_url, $child_theme_url, $fileToRead), 'r')) { //child theme exists $fileToRead = str_replace($current_theme_url, $child_theme_url, $fileToRead); $f = fopen($fileToRead, 'r'); } else { $f = fopen($fileToRead, 'r'); } $contents = fread($f, filesize($fileToRead)); $contents = htmlspecialchars($contents); //read the templates header, sidebar and footer, added in v1.1 $headercontents = read_tag('header', $contents); $footercontents = read_tag('footer', $contents); //multiple sidebars, v1.2 $amount_sidebars = substr_count($contents, 'get_sidebar('); $nextContent = $contents; for ($i = 0; $i < $amount_sidebars; $i++) { $sidebarcontents .= read_tag('sidebar', $nextContent); $nextContent = substr(strstr($contents, 'get_sidebar('), 13); } $contents = $headercontents . $contents . $sidebarcontents . $footercontents; //check how many content field there have to be $editors = substr_count($contents, "the_block("); $nextString = $contents; for ($i = 0; $i < $editors; $i++) { //check whether the next one is a get_the_block or the_block $get = false; $firstThe = strpos($nextString, ' the_block'); $firstGet = strpos($nextString, 'get_the_block'); if ($firstThe > $firstGet && $firstGet != 0 || $firstThe == 0) { //get_the_block is first $get = true; } //get the name from it $stringFirst = strstr($nextString, ' the_block('); if ($get) { $stringFirst = " " . strstr($nextString, 'get_the_block('); } $stringFirst = substr($stringFirst, 1); $stringLast = strstr($stringFirst, ')'); //remove single and double quotes if (!$get) { $editorName = str_replace('\'', '', str_replace('"', '', str_replace('the_block(', '', str_replace($stringLast, '', $stringFirst)))); } else { $editorName = str_replace('\'', '', str_replace('"', '', str_replace('get_the_block(', '', str_replace($stringLast, '', $stringFirst)))); } $nextString = $stringLast; //add editor $fieldName = str_replace(' ', '-', $editorName); echo '<p><strong>' . ucfirst($editorName) . '</strong></p>'; echo '<input type="hidden" name="multiplecontent_box-' . $i . '" value="' . $fieldName . '" />'; global $current_user; get_currentuserinfo(); if (get_usermeta($current_user->ID, 'rich_editing') == 'true') { //leave this away when wysigwyg is disabled echo '<a id="edButtonHTML" class="hide-if-no-js" onclick="switchEditors.go(\'multiplecontent_box-' . $fieldName . '\', \'html\');">HTML</a><a id="edButtonPreview" class="active hide-if-no-js" onclick="switchEditors.go(\'multiplecontent_box-' . $fieldName . '\', \'tinymce\');">Wysiwyg</a>'; } echo '<input type="hidden" name="multiplecontent_box-' . $fieldName . '-nonce" id="multiplecontent_box-' . $fieldName . '-nonce" value="' . wp_create_nonce("multiplecontent_box-" . $fieldName . "-nonce") . '" />' . "\n"; //nonce echo '<textarea id="multiplecontent_box-' . $fieldName . '" tabindex="2" name="multiplecontent_box-' . $fieldName . '" cols="158" class="theEditor" rows="15">'; $content = get_post_meta($post->ID, '_ot_multiplecontent_box-' . $fieldName, true); echo apply_filters('the_editor_content', $content); echo '</textarea>'; echo '<p> </p>'; } if ($editors == 0) { _e('There are no content blocks in this template.', 'cms'); } }