getTemplates(); $default_templates = $this->get_default_templates(); $templateOpts = array( 'nonce' => array ( 'Type' => 'nonce', 'Value' => 'update-AmazonLink-templates' ), 'ID' => array ( 'Default' => '', 'Type' => 'hidden'), 'title' => array ( 'Type' => 'section', 'Value' => '', 'Class' => 'hidden', 'Section_Class' => 'al_subhead'), 'Name' => array ( 'Type' => 'text', 'Name' => __('Template Name', 'amazon-link'), 'Default' => 'Template', 'Size' => '40'), 'Description' => array ( 'Type' => 'text', 'Name' => __('Template Description', 'amazon-link'), 'Default' => 'Template Description', 'Size' => '80'), 'Type' => array ( 'Type' => 'selection', 'Name' => __('Template Type', 'amazon-link'), 'Hint' => __('Type of Template, \'Multi\' templates are for multi-product ones that contain the %ASINS% keyword, \'No ASIN\' templates are for non-product specific ones, e.g. Banners and Scripts', 'amazon-link'), 'Default' => 'Product', 'Options' => array('Product', 'No ASIN', 'Multi') ), 'Preview_Off' => array ( 'Type' => 'checkbox', 'Name' => __('Disable Preview', 'amazon-link'), 'Hint' => __('Disable the preview if it contains a script that might conflict with the options pages.', 'amazon-link'), 'Default' => '0'), 'Content' => array ( 'Type' => 'textbox', 'Name' => __('The Template', 'amazon-link'), 'Rows' => 5, 'Description' => __('Template Content', 'amazon-link'), 'Default' => '' ), 'Buttons1' => array ( 'Type' => 'buttons', 'Buttons' => array ( __('Copy', 'amazon-link') => array( 'Action' => 'ALTemplateAction', 'Hint' => __( 'Make a Copy of this template', 'amazon-link'), 'Class' => 'button-secondary'), __('Update', 'amazon-link') => array( 'Action' => 'ALTemplateAction', 'Hint' => __( 'Save changes made to this template', 'amazon-link'), 'Class' => 'button-secondary'), __('New', 'amazon-link') => array( 'Action' => 'ALTemplateAction', 'Hint' => __( 'Create a New blank template', 'amazon-link'), 'Class' => 'button-secondary'), __('Delete', 'amazon-link') => array( 'Action' => 'ALTemplateAction', 'Hint' => __( 'Delete this template', 'amazon-link'), 'Class' => 'button-secondary') )), 'preview' => array ( 'Type' => 'title', 'Value' => '', 'Title_Class' => ''), 'end' => array ( 'Type' => 'end') ); $global_opts = array( 'nonce' => array ( 'Type' => 'nonce', 'Value' => 'update-AmazonLink-templates' ), 'Buttons1' => array ( 'Type' => 'buttons', 'Buttons' => array ( __('Export', 'amazon-link') => array( 'Action' => 'ALTemplateAction', 'Hint' => __( 'Export Templates to a Amazon Link Extra Plugin', 'amazon-link'), 'Class' => 'button-secondary'), __('New', 'amazon-link') => array( 'Action' => 'ALTemplateAction', 'Hint' => __( 'Create a New blank template', 'amazon-link'), 'Class' => 'button-secondary') )), ); /*****************************************************************************************/ $Action = (isset($_POST[ 'ALTemplateAction' ]) && check_admin_referer( 'update-AmazonLink-templates')) ? $_POST[ 'ALTemplateAction' ] : ( (isset($_POST[ 'ALDefTemplateAction' ]) && check_admin_referer( 'update-AmazonLink-def-templates')) ? $_POST[ 'ALDefTemplateAction' ] : 'No Action'); // Get the Template ID if selected. if (isset($_POST['ID'])) { $templateID=$_POST['ID']; } $NotifyUpdate = False; // See if the user has posted us some information // If they did, the admin Nonce should be set. if( $Action == __('Update', 'amazon-link') ) { // Update Template settings // Check for clash of ID with other templates $NewTemplateID = strtolower($_POST['Name']); if ($templateID !== $NewTemplateID) { $NewID = ''; while (isset($Templates[ $NewTemplateID . $NewID ])) $NewID++; unset($Templates[$templateID]); $templateID = $NewTemplateID . $NewID; $_POST['Name'] = $_POST['Name']. $NewID; } foreach ($templateOpts as $Setting => $Details) { if (isset($Details['Name'])) { // Read their posted value $Templates[$templateID][$Setting] = isset($_POST[$Setting]) ? stripslashes($_POST[$Setting]) : NULL; } } $NotifyUpdate = True; $UpdateMessage = sprintf (__('Template %s Updated','amazon-link'), $templateID); } else if ( $Action == __('Delete', 'amazon-link') ) { unset($Templates[$templateID]); $NotifyUpdate = True; $UpdateMessage = sprintf (__('Template "%s" deleted.','amazon-link'), $templateID); } else if ( $Action == __('Copy', 'amazon-link') ) { $NewID = 1; while (isset($Templates[ $templateID . $NewID ])) $NewID++; $Templates[$templateID. $NewID] = $Templates[$templateID]; $Templates[$templateID. $NewID]['Name'] = $templateID. $NewID; $NotifyUpdate = True; $UpdateMessage = sprintf (__('Template "%s" created from "%s".','amazon-link'), $templateID. $NewID, $templateID); } else if ( $Action == __('New', 'amazon-link') ) { $NewID = ''; while (isset($Templates[ __('template', 'amazon-link') . $NewID ])) $NewID++; $Templates[__('template', 'amazon-link') . $NewID] = array('Name' => __('Template', 'amazon-link') . $NewID, 'Content' => '', 'Type' => 'Product', 'Description' => __('Template Description', 'amazon-link')); $NotifyUpdate = True; $UpdateMessage = sprintf (__('Template "%s" created.','amazon-link'), __('template', 'amazon-link') . $NewID); } else if ($Action == __('Install', 'amazon-link') ) { $NewID = ''; while (isset($Templates[ $templateID . $NewID ])) $NewID++; $Templates[$templateID. $NewID] = $default_templates[$templateID]; $Templates[$templateID. $NewID]['Name'] = $templateID. $NewID; $NotifyUpdate = True; $UpdateMessage = sprintf (__('Template "%s" created from "%s".','amazon-link'), $templateID. $NewID, $templateID); } else if (($Action == __('Upgrade', 'amazon-link') ) || ($Action == __('Reset', 'amazon-link') )) { $Templates[$templateID] = $default_templates[$templateID]; $NotifyUpdate = True; $UpdateMessage = sprintf (__('Template "%s" overwritten with default version.','amazon-link'), $templateID); } else if (($Action == __('Export', 'amazon-link') )) { $result= $this->export_templates($this->extras_dir . 'amazon-link-exported-templates.php'); $NotifyUpdate = True; $UpdateMessage = $result['Message']; } /*****************************************************************************************/ /* * If first run need to create a default templates */ if(!isset($Templates['wishlist'])) { foreach ($default_templates as $templateName => $templateDetails) { if(!isset($Templates[$templateName])) { $Templates[$templateName] = $templateDetails; $NotifyUpdate = True; $UpdateMessage = sprintf (__('Default Templates Created - Note: \'wishlist\' template must exist.','amazon-link')); } } } /*****************************************************************************************/ if ($NotifyUpdate && current_user_can('manage_options')) { $this->saveTemplates($Templates); $Templates = $this->getTemplates(); // ********************************************************** // Put an options updated message on the screen ?>