Ejemplo n.º 1
0
 function truncate_at_ellipsis($content)
 {
     $end = '[...]';
     if (sustr::has($content, $end)) {
         $content = sustr::upto($content, $end);
         $content = sustr::rtrim_substr($content, $end);
     }
     return sustr::endwith($content, '[…]');
 }
 /**
  * Outputs a set of radio buttons into an admin form and saves the set's value into the database after form submission.
  * 
  * @since 1.5
  * @uses is_action()
  * @uses update_setting()
  * @uses admin_form_group_start()
  * @uses admin_form_group_end()
  * @uses su_esc_attr()
  * @uses get_setting()
  * 
  * @param string $name The name of the set of radio buttons.
  * @param array $values The keys of this array are the radio button values, and the array values are the label strings.
  * @param string|false $grouptext The text to display in a table cell to the left of the one containing the radio buttons. Optional.
  */
 function radiobuttons($name, $values, $grouptext = false)
 {
     //Save radio button setting after form submission
     if ($this->is_action('update') && isset($_POST[$name])) {
         $this->update_setting($name, $_POST[$name]);
     }
     if ($grouptext) {
         $this->admin_form_group_start($grouptext, false);
     } else {
         echo "<tr valign='top' class='su-admin-form-radio'>\n<td colspan='2'>\n";
     }
     if (is_array($values)) {
         register_setting($this->get_module_key(), $name);
         $name = su_esc_attr($name);
         $first = true;
         foreach ($values as $value => $desc) {
             $value = su_esc_attr($value);
             $id = "{$name}_{$value}";
             $current = strcmp($this->get_setting($name), $value) == 0;
             $class = $first ? 'first' : '';
             $first = false;
             if ($current) {
                 $class .= ' current-setting';
             }
             $class = trim($class);
             if ($class) {
                 $class = " class='{$class}'";
             }
             extract($this->insert_subfield_textboxes($name, $desc));
             echo "<div class='radio'><label for='{$id}'{$class}><input name='{$name}' id='{$id}' type='radio' value='{$value}'";
             if ($current) {
                 echo " checked='checked'";
             }
             echo " /> {$label}";
             if (!sustr::has($label, '</label>')) {
                 echo '</label>';
             }
             echo "</div>\n";
         }
     }
     if ($grouptext) {
         $this->admin_form_group_end(false);
     }
 }
Ejemplo n.º 3
0
 /**
  * Converts an array into a CSV file and outputs it.
  * 
  * @param array $csv The array to convert and output
  * 
  * @return bool Whether or not the conversion was successful
  */
 function print_csv($csv)
 {
     if (!is_array($csv) || !count($csv) || !is_array($csv[0])) {
         return false;
     }
     $headers = array_keys($csv[0]);
     array_unshift($csv, array_combine($headers, $headers));
     foreach ($csv as $row) {
         $csv_row = array();
         foreach ($headers as $header) {
             $csv_row[$header] = $row[$header];
             if (sustr::has($csv_row[$header], ',')) {
                 $csv_row[$header] = '"' . $csv_row[$header] . '"';
             }
         }
         echo implode(',', $csv_row) . "\r\n";
     }
     return true;
 }