コード例 #1
0
/**
 * get grouped array of content or page templates
 *
 * @param string $type [CONTENT|PAGE]
 * @param integer $selected_template
 * @return array
 */
function get_templates($type, $selected_template)
{
    global $site;
    global $class_path;
    global $objekt;
    // TODO: get rid of global objekt
    include_once $class_path . "extension.class.php";
    # for printing extensions template groups
    $template_data = array();
    ##########################
    # general SQL:
    # show visible templates that
    # are allowewd by modules or not depending on any module at all
    $gen_sql = $site->db->prepare("SELECT templ_tyyp.ttyyp_id,templ_tyyp.nimi,templ_tyyp.templ_fail,templ_tyyp.extension\r\n\t\tFROM templ_tyyp\r\n\t\tWHERE (templ_tyyp.on_nahtav='1'" . ($objekt->all['ttyyp_id'] ? ' or templ_tyyp.ttyyp_id = ' . $objekt->all['ttyyp_id'] : '') . ($objekt->all['page_ttyyp_id'] ? ' or templ_tyyp.ttyyp_id = ' . $objekt->all['page_ttyyp_id'] : '') . ")");
    $sql_user_defined = " AND (templ_tyyp.ttyyp_id >= 1000 AND templ_tyyp.ttyyp_id < 2000) ";
    $sql_saurus3 = " AND (templ_tyyp.ttyyp_id < 1000 OR templ_tyyp.ttyyp_id >= 2000) ";
    $sql_no_extension = " AND (templ_tyyp.extension = '' OR ISNULL(templ_tyyp.extension)) ";
    $sql_extension = " AND (templ_tyyp.extension <> '' OR NOT ISNULL(templ_tyyp.extension)) ";
    $sql_page_templ = " AND templ_tyyp.on_page_templ = '1' ";
    $sql_content_templ = " AND templ_tyyp.on_page_templ = '0' ";
    $order_by = " ORDER BY templ_tyyp.nimi ";
    ################################
    # 1. CONTENT Template selectbox
    ############################
    # group USER DEFINED:
    # SAPI templates (ttyyp_id >= 1000), not predefined (ttyyp_id < 2000), not extension template
    $sql = $gen_sql . ($type == 'CONTENT' ? $sql_content_templ : $sql_page_templ) . $sql_no_extension . $sql_user_defined;
    $sql .= $order_by;
    $sth = new SQL($sql);
    # if found templates
    if ($sth->rows) {
        while ($templ = $sth->fetch()) {
            $template_data['User defined'][$templ['ttyyp_id']] = $templ;
        }
    }
    # if found templates
    ############################
    # group EXTENSIONS:
    # SAPI extension CONTENT templates
    $sql = $gen_sql . ($type == 'CONTENT' ? $sql_content_templ : $sql_page_templ) . $sql_extension;
    $sql .= $order_by;
    # print extensions templates rows and get selected template array
    $template_data = array_merge($template_data, get_extension_templates($sql));
    ############################
    # group SAURUS 3 (was PREDEFINED):
    # BUILT-IN PHP-templates (ttyyp_id < 1000) + predefined SAPI templates (ttyyp_id >= 2000)
    $sql = $gen_sql . ($type == 'CONTENT' ? $sql_content_templ : $sql_page_templ) . $sql_no_extension . $sql_saurus3;
    $sql .= $order_by;
    $sth = new SQL($sql);
    # if found templates
    if ($sth->rows) {
        $tmp_templ_arr = array();
        $tmp_arr = array();
        while ($templ = $sth->fetch()) {
            $tmp_templ_arr[$site->sys_sona(array(sona => $templ['nimi'], tyyp => "system"))] = $templ;
            $tmp_arr[] = $site->sys_sona(array(sona => $templ['nimi'], tyyp => "system"));
        }
        asort($tmp_arr);
        reset($tmp_arr);
        foreach ($tmp_arr as $templ_name) {
            $templ = $tmp_templ_arr[$templ_name];
            if ($selected_template == $templ['ttyyp_id']) {
                $ttyyp = $templ;
            }
            $template_data['Saurus 3'][$templ['ttyyp_id']] = $templ;
        }
    }
    # if found templates
    ############################
    # CONTENT TEMPLATE configuration
    # arvestame, et konfigureeritavad v�ivad olla ainult v3 fiks php sisumallid
    if ($ttyyp[on_konfigureeritav]) {
        # -----------------------
        # Templaidi konfigureerimine
        # -----------------------
        if ($ttyyp[templ_fail] && file_exists("../" . $ttyyp[templ_fail])) {
            include_once "../" . $ttyyp[templ_fail];
        }
        if (function_exists("edit_params")) {
            // TODO: get rid of html buffering
            ob_start();
            edit_params(array(objekt => $objekt));
            $template_data['template_variable_html'] = ob_get_contents();
            ob_end_clean();
        }
    }
    # / template configuration
    ############################
    return $template_data;
}
コード例 #2
0
/**
* print_extension_templates (public)
* 
* Reads directory "extensions/" and displays template groups for each one.
* Prints out selectbox content: <option .. > rows
* 
* Return record data array of curretly selected template
*
* @package CMS
* 
*/
function print_extension_templates($sql, $selected_value)
{
    global $site;
    $ext_templ_arr = get_extension_templates($sql);
    foreach ($ext_templ_arr as $ext_title => $extension) {
        print '<optgroup label="' . $ext_title . '">';
        foreach ($ext_templ_arr[$ext_title] as $templ_id => $templ) {
            if ($templ['ttyyp_id'] == $selected_value) {
                $ttyyp = $templ;
            }
            print "<option value=\"" . $templ['ttyyp_id'] . "\"" . ($selected_value == $templ['ttyyp_id'] ? " selected" : "") . ($templ['ttyyp_id'] == $objekt->all['ttyyp_id'] || $templ['ttyyp_id'] == $objekt->all['page_ttyyp_id'] ? " style=\"color: #a7a6aa;\"" : "") . ">";
            print $templ['nimi'];
            print "</option>\n";
        }
        print '</optgroup>';
    }
    # if found templates for this extension
    ### return selected template array
    return $ttyyp;
}