# e2pdf/1.01.01/classes/controller/e2pdf-settings.php

E2Pdf – Export Pdf Tool for WordPress, version 1.01.01. 217 lines.

- Page: https://pluginprobe.com/plugins/e2pdf/1.01.01/code/classes/controller/e2pdf-settings.php
- Raw: https://pluginprobe.com/plugins/e2pdf/1.01.01/raw/classes/controller/e2pdf-settings.php
- Modified: 2018-11-07T14:59:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/e2pdf/1.01.01/code/classes/controller/e2pdf-settings.php#L10-L20`.

```php
<?php

/**
 * E2pdf Settings Controller
 * 
 * @copyright  Copyright 2017 https://e2pdf.com
 * @license    GPL v2
 * @version    1
 * @link       https://e2pdf.com
 * @since      0.00.01
 */
if (!defined('ABSPATH')) {
    die('Access denied.');
}

class Controller_E2pdf_Settings extends Helper_E2pdf_View {

    /**
     * @url admin.php?page=e2pdf-settings
     */
    public function index_action() {
        if ($this->post->get()) {
            $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
            $options = Model_E2pdf_Options::get_options(false, array('common_group'));
            foreach ($options as $group_key => $group) {
                foreach ($group['options'] as $option_key => $option_value) {
                    if (array_key_exists($option_value['key'], $this->post->get())) {
                        update_option($option_value['key'], $this->post->get($option_value['key']));
                    }
                }
            }
            $this->add_notification('update', __('Settings saved', 'e2pdf'));
        }

        $options = Model_E2pdf_Options::get_options(false, array('common_group'));
        $groups = $this->get_groups();

        $this->view('options', $options);
        $this->view('groups', $groups);
    }

    /**
     * @url admin.php?page=e2pdf-settings&action=fonts
     */
    public function fonts_action() {

        $model_e2pdf_font = new Model_E2pdf_Font();
        $groups = $this->get_groups();

        if ($this->post->get()) {
            $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');

            $allowed_ext = array(
                'ttf'
            );

            $font = $this->files->get('font');

            $name = $font['name'];
            $tmp = $font['tmp_name'];


            $filename = pathinfo($name, PATHINFO_FILENAME);
            $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
            $name = $filename . "." . $ext;

            $fonts = $model_e2pdf_font->get_fonts();

            $font_info = false;
            $exist = false;

            if (in_array($ext, $allowed_ext)) {
                $font_info = $model_e2pdf_font->get_font_info(false, 4, $tmp);
                if ($font_info) {
                    $exist = array_search($font_info, $fonts);
                }
            }

            if (!$tmp) {
                $this->add_notification('error', __('Please choose font to upload', 'e2pdf'));
            } else if ($font['error']) {
                $this->add_notification('error', $font['error']);
            } elseif (!in_array($ext, $allowed_ext)) {
                $this->add_notification('error', __('Incorrect file extension', 'e2pdf'));
            } elseif (!$font_info) {
                $this->add_notification('error', __('Incompatible type', 'e2pdf'));
            } elseif (array_key_exists($name, $fonts)) {
                $this->add_notification('error', __('Font with this filename already exists', 'e2pdf'));
            } elseif ($exist) {
                $this->add_notification('error', __('Font with this name already exists', 'e2pdf'));
            } elseif (move_uploaded_file($font['tmp_name'], $this->helper->get('fonts_dir') . $name)) {
                $this->add_notification('update', __('Font uploaded successfully', 'e2pdf'));
            }
        }

        $fonts = $model_e2pdf_font->get_fonts();

        $this->view('fonts', $fonts);
        $this->view('groups', $groups);
    }

    public function extension_action() {

        $group_key = $this->get->get('group');

        if ($this->post->get()) {

            $this->check_nonce($this->post->get('_nonce'), 'e2pdf_post');
            $options = Model_E2pdf_Options::get_options(false, array($group_key));

            foreach ($options as $group_key => $group) {
                foreach ($group['options'] as $option_key => $option_value) {
                    if (array_key_exists($option_value['key'], $this->post->get())) {
                        update_option($option_value['key'], $this->post->get($option_value['key']));
                    }
                }
            }

            $this->add_notification('update', __('Settings saved', 'e2pdf'));
        }

        $options = Model_E2pdf_Options::get_options(false, array($group_key));
        $groups = $this->get_groups();

        $this->view('options', $options);
        $this->view('groups', $groups);
    }

    /**
     * Get options list
     * 
     * @return array() - Options list
     */
    public function get_groups() {
        $groups = Model_E2pdf_Options::get_options(false, array(
                    'static_group',
                        ), true);

        return $groups;
    }

    /**
     * Remove font via ajax
     * action: wp_ajax_e2pdf_delete_font
     * function: e2pdf_delete_font
     * 
     * @return json
     */
    public function ajax_delete_font() {

        $this->check_nonce($this->get->get('_nonce'), 'e2pdf_ajax');
        $font = $this->post->get('data');

        $model_e2pdf_font = new Model_E2pdf_Font();
        $model_e2pdf_font->delete_font($font);

        $response = array(
            'redirect' => $this->helper->get_url(array(
                'page' => 'e2pdf-settings',
                'action' => 'fonts'
                    )
            )
        );

        $this->add_notification('update', __('Font removed successfully', 'e2pdf'));
        $this->json_response($response);
    }

    public function ajax_email() {
        $this->check_nonce($this->get->get('_nonce'), 'e2pdf_ajax');

        $data = $this->post->get('data');
        $email = isset($data['email']) ? trim($data['email']) : '';
        $email_code = isset($data['email_code']) ? trim($data['email_code']) : '';


        $model_e2pdf_api = new Model_E2pdf_Api();
        $model_e2pdf_api->set(array(
            'action' => 'common/email',
            'data' => array(
                'email' => $email,
                'email_code' => $email_code,
                'email_confirm' => isset($data['email_code'])
            )
        ));
        $request = $model_e2pdf_api->request();



        if (isset($request['error'])) {
            if ($request['error'] === 'incorrect_email') {
                $response = array(
                    'error' => __('E-mail address incorrect', 'e2pdf')
                );
            } elseif ($request['error'] === 'incorrect_code') {
                $response = array(
                    'error' => __('Confirmation code incorrect', 'e2pdf')
                );
            } else {
                $response = array(
                    'error' => $request['error']
                );
            }
        } elseif (isset($request['success'])) {
            $response = array(
                'content' => $request['success']
            );
            if ($request['success'] == 'subscribed') {
                update_option('e2pdf_email', $email);
            }
        }

        $this->json_response($response);
    }

}

```
