mostly filebased Content Presentation System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 3 години
преди 3 години
преди 3 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
преди 4 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. <?php
  2. namespace Modules;
  3. class FilesInFolders {
  4. private $folder;
  5. public $content = array();
  6. public $extras = array();
  7. private $domains = array('default'=>'default');
  8. private $keyfiles = array();
  9. public $structs = array();
  10. private $EXT=array(
  11. 'txt'=>array( 'txt', 'text', 'md' ),
  12. 'pic'=>array( 'jpg', 'jpeg', 'png', 'svg' ),
  13. 'tpl'=>array( 'html', 'htm', 'tpl' ),
  14. 'audio'=>array('mp3','wav','ogg'),
  15. 'csv'=>array( 'csv' )
  16. );
  17. public $config = array();
  18. private $state=array();
  19. function __construct($folder,$conf=array()) {
  20. debug("about to construct FIF: $folder");
  21. $f3 = \Base::instance();
  22. if(is_dir($folder)) { // are we given a valid path?
  23. $this->folder = $folder;
  24. } else { // and if not?
  25. $this->folder = $f3->get('CONTENT')."./";
  26. }
  27. if(is_array($conf)) {
  28. foreach($conf as $key=>$value) {
  29. switch($key) {
  30. case 'content':
  31. if(is_array($value)) {
  32. foreach($value as $k=>$v) {
  33. $this->domains[$k] = $v;
  34. }
  35. }
  36. break;
  37. case 'keyfiles':
  38. if(is_array($value)) {
  39. foreach($value as $k=>$v) {
  40. $this->keyfiles[$k] = $v;
  41. }
  42. }
  43. break;
  44. }
  45. }
  46. }
  47. foreach($this->domains as $domain) {
  48. $this->content[$domain] = array();
  49. }
  50. foreach($this->keyfiles as $keys=>$d) {
  51. $this->extras[$keys] = "";
  52. }
  53. debug("constructed files in folder: $folder");
  54. }
  55. /////////////////////////////
  56. // read folder into struct //
  57. /////////////////////////////
  58. function prepare_files() {
  59. foreach ($this->domains as $k=>$v) {
  60. foreach($this->EXT as $cat=>$endings) {
  61. $this->structs[$k][$cat]=array();
  62. }
  63. }
  64. $ls = scandir($this->folder);
  65. foreach ($ls as $k=>$f) {
  66. if (!strncmp($f,'.',1)) continue; // ignore hidden files
  67. $ex=explode(".", $f);
  68. $ext=strtolower(end($ex));
  69. if (array_key_exists($ex[0],$this->domains)) {
  70. $domain_key=$ex[0];
  71. $sort_key=1;
  72. } elseif (array_key_exists($ex[0], $this->keyfiles)) {
  73. if(in_array($ext,$this->EXT[$this->keyfiles[$ex[0]]['type']])) {
  74. $this->extras[$ex[0]]=$this->folder.$f;
  75. continue;
  76. }
  77. $domain_key='default';
  78. $sort_key=0;
  79. } else {
  80. $domain_key='default';
  81. $sort_key=0;
  82. }
  83. foreach ($this->EXT as $cat=>$endings) {
  84. if (in_array($ext, $endings)) {
  85. $this->structs[$domain_key][$cat][$ex[$sort_key]] = $this->folder.$f;
  86. break;
  87. }
  88. }
  89. }
  90. foreach($this->keyfiles as $key=>$param) {
  91. if(!$this->extras[$key]) {
  92. $this->extras[$key] = self::search_up(
  93. $key,
  94. array($this->folder,$param['until']),
  95. $this->EXT[$param['type']]
  96. );
  97. }
  98. if($this->extras[$key]) {
  99. if ($param['type'] == 'txt') {
  100. $this->read_textfile($this->extras[$key]);
  101. }
  102. }
  103. }
  104. }
  105. ///////////////////////////////////////
  106. // prepare content as per the struct //
  107. ///////////////////////////////////////
  108. function fill_content() {
  109. $f3 = \Base::instance();
  110. $md = new \freaParsedown();
  111. $md->deactivate_ol();
  112. //var_dump($md->get_BlockTypes());
  113. foreach($this->domains as $domain_key=>$domain) {
  114. // don't act on hidden files
  115. if ($domain == 'hidden') { continue; }
  116. $this->state['current_domain'] = $domain_key;
  117. foreach($this->structs[$domain_key]['txt'] as $key=>$file) {
  118. $str = $this->read_textfile($file);
  119. $str = self::content_element_dispatcher($str);
  120. $str = $md->text($str);
  121. //$str = sprintf("%s", $str);
  122. $this->content[$domain][$key] = sprintf(
  123. "<div class=\"item %s %s\">%s</div>",
  124. $page,
  125. $key,
  126. $str
  127. );
  128. }
  129. foreach($this->structs[$domain_key]['tpl'] as $key=>$file) {
  130. $str = file_get_contents($file);
  131. $str = \Template::instance()->render($file);
  132. $str = self::linkify($str);
  133. $this->content[$domain][$key] = sprintf(
  134. "<div class=\"item %s %s\">%s</div>",
  135. $page,
  136. $key,
  137. $str
  138. );
  139. }
  140. $bulkIncludePic = array_key_exists('bulkIncludePic',$this->config)
  141. ? $this->config['bulkIncludePic']
  142. : $f3->get('bulkIncludePic') ? : FALSE
  143. ;
  144. if ($bulkIncludePic) {
  145. foreach($this->structs[$domain_key]['pic'] as $key=>$file) {
  146. $this->content[$domain][$key] = sprintf(
  147. "<img class=\"bulkImportedImage $bulkIncludePic\" src=\"/$file\" />"
  148. );
  149. }
  150. }
  151. $bulkIncludeAudio = array_key_exists('bulkIncludeAudio',$this->config)
  152. ? $this->config['bulkIncludeAudio']
  153. : $f3->get('bulkIncludeAudio') ? : FALSE
  154. ;
  155. if ($bulkIncludeAudio) {
  156. foreach ($this->structs[$domain_key]['audio'] as $key=>$file) {
  157. $this->content[$domain][$key] = sprintf(
  158. '<a href="%s" class="audio">%s</a><br>',
  159. $file, $key
  160. );
  161. }
  162. }
  163. foreach($this->structs[$domain_key]['csv'] as $key=>$file) {
  164. $csv = new \Modules\Ography($file,TRUE);
  165. $str="<table>";
  166. foreach($csv->entries as $entry) {
  167. $tmp="";
  168. foreach($entry as $key=>$value) {
  169. $tmp .= sprintf("<td class=\"%s\">%s</td>", $key, $value);
  170. }
  171. $str .= sprintf("<tr>%s</tr>",$tmp);
  172. }
  173. $str.="</table>";
  174. $this->content[$domain][$key] = $str;
  175. }
  176. }
  177. }
  178. //////////////////////
  179. // read config data //
  180. //////////////////////
  181. function read_config($domain=false) {
  182. foreach ($this->domains as $source=>$destination) {
  183. if (is_string($domain)) {
  184. if ($source != $domain) { continue; }
  185. } elseif (is_array($domain)) {
  186. if (!in_array($source,$domain)) { continue; }
  187. }
  188. foreach ($this->structs[$source]['txt'] as $key=>$file) {
  189. $this->read_textfile($file);
  190. }
  191. }
  192. return $this->config;
  193. }
  194. ////////////////
  195. // recursions //
  196. ////////////////
  197. function search_up($key,$paths,$ext) {
  198. $return = "";
  199. if(count($paths) == 2) {
  200. $current = $paths[0];
  201. $last_try = $paths[1];
  202. $ls=scandir($current);
  203. foreach($ls as $f) {
  204. if(!strncmp($f,'.',1)) continue; // ignore hidden files
  205. $ex=explode(".", $f);
  206. if(in_array(strtolower(end($ex)),$ext)) {
  207. if($ex[0]==$key) {
  208. $return = $current.$f;
  209. break;
  210. }
  211. }
  212. }
  213. }
  214. if ($return) {
  215. return $return;
  216. } elseif($current == $last_try) {
  217. return false;
  218. } else {
  219. $p = explode('/',$current);
  220. array_pop($p);
  221. array_pop($p);
  222. return self::search_up($key,array(implode("/",$p)."/",$last_try),$ext);
  223. }
  224. }
  225. ///////////////////////
  226. // Utility functions //
  227. ///////////////////////
  228. function read_textfile($file) {
  229. debug("about to read file: $file");
  230. $str = file_get_contents($file);
  231. debug("read file: $file");
  232. $str = self::linkify($str);
  233. $str = self::strip_comments($str);
  234. $str = self::get_config_from_content($str);
  235. debug("processed file: $file");
  236. return $str;
  237. }
  238. function strip_comments($str) {
  239. $single_line_comments = "/(^;.*\R)/m";
  240. $str = preg_replace($single_line_comments,"",$str);
  241. $multi_line_comments = "/\/\*.*?\*\//s";
  242. $str = preg_replace($multi_line_comments,"",$str);
  243. return $str;
  244. }
  245. function linkify($string) {
  246. $pattern = "/\s@(\w+)[=]([\w,]+)\s/";
  247. $count = 0;
  248. $new = preg_replace_callback
  249. ($pattern,
  250. function($m){
  251. $f3 = \Base::instance();
  252. return $f3->get('SITE_URL')
  253. .$f3->alias($m[1],self::$keyword."=".$m[2])
  254. ;},
  255. $string);
  256. return $new;
  257. }
  258. function get_config_from_content($string) {
  259. $f3 = \Base::instance();
  260. $f = 0;
  261. $pattern = "/#\+(\w+):\s?(.*)/";
  262. $f = preg_match_all($pattern, $string,$matches,PREG_PATTERN_ORDER);
  263. for ($i=0;$i<$f;$i++) {
  264. $string = str_replace($matches[0][$i],"",$string);
  265. $key = $matches[1][$i];
  266. $value = trim($matches[2][$i]);
  267. if(strtolower($value) == "false") {
  268. $value = FALSE;
  269. }
  270. if(!strncmp(trim($value),'@',1)) {
  271. //var_dump($f3->get('DATA'));
  272. if (array_key_exists($key,$f3->get('DATA'))) {
  273. $DATA = $f3->get('DATA.'.$key);
  274. $conf = array($DATA['type'],$DATA['dir']);
  275. $relation = new \Modules\TOC($conf,$f3->get('CONTENT'),substr($value,1));
  276. $relation->dispatch();
  277. $this->config[$key]=array_shift($relation->entries);
  278. } else {
  279. $this->config[$key]=$value;
  280. }
  281. } else {
  282. $this->config[$key]=$value;
  283. }
  284. }
  285. $pattern = "/§>\s*(\w+):(.*?)\R[\011\040]*\R/s";
  286. $f = preg_match_all($pattern, $string,$matches,PREG_PATTERN_ORDER);
  287. for ($i=0;$i<$f;$i++) {
  288. $string = str_replace($matches[0][$i],"",$string);
  289. $key = $matches[1][$i];
  290. $value = trim($matches[2][$i]);
  291. if(strtolower($value) == "false") {
  292. $value = FALSE;
  293. }
  294. if (!strncmp($value,'@',1)) {
  295. # var_dump();
  296. if (array_key_exists($key,$f3->get('DATA'))) {
  297. $entries = explode("@",$value);
  298. array_shift($entries); // first entry is always empty
  299. $DATA = $f3->get('DATA.'.$key);
  300. $conf = array($DATA['type'],$DATA['dir']);
  301. $relation = new \Modules\TOC($conf,$f3->get('CONTENT'),$entries);
  302. $relation->dispatch();
  303. if(/*count($entries) >*/ 1) {
  304. $this->config[$key]= new CMultiple($relation->entries);
  305. } else {
  306. $this->config[$key]=array_shift($relation->entries);
  307. }
  308. } else {
  309. $this->config[$key]=$value;
  310. }
  311. } else {
  312. $this->config[$key]=$value;
  313. }
  314. }
  315. return $string;
  316. }
  317. function content_element_dispatcher($string) {
  318. $f3 = \Base::instance();
  319. $md = new \freaParsedown();
  320. $md->deactivate_ol();
  321. $f0 = 0;
  322. // find occorances of {| keyword |}
  323. $pattern = "/\{\|(.+?)\|\}/s";
  324. $f = preg_match_all($pattern, $string,$matches,PREG_PATTERN_ORDER);
  325. for ($i=0;$i<$f;$i++) {
  326. $body = preg_split("/\R/",trim($matches[1][$i]));
  327. $request = explode(":", trim(array_shift($body)));
  328. $new="";
  329. switch($request[0]) {
  330. case 'test':
  331. $new="seems to work";
  332. break;
  333. case ';':
  334. $new="";
  335. break;
  336. case 'path':
  337. $new="/".$this->folder;
  338. break;
  339. case 'space':
  340. $new=sprintf("<div style=\"height:%s;\"></div>",
  341. $request[1]
  342. );
  343. break;
  344. case 'span':
  345. $new=sprintf("<span class=\"%s\">%s</span>",
  346. $request[1],
  347. $request[2] ? : implode("\n",$body)
  348. );
  349. break;
  350. case 'small-text':
  351. if(count($body)) {
  352. $new=sprintf("<div class=\"smalltext\">%s</div>",
  353. implode("\n",$body)
  354. );
  355. } else {
  356. $new=sprintf("<span class=\"smalltext\">%s</span>",
  357. $request[1]
  358. );
  359. }
  360. break;
  361. case 'TOC':
  362. // throw away TOC part of request, we don't need it
  363. array_shift($request);
  364. $toc = new \Modules\TOC($request,$this->folder,$body);
  365. $toc->dispatch();
  366. $new=sprintf("<div class=\"TOC %s\">%s</div>",
  367. array_shift($request),
  368. $toc);
  369. break;
  370. case 'box':
  371. array_shift($request); //get rid of identifier
  372. $type = array_shift($request);
  373. $pics = explode(":",array_shift($body));
  374. $pic = $pics[0];
  375. $pic_hover = count($pics) > 1 ? $pics[1] : $pic;
  376. if (count($body) >= 3) {
  377. $caption = ['normal'=>['cap1' => array_shift($body),
  378. 'cap2' => array_shift($body)],
  379. 'hover'=> ['cap1' => array_shift($body),
  380. 'cap2' => array_shift($body)]];
  381. $caption_html=[];
  382. foreach ($caption as $state => $set) {
  383. if(!$set['cap2']) {
  384. $caption_html[$state] = [
  385. sprintf('<span class="first">&nbsp;</span>'),
  386. sprintf('<span class="first">%s</span>',$set['cap1'])
  387. ];
  388. } else if (!$set['cap1'] && $set['cap2']) {
  389. $caption_html[$state] = [
  390. sprintf('<span class="second">%s</span>',$set['cap2'])
  391. ];
  392. } else {
  393. $caption_html[$state] = [
  394. sprintf('<span class="first">%s</span>',$set['cap1']?:"&nbsp;"),
  395. sprintf('<span class="second">%s</span>',$set['cap2'])
  396. ];
  397. }
  398. }
  399. $has_caption = TRUE;
  400. } else {
  401. $has_caption = FALSE;
  402. }
  403. if (file_exists($this->folder.$pic)) {
  404. $pic = $this->folder.$pic;
  405. } else {
  406. $pic = $f3->get('RESOURCES')."img/default_img.png";
  407. }
  408. if (file_exists($this->folder.$pic_hover)) {
  409. $pic_hover = $this->folder.$pic_hover;
  410. } else {
  411. $pic_hover = $pic;
  412. }
  413. if(0) {
  414. $PIC = new \Image($pic);
  415. $orientation = $PIC->width() > $PIC->height()
  416. ? 'landscape'
  417. : 'portrait'
  418. ;
  419. unset($PIC);
  420. } else {
  421. list($wwidth, $hheight) = getimagesize($pic);
  422. $orientation = $wwidth > $hheight ? 'landscape' : 'portrait';
  423. }
  424. $pic = new CachedImage($pic);
  425. $pic_hover = new CachedImage($pic_hover);
  426. $class="";
  427. $add="";
  428. switch($type) {
  429. case 'plain':
  430. $link=false;
  431. break;
  432. case 'download':
  433. $file = "/".$this->folder.implode(":",$request);
  434. $link='href="'.$file.'" download ';
  435. break;
  436. case 'lightbox':
  437. $body = implode("\n",$body);
  438. if (count($request) % 2) {
  439. $class = array_pop($request);
  440. }
  441. if (count($request) >= 2) {
  442. $body=str_replace([$request[0],$request[1]],["{|","|}"],$body);
  443. $body=$this->content_element_dispatcher($body);
  444. }
  445. $hash=md5($body);
  446. $add=sprintf("<div id=\"%s\" class=\"content_elment_box_body\">\n%s\n</div>",
  447. $hash,
  448. $md->text($body));
  449. $link='href="#" data-featherlight="#'.$hash.'" ';
  450. break;
  451. case 'internal':
  452. $dest=implode(":",$request);
  453. $data = [];
  454. $base = substr($dest,0,strpos($dest,'?') ? : strlen($dest));
  455. parse_str(parse_url($dest,PHP_URL_QUERY),$data);
  456. $fragment = parse_url($dest,PHP_URL_FRAGMENT);
  457. if ($f3->get('LANG') != $f3->get('default_lang')) {
  458. if (!array_key_exists('lang',$data)) {
  459. $data['lang'] = $f3->get('LANG');
  460. }
  461. }
  462. $new_dest = $base;
  463. if (count($data) > 0) {
  464. $new_dest .= "?" . http_build_query($data);
  465. }
  466. if ($fragment) {
  467. $new_dest .= "#" . $fragment;
  468. }
  469. //if ($f3->get('LANG') != $f3->get('default_lang')) {
  470. // $dest .= "?lang=".$f3->get('LANG');
  471. //}
  472. $link=sprintf('href="%s" ',$f3->get('SITE_URL')."/".$new_dest);
  473. break;
  474. case 'external':
  475. $dest=implode(":",$request);
  476. $target = $f3->get('external_links_open_in_new_window')
  477. ? 'target="_blank"'
  478. : ''
  479. ;
  480. $link=sprintf('href="%s" %s',$dest, $target);
  481. break;
  482. default:
  483. $link='href="#"';
  484. break;
  485. }
  486. $new=sprintf("<div class=\"brick %s\">\n<a class=\"content_element_box\" %s>\n<div class=\"content_element_box\">
  487. <div class=\"image\">
  488. <img class=\"standard\" src=\"%s\" /><img class=\"hover\" src=\"%s\" />
  489. </div>
  490. %s
  491. %s
  492. \n</div>\n</a>\n%s\n</div>",
  493. implode(" ",[$orientation,$class,$type]),
  494. $link,
  495. $pic->get_src(1600),
  496. $pic_hover->get_src(1600),
  497. ($has_caption ? "<div class=\"caption standard\">".implode("<br>",$caption_html['normal'])."</div>": " "),
  498. ($has_caption ? "<div class=\"caption hover\">".implode("<br>",$caption_html['hover'])."</div>" : " " ),
  499. $add
  500. );
  501. break;
  502. case 'brick':
  503. array_shift($request);
  504. $class = array_shift($request);
  505. $new = sprintf("<div class=\"content_element brick %s\">\n%s\n</div>",
  506. $class,
  507. $md->text(implode("\n",$body))
  508. );
  509. break;
  510. case 'calendar':
  511. array_shift($request);
  512. $conf = array('path', $this->folder);
  513. $v = $this->read_config();
  514. $cal = new \Modules\CCalendar($v,$conf);
  515. $new=sprintf("<div class=\"calendar\">\n%s\n</div>",
  516. $cal);
  517. break;
  518. case 'header':
  519. array_shift($request);
  520. $conf = array('path', $this->folder);
  521. $v = $this->read_config();
  522. switch (array_shift($request)) {
  523. case 'event':
  524. $el = new CEvent($v,$conf);
  525. $el->set_layout('archive');
  526. $new = $el;
  527. break;
  528. case 'concert':
  529. $el = new CConcert($v,$conf);
  530. $el->set_layout('header');
  531. $new = $el;
  532. break;
  533. }
  534. break;
  535. case 'image':
  536. $key=$request[1];
  537. $image="";
  538. // if(!$key) {
  539. // $new=self::warn("Content Module \"Image\" needs name of a file (without extension)");
  540. // break;
  541. //}
  542. foreach($this->structs as $domain=>$destination) {
  543. if(array_key_exists($key, $this->structs[$domain]['pic'])) {
  544. $image = $this->structs[$domain]['pic'][$key];
  545. unset($this->structs[$domain]['pic'][$key]);
  546. unset($this->content[$this->domains[$domain]][$key]);
  547. break;
  548. }
  549. }
  550. if ($image) {
  551. if( in_array($request[2],array('left','right','full'))) {
  552. $class = $request[2];
  553. } else {
  554. $class = 'full';
  555. }
  556. $img = new \Image($image);
  557. $ratio = ($img->width() >= $img->height())
  558. ? "landscape"
  559. : "portrait"
  560. ;
  561. $cached = new CachedImage($image);
  562. foreach ($body as $k=>$line) {
  563. if (strpos($line,"©") !== FALSE
  564. || strpos($line,"&copy;") !== FALSE) {
  565. $body[$k] = sprintf("<span class=\"copyright\">%s</span>",$line);
  566. }
  567. }
  568. $new=sprintf("<div class='content_element_image %s'>"
  569. ."<div class=\"media %s\"><a href=\"%s\" data-featherlight=\"image\"><img src=\"%s\" alt=\"user supplied image\" /></a></div>"
  570. ."<img src=\"%s\" style=\"display:none;\" alt=\"user supplied image\" />"
  571. ."<div class=\"caption\">%s</div>"
  572. ."</div>",
  573. $class,
  574. $ratio,
  575. $cached->get_src(1600),
  576. $cached->get_src(1600),
  577. $cached->get_src(1600),
  578. $md->text(implode("\n",$body))
  579. );
  580. } else {
  581. $new=sprintf("<div class='content_element_image %s'>\n"
  582. ."<div class=\"media %s\">\n"
  583. ."<div class=\"caption\">\n%s\n</div>\n"
  584. ."</div>\n",
  585. $class,
  586. $ratio,
  587. $md->text(implode("\n",$body))
  588. );
  589. }
  590. break;
  591. case 'devide':
  592. $contents = explode($request[1],implode("\n",$body));
  593. $c=count($contents);
  594. $str="";
  595. for ($iiii=0;$iiii<$c;$iiii++) {
  596. $str .= sprintf(" %f%%",100/$c);
  597. }
  598. $template = sprintf('grid-template-columns:%s;',
  599. $str);
  600. $counter=0;
  601. $new = sprintf('<div class="content_element_devided" style="%s">',$template);
  602. foreach($contents as $part) {
  603. $counter++;
  604. if (count($request) >= 4) {
  605. $part=str_replace([$request[2],$request[3]],["{|","|}"],$part);
  606. $part=$this->content_element_dispatcher($part);
  607. }
  608. $new .= sprintf("<div>\n%s\n</div>",
  609. $md->text($part)
  610. );
  611. }
  612. $new.="</div>";
  613. break;
  614. case 'page':
  615. array_shift($request);
  616. $target = array_shift($request);
  617. $class = array_shift($request);
  618. $folder = $this->folder.$target."/";
  619. $anchor_name=array_pop(explode("/",$target));
  620. $fff = new \Modules\FilesInFolders(
  621. $folder,
  622. array(
  623. 'content'=>array(
  624. 'secondary'=>'secondary',
  625. 'zzz'=>'hidden',
  626. 'unpublish'=>'hidden'
  627. ))
  628. );
  629. $fff->prepare_files();
  630. $fff->fill_content();
  631. $new = sprintf("<div class=\"content_element_page %s\"><a name=\"%s\"></a>\n%s\n</div>",
  632. $class,
  633. $anchor_name,
  634. implode("\n",$fff->content['default']));
  635. break;
  636. case 'youtube':
  637. $vid=array_shift($request);
  638. $pos= array_shift($request);
  639. if( in_array($pos,array('left','right','full'))) {
  640. $class = $pos;
  641. } else {
  642. $class = 'left';
  643. }
  644. $video=sprintf("<iframe width=\"700\" height=\"394\" class=\"ytvideo\" "
  645. ."src=\"https://www.youtube.com/embed/%s\"></iframe>",
  646. $vid);
  647. $thumbnail = sprintf("<div class=\"video-thumbnail\"><a href=\"%s\" data-featherlight=\"#%s\">"
  648. ."<img class=\"thumbnail\" src=\"https://img.youtube.com/vi/%s/mqdefault.jpg\" alt=\"video-preview\"/>"
  649. ."<img class=\"play-button\" src=\"%s\" alt=\"play-button\" />"
  650. ."</a></div><div class=\"lightbox\" id=\"%s\" >%s</div>",
  651. "https://www.youtube.com/watch?v=".$vid,
  652. $vid,
  653. $vid,
  654. "/rsc/img/play-button.png",
  655. $vid,
  656. $video
  657. );
  658. foreach ($body as $k=>$line) {
  659. if (strpos($line,"©") !== FALSE
  660. || strpos($line,"&copy;") !== FALSE) {
  661. $body[$k] = sprintf("<span class=\"copyright\">%s</span>",$line);
  662. }
  663. }
  664. $new=sprintf("<div class='video-container %s'>"
  665. ."<div class=\"media\">%s</div>"
  666. ."<div class=\"caption\">%s</div>"
  667. ."</div>",
  668. $class,
  669. $thumbnail,
  670. $md->text(implode("\n",$body)));
  671. break;
  672. default:
  673. $new=self::warn("Content Module \"".$request[0]."\" unknown");
  674. break;
  675. }
  676. $string = str_replace($matches[0][$i],$new,$string);
  677. }
  678. return $string;
  679. }
  680. function warn($message) {
  681. return sprintf("<div class=\"warning\">%s</div>",$message);
  682. }
  683. }