/** * Renders a select field. * * @access public * @since 0.8 * * @uses wp_parse_args() * @uses esc_attr() * @uses selected() * @uses esc_html() * * @param array $atts The field attributes. * @param string $value The selected option. * * @return string The rendered field. */ public static function select($atts, $value = '') { $defaults = array('prefix' => 'cn-', 'class' => array(), 'id' => '', 'style' => array(), 'default' => '', 'options' => array(), 'readonly' => FALSE, 'data' => array(), 'enhanced' => FALSE, 'label' => '', 'before' => '', 'after' => '', 'parts' => array('%label%', '%field%'), 'layout' => '%label%%field%', 'return' => FALSE); $atts = wp_parse_args($atts, $defaults); // If no `id` was supplied, bail. if (empty($atts['id'])) { return ''; } // The field name. $name = !empty($atts['name']) ? $atts['name'] : $atts['id']; // The field parts to be searched for in $atts['layout']. $search = $atts['parts']; // An array to store the replacement strings for the label and field. $replace = array(); // Add the 'cn-enhanced-select' class for the jQuery Chosen Plugin will enhance the drop down. if ($atts['enhanced']) { $atts['class'] = array_merge((array) $atts['class'], array('enhanced-select')); } // Prefix the `class` and `id` attribute. if (!empty($atts['prefix'])) { $atts['class'] = self::prefix($atts['class']); $atts['id'] = self::prefix($atts['id']); } // Create the field label, if supplied. $replace['label'] = !empty($atts['label']) ? self::label(array('for' => $atts['id'], 'label' => $atts['label'], 'return' => TRUE)) : ''; // Open the select. $replace['field'] = sprintf('<select %1$s %2$s %3$s %4$s %5$s %6$s %7$s>', self::attribute('class', $atts['class']), self::attribute('id', $atts['id']), self::attribute('name', $name), self::attribute('style', $atts['style']), self::attribute('data', $atts['data']), !empty($atts['default']) && $atts['enhanced'] ? ' data-placeholder="' . esc_attr($atts['default']) . '"' : '', $atts['readonly'] ? 'disabled="disabled"' : ''); // If the select is NOT a Chosen enhanced select; prepend the default option to the top of the options array. if (!empty($atts['default']) && !$atts['enhanced']) { $atts['options'] = (array) $atts['default'] + $atts['options']; } // If the select IS a Chosen enhanced select; prepend the blank option required for Chosen. if (!empty($atts['default']) && $atts['enhanced']) { $atts['options'] = array('' => '') + $atts['options']; } foreach ($atts['options'] as $key => $label) { $replace['field'] .= sprintf('<option value="%1$s" %2$s>%3$s</option>', esc_attr($key), selected($value, $key, FALSE), esc_html($label)); } // Close the select. $replace['field'] .= '</select>'; $out = str_ireplace($search, $replace, $atts['layout']); $out = cnString::replaceWhatWith($out, ' '); if ($atts['readonly']) { $out .= sprintf('<input type="hidden" name="%1$s" value="%2$s" />', esc_attr($name), esc_attr($value)); } $html = $atts['before'] . $out . $atts['after'] . PHP_EOL; return self::echoOrReturn($atts['return'], $html); }
/** * Normalize a string. Replace all occurrence of one or more spaces with a single space, remove control characters * and trim whitespace from both ends. * * @access public * @since 8.1.6 * * @param string $string The string to normalize. * * @return string */ public static function normalize($string) { return cnString::replaceWhatWith($string); }
/** * Echo or return the entry's anniversary in a HTML string. * * Accepted options for the $atts property are: * format (string) The tokens to use to display the date block parts. * Permitted Tokens: * %label% * %date% * %separator% * name_format (string) Tokens for the parts of the name. See cnOutput::getNameBlock * date_format (string) See http://php.net/manual/en/function.date.php * separator (string) The separator to use between the label and date. * before (string) HTML to output before the dates. * after (string) HTML to after before the dates. * return (bool) Return string if set to TRUE instead of echo string. * * @access public * @since 0.7.3 * * @param string $format deprecated since 0.7.3 * @param array $atts * * @return string */ public function getAnniversaryBlock($format = '', $atts = array()) { /* * // START -- Set the default attributes array. \\ */ $defaults = array(); $defaults['format'] = ''; $defaults['name_format'] = ''; // The $format option has been deprecated since 0.7.3. If it has been supplied override the $defaults['date_format] value. $defaults['date_format'] = empty($format) ? 'F jS' : $format; $defaults['separator'] = ':'; $defaults['before'] = ''; $defaults['after'] = ''; $defaults['return'] = FALSE; $atts = cnSanitize::args($atts, $defaults); /* * // END -- Set the default attributes array if not supplied. \\ */ $out = ''; $search = array('%label%', '%date%', '%separator%'); $replace = array(); if (!$this->getAnniversary()) { return ''; } /* * NOTE: The vevent span is for hCalendar compatibility. * NOTE: The second birthday span [hidden] is for hCard compatibility. * NOTE: The third span series [hidden] is for hCalendar compatibility. */ $out .= '<div class="vevent"><span class="anniversary">'; $replace[] = '<span class="date-name">' . __('Anniversary', 'connections') . '</span>'; $replace[] = '<abbr class="dtstart" title="' . $this->getAnniversary('Ymd') . '">' . date_i18n($atts['date_format'], strtotime($this->getAnniversary('Y-m-d')), FALSE) . '</abbr>'; $replace[] = '<span class="cn-separator">' . $atts['separator'] . '</span>'; $out .= str_ireplace($search, $replace, empty($atts['format']) ? '%label%%separator% %date%' : $atts['format']); $out = cnString::replaceWhatWith($out, ' '); $out .= '<span class="bday" style="display:none">' . $this->getAnniversary('Y-m-d') . '</span>'; $out .= '<span class="summary" style="display:none">' . __('Anniversary', 'connections') . ' - ' . $this->getName(array('format' => $atts['name_format'])) . '</span><span class="uid" style="display:none">' . $this->getAnniversary('YmdHis') . '</span>'; $out .= '</div>'; $out = $atts['before'] . $out . $atts['after'] . PHP_EOL; return $this->echoOrReturn($atts['return'], $out); }