pligg add module to story - php

in pligg adding new modules to the the main pligg template pligg.tpl is quite straight forward, however, i want to add a new module to the story. located in link_summary.tpl. the problem is that when the link summary template is created, a new variable $main_smarty is created with it's own local scope, not available to my modulename_main.php file. when I use the global $main_smarty variable, it refferences the main pligg template smarty object. So i have used to quick and somewhat dirty fix to the main architecture php code, to the link.php file I added a new call back:
$vars = '';
check_actions('add_to_summary', $vars);
and then created a new global variable refferencing the $main_smarty object in the link.php file, which i then used in my modulename_main.php
global $link_smarty;
global $link_variables;
$link_variables = $this;
$link_smarty = $main_smarty;
is there a more native, proper and cleaner way of doing this without tweaking the main architecture pligg code?

Not sure if this would be helpful.
An alternative way would be to write a new module and assign it to that particular page, in your case link_summary.
As you know, each module has an init file, something like your_module_init.php. In your case the init file would be similar to:
<?php
if(defined('mnminclude')){
include_once('your_module_settings.php');
$include_in_pages = array('link_summary');
$do_not_include_in_pages = array();
if( do_we_load_module() ) {
module_add_action('');
include_once(mnmmodules . 'your_module_name/your_module_main.php');
}
}
?>
Cheers,

Related

How to change a Wordpress core DB function without editing core files?

I have been fighting with this problem for several days now & I would appreciate input from (PHP / Wordpress) developers that are more experienced than me.
I'm making a debugging plugin for Wordpress, but one of the errors that I need to change comes from this file:
/site/public/wp-includes/wp-db.php
I need to change the structure and add more information to the $error_str in lines 1363 and 1366 so the output better suits our log reader and contains more useful information.
To do that I think I need to change the print_error() in line 1344
The problems are:
That the file is a core file in Wordpress, so I can't edit it directly.
It also have a global $wpdb variable that is used to call: $wpdb->query() & $wpdb->get_row() (also core functions in same file & class) that both in turn calls the print_error() function.
Other plugins are using these functions & I can't mess up their functionality but I should change their output too.
I think the most likely solution is to inherit & override the print_error() (and maybe also query() & get_row() so I can re-direct them to my new print_error()), but other plugins are using the $wpdb & those functions, I can (should) change the error_log() output for those plugins too, but I can't edit those plugins either & I can't mess them up with a faulty solution.
Questions:
How can I replace the print_error()?
What is the best way to do this?
How do I deal with the global $wpdb variable?
Do any of you have a better solution? I would very much appreciate it.
Link to the print_error() documentation (with source code):
https://developer.wordpress.org/reference/classes/wpdb/print_error/
Link directly to the source code: https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-includes/wp-db.php#L1344
Not entirely sure this is an excellent idea, but you could extend the wpdb class and replace the global $wpdb object.
E.g.
global $wpdb;
$wpdb = new YourWpdbClass(); // you can override methods here to your heart's content
wp_set_wpdb_vars();
Officially, the way to replace the global $wpdb is by creating a db.php file inside wp-content. So if you plugin needs to alter db functionality it would need to include that file and possibly custom installation instructions

Include generic testcase in codeception

I have multiple similar websites that I want to test. Here's the current approach:
Clone an existing codeception project
Adjust the variables
Add some additional specific test cases if required
This works just fine, but has one issue. If the general test case changes that means that I have to go into every project and make the changes. So what I would rather see is a way to include a generic top level test case in every project and call it with a parameter.
I tried so with a simple include() statement, but unfortunately this doesn work. And ideas how I can accomplish this?
Here some code of my initial try:
/home/tests/site1/tests/acceptance/isOnlineCept.php
include("../1generic_tests/isonline.php");
$I = new AcceptanceTester($scenario);
$I->am('user');
$I->wantTo('see the content of the site');
$I->lookForwardTo('see the homepage');
$I->amOnPage('/');
$I->see("Tech, Geek and Rock'n'Roll");
The file I include looks like this
$I = new AcceptanceTester($scenario);
$I->am('user');
$I->wantTo('see the content of the site');
$I->lookForwardTo('see the homepage');
$I->amOnPage('/');
$I->see('something else');
Unfortunately it fails with this error
[PHPUnit_Framework_Exception] Undefined index: class
Maybe include is not the right way to do it, but what would be a better way?
You can use Page Object for this.
Create one Constants.php file using Page Object where you can define all the selectors.
Create one other file where you can keep all common operation going to be performed. E.g. Settings.php file where you can have all methods as per your requirement. you can define it with parameter too.
To access any selector and/or method from declared under page dir can be accessible by using the following line.
use Page\Constants as ConstantsPage;
To access any selector from any specific file
FileNamePage::$selectorName;
To access any method, first create the object and then call the method.
E.g.
$settings = new SettingsPage( $I )
$settings->methodName();
To call the method and/pr selector in the same file.
self::selectorName;
self::methodName();
Hope this will be helpful.

Pimcore custom classes

I wrote custom classes and want to use them in pimcore application.
I took them to /website/lib/Custom directory on server. Afterwards, I wrote recursive script includer for each Class located in the directory and included that script in /index.php file.
It is absolutely not pimcore standard but it works.
In pimcore/config/startup.php exists snippet:
$autoloaderClassMapFiles = [
PIMCORE_CONFIGURATION_DIRECTORY . "/autoload-classmap.php",
PIMCORE_CUSTOM_CONFIGURATION_DIRECTORY . "/autoload-classmap.php",
PIMCORE_PATH . "/config/autoload-classmap.php",
];
$test = PIMCORE_ASSET_DIRECTORY;
foreach ($autoloaderClassMapFiles as $autoloaderClassMapFile) {
if (file_exists($autoloaderClassMapFile)) {
$classMapAutoLoader = new \Pimcore\Loader\ClassMapAutoloader([$autoloaderClassMapFile]);
$classMapAutoLoader->register();
break;
}
}
I guess that this provides inclusion of all those classes put into returning array from autoload-classmap.php.
Having in mind that /pimcore/config/autoload-classmap.php exists, the mentioned loop would break at first iteration so classes that I would put into custom autoload-classmap are not going to be included in project.
My question is can I change files from /pimcore directory and expect that everything would be fine after system update?
No, you should not overwrite anything in the pimcore directory, since the files in there get overwritten by the update mechanism.
You can do what you want by using the /website/config/startup.php which will not get overwritten:
https://www.pimcore.org/wiki/display/PIMCORE4/Hook+into+the+startup-process
But instead of loading all your classes as you did, take advantage of the autoloader by adding this to the /website/config/startup.php:
// The first line is not absolutely necessary, since the $autoloader variable already gets
// set in the /pimcore/config/startup.php, but it is a more future-proof option
$autoloader = \Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Custom');
If you are properly using namespaces and naming your files correctly that's all you need to do.

Joomla 3! Module Parameters

I have a Joomla website where I have a custom module with mod_myModuleName.php and mod_myModuleName.xml files and a folder where there are several PHP scripts that add special functionality to my module. There is a config.php file in the folder that holds an associative array with variables and their values hard-coded. The module works just fine.
What I want though is to provide administrator area for the values of the variables in the array, so that I can put values in administrator panel and get their values in config.php. In my mod_myModuleName.php I use <?php echo $params->get('param')?> and it works like a charm.
But when I try to use the same technique in the config.php it breaks my code. I tried to get the values in mod_myModuleName.php and then include it in config.php and use the variables but it does not work either. I have not got so much experience in php and cannot understand what can be the reason.
It sometimes gives me an error of something non object and I guess it must be something connected with object oriented php, am I right? And if so is there a way to overcome this without object orientation or how can I solve my problem?
The problem will be with the way you're using your config.php.
When your modules entry point file mod_myModuleName.php is loaded by Joomla the $params object is already available in that context, you need to provide it to your scripts.
If you look at something like the mod_articles_latest module you will notice that the helper class is included with this line:
require_once __DIR__ . '/helper.php';
And then helper class is has it's getList() method called statically with the $params passed into it, so that $params is available to class context:
$list = ModArticlesLatestHelper::getList($params);
Inside the helper class ModArticlesLatestHelper you will notice that the getList() expects the $params to be passed in.
public static function getList(&$params)
{
...
}
I would strongly recommend reading the articles in the Modules section of Developers Portal on the Joomla Doc's.
Try the "Creating a simple module" article.

PHP: Is this the correct way of using a function that is defined under a class?

I have a PHP class inside my Wordpress plugin that is activated in a website. I want to use a method (doc_export function) that is defined inside this class in another plugins (also activated in the same website). I add this one and it seems working:
<?php
// Export doc
if (defined('DOC_ADMIN_MODE')) {
$my_Documentation = new Class_Documentation;
$mydocexport = $my_Documentation->doc_export();
$mydocexport_file = ABSPATH . '_export/' . basename($site['site_url']) . '/doc.xml';
file_put_contents($mydocexport_file, $mydocexport);
}
?>
I want to know if this is the proper approach..Thanks.
Yes that's the proper approach. You can also read about the OOP basis in PHP at http://php.net/manual/en/language.oop5.basic.php

Categories