• Resolved ironandsteel

    (@ironandsteel)


    My data has a couple fields that are links, and hence in my csv file, I have data in the form of:

    [display text](url of link)

    This works great except some of my records do not have a link- just plain text. So, the handling of data for link fields should be a little smarter- basically only display as a link if you have both the [] and the ().

    It would be great if you could make it so that for link fields, if there is no () or you have empty () or there is simply text not in [], it would just show the text.

    Cheers!

    http://wordpress.org/plugins/participants-database/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author xnau webdesign

    (@xnau)

    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.

    Thread Starter ironandsteel

    (@ironandsteel)

    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);
        }
      }

    Plugin Author xnau webdesign

    (@xnau)

    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);
      }
    Thread Starter ironandsteel

    (@ironandsteel)

    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘display link text even if href is empty’ is closed to new replies.