/** * Draws the html form element * * @param array $data to pre-populate element with * @param int $repeatCounter repeat group counter * * @return string elements html */ public function render($data, $repeatCounter = 0) { $name = $this->getHTMLName($repeatCounter); $id = $this->getHTMLId($repeatCounter); $params = $this->getParams(); $bits = $this->inputProperties($repeatCounter); $value = $this->getValue($data, $repeatCounter); $opts = array(); if ($value == '') { $value = array('label' => '', 'link' => ''); } else { if (!is_array($value)) { $value = FabrikWorker::JSONtoData($value, true); /** * In some legacy case, data is like ... * [{"label":"foo","link":"bar"}] * ... I think if it came from 2.1. So lets check to see if we need * to massage that into the right format */ if (array_key_exists(0, $value) && is_object($value[0])) { $value = JArrayHelper::fromObject($value[0]); } elseif (array_key_exists(0, $value)) { $value['label'] = $value[0]; } } } if (count($value) == 0) { $value = array('label' => '', 'link' => ''); } if (FabrikWorker::getMenuOrRequestVar('rowid') == 0 && FArrayHelper::getValue($value, 'link', '') === '') { $value['link'] = $params->get('link_default_url'); } if (!$this->isEditable()) { $lbl = trim(FArrayHelper::getValue($value, 'label')); $href = trim(FArrayHelper::getValue($value, 'link')); $w = new FabrikWorker(); $href = is_array($data) ? $w->parseMessageForPlaceHolder($href, $data) : $w->parseMessageForPlaceHolder($href); $opts['target'] = trim($params->get('link_target', '')); $opts['smart_link'] = $params->get('link_smart_link', false); $opts['rel'] = $params->get('rel', ''); $title = $params->get('link_title', ''); if ($title !== '') { $opts['title'] = strip_tags($w->parseMessageForPlaceHolder($title, $data)); } return FabrikHelperHTML::a($href, $lbl, $opts); } $labelname = FabrikString::rtrimword($name, '[]') . '[label]'; $linkname = FabrikString::rtrimword($name, '[]') . '[link]'; $bits['name'] = $labelname; $bits['placeholder'] = FText::_('PLG_ELEMENT_LINK_LABEL'); $bits['value'] = $value['label']; $bits['class'] .= ' fabrikSubElement'; unset($bits['id']); $layout = $this->getLayout('form'); $layoutData = new stdClass(); $layoutData->id = $id; $layoutData->name = $name; $layoutData->linkAttributes = $bits; $bits['placeholder'] = FText::_('PLG_ELEMENT_LINK_URL'); $bits['name'] = $linkname; $bits['value'] = FArrayHelper::getValue($value, 'link'); if (is_a($bits['value'], 'stdClass')) { $bits['value'] = $bits['value']->{0}; } $layoutData->labelAttributes = $bits; return $layout->render($layoutData); }
/** * Format guess link type * * @param string &$value Original field value * @param array $data Record data * * @return void */ protected function _guessLinkType(&$value, $data) { $params = $this->getParams(); if ($params->get('guess_linktype') == '1') { $w = new FabrikWorker(); $opts = $this->linkOpts(); $title = $params->get('link_title', ''); if (FabrikWorker::isEmail($value) || JString::stristr($value, 'http')) { } elseif (JString::stristr($value, 'www.')) { $value = 'http://' . $value; } if ($title !== '') { $opts['title'] = strip_tags($w->parseMessageForPlaceHolder($title, $data)); } $label = FArrayHelper::getValue($opts, 'title', '') !== '' ? $opts['title'] : $value; $value = FabrikHelperHTML::a($value, $label, $opts); } }
/** * Format guess link type * * @param string &$value Original field value * @param array $data Record data * @param int $repeatCounter Repeat counter * * @return void */ protected function _guessLinkType(&$value, $data, $repeatCounter = 0) { $params = $this->getParams(); $guessed = false; if ($params->get('guess_linktype') == '1') { $w = new FabrikWorker(); $opts = $this->linkOpts(); $title = $params->get('link_title', ''); if (FabrikWorker::isEmail($value) || JString::stristr($value, 'http')) { $guessed = true; } elseif (JString::stristr($value, 'www.')) { $value = 'http://' . $value; $guessed = true; } if ($title !== '') { $opts['title'] = strip_tags($w->parseMessageForPlaceHolder($title, $data)); } $value = FabrikHelperHTML::a($value, $value, $opts); } }