Permalink
Browse files

[#24820] Infinite links in com_contacts.

  • Loading branch information...
jonnsl committed Nov 13, 2011
1 parent 1d558b7 commit a10686becd61fffcb3b66afa97e8d3d9a740e3cb
@@ -220,7 +220,7 @@
<field name="show_links"
label="COM_CONTACT_FIELD_SHOW_LINKS_LABEL"
- description="COM_CONTACT_FIELD_SHOW_LINKS_LABEL"
+ description="COM_CONTACT_FIELD_SHOW_LINKS_DESC"
type="radio"
default="1"
>
@@ -229,41 +229,6 @@
</field>
- <field name="linka_name"
- type="text"
- label="COM_CONTACT_FIELD_LINKA_NAME_LABEL"
- description="COM_CONTACT_FIELD_LINK_NAME_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linkb_name"
- type="text"
- label="COM_CONTACT_FIELD_LINKB_NAME_LABEL"
- description="COM_CONTACT_FIELD_LINK_NAME_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linkc_name" type="text"
- label="COM_CONTACT_FIELD_LINKC_NAME_LABEL" description="COM_CONTACT_FIELD_LINK_NAME_DESC"
- class="inputbox" size="30" />
-
- <field name="linkd_name"
- type="text"
- label="COM_CONTACT_FIELD_LINKD_NAME_LABEL"
- description="COM_CONTACT_FIELD_LINK_NAME_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linke_name"
- type="text"
- label="COM_CONTACT_FIELD_LINKE_NAME_LABEL"
- description="COM_CONTACT_FIELD_LINK_NAME_DESC"
- class="inputbox" size="30"
- />
-
</fieldset>
<fieldset name="Icons"
label="COM_CONTACT_ICONS_SETTINGS"
@@ -126,9 +126,12 @@ public function getItem($pk = null)
{
if ($item = parent::getItem($pk)) {
// Convert the params field to an array.
- $registry = new JRegistry;
- $registry->loadString($item->metadata);
+ $registry = new JRegistry($item->metadata);
$item->metadata = $registry->toArray();
+
+ // Convert the links field to an object.
+ $registry = new JRegistry($item->links);
+ $item->links = $registry->toArray();
}
return $item;
@@ -0,0 +1,81 @@
+<?php
+/**
+ * @version $Id$
+ * @package Joomla.Administrator
+ * @subpackage com_contact
+ * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+defined('JPATH_BASE') or die;
+
+jimport('joomla.form.formfield');
+
+/**
+ *
+ *
+ * @package Joomla.Administrator
+ * @subpackage com_contact
+ * @since 1.6
+ */
+class JFormFieldLinks extends JFormField
+{
+ /**
+ * The form field type.
+ *
+ * @var string
+ */
+ protected $type = 'Links';
+
+ /**
+ * Method to get the field input markup.
+ *
+ * @return string
+ */
+ protected function getInput()
+ {
+ $links = (array) $this->value;
+ // Show at least one empty link
+ if(empty($links)) $links = array(array('label'=>'','url'=>''));
+
+ $labelLabel = JText::_('COM_CONTACT_FIELD_LINKS_LABEL_LABEL');
+ $labelTip = $labelLabel.'::'.JText::_('COM_CONTACT_FIELD_LINKS_LABEL_DESC');
+
+ $urlLabel = JText::_('COM_CONTACT_FIELD_LINKS_URL_LABEL');
+ $urlTip = $urlLabel.'::'.JText::_('COM_CONTACT_FIELD_LINKS_URL_DESC');
+
+ // Add Javascript
+ JHtml::_('script', 'contacts/links.js', false, true);
+ // Load the javascript language strings
+ JText::script('COM_CONTACT_FIELD_LINKS_LEGEND');
+ JText::script('COM_CONTACT_FIELD_LINKS_LABEL_LABEL');
+ JText::script('COM_CONTACT_FIELD_LINKS_LABEL_DESC');
+ JText::script('COM_CONTACT_FIELD_LINKS_URL_LABEL');
+ JText::script('COM_CONTACT_FIELD_LINKS_URL_DESC');
+ JText::script('COM_CONTACT_FIELD_LINKS_REMOVE_LINK');
+ ?>
+ <script type="text/javascript">
+ window.addEvent('domready', function() {
+ new Links('<?php echo $this->name; ?>', document.id('links'), document.id('add-link'));
+ });
+ </script>
+ <button type="button" id="add-link"><?php echo JText::_('COM_CONTACT_FIELD_LINKS_ADD_LINK'); ?></button>
+ <div style="clear:both;"></div>
+ <div id="links">
+ <?php foreach ($links as $i => $link) : ?>
+ <fieldset class="adminForm contact-link">
+ <legend><?php echo JText::sprintf('COM_CONTACT_FIELD_LINKS_LEGEND', $i+1); ?></legend>
+ <label for="label" class="hasTip" title="<?php echo $labelTip;?>" ><?php echo $labelLabel; ?></label>
+ <input type="text" name="<?php echo $this->name.'['.$i.'][label]'; ?>" value="<?php echo $link['label']; ?>" />
+ <label for="url" class="hasTip" title="<?php echo $urlTip;?>" ><?php echo $urlLabel; ?></label>
+ <input type="text" name="<?php echo $this->name.'['.$i.'][url]'; ?>" value="<?php echo $link['url']; ?>" />
+ <button type="button" class="remove-link"><?php echo JText::_('COM_CONTACT_FIELD_LINKS_REMOVE_LINK'); ?></button>
+ </fieldset>
+ <?php endforeach; ?>
+ </div>
+
+ <?php
+
+ return '';
+ }
+}
@@ -169,6 +169,12 @@
size="30"
/>
+ <field name="links" type="links"
+ label="COM_CONTACT_FIELD_LINKS_LABEL"
+ description="COM_CONTACT_FIELD_LINKS_DESC"
+ class="inputbox"
+ filter="ContactHelper::filterLinks"/>
+
<field name="misc" type="editor"
label="COM_CONTACT_FIELD_INFORMATION_MISC_LABEL"
description="COM_CONTACT_FIELD_INFORMATION_MISC_DESC"
@@ -524,81 +530,6 @@
<option value="1">JSHOW</option>
</field>
- <field name="linka_name" type="text"
- label="COM_CONTACT_FIELD_LINKA_NAME_LABEL"
- description="COM_CONTACT_FIELD_LINK_NAME_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linka" type="text"
- label="COM_CONTACT_FIELD_LINKA_LABEL"
- description="COM_CONTACT_FIELD_LINKA_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linkb_name" type="text"
- label="COM_CONTACT_FIELD_LINKB_NAME_LABEL"
- description="COM_CONTACT_FIELD_LINK_NAME_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linkb" type="text"
- label="COM_CONTACT_FIELD_LINKB_LABEL"
- description="COM_CONTACT_FIELD_LINKB_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linkc_name"
- type="text"
- label="COM_CONTACT_FIELD_LINKC_NAME_LABEL"
- description="COM_CONTACT_FIELD_LINK_NAME_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linkc"
- type="text"
- label="COM_CONTACT_FIELD_LINKC_LABEL"
- description="COM_CONTACT_FIELD_LINKC_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linkd_name"
- type="text"
- label="COM_CONTACT_FIELD_LINKD_NAME_LABEL"
- description="COM_CONTACT_FIELD_LINK_NAME_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linkd"
- type="text"
- label="COM_CONTACT_FIELD_LINKD_LABEL"
- description="COM_CONTACT_FIELD_LINKD_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linke_name"
- type="text"
- label="COM_CONTACT_FIELD_LINKE_NAME_LABEL"
- description="COM_CONTACT_FIELD_LINK_NAME_DESC"
- class="inputbox"
- size="30"
- />
-
- <field name="linke"
- type="text"
- label="COM_CONTACT_FIELD_LINKE_LABEL"
- description="COM_CONTACT_FIELD_LINKE_DESC"
- class="inputbox"
- size="30"
- />
<field
name="contact_layout"
type="componentlayout"
@@ -11,6 +11,7 @@ CREATE TABLE `#__contact_details` (
`telephone` varchar(255) default NULL,
`fax` varchar(255) default NULL,
`misc` mediumtext,
+ `links` text,
`image` varchar(255) default NULL,
`imagepos` varchar(20) default NULL,
`email_to` varchar(255) default NULL,
@@ -38,14 +38,12 @@ public function __construct(& $db)
public function bind($array, $ignore = '')
{
if (isset($array['params']) && is_array($array['params'])) {
- $registry = new JRegistry();
- $registry->loadArray($array['params']);
+ $registry = new JRegistry($array['params']);
$array['params'] = (string) $registry;
}
if (isset($array['metadata']) && is_array($array['metadata'])) {
- $registry = new JRegistry();
- $registry->loadArray($array['metadata']);
+ $registry = new JRegistry($array['metadata']);
$array['metadata'] = (string) $registry;
}
@@ -104,6 +102,38 @@ public function store($updateNulls = false)
*/
function check()
{
+ if (!empty($this->links) && is_array($this->links))
+ {
+ foreach ($this->links as $k => $link)
+ {
+ if ($link['url'] === '')
+ {
+ unset($this->links[$k]);
+ continue;
+ }
+
+ if (JFilterInput::checkAttribute(array('href', $link['url'])))
+ {
+ unset($this->links[$k]);
+ continue;
+ }
+
+ // check for http, https, ftp on webpage
+ if ( (stripos($link['url'], 'http://') === false)
+ && (stripos($link['url'], 'https://') === false)
+ && (stripos($link['url'], 'ftp://') === false))
+ {
+ $this->links[$k]['url'] = 'http://'.$link['url'];
+ }
+ }
+
+ // Reset the keys, so the JForm can properly bind the links data into the form.
+ $this->links = JArrayHelper::resetKeys($this->links);
+
+ $registry = new JRegistry($this->links);
+ $this->links = (string) $registry;
+ }
+
$this->default_con = intval($this->default_con);
if (JFilterInput::checkAttribute(array ('href', $this->webpage))) {
@@ -156,6 +156,11 @@
</ul>
</fieldset>
+ <?php echo JHtml::_('sliders.panel',JText::_('COM_CONTACT_LINKS'), 'contact-links'); ?>
+ <fieldset class="panelform">
+ <?php echo $this->form->getInput('links'); ?>
+ </fieldset>
+
<?php echo $this->loadTemplate('params'); ?>
<?php echo $this->loadTemplate('metadata'); ?>
@@ -135,24 +135,17 @@ COM_CONTACT_FIELD_INITIAL_SORT_LABEL="Sort by"
COM_CONTACT_FIELD_LANGUAGE_DESC="Assign a language for this contact"
COM_CONTACT_FIELD_LIMIT_BOX_DESC="Show/Hide limit box"
COM_CONTACT_FIELD_LIMIT_BOX_LABEL="Limit box"
-COM_CONTACT_FIELD_LINK_NAME_DESC="An additional link for this contact"
-COM_CONTACT_FIELD_LINKA_DESC="Description for Link A"
-COM_CONTACT_FIELD_LINKA_LABEL="Link A URL"
-COM_CONTACT_FIELD_LINKA_NAME_LABEL="Link A Label"
-COM_CONTACT_FIELD_LINKB_DESC="Description for Link B"
-COM_CONTACT_FIELD_LINKB_LABEL="Link B URL"
-COM_CONTACT_FIELD_LINKB_NAME_LABEL="Link B Label"
-COM_CONTACT_FIELD_LINKC_DESC="Description for Link C"
-COM_CONTACT_FIELD_LINKC_LABEL="Link C URL"
-COM_CONTACT_FIELD_LINKC_NAME_LABEL="Link C Label"
-COM_CONTACT_FIELD_LINKD_DESC="Description for Link D"
-COM_CONTACT_FIELD_LINKD_LABEL="Link D URL"
-COM_CONTACT_FIELD_LINKD_NAME_LABEL="Link D Label"
-COM_CONTACT_FIELD_LINKE_DESC="Description for Link E"
-COM_CONTACT_FIELD_LINKE_LABEL="Link E URL"
-COM_CONTACT_FIELD_LINKE_NAME_LABEL="Link E Label"
COM_CONTACT_FIELD_LINKED_USER_DESC="Linked Joomla! User"
COM_CONTACT_FIELD_LINKED_USER_LABEL="Linked User"
+COM_CONTACT_FIELD_LINKS_ADD_LINK="Add Link"
+COM_CONTACT_FIELD_LINKS_DESC="Additional links for this contact"
+COM_CONTACT_FIELD_LINKS_LABEL="Links"
+COM_CONTACT_FIELD_LINKS_LABEL_DESC="Label for the link"
+COM_CONTACT_FIELD_LINKS_LABEL_LABEL="Label"
+COM_CONTACT_FIELD_LINKS_LEGEND="Link %s"
+COM_CONTACT_FIELD_LINKS_REMOVE_LINK="Remove Link"
+COM_CONTACT_FIELD_LINKS_URL_DESC="URL of the Link"
+COM_CONTACT_FIELD_LINKS_URL_LABEL="URL"
COM_CONTACT_FIELD_MODIFIED_DESC="The date and time that the contact was last modified."
COM_CONTACT_FIELD_NAME_DESC="Contact Name"
COM_CONTACT_FIELD_NAME_LABEL="Name"
@@ -228,6 +221,7 @@ COM_CONTACT_FILTER_LABEL="Filter field"
COM_CONTACT_FILTER_SEARCH_DESC="Enter text to show matching contacts"
COM_CONTACT_ICONS_SETTINGS="Icons"
COM_CONTACT_ID_LABEL="ID"
+COM_CONTACT_LINKS="Links"
COM_CONTACT_MAIL_FIELDSET_LABEL="Mail Options"
COM_CONTACT_MANAGER_CONTACT="Contact Manager: Contact"
COM_CONTACT_MANAGER_CONTACTS="Contact Manager: Contacts"
@@ -264,7 +258,7 @@ COM_CONTACT_TOGGLE_TO_UNFEATURE="Toggle to change contact state to 'Unfeatured'"
COM_CONTACT_UNFEATURED="Unfeatured contact"
COM_CONTACT_WARNING_CATEGORY="This category is invalid"
COM_CONTACT_WARNING_PROVIDE_VALID_NAME="Please provide a valid name"
-COM_CONTACT_WARNING_PROVIDE_VALID_URL="Please provide a valid URL"
+COM_CONTACT_WARNING_PROVIDE_VALID_URL="Please provide a valid URL for the Website"
COM_CONTACT_WARNING_SAME_NAME="The name of this contact is already used. Please enter another name"
COM_CONTACT_WARNING_SELECT_CONTACT_TOPUBLISH="Please select a contact to publish"
COM_CONTACT_XML_DESCRIPTION="This component shows a listing of contact information"
@@ -1023,6 +1023,10 @@ input.required {
font-size:1.2em;
}
+.panel .contact-link {
+ border: 1px solid #CCC
+}
+
/* -------- Batch Section ---------- */
fieldset.batch {
margin: 20px 0 10px 0;
@@ -167,11 +167,14 @@ public function &getItem($pk = null)
}
// Convert parameter fields to objects.
- $registry = new JRegistry;
- $registry->loadString($data->params);
+ $registry = new JRegistry($data->params);
$data->params = clone $this->getState('params');
$data->params->merge($registry);
+ // Convert links fields to objects.
+ $registry = new JRegistry($data->links);
+ $data->links = $registry->toObject();
+
$registry = new JRegistry;
$registry->loadString($data->metadata);
$data->metadata = $registry;
Oops, something went wrong.

0 comments on commit a10686b

Please sign in to comment.