PageRenderTime 56ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/class-SS_Framework_Foundation.php

https://gitlab.com/aristath/shoestrap-foundation
PHP | 469 lines | 298 code | 107 blank | 64 comment | 66 complexity | c4148a06417cf69d267f4874efa9c6f4 MD5 | raw file
  1. <?php
  2. if ( !class_exists( 'SS_Framework_Foundation' ) ) {
  3. /**
  4. * The Foundation Framework module
  5. */
  6. class SS_Framework_Foundation extends SS_Framework_Core {
  7. var $defines = array(
  8. // Generic framework definitions
  9. 'shortname' => 'foundation',
  10. 'name' => 'Foundation',
  11. 'classname' => 'SS_Framework_Foundation',
  12. 'compiler' => 'sass_php',
  13. // Layout
  14. 'container' => null,
  15. 'row' => 'row',
  16. 'col-mobile' => 'small',
  17. 'col-tablet' => 'small',
  18. 'col-medium' => 'medium',
  19. 'col-large' => 'large',
  20. // Block Grid not supported
  21. // Buttons
  22. 'button' => 'button',
  23. 'button-default' => null,
  24. 'button-primary' => null,
  25. 'button-success' => 'success',
  26. 'button-info' => 'secondary',
  27. 'button-warning' => 'alert',
  28. 'button-danger' => 'alert',
  29. 'button-link' => null,
  30. 'button-disabled'=> 'disabled',
  31. 'button-extra-small' => 'tiny',
  32. 'button-small' => 'small',
  33. 'button-medium' => null,
  34. 'button-large' => 'large',
  35. 'button-extra-large' => 'large',
  36. 'button-block' => 'expand',
  37. // Button-Groups
  38. 'button-group' => 'button-group',
  39. 'button-group-extra-small' => null,
  40. 'button-group-small' => null,
  41. 'button-group-default' => null,
  42. 'button-group-large' => null,
  43. 'button-group-extra-large' => null,
  44. // Button Bar not supported
  45. // Alerts
  46. 'alert' => 'alert-box',
  47. 'alert-success' => 'success',
  48. 'alert-info' => 'info',
  49. 'alert-warning' => 'warning',
  50. 'alert-danger' => 'warning',
  51. // Miscelaneous
  52. 'clearfix' => '<div class="clearfix"></div>',
  53. // Forms
  54. 'form-input' => 'form-control',
  55. );
  56. /**
  57. * Class constructor
  58. */
  59. function __construct() {
  60. if ( ! defined( 'SS_FRAMEWORK_PATH' ) ) {
  61. define( 'SS_FRAMEWORK_PATH', dirname( __FILE__ ) );
  62. }
  63. if ( class_exists( 'ReduxFrameworkPlugin' ) ) {
  64. include_once( dirname( __FILE__ ) . '/modules/class-SS_Foundation_Colors.php' );
  65. include_once( dirname( __FILE__ ) . '/modules/class-SS_Foundation_Typography.php' );
  66. include_once( dirname( __FILE__ ) . '/modules/class-SS_Foundation_Walker_Comment.php' );
  67. // include_once( dirname( __FILE__ ) . '/modules/class-Shoestrap_Social.php' );
  68. include_once( dirname( __FILE__ ) . '/modules/class-SS_Foundation_Layout.php' );
  69. include_once( dirname( __FILE__ ) . '/modules/class-SS_Foundation_Background.php' );
  70. include_once( dirname( __FILE__ ) . '/modules/class-SS_Foundation_Header.php' );
  71. include_once( dirname( __FILE__ ) . '/modules/class-SS_Foundation_Menus.php' );
  72. include_once( dirname( __FILE__ ) . '/modules/class-SS_Foundation_Footer.php' );
  73. include_once( dirname( __FILE__ ) . '/modules/widgets.php' );
  74. // instantiate the classes
  75. global $ss_layout;
  76. $ss_layout = new SS_Foundation_Layout();
  77. global $ss_background;
  78. $ss_background = new SS_Foundation_Background();
  79. global $ss_branding;
  80. $ss_branding = new SS_Foundation_Colors();
  81. global $ss_headers;
  82. $ss_headers = new SS_Foundation_Header();
  83. global $ss_menus;
  84. $ss_menus = new SS_Foundation_Menus();
  85. global $ss_typography;
  86. $ss_typography = new SS_Foundation_Typography();
  87. global $ss_footer;
  88. $ss_footer = new SS_Foundation_Footer();
  89. add_filter( 'foundation_scss', array( $this, 'styles_filter' ) );
  90. add_filter( 'comments_template', array( $this, 'comments_template' ) );
  91. add_action( 'wp_enqueue_scripts', array( $this, 'css' ), 101 );
  92. add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ), 110 );
  93. }
  94. }
  95. /**
  96. * Enqueue scripts and stylesheets
  97. */
  98. function enqueue_scripts() {
  99. wp_register_script( 'foundation-min', SSF_PLUGIN_URL . '/assets/js/foundation.min.js', false, null, true );
  100. wp_enqueue_script( 'foundation-min' );
  101. }
  102. function comments_template() {
  103. return dirname( __FILE__ ) . '/templates/comments.php';
  104. }
  105. public function make_dropdown_button( $color = 'primary', $size = 'medium', $type = null, $extra = null, $label = '', $content = '' ) {
  106. global $ss_framework;
  107. $id_nr = rand( 0, 9999 );
  108. $return .= '<a href="#" data-dropdown="drop' . $id_nr . '" class="' . $ss_framework->button_classes( $color, $size, $type, 'dropdown ' . $extra ) . '">' . $label . '</a>';
  109. $return .= '<ul id="drop' . $id_nr . '" data-dropdown-content class="f-dropdown">' . $content . '</ul>';
  110. return $return;
  111. }
  112. /**
  113. * The framework's alert boxes.
  114. */
  115. function alert( $type = 'info', $content = '', $id = null, $extra_classes = null, $dismiss = false ) {
  116. $classes = array();
  117. $classes[] = $this->defines['alert'];
  118. $classes[] = $this->defines['alert-' . $type];
  119. if ( true == $dismiss ) {
  120. $dismiss = '<a href="#" class="close">&times;</a>';
  121. } else {
  122. $dismiss = null;
  123. }
  124. if ( !is_null( $extra_classes ) ) {
  125. $extras = explode( ' ', $extra_classes );
  126. foreach ( $extras as $extra ) {
  127. $classes[] = $extra;
  128. }
  129. }
  130. // If an ID has been defined, format it properly.
  131. if ( !is_null( $id ) ) {
  132. $id = ' id=' . $id . '"';
  133. }
  134. $classes = implode( ' ', $classes );
  135. return '<div data-alert class="' . $classes . '"' . $id . '>' . $content . $dismiss . '</div>';
  136. }
  137. function open_panel( $extra_classes = null, $id = null ) {
  138. $classes = array();
  139. if ( !is_null( $extra_classes ) ) {
  140. $extras = explode( ' ', $extra_classes );
  141. foreach ( $extras as $extra ) {
  142. $classes[] = $extra;
  143. }
  144. $classes = ' ' . implode( ' ', $classes );
  145. } else {
  146. $classes = null;
  147. }
  148. // If an ID has been defined, format it properly.
  149. if ( !is_null( $id ) ) {
  150. $id = ' id=' . $id . '"';
  151. }
  152. return '<div class="panel ' . $classes . '"' . $id . '>';
  153. }
  154. function panel_classes() {
  155. return 'panel';
  156. }
  157. function open_panel_heading( $extra_classes = null ) {
  158. $classes = array();
  159. if ( !is_null( $extra_classes ) ) {
  160. $extras = explode( ' ', $extra_classes );
  161. foreach ( $extras as $extra ) {
  162. $classes[] = $extra;
  163. }
  164. $classes = ' ' . implode( ' ', $classes );
  165. } else {
  166. $classes = null;
  167. }
  168. return '<div class="panel-heading' . $classes . '">';
  169. }
  170. function open_panel_body( $extra_classes = null ) {
  171. $classes = array();
  172. if ( !is_null( $extra_classes ) ) {
  173. $extras = explode( ' ', $extra_classes );
  174. foreach ( $extras as $extra ) {
  175. $classes[] = $extra;
  176. }
  177. $classes = ' ' . implode( ' ', $classes );
  178. } else {
  179. $classes = null;
  180. }
  181. return '<div class="panel-body' . $classes . '">';
  182. }
  183. function open_panel_footer( $extra_classes = null ) {
  184. $classes = array();
  185. if ( !is_null( $extra_classes ) ) {
  186. $extras = explode( ' ', $extra_classes );
  187. foreach ( $extras as $extra ) {
  188. $classes[] = $extra;
  189. }
  190. $classes = ' ' . implode( ' ', $classes );
  191. } else {
  192. $classes = null;
  193. }
  194. return '<div class="panel-footer' . $classes . '">';
  195. }
  196. /**
  197. * Variables to use for the compiler.
  198. * These override the default Bootstrap Variables.
  199. */
  200. function styles() {
  201. global $ss_settings;
  202. $vars = '';
  203. // Base font-size
  204. if ( isset( $ss_settings['base-font']['font-size'] ) && ! empty( $ss_settings['base-font']['font-size'] ) ) {
  205. $vars .= '$base-font-size:' . $ss_settings['base-font']['font-size'] . ';';
  206. }
  207. // Base font-color
  208. if ( isset( $ss_settings['base-font']['font-color'] ) && ! empty( $ss_settings['base-font']['font-color'] ) ) {
  209. $vars .= '$body-font-color:' . $ss_settings['base-font']['color'] . ';';
  210. }
  211. // Base font-family
  212. if ( isset( $ss_settings['base-font']['font-family'] ) && ! empty( $ss_settings['base-font']['font-family'] ) ) {
  213. $vars .= '$body-font-family:' . $ss_settings['base-font']['font-family'] . ';';
  214. }
  215. // Base font-weight
  216. if ( isset( $ss_settings['base-font']['font-weight'] ) && ! empty( $ss_settings['base-font']['font-weight'] ) ) {
  217. $vars .= '$body-font-weight:' . $ss_settings['base-font']['font-weight'] . ';';
  218. }
  219. // Headers font-family
  220. if ( isset( $ss_settings['header-font']['font-family'] ) && ! empty( $ss_settings['header-font']['font-family'] ) ) {
  221. $vars .= '$header-font-family: ' . $ss_settings['header-font']['font-family'] . ';';
  222. }
  223. // Headers font-color
  224. if ( isset( $ss_settings['header-font']['font-color'] ) && ! empty( $ss_settings['header-font']['font-color'] ) ) {
  225. $vars .= '$header-font-color: ' . $ss_settings['header-font']['color'] . ';';
  226. }
  227. // Primary Color
  228. if ( isset( $ss_settings['primary-color'] ) && ! empty( $ss_settings['primary-color'] ) ) {
  229. $vars .= '$primary-color: ' . $ss_settings['primary-color'] . ';';
  230. }
  231. // Secondary Color
  232. if ( isset( $ss_settings['secondary-color'] ) && ! empty( $ss_settings['secondary-color'] ) ) {
  233. $vars .= '$secondary-color: ' . $ss_settings['secondary-color'] . ';';
  234. }
  235. // Alert Color
  236. if ( isset( $ss_settings['alert-color'] ) && ! empty( $ss_settings['alert-color'] ) ) {
  237. $vars .= '$alert-color: ' . $ss_settings['alert-color'] . ';';
  238. }
  239. // Success Color
  240. if ( isset( $ss_settings['success-color'] ) && ! empty( $ss_settings['success-color'] ) ) {
  241. $vars .= '$success-color: ' . $ss_settings['success-color'] . ';';
  242. }
  243. // Warning Color
  244. if ( isset( $ss_settings['warning-color'] ) && ! empty( $ss_settings['warning-color'] ) ) {
  245. $vars .= '$warning-color: ' . $ss_settings['warning-color'] . ';';
  246. }
  247. // Info Color
  248. if ( isset( $ss_settings['info-color'] ) && ! empty( $ss_settings['info-color'] ) ) {
  249. $vars .= '$info-color: ' . $ss_settings['info-color'] . ';';
  250. }
  251. // top-bar background
  252. if ( isset( $ss_settings['navigation-bg'] ) && ! empty( $ss_settings['navigation-bg'] ) ) {
  253. $vars .= '$topbar-bg: ' . $ss_settings['navigation-bg'] . ';';
  254. $vars .= '$tabbar-bg: ' . $ss_settings['navigation-bg'] . ';';
  255. $vars .= '$off-canvas-bg: ' . $ss_settings['navigation-bg'] . ';';
  256. if ( Shoestrap_Color::get_brightness( $ss_settings['navigation-bg'] ) > 150 ) {
  257. $vars .= '$topbar-link-bg-hover: ' . Shoestrap_Color::adjust_brightness( $ss_settings['navigation-bg'], -15 ) . ';';
  258. } else {
  259. $vars .= '$topbar-link-bg-hover: ' . Shoestrap_Color::adjust_brightness( $ss_settings['navigation-bg'], 15 ) . ';';
  260. }
  261. }
  262. // top-bar height
  263. if ( isset( $ss_settings['navbar_height'] ) && ! empty( $ss_settings['navbar_height'] ) ) {
  264. $vars .= '$topbar-height: ' . $ss_settings['navbar_height'] . 'px;';
  265. $vars .= '$tabbar-height: ' . $ss_settings['navbar_height'] . 'px;';
  266. }
  267. // topbar-breakpoint
  268. if ( isset( $ss_settings['topbar_breakpoint'] ) && ! empty( $ss_settings['topbar_breakpoint'] ) ) {
  269. $vars .= '$topbar-breakpoint: ' . $ss_settings['topbar_breakpoint'] . 'px;';
  270. $vars .= '$topbar-media-query: "only screen and (min-width: ' . $ss_settings['topbar_breakpoint'] . 'px)";';
  271. }
  272. return $vars;
  273. }
  274. /**
  275. * Add styles to the compiler
  276. */
  277. function styles_filter( $scss ) {
  278. return $this->styles() . $scss;
  279. }
  280. /*
  281. * This function can be used to compile a less file to css using the lessphp compiler
  282. */
  283. function compiler() {
  284. global $ss_settings;
  285. if ( isset( $ss_settings['minimize_css'] ) && $ss_settings['minimize_css'] == 1 ) {
  286. $compress = true;
  287. } else {
  288. $compress = false;
  289. }
  290. $options = array( 'compress' => $compress );
  291. $scss_location = dirname( __FILE__ ) . '/assets/scss/';
  292. $webfont_location = get_template_directory_uri() . '/assets/fonts/';
  293. $custom_less_file = get_stylesheet_directory() . '/assets/less/custom.less';
  294. $scss = new scssc();
  295. $scss->setImportPaths( $scss_location );
  296. $css = $scss->compile( apply_filters( 'foundation_scss', '@import "app.scss";' ) );
  297. // Ugly hack to properly set the path to webfonts
  298. $css = str_replace( "url('Elusive-Icons", "url('" . $webfont_location . "Elusive-Icons", $css );
  299. return $css;
  300. }
  301. /**
  302. * The inline icon links for social networks.
  303. */
  304. function navbar_social_bar() {}
  305. /**
  306. * Build the social links for the navbar
  307. */
  308. function navbar_social_links() {}
  309. /**
  310. * Additiona CSS that is not included in the compiler
  311. */
  312. function css() {
  313. global $ss_settings;
  314. $css = '';
  315. // the container max-width
  316. if ( isset( $ss_settings['max-width'] ) && $ss_settings['max-width'] != 1000 ) {
  317. $css .= ".row, .contain-to-grid .top-bar { max-width:" . $ss_settings['max-width'] . "px }";
  318. }
  319. // the label-tags link text color.
  320. if ( isset( $ss_settings['primary-color'] ) ) {
  321. if ( Shoestrap_Color::get_brightness( $ss_settings['primary-color'] ) > 150 ) {
  322. $css .= '.label-tag a { color: #222; }';
  323. } else {
  324. $css .= '.label-tag a { color: #fff; }';
  325. }
  326. }
  327. wp_add_inline_style( 'shoestrap_css', $css );
  328. }
  329. function include_wrapper() {
  330. global $ss_layout;
  331. return $ss_layout->include_wrapper();
  332. }
  333. function float_class( $alignment = 'left' ) {
  334. if ( $alignment == 'left' || $alignment == 'l' ) {
  335. return 'left';
  336. } elseif ( $alignment == 'right' || $alignment == 'r' ) {
  337. return 'right';
  338. }
  339. }
  340. function make_tabs( $tab_titles = array(), $tab_contents = array() ) {
  341. $content = '<dl class="tabs" data-tab>';
  342. $i = 0;
  343. foreach ( $tab_titles as $tab_title ) {
  344. // Make the first tab active
  345. $active = $i = 0 ? ' class="active"' : null;
  346. $content .= '<dd' . $active . '><a href="#panel-' . $i . '">' . $tab_title . '</a></dd>';
  347. $i++;
  348. }
  349. $content .= '</dl>';
  350. $content .= '<div class="tabs-content">';
  351. $i = 0;
  352. foreach ( $tab_contents as $tab_content ) {
  353. // Make the first tab active
  354. $active = $i = 0 ? ' active' : null;
  355. $content .= '<div class="content' . $active . '" id="panel' . $i . '">' . $tab_content . '</div>';
  356. $i++;
  357. }
  358. $content .= '</div>';
  359. return $content;
  360. }
  361. }
  362. }