Opencart how to test if vqmod installed? - php

I have written a module that uses vqmod for opencart. How can I check if vqmod is installed from within the admin module?
I would like to display a warning inside of the module that checks if vqmod is installed? Even better would be to check if it also has correct write permission to generate cached files and write to the vamod.log
What is the best way of doing this?
PS: it would be cool if you could tag questions with vqmod. I dont have enough reputation to create a new tag.

/vqmod/install
if it is installed it will tell you "vqmod is already installed"

<?php
if(class_exists('VQMod')) {
// vqmod exists
}
?>

To check via code, you would need to do
global $vqmod;
if(!empty($vqmod) && is_a($vqmod, 'VQMod')) {
// INSTALLED
} else {
//
}
While #NADH's is along the right lines, it only checks that vqmod's class has been included, not that it's been set to the $vqmod variable
Edit
As of 2.4.0, this will no longer work, and it's recommended to use NADH's method

Based on your comments #John, since you're looking for confirmation that VQmod is installed and also executing correctly, the safest thing to do to is check for the filename you are expecting to appear in the vqmod/cache directory. You'll know the filename if you have created the vqmod/xml definition file yourself.
You could also check for the VQMod class existing like #NADH suggested, but it doesn't mean that its working correctly. A bit like writing unit tests, always assert on the desired output. In this case its' the cache file you are creating.

Related

Having PHP site point to a different path than one that is in the code

I am running a PHP site on Windows using Wampserver. All throughout the site there is a hardcoded line such as:
$settings = parse_ini_file("/usr/local/apache2/myconfigs/settings.ini", true);
I know this is bad practice to begin with but it is out of my control.
When the site runs is there any possible way I can trick the site to point to C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini whenever the code is looking for /usr/local/apache2/myconfigs/settings.ini in the parse_ini_file function?
$settings = parse_ini_file(APACHE_INI_PATH, true);
// $settings = parse_ini_file("/usr/local/apache2/myconfigs/settings.ini", true);
This is a bit hackish but I think it's what you are looking for, so the trick here is to redefine the parse_ini_file function and make it ignore the invalid passed path ("/usr/local/apache2/myconfigs/settings.ini") and use your correct file instead.
This seems straightforward but a bit tricky since your new function should also call the original parse_ini_file function somehow, that's why you need to rename it first then override it
You will need PHP runkit extension enabled for this, have look at runkit_function_redefine and runkit_function_rename for reference.
Untested but should work, the code should be something around these lines :
runkit_function_rename('parse_ini_file','original_parse_ini_file');
runkit_function_redefine('parse_ini_file', function() {
original_parse_ini_file("C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini", true);
});
Make sure the code above is executed at the start of your application script and any parse_ini_file call should use your file instead of the hardcoded one.
If there is no single entry point to your application where you can put the code above, you can put it in a separate script and make PHP load before running any script via the auto_prepend_file setting in your settings.ini file, also make sure that runkit.internal_override is set to On since parse_ini_file is not a user defined function.
Hello please check this
runkit_function_rename('parse_ini_file','o_parse_ini_file');
runkit_function_redefine('parse_ini_file', function($p1,$p2) use($someCondition) {
if($someCondition)
o_parse_ini_file("C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini", true);
else
o_parse_ini_file($p1,$p2);
});
it can return
Call to undefined function runkit_function_rename()
to fix this error please read here
or here
If you don't want to do a find and replace as suggested by #cddoma, I propose that you create the directory /usr/local/apache2/myconfigs/ in your windows machine, and copy the file settings.ini from C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini to that directory.
Open your windows command line and enter the following
mkdir C:\usr\local\apache2\myconfigs\
copy C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini C:\usr\local\apache2\myconfigs\
you may be able to do this with a Symbolic link on Windows

How to wp_dequeue_script or wp_deregister_script jquery (not effected) file from wp theme

NOTE: I already use wp_dequeue_script or wp_deregister_script but not successfull
Here is the scenario, i make a image slider plugin that use jquery-cycle2 and it work successfully.
There is a user who used a wp theme and in theme there is a jquery-cycle1, now when he install my plugin the jquery-cycle1 and jquery-cycle2 conflicts, when user delete the jquery-cycle1 file all things work fine and perfectly but i don't want to delete file by user.
Now i am trying that when user install my plugin the jquery-cycle1 in theme close or deregister or stop its effect.
I get file from theme successfully
if((file_exists($theme_file_path."/jquery.cycle.all.js"))){
echo "yes";
}
but i have no idea to close jquery-cycle1 file or stop its effect.
Last Option: I have last solution that delete the file from theme but its my last option.
Please any suggestions, help me.
You will have to place an incompatibility notice on your theme.
It is not possible to attempt to detect the existence of script from server side. You are able to detect queued scripts via the word press methods, however, this assumes that the user has not simply linked the file with a <script></script> tag. The file_exists method assume the file is stored on the server itself - it could be linked from a CDN or another server.
Also, whatever methods you use to detect and remove jQuery-Cycle; You are going to break any feature on the site that uses the existing plugin.
Thus, any solution you able to devise would either be extremely complicated, or would not be generalised enough to account for all these possibilities.
You may be able to use the following to prevent loading your script
if (jQuery().cycle) {
// Script already loaded
console.log("Error: Another version of jQuery-Cycle is already loaded!");
} else {
// Load your script
}
but this cannot unload what is already loaded.
There is a simple hack you can do on you end. In the Cycle2 source replace all $.fn.cycle with $.fn.cycle2 and ).cycle( to ).cycle2(.
I am using the source from here http://malsup.github.io/jquery.cycle2.js
After that You can access it like
$("#id").cycle2({option})
Here is a demo http://jsfiddle.net/33g6z79h/
Here i assume that you are not using cycle events http://jquery.malsup.com/cycle2/api/#events
and cycle extra transitions.
If you are using it you can make a fiddle for your cycle2 implementation and i would be glad to help :)

PHP include code for if file exists and what to do if it doesn't

Long ago, this code used to work but now it seems something is going on preventing it from functioning properly. I'm hoping somebody can tell me whats going on. I'm concerned upgrades to PHP have killed this code. Or has it?
I use this code (posted below) to check and to see if an html file exists, and if it does it'll use it. If not, it will use the file index2.html.
<?php if ((file_exists("$id.html")) == true) { require ("$id.html"); } else { require ("index2.html"); } ?>
I use this code on my homepage, index.php. However for some odd reason, when I type in a link: example: index.php?id=exampleurlhere, the code isn't checking to see if the file exists and is automatically using the index2.html file, despite my code telling that if the file exists (which it does), then it's required to use it. Why is it now ignoring my command?
Been using this code for years and never had any problems with it until recently it seems. Any suggestions to fix it?
I think the problem lies in the "register_globals" setting. This used to be on by default in the (very) older versions of PHP, but has been removed in the newer versions, as this caused a lot of variable injection attacks in the old PHP.
Your $id came directly from the value in the URL. Now that it no longer auto registers, you can add in a line "$id=$_GET['id'];" just above that line to get it to work again.
This is just a quick fix. I suggest you rewrite the program so that there will not be any change of users accessing files illegally using the URL.

Vtiger Custom Module : "Sorry! Attempt to access restricted file."

I have created a test module name Mytest. While saving values from the module, I am getting a blank page and it saying "Sorry! Attempt to access restricted file. " . Do anyone know, why this happening. Any help on this is really appreciating.
The most likely cause for the vTiger error “Sorry! Attempt to access restricted file.” is the $root_directory value in the ‘config.inc.php’ is incorrect or misspelled.
In order to correct it follow the steps below:
Go to your vTigerCRM directory
Open “config.inc.php” with your favorite text editor
Go to line 86 and adjust $root_directory value to correct vTiger
directory. Note, that the directory must end with /. It should look
something like this – $root_directory = ‘/var/www/vtigercrm/’;
Also there is a problem with cache memory. So do check your cache file for template files. For that go to your vTigerCRM directory.
Then Go to Smarty->templates_c.
Here you will get list of cache files. Delete this file and check weather your problem is solved or not.
Don't worry about deletion of this file.
When trying to include files from your custom module, you will get these messages because Vtiger thinks you are including these files from a location they find rather unsafe.
To avoid this error you could use the standard way a module is used in Vtiger by navigating to it like so: ......./index.php?module=Mytest&action=index. Vtiger will include your module and now there is no need for you to include CRMEntity and other data or utils related files. It should all be available this way but make sure you are using the global statement for $current_user, $current_module etc though.
Another way is to edit the following functions located in utils/CommonUtils.php:
heckFileAccessForInclusion() and checkFileAccess()
Remove or comment out the die() in these functions to fix it.
In Save.php file, just add a line.
$focus->column_fields['assigned_user_id'] = '';
before the
if($_REQUEST['assigntype'] == 'U') {
$focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_user_id'];
} elseif($_REQUEST['assigntype'] == 'T') {
$focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_group_id'];
}
To second what caspersky said:
Go to /include/database/PearDatabase.php and add
$adb->setDebug(true); right after $adb->connect();
I just wrote a module and received this error and it was because the record could not save because I left out:
$moduleInstance->setEntityIdentifier($fieldInstance);
Check out file permissions and file path it's trying to refer.
If you want to debug more set $adb->setDebug(true) in your index file and checkout for the errors.
A couple of things spring to mind:
Have you actually created the modules/CustomeModule directory and populated
it? (Using the template in vtlib/ModuleDir/5.4.0 and then editing the
filenames and class of CustomeModule.php)
Check the case of your module class definition, e.g. class CustomeModule
vs. class Customemodule
If you are using any version control or symlinks in the development
of your modules/Mytest code then this can trigger the "Sorry! Attempt
to access restricted file." messages.
In module setup script make sure you have added this lines.
$module->initTables();
$module->initWebservice();
Check that all language files exist.
The user module allows the admin user to configure a user's language even though the language file is not present on disk.
To quickly verify this is indeed the issue :-
- Edit the include/utils/CommonUtils.php and print the $realfilepath variable ,and comment out the die();
- In the database, "select distinct language from xxx_users";
You can fix this by downloading the required files.
As a quick fix (read:hack):-
- go to the include/language directory
- copy an existing language file as the required one. (may not always work - for example en_us to en_gb is great, but en_us to sp_es is not)
It seems you did not set write permission for Smarty folder
Probably a file is missing in your vtiger install.
To find out which one is mission you would need to edit the include/utils/CommonUtils.php file. Open it with a text editor, go around line 2755 and add the following
echo “REAL: $realfilepath, ROOT: $rootdirpath”;
Before die(Sorry....)
This would print on the screen which one is the missing file.
Sometimes this error is caused by an nonexistent module, what I mean here is that vtiger thinks you have a module but the files are not in there (might be caused by a bad migration to a new server).
Disable some modules and try again until you find which module is broken.
In my case the broken module was VGS.
I solved this on vtiger 7.3.. (maybe it works for other vesion)
I went to users permission on vtiger inside configuration settings and update tham all again with the same settings .. and got them to a more default settings .. them all users appeared back and I was able to create new users ..change password again.
I suggest logging out and maybe forcing refresh and waiting a little to make it work .

custom php function creation and install

I would like to know how to create a php function that can be installed in php
just like the already built in functions like :
rename
copy
The main point I would like to achieve is a simple php function that can be called from ANY php page on the whole host without needing to have a php function within the php page / needing an include.
so simply I would like to create a function that will work like this :
location();
That without a given input string will output the current location of the file via echo etc
Well, there are a couple of options here. One of them is to actually extend the language by writing an extension. You'd have to muck around with the PHP source code, write it in C, and deal with the Zend Engine internally. You probably wouldn't be able to use this on a shared host and it would be quite time consuming and probably not worth it.
What I would do is put all of your functions into a separate PHP file, say helper_functions.php. Now, go into your php.ini and add the directive: auto_prepend_file = helper_functions.php. This file should be in one of the directories specified in your include_path (that's a php.ini directive too).
What this does is basically automatically put include 'helper_functions.php'; on every script. Each and every request will have these functions included, and you can use them globally.
Read more about auto_append_file.
As others have said, there's probably an easier, better way to do most things. But if you want to write an extension, try these links:
http://docstore.mik.ua/orelly/webprog/php/ch14_01.htm
http://www.tuxradar.com/practicalphp/2/3/0
So you want to extend PHP's core language to create a function called location(), written in C, which could be done in PHP by:
echo __FILE__;
Right. Have fun doing that.

Categories