PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/marker.php

https://github.com/markwu/PongoCMS-Laravel-cms-bundle
PHP | 1857 lines | 932 code | 531 blank | 394 comment | 240 complexity | 730eb992315a1ec75d0360e1a7502dfd MD5 | raw file
  1. <?php
  2. class Marker {
  3. /**
  4. * Substitute tag in text with specific HTML
  5. *
  6. * @param string $text
  7. * @return string
  8. */
  9. public static function decode($text)
  10. {
  11. $tmp_text = trim($text);
  12. //con json
  13. preg_match_all('/\[\$([!?A-Z_]+)\[([^$]+)?\]\]/i', $tmp_text, $matches);
  14. foreach($matches[0] as $key => $value) {
  15. //METHOD TO EXECUTE
  16. $method = $matches[1][$key];
  17. //STRING FOUND
  18. $found = $matches[2][$key];
  19. if(substr($found, -1) == ',') $found = substr($found, 0, -1);
  20. //CLEAN HTML
  21. $found = strip_tags($found);
  22. $found = html_entity_decode($found);
  23. $v = json_decode($found, true);
  24. if(!is_array($v)) $v = array();
  25. $vars = $v;
  26. if(method_exists('Marker', $method)) {
  27. //EXECUTE METHOD IF FOUND
  28. $replace = call_user_func('self::' . $method , $vars);
  29. //SUBSTITUTE TAG IN TEXT
  30. if($replace or empty($replace)) $tmp_text = str_replace($value, $replace, $tmp_text);
  31. }
  32. //SKIP ! EXECUTION
  33. if(substr($method, 0, 1) == '!') $tmp_text = str_replace('$!', '$', $tmp_text);
  34. }
  35. //IMG PATH REPLACE
  36. $img_path = '/' . Config::get('cms::settings.data');
  37. $url = Config::get('application.url');
  38. $tmp_text = str_replace('"'.$img_path, '"'.$url.$img_path, $tmp_text);
  39. return $tmp_text;
  40. }
  41. /**
  42. * BACK Marker - Shows a back button
  43. *
  44. * [$BACK[{
  45. * "label":"<label back>" => (default: cms::button.back)
  46. * "url":"" => OPTIONAL (default: SLUG_BACK)
  47. * "id":"<id>", => OPTIONAL (id of <a>)
  48. * "class":"<class>", => OPTIONAL (default: back)
  49. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  50. * }]]
  51. *
  52. * @param array
  53. * @return string
  54. */
  55. public static function BACK($vars = array())
  56. {
  57. //Get variables from array $vars
  58. if( ! empty($vars)) extract($vars);
  59. //Bind variables
  60. $_label = LL('cms::button.back', SITE_LANG);
  61. if(isset($label) and !empty($label)) $_label = $label;
  62. $_url = SLUG_BACK;
  63. if(isset($url) and !empty($url)) $_url = $url;
  64. $_id = null;
  65. if(isset($id) and !empty($id)) $_id = $id;
  66. $_class = 'back';
  67. if(isset($class) and !empty($class)) $_class = $class;
  68. $_tpl = 'back';
  69. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  70. if(!empty($_url)) {
  71. $options = array(
  72. 'id' => $_id,
  73. 'class' => $_class,
  74. );
  75. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  76. $view['label'] = $_label;
  77. $view['url'] = $_url;
  78. $view['options'] = HTML::attributes($options);
  79. return $view;
  80. }
  81. }
  82. /**
  83. * BANNER Marker - Shows a banner rotator as saved in Services / Banner
  84. *
  85. * [$BANNER[{
  86. * "name":"<banner name>",
  87. * "thumb":"<thumb type>" => (default: none)
  88. * "type":"<slider name>" => (default: none)
  89. * "theme":"<theme>" => (default: default)
  90. * "caption":"false" => (default: false)
  91. * "class":"<class>", => OPTIONAL
  92. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  93. * }]]
  94. *
  95. * @param array
  96. * @return string
  97. */
  98. public static function BANNER($vars = array())
  99. {
  100. //Get variables from array $vars
  101. if( ! empty($vars)) extract($vars);
  102. //Bind variables
  103. $_name = '';
  104. if(isset($name) and !empty($name)) $_name = $name;
  105. $_type = '';
  106. if(isset($type) and !empty($type)) $_type = $type;
  107. $_thumb = '';
  108. if(isset($thumb) and !empty($thumb)) $_thumb = $thumb;
  109. $_theme = 'default';
  110. if(isset($theme) and !empty($theme)) $_theme = $theme;
  111. $_caption = false;
  112. if(isset($caption) and !empty($caption) and $caption == 'true') $_caption = true;
  113. $_class = 'banner';
  114. if(isset($class) and !empty($class)) $_class = $class;
  115. $_tpl = 'banner';
  116. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  117. //FORCE NIVO TPL
  118. if(isset($type) and $type == 'nivo') $_tpl = 'nivo';
  119. if(!empty($_name)) {
  120. if($_type == 'nivo') {
  121. //LOAD NIVOSLIDER LIBS
  122. Asset::container('header')->add('nivoslidercss', 'bundles/cms/css/nivoslider.css', 'site_css');
  123. Asset::container('header')->add('nivo'.$_theme, 'bundles/cms/nivoslider/themes/'.$_theme.'/'.$_theme.'.css', 'nivoslidercss');
  124. Asset::container('footer')->add('nivosliderjs', 'bundles/cms/js/jquery.nivoslider.js', 'jquery_lib');
  125. Asset::container('footer')->add('banner', 'js/markers/banner.js', 'site_js');
  126. }
  127. //CACHE DATA
  128. if(CACHE) {
  129. $list = Cache::remember('img_banner_'.$_name, function() use ($_name) {
  130. return CmsBanner::with(array(
  131. 'files' => function($query) {
  132. $query->where('files_banners.date_off', '>=', dateTime2Db(date('Y-m-d H:i:s')));
  133. },
  134. 'files.filetexts' => function($query) {
  135. $query->where('lang', '=', SITE_LANG);
  136. }))->where_name($_name)->first();
  137. }, 1440);
  138. } else {
  139. $list = CmsBanner::with(array(
  140. 'files' => function($query) {
  141. $query->where('files_banners.date_off', '>=', dateTime2Db(date('Y-m-d H:i:s')));
  142. },
  143. 'files.filetexts' => function($query) {
  144. $query->where('lang', '=', SITE_LANG);
  145. }))->where_name($_name)->first();
  146. }
  147. //Load file lable and title
  148. if(!empty($list->files)) {
  149. $images = $list->files;
  150. $attr = $list->files;
  151. } else {
  152. $images = array();
  153. $attr = '';
  154. }
  155. } else {
  156. $images = array();
  157. $attr = '';
  158. }
  159. $options = array(
  160. 'id' => $_name,
  161. 'class' => $_class,
  162. );
  163. $thumbs = CONF('cms::theme.thumb', $_thumb);
  164. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  165. $view['images'] = $images;
  166. $view['thumb'] = (strlen($_thumb) > 0 and array_key_exists('suffix', $thumbs)) ? $thumbs['suffix'] : '';
  167. $view['theme'] = $_theme;
  168. $view['attr'] = $attr;
  169. $view['caption'] = $_caption;
  170. $view['options'] = HTML::attributes($options);
  171. return $view;
  172. }
  173. /**
  174. * BLOGVIEW Marker - Shows a list of last n blogs
  175. *
  176. * [$BLOGVIEW[{
  177. * "source":"<source label>", => (available: blogs, products...)
  178. * "time":"<time label>", => (available: future, past, null - default: null)
  179. * "n":"<n items per page>", => (default: 5)
  180. * "order":"desc", => OPTIONAL (asc, desc default: desc)
  181. * "id":"<id>", => OPTIONAL <ul> id
  182. * "class":"<class>", => OPTIONAL <ul><li> class (default: list)
  183. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  184. * }]]
  185. *
  186. * @param array
  187. * @return string
  188. */
  189. public static function BLOGVIEW($vars = array())
  190. {
  191. //Get variables from array $vars
  192. if( ! empty($vars)) extract($vars);
  193. //Bind variables
  194. $_time = null;
  195. if(isset($time) and !empty($time)) $_time = $time;
  196. $_n = 5;
  197. if(isset($n) and !empty($n)) $_n = $n;
  198. $_order = 'desc';
  199. if(isset($order) and !empty($order)) $_order = $order;
  200. $_id = 'blogview';
  201. if(isset($id) and !empty($id)) $_id = $id;
  202. $_class = 'list';
  203. if(isset($class) and !empty($class)) $_class = $class;
  204. $_tpl = 'blogview';
  205. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  206. //CHECK SOURCE CLASS
  207. if($_n > 0) {
  208. $_sign = '<';
  209. if($_time == 'future') $_sign = '>';
  210. //CACHE DATA
  211. if(CACHE) {
  212. $list = Cache::remember('blog_last', function() {
  213. return CmsBlog::with(array('pages'))
  214. ->where_lang(SITE_LANG)
  215. ->where('datetime_on', $_sign.'=', date('Y-m-d H:i:s'))
  216. ->where('datetime_off', '>', date('Y-m-d H:i:s'))
  217. ->where_is_valid(1)
  218. ->order_by('datetime_on', $_order)
  219. ->take($_n)
  220. ->get();
  221. }, 5);
  222. } else {
  223. $list = CmsBlog::with(array('pages'))
  224. ->where_lang(SITE_LANG)
  225. ->where('datetime_on', $_sign.'=', date('Y-m-d H:i:s'))
  226. ->where('datetime_off', '>', date('Y-m-d H:i:s'))
  227. ->where_is_valid(1)
  228. ->order_by('datetime_on', $_order)
  229. ->take($_n)
  230. ->get();
  231. }
  232. if(!empty($list)) {
  233. $ul_options = array(
  234. 'id' => $_id,
  235. );
  236. $li_options = array(
  237. 'class' => $_class,
  238. );
  239. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  240. $view['list'] = $list;
  241. $view['ul_options'] = HTML::attributes($ul_options);
  242. $view['li_options'] = HTML::attributes($li_options);
  243. return $view;
  244. }
  245. }
  246. }
  247. /**
  248. * CRUMB Marker - Shows a BREADCRUMB style navigation menu
  249. *
  250. * [$CRUMB[{
  251. * "home":"true", => OPTIONAL (default: true)
  252. * "separator":"<char>", => OPTIONAL
  253. * "first":"false", => OPTIONAL (separator at start)
  254. * "last":"false", => OPTIONAL (separator at the end)
  255. * "label":"" => OPTIONAL (default: cms::marker.crumb_here)
  256. * "id":"<id>", => OPTIONAL (id of <ul>)
  257. * "class":"<class>", => OPTIONAL (class of <ul>)
  258. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  259. * }]]
  260. *
  261. * @param array
  262. * @return string
  263. */
  264. public static function CRUMB($vars = array())
  265. {
  266. //Get variables from array $vars
  267. if( ! empty($vars)) extract($vars);
  268. //Bind variables
  269. $_home = true;
  270. if(isset($home) and !empty($home) and $home == 'false') $_home = false;
  271. $_separator = '';
  272. if(isset($separator) and !empty($separator)) $_separator = $separator;
  273. $_first = false;
  274. if(isset($first) and !empty($first) and $first == 'true') $_first = true;
  275. $_last = false;
  276. if(isset($last) and !empty($last) and $last == 'true') $_last = true;
  277. $_label = LL('cms::marker.crumb_here', SITE_LANG)->get();
  278. if(isset($label) and !empty($label)) $_label = $label;
  279. $_id = null;
  280. if(isset($id) and !empty($id)) $_id = $id;
  281. $_class = 'crumb';
  282. if(isset($class) and !empty($class)) $_class = $class;
  283. $_tpl = 'crumb';
  284. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  285. if(!empty($_tpl)) {
  286. //CACHE DATA
  287. if(CACHE) {
  288. $menu = Cache::remember('menu_crumb_'.SITE_LANG, function() {
  289. return $menu = CmsPage::where_lang(SITE_LANG)->get();
  290. }, 1440);
  291. } else {
  292. $menu = CmsPage::where_lang(SITE_LANG)->get();
  293. }
  294. //EXPLODE SLUG
  295. $slugs = explode('/', SLUG_FULL);
  296. $crumbs = array();
  297. $tmp_slug = '';
  298. if($_home) {
  299. foreach ($menu as $item) {
  300. if($item->is_home == 1) {
  301. $crumbs['/'] = $item->name;
  302. }
  303. }
  304. }
  305. foreach ($slugs as $slug) {
  306. $tmp_slug = str_replace('//', '/', $tmp_slug . '/' . $slug);
  307. foreach ($menu as $item) {
  308. if($tmp_slug == $item->slug) {
  309. $crumbs[$tmp_slug] = $item->name;
  310. }
  311. }
  312. }
  313. if(count($slugs) > count($crumbs)) {
  314. $last_slug = SLUG_FULL;
  315. $crumbs[$last_slug] = $_label;
  316. }
  317. } else {
  318. $crumbs = array();
  319. }
  320. $options = array(
  321. 'id' => $_id,
  322. 'class' => $_class,
  323. );
  324. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  325. $view['crumbs'] = $crumbs;
  326. $view['separator'] = $_separator;
  327. $view['first'] = $_first;
  328. $view['last'] = $_last;
  329. $view['options'] = HTML::attributes($options);
  330. return $view;
  331. }
  332. /**
  333. * DOWNLIST Marker - Show a list of download saved in Service / Download
  334. *
  335. * [$DOWNLIST[{
  336. * "name":"<list name>",
  337. * "full":"false", => OPTIONAL (if true, recursive on DOWNLOAD marker)
  338. * "class":"<class>", => OPTIONAL (class of <ul>)
  339. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  340. * }]]
  341. *
  342. * @param array
  343. * @return string
  344. */
  345. public static function DOWNLIST($vars = array())
  346. {
  347. //Get variables from array $vars
  348. if( ! empty($vars)) extract($vars);
  349. //Bind variables
  350. $_name = '';
  351. if(isset($name) and !empty($name)) $_name = $name;
  352. $_full = false;
  353. if(isset($full) and !empty($full) and $full == 'true') $_full = true;
  354. $_class = null;
  355. if(isset($class) and !empty($class)) $_class = $class;
  356. $_tpl = 'downlist';
  357. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  358. //Get DB information
  359. if(!empty($_name)) {
  360. //CACHE DATA
  361. if(CACHE) {
  362. $list = Cache::remember('file_list_'.$_name, function() use ($_name) {
  363. return CmsDownload::with(array(
  364. 'files',
  365. 'files.filetexts' => function($query) {
  366. $query->where('lang', '=', SITE_LANG);
  367. }
  368. ))->where_name($_name)->first();
  369. }, 1440);
  370. } else {
  371. $list = CmsDownload::with(array(
  372. 'files',
  373. 'files.filetexts' => function($query) {
  374. $query->where('lang', '=', SITE_LANG);
  375. }
  376. ))->where_name($_name)->first();
  377. }
  378. //Load file lable and title
  379. if(!empty($list->files)) {
  380. $files = $list->files;
  381. } else {
  382. $files = array();
  383. }
  384. } else {
  385. $files = array();
  386. }
  387. $options = array(
  388. 'id' => $_name,
  389. 'class' => $_class,
  390. );
  391. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  392. $view['files'] = $files;
  393. $view['full'] = $_full;
  394. $view['options'] = HTML::attributes($options);
  395. return $view;
  396. }
  397. /**
  398. * DOWNLOAD Marker - Show a download link to file (not image)
  399. *
  400. * [$DOWNLOAD[{
  401. * "file":"<filename>",
  402. * "label":"label", => OPTIONAL (Overrides default label)
  403. * "id":"<id>", => OPTIONAL (id of <a>)
  404. * "class":"<class>", => OPTIONAL (class of <a> default: download)
  405. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  406. * }]]
  407. *
  408. * @param array
  409. * @return string
  410. */
  411. public static function DOWNLOAD($vars = array())
  412. {
  413. //Get variables from array $vars
  414. if( ! empty($vars)) extract($vars);
  415. //Bind variables
  416. $_file = '';
  417. if(isset($file) and !empty($file)) $_file = $file;
  418. $_label = '';
  419. if(isset($label) and !empty($label)) $_label = $label;
  420. $_id = null;
  421. if(isset($id) and !empty($id)) $_id = $id;
  422. $_class = 'download';
  423. if(isset($class) and !empty($class)) $_class = $class;
  424. $_tpl = 'download';
  425. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  426. //Get DB information
  427. if(!empty($_file)) {
  428. //CACHE DATA
  429. if(CACHE) {
  430. $file = Cache::remember('file_'.MEDIA_NOPOINT($_file).'_'.SITE_LANG, function() use ($_file) {
  431. return CmsFile::with(array('filetexts' => function($query) {
  432. $query->where('lang', '=', SITE_LANG);
  433. }))->where_name($_file)->first();
  434. }, 1440);
  435. } else {
  436. $file = CmsFile::with(array('filetexts' => function($query) {
  437. $query->where('lang', '=', SITE_LANG);
  438. }))->where_name($_file)->first();
  439. }
  440. //Get img dimension
  441. if(!empty($file)) {
  442. $full_path = $file->path;
  443. } else {
  444. $full_path = '';
  445. }
  446. //Load file lable and title
  447. if(!empty($file->filetexts)) {
  448. $title = $file->filetexts[0]->title;
  449. $lab = $file->filetexts[0]->label;
  450. } else {
  451. $title = '';
  452. $lab = $_file;
  453. }
  454. //Override label
  455. if(!empty($_label)) $lab = $_label;
  456. } else {
  457. $full_path = '';
  458. $lab = '';
  459. }
  460. $options = array(
  461. 'id' => $_id,
  462. 'class' => $_class,
  463. 'title' => $title,
  464. );
  465. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  466. $view['path'] = $full_path;
  467. $view['label'] = $lab;
  468. $view['options'] = HTML::attributes($options);
  469. return $view;
  470. }
  471. /**
  472. * GALLERY Marker - Shows an image gallery saved in Service / Gallery
  473. *
  474. * [$GALLERY[{
  475. * "name":"<gallery name>",
  476. * "class":"<class>", => OPTIONAL
  477. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  478. * }]]
  479. *
  480. * @param array
  481. * @return string
  482. */
  483. public static function GALLERY($vars = array())
  484. {
  485. //Get variables from array $vars
  486. if( ! empty($vars)) extract($vars);
  487. //Bind variables
  488. $_name = '';
  489. if(isset($name) and !empty($name)) $_name = $name;
  490. $_class = 'gallery';
  491. if(isset($class) and !empty($class)) $_class = $class;
  492. $_tpl = 'gallery';
  493. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  494. //Get DB information
  495. if(!empty($_name)) {
  496. //CACHE DATA
  497. if(CACHE) {
  498. $gallery = Cache::remember('img_gallery_'.$_name, function() use ($_name) {
  499. return CmsGallery::with(array('files'))->where_name($_name)->first();
  500. }, 1440);
  501. } else {
  502. $gallery = CmsGallery::with(array('files'))->where_name($_name)->first();
  503. }
  504. //Load file lable and title
  505. if(!empty($gallery->files)) {
  506. $images = $gallery->files;
  507. $thumb = $gallery->thumb;
  508. } else {
  509. $images = array();
  510. $thumb = 'thumb';
  511. }
  512. } else {
  513. $images = array();
  514. $thumb = 'thumb';
  515. }
  516. $options = array(
  517. 'id' => $_name,
  518. 'class' => $_class,
  519. );
  520. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  521. $view['images'] = $images;
  522. $view['thumb'] = $thumb;
  523. $view['options'] = HTML::attributes($options);
  524. return $view;
  525. }
  526. /**
  527. * IMAGE Marker - Show a on-the-fly resized image
  528. *
  529. * [$IMAGE[{
  530. * "file":"<filename>",
  531. * "w":"100",
  532. * "h":"100",
  533. * "wm":"true | false", => OPTIONAL
  534. * "id":"<id>", => OPTIONAL
  535. * "class":"<class>" => OPTIONAL
  536. * }]]
  537. *
  538. * @param array
  539. * @return string
  540. */
  541. public static function IMAGE($vars = array())
  542. {
  543. //Get variables from array $vars
  544. if( ! empty($vars)) extract($vars);
  545. //Bind variables
  546. $_file = '';
  547. if(isset($file) and !empty($file)) $_file = $file;
  548. $_w = 100;
  549. if(isset($w) and !empty($w)) $_w = $w;
  550. $_h = 100;
  551. if(isset($h) and !empty($h)) $_h = $h;
  552. $_wm = 'no';
  553. if(isset($wm) and !empty($wm) and $wm == 'true') $_wm = 'wm';
  554. $_id = null;
  555. if(isset($id) and !empty($id)) $_id = $id;
  556. $_class = null;
  557. if(isset($class) and !empty($class)) $_class = $class;
  558. //Get DB information
  559. if(!empty($_file)) {
  560. //CACHE DATA
  561. if(CACHE) {
  562. $file = Cache::remember('img_'.MEDIA_NOPOINT($_file).'_'.SITE_LANG, function() use ($_file) {
  563. return CmsFile::with(array('filetexts' => function($query) {
  564. $query->where('lang', '=', SITE_LANG);
  565. }))->where_name($_file)->first();
  566. }, 1440);
  567. } else {
  568. $file = CmsFile::with(array('filetexts' => function($query) {
  569. $query->where('lang', '=', SITE_LANG);
  570. }))->where_name($_file)->first();
  571. }
  572. //Get img dimension
  573. if(!empty($file)) {
  574. $dim = MEDIA_DIM($file->w, $file->h, $_w, $_h);
  575. } else {
  576. $dim['w'] = '';
  577. $dim['h'] = '';
  578. }
  579. //Load file alt
  580. if(!empty($file->filetexts)) {
  581. $alt = $file->filetexts[0]->alt;
  582. $caption = $file->filetexts[0]->caption;
  583. } else {
  584. $alt = '';
  585. $caption = '';
  586. }
  587. } else {
  588. $alt = '';
  589. $caption = '';
  590. $dim['w'] = '';
  591. $dim['h'] = '';
  592. }
  593. //Create URL path
  594. $url = URL::to_action('cms::image@resize', array($dim['w'], $dim['h'], $_wm, $_file));
  595. return HTML::image($url, $alt, array('width' => $dim['w'], 'height' => $dim['h'], 'id' => $_id, 'class' => $_class));
  596. }
  597. /**
  598. * LANG Marker - Shows a change lang menu
  599. *
  600. * [$LANG[{
  601. * "separator":"<char>", => OPTIONAL
  602. * "first":"false", => OPTIONAL (separator at start)
  603. * "last":"false", => OPTIONAL (separator at the end)
  604. * "exclude":"<lang code-langcode-...>", => OPTIONAL (default: empty)
  605. * "id":"<id>" => (lang id container | default: lang_menu)
  606. * "class":"<class>", => OPTIONAL (default: lang)
  607. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  608. * }]]
  609. *
  610. * @param array
  611. * @return string
  612. */
  613. public static function LANG($vars = array())
  614. {
  615. //Get variables from array $vars
  616. if( ! empty($vars)) extract($vars);
  617. $_separator = '';
  618. if(isset($separator) and !empty($separator)) $_separator = $separator;
  619. $_first = false;
  620. if(isset($first) and !empty($first) and $first == 'true') $_first = true;
  621. $_last = false;
  622. if(isset($last) and !empty($last) and $last == 'true') $_last = true;
  623. $_exclude = '';
  624. if(isset($exclude) and !empty($exclude)) $_exclude = $exclude;
  625. $_id = 'lang_menu';
  626. if(isset($id) and !empty($id)) $_id = $id;
  627. $_class = 'lang';
  628. if(isset($class) and !empty($class)) $_class = $class;
  629. $_tpl = 'lang';
  630. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  631. $options = array(
  632. 'id' => $_id,
  633. 'class' => $_class,
  634. );
  635. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  636. $view['langs'] = Config::get('cms::settings.langs');
  637. $view['separator'] = $_separator;
  638. $view['first'] = $_first;
  639. $view['last'] = $_last;
  640. $view['exclude'] = $_exclude;
  641. $view['options'] = HTML::attributes($options);
  642. return $view;
  643. }
  644. /**
  645. * LINK Marker - Show a link to url
  646. *
  647. * [$LINK[{
  648. * "url":"<url slug>", => (default: base url)
  649. * "label":"<label>", => OPTIONAL (Overrides default label)
  650. * "target":"<target>", => OPTIONAL (default: null)
  651. * "id":"<id>", => OPTIONAL (id of <a>)
  652. * "class":"<class>", => OPTIONAL (class of <a>)
  653. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  654. * }]]
  655. *
  656. * @param array
  657. * @return string
  658. */
  659. public static function LINK($vars = array())
  660. {
  661. //Get variables from array $vars
  662. if( ! empty($vars)) extract($vars);
  663. //Bind variables
  664. $_url = URL::base();
  665. if(isset($url) and !empty($url)) $_url = $url;
  666. $_label = $_url;
  667. if(isset($label) and !empty($label)) $_label = $label;
  668. $_target = null;
  669. if(isset($target) and !empty($target)) $_target = $target;
  670. $_id = null;
  671. if(isset($id) and !empty($id)) $_id = $id;
  672. $_class = null;
  673. if(isset($class) and !empty($class)) $_class = $class;
  674. $_tpl = 'link';
  675. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  676. if(!empty($_url)) {
  677. $options = array(
  678. 'id' => $_id,
  679. 'class' => $_class,
  680. 'target' => $_target,
  681. );
  682. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  683. $view['url'] = $_url;
  684. $view['label'] = $_label;
  685. $view['options'] = HTML::attributes($options);
  686. return $view;
  687. }
  688. }
  689. /**
  690. * LOGIN Marker - Shows a login form
  691. *
  692. * [$LOGIN[{
  693. * "id":"<id>" => OPTIONAL (form ID - default: login_form)
  694. * "class":"<class>", => OPTIONAL (default: login)
  695. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  696. * }]]
  697. *
  698. * @param array
  699. * @return string
  700. */
  701. public static function LOGIN($vars = array())
  702. {
  703. //Get variables from array $vars
  704. if( ! empty($vars)) extract($vars);
  705. $_id = 'login_form';
  706. if(isset($id) and !empty($id)) $_id = $id;
  707. $_class = 'login';
  708. if(isset($class) and !empty($class)) $_class = $class;
  709. $_tpl = 'login';
  710. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  711. $options = array(
  712. 'id' => $_id,
  713. 'class' => $_class,
  714. );
  715. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  716. $view['options'] = HTML::attributes($options);
  717. return $view;
  718. }
  719. /**
  720. * MAP Marker - Shows a Google Maps map
  721. *
  722. * [$MAP[{
  723. * "address":"<street address>",
  724. * "zoom":"14" => Zoom level (default: 14)
  725. * "w":"320", => (map width)
  726. * "h":"240", => (map height)
  727. * "type":"", => (map type: google.maps.MapTypeId.SATELLITE - default: empty)
  728. * "id":"map" => (map id container | default: map)
  729. * "class":"<class>", => OPTIONAL (default: map)
  730. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  731. * }]]
  732. *
  733. * @param array
  734. * @return string
  735. */
  736. public static function MAP($vars = array())
  737. {
  738. //Get variables from array $vars
  739. if( ! empty($vars)) extract($vars);
  740. //Bind variables
  741. $_address = '';
  742. if(isset($address) and !empty($address)) $_address = $address;
  743. $_address = str_replace("'", "\'", $_address);
  744. $_zoom = 14;
  745. if(isset($zoom) and !empty($zoom)) $_zoom = $zoom;
  746. $_w = 320;
  747. if(isset($w) and !empty($w)) $_w = $w;
  748. $_h = 240;
  749. if(isset($h) and !empty($h)) $_h = $h;
  750. $_type = '';
  751. if(isset($type) and !empty($type)) $_type = $type;
  752. $_id = 'map';
  753. if(isset($id) and !empty($id)) $_id = $id;
  754. $_class = 'map';
  755. if(isset($class) and !empty($class)) $_class = $class;
  756. $_tpl = 'map';
  757. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  758. if(!empty($_address)) {
  759. //LOAD GOOLE MAPS LIBS
  760. Asset::container('header')->add('googlemaps', 'http://maps.google.com/maps/api/js?sensor=false', 'jquery');
  761. Asset::container('header')->add('gmap3', 'bundles/cms/js/jquery.gmap3.js', 'googlemaps');
  762. switch ($_type) {
  763. case 'satellite':
  764. $map_type = 'google.maps.MapTypeId.SATELLITE';
  765. break;
  766. default:
  767. $map_type = '';
  768. break;
  769. }
  770. $options = array(
  771. 'id' => $_id,
  772. 'class' => $_class,
  773. );
  774. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  775. $view['address'] = $_address;
  776. $view['zoom'] = $_zoom;
  777. $view['w'] = $_w;
  778. $view['h'] = $_h;
  779. $view['maptype'] = $map_type;
  780. $view['id'] = $_id;
  781. $view['options'] = HTML::attributes($options);
  782. return $view;
  783. }
  784. }
  785. /**
  786. * MENU Marker - Show a menu saved in Service / Menu
  787. *
  788. * [$MENU[{
  789. * "name":"<menu name>",
  790. * "class":"<class>", => OPTIONAL (<ul> class)
  791. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  792. * }]]
  793. *
  794. * @param array
  795. * @return string
  796. */
  797. public static function MENU($vars = array())
  798. {
  799. //Get variables from array $vars
  800. if( ! empty($vars)) extract($vars);
  801. //Bind variables
  802. $_name = '';
  803. if(isset($name) and !empty($name)) $_name = $name;
  804. $_class = 'menu';
  805. if(isset($class) and !empty($class)) $_class = $class;
  806. $_tpl = 'menu';
  807. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  808. //Get DB information
  809. if(!empty($_name)) {
  810. //CACHE DATA
  811. if(CACHE) {
  812. $m = Cache::remember('menu_'.$_name.'_'.SITE_LANG, function() use ($_name) {
  813. return CmsMenu::where_name($_name)
  814. ->where_lang(SITE_LANG)
  815. ->first();
  816. }, 5);
  817. } else {
  818. $m = CmsMenu::where_name($_name)
  819. ->where_lang(SITE_LANG)
  820. ->first();
  821. }
  822. if(!empty($m)) {
  823. $id = $m->id;
  824. $nested = (bool) $m->is_nested;
  825. $lower_parent = 0;
  826. if($nested) {
  827. $lower_parent = $m->parent_start;
  828. }
  829. //CACHE DATA
  830. if(CACHE) {
  831. $menu = Cache::remember('menu_pages_'.$_name.'_'.SITE_LANG, function() use ($_name, $nested, $lower_parent) {
  832. return CmsMenu::with(array('pages' => function($query) use ($nested, $lower_parent) {
  833. if($nested) $query->where('parent_id', '=', $lower_parent);
  834. }))
  835. ->where_name($_name)
  836. ->where_lang(SITE_LANG)
  837. ->first();
  838. }, 5);
  839. } else {
  840. $menu = CmsMenu::with(array('pages' => function($query) use ($nested, $lower_parent) {
  841. if($nested) $query->where('parent_id', '=', $lower_parent);
  842. }))
  843. ->where_name($_name)
  844. ->where_lang(SITE_LANG)
  845. ->first();
  846. }
  847. //Load file lable and title
  848. if(!empty($menu->pages)) {
  849. $pages = $menu->pages;
  850. // $nested = (bool) $m->is_nested;
  851. $nested = (bool) $nested;
  852. } else {
  853. $pages = array();
  854. $nested = false;
  855. }
  856. } else {
  857. $id = null;
  858. $pages = array();
  859. $nested = false;
  860. }
  861. } else {
  862. $id = null;
  863. $pages = array();
  864. $nested = false;
  865. }
  866. $options = array(
  867. 'id' => $_name,
  868. 'class' => $_class,
  869. );
  870. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  871. $view['mid'] = $id;
  872. $view['pages'] = $pages;
  873. $view['nested'] = $nested;
  874. $view['options'] = HTML::attributes($options);
  875. return $view;
  876. }
  877. /**
  878. * MENU_CUSTOM Marker - Show a custom menu by template
  879. *
  880. * [$MENU_CUSTOM[{
  881. * "id":"menu_custom" => (menu id container | default: menu_custom)
  882. * "class":"<class>", => OPTIONAL (default: menu_custom)
  883. * "tpl":"menu_custom" => OPTIONAL (in /partials/markers)
  884. * }]]
  885. *
  886. * @param array
  887. * @return string
  888. */
  889. public static function MENU_CUSTOM($vars = array())
  890. {
  891. //Get variables from array $vars
  892. if( ! empty($vars)) extract($vars);
  893. //Bind variables
  894. $_id = 'menu_custom';
  895. if(isset($id) and !empty($id)) $_id = $id;
  896. $_class = 'menu_custom';
  897. if(isset($class) and !empty($class)) $_class = $class;
  898. $_tpl = 'menu_custom';
  899. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  900. $options = array(
  901. 'id' => $_id,
  902. 'class' => $_class,
  903. );
  904. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  905. $view['options'] = HTML::attributes($options);
  906. return $view;
  907. }
  908. /**
  909. * MENU_SUB Marker - Shows a submenu linked to sub elements
  910. *
  911. * [$MENU_SUB[{
  912. * "zone":"<elem's zone>" => (default: 1)
  913. * "id":"menu_sub" => OPTIONAL (menu id container | default: menu_sub)
  914. * "class":"<class>", => OPTIONAL (default: menu_sub)
  915. * "tpl":"menu_sub" => OPTIONAL (in /partials/markers)
  916. * }]]
  917. *
  918. * @param array
  919. * @return string
  920. */
  921. public static function MENU_SUB($vars = array())
  922. {
  923. //Get variables from array $vars
  924. if( ! empty($vars)) extract($vars);
  925. //Bind variables
  926. $_zone = 'ZONE1';
  927. if(isset($zone) and !empty($zone)) $_zone = 'ZONE'.$zone;
  928. $_id = 'menu_sub';
  929. if(isset($id) and !empty($id)) $_id = $id;
  930. $_class = 'menu_sub';
  931. if(isset($class) and !empty($class)) $_class = $class;
  932. $_tpl = 'menu_sub';
  933. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  934. //CACHE DATA
  935. if(CACHE) {
  936. $page = Cache::remember('menu_sub_'.md5(SLUG_FULL).'_'.SITE_LANG, function() use ($_zone) {
  937. return CmsPage::with(array('elements' => function($query) use ($_zone) {
  938. $query->where_zone($_zone)->where_is_valid(1);
  939. }))
  940. ->where_slug(SLUG_FULL)
  941. ->where_lang(SITE_LANG)
  942. ->where_is_valid(1)
  943. ->first();
  944. }, 5);
  945. } else {
  946. $page = CmsPage::with(array('elements' => function($query) use ($_zone) {
  947. $query->where_zone($_zone)->where_is_valid(1);
  948. }))
  949. ->where_slug(SLUG_FULL)
  950. ->where_lang(SITE_LANG)
  951. ->where_is_valid(1)
  952. ->first();
  953. }
  954. $elements = !empty($page->elements) ? $page->elements : array();
  955. $options = array(
  956. 'id' => $_id,
  957. 'class' => $_class,
  958. );
  959. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  960. $view['slug'] = SLUG_FULL;
  961. $view['elements'] = $elements;
  962. $view['options'] = HTML::attributes($options);
  963. return $view;
  964. }
  965. /**
  966. * PREVIEW Marker - Shows a list of contents from source
  967. *
  968. * [$PREVIEW[{
  969. * "source":"<source label>", => (available: blogs, products...)
  970. * "time":"<time label>", => (available: future, past, null - default: null)
  971. * "n":"<n items per page>", => (default: config.design.pag)
  972. * "id":"<id>", => OPTIONAL <ul> id
  973. * "class":"<class>", => OPTIONAL <ul><li> class (default: list)
  974. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  975. * }]]
  976. *
  977. * @param array
  978. * @return string
  979. */
  980. public static function PREVIEW($vars = array())
  981. {
  982. //Get variables from array $vars
  983. if( ! empty($vars)) extract($vars);
  984. //Bind variables
  985. $_source = '';
  986. if(isset($source) and !empty($source)) $_source = $source;
  987. $_time = null;
  988. if(isset($time) and !empty($time)) $_time = $time;
  989. $_n = Config::get('cms::theme.site_pag');
  990. if(isset($n) and !empty($n)) $_n = $n;
  991. $_id = 'preview';
  992. if(isset($id) and !empty($id)) $_id = $id;
  993. $_class = 'list';
  994. if(isset($class) and !empty($class)) $_class = $class;
  995. $_tpl = 'preview';
  996. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  997. if(!empty($_source)) {
  998. //SET MODEL RELATION
  999. $_source = $_source . '_preview';
  1000. if(!is_null($_time)) $_source = $_source . '_' . $_time;
  1001. //CACHE DATA
  1002. if(CACHE) {
  1003. $page = Cache::remember('page_'.Str::slug(SLUG_LAST, '_').'_'.SITE_LANG, function() use ($_source) {
  1004. return CmsPage::where_lang(SITE_LANG)->where_slug(SLUG_FULL)->first();
  1005. }, 5);
  1006. } else {
  1007. $page = CmsPage::where_lang(SITE_LANG)->where_slug(SLUG_FULL)->first();
  1008. }
  1009. if(!empty($page)) {
  1010. //CACHE DATA
  1011. if(CACHE) {
  1012. $list = Cache::remember($_source.'_'.$page->id.'_'.Input::get('page', 1), function() use ($_source, $page, $_n) {
  1013. return CmsPage::find($page->id)
  1014. ->$_source()
  1015. ->paginate($_n);
  1016. }, 5);
  1017. } else {
  1018. $list = CmsPage::find($page->id)
  1019. ->$_source()
  1020. ->paginate($_n);
  1021. }
  1022. $ul_options = array(
  1023. 'id' => $_id,
  1024. );
  1025. $li_options = array(
  1026. 'class' => $_class,
  1027. );
  1028. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  1029. $view['page'] = $page;
  1030. $view['ul_options'] = HTML::attributes($ul_options);
  1031. $view['li_options'] = HTML::attributes($li_options);
  1032. if(!empty($list)) {
  1033. $view['list'] = $list;
  1034. } else {
  1035. $view['list'] = array();
  1036. }
  1037. return $view;
  1038. }
  1039. }
  1040. }
  1041. /**
  1042. * SEARCH Marker - Shows a search form
  1043. *
  1044. * [$SEARCH[{
  1045. * "source":"<source-source>", => (available: pages, blogs - default: pages)
  1046. * "id":"<id>" => OPTIONAL (form ID - default: search_form)
  1047. * "class":"<class>", => OPTIONAL (default: search)
  1048. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  1049. * }]]
  1050. *
  1051. * @param array
  1052. * @return string
  1053. */
  1054. public static function SEARCH($vars = array())
  1055. {
  1056. //Get variables from array $vars
  1057. if( ! empty($vars)) extract($vars);
  1058. $_source = 'pages';
  1059. if(isset($source) and !empty($source)) $_source = $source;
  1060. $_id = 'search_form';
  1061. if(isset($id) and !empty($id)) $_id = $id;
  1062. $_class = 'search';
  1063. if(isset($class) and !empty($class)) $_class = $class;
  1064. $_tpl = 'search';
  1065. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  1066. $options = array(
  1067. 'id' => $_id,
  1068. 'class' => $_class,
  1069. );
  1070. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  1071. $view['source'] = $_source;
  1072. $view['options'] = $options;
  1073. return $view;
  1074. }
  1075. /**
  1076. * SOCIAL Marker - Shows a social toolbar
  1077. *
  1078. * [$SOCIAL[{
  1079. * "what":"facebook", => (available: facebook-twitter-linkedin-google-follow)
  1080. * "user":"[username]" => OPTIONAL (MANDATORY if 'what' includes 'follow or linkedin')
  1081. * "class":"<class>", => OPTIONAL (default: social)
  1082. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  1083. * }]]
  1084. *
  1085. * @param array
  1086. * @return string
  1087. */
  1088. public static function SOCIAL($vars = array())
  1089. {
  1090. //Get variables from array $vars
  1091. if( ! empty($vars)) extract($vars);
  1092. //Bind variables
  1093. $_what = 'facebook';
  1094. if(isset($what) and !empty($what)) $_what = trim(str_replace(' ', '', $what));
  1095. $_user = '';
  1096. if(isset($user) and !empty($user)) $_user = $user;
  1097. $_class = 'addthis_toolbox addthis_default_style social';
  1098. if(isset($class) and !empty($class)) $_class = $class;
  1099. $_tpl = 'social';
  1100. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  1101. if(!empty($_what)) {
  1102. //LOAD ADDTHIS LIBS
  1103. Asset::container('header')->add('addthis', 'http://s7.addthis.com/js/250/addthis_widget.js', 'jquery');
  1104. $services = explode("-", $_what);
  1105. $options = array(
  1106. 'class' => $_class,
  1107. );
  1108. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  1109. $view['services'] = $services;
  1110. $view['user'] = $_user;
  1111. $view['options'] = HTML::attributes($options);
  1112. return $view;
  1113. }
  1114. }
  1115. /**
  1116. * THUMB Marker - Show a pre-config or on-the-fly resized thumb image linked to original
  1117. *
  1118. * [$THUMB[{
  1119. * "file":"<filename>",
  1120. * "thumb":"thumb",
  1121. * "caption":"false" => (default: false)
  1122. * "w":"100", => OPTIONAL (overrides thumb)
  1123. * "h":"100", => OPTIONAL (overrides thumb)
  1124. * "wm":"true | false", => OPTIONAL
  1125. * "id":"<id>", => OPTIONAL (id of <a>)
  1126. * "class":"<class>", => OPTIONAL
  1127. * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers)
  1128. * }]]
  1129. *
  1130. * @param array
  1131. * @return string
  1132. */
  1133. public static function THUMB($vars = array())
  1134. {
  1135. //Get variables from array $vars
  1136. if( ! empty($vars)) extract($vars);
  1137. //Bind variables
  1138. $_file = '';
  1139. if(isset($file) and !empty($file)) $_file = $file;
  1140. $_thumb = 'thumb';
  1141. if(isset($thumb) and !empty($thumb)) $_thumb = $thumb;
  1142. $_caption = false;
  1143. if(isset($caption) and !empty($caption) and $caption == 'true') $_caption = true;
  1144. $_w = '';
  1145. if(isset($w) and !empty($w)) $_w = $w;
  1146. $_h = '';
  1147. if(isset($h) and !empty($h)) $_h = $h;
  1148. $_wm = 'no';
  1149. if(isset($wm) and !empty($wm) and $wm == 'true') $_wm = 'wm';
  1150. $_id = null;
  1151. if(isset($id) and !empty($id)) $_id = $id;
  1152. $_class = null;
  1153. if(isset($class) and !empty($class)) $_class = $class;
  1154. $_tpl = 'thumb';
  1155. if(isset($tpl) and !empty($tpl)) $_tpl = $tpl;
  1156. //Get DB information
  1157. if(!empty($_file)) {
  1158. //CACHE DATA
  1159. if(CACHE) {
  1160. $file = Cache::remember('img_'.MEDIA_NOPOINT($_file).'_'.SITE_LANG, function() use ($_file) {
  1161. return CmsFile::with(array('filetexts' => function($query) {
  1162. $query->where('lang', '=', SITE_LANG);
  1163. }))->where_name($_file)->first();
  1164. }, 1440);
  1165. } else {
  1166. $file = CmsFile::with(array('filetexts' => function($query) {
  1167. $query->where('lang', '=', SITE_LANG);
  1168. }))->where_name($_file)->first();
  1169. }
  1170. //Get img dimension
  1171. if(!empty($file)) {
  1172. //LOAD FANCYBOX LIBS
  1173. Asset::container('header')->add('fancyboxcss', 'bundles/cms/css/fancybox.css', 'site_css');
  1174. Asset::container('footer')->add('fancybox', 'bundles/cms/js/jquery.fancybox.js', 'jquery_lib');
  1175. Asset::container('footer')->add('thumb', 'js/markers/thumb.js', 'site_js');
  1176. if(empty($_w) and empty($_h)) {
  1177. $_filename = MEDIA_NAME($_file, Config::get('cms::theme.thumb.'.$_thumb.'.suffix'));
  1178. $dim['w'] = Config::get('cms::theme.thumb.'.$_thumb.'.width');
  1179. $dim['h'] = Config::get('cms::theme.thumb.'.$_thumb.'.height');
  1180. $url = MEDIA_NAME($file->path, Config::get('cms::theme.thumb.'.$_thumb.'.suffix'));
  1181. } else {
  1182. $_filename = $file->name;
  1183. $dim = MEDIA_DIM($file->w, $file->h, $_w, $_h);
  1184. $url = URL::to_action('cms::image@resize', array($_w, $_h, $_wm, $_filename));
  1185. }
  1186. $full_path = $file->path;
  1187. } else {
  1188. $_filename = '';
  1189. $dim['w'] = '';
  1190. $dim['h'] = '';
  1191. }
  1192. //Load file alt and title
  1193. if(!empty($file->filetexts)) {
  1194. $title = $file->filetexts[0]->title;
  1195. $alt = $file->filetexts[0]->alt;
  1196. $caption = $file->filetexts[0]->caption;
  1197. } else {
  1198. $title = '';
  1199. $alt = '';
  1200. $caption = '';
  1201. }
  1202. } else {
  1203. $full_path = '';
  1204. $title = '';
  1205. $alt = '';
  1206. $caption = '';
  1207. $url = '';
  1208. $dim['w'] = '';
  1209. $dim['h'] = '';
  1210. }
  1211. $img = HTML::image($url, $alt, array('width' => $dim['w'], 'height' => $dim['h'], 'id' => $_id, 'class' => $_class));
  1212. $options = array(
  1213. 'id' => $_id,
  1214. 'title' => $title,
  1215. 'rel' => 'fancybox'
  1216. );
  1217. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_tpl);
  1218. $view['path'] = $full_path;
  1219. $view['img'] = $img;
  1220. $view['options'] = HTML::attributes($options);
  1221. $view['caption'] = $_caption;
  1222. $view['caption_text'] = $caption;
  1223. return $view;
  1224. }
  1225. /**
  1226. * TRANSLATION Marker - Shows a translated portion of text in current language
  1227. *
  1228. * [$TRANSLATION[{
  1229. * "key":"<text>",
  1230. * "style":"<lower | upper | capital | allcapital>", => OPTIONAL (default: lower)
  1231. * "to":"<lang code>" => OPTIONAL (default: settings.language)
  1232. * }]]
  1233. *
  1234. * @param array
  1235. * @return string
  1236. */
  1237. public static function TRANSLATION($vars = array())
  1238. {
  1239. //Get variables from array $vars
  1240. if( ! empty($vars)) extract($vars);
  1241. //Bind variables
  1242. $_key = '';
  1243. if(isset($key) and !empty($key)) $_key = trim(str_replace(' ', ' ', $key));
  1244. $_style = '';
  1245. if(isset($style) and !empty($style)) $_style = $style;
  1246. $_to = SITE_LANG;
  1247. if(isset($to) and !empty($to)) $_to = $to;
  1248. //Get DB information
  1249. if(!empty($_key)) {
  1250. //CACHE DATA
  1251. if(CACHE) {
  1252. $trans = Cache::remember('trans_'.md5($_key).'_'.$_to, function() use ($_key, $_to) {
  1253. return CmsTranslation::where_lang_from(Config::get('cms::settings.language'))
  1254. ->where_lang_to($_to)
  1255. ->where_word($_key)
  1256. ->first();
  1257. }, 1440);
  1258. } else {
  1259. $trans = CmsTranslation::where_lang_from(Config::get('cms::settings.language'))
  1260. ->where_lang_to($_to)
  1261. ->where_word($_key)
  1262. ->first();
  1263. }
  1264. //Load file lable and title
  1265. if(!empty($trans)) {
  1266. $value = $trans->value;
  1267. return CmsUtility::string_style($value, $style = $_style);
  1268. } else {
  1269. return $_key;
  1270. }
  1271. } else {
  1272. return $_key;
  1273. }
  1274. return $_key;
  1275. }
  1276. /**
  1277. * VIDEO Marker - Shows video embed from Youtube, Screenr or Vimeo
  1278. *
  1279. * [$video[{
  1280. * "code":"<video code>", => (video code)
  1281. * "site":"youtube", => (available: youtube || screenr || vimeo)
  1282. * "w":"420", => (video width)
  1283. * "h":"315", => (video height)
  1284. * "class":"<class>", => OPTIONAL (default: video)
  1285. * }]]
  1286. *
  1287. * @param array
  1288. * @return string
  1289. */
  1290. public static function VIDEO($vars = array())
  1291. {
  1292. //Get variables from array $vars
  1293. if( ! empty($vars)) extract($vars);
  1294. //Bind variables
  1295. $_code = '';
  1296. if(isset($code) and !empty($code)) $_code = $code;
  1297. $_site = 'youtube';
  1298. if(isset($site) and !empty($site)) $_site = $site;
  1299. $_w = 420;
  1300. if(isset($w) and !empty($w)) $_w = $w;
  1301. $_h = 315;
  1302. if(isset($h) and !empty($h)) $_h = $h;
  1303. $_class = 'video';
  1304. if(isset($class) and !empty($class)) $_class = $class;
  1305. if(!empty($_code)) {
  1306. $options = array(
  1307. 'class' => $_class,
  1308. );
  1309. $view = View::make('cms::theme.'.THEME.'.partials.markers.'.$_site);
  1310. $view['code'] = $_code;
  1311. $view['w'] = $_w;
  1312. $view['h'] = $_h;
  1313. $view['options'] = HTML::attributes($options);
  1314. return $view;
  1315. }
  1316. }
  1317. }