SZGoogleAdmin

The SZ - Google SZGoogleAdmin class.

Defined (1)

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

/admin/classes/SZGoogleAdmin.php  
  1. class SZGoogleAdmin 
  2. /** 
  3. * Definition of variables containing the configuration 
  4. * to be applied to the various function calls wordpress 
  5. */ 
  6.  
  7. protected $titlefix = 'SZ-Google - '; 
  8. protected $capability = 'manage_options'; 
  9. protected $parentslug = 'sz-google-admin.php'; 
  10.  
  11. /** 
  12. * Definition of variables containing the configuration 
  13. * to be applied to the various function calls wordpress 
  14. */ 
  15.  
  16. protected $null = ''; 
  17. protected $pagetitle = ''; 
  18. protected $menutitle = ''; 
  19. protected $menuslug = ''; 
  20. protected $sections = ''; 
  21. protected $sectionsmenu = ''; 
  22. protected $sectionsfields = ''; 
  23. protected $sectionstabs = ''; 
  24. protected $sectionstitle = ''; 
  25. protected $sectionsgroup = ''; 
  26. protected $sectionsoptions = ''; 
  27. protected $validate = ''; 
  28. protected $callback = ''; 
  29. protected $callbackstart = ''; 
  30. protected $callbacksection = ''; 
  31. protected $formHTML = ''; 
  32. protected $formsavebutton = '1'; 
  33.  
  34. /** 
  35. * Definition of variables containing the configuration 
  36. * set during the call to the function moduleAddSetup() 
  37. */ 
  38.  
  39. private $moduleClassName = false; 
  40. private $moduleOptions = false; 
  41. private $moduleOptionSet = false; 
  42.  
  43. /** 
  44. * Definition the constructor function, which is called 
  45. * at the time of the creation of an instance of this class 
  46. */ 
  47.  
  48. function __construct() 
  49. // Setting variables for the correct processing of module,  
  50. // options can be redefined in the function moduleSetup() 
  51.  
  52. $this->validate = array($this, 'moduleValidate'); 
  53. $this->callback = array($this, 'moduleCallback'); 
  54. $this->callbackstart = array($this, 'moduleCallbackStart'); 
  55. $this->callbacksection = array($this, 'moduleCallbackSection'); 
  56.  
  57. // Definition actions for creating the wordpress admin menu  
  58. // and options page for variables of configuration module  
  59.  
  60. add_action('admin_menu', array($this, 'moduleAddMenu')); 
  61. add_action('admin_init', array($this, 'moduleAddFields')); 
  62.  
  63. /** 
  64. * Creating the menu on the admin panel using values ** 
  65. * such as configuration variables object (parent function) 
  66. */ 
  67.  
  68. function moduleAddMenu() 
  69. // Definition of general values **for the creation of a menu associated  
  70. // with the module options. Example slug, page title and menu title 
  71.  
  72. if (function_exists('add_submenu_page'))  
  73. $pagehook = add_submenu_page($this->parentslug, $this->titlefix.$this->pagetitle,  
  74. $this->menutitle, $this->capability, $this->menuslug, $this->callback); 
  75. add_action('admin_print_scripts-'.$pagehook, array($this, 'moduleAddJavascriptPlugins')); 
  76.  
  77. /** 
  78. * Function to add sections and the corresponding options in the configuration 
  79. * page, each option belongs to a section, which is linked to a general tab  
  80. */ 
  81.  
  82. function moduleAddFields() 
  83. if (!is_array($this->sectionsoptions)) $this->sectionsoptions = array(); 
  84. if (!is_array($this->sectionsmenu)) $this->sectionsmenu = array(); 
  85. if (!is_array($this->sectionsfields)) $this->sectionsfields = array(); 
  86.  
  87. // Loading options in reference to a predefined group  
  88. // that will be invoked in the final form 
  89.  
  90. foreach ($this->sectionsoptions as $value) {  
  91. register_setting($this->sectionsoptions[0], $value);  
  92. }  
  93.  
  94. // General reading array containing a list of sections 
  95. // On every section you have to define an array to list fields 
  96.  
  97. foreach($this->sectionsmenu as $key=>$value) { 
  98. add_settings_section($value['section'], $value['title'], $value['callback'], $value['slug']); 
  99.  
  100. // General reading array containing a list of fields 
  101. // that must be added to the sections previously defined 
  102.  
  103. foreach($this->sectionsfields as $key=>$sectionsfield) { 
  104. foreach($sectionsfield as $value) { 
  105. add_settings_field($value['field'], $value['title'], $value['callback'], $this->sectionsmenu[$key]['slug'], $this->sectionsmenu[$key]['section']); 
  106.  
  107. /** 
  108. * Call the general function for creating the general form,  
  109. * sections must be passed as an array of name = > title 
  110. */ 
  111.  
  112. function moduleCallback() 
  113. $this->moduleCommonForm($this->sectionstitle, $this->sectionsoptions,  
  114. $this->sections, $this->formsavebutton, $this->formHTML 
  115. );  
  116.  
  117. /** 
  118. * Defining a callback dummy for the section that is developed 
  119. * during the definition of the sections and input fields  
  120. */ 
  121.  
  122. function moduleCallbackStart() 
  123.  
  124. /** 
  125. * Defining a callback dummy for the section that is developed 
  126. * during the definition of the sections and input fields  
  127. */ 
  128.  
  129. function moduleCallbackSection() 
  130.  
  131. /** 
  132. * Defining a callback dummy for the section that is developed 
  133. * during the definition of the sections and input fields  
  134. */ 
  135.  
  136. function moduleValidate($options) { 
  137. return $options; 
  138.  
  139. /** 
  140. * Add the plugin javascript required only in admin pages that 
  141. * are related to the plugin sz-google and associated loading 
  142. */ 
  143.  
  144. function moduleAddJavascriptPlugins()  
  145. wp_enqueue_script('jquery-ui-sortable'); 
  146. wp_enqueue_script('postbox'); 
  147. wp_enqueue_script('utils'); 
  148. wp_enqueue_script('dashboard'); 
  149. wp_enqueue_script('thickbox'); 
  150.  
  151. /** 
  152. * Calculate the name of the current administration page 
  153. * which can be useful for loading specific modules 
  154. */ 
  155.  
  156. function moduleAdminGetPageNow() { 
  157. global $pagenow; 
  158. return $pagenow; 
  159.  
  160. /** 
  161. * Calculate the name of the current administration page 
  162. * which can be useful for loading specific modules 
  163. */ 
  164.  
  165. function moduleAdminGetAdminPage() { 
  166. if (isset($_GET['page'])) return $_GET['page'];  
  167. else return ''; 
  168.  
  169. /** 
  170. * Calculation options related to the module with execution  
  171. * of formal checks of consistency and setting the default 
  172. */ 
  173.  
  174. function getOptions() 
  175. {  
  176. if ($this->moduleOptions) return $this->moduleOptions; 
  177. else $this->moduleOptions = $this->getOptionsSet($this->moduleOptionSet); 
  178.  
  179. // Return back the correct set of options from 
  180. // formal checks executed by the control function 
  181.  
  182. return $this->moduleOptions; 
  183.  
  184. /** 
  185. * Calculation options related to the module with execution  
  186. * of formal checks of consistency and setting the default  
  187. */ 
  188.  
  189. function getOptionsSet($nameset) 
  190. $optionsDB = get_option($nameset); 
  191. $optionsList = include(dirname(SZ_PLUGIN_GOOGLE_MAIN)."/options/{$nameset}.php"); 
  192.  
  193. // Control options in the event of non-existing 
  194. // function call to the control isset() 
  195.  
  196. foreach($optionsList as $key => $item)  
  197. // Control options in the event of non-existing 
  198. // otherwise add the field in the original array 
  199.  
  200. if (!isset($optionsDB[$key])) $optionsDB[$key] = $item['value']; 
  201.  
  202. // Check if the option field contains a value of NULL 
  203. // in this case check the value option the default 
  204.  
  205. if (isset($item['N']) and $item['N'] == '1') { 
  206. if ($optionsDB[$key] == '') $optionsDB[$key] = $item['value']; 
  207.  
  208. // Check if the option field contains a value of ZERO 
  209. // in this case check the value option the default 
  210.  
  211. if (isset($item['Z']) and $item['Z'] == '1') { 
  212. if ($optionsDB[$key] == '0') $optionsDB[$key] = $item['value']; 
  213.  
  214. // Check if the option field contains a value of YES/NO 
  215. // in this case check the value option the default 
  216.  
  217. if (isset($item['Y']) and $item['Y'] == '1') { 
  218. if (!in_array($optionsDB[$key], array('1', '0'))) $optionsDB[$key] = '0'; 
  219.  
  220. // Back to list the options related to the specified set,  
  221. // convert array to object for direct access 
  222.  
  223. return (object) $optionsDB; 
  224.  
  225. /** 
  226. * Functions for assigning values **that are used for initial  
  227. * setup of the module as the class name and the set of options 
  228. */ 
  229.  
  230. function moduleSetClassName($classname) { $this->moduleClassName = $classname; } 
  231. function moduleSetOptionSet($nameset) { $this->moduleOptionSet = $nameset; } 
  232.  
  233. /** 
  234. * Defining the function to draw the general form of the 
  235. * pages present in the admin panel with plugin options 
  236. */ 
  237.  
  238. function moduleCommonForm($title, $group, $sections, $formsavebutton, $HTML) 
  239. // HTML code creation for the main container to which 
  240. // you add a title, system notifications and any tabs 
  241.  
  242. echo '<div id="sz-google-wrap" class="wrap">'; 
  243. echo '<h2>'.ucwords($title).'</h2>'; 
  244.  
  245. // Issue messages after setting the title, such as 
  246. // the update message of the options in configuration 
  247.  
  248. settings_errors(); 
  249.  
  250. // Main container area designated for configuration parameters 
  251. // defined by the calls of individual modules enabled from admin panel 
  252.  
  253. echo '<div class="postbox-container" id="sz-google-admin-options">'; 
  254. echo '<div class="metabox-holder">'; 
  255. echo '<div class="meta-box-sortables ui-sortable" id="sz-google-box">'; 
  256.  
  257. // If the call contains an array of documentation do I turn off 
  258. // the form for editing parameters, because it is read-only 
  259.  
  260. if ($formsavebutton == '1') { 
  261. echo '<form method="post" action="options.php" enctype="multipart/form-data">'; 
  262. echo '<input type="hidden" name="sz_google_options_plus[plus_redirect_flush]" value="0">'; 
  263.  
  264. // If the call does not contain an array of documentation,  
  265. // I run the creation of the HTML with all fields option to edit 
  266.  
  267. if ($HTML != '')  
  268. echo '<div class="postbox">';  
  269. echo '<div class="handlediv" title="'.ucfirst(__('click to toggle', 'szgoogleadmin')).'"><br></div>'; 
  270. echo '<h3 class="hndle"><span>'.ucfirst(__('documentation', 'szgoogleadmin')).'</span></h3>'; 
  271. echo '<div class="inside">'; 
  272. echo '<div class="help">'; 
  273. echo $HTML; 
  274. echo '</div>'; 
  275. echo '</div>'; 
  276. echo '</div>'; 
  277.  
  278. } else { 
  279.  
  280. // Creating session of the form to add the list of 
  281. // fields in hidden that are needed to submission 
  282.  
  283. settings_fields($group[0]); 
  284.  
  285. // Composition model with the specified tab in sectionstabs 
  286. // otherwise execute the composition of the HTML sections 
  287.  
  288. if (is_array($this->sectionstabs))  
  289. // Composition of the HTML title H2 with various tabs 
  290. // that make up the configuration page of the module 
  291.  
  292. echo '<h2 id="sz-google-tab" class="nav-tab-wrapper">'; 
  293.  
  294. foreach ($this->sectionstabs as $TABKey => $TABValue) { 
  295. echo '<a class="nav-tab" '; 
  296. echo 'id="sz-google-tab-'.$TABValue['anchor'].'" '; 
  297. echo 'href="#'.$TABValue['anchor'].'"'; 
  298. echo '>'.ucfirst($TABValue['description']).'</a>'; 
  299.  
  300. echo '</h2>'; 
  301.  
  302. // For each tab that I find in array design section HTML 
  303. // in hidden mode that will be activated by selecting the tab 
  304.  
  305. foreach ($this->sectionstabs as $TABKey => $TABValue)  
  306. echo '<div class="sz-google-tab-div" id="sz-google-tab-div-'.$TABValue['anchor'].'">'; 
  307.  
  308. foreach ($sections as $key => $value)  
  309. if ($TABKey == $value['tab']) { 
  310. echo '<div class="postbox">';  
  311. echo '<div class="handlediv" title="'.ucfirst(__('click to toggle', 'szgoogleadmin')).'"><br></div>'; 
  312. echo '<h3 class="hndle"><span>'.$value['title'].'</span></h3>'; 
  313. echo '<div class="inside">'; 
  314. do_settings_sections($value['section']); 
  315. echo '</div>'; 
  316. echo '</div>'; 
  317.  
  318. echo '</div>'; 
  319.  
  320. // Composition simple model without reading array of tabs,  
  321. // I write the HTML sections in order to define standard 
  322.  
  323. } else { 
  324.  
  325. foreach ($sections as $key => $value)  
  326. echo '<div class="postbox">';  
  327. echo '<div class="handlediv" title="'.ucfirst(__('click to toggle', 'szgoogleadmin')).'"><br></div>'; 
  328. echo '<h3 class="hndle"><span>'.$value['title'].'</span></h3>'; 
  329. echo '<div class="inside">'; 
  330. do_settings_sections($value['section']); 
  331. echo '</div>'; 
  332. echo '</div>'; 
  333.  
  334. // If the call contains an array of documentation do I turn off the 
  335. // form for the modification of parameters, because it is read-only 
  336.  
  337. if ($formsavebutton == '1') { 
  338. echo '<p class="submit"><input name="Submit" type="submit" class="button-primary" value="'.ucfirst(__('save changes', 'szgoogleadmin')).'"/></p>'; 
  339. echo '</form>'; 
  340.  
  341. echo '</div>'; 
  342. echo '</div>'; 
  343. echo '</div>'; 
  344.  
  345. // Secondary container with information of the authors and some 
  346. // links, such as the community of Italian wordpress for ever :) 
  347.  
  348. echo '<div class="postbox-container" id="sz-google-admin-sidebar">'; 
  349. echo '<div class="metabox-holder">'; 
  350. echo '<div class="meta-box-sortables ui-sortable">'; 
  351.  
  352. // Section on the sidebar menu present on the right side 
  353. // Definition of the menu that will contain "Give us a little help" 
  354.  
  355. echo '<div id="help-us" class="postbox">'; 
  356. echo '<div class="handlediv" title="'.ucfirst(__('click to toggle', 'szgoogleadmin')).'"><br></div>'; 
  357. echo '<h3 class="hndle"><span><strong>'.ucwords(__('give us a little help', 'szgoogleadmin')).'</strong></span></h3>'; 
  358. echo '<div class="inside">'; 
  359. echo '<ul>'; 
  360. echo '<li><a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/sz-google">'.ucfirst(__('rate the plugin', 'szgoogleadmin')).'</a></li>'; 
  361. echo '<li><a target="_blank" href="https://plus.google.com/communities/109254048492234113886">'.ucfirst(__('join our community', 'szgoogleadmin')).'</a></li>'; 
  362. echo '<li><a target="_blank" href="https://plus.google.com/+wpitalyplus">'.ucfirst(__('join our google+ page', 'szgoogleadmin')).'</a></li>'; 
  363. echo '</ul>'; 
  364. echo '</div>'; 
  365. echo '</div>'; 
  366.  
  367. // Section on the sidebar menu present on the right side 
  368. // Definition of the menu that will contain "Official page" 
  369.  
  370. echo '<div id="official-plugin" class="postbox">'; 
  371. echo '<div class="handlediv" title="'.ucfirst(__('click to toggle', 'szgoogleadmin')).'"><br></div>'; 
  372. echo '<h3 class="hndle"><span><strong>'.ucwords(__('official page', 'szgoogleadmin')).'</strong></span></h3>'; 
  373. echo '<div class="inside">'; 
  374. echo '<a target="_blank" href="https://plus.google.com/+wpitalyplus"><img src="'.plugin_dir_url(SZ_PLUGIN_GOOGLE_MAIN).'frontend/files/images/wpitalyplus.png'.'" alt="WordPress Italy+" style="width:100%;height:auto;vertical-align:bottom;"></a>'; 
  375. echo '</div>'; 
  376. echo '</div>'; 
  377.  
  378. // Section on the sidebar menu present on the right side 
  379. // Definition of the menu that will contain "Request for support" 
  380.  
  381. echo '<div id="support-plugin" class="postbox">'; 
  382. echo '<div class="handlediv" title="'.ucfirst(__('click to toggle', 'szgoogleadmin')).'"><br></div>'; 
  383. echo '<h3 class="hndle"><span><strong>'.ucwords(__('support', 'szgoogleadmin')).'</strong></span></h3>'; 
  384. echo '<div class="inside">'; 
  385. echo '<ul>'; 
  386. echo '<li><a target="_blank" href="http://wordpress.org/support/plugin/sz-google">'.ucfirst(__('support for bugs and reports', 'szgoogleadmin')).'</a></li>'; 
  387. echo '<li><a target="_blank" href="https://plus.google.com/communities/109254048492234113886">'.ucfirst(__('support for new requests', 'szgoogleadmin')).'</a></li>'; 
  388. echo '</ul>'; 
  389. echo '</div>'; 
  390. echo '</div>'; 
  391.  
  392. // Section on the sidebar menu present on the right side 
  393. // Definition of the menu that will contain "Authors of the plugin" 
  394.  
  395. echo '<div id="authors-plugin" class="postbox">'; 
  396. echo '<div class="handlediv" title="'.ucfirst(__('click to toggle', 'szgoogleadmin')).'"><br></div>'; 
  397. echo '<h3 class="hndle"><span><strong>'.ucwords(__('authors', 'szgoogleadmin')).'</strong></span></h3>'; 
  398. echo '<div class="inside">'; 
  399. echo '<ul>'; 
  400. echo '<li><a target="_blank" href="https://plus.google.com/+MassimoDellaRovere">Massimo Della Rovere</a></li>'; 
  401. echo '</ul>'; 
  402. echo '</div>'; 
  403. echo '</div>'; 
  404.  
  405. // Section on the sidebar menu present on the right side 
  406. // Definition of the menu that will contain "About the plugin" 
  407.  
  408. echo '<div id="info-plugin" class="postbox">'; 
  409. echo '<div class="handlediv" title="'.ucfirst(__('click to toggle', 'szgoogleadmin')).'"><br></div>'; 
  410. echo '<h3 class="hndle"><span><strong>'.ucwords(__('latest news', 'szgoogleadmin')).'</strong></span></h3>'; 
  411. echo '<div class="inside">'; 
  412. echo '<ul>'; 
  413. echo '<li><a target="_blank" href="https://plus.google.com/+wpitalyplus">'.ucfirst(__('news:', 'szgoogleadmin'))." ".ucfirst(__('official page', 'szgoogleadmin')).'</a></li>'; 
  414. echo '<li><a target="_blank" href="https://otherplus.com/tech/sz-google/">'.ucfirst(__('news:', 'szgoogleadmin'))." ".ucfirst(__('official website', 'szgoogleadmin')).'</a></li>'; 
  415. echo '<li><a target="_blank" href="https://plus.google.com/communities/109254048492234113886">'.ucfirst(__('news:', 'szgoogleadmin'))." ".ucfirst(__('community WordPress', 'szgoogleadmin')).'</a></li>'; 
  416. echo '<li><a target="_blank" href="http://www.youtube.com/user/wpitalyplus?sub_confirmation=1">'.ucfirst(__('news:', 'szgoogleadmin'))." ".ucfirst(__('youtube channel', 'szgoogleadmin')).'</a></li>'; 
  417. echo '</ul>'; 
  418. echo '</div>'; 
  419. echo '</div>'; 
  420.  
  421. // Section on the sidebar menu present on the right side 
  422. // Closing the main HTML container for main sidebar right 
  423.  
  424. echo '</div>'; 
  425. echo '</div>'; 
  426. echo '</div>'; 
  427.  
  428. echo '</div>'; 
  429.  
  430. /** 
  431. * Description option to be included in the input field 
  432. * present in the general form of the pages with the options 
  433. */ 
  434.  
  435. function moduleCommonFormDescription($description)  
  436. echo '</td></tr>'; 
  437. echo '<tr><td class="description" colspan="2">'; 
  438. echo ucfirst(trim($description)); 
  439.  
  440. /** 
  441. * Description TEXT field to be inserted in the input field 
  442. * present in the general form of the pages with the options 
  443. */ 
  444.  
  445. function moduleCommonFormText($optionset, $name, $class='medium', $placeholder='')  
  446. {  
  447. $options = get_option($optionset); 
  448.  
  449. if (!isset($options[$name])) $options[$name] = ''; 
  450. else $options[$name] = esc_html($options[$name]); 
  451.  
  452. echo '<input name="'.$optionset.'['.$name.']" type="text" class="'.$class.'" '; 
  453. echo 'value="'.$options[$name].'" placeholder="'.$placeholder.'"/>'; 
  454.  
  455. /** 
  456. * Description SELECT field to be inserted in the input field 
  457. * present in the general form of the pages with the options 
  458. */ 
  459.  
  460. function moduleCommonFormSelect($optionset, $name, $values, $class='medium', $placeholder='')  
  461. $options = get_option($optionset); 
  462.  
  463. if (!isset($options[$name])) $options[$name] = "";  
  464. if (!isset($options['plus_language'])) $options['plus_language'] = '99'; 
  465.  
  466. echo '<select name="'.$optionset.'['.$name.']" class="'.$class.'">'; 
  467.  
  468. foreach ($values as $key=>$value) { 
  469. $selected = ($options[$name] == $key) ? ' selected = "selected"' : ''; 
  470. echo '<option value="'.$key.'"'.$selected.'>'.$value.'</option>'; 
  471.  
  472. echo '</select>'; 
  473.  
  474. /** 
  475. * Description YES/NO field to be inserted in the input field 
  476. * present in the general form of the pages with the options 
  477. */ 
  478.  
  479. function moduleCommonFormCheckboxYesNo($optionset, $name, $class='medium')  
  480. $options = get_option($optionset); 
  481.  
  482. if (!isset($options[$name])) $options[$name] = '0'; 
  483.  
  484. echo '<input type="hidden" name="'.$optionset.'['.$name.']" value="0"/>'; 
  485. echo '<label class="sz-google"><input name="'.$optionset.'['.$name.']" type="checkbox" value="1" '; 
  486. echo 'class="'.$class.'" '.checked(1, $options[$name], false).'/><span class="checkbox" style="display:none">'.__('YES / NO', 'szgoogleadmin').'</span></label>'; 
  487.  
  488. /** 
  489. * Description NUMERIC field to be inserted in the input field 
  490. * present in the general form of the pages with the options 
  491. */ 
  492.  
  493. function moduleCommonFormNumberStep1($optionset, $name, $class='medium', $placeholder='')  
  494. $options = get_option($optionset); 
  495.  
  496. if (!isset($options[$name])) $options[$name]="";  
  497.  
  498. echo '<input name="'.$optionset.'['.$name.']" type="number" step="1" class="'.$class.'" '; 
  499. echo 'value="'.$options[$name].'" placeholder="'.$placeholder.'"/>';