changed: plugin 'menu': ezc funtion: menu_dir_tab

now we have two parameters: first is a path and second is: "images", "dirs", "files" or empty
          


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@786 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2012-01-02 02:05:12 +00:00
parent 43470b2a41
commit 543d464cbc
5 changed files with 107 additions and 51 deletions

View File

@ -42,7 +42,7 @@
[end]
[# !! co to?]
[if winix_function_is "gallery-old"]
[if-one gallery_has_not_mount_type gallery_mount_type_arg_is "lightbox"]

View File

@ -135,9 +135,9 @@ html_lang_attr_value = "pl"
# current limitation: winix is not allowed to convert polish capital letters to lower case
# so we need to give both versions (small and capital letters)
language_orphans = ( "(np.", "a", "al.", "ale", "bo", "bp", "by", "co", "cz.", "czy", "dn.",
language_orphans = ( "(np.", "a", "al.", "ale", "aż", "aŻ", "bo", "bp", "by", "co", "cz.", "czy", "dn.",
"doc.", "dr", "dyr.", "dz.", "do", "ds.", "fot.", "go", "godz.", "i",
"ich", "im.", "inż.", "inŻ.", "ja", "je", "jej", "jest", "już", "juŻ", "ją",
"ich", "im.", "inż.", "inŻ.", "iż", "iŻ", "ja", "je", "jej", "jest", "już", "juŻ", "ją",
"jĄ", "ks.", "ku", "li", "m.in.", "mgr", "mi", "na", "nie", "np.", "nr",
"o", "od", "os.", "ów", "Ów", "po", "prof.", "s.", "są", "sĄ", "ta",
"to", "tu", "tą", "tĄ", "tel.", "tę", "tĘ", "u", "ul.", "w", "we", "wg",

View File

@ -15,17 +15,19 @@
// !! temporarily
template<class Key, class Value>
template<class Key1, class Key2, class Value>
class Stack
{
public:
typedef Key StackKey;
typedef Key1 StackKey1;
typedef Key2 StackKey2;
typedef Value StackValue;
struct Item
{
StackKey key;
StackKey1 key1;
StackKey2 key2;
StackValue value;
};
@ -37,11 +39,11 @@ public:
StackValue * Get(const StackKey & key)
StackValue * Get(const StackKey1 & key1, const StackKey2 & key2)
{
for(size_t i=0 ; i<tab.size() ; ++i)
{
if( tab[i].key == key )
if( tab[i].key1 == key1 && tab[i].key2 == key2 )
{
added_new = false;
return &tab[i].value;
@ -52,7 +54,8 @@ public:
// so we add a new item
tab.push_back(Item());
tab.back().key = key;
tab.back().key1 = key1;
tab.back().key2 = key2;
added_new = true;
return &tab.back().value;
@ -107,12 +110,12 @@ struct MenuDir
static MenuDir * menu_dir = 0;
static DbItemQuery iq;
static Stack<std::wstring, MenuDir> menu_dir_stack;
static Stack<std::wstring, std::wstring, MenuDir> menu_dir_stack;
static size_t req_id = 0;
static std::wstring strempty;
// O(n^2) complexity
// warning: O(n^2) complexity
void menu_dir_skip_items(long parent_id)
{
Mount * m = system->mounts.CalcMount(parent_id);
@ -135,20 +138,19 @@ void menu_dir_skip_items(long parent_id)
}
void menu_dir_skip_static_files()
{
for(size_t x=0 ; x<menu_dir->items.size() ; )
{
if( menu_dir->items[x].type == Item::file && menu_dir->items[x].file_type != WINIX_ITEM_FILETYPE_NONE )
menu_dir->items.erase(menu_dir->items.begin() + x);
else
x += 1;
}
void menu_dir_skip_static_files()
{
for(size_t x=0 ; x<menu_dir->items.size() ; )
{
if( menu_dir->items[x].type == Item::file && menu_dir->items[x].file_type != WINIX_ITEM_FILETYPE_NONE )
menu_dir->items.erase(menu_dir->items.begin() + x);
else
x += 1;
}
}
void menu_dir_load_menu(long parent_id)
void menu_dir_load_menu(long parent_id, const std::wstring & arg)
{
iq.SetAll(false, false);
iq.sel_subject = true;
@ -158,39 +160,54 @@ void menu_dir_load_menu(long parent_id)
iq.sel_file = true;
iq.WhereParentId(parent_id);
db->GetItems(menu_dir->items, iq);
if( arg == L"images" )
{
iq.WhereType(Item::file);
iq.WhereFileType(WINIX_ITEM_FILETYPE_IMAGE);
}
else
if( arg == L"dirs" )
{
iq.WhereType(Item::dir);
}
else
if( arg == L"files" )
{
iq.WhereType(Item::file);
}
else
if( arg == L"" )
{
}
else
{
log << log1 << "Menu: unknown parameter: " << arg << logend;
}
db->GetItems(menu_dir->items, iq);
menu_dir_skip_items(parent_id);
menu_dir_skip_static_files();
// !! FIXME: in the future is better to have DbItemQuery with a special option
// that skips static files
if( arg == L"" )
menu_dir_skip_static_files();
// !! temporarily for debug purposes
log << log1 << "Menu: db used" << logend;
}
void menu_dir_init(const std::wstring & path)
void menu_dir_init(const std::wstring & path, const std::wstring & arg)
{
if( cur->request->id != req_id )
{
menu_dir_stack.Clear();
req_id = cur->request->id;
}
menu_dir = menu_dir_stack.Get(path);
if( !path.empty() && path[0] != '/' )
{
log << log1 << "Menu: path for menu should not be relative" << logend;
return;
}
menu_dir = menu_dir_stack.Get(path, arg);
if( menu_dir_stack.AddedNew() )
{
if( path.empty() )
{
// current directory
menu_dir_load_menu(cur->request->dir_tab.back()->id);
menu_dir_load_menu(cur->request->dir_tab.back()->id, arg);
system->dirs.MakePath(cur->request->dir_tab, menu_dir->dir);
}
else
@ -199,7 +216,7 @@ void menu_dir_init(const std::wstring & path)
Item * pdir = system->dirs.GetDir(path);
if( pdir )
menu_dir_load_menu(pdir->id);
menu_dir_load_menu(pdir->id, arg);
else
log << log1 << "Menu: I cannot find a directory: " << path << logend;
}
@ -208,9 +225,37 @@ void menu_dir_init(const std::wstring & path)
void menu_dir_init(const std::vector<std::wstring> & params)
{
if( cur->request->id != req_id )
{
menu_dir_stack.Clear();
menu_dir = 0;
req_id = cur->request->id;
}
if( !params.empty() && !params[0].empty() && params[0][0] != '/' )
{
log << log1 << "Menu: path for a menu should not be relative" << logend;
return;
}
strempty.clear(); // for safety
if( params.empty() )
menu_dir_init(strempty, strempty);
else
if( params.size() == 1 )
menu_dir_init(params[0], strempty);
else
menu_dir_init(params[0], params[1]);
}
void menu_dir_tab(Info & i)
{
menu_dir_init(i.par);
menu_dir_init(i.params);
menu_dir->index = i.iter;
i.res = menu_dir->index < menu_dir->items.size();
@ -219,14 +264,14 @@ void menu_dir_tab(Info & i)
void menu_dir_tab_subject(Info & i)
{
if( menu_dir->index < menu_dir->items.size() )
if( menu_dir && menu_dir->index < menu_dir->items.size() )
i.out << menu_dir->items[menu_dir->index].subject;
}
void menu_dir_tab_url(Info & i)
{
if( menu_dir->index < menu_dir->items.size() )
if( menu_dir && menu_dir->index < menu_dir->items.size() )
i.out << menu_dir->items[menu_dir->index].url;
}
@ -236,7 +281,7 @@ void menu_dir_tab_url(Info & i)
void menu_dir_tab_link(Info & i)
{
if( menu_dir->index < menu_dir->items.size() )
if( menu_dir && menu_dir->index < menu_dir->items.size() )
{
i.out << menu_dir->dir;
@ -251,7 +296,7 @@ void menu_dir_tab_link(Info & i)
void menu_dir_tab_is_current(Info & i)
{
if( menu_dir->index < menu_dir->items.size() )
if( menu_dir && menu_dir->index < menu_dir->items.size() )
{
i.res = (menu_dir->items[menu_dir->index].id == cur->request->last_item->id);
}
@ -263,7 +308,7 @@ void menu_dir_tab_is_current(Info & i)
// returning true if the dir tab element is a first parent for current item
void menu_dir_tab_is_first_parent_for_current_item(Info & i)
{
if( menu_dir->index < menu_dir->items.size() )
if( menu_dir && menu_dir->index < menu_dir->items.size() )
i.res = (menu_dir->items[menu_dir->index].id == cur->request->last_item->parent_id);
}
@ -272,7 +317,7 @@ void menu_dir_tab_is_first_parent_for_current_item(Info & i)
// (it don't have to be the first parent - it can be a descendant)
void menu_dir_tab_is_parent_for_current_item(Info & i)
{
if( menu_dir->index < menu_dir->items.size() )
if( menu_dir && menu_dir->index < menu_dir->items.size() )
{
size_t len = cur->request->dir_tab.size(); // at least one

View File

@ -550,6 +550,7 @@ ul.galleryimages li {
display: block;
float: left;
margin: 0 0 6px 10px;
background: none;
}
ul.galleryimages a, ul.galleryimages a:hover, ul.galleryimages a:focus, ul.galleryimages a:active {
@ -599,8 +600,12 @@ height: 50px;
div#fileupload {
font-size: 0.8em;
font-size: 11px;
/* warning: file upload "add file" button doesn't want to work for small fonts in Firefox */
}
div#fileupload table, div#fileupload th, div#fileupload td {
border: none;
}

View File

@ -889,6 +889,7 @@ ul.galleryimages li {
display: block;
float: left;
margin: 0 0 6px 10px;
background: none;
}
ul.galleryimages a, ul.galleryimages a:hover, ul.galleryimages a:focus, ul.galleryimages a:active {
@ -938,6 +939,11 @@ height: 50px;
div#fileupload {
font-size: 0.8em;
font-size: 11px;
/* warning: file upload "add file" button doesn't want to work for small fonts in Firefox */
}
div#fileupload table, div#fileupload th, div#fileupload td {
border: none;
}