mostly filebased Content Presentation System
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

779 行
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. $includeTemplates = array_key_exists('includeTemplates', $this->config)
  130. ? $this->config['includeTemplates']
  131. : $f3->get('includeTemplates') ? : FALSE
  132. ;
  133. foreach($this->structs[$domain_key]['tpl'] as $key=>$file) {
  134. $str = \Template::instance()->render(substr($file,7));
  135. $str = self::linkify($str);
  136. $this->content[$domain][$key."00tpl"] = sprintf(
  137. "<div class=\"item %s %s\">%s</div>",
  138. $page,
  139. $key,
  140. $str
  141. );
  142. }
  143. $bulkIncludePic = array_key_exists('bulkIncludePic',$this->config)
  144. ? $this->config['bulkIncludePic']
  145. : $f3->get('bulkIncludePic') ? : FALSE
  146. ;
  147. if ($bulkIncludePic) {
  148. foreach($this->structs[$domain_key]['pic'] as $key=>$file) {
  149. $this->content[$domain][$key."10image"] = sprintf(
  150. "<img class=\"bulkImportedImage $bulkIncludePic\" src=\"/$file\" />"
  151. );
  152. }
  153. }
  154. $bulkIncludeAudio = array_key_exists('bulkIncludeAudio',$this->config)
  155. ? $this->config['bulkIncludeAudio']
  156. : $f3->get('bulkIncludeAudio') ? : FALSE
  157. ;
  158. if ($bulkIncludeAudio) {
  159. foreach ($this->structs[$domain_key]['audio'] as $key=>$file) {
  160. $this->content[$domain][$key."20audio"] = sprintf(
  161. '<a href="%s" class="audio">%s</a><br>',
  162. $file, $key
  163. );
  164. }
  165. }
  166. foreach($this->structs[$domain_key]['csv'] as $key=>$file) {
  167. $csv = new \Modules\Ography($file,TRUE);
  168. $str="<table>";
  169. foreach($csv->entries as $entry) {
  170. $tmp="";
  171. foreach($entry as $key=>$value) {
  172. $tmp .= sprintf("<td class=\"%s\">%s</td>", $key, $value);
  173. }
  174. $str .= sprintf("<tr>%s</tr>",$tmp);
  175. }
  176. $str.="</table>";
  177. $this->content[$domain][$key."30csv"] = $str;
  178. }
  179. }
  180. }
  181. //////////////////////
  182. // read config data //
  183. //////////////////////
  184. function read_config($domain=false) {
  185. foreach ($this->domains as $source=>$destination) {
  186. if (is_string($domain)) {
  187. if ($source != $domain) { continue; }
  188. } elseif (is_array($domain)) {
  189. if (!in_array($source,$domain)) { continue; }
  190. }
  191. foreach ($this->structs[$source]['txt'] as $key=>$file) {
  192. $this->read_textfile($file);
  193. }
  194. }
  195. return $this->config;
  196. }
  197. ////////////////
  198. // recursions //
  199. ////////////////
  200. function search_up($key,$paths,$ext) {
  201. $return = "";
  202. if(count($paths) == 2) {
  203. $current = $paths[0];
  204. $last_try = $paths[1];
  205. $ls=scandir($current);
  206. foreach($ls as $f) {
  207. if(!strncmp($f,'.',1)) continue; // ignore hidden files
  208. $ex=explode(".", $f);
  209. if(in_array(strtolower(end($ex)),$ext)) {
  210. if($ex[0]==$key) {
  211. $return = $current.$f;
  212. break;
  213. }
  214. }
  215. }
  216. }
  217. if ($return) {
  218. return $return;
  219. } elseif($current == $last_try) {
  220. return false;
  221. } else {
  222. $p = explode('/',$current);
  223. array_pop($p);
  224. array_pop($p);
  225. return self::search_up($key,array(implode("/",$p)."/",$last_try),$ext);
  226. }
  227. }
  228. ///////////////////////
  229. // Utility functions //
  230. ///////////////////////
  231. function read_textfile($file) {
  232. debug("about to read file: $file");
  233. $str = file_get_contents($file);
  234. debug("read file: $file");
  235. $str = self::linkify($str);
  236. $str = self::strip_comments($str);
  237. $str = self::get_config_from_content($str);
  238. debug("processed file: $file");
  239. return $str;
  240. }
  241. function strip_comments($str) {
  242. $single_line_comments = "/(^;.*\R)/m";
  243. $str = preg_replace($single_line_comments,"",$str);
  244. $multi_line_comments = "/\/\*.*?\*\//s";
  245. $str = preg_replace($multi_line_comments,"",$str);
  246. return $str;
  247. }
  248. function linkify($string) {
  249. $pattern = "/\s@(\w+)[=]([\w,]+)\s/";
  250. $count = 0;
  251. $new = preg_replace_callback
  252. ($pattern,
  253. function($m){
  254. $f3 = \Base::instance();
  255. return $f3->get('SITE_URL')
  256. .$f3->alias($m[1],self::$keyword."=".$m[2])
  257. ;},
  258. $string);
  259. return $new;
  260. }
  261. function get_config_from_content($string) {
  262. $f3 = \Base::instance();
  263. $f = 0;
  264. $pattern = "/#\+(\w+):\s?(.*)/";
  265. $f = preg_match_all($pattern, $string,$matches,PREG_PATTERN_ORDER);
  266. for ($i=0;$i<$f;$i++) {
  267. $string = str_replace($matches[0][$i],"",$string);
  268. $key = $matches[1][$i];
  269. $value = trim($matches[2][$i]);
  270. if(strtolower($value) == "false") {
  271. $value = FALSE;
  272. }
  273. if(!strncmp(trim($value),'@',1)) {
  274. //var_dump($f3->get('DATA'));
  275. if (array_key_exists($key,$f3->get('DATA'))) {
  276. $DATA = $f3->get('DATA.'.$key);
  277. $conf = array($DATA['type'],$DATA['dir']);
  278. $relation = new \Modules\TOC($conf,$f3->get('CONTENT'),substr($value,1));
  279. $relation->dispatch();
  280. $this->config[$key]=array_shift($relation->entries);
  281. } else {
  282. $this->config[$key]=$value;
  283. }
  284. } else {
  285. $this->config[$key]=$value;
  286. }
  287. }
  288. $pattern = "/§>\s*(\w+):(.*?)\R[\011\040]*\R/s";
  289. $f = preg_match_all($pattern, $string,$matches,PREG_PATTERN_ORDER);
  290. for ($i=0;$i<$f;$i++) {
  291. $string = str_replace($matches[0][$i],"",$string);
  292. $key = $matches[1][$i];
  293. $value = trim($matches[2][$i]);
  294. if(strtolower($value) == "false") {
  295. $value = FALSE;
  296. }
  297. if (!strncmp($value,'@',1)) {
  298. # var_dump();
  299. if (array_key_exists($key,$f3->get('DATA'))) {
  300. $entries = explode("@",$value);
  301. array_shift($entries); // first entry is always empty
  302. $DATA = $f3->get('DATA.'.$key);
  303. $conf = array($DATA['type'],$DATA['dir']);
  304. $relation = new \Modules\TOC($conf,$f3->get('CONTENT'),$entries);
  305. $relation->dispatch();
  306. if(/*count($entries) >*/ 1) {
  307. $this->config[$key]= new CMultiple($relation->entries);
  308. } else {
  309. $this->config[$key]=array_shift($relation->entries);
  310. }
  311. } else {
  312. $this->config[$key]=$value;
  313. }
  314. } else {
  315. $this->config[$key]=$value;
  316. }
  317. }
  318. return $string;
  319. }
  320. function content_element_dispatcher($string) {
  321. $f3 = \Base::instance();
  322. $md = new \freaParsedown();
  323. $md->deactivate_ol();
  324. $f0 = 0;
  325. // find occorances of {| keyword |}
  326. $pattern = "/\{\|(.+?)\|\}/s";
  327. $f = preg_match_all($pattern, $string,$matches,PREG_PATTERN_ORDER);
  328. for ($i=0;$i<$f;$i++) {
  329. $body = preg_split("/\R/",trim($matches[1][$i]));
  330. $request = explode(":", trim(array_shift($body)));
  331. $new="";
  332. switch($request[0]) {
  333. case 'test':
  334. $new="seems to work";
  335. break;
  336. case ';':
  337. $new="";
  338. break;
  339. case 'path':
  340. $new="/".$this->folder;
  341. break;
  342. case 'space':
  343. $new=sprintf("<div style=\"height:%s;\"></div>",
  344. $request[1]
  345. );
  346. break;
  347. case 'span':
  348. $new=sprintf("<span class=\"%s\">%s</span>",
  349. $request[1],
  350. $request[2] ? : implode("\n",$body)
  351. );
  352. break;
  353. case 'small-text':
  354. if(count($body)) {
  355. $new=sprintf("<div class=\"smalltext\">%s</div>",
  356. implode("\n",$body)
  357. );
  358. } else {
  359. $new=sprintf("<span class=\"smalltext\">%s</span>",
  360. $request[1]
  361. );
  362. }
  363. break;
  364. case 'TOC':
  365. // throw away TOC part of request, we don't need it
  366. array_shift($request);
  367. $toc = new \Modules\TOC($request,$this->folder,$body);
  368. $toc->dispatch();
  369. $new=sprintf("<div class=\"TOC %s\">%s</div>",
  370. array_shift($request),
  371. $toc);
  372. break;
  373. case 'form':
  374. $token_db = $f3->get('TEMP') . "CEform/";
  375. $form_config_file = sprintf("%s%s.cfg",
  376. ROOT.$this->folder,
  377. $request[1]);
  378. $db = new \DB\Jig($token_db,\DB\Jig::FORMAT_JSON);
  379. $formcall = new \DB\Jig\Mapper($db,'form_calls');
  380. $timestamp = time();
  381. $token = md5($timestamp . $form_config_file . rand(100,999));
  382. $f3->config($form_config_file);
  383. $f3->set('fields',
  384. array_merge(
  385. $f3->get('fields'),
  386. ['xss-token'=>[
  387. 'type'=>'hidden',
  388. 'value'=>$token,
  389. 'length'=>strlen($token)
  390. ]]
  391. ));
  392. $formcall->token = $token;
  393. $formcall->timestamp = $timestamp;
  394. $formcall->form = $form_config_file;
  395. $formcall->save();
  396. $form_view = new \Template;
  397. $new=$form_view->render('form.htm');
  398. break;
  399. case 'box':
  400. array_shift($request); //get rid of identifier
  401. $type = array_shift($request);
  402. $pics = explode(":",array_shift($body));
  403. $pic = $pics[0];
  404. $pic_hover = count($pics) > 1 ? $pics[1] : $pic;
  405. if (count($body) >= 3) {
  406. $caption = ['normal'=>['cap1' => array_shift($body),
  407. 'cap2' => array_shift($body)],
  408. 'hover'=> ['cap1' => array_shift($body),
  409. 'cap2' => array_shift($body)]];
  410. $caption_html=[];
  411. foreach ($caption as $state => $set) {
  412. if(!$set['cap2']) {
  413. $caption_html[$state] = [
  414. sprintf('<span class="first">&nbsp;</span>'),
  415. sprintf('<span class="first">%s</span>',$set['cap1'])
  416. ];
  417. } else if (!$set['cap1'] && $set['cap2']) {
  418. $caption_html[$state] = [
  419. sprintf('<span class="second">%s</span>',$set['cap2'])
  420. ];
  421. } else {
  422. $caption_html[$state] = [
  423. sprintf('<span class="first">%s</span>',$set['cap1']?:"&nbsp;"),
  424. sprintf('<span class="second">%s</span>',$set['cap2'])
  425. ];
  426. }
  427. }
  428. $has_caption = TRUE;
  429. } else {
  430. $has_caption = FALSE;
  431. }
  432. if (file_exists($this->folder.$pic)) {
  433. $pic = $this->folder.$pic;
  434. } else {
  435. $pic = $f3->get('RESOURCES')."img/default_img.png";
  436. }
  437. if (file_exists($this->folder.$pic_hover)) {
  438. $pic_hover = $this->folder.$pic_hover;
  439. } else {
  440. $pic_hover = $pic;
  441. }
  442. if(0) {
  443. $PIC = new \Image($pic);
  444. $orientation = $PIC->width() > $PIC->height()
  445. ? 'landscape'
  446. : 'portrait'
  447. ;
  448. unset($PIC);
  449. } else {
  450. list($wwidth, $hheight) = getimagesize($pic);
  451. $orientation = $wwidth > $hheight ? 'landscape' : 'portrait';
  452. }
  453. $pic = new CachedImage($pic);
  454. $pic_hover = new CachedImage($pic_hover);
  455. $class="";
  456. $add="";
  457. switch($type) {
  458. case 'plain':
  459. $link=false;
  460. break;
  461. case 'download':
  462. $file = "/".$this->folder.implode(":",$request);
  463. $link='href="'.$file.'" download ';
  464. break;
  465. case 'lightbox':
  466. $body = implode("\n",$body);
  467. if (count($request) % 2) {
  468. $class = array_pop($request);
  469. }
  470. if (count($request) >= 2) {
  471. $body=str_replace([$request[0],$request[1]],["{|","|}"],$body);
  472. $body=$this->content_element_dispatcher($body);
  473. }
  474. $hash=md5($body);
  475. $add=sprintf("<div id=\"%s\" class=\"content_elment_box_body\">\n%s\n</div>",
  476. $hash,
  477. $md->text($body));
  478. $link='href="#" data-featherlight="#'.$hash.'" ';
  479. break;
  480. case 'internal':
  481. $dest=implode(":",$request);
  482. $data = [];
  483. $base = substr($dest,0,strpos($dest,'?') ? : strlen($dest));
  484. parse_str(parse_url($dest,PHP_URL_QUERY),$data);
  485. $fragment = parse_url($dest,PHP_URL_FRAGMENT);
  486. if ($f3->get('LANG') != $f3->get('default_lang')) {
  487. if (!array_key_exists('lang',$data)) {
  488. $data['lang'] = $f3->get('LANG');
  489. }
  490. }
  491. $new_dest = $base;
  492. if (count($data) > 0) {
  493. $new_dest .= "?" . http_build_query($data);
  494. }
  495. if ($fragment) {
  496. $new_dest .= "#" . $fragment;
  497. }
  498. //if ($f3->get('LANG') != $f3->get('default_lang')) {
  499. // $dest .= "?lang=".$f3->get('LANG');
  500. //}
  501. $link=sprintf('href="%s" ',$f3->get('SITE_URL')."/".$new_dest);
  502. break;
  503. case 'external':
  504. $dest=implode(":",$request);
  505. $target = $f3->get('external_links_open_in_new_window')
  506. ? 'target="_blank"'
  507. : ''
  508. ;
  509. $link=sprintf('href="%s" %s',$dest, $target);
  510. break;
  511. default:
  512. $link='href="#"';
  513. break;
  514. }
  515. $new=sprintf("<div class=\"brick %s\">\n<a class=\"content_element_box\" %s>\n<div class=\"content_element_box\">
  516. <div class=\"image\">
  517. <img class=\"standard\" src=\"%s\" /><img class=\"hover\" src=\"%s\" />
  518. </div>
  519. %s
  520. %s
  521. \n</div>\n</a>\n%s\n</div>",
  522. implode(" ",[$orientation,$class,$type]),
  523. $link,
  524. $pic->get_src(1600),
  525. $pic_hover->get_src(1600),
  526. ($has_caption ? "<div class=\"caption standard\">".implode("<br>",$caption_html['normal'])."</div>": " "),
  527. ($has_caption ? "<div class=\"caption hover\">".implode("<br>",$caption_html['hover'])."</div>" : " " ),
  528. $add
  529. );
  530. break;
  531. case 'brick':
  532. array_shift($request);
  533. $class = array_shift($request);
  534. $new = sprintf("<div class=\"content_element brick %s\">\n%s\n</div>",
  535. $class,
  536. $md->text(implode("\n",$body))
  537. );
  538. break;
  539. case 'calendar':
  540. array_shift($request);
  541. $conf = array('path', $this->folder);
  542. $v = $this->read_config();
  543. $cal = new \Modules\CCalendar($v,$conf);
  544. $new=sprintf("<div class=\"calendar\">\n%s\n</div>",
  545. $cal);
  546. break;
  547. case 'header':
  548. array_shift($request);
  549. $conf = array('path', $this->folder);
  550. $v = $this->read_config();
  551. switch (array_shift($request)) {
  552. case 'event':
  553. $el = new CEvent($v,$conf);
  554. $el->set_layout('archive');
  555. $new = $el;
  556. break;
  557. case 'concert':
  558. $el = new CConcert($v,$conf);
  559. $el->set_layout('header');
  560. $new = $el;
  561. break;
  562. }
  563. break;
  564. case 'image':
  565. $key=$request[1];
  566. $image="";
  567. // if(!$key) {
  568. // $new=self::warn("Content Module \"Image\" needs name of a file (without extension)");
  569. // break;
  570. //}
  571. foreach($this->structs as $domain=>$destination) {
  572. if(array_key_exists($key, $this->structs[$domain]['pic'])) {
  573. $image = $this->structs[$domain]['pic'][$key];
  574. unset($this->structs[$domain]['pic'][$key]);
  575. unset($this->content[$this->domains[$domain]][$key]);
  576. break;
  577. }
  578. }
  579. if ($image) {
  580. if( in_array($request[2],array('left','right','full'))) {
  581. $class = $request[2];
  582. } else {
  583. $class = 'full';
  584. }
  585. $img = new \Image($image);
  586. $ratio = ($img->width() >= $img->height())
  587. ? "landscape"
  588. : "portrait"
  589. ;
  590. $cached = new CachedImage($image);
  591. foreach ($body as $k=>$line) {
  592. if (strpos($line,"©") !== FALSE
  593. || strpos($line,"&copy;") !== FALSE) {
  594. $body[$k] = sprintf("<span class=\"copyright\">%s</span>",$line);
  595. }
  596. }
  597. $new=sprintf("<div class='content_element_image %s'>"
  598. ."<div class=\"media %s\"><a href=\"%s\" data-featherlight=\"image\"><img src=\"%s\" alt=\"user supplied image\" /></a></div>"
  599. ."<img src=\"%s\" style=\"display:none;\" alt=\"user supplied image\" />"
  600. ."<div class=\"caption\">%s</div>"
  601. ."</div>",
  602. $class,
  603. $ratio,
  604. $cached->get_src(1600),
  605. $cached->get_src(1600),
  606. $cached->get_src(1600),
  607. $md->text(implode("\n",$body))
  608. );
  609. } else {
  610. $new=sprintf("<div class='content_element_image %s'>\n"
  611. ."<div class=\"media %s\">\n"
  612. ."<div class=\"caption\">\n%s\n</div>\n"
  613. ."</div>\n",
  614. $class,
  615. $ratio,
  616. $md->text(implode("\n",$body))
  617. );
  618. }
  619. break;
  620. case 'devide':
  621. $contents = explode($request[1],implode("\n",$body));
  622. $c=count($contents);
  623. $str="";
  624. for ($iiii=0;$iiii<$c;$iiii++) {
  625. $str .= sprintf(" %f%%",100/$c);
  626. }
  627. $template = sprintf('grid-template-columns:%s;',
  628. $str);
  629. $counter=0;
  630. $new = sprintf('<div class="content_element_devided" style="%s">',$template);
  631. foreach($contents as $part) {
  632. $counter++;
  633. if (count($request) >= 4) {
  634. $part=str_replace([$request[2],$request[3]],["{|","|}"],$part);
  635. $part=$this->content_element_dispatcher($part);
  636. }
  637. $new .= sprintf("<div>\n%s\n</div>",
  638. $md->text($part)
  639. );
  640. }
  641. $new.="</div>";
  642. break;
  643. case 'page':
  644. array_shift($request);
  645. $target = array_shift($request);
  646. $class = array_shift($request);
  647. $folder = $this->folder.$target."/";
  648. $anchor_name=array_pop(explode("/",$target));
  649. $fff = new \Modules\FilesInFolders(
  650. $folder,
  651. array(
  652. 'content'=>array(
  653. 'secondary'=>'secondary',
  654. 'zzz'=>'hidden',
  655. 'unpublish'=>'hidden'
  656. ))
  657. );
  658. $fff->prepare_files();
  659. $fff->fill_content();
  660. $new = sprintf("<div class=\"content_element_page %s\"><a name=\"%s\"></a>\n%s\n</div>",
  661. $class,
  662. $anchor_name,
  663. implode("\n",$fff->content['default']));
  664. break;
  665. case 'youtube':
  666. $vid=array_shift($request);
  667. $pos= array_shift($request);
  668. if( in_array($pos,array('left','right','full'))) {
  669. $class = $pos;
  670. } else {
  671. $class = 'left';
  672. }
  673. $video=sprintf("<iframe width=\"700\" height=\"394\" class=\"ytvideo\" "
  674. ."src=\"https://www.youtube.com/embed/%s\"></iframe>",
  675. $vid);
  676. $thumbnail = sprintf("<div class=\"video-thumbnail\"><a href=\"%s\" data-featherlight=\"#%s\">"
  677. ."<img class=\"thumbnail\" src=\"https://img.youtube.com/vi/%s/mqdefault.jpg\" alt=\"video-preview\"/>"
  678. ."<img class=\"play-button\" src=\"%s\" alt=\"play-button\" />"
  679. ."</a></div><div class=\"lightbox\" id=\"%s\" >%s</div>",
  680. "https://www.youtube.com/watch?v=".$vid,
  681. $vid,
  682. $vid,
  683. "/rsc/img/play-button.png",
  684. $vid,
  685. $video
  686. );
  687. foreach ($body as $k=>$line) {
  688. if (strpos($line,"©") !== FALSE
  689. || strpos($line,"&copy;") !== FALSE) {
  690. $body[$k] = sprintf("<span class=\"copyright\">%s</span>",$line);
  691. }
  692. }
  693. $new=sprintf("<div class='video-container %s'>"
  694. ."<div class=\"media\">%s</div>"
  695. ."<div class=\"caption\">%s</div>"
  696. ."</div>",
  697. $class,
  698. $thumbnail,
  699. $md->text(implode("\n",$body)));
  700. break;
  701. default:
  702. $new=self::warn("Content Module \"".$request[0]."\" unknown");
  703. break;
  704. }
  705. $string = str_replace($matches[0][$i],$new,$string);
  706. }
  707. return $string;
  708. }
  709. function warn($message) {
  710. return sprintf("<div class=\"warning\">%s</div>",$message);
  711. }
  712. }