Well, I try to anticipate how people will want their data processed, but in the end I just have to go with whatever seems most reasonable. I didn’t consider the possibility that there would be something other than a URL in there…perhaps it might be more flexible to allow non-URL content in that type of field. Thanks for that.
Yeah, sometimes data is inconsistent. I’ve been poking around in the code and I thought I found where to alter this behavior but it didn’t work for me. In classes/PDb_Template.class, I tried tweaking the print_with_link method, but this must not be the right place:
public function print_with_link($name, $href) {
if (empty($href)) {
$this->_print($name);
} else if (is_object($this->fields->{$name}) && !empty($href)) {
$this->_set_link($name, $href);
error_log(__METHOD__.' field:'.print_r($this->fields,1));
$this->_print($name);
}
}
That function is for a different purpose. If you want to alter it yourself, this is the code I am adding in the new release…
from participants-database.php:
/**
* parses the markdown string used to store the values for a link form element
*
* will also accept a bare URL. If the supplied string or URL does not validate
* as an URL, return the string
*
* @param string $markdown_string
* @return array URL, linktext
*/
public static function get_link_array($markdown_string)
{
if (preg_match('#^<([^>]+)>$#', trim($markdown_string), $matches)) {
return array($matches[1], '');
} elseif (preg_match('#^\[([^\]]+)\]\(([^\)]+)\)$#', trim($markdown_string), $matches)) {
$url = filter_var($matches[2], FILTER_VALIDATE_URL) ? $matches[2] : '';
return array($url, $matches[1]);
}
else
return filter_var($markdown_string, FILTER_VALIDATE_URL) ? array($markdown_string, '') : array('',$markdown_string);
}
Once I figured out that I had to replace ' with a single quote, this worked great 🙂
Thanks for the effort on this, especially on a Sunday night! I’m not the only one chained to my computer…
LK