NegretaSubratllat

API Joomla

http://dev.joomla.org
http://api.joomla.org

// API de Joomla
JPATH_COMPONENT.DS
JURI::base()
$this->baseurl
dirname(__FILE__).DIRECTORY_SEPARATOR
JPATH_ROOT.DS
$mainframe->addCustomHeadTag('<script type="text/javascript" src="'.$this->baseurl.'script.js"></script>');

$document = & JFactory::getDocument();
$document->setTitle('titol');
$document->setMetaData('robots', 'noindex, nofollow'); //per reemplaçar
$document->setMetadata( 'keywords' , 'paruales clau' );
$document->setMetadata( 'description' , 'descripcio clau' );
$document->addCustomTag('<style>...</style>');
$document->addScript(JURI::base().'components/com_jcrop/js/jquery.Jcrop.pack.js');
$document->addStyleSheet(JURI::base().'components/com_jcrop/css/jquery.Jcrop.css');

JError::raiseError(500, JText::_( 'Select an item to' .$action, true ) );

$msg = sprintf ( JText::_( 'Atention! This file is not %s type. Upload a valid file' ), $conf->get('upload_files'));
$mainframe->redirect( JRoute::_('index.php?option=com_mp3upload'.$itemid), $msg );  

$user 	=& JFactory::getUser();

echo $user->get( 'gid' ); //number group (Super Administrator = 25)
$gid = $user->get('aid', 0); //acces

if( ($user->usertype != "Super Administrator") && ($user->usertype != "Administrator") && ($user->usertype != "Manager") )

$document =& JFactory::getDocument();
$dispatcher =& JDispatcher::getInstance();
$pathway =& $mainframe->getPathway();
$params =& $mainframe->getParams('com_content');
JRoute::_( 'index.php?option=com_test' );

// template
$app =& JFactory::getApplication();
$templateDir = JURI::base() . 'templates/' . $app->getTemplate();

// Check for request forgeries => Spoofers 

JRequest::checkToken() or die( 'Invalid Token' );

//redireccionar
$mainframe->redirect( 'index.php?option=com_reviews' );

//classe HTML custom
HTML_reviews::editReview($row, $lists, $option);

//recollir variables
$task	= JRequest::getCmd('task');
$id 	= JRequest::getVar('id', 0, 'get', 'int');
$cid 	= JRequest::getVar('cid', array(0), 'post', 'array');
$GLOBALS['email']	= JRequest::getVar( 'email','','post');

//llengua
if(file_exists(JPATH_ROOT.DS.'components/com_medis/language/'.$mainframe->getCfg('lang').'.php')){
	include(JPATH_ROOT.DS.'components/com_medis/language/'.$mainframe->getCfg('lang').'.php');
} else {
	include(JPATH_ROOT.DS.'components/com_medis/language/english.php');
}

//calendari
echo JHTML::_('calendar', $now, 'date', 'date', '%Y-%m-%d', array('class'=>'inputbox', 'size'=>'10',  'maxlength'=>'10'));

Ideal per IE

<?php JHTML::_('behavior.calendar'); ?> 
	<input type="text" name="entry" id="entry" value="" /><img class="calendar" src="templates/system/images/calendar.png" alt="calendar" id="showCalendar1" /> 
<script type="text/javascript"> 
        var startDate = new Date(1980,01,01) 
        Calendar.setup( 
          { 
            inputField  : "entry",         // ID of the input field 
            ifFormat    : "%d-%m-%Y",    // the date format 
            button      : "showCalendar1",       // ID of the button 
            date        : startDate 
          } 
        ); 
</script>

<?php JHTML::_('behavior.calendar'); ?>   
          <input class="inputbox" name="arrivalDate" type="text" id="arrivalDate" size="18" maxlength="20" value="" /> 
        <img class="calendar" src="templates/system/images/calendar.png" alt="calendar" id="showArrivalCalendar" /> 
        <script type="text/javascript"> 
            var startDate = new Date(2008, 8, 7); 
            Calendar.setup({ 
                inputField  : "arrivalDate", 
                ifFormat    : "%m/%d/%Y",                         
                button      : "showArrivalCalendar", 
                range        : [2008,2008], 
                date        : startDate 
            }); 
        </script> 

//Crear alias (per fer links)
$alias = JFilterOutput::stringURLSafe($row->title);

//convertir data
JHTML::Date( $row->date_start, JText::_( 'DATE_FORMAT_LC1' ) );

//data
$datenow = new JDate();
$datenow = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");

<?php echo $date->toFormat(JText::_('DATE_FORMAT_LC2')); ?>

//Base de dades
$db =& JFactory::getDBO();
$query = "SELECT * FROM #__reviews";
$db->setQuery( $query );
$rows = $db->loadObjectList();
if ($db->getErrorNum()) {
	echo $db->stderr();
	return false;
}

$cids = implode( ',', $cid );
$query = 'UPDATE #__reviews'

. ' SET published = ' . (int) $state

. ' WHERE id IN ( '. $cids .' )'

;

$db->setQuery( $query );

if (!$db->query()) {

	JError::raiseError(500, $db->getErrorMsg() );

}

$query = "SELECT title FROM #__content WHERE id=1";
$db->setQuery($query);
$row = $db->loadResult();

echo $row[0]->title;

//Select ràpida d'un registre
$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
$id = $cid[0];
$row->load($id);

//paginació
jimport('joomla.html.pagination');
$pageNav = new JPagination($total, $limitstart, $limit);

echo $pageNav->getListFooter();

O amb desglossat:

jimport('joomla.html.pagination');
$pagination = new JPagination( $total, $limitstart, $limit );
$pageNav = $pagination->getListFooter();
$pageNav .= $pagination->getPagesLinks()."<br/>";
$pageNav .= $pagination->getPagesCounter()."<br/>";

// tasca
switch ($task){
	case 'apply':
	function();
	break;
	default:
	function();
}

// Passar una variable dins d'una funció sense paràmetres
$GLOBALS['prova'] = "prova1";

function test(){
	global $prova;
	echo $prova;
}

//Spoofers
<form method="post" action="<?php echo JRoute::_( 'index.php?option=com_test' );?>">
  <!-- Other form fields -->
  <input type="hidden" name="task" value="save" />
  <input type="hidden" name="<?php echo JUtility::getToken(); ?>" value="1" />
</form>

Step 2 is to add the Session Token check to your task in your component, like this:

/**
 * Saves the form
 */
function save()
{
  // perform token check (prevent spoofing)
  $token	= JUtility::getToken();
  if(!JRequest::getInt($token, 0, 'post')) {
    JError::raiseError(403, 'Request Forbidden');
  }
  // go do some other stuff now
}

// Correu electrònic

correu electrònic està protegida dels spambots: mosHTML::emailCloaking($row[0]->email)

function sendMail(){
 
           $mailer =& JFactory::getMailer();
           $sender = JRequest::getVar(‘email’);
           $nombre = JRequest::getVar(‘nombre’);
           $apellidos = JRequest::getVar(‘apellidos’);
           $fromname = $nombre . " " . $apellidos ;
           $asunto = "NUEVO CLIENTE INTERESADO : ". $fromname;
           $body = JRequest::getVar(‘comentarios’);
 
           $mailer->setSender(array($sender, $fromname));
           $mailer->setSubject($asunto);
           $mailer->setBody($body);
           $mailer->IsHTML(0);
 
           // Add recipients
           $mailer->addRecipient("atencionClientes@empresa.com");
 
           // Send the Mail
           $rs  = $mailer->Send();
 
           if ( JError::isError($rs) ) {
                   $msg = $rs->getError();
                   $this->setRedirect( "index.php?option=com_miComponente&view=contacto" , $msg);
           } else {
                   $msg = "Mensaje enviado correctamente. Pronto nos pondremos en contacto usted.";
                   $this->setRedirect("index.php",$msg);
           }
 
}

// Module i Pluging XML
<param name="limit" type="text" default="" label="Limit" description="Limit content of list" />

<param name="description" type="textarea" rows="3" cols="40" default="" label="Description" description="" />

<param name="show_introtext" type="radio" default="1" label="Show Introtext" description="Show/Hide items introtext">
	<option value="1">show</option>
	<option value="0">hide</option>
</param>

<param name="@spacer" type="spacer" default="" label="" description="" />

<param name="cache" type="list" default="1" label="Caching" description="Select whether to cache the content of this module">
	<option value="1">Use global</option>
	<option value="0">No caching</option>
</param>

<param name="section" type="section" default="" label="Section" description="Select Section" />
<param name="category" type="category" default="" label="Category" description="Select Category" />

// Config
$config = &JFactory::getConfig();

$emails = array(
$emails = array("email" => $email),
$emails = array("email" => $rows[0]->email),
$emails = array("email" => $config->getValue('mailfrom') )
);

//Modificar el formulari content del frontend
  - Formulari HTML -> components/com_content/views/article/tmplf/form.php Per imprimir el valor, hem d'afegir: <?php echo $this->escape($this->article->prova); ?>
  - Estructura de la base de dades -> libraries/joomla/database/table/content.php
  - Control en el moment de guardar (si fa falta) -> components/com_content/controller.php => function save()

//Vincle amb finestra flotant
JHTML::_('behavior.modal');
<a href="http://"  rel="{handler: 'iframe', size: {x: 650, y: 375}}" class="modal">vincle</a>

//Editor USER
$editor =& JFactory::getEditor();
echo $editor->display( 'fulltext', $row->fulltext,'100%', '450', '40', '5' );

if ($this->editoruser) :

  echo $this->editor->display('datdescription', $this->row->datdescription, '100%', '400', '70', '5', array('pagebreak', 'readmore') );

else :

?>

  <textarea style="width:100%;" rows="10" name="datdescription" class="inputbox" wrap="virtual" onkeyup="berechne(this.form)"><?php echo $this->row->datdescription; ?></textarea><br />

<?php endif; ?>

// Return
$return = base64_encode($return);
$return = JRequest::getVar('return', '', 'method', 'base64');

//cache.
Per activar la cache, important que el display estigui a false perque generi els fitxers corresponents.

==Opció 1==
class pruebaController extends JController
{	

	function display()

	{	


	$view = "prueba";

	$option = JRequest::getCmd('option');

	$cache =& JFactory::getCache($option);

	$cache->get($view, 'display');

	parent::display(true);

	}

}

==Opció 2 (recomenable)==
    function display($cachable=false)
    {
        $cachable = True;
        $document =& JFactory::getDocument();
 
        $viewType       = $document->getType();
        $viewName       = JRequest::getCmd( 'view', $this->getName() );
        $viewLayout     = JRequest::getCmd( 'layout', 'default' );
 
        $view = & $this->getView( $viewName, $viewType, '', array( 'base_path'=>$this->_basePath));
 
        // Get/Create the model
        if ($model = & $this->getModel($viewName)) {
                // Push the model into the view (as default)
                $view->setModel($model, true);
        }
 
        // Set the layout
        $view->setLayout($viewLayout);
 
        // Display the view
        if ($cachable && $viewType != 'feed') {
                global $option;
                $cache =& JFactory::getCache($option, 'view');
                $cache->get($view, 'display');
        } else {
                $view->display();
        }
    }

Per esborrar la cache quan editem:
$cache = &JFactory::getCache('com_eventlist');
$cache->clean();

//Detectar si existeix un menú pel SEO
$component	= &JComponentHelper::getComponent('com_medis');
$menu		= &JSite::getMenu();
$items		= $menu->getItems('componentid', $component->id);

 
joomla/developer/api.txt · Darrera modificació: 2010/11/02 14:08 per resteve
 
Copyright: Zikzakmedia Llicència Creative Commons By-NC-SA
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki