Beispiel #1
0
$user = new usersMenus();
if ($user->AsSquidAdministrator == false) {
    $tpl = new templates();
    echo "alert('" . $tpl->javascript_parse_text("{ERROR_NO_PRIVS}") . "');";
    die;
    exit;
}
if (isset($_POST["TEMPLATE_DATA"])) {
    TEMPLATE_SAVE();
}
if (isset($_GET["popup"])) {
    popup();
    exit;
}
if (isset($_GET["templates-list"])) {
    templates_list();
    exit;
}
if (isset($_GET["TEMP"])) {
    FormTemplate();
    exit;
}
js();
function js()
{
    $tpl = new templates();
    $page = CurrentPageName();
    $title = $tpl->_ENGINE_parse_body("{squid_templates_error}");
    $html = "\n\t\tYahooWin2('360','{$page}?popup=yes','{$title}');\n\t\n\t";
    echo $html;
}
 function templates_list_cells($label, $name, $selected_id = null, $special_option = false)
 {
     $controls = templates_list($name, $selected_id, $special_option);
     View::get()->addComboControls($label, $controls);
 }
function templates_view()
{
    global $USER, $CFG;
    $run_result = "";
    $user_template = user_info('template_name', $USER->ident);
    $sitename = sitename;
    $title = __gettext("Select / Create / Edit Themes");
    // gettext variable
    $header = __gettext("Public Themes");
    // gettext variable
    $desc = sprintf(__gettext("The following are public themes that you can use to change the way your %s looks - these do not change the content only the appearance. Check the preview and then select the one you want. If you wish you can adapt one of these using the 'create theme' option below."), $sitename);
    // gettext variable
    $panel = <<<END

    <h2>{$title}</h2>
    <form action="" method="post">
    <h3>
        {$header}
    </h3>
    <p>
        {$desc}
    </p>
    
END;
    /*
            $template_list[] = array(
                                        'name' => __gettext("Default Theme"),
                                        'shortname' => "Default_Template",
                                        'id' => -1
                                    );
    */
    $template_list = templates_list();
    foreach ($template_list as $template) {
        if ($template['name'] == "Default Template") {
            $template['name'] = __gettext("Default Template");
        }
        $name = "<input type='radio' name='selected_template' value='" . $template['shortname'] . "' ";
        if ($template['shortname'] == $user_template) {
            $name .= "checked=\"checked\"";
        }
        $name .= " /> ";
        $column1 = "<b>" . $template['name'] . "</b>";
        $column2 = "<a href=\"" . url . "mod/template/preview.php?template_preview=" . $template['shortname'] . "\" target=\"preview\">" . __gettext("Preview") . "</a>";
        $panel .= templates_draw(array('context' => 'adminTable', 'name' => $name, 'column1' => $column1, 'column2' => $column2));
    }
    $templates = get_records('templates', 'owner', $USER->ident);
    $header2 = __gettext("Personal themes");
    // gettext variable
    $desc2 = __gettext("These are themes that you have created. You can edit and delete these. These theme(s) only control actual look and feel - you cannot change any content here. To change any of your content you need to use the other menu options such as: edit profile, update weblog etc.");
    // gettext variable
    if (is_array($templates) && sizeof($templates) > 0) {
        $panel .= <<<END
    <h3>
        {$header2}
    </h3>
    <p>
        {$desc2}
    </p>
        
END;
        foreach ($templates as $template) {
            $name = "<input type='radio' name='selected_template' value='db" . $template->ident . "'";
            if ($template->shortname == $user_template) {
                $name .= " checked=\"checked\"";
            }
            $name .= " /> ";
            $column1 = "<b>" . $template->name . "</b>";
            $column2 = "<a href=\"" . url . "mod/template/preview.php?template_preview=" . $template->shortname . "\" target=\"preview\">" . __gettext("Preview") . "</a>";
            $column2 .= " | <a href=\"" . url . "mod/template/edit.php?id=" . $template->ident . "\" >" . __gettext("Edit") . "</a>";
            $column2 .= " | <a href=\"" . url . "mod/template/?action=deletetemplate&amp;delete_template_id=" . $template->ident . "\"  onclick=\"return confirm('" . __gettext("Are you sure you want to permanently remove this template?") . "')\">" . __gettext("Delete") . "</a>";
            $panel .= templates_draw(array('context' => 'adminTable', 'name' => $name, 'column1' => $column1, 'column2' => $column2));
        }
    }
    $ownerCommunities = get_records('users', 'owner', $USER->ident);
    $header3 = __gettext("Change templates");
    $decs3 = __gettext("The selected changes will affect:");
    $panel .= <<<END
<br />
    <h2>
        {$header3}
    </h2>
    <p>
        {$decs3}
    </p>
END;
    $name = "<input type='checkbox' name='affected_areas[]' value='" . $USER->ident . "' checked=\"checked\" />";
    $column1 = "<h4>User page</h4>";
    $column2 = "<h4>" . __gettext("Your personal space") . "</h4>";
    $panel .= templates_draw(array('context' => 'adminTable', 'name' => $name, 'column1' => $column1, 'column2' => $column2));
    if (!empty($ownerCommunities)) {
        foreach ($ownerCommunities as $ownerCommunity) {
            $name = "<input type='checkbox' name='affected_areas[]' value='" . $ownerCommunity->ident . "' />";
            $column1 = "<h4>" . stripslashes($ownerCommunity->name) . "</h4>";
            $column2 = "<h4>" . __gettext("Community: ") . stripslashes($ownerCommunity->name) . "</h4>";
            $panel .= templates_draw(array('context' => 'adminTable', 'name' => $name, 'column1' => $column1, 'column2' => $column2));
        }
    }
    $submitValue = __gettext("Select new theme");
    // gettext variable
    $panel .= <<<END
    
        <p>
            <input type="submit" value="{$submitValue}" />
            <input type="hidden" name="action" value="templates:select" />
        </p>
        
    </form>
    
END;
    $run_result .= $panel;
    return $run_result;
}
Beispiel #4
0
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new template();
    switch ($_REQUEST['act']) {
        case 'json':
        case 1:
            // json data retrieval & operations
            switch ($_REQUEST['oper']) {
                case 'del':
                    // remove rows
                    $ids = $_REQUEST['ids'];
                    foreach ($ids as $id) {
                        $item->load($id);
                        $item->delete();
                    }
                    echo json_encode(true);
                    break;
                default:
                    // list or search
                    // we have to merge the theme templates with the custom private templates (which are defined in the DB)
                    // as we don't expect a lot of templates, we will always return the whole dataset
                    // for this reason, paginate is useless
                    $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'];
                    if (isset($_REQUEST['quicksearch'])) {
                        $dataset = template::search($orderby, array('quicksearch' => $_REQUEST['quicksearch']));
                    } else {
                        $dataset = template::search($orderby);
                    }
                    $total = count($dataset);
                    $out = array();
                    $permissions = array(0 => '<img src="img/icons/silk/world.png" align="absmiddle" /> ' . t(69, 'Published'), 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" /> ' . t(70, 'Private'), 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" /> ' . t(81, 'Hidden'));
                    if (empty($dataset)) {
                        $rows = 0;
                    } else {
                        $rows = count($dataset);
                    }
                    for ($i = 0; $i < $rows; $i++) {
                        $out[$i] = array(0 => $dataset[$i]['id'], 1 => $dataset[$i]['title'], 2 => $dataset[$i]['theme'], 3 => $permissions[$dataset[$i]['permission']], 4 => $dataset[$i]['enabled'] == 1 ? '<img src="img/icons/silk/accept.png" />' : '<img src="img/icons/silk/cancel.png" />');
                    }
                    navitable::jqgridJson($out, 1, 0, PHP_INT_MAX, $total);
                    break;
            }
            core_terminate();
            break;
        case 'load':
        case 2:
            // edit/new form
            if (!empty($_REQUEST['id'])) {
                if (is_numeric($_REQUEST['id'])) {
                    $item->load(intval($_REQUEST['id']));
                } else {
                    $item->load_from_theme($_REQUEST['id']);
                }
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    if (!empty($_REQUEST['property-enabled'])) {
                        $enableds = array_values($_REQUEST['property-enabled']);
                    } else {
                        $enableds = array();
                    }
                    property::reorder("template", $item->id, $_REQUEST['template-properties-order'], $enableds);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'save', $item->title, json_encode($_REQUEST));
            } else {
                users_log::action($_REQUEST['fid'], $item->id, 'load', $item->title);
            }
            $out = templates_form($item);
            break;
        case 'save_template_file':
            // save template html
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            $data = $_REQUEST['templates-file-edit-area'];
            $data = str_replace("\r\n", "\r", $data);
            $x = file_put_contents(NAVIGATE_PRIVATE . '/' . $website->id . '/templates/' . $item->file, $data);
            echo json_encode($x > 0);
            session_write_close();
            exit;
            break;
        case 4:
            // remove
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = templates_list();
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = webdictionary_list();
                }
                users_log::action($_REQUEST['fid'], $item->id, $item->title, 'remove');
            }
            break;
        case 'template_property_load':
            $property = new property();
            if (!empty($_REQUEST['id'])) {
                if (is_numeric($_REQUEST['id'])) {
                    $property->load(intval($_REQUEST['id']));
                } else {
                    $property->load_from_theme($_REQUEST['id'], null, 'template', $_REQUEST['template']);
                }
            }
            header('Content-type: text/json');
            $types = property::types();
            $property->type_text = $types[$property->type];
            echo json_encode($property);
            session_write_close();
            exit;
            break;
        case 'template_property_save':
            // save property details
            $property = new property();
            if (!empty($_REQUEST['property-id'])) {
                $property->load(intval($_REQUEST['property-id']));
            }
            $property->load_from_post();
            $property->save();
            header('Content-type: text/json');
            $types = property::types();
            $property->type_text = $types[$property->type];
            echo json_encode($property);
            session_write_close();
            exit;
            break;
        case 'template_property_remove':
            // remove property
            $property = new property();
            if (!empty($_REQUEST['property-id'])) {
                $property->load(intval($_REQUEST['property-id']));
            }
            $property->delete();
            session_write_close();
            exit;
            break;
        case 0:
            // list / search result
        // list / search result
        default:
            $out = templates_list();
            break;
    }
    return $out;
}