Source for file article.php

Documentation is available at article.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_content
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('JPATH_BASE'or die;
  11.  
  12. /**
  13.  * Supports a modal article picker.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_content
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * The form field type.
  22.      *
  23.      * @var        string 
  24.      * @since   1.6
  25.      */
  26.     protected $type = 'Modal_Article';
  27.  
  28.     /**
  29.      * Method to get the field input markup.
  30.      *
  31.      * @return  string    The field input markup.
  32.      * @since   1.6
  33.      */
  34.     protected function getInput()
  35.     {
  36.         $allowEdit        ((string) $this->element['edit'== 'true'true false;
  37.         $allowClear        ((string) $this->element['clear'!= 'false'true false;
  38.  
  39.         // Load language
  40.         JFactory::getLanguage()->load('com_content'JPATH_ADMINISTRATOR);
  41.  
  42.         // Load the modal behavior script.
  43.         JHtml::_('behavior.modal''a.modal');
  44.  
  45.         // Build the script.
  46.         $script array();
  47.  
  48.         // Select button script
  49.         $script['    function jSelectArticle_'.$this->id.'(id, title, catid, object) {';
  50.         $script['        document.getElementById("'.$this->id.'_id").value = id;';
  51.         $script['        document.getElementById("'.$this->id.'_name").value = title;';
  52.  
  53.         if ($allowEdit)
  54.         {
  55.             $script['        jQuery("#'.$this->id.'_edit").removeClass("hidden");';
  56.         }
  57.  
  58.         if ($allowClear)
  59.         {
  60.             $script['        jQuery("#'.$this->id.'_clear").removeClass("hidden");';
  61.         }
  62.  
  63.         $script['        SqueezeBox.close();';
  64.         $script['    }';
  65.  
  66.         // Clear button script
  67.         static $scriptClear;
  68.  
  69.         if ($allowClear && !$scriptClear)
  70.         {
  71.             $scriptClear true;
  72.  
  73.             $script['    function jClearArticle(id) {';
  74.             $script['        document.getElementById(id + "_id").value = "";';
  75.             $script['        document.getElementById(id + "_name").value = "'.htmlspecialchars(JText::_('COM_CONTENT_SELECT_AN_ARTICLE'true)ENT_COMPAT'UTF-8').'";';
  76.             $script['        jQuery("#"+id + "_clear").addClass("hidden");';
  77.             $script['        if (document.getElementById(id + "_edit")) {';
  78.             $script['            jQuery("#"+id + "_edit").addClass("hidden");';
  79.             $script['        }';
  80.             $script['        return false;';
  81.             $script['    }';
  82.         }
  83.  
  84.         // Add the script to the document head.
  85.         JFactory::getDocument()->addScriptDeclaration(implode("\n"$script));
  86.  
  87.         // Setup variables for display.
  88.         $html    array();
  89.         $link    'index.php?option=com_content&amp;view=articles&amp;layout=modal&amp;tmpl=component&amp;function=jSelectArticle_'.$this->id;
  90.  
  91.         if (isset($this->element['language']))
  92.         {
  93.             $link .= '&amp;forcedLanguage='.$this->element['language'];
  94.         }
  95.  
  96.         $db    JFactory::getDbo();
  97.         $db->setQuery(
  98.             'SELECT title' .
  99.             ' FROM #__content' .
  100.             ' WHERE id = '.(int) $this->value
  101.         );
  102.  
  103.         try
  104.         {
  105.             $title $db->loadResult();
  106.         }
  107.         catch (RuntimeException $e)
  108.         {
  109.             JError::raiseWarning(500$e->getMessage());
  110.         }
  111.  
  112.         if (empty($title))
  113.         {
  114.             $title JText::_('COM_CONTENT_SELECT_AN_ARTICLE');
  115.         }
  116.         $title htmlspecialchars($titleENT_QUOTES'UTF-8');
  117.  
  118.         // The active article id field.
  119.         if (== (int) $this->value)
  120.         {
  121.             $value '';
  122.         }
  123.         else
  124.         {
  125.             $value = (int) $this->value;
  126.         }
  127.  
  128.         // The current article display field.
  129.         $html['<span class="input-append">';
  130.         $html['<input type="text" class="input-medium" id="'.$this->id.'_name" value="'.$title.'" disabled="disabled" size="35" />';
  131.         $html['<a class="modal btn hasTooltip" title="'.JHtml::tooltipText('COM_CONTENT_CHANGE_ARTICLE').'"  href="'.$link.'&amp;'.JSession::getFormToken().'=1" rel="{handler: \'iframe\', size: {x: 800, y: 450}}"><i class="icon-file"></i> '.JText::_('JSELECT').'</a>';
  132.  
  133.         // Edit article button
  134.         if ($allowEdit)
  135.         {
  136.             $html['<a class="btn hasTooltip'.($value '' ' hidden').'" href="index.php?option=com_content&layout=modal&tmpl=component&task=article.edit&id=' $value'" target="_blank" title="'.JHtml::tooltipText('COM_CONTENT_EDIT_ARTICLE').'" ><span class="icon-edit"></span> ' JText::_('JACTION_EDIT''</a>';
  137.         }
  138.  
  139.         // Clear article button
  140.         if ($allowClear)
  141.         {
  142.             $html['<button id="'.$this->id.'_clear" class="btn'.($value '' ' hidden').'" onclick="return jClearArticle(\''.$this->id.'\')"><span class="icon-remove"></span> ' JText::_('JCLEAR''</button>';
  143.         }
  144.  
  145.         $html['</span>';
  146.  
  147.         // class='required' for client side validation
  148.         $class '';
  149.         if ($this->required)
  150.         {
  151.             $class ' class="required modal-value"';
  152.         }
  153.  
  154.         $html['<input type="hidden" id="'.$this->id.'_id"'.$class.' name="'.$this->name.'" value="'.$value.'" />';
  155.  
  156.         return implode("\n"$html);
  157.     }
  158. }

Documentation generated on Tue, 19 Nov 2013 14:53:56 +0100 by phpDocumentor 1.4.3