mostly filebased Content Presentation System
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

776 lines
30KB

  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."30text"] = 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."00tpl"] = 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."10image"] = 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."20audio"] = 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."30csv"] = $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 'form':
  371. $token_db = $f3->get('TEMP') . "CEform/";
  372. $form_config_file = sprintf("%s%s.cfg",
  373. ROOT.$this->folder,
  374. $request[1]);
  375. $db = new \DB\Jig($token_db,\DB\Jig::FORMAT_JSON);
  376. $formcall = new \DB\Jig\Mapper($db,'form_calls');
  377. $timestamp = time();
  378. $token = md5($timestamp . $form_config_file . rand(100,999));
  379. $f3->config($form_config_file);
  380. $f3->set('fields',
  381. array_merge(
  382. $f3->get('fields'),
  383. ['xss-token'=>[
  384. 'type'=>'hidden',
  385. 'value'=>$token,
  386. 'length'=>strlen($token)
  387. ]]
  388. ));
  389. $formcall->token = $token;
  390. $formcall->timestamp = $timestamp;
  391. $formcall->form = $form_config_file;
  392. $formcall->save();
  393. $form_view = new \Template;
  394. $new=$form_view->render('form.htm');
  395. break;
  396. case 'box':
  397. array_shift($request); //get rid of identifier
  398. $type = array_shift($request);
  399. $pics = explode(":",array_shift($body));
  400. $pic = $pics[0];
  401. $pic_hover = count($pics) > 1 ? $pics[1] : $pic;
  402. if (count($body) >= 3) {
  403. $caption = ['normal'=>['cap1' => array_shift($body),
  404. 'cap2' => array_shift($body)],
  405. 'hover'=> ['cap1' => array_shift($body),
  406. 'cap2' => array_shift($body)]];
  407. $caption_html=[];
  408. foreach ($caption as $state => $set) {
  409. if(!$set['cap2']) {
  410. $caption_html[$state] = [
  411. sprintf('<span class="first">&nbsp;</span>'),
  412. sprintf('<span class="first">%s</span>',$set['cap1'])
  413. ];
  414. } else if (!$set['cap1'] && $set['cap2']) {
  415. $caption_html[$state] = [
  416. sprintf('<span class="second">%s</span>',$set['cap2'])
  417. ];
  418. } else {
  419. $caption_html[$state] = [
  420. sprintf('<span class="first">%s</span>',$set['cap1']?:"&nbsp;"),
  421. sprintf('<span class="second">%s</span>',$set['cap2'])
  422. ];
  423. }
  424. }
  425. $has_caption = TRUE;
  426. } else {
  427. $has_caption = FALSE;
  428. }
  429. if (file_exists($this->folder.$pic)) {
  430. $pic = $this->folder.$pic;
  431. } else {
  432. $pic = $f3->get('RESOURCES')."img/default_img.png";
  433. }
  434. if (file_exists($this->folder.$pic_hover)) {
  435. $pic_hover = $this->folder.$pic_hover;
  436. } else {
  437. $pic_hover = $pic;
  438. }
  439. if(0) {
  440. $PIC = new \Image($pic);
  441. $orientation = $PIC->width() > $PIC->height()
  442. ? 'landscape'
  443. : 'portrait'
  444. ;
  445. unset($PIC);
  446. } else {
  447. list($wwidth, $hheight) = getimagesize($pic);
  448. $orientation = $wwidth > $hheight ? 'landscape' : 'portrait';
  449. }
  450. $pic = new CachedImage($pic);
  451. $pic_hover = new CachedImage($pic_hover);
  452. $class="";
  453. $add="";
  454. switch($type) {
  455. case 'plain':
  456. $link=false;
  457. break;
  458. case 'download':
  459. $file = "/".$this->folder.implode(":",$request);
  460. $link='href="'.$file.'" download ';
  461. break;
  462. case 'lightbox':
  463. $body = implode("\n",$body);
  464. if (count($request) % 2) {
  465. $class = array_pop($request);
  466. }
  467. if (count($request) >= 2) {
  468. $body=str_replace([$request[0],$request[1]],["{|","|}"],$body);
  469. $body=$this->content_element_dispatcher($body);
  470. }
  471. $hash=md5($body);
  472. $add=sprintf("<div id=\"%s\" class=\"content_elment_box_body\">\n%s\n</div>",
  473. $hash,
  474. $md->text($body));
  475. $link='href="#" data-featherlight="#'.$hash.'" ';
  476. break;
  477. case 'internal':
  478. $dest=implode(":",$request);
  479. $data = [];
  480. $base = substr($dest,0,strpos($dest,'?') ? : strlen($dest));
  481. parse_str(parse_url($dest,PHP_URL_QUERY),$data);
  482. $fragment = parse_url($dest,PHP_URL_FRAGMENT);
  483. if ($f3->get('LANG') != $f3->get('default_lang')) {
  484. if (!array_key_exists('lang',$data)) {
  485. $data['lang'] = $f3->get('LANG');
  486. }
  487. }
  488. $new_dest = $base;
  489. if (count($data) > 0) {
  490. $new_dest .= "?" . http_build_query($data);
  491. }
  492. if ($fragment) {
  493. $new_dest .= "#" . $fragment;
  494. }
  495. //if ($f3->get('LANG') != $f3->get('default_lang')) {
  496. // $dest .= "?lang=".$f3->get('LANG');
  497. //}
  498. $link=sprintf('href="%s" ',$f3->get('SITE_URL')."/".$new_dest);
  499. break;
  500. case 'external':
  501. $dest=implode(":",$request);
  502. $target = $f3->get('external_links_open_in_new_window')
  503. ? 'target="_blank"'
  504. : ''
  505. ;
  506. $link=sprintf('href="%s" %s',$dest, $target);
  507. break;
  508. default:
  509. $link='href="#"';
  510. break;
  511. }
  512. $new=sprintf("<div class=\"brick %s\">\n<a class=\"content_element_box\" %s>\n<div class=\"content_element_box\">
  513. <div class=\"image\">
  514. <img class=\"standard\" src=\"%s\" /><img class=\"hover\" src=\"%s\" />
  515. </div>
  516. %s
  517. %s
  518. \n</div>\n</a>\n%s\n</div>",
  519. implode(" ",[$orientation,$class,$type]),
  520. $link,
  521. $pic->get_src(1600),
  522. $pic_hover->get_src(1600),
  523. ($has_caption ? "<div class=\"caption standard\">".implode("<br>",$caption_html['normal'])."</div>": " "),
  524. ($has_caption ? "<div class=\"caption hover\">".implode("<br>",$caption_html['hover'])."</div>" : " " ),
  525. $add
  526. );
  527. break;
  528. case 'brick':
  529. array_shift($request);
  530. $class = array_shift($request);
  531. $new = sprintf("<div class=\"content_element brick %s\">\n%s\n</div>",
  532. $class,
  533. $md->text(implode("\n",$body))
  534. );
  535. break;
  536. case 'calendar':
  537. array_shift($request);
  538. $conf = array('path', $this->folder);
  539. $v = $this->read_config();
  540. $cal = new \Modules\CCalendar($v,$conf);
  541. $new=sprintf("<div class=\"calendar\">\n%s\n</div>",
  542. $cal);
  543. break;
  544. case 'header':
  545. array_shift($request);
  546. $conf = array('path', $this->folder);
  547. $v = $this->read_config();
  548. switch (array_shift($request)) {
  549. case 'event':
  550. $el = new CEvent($v,$conf);
  551. $el->set_layout('archive');
  552. $new = $el;
  553. break;
  554. case 'concert':
  555. $el = new CConcert($v,$conf);
  556. $el->set_layout('header');
  557. $new = $el;
  558. break;
  559. }
  560. break;
  561. case 'image':
  562. $key=$request[1];
  563. $image="";
  564. // if(!$key) {
  565. // $new=self::warn("Content Module \"Image\" needs name of a file (without extension)");
  566. // break;
  567. //}
  568. foreach($this->structs as $domain=>$destination) {
  569. if(array_key_exists($key, $this->structs[$domain]['pic'])) {
  570. $image = $this->structs[$domain]['pic'][$key];
  571. unset($this->structs[$domain]['pic'][$key]);
  572. unset($this->content[$this->domains[$domain]][$key]);
  573. break;
  574. }
  575. }
  576. if ($image) {
  577. if( in_array($request[2],array('left','right','full'))) {
  578. $class = $request[2];
  579. } else {
  580. $class = 'full';
  581. }
  582. $img = new \Image($image);
  583. $ratio = ($img->width() >= $img->height())
  584. ? "landscape"
  585. : "portrait"
  586. ;
  587. $cached = new CachedImage($image);
  588. foreach ($body as $k=>$line) {
  589. if (strpos($line,"©") !== FALSE
  590. || strpos($line,"&copy;") !== FALSE) {
  591. $body[$k] = sprintf("<span class=\"copyright\">%s</span>",$line);
  592. }
  593. }
  594. $new=sprintf("<div class='content_element_image %s'>"
  595. ."<div class=\"media %s\"><a href=\"%s\" data-featherlight=\"image\"><img src=\"%s\" alt=\"user supplied image\" /></a></div>"
  596. ."<img src=\"%s\" style=\"display:none;\" alt=\"user supplied image\" />"
  597. ."<div class=\"caption\">%s</div>"
  598. ."</div>",
  599. $class,
  600. $ratio,
  601. $cached->get_src(1600),
  602. $cached->get_src(1600),
  603. $cached->get_src(1600),
  604. $md->text(implode("\n",$body))
  605. );
  606. } else {
  607. $new=sprintf("<div class='content_element_image %s'>\n"
  608. ."<div class=\"media %s\">\n"
  609. ."<div class=\"caption\">\n%s\n</div>\n"
  610. ."</div>\n",
  611. $class,
  612. $ratio,
  613. $md->text(implode("\n",$body))
  614. );
  615. }
  616. break;
  617. case 'devide':
  618. $contents = explode($request[1],implode("\n",$body));
  619. $c=count($contents);
  620. $str="";
  621. for ($iiii=0;$iiii<$c;$iiii++) {
  622. $str .= sprintf(" %f%%",100/$c);
  623. }
  624. $template = sprintf('grid-template-columns:%s;',
  625. $str);
  626. $counter=0;
  627. $new = sprintf('<div class="content_element_devided" style="%s">',$template);
  628. foreach($contents as $part) {
  629. $counter++;
  630. if (count($request) >= 4) {
  631. $part=str_replace([$request[2],$request[3]],["{|","|}"],$part);
  632. $part=$this->content_element_dispatcher($part);
  633. }
  634. $new .= sprintf("<div>\n%s\n</div>",
  635. $md->text($part)
  636. );
  637. }
  638. $new.="</div>";
  639. break;
  640. case 'page':
  641. array_shift($request);
  642. $target = array_shift($request);
  643. $class = array_shift($request);
  644. $folder = $this->folder.$target."/";
  645. $anchor_name=array_pop(explode("/",$target));
  646. $fff = new \Modules\FilesInFolders(
  647. $folder,
  648. array(
  649. 'content'=>array(
  650. 'secondary'=>'secondary',
  651. 'zzz'=>'hidden',
  652. 'unpublish'=>'hidden'
  653. ))
  654. );
  655. $fff->prepare_files();
  656. $fff->fill_content();
  657. $new = sprintf("<div class=\"content_element_page %s\"><a name=\"%s\"></a>\n%s\n</div>",
  658. $class,
  659. $anchor_name,
  660. implode("\n",$fff->content['default']));
  661. break;
  662. case 'youtube':
  663. $vid=array_shift($request);
  664. $pos= array_shift($request);
  665. if( in_array($pos,array('left','right','full'))) {
  666. $class = $pos;
  667. } else {
  668. $class = 'left';
  669. }
  670. $video=sprintf("<iframe width=\"700\" height=\"394\" class=\"ytvideo\" "
  671. ."src=\"https://www.youtube.com/embed/%s\"></iframe>",
  672. $vid);
  673. $thumbnail = sprintf("<div class=\"video-thumbnail\"><a href=\"%s\" data-featherlight=\"#%s\">"
  674. ."<img class=\"thumbnail\" src=\"https://img.youtube.com/vi/%s/mqdefault.jpg\" alt=\"video-preview\"/>"
  675. ."<img class=\"play-button\" src=\"%s\" alt=\"play-button\" />"
  676. ."</a></div><div class=\"lightbox\" id=\"%s\" >%s</div>",
  677. "https://www.youtube.com/watch?v=".$vid,
  678. $vid,
  679. $vid,
  680. "/rsc/img/play-button.png",
  681. $vid,
  682. $video
  683. );
  684. foreach ($body as $k=>$line) {
  685. if (strpos($line,"©") !== FALSE
  686. || strpos($line,"&copy;") !== FALSE) {
  687. $body[$k] = sprintf("<span class=\"copyright\">%s</span>",$line);
  688. }
  689. }
  690. $new=sprintf("<div class='video-container %s'>"
  691. ."<div class=\"media\">%s</div>"
  692. ."<div class=\"caption\">%s</div>"
  693. ."</div>",
  694. $class,
  695. $thumbnail,
  696. $md->text(implode("\n",$body)));
  697. break;
  698. default:
  699. $new=self::warn("Content Module \"".$request[0]."\" unknown");
  700. break;
  701. }
  702. $string = str_replace($matches[0][$i],$new,$string);
  703. }
  704. return $string;
  705. }
  706. function warn($message) {
  707. return sprintf("<div class=\"warning\">%s</div>",$message);
  708. }
  709. }