/** * Creates a new instance of the class and adds all the options * * @param array $input * @param UTCW_Plugin $plugin * * @since 2.3 */ public function __construct(array $input, UTCW_Plugin $plugin) { $this->addOption('strategy', 'class', array('classMap' => array('popularity' => 'UTCW_PopularityStrategy', 'random' => 'UTCW_RandomStrategy', 'creation' => 'UTCW_CreationTimeStrategy', 'current_list' => 'UTCW_CurrentListStrategy'), 'baseClass' => 'UTCW_SelectionStrategy', 'default' => 'popularity', 'factory' => array($this, 'strategyFactory'))); $this->addOption('order', 'set', array('values' => array('name', 'random', 'slug', 'id', 'color', 'count'))); $this->addOption('tags_list_type', 'set', array('values' => array('exclude', 'include'))); $this->addOption('color', 'set', array('values' => array('none', 'random', 'set', 'span'))); $this->addOption('color_span_to', 'color', array('default' => '')); $this->addOption('color_span_from', 'color', array('default' => '')); $this->addOption('color_set', 'array', array('type' => 'color')); $this->addOption('taxonomy', 'array', array('type' => 'set', 'typeOptions' => array('values' => $plugin->getAllowedTaxonomies()), 'default' => array('post_tag'))); $this->addOption('post_type', 'array', array('type' => 'set', 'typeOptions' => array('values' => $plugin->getAllowedPostTypes()), 'default' => array('post'))); $this->addOption('authors', 'array', array('type' => 'integer')); $this->addOption('tags_list', 'array', array('type' => 'integer')); $this->addOption('post_term', 'array', array('type' => 'integer')); $this->addOption('size_from', 'measurement', array('default' => '10px')); $this->addOption('size_to', 'measurement', array('default' => '30px')); $this->addOption('max', 'integer', array('default' => 45, 'min' => 1)); $this->addOption('minimum', 'integer', array('default' => 1)); $this->addOption('days_old', 'integer'); $this->addOption('reverse', 'boolean'); $this->addOption('case_sensitive', 'boolean'); $this->addOption('post_term_query_var', 'boolean'); $this->plugin = $plugin; parent::__construct($input, $plugin); $this->checkSizes(); }
/** * Creates a new instance of the QueryBuilder * * @param UTCW_Plugin $plugin Main plugin instance * * @since 2.2 */ public function __construct(UTCW_Plugin $plugin) { $this->db = $plugin->get('wpdb'); $this->plugin = $plugin; $this->query = $this->getBaseQuery(); $this->parameters = array(); }
function test_function_and_shortcode_is_equal() { $utcw = UTCW_Plugin::getInstance(); $shortCode = new UTCW_ShortCode($utcw); $this->expectOutputString($shortCode->render(array())); do_utcw(array()); }
/** * Cleans up sensitive data before being used in debug output */ public function cleanupForDebug() { unset($this->db); $this->plugin->remove('wpdb'); $this->plugin->remove('data'); $this->config->strategy->cleanupForDebug(); }
/** * Will add the style to the internal array if the option doesn't have is default value * * @param string $option * @param string $template * @param string $value * * @since 2.6 */ protected function addStyle($option, $template, $value = '') { if (!$value) { $value = $this->plugin->get('renderConfig')->{$option}; } if (!$this->hasDefaultValue($option)) { $this->styles[] = sprintf($template, $value); } }
/** * Function for rendering the widget * * @param array $args * * @param array $instance */ public function widget($args, $instance) { global $wpdb; $input = array_merge($instance, $args); $this->plugin->set('wpdb', $wpdb); $this->plugin->set('dataConfig', new UTCW_DataConfig($input, $this->plugin)); $this->plugin->set('renderConfig', new UTCW_RenderConfig($input, $this->plugin)); $this->plugin->set('data', new UTCW_Data($this->plugin)); $render = new UTCW_Render($this->plugin); $render->render(); }
/** * Creates a new term * * @param stdClass $input Object with properties term_id, count, slug, name, color and taxonomy * @param UTCW_Plugin $plugin Reference to the plugin instance * * @since 2.0 */ public function __construct(stdClass $input, UTCW_Plugin $plugin) { $this->setInteger($input, 'term_id'); $this->setInteger($input, 'count'); $this->setSlug($input, 'slug'); $this->setString($input, 'name'); $this->setString($input, 'taxonomy'); $this->setColor($input, 'color'); if ($this->term_id && $this->taxonomy) { $this->link = $plugin->getTermLink($this->term_id, $this->taxonomy); } }
/** * Short code handler for 'utcw' hook * * @param array $args * * @return string * @since 2.4 */ public function render(array $args) { global $wpdb; if (isset($args['load_config'])) { $loaded = $this->plugin->loadConfiguration($args['load_config']); if (is_array($loaded)) { $args = $loaded; } } $this->plugin->set('wpdb', $wpdb); $this->plugin->set('dataConfig', new UTCW_DataConfig($args, $this->plugin)); $this->plugin->set('renderConfig', new UTCW_RenderConfig($args, $this->plugin)); $this->plugin->set('data', new UTCW_Data($this->plugin)); $render = new UTCW_Render($this->plugin); do_action('utcw_shortcode', $args); return apply_filters('filter_shortcode', $render->getCloud()); }
/** * Returns the title attribute for the given term * * @param UTCW_Term $term * * @return string * @since 2.4 */ private function getTitle(UTCW_Term $term) { $title = ''; switch ($this->config->title_type) { case 'counter': $term_title_singular = $this->plugin->applyFilters('utcw_render_term_title_singular', '%d topic'); $term_title_plural = $this->plugin->applyFilters('utcw_render_term_title_plural', '%d topics'); $title = _n($term_title_singular, $term_title_plural, $term->count, 'utcw'); if (strpos($title, '%d') !== false) { $title = sprintf(' title="' . $title . '"', $term->count); } break; case 'name': $title = sprintf(' title="%s"', $term->name); break; case 'custom': $template = $this->config->title_custom_template; $stringPosition = strpos($template, '%s'); $numberPosition = strpos($template, '%d'); $containsString = $stringPosition !== false; $containsNumber = $numberPosition !== false; $stringFirst = $stringPosition < $numberPosition; if ($containsString && $containsNumber && $stringFirst) { $title = sprintf(' title="' . $template . '"', $term->name, $term->count); } elseif ($containsString && $containsNumber) { $title = sprintf(' title="' . $template . '"', $term->count, $term->name); } elseif ($containsString) { $title = sprintf(' title="' . $template . '"', $term->name); } elseif ($containsNumber) { $title = sprintf(' title="' . $template . '"', $term->count); } else { $title = sprintf(' title="%s"', $template); } break; } return $title; }
function test_plugin_singleton() { $utcw = UTCW_Plugin::getInstance(); $this->assertTrue($utcw instanceof UTCW_Plugin); }
} break; case 'Integer': return 10; case 'Measurement': return '"10px"'; case 'Boolean': return $option->getDefaultValue() ? 0 : 1; case 'String': return '"foo"'; case 'Class': return 'ClassName'; default: die('Unknown type: ' . $type); } } public function getDocumentation() { $documentation = []; foreach ($this->configurationObjects as $configurationObject) { $documentation = array_merge($documentation, $this->getDocumentationForConfig($configurationObject)); } $result = join("\n", $documentation); $result .= "\n"; $result .= '*Configuration options auto generated at ' . date('Y-m-d H:i:s') . ' for version ' . $this->version . '*'; return $result; } } $objects = [new UTCW_DataConfig(array(), UTCW_Plugin::getInstance()), new UTCW_RenderConfig(array(), UTCW_Plugin::getInstance())]; $generator = new DocumentationGenerator($objects, UTCW_VERSION); echo $generator->getDocumentation();
function setUp() { $this->plugin = UTCW_Plugin::getInstance(); $this->shortCode = new UTCW_ShortCode($this->plugin); }
/** * Clean up the internal members for debug output * * @return void */ public function cleanupForDebug() { $this->plugin->remove('wpdb'); }
/** * Returns an instance of the plugin * * @static * @return UTCW_Plugin * @since 2.0 */ public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * Function for theme integration * * @param array $args * * @since 1.3 */ function do_utcw(array $args) { $plugin = UTCW_Plugin::getInstance(); $shortCode = new UTCW_ShortCode($plugin); echo $shortCode->render($args); }