E107: Extending core functionality - e_ addons

Created on 5 Jul 2017  路  20Comments  路  Source: e107inc/e107

In version 2 there is only limited list of e_ addons that can be used. There were other addons too in version 1 - e_gold for example.

How someone can get other e_ files loaded to plugin table (or checked in plugin check) than core e_ files?

Why not are all e_ files loaded as addons? How this works?

question

Most helpful comment

Funny you should mention e gold. Im just about to start work on converting to version 2, initially making sure they all work. I will take note of the comments above and Cam, would you want e_gold.php or gold_add.php (for example).

All 20 comments

The reason for this is:
1) So that all e_xxxx files follow the correct specifications. (some in the past didn't, and we were stuck with trying to keep them functional for the sake of other plugins using them)
2) We control what is expanded and what is not - which means less security issues.

This was 'open' before the age of github, so requesting new e_xxxxx options via an 'issue' and with enough support a pull-request. This is the correct way to go about it at this time.

Understable. Ok. So for plugin development only solution is to check if file e_xxx exists in plugin folder. Maybe to use file name without e_ would be better idea to avoid confusing why file is not loaded to plugin table.
Thanks

Funny you should mention e gold. Im just about to start work on converting to version 2, initially making sure they all work. I will take note of the comments above and Cam, would you want e_gold.php or gold_add.php (for example).

@G4HDU How did you decide to call it? My idea: pluginname_addon.php Then only way I found is to load it this way. Any better idea? Thanks

        $plugins = array_keys(e107::getConfig()->get('plug_installed'));

        foreach ($plugins as $plugin)
        {
            if(is_readable(e_PLUGIN.$plugin.'/gsitemap_addon.php'))
            {
                require_once (e_PLUGIN.$plugin.'/gsitemap_addon.php');
            }
        }

@Jimmi08 I might be a little offside, but i think there's a simpler way, at least that's what i'm using:

if (!e107::isInstalled('phil_cat'))
{
        $msg = e107::getMessage();
        $msg->warning('Falta instalar o plugin necess谩rio em falta! Aborting...');
  if (ADMIN == TRUE) {
        $msg->error('Falta instalar e configurar o Plugin Phil Catalogue!!!');
  }
}

e107::isInstalled('plugin_name')......

You get it wrong. Addons work different way. In plugin with addon support you are loading setting from other plugins that are supporting this addon. For example you can extend gold plugin with your own plugin but adding e_gold setting. In my case I need extend gsitemap plugin (not core) with other custom plugin to import links to gsitemap. Maybe this is solution of your question how extend one plugin by other one. Sorry, on mobile. Pity there is no documentation, only working example is gold plugin.

Just for testing I have been using e_gold.php but happy to go with, say, gold_add.php I will set it up on Github what I've done with the admin config to scan and manage e_gold.php.

Have to wait until I get up, it is 02:15 here

@G4HDU Leave it as e_gold.php. gold_add.php is like file for add new record for me.

@G4HDU If your plugin is called 'gold' then it should be e_gold.php ie. e_{pluginfolder}.php

This is how I have structured the class so far, is it ok or am I up the wrong route

`
class plugin_addressbook_gold_class extends gold_class
{

static private $goldInfo = array(
    'gold_plug_name' => 'addressbook',
    'gold_plug_version' => '2.0.5',
    'gold_plug_author' => 'Barry Keal G4HDU',
    'gold_plug_depends' => '');


function __construct($parent)
{
    $this->parent = $parent;
}
static public function getInfo() {
    return self::$goldInfo;
}

... rest of class
`

Then in the gold system admin config scan for e_gold.php we have in the admin ui

` function scanGoldPage()
{
require_once (e_HANDLER . 'file_class.php');
$fred = new e_file();
$fred->setMode('all');
// echo e_PLUGIN_ABS;
$files = $fred->get_files(e_PLUGIN, 'e_gold.*', 'standard', 2);
print_a($fred->getErrorMessage());
foreach ($files as $file) {
$this->processEGold($file);

    }
    $this->message->addInfo($this->updated . " plugins updated");
    $this->message->addInfo($this->inserted . " plugins inserted");
    $this->message->addInfo(($this->unchanged - $this->updated - $this->inserted) .
        " plugins unchanged");
    //  print_a($files);

}
function processEGold($file = array())
{


    $filePath = $file['path'] . $file['fname'];
    //   print_a($filePath);
    require_once ($filePath);

    // get filename
    $path_parts = pathinfo($filePath);

    if ($path_parts['extension'] === 'php') {
        $dirArray = array_reverse(explode('/', $path_parts['dirname']));
        $dirName = $dirArray[0];
        $className = 'plugin_' . $dirName . '_gold_class';
        if (class_exists($className, false)) {
            $this->unchanged++;
            $info = $className::getInfo();
            //print_a($info);
            // var_dump(e107::isInstalled($dirName));
            $qry = "SELECT * from #gold_system_plugins WHERE gold_plug_name ='" . $info['gold_plug_name'] .
                "'";
            if (e107::getDB()->gen($qry, false)) {
                // the record exists check if any fields have changed
                $row = e107::getDB()->fetch('assoc');
                //    print_a($row);
                //    print_a($info);
                $pluginstalled = (e107::isInstalled($info['gold_plug_name']) ? 1 : 0);

                if (trim($info['gold_plug_version']) !== trim($row['gold_plug_version']) || trim
                    ($info['gold_plug_author']) !== trim($row['gold_plug_author']) || trim($path_parts['dirname'])
                    !== trim($row['gold_plug_path']) || trim($pluginstalled) != trim($row['gold_plug_installed']) ||
                    trim($info['gold_plug_depends']) !== trim($row['gold_plug_depends'])) {
                    $qry = "UPDATE #gold_system_plugins SET
                        gold_plug_version = '" . $info['gold_plug_version'] .
                        "', 
                        gold_plug_author = '" . $info['gold_plug_author'] .
                        "', 
                        gold_plug_path = '" . $path_parts['dirname'] . "',
                        gold_plug_installed = '" . $pluginstalled . "',
                        gold_plug_depends = '" . $info['gold_plug_depends'] .
                        "' WHERE
                        gold_plug_name = '" . $info['gold_plug_name'] . "'";
                    if (e107::getDB()->gen($qry, true)) {
                        $this->updated++;
                        $this->message->addSuccess("Updated " . $info['gold_plug_name']);
                    } else {
                        $this->message->addError("Unable to update " . $info['gold_plug_name']);
                    }
                }

            } else {
                $qry = "INSERT INTO #gold_system_plugins 
                (gold_plug_name,
                gold_plug_version,
                gold_plug_author,
                gold_plug_path,
                gold_plug_installed,
                gold_plug_depends) VALUES (
                '" . $info['gold_plug_name'] . "',
                '" . $info['gold_plug_version'] . "',
                '" . $info['gold_plug_author'] . "',
                '" . $path_parts['dirname'] . "',
                '" . $pluginstalled . "',
                '" . $info['gold_plug_depends'] . "') 
                ";
                if (e107::getDB()->gen($qry, true)) {
                    $this->inserted++;
                    $this->message->addSuccess("Added " . $info['gold_plug_name']);
                } else {
                    $this->message->addError("Unable to add " . $info['gold_plug_name']);
                }
            }


        }

`

Auto add to the gold plugins table also done when a plugin is installed in plugin_setup.php

Comments, observations and criticisms please guys before I screw up e107 !!!!!

@Jimmi08 Sorry, as i stated, i was (and i'm still) a little offside.

Anyway, just my two cents:
Your function might be a candidate for a core e107 function, just like e107::isInstalled....
What do you think?

@G4HDU Just curious, what's the purpose of the gold system (still offside...... 馃挮 )?

The gold system is a reward system. Collect gold for forum posts, your birthday, comments, win gold in a lottery, playing higher or lower. The gold can then be spent on presents for others, orbs, posh avatars, fancy effects on your name etc. Also we had a tamagochi type pet you could buy you need to purcase food for it, pay vet bills etc.

It was originally designed by somebody else but he abandoned it. I was asked to pick up the pieces and just got carried away adding to it. Needs a complete rewrite for version 2. Its purose is to encourage greater participation in the web site.

I saw this plugin to use as "credit" system, you can buy golds (paypal) or get them by your activity or get them as gift. Or maybe I mistake it with shop plugin... But I saw e_gold.php extension for download plugin too. Ans aacgc,com has a lot of plugins with this extention.

@G4HDU that code is in gold plugin admin section? And each plugin needs to have 'plugin_' . $dirName . '_gold_class' class inside e_gold.php. I hope I get it.

@rica-carv it would be pointless, code is old, I just use arrays, not classes. gsitemap works with arrays too... I just instead of hardcoded arrays (news, pages, forum) moved it to e_ file. This is not correct way how to do it, it's just solving actual need.

@G4HDU It looks more like a "sitewide" gold stockpile game..... I can see the positive, and also the drawbacks, but anyway, it's another ideia...

@G4HDU

For e_gold.php, I would work from e_cron.php as your guide. Use the config() method as the default setup with names, meta and function names.

For your admin, let e107 do the scanning (which it will do during plugin install), it will be MUCH faster, because it will use the global pref instead of scanning through files and directories every time someone visits your admin area. .

e107::getAddonConfig('e_gold'); should return an array with all plugins and their config data.
Take that data and call methods as needed.

For your testing purposes, you'll need to modify the addon list in plugin_class.php so that it checks for "e_gold"

@CaMer0n Works like charm. Just it was needed to add at 3 places in plugin_class.php. Thank you

@Jimmi08 @G4HDU If e_gold has been implemented correctly by the plugin, I'll be happy to receive a pull-request with e_gold added to the plugin_class.php file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jimmi08 picture Jimmi08  路  5Comments

CaMer0n picture CaMer0n  路  4Comments

Jimmi08 picture Jimmi08  路  5Comments

rica-carv picture rica-carv  路  5Comments

MaDDoG9x9 picture MaDDoG9x9  路  4Comments