Plugin Directory

Changeset 1532717


Ignore:
Timestamp:
11/12/2016 03:31:57 AM (9 years ago)
Author:
Tsjuder
Message:

Add version 1.2.2

Location:
tea-page-content
Files:
6 added
17 edited

Legend:

Unmodified
Added
Removed
  • tea-page-content/trunk/assets/css/tea-page-content-admin.css

    r1485276 r1532717  
    380380    vertical-align: middle;
    381381}
     382
     383.tpc-settings-page {
     384
     385}
     386.tpc-settings-page h2 {
     387    margin-bottom: 30px !important;
     388}
     389.tpc-form-group {
     390    display: block;
     391    margin-top: 10px;
     392}
     393.tpc-form-group:first-child {
     394    margin-top: 0;
     395}
     396
     397.tpc-form-group {
     398    font-size: 1.2em;
     399}
     400
     401.tpc-form-group span {
     402    margin: 10px 0;
     403}
     404.tpc-form-group small {
     405}
     406.tpc-form-group input,
     407.tpc-form-group select {
     408    margin-top: 10px;
     409    min-width: 250px;
     410}
  • tea-page-content/trunk/assets/js/tea-page-content-admin-notices.js

    r1485276 r1532717  
    55        $('#tpc-deprecated-notice .notice-dismiss').one('click', function() {
    66            jQuery.post(ajaxurl, {
    7                 'action': 'set_notice_seen',
    8                 'version': '1.2'
     7                'action': 'set_notice_seen'
    98            }, function(response) {});
    109        });
  • tea-page-content/trunk/assets/js/tea-page-content-admin.js

    r1485963 r1532717  
    4848                    'resizable': false,
    4949                    'closeText': '',
     50                    'class': 'tpc-ui-modal-wrapper',
    5051                    'buttons': [
    5152                        {
     
    5960                        }
    6061                    ],
    61                     'close': API.callbacks.dialog_on_close
     62                    'close': API.callbacks.dialog_on_close,
     63                    'open': API.callbacks.dialog_on_open,
    6264                };
    6365
  • tea-page-content/trunk/assets/js/tea-page-content-api.js

    r1485276 r1532717  
    271271
    272272                setTimeout(function() {
    273                     //send_to_editor('Nie wieder stress mit');
    274 
    275273                    $preloader.addClass('is-hidden');
    276274                   
     
    280278                }, 500);
    281279            });
    282 
    283            
    284280        },
    285281
     
    330326        },
    331327
     328        'dialog_on_open': function(event, ui) {
     329            var $dialogWrapper = TeaPageContent_API.storage.get('dialog').parent();
     330            var $window = jQuery(window);
     331
     332            var topMargin = 30;
     333
     334            if($window.height() >= $dialogWrapper.height() - topMargin) {
     335                $dialogWrapper.css('margin-top', topMargin + 'px');
     336            }
     337        },
     338
    332339        'media_on_select': function() {
    333340            var $this = jQuery(this);
  • tea-page-content/trunk/classes/config.class.php

    r1485963 r1532717  
    22/**
    33 * @package Tea Page Content
    4  * @version 1.2.1
     4 * @version 1.2.2
    55 */
    66
    77class TeaPageContent_Config {
    88    private static $_instance;
     9
    910    private $_config;
     11    private $_helper;
     12    private $_map;
    1013
    1114    /**
     
    2831     */
    2932    private static function initialize() {
    30         $config = include(TEA_PAGE_CONTENT_PATH . '/config.php');
     33        $config = require_once(TEA_PAGE_CONTENT_PATH . '/config.php');
     34        $map = require_once(TEA_PAGE_CONTENT_PATH . '/config.map.php');
     35
     36        // Create new helper instance
     37        self::$_instance->_helper = new TeaPageContent_Helper;
    3138
    3239        if(is_array($config)) {
    3340            self::$_instance->_config = apply_filters('tpc_config_array', $config);
     41
     42            if(is_array($map)) {
     43                self::$_instance->_map = apply_filters('tpc_config_map_array', $map);
     44            }
    3445
    3546            unset($config);
     
    5869
    5970    /**
     71     * Return the config map which load previously.
     72     *
     73     * @return array
     74     */
     75    public function get_config_map() {
     76        return $this->_map;
     77    }
     78
     79    public function sanitizeOption($param, $value) {
     80        if(!isset($this->_map[$param])) {
     81            return $value;
     82        }
     83
     84        $filter = 'safehtml'; // @todo via config
     85        if(isset($this->_map[$param]['filter'])) {
     86            $filter = $this->_map[$param]['filter'];
     87        }
     88
     89        switch ($filter) {
     90            case 'safehtml':
     91                $value = htmlspecialchars($value);
     92            break;
     93            case 'string':
     94                $value = htmlspecialchars(strip_tags($value));
     95            break;
     96        }
     97
     98        return addslashes($value);
     99    }
     100
     101    /**
    60102     * Public getter. Returns a config parameter,
    61103     * if it exists. In other case returns null.
     
    63105     * @param string $params Dot-separated path to needly parameter
    64106     * @param string|array $except Determine parameters that will be excluded
     107     * @param boolean $use_option If true, checking for existed self-titled option and return option value
    65108     *
    66109     * @return mixed|null
    67110     */
    68     public function get($param, $except = null) {
     111    public function get($param, $except = null, $use_option = false) {
    69112        $pieces = explode('.', $param);
    70113        $piecesCount = count($pieces);
    71114
    72115        $result = null;
     116
     117        // Force result find. If we use options, find in database and return result if finded.
     118        // Please note, excerpts are not supported in options now.
     119        if($use_option) {
     120            $alias = $this->_helper->convertConfigPathToSetting($param); // @todo make dis shit dry {4}
     121
     122            if(!is_null($result = get_option($alias, null))) {
     123                return $this->sanitizeOption($param, $result);
     124            }
     125        }
     126
     127        // If not, find in config stack.
    73128        $stack = $this->_config;
    74129        for ($i = 0; $i <= $piecesCount; $i++) {
     
    93148        return $result;
    94149    }
     150
     151    public function get_current($param) {
     152        return $this->get($param, null, true);
     153    }
     154
     155    public function get_default($param, $except = null) {
     156        return $this->get($param, $except, false);
     157    }
    95158}
  • tea-page-content/trunk/classes/helper.class.php

    r1485963 r1532717  
    22/**
    33 * @package Tea Page Content
    4  * @version 1.2.1
     4 * @version 1.2.2
    55 */
    66
     
    130130        }
    131131
     132        // Filter by post status...
     133        if(!isset($params['post_status'])) {
     134            $params['post_status'] = $this->_config->get_current('defaults.posts.post_status');
     135        }
     136
     137        // ...and by protected settings too
     138        if(!isset($params['has_password'])) {
     139            $params['has_password'] = $this->_config->get_current('defaults.posts.has_password');
     140        }
     141
    132142        // Filter param array
    133143        $params = apply_filters('tpc_post_params', $params);
     
    353363    }
    354364
     365    /**
     366     * Get page variables from global (passed) array for one specified entry.
     367     *
     368     * @param array $page_variables
     369     * @param int|null $entry_id
     370     * @return array
     371     */
    355372    public function getPageVariables($page_variables, $entry_id = null) {
    356373        $result = array();
     
    381398    }
    382399
     400    /**
     401     * Remove prefix before merging page variables with entry properties.
     402     * Need this because page variables should override some properties of entry.
     403     *
     404     * @param array $page_variables
     405     * @return array
     406     */
    383407    public function preparePageVariablesForMerge($page_variables) {
    384408        $page_var_prefix = $this->_config->get('system.page-variables.prefix');
     
    468492                                        $exploded[1] = wp_get_attachment_url($exploded[1]);
    469493                                    } else {
    470                                         $exploded[1] = wp_get_attachment_image($exploded[1], 'post-thumbnail'); // @todo в конфиг
     494                                        $thumbnail_size = 'post-thumbnail'; // @todo в конфиг
     495                                        $thumbnail_size = apply_filters('tpc_thumbnail_size', $thumbnail_size, $exploded[1], $entry_id);
     496
     497                                        $exploded[1] = wp_get_attachment_image($exploded[1], $thumbnail_size);
    471498                                    }
    472499                                }
     
    492519     * @return array
    493520     */
    494     public function extractPageVariables($attrs, $apply_rules = true) {
     521    public function extractPageVariables($attrs, $entry_id = null, $apply_rules = true) {
    495522        $existed_variables = $this->_config->get('defaults.page-variables');
    496523
     
    506533                                $value = wp_get_attachment_url($value);
    507534                            } else {
    508                                 $value = wp_get_attachment_image($value, 'post-thumbnail'); // @todo в конфиг
     535                                $thumbnail_size = 'post-thumbnail'; // @todo в конфиг
     536                                $thumbnail_size = apply_filters('tpc_thumbnail_size', $thumbnail_size, $value, $entry_id);
     537
     538                                $value = wp_get_attachment_image($value, $thumbnail_size);
    509539                            }
    510540                        }
     
    551581        return $templates;
    552582    }
     583
     584    public function getMappedSettings() {
     585        $result = array();
     586
     587        $map = $this->_config->get_config_map();
     588
     589        foreach ($map as $config_path => $params) {
     590            $alias = $this->convertConfigPathToSetting($config_path);
     591
     592            $default_value = $this->_config->get_current($config_path);
     593
     594            $params['default'] = $default_value;
     595
     596            $result[$alias] = $params;
     597        }
     598
     599        return $result;
     600    }
     601
     602    public function convertSettingToConfigPath($setting) {
     603        if(!is_string($setting)) {
     604            return false;
     605        }
     606
     607        return str_replace(array('tpc_', '__'), array('', '.'), $setting); // @todo make dis shit dry {4}
     608        // get tpc_ via config
     609    }
     610
     611    public function convertConfigPathToSetting($config_path) {
     612        if(!is_string($config_path)) {
     613            return false;
     614        }
     615
     616        return 'tpc_' . str_replace('.', '__', $config_path);
     617    }
     618
     619    public function updateDeprecatedNoticeOption() {
     620        $version = $this->_config->get('system.versions.plugin');
     621
     622        if(!get_option('tpc_deprecated_notice')) {
     623            add_option('tpc_deprecated_notice', $version, '', 'no');
     624        } else {
     625            update_option('tpc_deprecated_notice', $version, 'no');
     626        }
     627    }
    553628}
  • tea-page-content/trunk/config.php

    r1485963 r1532717  
    22/**
    33 * @package Tea Page Content
    4  * @version 1.2.1
     4 * @version 1.2.2
    55 */
    66
     
    3737        ),
    3838        'post-types' => array(
    39             'public' => true
     39            'public' => true,
     40        ),
     41        'posts' => array(
     42            'post_status' => 'publish', // may be an array too
     43            'has_password' => false,
    4044        ),
    4145        'template-variables' => array(
     
    6266    'system' => array(
    6367        'posts' => array(
    64             'types-operator' => 'or'
     68            'types-operator' => 'or',
    6569        ),
    6670        'predefined-templates' => array(
     
    7882        'template-directories' => array(
    7983            'plugin' => TEA_PAGE_CONTENT_PATH . '/templates/',
    80             'theme' => get_template_directory() . '/templates/'
     84            'theme' => get_stylesheet_directory() . '/templates/'
    8185        ),
    8286        'versions' => array(
    83             'plugin' => '1.2.0',
    84             'scripts' => '1.2',
    85             'styles' => '1.2'
    86         )
     87            'plugin' => '1.2.2',
     88            'scripts' => '1.2.2',
     89            'styles' => '1.2.2'
     90        ),
     91
     92        'settings' => array(
     93            'include-css' => true,
     94        ),
    8795    )
    8896);
  • tea-page-content/trunk/languages/tea-page-content-ru_RU.po

    r1485276 r1532717  
    66"Project-Id-Version: tea-page-content\n"
    77"Report-Msgid-Bugs-To: Translator Name <[email protected]>\n"
    8 "POT-Creation-Date: 2016-08-29 00:27+0400\n"
     8"POT-Creation-Date: 2016-11-11 20:13+0400\n"
    99"PO-Revision-Date: \n"
    1010"Last-Translator: \n"
     
    2525"X-Poedit-SearchPath-0: .\n"
    2626
    27 #: config.php:48 templates/default-widget-admin-dialog-insert-shortcode.php:6
     27#: config.map.php:9
     28msgid "Enable plugin's CSS?"
     29msgstr "Включить CSS плагина?"
     30
     31#: config.map.php:10
     32msgid ""
     33"You can exclude css of plugin from output if you do not use default "
     34"templates."
     35msgstr ""
     36"Вы можете отключить css плагина, если вы не используете стандартные шаблоны."
     37
     38#: config.php:52 templates/default-widget-admin-dialog-insert-shortcode.php:6
    2839#: templates/default-widget-admin.php:5
    2940msgid "Title"
    3041msgstr "Заголовок"
    3142
    32 #: config.php:52
     43#: config.php:56
    3344msgid "Content"
    3445msgstr "Контент"
    3546
    36 #: config.php:56
     47#: config.php:60
    3748msgid "Thumbnail"
    3849msgstr "Миниатюра"
    3950
    40 #: modules/widget.php:27
     51#: modules/widget.php:27 tea-page-content.class.php:110
    4152msgid "Tea Page Content"
    4253msgstr "Tea Page Content"
     
    4657msgstr "Позволяет отображать любой контент любой записи."
    4758
    48 #: tea-page-content.class.php:67
     59#: tea-page-content.class.php:88 templates/default-settings-page.php:2
     60msgid "Settings"
     61msgstr "Настройки"
     62
     63#: tea-page-content.class.php:101
    4964msgid "Tea Page Content Shortcode"
    5065msgstr "Шорткод Tea Page Content"
    5166
    52 #: tea-page-content.class.php:377
     67#: tea-page-content.class.php:110
     68msgid "Tea Page Content - Settings"
     69msgstr ""
     70
     71#: tea-page-content.class.php:437
    5372msgid ""
    54 "Thanks for update! In Tea Page Content 1.2 was added some new features. We "
    55 "recommend you check out the <a href=\"https://wordpress.org/plugins/tea-page-"
    56 "content/changelog/\">changelog</a>. <b>This notice appears only once!</b>"
     73"Thanks for update! We recommend you check out the <a href=\"https://"
     74"wordpress.org/plugins/tea-page-content/changelog/\">changelog</a>. <b>This "
     75"notice appears only one time.</b>"
    5776msgstr ""
    58 "Спасибо за обновление! В Tea Page Content 1.2 были добавлены новые "
    59 "возможности. Мы рекомендуем ознакомиться с ними в <a href=\"https://"
    60 "wordpress.org/plugins/tea-page-content/changelog/\">логе изменений</a>. "
    61 "<b>Это сообщение появляется только один раз!</b>"
     77"Спасибо за обновление! Мы рекомендуем просмотреть <a href=\"https://"
     78"wordpress.org/plugins/tea-page-content/changelog/\">список обновлений</a>. "
     79"<b>Это уведомление появляется лишь один раз.</b>"
     80
     81#: templates/default-settings-page.php:27
     82msgid "Yes"
     83msgstr "Да"
     84
     85#: templates/default-settings-page.php:28
     86msgid "No"
     87msgstr "Нет"
     88
     89#: templates/default-settings-page.php:51
     90msgid "Submit"
     91msgstr "Отправить"
    6292
    6393#: templates/default-widget-admin-dialog-insert-shortcode.php:16
     
    135165
    136166#~ msgid ""
     167#~ "Thanks for update! In Tea Page Content 1.2 was added some new features. "
     168#~ "We recommend you check out the <a href=\"https://wordpress.org/plugins/"
     169#~ "tea-page-content/changelog/\">changelog</a>. <b>This notice appears only "
     170#~ "once!</b>"
     171#~ msgstr ""
     172#~ "Спасибо за обновление! В Tea Page Content 1.2 были добавлены новые "
     173#~ "возможности. Мы рекомендуем ознакомиться с ними в <a href=\"https://"
     174#~ "wordpress.org/plugins/tea-page-content/changelog/\">логе изменений</a>. "
     175#~ "<b>Это сообщение появляется только один раз!</b>"
     176
     177#~ msgid ""
    137178#~ "Warning! Since Tea Page Content 1.1 some parameters is <b>deprecated</b>, "
    138179#~ "and will be <b>deleted</b> in the next release. We strongly recommend you "
  • tea-page-content/trunk/modules/shortcode.php

    r1485963 r1532717  
    22/**
    33 * @package Tea Page Content
    4  * @version 1.2.1
     4 * @version 1.2.2
    55 */
    66
     
    104104
    105105                foreach ($current_posts as $current_post_id) {
    106 
    107                     $pageVariables[(int)$current_post_id] = $helper->extractPageVariables($innerAttrs);
     106                    $pageVariables[(int)$current_post_id] = $helper->extractPageVariables($innerAttrs, (int)$current_post_id);
    108107                }
    109108
     
    130129            $params = array_merge($params, $helper->getParams($attrs, 'flatten'));
    131130
    132            
    133131
    134132        } else { // If we haven't content. It means that this is usual shortcode
     133
    135134           
    136135            // Pre-create template variables, if exists
  • tea-page-content/trunk/modules/widget.php

    r1485963 r1532717  
    22/**
    33 * @package Tea Page Content
    4  * @version 1.2.1
     4 * @version 1.2.2
    55 */
    66
     
    126126
    127127                    foreach ($newInstance[$param] as $page_id => $variable_data) {
    128                        
    129                         if(trim($variable_data)) {
    130                             $parsed_data = $this->_helper->decodePageVariables($variable_data, null, false);
    131 
    132                             if(empty($parsed_data)) {
    133                                 continue;
    134                             }
    135 
     128                        if(!trim($variable_data)) { // If raw variable data is not empty...
     129                            continue;
     130                        }
     131
     132                        // try to parse it for check values of every variable...
     133                        $parsed_data = $this->_helper->decodePageVariables($variable_data, null, false);
     134
     135                        // ... and, if parsed data is not empty, save page vars
     136                        if(!empty($parsed_data)) {
    136137                            $instance['page_variables'][$page_id] = $variable_data;
     138                        } else {
     139                            // if empty, unset page vars
     140                            unset($instance['page_variables'][$page_id]);
    137141                        }
    138                        
    139142                    }
    140143                }
     
    146149
    147150    /**
    148      * Creates and render a form for
    149      * admin part of this widget
     151     * Creates and render a form for admin part of this widget
    150152     *
    151153     * @param array $instance
  • tea-page-content/trunk/readme.txt

    r1485963 r1532717  
    1 === Tea Page Widget & Content ===
     1=== Tea Page Content ===
    22Contributors: Tsjuder
    33Tags: plugin, widget, shortcode, posts, post, pages, page, content, template, templates
    44Requires at least: 4.0, PHP 5.3
    55Tested up to: 4.6
    6 Stable tag: 1.2.1
     6Stable tag: 1.2.2
    77Author URI: https://github.com/Tsjuder
    88Plugin URI: http://tsjuder.github.io/tea-page-content/
     
    2323* Easy to use and beautiful UI
    2424
    25 = Migration Guides =
    26 Stay tuned with new versions. For make updates safe and fast, check changelog at <a href="https://wordpress.org/plugins/tea-page-content/changelog/">Changelog</a> tab.
    27 
    2825If you found a bug or have a suggestion, please create topic on forum or send me email (raymondcostner at gmail.com).
    2926
     
    3734
    3835== Screenshots ==
    39 1. Widget UI. Click by gear for open page level variables modal
    40 2. Page level variables window (opens after clicking by gear)
    41 3. Insert shortcode modal window
     361. First screen with list of posts and basic parameters
     372. Second screen after choosing template and list of template variables
    4238
    4339== Frequently Asked Questions ==
     
    6359
    6460== Changelog ==
    65 
    66 = 1.2.1 =
     61= 1.2.1
    6762* \* Fix bug with non-opening modal window of page level variables
    6863
    69 = 1.2.0 =
     64= 1.2.0
    7065* \+ New feature - page-level variables
    7166* \+ Added button for inserting shortcode in editor
     
    8681* \+ New template: Bootstrap 3.x
    8782* \+ Added possibility hide title, content and link it. This feature depends of used template (all built-in templates except deprecated supports it)
    88 * \- Default-Padded template, `thumbnail` widget and shortcode parameter, `id` shortcode parameter is **deprecated**. See docs for migration guide
    89 * \* CSS for frontend part changed, improved paddings, adds hover effects
     83* \- Default-Padded template, `thumbnail` widget and shortcode parameter, `id` shortcode parameter is **deprecated**
     84* \* CSS for frontend part changed, improved paddings, added some hover effects
    9085* \* Global code refactoring. We are friendly for developers!
    9186* \* Bug fixes
     
    135130* **$count** - Count of all passed entries
    136131* **$instance** - Array with user defined and default parameters. There is all list of options from self-titled section above.
     132* **$template_variables** - Array with template-level variables.
     133* **$caller** - Special flag that determine a module that called template: from widget or from shortcode. Can be `widget` or `shortcode`.
    137134* **$entries** - List of posts, pages, etc.
    138135    * **title** - Title of current entry
     
    142139    * **id** - Entry ID
    143140
    144 = Details =
     141= Details & Filters =
    145142Because full manual is too long, you can see it at <a href="http://tsjuder.github.io/tea-page-content/">Github Page</a>. Get details and updating information about new features includes filters, template-level variables and more.
    146 
    147 = Migration Guide =
    148 **From 1.0.x to 1.1.x**
    149 Since 1.1.x, nothing was deleted. But some options was marked as deprecated. We recommend do these steps:
    150 * If you're using **default padded** template, change it on **default** with layout what you prefer.
    151 * If you're using shortcodes, replace parameter `id` to `posts`.
    152 * If you're using widgets with **turned off** thumbnail option, re-save each of it.
  • tea-page-content/trunk/tea-page-content.class.php

    r1485963 r1532717  
    22/**
    33 * @package Tea Page Content
    4  * @version 1.2.1
     4 * @version 1.2.2
    55 */
    66
     
    2828        add_action('init', array($this, 'registerShortcodes'));
    2929        add_action('widgets_init', array($this, 'registerWidgets'));
     30
     31        add_action('init', array($this, 'updateSettings'));
    3032
    3133        // Modify Admin page
     
    5153        add_action('media_buttons', array($this, 'add_my_media_button'), 1000);
    5254
    53         // At first time notice user about possible migration
    54         if(!get_option('tpc_deprecated_notice')) {
    55             add_action('admin_notices', array($this, 'displayDeprecatedNotice'));
    56         }
     55        add_action('admin_menu', array($this, 'addMenu'), 100);
     56
     57        add_filter('plugin_row_meta', array($this, 'addPluginMetaLinks'), 100, 2);
     58
    5759
    5860        // Create new helper instance
     
    6163        // Gets instance of the config class
    6264        $this->_config = TeaPageContent_Config::getInstance();
    63     }
    64 
     65
     66
     67        // At first time notice user about possible migration
     68        if
     69            (
     70                ($last_version = get_option('tpc_deprecated_notice'))
     71                &&
     72                $last_version !== $this->_config->get('system.versions.plugin')
     73            )
     74        {
     75            add_action('admin_notices', array($this, 'displayDeprecatedNotice'));
     76        }
     77    }
     78
     79    /**
     80     * Add meta-link in plugin description on plugin list page.
     81     *
     82     * @param array $links
     83     * @param string $file
     84     * @return array
     85     */
     86    public function addPluginMetaLinks($links, $file) {
     87        if($file == plugin_basename(TEA_PAGE_CONTENT_FILE)) {
     88            $links[] = '<a href="options-general.php?page=tea-page-content">' . __('Settings', 'tea-page-content') . '</a>';
     89        }
     90
     91        return $links;
     92    }
     93
     94    /**
     95     * Add button for inserting shortcode above text editor on admin pages.
     96     *
     97     * @return void
     98     */
    6599    public function add_my_media_button() {
    66100        $mask = '<a href="#" id="tpc-insert-shortcode" data-modal="tpc-call-shortcode-modal" data-button="insert" class="button tpc-button tpc-call-modal-button">%s</a>';
     
    69103
    70104    /**
     105     * Add sub-menu for Options level.
     106     *
     107     * @return void
     108     */
     109    public function addMenu() {
     110        add_submenu_page('options-general.php', __('Tea Page Content - Settings', 'tea-page-content'), __('Tea Page Content', 'tea-page-content'), 'edit_dashboard', 'tea-page-content', array($this, 'renderSettingsPage'));
     111    }
     112
     113    /**
    71114     * Register Tea Page Content widget
    72115     *
     
    96139        $url = plugins_url('/assets', TEA_PAGE_CONTENT_FILE);
    97140
    98         if($hook === 'post.php' || $hook === 'post-new.php' || $hook === 'edit.php') {
     141        if($hook === 'post.php' || $hook === 'post-new.php' || $hook === 'edit.php' || $hook === 'settings_page_tea-page-content') {
    99142           
    100143            wp_enqueue_script(
     
    150193        }
    151194
    152         if(!get_option('tpc_deprecated_notice')) {
     195        if
     196            (
     197                ($last_version = get_option('tpc_deprecated_notice'))
     198                &&
     199                $last_version !== $this->_config->get('system.versions.plugin')
     200            )
     201        {
    153202            wp_enqueue_script(
    154203                'tea-page-content-notices-js',
     
    170219        $url = plugins_url('/assets', TEA_PAGE_CONTENT_FILE);
    171220   
    172         wp_enqueue_style(
    173             'tea-page-content-css',
    174             $url . '/css/tea-page-content-main.css',
    175             array(),
    176             $this->_config->get('system.versions.styles'),
    177             'all'
    178         );
     221        if($this->_config->get_current('system.settings.include-css')) {
     222            wp_enqueue_style(
     223                'tea-page-content',
     224                $url . '/css/tea-page-content-main.css',
     225                array(),
     226                $this->_config->get('system.versions.styles'),
     227                'all'
     228            );
     229        }
    179230    }
    180231
     
    193244            $pair = explode('=', $pair);
    194245
    195             $keys = preg_split('/[\[\]]+/', urldecode($pair[0]), -1, PREG_SPLIT_NO_EMPTY);
    196 
    197246            if(!trim($pair[1])) {
    198247                continue;
    199248            }
    200249
     250            $keys = preg_split('/[\[\]]+/', urldecode($pair[0]), -1, PREG_SPLIT_NO_EMPTY);
     251           
     252            // $keys[0] is property name (order, page_variables, etc.)
     253            // $keys[1] is a page id (as usual)
     254            // So, if we haven't property in prepared data, set it up
    201255            if(!array_key_exists($keys[0], $prepared_data)) {
    202256               
    203257                if(isset($keys[1])) {
     258                    // page variables, set it
    204259                    $prepared_data[$keys[0]] = array(
    205260                        $keys[1] => $pair[1]
    206261                    );
    207262                } else {
     263                    // just post id, set it too
    208264                    $prepared_data[$keys[0]] = array(
    209265                        $pair[1]
     
    211267                }
    212268
    213             } elseif(isset($keys[1]) && array_key_exists($keys[1], $prepared_data[$keys[0]])) {
    214 
     269            // But, if we have it already and post_id is not in $prepared_data, it means, we set up page variables
     270            } elseif(isset($keys[1]) && !array_key_exists($keys[1], $prepared_data[$keys[0]])) {
     271
     272                // page variables in raw format stored in $pair array
    215273                $prepared_data[$keys[0]][$keys[1]] = $pair[1];
    216274
     275            // And finally, if we haven't property and $keys[1] isn't set...
    217276            } else {
    218277
     278                // ...it means, this is just post id that we need set separately
     279                // $pair[1] in these times can be just post_id integer
     280                // so $keys[0] now is `posts`
    219281                $prepared_data[$keys[0]][] = $pair[1];
    220 
     282               
    221283            }
    222284        }
     
    359421     */
    360422    public function setNoticeSeenCallback() {
    361         $version = $_POST['version']; // @todo get version from config
    362 
    363         if(!get_option('tpc_deprecated_notice')) {
    364             add_option('tpc_deprecated_notice', $version, '', 'no');
    365         }
     423        $this->_helper->updateDeprecatedNoticeOption();
    366424    }
    367425
     
    375433     */
    376434    public function displayDeprecatedNotice() {
    377         $message = __('Thanks for update! In Tea Page Content 1.2 was added some new features. We recommend you check out the <a href="https://wordpress.org/plugins/tea-page-content/changelog/">changelog</a>. <b>This notice appears only once!</b>');
     435        $message = __('Thanks for update! We recommend you check out the <a href="https://wordpress.org/plugins/tea-page-content/changelog/">changelog</a>. <b>This notice disappear after closing.</b>');
    378436        $content = '<div id="tpc-deprecated-notice" class="error notice tpc-deprecated-notice is-dismissible"><p>' . $message . '</p></div>';
    379437
    380438        echo $content;
     439    }
     440
     441    /**
     442     * Render settings page.
     443     *
     444     * @return void
     445     */
     446    public function renderSettingsPage() {
     447        $params = array(
     448            'settings' => $this->_helper->getMappedSettings(),
     449        );
     450
     451        $template = 'default-settings-page'; // @todo via config
     452
     453        $templatePath = $this->_helper->getTemplatePath($template);
     454
     455        echo $this->_helper->renderTemplate($params, $templatePath);
    381456    }
    382457
     
    401476    }
    402477
     478    /**
     479     * Print in footer modal window html for inserting shortcode
     480     *
     481     * @return void
     482     */
    403483    public function addInsertShortcodeModal() {
    404484        $template = 'default-widget-admin-dialog-insert-shortcode'; // @todo через конфиг
     
    435515        echo $content;
    436516    }
     517
     518    /**
     519     * Update settings if POST is not empty
     520     *
     521     * @return void
     522     */
     523    public function updateSettings() {
     524        if(!is_admin() || empty($_POST) || !isset($_POST['tpc_settings_update'])) {
     525            return;
     526        }
     527
     528        unset($_POST['tpc_settings_update']);
     529
     530        foreach ($_POST as $setting_name => $setting_value) {
     531            if
     532                (
     533                    strpos($setting_name, 'tpc_') === false // @todo make dis shit dry {4}
     534                    ||
     535                    preg_match('/[^\w-]/', $setting_name)
     536                    ||
     537                    !is_scalar($setting_value)
     538                )
     539            {
     540                continue;
     541            }
     542
     543            $config_path = $this->_helper->convertSettingToConfigPath($setting_name);
     544
     545            $initial = $this->_config->get_default($config_path);
     546
     547            if(is_null(get_option($setting_name, null))) {
     548                add_option($setting_name, $setting_value, '', 'no');
     549            } elseif($initial == $setting_value) {
     550                delete_option($setting_name);
     551            } else {
     552                update_option($setting_name, $setting_value, 'no');
     553            }
     554        }
     555    }
    437556}
  • tea-page-content/trunk/tea-page-content.php

    r1485967 r1532717  
    3131Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    3232
    33 Copyright 2015 Danil Kosterin
     33Copyright 2016 Raymond Costner
    3434*/
    3535
  • tea-page-content/trunk/templates/default-widget-admin-dialog-insert-shortcode.php

    r1485276 r1532717  
    3535                                    <input type="hidden" name="page_variables[<?php echo $postData['id'] ?>]" id="tpc-page_variables-<?php echo $postData['id'] ?>" value="" data-thumbnail-url="" autocomplete="off" />
    3636
    37                                     <span class="tpc-item-title"><?php echo $postData['title'] ?></span>
     37                                    <span class="tpc-item-title" title="<?php echo $postData['title'] ?>"><?php echo $postData['title'] ?></span>
    3838                                </label>
    3939                            <?php endforeach; ?>
  • tea-page-content/trunk/templates/default-widget-admin.php

    r1485276 r1532717  
    4141                                <input type="hidden" name="<?php echo $bind->get_field_name('page_variables') ?>[<?php echo $postData['id'] ?>]" id="<?php echo $bind->get_field_id('page_variables') . '-' . $postData['id'] ?>" value="<?php echo $raw_page_variables ?>" data-thumbnail-url="<?php echo $data_thumbnail_url ?>" autocomplete="off" />
    4242
    43                                 <span class="tpc-item-title"><?php echo $postData['title'] ?></span>
     43                                <span class="tpc-item-title" title="<?php echo $postData['title'] ?>"><?php echo $postData['title'] ?></span>
    4444                            </label>
    4545                        <?php endforeach; ?>
  • tea-page-content/trunk/uninstall.php

    r1485963 r1532717  
    22/**
    33 * @package Tea Page Content
    4  * @version 1.2.1
     4 * @version 1.2.2
    55 */
    66
     
    88    exit();
    99}
    10  
     10
     11$settings_map = include('config.map.php');
     12
     13if(is_array($settings_map) && !empty($settings_map)) {
     14    foreach ($settings_map as $setting_name => $setting_params) {
     15        $option = 'tpc_' . str_replace('.', '__', $setting_name);
     16
     17        if(!is_null(get_option($option, null))) {
     18            delete_option($option);
     19        }
     20    }
     21}
     22
    1123delete_option('tpc_deprecated_notice');
Note: See TracChangeset for help on using the changeset viewer.