Index: /extensions/PWG_Stuffs/admin/add_module.inc.php =================================================================== --- /extensions/PWG_Stuffs/admin/add_module.inc.php (revision 9409) +++ /extensions/PWG_Stuffs/admin/add_module.inc.php (revision 9410) @@ -72,5 +72,5 @@ $query = ' -INSERT INTO ' . STUFFS_TABLE . ' ( id, pos, name, descr, path, parent, datas, users, groups, show_title, on_home, on_root, on_cats, on_picture, id_line, width ) +INSERT INTO ' . STUFFS_TABLE . ' ( id, pos, name, descr, path, datas, users, groups, show_title, on_home, on_root, on_cats, on_picture, id_line, width ) VALUES (' . $next_element_id . ' , ' . $pos . ', @@ -78,5 +78,4 @@ ' . $desc . ', "' . $module_path . '", - ' . (isset($modules[$module_path]['parent']) ? '"'.$modules[$module_path]['parent'].'"' : 'NULL') .', ' . $sav_datas . ', ' . $users . ', Index: /extensions/PWG_Stuffs/admin/admin.php =================================================================== --- /extensions/PWG_Stuffs/admin/admin.php (revision 9409) +++ /extensions/PWG_Stuffs/admin/admin.php (revision 9410) @@ -7,5 +7,5 @@ load_language('plugin.lang', STUFFS_PATH); include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); -include_once(STUFFS_PATH . 'include/functions.inc.php'); +include_once(STUFFS_PATH . 'functions.inc.php'); $my_base_url = get_admin_plugin_menu_link(__FILE__); @@ -42,9 +42,4 @@ { $module['path'] = PHPWG_ROOT_PATH.trim($module['path'], './').'/'; - - if (preg_match('#^'.preg_quote(PHPWG_PLUGINS_PATH).'([^/]*?)/#', $module['path'], $match) and $match[1] != 'PWG_Stuffs') - { - $module['parent'] = $match[1]; - } $modules[$module['path']] = $module; } Index: /extensions/PWG_Stuffs/admin/manage.inc.php =================================================================== --- /extensions/PWG_Stuffs/admin/manage.inc.php (revision 9409) +++ /extensions/PWG_Stuffs/admin/manage.inc.php (revision 9410) @@ -37,5 +37,5 @@ // Display -$q = 'SELECT id, name, descr, path, parent, id_line, width, datas +$q = 'SELECT id, name, descr, path, id_line, width, datas FROM ' . STUFFS_TABLE . ' ORDER BY pos ASC;'; @@ -60,4 +60,11 @@ $module['name'] = !empty($module['path']) ? $module['name'] : l10n('stuffs_main_block'); + $missing = false; + if (!empty($module['path'])) + { + preg_match('#^'.preg_quote(PHPWG_PLUGINS_PATH).'([^/]*?)/#', $module['path'], $match); + $missing = !isset($pwg_loaded_plugins[$match[1]]); + } + $template->append('modules', array( 'ID' => $module['id'], @@ -73,5 +80,5 @@ 'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin§ion=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php&tab=edit_module&edit='.$module['id'], 'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin§ion=' . STUFFS_DIR . '%2Fadmin%2Fadmin.php&del=' . $module['id'] : '', - 'MISSING' => (isset($module['parent']) and !isset($pwg_loaded_plugins[$module['parent']])), + 'MISSING' => $missing, ) ); Index: /extensions/PWG_Stuffs/admin/upgrade.inc.php =================================================================== --- /extensions/PWG_Stuffs/admin/upgrade.inc.php (revision 9409) +++ /extensions/PWG_Stuffs/admin/upgrade.inc.php (revision 9410) @@ -92,5 +92,4 @@ $query = 'ALTER TABLE ' . $prefixeTable . 'stuffs CHANGE `type` `path` VARCHAR( 255 ) NULL DEFAULT NULL, -ADD `parent` VARCHAR( 255 ) NULL DEFAULT NULL AFTER `path`, ADD `level` TINYINT( 3 ) NOT NULL default "0" AFTER `groups`, ADD `on_root` enum(\'true\',\'false\') NOT NULL AFTER `on_home` Index: /extensions/PWG_Stuffs/class.inc.php =================================================================== --- /extensions/PWG_Stuffs/class.inc.php (revision 9410) +++ /extensions/PWG_Stuffs/class.inc.php (revision 9410) @@ -0,0 +1,230 @@ +prefixe = 'PLUGIN_PICTURE_'; + $template->set_prefilter('header', array('stuffs', 'prefilter_picture_css')); + pwgs_picture_special_sections(); + } + else + { + $template->set_prefilter( 'header', array('stuffs', 'prefilter_index_css') ); + } + + $this->get_user_groups(); + $this->get_modules(); + $this->process_modules(); + } + + /* Retrieve user groups */ + function get_user_groups() + { + global $user; + + $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';'; + $result = pwg_query($query); + while ($row = mysql_fetch_assoc($result)) + { + array_push($this->user_groups, $row['group_id']); + } + } + + /* Retrieve modules from table */ + function get_modules() + { + global $page, $user; + + if (!isset($page['stuffs_section'])) return; + + $query = ' +SELECT DISTINCT id, name, path, datas, groups, show_title, id_line, width +FROM ' . STUFFS_TABLE . ' +LEFT JOIN ' . USER_GROUP_TABLE . ' + ON user_id = '.$user['id'].' +WHERE (users IS NULL OR users LIKE "%' . $user['status'] . '%") + AND (groups IS NULL OR groups REGEXP CONCAT("(^|,)",group_id,"(,|$)")) + AND level <= '.$user['level'].' + AND '.$page['stuffs_section'].' = "true" +ORDER BY pos ASC +;'; + + $result = pwg_query($query); + + while ($row = mysql_fetch_assoc($result)) + { + array_push($this->modules, $row); + } + } + + /* Process modules */ + function process_modules() + { + global $pwg_loaded_plugins; + + foreach ($this->modules as $module) + { + if ($module['name'] == 'MainBlock') + { + $this->pos = 'end'; + if (!empty($module['datas']) + and $datas = unserialize($module['datas']) + and $datas['hide']) + { + add_event_handler('loc_end_index', 'hide_main_block'); + } + continue; + } + + preg_match('#^'.preg_quote(PHPWG_PLUGINS_PATH).'([^/]*?)/#', $module['path'], $match); + if (!isset($pwg_loaded_plugins[$match[1]])) + { + continue; + } + + $datas = (!empty($module['datas']) ? unserialize($module['datas']) : false); + $block = array(); + + include($module['path'].'main.inc.php'); + + if (!empty($block['TEMPLATE'])) + { + $block['ID'] = $module['id']; + if ($module['show_title'] == 'true') + { + $block['TITLE'] = trigger_event('render_stuffs_name', $module['name']); + } + if (is_admin()) + { + $block['U_EDIT'] = PHPWG_ROOT_PATH.'admin.php?page=plugin§ion='.STUFFS_DIR.'%2Fadmin%2Fadmin.php&tab=edit_module&edit='.$module['id'].'&redirect='.urlencode(urlencode($_SERVER['REQUEST_URI'])); + } + $this->set_tpl_block($block, $module); + } + } + } + /* Set template blocks */ + function set_tpl_block($block, $module) + { + if (!empty($module['id_line'])) + { + $block['id_line'] = $module['id_line']; + $block['given_width'] = !empty($module['width']) ? $module['width'] : ''; + + if (!empty($this->blocks[$this->pos])) + { + $last = end($this->blocks[$this->pos]); + $key = key($this->blocks[$this->pos]); + $penul = prev($this->blocks[$this->pos]); + + if (isset($last['id_line']) and $last['id_line'] == $module['id_line']) + { + if (isset($penul['id_line']) and $penul['id_line'] == $module['id_line']) + { + $i = 3; + !$block['given_width'] or $i--; + !$last['given_width'] or $i--; + !$penul['given_width'] or $i--; + + !$i or $default_width = intval((100 - $block['given_width'] - $last['given_width'] - $penul['given_width']) / $i); + + $penul['WIDTH'] = $penul['given_width'] ? $penul['given_width'] : $default_width; + $block['WIDTH'] = $block['given_width'] ? $block['given_width'] : $default_width; + + $block['CLASS'] = 'right_block'; + $block['new_line'] = false; + $block['end_line'] = false; + $last['end_line'] = true; + $this->blocks[$this->pos][$key-1] = $penul; + $this->blocks[$this->pos][$key] = $block; + $this->blocks[$this->pos][] = $last; + return; + } + else + { + if (empty($block['given_width']) and empty($last['given_width'])) + { + $last['WIDTH'] = 50; + } + elseif ($block['given_width']>0) + { + $last['WIDTH'] = 100 - $block['given_width']; + } + else + { + $last['WIDTH'] = $last['given_width']; + } + $block['CLASS'] = 'middle_block'; + $last['CLASS'] = 'left_block'; + $block['new_line'] = false; + $block['end_line'] = true; + $last['end_line'] = false; + $this->blocks[$this->pos][$key] = $last; + $this->blocks[$this->pos][] = $block; + return; + } + } + } + } + + $block['new_line'] = true; + $block['end_line'] = true; + $block['CLASS'] = 'middle_block'; + $this->blocks[$this->pos][] = $block; + } + + static function prefilter_index_css($source, &$smarty) + { + $css = array( + '' + ); + + foreach ($smarty->get_template_vars('themes') as $theme) + { + if (file_exists(PHPWG_THEMES_PATH.$theme['id'].'/stuffs_index.css')) + { + array_push($css, ''); + } + } + + $source = str_replace("\n", "\n".implode( "\n", $css )."\n", $source); + + return $source; + } + + static function prefilter_picture_css($source, &$smarty) + { + $css = array( + '' + ); + + foreach ($smarty->get_template_vars('themes') as $theme) + { + if (file_exists(PHPWG_THEMES_DIR.$theme['id'].'/stuffs_picture.css')) + { + array_push($css, ''); + } + } + + if (!empty($css)) + { + $source = str_replace("\n", "\n".implode( "\n", $css )."\n", $source); + } + + return $source; + } +} + +?> Index: /extensions/PWG_Stuffs/functions.inc.php =================================================================== --- /extensions/PWG_Stuffs/functions.inc.php (revision 9410) +++ /extensions/PWG_Stuffs/functions.inc.php (revision 9410) @@ -0,0 +1,153 @@ + $path, + 'name' => l10n('module_name_' . strtolower($file)), + 'description' => l10n('module_desc_' . strtolower($file)), + ) + ); + } + } + } + closedir($dir); + return $modules; +} + +function pwgs_picture_special_sections() +{ + global $page, $conf; + + if (preg_match('#&(pwgs_..)=#', $_SERVER['REQUEST_URI'], $matches)) + { + if (isset($_GET['action'])) + { + if (isset($page['category'])) + { + $page['section'] = 'category/'.$page['category']['id']; + unset($page['category']); + } + $page['section'] .= $matches[0] . $_GET[$matches[1]]; + } + else + { + unset($page['flat']); + $page['PWG_Stuffs_section'] = $matches[1]; + $page['items'] = explode(',', $_GET[$matches[1]]); + $page['rank_of'] = array_flip($page['items']); + switch ($matches[1]) + { + case 'pwgs_mv': $title = l10n('Most visited'); break; + case 'pwgs_br': $title = l10n('Best rated'); break; + case 'pwgs_re': $title = l10n('Recent pictures'); break; + case 'pwgs_ra': $title = l10n('Random pictures'); break; + } + $page['title'] .= $conf['level_separator'] . $title; + add_event_handler('loc_end_page_header', 'add_pwgs_url_params'); + } + } +} + +function add_pwgs_url_params() +{ + global $page, $template; + + $param = $page['PWG_Stuffs_section']; + + $urls = array( + 'first.U_IMG', + 'previous.U_IMG', + 'next.U_IMG', + 'last.U_IMG', + 'slideshow.U_START_PLAY', + 'slideshow.U_STOP_PLAY', + 'slideshow.U_START_REPEAT', + 'slideshow.U_STOP_REPEAT', + 'slideshow.U_DEC_PERIOD', + 'slideshow.U_INC_PERIOD', + 'U_SLIDESHOW_START', + 'U_SLIDESHOW_STOP', + 'U_METADATA', + 'favorite.U_FAVORITE', + 'U_SET_AS_REPRESENTATIVE', + 'U_CADDIE', + 'rating.F_ACTION', + 'comment_add.F_ACTION', + 'page_refresh.U_REFRESH', + ); + + foreach ($urls as $url) + { + $k = explode('.', $url); + if (isset($k[1]) and isset($template->smarty->_tpl_vars[$k[0]][$k[1]])) + { + $template->smarty->_tpl_vars[$k[0]][$k[1]] = add_url_params($template->smarty->_tpl_vars[$k[0]][$k[1]], array($param => $_GET[$param])); + } + elseif (!isset($k[1]) and isset($template->smarty->_tpl_vars[$k[0]])) + { + $template->smarty->_tpl_vars[$k[0]] = add_url_params($template->smarty->_tpl_vars[$k[0]], array($param => $_GET[$param])); + } + } +} + +function hide_main_block() +{ + global $page, $template; + + if ($page['stuffs_section'] == 'on_home') + { + $template->set_prefilter('index', 'hide_main_block_prefilter'); + } +} + +function hide_main_block_prefilter($content, $smarty) +{ + return preg_replace('#