Example #1
0
 public function run()
 {
     Event::forge('Foolz\\Plugin\\Plugin::execute.foolz/foolslide-nginx-cache-purge')->setCall(function ($result) {
         /* @var Context $context */
         $context = $result->getParam('context');
         /** @var Autoloader $autoloader */
         $autoloader = $context->getService('autoloader');
         $autoloader->addClassMap(['Foolz\\Foolframe\\Controller\\Admin\\Plugins\\NginxCachePurge' => __DIR__ . '/classes/controller/admin.php', 'Foolz\\Foolslide\\Plugins\\NginxCachePurge\\Model\\NginxCachePurge' => __DIR__ . '/classes/model/nginx_cache_purge.php']);
         $context->getContainer()->register('foolslide-plugin.nginx_purge_cache', 'Foolz\\Foolslide\\Plugins\\NginxCachePurge\\Model\\NginxCachePurge')->addArgument($context);
         Event::forge('Foolz\\Foolframe\\Model\\Context.handleWeb.has_auth')->setCall(function ($result) use($context) {
             // don't add the admin panels if the user is not an admin
             if ($context->getService('auth')->hasAccess('maccess.admin')) {
                 $context->getRouteCollection()->add('foolslide.plugin.nginx_cache_purge.admin', new \Symfony\Component\Routing\Route('/admin/plugins/nginx_cache_purge/{_suffix}', ['_suffix' => 'manage', '_controller' => 'Foolz\\Foolframe\\Controller\\Admin\\Plugins\\NginxCachePurge::manage'], ['_suffix' => '.*']));
                 Event::forge('Foolz\\Foolframe\\Controller\\Admin.before.sidebar.add')->setCall(function ($result) {
                     $sidebar = $result->getParam('sidebar');
                     $sidebar[]['plugins'] = ["content" => ["nginx_cache_purge/manage" => ["level" => "admin", "name" => 'Nginx Cache Purge', "icon" => 'icon-leaf']]];
                     $result->setParam('sidebar', $sidebar);
                 });
             }
         });
         Event::forge('Foolz\\Foolslide\\Model\\Media::delete.call.before.method')->setCall(function ($result) use($context) {
             $context->getService('foolslide-plugin.nginx_purge_cache')->beforeDeleteMedia($result);
         });
     });
 }
Example #2
0
 public function handleWeb(Request $request)
 {
     $preferences = $this->context->getService('preferences');
     $config = $this->context->getService('config');
     $uri = $this->context->getService('uri');
     $theme_instance = \Foolz\Theme\Loader::forge('foolslide');
     $theme_instance->addDir($config->get('foolz/foolslide', 'package', 'directories.themes'));
     $theme_instance->addDir(VAPPPATH . 'foolz/foolslide/themes/');
     $theme_instance->setBaseUrl($uri->base() . 'foolslide/');
     $theme_instance->setPublicDir(DOCROOT . 'foolslide/');
     // set an ->enabled on the themes we want to use
     /** @var Auth $auth */
     $auth = $this->context->getService('auth');
     if ($auth->hasAccess('maccess.admin')) {
         Event::forge('Foolz\\Foolframe\\Model\\System::environment.result')->setCall(function ($result) use($config) {
             $environment = $result->getParam('environment');
             foreach ($config->get('foolz/foolslide', 'environment') as $section => $data) {
                 foreach ($data as $k => $i) {
                     array_push($environment[$section]['data'], $i);
                 }
             }
             $result->setParam('environment', $environment)->set($environment);
         })->setPriority(0);
         foreach ($theme_instance->getAll() as $theme) {
             $theme->enabled = true;
         }
     } else {
         if ($themes_enabled = $preferences->get('foolslide.theme.active_themes')) {
             $themes_enabled = unserialize($themes_enabled);
         } else {
             $themes_enabled = ['foolz/foolslide-theme-foolslide' => 1];
         }
         foreach ($themes_enabled as $key => $item) {
             if (!$item && !$auth->hasAccess('maccess.admin')) {
                 continue;
             }
             try {
                 $theme = $theme_instance->get($key);
                 $theme->enabled = true;
             } catch (\OutOfBoundsException $e) {
             }
         }
     }
     try {
         $theme_name = $request->query->get('theme', $request->cookies->get($this->context->getService('config')->get('foolz/foolframe', 'config', 'config.cookie_prefix') . 'theme')) ?: $preferences->get('foolslide.theme.default');
         $theme_name_exploded = explode('/', $theme_name);
         // must get rid of the style
         if (count($theme_name_exploded) >= 2) {
             $theme_name = $theme_name_exploded[0] . '/' . $theme_name_exploded[1];
         }
         $theme = $theme_instance->get($theme_name);
         if (!isset($theme->enabled) || !$theme->enabled) {
             throw new \OutOfBoundsException();
         }
     } catch (\OutOfBoundsException $e) {
         $theme = $theme_instance->get('foolz/foolslide-theme-foolslide');
     }
     $theme->bootstrap();
 }
Example #3
0
 public function run()
 {
     Event::forge('Foolz\\Plugin\\Plugin::execute.foolz/foolfuuka-plugin-dice-roll')->setCall(function ($result) {
         /* @var Context $context */
         $context = $result->getParam('context');
         /** @var Autoloader $autoloader */
         $autoloader = $context->getService('autoloader');
         $autoloader->addClass('Foolz\\Foolfuuka\\Plugins\\DiceRoll\\Model\\Dice', __DIR__ . '/classes/model/dice.php');
         Event::forge('Foolz\\Foolfuuka\\Model\\CommentInsert::insert.call.after.input_checks')->setCall('Foolz\\Foolfuuka\\Plugins\\DiceRoll\\Model\\Dice::roll')->setPriority(4);
         Event::forge('Foolz\\Foolfuuka\\Model\\Radix::structure.result')->setCall(function ($result) {
             $structure = $result->getParam('structure');
             $structure['plugin_dice_roll_enable'] = ['database' => true, 'boards_preferences' => true, 'type' => 'checkbox', 'help' => _i('Enable dice roll?')];
             $result->setParam('structure', $structure)->set($structure);
         })->setPriority(4);
     });
 }
Example #4
0
 public function run()
 {
     Event::forge('Foolz\\Plugin\\Plugin::execute.foolz/foolfuuka-plugin-geoip-region-lock')->setCall(function (Result $result) {
         /* @var $context Context */
         $context = $result->getParam('context');
         /** @var Autoloader $autoloader */
         $autoloader = $context->getService('autoloader');
         $autoloader->addClassMap(['Foolz\\Foolframe\\Controller\\Admin\\Plugins\\GeoipRegionLock' => __DIR__ . '/classes/controller/admin.php', 'Foolz\\Foolfuuka\\Plugins\\GeoipRegionLock\\Model\\GeoipRegionLock' => __DIR__ . '/classes/model/geoip_region_lock.php']);
         Event::forge('Foolz\\Foolframe\\Model\\Context.handleWeb.has_auth')->setCall(function ($result) use($context) {
             // don't add the admin panels if the user is not an admin
             /** @var Auth $auth */
             $auth = $context->getService('auth');
             if ($auth->hasAccess('maccess.admin')) {
                 $context->getRouteCollection()->add('foolframe.plugin.geoip_region_lock.admin', new \Symfony\Component\Routing\Route('/admin/plugins/geoip_region_lock/{_suffix}', ['_suffix' => 'manage', '_controller' => '\\Foolz\\Foolframe\\Controller\\Admin\\Plugins\\GeoipRegionLock::manage'], ['_suffix' => '.*']));
                 Event::forge('Foolz\\Foolframe\\Controller\\Admin.before.sidebar.add')->setCall(function ($result) {
                     $sidebar = $result->getParam('sidebar');
                     $sidebar[]['plugins'] = ["content" => ["geoip_region_lock/manage" => ["level" => "admin", "name" => 'GeoIP Region Lock', "icon" => 'icon-flag']]];
                     $result->setParam('sidebar', $sidebar);
                 });
             }
             $preferences = $context->getService('preferences');
             $context->getContainer()->register('foolfuuka-plugin.geoip_region_lock', 'Foolz\\Foolfuuka\\Plugins\\GeoipRegionLock\\Model\\GeoipRegionLock')->addArgument($context);
             /** @var GeoipRegionLock $object */
             $object = $context->getService('foolfuuka-plugin.geoip_region_lock');
             if (!$auth->hasAccess('maccess.mod') && !($preferences->get('foolfuuka.plugins.geoip_region_lock.allow_logged_in') && $auth->hasAccess('access.user'))) {
                 Event::forge('Foolz\\Foolframe\\Model\\Context.handleWeb.override_response')->setCall(function (Result $result) use($context, $object) {
                     $object->blockCountryView($result);
                 })->setPriority(2);
                 Event::forge('Foolz\\Foolfuuka\\Model\\CommentInsert::insert.call.before.method')->setCall(function (Result $result) use($context, $object) {
                     $object->blockCountryComment($result);
                 })->setPriority(4);
             }
         });
         Event::forge('Foolz\\Foolfuuka\\Model\\Radix::structure.result')->setCall(function (Result $result) {
             $structure = $result->getParam('structure');
             $structure['plugin_geo_ip_region_lock_allow_comment'] = ['database' => true, 'boards_preferences' => true, 'type' => 'input', 'class' => 'span3', 'label' => 'Nations allowed to post comments', 'help' => _i('Comma separated list of GeoIP 2-letter nation codes.'), 'default_value' => false];
             $structure['plugin_geo_ip_region_lock_disallow_comment'] = ['database' => true, 'boards_preferences' => true, 'type' => 'input', 'class' => 'span3', 'label' => 'Nations disallowed to post comments', 'help' => _i('Comma separated list of GeoIP 2-letter nation codes.'), 'default_value' => false];
             $result->setParam('structure', $structure)->set($structure);
         })->setPriority(8);
     });
 }
Example #5
0
<?php

\Foolz\Plugin\Event::forge('Foolz\\Plugin\\Plugin::execute.foolz/foolfuuka-plugin-gifsicle')->setCall(function ($result) {
    \Foolz\Plugin\Event::forge('Foolz\\Foolfuuka\\Model\\Media::insert.result.create_thumbnail')->setCall(function ($result) {
        if (!$result instanceof \Foolz\Plugin\Void || strtolower($this->temp_extension) !== 'gif') {
            // someone is already done with the image or it's not a gif
            return;
        }
        exec("gifsicle " . $result->getParam('full_path') . " --colors 256 --color-method blend-diversity" . " --resize-fit " . $result->getParam('thumb_width') . "x" . $result->getParam('thumb_height') . " --dither > " . $this->path_from_filename(true, $result->getParam('is_op'), true));
        // only change the result so it's not void
        $result->set('done');
    });
});
Example #6
0
<?php

use Foolz\Plugin\Event;
use Symfony\Component\Routing\Route;
require_once __DIR__ . '/functions.php';
require_once __DIR__ . '/controller.php';
Event::forge('Foolz\\FoolFuuka\\Model\\Context::loadRoutes#obj.afterRouting')->setCall(function ($result) {
    $obj = $result->getObject();
    foreach ($obj->context->getService('foolfuuka.radix_collection')->getAll() as $radix) {
        $obj->context->getRouteCollection()->add('foolfuuka.chan.radix.' . $radix->shortname, new Route('/' . $radix->shortname . '/{_suffix}', ['_default_suffix' => 'page', '_suffix' => 'page', '_controller' => '\\Foolz\\FoolFuuka\\Themes\\Fuuka\\Controller\\Chan::*', 'radix_shortname' => $radix->shortname], ['_suffix' => '.*']));
    }
});
// use hooks for manipulating comments
Event::forge('Foolz\\FoolFuuka\\Model\\Comment::processComment#var.greentext')->setCall(function ($result) {
    $html = '\\1<span class="greentext">\\2</span>\\3';
    $result->setParam('html', $html)->set($html);
})->setPriority(8);
Event::forge('Foolz\\FoolFuuka\\Model\\Comment::processInternalLinks#var.link')->setCall(function ($result) {
    $data = $result->getParam('data');
    $html = ['tags' => ['<span class="unkfunc">', '</span>'], 'hash' => '', 'attr' => 'class="backlink" onclick="replyHighlight(' . $data->num . ');"', 'attr_op' => 'class="backlink"', 'attr_backlink' => 'class="backlink"'];
    $result->setParam('build_url', $html)->set($html);
})->setPriority(8);
Event::forge('Foolz\\FoolFuuka\\Model\\Comment::processExternalLinks#var.link')->setCall(function ($result) {
    $data = $result->getParam('data');
    $html = ['tags' => ['open' => '<span class="unkfunc">', 'close' => '</span>'], 'short_link' => '//boards.4chan.org/' . $data->shortname . '/', 'query_link' => '//boards.4chan.org/' . $data->shortname . '/res/' . $data->query, 'backlink_attr' => 'class="backlink"', 'attributes' => ''];
    $result->setParam('build_url', $html)->set($html);
})->setPriority(8);
Example #7
0
<?php

require_once __DIR__ . '/controller.php';
\Foolz\Plugin\Event::forge('Fuel\\Core\\Router::parse_match.intercept')->setCall(function ($result) {
    if ($result->getParam('controller') === 'Foolz\\FoolFuuka\\Controller\\Chan') {
        // reroute everything that goes to Chan through the custom Chan controller
        $result->setParam('controller', 'Foolz\\FoolFuuka\\Themes\\Yotsubatwo\\Controller\\Chan');
        $result->set(true);
    }
});
Example #8
0
<?php

use Symfony\Component\Routing\Route;
require_once __DIR__ . '/functions.php';
require_once __DIR__ . '/controller.php';
\Foolz\Plugin\Event::forge('Foolz\\Foolfuuka\\Model\\Context.loadRoutes.after')->setCall(function ($result) {
    $obj = $result->getObject();
    foreach ($obj->context->getService('foolfuuka.radix_collection')->getAll() as $radix) {
        $obj->context->getRouteCollection()->add('foolfuuka.chan.radix.' . $radix->shortname, new Route('/' . $radix->shortname . '/{_suffix}', ['_default_suffix' => 'page', '_suffix' => 'page', '_controller' => '\\Foolz\\Foolfuuka\\Themes\\Fuuka\\Controller\\Chan::*', 'radix_shortname' => $radix->shortname], ['_suffix' => '.*']));
    }
});
// use hooks for manipulating comments
\Foolz\Plugin\Event::forge('Foolz\\Foolfuuka\\Model\\Comment::processComment.result.greentext')->setCall(function ($result) {
    $html = '\\1<span class="greentext">\\2</span>\\3';
    $result->setParam('html', $html)->set($html);
})->setPriority(8);
\Foolz\Plugin\Event::forge('Foolz\\Foolfuuka\\Model\\Comment::processInternalLinks.result.html')->setCall(function ($result) {
    $data = $result->getParam('data');
    $html = ['tags' => ['<span class="unkfunc">', '</span>'], 'hash' => '', 'attr' => 'class="backlink" onclick="replyHighlight(' . $data->num . ');"', 'attr_op' => 'class="backlink"', 'attr_backlink' => 'class="backlink"'];
    $result->setParam('build_url', $html)->set($html);
})->setPriority(8);
\Foolz\Plugin\Event::forge('Foolz\\Foolfuuka\\Model\\Comment::processExternalLinks.result.html')->setCall(function ($result) {
    $data = $result->getParam('data');
    $html = ['tags' => ['open' => '<span class="unkfunc">', 'close' => '</span>'], 'short_link' => '//boards.4chan.org/' . $data->shortname . '/', 'query_link' => '//boards.4chan.org/' . $data->shortname . '/res/' . $data->query, 'backlink_attr' => 'class="backlink"', 'attributes' => ''];
    $result->setParam('build_url', $html)->set($html);
})->setPriority(8);
Example #9
0
<?php

use Foolz\Foolslide\Model\Comment;
\Foolz\Plugin\Event::forge('Foolz\\Plugin\\Plugin::execute.foolz/patch_sopa_spoilers_2012')->setCall(function ($result) {
    $event = new \Foolz\Plugin\Event('Foolz\\Foolslide\\Model\\Comment.processComment.call.before');
    $event->setCall(function ($result) {
        return;
        /** @var Comment $post */
        $post = $result->getObject();
        // the comment checker may be running and timestamp may not be set, otherwise do the check
        if (isset($post->comment->timestamp) && $post->comment->timestamp > 1326840000 && $post->comment->timestamp < 1326955000) {
            if (strpos($post->comment, '</spoiler>') > 0) {
                $post->comment->comment = str_replace(['[spoiler]', '[/spoiler]', '</spoiler>'], '', $post->comment->comment);
            }
            if (preg_match('/^\\[spoiler\\].*\\[\\/spoiler\\]$/s', $post->comment->comment)) {
                $post->comment->comment = str_replace(['[spoiler]', '[/spoiler]'], '', $post->comment->comment);
            }
        }
    });
});
Example #10
0
 public function run()
 {
     Event::forge('Foolz\\Plugin\\Plugin::execute.foolz/foolfuuka-plugin-board-statistics')->setCall(function ($result) {
         /* @var Context $context */
         $context = $result->getParam('context');
         /** @var Autoloader $autoloader */
         $autoloader = $context->getService('autoloader');
         $autoloader->addClassMap(['Foolz\\Foolframe\\Controller\\Admin\\Plugins\\BoardStatistics' => __DIR__ . '/classes/controller/admin.php', 'Foolz\\Foolfuuka\\Controller\\Chan\\BoardStatistics' => __DIR__ . '/classes/controller/chan.php', 'Foolz\\Foolfuuka\\Plugins\\BoardStatistics\\Model\\BoardStatistics' => __DIR__ . '/classes/model/board_statistics.php', 'Foolz\\Foolfuuka\\Plugins\\BoardStatistics\\Console\\Console' => __DIR__ . '/classes/console/console.php']);
         $context->getContainer()->register('foolfuuka-plugin.board_statistics', 'Foolz\\Foolfuuka\\Plugins\\BoardStatistics\\Model\\BoardStatistics')->addArgument($context);
         Event::forge('Foolz\\Foolframe\\Model\\Context.handleWeb.has_auth')->setCall(function ($result) use($context) {
             // don't add the admin panels if the user is not an admin
             if ($context->getService('auth')->hasAccess('maccess.admin')) {
                 Event::forge('Foolz\\Foolframe\\Controller\\Admin.before.sidebar.add')->setCall(function ($result) {
                     $sidebar = $result->getParam('sidebar');
                     $sidebar[]['plugins'] = ["content" => ["board_statistics/manage" => ["level" => "admin", "name" => _i("Board Statistics"), "icon" => 'icon-bar-chart']]];
                     $result->setParam('sidebar', $sidebar);
                 });
                 $context->getRouteCollection()->add('foolframe.plugin.board_statistics.admin', new Route('/admin/plugins/board_statistics/{_suffix}', ['_suffix' => 'manage', '_controller' => '\\Foolz\\Foolframe\\Controller\\Admin\\Plugins\\BoardStatistics::manage'], ['_suffix' => '.*']));
             }
             Event::forge('foolframe.themes.generic_top_nav_buttons')->setCall(function ($result) {
                 $obj = $result->getObject();
                 $top_nav = $result->getParam('nav');
                 if ($obj->getRadix()) {
                     $top_nav[] = ['href' => $obj->getUri()->create([$obj->getRadix()->shortname, 'statistics']), 'text' => _i('Stats')];
                     $result->set($top_nav);
                     $result->setParam('nav', $top_nav);
                 }
             })->setPriority(3);
         });
         Event::forge('Foolz\\Foolframe\\Model\\Context::handleConsole.add')->setCall(function ($result) use($context) {
             $result->getParam('application')->add(new \Foolz\Foolfuuka\Plugins\BoardStatistics\Console\Console($context));
         });
         Event::forge('Foolz\\Foolframe\\Model\\Context.handleWeb.route_collection')->setCall(function ($result) use($context) {
             /** @var RadixCollection $radix_coll */
             $radix_coll = $context->getService('foolfuuka.radix_collection');
             $radix_all = $radix_coll->getAll();
             foreach ($radix_all as $radix) {
                 $obj = $result->getObject();
                 $obj->getRouteCollection()->add('foolfuuka.plugin.board_statistics.chan.radix.' . $radix->shortname, new Route('/' . $radix->shortname . '/statistics/{_suffix}', ['_suffix' => '', '_controller' => '\\Foolz\\Foolfuuka\\Controller\\Chan\\BoardStatistics::statistics', 'radix_shortname' => $radix->shortname], ['_suffix' => '.*']));
             }
         });
     });
     Event::forge('Foolz\\Foolframe\\Model\\Plugin::schemaUpdate.foolz/foolfuuka-plugin-board-statistics')->setCall(function ($result) {
         /** @var Context $context */
         $context = $result->getParam('context');
         /** @var DoctrineConnection $dc */
         $dc = $context->getService('doctrine');
         /** @var Schema $schema */
         $schema = $result->getParam('schema');
         $table = $schema->createTable($dc->p('plugin_fu_board_statistics'));
         if ($dc->getConnection()->getDriver()->getName() == 'pdo_mysql') {
             $table->addOption('charset', 'utf8mb4');
             $table->addOption('collate', 'utf8mb4_general_ci');
         }
         $table->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]);
         $table->addColumn('board_id', 'integer', ['unsigned' => true]);
         $table->addColumn('name', 'string', ['length' => 32]);
         $table->addColumn('timestamp', 'integer', ['unsigned' => true]);
         $table->addColumn('data', 'text', ['length' => 65532]);
         $table->setPrimaryKey(['id']);
         $table->addUniqueIndex(['board_id', 'name'], $dc->p('plugin_fu_board_statistics_board_id_name_index'));
         $table->addIndex(['timestamp'], $dc->p('plugin_fu_board_statistics_timestamp_index'));
     });
 }