Using a third party plugin with Yii - yii

i am using a third party plugin with yii, it provides chat functionality, it has its own DB and php files that provide the functionality,
now i am want to use it in the view, but the simple include statements are not working, do i need to convert it to yii or can i use it as is?
<?php
session_start();
// Load MySQL DB settings
include_once('config.inc.php');
$_SESSION['username'] = 'Currently logged in users's username from database';
$_SESSION['user_id'] = 'Currently logged in user's id';
?>
//That's it! To print online users, you need to do it like this:
<?php
$users = mysql_query("SELECT id,username FROM ".$sql_table_users." WHERE chat_status='online' AND id!='".$_SESSION['user_id']."'");
if(mysql_num_rows($users) > 0){
while($user = mysql_fetch_assoc($users)){
print ''.$user['username'].'<br />';
}
}
?>
this is the interface plugin has provided for me.
plugin location is /assets/plugin.
i cant use direct php query commands to another Database, which i want to keep seperate from mine, plus the js file that comes with the plugin calls the script with wrong URL parameters, so what is the best method to incorperate this into my yii app. thanks

You should create a Yii extension that'll wrap your plugin.
Then in your view you'll have to call a widget that'll display your chat.
I think this is the best way to do it because using this all your call to the plugin will be performed with the yii strucutre and philosophy. Only your extension will be structured using the chat philosophy.
Source about creating widgets

Related

Yii - Route without Controller

I'm using an existing upload script that require user authentication. However since I did not write the upload script, it's nearly impossible for me to read the source code and make it into separate view and controller file. The problem is if the script does not get routed by the bootstrap file, it has no access to the Yii variable and thus user log in information.
I tried to set a custom session variable when the user login. However it work barely because my custom session would expire before the session set by Yii.
Any help would be appreciated.
Because of the way the script is written I've only been able to find one way of doing this. It will involve re-writing some elements of the script.
Save the filemanager in protected/vendors.
You need a controller to handle the routing of the request. This will also give you the access control that you need. Call it FileUpload and create it where you normally create controllers in your project. Right at the start of the controller, before the class is declared, import the fileUpload files from it's previously saved location; Yii::import('application.vendors.*');
You need an action to handle the incoming request. Call this actionIndex. Give it the following code.
public function actionIndex() {
//Start capturing the output from the script
ob_start();
require_once('filemanager/dialog.php');
//Finish capturing output, and save to a variable
$output = ob_end_clean();
$this->render('index', array('output' => $output));
}
Then you need a view file. Call it 'output.php' and it just contains one line; <?php echo $output; ?>
This will render the html generated by the script, and hopefully contain it within your existing template.
Your first problem is that the script sends headers which aren't discarded by ob_start. You will need to delete these from the script. It also starts a session, which will throw an error 'Session already started', which can be cured by changing the first line of config.php to
if(!isset($_SESSION))
{
session_start();
}
Your next problem will be that none of the scripts and stylesheets are loaded, because the vendor hasn't used relative filepaths, and also because you've just deleted the headers. You will need to re-write lots of the script to include the necessary files. Fortunately, you now have access to Yii functions, so can use the asset manager to publish all the js and css files needed by the script.
Your final (hopefully!) problem will be the urls used by the script page. Currently they are all pointing to files within the script. You will need to rewrite these to use Yii routing. Fortunately, inside the main file dialog.php you should have access to all the normal Yii functions, so you can set $baseUrl as $this->createUrl() etc. If you need to add extra actions to the controller you can follow the pattern above to call other files, like the upload.php file in the script.
Hope that all works for you!
You are using a Framework with mvc pattern so controllers are preferred way to route requests .As per your problem i would suggest you to use htaccess file to do the routing to the required file and handle other files by Yii
copy code from existing source to new Yii Controler/Action ... done :D

Module Login on article Joomla 2.5

I created an article on joomla and I'd like to display a part for all(public) and another part of article only for registered users. Now I create a module that I integrated on article page, but I'd like to display the login.
Alternatively I can create 2 page: a login page that redirect to the my registered article. How can I do this?
Thanks
Or just use the built in show unauthorized feature that shows the intro but not the body to users who do not have authorization to see the article. YOu can set this globally or article by article or with a menu link.
For the login module, what you can do is, define a custom position for it by typing one in, rather than selecting one of the predefined ones, then embed it by using the following code:
{loadposition xxx} //xxx being the position you defined
Or, you can use an extensions from the Content Restriction category on JED to restrict content.
Personally, I think Hider might be your best choice, as it allows you to defines specific groups and specific content.
Alternatively, you can do it this way. Firstly, download and install Sourcerer which allows you to use any code in your articles. Then use the following code inside your article and be sure to use the {source} tags:
{source}
$user = JFactory::getUser();
if ($user->guest) {
echo "some content";
echo "Login to read more";
echo "{loadposition xxx}";
}
else {
echo "all content";
}
{/source}

Is there a way of adding a quick link on the administration page to a module's configuration?

Is it possible to add a link on the top menubar of the Administration page (Catalog, Orders, Customers...) going straight to a module's configuration page? I've inherited a large module with a ton of messy code that I'd really like to leave be, if at all possible.
The only requirement is that its configuration has to be accessible from that menu bar in particular (or, if there's no other possible option, from the quick links section; this one in particular can easily be achieved, except for the token part).
EDIT: I managed to pull it off by creating an Admin controller, but I am having issues generating the correct access token. I do not really know what to do to fix it and, as such, I am hereby launching (yet another) bounty.
Here's the code I am using for the redirect:
<?php
class AdminMultiBlockController extends AdminController
{
public function __construct()
{
global $cookie;
// this doesn't really work
$tab = 'adminmodules';
$token = Tools::getAdminToken($tab.(int)(Tab::getIdFromClassName($tab)).(int)($cookie->id_employee));
Tools::redirectAdmin('index.php?controller=adminmodules&configure=egr_MultiBlockSlider&token=' . $token);
}
}
My workaround was to force a working token, but this won't do.
What am I doing wrong? What parameters should I put inside the getAdminToken() function in order to successfully access a module's configuration?
I am currently using Prestashop v1.5.1.
Cheers guys!
Not being able to reproduce the problem, I can only guess.
However, try with the following code:
$url = 'index.php?controller=AdminModules&configure=egr_MultiBlockSlider';
$url .= '&token='.Tools::getAdminTokenLite('AdminModules');
Tools::redirectAdmin($url);

How can I display Joomla modules within a component?

I have a component with several categories of games and I want to display a different banner depending on the category. I need the banner (and link) to be customizable so it's not simply a case of showing categoryX.jpg or whatever.
I saw this Joomla help page on another question, but it only seems to display a module type, not one specific module. I'd like to use various mod_custom modules and display the one appropriate to the category (I can store each module's ID if necessary).
Any ideas?
This can be done in a 2 step process:
Use the "Load module into article" plugin to allow yourself to access the module using a plugin call like:
{module [*mod_id*]} // where *mod_id* is the module id
Now that you can call a plugin to put your module anywhere, you now need to go to the view code of your/a component you wish to add the module to and add this code:
echo JHTML::_('content.prepare', '{module [*mod_id*]}');
Please see this link - http://www.alltogetherasawhole.org/group/developers/forum/topics/running-joomla-content-plugins - regarding point number 2. I was trying to do the same thing and I found it didn't work, and the reason for this was a comment you can find on the page link above:
"I noticed that some plugin actually expect option=com_content for them to process onPrepareContent properly, so you might actually want to "fool" them by callin JRequet::setVar and restoring the correct values after the trigger."
If you would like to show module within PHP code then use this code, it's worked for me :
<?php echo JHTML::_('content.prepare', '{loadposition position-2}'); ?>
If you want to show module inside html content then just put this code where you want to show module.
{loadposition position-2}
It loads all modules which are assigned to position-2.
You can also use the Joomla Module Renderer
$doc = JFactory::getDocument();
$renderer = $doc->loadRenderer('modules');
$position = 'custom_position_name';
$options = array('style' => 'raw');
echo $renderer->render($position, $options, null);
Just a heads up, Along with being assigned the module position, that module also has to be set to "Display on All pages".
Joomla has this functionality built in. You can use the {loadposition XX} command within your content items. You can specify custom module positions that do not appear in your template to insure that you have the correct module in the correct article.
http://docs.joomla.org/How_do_you_put_a_module_inside_an_article%3F
You could create a new module?
If each category appears in the querystring (catid=X) then you could take a similar approach to https://support.pillwax.com/open-source/doku.php?id=joomla:header_image.
Alternatively, that link might actually do it for you.

authentication in CodeIgniter

in the project I'm creating I need to check if the user is logged in or not, the tutorials I have seen do explain how to authenticate in the controllers and give access to a page or not. But I want all the pages to be visible to everyone but only show certain options if a user is logged in or not.
something like this in the views
if(is_logged_in()):
//some options here
else:
echo "you need to login to have more options";
endif;
so where should I add this code? in the helper folder?
EDIT: I'm now checking in the views like this, it works but I don't know if it's a best practice. The 'is_logged_in' is something I set to true when the credentials were validated
if($this->session->userdata('is_logged_in'))
EDIT:
so if I make a helper to call that function. Can I check using the userdata function?
this is the function that creates the session
$data = array(
'username' => $this->input->post('username'),
//usertype toevoegen hier
//email toevoegen
//deposit money
'is_logged_in' => true
);
$this->session->set_userdata($data);
How could I used the session data in the function in my helper file?
If you want to have it as a stand-alone function that you can call from anywhere then you are best making it an helper. It might be helpful to think of helpers as the blades of a swiss army knife in your CodeIgniter toolbox.
That way you can change your checks later, move things all around, and still be making calls to isloggedin(). However, both ways work. $this->user->isloggedin() is slightly more verbose, but presents the same useful separation of concerns.
EDIT:
If you want to make calls to your session data in a helper, the way to do that is via get_instance().
In the beginning of your helper file, do this: $CI =& get_instance();
function user_logged_in() {
$CI =& get_instance();
// Do what you want to do with session.
// Simply replace $this->session ... etc. with
// $CI->session ... etc.
...
}
It would be fine to add it into the view, and this is presentation logic.