Esempio n. 1
0
function text_field($text, $set_width = false, $wrapper = false)
{
    $text = get_field($text);
    $set_width = $set_width === true ? 'class="panel__text"' : false;
    if ($wrapper === true) {
        if (variable_exists($text)) {
            echo '<p ' . $set_width . '>' . $text . '</p>';
        }
    } else {
        echo $text;
    }
}
function parse_template($tpl_input_string, $site_id = '1')
{
    // Take $tpl_input_string and replace values between <tpl> and </tpl> tags
    // with corresponding variables
    global $dbhost, $dbusername, $dbpassword, $default_dbname, $tpl_template_set;
    global $tpl_global_variable_statement_string;
    eval($tpl_global_variable_statement_string);
    // Only continue if we've got some variables
    if ($tpl_global_variable_statement_string != "global \$tpl_local_templates, \$;") {
        eval($tpl_global_variable_statement_string);
        // Get a list of the variables stored in the template system
        if (!isset($tpl_template_set)) {
            // Get them from database
            $link_id = db_connect();
            $tpl_template_names = get_variable_names($link_id, $site_id);
        } else {
            $tpl_template_names = extract_templates_from_global_string($tpl_global_variable_statement_string);
        }
        // Loop through $tpl_input_string, check whether variable exists and replace
        do {
            $tpl_start_pos = strpos($tpl_input_string, "<tpl>");
            $tpl_end_pos = strpos($tpl_input_string, "</tpl>", $tpl_start_pos) + 5;
            $tpl_found_long_variable_name = substr($tpl_input_string, $tpl_start_pos, $tpl_end_pos - $tpl_start_pos + 1);
            $tpl_found_short_variable_name = extract_variable_name($tpl_found_long_variable_name);
            if (variable_exists($tpl_template_names, $tpl_found_long_variable_name) == 1) {
                // Replace found variable name with its contents
                eval("\$tpl_output_string=str_replace(\"{$tpl_found_long_variable_name}\",\${$tpl_found_short_variable_name},\"{$tpl_input_string}\");");
            } else {
                // See if found variable is a local variable. If it is, then replace it too
                if (exist_local_template($tpl_found_short_variable_name)) {
                    eval("\$tpl_output_string=str_replace(\"{$tpl_found_long_variable_name}\",\$tpl_local_templates[\"{$tpl_found_short_variable_name}\"],\"{$tpl_input_string}\");");
                } else {
                    eval("\$tpl_output_string=str_replace(\"{$tpl_found_long_variable_name}\",\"\",\"{$tpl_input_string}\");");
                }
            }
            $tpl_input_string = $tpl_output_string;
        } while (strstr($tpl_input_string, "<tpl>") && strstr($tpl_input_string, "</tpl>"));
        // Display parsed string to browser
        echo $tpl_output_string;
    }
}