/**
 		@brief		Test the current_url function with a whole combination of weird settings.
 		@since		2014-01-14 16:04:40
 	**/
 public function test_current_url()
 {
     // Test a normal URL.
     $SERVER = ['HTTP_HOST' => 'subdomain.domain.com', 'REQUEST_URI' => '/index.php', 'SERVER_PORT' => 80];
     $result = \plainview\sdk_broadcast\base::current_url($SERVER);
     $this->assertEquals($result, 'http://subdomain.domain.com/index.php');
     // With a different port.
     $SERVER['SERVER_PORT'] = 82;
     $result = \plainview\sdk_broadcast\base::current_url($SERVER);
     $this->assertEquals($result, 'http://subdomain.domain.com:82/index.php');
     // HTTPS
     $SERVER['SERVER_PORT'] = 443;
     $SERVER['HTTPS'] = 'on';
     $result = \plainview\sdk_broadcast\base::current_url($SERVER);
     $this->assertEquals($result, 'https://subdomain.domain.com/index.php');
     // HTTPS on a weird port.
     $SERVER['SERVER_PORT'] = 444;
     $result = \plainview\sdk_broadcast\base::current_url($SERVER);
     $this->assertEquals($result, 'https://subdomain.domain.com:444/index.php');
     // Normal HTTP with HTTPS set to off (thanks Microsoft IIS!)
     $SERVER['SERVER_PORT'] = 80;
     $SERVER['HTTPS'] = 'off';
     $result = \plainview\sdk_broadcast\base::current_url($SERVER);
     $this->assertEquals($result, 'http://subdomain.domain.com/index.php');
     // HTTPS on port 80
     $SERVER['HTTPS'] = 'on';
     $result = \plainview\sdk_broadcast\base::current_url($SERVER);
     $this->assertEquals($result, 'https://subdomain.domain.com:80/index.php');
 }
Exemple #2
0
 /**
 		@brief		Displays an array of inputs using Wordpress table formatting.
 		@param		array		$o	Array of options.
 		@since		20130416
 	**/
 public function display_form_table($o = array())
 {
     $o = \plainview\sdk_broadcast\base::merge_objects(array('base' => $this->base, 'header' => '', 'header_level' => 'h3', 'r' => ''), $o);
     $r = '';
     $o->inputs = $this->inputs;
     $this->display_form_table_inputs($o);
     return $o->r;
 }
Exemple #3
0
 public function __construct($row, $id = null)
 {
     if ($id !== null) {
         $this->id = $id;
         $this->attribute('id')->set($this->id);
     } else {
         $this->id = \plainview\sdk_broadcast\base::uuid();
     }
     $this->row = $row;
 }
Exemple #4
0
 public function __construct($section, $id = null)
 {
     if ($id !== null) {
         $this->attribute('id')->set($id);
         $this->id = $id;
     } else {
         $this->id = \plainview\sdk_broadcast\base::uuid();
     }
     $this->cells = array();
     $this->section = $section;
 }
Exemple #5
0
 public function validate_email()
 {
     $value = $this->get_post_value();
     // Check the email address only if (1) it is required or (2) there is something there.
     if ($value == '' && !$this->is_required()) {
         return;
     }
     if (!\plainview\sdk_broadcast\base::is_email($value)) {
         $text = $this->form()->_('The e-mail address in %s is not valid!', '<em>' . $this->get_label()->content . '</em>');
         $this->validation_error()->set_unfiltered_label_($text);
     }
 }
Exemple #6
0
 /**
 		@brief		Construct the class.
 		@param		string		$filename		The __FILE__ special variable of the parent.
 		@since		20130416
 	**/
 public function __construct($__FILE__ = null)
 {
     // If no filename was specified, try to get the parent's filename.
     if ($__FILE__ === null) {
         $stacktrace = @debug_backtrace(false);
         $__FILE__ = $stacktrace[0]['file'];
     }
     if (!defined('ABSPATH')) {
         // Was this run from the command line?
         if (isset($_SERVER['argc'])) {
             $this->paths = array('__FILE__' => $__FILE__, 'name' => get_class($this), 'filename' => basename($__FILE__));
             $this->do_cli();
         } else {
             wp_die('ABSPATH is not defined!');
         }
     }
     parent::__construct();
     global $wpdb;
     $this->wpdb = $wpdb;
     $this->is_network = MULTISITE;
     $this->is_multisite = MULTISITE;
     $this->submenu_pages = new \plainview\sdk_broadcast\collections\collection();
     // Completely different path handling for Windows and then everything else. *sigh*
     if (PHP_OS == 'WINNT') {
         $wp_plugin_dir = str_replace('/', DIRECTORY_SEPARATOR, WP_PLUGIN_DIR);
         $base_dir = dirname(dirname(WP_PLUGIN_DIR));
         $path_from_plugin_directory = dirname(str_replace($wp_plugin_dir, '', $__FILE__));
         $__FILE___from_plugin_directory = $path_from_plugin_directory . DIRECTORY_SEPARATOR . basename($__FILE__);
         $this->paths = array('__FILE__' => $__FILE__, 'name' => get_class($this), 'filename' => basename($__FILE__), 'filename_from_plugin_directory' => $__FILE___from_plugin_directory, 'path_from_plugin_directory' => $path_from_plugin_directory, 'path_from_base_directory' => str_replace($base_dir, '', $wp_plugin_dir) . $path_from_plugin_directory, 'url' => plugins_url() . str_replace(DIRECTORY_SEPARATOR, '/', $path_from_plugin_directory));
     } else {
         // Everything else except Windows.
         $this->paths = array('__FILE__' => $__FILE__, 'name' => get_class($this), 'filename' => basename($__FILE__), 'filename_from_plugin_directory' => str_replace(WP_PLUGIN_DIR, '', $__FILE__), 'path_from_plugin_directory' => str_replace(WP_PLUGIN_DIR, '', dirname($__FILE__)), 'path_from_base_directory' => dirname(str_replace(ABSPATH, '', $__FILE__)), 'url' => plugins_url() . str_replace(WP_PLUGIN_DIR, '', dirname($__FILE__)));
     }
     register_activation_hook($this->paths('filename_from_plugin_directory'), array($this, 'activate_internal'));
     register_deactivation_hook($this->paths('filename_from_plugin_directory'), array($this, 'deactivate_internal'));
     $this->_construct();
 }
Exemple #7
0
 /**
 		@brief		Output the unix time as a human-readable string.
 		@details
 
 		In order to aid in translation, use the various text_* keys in the options array.
 
 		See the source below for a list of keys to include.
 
 		@param		int			$current		Current timestamp.
 		@param		int			$reference		Reference timestamp, if not now.
 		@param		array		$options		Options.
 		@since		20130809
 	**/
 public static function human_time($current, $reference = null, $options = [])
 {
     $options = \plainview\sdk_broadcast\base::merge_objects(['time' => date('U'), 'text_day' => '1 day', 'text_days' => '%d days', 'text_hour' => '1 hour', 'text_hours' => '%d hours', 'text_minute' => '1 minute', 'text_minutes' => '%d minutes', 'text_second' => '1 second', 'text_seconds' => '%d seconds'], $options);
     if ($reference === null) {
         $reference = $options->time;
     }
     if (!is_int($current)) {
         $current = strtotime($current);
     }
     $difference = abs($reference - $current);
     $seconds = round($difference, 0);
     $minutes = round($difference / 60, 0);
     $hours = round($difference / (60 * 60), 0);
     $days = round($difference / (60 * 60 * 24), 0);
     if ($days > 0) {
         if ($days == 1) {
             return $options->text_day;
         } else {
             return sprintf($options->text_days, $days);
         }
     }
     if ($hours > 0) {
         if ($hours == 1) {
             return $options->text_hour;
         } else {
             return sprintf($options->text_hours, $hours);
         }
     }
     if ($minutes > 0) {
         if ($minutes == 1) {
             return $options->text_minute;
         } else {
             return sprintf($options->text_minutes, $minutes);
         }
     }
     if ($seconds == 1) {
         return $options->text_second;
     } else {
         return sprintf($options->text_seconds, $seconds);
     }
 }
 /**
 		@brief		Convenience method to p the markup before setting it.
 		@param		string		$markup
 		@return		this		Object chaining.
 		@since		20130524
 	**/
 public function p($markup)
 {
     return $this->markup(\plainview\sdk_broadcast\base::wpautop($markup));
 }
Exemple #9
0
 public function __construct()
 {
     // Add the standard input types.
     $input_types = array('button', 'checkbox', 'checkboxes', 'datalist', 'date', 'datetime', 'datetimelocal', 'email', 'fieldset', 'file', 'hidden', 'markup', 'meter', 'month', 'number', 'password', 'radio', 'radios', 'range', 'search', 'select', 'submit', 'tel', 'time', 'text', 'textarea', 'url', 'week');
     foreach ($input_types as $input_type) {
         $o = new \stdClass();
         $o->name = $input_type;
         $o->class = '\\plainview\\sdk_broadcast\\form2\\inputs\\' . $input_type;
         $this->register_input_type($o);
     }
     // action may not be empty
     $this->set_attribute('action', \plainview\sdk_broadcast\base::current_url());
     // default method is post
     $this->set_attribute('method', 'post');
 }
Exemple #10
0
 /**
 		@brief		Converts all of the items to a string.
 		@since		2014-05-04 13:09:23
 	**/
 public function __toString()
 {
     $r = implode("\n", $this->items);
     $r = \plainview\sdk_broadcast\base::wpautop($r);
     return $r;
 }
Exemple #11
0
 /**
 		@brief		Make a unique ID for this input.
 		@return		string		A unique string fit for use as the HTML ID attribute.
 		@since		20130524
 	**/
 public function make_id()
 {
     if ($this->has_attribute('id')) {
         return $this->get_attribute('id');
     }
     $id = $this->make_name();
     $id = \plainview\sdk_broadcast\base::strtolower($id);
     $id = preg_replace('/[\\[|\\]]/', '_', $id);
     return $id;
 }
 /**
 		@brief		Renders the complete pagination HTML string.
 		@return		string		The rendered pagination HTML.
 		@see		prerender()
 		@since		20130718
 	**/
 public function render()
 {
     $this->prerender();
     $this->page = base::minmax($this->page, 1, $this->pages);
     $this->render_output = $this->open_tag();
     $this->render_output .= $this->render_pages();
     $this->render_output .= $this->close_tag();
     return $this->render_output;
 }