/** * Makes links to other DB pages. */ public static function replace_double_square_brackets_with_link_to_db_page($in) { #echo "\$in: \n\n$in\n"; #$out = $in; #$out = ''; # #$lines = Strings_Splitter::line_separated($in); # #foreach ($lines as $line) { # if ($line) # # $out .= "$line\n"; #} # #return $out; /* * Split the string on all the square bracket links. */ $parts = preg_split('/(?:(?<!\\\\)|(?<=\\\\\\\\))(\\[\\[[-\\w]+(?:\\|[- \\w\'".\\/]+)?\\]\\])/', $in, -1, PREG_SPLIT_DELIM_CAPTURE); #echo "\nParts: \n\n"; # #print_r($parts); /* * Make the appropriate stings into links. */ $out = ''; foreach ($parts as $part) { if (preg_match('/^\\[\\[([-\\w]+)(?:\\|([- \\w\'".\\/]+))?\\]\\]$/', $part, $matches)) { #print_r($matches); $page_name = $matches[1]; if (isset($matches[2])) { $title = $matches[2]; } else { $title = Formatting_ListOfWordsHelper::capitalise_delimited_string($page_name, '-'); } $page_url = DPPages_URLsHelper::get_db_page_url($page_name); #$out .= "<a href=\"/db-pages/$page_name.html\">$title</a>"; $out .= '<a href="' . $page_url->get_as_string() . "\">{$title}</a>"; } else { #echo "\$part: $part\n"; /* * Remove any back slashes that were used to escape any * brackets. */ $part = preg_replace('/(?<!\\\\)\\\\(?=\\[\\[)/', '', $part); $out .= $part; } } #echo "$out\n"; return $out; }
public function get_managed_object_name_plural() { $table_name = $this->get_table_name(); #echo $table_name; if (preg_match('/^(?:ps_|hpi_|hci_)(\\w+)/', $table_name, $matches)) { #echo "Match\n"; # #print_r($matches); $table_name = $matches[1]; } else { echo "No match!\n"; } $c = Formatting_ListOfWordsHelper::capitalise_delimited_string($table_name, '_'); #echo $c; #exit; return $c; }
protected function render_form_li_textarea($name, $value = NULL, $title = NULL, $cols = 50, $rows = 20) { #echo $value; exit; if (!isset($title)) { $title = Formatting_ListOfWordsHelper::capitalise_delimited_string($name, '_'); } ?> <li> <label for="page"><?php echo $title; ?> </label> <textarea name="<?php echo $name; ?> " id="<?php echo $name; ?> " cols="<?php echo $cols; ?> " rows="<?php echo $rows; ?> " ><?php if (isset($value)) { $value = stripcslashes($value); echo $value; } ?> </textarea> <span id="<?php echo $name; ?> msg" class="rules" ></span> </li> <?php }
public function get_display_field_titles() { $display_field_titles = array(); foreach ($this->get_display_fields() as $df) { if (isset($df['title'])) { $display_field_titles[] = $df['title']; } else { $display_field_titles[] = Formatting_ListOfWordsHelper::capitalise_delimited_string($df['name'], '_'); } } return $display_field_titles; }
/** * Renders an array of assocs in a table. * * @param array $array_of_assocs The array of assocs to render. * @param array $title_overrides Optional assoc of titles to override the default capitalisation. */ public static function render_array_of_assocs_in_table($array_of_assocs, $title_overrides = NULL) { if (count($array_of_assocs) > 0) { /* * Make the titles. */ $titles = array(); foreach (array_keys($array_of_assocs[0]) as $key) { $titles[$key] = Formatting_ListOfWordsHelper::capitalise_delimited_string($key, '_'); } /* * Has the user overridden one of the titles? */ if (isset($title_overrides)) { foreach (array_keys($title_overrides) as $key) { $titles[$key] = $title_overrides[$key]; } } /* * Make the columns the correct width. */ $column_widths = array(); foreach (array_keys($titles) as $key) { $column_widths[$key] = strlen($titles[$key]); foreach ($array_of_assocs as $assoc) { $field_width = strlen($assoc[$key]); $column_widths[$key] = $column_widths[$key] > $field_width ? $column_widths[$key] : $field_width; } } /* * Put the titles together. */ $title_str = '|'; foreach (array_keys($titles) as $key) { $title_str .= str_pad($titles[$key], $column_widths[$key], ' ', STR_PAD_BOTH); $title_str .= '|'; } /* * Make a horizontal rule to separate the titles from the data. */ $hr = str_repeat('-', strlen($title_str) - 2); $title_str = $title_str . PHP_EOL; #$hr = "|$hr|" . PHP_EOL; $hr = "+{$hr}+" . PHP_EOL; echo $hr; echo $title_str; echo $hr; /* * Render the data. */ foreach ($array_of_assocs as $assoc) { echo '|'; foreach (array_keys($assoc) as $key) { echo str_pad($assoc[$key], $column_widths[$key], ' ', STR_PAD_BOTH); echo '|'; } echo PHP_EOL; } echo $hr; } }
protected function get_form_li_text_input($name, $value = NULL, $title = NULL) { if (!isset($title)) { $title = Formatting_ListOfWordsHelper::capitalise_delimited_string($name, '_'); } $html = <<<HTML <li> \t<label for="{$name}">{$title}</label> \t<input \t\ttype="text" \t\tname="{$name}" \t\tid="{$name}" HTML; if (isset($value)) { $html .= "value=\"{$value}\""; } $html .= <<<HTML \t/> </li> HTML; return $html; }