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.

850 lines
33KB

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