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