PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/system/nnframework/fields/articles.php

https://bitbucket.org/organicdevelopment/joomla-2.5
PHP | 114 lines | 79 code | 13 blank | 22 comment | 11 complexity | bd4cddd59abfca9d7a56303fa62600e6 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, MIT, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * Element: Articles
  4. * Displays an article id field with a button
  5. *
  6. * @package NoNumber Framework
  7. * @version 12.8.2
  8. *
  9. * @author Peter van Westen <peter@nonumber.nl>
  10. * @link http://www.nonumber.nl
  11. * @copyright Copyright Š 2012 NoNumber All Rights Reserved
  12. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
  13. */
  14. // No direct access
  15. defined('_JEXEC') or die;
  16. /**
  17. * Articles Element
  18. */
  19. class nnFieldArticles
  20. {
  21. var $_version = '12.8.2';
  22. function getInput($name, $id, $value, $params, $children)
  23. {
  24. $this->params = $params;
  25. JHtml::_('behavior.modal', 'a.modal');
  26. $_size = $this->def('size');
  27. $_multiple = $this->def('multiple', 1);
  28. $_doc = JFactory::getDocument();
  29. $_js_part = "
  30. if ( document.getElementById(object+'_name') ) {
  31. document.getElementById(object+'_id').value = id;
  32. document.getElementById(object+'_name').value = title;
  33. } else {
  34. // multiple
  35. var vals = document.getElementById(object+'_id').value.trim().split(',');
  36. vals[vals.length] = id;
  37. var tmpvals = new Array();
  38. for ( var i=0; i<vals.length; i++ ) {
  39. val = vals[i].trim().toInt();
  40. if ( val ) {
  41. tmpvals[val] = val;
  42. }
  43. }
  44. vals = new Array();
  45. for ( val in tmpvals ) {
  46. if ( typeof(tmpvals[val]) === 'number' ) {
  47. vals[vals.length] = tmpvals[val];
  48. }
  49. }
  50. document.getElementById(object+'_id').value = vals.join();
  51. }";
  52. $_js = "
  53. function nnSelectArticle_".$id."( id, title, catid )
  54. {
  55. var object = '".$id."';
  56. ".$_js_part."
  57. SqueezeBox.close();
  58. }";
  59. $_doc->addScriptDeclaration($_js);
  60. $_link = 'index.php?option=com_content&amp;view=articles&amp;layout=modal&amp;tmpl=component&amp;function=nnSelectArticle_'.$id;
  61. $html = "\n".'<div style="float: left;">';
  62. if (!$_multiple) {
  63. $val_name = $value;
  64. if ($value) {
  65. $db = JFactory::getDBO();
  66. $query = $db->getQuery(true);
  67. $query->select('c.title');
  68. $query->from('#__content AS c');
  69. $query->where('c.id = '.(int) $value);
  70. $db->setQuery($query);
  71. $val_name = $db->loadResult();
  72. $val_name .= ' ['.$value.']';
  73. }
  74. $html .= '<input type="text" id="'.$id.'_name" value="'.$val_name.'" class="inputbox" size="'.$_size.'" disabled="disabled" />';
  75. $html .= '<input type="hidden" name="'.$name.'" id="'.$id.'_id" value="'.$value.'" />';
  76. } else {
  77. $html .= '<input type="text" name="'.$name.'" id="'.$id.'_id" value="'.$value.'" class="inputbox" size="'.$_size.'" />';
  78. }
  79. $html .= '</div>';
  80. $html .= '<div class="button2-left"><div class="blank"><a class="modal" title="'.JText::_('NN_SELECT_AN_ARTICLE').'" href="'.$_link.'" rel="{handler: \'iframe\', size: {x: 650, y: 375}}">'.JText::_('NN_SELECT').'</a></div></div>'."\n";
  81. return $html;
  82. }
  83. private function def($val, $default = '')
  84. {
  85. return (isset($this->params[$val]) && (string) $this->params[$val] != '') ? (string) $this->params[$val] : $default;
  86. }
  87. }
  88. class JFormFieldNN_Articles extends JFormField
  89. {
  90. /**
  91. * The form field type
  92. *
  93. * @var string
  94. */
  95. public $type = 'Articles';
  96. protected function getInput()
  97. {
  98. $this->_nnfield = new nnFieldArticles();
  99. return $this->_nnfield->getInput($this->name, $this->id, $this->value, $this->element->attributes(), $this->element->children());
  100. }
  101. }