Source for file templates.php

Documentation is available at templates.php

  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // Copyright (C) ReloadCMS Development Team //
  4. // http://reloadcms.sf.net //
  5. // //
  6. // This program is distributed in the hope that it will be useful, //
  7. // but WITHOUT ANY WARRANTY, without even the implied warranty of //
  8. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
  9. // //
  10. // This product released under GNU General Public License v2 //
  11. ////////////////////////////////////////////////////////////////////////////////
  12.  
  13.  
  14.  
  15. function user_tz_select($default = 0, $select_name = 'timezone') {
  16. global $lang;
  17.  
  18. $tz_select = '<select name="' . $select_name . '">';
  19. while(list($offset, $zone) = @each($lang['tz'])) {
  20. $selected = ( $offset == $default ) ? ' selected="selected"' : '';
  21. $tz_select .= '<option value="' . $offset . '"' . $selected . '>' . $zone . '</option>';
  22. }
  23. $tz_select .= '</select>';
  24.  
  25. return $tz_select;
  26. }
  27.  
  28. function user_skin_select($dir, $select_name, $default = '', $style = '', $script = '') {
  29. $skins = rcms_scandir($dir);
  30. $frm = '<select name="' . $select_name . '" style="' . $style . '" ' . $script . '>';
  31. foreach ($skins as $skin){
  32. if(is_dir($dir . $skin) && is_file($dir . $skin . '/skin_name.txt')){
  33. $name = file_get_contents($dir . $skin . '/skin_name.txt');
  34. $frm .= '<option value="' . $skin . '"' . (($default == $skin) ? ' selected="selected">' : '>') . $name . '</option>';
  35. }
  36. }
  37. $frm .= '</select>';
  38. return $frm;
  39. }
  40.  
  41. function user_lang_select($select_name, $default = '', $style = '', $script = '') {
  42. global $system;
  43. $frm = '<select name="' . $select_name . '" style="' . $style . '" ' . $script . '>';
  44. foreach ($system->data['languages'] as $lang_id => $lang_name){
  45. $frm .= '<option value="' . $lang_id . '"' . (($default == $lang_id) ? ' selected="selected">' : '>') . $lang_name . '</option>';
  46. }
  47. $frm .= '</select>';
  48. return $frm;
  49. }
  50.  
  51. function rcms_pagination($total, $perpage, $current, $link){
  52. $return = '';
  53. $link = preg_replace("/((&amp;|&)page=(\d*))/", '', $link);
  54. if(!empty($perpage)) {
  55. $pages = ceil($total/$perpage);
  56. if($pages != 1){
  57. $c = 1;
  58. while($c <= $pages){
  59. if($c != $current) $return .= ' [' . '<a href="' . $link . '&amp;page=' . $c . '">' . $c . '</a>] ';
  60. else $return .= ' [' . $c . '] ';
  61. $c++;
  62. }
  63. }
  64. }
  65. return $return;
  66. }
  67.  
  68. function rcms_parse_menu($format) {
  69. global $system;
  70. $navigation = parse_ini_file(CONFIG_PATH . 'navigation.ini', true);
  71. $dyna = parse_ini_file(CONFIG_PATH . 'dynamik.ini', true);
  72. $result = array();
  73. foreach ($navigation as $link) {
  74. if(substr($link['url'], 0, 9) == 'external:') {
  75. $target = '_blank';
  76. $link['url'] = substr($link['url'], 9);
  77. } else {
  78. $target = '';
  79. }
  80. $tdata = explode(':', $link['url'], 2);
  81. if(count($tdata) == 2){
  82. list($modifier, $value) = $tdata;
  83. } else {
  84. $modifier = $tdata[0];
  85. }
  86. if(!empty($value) && !empty($system->navmodifiers[$modifier])){
  87. if($clink = call_user_func($system->navmodifiers[$modifier]['m'], $value)){
  88. $result[] = array($clink[0], (empty($link['name'])) ? $clink[1] : __($link['name']), $target);
  89. }
  90. } else {
  91. $result[] = array($link['url'], __($link['name']));
  92. }
  93. }
  94. $menu = '';
  95. foreach ($result as $item){
  96. if(empty($item[2])) {
  97. $item[2] = '_top';
  98. }
  99. // Begin of Icons support by Migel
  100. if ($item[0] == '?module=index') {
  101. $item[3] = 'home.png';
  102. } elseif ($item[0] == '?module=articles') {
  103. $item[3] = 'articles.png';
  104. } elseif ($item[0] == '?module=guestbook') {
  105. $item[3] = 'guestbook.png';
  106. } elseif ($item[0] == '?module=gallery') {
  107. $item[3] = 'gallery.png';
  108. } elseif ($item[0] == '?module=user.list') {
  109. $item[3] = 'userlist.png';
  110. } elseif ($item[0] == '?module=filesdb') {
  111. $item[3] = 'files.png';
  112. } elseif ($item[0] == '?module=feedback') {
  113. $item[3] = 'email.png';
  114. } elseif ($item[0] == '?module=forum') {
  115. $item[3] = 'forum.png';
  116. } else {
  117. $item[3] = 'default.png';
  118. }
  119. if (isset($dyna['ico']))
  120. $item[3] = '<img src="skins/icons/'.$item[3].'">';
  121. else
  122. $item[3]='';
  123. $menu .= str_replace('{link}', $item[0], str_replace('{title}', $item[1], str_replace('{target}', @$item[2], str_replace('{icon}', $item[3], $format))));
  124. // End of Icons support by Migel
  125. }
  126. $result = $menu;
  127. return $result;
  128. }
  129.  
  130. function rcms_parse_dynamik_menu($format) {
  131. global $system;
  132. function convertArray($ar){
  133. $var = '{ ';
  134. foreach ($ar as $key=>$val ){
  135. $var .= '"'.$key.'" : ';
  136. if ( is_array( $val ) ){
  137. $var .= convertArray($val).', ';
  138. } else {
  139. $var .= '"'.$val.'", ';
  140. }
  141. }
  142. if ($var[strlen($var)-2] == ',') $var[strlen($var)-2] = ' ';
  143. return $var.'} ';
  144. }
  145.  
  146. $pic_right = '&nbsp;&nbsp;<b>•</b> ';
  147. //Commented becouse fucking IE, Microsoft, Gates and his mother...
  148. //$pic_right = '&nbsp;<img src = \''.SKIN_PATH.'arrow_right.gif\'>';
  149. $pic_down = '<img src = \''.SKIN_PATH.'arrow_down.gif\'>';
  150. $navigation = parse_ini_file(CONFIG_PATH . 'navigation.ini', true);
  151. $dyna = parse_ini_file(CONFIG_PATH . 'dynamik.ini', true);
  152. $result = array();
  153. foreach ($navigation as $link) {
  154. if(substr($link['url'], 0, 9) == 'external:') {
  155. $target = '_blank';
  156. $link['url'] = substr($link['url'], 9);
  157. } else {
  158. $target = '';
  159. }
  160. $tdata = explode(':', $link['url'], 2);
  161. if(count($tdata) == 2){
  162. list($modifier, $value) = $tdata;
  163. } else {
  164. $modifier = $tdata[0];
  165. }
  166. if(!empty($value) && !empty($system->navmodifiers[$modifier])){
  167. if($clink = call_user_func($system->navmodifiers[$modifier]['m'], $value)){
  168. $result[] = array($clink[0], (empty($link['name'])) ? $clink[1] : __($link['name']), $target);
  169. }
  170. } else {
  171. $result[] = array($link['url'], __($link['name']));
  172. }
  173. }
  174. $menu = ' <script type="text/javascript" src="navigation.js"></script> <div class="dhtml_menu"> <div class="horz_menu"> ';
  175. foreach ($result as $item){
  176. if(empty($item[2])) {
  177. $item[2] = '_top';
  178. }
  179. if(empty($item[4])) {
  180. $item[4] = '';
  181. }
  182. // Begin of Icons support by Migel
  183. //$arr = array();
  184. if ($item[0] == '?module=articles') {
  185. if (!isset($dyna['use_art'])){
  186. $articles = new articles();
  187. $containers = $articles -> getContainers();
  188. $count = 0;
  189. if (is_array($containers)){
  190. $item[1] .= '&nbsp;'.$pic_down;
  191. $containers = array_reverse($containers);
  192. foreach ($containers as $conkey => $conval) {
  193. $count++;
  194. if ($count != $dyna['max']) {
  195. $arr['ddm_article']['&nbsp;&nbsp; '.cut_text($conval).'&nbsp;&nbsp; '] = '?module=articles&c='.$conkey;
  196. if (!isset($dyna['min'])){
  197. $articles -> setWorkContainer($conkey);
  198. $art = $articles -> getCategories();
  199. $count2 = 0;
  200. if (is_array($art)){
  201. unset($arr['ddm_article']['&nbsp;&nbsp; '.cut_text($conval).'&nbsp;&nbsp; ']);
  202. $arr['ddm_article'][$pic_right.'&nbsp;&nbsp; '.cut_text($conval).'&nbsp;&nbsp; '] = array('-' => '?module=articles&c='.$conkey);
  203. $art = array_reverse($art);
  204. foreach ($art as $artkey => $artval){
  205. $count2++;
  206. if ($count2 != $dyna['max']) {
  207. $arr['ddm_article'][$pic_right.'&nbsp;&nbsp; '.cut_text($conval).'&nbsp;&nbsp; ']['&nbsp;&nbsp; '.cut_text($artval['title']).'&nbsp;&nbsp;'] = '?module=articles&c='.$conkey.'&b='.$artval['id'];
  208. $art2 = $articles -> getArticles($artval['id']);
  209. $count3 = 0;
  210. if (count($art2) > 0){
  211. unset($arr['ddm_article'][$pic_right.'&nbsp;&nbsp; '.cut_text($conval).'&nbsp;&nbsp; ']['&nbsp;&nbsp; '.cut_text($artval['title']).'&nbsp;&nbsp;']);
  212. $arr['ddm_article'][$pic_right.'&nbsp;&nbsp; '.cut_text($conval).'&nbsp;&nbsp; '][$pic_right.'&nbsp;&nbsp; '.cut_text($artval['title']).'&nbsp;&nbsp;'] = array('-' => '?module=articles&c='.$conkey.'&b='.$artval['id']);
  213. $art2 = array_reverse($art2);
  214. foreach ($art2 as $art2key => $art2val){
  215. $count3++;
  216. if ($count3 != $dyna['max'])
  217. $arr['ddm_article'][$pic_right.'&nbsp;&nbsp; '.cut_text($conval).'&nbsp;&nbsp; '][$pic_right.'&nbsp;&nbsp; '.cut_text($artval['title']).'&nbsp;&nbsp;']['&nbsp;&nbsp;'.cut_text($art2val['title']).'&nbsp;&nbsp;'] = '?module=articles&c='.$conkey.'&b='.$artval['id'].'&a='.$art2val['id'];
  218. }
  219. }
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }
  227. $item[4] = 'ddm_article';
  228. }
  229. $item[3] = 'articles.png';
  230. } elseif ($item[0] == '?module=gallery') {
  231. if (!isset($dyna['use_gal'])){
  232. $gallery = new gallery();
  233. $kw = $gallery -> getAvaiableValues('keywords');
  234. $count = 0;
  235. if (is_array($kw)){
  236. $kw = array_reverse($kw);
  237. $count++;;
  238. if (!isset($dyna['min']))
  239. foreach($kw as $key => $val){
  240. if ($count != $dyna['max']) {
  241. $arr['ddm_gallery'][$pic_right.'&nbsp;&nbsp;'.__('By keywords').'&nbsp;&nbsp;'][$pic_right.'&nbsp;&nbsp;'.cut_text($val).'&nbsp;&nbsp;'] = array('-' => '?module=gallery&keyword='.$val);
  242. $kw2 = $gallery->getLimitedImagesList('keywords', $val);
  243. $kw2 = array_reverse($kw2);
  244. $count2 = 0;
  245. foreach ($kw2 as $key2 => $val2){
  246. $count2++;
  247. if ($count2 != $dyna['max']) {
  248. $arr['ddm_gallery'][$pic_right.'&nbsp;&nbsp;'.__('By keywords').'&nbsp;&nbsp;'][$pic_right.'&nbsp;&nbsp;'.cut_text($val).'&nbsp;&nbsp;']['&nbsp;&nbsp;'.cut_text($val2).'&nbsp;&nbsp;'] = '?module=gallery&id='.$val2;
  249. }
  250. }
  251. }
  252. }
  253. }
  254. $kw = $gallery -> getAvaiableValues('size');
  255. $count = 0;
  256. if (is_array($kw)){
  257. $kw = array_reverse($kw);
  258. $count++;
  259. $item[1] .= '&nbsp;'.$pic_down;
  260. if (!isset($dyna['min']))
  261. foreach($kw as $key => $val){
  262. if ($count != $dyna['max']) {
  263. $arr['ddm_gallery'][$pic_right.'&nbsp;&nbsp;'.__('By size').'&nbsp;&nbsp;'][$pic_right.'&nbsp;&nbsp;'.cut_text($val).'&nbsp;&nbsp;'] = array('-' => '?module=gallery&size='.$val);
  264. $kw2 = $gallery->getLimitedImagesList('size', $val);
  265. $kw2 = array_reverse($kw2);
  266. $count2 = 0;
  267. foreach ($kw2 as $key2 => $val2){
  268. $count2++;
  269. if ($count2 != $dyna['max']) {
  270. $arr['ddm_gallery'][$pic_right.'&nbsp;&nbsp;'.__('By size').'&nbsp;&nbsp;'][$pic_right.'&nbsp;&nbsp;'.cut_text($val).'&nbsp;&nbsp;']['&nbsp;&nbsp;'.cut_text($val2).'&nbsp;&nbsp;'] = '?module=gallery&id='.$val2;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. $kw = $gallery -> getAvaiableValues('type');
  277. $count = 0;
  278. if (is_array($kw)){
  279. $kw = array_reverse($kw);
  280. $count++;
  281. if (!isset($dyna['min']))
  282. foreach($kw as $key => $val){
  283. if ($count != $dyna['max']) {
  284. $arr['ddm_gallery'][$pic_right.'&nbsp;&nbsp;'.__('By type').'&nbsp;&nbsp;'][$pic_right.'&nbsp;&nbsp;'.cut_text($val).'&nbsp;&nbsp;'] = array('-' => '?module=gallery&type='.$val);
  285. $kw2 = $gallery->getLimitedImagesList('type', $val);
  286. $kw2 = array_reverse($kw2);
  287. $count2 = 0;
  288. foreach ($kw2 as $key2 => $val2){
  289. $count2++;
  290. if ($count2 != $dyna['max']) {
  291. $arr['ddm_gallery'][$pic_right.'&nbsp;&nbsp;'.__('By type').'&nbsp;&nbsp;'][$pic_right.'&nbsp;&nbsp;'.cut_text($val).'&nbsp;&nbsp;']['&nbsp;&nbsp;'.cut_text($val2).'&nbsp;&nbsp;'] = '?module=gallery&id='.$val2;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. $kw = $gallery -> getFullImagesList();
  298. $count = 0;
  299. if (count($kw) > 0){
  300. $kw = array_reverse($kw);
  301. $count++;
  302. foreach($kw as $key => $val){
  303. if ($count != $dyna['max']) {
  304. $arr['ddm_gallery']['&nbsp;&nbsp;'.cut_text($val).'&nbsp;&nbsp;'] = '?module=gallery&id='.$val;
  305. }
  306. }
  307. }
  308. $item[4] = 'ddm_gallery';
  309. }
  310. $item[3] = 'gallery.png';
  311. } elseif ($item[0] == '?module=user.list') {
  312. if (!isset($dyna['use_mem'])){
  313. $userlist = $system->getUserList('*', 'nickname');
  314. $count = 0;
  315. if (count($userlist) > 0) {
  316. $item[1] .= '&nbsp;'.$pic_down;
  317. $userlist = array_reverse($userlist);
  318. foreach ($userlist as $conkey => $conval) {
  319. $count++;
  320. if ($count != $dyna['max'])
  321. $arr['ddm_users']['&nbsp;&nbsp;'.cut_text($conval['nickname']).'&nbsp;&nbsp;'] = '?module=user.list&user='.$conval['username'];
  322. }
  323. }
  324. $item[4] = 'ddm_users';
  325. }
  326. $item[3] = 'userlist.png';
  327. } elseif ($item[0] == '?module=filesdb') {
  328. if (!isset($dyna['use_fdb'])){
  329. $filesdb = new linksdb(DOWNLOADS_DATAFILE);
  330. $count = 0;
  331. if (!empty($filesdb -> data)) {
  332. $item[1] .= '&nbsp;'.$pic_down;
  333. $fdb = array_reverse($filesdb -> data);
  334. foreach ($fdb as $conkey => $conval) {
  335. $count++;
  336. if ($count != $dyna['max']) {
  337. $arr['ddm_filesdb']['&nbsp;&nbsp;'.cut_text($conval['name']).'&nbsp;&nbsp;'] = '?module=filesdb&id='.(sizeof($fdb) - ($count - 1));
  338. if (count($conval['files']) > 0)
  339. if (!isset($dyna['min'])){
  340. unset($arr['ddm_filesdb']['&nbsp;&nbsp;'.cut_text($conval['name']).'&nbsp;&nbsp;']);
  341. $arr['ddm_filesdb'][$pic_right.'&nbsp;&nbsp;'.cut_text($conval['name']).'&nbsp;&nbsp;'] = array('-' => '?module=filesdb&id='.(sizeof($fdb) - ($count - 1)));
  342. $count2 = 0;
  343. $conval['files'] = array_reverse($conval['files']);
  344. foreach ($conval['files'] as $artkey => $artval){
  345. $count2++;
  346. if ($count2 != $dyna['max'])
  347. $arr['ddm_filesdb'][$pic_right.'&nbsp;&nbsp;'.cut_text($conval['name']).'&nbsp;&nbsp;']['&nbsp;&nbsp;'.cut_text($artval['name']).'&nbsp;&nbsp;'] = '?module=filesdb&id='.(sizeof($fdb) - ($count - 1)).'&fid='.(sizeof($conval['files']) - ($count2 - 1));
  348. }
  349. }
  350. }
  351. }
  352. }
  353. $item[4] = 'ddm_filesdb';
  354. }
  355. $item[3] = 'files.png';
  356. } elseif ($item[0] == '?module=forum') {
  357. if (!isset($dyna['use_for'])){
  358. $topics = @unserialize(@file_get_contents(FORUM_PATH . 'topic_index.dat'));
  359. $count = 0;
  360. if (count($topics) > 0) {
  361. $item[1] .= '&nbsp;'.$pic_down;
  362. if (is_array($topics)){
  363. $topics = array_reverse($topics);
  364. foreach ($topics as $conkey => $conval) {
  365. $count++;
  366. if ($count != $dyna['max'])
  367. $arr['ddm_forum']['&nbsp;&nbsp;'.cut_text($conval['title']).'&nbsp;&nbsp;'] = '?module=forum&id='.(sizeof($topics) - ($count)).'&action=topic';
  368. }
  369. }
  370. }
  371. $item[4] = 'ddm_forum';
  372. }
  373. $item[3] = 'forum.png';
  374. } else {
  375. $item[3] = 'default.png';
  376. }
  377. if (isset($dyna['ico']))
  378. $item[3] = '<img src="skins/icons/'.$item[3].'">';
  379. else
  380. $item[3]='';
  381. $menu .= str_replace('{link}', $item[0], str_replace('{title}', $item[1], str_replace('{target}', @$item[2], str_replace('{icon}', $item[3], str_replace('{id}', $item[4], $format)))));
  382. // End of Icons support by Migel
  383. }
  384. $menu .= ' <br clear="both" /> </div>';
  385. $result = $menu.' <script type="text/javascript"> dhtmlmenu_build('.convertArray($arr,'arr').');</script></div>';
  386.  
  387. return $result;
  388. }
  389.  
  390.  
  391. function rcms_parse_module_template($module, $tpldata = array()) {
  392. global $system;
  393. ob_start();
  394. if(is_file(CUR_SKIN_PATH . $module . '.php')) {
  395. include(CUR_SKIN_PATH . $module . '.php');
  396. } elseif(is_file(MODULES_TPL_PATH . $module . '.php')) {
  397. include(MODULES_TPL_PATH . $module . '.php');
  398. }
  399. $return = ob_get_contents();
  400. ob_end_clean();
  401. return $return;
  402. }
  403.  
  404. function rcms_open_browser_window($id, $link, $attributes = '', $return = false){
  405. global $system;
  406. $code = '<script language="javascript">window.open(\'' . addslashes($link) . '\', \'' . $id . '\',\'' . $attributes . '\');</script>';
  407. if($return){
  408. return $code;
  409. } else {
  410. @$system->config['meta'] .= $code;
  411. }
  412. }
  413.  
  414. function rcms_parse_module_template_path($module) {
  415. if(is_file(CUR_SKIN_PATH . $module . '.php')) {
  416. return (CUR_SKIN_PATH . $module . '.php');
  417. } elseif(is_file(MODULES_TPL_PATH . $module . '.php')) {
  418. return (MODULES_TPL_PATH . $module . '.php');
  419. } else {
  420. return false;
  421. }
  422. }
  423.  
  424. function rcms_show_element($element, $parameters = ''){
  425. global $system;
  426. switch($element){
  427. case 'title':
  428. if(!@$system->config['hide_title']) {
  429. echo $system->config['title'];
  430. if(!empty($system->config['pagename'])) echo ' - ';
  431. }
  432. echo (!empty($system->config['pagename'])) ? $system->config['pagename'] : '';
  433. break;
  434. case 'menu_point':
  435. list($point, $template) = explode('@', $parameters);
  436. if(is_file(CUR_SKIN_PATH . 'skin.' . $template . '.php')) {
  437. $tpl_path = CUR_SKIN_PATH . 'skin.' . $template . '.php';
  438. } elseif(is_file(MODULES_TPL_PATH . $template . '.php')) {
  439. $tpl_path = MODULES_TPL_PATH . $template . '.php';
  440. }
  441. if(!empty($tpl_path) && !empty($system->output['menus'][$point])){
  442. foreach($system->output['menus'][$point] as $module){
  443. $system->showWindow($module[0], $module[1], $module[2], $tpl_path);
  444. }
  445. }
  446. break;
  447. case 'main_point':
  448. foreach ($system->output['modules'] as $module) {
  449. $system->showWindow($module[0], $module[1], $module[2], CUR_SKIN_PATH . 'skin.' . substr(strstr($parameters, '@'), 1) . '.php');
  450. }
  451. break;
  452. case 'navigation':
  453. $dyna = parse_ini_file(CONFIG_PATH . 'dynamik.ini', true);
  454. if (isset($dyna['use'])) {
  455. echo rcms_parse_dynamik_menu($parameters);
  456. break;
  457. }
  458. echo rcms_parse_menu($parameters);
  459. break;
  460. case 'meta':
  461. readfile(DATA_PATH . 'meta_tags.html');
  462. echo '<meta http-equiv="Content-Type" content="text/html; charset=' . $system->config['encoding'] . '" />' . "\r\n";
  463. if(!empty($system->config['enable_rss'])){
  464. foreach ($system->feeds as $module => $d) {
  465. echo '<link rel="alternate" type="application/xml" title="RSS ' . $d[0] . '" href="./rss.php?m=' . $module . '" />' . "\r\n";
  466. }
  467. }
  468. if(!empty($system->config['meta'])) echo $system->config['meta'];
  469. break;
  470. case 'copyright':
  471. if(!defined('RCMS_COPYRIGHT_SHOWED') || !RCMS_COPYRIGHT_SHOWED){
  472. echo RCMS_POWERED . ' ' . RCMS_VERSION_A . '.' . RCMS_VERSION_B . '.' . RCMS_VERSION_C . RCMS_VERSION_SUFFIX . '<br />' . RCMS_COPYRIGHT;
  473. }
  474. break;
  475. }
  476. }
  477. ?>

Documentation generated on Fri, 08 Jun 2007 12:21:34 +0300 by phpDocumentor 1.3.0RC3