Create custom plugin joomla with custom ordering on install - joomla

Is the a trick to set my custom plugin to load the final plugin in joomla?
I want to set order on install and not after.
Is s there a custom params to set in xml like order="xxx" ?

I just found the answer by adding in the xml file
<scriptfile>script.php</scriptfile>
And in the script file
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/**
* Script file of yourplugin component.
*/
class plgSystemyourplginInstallerScript
{
/**
* method to run after an install/update/uninstall method.
*/
public function postflight($type, $parent)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$fields = array(
$db->quoteName('ordering').' = '.(int) 999,
);
$conditions = array(
$db->quoteName('element').' = '.$db->quote('wraprotect'),
$db->quoteName('type').' = '.$db->quote('plugin'),
);
$query->update($db->quoteName('#__extensions'))->set($fields)->where($conditions);
$db->setQuery($query);
$db->execute();
// $parent is the class calling this method
// $type is the type of change (install, update or discover_install)
}
}
Don't forget to edit your plugin name
And in joomla 1.5 edit #__extensions to #__plugins
And delete the line $db->quoteName('type').' = '.$db->quote('plugin')

Related

Joomla 3 Lis users in usergroup module

Anyone know of such a module?
Basically I want to dynamically load the users in certain usergroups inside an article with the loadmodule option.
Ended up building myself.
modfile:
<?php
defined('_JEXEC') or die;
// Include the latest functions only once
require_once __DIR__ . '/helper.php';
$shownumber = $params->get('shownumber', 10);
$groupnumber = $params->get('group', 4);
$names = ModUsersUsergroupHelper::getUsers($params);
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8');
require JModuleHelper::getLayoutPath('mod_users_usergroup', $params->get('layout', 'default'));
helper:
<?php
defined('_JEXEC') or die;
/**
* Helper for mod_users_usergroup
*
* #package Joomla.Site
* #subpackage mod_users_usergroup
*
* #since 1.6
*/
class ModUsersUsergroupHelper
{
/**
* Get users in a certain usergroup
*
* #param \Joomla\Registry\Registry $params module parameters
*
* #return array The array of users
*
* #since 1.6
*/
public static function getUsers($params)
{
$db = JFactory::getDbo();
$groupId = $params->get('group', 2);
$query = $db->getQuery(true)
->select($db->quoteName(array('u.id', 'u.name', 'u.username', 'u.registerDate')))
->order($db->quoteName('u.registerDate') . ' DESC')
->from('#__users AS u')
->join('INNER', '#__user_usergroup_map AS ugm ON ugm.user_id = u.id')
->where('ugm.group_id =' . $db->quote($groupId));
$db->setQuery($query, 0, $params->get('shownumber'));
try
{
return (array) $db->loadObjectList();
}
catch (RuntimeException $e)
{
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
return array();
}
}
}
I am not aware of such an extension but you could include some code in a Custom HTML module using Sourcerer or similar to achieve the desired result.
The Custom HTML module can then be displayed in an article using loadmodule.
For some example code see: https://stackoverflow.com/a/20743966

Magento unique TaxVat atrribute for every customer

.Hi,
I'm trying to make the attribute taxvat unique for every customer. (especially for users that i create from the backend). i.e no duplicates.
Just like the email attribute, if the email is already used, user gets notified to use another email.
I tried from the eav_attribute to change "is_unique" to "1" but nothing happened..
Can you please help me how to achieve this..?
Thanks
ok, i found the solution..
Find file /app/code/core/Mage/Customer/Model/Form.php (Don't forget to override instead..)
in "public function validateData(array $data)"
add the code inside the
foreach ($this->getAttributes() as $attribute)
foreach ($this->getAttributes() as $attribute) {
...
...
//## code to add
if ($attribute->getIsUnique()) {
$cid = $this->getEntity()->getData('entity_id'); //get current customer id
$cli = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToFilter($attribute->getAttributeCode(), $data[$attribute->getAttributeCode()]);
//->addFieldToFilter('customer_id', array('neq' => $cid)); //exclude current user from results //###### not working......
$flag=0;
foreach ($cli as $customer) {
$dataid=$customer->getId();
if ($dataid != $cid) //if the value is from another customer_id
$flag |= 1; //we found a dup value
}
if ($flag) {
$label = $attribute->getStoreLabel();
$errors = array_merge($errors, Mage::helper('customer')->__('"%s" already used!',$label));
}
}
//## End of code to add
}
I've modified what Karpa wrote to make it better
if ($attribute->getIsUnique()) {
$cid = $this->getEntity()->getData('entity_id'); //get current customer id
$cli = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToFilter($attribute->getAttributeCode(), $data[$attribute->getAttributeCode()])
->addFieldToFilter('entity_id', array('neq' => $cid)); //exclude current user from results //###### not working......
if (count($cli)>0) {
$label = $attribute->getStoreLabel();
$errors = array_merge($errors, array(Mage::helper('customer')->__('"%s" already used!',$label)));
}
I was looking for this solution for some time. But I noticed that the form.php file that you reference is the 1.5 version of magento. In version 1.6 the file is different ... Where to put this code in version 1.6? Thank you.
I found the file. It is in /app/code/core/Mage/Eav/Model/form.php.
But I put the code and did not work here ... I keep trying a solution.
You can create an event :
<customer_save_before>
<observers>
<mymodule_customer_save_before>
<class>mymodule/observer</class>
<method>checkUniqueAttribute</method>
</mymodule_customer_save_before>
</observers>
</customer_save_before>
And in your observer :
/**
* Check customer attribute which must be unique
*
* #param Varien_Event_Observer $observer
* #return $this
* ##see customer_save_before
*/
public function checkUniqueAttribute(Varien_Event_Observer $observer)
{
/** #var Mage_Customer_Model_Customer $customer */
$customer = $observer->getEvent()->getCustomer();
foreach ($customer->getAttributes() as $attribute) {
if ($attribute->getIsUnique()) {
$collection = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToFilter($attribute->getAttributeCode(), $customer->getData($attribute->getAttributeCode()))
->addFieldToFilter('entity_id', array('neq' => $customer->getId()));
if ($collection->getSize()) {
Mage::throwException(sprintf(
'The value %s for %s is already used',
$customer->getData($attribute->getAttributeCode()),
$attribute->getStoreLabel()
));
}
}
}
return $this;

Joomla 1.7 Authentication from external app

My aim is to check that a Joomla username and password is valid from my external application. It is not necessary that the user is logged into the system, just that their account exists.
I decided to create my own authentication plugin based on the Joomla Authentication (JOOMLA_PATH/plugins/authentication/joomla). I only changed the name:
<?php
/**
* #version $Id: joomla.php 21097 2011-04-07 15:38:03Z dextercowley $
* #copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
/**
* Joomla Authentication plugin
*
* #package Joomla.Plugin
* #subpackage Authentication.Webservice
* #since 1.5
*/
class plgAuthenticationWebservice extends JPlugin
{
/**
* This method should handle any authentication and report back to the subject
*
* #access public
* #param array Array holding the user credentials
* #param array Array of extra options
* #param object Authentication response object
* #return boolean
* #since 1.5
*/
function onUserAuthenticate($credentials, $options, &$response)
{
jimport('joomla.user.helper');
$response->type = 'Webservice';
// Joomla does not like blank passwords
if (empty($credentials['password'])) {
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = JText::_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');
return false;
}
// Initialise variables.
$conditions = '';
// Get a database object
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id, password');
$query->from('#__users');
$query->where('username=' . $db->Quote($credentials['username']));
$db->setQuery($query);
$result = $db->loadObject();
if ($result) {
$parts = explode(':', $result->password);
$crypt = $parts[0];
$salt = #$parts[1];
$testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);
if ($crypt == $testcrypt) {
$user = JUser::getInstance($result->id); // Bring this in line with the rest of the system
$response->email = $user->email;
$response->fullname = $user->name;
if (JFactory::getApplication()->isAdmin()) {
$response->language = $user->getParam('admin_language');
}
else {
$response->language = $user->getParam('language');
}
$response->status = JAUTHENTICATE_STATUS_SUCCESS;
$response->error_message = '';
} else {
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = JText::_('JGLOBAL_AUTH_INVALID_PASS');
}
} else {
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = JText::_('JGLOBAL_AUTH_NO_USER');
}
}
}
I added one more file to my plugin to access the authentication, I called it test_auth.php and it goes like this:
<?php
define('_JEXEC', 1 );
define('JPATH_BASE', 'C:\xampp\htdocs\joomla');
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
include("Webservice.php");
$credentials = array(
'username' => 'test',
'password' => 'test');
$options = array();
$response = array();
$auth = new plgAuthenticationWebservice();
$auth->onUserAuthenticate($credentials, $options, &$response);
var_dump($response);
But when I call it, it get these errors:
Warning: Missing argument 1 for JPlugin::__construct(), called in
C:\xampp\htdocs\joomla\plugins\authentication\Webservice\test_auth.php
on line 25 and defined in
C:\xampp\htdocs\joomla\libraries\joomla\plugin\plugin.php on line 57
Fatal error: Call to a member function attach() on a non-object in
C:\xampp\htdocs\joomla\libraries\joomla\base\observer.php on line 41
What am I doing wrong?
I think I could place all php scripts outside and independent from joomla and work with require_once(JPATH_BASE .DS.'includes'.DS.'defines.php') etc.
Or I could write a plugin, install it with the extension manager and won't struggle with an unavailable joomla framework. But in fact it won't work if I leave out defines.php and framework.php.
I think a guide for plugin creation in Joomla 1.7 would be helpful.
OK, i completely dropped my first try.
Instead I use JOOMLA_ROOT/libraries/joomla/user/authentication.php now (insprired by JOOMLA_ROOT/libraries/joomla/application/application.php).
My test_auth.php looks like this now:
<?php
define('_JEXEC', 1 );
define('DS', DIRECTORY_SEPARATOR);
define('JPATH_BASE', dirname(__FILE__) . DS . '..' . DS . '..' . DS . '..'); // assuming we are in the authorisation plugin folder and need to go up 3 steps to get to the Joomla root
require_once (JPATH_BASE .DS. 'includes' .DS. 'defines.php');
require_once (JPATH_BASE .DS. 'includes' .DS. 'framework.php');
require_once (JPATH_BASE .DS. 'libraries' .DS. 'joomla'. DS. 'user' .DS. 'authentication.php');
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$credentials = array(
'username' => 'test',
'password' => 'test');
$options = array();
$authenticate = JAuthentication::getInstance();
$response = $authenticate->authenticate($credentials, $options);
if ($response->status === JAUTHENTICATE_STATUS_SUCCESS) {
echo('<br />It works<br />');
}
var_dump($response);
For any improvements I would be deeply grateful!
EDIT: I dismissed the plugin installation. It is a simple external script, which wouldn't be called from Joomla itself. I simply moved it to a new folder in the Joomla root.

CodeIgniter - Displaying and entering dynamic meta data

I have started using CodeIgniter ... Im finding it is quite good, although I have a bit of an issue.
Whats the best way to handle meta data? ... In the views folder, I have created another folder called 'includes' then in there I have added header, footer, nav views.
So I'm taking it that for each controller meta data needs to be entered and then passed to the header view.
If I could get some examples of how you all go about this, that would be fantastic.
Cheers,
I know this is an out of date question, but in case anyone is looking for a simple solution for this in Codeigniter 2.2
I found the simplest thing was to create a helper for this.
Create a file located in config/seo_config.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['seo_title'] = 'My title';
$config['seo_desc'] = 'My description';
$config['seo_robot'] = true;
/* End of file seo_config.php */
/* Location: ./application/config/seo_config.php */
Create a file located in application/helers/seo_helper.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* SEO Helper function
*
* Generates Meta tags for SEO
*
* #author Henrik Oldenborg
* #version 1.0
*/
/**
* meta_tags()
*
* Generates tags for title, description and robots
* Using title and description from config file as default
*
* #access public
* #param string Title
* #param string Description (155 characters)
* #param bool Robots follow or no folow
*/
if(! function_exists('meta_tags')){
function meta_tags($meta)
{
$CI =& get_instance();
$CI->config->load('seo_config');
if(!isset($meta['title']))
$meta['title'] = $CI->config->item('seo_title');
if(!isset($meta['desc']))
$meta['desc'] = $CI->config->item('seo_desc');
if(!isset($meta['robot']))
$meta['robot'] = $CI->config->item('seo_robot');
$html = '';
//uses default set in seo_config.php
$html .= '<title>'.$meta['title'].'</title>';
$html .= '<meta name="title" content="'.$meta['title'].'"/>';
$html .= '<meta name="description" content="'.$meta['desc'].'"/>';
if($meta['robot'] == true){
$html .= '<meta name="robots" content="index,follow"/>';
} else {
$html .= '<meta name="robots" content="noindex,nofollow"/>';
}
echo $html;
}
}
/* End of file seo_helper.php */
/* Location: ./application/helpers/seo_helper.php */
Load up the helper - (Either in the controller or in config/autoload.php)
$this->load->helper('seo_helper');
Add the following code in your view between the two header tags
<?=(isset($meta) ? meta_tags($meta) : meta_tags());?>
Now, all you need to do is declare the $meta variable in your controller like so
$data['meta']['title'] = 'My special title';
$data['meta']['desc'] = 'My special description';
$this->load->view('mytemplate',$data)
Usefull tip
You might want to declare your meta data in the controllers constructor. This way you can easily override it when needed in a underlying function, like so.
class Forum extends CI_Controller {
private $data = array();
function __construct()
{
$this->data['meta']['title'] = 'My forum title';
$this->data['meta']['robot'] = false;
parent::__construct();
}
public function index()
{
$this->data['content'] = 'forum';
$this->load->view('userarea/template',$this->data);
}
public function topic($topic_id)
{
$this->data['meta']['title'] = 'My specific title';
$this->data['content'] = 'topic';
$this->load->view('userarea/template',$this->data);
}
}
Create a new file in your libraries folder:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class View_lib {
public function __construct()
{
$this->CI =& get_instance();
}
public function load_view($template, $data = NULL)
{
$this->CI->load->view('header', $data);
$this->CI->load->view($template);
$this->CI->load->view('footer');
}
}
/* End of file view_lib.php */
/* Location: ./system/application/libraries/view_lib.php */
Then load this library in your controller:
$this->load->library('view_lib');
Then call your view file in a function like this:
$this->view_lib->load_view('name_of_view_file', $data);
or (if you call a static file without any data to pass):
$this->view_lib->load_view('name_of_view_file');
There are many ways of doing this, but this one works nicely for the applications I am working on. In one of my projects I have multiple functions in the view_lib library to load with or without sidebar, different headers and footers depending if a user is logged in.
Hope this helps, cheers.
I find its just easiet to pass it right in the head of the page with arrays
$meta = array(
array('name' => 'description', 'content' => 'Political website, Liberal, progressive, blog, posts,'),
array('name' => 'keywords', 'content' => 'politics, McCain, Beck, Hannity, Rush Limbaugh, Environment, Obama, ZB Block, Sarah Palin, Republicans, GOP, Democrats, Liberals, Conservatives, Reagan, Politicususa, FreakOut Nation, Raw Story, Congress, Senate, Representatives, Constitution, White, Black, racial, racsim, blog, blogging, Lemon, Lemonrose, Fox, Fox News,
political, partys, president'),
array('name' => 'Content-type', 'content' => 'text/html; charset=utf-8', 'type' => 'equiv'),
);
echo meta($meta);

How to make link in joomla

hi i am new in joomla.I need the dynamic link in view file.
//no direct access
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
// include the helper file
require_once(dirname(FILE).DS.'helper.php');
// get a parameter from the module's configuration
$userCount = 5;
// get the items to display from the helper
$items = ModNewHelper::getItems($userCount);
//link of the component
// include the template for display
require(JModuleHelper::getLayoutPath('mod_new'));
this is main file
/**
* #author Raju Gautam
* #copyright 2011
*/
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
class ModNewHelper
{
/**
* Returns a list of post items
*/
public function getItems($userCount)
{
// get a reference to the database
$db = &JFactory::getDBO();
// get a list of $userCount randomly ordered users
$query = 'SELECT name,id FROM `#__hello` ORDER BY ordering LIMIT ' . $userCount . '';
$db->setQuery($query);
$items = ($items = $db->loadObjectList())?$items:array();
return $items;
} //end getItems
} //end ModHelloWorld2Helper
this is helper file
defined('JEXEC') or die('Restricted access'); // no direct access
echo JText::('Latest News');
//echo ""; print_r($items); exit;
foreach ($items as $item) {
echo JText::sprintf($item->name);
} this is view file
I need the link on echo JText::sprintf($item->name); this line. can i helped please?
change your this line from view file:
echo JText::sprintf($item->name);
to :
echo "<a href='".$item->link."'>". JText::sprintf($item->name)."</a>";
assuming, link is the field name of your link else change it according to the field name you've used for link. this may help, i guess .. good luck with it.
use
echo "<a href='".JRoute::_($item->link, false)."'>". JText::sprintf($item->name)."</a>";
JRoute will take care of routing also, if routing is enabled.

Resources