Exemplo n.º 1
0
 /**
  * Apply configuration.
  */
 protected function configure($config = null)
 {
     // gurantee configuration
     $config !== null or $config = array();
     // invoke htmltag instance configuration
     if (isset($config['attrs'])) {
         parent::configure($config['attrs']);
         unset($config['attrs']);
     } else {
         // no html attributes set
         parent::configure(array());
     }
     // setup meta fields
     $this->meta = pixreviews::instance('PixReviewsMeta', $config);
 }
Exemplo n.º 2
0
 /**
  * @return string attributes
  */
 function htmlattributes(array $extra = array())
 {
     $attr_segments = array();
     $attributes = pixreviews::merge($this->attrs->metadata_array(), $extra);
     foreach ($attributes as $key => $value) {
         if ($value !== false && $value !== null) {
             if (!empty($value)) {
                 if (is_array($value)) {
                     $htmlvalue = implode(' ', $value);
                     $attr_segments[] = "{$key}=\"{$htmlvalue}\"";
                 } else {
                     // value is not an array
                     $attr_segments[] = "{$key}=\"{$value}\"";
                 }
             } else {
                 // empty html tag; ie. no value html tag
                 $attr_segments[] = $key;
             }
         }
     }
     return implode(' ', $attr_segments);
 }
Exemplo n.º 3
0
        _e('Please check the fields for errors and typos.', 'comments-ratings');
        ?>
			</p>
		<?php 
    }
    if ($processor->performed_update()) {
        ?>
			<br/>
			<p class="update-nag">
				<?php 
        _e('Settings have been updated.', 'comments-ratings');
        ?>
			</p>
		<?php 
    }
    echo $f = pixreviews::form($config, $processor);
    echo $f->field('hiddens')->render();
    echo $f->field('labels')->render();
    echo $f->field('general')->render();
    ?>
		<button type="submit" class="button button-primary">
			<?php 
    _e('Save Changes', 'comments-ratings');
    ?>
		</button>

		<?php 
    echo $f->endform();
} elseif ($status['state'] == 'error') {
    ?>
Exemplo n.º 4
0
 /**
  * Execute postupdate hooks on input.
  */
 protected function postupdate($input)
 {
     $defaults = pixreviews::defaults();
     $plugin_hooks = $this->meta->get('processor', array('preupdate' => array(), 'postupdate' => array()));
     // Calculate hooks
     // ---------------
     $hooks = array();
     // check pixreviews defaults
     if (isset($defaults['processor']['postupdate'])) {
         $hooks = $defaults['processor']['postupdate'];
     }
     // check plugin defaults
     if (isset($plugin_hooks['postupdate'])) {
         $hooks = array_merge($hooks, $plugin_hooks['postupdate']);
     }
     // Execute hooks
     // -------------
     foreach ($hooks as $rule) {
         $callback = pixreviews::callback($rule, $this->meta);
         call_user_func($callback, $input, $this);
     }
 }
$config = (include 'plugin-config' . EXT);
// set textdomain
load_plugin_textdomain('comments-ratings', false, basename(dirname(__FILE__)) . '/languages/');
// Ensure Test Data
// ----------------
$defaults = (include 'plugin-defaults' . EXT);
$current_data = get_option($config['settings-key']);
if ($current_data === false) {
    add_option($config['settings-key'], $defaults);
} else {
    if (count(array_diff_key($defaults, $current_data)) != 0) {
        $plugindata = array_merge($defaults, $current_data);
        update_option($config['settings-key'], $plugindata);
    }
}
# else: data is available; do nothing
// Load Callbacks
// --------------
$basepath = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$callbackpath = $basepath . 'callbacks' . DIRECTORY_SEPARATOR;
pixreviews::require_all($callbackpath);
require_once plugin_dir_path(__FILE__) . 'class-pixreviews.php';
// Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively.
register_activation_hook(__FILE__, array('PixReviewsPlugin', 'activate'));
//register_deactivation_hook( __FILE__, array( 'pixreviewsPlugin', 'deactivate' ) );
function pixreviews_init_plugin()
{
    global $pixreviews_plugin;
    $pixreviews_plugin = PixReviewsPlugin::get_instance();
}
add_action('after_setup_theme', 'pixreviews_init_plugin');
Exemplo n.º 6
0
 /**
  * @param string rule
  * @return string error message
  */
 function error_message($rule)
 {
     if (self::$error_message_cache === null) {
         $defaults = pixreviews::defaults();
         $default_errors = $defaults['errors'];
         $plugin_errors = $this->meta->get('errors', array());
         self::$error_message_cache = array_merge($default_errors, $plugin_errors);
     }
     return self::$error_message_cache[$rule];
 }
Exemplo n.º 7
0
 /**
  * Sets a custom text domain; if null is passed the text domain will revert
  * to the default text domain.
  */
 static function settextdomain($textdomain)
 {
     if (!empty($textdomain)) {
         self::$textdomain = $textdomain;
     } else {
         // null or otherwise empty value
         // revert to default
         self::$textdomain = 'comments-ratings';
     }
 }
Exemplo n.º 8
0
 /**
  * @param string template path
  * @param array  configuration
  * @return string
  */
 function fieldtemplate($templatepath, $conf = array())
 {
     $config = pixreviews::instance('PixReviewsMeta', $conf);
     return $this->fieldtemplate_render($templatepath, $config);
 }
Exemplo n.º 9
0
<?php

return array('cleanup' => array('switch' => array('switch_not_available')), 'checks' => array('counter' => array('is_numeric', 'not_empty')), 'processor' => array('preupdate' => array(), 'postupdate' => array()), 'errors' => array('is_numeric' => esc_html__('Numeric value required.', pixreviews::textdomain()), 'not_empty' => esc_html__('Field is required.', pixreviews::textdomain())), 'callbacks' => array('switch_not_available' => 'pixreviews_cleanup_switch_not_available', 'is_numeric' => 'pixreviews_validate_is_numeric', 'not_empty' => 'pixreviews_validate_not_empty'));
# config