GFPDFRouter

The Gravity PDF GFPDF Router class.

Defined (1)

The class is defined in the following location(s).

/src/bootstrap.php  
  1. class Router implements Helper\Helper_Interface_Actions, Helper\Helper_Interface_Filters { 
  2.  
  3. /** 
  4. * Holds our log class 
  5. * @var \Monolog\Logger 
  6. * @since 4.0 
  7. */ 
  8. public $log; 
  9.  
  10. /** 
  11. * Holds the abstracted Gravity Forms API specific to Gravity PDF 
  12. * @var \GFPDF\Helper\Helper_Form 
  13. * @since 4.0 
  14. */ 
  15. public $gform; 
  16.  
  17. /** 
  18. * Holds our Helper_Notices object 
  19. * which we can use to queue up admin messages for the user 
  20. * @var \GFPDF\Helper\Helper_Notices 
  21. * @since 4.0 
  22. */ 
  23. public $notices; 
  24.  
  25. /** 
  26. * Holds our Helper_Data object 
  27. * which we can autoload with any data needed 
  28. * @var \GFPDF\Helper\Helper_Data 
  29. * @since 4.0 
  30. */ 
  31. public $data; 
  32.  
  33. /** 
  34. * Holds our Helper_Abstract_Options / Helper_Options_Fields object 
  35. * Makes it easy to access global PDF settings and individual form PDF settings 
  36. * @var \GFPDF\Helper\Helper_Options_Fields 
  37. * @since 4.0 
  38. */ 
  39. public $options; 
  40.  
  41. /** 
  42. * Holds our Helper_Misc object 
  43. * Makes it easy to access common methods throughout the plugin 
  44. * @var \GFPDF\Helper\Helper_Misc 
  45. * @since 4.0 
  46. */ 
  47. public $misc; 
  48.  
  49. /** 
  50. * Holds our Helper_Templates object 
  51. * used to ease access to our PDF templates 
  52. * @var \GFPDF\Helper\Helper_Templates 
  53. * @since 4.0 
  54. */ 
  55. public $templates; 
  56.  
  57. /** 
  58. * Makes our MVC classes sudo-singletons by allowing easy access to the original objects 
  59. * through `$singleton->get_class();` 
  60. * @var \GFPDF\Helper\Helper_Singleton 
  61. * @since 4.0 
  62. */ 
  63. public $singleton; 
  64.  
  65. /** 
  66. * Add user depreciation notice for any methods not included in current object 
  67. * @param string $name The function name to be called 
  68. * @param array $arguments An enumerated array containing the parameters passed to the $name'ed method 
  69. * @since 4.0 
  70. */ 
  71. public function __call( $name, $arguments ) { 
  72. trigger_error( sprintf( esc_html__( '"%s" has been deprecated as of Gravity PDF 4.0', 'gravity-forms-pdf-extended' ), $name ), E_USER_DEPRECATED ); 
  73.  
  74. /** 
  75. * Add user depreciation notice for any methods not included in current object 
  76. * @param string $name The function name to be called 
  77. * @param array $arguments An enumerated array containing the parameters passed to the $name'ed method 
  78. * @since 4.0 
  79. */ 
  80. public static function __callStatic( $name, $arguments ) { 
  81. trigger_error( sprintf( esc_html__( '"%s" has been deprecated as of Gravity PDF 4.0', 'gravity-forms-pdf-extended' ), $name ), E_USER_DEPRECATED ); 
  82.  
  83. /** 
  84. * Fired on the `after_setup_theme` action to initialise our plugin 
  85. * We do this on this hook instead of plugins_loaded so that users can tap into all our actions and filters 
  86. * directly from their theme (usually the functions.php file). 
  87. * @since 4.0 
  88. */ 
  89. public static function initialise_plugin() { 
  90.  
  91. global $gfpdf; 
  92.  
  93. /** Initialise our Router class */ 
  94. $gfpdf = new Router(); 
  95. $gfpdf->init(); 
  96.  
  97. /** Add backwards compatibility support */ 
  98. $deprecated = new GFPDF_Core(); 
  99. $deprecated->setup_constants(); 
  100. $deprecated->setup_deprecated_paths(); 
  101.  
  102. /** 
  103. * Setup our plugin functionality 
  104. * Note: This method runs during the `after_setup_theme` action 
  105. * @since 4.0 
  106. */ 
  107. public function init() { 
  108.  
  109. /** Set up our logger is not running via CLI (unit testing) */ 
  110. $this->setup_logger(); 
  111.  
  112. /** Set up our form object */ 
  113. $this->gform = new Helper\Helper_Form(); 
  114.  
  115. /** Set up our data access layer */ 
  116. $this->data = new Helper\Helper_Data(); 
  117. $this->data->init(); 
  118.  
  119. /** Set up our misc object */ 
  120. $this->misc = new Helper\Helper_Misc( $this->log, $this->gform, $this->data ); 
  121.  
  122. /** Set up our notices */ 
  123. $this->notices = new Helper\Helper_Notices(); 
  124. $this->notices->init(); 
  125.  
  126. /** Setup our template helper */ 
  127. $this->templates = new Helper\Helper_Templates( $this->log, $this->data ); 
  128.  
  129. /** Set up our options object - this is initialised on admin_init but other classes need to access its methods before this */ 
  130. $this->options = new Helper\Helper_Options_Fields( 
  131. $this->log,  
  132. $this->gform,  
  133. $this->data,  
  134. $this->misc,  
  135. $this->notices,  
  136. $this->templates 
  137. ); 
  138.  
  139. /** Setup our Singleton object */ 
  140. $this->singleton = new Helper\Helper_Singleton(); 
  141.  
  142. /** Load modules */ 
  143. $this->installer(); 
  144. $this->welcome_screen(); 
  145. $this->gf_settings(); 
  146. $this->gf_form_settings(); 
  147. $this->pdf(); 
  148. $this->shortcodes(); 
  149. $this->mergetags(); 
  150. $this->actions(); 
  151. $this->template_manager(); 
  152.  
  153. /** Add localisation support */ 
  154. $this->add_localization_support(); 
  155.  
  156. /** 
  157. * Run generic actions and filters needed to get the plugin functional 
  158. * The controllers will set more specific actions / filters as needed 
  159. */ 
  160. $this->add_actions(); 
  161. $this->add_filters(); 
  162.  
  163. /** 
  164. * Trigger action to signify Gravity PDF is now loaded 
  165. * See https://gravitypdf.com/documentation/v4/gfpdf_fully_loaded/ for more details about this action 
  166. */ 
  167. do_action( 'gfpdf_fully_loaded', $this ); 
  168.  
  169.  
  170. /** 
  171. * Add required plugin actions 
  172. * @since 4.0 
  173. * @return void 
  174. */ 
  175. public function add_actions() { 
  176.  
  177. add_action( 'init', [ $this, 'register_assets' ] ); 
  178. add_action( 'admin_enqueue_scripts', [ $this, 'load_admin_assets' ] ); 
  179.  
  180. /** Cache our Gravity PDF Settings and register our settings fields with the Options API */ 
  181. add_action( 'init', [ $this, 'init_settings_api' ], 1 ); 
  182. add_action( 'admin_init', [ $this, 'setup_settings_fields' ], 1 ); 
  183.  
  184. /** 
  185. * Add required plugin filters 
  186. * @since 4.0 
  187. * @return void 
  188. */ 
  189. public function add_filters() { 
  190.  
  191. /** Automatically handle GF noconflict mode */ 
  192. add_filter( 'gform_noconflict_scripts', [ $this, 'auto_noconflict_scripts' ] ); 
  193. add_filter( 'gform_noconflict_styles', [ $this, 'auto_noconflict_styles' ] ); 
  194.  
  195. /** Enable Gravity Forms Logging */ 
  196. add_filter( 'gform_logging_supported', [ $this, 'add_gf_logger' ] ); 
  197.  
  198. /** Add quick links on the plugins page */ 
  199. add_filter( 'plugin_action_links_' . PDF_PLUGIN_BASENAME, [ $this, 'plugin_action_links' ] ); 
  200. add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 ); 
  201.  
  202. /** Add class when on Gravity PDF pages */ 
  203. add_filter( 'admin_body_class', [ $this, 'add_body_class' ] ); 
  204.  
  205.  
  206. /** 
  207. * Setup WordPress localization support 
  208. * @since 4.0 
  209. */ 
  210. private function add_localization_support() { 
  211. load_plugin_textdomain( 'gravity-forms-pdf-extended', false, dirname( plugin_basename( __FILE__ ) ) . '/assets/languages/' ); 
  212.  
  213. /** 
  214. * Initialise our logging class (we're using Monolog instead of Gravity Form's KLogger) 
  215. * and set up appropriate handlers based on the logger settings 
  216. * @return void 
  217. * @since 4.0 
  218. */ 
  219. public function setup_logger() { 
  220.  
  221. /** Initialise our logger */ 
  222. $this->log = new Logger( 'gravitypdf' ); 
  223.  
  224. /** Setup our Gravity Forms local file logger, if enabled */ 
  225. $this->setup_gravityforms_logging(); 
  226.  
  227. /** Check if we have a handler pushed and add our Introspection and Memory Peak usage processors */ 
  228. if ( sizeof( $this->log->getHandlers() ) > 0 && substr( php_sapi_name(), 0, 3 ) !== 'cli' ) { 
  229. $this->log->pushProcessor( new IntrospectionProcessor ); 
  230. $this->log->pushProcessor( new MemoryPeakUsageProcessor ); 
  231. } else { 
  232. /** Disable logging if using CLI, or if Gravity Forms logging isn't enabled */ 
  233. $this->log->pushHandler( new NullHandler( Logger::INFO ) ); /** throw logs away */ 
  234.  
  235. /** 
  236. * Setup Gravity Forms logging, if currently enabled by the user 
  237. * @return void 
  238. * @since 4.0 
  239. */ 
  240. private function setup_gravityforms_logging() { 
  241.  
  242. /** Check if Gravity Forms logging is enabled and push stream logging */ 
  243. if ( class_exists( 'GFLogging' ) ) { 
  244.  
  245. /** 
  246. * Get the current plugin logger settings and check if it's enabled 
  247. * The new version of the logger uses the add-on storage method, while the old one stores it in gf_logging_settings 
  248. * so we'll test which settings we should use and get the appropriate log level 
  249. */ 
  250. if ( ! get_option( 'gform_enable_logging' ) && ( ! defined( 'GF_LOGGING_VERSION' ) || version_compare( GF_LOGGING_VERSION, '1.1', '<' ) ) ) { 
  251. $settings = get_option( 'gf_logging_settings' ); 
  252. $log_level = (int) rgar( $settings, 'gravity-pdf' ); 
  253. $log_filename = GFFormsModel::get_upload_root() . 'logs/gravity-pdf.txt'; 
  254. } else { 
  255. $gf_logger = GFLogging::get_instance(); 
  256. $gf_logger_settings = $gf_logger->get_plugin_settings(); 
  257. $log_level = ( isset( $gf_logger_settings['gravity-pdf']['log_level'] ) ) ? (int) $gf_logger_settings['gravity-pdf']['log_level'] : 0; 
  258. $log_filename = ( get_option( 'gform_enable_logging' ) ) ? $gf_logger->get_log_file_name( 'gravity-pdf' ) : $gf_logger::get_log_file_name( 'gravity-pdf' ); 
  259.  
  260. /** Enable logging if not equivalent to empty (0) and not level 6 (which is apprently off in GF world) */ 
  261. if ( ! empty( $log_level ) && $log_level !== 6 ) { 
  262.  
  263. /** Convert Gravity Forms log levels to the appropriate Monolog level */ 
  264. $monolog_level = ( $log_level === 4 ) ? Logger::ERROR : Logger::INFO; 
  265.  
  266. /** Setup our stream and change the format to more-suit Gravity Forms */ 
  267. $formatter = new LineFormatter( "%datetime% - %level_name% --> %message% %context% %extra%<br>\n" ); 
  268. $stream = new StreamHandler( $log_filename, $monolog_level ); 
  269. $stream->setFormatter( $formatter ); 
  270.  
  271. /** Add our log file stream */ 
  272. $this->log->pushHandler( $stream ); 
  273.  
  274. /** 
  275. * Show action links on the plugin screen. 
  276. * @param mixed $links Plugin Action links 
  277. * @return array 
  278. * @since 4.0 
  279. */ 
  280. public function plugin_action_links( $links ) { 
  281.  
  282. $action_links = [ 
  283. 'settings' => '<a href="' . esc_url( $this->data->settings_url ) . '" title="' . esc_attr__( 'View Gravity PDF Settings', 'gravity-forms-pdf-extended' ) . '">' . esc_html__( 'Settings', 'gravity-forms-pdf-extended' ) . '</a>',  
  284. ]; 
  285.  
  286. return array_merge( $action_links, $links ); 
  287.  
  288. /** 
  289. * Show row meta on the plugin screen. 
  290. * @param mixed $links Plugin Row Meta 
  291. * @param mixed $file Plugin Base file 
  292. * @return array 
  293. * @since 4.0 
  294. */ 
  295. public function plugin_row_meta( $links, $file ) { 
  296.  
  297. if ( $file == PDF_PLUGIN_BASENAME ) { 
  298. $row_meta = [ 
  299. 'docs' => '<a href="' . esc_url( 'https://gravitypdf.com/documentation/v4/five-minute-install/' ) . '" title="' . esc_attr__( 'View Gravity PDF Documentation', 'gravity-forms-pdf-extended' ) . '">' . esc_html__( 'Docs', 'gravity-forms-pdf-extended' ) . '</a>',  
  300. 'support' => '<a href="' . esc_url( $this->data->settings_url . '&tab=help' ) . '" title="' . esc_attr__( 'Get Help and Support', 'gravity-forms-pdf-extended' ) . '">' . esc_html__( 'Support', 'gravity-forms-pdf-extended' ) . '</a>',  
  301. 'shop' => '<a href="' . esc_url( 'https://gravitypdf.com/shop/' ) . '" title="' . esc_attr__( 'View Gravity PDF Theme Shop', 'gravity-forms-pdf-extended' ) . '">' . esc_html__( 'Theme Shop', 'gravity-forms-pdf-extended' ) . '</a>',  
  302. ]; 
  303.  
  304. return array_merge( $links, $row_meta ); 
  305.  
  306. return (array) $links; 
  307.  
  308. /** 
  309. * If on a Gravity Form page add a new class 
  310. * @param array $classes 
  311. * @since 4.0 
  312. * @return string 
  313. */ 
  314. public function add_body_class( $classes ) { 
  315.  
  316. if ( $this->misc->is_gfpdf_page() ) { 
  317. $classes .= ' gfpdf-page'; 
  318.  
  319. return $classes; 
  320.  
  321. /** 
  322. * Register all css and js which can be enqueued when needed 
  323. * @since 4.0 
  324. * @return void 
  325. */ 
  326. public function register_assets() { 
  327. $this->register_styles(); 
  328. $this->register_scripts(); 
  329.  
  330. /** 
  331. * Register requrired CSS 
  332. * @since 4.0 
  333. * @return void 
  334. */ 
  335. private function register_styles() { 
  336. $version = PDF_EXTENDED_VERSION; 
  337.  
  338. wp_register_style( 'gfpdf_css_styles', PDF_PLUGIN_URL . 'dist/assets/css/gfpdf-styles.min.css', [ 'wp-color-picker', 'wp-jquery-ui-dialog' ], $version ); 
  339. wp_register_style( 'gfpdf_css_admin_styles', PDF_PLUGIN_URL . 'dist/assets/css/gfpdf-admin-styles.min.css', [], $version ); 
  340.  
  341. /** 
  342. * Register requrired JS 
  343. * @since 4.0 
  344. * @return void 
  345. */ 
  346. private function register_scripts() { 
  347. $version = PDF_EXTENDED_VERSION; 
  348.  
  349. $pdf_settings_dependancies = [ 
  350. 'wpdialogs',  
  351. 'jquery-ui-tooltip',  
  352. 'gform_forms',  
  353. 'gform_form_admin',  
  354. 'gform_chosen',  
  355. 'jquery-color',  
  356. 'wp-color-picker',  
  357. ]; 
  358.  
  359. wp_register_script( 'gfpdf_js_settings', PDF_PLUGIN_URL . 'dist/assets/js/gfpdf-settings.min.js', $pdf_settings_dependancies, $version ); 
  360.  
  361. $pdf_backbone_dependancies = [ 
  362. 'gfpdf_js_settings',  
  363. 'backbone',  
  364. 'underscore',  
  365. 'gfpdf_js_backbone_model_binder',  
  366. 'wpdialogs',  
  367. ]; 
  368.  
  369. wp_register_script( 'gfpdf_js_backbone', PDF_PLUGIN_URL . 'dist/assets/js/gfpdf-backbone.min.js', $pdf_backbone_dependancies, $version ); /** @TODO - remove backbone and use React */ 
  370. wp_register_script( 'gfpdf_js_backbone_model_binder', PDF_PLUGIN_URL . 'bower_components/backbone.modelbinder/Backbone.ModelBinder.min.js', [ 'backbone', 'underscore' ], $version ); 
  371.  
  372. wp_register_script( 'gfpdf_js_vendors', PDF_PLUGIN_URL . 'dist/assets/js/vendor.bundle.min.js', [ 'jquery' ], $version ); 
  373. wp_register_script( 'gfpdf_js_entrypoint', PDF_PLUGIN_URL . 'dist/assets/js/app.bundle.min.js', [ 'jquery', 'gfpdf_js_vendors' ], $version ); 
  374. wp_register_script( 'gfpdf_js_entries', PDF_PLUGIN_URL . 'dist/assets/js/gfpdf-entries.min.js', [ 'jquery' ], $version ); 
  375. wp_register_script( 'gfpdf_js_v3_migration', PDF_PLUGIN_URL . 'dist/assets/js/gfpdf-migration.min.js', [ 'gfpdf_js_settings' ], $version ); 
  376.  
  377. /** Localise admin script */ 
  378. wp_localize_script( 'gfpdf_js_entrypoint', 'GFPDF', $this->data->get_localised_script_data( $this->options, $this->gform ) ); 
  379. wp_localize_script( 'gfpdf_js_settings', 'GFPDF', $this->data->get_localised_script_data( $this->options, $this->gform ) ); 
  380.  
  381.  
  382. /** 
  383. * Load any assets that are needed 
  384. * @since 4.0.4 
  385. * @return void 
  386. */ 
  387. public function load_admin_assets() { 
  388.  
  389. if ( $this->misc->is_gfpdf_page() ) { 
  390. /** load styles */ 
  391. wp_enqueue_style( 'gfpdf_css_styles' ); 
  392. wp_enqueue_style( 'gform_chosen', \GFCommon::get_base_url() . '/css/chosen.min.css', [], \GFCommon::$version ); 
  393.  
  394. /** load scripts */ 
  395. wp_enqueue_script( 'gfpdf_js_settings' ); 
  396.  
  397. /** add media uploader */ 
  398. wp_enqueue_media(); 
  399.  
  400. wp_enqueue_script( 'gfpdf_js_entrypoint' ); 
  401.  
  402. if ( $this->misc->is_gfpdf_settings_tab( 'help' ) || $this->misc->is_gfpdf_settings_tab( 'tools' ) ) { 
  403. wp_enqueue_script( 'gfpdf_js_backbone' ); 
  404.  
  405. if ( is_admin() && rgget( 'page' ) == 'gf_entries' ) { 
  406. wp_enqueue_script( 'gfpdf_js_entries' ); 
  407. wp_enqueue_style( 'gfpdf_css_styles' ); 
  408.  
  409. if ( is_admin() ) { 
  410. wp_enqueue_style( 'gfpdf_css_admin_styles' ); 
  411.  
  412. /** 
  413. * Auto no-conflict any preloaded scripts that begin with 'gfpdf_' 
  414. * @since 4.0 
  415. * @param array $items The current list of no-conflict scripts 
  416. * @return array 
  417. */ 
  418. public function auto_noconflict_scripts( $items ) { 
  419.  
  420. $wp_scripts = wp_scripts(); 
  421.  
  422. /** 
  423. * Set defaults we will allow to load on GF pages which are needed for Gravity PDF 
  424. * If any Gravity PDF modules requires WordPress-specific JS files you should add them to this list 
  425. */ 
  426. $default_scripts = [ 
  427. 'editor',  
  428. 'word-count',  
  429. 'quicktags',  
  430. 'wpdialogs-popup',  
  431. 'media-upload',  
  432. 'wplink',  
  433. 'backbone',  
  434. 'underscore',  
  435. 'media-editor',  
  436. 'media-models',  
  437. 'media-views',  
  438. 'plupload',  
  439. 'plupload-flash',  
  440. 'plupload-html4',  
  441. 'plupload-html5',  
  442. 'plupload-silverlight',  
  443. 'wp-plupload',  
  444. 'gform_placeholder',  
  445. 'jquery-ui-autocomplete',  
  446. 'thickbox',  
  447. ]; 
  448.  
  449. foreach ( $wp_scripts->queue as $object ) { 
  450. if ( substr( $object, 0, 8 ) === 'gfpdf_js' ) { 
  451. $items[] = $object; 
  452.  
  453. if ( $this->misc->is_gfpdf_page() ) { 
  454. $items = array_merge( $default_scripts, $items ); 
  455.  
  456. /** See https://gravitypdf.com/documentation/v4/gfpdf_gf_noconflict_scripts/ for more details about this filter */ 
  457.  
  458. return apply_filters( 'gfpdf_gf_noconflict_scripts', $items ); 
  459.  
  460. /** 
  461. * Auto no-conflict any preloaded styles that begin with 'gfpdf_' 
  462. * @since 4.0 
  463. * @param array $items The current list of no-conflict styles 
  464. * @return array 
  465. */ 
  466. public function auto_noconflict_styles( $items ) { 
  467.  
  468. $wp_styles = wp_styles(); 
  469.  
  470. /** 
  471. * Set defaults we will allow to load on GF pages which are needed for Gravity PDF 
  472. * If any Gravity PDF modules requires WordPress-specific CSS files you should add them to this list 
  473. */ 
  474. $default_styles = [ 
  475. 'editor-buttons',  
  476. 'wp-jquery-ui-dialog',  
  477. 'media-views',  
  478. 'buttons',  
  479. 'thickbox',  
  480. 'gform_chosen',  
  481. ]; 
  482.  
  483. foreach ( $wp_styles->queue as $object ) { 
  484. if ( substr( $object, 0, 9 ) === 'gfpdf_css' ) { 
  485. $items[] = $object; 
  486.  
  487. if ( $this->misc->is_gfpdf_page() ) { 
  488. $items = array_merge( $default_styles, $items ); 
  489.  
  490. /** See https://gravitypdf.com/documentation/v4/gfpdf_gf_noconflict_styles/ for more details about this filter */ 
  491.  
  492. return apply_filters( 'gfpdf_gf_noconflict_styles', $items ); 
  493.  
  494. /** 
  495. * Register our plugin with Gravity Form's Logger 
  496. * @param array $loggers 
  497. * @return array 
  498. * @since 4.0 
  499. */ 
  500. public function add_gf_logger( $loggers ) { 
  501. $loggers['gravity-pdf'] = esc_html__( 'Gravity PDF', 'gravity-forms-pdf-extended' ); 
  502.  
  503. return $loggers; 
  504.  
  505. /** 
  506. * Bootstrap our settings API for use 
  507. * @return void 
  508. * @return 4.0 
  509. */ 
  510. public function init_settings_api() { 
  511. /** load our options API */ 
  512. $this->options->init(); 
  513.  
  514. /** 
  515. * Register our admin settings 
  516. * @return void 
  517. * @return 4.0 
  518. */ 
  519. public function setup_settings_fields() { 
  520. /** register our options settings */ 
  521. $this->options->register_settings( $this->options->get_registered_fields() ); 
  522.  
  523. /** 
  524. * Loads our Gravity PDF installer classes 
  525. * @since 4.0 
  526. * @return void 
  527. */ 
  528. public function installer() { 
  529. $model = new Model\Model_Install( $this->gform, $this->log, $this->data, $this->misc, $this->notices ); 
  530. $class = new Controller\Controller_Install( $model, $this->gform, $this->log, $this->notices, $this->data, $this->misc ); 
  531. $class->init(); 
  532.  
  533. /** set up required data */ 
  534. $class->setup_defaults(); 
  535.  
  536. /** Add to our singleton controller */ 
  537. $this->singleton->add_class( $class ); 
  538. $this->singleton->add_class( $model ); 
  539.  
  540. /** 
  541. * Include Welcome Screen functionality for installation / upgrades 
  542. * @since 4.0 
  543. * @return void 
  544. */ 
  545. public function welcome_screen() { 
  546.  
  547. $model = new Model\Model_Welcome_Screen( $this->log ); 
  548. $view = new View\View_Welcome_Screen( [ 
  549. 'display_version' => PDF_EXTENDED_VERSION,  
  550. ], $this->gform ); 
  551.  
  552. $class = new Controller\Controller_Welcome_Screen( $model, $view, $this->log, $this->data, $this->options ); 
  553. $class->init(); 
  554.  
  555. /** Add to our singleton controller */ 
  556. $this->singleton->add_class( $class ); 
  557. $this->singleton->add_class( $model ); 
  558. $this->singleton->add_class( $view ); 
  559.  
  560. /** 
  561. * Include Settings Page functionality 
  562. * @since 4.0 
  563. * @return void 
  564. */ 
  565. public function gf_settings() { 
  566.  
  567. $model = new Model\Model_Settings( 
  568. $this->gform,  
  569. $this->log,  
  570. $this->notices,  
  571. $this->options,  
  572. $this->data,  
  573. $this->misc,  
  574. $this->templates 
  575. ); 
  576.  
  577. $view = new View\View_Settings( 
  578. [],  
  579. $this->gform,  
  580. $this->log,  
  581. $this->options,  
  582. $this->data,  
  583. $this->misc,  
  584. $this->templates 
  585. ); 
  586.  
  587. $class = new Controller\Controller_Settings( $model, $view, $this->gform, $this->log, $this->notices, $this->data, $this->misc ); 
  588. $class->init(); 
  589.  
  590. /** Add to our singleton controller */ 
  591. $this->singleton->add_class( $class ); 
  592. $this->singleton->add_class( $model ); 
  593. $this->singleton->add_class( $view ); 
  594.  
  595. /** 
  596. * Include Form Settings (PDF) functionality 
  597. * @since 4.0 
  598. * @return void 
  599. */ 
  600. public function gf_form_settings() { 
  601.  
  602. $model = new Model\Model_Form_Settings( 
  603. $this->gform,  
  604. $this->log,  
  605. $this->data,  
  606. $this->options,  
  607. $this->misc,  
  608. $this->notices,  
  609. $this->templates 
  610. ); 
  611.  
  612. $view = new View\View_Form_Settings( [] ); 
  613.  
  614. $class = new Controller\Controller_Form_Settings( 
  615. $model,  
  616. $view,  
  617. $this->data,  
  618. $this->options,  
  619. $this->misc 
  620. ); 
  621.  
  622. $class->init(); 
  623.  
  624. /** Add to our singleton controller */ 
  625. $this->singleton->add_class( $class ); 
  626. $this->singleton->add_class( $model ); 
  627. $this->singleton->add_class( $view ); 
  628.  
  629. /** 
  630. * Include PDF Display functionality 
  631. * @since 4.0 
  632. * @return void 
  633. */ 
  634. public function pdf() { 
  635.  
  636. $model = new Model\Model_PDF( 
  637. $this->gform,  
  638. $this->log,  
  639. $this->options,  
  640. $this->data,  
  641. $this->misc,  
  642. $this->notices,  
  643. $this->templates 
  644. ); 
  645.  
  646. $view = new View\View_PDF( 
  647. [],  
  648. $this->gform,  
  649. $this->log,  
  650. $this->options,  
  651. $this->data,  
  652. $this->misc,  
  653. $this->templates 
  654. ); 
  655.  
  656. $class = new Controller\Controller_PDF( $model, $view, $this->gform, $this->log, $this->misc ); 
  657. $class->init(); 
  658.  
  659. /** Add to our singleton controller */ 
  660. $this->singleton->add_class( $class ); 
  661. $this->singleton->add_class( $model ); 
  662. $this->singleton->add_class( $view ); 
  663.  
  664. /** 
  665. * Include PDF Shortcodes functionality 
  666. * @since 4.0 
  667. * @return void 
  668. */ 
  669. public function shortcodes() { 
  670.  
  671. $model = new Model\Model_Shortcodes( $this->gform, $this->log, $this->options, $this->misc ); 
  672. $view = new View\View_Shortcodes( [] ); 
  673.  
  674. $class = new Controller\Controller_Shortcodes( $model, $view, $this->log ); 
  675. $class->init(); 
  676.  
  677. /** Add to our singleton controller */ 
  678. $this->singleton->add_class( $class ); 
  679. $this->singleton->add_class( $model ); 
  680. $this->singleton->add_class( $view ); 
  681.  
  682. /** 
  683. * Include PDF Mergetag functionality 
  684. * @since 4.1 
  685. * @return void 
  686. */ 
  687. public function mergetags() { 
  688.  
  689. $model = new Model\Model_Mergetags( $this->options, $this->singleton->get_class( 'Model_PDF' ), $this->log, $this->misc ); 
  690.  
  691. $class = new Controller\Controller_Mergetags( $model ); 
  692. $class->init(); 
  693.  
  694. /** Add to our singleton controller */ 
  695. $this->singleton->add_class( $class ); 
  696. $this->singleton->add_class( $model ); 
  697.  
  698. /** 
  699. * Include one-time actions functionality 
  700. * @since 4.0 
  701. * @return void 
  702. */ 
  703. public function actions() { 
  704.  
  705. $model = new Model\Model_Actions( $this->data, $this->options, $this->notices ); 
  706. $view = new View\View_Actions( [] ); 
  707.  
  708. $class = new Controller\Controller_Actions( $model, $view, $this->gform, $this->log, $this->notices ); 
  709. $class->init(); 
  710.  
  711. /** Add to our singleton controller */ 
  712. $this->singleton->add_class( $class ); 
  713. $this->singleton->add_class( $model ); 
  714. $this->singleton->add_class( $view ); 
  715.  
  716. /** 
  717. * Include template manager functionality 
  718. * @since 4.0 
  719. * @return void 
  720. */ 
  721. public function template_manager() { 
  722.  
  723. $model = new Model\Model_Templates( $this->templates, $this->log, $this->data, $this->misc ); 
  724.  
  725. $class = new Controller\Controller_Templates( $model ); 
  726. $class->init(); 
  727.  
  728. /** Add to our singleton controller */ 
  729. $this->singleton->add_class( $class ); 
  730. $this->singleton->add_class( $model ); 
  731.  
  732. /** 
  733. * Backwards compatibility with our early v3 templates 
  734. * @param $form_id 
  735. * @return array 
  736. * @since 4.0 
  737. */ 
  738. public function get_config_data( $form_id ) { 
  739. return $this->get_default_config_data( $form_id ); 
  740.  
  741. /** 
  742. * Add backwards compatbility with v3.x.x default PDF template files 
  743. * This function will now pull the PDF configuration details from our query variables / or our backwards compatible URL params method 
  744. * @param integer $form_id The Gravity Form ID 
  745. * @return array The matched configuration being requested 
  746. * @since 4.0 
  747. */ 
  748. public function get_default_config_data( $form_id ) { 
  749.  
  750. $pid = $GLOBALS['wp']->query_vars['pid']; 
  751.  
  752. $settings = $this->options->get_pdf( $form_id, $pid ); 
  753.  
  754. if ( is_wp_error( $settings ) ) { 
  755.  
  756. $this->log->addError( 'Invalid PDF Settings.', [ 
  757. 'form_id' => $form_id,  
  758. 'pid' => $pid,  
  759. 'WP_Error_Message' => $settings->get_error_message(),  
  760. 'WP_Error_Code' => $settings->get_error_code(),  
  761. ] ); 
  762.  
  763. /** Reset the settings so it forces everything to false */ 
  764. $settings = []; 
  765.  
  766. return [ 
  767. 'empty_field' => ( isset( $settings['show_empty'] ) && $settings['show_empty'] == 'Yes' ) ? true : false,  
  768. 'html_field' => ( isset( $settings['show_html'] ) && $settings['show_html'] == 'Yes' ) ? true : false,  
  769. 'page_names' => ( isset( $settings['show_page_names'] ) && $settings['show_page_names'] == 'Yes' ) ? true : false,  
  770. 'section_content' => ( isset( $settings['show_section_content'] ) && $settings['show_section_content'] == 'Yes' ) ? true : false,  
  771. ];