PageRenderTime 24ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/skins/test.php

https://github.com/jmarc06/yacs
PHP | 284 lines | 150 code | 49 blank | 85 comment | 25 complexity | f947c6b54dcc0e3fd1222098097195dc MD5 | raw file
  1. <?php
  2. /**
  3. * test your skin
  4. *
  5. * This script enables any web site developer to visually control the rendering of a skin.
  6. * The skin under test may be selected among any available skins on this system.
  7. *
  8. * This page creates reference items to be used by any skin.
  9. * - [code]$context['extra'][/code] - side content specific to this page
  10. * - [code]$context['navigation'][/code] - side content
  11. * - [code]$context['page_image'][/code] - the main image of the page, if any
  12. * - [code]$context['page_menu'][/code] - an array of $url => $label to show available commands (e.g., 'back', 'edit', 'delete', etc.)
  13. * - [code]$context['page_title'][/code] - the page title
  14. * - [code]$context['path_bar'][/code] - an array of $url => $label to show the stack of pages from home
  15. * - [code]$context['page_author'][/code] - appears in meta
  16. * - [code]$context['page_publisher'][/code] - appears in meta
  17. * - [code]$context['prefix'][/code] - some page prefix
  18. * - [code]$context['text'][/code] - the main content of the page, with cover article and gadget boxes
  19. *
  20. * @see skins/index.php
  21. * @see index.php
  22. *
  23. * @link http://www.lipsum.com/ Lorem Ipsum is simply dummy text of the printing and typesetting industry...
  24. * @link http://www.somacon.com/p141.php HTML and CSS Table Border Style Wizard
  25. *
  26. * Use this page while developing or checking a skin, then move to help pages on YACS codes to
  27. * finalize your task.
  28. *
  29. * @see codes/index.php
  30. *
  31. * Accept following invocations:
  32. * - test.php/original_skin
  33. * - test.php?skin=original_skin
  34. *
  35. * @author Bernard Paques
  36. * @reference
  37. * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
  38. */
  39. include_once '../shared/global.php';
  40. // the skin under test
  41. $skin = '';
  42. if(isset($_REQUEST['skin']))
  43. $skin = $_REQUEST['skin'];
  44. if(isset($context['arguments'][0]))
  45. $skin = $context['arguments'][0];
  46. // avoid potential attacks
  47. $skin = preg_replace(FORBIDDEN_IN_PATHS, '', strip_tags($skin));
  48. // accept it if there is a template.php
  49. if(file_exists($context['path_to_root'].'skins/'.$skin.'/template.php'))
  50. $context['skin'] = 'skins/'.$skin;
  51. // load the skin
  52. load_skin('skins');
  53. if(!defined('DUMMY_TEXT'))
  54. define('DUMMY_TEXT', 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
  55. .' Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
  56. .' Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'
  57. .' Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.');
  58. $items = array('_1' => 'Lorem ipsum dolor sit amet', '_2' => 'Excepteur sint occaecat cupidatat non proident', '_3' => 'Ut enim ad minim veniam');
  59. define('COMPACT_LIST', Skin::build_list($items, 'compact'));
  60. // // $context['error'] - to report run time errors
  61. if($context['with_debug'] == 'Y')
  62. Logger::error(i18n::s('error messages, if any'));
  63. // minimum site parameters
  64. if(!$context['site_name'])
  65. $context['site_name'] = i18n::s('Site name');
  66. if(!$context['site_slogan'])
  67. $context['site_slogan'] = i18n::s('Site slogan');
  68. // $context['navigation'] - navigation boxes
  69. $context['navigation'] .= Skin::build_box(i18n::s('navigation').' 1', DUMMY_TEXT, 'navigation');
  70. $context['navigation'] .= Skin::build_box(i18n::s('navigation').' 2', COMPACT_LIST, 'navigation');
  71. // $context['extra'] - extra boxes
  72. $context['extra'] .= Skin::build_box(i18n::s('extra').' 1', DUMMY_TEXT, 'extra');
  73. $context['extra'] .= Skin::build_box(i18n::s('extra').' 2', COMPACT_LIST, 'extra');
  74. // $context['extra'] - a fake contextual menu
  75. $text = Skin::build_tree(array(array('#', '', i18n::s('menu').' 1', '', 'close'),
  76. array('#', '', i18n::s('menu').' 2', '', 'open', '', '',
  77. array(array('#', '', i18n::s('menu').' 2.1', '', 'close'),
  78. array('#', '', i18n::s('menu').' 2.2', '', 'open', '', '',
  79. array(array('#', '', i18n::s('menu').' 2.2.1', '', 'close'),
  80. array('#', '', i18n::s('menu').' 2.2.2', '', 'open', '', '',
  81. array(array('#', '', i18n::s('menu').' 2.2.2.1', '', 'close'),
  82. array('#', '', i18n::s('menu').' 2.2.2.2', '', 'open', '', '',
  83. array(array('#', '', i18n::s('menu').' 2.2.2.2.1', '', 'close'),
  84. array('#', '', i18n::s('menu').' 2.2.2.2.2', '', 'close'),
  85. array('#', '', i18n::s('menu').' 2.2.2.2.3', '', 'close'),
  86. array('#', '', i18n::s('menu').' 2.2.2.2.4', '', 'close'),
  87. array('#', '', i18n::s('menu').' 2.2.2.2.5', '', 'open'),
  88. array('#', '', i18n::s('menu').' 2.2.2.2.6', '', 'close')
  89. )),
  90. array('#', '', i18n::s('menu').' 2.2.2.3', '', 'close')
  91. )),
  92. array('#', '', i18n::s('menu').' 2.2.3', '', 'close')
  93. )),
  94. array('#', '', i18n::s('menu').' 2.3', '', 'close')
  95. )),
  96. array('#', '', i18n::s('menu').' 3', '', 'close'),
  97. array('#', '', i18n::s('menu').' 4', '', 'close')
  98. ));
  99. $context['components']['contextual'] = Skin::build_box(i18n::s('contextual menu'), $text, 'contextual', 'contextual_menu');
  100. // $context['page_author'] - the author
  101. $context['page_author'] = 'webmaestro, through some PHP script';
  102. // back to skin index
  103. $context['page_menu'] += array( 'skins/' => i18n::s('Themes') );
  104. // edit this skin
  105. if(isset($skin) && Surfer::is_associate())
  106. $context['page_menu'] += array( 'skins/edit.php?skin='.$skin => i18n::s('Edit this theme') );
  107. // validate at w3c
  108. $context['page_menu'] += array( 'http://validator.w3.org/check?uri=referer' => array('', i18n::s('Validate at w3c'), '', 'span') );
  109. // use this skin for the site
  110. if(isset($skin) && Surfer::is_associate())
  111. $context['page_menu'] += array('control/configure.php?parameter=skin&amp;value=skins/'.$skin => i18n::s('Use this theme'));
  112. // derive this skin
  113. if(isset($skin) && Surfer::is_associate())
  114. $context['page_menu'] += array('skins/derive.php?skin='.$skin => i18n::s('Derive this theme'));
  115. // $context['page_publisher'] - the publisher
  116. $context['page_publisher'] = 'webmaestro again, still through some PHP script';
  117. // page tags
  118. $context['page_tags'] = i18n::s('<a>tag 1</a> <a>tag 2</a>');
  119. // $context['page_title'] - the title of the page
  120. $context['page_title'] = i18n::s('Theme test');
  121. // $context['path_bar'] - back to other sections
  122. $context['path_bar'] = array( 'skins/' => i18n::s('Themes'));
  123. // $context['prefix'] - also list skins available on this system
  124. $context['prefix'] .= '<form method="get" action="'.$context['script_url'].'"><p>';
  125. $context['prefix'] .= i18n::s('Theme to test').' <select name="skin">';
  126. if ($dir = Safe::opendir("../skins")) {
  127. // valid skins have a template.php
  128. $skins = array();
  129. while(($file = Safe::readdir($dir)) !== FALSE) {
  130. if(($file[0] == '.') || !is_dir('../skins/'.$file))
  131. continue;
  132. if(!file_exists('../skins/'.$file.'/template.php'))
  133. continue;
  134. $checked = '';
  135. if($context['skin'] == 'skins/'.$file)
  136. $checked = ' selected="selected"';
  137. $skins[] = '<option value="'.$file.'"'.$checked.'>'.$file."</option>\n";
  138. }
  139. Safe::closedir($dir);
  140. if(count($skins)) {
  141. natsort($skins);
  142. foreach($skins as $skin)
  143. $context['prefix'] .= $skin;
  144. }
  145. }
  146. $context['prefix'] .= '</select> '.Skin::build_submit_button(i18n::s('Go')).'</p></form>';
  147. // $context['prefix'] - some prefix data
  148. $context['prefix'] .= '<p>'.sprintf(i18n::s('Use this page while developing or checking a theme, then activate the theme and move to %s to finalize your work.'), Skin::build_link('codes/', i18n::s('help pages on YACS codes'), 'shortcut')).'</p>';
  149. // several panels
  150. $panels = array();
  151. // regular panel
  152. // will be derivated to $context['text'] after codes::beautify()
  153. $text = '';
  154. // $context['text']
  155. $text .= DUMMY_TEXT;
  156. // $context['text'] - introduction
  157. $text .= Skin::build_block(DUMMY_TEXT, 'introduction');
  158. // surfer profile
  159. if(!$user_id = Surfer::get_id())
  160. $user_id = 1;
  161. // newest article
  162. $article_id = 1;
  163. if($item =& Articles::get_newest_for_anchor(NULL, TRUE))
  164. $article_id = $item['id'];
  165. // newest file
  166. $file_id = 1;
  167. if($item =& Files::get_newest())
  168. $file_id = $item['id'];
  169. // $context['text'] - basic content with links, etc.
  170. $text .= '[toc]'.DUMMY_TEXT."\n"
  171. .'<ul>'."\n"
  172. .'<li>[article='.$article_id.']</li>'."\n"
  173. .'<li>[section='.Sections::get_default().']</li>'."\n"
  174. .'<li>[category=featured]</li>'."\n"
  175. .'<li>[user='.$user_id.']</li>'."\n"
  176. .'<li>[download='.$file_id.']</li>'."\n"
  177. .'<li>[email]foo@bar.com[/email]</li>'."\n"
  178. .'<li>[link=Cisco]http://www.cisco.com/[/link]</li>'."\n"
  179. .'<li>[script]skins/test.php[/script]</li>'."\n"
  180. .'<li>'.Skin::build_link('skins/test.php', 'skins/test.php', 'shortcut').'</li>'."\n"
  181. .'<li>'.Skin::strip(DUMMY_TEXT, 7, 'skins/test.php').'</li>'."\n"
  182. .'<li>'.RESTRICTED_FLAG.i18n::s('Community - Access is granted to any identified surfer').'</li>'."\n"
  183. .'<li>'.PRIVATE_FLAG.i18n::s('Private - Access is restricted to selected persons').'</li>'."\n"
  184. .'<li>'.i18n::s('This item is new').NEW_FLAG.'</li>'."\n"
  185. .'<li>'.i18n::s('This item has been updated').UPDATED_FLAG.'</li>'."\n"
  186. .'<li>'.DRAFT_FLAG.i18n::s('This item is a draft, and is not publicly visible').'</li>'."\n"
  187. .'</ul>'."\n"
  188. .'<p>[button='.i18n::s('Click to reload this page').']skins/test.php[/button]</p>'."\n"
  189. .'<p>'.DUMMY_TEXT."</p>\n"
  190. .' [title]'.i18n::s('level 1 title').'[/title] '."\n".DUMMY_TEXT."\n"
  191. .' [subtitle]'.i18n::s('level 2 title').'[/subtitle] '."\n".DUMMY_TEXT;
  192. // a sidebar
  193. $sidebar =& Skin::build_box(i18n::s('sidebar box'), DUMMY_TEXT, 'sidebar');
  194. // $context['text'] - section with sidebar box
  195. $text .= Skin::build_box(i18n::s('with a sidebar box'), $sidebar.DUMMY_TEXT);
  196. // a folded box
  197. $folder =& Skin::build_box(i18n::s('folded box'), DUMMY_TEXT, 'folded');
  198. // $context['text'] - section with folded box
  199. $text .= Skin::build_box(i18n::s('with a folded box'), DUMMY_TEXT.$folder.DUMMY_TEXT);
  200. // a menu bar
  201. $menu_bar = array('skins/test.php' => i18n::s('Test page'), 'skins/' => i18n::s('Themes'), 'scripts/' => i18n::s('Server software'));;
  202. // $context['text'] - section with a menu bar
  203. $text .= Skin::build_box(i18n::s('with a menu bar'), DUMMY_TEXT.Skin::build_list($menu_bar, 'menu_bar').DUMMY_TEXT);
  204. // page neighbours
  205. $neighbours = array('#previous', i18n::s('Previous'), '#next', i18n::s('Next'), '', '<a class="pager-item">1</a> &nbsp; <a class="pager-current">2</a>');
  206. // $context['text'] - section with neighbours
  207. $text .= Skin::build_box(i18n::s('with neighbours'), DUMMY_TEXT.Skin::neighbours($neighbours, 'slideshow'));
  208. // user profile at page bottom
  209. $user = array();
  210. $user['id'] = $user_id;
  211. $user['nick_name'] = 'Geek101';
  212. $user['introduction'] = DUMMY_TEXT;
  213. $text .= Skin::build_profile($user, 'suffix');
  214. // finalize this panel
  215. $panels[] = array('b', i18n::s('Text'), 'b_panel', Codes::beautify($text));
  216. // gadgets panel
  217. //
  218. $text = DUMMY_TEXT;
  219. // $context['text'] - with gadgets -- see index.php and sections/view.php
  220. $text .= "\n".'<p id="gadgets_prefix"> </p>'."\n"
  221. .Skin::build_box(i18n::s('gadget').' 1', DUMMY_TEXT, 'gadget')
  222. .Skin::build_box(i18n::s('gadget').' 2', DUMMY_TEXT, 'gadget')
  223. .Skin::build_box(i18n::s('gadget').' 3', DUMMY_TEXT, 'gadget')
  224. .Skin::build_box(i18n::s('gadget').' 4', DUMMY_TEXT, 'gadget')
  225. .Skin::build_box(i18n::s('gadget').' 5', DUMMY_TEXT, 'gadget')
  226. .Skin::build_box(i18n::s('gadget').' 6', DUMMY_TEXT, 'gadget')
  227. .'<p id="gadgets_suffix"> </p>'."\n";
  228. // finalize this panel
  229. $panels[] = array('g', i18n::s('Gadgets'), 'g_panel', Codes::beautify($text));
  230. // assemble all panels
  231. //
  232. $context['text'] .= Skin::build_tabs($panels);
  233. // render the skin
  234. render_skin();
  235. ?>