mostly filebased Content Presentation System
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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