Ejemplo n.º 1
0
/**
 * Parse Navigate CMS tags like:
 * <ul>
 * <li>&lt;nv object="list"&gt;&lt;/nv&gt;</li>
 * <li>&lt;nv object="search"&gt;&lt;/nv&gt;</li>
 * <li>&lt;nv object="conditional"&gt;&lt;/nv&gt;</li>
 * </ul>
 *
 * Generate the final HTML code for these special tags or convert them
 * to a simpler nv tags.
 *
 * @param $html
 * @return mixed
 */
function nvweb_template_parse_lists($html, $process_delayed = false)
{
    global $current;
    if ($process_delayed) {
        // time to process delayed nvlists and nvsearches
        foreach ($current['delayed_nvlists'] as $uid => $vars) {
            $content = nvweb_list($vars);
            $html = str_replace('<!--#' . $uid . '#-->', $content, $html);
        }
        foreach ($current['delayed_nvsearches'] as $uid => $vars) {
            $content = nvweb_search($vars);
            $html = str_replace('<!--#' . $uid . '#-->', $content, $html);
        }
        return $html;
    }
    // parse special navigate tags (includes, lists, searches...)
    $tags = nvweb_tags_extract($html, 'nv', true, true, 'UTF-8');
    foreach ($tags as $tag) {
        $content = '';
        $changed = false;
        switch ($tag['attributes']['object']) {
            case 'list':
                $template_end = nvweb_templates_find_closing_list_tag($html, $tag['offset']);
                $tag['length'] = $template_end - $tag['offset'] + strlen('</nv>');
                // remove tag characters
                $list = substr($html, $tag['offset'] + strlen($tag['full_tag']), $tag['length'] - strlen('</nv>') - strlen($tag['full_tag']));
                @(include_once NAVIGATE_PATH . '/lib/webgets/list.php');
                $vars = array_merge($tag['attributes'], array('template' => $list));
                if ($tag['attributes']['delayed'] == 'true') {
                    $list_uid = uniqid('nvlist-');
                    $current['delayed_nvlists'][$list_uid] = $vars;
                    $html = substr_replace($html, '<!--#' . $list_uid . '#-->', $tag['offset'], $tag['length']);
                    $changed = true;
                    continue;
                }
                $content = nvweb_list($vars);
                $html = substr_replace($html, $content, $tag['offset'], $tag['length']);
                $changed = true;
                break;
            case 'search':
                $template_end = nvweb_templates_find_closing_list_tag($html, $tag['offset']);
                $tag['length'] = $template_end - $tag['offset'] + strlen('</nv>');
                // remove tag characters
                $search = substr($html, $tag['offset'] + strlen($tag['full_tag']), $tag['length'] - strlen('</nv>') - strlen($tag['full_tag']));
                @(include_once NAVIGATE_PATH . '/lib/webgets/search.php');
                $vars = array_merge($tag['attributes'], array('template' => $search));
                if ($tag['attributes']['delayed'] == 'true') {
                    $search_uid = uniqid('nvsearch-');
                    $current['delayed_nvsearches'][$search_uid] = $vars;
                    $html = substr_replace($html, '<!--#' . $search_uid . '#-->', $tag['offset'], $tag['length']);
                    $changed = true;
                    continue;
                }
                $content = nvweb_search($vars);
                $html = substr_replace($html, $content, $tag['offset'], $tag['length']);
                $changed = true;
                break;
            case 'conditional':
                $template_end = nvweb_templates_find_closing_list_tag($html, $tag['offset']);
                $tag['length'] = $template_end - $tag['offset'] + strlen('</nv>');
                // remove tag characters
                $conditional = substr($html, $tag['offset'] + strlen($tag['full_tag']), $tag['length'] - strlen('</nv>') - strlen($tag['full_tag']));
                @(include_once NAVIGATE_PATH . '/lib/webgets/conditional.php');
                $vars = array_merge($tag['attributes'], array('_template' => $conditional));
                $content = nvweb_conditional($vars);
                $html = substr_replace($html, $content, $tag['offset'], $tag['length']);
                $changed = true;
                break;
        }
        if ($changed) {
            // ok, we've found and processed ONE special tag
            // now the HTML has changed, so the original positions of the special <nv> tags have also changed
            // we must finish the current loop and start a new one
            $html = nvweb_template_parse_lists($html);
            break;
        }
    }
    return $html;
}
Ejemplo n.º 2
0
 $html = nvweb_plugins_event('before_parse', $html);
 $html = nvweb_theme_settings($html);
 $html = nvweb_template_parse_lists($html);
 $html = nvweb_template_parse($html);
 // if the content has added any nv tag, process them
 if (strpos($html, '{{nv ') !== false || strpos($html, '<nv ')) {
     $html = nvweb_template_parse_special($html);
     $html = nvweb_template_parse_lists($html);
     $html = nvweb_template_parse($html);
 }
 // if we have a delayed nv list we need to parse it now
 if (!empty($current['delayed_nvlists']) || !empty($current['delayed_nvsearches'])) {
     $html = nvweb_template_parse_lists($html, true);
     if (strpos($html, '{{nv ') !== false || strpos($html, '<nv ')) {
         $html = nvweb_template_parse_special($html);
         $html = nvweb_template_parse_lists($html);
         $html = nvweb_template_parse($html);
     }
 }
 $html = nvweb_template_oembed_parse($html);
 $html = nvweb_template_processes($html);
 $end .= nvweb_after_body('php');
 $end = nvweb_after_body('html');
 $end .= nvweb_after_body('js');
 $end .= "\n\n";
 $end .= '</body>';
 $html = str_replace('</body>', $end, $html);
 $html = nvweb_template_tweaks($html);
 $html = nvweb_template_restore_special($html);
 $events->trigger('theme', 'after_parse', array('html' => &$html));
 $html = nvweb_plugins_event('after_parse', $html);