PageRenderTime 24ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/wp-content/themes/variant-landing-page-four/mods/variantlp-functions.php

https://gitlab.com/vanafroo/voipWEB
PHP | 341 lines | 249 code | 25 blank | 67 comment | 19 complexity | c54c112c1c9a88db0efa299ac995c278 MD5 | raw file
  1. <?php
  2. define('VARIANTLP_DIR', get_template_directory() . '/mods/');
  3. define('VARIANTLP_DIR_URI', trailingslashit(get_template_directory_uri()) . 'mods/');
  4. require VARIANTLP_DIR . 'class-tgm-plugin-activation.php';
  5. /**
  6. * Register TGM
  7. */
  8. add_action('tgmpa_register', 'variantlp_register_required_plugins');
  9. /**
  10. * Load customizer class
  11. */
  12. require_once VARIANTLP_DIR . '/inc/customizer/variant-customizer.php';
  13. require_once VARIANTLP_DIR . '/inc/customizer/variant-custom-controls.php';
  14. /**
  15. * Generates contact form
  16. * @return string
  17. */
  18. function variantlp_lead_form($form_link, $height = '540', $echo = false, $position = '') {
  19. $iframe = '';
  20. if ($position) {
  21. $position = '&l=' . $position;
  22. }
  23. $form_custom_style = VARIANTLP_DIR_URI . 'assets/css/form-style/form.css';
  24. $find = 'form/share';
  25. $replace = 'e/form';
  26. $form_link = str_replace($find, $replace, $form_link);
  27. $src = esc_url($form_link . '/i?fgcss=' . $form_custom_style . $position);
  28. $atts = "height='" . $height . "' allowTransparency='true' frameborder='0' scrolling='yes' style='width:100%;border:none'";
  29. $iframe = "<iframe " . $atts . " src='" . $src . "'>" . __('Your Contact', 'variant-landing-page-four') . "</iframe>";
  30. if ($echo) {
  31. echo $iframe;
  32. }
  33. return $iframe;
  34. }
  35. /**
  36. * Get form id from given url
  37. * @param type $url
  38. * @return type
  39. */
  40. function variantlp_get_formID($url) {
  41. if ($url) {
  42. $s = explode("/", $url);
  43. return end($s);
  44. }
  45. }
  46. /**
  47. * Get theme option value
  48. * @param type $option_id
  49. * @param type $default
  50. * @return type mixed
  51. */
  52. function variantlp_four_get_option($option_id, $default = '') {
  53. if (function_exists('get_theme_mod')) {
  54. $option_val = get_theme_mod($option_id);
  55. if ($option_val != '') {
  56. return get_theme_mod($option_id);
  57. }
  58. }
  59. return $default;
  60. }
  61. /**
  62. * Load landing page template
  63. */
  64. function variantlp_load_template() {
  65. // include_once VARIANTLP_DIR . 'template/landing-page.php';
  66. locate_template('mods/template/landing-page.php', true);
  67. }
  68. /**
  69. * Landing page template selector
  70. * @return type string
  71. */
  72. function variantlp_template_selector() {
  73. $templates_arr = array('template1');
  74. $template = esc_attr(variantlp_four_get_option('template_designs', 'template1'));
  75. if (in_array($template, $templates_arr)) {
  76. return $template;
  77. }
  78. }
  79. /**
  80. * Manage template with admin bar
  81. */
  82. function variantlp_header() {
  83. if (current_user_can('manage_options')) {
  84. ?>
  85. <style>
  86. .template_one{
  87. position:relative;
  88. }
  89. .template_one .top_feature_container{
  90. margin-top: -26px;
  91. }
  92. .top_feature_container .header {
  93. margin-top: 44px !important;
  94. }
  95. </style>
  96. <?php
  97. }
  98. }
  99. add_action('wp_enqueue_scripts', 'variantlp_header');
  100. function variantlp_template_bg() {
  101. $bg_id = 'vlp_top_bg_img';
  102. $default_bg = 'template_one_top_bg';
  103. $min_height = '825px';
  104. ?>
  105. <style id="top_background" type="text/css">
  106. .top_feature_container {
  107. background: url("<?php echo esc_url(variantlp_four_get_option($bg_id, VARIANTLP_DIR_URI . 'assets/imgs/' . $default_bg . '.png')); ?>") center top repeat-x;
  108. width: 100%;
  109. min-height: <?php echo esc_html($min_height); ?>;
  110. color: #fff;
  111. }
  112. </style>
  113. <?php
  114. }
  115. add_action('wp_enqueue_scripts', 'variantlp_template_bg');
  116. /**
  117. * Register the required plugins for this theme.
  118. *
  119. * In this example, we register five plugins:
  120. * - one included with the TGMPA library
  121. * - two from an external source, one from an arbitrary source, one from a GitHub repository
  122. * - two from the .org repo, where one demonstrates the use of the `is_callable` argument
  123. *
  124. * The variable passed to tgmpa_register_plugins() should be an array of plugin
  125. * arrays.
  126. *
  127. * This function is hooked into tgmpa_init, which is fired within the
  128. * TGM_Plugin_Activation class constructor.
  129. */
  130. function variantlp_register_required_plugins() {
  131. /*
  132. * Array of plugin arrays. Required keys are name and slug.
  133. * If the source is NOT from the .org repo, then source is also required.
  134. */
  135. $plugins = array(
  136. // Option tree plugin from the WordPress Plugin Repository.
  137. array(
  138. 'name' => __('FormGet Contact Form', 'variant-landing-page-four'),
  139. 'slug' => 'formget-contact-form',
  140. 'required' => false,
  141. 'force_activation' => false,
  142. 'force_deactivation' => true,
  143. ),
  144. );
  145. /*
  146. * Array of configuration settings. Amend each line as needed.
  147. *
  148. * TGMPA will start providing localized text strings soon. If you already have translations of our standard
  149. * strings available, please help us make TGMPA even better by giving us access to these translations or by
  150. * sending in a pull-request with .po file(s) with the translations.
  151. *
  152. * Only uncomment the strings in the config array if you want to customize the strings.
  153. */
  154. $config = array(
  155. 'id' => 'tgmpa', // Unique ID for hashing notices for multiple instances of TGMPA.
  156. 'default_path' => '', // Default absolute path to bundled plugins.
  157. 'menu' => 'tgmpa-install-plugins', // Menu slug.
  158. 'parent_slug' => 'themes.php', // Parent menu slug.
  159. 'capability' => 'edit_theme_options', // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
  160. 'has_notices' => true, // Show admin notices or not.
  161. 'dismissable' => true, // If false, a user cannot dismiss the nag message.
  162. 'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
  163. 'is_automatic' => false, // Automatically activate plugins after installation or not.
  164. 'message' => '', // Message to output right before the plugins table.
  165. 'strings' => array(
  166. 'page_title' => __('Install Recommended Plugins', 'variant-landing-page-four'),
  167. 'menu_title' => __('Install Plugins', 'variant-landing-page-four'),
  168. 'installing' => __('Installing Plugin: %s', 'variant-landing-page-four'), // %s = plugin name.
  169. 'oops' => __('Something went wrong with the plugin API.', 'variant-landing-page-four'),
  170. 'notice_can_install_required' => _n_noop(
  171. 'This theme recommends the following plugin to add lead form on landing page: %1$s.', 'This theme requires the following plugins: %1$s.', 'variant-landing-page-four'
  172. ), // %1$s = plugin name(s).
  173. 'notice_can_install_recommended' => _n_noop(
  174. 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'variant-landing-page-four'
  175. ), // %1$s = plugin name(s).
  176. 'notice_cannot_install' => _n_noop(
  177. 'Sorry, but you do not have the correct permissions to install the %1$s plugin.', 'Sorry, but you do not have the correct permissions to install the %1$s plugins.', 'variant-landing-page-four'
  178. ), // %1$s = plugin name(s).
  179. 'notice_ask_to_update' => _n_noop(
  180. 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'variant-landing-page-four'
  181. ), // %1$s = plugin name(s).
  182. 'notice_ask_to_update_maybe' => _n_noop(
  183. 'There is an update available for: %1$s.', 'There are updates available for the following plugins: %1$s.', 'variant-landing-page-four'
  184. ), // %1$s = plugin name(s).
  185. 'notice_cannot_update' => _n_noop(
  186. 'Sorry, but you do not have the correct permissions to update the %1$s plugin.', 'Sorry, but you do not have the correct permissions to update the %1$s plugins.', 'variant-landing-page-four'
  187. ), // %1$s = plugin name(s).
  188. 'notice_can_activate_required' => _n_noop(
  189. 'This theme recommends the following plugin to add lead form on landing page is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'variant-landing-page-four'
  190. ), // %1$s = plugin name(s).
  191. 'notice_can_activate_recommended' => _n_noop(
  192. 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'variant-landing-page-four'
  193. ), // %1$s = plugin name(s).
  194. 'notice_cannot_activate' => _n_noop(
  195. 'Sorry, but you do not have the correct permissions to activate the %1$s plugin.', 'Sorry, but you do not have the correct permissions to activate the %1$s plugins.', 'variant-landing-page-four'
  196. ), // %1$s = plugin name(s).
  197. 'install_link' => _n_noop(
  198. 'Begin installing plugin', 'Begin installing plugins', 'variant-landing-page-four'
  199. ),
  200. 'update_link' => _n_noop(
  201. 'Begin updating plugin', 'Begin updating plugins', 'variant-landing-page-four'
  202. ),
  203. 'activate_link' => _n_noop(
  204. 'Begin activating plugin', 'Begin activating plugins', 'variant-landing-page-four'
  205. ),
  206. 'return' => __('Return to Required Plugins Installer', 'variant-landing-page-four'),
  207. 'plugin_activated' => __('Plugin activated successfully.', 'variant-landing-page-four'),
  208. 'activated_successfully' => __('The following plugin was activated successfully:', 'variant-landing-page-four'),
  209. 'plugin_already_active' => __('No action taken. Plugin %1$s was already active.', 'variant-landing-page-four'), // %1$s = plugin name(s).
  210. 'plugin_needs_higher_version' => __('Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'variant-landing-page-four'), // %1$s = plugin name(s).
  211. 'complete' => __('All plugins installed and activated successfully. %1$s', 'variant-landing-page-four'), // %s = dashboard link.
  212. 'contact_admin' => __('Please contact the administrator of this site for help.', 'variant-landing-page-four'),
  213. 'nag_type' => 'updated', // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.
  214. ),
  215. );
  216. tgmpa($plugins, $config);
  217. }
  218. function variantlp_formgetform_ajaxcallback() {
  219. ob_clean();
  220. $form_id = trim($_POST['formid']);
  221. if ($form_id) {
  222. ?>
  223. <div class="form_wrapper_custom">
  224. <?php
  225. //$height = variantlp_four_get_option('vlp_form_height', '482');
  226. echo variantlp_lead_form($form_id);
  227. ?>
  228. </div>
  229. <?php
  230. } else {
  231. echo '<a class="fg-placeholder" href="http://www.formget.com/app/" target="new"><img src="' . VARIANTLP_DIR_URI . 'assets/imgs/fg-placeholder.png" alt="' . __('Formget Placeholder', 'variant-landing-page-four') . '" /></a>';
  232. }
  233. die();
  234. }
  235. function variantlp_return_image_link() {
  236. if (isset($_POST['newval'])) {
  237. if (strpos($_POST['newval'], 'logo.png')) {
  238. $image['alt'] = get_bloginfo('name');
  239. $image['src'] = $_POST['newval'];
  240. echo json_encode($image);
  241. exit();
  242. } elseif (strpos($_POST['newval'], 'imgs/img_thumb')) {
  243. $image['alt'] = __('Feature Image', 'variant-landing-page-four');
  244. $image['src'] = $_POST['newval'];
  245. echo json_encode($image);
  246. exit();
  247. }
  248. $image_link = wp_get_attachment_image_src(absint($_POST['newval']), 'featured-image');
  249. $image_alt = get_post_meta(absint($_POST['newval']), '_wp_attachment_image_alt', true);
  250. $image = array(
  251. 'alt' => '',
  252. 'src' => ''
  253. );
  254. if (isset($image_link[0])) {
  255. $image['alt'] = $image_alt;
  256. $image['src'] = $image_link[0];
  257. echo json_encode($image);
  258. exit();
  259. } else {
  260. $image['alt'] = '';
  261. $image['src'] = '';
  262. echo json_encode($image);
  263. exit();
  264. }
  265. }
  266. die();
  267. }
  268. function variantlp_get_image_link($image_id = '') {
  269. if (isset($image_id) && $image_id != '') {
  270. $image_link = wp_get_attachment_image_src(absint($image_id), 'featured-image');
  271. $image_alt = get_post_meta(absint($image_id), '_wp_attachment_image_alt', true);
  272. $image = array(
  273. 'alt' => '',
  274. 'src' => ''
  275. );
  276. if (isset($image_link[0])) {
  277. $image['alt'] = $image_alt;
  278. $image['src'] = $image_link[0];
  279. return $image;
  280. } else {
  281. $image['alt'] = '';
  282. $image['src'] = '';
  283. return $image;
  284. }
  285. }
  286. }
  287. function variantlp_formgetform_ajax() {
  288. add_action('wp_ajax_variantlp_form_ajax', 'variantlp_formgetform_ajaxcallback');
  289. add_action('wp_ajax_nopriv_variantlp_form_ajax', 'variantlp_formgetform_ajaxcallback');
  290. add_action('wp_ajax_nopriv_variantlp_image_link_callback', 'variantlp_return_image_link');
  291. add_action('wp_ajax_variantlp_image_link_callback', 'variantlp_return_image_link');
  292. }
  293. add_action('init', 'variantlp_formgetform_ajax');
  294. /**
  295. * function to sanitize the html strings
  296. * Allowed only the WordPress allowed html tags and iframe html tag
  297. * @param string $value
  298. * @return string
  299. */
  300. function variantlp_sanitize_html($value) {
  301. $array = wp_kses_allowed_html('post');
  302. $allowedtags = array(
  303. 'iframe' => array(
  304. 'width' => array(),
  305. 'height' => array(),
  306. 'frameborder' => array(),
  307. 'scrolling' => array(),
  308. 'src' => array(),
  309. 'marginwidth' => array(),
  310. 'marginheight' => array()
  311. )
  312. );
  313. $data = array_merge($allowedtags, $array);
  314. $value = wp_kses($value, $data);
  315. return $value;
  316. }