repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
hosseinhezami/laravel-gemini
https://github.com/hosseinhezami/laravel-gemini/blob/4ab7bae02f0cc88f3e93455e8363d9a517c6eafe/src/Factory/ProviderFactory.php
src/Factory/ProviderFactory.php
<?php namespace HosseinHezami\LaravelGemini\Factory; use HosseinHezami\LaravelGemini\Contracts\ProviderInterface; use HosseinHezami\LaravelGemini\Exceptions\ValidationException; class ProviderFactory { public function create(?string $alias = null, ?string $apiKey = null): ProviderInterface { $alias = $alias ?: config('gemini.default_provider'); $providerConfig = config('gemini.providers.' . $alias); if (!$providerConfig || !isset($providerConfig['class'])) { throw new ValidationException("Unknown provider: $alias"); } $class = $providerConfig['class']; return new $class($providerConfig, $apiKey); } }
php
MIT
4ab7bae02f0cc88f3e93455e8363d9a517c6eafe
2026-01-05T04:55:15.491730Z
false
vinkla/laravel-gitlab
https://github.com/vinkla/laravel-gitlab/blob/b3fd4dcae567db0bf4b6a0d269e68a3353f697e4/src/GitLabServiceProvider.php
src/GitLabServiceProvider.php
<?php /* * This file is part of Laravel GitLab. * * (c) Vincent Klaiber <hello@vinkla.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace Vinkla\GitLab; use Gitlab\Client; use Illuminate\Contracts\Container\Container; use Illuminate\Foundation\Application as LaravelApplication; use Illuminate\Support\ServiceProvider; use Laravel\Lumen\Application as LumenApplication; /** * This is the GitLab service provider class. * * @author Vincent Klaiber <hello@vinkla.com> */ class GitLabServiceProvider extends ServiceProvider { /** * Boot the service provider. * * @return void */ public function boot() { $this->setupConfig(); } /** * Setup the config. * * @return void */ protected function setupConfig() { $source = realpath(__DIR__.'/../config/gitlab.php'); if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { $this->publishes([$source => config_path('gitlab.php')]); } elseif ($this->app instanceof LumenApplication) { $this->app->configure('gitlab'); } $this->mergeConfigFrom($source, 'gitlab'); } /** * Register the service provider. * * @return void */ public function register() { $this->registerFactory(); $this->registerManager(); $this->registerBindings(); } /** * Register the factory class. * * @return void */ protected function registerFactory() { $this->app->singleton('gitlab.factory', function () { return new GitLabFactory(); }); $this->app->alias('gitlab.factory', GitLabFactory::class); } /** * Register the manager class. * * @return void */ protected function registerManager() { $this->app->singleton('gitlab', function (Container $app) { $config = $app['config']; $factory = $app['gitlab.factory']; return new GitLabManager($config, $factory); }); $this->app->alias('gitlab', GitLabManager::class); } /** * Register the bindings. * * @return void */ protected function registerBindings() { $this->app->bind('gitlab.connection', function (Container $app) { $manager = $app['gitlab']; return $manager->connection(); }); $this->app->alias('gitlab.connection', Client::class); } /** * Get the services provided by the provider. * * @return string[] */ public function provides(): array { return [ 'gitlab', 'gitlab.factory', 'gitlab.connection', ]; } }
php
MIT
b3fd4dcae567db0bf4b6a0d269e68a3353f697e4
2026-01-05T04:55:19.269992Z
false
vinkla/laravel-gitlab
https://github.com/vinkla/laravel-gitlab/blob/b3fd4dcae567db0bf4b6a0d269e68a3353f697e4/src/GitLabFactory.php
src/GitLabFactory.php
<?php /* * This file is part of Laravel GitLab. * * (c) Vincent Klaiber <hello@vinkla.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace Vinkla\GitLab; use Gitlab\Client; use InvalidArgumentException; /** * This is the gitlab factory class. * * @author Vincent Klaiber <hello@vinkla.com> */ class GitLabFactory { /** * Make a new gitlab client. * * @param array $config * * @return \Gitlab\Client */ public function make(array $config): Client { $config = $this->getConfig($config); return $this->getClient($config); } /** * Get the configuration data. * * @param string[] $config * * @throws \InvalidArgumentException * * @return array */ protected function getConfig(array $config): array { $keys = ['token', 'url']; foreach ($keys as $key) { if (!array_key_exists($key, $config)) { throw new InvalidArgumentException("Missing configuration key [$key]."); } } return array_only($config, ['token', 'url', 'method', 'sudo']); } /** * Get the main client. * * @param array $config * * @return \Gitlab\Client */ protected function getClient(array $config): Client { $client = Client::create($config['url']); $client->authenticate( $config['token'], array_get($config, 'method', Client::AUTH_URL_TOKEN), array_get($config, 'sudo', null) ); return $client; } }
php
MIT
b3fd4dcae567db0bf4b6a0d269e68a3353f697e4
2026-01-05T04:55:19.269992Z
false
vinkla/laravel-gitlab
https://github.com/vinkla/laravel-gitlab/blob/b3fd4dcae567db0bf4b6a0d269e68a3353f697e4/src/GitLabManager.php
src/GitLabManager.php
<?php /* * This file is part of Laravel GitLab. * * (c) Vincent Klaiber <hello@vinkla.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace Vinkla\GitLab; use Gitlab\Client; use GrahamCampbell\Manager\AbstractManager; use Illuminate\Contracts\Config\Repository; /** * This is the gitlab manager class. * * @author Vincent Klaiber <hello@vinkla.com> */ class GitLabManager extends AbstractManager { /** * The factory instance. * * @var \Vinkla\GitLab\GitLabFactory */ private $factory; /** * Create a new gitlab manager instance. * * @param \Illuminate\Contracts\Config\Repository $config * @param \Vinkla\GitLab\GitLabFactory $factory * * @return void */ public function __construct(Repository $config, GitLabFactory $factory) { parent::__construct($config); $this->factory = $factory; } /** * Create the connection instance. * * @param array $config * * @return \Gitlab\Client */ protected function createConnection(array $config): Client { return $this->factory->make($config); } /** * Get the configuration name. * * @return string */ protected function getConfigName(): string { return 'gitlab'; } /** * Get the factory instance. * * @return \Vinkla\GitLab\GitLabFactory */ public function getFactory(): GitLabFactory { return $this->factory; } }
php
MIT
b3fd4dcae567db0bf4b6a0d269e68a3353f697e4
2026-01-05T04:55:19.269992Z
false
vinkla/laravel-gitlab
https://github.com/vinkla/laravel-gitlab/blob/b3fd4dcae567db0bf4b6a0d269e68a3353f697e4/src/Facades/GitLab.php
src/Facades/GitLab.php
<?php /* * This file is part of Laravel GitLab. * * (c) Vincent Klaiber <hello@vinkla.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace Vinkla\GitLab\Facades; use Illuminate\Support\Facades\Facade; /** * This is the GitLab facade class. * * @author Vincent Klaiber <hello@vinkla.com> */ class GitLab extends Facade { /** * Get the registered name of the component. * * @return string */ protected static function getFacadeAccessor(): string { return 'gitlab'; } }
php
MIT
b3fd4dcae567db0bf4b6a0d269e68a3353f697e4
2026-01-05T04:55:19.269992Z
false
vinkla/laravel-gitlab
https://github.com/vinkla/laravel-gitlab/blob/b3fd4dcae567db0bf4b6a0d269e68a3353f697e4/tests/AbstractTestCase.php
tests/AbstractTestCase.php
<?php /* * This file is part of Laravel GitLab. * * (c) Vincent Klaiber <hello@vinkla.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace Vinkla\Tests\GitLab; use GrahamCampbell\TestBench\AbstractPackageTestCase; use Vinkla\GitLab\GitLabServiceProvider; /** * This is the abstract test case class. * * @author Vincent Klaiber <hello@vinkla.com> */ abstract class AbstractTestCase extends AbstractPackageTestCase { /** * Get the service provider class. * * @param \Illuminate\Contracts\Foundation\Application $app * * @return string */ protected function getServiceProviderClass($app) { return GitLabServiceProvider::class; } }
php
MIT
b3fd4dcae567db0bf4b6a0d269e68a3353f697e4
2026-01-05T04:55:19.269992Z
false
vinkla/laravel-gitlab
https://github.com/vinkla/laravel-gitlab/blob/b3fd4dcae567db0bf4b6a0d269e68a3353f697e4/tests/GitLabFactoryTest.php
tests/GitLabFactoryTest.php
<?php /* * This file is part of Laravel GitLab. * * (c) Vincent Klaiber <hello@vinkla.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace Vinkla\Tests\GitLab; use Gitlab\Client; use Vinkla\GitLab\GitLabFactory; /** * This is the GitLab factory test class. * * @author Vincent Klaiber <hello@vinkla.com> */ class GitLabFactoryTest extends AbstractTestCase { public function testMakeStandard() { $factory = $this->getGitLabFactory(); $return = $factory->make([ 'token' => 'your-token', 'url' => 'https://git.yourdomain.com', ]); $this->assertInstanceOf(Client::class, $return); } /** * @expectedException \InvalidArgumentException */ public function testMakeWithoutToken() { $factory = $this->getGitLabFactory(); $factory->make([ 'url' => 'https://git.yourdomain.com', ]); } /** * @expectedException \InvalidArgumentException */ public function testMakeWithoutUrl() { $factory = $this->getGitLabFactory(); $factory->make([ 'token' => 'your-token', ]); } protected function getGitLabFactory() { return new GitLabFactory(); } }
php
MIT
b3fd4dcae567db0bf4b6a0d269e68a3353f697e4
2026-01-05T04:55:19.269992Z
false
vinkla/laravel-gitlab
https://github.com/vinkla/laravel-gitlab/blob/b3fd4dcae567db0bf4b6a0d269e68a3353f697e4/tests/AnalysisTest.php
tests/AnalysisTest.php
<?php /* * This file is part of Laravel Gitlab. * * (c) Vincent Klaiber <hello@vinkla.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace Vinkla\Tests\Gitlab; use GrahamCampbell\Analyzer\AnalysisTrait; use Laravel\Lumen\Application; use PHPUnit\Framework\TestCase; /** * This is the analysis test class. * * @author Vincent Klaiber <hello@vinkla.com> */ class AnalysisTest extends TestCase { use AnalysisTrait; /** * Get the code paths to analyze. * * @return string[] */ protected function getPaths() { return [ realpath(__DIR__.'/../config'), realpath(__DIR__.'/../src'), realpath(__DIR__), ]; } /** * Get the classes to ignore not existing. * * @return string[] */ protected function getIgnored() { return [Application::class]; } }
php
MIT
b3fd4dcae567db0bf4b6a0d269e68a3353f697e4
2026-01-05T04:55:19.269992Z
false
vinkla/laravel-gitlab
https://github.com/vinkla/laravel-gitlab/blob/b3fd4dcae567db0bf4b6a0d269e68a3353f697e4/tests/ServiceProviderTest.php
tests/ServiceProviderTest.php
<?php /* * This file is part of Laravel GitLab. * * (c) Vincent Klaiber <hello@vinkla.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace Vinkla\Tests\GitLab; use Gitlab\Client; use GrahamCampbell\TestBenchCore\ServiceProviderTrait; use Vinkla\GitLab\GitLabFactory; use Vinkla\GitLab\GitLabManager; /** * This is the service provider test class. * * @author Vincent Klaiber <hello@vinkla.com> */ class ServiceProviderTest extends AbstractTestCase { use ServiceProviderTrait; public function testGitLabFactoryIsInjectable() { $this->assertIsInjectable(GitLabFactory::class); } public function testGitLabManagerIsInjectable() { $this->assertIsInjectable(GitLabManager::class); } public function testBindings() { $this->assertIsInjectable(Client::class); $original = $this->app['gitlab.connection']; $this->app['gitlab']->reconnect(); $new = $this->app['gitlab.connection']; $this->assertNotSame($original, $new); $this->assertEquals($original, $new); } }
php
MIT
b3fd4dcae567db0bf4b6a0d269e68a3353f697e4
2026-01-05T04:55:19.269992Z
false
vinkla/laravel-gitlab
https://github.com/vinkla/laravel-gitlab/blob/b3fd4dcae567db0bf4b6a0d269e68a3353f697e4/tests/GitLabManagerTest.php
tests/GitLabManagerTest.php
<?php /* * This file is part of Laravel GitLab. * * (c) Vincent Klaiber <hello@vinkla.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace Vinkla\Tests\GitLab; use Gitlab\Client; use GrahamCampbell\TestBench\AbstractTestCase as AbstractTestBenchTestCase; use Illuminate\Contracts\Config\Repository; use Mockery; use Vinkla\GitLab\GitLabFactory; use Vinkla\GitLab\GitLabManager; /** * This is the GitLab manager test class. * * @author Vincent Klaiber <hello@vinkla.com> */ class GitLabManagerTest extends AbstractTestBenchTestCase { public function testCreateConnection() { $config = ['path' => __DIR__]; $manager = $this->getManager($config); $manager->getConfig()->shouldReceive('get')->once() ->with('gitlab.default')->andReturn('gitlab'); $this->assertSame([], $manager->getConnections()); $return = $manager->connection(); $this->assertInstanceOf(Client::class, $return); $this->assertArrayHasKey('gitlab', $manager->getConnections()); } protected function getManager(array $config) { $repository = Mockery::mock(Repository::class); $factory = Mockery::mock(GitLabFactory::class); $manager = new GitLabManager($repository, $factory); $manager->getConfig()->shouldReceive('get')->once() ->with('gitlab.connections')->andReturn(['gitlab' => $config]); $config['name'] = 'gitlab'; $manager->getFactory()->shouldReceive('make')->once() ->with($config)->andReturn(Mockery::mock(Client::class)); return $manager; } }
php
MIT
b3fd4dcae567db0bf4b6a0d269e68a3353f697e4
2026-01-05T04:55:19.269992Z
false
vinkla/laravel-gitlab
https://github.com/vinkla/laravel-gitlab/blob/b3fd4dcae567db0bf4b6a0d269e68a3353f697e4/tests/Facades/GitLabTest.php
tests/Facades/GitLabTest.php
<?php /* * This file is part of Laravel GitLab. * * (c) Vincent Klaiber <hello@vinkla.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); namespace Vinkla\Tests\GitLab\Facades; use GrahamCampbell\TestBenchCore\FacadeTrait; use Vinkla\GitLab\Facades\GitLab; use Vinkla\GitLab\GitLabManager; use Vinkla\Tests\GitLab\AbstractTestCase; /** * This is the GitLab test class. * * @author Vincent Klaiber <hello@vinkla.com> */ class GitLabTest extends AbstractTestCase { use FacadeTrait; /** * Get the facade accessor. * * @return string */ protected function getFacadeAccessor() { return 'gitlab'; } /** * Get the facade class. * * @return string */ protected function getFacadeClass() { return GitLab::class; } /** * Get the facade root. * * @return string */ protected function getFacadeRoot() { return GitLabManager::class; } }
php
MIT
b3fd4dcae567db0bf4b6a0d269e68a3353f697e4
2026-01-05T04:55:19.269992Z
false
vinkla/laravel-gitlab
https://github.com/vinkla/laravel-gitlab/blob/b3fd4dcae567db0bf4b6a0d269e68a3353f697e4/config/gitlab.php
config/gitlab.php
<?php /* * This file is part of Laravel GitLab. * * (c) Vincent Klaiber <hello@vinkla.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); return [ /* |-------------------------------------------------------------------------- | Default Connection Name |-------------------------------------------------------------------------- | | Here you may specify which of the connections below you wish to use as | your default connection for all work. Of course, you may use many | connections at once using the manager class. | */ 'default' => 'main', /* |-------------------------------------------------------------------------- | GitLab Connections |-------------------------------------------------------------------------- | | Here are each of the connections setup for your application. Example | configuration has been included, but you may add as many connections as | you would like. | */ 'connections' => [ 'main' => [ 'token' => 'your-token', 'url' => 'https://git.yourdomain.com', ], 'alternative' => [ 'token' => 'your-token', 'url' => 'https://git.yourdomain.com', ], ], ];
php
MIT
b3fd4dcae567db0bf4b6a0d269e68a3353f697e4
2026-01-05T04:55:19.269992Z
false
imanghafoori1/laravel-smart-facades
https://github.com/imanghafoori1/laravel-smart-facades/blob/598803dec72bf7cd1c169faa068b38eef773214b/src/Facade.php
src/Facade.php
<?php namespace Imanghafoori\SmartFacades; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Facade as LaravelFacade; use Illuminate\Support\Str; use ReflectionMethod; use ReflectionParameter; use RuntimeException; use TypeError; class Facade extends LaravelFacade { /** * @var \Closure|string|null */ protected static $tmpDriver = null; /** * Get the registered name of the component. * * @return string */ protected static function getFacadeAccessor() { if ($tmp = static::$tmpDriver) { static::$tmpDriver = null; return $tmp; } return static::class; } /** * Temporarily changes the driver, only for the next call. * * @param \Closure|string $name * @return string */ public static function changeProxyTo($name) { static::$tmpDriver = $name; return static::class; } /** * Temporarily changes the driver, only for the next call. * * @param \Closure|string $name * @return string */ public static function withDriver($name) { return static::changeProxyTo($name); } /** * Changes the default driver of the facade. * * @param \Closure|string $class * @return string */ public static function shouldProxyTo($class) { self::clearResolvedInstance(self::getFacadeAccessor()); static::$app->singleton(self::getFacadeAccessor(), $class); return static::class; } /** * Sets up a listener to be invoked before the actual method call. * * @param string $methodName * @param \Closure|string $listener */ public static function preCall($methodName, $listener) { $listener = self::makeListener($methodName, $listener); Event::listen('calling: '.static::class.'@'.$methodName, $listener); } /** * Sets up a listener to be invoked after the actual method. * * @param string $methodName * @param \Closure|string $listener */ public static function postCall($methodName, $listener) { $listener = self::makeListener($methodName, $listener); Event::listen('called: '.static::class.'@'.$methodName, $listener); } /** * Handle dynamic, static calls to the object. * * @param string $method * @param array $args * @return mixed * * @throws \RuntimeException * @throws \ReflectionException */ public static function __callStatic($method, $args) { Event::dispatch('calling: '.static::class.'@'.$method, [$method, $args]); $instance = static::getFacadeRoot(); if (! $instance) { throw new RuntimeException('A facade root has not been set.'); } try { $result = $instance->$method(...$args); Event::dispatch('called: '.static::class.'@'.$method, [$method, $args, $result]); return $result; } catch (TypeError $error) { $params = (new ReflectionMethod($instance, $method))->getParameters(); self::addMissingDependencies($params, $args); $result = $instance->$method(...$args); Event::dispatch('called: '.static::class.'@'.$method, [$method, $args, $result]); return $result; } } /** * Adds missing dependencies to the user-provided input. * * @param ReflectionParameter[] $parameters * @param array $inputData */ private static function addMissingDependencies($parameters, array &$inputData) { foreach ($parameters as $i => $parameter) { // Injects missing type hinted parameters within the array $class = $parameter->getClass()->name ?? false; if ($class && ! ($inputData[$i] ?? false) instanceof $class) { array_splice($inputData, $i, 0, [self::$app[$class]]); } elseif (! array_key_exists($i, $inputData) && $parameter->isDefaultValueAvailable()) { $inputData[] = $parameter->getDefaultValue(); } } } /** * @param string $method * @param \Closure|string $listener * @return \Closure */ private static function makeListener($method, $listener) { if (Str::contains($method, '*')) { // The $_eventName variable is passed to us by laravel // but we do not need it, because we already know it. return function ($_eventName, $methodAndArguments) use ($listener) { static::$app->call($listener, $methodAndArguments); }; } return function ($methodName, $args, $result = null) use ($listener) { static::$app->call($listener, [ 'methodName' => $methodName, 'args' => $args, 'result' => $result, ]); }; } /** * Handle dynamic, static calls to the object. * * @param string $method * @param array $args * @return mixed * * @throws \RuntimeException * @throws \ReflectionException */ public function __call($method, $args) { return static::__callStatic($method, $args); } }
php
MIT
598803dec72bf7cd1c169faa068b38eef773214b
2026-01-05T04:55:25.208179Z
false
imanghafoori1/laravel-smart-facades
https://github.com/imanghafoori1/laravel-smart-facades/blob/598803dec72bf7cd1c169faa068b38eef773214b/tests/TestCase.php
tests/TestCase.php
<?php abstract class TestCase extends Orchestra\Testbench\TestCase { protected function getPackageProviders($app) { return []; } }
php
MIT
598803dec72bf7cd1c169faa068b38eef773214b
2026-01-05T04:55:25.208179Z
false
imanghafoori1/laravel-smart-facades
https://github.com/imanghafoori1/laravel-smart-facades/blob/598803dec72bf7cd1c169faa068b38eef773214b/tests/TestCases.php
tests/TestCases.php
<?php namespace Imanghafoori\FacadeTests; use ArgumentCountError; use Imanghafoori\FacadeTests\Stubs\ApplicationStub; use Imanghafoori\FacadeTests\Stubs\ConcreteFacadeStub; use Imanghafoori\FacadeTests\Stubs\ConcreteFacadeStub2; use Imanghafoori\FacadeTests\Stubs\FacadeStub; use Imanghafoori\FacadeTests\Stubs\FacadeStub1; use Imanghafoori\FacadeTests\Stubs\FacadeStub2; use TestCase; class TestCases extends TestCase { public function test_does_not_swallow_internal_type_error_of_the_target_class() { try { FacadeStub::faulty(); } catch (ArgumentCountError $error) { $this->assertRegExp('/Too few arguments to function .*?FacadeStub1::method\(\), 0 passed in .* and exactly 1 expected/', $error->getMessage()); } } public function test_it_can_inject_for_first_param() { $this->assertEquals('def1', FacadeStub::m1(new FacadeStub1())); $this->assertEquals('def1', FacadeStub::m1()); $this->assertEquals('def12', FacadeStub::m2('2')); $this->assertEquals('def1'.'ab'.'def3', FacadeStub::m3(new FacadeStub1(), 'ab')); $this->assertEquals('def1'.'bb'.'def3', FacadeStub::m3('bb')); $this->assertEquals('def1'.'bb'.'cc', FacadeStub::m3('bb', 'cc')); $this->assertEquals('def1'.'bb'.'cc', FacadeStub::m3('bb', 'cc', 'dd')); $this->assertEquals('val1'.'def2'.'def3', FacadeStub::m3(new FacadeStub1('val1'))); $this->assertEquals('def1'.'def2'.'def3', FacadeStub::m3()); } public function test_pre_call_wildcard() { $obj = new FacadeStub1(); FacadeStub::preCall('m*', function ($methodName, $args) use ($obj) { $this->assertIsArray($args); $this->assertEquals($args[0], $obj); $this->assertEquals($methodName, 'm1'); }); FacadeStub::postCall('m*', function ($methodName, $args, $result) use ($obj) { $this->assertIsArray($args); $this->assertEquals($args[0], $obj); $this->assertEquals($result, 'def1'); $this->assertEquals($methodName, 'm1'); }); $this->assertEquals('def1', FacadeStub::m1($obj)); } public function test_pre_call() { $obj = new FacadeStub1(); FacadeStub::preCall('m1', function ($methodName, $args) use ($obj) { $this->assertIsArray($args); $this->assertEquals($args[0], $obj); $this->assertEquals($methodName, 'm1'); }); FacadeStub::postCall('m1', function ($methodName, $args, $result) use ($obj) { $this->assertIsArray($args); $this->assertEquals($args[0], $obj); $this->assertEquals($result, 'def1'); $this->assertEquals($methodName, 'm1'); }); $this->assertEquals('def1', FacadeStub::m1($obj)); } public function test_pre_call_is_not_called() { FacadeStub::preCall('m2', function ($methodName, $args) { $a = $args[0]; $a->a = $a->a + 1; }); FacadeStub::postCall('m2', function ($methodName, $args) { $a = $args[0]; $a->a = $a->a + 1; }); $obj = new FacadeStub1(0); $this->assertEquals(0, FacadeStub::m1($obj)); $this->assertEquals($obj->a, 0); } public function test_it_can_inject_for_second_param() { $this->assertEquals('abc'.FacadeStub1::class.'def3', FacadeStub::m5('abc')); $this->assertEquals('abc'.FacadeStub1::class.'def3', FacadeStub::m5('abc', new FacadeStub1())); $this->assertEquals('bb'.FacadeStub1::class.'cc', FacadeStub::m5('bb', 'cc')); $this->assertEquals('bb'.FacadeStub1::class.'cc', FacadeStub::m5('bb', new FacadeStub1, 'cc')); } public function test_it_can_switch_after_first_call() { FacadeStub::setFacadeApplication(app()); FacadeStub::shouldProxyTo(ConcreteFacadeStub::class); FacadeStub::m1(); FacadeStub::shouldProxyTo(ConcreteFacadeStub2::class); $result = FacadeStub::m1(); $this->assertEquals('I am stub2', $result); $this->assertInstanceOf(ConcreteFacadeStub2::class, FacadeStub::getFacadeRoot()); } public function test_it_can_inject_two_dependencies() { $this->assertEquals('val1'.'def2'.'x_default', FacadeStub::m6(new FacadeStub1('val1'), 'x_')); $this->assertEquals('def1'.'val2'.'x_default', FacadeStub::m6(new FacadeStub2('val2'), 'x_')); $this->assertEquals('val1'.'val2'.'x_default', FacadeStub::m6(new FacadeStub1('val1'), new FacadeStub2('val2'), 'x_')); $this->assertEquals('val1'.'def2'.'x_y', FacadeStub::m6(new FacadeStub1('val1'), 'x_', 'y')); $this->assertEquals('def1'.'val2'.'x_y', FacadeStub::m6(new FacadeStub2('val2'), 'x_', 'y')); $this->assertEquals('def1'.'def2'.'x_default', FacadeStub::m6('x_')); $this->assertEquals('def1'.'def2'.'x_y', FacadeStub::m6('x_', 'y')); } public function test_it_can_inject_two_dependencies2() { FacadeStub::setFacadeApplication(app()); FacadeStub::shouldProxyTo(ConcreteFacadeStub::class); $this->assertEquals('val1'.'x_y'.'def2', FacadeStub::m7(new FacadeStub1('val1'), 'x_', 'y')); $this->assertEquals('val1'.'x_y'.'val2', FacadeStub::m7(new FacadeStub1('val1'), 'x_', 'y', new FacadeStub2('val2'))); } public function test_dynamic_proxy_changing_by_with_driver() { $this->assertEquals(ConcreteFacadeStub::class, get_class(FacadeStub::getFacadeRoot())); FacadeStub::withDriver(ConcreteFacadeStub2::class); $this->assertEquals(ConcreteFacadeStub2::class, get_class(FacadeStub::getFacadeRoot())); FacadeStub::withDriver(ConcreteFacadeStub::class); $this->assertEquals(ConcreteFacadeStub::class, get_class(FacadeStub::getFacadeRoot())); } public function test_dynamic_proxy_changing() { $this->assertEquals(ConcreteFacadeStub::class, get_class(FacadeStub::getFacadeRoot())); FacadeStub::changeProxyTo(ConcreteFacadeStub2::class); $this->assertEquals(ConcreteFacadeStub2::class, get_class(FacadeStub::getFacadeRoot())); // since changeProxyTo sets a temporary driver, it should get rolled back to the last driver after being retrieved once FacadeStub::m1(new FacadeStub1('val1')); $this->assertEquals(ConcreteFacadeStub::class, get_class(FacadeStub::getFacadeRoot())); } public function setUp(): void { parent::setUp(); $app = new ApplicationStub; $app->setAttributes([ 'foo' => new ConcreteFacadeStub, FacadeStub1::class => new FacadeStub1(), FacadeStub2::class => new FacadeStub2(), ]); $app = app(); FacadeStub::setFacadeApplication($app); FacadeStub::shouldProxyTo(ConcreteFacadeStub::class); } }
php
MIT
598803dec72bf7cd1c169faa068b38eef773214b
2026-01-05T04:55:25.208179Z
false
imanghafoori1/laravel-smart-facades
https://github.com/imanghafoori1/laravel-smart-facades/blob/598803dec72bf7cd1c169faa068b38eef773214b/tests/Stubs/FacadeStub1.php
tests/Stubs/FacadeStub1.php
<?php namespace Imanghafoori\FacadeTests\Stubs; class FacadeStub1 { public $a; public function __construct($a = 'def1') { $this->a = $a; } public function method($param) { } }
php
MIT
598803dec72bf7cd1c169faa068b38eef773214b
2026-01-05T04:55:25.208179Z
false
imanghafoori1/laravel-smart-facades
https://github.com/imanghafoori1/laravel-smart-facades/blob/598803dec72bf7cd1c169faa068b38eef773214b/tests/Stubs/ConcreteFacadeStub2.php
tests/Stubs/ConcreteFacadeStub2.php
<?php namespace Imanghafoori\FacadeTests\Stubs; class ConcreteFacadeStub2 extends ConcreteFacadeStub { public function m1(FacadeStub1 $p1) { return 'I am stub2'; } }
php
MIT
598803dec72bf7cd1c169faa068b38eef773214b
2026-01-05T04:55:25.208179Z
false
imanghafoori1/laravel-smart-facades
https://github.com/imanghafoori1/laravel-smart-facades/blob/598803dec72bf7cd1c169faa068b38eef773214b/tests/Stubs/ConcreteFacadeStub.php
tests/Stubs/ConcreteFacadeStub.php
<?php namespace Imanghafoori\FacadeTests\Stubs; class ConcreteFacadeStub { public function m1(FacadeStub1 $p1) { return $p1->a; } public function m2(FacadeStub1 $p1, $p2) { return $p1->a.$p2; } public function m3(FacadeStub1 $p1, $p2 = 'def2', $p3 = 'def3') { return $p1->a.$p2.$p3; } public function m4($p1, $p2 = 'def2') { return get_class($p1).$p2; } public function m5($p1, FacadeStub1 $p2, $p3 = 'def3') { return $p1.get_class($p2).$p3; } public function m6(FacadeStub1 $p1, FacadeStub2 $p2, $p3, $p4 = 'default') { return $p1->a.$p2->b.$p3.$p4; } public function m7(FacadeStub1 $p1, $p2, $p3, FacadeStub2 $p4) { return $p1->a.$p2.$p3.$p4->b; } public function faulty(FacadeStub1 $p1) { $p1->method(); } }
php
MIT
598803dec72bf7cd1c169faa068b38eef773214b
2026-01-05T04:55:25.208179Z
false
imanghafoori1/laravel-smart-facades
https://github.com/imanghafoori1/laravel-smart-facades/blob/598803dec72bf7cd1c169faa068b38eef773214b/tests/Stubs/FacadeStub.php
tests/Stubs/FacadeStub.php
<?php namespace Imanghafoori\FacadeTests\Stubs; use Imanghafoori\SmartFacades\Facade; class FacadeStub extends Facade { // }
php
MIT
598803dec72bf7cd1c169faa068b38eef773214b
2026-01-05T04:55:25.208179Z
false
imanghafoori1/laravel-smart-facades
https://github.com/imanghafoori1/laravel-smart-facades/blob/598803dec72bf7cd1c169faa068b38eef773214b/tests/Stubs/FacadeStub2.php
tests/Stubs/FacadeStub2.php
<?php namespace Imanghafoori\FacadeTests\Stubs; class FacadeStub2 { public $b; public function __construct($b = 'def2') { $this->b = $b; } }
php
MIT
598803dec72bf7cd1c169faa068b38eef773214b
2026-01-05T04:55:25.208179Z
false
imanghafoori1/laravel-smart-facades
https://github.com/imanghafoori1/laravel-smart-facades/blob/598803dec72bf7cd1c169faa068b38eef773214b/tests/Stubs/ApplicationStub.php
tests/Stubs/ApplicationStub.php
<?php namespace Imanghafoori\FacadeTests\Stubs; use ArrayAccess; class ApplicationStub implements ArrayAccess { protected $attributes = []; public function setAttributes($attributes) { $this->attributes = $attributes; } public function instance($key, $instance) { $this->attributes[$key] = $instance; } public function offsetExists($offset) { return isset($this->attributes[$offset]); } public function offsetGet($key) { return $this->attributes[$key]; } public function offsetSet($key, $value) { $this->attributes[$key] = $value; } public function offsetUnset($key) { unset($this->attributes[$key]); } }
php
MIT
598803dec72bf7cd1c169faa068b38eef773214b
2026-01-05T04:55:25.208179Z
false
joshcanhelp/php-form-builder
https://github.com/joshcanhelp/php-form-builder/blob/892ea8cfb67d54e9e46e3b691369c15b900b9be2/PhpFormBuilder.php
PhpFormBuilder.php
<?php // v 0.8.6 class PhpFormBuilder { // Stores all form inputs private $inputs = array(); // Stores all form attributes private $form = array(); // Does this form have a submit value? private $has_submit = false; /** * Constructor function to set form action and attributes * * @param string $action * @param bool $args */ function __construct( $action = '', $args = false ) { // Default form attributes $defaults = array( 'action' => $action, 'method' => 'post', 'enctype' => 'application/x-www-form-urlencoded', 'class' => array(), 'id' => '', 'markup' => 'html', 'novalidate' => false, 'add_nonce' => false, 'add_honeypot' => true, 'form_element' => true, 'add_submit' => true ); // Merge with arguments, if present if ( $args ) { $settings = array_merge( $defaults, $args ); } // Otherwise, use the defaults wholesale else { $settings = $defaults; } // Iterate through and save each option foreach ( $settings as $key => $val ) { // Try setting with user-passed setting // If not, try the default with the same key name if ( ! $this->set_att( $key, $val ) ) { $this->set_att( $key, $defaults[ $key ] ); } } } /** * Validate and set form * * @param string $key A valid key; switch statement ensures validity * @param string | bool $val A valid value; validated for each key * * @return bool */ function set_att( $key, $val ) { switch ( $key ) : case 'action': break; case 'method': if ( ! in_array( $val, array( 'post', 'get' ) ) ) { return false; } break; case 'enctype': if ( ! in_array( $val, array( 'application/x-www-form-urlencoded', 'multipart/form-data' ) ) ) { return false; } break; case 'markup': if ( ! in_array( $val, array( 'html', 'xhtml' ) ) ) { return false; } break; case 'class': case 'id': if ( ! $this->_check_valid_attr( $val ) ) { return false; } break; case 'novalidate': case 'add_honeypot': case 'form_element': case 'add_submit': if ( ! is_bool( $val ) ) { return false; } break; case 'add_nonce': if ( ! is_string( $val ) && ! is_bool( $val ) ) { return false; } break; default: return false; endswitch; $this->form[ $key ] = $val; return true; } /** * Add an input field to the form for outputting later * * @param string $label * @param string $args * @param string $slug */ function add_input( $label, $args = '', $slug = '' ) { if ( empty( $args ) ) { $args = array(); } // Create a valid id or class attribute if ( empty( $slug ) ) { $slug = $this->_make_slug( $label ); } $defaults = array( 'type' => 'text', 'name' => $slug, 'id' => $slug, 'label' => $label, 'value' => '', 'placeholder' => '', 'class' => array(), 'min' => '', 'max' => '', 'step' => '', 'autofocus' => false, 'checked' => false, 'selected' => false, 'required' => false, 'add_label' => true, 'options' => array(), 'wrap_tag' => 'div', 'wrap_class' => array( 'form_field_wrap' ), 'wrap_id' => '', 'wrap_style' => '', 'before_html' => '', 'after_html' => '', 'request_populate' => true ); // Combined defaults and arguments // Arguments override defaults $args = array_merge( $defaults, $args ); $this->inputs[ $slug ] = $args; } /** * Add multiple inputs to the input queue * * @param $arr * * @return bool */ function add_inputs( $arr ) { if ( ! is_array( $arr ) ) { return false; } foreach ( $arr as $field ) { $this->add_input( $field[0], isset( $field[1] ) ? $field[1] : '', isset( $field[2] ) ? $field[2] : '' ); } return true; } /** * Build the HTML for the form based on the input queue * * @param bool $echo Should the HTML be echoed or returned? * * @return string */ function build_form( $echo = true ) { $output = ''; if ( $this->form['form_element'] ) { $output .= '<form method="' . $this->form['method'] . '"'; if ( ! empty( $this->form['enctype'] ) ) { $output .= ' enctype="' . $this->form['enctype'] . '"'; } if ( ! empty( $this->form['action'] ) ) { $output .= ' action="' . $this->form['action'] . '"'; } if ( ! empty( $this->form['id'] ) ) { $output .= ' id="' . $this->form['id'] . '"'; } if ( count( $this->form['class'] ) > 0 ) { $output .= $this->_output_classes( $this->form['class'] ); } if ( $this->form['novalidate'] ) { $output .= ' novalidate'; } $output .= '>'; } // Add honeypot anti-spam field if ( $this->form['add_honeypot'] ) { $this->add_input( 'Leave blank to submit', array( 'name' => 'honeypot', 'slug' => 'honeypot', 'id' => 'form_honeypot', 'wrap_tag' => 'div', 'wrap_class' => array( 'form_field_wrap', 'hidden' ), 'wrap_id' => '', 'wrap_style' => 'display: none', 'request_populate' => false ) ); } // Add a WordPress nonce field if ( $this->form['add_nonce'] && function_exists( 'wp_create_nonce' ) ) { $this->add_input( 'WordPress nonce', array( 'value' => wp_create_nonce( $this->form['add_nonce'] ), 'add_label' => false, 'type' => 'hidden', 'request_populate' => false ) ); } // Iterate through the input queue and add input HTML foreach ( $this->inputs as $val ) : $min_max_range = $element = $end = $attr = $field = $label_html = ''; // Automatic population of values using $_REQUEST data if ( $val['request_populate'] && isset( $_REQUEST[ $val['name'] ] ) ) { // Can this field be populated directly? if ( ! in_array( $val['type'], array( 'html', 'title', 'radio', 'checkbox', 'select', 'submit' ) ) ) { $val['value'] = $_REQUEST[ $val['name'] ]; } } // Automatic population for checkboxes and radios if ( $val['request_populate'] && ( $val['type'] == 'radio' || $val['type'] == 'checkbox' ) && empty( $val['options'] ) ) { $val['checked'] = isset( $_REQUEST[ $val['name'] ] ) ? true : $val['checked']; } switch ( $val['type'] ) { case 'html': $element = ''; $end = $val['label']; break; case 'title': $element = ''; $end = ' <h3>' . $val['label'] . '</h3>'; break; case 'textarea': $element = 'textarea'; $end = '>' . $val['value'] . '</textarea>'; break; case 'select': $element = 'select'; $end .= '>'; foreach ( $val['options'] as $key => $opt ) { $opt_insert = ''; if ( // Is this field set to automatically populate? $val['request_populate'] && // Do we have $_REQUEST data to use? isset( $_REQUEST[ $val['name'] ] ) && // Are we currently outputting the selected value? $_REQUEST[ $val['name'] ] === $key ) { $opt_insert = ' selected'; // Does the field have a default selected value? } else if ( $val['selected'] === $key ) { $opt_insert = ' selected'; } $end .= '<option value="' . $key . '"' . $opt_insert . '>' . $opt . '</option>'; } $end .= '</select>'; break; case 'radio': case 'checkbox': // Special case for multiple check boxes if ( count( $val['options'] ) > 0 ) : $element = ''; foreach ( $val['options'] as $key => $opt ) { $slug = $this->_make_slug( $opt ); $end .= sprintf( '<input type="%s" name="%s[]" value="%s" id="%s"', $val['type'], $val['name'], $key, $slug ); if ( // Is this field set to automatically populate? $val['request_populate'] && // Do we have $_REQUEST data to use? isset( $_REQUEST[ $val['name'] ] ) && // Is the selected item(s) in the $_REQUEST data? in_array( $key, $_REQUEST[ $val['name'] ] ) ) { $end .= ' checked'; } $end .= $this->field_close(); $end .= ' <label for="' . $slug . '">' . $opt . '</label>'; } $label_html = '<div class="checkbox_header">' . $val['label'] . '</div>'; break; endif; // Used for all text fields (text, email, url, etc), single radios, single checkboxes, and submit default : $element = 'input'; $end .= ' type="' . $val['type'] . '" value="' . $val['value'] . '"'; $end .= $val['checked'] ? ' checked' : ''; $end .= $this->field_close(); break; } // Added a submit button, no need to auto-add one if ( $val['type'] === 'submit' ) { $this->has_submit = true; } // Special number values for range and number types if ( $val['type'] === 'range' || $val['type'] === 'number' ) { $min_max_range .= ! empty( $val['min'] ) ? ' min="' . $val['min'] . '"' : ''; $min_max_range .= ! empty( $val['max'] ) ? ' max="' . $val['max'] . '"' : ''; $min_max_range .= ! empty( $val['step'] ) ? ' step="' . $val['step'] . '"' : ''; } // Add an ID field, if one is present $id = ! empty( $val['id'] ) ? ' id="' . $val['id'] . '"' : ''; // Output classes $class = $this->_output_classes( $val['class'] ); // Special HTML5 fields, if set $attr .= $val['autofocus'] ? ' autofocus' : ''; $attr .= $val['checked'] ? ' checked' : ''; $attr .= $val['required'] ? ' required' : ''; // Build the label if ( ! empty( $label_html ) ) { $field .= $label_html; } elseif ( $val['add_label'] && ! in_array( $val['type'], array( 'hidden', 'submit', 'title', 'html' ) ) ) { if ( $val['required'] ) { $val['label'] .= ' <strong>*</strong>'; } $field .= '<label for="' . $val['id'] . '">' . $val['label'] . '</label>'; } // An $element was set in the $val['type'] switch statement above so use that if ( ! empty( $element ) ) { if ( $val['type'] === 'checkbox' ) { $field = ' <' . $element . $id . ' name="' . $val['name'] . '"' . $min_max_range . $class . $attr . $end . $field; } else { $field .= ' <' . $element . $id . ' name="' . $val['name'] . '"' . $min_max_range . $class . $attr . $end; } // Not a form element } else { $field .= $end; } // Parse and create wrap, if needed if ( $val['type'] != 'hidden' && $val['type'] != 'html' ) : $wrap_before = $val['before_html']; if ( ! empty( $val['wrap_tag'] ) ) { $wrap_before .= '<' . $val['wrap_tag']; $wrap_before .= count( $val['wrap_class'] ) > 0 ? $this->_output_classes( $val['wrap_class'] ) : ''; $wrap_before .= ! empty( $val['wrap_style'] ) ? ' style="' . $val['wrap_style'] . '"' : ''; $wrap_before .= ! empty( $val['wrap_id'] ) ? ' id="' . $val['wrap_id'] . '"' : ''; $wrap_before .= '>'; } $wrap_after = $val['after_html']; if ( ! empty( $val['wrap_tag'] ) ) { $wrap_after = '</' . $val['wrap_tag'] . '>' . $wrap_after; } $output .= $wrap_before . $field . $wrap_after; else : $output .= $field; endif; endforeach; // Auto-add submit button if ( ! $this->has_submit && $this->form['add_submit'] ) { $output .= '<div class="form_field_wrap"><input type="submit" value="Submit" name="submit"></div>'; } // Close the form tag if one was added if ( $this->form['form_element'] ) { $output .= '</form>'; } // Output or return? if ( $echo ) { echo $output; } else { return $output; } } // Easy way to auto-close fields, if necessary function field_close() { return $this->form['markup'] === 'xhtml' ? ' />' : '>'; } // Validates id and class attributes // TODO: actually validate these things private function _check_valid_attr( $string ) { $result = true; // Check $name for correct characters // "^[a-zA-Z0-9_-]*$" return $result; } // Create a slug from a label name private function _make_slug( $string ) { $result = ''; $result = str_replace( '"', '', $string ); $result = str_replace( "'", '', $result ); $result = str_replace( '_', '-', $result ); $result = preg_replace( '~[\W\s]~', '-', $result ); $result = strtolower( $result ); return $result; } // Parses and builds the classes in multiple places private function _output_classes( $classes ) { $output = ''; if ( is_array( $classes ) && count( $classes ) > 0 ) { $output .= ' class="'; foreach ( $classes as $class ) { $output .= $class . ' '; } $output .= '"'; } else if ( is_string( $classes ) ) { $output .= ' class="' . $classes . '"'; } return $output; } }
php
MIT
892ea8cfb67d54e9e46e3b691369c15b900b9be2
2026-01-05T04:55:38.223038Z
false
joshcanhelp/php-form-builder
https://github.com/joshcanhelp/php-form-builder/blob/892ea8cfb67d54e9e46e3b691369c15b900b9be2/index.php
index.php
<?php ini_set( 'display_errors', 1 ); error_reporting( E_ALL ); ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>PHPFormBuilder test</title> </head> <body> <?php require_once( 'PhpFormBuilder.php' ); /* Create a new instance Pass in a URL to set the action */ $form = new PhpFormBuilder(); /* Form attributes are modified with the set_att function. First argument is the setting Second argument is the value */ $form->set_att('method', 'post'); $form->set_att('enctype', 'multipart/form-data'); $form->set_att('markup', 'html'); $form->set_att('class', 'class_1'); $form->set_att('class', 'class_2'); $form->set_att('id', 'a_contact_form'); $form->set_att('novalidate', true); $form->set_att('add_honeypot', true); $form->set_att('add_nonce', 'a_contact_form'); $form->set_att('form_element', true); $form->set_att('add_submit', true); /* Uss add_input to create form fields First argument is the name Second argument is an array of arguments for the field Third argument is an alternative name field, if needed */ $form->add_input( 'Name', array( 'request_populate' => false ), 'contact_name' ); $form->add_input( 'Email', array( 'type' => 'email', 'class' => array( 'class_1', 'class_2', 'class_3' ) ), 'contact_email' ); $form->add_input( 'Filez', array( 'type' => 'file' ), 'filez_here' ); $form->add_input( 'Should we call you?', array( 'type' => 'checkbox', 'value' => 1 ) ); $form->add_input( 'True or false', array( 'type' => 'radio', 'checked' => false, 'value' => 1 ) ); $form->add_input( 'Reason for contacting', array( 'type' => 'checkbox', 'options' => array( 'say_hi' => 'Just saying hi!', 'complain' => 'I have a bone to pick', 'offer_gift' => 'I\'d like to give you something neat', ) ) ); $form->add_input( 'Bad Headline', array( 'type' => 'radio', 'options' => array( 'say_hi_2' => 'Just saying hi! 2', 'complain_2' => 'I have a bone to pick 2', 'offer_gift_2' => 'I\'d like to give you something neat 2', ) ) ); $form->add_input( 'Reason for contact', array( 'type' => 'select', 'options' => array( '' => 'Select...', 'say_hi' => 'Just saying hi!', 'complain' => 'I have a bone to pick', 'offer_gift' => 'I\'d like to give you something neat', ) ) ); $form->add_input( 'Question or comment', array( 'required' => true, 'type' => 'textarea', 'value' => 'Type away!' ) ); $form->add_inputs( array( array( 'Field 1' ), array( 'Field 2' ), array( 'Field 3' ) ) ); /* Create the form */ $form->build_form(); /* * Debugging */ echo '<pre>'; print_r( $_REQUEST ); echo '</pre>'; echo '<pre>'; print_r( $_FILES ); echo '</pre>'; ?> </body> </html>
php
MIT
892ea8cfb67d54e9e46e3b691369c15b900b9be2
2026-01-05T04:55:38.223038Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/footer.php
footer.php
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; if (!empty($this->options->cdn) && $this->options->cdn) { define('__TYPECHO_THEME_URL__', Typecho_Common::url(__TYPECHO_THEME_DIR__ . '/' . basename(dirname(__FILE__)), $this->options->cdn)); } ?> <section class="main-footer-waves-area waves-area"> <svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"> <defs> <path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z" /> </defs> <g class="parallax"> <use xlink:href="#gentle-wave" x="48" y="0" /> <use xlink:href="#gentle-wave" x="48" y="3" /> <use xlink:href="#gentle-wave" x="48" y="5" /> <use xlink:href="#gentle-wave" x="48" y="7" /> </g> </svg> </section> <section class="py-5 main-footer-info"> <div class="container-sm"> <div class="row"> <div class="d-none d-lg-block col main-footer-info-tags"> <h3 class="mb-3 main-footer-info-title main-footer-info-tags-title">标签</h3> <div class="d-flex flex-row flex-wrap align-items-start w-100 h-100 main-footer-info-tags-list"> <?php $this->widget('Widget_Metas_Tag_Cloud') ->to($taglist); ?><?php while($taglist->next()): ?> <a href="<?php $taglist->permalink(); ?>" title="<?php $taglist->name(); ?>" class="tag-item"><?php $taglist->name(); ?></a> <?php endwhile; ?> </div> </div> <div class="d-none d-lg-block col main-footer-info-navigation"> <h3 class="mb-3 main-footer-info-title main-footer-info-navigation-title">导航</h3> <div class="w-100 h-100 main-footer-info-navigation-list"> <div class="side-navbar-nav list-group list-group-flush"> 暂无导航 </div> </div> </div> </div> </div> </section> <footer class="main-footer"> <div class="container d-flex justify-content-md-between justify-content-center"> <div class="text-center main-footer-copyright"> <p>Powered by <a href="https://typecho.org/" rel="noopener nofollow" target="_blank">TYPECHO</a>. Copyright &copy; 2020. Crafted with <a href="https://github.com/JaydenForYou/Spring" target="_blank" rel="noopener nofollow">Spring</a>. </p> </div> <div class="d-none d-md-block main-footer-meta">只争朝夕,不负韶华。</div> </div> <div class="container d-flex flex-wrap-reverse justify-content-md-between justify-content-center text-center main-footer-audit"> <p> <?php if (!null == $this->options->beian): ?><a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener"><?php echo $this->options->beian ?></a><?php endif ?> </p> </div> </footer> </div> <div class="search-wrapper"> <div class="container-sm"> <button type="button" class="close search-close click-search-close" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> <div class="search-content"> <form id="search" method="post" action="<?php $this->options->siteUrl(); ?>" role="search"> <div class="search-form"> <i class="search-icon fas fa-search"></i> <label> <input type="text" name="s" id="ghost-search-field" class="search-input" placeholder="请输入搜索关键词..."> </label> </div> </form> </div> </div> </div> <div class="d-flex justify-content-center align-items-center flex-column animated fixed-to-top click-to-top"> <i class="fas fa-angle-double-up"></i> <?php if ($this->is('post')): ?> <span class="animated progress-number"></span> <?php endif ?> </div> </div> <div class="toast-wrapper" aria-live="polite" aria-atomic="true"> <div class="toast-wrapper-list"></div> </div> <script id="jquery-js" type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.bundle.min.js"></script> <?php if (Utils::isEnabled('enableComments', 'JConfig')): ?> <script type="text/javascript" src="<?php $this->options->themeUrl('assets/js/commentAjax.js'); ?>"></script> <?php endif ?> <script> const appId = "<?php $this->options->APPID()?>"; const appKey = "<?php $this->options->APPKEY()?>"; const serverUrls = "<?php $this->options->serverURLs()?>"; if ($('.next')) { $('.next').attr('class', 'page-link') $('.next').attr('aria-label', '下一页') $('.next').attr('title', '下一页') } if ($('.prev')) { $('.prev').attr('class', 'page-link') $('.prev').attr('aria-label', '上一页') $('.prev').attr('title', '上一页') } </script> <script type="text/javascript"> window.Spring = { name: "<?= $this->options->ititle ?>" } </script> <script type="text/javascript" src="<?php $this->options->themeUrl('assets/js/bundle.js'); ?>"></script> <?php $this->footer(); ?> </body> </html>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/page.php
page.php
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php $this->need('header.php'); ?> <section class="main-hero"> <div class="main-hero-bg" style="background-image: url('<?= $this->fields->thumbnail ?>')"></div> <div class="d-flex flex-column align-content-center justify-content-center main-hero-content"> <div class="text-center main-hero-content-title"><?= $this->title; ?></div> <div class="main-hero-waves-area waves-area"> <svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"> <defs> <path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"/> </defs> <g class="parallax"> <use xlink:href="#gentle-wave" x="48" y="0"/> <use xlink:href="#gentle-wave" x="48" y="3"/> <use xlink:href="#gentle-wave" x="48" y="5"/> <use xlink:href="#gentle-wave" x="48" y="7"/> </g> </svg> </div> </section> <main class="main-content"> <div class="container-sm"> <div class="row post-content-main"> <article class="col-12 col-sm-12 px-0 borderbox post-content article-main post-content-use-blank"> <?= Utils::getContent($this->content); ?> </article> </div> </main> <section class="main-footer-waves-area waves-area"> <svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"> <defs> <path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z" /> </defs> <g class="parallax"> <use xlink:href="#gentle-wave" x="48" y="0" /> <use xlink:href="#gentle-wave" x="48" y="3" /> <use xlink:href="#gentle-wave" x="48" y="5" /> <use xlink:href="#gentle-wave" x="48" y="7" /> </g> </svg> </section> <?php $this->need('footer.php'); ?>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/comments.php
comments.php
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php function threadedComments($comments, $options) { $commentClass = ''; if ($comments->authorId) { if ($comments->authorId == $comments->ownerId) { $commentClass .= ' comment-by-author'; } else { $commentClass .= ' comment-by-user'; } } $commentLevelClass = $comments->levels > 0 ? ' comment-child' : ' comment-parent'; ?> <?php $host = 'https://gravatar.loli.net'; $url = '/avatar/'; $rating = Helper::options()->commentsAvatarRating; $hash = md5(strtolower($comments->mail)); $email = strtolower($comments->mail); $qq = str_replace('@qq.com', '', $email); if (strstr($email, "qq.com") && is_numeric($qq) && strlen($qq) < 11 && strlen($qq) > 4) { $avatar = '//q3.qlogo.cn/g?b=qq&nk=' . $qq . '&s=100'; } else { $avatar = $host . $url . $hash . '?s=50' . '&r=' . $rating . '&d=mm'; } ?> <div class="vlist" id="<?php $comments->theId(); ?>"> <div class="vcard"> <img class="vimg" src="<?php echo $avatar ?>"> <div class="vh"> <div class="vhead"> <span class="vnick"><?php $comments->author(); ?></span><span class="vsys"><?php echo getBrowser($comments->agent); ?></span><span class="vsys"><?php echo getOs($comments->agent); ?></span> </div> <div class="vmeta"> <span class="vtime"><?php $comments->dateWord(); ?></span> <span class="vat"><a href="javascript:void(0);" onclick="replyMsg('<?php $comments->theId(); ?>', '<?= $comments->author; ?>')">回复</a></span> </div> <div class="vcontent"> <?php showCommentContent($comments->coid); ?> </div> </div> </div> <?php if ($comments->children) { ?> <?php $comments->threadedComments($options); ?> <?php } ?> </div> <?php } ?> <?php $this->comments()->to($comments); ?> <?php if ($this->allow('comment')): ?> <div class="blog-post-comments v" id="<?php $this->respondId(); ?>"> <form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" onsubmit="return false"> <?php if ($this->user->hasLogin()): ?> <?php _e('登录身份: '); ?><h5><a href="<?php $this->options->profileUrl(); ?>"><?php $this->user->screenName(); ?></a>. <a href="<?php $this->options->logoutUrl(); ?>" title="Logout"><?php _e('退出'); ?> &raquo;</a></h5> <div class="vwrap"> <div class="vheader item3"> </div> <div class="vedit"> <textarea name="text" id="veditor" class="veditor vinput" placeholder="说点什么?"><?php $this->remember('text', false); ?></textarea> </div> <div class="vcontrol"> <div class="col col-20" title="Markdown is supported"> <a href="https://segmentfault.com/markdown" target="_blank"> <svg class="markdown" viewbox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"> <path fill-rule="evenodd" d="M14.85 3H1.15C.52 3 0 3.52 0 4.15v7.69C0 12.48.52 13 1.15 13h13.69c.64 0 1.15-.52 1.15-1.15v-7.7C16 3.52 15.48 3 14.85 3zM9 11H7V8L5.5 9.92 4 8v3H2V5h2l1.5 2L7 5h2v6zm2.99.5L9.5 8H11V5h2v3h1.5l-2.51 3.5z"></path> </svg> </a> </div> <div class="col col-80 text-right"> <button type="submit" title="Cmd|Ctrl+Enter" class="vsubmit vbtn" id="misubmit">回复</button> <?php $security = $this->widget('Widget_Security'); ?> </div> </div> <div style="display:none;" class="vmark"> </div> </div> <?php else: ?> <div class="vwrap"> <div class="vheader item3"> <input name="author" placeholder="昵称" class="vnick vinput" type="text" value="<?php $this->remember('author'); ?>" required><input name="mail" placeholder="邮箱" class="vmail vinput" type="email" value="<?php $this->remember('mail'); ?>"<?php if ($this->options->commentsRequireMail): ?> required<?php endif; ?>><input name="url" placeholder="网址(http://)" class="vlink vinput" type="text" value="<?php $this->remember('mail'); ?>"<?php if ($this->options->commentsRequireMail): ?> required<?php endif; ?>> <input name="_" type="hidden" id="comment_token" value="<?php echo Helper::security()->getToken(Typecho_Request::getInstance()->getRequestUrl());?>"/> </div> <div class="vedit"> <textarea name="text" id="veditor" class="veditor vinput" placeholder="说点什么?"><?php $this->remember('text'); ?></textarea> </div> <div class="vcontrol"> <div class="col col-20" title="Markdown is supported"> <a href="https://segmentfault.com/markdown" target="_blank"> <svg class="markdown" viewbox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"> <path fill-rule="evenodd" d="M14.85 3H1.15C.52 3 0 3.52 0 4.15v7.69C0 12.48.52 13 1.15 13h13.69c.64 0 1.15-.52 1.15-1.15v-7.7C16 3.52 15.48 3 14.85 3zM9 11H7V8L5.5 9.92 4 8v3H2V5h2l1.5 2L7 5h2v6zm2.99.5L9.5 8H11V5h2v3h1.5l-2.51 3.5z"></path> </svg> </a> </div> <div class="col col-80 text-right"> <?php spam_protection_math(); ?> <button type="submit" title="Cmd|Ctrl+Enter" class="vsubmit vbtn" id="misubmit">回复</button> <?php $security = $this->widget('Widget_Security'); ?> </div> </div> <div style="display:none;" class="vmark"> </div> </div> <?php endif; ?> </form> <?php if ($this->commentsNum != 0): ?> <div class="vinfo" style="display:block;"> <div class="vcount col"> <span class="vnum"><?php $this->commentsNum('%d'); ?></span> 评论 </div> </div> <?php else: ?> <div class="vempty" style="display:block;">快来做第一个评论的人吧~</div> <?php endif; ?> <?php if ($comments->have()): ?> <?php $comments->listComments(); ?> <?php endif; ?> <?php $comments->pageNav('<i class="fa fa-angle-left"></i>', '<i class="fa fa-angle-right"></i>', 10, '', array('wrapTag' => 'div', 'wrapClass' => 'pagination', 'itemTag' => '', 'currentClass' => 'page-number',)); ?> <?php endif; ?>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/post.php
post.php
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php $this->need('header.php'); ?> <section class="main-hero"> <div class="main-hero-bg" style="background-image: url('<?= $this->fields->thumbnail ?>')"></div> <div class="d-flex flex-column align-content-center justify-content-center main-hero-content"> <div class="text-center main-hero-content-title"><?= $this->title; ?></div> <div class="text-center main-hero-content-description"><?php $this->author(); ?> / <?= date('Y-m-d', $this->created) ?> / <?= getCategory($this)['category'] ?> / 阅读量 <?php get_post_view($this) ?></div> </div> <div class="main-hero-waves-area waves-area"> <svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"> <defs> <path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"/> </defs> <g class="parallax"> <use xlink:href="#gentle-wave" x="48" y="0"/> <use xlink:href="#gentle-wave" x="48" y="3"/> <use xlink:href="#gentle-wave" x="48" y="5"/> <use xlink:href="#gentle-wave" x="48" y="7"/> </g> </svg> </div> </section> <main class="main-content"> <div class="container-sm"> <nav class="d-none d-md-block post-content-main-breadcrumb" aria-label="breadcrumb"> <ol class="px-3 py-0 px-md-0 breadcrumb"> <li class="breadcrumb-item"><a href="<?= $this->options->siteUrl() ?>"><?php $this->options->title(); ?></a> </li> <li class="breadcrumb-item"><a href="<?= getCategory($this)['url'] ?>"><?= getCategory($this)['category'] ?></a> </li> <li class="breadcrumb-item active" aria-current="page"><?= $this->title; ?></li> </ol> </nav> <div class="row post-content-main"> <article class="col-12 col-sm-12 col-md-9 col-lg-9 col-xl-9 px-0 borderbox post-content article-main"> <?= Utils::getContent($this->content); ?> </article> <div class="d-none d-md-block col-12 col-sm-12 col-md-3 col-lg-3 col-xl-3 px-0 article-toc-area"> <nav id="site-toc" data-toggle="toc" class="sticky-top article-toc-nav"> </nav> </div> </div> <section class="post-tools text-center w-100"> <button type="button" class="btn site-popover btn-tools-item btn-share btn-share-popover" data-container=".site-wrapper" data-toggle="popover" data-placement="bottom" data-trigger="focus" data-content="<ul class='d-flex justify-content-center align-items-center site-popover-wrapper-share'><li><a class='share-weibo' href='https://service.weibo.com/share/share.php?title=<?= $this->title; ?>&url=<?= $this->permalink; ?>&pic=<?= $this->fields->thumbnail ?>' title='分享到微博' target='_blank' rel='nofollow noopener'><i class='fab fa-weibo'></i></a></li><li><a class='share-qq' href='https://connect.qq.com/widget/shareqq/index.html?url=<?= $this->permalink; ?>&title=<?= $this->title; ?>&summary=<?= htmlspecialchars(excerpt($this->content)); ?>&pics=<?= $this->fields->thumbnail ?>&site=<?= $this->options->title ?>' title='分享到QQ' target='_blank' rel='nofollow noopener'><i class='fab fa-qq'></i></a></li><li><a class='share-wechat' title='分享到微信'><i class='fab fa-weixin'></i></a><div class='post-share-wechat-qr' id='wechat-qr-code-img'></div></li><li><a class='share-twitter' href='https://twitter.com/share?text=<?= $this->title; ?>&url=<?= $this->permalink; ?>' title='分享到推特' target='_blank' rel='nofollow noopener'><i class='fab fa-twitter'></i></a></li></ul>" > <i class="fas fa-share-alt"></i> </button> <button type="button" class="btn btn-tools-item btn-donation" data-toggle="collapse" data-target="#collapseDonation" aria-expanded="false" aria-controls="collapseDonation" title="捐赠" > <i class="fas fa-coffee"></i> </button> <div class="collapse collapse-donation" id="collapseDonation"> <div class="card card-body card-collapse"> <div class="row"> <?php if ($this->options->alipay != null): ?> <div class="col-sm"> <figure class="figure"> <img src="<?= $this->options->alipay; ?>" alt="支付宝捐赠" title="请使用支付宝扫一扫进行捐赠"> <figcaption class="figure-caption">请使用支付宝扫一扫进行捐赠</figcaption> </figure> </div> <?php endif ?> <?php if ($this->options->wpay != null): ?> <div class="col-sm"> <figure class="figure"> <img src="<?= $this->options->wpay; ?>" alt="微信捐赠" title="请使用微信扫一扫进行赞赏"> <figcaption class="figure-caption">请使用微信扫一扫进行赞赏</figcaption> </figure> </div> <?php endif ?> </div> </div> </div> </section> <ul class="post-copyright"> <li class="post-copyright-author"> <strong>文章作者: </strong> <?php $this->author(); ?> </li> <li class="post-copyright-link" style="word-wrap:break-word; word-break:break-all;"> <strong>文章链接:</strong> <a href="<?= $this->permalink; ?>" title="<?= $this->title; ?>"><?= $this->permalink; ?></a> </li> <li class="post-copyright-license"> <strong>版权声明: </strong>本博客所有文章除特别声明外,均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处! </li> </ul> <section class="d-flex justify-content-between align-items-center post-author-footer"> <section class="author-card d-flex justify-content-between align-items-center"> <?php echo $this->author->gravatar(320, 'G', NULL, 'author-profile-image') ?> <section class="author-card-content"> <h4 class="author-card-name"> <a href="<?= $this->author->permalink; ?>"><?php $this->author(); ?></a> </h4> <div class="author-card-social"> <a class="site-tooltip author-card-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->QQGROUP ?>" data-toggle="tooltip" data-placement="top" title="QQ"> <i class="fab fa-qq"></i> </a> <a class="site-popover author-card-social-links" href="#" data-container=".site-wrapper" data-toggle="popover" data-placement="top" data-trigger="hover" data-content="<div class='hero-social-wechat'><img src='<?php if ($this->options->wpay != null) { echo $this->options->wpay; } else { echo 'https://ae01.alicdn.com/kf/He5dccc6dc2d945f184c14f6bed323a4fI.png'; } ?>' alt='微信二维码'/></div>" > <i class="fab fa-weixin"></i> </a> <a class="site-tooltip author-card-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->weibo ?>" data-toggle="tooltip" data-placement="top" title="WeiBo"> <i class="fab fa-weibo"></i> </a> <a class="site-tooltip author-card-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->github ?>" data-toggle="tooltip" data-placement="top" title="Github"> <i class="fab fa-github"></i> </a> </div> <p><?= Utils::getAuthor($this->author->url)['bio'] ?></p> </section> </section> <div class="post-footer-right"> <a class="author-card-button" href="<?= $this->author->permalink; ?>">更多文章</a> </div> </section> <?php if (posts($this) != false || thePrev($this) != false || theNext($this) != false): ?> <aside class="post-read-more"> <div class="row read-next-feed"> <div class="col-lg px-0 px-sm-3 d-flex min-h-300 post-read-more-item"> <article class="read-next-card" style="background-image: url(https://demo.ghost.io/content/images/size/w600/2017/07/blog-cover.jpg)"> <header class="read-next-card-header"> <small class="read-next-card-header-sitetitle">&mdash; <?php $this->author(); ?> &mdash;</small> <h3 class="read-next-card-header-title"> <a href="<?= getCategory($this)['url']; ?>"><?= getCategory($this)['category']; ?></a> </h3> </header> <div class="read-next-divider"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M13 14.5s2 3 5 3 5.5-2.463 5.5-5.5S21 6.5 18 6.5c-5 0-7 11-12 11C2.962 17.5.5 15.037.5 12S3 6.5 6 6.5s4.5 3.5 4.5 3.5"></path> </svg> </div> <div class="read-next-card-content"> <ul> <?php if (posts($this) != false): ?> <?php foreach (posts($this) as $v) { ?> <li><a href="<?= $v['url'] ?>"><?= $v['title'] ?></a></li> <?php } ?> <?php endif; ?> </ul> </div> <footer class="read-next-card-footer"> <a href="<?= getCategory($this)['url']; ?>">查看更多文章 →</a> </footer> </article> </div> <?php if (thePrev($this) != false): ?> <div class="col-lg px-0 px-sm-3 d-flex min-h-300 post-read-more-item"> <article class="post-read-next"> <a class="post-read-next-image-link" href="<?= thePrev($this)['url']; ?>"> <img class="post-read-next-image" src="<?php if (!empty(thePrev($this)['thumbnail'])) { echo thePrev($this)['thumbnail']; } else { echo 'https://casper.ghost.org/v2.0.0/images/welcome-to-ghost.jpg'; } ?>" alt="#"> </a> <div class="post-read-next-content"> <a class="post-read-next-content-link" href="<?= thePrev($this)['url']; ?>"> <header class="post-read-next-header"> <span class="post-read-next-tags"><?= thePrev($this)['category']; ?></span> <h2 class="post-read-next-title"><?= thePrev($this)['title']; ?></h2> </header> <section class="post-read-next-excerpt"> <p><?= thePrev($this)['content']; ?></p> </section> </a> <footer class="post-read-next-meta"> <ul class="author-list"> <li class="author-list-item"> <a href="<?= thePrev($this)['url']; ?>" class="static-avatar"> <?php echo $this->author->gravatar(320, 'G', NULL, 'author-profile-image') ?> <span class="author-profile-name"><?php $this->author(); ?></span> </a> </li> </ul> <span class="reading-time"><?= thePrev($this)['rate'] ?>分钟阅读</span> </footer> </div> </article> </div> <?php endif; ?> <?php if (theNext($this) != false): ?> <div class="col-xl px-0 px-sm-3 d-flex min-h-300 post-read-more-item"> <article class="post-read-next"> <a class="post-read-next-image-link" href="<?= theNext($this)['url']; ?>"> <img class="post-read-next-image" src="<?php if (!empty(theNext($this)['thumbnail'])) { echo theNext($this)['thumbnail']; } else { echo 'https://casper.ghost.org/v2.0.0/images/welcome-to-ghost.jpg'; } ?>" alt="#"> </a> <div class="post-read-next-content"> <a class="post-read-next-content-link" href="<?= theNext($this)['url']; ?>"> <header class="post-read-next-header"> <span class="post-read-next-tags"><?= theNext($this)['category']; ?></span> <h2 class="post-read-next-title"><?= theNext($this)['title']; ?></h2> </header> <section class="post-read-next-excerpt"> <p><?= theNext($this)['content']; ?></p> </section> </a> <footer class="post-read-next-meta"> <ul class="author-list"> <li class="author-list-item"> <a href="<?= theNext($this)['url']; ?>" class="static-avatar"> <?php echo $this->author->gravatar(320, 'G', NULL, 'author-profile-image') ?> <span class="author-profile-name"><?php $this->author(); ?></span> </a> </li> </ul> <span class="reading-time"><?= theNext($this)['rate'] ?>分钟阅读</span> </footer> </div> </article> </div> <?php endif; ?> </div> </aside> <?php endif; ?> <div id="comments" class="w-100 post-comments"> <!-- 这里放置评论框 --> <?php if (Utils::isEnabled('enableComments', 'JConfig')): ?> <?php $this->need('comments.php'); ?> <?php else: ?> <div id="vcomments" class="v"> </div> <?php endif ?> </div> </div> </main> <?php $this->need('footer.php'); ?>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/page-about.php
page-about.php
<?php /** * 名片 * * @package custom * @author 林尽欢 * @link https://iobiji.com/ * @version 1.0.0 */ $this->need('header.php'); ?> <section class="main-hero template-about-me"> <div class="main-hero-bg" style="background-image: url('<?= $this->fields->thumbnail ?>')"></div> <div class="d-flex flex-column align-content-center justify-content-center main-hero-content"> <div class="text-center main-hero-content-title"><?= $this->title; ?></div> <div class="main-hero-waves-area waves-area"> <svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"> <defs> <path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"/> </defs> <g class="parallax"> <use xlink:href="#gentle-wave" x="48" y="0"/> <use xlink:href="#gentle-wave" x="48" y="3"/> <use xlink:href="#gentle-wave" x="48" y="5"/> <use xlink:href="#gentle-wave" x="48" y="7"/> </g> </svg> </div> </section> <main class="main-content custom-about-template"> <div class="d-flex justify-content-center align-items-center flex-column about-me-home"> <div class="col-12 col-sm-12 col-md-5 col-lg-5 col-xl-5 about-me"> <div class="about-me__side about-me__side--front"> <div class="about-me__cont"> <span class="blue">alert</span><span>(<span class="green">'Hello World!'</span>)</span> </div> </div> <div class="about-me__side about-me__side--back"> <!-- Back Content --> <div class="about-me__cta"> <p> <span class="purple">const</span> aboutMe <span class="cyan">=</span> { <br /> <span class="space red">name</span><span class="cyan">:</span> <span class="green">'Leslie Lin'</span>, <br/> <span class="space red">email</span><span class="cyan">:</span> <span class="green">'i@iobiji.com'</span>, <br/> <span class="space red">position</span><span class="cyan">:</span> <span class="green">'Web Front-End Developer'</span>, <br/> <span class="space red">website</span><span class="cyan">:</span> <span class="green">'https://iobiji.com'</span> <br/> }; </p> </div> </div> </div> </div> <div class="container-sm"> <div class="row"> <article class="col-12 col-sm-12 px-0 post-content article-main borderbox"> <?php echo Utils::getContent($this->content) ?> </article> </div> </div> </main> <section class="main-footer-waves-area waves-area"> <svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"> <defs> <path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z" /> </defs> <g class="parallax"> <use xlink:href="#gentle-wave" x="48" y="0" /> <use xlink:href="#gentle-wave" x="48" y="3" /> <use xlink:href="#gentle-wave" x="48" y="5" /> <use xlink:href="#gentle-wave" x="48" y="7" /> </g> </svg> </section> <?php $this->need('footer.php'); ?>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/search.php
search.php
<?php /** * 响应式TYPECHO主题 * * @package Spring * @author 林尽欢 * @version 1.0.1 * @link https://iobiji.com */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php $this->need('header.php'); $hiddens = ''; $hidden = ''; $prev = $this->_currentPage - 1; $next = $this->_currentPage + 1; if ($this->_currentPage == 0 || $this->_currentPage == 1) { $hidden = 'hidden'; $cpage = 1; } else { $cpage = $this->_currentPage; } if ($this->_currentPage == ceil($this->getTotal() / $this->parameter->pageSize)) { $hiddens = 'hidden'; } elseif (ceil($this->getTotal() / $this->parameter->pageSize) == 1) { $hiddens = 'hidden'; $hidden = 'hidden'; } ?> <section class="main-hero"> <div class="main-hero-bg" style="background-image: url('<?php if ($this->getDescription() != null && !$this->is('index') && !$this->is('author')) { echo Utils::getCategoryCount($this->getDescription())[1]; } else { echo $this->options->bgUrl; } ?>')"></div> <div class="d-flex flex-column align-content-center justify-content-center main-hero-content"> <?php if ($this->is('author')): ?> <div class="text-center main-hero-content-avatar"> <img class="main-hero-content-avatar-img" src="<?= Utils::getGravatar($this->author->mail) ?>" alt="头像"/> </div> <div class="text-center main-hero-content-title"><?php $this->author(); ?></div> <div class="text-center main-hero-content-description"><?= Utils::getAuthor($this->author->url)['bio'] ?></div> <div class="text-center main-hero-content-description"> <i class="fas fa-map-marker-alt"></i> <?= Utils::getAuthor($this->author->url)['location'] ?> <span class="date-divider"></span> <i class="fas fa-poll-h"></i> <?= Utils::getAuthorPosts($this->author->uid) ?> 篇文章 </div> <div class="text-center main-hero-content-social"> <a class="site-tooltip main-hero-content-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->QQGROUP ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="加入QQ群"> <i class="fab fa-qq"></i> </a> <a class="site-popover main-hero-content-social-links" href="#" data-container=".site-wrapper" data-toggle="popover" data-placement="bottom" data-trigger="hover" data-content="<div class='hero-social-wechat'><img src='<?php if ($this->options->wpay != null) { echo $this->options->wpay; } else { echo 'https://ae01.alicdn.com/kf/He5dccc6dc2d945f184c14f6bed323a4fI.png'; } ?>' alt='微信二维码'/></div>" > <i class="fab fa-weixin"></i> </a> <a class="site-tooltip main-hero-content-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->weibo ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="访问微博"> <i class="fab fa-weibo"></i> </a> <a class="site-tooltip main-hero-content-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->github ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="访问Github"> <i class="fab fa-github"></i> </a> <a class="site-tooltip main-hero-content-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= Utils::getAuthor($this->author->url)['site'] ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="个人地址"> <i class="fas fa-globe-asia"></i> </a> </div> <?php elseif ($this->is('category')): ?> <div class="text-center main-hero-content-title"><?php $this->archiveTitle(array( 'category' => _t('%s') ), '', ''); ?></div> <?php if ($this->getDescription() != null): ?> <div class="text-center main-hero-content-description"><?= Utils::getCategoryCount($this->getDescription())[0] ?></div><?php endif ?> <div class="text-center main-hero-content-description">该分类下有<?= Utils::getCnums($this->category) ?>篇文章 </div> <?php elseif ($this->is('index')): ?> <div class="text-center main-hero-content-title"><?= $this->options->ititle ?></div> <div class="text-center main-hero-content-description home-sentence">我最不喜欢做选择,但我选择了,就一定不后悔。</div> <?php endif ?> </div> <div class="main-hero-waves-area"> <svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"> <defs> <path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"/> </defs> <g class="parallax"> <use xlink:href="#gentle-wave" x="48" y="0"/> <use xlink:href="#gentle-wave" x="48" y="3"/> <use xlink:href="#gentle-wave" x="48" y="5"/> <use xlink:href="#gentle-wave" x="48" y="7"/> </g> </svg> </div> </section> <main class="main-content"> <div class="container-sm pb-3 pb-lg-0"> <?php while ($this->next()): ?> <article class="row mb-3 my-lg-5 post-card home-post-item"> <div class="col-12 col-sm-12 col-md-12 col-lg-7 col-xl-6 px-0<?php if ($this->sequence % 2 === 0) { echo ' order-md-last'; } ?>"> <div class="post-card-image"> <div class="post-card-image-shadow"></div> <a data-ajax href="<?= $this->permalink; ?>" class="post-card-image-link<?php if ($this->sequence % 2 === 0) { echo ' even'; } else { echo ' odd'; } ?>"> <div class="post-card-image-link-background" style="background-image: url('<?php if ($this->fields->thumbnail) { echo $this->fields->thumbnail; } else { echo Utils::getThumbnail(); } ?>')"></div> </a> </div> </div> <div class="col-12 col-sm-12 col-md-12 col-lg-6 col-xl-6<?php if ($this->sequence % 2 === 0) { echo ' order-md-first'; } ?>"> <div class="d-flex flex-column justify-content-center post-card-content"> <div class="text-center <?php if ($this->sequence % 2 === 0) { echo 'text-lg-right '; } else { echo 'text-lg-left '; } ?> mt-3 mt-lg-0 post-card-content-tag"> <i class="fas fa-bookmark"></i> <?php $this->category('/', false); ?> </div> <h3 class="<?php if ($this->sequence % 2 === 0) { echo 'text-right '; } else { echo 'text-left '; } ?>post-card-content-title"> <a data-ajax href="<?= $this->permalink; ?>" class="post-card-content-title-link"><?php $this->title(); ?></a> </h3> <p class="mb-3 mb-md-5 <?php if ($this->sequence % 2 === 0) { echo 'text-right '; } else { echo 'text-left '; } ?>post-card-content-excerpt"> <?php if ($this->fields->previewContent) $this->fields->previewContent(); else $this->excerpt(500, '...'); ?> </p> <div class="d-flex <?php if ($this->sequence % 2 === 0) { echo 'justify-content-start justify-content-md-end '; } else { echo 'justify-content-start '; } ?>align-items-center post-card-content-meta"> <div class="d-flex align-items-center mr-1 post-card-content-meta-authors"> <a href="<?= $this->author->permalink; ?>" class="post-card-content-meta-authors-link site-tooltip" data-toggle="tooltip" data-placement="top" title="<?php $this->author(); ?>"> <?php echo $this->author->gravatar(320, 'G', NULL, 'img-thumbnail rounded-circle post-card-content-meta-authors-link-avatar') ?> </a> </div> <div class="d-flex flex-column align-items-start ml-1 post-card-content-meta-other"> <div class="post-card-content-meta-other-date"> <i class="icon far fa-clock"></i> <?= date('Y-m-d', $this->created) ?> </div> <div class="post-card-content-meta-other-readtime"> <i class="icon far fa-bookmark"></i> <?= getRate($this->text); ?>分钟阅读 </div> </div> </div> </div> </div> </article> <?php endwhile; ?> </div> <?php if (ceil($this->getTotal() / $this->parameter->pageSize) <> 0): ?> <div class="container-sm"> <div class="py-3 py-md-5 site-pagination"> <nav aria-label="文章分页"> <ul class="mb-0 pagination"> <li class="page-item" <?php echo $hidden ?>> <?php $this->pageLink('<span aria-hidden="true"><i class="fas fa-angle-left"></i></span>') ?> </li> <li class="page-item"><a class="page-link">第 <?= $cpage ?> 页,共<?php echo ceil($this->getTotal() / $this->parameter->pageSize); ?>页</a></li> <li class="page-item" <?php echo $hiddens ?>> <?php $this->pageLink('<span aria-hidden="true"><i class="fas fa-angle-right"></i></span>','next')?> </li> </ul> </nav> </div> </div> <?php else: ?> <div class="container-sm"> <p style="text-align: center"><strong>搜索不到关键字为<?= Utils::getSkey($_SERVER['PHP_SELF']); ?>的文章</strong></p> </div> <?php endif ?> </main> <?php $this->need('footer.php'); ?>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/functions.php
functions.php
<?php error_reporting(0); if (!defined('__TYPECHO_ROOT_DIR__')) exit; define('Spring_VERSION', '1.0.1'); define('__TYPECHO_GRAVATAR_PREFIX__', Helper::options()->Gravatar ? Helper::options()->Gravatar : '//cdn.v2ex.com/gravatar/'); require_once 'lib/Utils.php'; require_once 'lib/Comments.php'; if (!empty(Helper::options()->cdn)) { define('__TYPECHO_UPLOAD_URL__', $_SERVER['REQUEST_SCHEME'] . '://' . Helper::options()->cdn); } function themeConfig($form) { echo '<script>var Spring_VERSION = "' . Spring_VERSION . '";</script>'; ?> <style>form { position: relative; max-width: 100% } form input:not([type]), form input[type="date"], form input[type="datetime-local"], form input[type="email"], form input[type="number"], form input[type="password"], form input[type="search"], form input[type="tel"], form input[type="time"], form input[type="text"], form input[type="file"], form input[type="url"] { font-family: 'Lato', 'Helvetica Neue', Arial, Helvetica, sans-serif; margin: 0em; outline: none; -webkit-appearance: none; tap-highlight-color: rgba(255, 255, 255, 0); line-height: 1.21428571em; padding: 0.67857143em 1em; font-size: 1em; background: #FFFFFF; border: 1px solid rgba(34, 36, 38, 0.15); color: rgba(0, 0, 0, 0.87); border-radius: 0.28571429rem; -webkit-box-shadow: 0em 0em 0em 0em transparent inset; box-shadow: 0em 0em 0em 0em transparent inset; -webkit-transition: color 0.5s ease, border-color 0.5s ease; transition: color 0.5s ease, border-color 0.5s ease } form textarea { margin: 0em; -webkit-appearance: none; tap-highlight-color: rgba(255, 255, 255, 0); padding: 0.78571429em 1em; background: #FFFFFF; border: 1px solid rgba(34, 36, 38, 0.15); outline: none; color: rgba(0, 0, 0, 0.87); border-radius: 0.28571429rem; -webkit-box-shadow: 0em 0em 0em 0em transparent inset; box-shadow: 0em 0em 0em 0em transparent inset; -webkit-transition: color 0.1s ease, border-color 0.5s ease; transition: color 0.1s ease, border-color 0.5s ease; font-size: 1em; line-height: 1.2857; resize: vertical } form textarea:not([rows]) { height: 12em; min-height: 8em; max-height: 24em } form textarea, form input[type="checkbox"] { vertical-align: top } form textarea:focus, form input:focus { color: rgba(0, 0, 0, 0.95); border-color: #85B7D9; border-radius: 0.28571429rem; background: #FFFFFF; -webkit-box-shadow: 0px 0em 0em 0em rgba(34, 36, 38, 0.35) inset; box-shadow: 0px 0em 0em 0em rgba(34, 36, 38, 0.35) inset; -webkit-appearance: none } .tip { max-width: 100%; position: relative; min-height: 1em; margin: 0 10px; background: #F8F8F9; padding: 1em 1.5em; line-height: 1.4285em; color: rgba(0, 0, 0, 0.87); -webkit-transition: opacity 0.1s ease, color 0.1s ease, background 0.1s ease, -webkit-box-shadow 0.1s ease; transition: opacity 0.1s ease, color 0.1s ease, background 0.1s ease, -webkit-box-shadow 0.1s ease; transition: opacity 0.1s ease, color 0.1s ease, background 0.1s ease, box-shadow 0.1s ease; transition: opacity 0.1s ease, color 0.1s ease, background 0.1s ease, box-shadow 0.1s ease, -webkit-box-shadow 0.1s ease; border-radius: 0.28571429rem; -webkit-box-shadow: 0 0 0 1px rgba(34, 36, 38, .22) inset, 0 2px 4px 0 rgba(34, 36, 38, .12), 0 2px 10px 0 rgba(34, 36, 38, .15); box-shadow: 0 0 0 1px rgba(34, 36, 38, .22) inset, 0 2px 4px 0 rgba(34, 36, 38, .12), 0 2px 10px 0 rgba(34, 36, 38, .15) } .tip-header { text-align: center; margin: 10px auto 20px auto; color: #444; text-shadow: 0 0 2px #c2c2c2 } .current-ver { position: relative; border-color: #b21e1e !important; background-color: #DB2828 !important; color: #FFF !important; left: -37px; padding-left: 1rem; border-bottom-right-radius: 5px; padding-right: 1.2em } .current-ver:after { position: absolute; content: ''; top: 100%; left: 0; background-color: transparent !important; border-style: solid; border-width: 0 1.2em 1.2em 0; border-color: transparent; border-right-color: inherit; width: 0; height: 0 } .btn.primary { cursor: pointer; display: inline-block; background: #E0E1E2 none; color: rgba(0, 0, 0, 0.6); padding: 0 1.5em; border-radius: 0.28571429rem; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; outline: none; -webkit-transition: opacity 0.5s ease, background-color 0.5s ease, color 0.5s ease, background 0.5s ease, -webkit-box-shadow 0.5s ease; transition: opacity 0.5s ease, background-color 0.5s ease, color 0.5s ease, background 0.5s ease, -webkit-box-shadow 0.5s ease; transition: opacity 0.5s ease, background-color 0.5s ease, color 0.5s ease, box-shadow 0.5s ease, background 0.5s ease; transition: opacity 0.5s ease, background-color 0.5s ease, color 0.5s ease, box-shadow 0.5s ease, background 0.5s ease, -webkit-box-shadow 0.5s ease; -webkit-tap-highlight-color: transparent } .btn.primary:hover { background-color: #CACBCD; color: rgba(0, 0, 0, 0.8) } .btn.primary[type="submit"] { position: fixed; right: 100px; bottom: 100px } .btn.confirm { background-color: #95f798 !important } .btn.alert { background-color: #fa9492 !important } i.confirm { position: absolute; left: .5em } i.confirm:after, i.confirm:before { content: ""; background: green; display: block; position: absolute; width: 3px; border-radius: 3px } i.confirm:after { height: 6px; transform: rotate(-45deg); top: 9px; left: 6px } i.confirm:before { height: 11px; transform: rotate(45deg); top: 5px; left: 10px } i.alert { position: absolute; left: .5em } i.alert:after, i.alert:before { content: ""; background: red; display: block; position: absolute; width: 3px; border-radius: 3px; left: 9px } i.alert:after { height: 3px; top: 14px } i.alert:before { height: 8px; top: 4px } .multiline { position: relative; display: inline-block; -webkit-backface-visibility: hidden; backface-visibility: hidden; outline: none; vertical-align: baseline; font-style: normal; min-height: 17px; font-size: 1rem; line-height: 17px; min-width: 17px } .multiline input[type="checkbox"], .multiline input[type="radio"] { cursor: pointer; position: absolute; top: 0px; left: 0px; opacity: 0 !important; outline: none; z-index: 3; width: 17px; height: 17px } .multiline { min-height: 1.5rem } .multiline input { width: 3.5rem; height: 1.5rem } .multiline .box, .multiline label { min-height: 1.5rem; padding-left: 4.5rem; color: rgba(0, 0, 0, 0.87) } .multiline label { padding-top: 0.15em } .multiline .box:before, .multiline label:before { cursor: pointer; display: block; position: absolute; content: ''; z-index: 1; -webkit-transform: none; transform: none; border: none; top: 0rem; background: rgba(0, 0, 0, 0.05); -webkit-box-shadow: none; box-shadow: none; width: 3.5rem; height: 1rem; border-radius: 500rem } .multiline .box:after, .multiline label:after { cursor: pointer; background: #FFFFFF -webkit-gradient(linear, left top, left bottom, from(transparent), to(rgba(0, 0, 0, 0.05))); background: #FFFFFF -webkit-linear-gradient(transparent, rgba(0, 0, 0, 0.05)); background: #FFFFFF linear-gradient(transparent, rgba(0, 0, 0, 0.05)); position: absolute; content: '' !important; opacity: 1; z-index: 2; border: none; -webkit-box-shadow: 0px 1px 2px 0 rgba(34, 36, 38, 0.15), 0px 0px 0px 1px rgba(34, 36, 38, 0.15) inset; box-shadow: 0px 1px 2px 0 rgba(34, 36, 38, 0.15), 0px 0px 0px 1px rgba(34, 36, 38, 0.15) inset; width: 1.2rem; height: 1.2rem; top: -.1rem; left: 0em; border-radius: 500rem; -webkit-transition: background 0.3s ease, left 0.3s ease; transition: background 0.3s ease, left 0.3s ease } .multiline input ~ .box:after, .multiline input ~ label:after { left: -0.05rem; -webkit-box-shadow: 0px 1px 2px 0 rgba(34, 36, 38, 0.15), 0px 0px 0px 1px rgba(34, 36, 38, 0.15) inset; box-shadow: 0px 1px 2px 0 rgba(34, 36, 38, 0.15), 0px 0px 0px 1px rgba(34, 36, 38, 0.15) inset } .multiline input:focus ~ .box:before, .multiline input:focus ~ label:before { background-color: rgba(0, 0, 0, 0.15); border: none } .multiline .box:hover::before, .multiline label:hover::before { background-color: rgba(0, 0, 0, 0.15); border: none } .multiline input:checked ~ .box, .multiline input:checked ~ label { color: rgba(0, 0, 0, 0.95) !important } .multiline input:checked ~ .box:before, .multiline input:checked ~ label:before { background-color: #2185D0 !important } .multiline input:checked ~ .box:after, .multiline input:checked ~ label:after { left: 2.3rem; -webkit-box-shadow: 0px 1px 2px 0 rgba(34, 36, 38, 0.15), 0px 0px 0px 1px rgba(34, 36, 38, 0.15) inset; box-shadow: 0px 1px 2px 0 rgba(34, 36, 38, 0.15), 0px 0px 0px 1px rgba(34, 36, 38, 0.15) inset } .multiline input:focus:checked ~ .box, .multiline input:focus:checked ~ label { color: rgba(0, 0, 0, 0.95) !important } .multiline input:focus:checked ~ .box:before, .multiline input:focus:checked ~ label:before { background-color: #0d71bb !important } #typecho-option-item-MathJaxConfig-15 { display: none } </style> <?php echo '<div class="tip"><span class="current-ver"><strong><code>Ver ' . Spring_VERSION . '</code></strong></span> <div class="tip-header"><h1>Theme-Spring</h1></div> <p>感谢选择使用 <code>Spring</code> </p> <p><a href="https://github.com/JaydenForYou/Spring/issues">issue</a></p> </div>'; $bgUrl = new Typecho_Widget_Helper_Form_Element_Text('bgUrl', NULL, 'https://www.bing.com/th?id=OHR.Lunarnewyeareve2020_ZH-CN1514309048_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=HpEdgeAn', _t('首页背景图片'), _t('在这里填入一个图片 URL 地址')); $Gravatar = new Typecho_Widget_Helper_Form_Element_Text('Gravatar', NULL, NULL, _t('自定义 Gravatar 源'), _t('输入Gravatar源,如https://cdn.v2ex.com/gravatar/')); $cdn = new Typecho_Widget_Helper_Form_Element_Text('cdn', NULL, NULL, _t('使用自己的静态存储'), _t('输入静态存储链接(不需要带http/https)')); $APPID = new Typecho_Widget_Helper_Form_Element_Text('APPID', NULL, NULL, _t('APP ID'), _t('输入在Valine获取的APP ID')); $APPKEY = new Typecho_Widget_Helper_Form_Element_Text('APPKEY', NULL, NULL, _t('APP KEY'), _t('输入在Valine获取的APP KEY')); $serverURLs = new Typecho_Widget_Helper_Form_Element_Text('serverURLs', NULL, NULL, _t('Valine安全域名'), _t('输入在Valine设置的安全域名')); $weibo = new Typecho_Widget_Helper_Form_Element_Text('weibo', NULL, '#', _t('微博地址'), _t('输入微博地址')); $beian = new Typecho_Widget_Helper_Form_Element_Text('beian', NULL, NULL, _t('ICP备案号'), _t('')); $Subtitle = new Typecho_Widget_Helper_Form_Element_Text('Subtitle', NULL, NULL, _t('站点副标题'), _t('')); $alipay = new Typecho_Widget_Helper_Form_Element_Text('alipay', NULL, NULL, _t('支付宝收款二维码链接'), _t('')); $wpay = new Typecho_Widget_Helper_Form_Element_Text('wpay', NULL, NULL, _t('微信收款二维码链接'), _t('')); $qiniu = new Typecho_Widget_Helper_Form_Element_Text('qiniu', NULL, NULL, _t('七牛云替换全站镜像'), _t('需要带http/https')); $github = new Typecho_Widget_Helper_Form_Element_Text('github', NULL, '#', _t('GITHUB'), _t('')); $QQGROUP = new Typecho_Widget_Helper_Form_Element_Text('QQGROUP', NULL, '#', _t('QQ群链接'), _t('')); $ititle = new Typecho_Widget_Helper_Form_Element_Text('ititle', NULL, '首页标题', _t('首页标题'), _t('')); $Logo = new Typecho_Widget_Helper_Form_Element_Text('Logo', NULL, '网站logo', _t('网站logo'), _t('')); $form->addInput($bgUrl); $form->addInput($Logo); $form->addInput($ititle); $form->addInput($Subtitle); $form->addInput($beian); $form->addInput($qiniu); $form->addInput($weibo); $form->addInput($Gravatar); $form->addInput($cdn); $form->addInput($APPID); $form->addInput($APPKEY); $form->addInput($serverURLs); $form->addInput($alipay); $form->addInput($wpay); $form->addInput($github); $form->addInput($QQGROUP); $JConfig = new Typecho_Widget_Helper_Form_Element_Checkbox('JConfig', array( 'enableComments' => '开启主题自带评论系统' ), [], '开关设置' ); $form->addInput($JConfig->multiMode()); } function themeFields($layout) { //$showTOC = new Typecho_Widget_Helper_Form_Element_Radio('showTOC', array(true => _t('开启'), false => _t('关闭')), false, _t('TOC文章目录解析'), _t('1代表开启,0代表关闭,解析h1-h6标签')); $previewContent = new Typecho_Widget_Helper_Form_Element_Text('previewContent', NULL, NULL, _t('文章摘要'), _t('设置文章的预览内容,留空自动截取文章前55个字。')); $thumbnail = new Typecho_Widget_Helper_Form_Element_Text('thumbnail', NULL, NULL, _t('文章/页面缩略图Url'), _t('需要带上http(s)://')); $layout->addItem($thumbnail); //$layout->addItem($showTOC); $layout->addItem($previewContent); } function get_post_view($archive) { $cid = $archive->cid; $db = Typecho_Db::get(); $prefix = $db->getPrefix(); if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) { $db->query('ALTER TABLE `' . $prefix . 'contents` ADD `views` INT(10) DEFAULT 0;'); echo 0; return; } $row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid)); if ($archive->is('single')) { $views = Typecho_Cookie::get('extend_contents_views'); if (empty($views)) { $views = array(); } else { $views = explode(',', $views); } if (!in_array($cid, $views)) { $db->query($db->update('table.contents')->rows(array('views' => (int)$row['views'] + 1))->where('cid = ?', $cid)); array_push($views, $cid); $views = implode(',', $views); Typecho_Cookie::set('extend_contents_views', $views); //记录查看cookie } } echo $row['views']; } function themeInit($archive) { // 判断是否是添加评论的操作 // 为文章或页面、post操作,且包含参数`themeAction=comment`(自定义) if ($archive->is('single') && $archive->request->isPost() && $archive->request->is('Ajax=comment')) { // 为添加评论的操作时 ajaxComment($archive); } } /** * ajaxComment * 实现Ajax评论的方法(实现feedback中的comment功能) * @param Widget_Archive $archive * @return void */ function ajaxComment($archive) { $options = Helper::options(); $user = Typecho_Widget::widget('Widget_User'); $db = Typecho_Db::get(); // Security 验证不通过时会直接跳转,所以需要自己进行判断 // 需要开启反垃圾保护,此时将不验证来源 if ($archive->request->get('_') != Helper::security()->getToken($archive->request->getReferer())) { $archive->response->throwJson(array('status' => 0, 'msg' => _t('非法请求'))); } /** 评论关闭 */ if (!$archive->allow('comment')) { $archive->response->throwJson(array('status' => 0, 'msg' => _t('评论已关闭'))); } /** 检查ip评论间隔 */ if (!$user->pass('editor', true) && $archive->authorId != $user->uid && $options->commentsPostIntervalEnable) { $latestComment = $db->fetchRow($db->select('created')->from('table.comments') ->where('cid = ?', $archive->cid) ->where('ip = ?', $archive->request->getIp()) ->order('created', Typecho_Db::SORT_DESC) ->limit(1)); if ($latestComment && ($options->gmtTime - $latestComment['created'] > 0 && $options->gmtTime - $latestComment['created'] < $options->commentsPostInterval)) { $archive->response->throwJson(array('status' => 0, 'msg' => _t('对不起, 您的发言过于频繁, 请稍侯再次发布'))); } } $comment = array( 'cid' => $archive->cid, 'created' => $options->gmtTime, 'agent' => $archive->request->getAgent(), 'ip' => $archive->request->getIp(), 'ownerId' => $archive->author->uid, 'type' => 'comment', 'status' => !$archive->allow('edit') && $options->commentsRequireModeration ? 'waiting' : 'approved' ); /** 判断父节点 */ if ($parentId = $archive->request->filter('int')->get('parent')) { if ($options->commentsThreaded && ($parent = $db->fetchRow($db->select('coid', 'cid')->from('table.comments') ->where('coid = ?', $parentId))) && $archive->cid == $parent['cid']) { $comment['parent'] = $parentId; } else { $archive->response->throwJson(array('status' => 0, 'msg' => _t('父级评论不存在'))); } } $feedback = Typecho_Widget::widget('Widget_Feedback'); //检验格式 $validator = new Typecho_Validate(); $validator->addRule('author', 'required', _t('必须填写用户名')); $validator->addRule('author', 'xssCheck', _t('请不要在用户名中使用特殊字符')); $validator->addRule('author', array($feedback, 'requireUserLogin'), _t('您所使用的用户名已经被注册,请登录后再次提交')); $validator->addRule('author', 'maxLength', _t('用户名最多包含200个字符'), 200); if ($options->commentsRequireMail && !$user->hasLogin()) { $validator->addRule('mail', 'required', _t('必须填写电子邮箱地址')); } $validator->addRule('mail', 'email', _t('邮箱地址不合法')); $validator->addRule('mail', 'maxLength', _t('电子邮箱最多包含200个字符'), 200); if ($options->commentsRequireUrl && !$user->hasLogin()) { $validator->addRule('url', 'required', _t('必须填写个人主页')); } $validator->addRule('url', 'url', _t('个人主页地址格式错误')); $validator->addRule('url', 'maxLength', _t('个人主页地址最多包含200个字符'), 200); $validator->addRule('text', 'required', _t('必须填写评论内容')); $comment['text'] = $archive->request->text; /** 对一般匿名访问者,将用户数据保存一个月 */ if (!$user->hasLogin()) { /** Anti-XSS */ $comment['author'] = $archive->request->filter('trim')->author; $comment['mail'] = $archive->request->filter('trim')->mail; $comment['url'] = $archive->request->filter('trim')->url; /** 修正用户提交的url */ if (!empty($comment['url'])) { $urlParams = parse_url($comment['url']); if (!isset($urlParams['scheme'])) { $comment['url'] = 'http://' . $comment['url']; } } $expire = $options->gmtTime + $options->timezone + 30 * 24 * 3600; Typecho_Cookie::set('__typecho_remember_author', $comment['author'], $expire); Typecho_Cookie::set('__typecho_remember_mail', $comment['mail'], $expire); Typecho_Cookie::set('__typecho_remember_url', $comment['url'], $expire); } else { $comment['author'] = $user->screenName; $comment['mail'] = $user->mail; $comment['url'] = $user->url; /** 记录登录用户的id */ $comment['authorId'] = $user->uid; } /** 评论者之前须有评论通过了审核 */ if (!$options->commentsRequireModeration && $options->commentsWhitelist) { if ($feedback->size($feedback->select()->where('author = ? AND mail = ? AND status = ?', $comment['author'], $comment['mail'], 'approved'))) { $comment['status'] = 'approved'; } else { $comment['status'] = 'waiting'; } } if ($error = $validator->run($comment)) { $archive->response->throwJson(array('status' => 0, 'msg' => implode(';', $error))); } /** 添加评论 */ if (preg_match("/[\x{4e00}-\x{9fa5}]/u", $comment['text']) == 0) { $archive->response->throwJson(array('status' => 0, 'msg' => _t('评论内容请不少于一个中文汉字'))); } $commentId = $feedback->insert($comment); if (!$commentId) { $archive->response->throwJson(array('status' => 0, 'msg' => _t('评论失败'))); } Typecho_Cookie::delete('__typecho_remember_text'); $db->fetchRow($feedback->select()->where('coid = ?', $commentId) ->limit(1), array($feedback, 'push')); $feedback->pluginHandle()->finishComment($feedback); // 返回评论数据 $data = array( 'cid' => $feedback->cid, 'coid' => $feedback->coid, 'parent' => $feedback->parent, 'mail' => $feedback->mail, 'url' => $feedback->url, 'ip' => $feedback->ip, 'browser' => getBrowser($feedback->agent), 'os' => getOs($feedback->agent), 'author' => $feedback->author, 'authorId' => $feedback->authorId, 'permalink' => $feedback->permalink, 'created' => $feedback->created, 'datetime' => $feedback->date->format('Y-m-d H:i:s'), 'status' => $feedback->status, ); // 评论内容 ob_start(); $feedback->content(); $data['content'] = ob_get_clean(); preg_match("~<p>(.*)</p>~", $data['content'], $newcontent); $data['content'] = $newcontent[1]; $data['avatar'] = Typecho_Common::gravatarUrl($data['mail'], 48, Helper::options()->commentsAvatarRating, NULL, $archive->request->isSecure()); $archive->response->throwJson(array('status' => 1, 'comment' => $data)); } function getCommentAt($coid) { $db = Typecho_Db::get(); $prow = $db->fetchRow($db->select('parent') ->from('table.comments') ->where('coid = ? AND status = ?', $coid, 'approved')); $parent = $prow['parent']; if ($parent != "0") { $arow = $db->fetchRow($db->select('author') ->from('table.comments') ->where('coid = ? AND status = ?', $parent, 'approved')); $author = $arow['author']; $href = '<a href="#comment-' . $parent . '" class="cute atreply">@' . $author . '</a>'; //$href = '@'.$author; return $href; } else { return ''; } } function ounts($sum, $total) { if ($sum > $total) { $sum -= 1; return ounts($sum, $total); } else { return $sum; } } /** * 随机输出文章 * * @access public */ function posts($widget) { $db = Typecho_Db::get(); $sql = $db->select()->from('table.contents') ->where('table.contents.status = ?', 'publish') ->where('table.contents.type = ?', $widget->type) ->where('table.contents.password IS NULL') ->order('table.contents.created', Typecho_Db::SORT_ASC); $data = $db->fetchALL($sql); $total = count($data); $nums = ounts(3, $total); $temp = array_rand($data, $nums); $content = array(); foreach ($temp as $val) { $content[] = $data[$val]; } if ($content) { $arr = array(); foreach ($content as $key => $v) { $contents = $widget->filter($content[$key]); $arr[$key]['title'] = $contents['title']; $arr[$key]['url'] = $contents['permalink']; //$arr[$key]['category'] = $contents['categories'][0]['name']; //$arr[$key]['timeStamp'] = $contents['date']->timeStamp; } return $arr; } else { return false; } } function excerpt($post_excerpt) { $post_excerpt = strip_tags(htmlspecialchars_decode($post_excerpt)); $post_excerpt = trim($post_excerpt); $patternArr = array('/\s/', '/ /'); $replaceArr = array('', ''); $post_excerpt = preg_replace($patternArr, $replaceArr, $post_excerpt); $value = mb_strcut($post_excerpt, 0, 400, 'utf-8'); return $value; } /** * 显示下一篇 * * @access public */ function theNext($widget) { $db = Typecho_Db::get(); $sql = $db->select()->from('table.contents') ->where('table.contents.created > ?', $widget->created) ->where('table.contents.status = ?', 'publish') ->where('table.contents.type = ?', $widget->type) ->where('table.contents.password IS NULL') ->order('table.contents.created', Typecho_Db::SORT_ASC) ->limit(1); $content = $db->fetchRow($sql); $arr = array(); $fields = array(); $rows = $db->fetchAll($db->select()->from('table.fields') ->where('cid = ?', $content['cid'])); foreach ($rows as $row) { $fields[$row['name']] = $row[$row['type'] . '_value']; } if ($content) { $content = $widget->filter($content); $arr['url'] = $content['permalink']; $arr['title'] = $content['title']; $arr['content'] = excerpt($content['text']); $arr['thumbnail'] = $fields['thumbnail']; $arr['category'] = $content['categories'][0]['name']; $arr['rate'] = getRate($content['text']); return $arr; } else { return false; } } /** * 显示上一篇 * * @access public */ function thePrev($widget) { $db = Typecho_Db::get(); $sql = $db->select()->from('table.contents') ->where('table.contents.created < ?', $widget->created) ->where('table.contents.status = ?', 'publish') ->where('table.contents.type = ?', $widget->type) ->where('table.contents.password IS NULL') ->order('table.contents.created', Typecho_Db::SORT_DESC) ->limit(1); $content = $db->fetchRow($sql); $arr = array(); $fields = array(); $rows = $db->fetchAll($db->select()->from('table.fields') ->where('cid = ?', $content['cid'])); foreach ($rows as $row) { $fields[$row['name']] = $row[$row['type'] . '_value']; } if ($content) { $content = $widget->filter($content); $arr['url'] = $content['permalink']; $arr['title'] = $content['title']; $arr['content'] = excerpt($content['text']); $arr['thumbnail'] = $fields['thumbnail']; $arr['category'] = $content['categories'][0]['name']; $arr['rate'] = getRate($content['text']); return $arr; } else { return false; } } function getRate($content) { $speed = 300; $nums = preg_replace('/[\x80-\xff]{1,3}/', ' ', $content, -1); $nums = strlen($nums); $rate = ceil($nums / $speed); return $rate; } function getCategory($widget) { $db = Typecho_Db::get(); $sql = $db->select()->from('table.contents') ->where('table.contents.cid = ?', $widget->cid); $content = $db->fetchRow($sql); $arr = array(); if ($content) { $content = $widget->filter($content); $arr['category'] = $content['categories'][0]['name']; $arr['url'] = $content['categories'][0]['permalink']; return $arr; } else { return false; } } function spam_protection_math() { $num1 = 1; $num2 = rand(1, 9); echo "$num1 + $num2 = "; echo "<input type=\"text\" name=\"sum\" class=\"vnick vinput\" value=\"\" size=\"25\" tabindex=\"4\" style=\" width:70px;\" placeholder=\"计算结果\">\n"; echo "<input type=\"hidden\" name=\"num1\" value=\"$num1\">\n"; echo "<input type=\"hidden\" name=\"num2\" value=\"$num2\">"; } function getBrowser($agent) { $outputer = false; if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) { $outputer = 'IE Browser'; } else if (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) { $str1 = explode('Firefox/', $regs[0]); $FireFox_vern = explode('.', $str1[1]); $outputer = 'Firefox Browser ' . $FireFox_vern[0]; } else if (preg_match('/Maxthon([\d]*)\/([^\s]+)/i', $agent, $regs)) { $str1 = explode('Maxthon/', $agent); $Maxthon_vern = explode('.', $str1[1]); $outputer = 'Maxthon Browser ' . $Maxthon_vern[0]; } else if (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $agent, $regs)) { $outputer = 'Sogo Browser'; } else if (preg_match('#360([a-zA-Z0-9.]+)#i', $agent, $regs)) { $outputer = '360 Browser'; } else if (preg_match('/Edge([\d]*)\/([^\s]+)/i', $agent, $regs)) { $str1 = explode('Edge/', $regs[0]); $Edge_vern = explode('.', $str1[1]); $outputer = 'Edge ' . $Edge_vern[0]; } else if (preg_match('/EdgiOS([\d]*)\/([^\s]+)/i', $agent, $regs)) { $str1 = explode('EdgiOS/', $regs[0]); $outputer = 'Edge'; } else if (preg_match('/UC/i', $agent)) { $str1 = explode('rowser/', $agent); $UCBrowser_vern = explode('.', $str1[1]); $outputer = 'UC Browser ' . $UCBrowser_vern[0]; } else if (preg_match('/OPR/i', $agent)) { $str1 = explode('OPR/', $agent); $opr_vern = explode('.', $str1[1]); $outputer = 'Open Browser ' . $opr_vern[0]; } else if (preg_match('/MicroMesseng/i', $agent, $regs)) { $outputer = 'Weixin Browser'; } else if (preg_match('/WeiBo/i', $agent, $regs)) { $outputer = 'WeiBo Browser'; } else if (preg_match('/QQ/i', $agent, $regs) || preg_match('/QQ Browser\/([^\s]+)/i', $agent, $regs)) { $str1 = explode('rowser/', $agent); $QQ_vern = explode('.', $str1[1]); $outputer = 'QQ Browser ' . $QQ_vern[0]; } else if (preg_match('/MQBHD/i', $agent, $regs)) { $str1 = explode('MQBHD/', $agent); $QQ_vern = explode('.', $str1[1]); $outputer = 'QQ Browser ' . $QQ_vern[0]; } else if (preg_match('/BIDU/i', $agent, $regs)) { $outputer = 'Baidu Browser'; } else if (preg_match('/LBBROWSER/i', $agent, $regs)) { $outputer = 'KS Browser'; } else if (preg_match('/TheWorld/i', $agent, $regs)) { $outputer = 'TheWorld Browser'; } else if (preg_match('/XiaoMi/i', $agent, $regs)) { $outputer = 'XiaoMi Browser'; } else if (preg_match('/UBrowser/i', $agent, $regs)) { $str1 = explode('rowser/', $agent); $UCBrowser_vern = explode('.', $str1[1]); $outputer = 'UCBrowser ' . $UCBrowser_vern[0]; } else if (preg_match('/mailapp/i', $agent, $regs)) { $outputer = 'Email Browser'; } else if (preg_match('/2345Explorer/i', $agent, $regs)) { $outputer = '2345 Browser'; } else if (preg_match('/Sleipnir/i', $agent, $regs)) { $outputer = 'Sleipnir Browser'; } else if (preg_match('/YaBrowser/i', $agent, $regs)) { $outputer = 'Yandex Browser'; } else if (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)) { $outputer = 'Opera Browser'; } else if (preg_match('/MZBrowser/i', $agent, $regs)) { $outputer = 'MZ Browser'; } else if (preg_match('/VivoBrowser/i', $agent, $regs)) { $outputer = 'Vivo Browser'; } else if (preg_match('/Quark/i', $agent, $regs)) { $outputer = 'Quark Browser'; } else if (preg_match('/mixia/i', $agent, $regs)) { $outputer = 'Mixia Browser'; } else if (preg_match('/fusion/i', $agent, $regs)) { $outputer = 'Fusion'; } else if (preg_match('/CoolMarket/i', $agent, $regs)) { $outputer = 'CoolMarket Browser'; } else if (preg_match('/Thunder/i', $agent, $regs)) { $outputer = 'Thunder Browser'; } else if (preg_match('/Chrome([\d]*)\/([^\s]+)/i', $agent, $regs)) { $str1 = explode('Chrome/', $agent); $chrome_vern = explode('.', $str1[1]); $outputer = 'Chrome ' . $chrome_vern[0]; } else if (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) { $str1 = explode('Version/', $agent); $safari_vern = explode('.', $str1[1]); $outputer = 'Safari ' . $safari_vern[0]; } else { return false; } return $outputer; } /** 获取操作系统信息 <?php echo getOs($comments->agent); ?>*/ function getOs($agent) { $os = false; if (preg_match('/win/i', $agent)) { if (preg_match('/nt 6.0/i', $agent)) { $os = 'Windows Vista'; } else if (preg_match('/nt 6.1/i', $agent)) { $os = 'Windows 7'; } else if (preg_match('/nt 6.2/i', $agent)) { $os = 'Windows 8'; } else if (preg_match('/nt 6.3/i', $agent)) { $os = 'Windows 8.1'; } else if (preg_match('/nt 5.1/i', $agent)) { $os = 'Windows XP'; } else if (preg_match('/nt 10.0/i', $agent)) { $os = 'Windows 10'; } else { $os = 'Windows'; } } else if (preg_match('/android/i', $agent)) { if (preg_match('/android 9/i', $agent)) { $os = 'Android P'; } else if (preg_match('/android 8/i', $agent)) { $os = 'Android O'; } else if (preg_match('/android 7/i', $agent)) { $os = 'Android N'; } else if (preg_match('/android 6/i', $agent)) { $os = 'Android M'; } else if (preg_match('/android 5/i', $agent)) { $os = 'Android L'; } else { $os = 'Android'; }
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
true
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/full-width-for-post.php
full-width-for-post.php
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php /** * 文章全宽模板 * * @package custom * @author 林尽欢 * @link https://iobiji.com/ * @version 1.0.0 */ $this->need('header.php'); ?> <section class="main-hero"> <div class="main-hero-bg" style="background-image: url('<?= $this->fields->thumbnail ?>')"></div> <div class="d-flex flex-column align-content-center justify-content-center main-hero-content"> <div class="text-center main-hero-content-title"><?= $this->title; ?></div> <div class="text-center main-hero-content-description"><?php $this->author(); ?> / <?= date('Y-m-d', $this->created) ?> / <?= getCategory($this)['category'] ?> / 阅读量 <?php get_post_view($this) ?></div> </div> <div class="main-hero-waves-area waves-area"> <svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"> <defs> <path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"/> </defs> <g class="parallax"> <use xlink:href="#gentle-wave" x="48" y="0"/> <use xlink:href="#gentle-wave" x="48" y="3"/> <use xlink:href="#gentle-wave" x="48" y="5"/> <use xlink:href="#gentle-wave" x="48" y="7"/> </g> </svg> </div> </section> <main class="main-content"> <div class="container-sm"> <div class="row post-content-main"> <article class="post tag-tips tag-vue tag-web-front-end borderbox post-content post-content-use-blank article-main"> <?= Utils::getContent($this->content); ?> </article> </div> <section class="post-tools text-center w-100"> <button type="button" class="btn site-popover btn-tools-item btn-share btn-share-popover" data-container=".site-wrapper" data-toggle="popover" data-placement="bottom" data-trigger="focus" data-content="<ul class='d-flex justify-content-center align-items-center site-popover-wrapper-share'><li><a class='share-weibo' href='https://service.weibo.com/share/share.php?title=<?= $this->title; ?>&url=<?= $this->permalink; ?>&pic=<?= $this->fields->thumbnail ?>' title='分享到微博' target='_blank' rel='nofollow noopener'><i class='fab fa-weibo'></i></a></li><li><a class='share-qq' href='https://connect.qq.com/widget/shareqq/index.html?url=<?= $this->permalink; ?>&title=<?= $this->title; ?>&summary=<?= htmlspecialchars(excerpt($this->content)); ?>&pics=<?= $this->fields->thumbnail ?>&site=<?= $this->options->title ?>' title='分享到QQ' target='_blank' rel='nofollow noopener'><i class='fab fa-qq'></i></a></li><li><a class='share-wechat' title='分享到微信'><i class='fab fa-weixin'></i></a><div class='post-share-wechat-qr' id='wechat-qr-code-img'></div></li><li><a class='share-twitter' href='https://twitter.com/share?text=<?= $this->title; ?>&url=<?= $this->permalink; ?>' title='分享到推特' target='_blank' rel='nofollow noopener'><i class='fab fa-twitter'></i></a></li></ul>" > <i class="fas fa-share-alt"></i> </button> <button type="button" class="btn btn-tools-item btn-donation" data-toggle="collapse" data-target="#collapseDonation" aria-expanded="false" aria-controls="collapseDonation" title="捐赠" > <i class="fas fa-coffee"></i> </button> <div class="collapse collapse-donation" id="collapseDonation"> <div class="card card-body card-collapse"> <div class="row"> <?php if ($this->options->alipay != null): ?> <div class="col-sm"> <figure class="figure"> <img src="<?= $this->options->alipay; ?>" alt="支付宝捐赠" title="请使用支付宝扫一扫进行捐赠"> <figcaption class="figure-caption">请使用支付宝扫一扫进行捐赠</figcaption> </figure> </div> <?php endif ?> <?php if ($this->options->wpay != null): ?> <div class="col-sm"> <figure class="figure"> <img src="<?= $this->options->wpay; ?>" alt="微信捐赠" title="请使用微信扫一扫进行赞赏"> <figcaption class="figure-caption">请使用微信扫一扫进行赞赏</figcaption> </figure> </div> <?php endif ?> </div> </div> </div> </section> <ul class="post-copyright"> <li class="post-copyright-author"> <strong>文章作者: </strong> <?php $this->author(); ?> </li> <li class="post-copyright-link" style="word-wrap:break-word; word-break:break-all;"> <strong>文章链接:</strong> <a href="<?= $this->permalink; ?>" title="<?= $this->title; ?>"><?= $this->permalink; ?></a> </li> <li class="post-copyright-license"> <strong>版权声明: </strong>本博客所有文章除特别声明外,均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处! </li> </ul> <section class="d-flex justify-content-between align-items-center post-author-footer"> <section class="author-card d-flex justify-content-between align-items-center"> <?php echo $this->author->gravatar(320, 'G', NULL, 'author-profile-image') ?> <section class="author-card-content"> <h4 class="author-card-name"> <a href="<?= $this->author->permalink; ?>"><?php $this->author(); ?></a> </h4> <div class="author-card-social"> <a class="site-tooltip author-card-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->QQGROUP ?>" data-toggle="tooltip" data-placement="top" title="QQ"> <i class="fab fa-qq"></i> </a> <a class="site-popover author-card-social-links" href="#" data-container=".site-wrapper" data-toggle="popover" data-placement="top" data-trigger="hover" data-content="<div class='hero-social-wechat'><img src='<?php if ($this->options->wpay != null) { echo $this->options->wpay; } else { echo 'https://ae01.alicdn.com/kf/He5dccc6dc2d945f184c14f6bed323a4fI.png'; } ?>' alt='微信二维码'/></div>" > <i class="fab fa-weixin"></i> </a> <a class="site-tooltip author-card-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->weibo ?>" data-toggle="tooltip" data-placement="top" title="WeiBo"> <i class="fab fa-weibo"></i> </a> <a class="site-tooltip author-card-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->github ?>" data-toggle="tooltip" data-placement="top" title="Github"> <i class="fab fa-github"></i> </a> </div> <p><?= Utils::getAuthor($this->author->url)['bio'] ?></p> </section> </section> <div class="post-footer-right"> <a class="author-card-button" href="<?= $this->author->permalink; ?>">更多文章</a> </div> </section> <?php if (posts($this) != false || thePrev($this) != false || theNext($this) != false): ?> <aside class="post-read-more"> <div class="row read-next-feed"> <div class="col-lg px-0 px-sm-3 d-flex min-h-300 post-read-more-item"> <article class="read-next-card" style="background-image: url(https://demo.ghost.io/content/images/size/w600/2017/07/blog-cover.jpg)"> <header class="read-next-card-header"> <small class="read-next-card-header-sitetitle">&mdash; <?php $this->author(); ?> &mdash;</small> <h3 class="read-next-card-header-title"> <a href="<?= getCategory($this)['url']; ?>"><?= getCategory($this)['category']; ?></a> </h3> </header> <div class="read-next-divider"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M13 14.5s2 3 5 3 5.5-2.463 5.5-5.5S21 6.5 18 6.5c-5 0-7 11-12 11C2.962 17.5.5 15.037.5 12S3 6.5 6 6.5s4.5 3.5 4.5 3.5"></path> </svg> </div> <div class="read-next-card-content"> <ul> <?php if (posts($this) != false): ?> <?php foreach (posts($this) as $v) { ?> <li><a href="<?= $v['url'] ?>"><?= $v['title'] ?></a></li> <?php } ?> <?php endif; ?> </ul> </div> <footer class="read-next-card-footer"> <a href="<?= getCategory($this)['url']; ?>">查看更多文章 →</a> </footer> </article> </div> <?php if (thePrev($this) != false): ?> <div class="col-lg px-0 px-sm-3 d-flex min-h-300 post-read-more-item"> <article class="post-read-next"> <a class="post-read-next-image-link" href="<?= thePrev($this)['url']; ?>"> <img class="post-read-next-image" src="<?php if (!empty(thePrev($this)['thumbnail'])) { echo thePrev($this)['thumbnail']; } else { echo 'https://casper.ghost.org/v2.0.0/images/welcome-to-ghost.jpg'; } ?>" alt="#"> </a> <div class="post-read-next-content"> <a class="post-read-next-content-link" href="<?= thePrev($this)['url']; ?>"> <header class="post-read-next-header"> <span class="post-read-next-tags"><?= thePrev($this)['category']; ?></span> <h2 class="post-read-next-title"><?= thePrev($this)['title']; ?></h2> </header> <section class="post-read-next-excerpt"> <p><?= thePrev($this)['content']; ?></p> </section> </a> <footer class="post-read-next-meta"> <ul class="author-list"> <li class="author-list-item"> <a href="<?= thePrev($this)['url']; ?>" class="static-avatar"> <?php echo $this->author->gravatar(320, 'G', NULL, 'author-profile-image') ?> <span class="author-profile-name"><?php $this->author(); ?></span> </a> </li> </ul> <span class="reading-time"><?= thePrev($this)['rate'] ?>分钟阅读</span> </footer> </div> </article> </div> <?php endif; ?> <?php if (theNext($this) != false): ?> <div class="col-xl px-0 px-sm-3 d-flex min-h-300 post-read-more-item"> <article class="post-read-next"> <a class="post-read-next-image-link" href="<?= theNext($this)['url']; ?>"> <img class="post-read-next-image" src="<?php if (!empty(theNext($this)['thumbnail'])) { echo theNext($this)['thumbnail']; } else { echo 'https://casper.ghost.org/v2.0.0/images/welcome-to-ghost.jpg'; } ?>" alt="#"> </a> <div class="post-read-next-content"> <a class="post-read-next-content-link" href="<?= theNext($this)['url']; ?>"> <header class="post-read-next-header"> <span class="post-read-next-tags"><?= theNext($this)['category']; ?></span> <h2 class="post-read-next-title"><?= theNext($this)['title']; ?></h2> </header> <section class="post-read-next-excerpt"> <p><?= theNext($this)['content']; ?></p> </section> </a> <footer class="post-read-next-meta"> <ul class="author-list"> <li class="author-list-item"> <a href="<?= theNext($this)['url']; ?>" class="static-avatar"> <?php echo $this->author->gravatar(320, 'G', NULL, 'author-profile-image') ?> <span class="author-profile-name"><?php $this->author(); ?></span> </a> </li> </ul> <span class="reading-time"><?= theNext($this)['rate'] ?>分钟阅读</span> </footer> </div> </article> </div> <?php endif; ?> </div> </aside> <?php endif; ?> <div id="comments" class="w-100 post-comments"> <!-- 这里放置评论框 --> <?php if (Utils::isEnabled('enableComments', 'JConfig')): ?> <?php $this->need('comments.php'); ?> <?php else: ?> <div id="vcomments" class="v"> </div> <?php endif ?> </div> </div> </main> <?php $this->need('footer.php'); ?>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/index.php
index.php
<?php /** * 响应式TYPECHO主题 * * @package Spring * @author 林尽欢 * @version 1.0.1 * @link https://iobiji.com */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <?php $this->need('header.php'); $hiddens = ''; $hidden = ''; $prev = $page . ($this->_currentPage - 1); $next = $page . ($this->_currentPage + 1); if ($this->_currentPage == 0 || $this->_currentPage == 1) { $hidden = 'hidden'; $cpage = 1; } else { $cpage = $this->_currentPage; } if ($this->_currentPage == ceil($this->getTotal() / $this->parameter->pageSize)) { $hiddens = 'hidden'; } elseif (ceil($this->getTotal() / $this->parameter->pageSize) == 1) { $hiddens = 'hidden'; $hidden = 'hidden'; } ?> <section class="main-hero"> <div class="main-hero-bg" style="background-image: url('<?php if ($this->getDescription() != null && !$this->is('index') && !$this->is('author')) { echo Utils::getCategoryCount($this->getDescription())[1]; } else { echo $this->options->bgUrl; } ?>')"></div> <div class="d-flex flex-column align-content-center justify-content-center main-hero-content"> <?php if ($this->is('author')): ?> <div class="text-center main-hero-content-avatar"> <img class="main-hero-content-avatar-img" src="<?= Utils::getGravatar($this->author->mail) ?>" alt="头像"/> </div> <div class="text-center main-hero-content-title"><?php $this->author(); ?></div> <div class="text-center main-hero-content-description"><?= Utils::getAuthor($this->author->url)['bio'] ?></div> <div class="text-center main-hero-content-description"> <i class="fas fa-map-marker-alt"></i> <?= Utils::getAuthor($this->author->url)['location'] ?> <span class="date-divider"></span> <i class="fas fa-poll-h"></i> <?= Utils::getAuthorPosts($this->author->uid) ?> 篇文章 </div> <div class="text-center main-hero-content-social"> <a class="site-tooltip main-hero-content-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->QQGROUP ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="加入QQ群"> <i class="fab fa-qq"></i> </a> <a class="site-popover main-hero-content-social-links" href="#" data-container=".site-wrapper" data-toggle="popover" data-placement="bottom" data-trigger="hover" data-content="<div class='hero-social-wechat'><img src='<?php if ($this->options->wpay != null) { echo $this->options->wpay; } else { echo 'https://ae01.alicdn.com/kf/He5dccc6dc2d945f184c14f6bed323a4fI.png'; } ?>' alt='微信二维码'/></div>" > <i class="fab fa-weixin"></i> </a> <a class="site-tooltip main-hero-content-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->weibo ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="访问微博"> <i class="fab fa-weibo"></i> </a> <a class="site-tooltip main-hero-content-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= $this->options->github ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="访问Github"> <i class="fab fa-github"></i> </a> <a class="site-tooltip main-hero-content-social-links" target="_blank" rel="noreferrer noopener nofollow" href="<?= Utils::getAuthor($this->author->url)['site'] ?>" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="个人地址"> <i class="fas fa-globe-asia"></i> </a> </div> <?php elseif ($this->is('category')): ?> <div class="text-center main-hero-content-title"><?php $this->archiveTitle(array( 'category' => _t('%s') ), '', ''); ?></div> <?php if ($this->getDescription() != null): ?> <div class="text-center main-hero-content-description"><?= Utils::getCategoryCount($this->getDescription())[0] ?></div><?php endif ?> <div class="text-center main-hero-content-description">该分类下有<?= Utils::getCnums($this->category) ?>篇文章 </div> <?php elseif ($this->is('index')): ?> <div class="text-center main-hero-content-title"><?= $this->options->ititle ?></div> <div class="text-center main-hero-content-description home-sentence">我最不喜欢做选择,但我选择了,就一定不后悔。</div> <?php endif ?> </div> <div class="main-hero-waves-area waves-area"> <svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"> <defs> <path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"/> </defs> <g class="parallax"> <use xlink:href="#gentle-wave" x="48" y="0"/> <use xlink:href="#gentle-wave" x="48" y="3"/> <use xlink:href="#gentle-wave" x="48" y="5"/> <use xlink:href="#gentle-wave" x="48" y="7"/> </g> </svg> </div> </section> <main class="main-content"> <div class="container-sm pb-3 pb-lg-0"> <?php while ($this->next()): ?> <article class="row mb-3 my-lg-5 post-card home-post-item"> <div class="col-12 col-sm-12 col-md-12 col-lg-7 col-xl-6 px-0<?php if ($this->sequence % 2 === 0) { echo ' order-md-last'; } ?>"> <div class="post-card-image"> <div class="post-card-image-shadow"></div> <a data-ajax href="<?= $this->permalink; ?>" class="post-card-image-link<?php if ($this->sequence % 2 === 0) { echo ' even'; } else { echo ' odd'; } ?>"> <div class="post-card-image-link-background" style="background-image: url('<?php if ($this->fields->thumbnail) { echo $this->fields->thumbnail; } else { echo Utils::getThumbnail(); } ?>')"></div> </a> </div> </div> <div class="col-12 col-sm-12 col-md-12 col-lg-6 col-xl-6<?php if ($this->sequence % 2 === 0) { echo ' order-md-first'; } ?>"> <div class="d-flex flex-column justify-content-center post-card-content"> <div class="text-center <?php if ($this->sequence % 2 === 0) { echo 'text-lg-right '; } else { echo 'text-lg-left '; } ?> mt-3 mt-lg-0 post-card-content-tag"> <i class="fas fa-bookmark"></i> <?php $this->category('/', false); ?> </div> <h3 class="<?php if ($this->sequence % 2 === 0) { echo 'text-right '; } else { echo 'text-left '; } ?>post-card-content-title"> <a data-ajax href="<?= $this->permalink; ?>" class="post-card-content-title-link"><?php $this->title(); ?></a> </h3> <p class="mb-3 mb-md-5 <?php if ($this->sequence % 2 === 0) { echo 'text-right '; } else { echo 'text-left '; } ?>post-card-content-excerpt"> <?php if ($this->fields->previewContent) $this->fields->previewContent(); else $this->excerpt(500, '...'); ?> </p> <div class="d-flex <?php if ($this->sequence % 2 === 0) { echo 'justify-content-start justify-content-md-end '; } else { echo 'justify-content-start '; } ?>align-items-center post-card-content-meta"> <div class="d-flex align-items-center mr-1 post-card-content-meta-authors"> <a href="<?= $this->author->permalink; ?>" class="post-card-content-meta-authors-link site-tooltip" data-toggle="tooltip" data-placement="top" title="<?php $this->author(); ?>"> <?php echo $this->author->gravatar(320, 'G', NULL, 'img-thumbnail rounded-circle post-card-content-meta-authors-link-avatar') ?> </a> </div> <div class="d-flex flex-column align-items-start ml-1 post-card-content-meta-other"> <div class="post-card-content-meta-other-date"> <i class="icon far fa-clock"></i> <?= date('Y-m-d', $this->created) ?> </div> <div class="post-card-content-meta-other-readtime"> <i class="icon far fa-bookmark"></i> <?= getRate($this->text); ?>分钟阅读 </div> </div> </div> </div> </div> </article> <?php endwhile; ?> </div> <?php if (ceil($this->getTotal() / $this->parameter->pageSize) <> 0): ?> <div class="container-sm"> <div class="py-3 py-md-5 site-pagination"> <nav aria-label="文章分页"> <ul class="mb-0 pagination"> <li class="page-item" <?php echo $hidden ?>> <?php $this->pageLink('<span aria-hidden="true"><i class="fas fa-angle-left"></i></span>') ?> </li> <li class="page-item"><a class="page-link">第 <?= $cpage ?> 页,共<?php echo ceil($this->getTotal() / $this->parameter->pageSize); ?>页</a></li> <li class="page-item" <?php echo $hiddens ?>> <?php $this->pageLink('<span aria-hidden="true"><i class="fas fa-angle-right"></i></span>','next')?> </li> </ul> </nav> </div> </div> <?php else: ?> <div class="container-sm"> <p style="text-align: center"><strong>暂无文章</strong></p> </div> <?php endif ?> </main> <?php $this->need('footer.php'); ?>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/404.php
404.php
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/> <title><?php $this->archiveTitle(array( 'category' => _t('%s'), 'search' => _t('%s'), 'tag' => _t('%s'), 'author' => _t('%s') ), '', ' - '); ?><?php $this->options->title(); ?><?php if ($this->is('index') && $this->options->Subtitle != null) { echo ' - ' . $this->options->Subtitle; } ?></title> <link rel="dns-prefetch" href="<?php $this->options->siteUrl(); ?>"> <?php if (!empty($this->options->qiniu)): ?> <link rel="dns-prefetch" href="<?php echo $this->options->qiniu; ?>"> <?php endif; ?> <?php if ($this->options->logoUrl): ?> <link rel="shortcut icon" href="<?= $this->options->logoUrl ?>" type="image/png"/> <?php endif; ?> <link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css"> <link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.12.0/css/all.min.css"> <link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/styles.css'); ?>"> <?php if ($this->is('post')): ?> <link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/style.css'); ?>"> <?php endif; ?> <?php if($this->options->Logo != null): ?> <link rel="shortcut icon" href="<?= $this->options->Logo; ?>" type="image/png" /> <?php endif ?> <?php $this->header(); ?> <?php if (!Utils::isEnabled('enableComments', 'JConfig') && $this->is('post')): ?> <script src='//unpkg.com/valine/dist/Valine.min.js'></script> <?php endif ?> </head> <main class="main-content template-error-404"> <div class="container-sm"> <div class="row"> <section class="d-flex flex-column justify-content-center align-items-center w-100 error-message"> <h1 class="error-code">Error 404</h1> <p class="error-description">Page not found</p> <a class="error-link" href="/">返回首页</a> </section> </div> </div> </main> <footer class="main-footer"> <div class="container d-flex justify-content-md-between justify-content-center"> <div class="text-center main-footer-copyright"> <p>Powered by <a href="https://typecho.org/" rel="noopener nofollow" target="_blank">TYPECHO</a>. Copyright &copy; 2020. Crafted with <a href="https://github.com/JaydenForYou/Spring" target="_blank" rel="noopener nofollow">Spring</a>. </p> </div> <div class="d-none d-md-block main-footer-meta">只争朝夕,不负韶华。</div> </div> <div class="container d-flex flex-wrap-reverse justify-content-md-between justify-content-center text-center main-footer-audit"> <p> <?php if (!null == $this->options->beian): ?><a href="http://www.beian.miit.gov.cn/" target="_blank" rel="nofollow noopener"><?php echo $this->options->beian ?></a><?php endif ?> </p> </div> </footer> </div> </div> <div class="toast-wrapper" aria-live="polite" aria-atomic="true"> <div class="toast-wrapper-list"></div> </div> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script> <script src="https://cdn.bootcss.com/jquery.pjax/2.0.1/jquery.pjax.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/scrollreveal@4.0.5/dist/scrollreveal.min.js"></script> <script> const bundle = "<?php $this->options->themeUrl('assets/js/bundle.js'); ?>"; const styleCss = "<?php $this->options->themeUrl('assets/css/style.css'); ?>"; const stylesCss = "<?php $this->options->themeUrl('assets/css/styles.css'); ?>"; const appId = "<?php $this->options->APPID()?>"; const appKey = "<?php $this->options->APPKEY()?>"; const serverUrls = "<?php $this->options->serverURLs()?>"; const Title = "<?= $this->options->ititle ?>"; </script> <script type="text/javascript" src="<?php $this->options->themeUrl('assets/js/bundle.js'); ?>"></script> <?php $this->footer(); ?> </body> </html>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/header.php
header.php
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; if (!empty($this->options->cdn) && $this->options->cdn) { define('__TYPECHO_THEME_URL__', Typecho_Common::url(__TYPECHO_THEME_DIR__ . '/' . basename(dirname(__FILE__)), $this->options->cdn)); } ?> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/> <title><?php $this->archiveTitle(array( 'category' => _t('%s'), 'search' => _t('%s'), 'tag' => _t('%s'), 'author' => _t('%s') ), '', ' - '); ?><?php $this->options->title(); ?><?php if ($this->is('index') && $this->options->Subtitle != null) { echo ' - ' . $this->options->Subtitle; } ?></title> <link rel="dns-prefetch" href="<?php $this->options->siteUrl(); ?>"> <?php if (!empty($this->options->qiniu)): ?> <link rel="dns-prefetch" href="<?php echo $this->options->qiniu; ?>"> <?php endif; ?> <?php if ($this->options->logoUrl): ?> <link rel="shortcut icon" href="<?= $this->options->logoUrl ?>" type="image/png"/> <?php endif; ?> <link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css"> <link id="fontawesome-css" type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/css/all.min.css"> <link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/styles.css'); ?>"> <?php if ($this->is('post') || $this->is('page')): ?> <link rel="stylesheet" href="<?php $this->options->themeUrl('assets/css/comments.css'); ?>"> <?php endif; ?> <?php if($this->options->Logo != null): ?> <link rel="shortcut icon" href="<?= $this->options->Logo; ?>" type="image/png" /> <?php endif ?> <?php $this->header(); ?> <?php if (!Utils::isEnabled('enableComments', 'JConfig') && $this->is('post')): ?> <script src='//unpkg.com/valine/dist/Valine.min.js'></script> <?php endif ?> </head> <body class="spring-body"> <div class="d-flex site-wrapper"> <div class="d-block d-lg-none d-xl-none sidebar-wrapper"> <div class="sidebar-container"> <div class="d-flex justify-content-between sidebar-header"> <div class="sidebar-title"><?= $this->options->title; ?></div> <div class="d-flex sidebar-right"> <div class="d-flex align-items-center justify-content-center sidebar-search click-search"> <i class="fas fa-search"></i> </div> <div class="d-flex align-items-center justify-content-center sidebar-close"> <i class="fas fa-times"></i> </div> </div> </div> <div class="list-group list-group-flush"> <?php $this->widget('Widget_Metas_Category_List')->to($category); ?> <?php while ($category->next()): ?> <a class="list-group-item list-group-item-action menu-item <?php if ($this->is('category', $category->slug)) { echo 'active'; } ?>" href="<?php $category->permalink(); ?>"><?php $category->name(); ?></a> <?php endwhile; ?> <?php $this->widget('Widget_Contents_Page_List')->to($pages); ?> <?php while ($pages->next()): ?> <a class="list-group-item list-group-item-action menu-item <?php if ($this->is('page', $pages->slug)) { echo 'active'; } ?>" href="<?php $pages->permalink(); ?>"><?php $pages->title(); ?></a> <?php endwhile; ?> </div> <div class="mt-2 text-center sidebar-footer"> <button type="button" class="btn site-tooltip btn-footer btn-dark-mode click-dark" data-toggle="tooltip" data-placement="bottom" title="切换风格"> 🌓 </button> </div> </div> </div> <div class="main-wrapper"> <?php if ($this->is('post')): ?> <div class="progress site-progress"> <div class="progress-bar reading-progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div> </div> <?php endif ?> <header class="fixed-top shadow-sm main-header scroll-reveal-header"> <nav class="navbar navbar-expand-lg header-navbar"> <div class="container"> <a class="navbar-brand" href="/"> <img src="https://getbootstrap.com/docs/4.4/assets/brand/bootstrap-solid.svg" width="30" height="30" class="d-inline-block align-top navbar-brand-logo" alt=""> <?= $this->options->title; ?> </a> <button class="navbar-toggler sidebar-toggler" type="button" data-toggle="collapse" aria-controls="sidebar-wrapper" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse"> <ul class="navbar-nav mr-auto"> <?php $this->widget('Widget_Metas_Category_List')->to($category); ?> <?php while ($category->next()): ?> <li class="nav-item<?php if ($this->is('category', $category->slug)) { echo ' nav-current active'; } ?>"><a class="nav-link" href="<?php $category->permalink(); ?>"><?php $category->name(); ?></a></li> <?php endwhile; ?> <?php $this->widget('Widget_Contents_Page_List')->to($pages); ?> <?php while ($pages->next()): ?> <li class="nav-item<?php if ($this->is('page', $pages->slug)) { echo ' nav-current active'; } ?>"><a class="nav-link" href="<?php $pages->permalink(); ?>"><?php $pages->title(); ?></a></li> <?php endwhile; ?> </ul> <div class="ml-auto nav-left"> <button type="button" class="btn site-tooltip btn-nav-left btn-dark-mode click-dark" data-toggle="tooltip" data-placement="bottom" title="切换风格"> 🌓 </button> <button type="button" class="btn site-tooltip btn-nav-left btn-search click-search" data-toggle="tooltip" data-placement="bottom" title="搜索文章"> <i class="fas fa-search"></i> </button> </div> </div> </div> </nav> </header>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/page-archive.php
page-archive.php
<?php /** * 文章归档 * * @package custom * @author 林尽欢 * @link https://iobiji.com/ * @version 1.0.0 */ $this->need('header.php'); ?> <?php Typecho_Widget::widget('Widget_Stat')->to($stat); ?> <body class="page-template page-links spring-body"> <section class="main-hero"> <div class="main-hero-bg" style="background-image: url('<?= $this->fields->thumbnail ?>')"></div> <div class="d-flex flex-column align-content-center justify-content-center main-hero-content"> <div class="text-center main-hero-content-title"><?= $this->title; ?></div> <div class="main-hero-waves-area waves-area"> <svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"> <defs> <path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"/> </defs> <g class="parallax"> <use xlink:href="#gentle-wave" x="48" y="0"/> <use xlink:href="#gentle-wave" x="48" y="3"/> <use xlink:href="#gentle-wave" x="48" y="5"/> <use xlink:href="#gentle-wave" x="48" y="7"/> </g> </svg> </div> </section> <main class="main-content"> <div class="container-sm"> <div class="row post-content-main"> <article class="borderbox post post-content article-main custom-archive-template page post-content-use-blank"> <div class="archive-page"> <div class="archive-page-title">截至 <?=date('Y年m月d日')?> 共写了<?php $stat->publishedPostsNum() ?>文章</div> <ul class="archive-page-list"> <?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=10000')->parse('<li class="archive-page-list-item"><time datetime="{year}-{month}-{day}">{year}-{month}-{day}</time><a href="{permalink}" class="archive-page-list-item-href" target="_blank">{title}</a></li>'); ?> </ul> </div> </article> </div> </main> </body> <?php $this->need('footer.php'); ?>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/page-links.php
page-links.php
<?php /** * 友链 * * @package custom * @author 林尽欢 * @link https://iobiji.com/ * @version 1.0.0 */ $this->need('header.php'); ?> <body class="page-template page-links spring-body"> <section class="main-hero"> <div class="main-hero-bg" style="background-image: url('<?= $this->fields->thumbnail ?>')"></div> <div class="d-flex flex-column align-content-center justify-content-center main-hero-content"> <div class="text-center main-hero-content-title"><?= $this->title; ?></div> <div class="main-hero-waves-area waves-area"> <svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"> <defs> <path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"/> </defs> <g class="parallax"> <use xlink:href="#gentle-wave" x="48" y="0"/> <use xlink:href="#gentle-wave" x="48" y="3"/> <use xlink:href="#gentle-wave" x="48" y="5"/> <use xlink:href="#gentle-wave" x="48" y="7"/> </g> </svg> </div> </section> <main class="main-content"> <div class="container-sm"> <div class="row post-content-main"> <article class="col-12 col-sm-12 px-0 borderbox post-content article-main custom-links-template page post-content-use-blank"> <?php echo Utils::getContent($this->content) ?> </article> </div> </main> </body> <?php $this->need('footer.php'); ?>
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/lib/Utils.php
lib/Utils.php
<?php if (!defined('__TYPECHO_ROOT_DIR__')) { exit; } /** * Utils.php * 部分工具 * * @author Jayden * @version since 1.0.3 */ class Utils { /** * 输出博客以及主题部分配置信息为前端提供接口 * * @return void */ public static function JConfig() { $JConfig = Helper::options()->JConfig; $options = Helper::options(); $enableLazyload = self::isEnabled('enableLazyload', 'JConfig'); $enableComments = self::isEnabled('enableComments', 'JConfig'); $enablePJAX = self::isEnabled('enablePJAX', 'JConfig'); $THEME_CONFIG = json_encode((object)array( "THEME_VERSION" => CREAMy_VERSION, "SITE_URL" => rtrim($options->siteUrl, "/"), "THEME_URL" => $options->themeUrl, "ENABLE_Comments" => $enableComments )); echo "<script>window.THEME_CONFIG = $THEME_CONFIG</script>\n"; } /** * 返回主题设置中某项开关的开启/关闭状态 * * @param string $item 项目名 * @param string $config 设置名 * * @return bool */ public static function isEnabled($item, $config) { $config = Helper::options()->$config; $status = !empty($config) && in_array($item, $config) ? true : false; return $status; } /** * 获取背景图片 * * @return void */ public static function getBackground() { $options = Helper::options(); if (!null == $options->qiniu) { $qurl = str_replace($options->siteUrl, $options->qiniu . '/', $options->themeUrl); } else { $qurl = $options->themeUrl; } if ($options->bgUrl) { echo $options->bgUrl; } else { echo $qurl . '/assets/img/hero-background.jpg'; } } /** * 获取默认缩略图 */ public static function getThumbnail() { /*$options = Helper::options(); if (!null == $options->qiniu) { $qurl = str_replace($options->siteUrl, $options->qiniu . '/', $options->themeUrl); } else { $qurl = $options->themeUrl; } return $qurl . '/assets/img/post.jpg';*/ return 'https://ae01.alicdn.com/kf/H54ab5ecac0e4422aa32abbde20d98842E.png'; } /** * 获取内容 */ public static function getContent($content) { $options = Helper::options(); if ($options->qiniu != null) { $site = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']; return str_replace($site, $options->qiniu, $content); } else { return $content; } } /** * 获取分类文章数量 */ public static function getCnums($name) { $db = Typecho_Db::get(); $cx = $db->fetchRow($db->select()->from('table.metas')->where('table.metas.type = ?', 'category')->where('table.metas.slug = ?', $name))['count']; if ($cx <= 0) { return 0; } return $cx; } /** * 获取评论者GRAVATAR头像 */ public static function gGravatar($author) { $db = Typecho_Db::get(); $cx = $db->fetchRow($db->select()->from('table.comments')->where('table.comments.author = ?', $author))['mail']; if (defined('__TYPECHO_GRAVATAR_PREFIX__')) { $url = __TYPECHO_GRAVATAR_PREFIX__; } else { if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { $http_type = 'https'; } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { $http_type = 'https'; } elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { $http_type = 'https'; } $http_type = 'http'; if ($http_type == 'https') { $url = 'https://secure.gravatar.com'; } else { $url = 'http://www.gravatar.com'; } $url .= '/avatar/'; } if (!empty($cx)) { $url .= md5(strtolower(trim($cx))); } $url .= '?s=60'; $url .= '&amp;r=G'; return $url; } public static function getCategoryCount($content) { $tmp = explode('$', $content); return $tmp; } public static function getSkey($key) { $tmp = explode('/search/', $key); $tmp = str_replace('/', '', $tmp); return $tmp[1]; } public static function getCagegoryName($slug) { $db = Typecho_Db::get(); $name = $db->fetchRow($db->select()->from('table.metas')->where('table.metas.type = ?', 'category')->where('table.metas.slug = ?', $slug))['name']; return $name; } public static function getAuthorPosts($id) { $db = Typecho_Db::get(); $postnum = $db->fetchRow($db->select(array('COUNT(authorId)' => 'allpostnum'))->from('table.contents')->where('table.contents.authorId=?', $id)->where('table.contents.type=?', 'post')); $postnum = $postnum['allpostnum']; return $postnum; } public static function getAuthor($data) { $tmp = explode('$', $data); $arr['site'] = $tmp[0]; $arr['bio'] = $tmp[1]; $arr['location'] = $tmp[2]; return $arr; } public static function getGravatar($email, $s = 96, $d = 'mp', $r = 'g', $img = false, $atts = array()) { $url = '//cdn.v2ex.com/gravatar/'; $url .= md5(strtolower(trim($email))); $url .= "?s=$s&d=$d&r=$r"; if ($img) { $url = '<img src="' . $url . '"'; foreach ($atts as $key => $val) $url .= ' ' . $key . '="' . $val . '"'; $url .= ' />'; } return $url; } }
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
unsafe-ptr/Spring
https://github.com/unsafe-ptr/Spring/blob/23d1f9522acf20328441432340609cef3cc74082/lib/Comments.php
lib/Comments.php
<?php if (!defined('__TYPECHO_ROOT_DIR__')) { exit; } /** * Comments.php * 评论相关组件 * * @author Jayden * @version since 1.0.4 */ class Comments { /** * 解析评论user-agent * * @param string $ua * * @return string */ public static function parseUseragent($ua) { // 解析操作系统 $htmlTag = ""; $os = null; $fontClass = null; if (preg_match('/Windows NT 6.0/i', $ua)) {$os = "Windows Vista"; } elseif (preg_match('/Windows NT 6.1/i', $ua)) {$os = "Windows 7"; } elseif (preg_match('/Windows NT 6.2/i', $ua)) {$os = "Windows 8"; } elseif (preg_match('/Windows NT 6.3/i', $ua)) {$os = "Windows 8.1"; } elseif (preg_match('/Windows NT 10.0/i', $ua)) {$os = "Windows 10"; } elseif (preg_match('/Windows NT 5.1/i', $ua)) {$os = "Windows XP"; } elseif (preg_match('/Windows NT 5.2/i', $ua) && preg_match('/Win64/i', $ua)) {$os = "Windows XP 64 bit"; } elseif (preg_match('/Android ([0-9.]+)/i', $ua, $matches)) {$os = "Android " . $matches[1]; } elseif (preg_match('/iPhone OS ([_0-9]+)/i', $ua, $matches)) {$os = 'iPhone ' . $matches[1]; } elseif (preg_match('/iPad/i', $ua)) {$os = "iPad"; } elseif (preg_match('/Mac OS X ([_0-9]+)/i', $ua, $matches)) {$os = 'Mac OS X ' . $matches[1]; } elseif (preg_match('/Gentoo/i', $ua)) {$os = 'Gentoo Linux'; } elseif (preg_match('/Ubuntu/i', $ua)) {$os = 'Ubuntu Linux'; } elseif (preg_match('/Debian/i', $ua)) {$os = 'Debian Linux'; } elseif (preg_match('/X11; FreeBSD/i', $ua)) {$os = 'FreeBSD'; } elseif (preg_match('/X11; Linux/i', $ua)) {$os = 'Linux'; } else { $os = 'unknown os'; } $htmlTag = '<span class="vsys">'.$os.'</span>'; $browser = null; //解析浏览器 if (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Sogou browser'; } elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = '360 browser '; } elseif (preg_match('#Maxthon( |\/)([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Maxthon '; } elseif (preg_match('#Edge( |\/)([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Edge '; } elseif (preg_match('#MicroMessenger/([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Wechat '; } elseif (preg_match('#QQ/([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'QQ Mobile '; } elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Chrome '; } elseif (preg_match('#CriOS/([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Chrome '; } elseif (preg_match('#Chromium/([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Chromium '; } elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Safari '; } elseif (preg_match('#opera mini#i', $ua)) { preg_match('#Opera/([a-zA-Z0-9.]+)#i', $ua, $matches); $browser = 'Opera Mini ';} elseif (preg_match('#Opera.([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Opera '; } elseif (preg_match('#QQBrowser ([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'QQ browser '; } elseif (preg_match('#UCWEB([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'UCWEB '; } elseif (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Internet Explorer '; } elseif (preg_match('#Trident/([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Internet Explorer 11'; } elseif (preg_match('#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i', $ua, $matches)) {$browser = 'Firefox '; } else { $browser = 'unknown br'; } $htmlTag .= "&nbsp;"; $htmlTag .= '<span class="vsys">'.$browser.'</span>'; return $htmlTag; } }
php
MIT
23d1f9522acf20328441432340609cef3cc74082
2026-01-05T04:55:52.719654Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/upgrade.php
upgrade.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ if (!defined("UPGRADABLE")) { exit(); } function rrmdir($dir) { $files = array_diff(scandir($dir), array('.','..')); foreach ($files as $file) { if (is_dir("$dir/$file")) { rrmdir("$dir/$file"); } else { unlink("$dir/$file"); } } return rmdir($dir); } switch ($version) { case '1.0.0': /* Change homepage id to slug */ $homepage = $this->core->getSettings('settings', 'homepage'); $homepage = $this->core->db('pages')->where('id', $homepage)->oneArray(); $this->core->db('settings')->where('field', 'homepage')->save(['value' => $homepage['slug']]); /* Add 404 pages if does not exist */ if (!$this->core->db('pages')->where('slug', '404')->where('lang', 'en_english')->oneArray()) { // 404 - EN $this->core->db()->pdo()->exec("INSERT INTO `pages` (`title`, `slug`, `desc`, `lang`, `template`, `date`, `content`) VALUES ('404', '404', 'Not found', 'en_english', 'index.html', datetime('now'), '<p>Sorry, page does not exist.</p>') "); } if (!$this->core->db('pages')->where('slug', '404')->where('lang', 'pl_polski')->oneArray()) { // 404 -PL $this->core->db()->pdo()->exec("INSERT INTO `pages` (`title`, `slug`, `desc`, `lang`, `template`, `date`, `content`) VALUES ('404', '404', 'Not found', 'pl_polski', 'index.html', datetime('now'), '<p>Niestety taka strona nie istnieje.</p>') "); } /* Remove LESS directory */ deleteDir('inc/less'); // Upgrade version $return = '1.0.1'; case '1.0.1': $return = "1.0.2"; case '1.0.2': $return = "1.0.3"; case '1.0.3': // Add columns for markdown flag - blog and pages $this->core->db()->pdo()->exec("ALTER TABLE blog ADD COLUMN markdown INTEGER DEFAULT 0"); $this->core->db()->pdo()->exec("ALTER TABLE pages ADD COLUMN markdown INTEGER DEFAULT 0"); $this->core->db()->pdo()->exec("CREATE TABLE `login_attempts` ( `ip` TEXT NOT NULL, `attempts` INTEGER NOT NULL, `expires` INTEGER NOT NULL DEFAULT 0 )"); $this->rcopy(BASE_DIR.'/tmp/update/admin', BASE_DIR.'/admin'); $return = "1.0.4"; case '1.0.4': $return = '1.0.4a'; case '1.0.4a': $this->core->db()->pdo()->exec("ALTER TABLE modules ADD COLUMN sequence INTEGER DEFAULT 0"); $this->rcopy(BASE_DIR.'/tmp/update/admin', BASE_DIR.'/admin'); $this->rcopy(BASE_DIR.'/tmp/update/.htaccess', BASE_DIR.'/.htaccess'); $this->rcopy(BASE_DIR.'/tmp/update/inc/fonts', BASE_DIR.'/inc/fonts'); $this->rcopy(BASE_DIR.'/tmp/update/themes/admin', BASE_DIR.'/themes/admin'); $return = '1.0.5'; case '1.0.5': if (file_exists(BASE_DIR.'/themes/default')) { $this->rcopy(BASE_DIR.'/tmp/update/themes/default/preview.png', BASE_DIR.'/themes/default/preview.png'); $this->rcopy(BASE_DIR.'/tmp/update/themes/default/manifest.json', BASE_DIR.'/themes/default/manifest.json'); $this->rcopy(BASE_DIR.'/tmp/update/themes/admin', BASE_DIR.'/themes/admin'); } $return = '1.1.0'; case '1.1.0': $this->core->db()->pdo()->exec('CREATE TABLE "blog_tags" ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `name` TEXT, `slug` TEXT );'); $this->core->db()->pdo()->exec('CREATE TABLE `blog_tags_relationship` ( `blog_id` INTEGER NOT NULL, `tag_id` INTEGER NOT NULL );'); $this->core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('contact', 'email', 1), ('contact', 'driver', 'mail'), ('contact', 'phpmailer.server', 'smtp.example.com'), ('contact', 'phpmailer.port', '587'), ('contact', 'phpmailer.username', 'login@example.com'), ('contact', 'phpmailer.name', 'Batflat contact'), ('contact', 'phpmailer.password', 'yourpassword')"); $this->rcopy(BASE_DIR.'/tmp/update/inc/core', BASE_DIR.'/inc/core'); $this->rcopy(BASE_DIR.'/tmp/update/themes/admin', BASE_DIR.'/themes/admin'); $this->rcopy(BASE_DIR.'/tmp/update/admin', BASE_DIR.'/admin'); $this->rcopy(BASE_DIR.'/tmp/update/index.php', BASE_DIR.'/index.php'); $return = '1.2.0'; case '1.2.0': $return = '1.2.1'; case '1.2.1': register_shutdown_function(function () { sleep(2); redirect(url([ADMIN, 'settings', 'updates'])); }); $lang = $this->core->getSettings('settings', 'lang_site'); $this->rcopy(BASE_DIR.'/tmp/update/admin', BASE_DIR.'/admin'); $this->rcopy(BASE_DIR.'/tmp/update/index.php', BASE_DIR.'/index.php'); $this->rcopy(BASE_DIR.'/tmp/update/LICENSE.txt', BASE_DIR.'/LICENSE.txt'); $this->rcopy(BASE_DIR.'/tmp/update/themes/admin', BASE_DIR.'/themes/admin'); $this->rcopy(BASE_DIR.'/tmp/update/themes/batblog', BASE_DIR.'/themes/batblog'); // Settings $this->core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'timezone', '".date_default_timezone_get()."')"); $this->core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'license', '')"); $this->core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('blog', 'latestPostsCount', '5')"); // Users $this->core->db()->pdo()->exec("ALTER TABLE users ADD COLUMN description TEXT NULL"); $this->core->db()->pdo()->exec("ALTER TABLE users ADD COLUMN avatar TEXT NULL"); $this->core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `remember_me` ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `token` text NOT NULL, `user_id` integer NOT NULL REFERENCES users(id) ON DELETE CASCADE, `expiry` integer NOT NULL )"); if (!is_dir(UPLOADS."/users")) { mkdir(UPLOADS."/users", 0777); } $users = $this->core->db('users')->toArray(); foreach ($users as $user) { $avatar = uniqid('avatar').'.png'; copy(MODULES.'/users/img/default.png', UPLOADS.'/users/'.$avatar); $this->core->db('users')->where('id', $user['id'])->save(['avatar' => $avatar]); } // Blog $this->core->db()->pdo()->exec("ALTER TABLE blog ADD COLUMN lang TEXT NULL"); $this->core->db()->pdo()->exec("UPDATE blog SET lang = '".$lang."'"); // Snippets $snippets = $this->core->db('snippets')->toArray(); foreach ($snippets as $snippet) { $this->core->db('snippets')->where('id', $snippet['id'])->save(['content' => '{lang: '.$lang.'}'.$snippet['content'].'{/lang}']); } $return = '1.3.0'; case '1.3.0': $this->core->db()->pdo()->exec("ALTER TABLE navs_items ADD COLUMN class TEXT NULL"); $return = '1.3.1'; case '1.3.1': $this->rcopy(BASE_DIR.'/backup/'.$backup_date.'/inc/core/defines.php', BASE_DIR.'/inc/core/defines.php'); $this->rcopy(BASE_DIR.'/tmp/update/themes/admin', BASE_DIR.'/themes/admin'); $return = '1.3.1a'; case '1.3.1a': $return = '1.3.1b'; case '1.3.1b': $return = '1.3.2'; case '1.3.2': $this->rcopy(BASE_DIR.'/tmp/update/admin', BASE_DIR.'/admin'); $this->rcopy(BASE_DIR.'/tmp/update/themes/admin', BASE_DIR.'/themes/admin'); $this->core->db()->pdo()->exec("INSERT INTO modules (`dir`) VALUES ('devbar')"); $return = '1.3.3'; case '1.3.3': $this->rcopy(BASE_DIR.'/tmp/update/admin', BASE_DIR.'/admin'); $this->rcopy(BASE_DIR.'/tmp/update/themes/admin', BASE_DIR.'/themes/admin'); $return = '1.3.4'; case '1.3.4': $this->rcopy(BASE_DIR.'/tmp/update/themes/admin/css', BASE_DIR.'/themes/admin/css'); $this->core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('contact', 'checkbox.switch', '0')"); $this->core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('contact', 'checkbox.content', 'I agree to the processing of personal data...')"); $return = '1.3.5'; case '1.3.5': $return = '1.3.6'; } return $return;
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/index.php
index.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ header('Content-Type:text/html;charset=utf-8'); define('BASE_DIR', __DIR__); require_once('inc/core/defines.php'); if (DEV_MODE) { error_reporting(E_ALL); ini_set('display_errors', 1); } else { error_reporting(0); } require_once('inc/core/lib/Autoloader.php'); ob_start(base64_decode('XEluY1xDb3JlXE1haW46OnZlcmlmeUxpY2Vuc2U=')); // Site core init $core = new Inc\Core\Site; ob_end_flush();
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/admin/index.php
admin/index.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ ob_start(); header('Content-Type:text/html;charset=utf-8'); define('BASE_DIR', __DIR__.'/..'); require_once('../inc/core/defines.php'); if (DEV_MODE) { error_reporting(E_ALL); ini_set('display_errors', 1); } else { error_reporting(0); } require_once('../inc/core/lib/Autoloader.php'); // Admin core init $core = new Inc\Core\Admin; if ($core->loginCheck()) { $core->loadModules(); // Modules routing $core->router->set('(:str)/(:str)(:any)', function ($module, $method, $params) use ($core) { $core->createNav($module, $method); if ($params) { $core->loadModule($module, $method, explode('/', trim($params, '/'))); } else { $core->loadModule($module, $method); } }); $core->router->execute(); $core->drawTheme('index.html'); $core->module->finishLoop(); } else { if (isset($_POST['login'])) { if ($core->login($_POST['username'], $_POST['password'], isset($_POST['remember_me']))) { if (count($arrayURL = parseURL()) > 1) { $url = array_merge([ADMIN], $arrayURL); redirect(url($url)); } redirect(url([ADMIN, 'dashboard', 'main'])); } } $core->drawTheme('login.html'); } ob_end_flush();
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/carousel/Info.php
inc/modules/carousel/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['carousel']['module_name'], 'description' => $core->lang['carousel']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.0', 'compatibility' => '1.3.*', 'icon' => 'retweet', ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/carousel/Site.php
inc/modules/carousel/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Carousel; use Inc\Core\SiteModule; class Site extends SiteModule { public function init() { $this->tpl->set('carousel', $this->_insertCarousels()); } private function _insertCarousels() { $assign = []; $tempAssign = []; $galleries = $this->db('galleries')->toArray(); if (!empty($galleries)) { foreach ($galleries as $gallery) { $items = $this->db('galleries_items')->where('gallery', $gallery['id'])->toArray(); $tempAssign = $gallery; if (count($items)) { foreach ($items as &$item) { $item['src'] = unserialize($item['src']); } $tempAssign['items'] = $items; $assign[$gallery['slug']] = $this->draw('carousel.html', ['carousel' => $tempAssign]); } } } return $assign; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/snippets/Admin.php
inc/modules/snippets/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Snippets; use Inc\Core\AdminModule; class Admin extends AdminModule { public function navigation() { return [ $this->lang('manage', 'general') => 'manage', $this->lang('add') => 'add', ]; } /** * list of snippets */ public function getManage() { $rows = $this->db('snippets')->toArray(); if (count($rows)) { foreach ($rows as &$row) { $row['tag'] = $this->tpl->noParse('{$snippet.'.$row['slug'].'}'); $row['editURL'] = url([ADMIN, 'snippets', 'edit', $row['id']]); $row['delURL'] = url([ADMIN, 'snippets', 'delete', $row['id']]); } } return $this->draw('manage.html', ['snippets' => $rows]); } /** * add new snippet */ public function getAdd() { return $this->getEdit(); } /** * edit snippet */ public function getEdit($id = null) { $this->_add2header(); if (!empty($redirectData = getRedirectData())) { $assign = $redirectData; } if ($id === null) { $row = ['name' => isset_or($assign['name'], null), 'content' => isset_or($assign['content'], null)]; $assign['title'] = $this->lang('add'); } elseif (!empty($row = $this->db('snippets')->oneArray($id))) { $assign['title'] = $this->lang('edit'); } else { redirect(url([ADMIN, 'snippets', 'manage'])); } $assign = array_merge($assign, htmlspecialchars_array($row)); $assign['languages'] = $this->_getLanguages($this->settings('settings', 'lang_site')); $assign['content'] = []; preg_match_all("/{lang: ([a-z]{2}_[a-z]+)}(.*?){\/lang}/ms", $row['content'], $matches); foreach ($matches[1] as $key => $value) { $assign['content'][trim($value)] = $this->tpl->noParse(trim($matches[2][$key])); } $assign['editor'] = $this->settings('settings', 'editor'); return $this->draw('form.html', ['snippets' => $assign]); } /** * remove snippet */ public function getDelete($id) { if ($this->db('snippets')->delete($id)) { $this->notify('success', $this->lang('delete_success')); } else { $this->notify('failure', $this->lang('delete_failure')); } redirect(url([ADMIN, 'snippets', 'manage'])); } /** * save snippet */ public function postSave($id = null) { unset($_POST['save']); $formData = htmlspecialchars_array($_POST); if (checkEmptyFields(['name'], $formData)) { $this->notify('failure', $this->lang('empty_inputs', 'general')); if (!$id) { redirect(url([ADMIN, 'snippets', 'add'])); } else { redirect(url([ADMIN, 'snippets', 'edit', $id])); } } $formData['name'] = trim($formData['name']); $formData['slug'] = createSlug($formData['name']); $tmp = null; foreach ($formData['content'] as $lang => $content) { $tmp .= "{lang: $lang}".$content."{/lang}"; } $formData['content'] = $tmp; if ($id === null) { // new $location = url([ADMIN, 'snippets', 'add']); if (!$this->db('snippets')->where('slug', $formData['slug'])->count()) { if ($this->db('snippets')->save($formData)) { $location = url([ADMIN, 'snippets', 'edit', $this->db()->lastInsertId()]); $this->notify('success', $this->lang('save_success')); } else { $this->notify('failure', $this->lang('save_failure')); } } else { $this->notify('failure', $this->lang('already_exists')); } } else { // edit if (!$this->db('snippets')->where('slug', $formData['slug'])->where('id', '<>', $id)->count()) { if ($this->db('snippets')->where($id)->save($formData)) { $this->notify('success', $this->lang('save_success')); } else { $this->notify('failure', $this->lang('save_failure')); } } else { $this->notify('failure', $this->lang('already_exists')); } $location = url([ADMIN, 'snippets', 'edit', $id]); } redirect($location, $formData); } /** * module JavaScript */ public function getJavascript() { header('Content-type: text/javascript'); echo $this->draw(MODULES.'/snippets/js/admin/snippets.js'); exit(); } private function _add2header() { // WYSIWYG $this->core->addCSS(url('inc/jscripts/wysiwyg/summernote.min.css')); $this->core->addJS(url('inc/jscripts/wysiwyg/summernote.min.js')); if ($this->settings('settings', 'lang_admin') != 'en_english') { $this->core->addJS(url('inc/jscripts/wysiwyg/lang/'.$this->settings('settings', 'lang_admin').'.js')); } // HTML EDITOR $this->core->addCSS(url('/inc/jscripts/editor/markitup.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/markitup.highlight.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/sets/html/set.min.css')); $this->core->addJS(url('/inc/jscripts/editor/highlight.min.js')); $this->core->addJS(url('/inc/jscripts/editor/markitup.min.js')); $this->core->addJS(url('/inc/jscripts/editor/markitup.highlight.min.js')); $this->core->addJS(url('/inc/jscripts/editor/sets/html/set.min.js')); // ARE YOU SURE? $this->core->addJS(url('inc/jscripts/are-you-sure.min.js')); // MODULE SCRIPTS $this->core->addJS(url([ADMIN, 'snippets', 'javascript'])); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/snippets/Info.php
inc/modules/snippets/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['snippets']['module_name'], 'description' => $core->lang['snippets']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.2', 'compatibility' => '1.3.*', 'icon' => 'puzzle-piece', 'install' => function () use ($core) { $core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `snippets` ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `name` text NOT NULL, `slug` text NOT NULL, `content` text NOT NULL )"); }, 'uninstall' => function () use ($core) { $core->db()->pdo()->exec("DROP TABLE `snippets`"); } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/snippets/Site.php
inc/modules/snippets/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Snippets; use Inc\Core\SiteModule; class Site extends SiteModule { public function init() { $this->_importSnippets(); } private function _importSnippets() { $rows = $this->db('snippets')->toArray(); $snippets = []; foreach ($rows as $row) { $snippets[$row['slug']] = $row['content']; } return $this->tpl->set('snippet', $snippets); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/devbar/Admin.php
inc/modules/devbar/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Devbar; use Inc\Core\AdminModule; class Admin extends AdminModule { private $timer = 0; public function __construct(\Inc\Core\Main $core) { parent::__construct($core); $this->timer = -microtime(true); } public function init() { if (DEV_MODE && strpos(get_headers_list('Content-Type'), 'text/html') !== false) { $this->core->addCSS(url(MODULES.'/devbar/css/style.css?ver={?= time() ?}')); } } public function finish() { if (DEV_MODE && strpos(get_headers_list('Content-Type'), 'text/html') !== false) { $a = \debug_backtrace(); foreach (Dump::$data as &$d) { $d['value'] = \htmlspecialchars($this->tpl->noParse($d['value'])); } echo $this->draw(MODULES.'/devbar/view/bar.html', [ 'devbar' => [ 'version' => $this->settings('settings', 'version'), 'timer' => round(($this->timer + microtime(true))*1000, 2), 'memory' => round(memory_get_usage()/1024/1024, 2), 'database' => \Inc\Core\Lib\QueryBuilder::lastSqls(), 'requests' => [ '$_GET' => ['print' => print_r($_GET, true), 'count' => count($_GET)], '$_POST' => ['print' => print_r($_POST, true), 'count' => count($_POST)], '$_COOKIE' => ['print' => print_r($_COOKIE, true), 'count' => 0], '$_SERVER' => ['print' => print_r($_SERVER, true), 'count' => 0], ], 'dump' => Dump::$data, 'sqlite' => $this->db()->pdo()->query('select sqlite_version()')->fetch()[0], 'modules' => array_keys($this->core->module->getArray()), ], ]); } } } require_once('functions.php');
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/devbar/Info.php
inc/modules/devbar/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['devbar']['module_name'], 'description' => $core->lang['devbar']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.0', 'compatibility' => '1.3.*', 'icon' => 'bug', 'install' => function() use($core) { }, 'uninstall' => function() use($core) { } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/devbar/functions.php
inc/modules/devbar/functions.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ function dump($variable) { $backtrace = debug_backtrace()[0]; Inc\Modules\Devbar\Dump::$data[] = [ 'trace' => 'file <b>'.str_replace(BASE_DIR, null, $backtrace['file']).'</b> in line <b>'.$backtrace['line'].'</b>', 'value' => print_r($variable, true), ]; } function http_response_status() { $text = null; switch (http_response_code()) { case 100: $text = 'Continue'; break; case 101: $text = 'Switching Protocols'; break; case 200: $text = 'OK'; break; case 201: $text = 'Created'; break; case 202: $text = 'Accepted'; break; case 203: $text = 'Non-Authoritative Information'; break; case 204: $text = 'No Content'; break; case 205: $text = 'Reset Content'; break; case 206: $text = 'Partial Content'; break; case 300: $text = 'Multiple Choices'; break; case 301: $text = 'Moved Permanently'; break; case 302: $text = 'Moved Temporarily'; break; case 303: $text = 'See Other'; break; case 304: $text = 'Not Modified'; break; case 305: $text = 'Use Proxy'; break; case 400: $text = 'Bad Request'; break; case 401: $text = 'Unauthorized'; break; case 402: $text = 'Payment Required'; break; case 403: $text = 'Forbidden'; break; case 404: $text = 'Not Found'; break; case 405: $text = 'Method Not Allowed'; break; case 406: $text = 'Not Acceptable'; break; case 407: $text = 'Proxy Authentication Required'; break; case 408: $text = 'Request Time-out'; break; case 409: $text = 'Conflict'; break; case 410: $text = 'Gone'; break; case 411: $text = 'Length Required'; break; case 412: $text = 'Precondition Failed'; break; case 413: $text = 'Request Entity Too Large'; break; case 414: $text = 'Request-URI Too Large'; break; case 415: $text = 'Unsupported Media Type'; break; case 500: $text = 'Internal Server Error'; break; case 501: $text = 'Not Implemented'; break; case 502: $text = 'Bad Gateway'; break; case 503: $text = 'Service Unavailable'; break; case 504: $text = 'Gateway Time-out'; break; case 505: $text = 'HTTP Version not supported'; break; default: $text = 'Unknown http status code "' . htmlentities($code) . '"'; break; } return $text; }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/devbar/Site.php
inc/modules/devbar/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Devbar; use Inc\Core\SiteModule; class Site extends SiteModule { private $timer = 0; public function __construct(\Inc\Core\Main $core) { parent::__construct($core); $this->timer = -microtime(true); } public function init() { if (DEV_MODE && strpos(get_headers_list('Content-Type'), 'text/html') !== false) { $this->core->addCSS(url(MODULES.'/devbar/css/style.css?ver={?= time() ?}')); } } public function finish() { if (DEV_MODE && strpos(get_headers_list('Content-Type'), 'text/html') !== false) { $a = \debug_backtrace(); foreach (Dump::$data as &$d) { $d['value'] = \htmlspecialchars($this->tpl->noParse($d['value'])); } echo $this->draw('bar.html', [ 'devbar' => [ 'version' => $this->settings('settings', 'version'), 'timer' => round(($this->timer + microtime(true))*1000, 2), 'memory' => round(memory_get_usage()/1024/1024, 2), 'database' => \Inc\Core\Lib\QueryBuilder::lastSqls(), 'requests' => [ '$_GET' => ['print' => print_r($_GET, true), 'count' => count($_GET)], '$_POST' => ['print' => print_r($_POST, true), 'count' => count($_POST)], '$_COOKIE' => ['print' => print_r($_COOKIE, true), 'count' => 0], '$_SERVER' => ['print' => print_r($_SERVER, true), 'count' => 0], ], 'dump' => Dump::$data, 'sqlite' => $this->db()->pdo()->query('select sqlite_version()')->fetch()[0], 'modules' => array_keys($this->core->module->getArray()), ], ]); } } } require_once('functions.php');
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/devbar/Dump.php
inc/modules/devbar/Dump.php
<?php namespace Inc\Modules\Devbar; class Dump { public static $data = []; }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/settings/Admin.php
inc/modules/settings/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Settings; use Inc\Core\AdminModule; use Inc\Core\Lib\License; use Inc\Core\Lib\HttpRequest; use ZipArchive; use RecursiveIteratorIterator; use RecursiveDirectoryIterator; use FilesystemIterator; use Inc\Modules\Settings\Inc\RecursiveDotFilterIterator; class Admin extends AdminModule { private $assign = []; private $feed_url = "http://feed.sruu.pl"; public function init() { if (file_exists(BASE_DIR.'/inc/engine')) { deleteDir(BASE_DIR.'/inc/engine'); } } public function navigation() { return [ $this->lang('general') => 'general', $this->lang('theme', 'general') => 'theme', $this->lang('translation') => 'translation', $this->lang('updates') => 'updates', ]; } public function getGeneral() { $settings = $this->settings('settings'); // lang if (isset($_GET['lang']) && !empty($_GET['lang'])) { $lang = $_GET['lang']; } else { $lang = $settings['lang_site']; } $settings['langs'] = [ 'site' => $this->_getLanguages($settings['lang_site'], 'selected'), 'admin' => $this->_getLanguages($settings['lang_admin'], 'selected') ]; $settings['themes'] = $this->_getThemes(); $settings['pages'] = $this->_getPages($lang); $settings['timezones'] = $this->_getTimezones(); $settings['system'] = [ 'php' => PHP_VERSION, 'sqlite' => $this->db()->pdo()->query('select sqlite_version()')->fetch()[0], 'sqlite_size' => $this->roundSize(filesize(BASE_DIR.'/inc/data/database.sdb')), 'system_size' => $this->roundSize($this->_directorySize(BASE_DIR)), ]; $settings['license'] = []; $settings['license']['type'] = $this->_verifyLicense(); switch ($settings['license']['type']) { case License::FREE: $settings['license']['name'] = $this->lang('free'); break; case License::COMMERCIAL: $settings['license']['name'] = $this->lang('commercial'); break; default: $settings['license']['name'] = $this->lang('invalid_license'); } foreach ($this->core->getRegisteredPages() as $page) { $settings['pages'][] = $page; } if (!empty($redirectData = getRedirectData())) { $settings = array_merge($settings, $redirectData); } $this->tpl->set('settings', $this->tpl->noParse_array(htmlspecialchars_array($settings))); $this->tpl->set('updateurl', url([ADMIN, 'settings', 'updates'])); return $this->draw('general.html'); } public function postSaveGeneral() { unset($_POST['save']); if (checkEmptyFields(array_keys($_POST), $_POST)) { $this->notify('failure', $this->lang('empty_inputs', 'general')); redirect(url([ADMIN, 'settings', 'general']), $_POST); } else { $errors = 0; if ($this->settings('settings', 'autodetectlang')) { $_POST['autodetectlang'] = isset_or($_POST['autodetectlang'], 0); } foreach ($_POST as $field => $value) { if (!$this->db('settings')->where('module', 'settings')->where('field', $field)->save(['value' => $value])) { $errors++; } } if (!$errors) { $this->notify('success', $this->lang('save_settings_success')); } else { $this->notify('failure', $this->lang('save_settings_failure')); } unset($_SESSION['lang']); redirect(url([ADMIN, 'settings', 'general'])); } } public function anyLicense() { if (isset($_POST['license-key'])) { $licenseKey = str_replace('-', null, $_POST['license-key']); if (!($licenseKey = License::getLicenseData($licenseKey))) { $this->notify('failure', $this->lang('license_invalid_key')); } $verify = License::verify($licenseKey); if ($verify != License::COMMERCIAL) { $this->notify('failure', $this->lang('license_invalid_key')); } else { $this->notify('success', $this->lang('license_good_key')); } } elseif (isset($_GET['downgrade'])) { $this->db('settings')->where('module', 'settings')->where('field', 'license')->save(['value' => '']); } redirect(url([ADMIN,'settings','general'])); } public function anyTheme($theme = null, $file = null) { $this->core->addCSS(url(MODULES.'/settings/css/admin/settings.css')); if (empty($theme) && empty($file)) { $this->tpl->set('settings', $this->settings('settings')); $this->tpl->set('themes', $this->_getThemes()); return $this->draw('themes.html'); } else { if ($file == 'activate') { $this->db('settings')->where('module', 'settings')->where('field', 'theme')->save(['value' => $theme]); $this->notify('success', $this->lang('theme_changed')); redirect(url([ADMIN, 'settings', 'theme'])); } // Source code editor $this->core->addCSS(url('/inc/jscripts/editor/markitup.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/markitup.highlight.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/sets/html/set.min.css')); $this->core->addJS(url('/inc/jscripts/editor/highlight.min.js')); $this->core->addJS(url('/inc/jscripts/editor/markitup.min.js')); $this->core->addJS(url('/inc/jscripts/editor/markitup.highlight.min.js')); $this->core->addJS(url('/inc/jscripts/editor/sets/html/set.min.js')); $this->assign['files'] = $this->_getThemeFiles($file, $theme); if ($file) { $file = $this->assign['files'][$file]['path']; } else { $file = reset($this->assign['files'])['path']; } $this->assign['content'] = $this->tpl->noParse(htmlspecialchars(file_get_contents($file))); $this->assign['lang'] = pathinfo($file, PATHINFO_EXTENSION); if (isset($_POST['save']) && !FILE_LOCK) { if (file_put_contents($file, htmlspecialchars_decode($_POST['content']))) { $this->notify('success', $this->lang('save_file_success')); } else { $this->notify('failure', $this->lang('save_file_failure')); } redirect(url([ADMIN, 'settings', 'theme', $theme, md5($file)])); } $this->tpl->set('settings', $this->settings('settings')); $this->tpl->set('theme', array_merge($this->_getThemes($theme), $this->assign)); return $this->draw('theme.html'); } } public function getTranslation() { if (isset($_GET['export'])) { $export = $_GET['export']; if (file_exists(BASE_DIR.'/inc/lang/'.$export)) { $file = tempnam("tmp", "zip"); $zip = new ZipArchive(); $zip->open($file, ZipArchive::OVERWRITE); foreach (glob(BASE_DIR.'/inc/lang/'.$export.'/admin/*.ini') as $f) { $zip->addFile($f, str_replace(BASE_DIR, null, $f)); } foreach (glob(MODULES.'/*/lang/'.$export.'.ini') as $f) { $zip->addFile($f, str_replace(BASE_DIR, null, $f)); } foreach (glob(MODULES.'/*/lang/admin/'.$export.'.ini') as $f) { $zip->addFile($f, str_replace(BASE_DIR, null, $f)); } // Close and send to users $zip->close(); header('Content-Type: application/zip'); header('Content-Length: ' . filesize($file)); header('Content-Disposition: attachment; filename="Batflat_'.str_replace('.', '-', $this->settings('settings', 'version')).'_'.$export.'.zip"'); readfile($file); unlink($file); exit(); } } if (!isset($_GET['lang'])) { $_GET['lang'] = $this->settings('settings', 'lang_site'); } if (!isset($_GET['source'])) { $_GET['source'] = 0; } $settings = [ 'langs' => $this->_getLanguages($_GET['lang']), 'langs_all' => $this->_getLanguages($_GET['lang'], 'active', true), 'selected' => $_GET['lang'], ]; $translations = $this->_getAllTranslations($_GET['lang']); $translation = $translations[$_GET['source']]; $translations = array_keys($translations); $this->tpl->set('translation', $translation); $this->tpl->set('translations', $translations); $this->tpl->set('module', $_GET['source']); $this->tpl->set('settings', $settings); //unset($translations, $settings); return $this->draw('translation.html'); } public function postTranslation() { if (!isset($_GET['lang'])) { $_GET['lang'] = $this->settings('settings', 'lang_site'); } if (!isset($_GET['source'])) { $_GET['source'] = 0; } if (isset($_POST['upload']) && FILE_LOCK === false) { $zip = new ZipArchive(); $allowedDest = '/(.*?inc\/)((jscripts|lang|modules).*$)/'; $count = 0; $file = !empty($_FILES['lang_package']['tmp_name']) ? $_FILES['lang_package']['tmp_name'] : '/'; $open = $zip->open($file); if ($open === true) { for ($i = 0; $i < $zip->numFiles; $i++) { $filename = pathinfo($zip->getNameIndex($i)); if (isset($filename['extension']) && ($filename['extension'] == 'ini' || $filename['extension'] == 'js') ) { preg_match($allowedDest, $filename['dirname'], $matches); $dest = realpath(BASE_DIR) . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . $matches[2]; if (!file_exists($dest)) { mkdir($dest, 0755, true); } copy( 'zip://' . $file . '#' . $filename['dirname'] . DIRECTORY_SEPARATOR . $filename['basename'], $dest . DIRECTORY_SEPARATOR . $filename['basename'] ); $count++; } } if ($count > 0) { $this->notify('success', $this->lang('lang_import_success')); } else { $this->notify('failure', $this->lang('lang_import_error')); } $zip->close(); } } if (isset($_POST['new_language']) && FILE_LOCK === false) { $lang = $_POST['language_name']; if (preg_match("/^[a-z]{2}_[a-z]+$/", $lang)) { if (file_exists(BASE_DIR.'/inc/lang/'.$lang)) { $this->notify('failure', $this->lang('new_lang_exists')); } else { if (mkdir(BASE_DIR.'/inc/lang/'.$lang.'/admin', 0755, true)) { $this->notify('success', $this->lang('new_lang_success')); redirect(url([ADMIN, 'settings', 'translation?lang='.$lang])); } else { $this->notify('success', $this->lang('new_lang_create_fail')); } } } else { $this->notify('failure', $this->lang('new_lang_failure')); } } if (isset($_POST['save'], $_POST[$_GET['source']]) && FILE_LOCK === false) { $toSave = $_POST[$_GET['source']]; if (is_numeric($_GET['source'])) { $pad = 0; array_walk($toSave['admin'], function ($value, $key) use (&$pad) { $length = strlen($key); if ($pad < $length) { $pad = $length; } }); $pad = $pad + 4 - $pad%4; $output = []; foreach ($toSave['admin'] as $key => $value) { $value = preg_replace("/(?<!\\\\)\"/", '\"', $value); $output[] = str_pad($key, $pad).'= "'.$value.'"'; } $output = implode("\n", $output); if (file_put_contents('../inc/lang/'.$_GET['lang'].'/admin/general.ini', $output)) { $this->notify('success', $this->lang('save_file_success')); } else { $this->notify('failure', $this->lang('save_file_failure')); } } else { if (isset($toSave['front'])) { $pad = 0; array_walk($toSave['front'], function ($value, $key) use (&$pad) { $length = strlen($key); if ($pad < $length) { $pad = $length; } }); $pad = $pad + 4 - $pad%4; $output = []; foreach ($toSave['front'] as $key => $value) { $value = preg_replace("/(?<!\\\\)\"/", '\"', $value); $output[] = str_pad($key, $pad).'= "'.$value.'"'; } $output = implode("\n", $output); if (file_put_contents(MODULES.'/'.$_GET['source'].'/lang/'.$_GET['lang'].'.ini', $output)) { $this->notify('success', $this->lang('save_file_success')); } else { $this->notify('failure', $this->lang('save_file_failure')); } } if (isset($toSave['admin'])) { $pad = 0; array_walk($toSave['admin'], function ($value, $key) use (&$pad) { $length = strlen($key); if ($pad < $length) { $pad = $length; } }); $pad = $pad + 4 - $pad%4; $output = []; foreach ($toSave['admin'] as $key => $value) { $value = preg_replace("/(?<!\\\\)\"/", '\"', $value); $output[] = str_pad($key, $pad).'= "'.$value.'"'; } $output = implode("\n", $output); if (file_put_contents(MODULES.'/'.$_GET['source'].'/lang/admin/'.$_GET['lang'].'.ini', $output)) { $this->notify('success', $this->lang('save_file_success')); } else { $this->notify('failure', $this->lang('save_file_failure')); } } } } redirect(url([ADMIN, 'settings', 'translation?lang='.$_GET['lang']])); } /** * remove language from server */ public function getDeleteLanguage($name) { if (($this->settings('settings', 'lang_site') == $name) || ($this->settings('settings', 'lang_admin') == $name)) { $this->notify('failure', $this->lang('lang_delete_failure')); } else { if (unlink(BASE_DIR.'/inc/lang/'.$name.'/.lock') && deleteDir(BASE_DIR.'/inc/lang/'.$name)) { $this->notify('success', $this->lang('lang_delete_success')); } else { $this->notify('failure', $this->lang('lang_delete_failure')); } } redirect(url([ADMIN, 'settings', 'translation'])); } /** * activate language */ public function getActivateLanguage($name) { if (unlink(BASE_DIR.'/inc/lang/'.$name.'/.lock')) { $this->notify('success', $this->lang('lang_activate_success')); } else { $this->notify('failure', $this->lang('lang_activate_failure')); } redirect(url([ADMIN, 'settings', 'translation'])); } /** * deactivate language */ public function getDeactivateLanguage($name) { if (($this->settings('settings', 'lang_site') == $name) || ($this->settings('settings', 'lang_admin') == $name)) { $this->notify('failure', $this->lang('lang_deactivate_failure')); } else { if (touch(BASE_DIR.'/inc/lang/'.$name.'/.lock')) { $this->notify('success', $this->lang('lang_deactivate_success')); } else { $this->notify('failure', $this->lang('lang_deactivate_failure')); } } redirect(url([ADMIN, 'settings', 'translation'])); } public function anyUpdates() { $this->tpl->set('allow_curl', intval(function_exists('curl_init'))); $settings = $this->settings('settings'); if (isset($_POST['check'])) { $request = $this->updateRequest('/batflat/update', [ 'ip' => isset_or($_SERVER['SERVER_ADDR'], $_SERVER['SERVER_NAME']), 'version' => $settings['version'], 'domain' => url(), ]); $this->_updateSettings('update_check', time()); if (!is_array($request)) { $this->tpl->set('error', $request); } elseif ($request['status'] == 'error') { $this->tpl->set('error', $request['message']); } else { $this->_updateSettings('update_version', $request['data']['version']); $this->_updateSettings('update_changelog', $request['data']['changelog']); $this->tpl->set('update_version', $request['data']['version']); // if(DEV_MODE) // $this->tpl->set('request', $request); } } elseif (isset($_POST['update'])) { if (!class_exists("ZipArchive")) { $this->tpl->set('error', "ZipArchive is required to update Batflat."); } if (!isset($_GET['manual'])) { $request = $this->updateRequest('/batflat/update', [ 'ip' => isset_or($_SERVER['SERVER_ADDR'], $_SERVER['SERVER_NAME']), 'version' => $settings['version'], 'domain' => url(), ]); $this->download($request['data']['download'], BASE_DIR.'/tmp/latest.zip'); } else { $package = glob(BASE_DIR.'/batflat-*.zip'); if (!empty($package)) { $package = array_shift($package); $this->rcopy($package, BASE_DIR.'/tmp/latest.zip'); } } define("UPGRADABLE", true); // Making backup $backup_date = date('YmdHis'); $this->rcopy(BASE_DIR, BASE_DIR.'/backup/'.$backup_date.'/', 0755, [BASE_DIR.'/backup', BASE_DIR.'/tmp/latest.zip', (isset($package) ? BASE_DIR.'/'.basename($package) : '')]); // Unzip latest update $zip = new ZipArchive; $zip->open(BASE_DIR.'/tmp/latest.zip'); $zip->extractTo(BASE_DIR.'/tmp/update'); // Copy files $this->rcopy(BASE_DIR.'/tmp/update/inc/css', BASE_DIR.'/inc/css'); $this->rcopy(BASE_DIR.'/tmp/update/inc/core', BASE_DIR.'/inc/core'); $this->rcopy(BASE_DIR.'/tmp/update/inc/jscripts', BASE_DIR.'/inc/jscripts'); $this->rcopy(BASE_DIR.'/tmp/update/inc/lang', BASE_DIR.'/inc/lang'); $this->rcopy(BASE_DIR.'/tmp/update/inc/modules', BASE_DIR.'/inc/modules'); // Restore defines $this->rcopy(BASE_DIR.'/backup/'.$backup_date.'/inc/core/defines.php', BASE_DIR.'/inc/core/defines.php'); // Run upgrade script $version = $settings['version']; $new_version = include(BASE_DIR.'/tmp/update/upgrade.php'); // Close archive and delete all unnecessary files $zip->close(); unlink(BASE_DIR.'/tmp/latest.zip'); deleteDir(BASE_DIR.'/tmp/update'); $this->_updateSettings('version', $new_version); $this->_updateSettings('update_version', 0); $this->_updateSettings('update_changelog', ''); $this->_updateSettings('update_check', time()); sleep(2); redirect(url([ADMIN, 'settings', 'updates'])); } elseif (isset($_GET['reset'])) { $this->_updateSettings('update_version', 0); $this->_updateSettings('update_changelog', ''); $this->_updateSettings('update_check', 0); } elseif (isset($_GET['manual'])) { $package = glob(BASE_DIR.'/batflat-*.zip'); $version = false; if (!empty($package)) { $package_path = array_shift($package); preg_match('/batflat\-([0-9\.a-z]+)\.zip$/', $package_path, $matches); $version = $matches[1]; } $manual_mode = ['version' => $version]; } $this->settings->reload(); $settings = $this->settings('settings'); $this->tpl->set('settings', $settings); $this->tpl->set('manual_mode', isset_or($manual_mode, false)); return $this->draw('update.html'); } public function postChangeOrderOfNavItem() { foreach ($_POST as $module => $order) { $this->db('modules')->where('dir', $module)->save(['sequence' => $order]); } exit(); } public function _checkUpdate() { $settings = $this->settings('settings'); if (time() - $settings['update_check'] > 3600*6) { $request = $this->updateRequest('/batflat/update', [ 'ip' => isset_or($_SERVER['SERVER_ADDR'], $_SERVER['SERVER_NAME']), 'version' => $settings['version'], 'domain' => url(), ]); if (is_array($request) && $request['status'] != 'error') { $settings['update_version'] = $request['data']['version']; $this->_updateSettings('update_version', $request['data']['version']); $this->_updateSettings('update_changelog', $request['data']['changelog']); } $this->_updateSettings('update_check', time()); } if (cmpver($settings['update_version'], $settings['version']) === 1) { return true; } return false; } private function updateRequest($resource, $params = []) { $output = HttpRequest::post($this->feed_url.$resource, $params); if ($output === false) { $output = HttpRequest::getStatus(); } else { $output = json_decode($output, true); } return $output; } private function download($source, $dest) { set_time_limit(0); $fp = fopen($dest, 'w+'); $ch = curl_init($source); curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); curl_close($ch); fclose($fp); } /** * list of themes * @return array */ private function _getThemes($theme = null) { $themes = glob(THEMES.'/*', GLOB_ONLYDIR); $return = []; foreach ($themes as $e) { if ($e != THEMES.'/admin') { $manifest = array_fill_keys(['name', 'version', 'author', 'email', 'thumb'], 'Unknown'); $manifest['name'] = basename($e); $manifest['thumb'] = '../admin/img/unknown_theme.png'; if (file_exists($e.'/manifest.json')) { $manifest = array_merge($manifest, json_decode(file_get_contents($e.'/manifest.json'), true)); } if ($theme == basename($e)) { return array_merge($manifest, ['dir' => basename($e)]); } $return[] = array_merge($manifest, ['dir' => basename($e)]); } } return $return; } /** * list of pages * @param string $lang * @param integer $selected * @return array */ private function _getPages($lang) { $rows = $this->db('pages')->where('lang', $lang)->toArray(); if (count($rows)) { foreach ($rows as $row) { $result[] = ['id' => $row['id'], 'title' => $row['title'], 'slug' => $row['slug']]; } } return $result; } /** * list of theme files (html, css & js) * @param string $selected * @return array */ private function _getThemeFiles($selected = null, $theme = null) { $theme = ($theme ? $theme : $this->settings('settings', 'theme')); $files = $this->rglob(THEMES.'/'.$theme.'/*.html'); $files = array_merge($files, $this->rglob(THEMES.'/'.$theme.'/*.css')); $files = array_merge($files, $this->rglob(THEMES.'/'.$theme.'/*.js')); $result = []; foreach ($files as $file) { if ($selected && ($selected == md5($file))) { $attr = 'selected'; } else { $attr = null; } $result[md5($file)] = ['name' => basename($file), 'path' => $file, 'short' => str_replace(BASE_DIR, null, $file), 'attr' => $attr]; } return $result; } private function _updateSettings($field, $value) { return $this->settings('settings', $field, $value); } private function rcopy($source, $dest, $permissions = 0755, $expect = []) { foreach ($expect as $e) { if ($e == $source) { return; } } if (is_link($source)) { return symlink(readlink($source), $dest); } if (is_file($source)) { if (!is_dir(dirname($dest))) { mkdir(dirname($dest), 0777, true); } return copy($source, $dest); } if (!is_dir($dest)) { mkdir($dest, $permissions, true); } $dir = dir($source); while (false !== $entry = $dir->read()) { if ($entry == '.' || $entry == '..') { continue; } $this->rcopy("$source/$entry", "$dest/$entry", $permissions, $expect); } $dir->close(); return true; } private function _verifyLicense() { $licenseArray = (array) json_decode(base64_decode($this->settings('settings', 'license')), true); $license = array_replace(array_fill(0, 5, null), $licenseArray); list($md5hash, $pid, $lcode, $dcode, $tstamp) = $license; if (empty($md5hash)) { return License::FREE; } if ($md5hash == md5($pid.$lcode.$dcode.domain(false))) { return License::COMMERCIAL; } return License::ERROR; } private function _getTimezones() { $regions = array( \DateTimeZone::AFRICA, \DateTimeZone::AMERICA, \DateTimeZone::ANTARCTICA, \DateTimeZone::ASIA, \DateTimeZone::ATLANTIC, \DateTimeZone::AUSTRALIA, \DateTimeZone::EUROPE, \DateTimeZone::INDIAN, \DateTimeZone::PACIFIC, \DateTimeZone::UTC, ); $timezones = array(); foreach ($regions as $region) { $timezones = array_merge($timezones, \DateTimeZone::listIdentifiers($region)); } $timezone_offsets = array(); foreach ($timezones as $timezone) { $tz = new \DateTimeZone($timezone); $timezone_offsets[$timezone] = $tz->getOffset(new \DateTime); } // sort timezone by offset asort($timezone_offsets); $timezone_list = array(); foreach ($timezone_offsets as $timezone => $offset) { $offset_prefix = $offset < 0 ? '-' : '+'; $offset_formatted = gmdate('H:i', abs($offset)); $pretty_offset = "UTC${offset_prefix}${offset_formatted}"; $timezone_list[$timezone] = "(${pretty_offset}) $timezone"; } return $timezone_list; } private function _getAllTranslations($lang) { $modules = []; $general = parse_ini_file('../inc/lang/en_english/admin/general.ini'); if (file_exists('../inc/lang/'.$lang.'/admin/general.ini')) { $current = parse_ini_file('../inc/lang/'.$lang.'/admin/general.ini'); } else { $current = []; } foreach ($general as $key => $value) { $modules[0]['admin'][] = [ 'key' => $key, 'value' => isset_or($current[$key], null), 'english' => $value ]; } $dirs = glob(MODULES.'/*'); foreach ($dirs as $dir) { $modules[basename($dir)] = []; if (file_exists($dir.'/lang/en_english.ini')) { $tmp = parse_ini_file($dir.'/lang/en_english.ini'); if (file_exists($dir.'/lang/'.$lang.'.ini')) { $current = parse_ini_file($dir.'/lang/'.$lang.'.ini'); } else { $current = []; } foreach ($tmp as $key => $value) { $modules[basename($dir)]['front'][] = [ 'key' => $key, 'value' => isset_or($current[$key], null), 'english' => $value ]; } } if (file_exists($dir.'/lang/admin/en_english.ini')) { $tmp = parse_ini_file($dir.'/lang/admin/en_english.ini'); if (file_exists($dir.'/lang/admin/'.$lang.'.ini')) { $current = parse_ini_file($dir.'/lang/admin/'.$lang.'.ini'); } else { $current = []; } foreach ($tmp as $key => $value) { $modules[basename($dir)]['admin'][] = [ 'key' => $key, 'value' => isset_or($current[$key], null), 'english' => $value ]; } } } return $modules; } private function rglob($pattern, $flags = 0) { $files = glob($pattern, $flags); foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { $files = array_merge($files, $this->rglob($dir.'/'.basename($pattern), $flags)); } return $files; } private function _directorySize($path) { $bytestotal = 0; $path = realpath($path); if ($path!==false) { foreach (new RecursiveIteratorIterator(new RecursiveDotFilterIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS))) as $object) { try { $bytestotal += $object->getSize(); } catch (\Exception $e) { } } } return $bytestotal; } private function roundSize($bytes) { if ($bytes/1024 < 1) { return $bytes.' B'; } if ($bytes/1024/1024 < 1) { return round($bytes/1024).' KB'; } if ($bytes/1024/1024/1024 < 1) { return round($bytes/1024/1024, 2).' MB'; } else { return round($bytes/1024/1024/1024, 2).' GB'; }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
true
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/settings/Info.php
inc/modules/settings/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['settings']['module_name'], 'description' => $core->lang['settings']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.3', 'compatibility' => '1.3.*', 'icon' => 'wrench', 'install' => function () use ($core) { $core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `settings` ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `module` text NOT NULL, `field` text NOT NULL, `value` text )"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'title', 'Batflat')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'description', 'Gotham’s time has come.')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'keywords', 'key, words')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'footer', 'Copyright {?=date(\"Y\")?} &copy; by Company Name. All rights reserved.')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'homepage', 'blog')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'timezone', '".date_default_timezone_get()."')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'theme', 'batblog')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'editor', 'wysiwyg')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'lang_site', 'en_english')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'lang_admin', 'en_english')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'version', '1.3.6')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'update_check', '0')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'update_changelog', '')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'update_version', '0')"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('settings', 'license', '')"); }, 'uninstall' => function () use ($core) { $core->db()->pdo()->exec("DROP TABLE `settings`"); } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/settings/Site.php
inc/modules/settings/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Settings; use Inc\Core\SiteModule; class Site extends SiteModule { public function init() { $this->_importSettings(); } private function _importSettings() { $tmp = $this->core->settings->all(); $tmp = array_merge($tmp, $tmp['settings']); unset($tmp['settings']); $this->tpl->set('settings', $tmp); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/settings/inc/RecursiveDotFilterIterator.php
inc/modules/settings/inc/RecursiveDotFilterIterator.php
<?php namespace Inc\Modules\Settings\Inc; class RecursiveDotFilterIterator extends \RecursiveFilterIterator { public function accept() { return '.' !== substr($this->current()->getFilename(), 0, 1); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/galleries/Admin.php
inc/modules/galleries/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Galleries; use Inc\Core\AdminModule; class Admin extends AdminModule { private $_thumbs = ['md' => 600, 'sm' => 300, 'xs' => 150]; private $_uploads = UPLOADS.'/galleries'; public function navigation() { return [ $this->lang('manage', 'general') => 'manage', ]; } /** * galleries manage */ public function getManage() { $assign = []; // list $rows = $this->db('galleries')->toArray(); if (count($rows)) { foreach ($rows as $row) { $row['tag'] = $this->tpl->noParse('{$gallery.'.$row['slug'].'}'); $row['editURL'] = url([ADMIN, 'galleries', 'edit', $row['id']]); $row['delURL'] = url([ADMIN, 'galleries', 'delete', $row['id']]); $assign[] = $row; } } return $this->draw('manage.html', ['galleries' => $assign]); } /** * add new gallery */ public function anyAdd() { $location = [ADMIN, 'galleries', 'manage']; if (!empty($_POST['name'])) { $name = htmlspecialchars(trim($_POST['name']), ENT_NOQUOTES, 'UTF-8'); if (!$this->db('galleries')->where('slug', createSlug($name))->count()) { $query = $this->db('galleries')->save(['name' => $name, 'slug' => createSlug($name)]); if ($query) { $id = $this->db()->lastInsertId(); $dir = $this->_uploads.'/'.$id; if (mkdir($dir, 0755, true)) { $this->notify('success', $this->lang('add_gallery_success')); $location = [ADMIN, 'galleries', 'edit', $this->db()->lastInsertId()]; } } else { $this->notify('failure', $this->lang('add_gallery_failure')); } } else { $this->notify('failure', $this->lang('gallery_already_exists')); } } else { $this->notify('failure', $this->lang('empty_inputs', 'general')); } redirect(url($location)); } /** * remove gallery */ public function getDelete($id) { $query = $this->db('galleries')->delete($id); deleteDir($this->_uploads.'/'.$id); if ($query) { $this->notify('success', $this->lang('delete_gallery_success')); } else { $this->notify('failure', $this->lang('delete_gallery_failure')); } redirect(url([ADMIN, 'galleries', 'manage'])); } /** * edit gallery */ public function getEdit($id, $page = 1) { $assign = []; $assign['settings'] = $this->db('galleries')->oneArray($id); // pagination $totalRecords = $this->db('galleries_items')->where('gallery', $id)->toArray(); $pagination = new \Inc\Core\Lib\Pagination($page, count($totalRecords), 10, url([ADMIN, 'galleries', 'edit', $id, '%d'])); $assign['pagination'] = $pagination->nav(); $assign['page'] = $page; // items if ($assign['settings']['sort'] == 'ASC') { $rows = $this->db('galleries_items')->where('gallery', $id) ->limit($pagination->offset().', '.$pagination->getRecordsPerPage()) ->asc('id')->toArray(); } else { $rows = $this->db('galleries_items')->where('gallery', $id) ->limit($pagination->offset().', '.$pagination->getRecordsPerPage()) ->desc('id')->toArray(); } if (count($rows)) { foreach ($rows as $row) { $row['title'] = $this->tpl->noParse(htmlspecialchars($row['title'])); $row['desc'] = $this->tpl->noParse(htmlspecialchars($row['desc'])); $row['src'] = unserialize($row['src']); if (!isset($row['src']['sm'])) { $row['src']['sm'] = isset($row['src']['xs']) ? $row['src']['xs'] : $row['src']['lg']; } $assign['images'][] = $row; } } $assign['id'] = $id; $this->core->addCSS(url('inc/jscripts/lightbox/lightbox.min.css')); $this->core->addJS(url('inc/jscripts/lightbox/lightbox.min.js')); $this->core->addJS(url('inc/jscripts/are-you-sure.min.js')); return $this->draw('edit.html', ['gallery' => $assign]); } /** * save gallery data */ public function postSaveSettings($id) { $formData = htmlspecialchars_array($_POST); if (checkEmptyFields(['name', 'sort'], $formData)) { $this->notify('failure', $this->lang('empty_inputs', 'general')); redirect(url([ADMIN, 'galleries', 'edit', $id])); } $formData['slug'] = createSlug($formData['name']); if ($this->db('galleries')->where($id)->save($formData)) { $this->notify('success', $this->lang('save_settings_success')); } redirect(url([ADMIN, 'galleries', 'edit', $id])); } /** * save images data */ public function postSaveImages($id, $page) { foreach ($_POST['img'] as $key => $val) { $query = $this->db('galleries_items')->where($key)->save(['title' => $val['title'], 'desc' => $val['desc']]); } if ($query) { $this->notify('success', $this->lang('save_settings_success')); } redirect(url([ADMIN, 'galleries', 'edit', $id, $page])); } /** * image uploading */ public function postUpload($id) { $dir = $this->_uploads.'/'.$id; $cntr = 0; if (!is_uploaded_file($_FILES['files']['tmp_name'][0])) { $this->notify('failure', $this->lang('no_files')); } else { foreach ($_FILES['files']['tmp_name'] as $image) { $img = new \Inc\Core\Lib\Image(); if ($img->load($image)) { $imgName = time().$cntr++; $imgPath = $dir.'/'.$imgName.'.'.$img->getInfos('type'); $src = []; // oryginal size $img->save($imgPath); $src['lg'] = str_replace(BASE_DIR.'/', null, $imgPath); // generate thumbs foreach ($this->_thumbs as $key => $width) { if ($img->getInfos('width') > $width) { $img->resize($width); $img->save($thumbPath = "{$dir}/{$imgName}-{$key}.{$img->getInfos('type')}"); $src[$key] = str_replace(BASE_DIR.'/', null, $thumbPath); } } $query = $this->db('galleries_items')->save(['src' => serialize($src), 'gallery' => $id]); } else { $this->notify('failure', $this->lang('wrong_extension'), 'jpg, png, gif'); } } if ($query) { $this->notify('success', $this->lang('add_images_success')); }; } redirect(url([ADMIN, 'galleries', 'edit', $id])); } /** * remove image */ public function getDeleteImage($id) { $image = $this->db('galleries_items')->where($id)->oneArray(); if (!empty($image)) { if ($this->db('galleries_items')->delete($id)) { $images = unserialize($image['src']); foreach ($images as $src) { if (file_exists(BASE_DIR.'/'.$src)) { if (!unlink(BASE_DIR.'/'.$src)) { $this->notify('failure', $this->lang('delete_image_failure')); } else { $this->notify('success', $this->lang('delete_image_success')); } } } } } else { $this->notify('failure', $this->lang('image_doesnt_exists')); } redirect(url([ADMIN, 'galleries', 'edit', $image['gallery']])); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/galleries/Info.php
inc/modules/galleries/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['galleries']['module_name'], 'description' => $core->lang['galleries']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.1', 'compatibility' => '1.3.*', 'icon' => 'camera', 'install' => function () use ($core) { $core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `galleries` ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `name` text NOT NULL, `slug` text NOT NULL, `img_per_page` integer NOT NULL DEFAULT 0, `sort` text NOT NULL DEFAULT 'DESC' )"); $core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `galleries_items` ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `gallery` integer NOT NULL, `src` text NOT NULL, `title` text NULL, `desc` text NULL )"); if (!file_exists(UPLOADS.'/galleries')) { mkdir(UPLOADS.'/galleries', 0755, true); } }, 'uninstall' => function () use ($core) { $core->db()->pdo()->exec("DROP TABLE `galleries`"); $core->db()->pdo()->exec("DROP TABLE `galleries_items`"); deleteDir(UPLOADS.'/galleries'); } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/galleries/Site.php
inc/modules/galleries/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Galleries; use Inc\Core\SiteModule; class Site extends SiteModule { public function init() { $this->_importGalleries(); } private function _importGalleries() { $assign = []; $tempAssign = []; $galleries = $this->db('galleries')->toArray(); if (count($galleries)) { foreach ($galleries as $gallery) { if ($gallery['sort'] == 'ASC') { $items = $this->db('galleries_items')->where('gallery', $gallery['id'])->asc('id')->toArray(); } else { $items = $this->db('galleries_items')->where('gallery', $gallery['id'])->desc('id')->toArray(); } $tempAssign = $gallery; if (count($items)) { foreach ($items as &$item) { $item['src'] = unserialize($item['src']); if (!isset($item['src']['sm'])) { $item['src']['sm'] = isset($item['src']['xs']) ? $item['src']['xs'] : $item['src']['lg']; } } $tempAssign['items'] = $items; $assign[$gallery['slug']] = $this->draw('gallery.html', ['gallery' => $tempAssign]); } } } $this->tpl->set('gallery', $assign); $this->core->addCSS(url('inc/jscripts/lightbox/lightbox.min.css')); $this->core->addJS(url('inc/jscripts/lightbox/lightbox.min.js')); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/pages/Admin.php
inc/modules/pages/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Pages; use Inc\Core\AdminModule; class Admin extends AdminModule { private $assign = []; public function navigation() { return [ $this->lang('manage', 'general') => 'manage', $this->lang('add_new') => 'add' ]; } /** * list of pages */ public function getManage($page = 1) { // lang if (!empty($_GET['lang'])) { $lang = $_GET['lang']; $_SESSION['pages']['last_lang'] = $lang; } elseif (!empty($_SESSION['pages']['last_lang'])) { $lang = $_SESSION['pages']['last_lang']; } else { $lang = $this->settings('settings', 'lang_site'); } // pagination $totalRecords = $this->db('pages')->where('lang', $lang)->toArray(); $pagination = new \Inc\Core\Lib\Pagination($page, count($totalRecords), 10, url([ADMIN, 'pages', 'manage', '%d'])); $this->assign['pagination'] = $pagination->nav(); // list $rows = $this->db('pages')->where('lang', $lang) ->limit($pagination->offset().', '.$pagination->getRecordsPerPage()) ->toArray(); $this->assign['list'] = []; if (count($rows)) { foreach ($rows as $row) { $row = htmlspecialchars_array($row); $row['editURL'] = url([ADMIN, 'pages', 'edit', $row['id']]); $row['delURL'] = url([ADMIN, 'pages', 'delete', $row['id']]); $row['viewURL'] = url(explode('_', $lang)[0].'/'.$row['slug']); $row['desc'] = str_limit($row['desc'], 48); $this->assign['list'][] = $row; } } $this->assign['langs'] = $this->_getLanguages($lang); return $this->draw('manage.html', ['pages' => $this->assign]); } /** * add new page */ public function getAdd() { $this->assign['editor'] = $this->settings('settings', 'editor'); $this->_addHeaderFiles(); // Unsaved data with failure if (!empty($e = getRedirectData())) { $this->assign['form'] = ['title' => isset_or($e['title'], ''), 'desc' => isset_or($e['desc'], ''), 'content' => isset_or($e['content'], ''), 'slug' => isset_or($e['slug'], '')]; } else { $this->assign['form'] = ['title' => '', 'desc' => '', 'content' => '', 'slug' => '', 'markdown' => 0]; } $this->assign['title'] = $this->lang('new_page'); $this->assign['langs'] = $this->_getLanguages($this->settings('settings.lang_site'), 'selected'); $this->assign['templates'] = $this->_getTemplates(isset_or($e['template'], 'index.html')); $this->assign['manageURL'] = url([ADMIN, 'pages', 'manage']); return $this->draw('form.html', ['pages' => $this->assign]); } /** * edit page */ public function getEdit($id) { $this->assign['editor'] = $this->settings('settings', 'editor'); $this->_addHeaderFiles(); $page = $this->db('pages')->where('id', $id)->oneArray(); if (!empty($page)) { // Unsaved data with failure if (!empty($e = getRedirectData())) { $page = array_merge($page, ['title' => isset_or($e['title'], ''), 'desc' => isset_or($e['desc'], ''), 'content' => isset_or($e['content'], ''), 'slug' => isset_or($e['slug'], '')]); } $this->assign['form'] = htmlspecialchars_array($page); $this->assign['form']['content'] = $this->tpl->noParse($this->assign['form']['content']); $this->assign['title'] = $this->lang('edit_page'); $this->assign['langs'] = $this->_getLanguages($page['lang'], 'selected'); $this->assign['templates'] = $this->_getTemplates($page['template']); $this->assign['manageURL'] = url([ADMIN, 'pages', 'manage']); return $this->draw('form.html', ['pages' => $this->assign]); } else { redirect(url([ADMIN, 'pages', 'manage'])); } } /** * save data */ public function postSave($id = null) { unset($_POST['save'], $_POST['files']); if (!$id) { $location = url([ADMIN, 'pages', 'add']); } else { $location = url([ADMIN, 'pages', 'edit', $id]); } if (checkEmptyFields(['title', 'lang', 'template'], $_POST)) { $this->notify('failure', $this->lang('empty_inputs', 'general')); redirect($location, $_POST); } $_POST['title'] = trim($_POST['title']); if (!isset($_POST['markdown'])) { $_POST['markdown'] = 0; } if (empty($_POST['slug'])) { $_POST['slug'] = createSlug($_POST['title']); } else { $_POST['slug'] = createSlug($_POST['slug']); } if ($id != null && $this->db('pages')->where('slug', $_POST['slug'])->where('lang', $_POST['lang'])->where('id', '!=', $id)->oneArray()) { $this->notify('failure', $this->lang('page_exists')); redirect(url([ADMIN, 'pages', 'edit', $id]), $_POST); } elseif ($id == null && $this->db('pages')->where('slug', $_POST['slug'])->where('lang', $_POST['lang'])->oneArray()) { $this->notify('failure', $this->lang('page_exists')); redirect(url([ADMIN, 'pages', 'add']), $_POST); } if (!$id) { $_POST['date'] = date('Y-m-d H:i:s'); $query = $this->db('pages')->save($_POST); $location = url([ADMIN, 'pages', 'edit', $this->db()->pdo()->lastInsertId()]); } else { $query = $this->db('pages')->where('id', $id)->save($_POST); } if ($query) { $this->notify('success', $this->lang('save_success')); } else { $this->notify('failure', $this->lang('save_failure')); } redirect($location); } /** * remove page */ public function getDelete($id) { if ($this->db('pages')->delete($id)) { $this->notify('success', $this->lang('delete_success')); } else { $this->notify('failure', $this->lang('delete_failure')); } redirect(url([ADMIN, 'pages', 'manage'])); } /** * image upload from WYSIWYG */ public function postEditorUpload() { header('Content-type: application/json'); $dir = UPLOADS.'/pages'; $error = null; if (!file_exists($dir)) { mkdir($dir, 0777, true); } if (isset($_FILES['file']['tmp_name'])) { $img = new \Inc\Core\Lib\Image; if ($img->load($_FILES['file']['tmp_name'])) { $imgPath = $dir.'/'.time().'.'.$img->getInfos('type'); $img->save($imgPath); echo json_encode(['status' => 'success', 'result' => url($imgPath)]); } else { $error = $this->lang('editor_upload_fail'); } if ($error) { echo json_encode(['status' => 'failure', 'result' => $error]); } } exit(); } /** * module JavaScript */ public function getJavascript() { header('Content-type: text/javascript'); echo $this->draw(MODULES.'/pages/js/admin/pages.js'); exit(); } /** * list of theme's templates * @param string $selected * @return array */ private function _getTemplates($selected = null) { $theme = $this->settings('settings', 'theme'); $tpls = glob(THEMES.'/'.$theme.'/*.html'); $result = []; foreach ($tpls as $tpl) { if ($selected == basename($tpl)) { $attr = 'selected'; } else { $attr = null; } $result[] = ['name' => basename($tpl), 'attr' => $attr]; } return $result; } private function _addHeaderFiles() { // WYSIWYG $this->core->addCSS(url('inc/jscripts/wysiwyg/summernote.min.css')); $this->core->addJS(url('inc/jscripts/wysiwyg/summernote.min.js')); if ($this->settings('settings', 'lang_admin') != 'en_english') { $this->core->addJS(url('inc/jscripts/wysiwyg/lang/'.$this->settings('settings', 'lang_admin').'.js')); } // HTML & MARKDOWN EDITOR $this->core->addCSS(url('/inc/jscripts/editor/markitup.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/markitup.highlight.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/sets/html/set.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/sets/markdown/set.min.css')); $this->core->addJS(url('/inc/jscripts/editor/highlight.min.js')); $this->core->addJS(url('/inc/jscripts/editor/markitup.min.js')); $this->core->addJS(url('/inc/jscripts/editor/markitup.highlight.min.js')); $this->core->addJS(url('/inc/jscripts/editor/sets/html/set.min.js')); $this->core->addJS(url('/inc/jscripts/editor/sets/markdown/set.min.js')); // ARE YOU SURE? $this->core->addJS(url('inc/jscripts/are-you-sure.min.js')); // MODULE SCRIPTS $this->core->addJS(url([ADMIN, 'pages', 'javascript'])); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/pages/Info.php
inc/modules/pages/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['pages']['module_name'], 'description' => $core->lang['pages']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.1', 'compatibility' => '1.3.*', 'icon' => 'file', 'install' => function () use ($core) { $core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `pages` ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `title` text NOT NULL, `slug` text NOT NULL, `desc` text NULL, `lang` text NOT NULL, `template` text NOT NULL, `date` text NOT NULL, `content` text NOT NULL, `markdown` INTEGER DEFAULT 0 )"); // About - EN $core->db()->pdo()->exec("INSERT INTO `pages` (`title`, `slug`, `desc`, `lang`, `template`, `date`, `content`) VALUES ('About me', 'about-me', 'Maecenas cursus accumsan est, sed interdum est pharetra quis.', 'en_english', 'index.html', datetime('now'), '<p>My name is Merely Ducard but I speak for Ra’s al Ghul… a man greatly feared by the criminal underworld. A mon who can offer you a path. Someone like you is only here by choice. You have been exploring the criminal fraternity but whatever your original intentions you have to become truly lost. The path of a man who shares his hatred of evil and wishes to serve true justice. The path of the League of Shadows.</p> <p>Every year, I took a holiday. I went to Florence, this cafe on the banks of the Arno. Every fine evening, I would sit there and order a Fernet Branca. I had this fantasy, that I would look across the tables and I would see you there with a wife maybe a couple of kids. You wouldn’t say anything to me, nor me to you. But we would both know that you’ve made it, that you were happy. I never wanted you to come back to Gotham. I always knew there was nothing here for you except pain and tragedy and I wanted something more for you than that. I still do.</p>') "); // About - PL $core->db()->pdo()->exec("INSERT INTO `pages` (`title`, `slug`, `desc`, `lang`, `template`, `date`, `content`) VALUES ('O mnie', 'about-me', 'Maecenas cursus accumsan est, sed interdum est pharetra quis.', 'pl_polski', 'index.html', datetime('now'), '<p>O, jak drudzy i świadki. I też same szczypiąc trawę ciągnęły powoli pod Twoją opiek ofiarowany, martwą podniosłem powiek i na kształt ogrodowych grządek: Że architekt był legijonistą przynosił kości stare na nim widzi sprzęty, też nie rozwity, lecz podmurowany. Świeciły się nagłe, jej wzrost i goście proszeni. Sień wielka jak znawcy, ci znowu w okolicy. i narody giną. Więc zbliżył się kołem. W mym domu przyszłą urządza zabawę. Dał rozkaz ekonomom, wójtom i w tkackim pudermanie). Wdział więc, jak wytnie dwa smycze chartów przedziwnie udawał psy tuż na polu szukała kogoś okiem, daleko, na Ojczyzny.</p> <p>Bonapartą. tu pan Hrabia z rzadka ciche szmery a brano z boru i Waszeć z Podkomorzym przy zachodzie wszystko porzucane niedbale i w pogody lilia jeziór skroń ucałowawszy, uprzejmie pozdrowił. A zatem. tu mieszkał? Stary żołnierz, stał w bitwie, gdzie panieńskim rumieńcem dzięcielina pała a brano z nieba spadała w pomroku. Wprawdzie zdała się pan Sędzia w lisa, tak nie rzuca w porządku. naprzód dzieci mało wdawał się ukłoni i czytając, z których nie śmieli. I bór czernił się pan rejent Bolesta, zwano go powitać.</p>') "); // Contact - EN $core->db()->pdo()->exec("INSERT INTO `pages` (`title`, `slug`, `desc`, `lang`, `template`, `date`, `content`) VALUES ('Contact', 'contact', '', 'en_english', 'index.html', datetime('now'), '<p>Want to get in touch with me? Fill out the form below to send me a message and I will try to get back to you within 24 hours!</p> {\$contact.form}') "); // Contact - PL $core->db()->pdo()->exec("INSERT INTO `pages` (`title`, `slug`, `desc`, `lang`, `template`, `date`, `content`) VALUES ('Kontakt', 'contact', '', 'pl_polski', 'index.html', datetime('now'), '<p>Chcesz się ze mną skontaktować? Wypełnij poniższy formularz, aby wysłać mi wiadomość, a ja postaram się odpisać w ciągu 24 godzin!</p> {\$contact.form}') "); // 404 - EN $core->db()->pdo()->exec("INSERT INTO `pages` (`title`, `slug`, `desc`, `lang`, `template`, `date`, `content`) VALUES ('404', '404', 'Not found', 'en_english', 'index.html', datetime('now'), '<p>Sorry, page does not exist.</p>') "); // 404 -PL $core->db()->pdo()->exec("INSERT INTO `pages` (`title`, `slug`, `desc`, `lang`, `template`, `date`, `content`) VALUES ('404', '404', 'Not found', 'pl_polski', 'index.html', datetime('now'), '<p>Niestety taka strona nie istnieje.</p>') "); if (!is_dir(UPLOADS."/pages")) { mkdir(UPLOADS."/pages", 0777); } }, 'uninstall' => function () use ($core) { $core->db()->pdo()->exec("DROP TABLE `pages`"); deleteDir(UPLOADS."/pages"); } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/pages/Site.php
inc/modules/pages/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Pages; use Inc\Core\SiteModule; class Site extends SiteModule { public function init() { $slug = parseURL(); $lang = $this->_getLanguageBySlug($slug[0]); if ($lang !== false) { $this->core->loadLanguage($lang); } if (empty($slug[0]) || ($lang !== false && empty($slug[1]))) { $this->core->router->changeRoute($this->settings('settings', 'homepage')); } \Inc\Core\Lib\Event::add('router.notfound', function () { $this->get404(); }); } public function routes() { // Load pages from default language $this->route('(:str)', function ($slug) { $this->_importPage($slug); }); // Load pages from specified language prefix $this->route('(:str)/(:str)', function ($lang, $slug) { // get current language by slug $lang = $this->_getLanguageBySlug($lang); // Set current language to specified or if not exists to default if ($lang) { $this->core->loadLanguage($lang); } else { $slug = null; } $this->_importPage($slug); }); $this->_importAllPages(); } /** * get a specific page */ private function _importPage($slug = null) { if (!empty($slug)) { $row = $this->db('pages')->where('slug', $slug)->where('lang', $this->_getCurrentLang())->oneArray(); if (empty($row)) { return $this->get404(); } } else { return $this->get404(); } if (intval($row['markdown'])) { $parsedown = new \Inc\Core\Lib\Parsedown(); $row['content'] = $parsedown->text($row['content']); } $this->filterRecord($row); $this->setTemplate($row['template']); $this->tpl->set('page', $row); } /** * get array with all pages */ private function _importAllPages() { $this->tpl->set('pages', function () { $rows = $this->db('pages')->where('lang', $this->_getCurrentLang())->toArray(); $assign = []; foreach ($rows as $row) { $this->filterRecord($row); $assign[$row['id']] = $row; } return $assign; }); } public function get404() { http_response_code(404); if (!($row = $this->db('pages')->like('slug', '404%')->where('lang', $this->_getCurrentLang())->oneArray())) { echo '<h1>404 Not Found</h1>'; echo $this->lang('not_found'); exit; } $this->setTemplate($row['template']); $this->tpl->set('page', $row); } private function _getCurrentLang() { if (!isset($_SESSION['lang'])) { return $this->settings('settings', 'lang_site'); } else { return $_SESSION['lang']; } } protected function _getLanguageBySlug($slug) { $langs = parent::_getLanguages(); foreach ($langs as $lang) { preg_match_all('/([a-z]{2})_([a-z]+)/', $lang['name'], $matches); if ($slug == $matches[1][0]) { return $matches[0][0]; } } return false; } protected function filterRecord(array &$page) { if (isset($page['title'])) { $page['title'] = htmlspecialchars($page['title']); } } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/sitemap/Info.php
inc/modules/sitemap/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['sitemap']['module_name'], 'description' => $core->lang['sitemap']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.0', 'compatibility' => '1.3.*', 'icon' => 'sitemap', 'install' => function() use($core) { }, 'uninstall' => function() use($core) { } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/sitemap/Site.php
inc/modules/sitemap/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Sitemap; use Inc\Core\SiteModule; class Site extends SiteModule { public function routes() { $this->route('sitemap.xml', function() { $this->setTemplate(false); header('Content-type: application/xml'); $urls = []; // Home Page $urls[] = [ 'url' => url(), 'lastmod' => null, ]; // Pages $pages = $this->db('pages')->asc('lang')->asc('id')->toArray(); $lang = $this->settings('settings.lang_site'); $homepage = $this->settings('settings.homepage'); foreach($pages as $page) { $page['date'] = strtotime($page['date']); $shortLang = strstr($page['lang'], '_', true); if(strpos($page['slug'], '404') !== FALSE) continue; if($lang == $page['lang'] && $homepage == $page['slug']) $urls[0]['lastmod'] = date('c', $page['date']); else if($homepage == $page['slug']) $urls[] = ['url' => url($shortLang), 'lastmod' => date('c', $page['date'])]; else if($lang == $page['lang']) $urls[] = ['url' => url($page['slug']), 'lastmod' => date('c', $page['date'])]; else $urls[] = ['url' => url([$shortLang, $page['slug']]), 'lastmod' => date('c', $page['date'])]; } // Blog $posts = $this->db('blog')->where('status', 2)->desc('published_at')->toArray(); $tags = $this->db('blog_tags_relationship')->leftJoin('blog_tags', 'blog_tags.id = blog_tags_relationship.tag_id')->leftJoin('blog', 'blog.id', 'blog_tags_relationship.blog_id')->where('blog.status', 2)->group('blog_tags.slug')->select(['slug' => 'blog_tags.slug'])->toArray(); if($homepage != 'blog') { $urls[] = [ 'url' => url('blog'), 'lastmod' => date('c', $posts[0]['published_at']) ]; } else { $urls[0]['lastmod'] = date('c', $posts[0]['published_at']); } foreach($posts as $post) { $post['published_at'] = $post['published_at']; $urls[] = [ 'url' => url(['blog','post',$post['slug']]), 'lastmod' => date('c', $post['published_at']), ]; } foreach($tags as $tag) { $urls[] = [ 'url' => url(['blog', 'tag', $tag['slug']]), 'lastmod' => null, ]; } echo $this->draw('sitemap.xml', compact('urls')); }); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/searchbox/Info.php
inc/modules/searchbox/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => 'SearchBox', 'description' => $core->lang['searchbox']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.0', 'compatibility' => '1.3.*', 'icon' => 'search', 'install' => function() use($core) { }, 'uninstall' => function() use($core) { } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/searchbox/Site.php
inc/modules/searchbox/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\SearchBox; use Inc\Core\SiteModule; class Site extends SiteModule { public function init() { if(isset($_GET['search'])) redirect(url('search/'.urlencode(strip_tags($_GET['search'])))); $this->tpl->set('searchBox', $this->_insertSearchBox()); } public function routes() { $this->route('search/(:any)', 'getSearch'); $this->route('search/(:any)/(:int)', 'getSearch'); } public function getSearch($phrase, $index = 1) { $phrase = urldecode($phrase); $phrase = strip_tags ($phrase); $phrase = htmlentities ($phrase); $searchTemplate = 'search.html'; $phraseMinLength = 3; $page = [ 'title' => $this->tpl->noParse(sprintf($this->lang('results_for'), $phrase)), 'desc' => $this->settings('settings.description') ]; // if $searchTemplate exists, use it instead of "index.html" if(file_exists(THEMES.'/'.$this->settings('settings.theme').'/'.$searchTemplate)) $this->setTemplate($searchTemplate); else $this->setTemplate('index.html'); // check if $phrase is long as value of $phraseMinLength if(strlen($phrase) < $phraseMinLength) $page['content'] = sprintf($this->lang('too_short_phrase'), $phraseMinLength); else { // select pages $pages = $this->db()->pdo()->prepare("SELECT * FROM pages WHERE lang = ? AND (title LIKE ? OR content LIKE ?)"); $pages->execute([$this->_currentLanguage(), '%'.$phrase.'%', '%'.$phrase.'%']); $pagesArray = $pages->fetchAll(); // add URL key to pages array foreach($pagesArray as &$item) { $item['url'] = url($item['slug']); } // select blog entries $blog = $this->db()->pdo()->prepare("SELECT * FROM blog WHERE lang = ? AND status = ? AND (title LIKE ? OR content LIKE ?)"); $blog->execute([$this->_currentLanguage(), 2, '%'.$phrase.'%', '%'.$phrase.'%']); $blogArray = $blog->fetchAll(); // add URL key to blog array foreach($blogArray as &$item) { $item['url'] = url('blog/post/'.$item['slug']); } // merge of pages and blog entries $rows = array_merge($pagesArray, $blogArray); // display results if(!empty($rows) && (count($rows) >= $index)) { $pagination = new \Inc\Core\Lib\Pagination($index, count($rows), 10, url('search/'.$phrase.'/%d')); $rows = array_chunk($rows, $pagination->getRecordsPerPage()); $page['content'] = $this->_insertResults($rows[$pagination->offset()]) . $pagination->nav(); } else $page['content'] = sprintf($this->lang('no_results'), $phrase); } $this->tpl->set('page', $page); } private function _insertSearchBox() { return $this->draw('input.html'); } private function _insertResults(array $results) { foreach($results as &$result) { // remove HTML and Template tags $result['content'] = preg_replace('/{(.*?)}/', '', strip_tags($result['content'])); } return $this->draw('results.html', ['results' => $results]); } private function _currentLanguage() { if(!isset($_SESSION['lang'])) return $this->settings('settings', 'lang_site'); else return $_SESSION['lang']; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/navigation/Admin.php
inc/modules/navigation/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Navigation; use Inc\Core\AdminModule; class Admin extends AdminModule { private $assign = []; public function navigation() { return [ $this->lang('manage', 'general') => 'manage', $this->lang('add_link') => 'newLink', $this->lang('add_nav') => 'newNav' ]; } /** * list of navs and their children */ public function getManage() { // lang if (!empty($_GET['lang'])) { $lang = $_GET['lang']; $_SESSION['navigation']['last_lang'] = $lang; } elseif (!empty($_SESSION['navigation']['last_lang'])) { $lang = $_SESSION['navigation']['last_lang']; } else { $lang = $this->settings('settings', 'lang_site'); } $this->assign['langs'] = $this->_getLanguages($lang, 'active'); // list $rows = $this->db('navs')->toArray(); if (count($rows)) { foreach ($rows as $row) { $row['name'] = $this->tpl->noParse('{$navigation.'.$row['name'].'}'); $row['editURL'] = url([ADMIN, 'navigation', 'editNav', $row['id']]); $row['delURL'] = url([ADMIN, 'navigation', 'deleteNav', $row['id']]); $row['items'] = $this->_getNavItems($row['id'], $lang); $this->assign['navs'][] = $row; } } return $this->draw('manage.html', ['navigation' => $this->assign]); } /** * add new link */ public function getNewLink() { // lang $lang = isset($_GET['lang']) ? $_GET['lang'] : $this->settings('settings', 'lang_site'); $this->assign['langs'] = $this->_getLanguages($lang, 'selected'); $this->assign['link'] = ['name' => '', 'lang' => '', 'page' => '', 'url' => '', 'parent' => '', 'class' => '']; // list of pages $this->assign['pages'] = $this->_getPages($lang); foreach ($this->core->getRegisteredPages() as $page) { $this->assign['pages'][] = array_merge($page, ['id' => $page['slug'], 'attr' => null]); } // list of parents $this->assign['navs'] = $this->_getParents($lang); $this->assign['title'] = $this->lang('add_link'); return $this->draw('form.link.html', ['navigation' => $this->assign]); } /** * edit link */ public function getEditLink($id) { $row = $this->db('navs_items')->oneArray($id); if (!empty($row)) { // lang $lang = isset($_GET['lang']) ? $_GET['lang'] : $row['lang']; $this->assign['langs'] = $this->_getLanguages($lang, 'selected'); $this->assign['link'] = filter_var_array($row, FILTER_SANITIZE_SPECIAL_CHARS); // list of pages $this->assign['pages'] = $this->_getPages($lang, $row['page']); foreach ($this->core->getRegisteredPages() as $page) { $this->assign['pages'][] = array_merge($page, ['id' => $page['slug'], 'attr' => (($row['page'] == 0 && $row['url'] == $page['slug']) ? 'selected' : null)]); } // list of parents $this->assign['navs'] = $this->_getParents($lang, $row['nav'], $row['parent'], $row['id']); $this->assign['title'] = $this->lang('edit_link'); return $this->draw('form.link.html', ['navigation' => $this->assign]); } else { redirect(url([ADMIN, 'navigation', 'manage'])); } } /** * save link data */ public function postSaveLink($id = null) { unset($_POST['save']); $formData = htmlspecialchars_array($_POST); // check if it's an external link $fields = $formData['page'] ? ['name', 'page', 'lang', 'parent'] : ['name', 'url', 'lang', 'parent']; $location = $id ? url([ADMIN, 'navigation', 'editLink', $id]) : url([ADMIN, 'navigation', 'newLink']); if (checkEmptyFields($fields, $formData)) { $this->notify('failure', $this->lang('empty_inputs', 'general')); $this->assign['form'] = filter_var_array($formData, FILTER_SANITIZE_SPECIAL_CHARS); redirect($location); } if ($formData['page']) { $formData['url'] = null; } // get parent $parent = explode('_', $formData['parent']); $formData['nav'] = $parent[0]; $formData['parent'] = (isset($parent[1]) ? $parent[1] : 0); if (!is_numeric($formData['page'])) { $formData['url'] = $formData['page']; $formData['page'] = 0; } if (!$id) { $formData['"order"'] = $this->_getHighestOrder($formData['nav'], $formData['parent'], $formData['lang']) + 1; $query = $this->db('navs_items')->save($formData); } else { $query = $this->db('navs_items')->where($id)->save($formData); if ($query) { $query = $this->db('navs_items')->where('parent', $id)->update(['nav' => $formData['nav']]); } } if ($query) { $this->notify('success', $this->lang('save_link_success')); } else { $this->notify('failure', $this->lang('save_link_failure')); } redirect($location); } /** * delete link */ public function getDeleteLink($id) { if ($this->db('navs_items')->where('id', $id)->orWhere('parent', $id)->delete()) { $this->notify('success', $this->lang('delete_link_success')); } else { $this->notify('failure', $this->lang('delete_link_failure')); } redirect(url([ADMIN, 'navigation', 'manage'])); } /** * add new nav */ public function getNewNav() { $this->assign['title'] = $this->lang('add_nav'); $this->assign['name'] = ''; return $this->draw('form.nav.html', ['navigation' => $this->assign]); } /** * edit nav */ public function getEditNav($id) { $this->assign['title'] = $this->lang('edit_nav'); $row = $this->db('navs')->where($id)->oneArray(); if (!empty($row)) { $this->assign['name'] = $row['name']; $this->assign['id'] = $row['id']; } else { redirect(url([ADMIN, 'navigation', 'manage'])); } return $this->draw('form.nav.html', ['navigation' => $this->assign]); } /** * save nav */ public function postSaveNav($id = null) { $formData = htmlspecialchars_array($_POST); if (empty($formData['name'])) { if (!$id) { redirect(url([ADMIN, 'navigation', 'newNav'])); } else { redirect(url([ADMIN, 'navigation', 'editNav', $id])); } $this->notify('failure', $this->lang('empty_inputs', 'general')); } $name = createSlug($formData['name']); // check if nav already exists if (!$this->db('navs')->where('name', $name)->count()) { if (!$id) { $query = $this->db('navs')->save(['name' => $name]); } else { $query = $this->db('navs')->where($id)->save(['name' => $name]); } if ($query) { $this->notify('success', $this->lang('save_nav_success')); } else { $this->notify('success', $this->lang('save_nav_failure')); } } else { $this->notify('failure', $this->lang('nav_already_exists')); } redirect(url([ADMIN, 'navigation', 'manage'])); } /** * remove nav */ public function getDeleteNav($id) { if ($this->db('navs')->delete($id)) { $this->db('navs_items')->delete('nav', $id); $this->notify('success', $this->lang('delete_nav_success')); } else { $this->notify('failure', $this->lang('delete_nav_failure')); } redirect(url([ADMIN, 'navigation', 'manage'])); } /** * list of pages * @param string $lang * @param integer $selected * @return array */ private function _getPages($lang, $selected = null) { $rows = $this->db('pages')->where('lang', $lang)->toArray(); if (count($rows)) { foreach ($rows as $row) { if ($selected == $row['id']) { $attr = 'selected'; } else { $attr = null; } $result[] = ['id' => $row['id'], 'title' => $row['title'], 'slug' => $row['slug'], 'attr' => $attr]; } } return $result; } /** * list of parents * @param string $lang * @param integer $selected * @return array */ private function _getParents($lang, $nav = null, $page = null, $except = null) { $rows = $this->db('navs')->toArray(); if (count($rows)) { foreach ($rows as &$row) { $row['name'] = $this->tpl->noParse('{$navigation.'.$row['name'].'}'); $row['items'] = $this->_getNavItems($row['id'], $lang); if ($nav && !$page && ($nav == $row['id'])) { $row['attr'] = 'selected'; } else { $row['attr'] = null; } if (is_array($row['items'])) { foreach ($row['items'] as $key => &$value) { if ($except && ($except == $value['id'])) { unset($row['items'][$key]); } else { if ($nav && $page && ($page == $value['id'])) { $value['attr'] = 'selected'; } else { $value['attr'] = null; } } } } } } return $rows; } /** * list of nav items * @param integer $nav * @param string $lang * @return array */ private function _getNavItems($nav, $lang) { $items = $this->db('navs_items')->where('nav', $nav)->where('lang', $lang)->asc('"order"')->toArray(); if (count($items)) { foreach ($items as &$item) { $item['editURL'] = url([ADMIN, 'navigation', 'editLink', $item['id']]); $item['delURL'] = url([ADMIN, 'navigation', 'deleteLink', $item['id']]); $item['upURL'] = url([ADMIN, 'navigation', 'changeOrder', 'up', $item['id']]); $item['downURL'] = url([ADMIN, 'navigation', 'changeOrder', 'down', $item['id']]); if ($item['page'] > 0) { $page = $this->db('pages')->where('id', $item['page'])->oneArray(); $item['fullURL'] = '/'.$page['slug']; } else { $item['fullURL'] = (parse_url($item['url'], PHP_URL_SCHEME) || strpos($item['url'], '#') === 0 ? '' : '/').trim($item['url'], '/'); } } return $this->buildTree($items); } } /** * generate tree from array * @param array $items * @return array */ public function buildTree(array $items) { $children = [0 => []]; foreach ($items as &$item) { $children[$item['parent']][] = &$item; } unset($item); foreach ($items as &$item) { if (isset($children[$item['id']])) { $item['children'] = $children[$item['id']]; } } return $children[0]; } /** * change order of nav item * @param string $direction * @param integer $id * @return void */ public function getChangeOrder($direction, $id) { $item = $this->db('navs_items')->oneArray($id); if (!empty($item)) { if ($direction == 'up') { $nextItem = $this->db('navs_items') ->where('"order"', '<', $item['order']) ->where('nav', $item['nav']) ->where('parent', $item['parent']) ->where('lang', $item['lang']) ->desc('"order"') ->oneArray(); } else { $nextItem = $this->db('navs_items') ->where('"order"', '>', $item['order']) ->where('nav', $item['nav']) ->where('parent', $item['parent']) ->where('lang', $item['lang']) ->asc('"order"') ->oneArray(); } if (!empty($nextItem)) { $this->db('navs_items')->where('id', $item['id'])->save(['"order"' => $nextItem['order']]); $this->db('navs_items')->where('id', $nextItem['id'])->save(['"order"' => $item['order']]); } } redirect(url(ADMIN.'/navigation/manage?lang='.$item['lang'])); } /** * get item with highest order * @param integer $nav * @param integer $parent * @param string $lang * @return integer */ private function _getHighestOrder($nav, $parent, $lang) { $item = $this->db('navs_items') ->where('nav', $nav) ->where('parent', $parent) ->where('lang', $lang) ->desc('"order"') ->oneArray(); return !empty($item) ? $item['order'] : 0; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/navigation/Info.php
inc/modules/navigation/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['navigation']['module_name'], 'description' => $core->lang['navigation']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.3', 'compatibility' => '1.3.*', 'icon' => 'list-ul', 'install' => function () use ($core) { $core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `navs` ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `name` text NOT NULL )"); $core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `navs_items` ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `name` text NOT NULL, `url` text NULL, `page` integer NULL, `lang` text NOT NULL, `parent` integer NOT NULL DEFAULT 0, `nav` integer NOT NULL, `order` integer NOT NULL, `class` text NULL )"); $core->db()->pdo()->exec("INSERT INTO `navs` (`name`) VALUES ('main')"); $core->db()->pdo()->exec("INSERT INTO `navs_items` (`name`, `url`, `page`, `lang`, `nav`, `order`) VALUES ('Home', 'blog', 0, 'en_english', 1, 1)"); $core->db()->pdo()->exec("INSERT INTO `navs_items` (`name`, `url`, `page`, `lang`, `nav`, `order`) VALUES ('Strona główna', 'blog', 0, 'pl_polski', 1, 1)"); $core->db()->pdo()->exec("INSERT INTO `navs_items` (`name`, `page`, `lang`, `nav`, `order`) VALUES ('About me', 1, 'en_english', 1, 2)"); $core->db()->pdo()->exec("INSERT INTO `navs_items` (`name`, `page`, `lang`, `nav`, `order`) VALUES ('O mnie', 2, 'pl_polski', 1, 2)"); $core->db()->pdo()->exec("INSERT INTO `navs_items` (`name`, `page`, `lang`, `nav`, `order`) VALUES ('Contact', 3, 'en_english', 1, 3)"); $core->db()->pdo()->exec("INSERT INTO `navs_items` (`name`, `page`, `lang`, `nav`, `order`) VALUES ('Kontakt', 4, 'pl_polski', 1, 3)"); }, 'uninstall' => function () use ($core) { $core->db()->pdo()->exec("DROP TABLE `navs`"); $core->db()->pdo()->exec("DROP TABLE `navs_items`"); } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/navigation/Site.php
inc/modules/navigation/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Navigation; use Inc\Core\SiteModule; class Site extends SiteModule { public function routes() { $this->_insertMenu(); } /** * get nav data */ private function _insertMenu() { $assign = []; $homepage = $this->settings('settings', 'homepage'); $lang_prefix = $this->core->lang['name']; if ($lang_prefix != $this->settings('settings', 'lang_site')) { $lang_prefix = explode('_', $lang_prefix)[0]; } else { $lang_prefix = null; } // get nav $navs = $this->db('navs')->toArray(); foreach ($navs as $nav) { // get nav children $items = $this->db('navs_items')->leftJoin('pages', 'pages.id = navs_items.page')->where('navs_items.nav', $nav['id'])->where('navs_items.lang', $this->core->lang['name'])->asc('`order`')->select(['navs_items.*', 'pages.slug'])->toArray(); if (count($items)) { // generate URL foreach ($items as &$item) { // if external URL field is empty, it means that it's a batflat page $item['active'] = null; if (!$item['url']) { if ($item['slug'] == $homepage) { $item['url'] = $lang_prefix ? url([$lang_prefix]) : url(''); } else { $item['url'] = $lang_prefix ? url([$lang_prefix, $item['slug']]) : url([$item['slug']]); } $url = parseURL(); if ($url[0] == $item['slug'] || (preg_match('/^[a-z]{2}$/', $url[0]) && isset_or($url[1], $homepage) == $item['slug']) || $this->_isChildActive($item['id'], $url[0]) || ($url[0] == null && $homepage == $item['slug'])) { $item['active'] = 'active'; } } else { $item['url'] = url($item['url']); $page = ['slug' => null]; if (url(parseURL(1)) == $item['url'] || $this->_isChildActive($item['id'], parseURL(1)) || (parseURL(1) == null && url($homepage) == $item['url'])) { $item['active'] = 'active'; } if ($item['url'] == url($homepage)) { $item['url'] = url(''); } } } $navigation_admin = new Admin($this->core); $assign[$nav['name']] = $this->draw('nav.html', ['navigation' => ['list' => $navigation_admin->buildTree($items)]]); } else { $assign[$nav['name']] = null; } } $this->tpl->set('navigation', $assign); } /** * check if parent's child is active */ private function _isChildActive($itemID, $slug) { $rows = $this->db('pages') ->leftJoin('navs_items', 'pages.id = navs_items.page') ->where('navs_items.parent', $itemID) ->toArray(); if (count($rows)) { foreach ($rows as $row) { if ($slug == $row['slug']) { return true; } } } return false; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/modules/Admin.php
inc/modules/modules/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Modules; use Inc\Core\AdminModule; class Admin extends AdminModule { public function navigation() { return [ $this->lang('manage', 'general') => 'manage', $this->lang('upload_new') => 'upload' ]; } /** * list of active/inactive modules */ public function getManage($type = 'active') { $modules = $this->_modulesList($type); return $this->draw('manage.html', ['modules' => array_chunk($modules, 2), 'tab' => $type]); } /** * module upload */ public function getUpload() { return $this->draw('upload.html'); } /** * module extract */ public function postExtract() { if (isset($_FILES['zip_module']['tmp_name']) && !FILE_LOCK) { $backURL = url([ADMIN, 'modules', 'upload']); $file = $_FILES['zip_module']['tmp_name']; // Verify ZIP $zip = zip_open($file); $modules = array(); while ($entry = zip_read($zip)) { $entry = zip_entry_name($entry); if (preg_match('/^(.*?)\/Info.php$/', $entry, $matches)) { $modules[] = ['path' => $matches[0], 'name' => $matches[1]]; } if (strpos($entry, '/') === false) { $this->notify('failure', $this->lang('upload_bad_file')); redirect($backURL); } } // Extract to modules $zip = new \ZipArchive; if ($zip->open($file) === true) { foreach ($modules as $module) { if (file_exists(MODULES.'/'.$module['name'])) { $tmpName = md5(time().rand(1, 9999)); file_put_contents('tmp/'.$tmpName, $zip->getFromName($module['path'])); $info_new = include('tmp/'.$tmpName); $info_old = include(MODULES.'/'.$module['name'].'/Info.php'); unlink('tmp/'.$tmpName); if (cmpver($info_new['version'], $info_old['version']) <= 0) { $this->notify('failure', $this->lang('upload_bad_version')); continue; } } $this->unzip($file, MODULES.'/'.$module['name'], $module['name']); } $this->notify('success', $this->lang('upload_success')); } else { $this->notify('failure', $this->lang('upload_bad_file')); } } redirect($backURL); } public function getInstall($dir) { $files = [ 'info' => MODULES.'/'.$dir.'/Info.php', 'admin' => MODULES.'/'.$dir.'/Admin.php', 'site' => MODULES.'/'.$dir.'/Site.php' ]; if ((file_exists($files['info']) && file_exists($files['admin'])) || (file_exists($files['info']) && file_exists($files['site']))) { $core = $this->core; $info = include($files['info']); if (!$this->checkCompatibility(isset_or($info['compatibility']))) { $this->notify('failure', $this->lang('module_outdated'), $dir); } elseif ($this->db('modules')->save(['dir' => $dir, 'sequence' => $this->db('modules')->count()])) { if (isset($info['install'])) { $info['install'](); } $this->notify('success', $this->lang('activate_success'), $dir); } else { $this->notify('failure', $this->lang('activate_failure'), $dir); } } else { $this->notify('failure', $this->lang('activate_failure_files'), $dir); } redirect(url([ADMIN, 'modules', 'manage', 'inactive'])); } public function getUninstall($dir) { if (in_array($dir, unserialize(BASIC_MODULES))) { $this->notify('failure', $this->lang('deactivate_failure'), $dir); redirect(url([ADMIN, 'modules', 'manage', 'active'])); } if ($this->db('modules')->delete('dir', $dir)) { $core = $this->core; $info = include(MODULES.'/'.$dir.'/Info.php'); if (isset($info['uninstall'])) { $info['uninstall'](); } $this->notify('success', $this->lang('deactivate_success'), $dir); } else { $this->notify('failure', $this->lang('deactivate_failure'), $dir); } redirect(url([ADMIN, 'modules', 'manage', 'active'])); } public function getRemove($dir) { if (in_array($dir, unserialize(BASIC_MODULES))) { $this->notify('failure', $this->lang('remove_failure'), $dir); redirect(url([ADMIN, 'modules', 'manage', 'inactive'])); } $path = MODULES.'/'.$dir; if (is_dir($path)) { if (deleteDir($path)) { $this->notify('success', $this->lang('remove_success'), $dir); } else { $this->notify('failure', $this->lang('remove_failure'), $dir); } } redirect(url([ADMIN, 'modules', 'manage', 'inactive'])); } public function getDetails($dir) { $files = [ 'info' => MODULES.'/'.$dir.'/Info.php', 'readme' => MODULES.'/'.$dir.'/ReadMe.md' ]; $module = $this->core->getModuleInfo($dir); $module['description'] = $this->tpl->noParse($module['description']); $module['last_modified'] = date("Y-m-d", filemtime($files['info'])); // ReadMe.md if (file_exists($files['readme'])) { $parsedown = new \Inc\Core\Lib\Parsedown(); $module['readme'] = $parsedown->text($this->tpl->noParse(file_get_contents($files['readme']))); } $this->tpl->set('module', $module); echo $this->tpl->draw(MODULES.'/modules/view/admin/details.html', true); exit(); } private function _modulesList($type) { $dbModules = array_column($this->db('modules')->toArray(), 'dir'); $result = []; foreach (glob(MODULES.'/*', GLOB_ONLYDIR) as $dir) { $dir = basename($dir); $files = [ 'info' => MODULES.'/'.$dir.'/Info.php', 'admin' => MODULES.'/'.$dir.'/Admin.php', 'site' => MODULES.'/'.$dir.'/Site.php' ]; if ($type == 'active') { $inArray = in_array($dir, $dbModules); } else { $inArray = !in_array($dir, $dbModules); } if (((file_exists($files['info']) && file_exists($files['admin'])) || (file_exists($files['info']) && file_exists($files['site']))) && $inArray) { $details = $this->core->getModuleInfo($dir); $details['description'] = $this->tpl->noParse($details['description']); $features = $this->core->getModuleNav($dir); $other = []; $urls = [ 'url' => (is_array($features) ? url([ADMIN, $dir, array_shift($features)]) : '#'), 'uninstallUrl' => url([ADMIN, 'modules', 'uninstall', $dir]), 'removeUrl' => url([ADMIN, 'modules', 'remove', $dir]), 'installUrl' => url([ADMIN, 'modules', 'install', $dir]), 'detailsUrl' => url([ADMIN, 'modules', 'details', $dir]) ]; $other['installed'] = $type == 'active' ? true : false; if (in_array($dir, unserialize(BASIC_MODULES))) { $other['basic'] = true; } else { $other['basic'] = false; } $other['compatible'] = $this->checkCompatibility(isset_or($details['compatibility'], '1.0.0')); $result[] = $details + $urls + $other; } } return $result; } private function unzip($zipFile, $to, $path = '/') { $path = trim($path, '/'); $zip = new \ZipArchive; $zip->open($zipFile); for ($i = 0; $i < $zip->numFiles; $i++) { $filename = $zip->getNameIndex($i); if (empty($path) || strpos($filename, $path) == 0) { $file = $to.'/'.str_replace($path, null, $filename); if (!file_exists(dirname($file))) { mkdir(dirname($file), 0777, true); } if (substr($file, -1) != '/') { file_put_contents($to.'/'.str_replace($path, null, $filename), $zip->getFromIndex($i)); } } } $zip->close(); } private function checkCompatibility($version) { $systemVersion = $this->settings('settings', 'version'); $version = str_replace(['.', '*'], ['\\.', '[0-9]+'], $version); return preg_match('/^'.$version.'[a-z]*$/', $systemVersion); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/modules/Info.php
inc/modules/modules/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['modules']['module_name'], 'description' => $core->lang['modules']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.1', 'compatibility' => '1.3.*', 'icon' => 'plug', 'install' => function () use ($core) { $core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `modules` ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `dir` text NOT NULL, `sequence` integer DEFAULT 0 )"); }, 'uninstall' => function () use ($core) { $core->db()->pdo()->exec("DROP TABLE `modules`"); } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/dashboard/Admin.php
inc/modules/dashboard/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Dashboard; use Inc\Core\AdminModule; class Admin extends AdminModule { public function navigation() { return [ 'Main' => 'main' ]; } public function getMain() { $this->core->addCSS(url(MODULES.'/dashboard/css/style.css?v={$bat.version}')); return $this->draw('dashboard.html', ['modules' => $this->_modulesList(), 'news' => $this->_fetchNews()]); } private function _modulesList() { $modules = array_column($this->db('modules')->toArray(), 'dir'); $result = []; if ($this->core->getUserInfo('access') != 'all') { $modules = array_intersect($modules, explode(',', $this->core->getUserInfo('access'))); } foreach ($modules as $name) { $files = [ 'info' => MODULES.'/'.$name.'/Info.php', 'admin' => MODULES.'/'.$name.'/Admin.php', ]; if (file_exists($files['info']) && file_exists($files['admin'])) { $details = $this->core->getModuleInfo($name); $features = $this->core->getModuleNav($name); if (empty($features)) { continue; } $details['url'] = url([ADMIN, $name, array_shift($features)]); $result[] = $details; } } return $result; } private function _fetchNews() { \libxml_use_internal_errors(true); $assign = []; $lang = $this->settings('settings.lang_admin'); if (!in_array($lang, ['en_english', 'pl_polski'])) { $lang = 'en_english'; } $xml = \Inc\Core\Lib\HttpRequest::get('https://batflat.org/blog/feed/'.$lang); if (!empty($xml) && ($rss = simplexml_load_string($xml))) { $counter = 0; foreach ($rss->channel->item as $item) { if ($counter >= 3) { break; } $assign[$counter]['title'] = (string) $item->title; $assign[$counter]['link'] = (string) $item->link; $assign[$counter]['desc'] = (string) $item->description; $assign[$counter]['date'] = date('Y-m-d', strtotime($item->pubDate)); if (isset($item->image)) { $assign[$counter]['image'] = (string) $item->image->url; } $counter++; } } else { $assign[] = [ 'title' => $this->lang('rss_fail_title'), 'link' => '#', 'desc' => $this->lang('rss_fail_desc'), 'date' => null ]; } return $assign; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/dashboard/Info.php
inc/modules/dashboard/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['dashboard']['module_name'], 'description' => $core->lang['dashboard']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.1', 'compatibility' => '1.3.*', 'icon' => 'home' ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/users/Admin.php
inc/modules/users/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Users; use Inc\Core\AdminModule; class Admin extends AdminModule { private $assign = []; public function navigation() { return [ $this->lang('manage', 'general') => 'manage', $this->lang('add_new') => 'add' ]; } /** * users list */ public function getManage() { $rows = $this->db('users')->toArray(); foreach ($rows as &$row) { if (empty($row['fullname'])) { $row['fullname'] = '----'; } $row['editURL'] = url([ADMIN, 'users', 'edit', $row['id']]); $row['delURL'] = url([ADMIN, 'users', 'delete', $row['id']]); } return $this->draw('manage.html', ['myId' => $this->core->getUserInfo('id'), 'users' => $rows]); } /** * add new user */ public function getAdd() { if (!empty($redirectData = getRedirectData())) { $this->assign['form'] = filter_var_array($redirectData, FILTER_SANITIZE_STRING); } else { $this->assign['form'] = [ 'username' => '', 'email' => '', 'fullname' => '', 'description' => '' ]; } $this->assign['title'] = $this->lang('new_user'); $this->assign['modules'] = $this->_getModules('all'); $this->assign['avatarURL'] = url(MODULES.'/users/img/default.png'); return $this->draw('form.html', ['users' => $this->assign]); } /** * edit user */ public function getEdit($id) { $user = $this->db('users')->oneArray($id); if (!empty($user)) { $this->assign['form'] = $user; $this->assign['title'] = $this->lang('edit_user'); $this->assign['modules'] = $this->_getModules($user['access']); $this->assign['avatarURL'] = url(UPLOADS.'/users/'.$user['avatar']); return $this->draw('form.html', ['users' => $this->assign]); } else { redirect(url([ADMIN, 'users', 'manage'])); } } /** * save user data */ public function postSave($id = null) { $errors = 0; $formData = htmlspecialchars_array($_POST); // location to redirect $location = $id ? url([ADMIN, 'users', 'edit', $id]) : url([ADMIN, 'users', 'add']); // admin if ($id == 1) { $formData['access'] = ['all']; } // check if required fields are empty if (checkEmptyFields(['username', 'email', 'access'], $formData)) { $this->notify('failure', $this->lang('empty_inputs', 'general')); redirect($location, $formData); } // check if user already exists if ($this->_userAlreadyExists($id)) { $errors++; $this->notify('failure', $this->lang('user_already_exists')); } // check if e-mail adress is correct $formData['email'] = filter_var($formData['email'], FILTER_SANITIZE_EMAIL); if (!filter_var($formData['email'], FILTER_VALIDATE_EMAIL)) { $errors++; $this->notify('failure', $this->lang('wrong_email')); } // check if password is longer than 5 characters if (isset($formData['password']) && strlen($formData['password']) < 5) { $errors++; $this->notify('failure', $this->lang('too_short_pswd')); } // access to modules if ((count($formData['access']) == count($this->_getModules())) || ($id == 1)) { $formData['access'] = 'all'; } else { $formData['access'][] = 'dashboard'; $formData['access'] = implode(',', $formData['access']); } // CREATE / EDIT if (!$errors) { unset($formData['save']); if (!empty($formData['password'])) { $formData['password'] = password_hash($formData['password'], PASSWORD_BCRYPT); } // user avatar if (($photo = isset_or($_FILES['photo']['tmp_name'], false)) || !$id) { $img = new \Inc\Core\Lib\Image; if (empty($photo) && !$id) { $photo = MODULES.'/users/img/default.png'; } if ($img->load($photo)) { if ($img->getInfos('width') < $img->getInfos('height')) { $img->crop(0, 0, $img->getInfos('width'), $img->getInfos('width')); } else { $img->crop(0, 0, $img->getInfos('height'), $img->getInfos('height')); } if ($img->getInfos('width') > 512) { $img->resize(512, 512); } if ($id) { $user = $this->db('users')->oneArray($id); } $formData['avatar'] = uniqid('avatar').".".$img->getInfos('type'); } } if (!$id) { // new $query = $this->db('users')->save($formData); } else { // edit $query = $this->db('users')->where('id', $id)->save($formData); } if ($query) { if (isset($img) && $img->getInfos('width')) { if (isset($user)) { unlink(UPLOADS."/users/".$user['avatar']); } $img->save(UPLOADS."/users/".$formData['avatar']); } $this->notify('success', $this->lang('save_success')); } else { $this->notify('failure', $this->lang('save_failure')); } redirect($location); } redirect($location, $formData); } /** * remove user */ public function getDelete($id) { if ($id != 1 && $this->core->getUserInfo('id') != $id && ($user = $this->db('users')->oneArray($id))) { if ($this->db('users')->delete($id)) { if (!empty($user['avatar'])) { unlink(UPLOADS."/users/".$user['avatar']); } $this->notify('success', $this->lang('delete_success')); } else { $this->notify('failure', $this->lang('delete_failure')); } } redirect(url([ADMIN, 'users', 'manage'])); } /** * list of active modules * @return array */ private function _getModules($access = null) { $result = []; $rows = $this->db('modules')->toArray(); $accessArray = $access ? explode(',', $access) : []; foreach ($rows as $row) { if ($row['dir'] != 'dashboard') { $details = $this->core->getModuleInfo($row['dir']); if (empty($accessArray)) { $attr = ''; } else { if (in_array($row['dir'], $accessArray) || ($accessArray[0] == 'all')) { $attr = 'selected'; } else { $attr = ''; } } $result[] = ['dir' => $row['dir'], 'name' => $details['name'], 'icon' => $details['icon'], 'attr' => $attr]; } } return $result; } /** * check if user already exists * @return array */ private function _userAlreadyExists($id = null) { if (!$id) { // new $count = $this->db('users')->where('username', $_POST['username'])->count(); } else { // edit $count = $this->db('users')->where('username', $_POST['username'])->where('id', '<>', $id)->count(); } return $count > 0; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/users/Info.php
inc/modules/users/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['users']['module_name'], 'description' => $core->lang['users']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.2', 'compatibility' => '1.3.*', 'icon' => 'user', 'install' => function () use ($core) { $core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `users` ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `username` text NOT NULL, `fullname` text NULL, `description` text NULL, `password` text NOT NULL, `avatar` text NOT NULL, `email` text NOT NULL, `role` text NOT NULL DEFAULT 'admin', `access` text NOT NULL DEFAULT 'all' )"); $core->db()->pdo()->exec("CREATE TABLE `login_attempts` ( `ip` TEXT NOT NULL, `attempts` INTEGER NOT NULL, `expires` INTEGER NOT NULL DEFAULT 0 )"); $core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `remember_me` ( `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `token` text NOT NULL, `user_id` integer NOT NULL REFERENCES users(id) ON DELETE CASCADE, `expiry` integer NOT NULL )"); $avatar = uniqid('avatar').'.png'; $core->db()->pdo()->exec('INSERT INTO `users` (`username`, `fullname`, `description`, `password`, `avatar`, `email`, `role`, `access`) VALUES ("admin", "Selina Kyle", "My name is Selina Kyle but I speak for Catwoman… A mon who can offer you a path. Someone like you is only here by choice. You have been exploring the criminal fraternity but whatever your original intentions you have to become truly lost.", "$2y$10$pgRnDiukCbiYVqsamMM3ROWViSRqbyCCL33N8.ykBKZx0dlplXe9i", "'.$avatar.'", "admin@localhost", "admin", "all")'); if (!is_dir(UPLOADS."/users")) { mkdir(UPLOADS."/users", 0777); } copy(MODULES.'/users/img/default.png', UPLOADS.'/users/'.$avatar); }, 'uninstall' => function () use ($core) { $core->db()->pdo()->exec("DROP TABLE `users`"); $core->db()->pdo()->exec("DROP TABLE `login_attempts`"); $core->db()->pdo()->exec("DROP TABLE `remember_me`"); deleteDir(UPLOADS."/users"); } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/users/Site.php
inc/modules/users/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Users; use Inc\Core\SiteModule; class Site extends SiteModule { public function init() { $this->tpl->set('users', function () { $result = []; $users = $this->db('users')->select(['id', 'username', 'fullname', 'description', 'avatar', 'email'])->toArray(); foreach ($users as $key => $value) { $result[$value['id']] = $users[$key]; $result[$value['id']]['avatar'] = url('uploads/users/' . $value['avatar']); } return $result; }); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/DB.php
inc/modules/statistics/DB.php
<?php namespace Inc\Modules\Statistics; use Inc\Core\Lib\QueryBuilder; class DB extends QueryBuilder { /** * @var \PDO */ protected static $db; } $database = BASE_DIR.'/inc/data/statistics.sdb'; DB::connect("sqlite:{$database}");
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/Admin.php
inc/modules/statistics/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Statistics; use Inc\Core\AdminModule; use Inc\Modules\Statistics\Src\Chart; use Inc\Modules\Statistics\Src\Statistics; class Admin extends AdminModule { /** * @var string */ protected $moduleDirectory = null; /** * @var Chart */ protected $chart = null; /** * @var Statistics */ protected $statistics = null; public function init() { $this->statistics = new Statistics(); $this->chart = new Chart(); $this->moduleDirectory = MODULES.'/statistics'; $this->core->addCSS(url($this->moduleDirectory.'/assets/css/style.css?v={$bat.version}')); $this->core->addJS(url($this->moduleDirectory.'/assets/js/Chart.bundle.min.js')); $this->core->addJS(url($this->moduleDirectory.'/assets/js/app.js?v={$bat.version}')); } public function navigation() { return [ 'Main' => 'main', ]; } public function getMain() { $statistics = $this->statistics; $chart = $this->chart; // Numbers $visitors['unique'] = $statistics->countUniqueVisits(); $visitors['online'] = $statistics->countCurrentOnline(); $visitors['visits']['today'] = $statistics->countAllVisits("TODAY"); $visitors['visits']['yesterday'] = $statistics->countUniqueVisits("YESTERDAY"); $visitors['visits']['7days'] = $statistics->countUniqueVisits("-7 days", 7); $visitors['visits']['30days'] = $statistics->countUniqueVisits("-30 days", 30); $visitors['visits']['all'] = $statistics->countUniqueVisits("ALL"); // Charts $visitors['chart'] = $chart->getVisitors(14); $visitors['platform'] = $chart->getOperatingSystems(); $visitors['countries'] = $chart->getCountries(); $visitors['browsers'] = $chart->getBrowsers(); // Lists $visitors['pages'] = $statistics->getPages(); $visitors['referrers'] = $statistics->getReferrers(); return $this->draw('dashboard.html', [ 'visitors' => $visitors ]); } public function getUrl($urlBase64) { $statistics = $this->statistics; $chart = $this->chart; $url = base64_decode($urlBase64); // Numbers $visitors['unique'] = $statistics->countUniqueVisits('ALL', 1, $url); $visitors['all'] = $statistics->countAllVisits('ALL', 1, $url); // Charts $visitors['chart'] = $chart->getVisitors(14, 0, $url); $visitors['platform'] = $chart->getOperatingSystems($url); $visitors['countries'] = $chart->getCountries($url); $visitors['browsers'] = $chart->getBrowsers($url); // Lists $visitors['referrers'] = $statistics->getReferrers($url, false); return $this->draw('url.html', [ 'url' => $url, 'visitors' => $visitors ]); } public function getreferrer($urlBase64) { $statistics = $this->statistics; $chart = $this->chart; $url = base64_decode($urlBase64); // Numbers $visitors['unique'] = $statistics->countUniqueVisits('ALL', 1, null, $url); $visitors['all'] = $statistics->countAllVisits('ALL', 1, null, $url); // Charts $visitors['chart'] = $chart->getVisitors(14, 0, null, $url); $visitors['platform'] = $chart->getOperatingSystems(null, $url); $visitors['countries'] = $chart->getCountries(null, $url); $visitors['browsers'] = $chart->getBrowsers(null, $url); // Lists $visitors['referrers'] = $chart->getReferrers($url, false); return $this->draw('referrer.html', [ 'url' => $url, 'visitors' => $visitors ]); } public function getPages() { $statistics = $this->statistics; $chart = $this->chart; $pages['chart'] = $chart->getPages(); $pages['list'] = $statistics->getPages(null, false); return $this->draw('pages.html', [ 'pages' => $pages ]); } public function getReferrers() { $statistics = $this->statistics; $chart = $this->chart; $referrer['chart'] = $chart->getReferrers(); $referrer['list'] = $statistics->getReferrers(null, false); return $this->draw('referrers.html', [ 'referrers' => $referrer ]); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/Info.php
inc/modules/statistics/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ use Inc\Modules\Statistics\DB; return [ 'name' => $core->lang['statistics']['module_name'], 'description' => $core->lang['statistics']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.0', 'compatibility' => '1.3.*', 'icon' => 'pie-chart', 'install' => function () use ($core) { if (file_exists(BASE_DIR.'/inc/data/statistics.sdb')) { return; } DB::pdo()->exec("CREATE TABLE IF NOT EXISTS `statistics` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `ip` TEXT NOT NULL, `useragent` TEXT, `uniqhash` TEXT, `browser` TEXT, `country` TEXT, `platform` TEXT, `url` TEXT, `referrer` TEXT, `status_code` INTEGER NOT NULL, `bot` INTEGER NOT NULL, `created_at` INTEGER NOT NULL );"); DB::pdo()->exec("CREATE INDEX statistics_idx1 ON statistics(ip,useragent,country,platform,url,referrer,status_code,bot)"); }, 'uninstall' => function () use ($core) { unlink(BASE_DIR.'/inc/data/statistics.sdb'); }, ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/Site.php
inc/modules/statistics/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Statistics; use Inc\Core\SiteModule; use Inc\Modules\Statistics\DB; use Inc\Modules\Statistics\PHPBrowserDetector\Browser; use Inc\Modules\Statistics\PHPBrowserDetector\Os; use Inc\Core\Lib\HttpRequest; class Site extends SiteModule { public function init() { // Browser $browser = new Browser; // OS $os = new Os; // IP and GEO $ip = $_SERVER['REMOTE_ADDR']; // Get latest country or fetch new $country = 'Unknown'; $latest = $this->db('statistics')->where('ip', $ip)->desc('created_at')->limit(1)->oneArray(); if (!$latest) { $details = json_decode(HttpRequest::get('https://freegeoip.app/json/'.$ip), true); if (!empty($details['country_code'])) { $country = $details['country_code']; } } else { $country = $latest['country']; } // referrer $referrer = isset_or($_SERVER['HTTP_referrer'], false); if ($referrer && $url = parse_url($referrer)) { if (strpos($url['host'], domain(false)) !== false) { $referrer = null; } } else { $referrer = null; } // Add visitor record $this->db('statistics')->save([ 'ip' => $ip, 'browser' => $browser->getName(), 'useragent' => $browser->getUserAgent()->getUserAgentString(), 'uniqhash' => md5($ip.$browser->getUserAgent()->getUserAgentString()), 'country' => $country, 'platform' => $os->getName(), 'url' => '/'.implode('/', parseURL()), 'referrer' => $referrer, 'status_code' => http_response_code(), 'bot' => ($browser->isRobot() ? 1 : 0), ]); } public function routes() { // } protected function db($table = null) { return new DB($table); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/src/Statistics.php
inc/modules/statistics/src/Statistics.php
<?php namespace Inc\Modules\Statistics\Src; use Inc\Modules\Statistics\DB; class Statistics { public function getReferrers($url = null, $limit = 15, $bot = false) { $query = $this->db('statistics') ->select([ 'referrer', 'count_unique' => 'COUNT(DISTINCT uniqhash)', 'count' => 'COUNT(uniqhash)', ]) ->where('bot', $bot ? 1 : 0) ->group(['referrer']) ->desc('count'); if (!empty($url)) { $query->where('url', $url); } if ($limit !== false) { $query->limit($limit); } $urls = $query->toArray(); return $urls; } public function getPages($referrer = null, $limit = 15) { $query = $this->db('statistics') ->select([ 'url', 'count_unique' => 'COUNT(DISTINCT uniqhash)', 'count' => 'COUNT(uniqhash)', ]) ->group(['url']) ->desc('count'); if ($limit !== false) { $query->limit($limit); } if (!empty($referrer)) { $query->where('referrer', $referrer); } $urls = $query->toArray(); return $urls; } public function countCurrentOnline($margin = "-5 minutes") { $online = $this->db('statistics') ->select([ 'count' => 'COUNT(DISTINCT uniqhash)', ]) ->where('bot', 0) ->where('created_at', '>', strtotime($margin)) ->oneArray(); return $online['count']; } public function countAllVisits($date = 'TODAY', $days = 1, $url = null, $referrer = null) { $query = $this->db('statistics') ->select([ 'count' => 'COUNT(uniqhash)', ]) ->where('bot', 0); if ($date != 'ALL') { $date = strtotime($date); $query->where('created_at', '>=', $date)->where('created_at', '<', $date + $days * 86400); } if (!empty($url)) { $query->where('url', $url); } if (!empty($referrer)) { $query->where('referrer', $referrer); } $all = $query->oneArray(); return $all['count']; } public function countUniqueVisits($date = 'TODAY', $days = 1, $url = null, $referrer = null) { $query = $this->db('statistics') ->select([ 'count' => 'COUNT(DISTINCT uniqhash)', ]) ->where('bot', 0); if ($date != 'ALL') { $date = strtotime($date); $query->where('created_at', '>=', $date)->where('created_at', '<', $date + $days * 86400); } if (!empty($url)) { $query->where('url', $url); } if (!empty($referrer)) { $query->where('referrer', $referrer); } $record = $query->oneArray(); return $record['count']; } protected function db($table) { return new DB($table); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/src/Chart.php
inc/modules/statistics/src/Chart.php
<?php namespace Inc\Modules\Statistics\Src; use Inc\Modules\Statistics\DB; class Chart { public function getVisitors($days = 14, $offset = 0, $url = null, $referrer = null) { $time = strtotime(date("Ymd000000", strtotime("-".$days + $offset." days"))); $query = $this->db('statistics') ->select([ 'count' => 'COUNT(*)', 'count_unique' => 'COUNT(DISTINCT uniqhash)', 'formatedDate' => "strftime('%Y-%m-%d', datetime(created_at, 'unixepoch', 'localtime'))", ]) ->where('bot', 0) ->where('created_at', '>=', $time) ->group(['formatedDate']) ->asc('formatedDate'); if (!empty($url)) { $query->where('url', $url); } if (!empty($referrer)) { $query->where('referrer', $referrer); } $data = $query->toArray(); $return = [ 'labels' => [], 'uniques' => [], 'visits' => [], ]; while ($time < (time() - ($offset * 86400))) { $return['labels'][] = '"'.date("Y-m-d", $time).'"'; $return['readable'][] = '"'.date("d M Y", $time).'"'; $return['uniques'][] = 0; $return['visits'][] = 0; $time = strtotime('+1 day', $time); } foreach ($data as $day) { $index = array_search('"'.$day['formatedDate'].'"', $return['labels']); if ($index === false) { continue; } $return['uniques'][$index] = $day['count_unique']; $return['visits'][$index] = $day['count']; } return $return; } public function getOperatingSystems($url = null, $referrer = null) { return $this->getPopularBy('platform', $url, $referrer); } public function getBrowsers($url = null, $referrer = null) { return $this->getPopularBy('browser', $url, $referrer); } public function getCountries($url = null, $referrer = null) { return $this->getPopularBy('country', $url, $referrer); } public function getPages($url = null, $referrer = null) { return $this->getPopularBy('url', $url, $referrer, 'desc'); } public function getReferrers($url = null, $referrer = null) { return $this->getPopularBy('referrer', $url, $referrer); } protected function getPopularBy($group, $url = null, $referrer = null, $order = 'asc') { $data = $this->db('statistics') ->select([ $group, 'count' => 'COUNT(DISTINCT uniqhash)', ]) ->where('bot', 0) ->group([$group]) ->asc('count'); if (!empty($url)) { $data->where('url', $url); } if (!empty($referrer)) { $data->where('referrer', $referrer); } $data = $data->toArray(); if ($order == 'desc') { $data = array_reverse($data); } $labels = array_map(function (&$value) { $value = preg_replace('/[^a-zA-Z0-9\/]/', '', $value); return '"'.$value.'"'; }, array_column($data, $group)); return [ 'labels' => $labels, 'data' => array_column($data, 'count'), ]; } protected function db($table) { return new DB($table); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/DeviceDetector.php
inc/modules/statistics/phpbrowserdetector/DeviceDetector.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; class DeviceDetector implements DetectorInterface { /** * Determine the user's device. * * @param Device $device * @param UserAgent $userAgent * @return bool */ public static function detect(Device $device, UserAgent $userAgent) { $device->setName($device::UNKNOWN); return ( self::checkIpad($device, $userAgent) || self::checkIphone($device, $userAgent) || self::checkWindowsPhone($device, $userAgent) || self::checkSamsungPhone($device, $userAgent) ); } /** * Determine if the device is iPad. * * @param Device $device * @param UserAgent $userAgent * @return bool */ private static function checkIpad(Device $device, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'ipad') !== false) { $device->setName(Device::IPAD); return true; } return false; } /** * Determine if the device is iPhone. * * @param Device $device * @param UserAgent $userAgent * @return bool */ private static function checkIphone(Device $device, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'iphone;') !== false) { $device->setName(Device::IPHONE); return true; } return false; } /** * Determine if the device is Windows Phone. * * @param Device $device * @param UserAgent $userAgent * @return bool */ private static function checkWindowsPhone(Device $device, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'Windows Phone') !== false) { if (preg_match('/Microsoft; (Lumia [^)]*)\)/', $userAgent->getUserAgentString(), $matches)) { $device->setName($matches[1]); return true; } $device->setName($device::WINDOWS_PHONE); return true; } return false; } /** * Determine if the device is Windows Phone. * * @param Device $device * @param UserAgent $userAgent * @return bool */ private static function checkSamsungPhone(Device $device, UserAgent $userAgent) { if (preg_match('/SAMSUNG SM-([^ ]*)/i', $userAgent->getUserAgentString(), $matches)) { $device->setName(str_ireplace('SAMSUNG', 'Samsung', $matches[0])); return true; } return false; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/Language.php
inc/modules/statistics/phpbrowserdetector/Language.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; /** * Language Detection. */ class Language { /** * @var AcceptLanguage */ private $acceptLanguage; /** * @var array */ private $languages; /** * @param null|string|AcceptLanguage $acceptLanguage * * @throws \Inc\Modules\Statistics\PHPBrowserDetector\InvalidArgumentException */ public function __construct($acceptLanguage = null) { if ($acceptLanguage instanceof AcceptLanguage) { $this->setAcceptLanguage($acceptLanguage); } elseif (null === $acceptLanguage || is_string($acceptLanguage)) { $this->setAcceptLanguage(new AcceptLanguage($acceptLanguage)); } else { throw new InvalidArgumentException(); } } /** * Get all user's languages. * * @return array */ public function getLanguages() { if (!is_array($this->languages)) { LanguageDetector::detect($this, $this->getAcceptLanguage()); } return $this->languages; } /** * Set languages. * * @param array $languages * * @return $this */ public function setLanguages($languages) { $this->languages = $languages; return $this; } /** * Get a user's language. * * @return string */ public function getLanguage() { if (!is_array($this->languages)) { LanguageDetector::detect($this, $this->getAcceptLanguage()); } return strtolower(substr(reset($this->languages), 0, 2)); } /** * Get a user's language and locale. * * @param string $separator * * @return string */ public function getLanguageLocale($separator = '-') { if (!is_array($this->languages)) { LanguageDetector::detect($this, $this->getAcceptLanguage()); } $userLanguage = $this->getLanguage(); foreach ($this->languages as $language) { if (strlen($language) === 5 && strpos($language, $userLanguage) === 0) { $locale = substr($language, -2); break; } } if (!empty($locale)) { return $userLanguage . $separator . strtoupper($locale); } else { return $userLanguage; } } /** * @param AcceptLanguage $acceptLanguage * * @return $this */ public function setAcceptLanguage(AcceptLanguage $acceptLanguage) { $this->acceptLanguage = $acceptLanguage; return $this; } /** * @return AcceptLanguage */ public function getAcceptLanguage() { return $this->acceptLanguage; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/OsDetector.php
inc/modules/statistics/phpbrowserdetector/OsDetector.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; class OsDetector implements DetectorInterface { /** * Determine the user's operating system. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ public static function detect(Os $os, UserAgent $userAgent) { $os->setName($os::UNKNOWN); $os->setVersion($os::VERSION_UNKNOWN); $os->setIsMobile(false); self::checkMobileBrowsers($os, $userAgent); return ( // Chrome OS before OS X self::checkChromeOs($os, $userAgent) || // iOS before OS X self::checkIOS($os, $userAgent) || self::checkOSX($os, $userAgent) || self::checkSymbOS($os, $userAgent) || self::checkWindows($os, $userAgent) || self::checkWindowsPhone($os, $userAgent) || self::checkFreeBSD($os, $userAgent) || self::checkOpenBSD($os, $userAgent) || self::checkNetBSD($os, $userAgent) || self::checkOpenSolaris($os, $userAgent) || self::checkSunOS($os, $userAgent) || self::checkOS2($os, $userAgent) || self::checkBeOS($os, $userAgent) || // Android before Linux self::checkAndroid($os, $userAgent) || self::checkLinux($os, $userAgent) || self::checkNokia($os, $userAgent) || self::checkBlackBerry($os, $userAgent) ); } /** * Determine if the user's browser is on a mobile device. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ public static function checkMobileBrowsers(Os $os, UserAgent $userAgent) { // Check for Opera Mini if (stripos($userAgent->getUserAgentString(), 'opera mini') !== false) { $os->setIsMobile(true); } // Set is mobile for Pocket IE elseif (stripos($userAgent->getUserAgentString(), 'mspie') !== false || stripos($userAgent->getUserAgentString(), 'pocket') !== false) { $os->setIsMobile(true); } } /** * Determine if the user's operating system is iOS. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkIOS(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'CPU OS') !== false || stripos($userAgent->getUserAgentString(), 'iPhone OS') !== false && stripos($userAgent->getUserAgentString(), 'OS X')) { $os->setName($os::IOS); if (preg_match('/CPU( iPhone)? OS ([\d_]*)/i', $userAgent->getUserAgentString(), $matches)) { $os->setVersion(str_replace('_', '.', $matches[2])); } $os->setIsMobile(true); return true; } return false; } /** * Determine if the user's operating system is Chrome OS. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkChromeOs(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), ' CrOS') !== false || stripos($userAgent->getUserAgentString(), 'CrOS ') !== false ) { $os->setName($os::CHROME_OS); if (preg_match('/Chrome\/([\d\.]*)/i', $userAgent->getUserAgentString(), $matches)) { $os->setVersion($matches[1]); } return true; } return false; } /** * Determine if the user's operating system is OS X. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkOSX(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'OS X') !== false) { $os->setName($os::OSX); if (preg_match('/OS X ([\d\._]*)/i', $userAgent->getUserAgentString(), $matches)) { if (isset($matches[1])) { $os->setVersion(str_replace('_', '.', $matches[1])); } } return true; } return false; } /** * Determine if the user's operating system is Windows. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkWindows(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'Windows NT') !== false) { $os->setName($os::WINDOWS); // Windows version if (preg_match('/Windows NT ([\d\.]*)/i', $userAgent->getUserAgentString(), $matches)) { if (isset($matches[1])) { switch (str_replace('_', '.', $matches[1])) { case '6.3': $os->setVersion('8.1'); break; case '6.2': $os->setVersion('8'); break; case '6.1': $os->setVersion('7'); break; case '6.0': $os->setVersion('Vista'); break; case '5.2': case '5.1': $os->setVersion('XP'); break; case '5.01': case '5.0': $os->setVersion('2000'); break; case '4.0': $os->setVersion('NT 4.0'); break; default: if ((float)$matches[1] >= 10.0) { $os->setVersion($matches[1]); } break; } } } return true; } // Windows Me, Windows 98, Windows 95, Windows CE elseif (preg_match( '/(Windows 98; Win 9x 4\.90|Windows 98|Windows 95|Windows CE)/i', $userAgent->getUserAgentString(), $matches )) { $os->setName($os::WINDOWS); switch (strtolower($matches[0])) { case 'windows 98; win 9x 4.90': $os->setVersion('Me'); break; case 'windows 98': $os->setVersion('98'); break; case 'windows 95': $os->setVersion('95'); break; case 'windows ce': $os->setVersion('CE'); break; } return true; } return false; } /** * Determine if the user's operating system is Windows Phone. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkWindowsPhone(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'Windows Phone') !== false) { $os->setIsMobile(true); $os->setName($os::WINDOWS_PHONE); // Windows version if (preg_match('/Windows Phone ([\d\.]*)/i', $userAgent->getUserAgentString(), $matches)) { if (isset($matches[1])) { $os->setVersion((float)$matches[1]); } } return true; } return false; } /** * Determine if the user's operating system is SymbOS. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkSymbOS(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'SymbOS') !== false) { $os->setName($os::SYMBOS); return true; } return false; } /** * Determine if the user's operating system is Linux. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkLinux(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'Linux') !== false) { $os->setVersion($os::VERSION_UNKNOWN); $os->setName($os::LINUX); return true; } return false; } /** * Determine if the user's operating system is Nokia. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkNokia(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'Nokia') !== false) { $os->setVersion($os::VERSION_UNKNOWN); $os->setName($os::NOKIA); $os->setIsMobile(true); return true; } return false; } /** * Determine if the user's operating system is BlackBerry. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkBlackBerry(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'BlackBerry') !== false) { if (stripos($userAgent->getUserAgentString(), 'Version/') !== false) { $aresult = explode('Version/', $userAgent->getUserAgentString()); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); $os->setVersion($aversion[0]); } } else { $os->setVersion($os::VERSION_UNKNOWN); } $os->setName($os::BLACKBERRY); $os->setIsMobile(true); return true; } elseif (stripos($userAgent->getUserAgentString(), 'BB10') !== false) { $aresult = explode('Version/10.', $userAgent->getUserAgentString()); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); $os->setVersion('10.' . $aversion[0]); } else { $os->setVersion('10'); } $os->setName($os::BLACKBERRY); $os->setIsMobile(true); return true; } return false; } /** * Determine if the user's operating system is Android. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkAndroid(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'Android') !== false) { if (preg_match('/Android ([\d\.]*)/i', $userAgent->getUserAgentString(), $matches)) { if (isset($matches[1])) { $os->setVersion($matches[1]); } } else { $os->setVersion($os::VERSION_UNKNOWN); } $os->setName($os::ANDROID); $os->setIsMobile(true); return true; } return false; } /** * Determine if the user's operating system is FreeBSD. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkFreeBSD(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'FreeBSD') !== false) { $os->setVersion($os::VERSION_UNKNOWN); $os->setName($os::FREEBSD); return true; } return false; } /** * Determine if the user's operating system is OpenBSD. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkOpenBSD(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'OpenBSD') !== false) { $os->setVersion($os::VERSION_UNKNOWN); $os->setName($os::OPENBSD); return true; } return false; } /** * Determine if the user's operating system is SunOS. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkSunOS(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'SunOS') !== false) { $os->setVersion($os::VERSION_UNKNOWN); $os->setName($os::SUNOS); return true; } return false; } /** * Determine if the user's operating system is NetBSD. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkNetBSD(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'NetBSD') !== false) { $os->setVersion($os::VERSION_UNKNOWN); $os->setName($os::NETBSD); return true; } return false; } /** * Determine if the user's operating system is OpenSolaris. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkOpenSolaris(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'OpenSolaris') !== false) { $os->setVersion($os::VERSION_UNKNOWN); $os->setName($os::OPENSOLARIS); return true; } return false; } /** * Determine if the user's operating system is OS2. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkOS2(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'OS\/2') !== false) { $os->setVersion($os::VERSION_UNKNOWN); $os->setName($os::OS2); return true; } return false; } /** * Determine if the user's operating system is BeOS. * * @param Os $os * @param UserAgent $userAgent * * @return bool */ private static function checkBeOS(Os $os, UserAgent $userAgent) { if (stripos($userAgent->getUserAgentString(), 'BeOS') !== false) { $os->setVersion($os::VERSION_UNKNOWN); $os->setName($os::BEOS); return true; } return false; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/BrowserDetector.php
inc/modules/statistics/phpbrowserdetector/BrowserDetector.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; class BrowserDetector implements DetectorInterface { const FUNC_PREFIX = 'checkBrowser'; protected static $userAgentString; /** * @var Browser */ protected static $browser; protected static $browsersList = array( // well-known, well-used // Special Notes: // (1) Opera must be checked before FireFox due to the odd // user agents used in some older versions of Opera // (2) WebTV is strapped onto Internet Explorer so we must // check for WebTV before IE // (3) Because of Internet Explorer 11 using // "Mozilla/5.0 ([...] Trident/7.0; rv:11.0) like Gecko" // as user agent, tests for IE must be run before any // tests checking for "Mozilla" // (4) (deprecated) Galeon is based on Firefox and needs to be // tested before Firefox is tested // (5) OmniWeb is based on Safari so OmniWeb check must occur // before Safari // (6) Netscape 9+ is based on Firefox so Netscape checks // before FireFox are necessary // (7) Microsoft Edge must be checked before Chrome and Safari // (7) Vivaldi must be checked before Chrome 'WebTv', 'InternetExplorer', 'Edge', 'Opera', 'Vivaldi', 'Dragon', 'Galeon', 'NetscapeNavigator9Plus', 'SeaMonkey', 'Firefox', 'Yandex', 'Samsung', 'Chrome', 'OmniWeb', // common mobile 'Android', 'BlackBerry', 'Nokia', 'Gsa', // common bots 'Robot', // wkhtmltopdf before Safari 'Wkhtmltopdf', // WebKit base check (post mobile and others) 'Safari', // everyone else 'NetPositive', 'Firebird', 'Konqueror', 'Icab', 'Phoenix', 'Amaya', 'Lynx', 'Shiretoko', 'IceCat', 'Iceweasel', 'Mozilla', /* Mozilla is such an open standard that you must check it last */ ); /** * Routine to determine the browser type. * * @param Browser $browser * @param UserAgent $userAgent * * @return bool */ public static function detect(Browser $browser, UserAgent $userAgent = null) { self::$browser = $browser; if (is_null($userAgent)) { $userAgent = self::$browser->getUserAgent(); } self::$userAgentString = $userAgent->getUserAgentString(); self::$browser->setName(Browser::UNKNOWN); self::$browser->setVersion(Browser::VERSION_UNKNOWN); self::checkChromeFrame(); self::checkFacebookWebView(); foreach (self::$browsersList as $browserName) { $funcName = self::FUNC_PREFIX . $browserName; if (self::$funcName()) { return true; } } return false; } /** * Determine if the user is using Chrome Frame. * * @return bool */ public static function checkChromeFrame() { if (strpos(self::$userAgentString, 'chromeframe') !== false) { self::$browser->setIsChromeFrame(true); return true; } return false; } /** * Determine if the user is using Facebook. * * @return bool */ public static function checkFacebookWebView() { if (strpos(self::$userAgentString, 'FBAV') !== false) { self::$browser->setIsFacebookWebView(true); return true; } return false; } /** * Determine if the user is using a BlackBerry. * * @return bool */ public static function checkBrowserBlackBerry() { if (stripos(self::$userAgentString, 'blackberry') !== false) { if (stripos(self::$userAgentString, 'Version/') !== false) { $aresult = explode('Version/', self::$userAgentString); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } } else { $aresult = explode('/', stristr(self::$userAgentString, 'BlackBerry')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } } self::$browser->setName(Browser::BLACKBERRY); return true; } elseif (stripos(self::$userAgentString, 'BB10') !== false) { $aresult = explode('Version/10.', self::$userAgentString); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion('10.' . $aversion[0]); } self::$browser->setName(Browser::BLACKBERRY); return true; } return false; } /** * Determine if the browser is a robot. * * @return bool */ public static function checkBrowserRobot() { if (stripos(self::$userAgentString, 'bot') !== false || stripos(self::$userAgentString, 'spider') !== false || stripos(self::$userAgentString, 'crawler') !== false ) { self::$browser->setIsRobot(true); return true; } return false; } /** * Determine if the browser is Internet Explorer. * * @return bool */ public static function checkBrowserInternetExplorer() { // Test for v1 - v1.5 IE if (stripos(self::$userAgentString, 'microsoft internet explorer') !== false) { self::$browser->setName(Browser::IE); self::$browser->setVersion('1.0'); $aresult = stristr(self::$userAgentString, '/'); if (preg_match('/308|425|426|474|0b1/i', $aresult)) { self::$browser->setVersion('1.5'); } return true; } // Test for versions > 1.5 and < 11 and some cases of 11 else { if (stripos(self::$userAgentString, 'msie') !== false && stripos(self::$userAgentString, 'opera') === false ) { // See if the browser is the odd MSN Explorer if (stripos(self::$userAgentString, 'msnb') !== false) { $aresult = explode(' ', stristr(str_replace(';', '; ', self::$userAgentString), 'MSN')); self::$browser->setName(Browser::MSN); if (isset($aresult[1])) { self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); } return true; } $aresult = explode(' ', stristr(str_replace(';', '; ', self::$userAgentString), 'msie')); self::$browser->setName(Browser::IE); if (isset($aresult[1])) { self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1])); } // See https://msdn.microsoft.com/en-us/library/ie/hh869301%28v=vs.85%29.aspx // Might be 11, anyway ! if (stripos(self::$userAgentString, 'trident') !== false) { preg_match('/rv:(\d+\.\d+)/', self::$userAgentString, $matches); if (isset($matches[1])) { self::$browser->setVersion($matches[1]); } // At this poing in the method, we know the MSIE and Trident // strings are present in the $userAgentString. If we're in // compatibility mode, we need to determine the true version. // If the MSIE version is 7.0, we can look at the Trident // version to *approximate* the true IE version. If we don't // find a matching pair, ( e.g. MSIE 7.0 && Trident/7.0 ) // we're *not* in compatibility mode and the browser really // is version 7.0. if (stripos(self::$userAgentString, 'MSIE 7.0;')) { if (stripos(self::$userAgentString, 'Trident/7.0;')) { // IE11 in compatibility mode self::$browser->setVersion('11.0'); self::$browser->setIsCompatibilityMode(true); } elseif (stripos(self::$userAgentString, 'Trident/6.0;')) { // IE10 in compatibility mode self::$browser->setVersion('10.0'); self::$browser->setIsCompatibilityMode(true); } elseif (stripos(self::$userAgentString, 'Trident/5.0;')) { // IE9 in compatibility mode self::$browser->setVersion('9.0'); self::$browser->setIsCompatibilityMode(true); } elseif (stripos(self::$userAgentString, 'Trident/4.0;')) { // IE8 in compatibility mode self::$browser->setVersion('8.0'); self::$browser->setIsCompatibilityMode(true); } } } return true; } // Test for versions >= 11 else { if (stripos(self::$userAgentString, 'trident') !== false) { self::$browser->setName(Browser::IE); preg_match('/rv:(\d+\.\d+)/', self::$userAgentString, $matches); if (isset($matches[1])) { self::$browser->setVersion($matches[1]); return true; } else { return false; } } // Test for Pocket IE else { if (stripos(self::$userAgentString, 'mspie') !== false || stripos( self::$userAgentString, 'pocket' ) !== false ) { $aresult = explode(' ', stristr(self::$userAgentString, 'mspie')); self::$browser->setName(Browser::POCKET_IE); if (stripos(self::$userAgentString, 'mspie') !== false) { if (isset($aresult[1])) { self::$browser->setVersion($aresult[1]); } } else { $aversion = explode('/', self::$userAgentString); if (isset($aversion[1])) { self::$browser->setVersion($aversion[1]); } } return true; } } } } return false; } /** * Determine if the browser is Opera. * * @return bool */ public static function checkBrowserOpera() { if (stripos(self::$userAgentString, 'opera mini') !== false) { $resultant = stristr(self::$userAgentString, 'opera mini'); if (preg_match('/\//', $resultant)) { $aresult = explode('/', $resultant); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } } else { $aversion = explode(' ', stristr($resultant, 'opera mini')); if (isset($aversion[1])) { self::$browser->setVersion($aversion[1]); } } self::$browser->setName(Browser::OPERA_MINI); return true; } elseif (stripos(self::$userAgentString, 'OPiOS') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'OPiOS')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } self::$browser->setName(Browser::OPERA_MINI); return true; } elseif (stripos(self::$userAgentString, 'opera') !== false) { $resultant = stristr(self::$userAgentString, 'opera'); if (preg_match('/Version\/(1[0-2].*)$/', $resultant, $matches)) { if (isset($matches[1])) { self::$browser->setVersion($matches[1]); } } elseif (preg_match('/\//', $resultant)) { $aresult = explode('/', str_replace('(', ' ', $resultant)); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } } else { $aversion = explode(' ', stristr($resultant, 'opera')); self::$browser->setVersion(isset($aversion[1]) ? $aversion[1] : ''); } self::$browser->setName(Browser::OPERA); return true; } elseif (stripos(self::$userAgentString, ' OPR/') !== false) { self::$browser->setName(Browser::OPERA); if (preg_match('/OPR\/([\d\.]*)/', self::$userAgentString, $matches)) { if (isset($matches[1])) { self::$browser->setVersion($matches[1]); } } return true; } return false; } /** * Determine if the browser is Samsung. * * @return bool */ public static function checkBrowserSamsung() { if (stripos(self::$userAgentString, 'SamsungBrowser') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'SamsungBrowser')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } self::$browser->setName(Browser::SAMSUNG_BROWSER); return true; } return false; } /** * Determine if the browser is Chrome. * * @return bool */ public static function checkBrowserChrome() { if (stripos(self::$userAgentString, 'Chrome') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'Chrome')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } self::$browser->setName(Browser::CHROME); return true; } elseif (stripos(self::$userAgentString, 'CriOS') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'CriOS')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } self::$browser->setName(Browser::CHROME); return true; } return false; } /** * Determine if the browser is Vivaldi. * * @return bool */ public static function checkBrowserVivaldi() { if (stripos(self::$userAgentString, 'Vivaldi') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'Vivaldi')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } self::$browser->setName(Browser::VIVALDI); return true; } return false; } /** * Determine if the browser is Microsoft Edge. * * @return bool */ public static function checkBrowserEdge() { if (stripos(self::$userAgentString, 'Edge') !== false) { $version = explode('Edge/', self::$userAgentString); if (isset($version[1])) { self::$browser->setVersion((float)$version[1]); } self::$browser->setName(Browser::EDGE); return true; } return false; } /** * Determine if the browser is Google Search Appliance. * * @return bool */ public static function checkBrowserGsa() { if (stripos(self::$userAgentString, 'GSA') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'GSA')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } self::$browser->setName(Browser::GSA); return true; } return false; } /** * Determine if the browser is WebTv. * * @return bool */ public static function checkBrowserWebTv() { if (stripos(self::$userAgentString, 'webtv') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'webtv')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } self::$browser->setName(Browser::WEBTV); return true; } return false; } /** * Determine if the browser is NetPositive. * * @return bool */ public static function checkBrowserNetPositive() { if (stripos(self::$userAgentString, 'NetPositive') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'NetPositive')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0])); } self::$browser->setName(Browser::NETPOSITIVE); return true; } return false; } /** * Determine if the browser is Galeon. * * @return bool */ public static function checkBrowserGaleon() { if (stripos(self::$userAgentString, 'galeon') !== false) { $aresult = explode(' ', stristr(self::$userAgentString, 'galeon')); $aversion = explode('/', $aresult[0]); if (isset($aversion[1])) { self::$browser->setVersion($aversion[1]); } self::$browser->setName(Browser::GALEON); return true; } return false; } /** * Determine if the browser is Konqueror. * * @return bool */ public static function checkBrowserKonqueror() { if (stripos(self::$userAgentString, 'Konqueror') !== false) { $aresult = explode(' ', stristr(self::$userAgentString, 'Konqueror')); $aversion = explode('/', $aresult[0]); if (isset($aversion[1])) { self::$browser->setVersion($aversion[1]); } self::$browser->setName(Browser::KONQUEROR); return true; } return false; } /** * Determine if the browser is iCab. * * @return bool */ public static function checkBrowserIcab() { if (stripos(self::$userAgentString, 'icab') !== false) { $aversion = explode(' ', stristr(str_replace('/', ' ', self::$userAgentString), 'icab')); if (isset($aversion[1])) { self::$browser->setVersion($aversion[1]); } self::$browser->setName(Browser::ICAB); return true; } return false; } /** * Determine if the browser is OmniWeb. * * @return bool */ public static function checkBrowserOmniWeb() { if (stripos(self::$userAgentString, 'omniweb') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'omniweb')); $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : ''); self::$browser->setVersion($aversion[0]); self::$browser->setName(Browser::OMNIWEB); return true; } return false; } /** * Determine if the browser is Phoenix. * * @return bool */ public static function checkBrowserPhoenix() { if (stripos(self::$userAgentString, 'Phoenix') !== false) { $aversion = explode('/', stristr(self::$userAgentString, 'Phoenix')); if (isset($aversion[1])) { self::$browser->setVersion($aversion[1]); } self::$browser->setName(Browser::PHOENIX); return true; } return false; } /** * Determine if the browser is Firebird. * * @return bool */ public static function checkBrowserFirebird() { if (stripos(self::$userAgentString, 'Firebird') !== false) { $aversion = explode('/', stristr(self::$userAgentString, 'Firebird')); if (isset($aversion[1])) { self::$browser->setVersion($aversion[1]); } self::$browser->setName(Browser::FIREBIRD); return true; } return false; } /** * Determine if the browser is Netscape Navigator 9+. * * @return bool */ public static function checkBrowserNetscapeNavigator9Plus() { if (stripos(self::$userAgentString, 'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i', self::$userAgentString, $matches) ) { if (isset($matches[1])) { self::$browser->setVersion($matches[1]); } self::$browser->setName(Browser::NETSCAPE_NAVIGATOR); return true; } elseif (stripos(self::$userAgentString, 'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i', self::$userAgentString, $matches) ) { if (isset($matches[1])) { self::$browser->setVersion($matches[1]); } self::$browser->setName(Browser::NETSCAPE_NAVIGATOR); return true; } return false; } /** * Determine if the browser is Shiretoko. * * @return bool */ public static function checkBrowserShiretoko() { if (stripos(self::$userAgentString, 'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i', self::$userAgentString, $matches) ) { if (isset($matches[1])) { self::$browser->setVersion($matches[1]); } self::$browser->setName(Browser::SHIRETOKO); return true; } return false; } /** * Determine if the browser is Ice Cat. * * @return bool */ public static function checkBrowserIceCat() { if (stripos(self::$userAgentString, 'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i', self::$userAgentString, $matches) ) { if (isset($matches[1])) { self::$browser->setVersion($matches[1]); } self::$browser->setName(Browser::ICECAT); return true; } return false; } /** * Determine if the browser is Nokia. * * @return bool */ public static function checkBrowserNokia() { if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", self::$userAgentString, $matches)) { self::$browser->setVersion($matches[2]); if (stripos(self::$userAgentString, 'Series60') !== false || strpos(self::$userAgentString, 'S60') !== false ) { self::$browser->setName(Browser::NOKIA_S60); } else { self::$browser->setName(Browser::NOKIA); } return true; } return false; } /** * Determine if the browser is Firefox. * * @return bool */ public static function checkBrowserFirefox() { if (stripos(self::$userAgentString, 'safari') === false) { if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", self::$userAgentString, $matches)) { if (isset($matches[1])) { self::$browser->setVersion($matches[1]); } self::$browser->setName(Browser::FIREFOX); return true; } elseif (preg_match('/Firefox$/i', self::$userAgentString, $matches)) { self::$browser->setVersion(''); self::$browser->setName(Browser::FIREFOX); return true; } } return false; } /** * Determine if the browser is SeaMonkey. * * @return bool */ public static function checkBrowserSeaMonkey() { if (stripos(self::$userAgentString, 'safari') === false) { if (preg_match("/SeaMonkey[\/ \(]([^ ;\)]+)/i", self::$userAgentString, $matches)) { if (isset($matches[1])) { self::$browser->setVersion($matches[1]); } self::$browser->setName(Browser::SEAMONKEY); return true; } elseif (preg_match('/SeaMonkey$/i', self::$userAgentString, $matches)) { self::$browser->setVersion(''); self::$browser->setName(Browser::SEAMONKEY); return true; } } return false; } /** * Determine if the browser is Iceweasel. * * @return bool */ public static function checkBrowserIceweasel() { if (stripos(self::$userAgentString, 'Iceweasel') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'Iceweasel')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } self::$browser->setName(Browser::ICEWEASEL); return true; } return false; } /** * Determine if the browser is Mozilla. * * @return bool */ public static function checkBrowserMozilla() { if (stripos(self::$userAgentString, 'mozilla') !== false && preg_match('/rv:[0-9].[0-9][a-b]?/i', self::$userAgentString) && stripos(self::$userAgentString, 'netscape') === false ) { $aversion = explode(' ', stristr(self::$userAgentString, 'rv:')); preg_match('/rv:[0-9].[0-9][a-b]?/i', self::$userAgentString, $aversion); self::$browser->setVersion(str_replace('rv:', '', $aversion[0])); self::$browser->setName(Browser::MOZILLA); return true; } elseif (stripos(self::$userAgentString, 'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i', self::$userAgentString) && stripos(self::$userAgentString, 'netscape') === false ) { $aversion = explode('', stristr(self::$userAgentString, 'rv:')); self::$browser->setVersion(str_replace('rv:', '', $aversion[0])); self::$browser->setName(Browser::MOZILLA); return true; } elseif (stripos(self::$userAgentString, 'mozilla') !== false && preg_match('/mozilla\/([^ ]*)/i', self::$userAgentString, $matches) && stripos(self::$userAgentString, 'netscape') === false ) { if (isset($matches[1])) { self::$browser->setVersion($matches[1]); } self::$browser->setName(Browser::MOZILLA); return true; } return false; } /** * Determine if the browser is Lynx. * * @return bool */ public static function checkBrowserLynx() { if (stripos(self::$userAgentString, 'lynx') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'Lynx')); $aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : '')); self::$browser->setVersion($aversion[0]); self::$browser->setName(Browser::LYNX); return true; } return false; } /** * Determine if the browser is Amaya. * * @return bool */ public static function checkBrowserAmaya() { if (stripos(self::$userAgentString, 'amaya') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'Amaya')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } self::$browser->setName(Browser::AMAYA); return true; } return false; } /** * Determine if the browser is Safari. * * @return bool */ public static function checkBrowserWkhtmltopdf() { if (stripos(self::$userAgentString, 'wkhtmltopdf') !== false) { self::$browser->setName(Browser::WKHTMLTOPDF); return true; } return false; } /** * Determine if the browser is Safari. * * @return bool */ public static function checkBrowserSafari() { if (stripos(self::$userAgentString, 'Safari') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'Version')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } else { self::$browser->setVersion(Browser::VERSION_UNKNOWN); } self::$browser->setName(Browser::SAFARI); return true; } return false; } /** * Determine if the browser is Yandex. * * @return bool */ public static function checkBrowserYandex() { if (stripos(self::$userAgentString, 'YaBrowser') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'YaBrowser')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } self::$browser->setName(Browser::YANDEX); return true; } return false; } /** * Determine if the browser is Comodo Dragon / Ice Dragon / Chromodo. * * @return bool */ public static function checkBrowserDragon() { if (stripos(self::$userAgentString, 'Dragon') !== false) { $aresult = explode('/', stristr(self::$userAgentString, 'Dragon')); if (isset($aresult[1])) { $aversion = explode(' ', $aresult[1]); self::$browser->setVersion($aversion[0]); } self::$browser->setName(Browser::DRAGON); return true; } return false; } /** * Determine if the browser is Android. * * @return bool */ public static function checkBrowserAndroid() { // Navigator if (stripos(self::$userAgentString, 'Android') !== false) { if (preg_match('/Version\/([\d\.]*)/i', self::$userAgentString, $matches)) { if (isset($matches[1])) { self::$browser->setVersion($matches[1]); } } else { self::$browser->setVersion(Browser::VERSION_UNKNOWN); } self::$browser->setName(Browser::NAVIGATOR); return true; } return false; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/Os.php
inc/modules/statistics/phpbrowserdetector/Os.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; /** * OS Detection. */ class Os { const UNKNOWN = 'unknown'; const OSX = 'OS X'; const IOS = 'iOS'; const SYMBOS = 'SymbOS'; const WINDOWS = 'Windows'; const ANDROID = 'Android'; const LINUX = 'Linux'; const NOKIA = 'Nokia'; const BLACKBERRY = 'BlackBerry'; const FREEBSD = 'FreeBSD'; const OPENBSD = 'OpenBSD'; const NETBSD = 'NetBSD'; const OPENSOLARIS = 'OpenSolaris'; const SUNOS = 'SunOS'; const OS2 = 'OS2'; const BEOS = 'BeOS'; const WINDOWS_PHONE = 'Windows Phone'; const CHROME_OS = 'Chrome OS'; const VERSION_UNKNOWN = 'unknown'; /** * @var string */ private $name; /** * @var string */ private $version; /** * @var bool */ private $isMobile = false; /** * @var UserAgent */ private $userAgent; /** * @param null|string|UserAgent $userAgent * * @throws \Inc\Modules\Statistics\PHPBrowserDetector\InvalidArgumentException */ public function __construct($userAgent = null) { if ($userAgent instanceof UserAgent) { $this->setUserAgent($userAgent); } elseif (null === $userAgent || is_string($userAgent)) { $this->setUserAgent(new UserAgent($userAgent)); } else { throw new InvalidArgumentException(); } } /** * Return the name of the OS. * * @return string */ public function getName() { if (!isset($this->name)) { OsDetector::detect($this, $this->getUserAgent()); } return $this->name; } /** * Set the name of the OS. * * @param string $name * * @return $this */ public function setName($name) { $this->name = (string)$name; return $this; } /** * Return the version of the OS. * * @return string */ public function getVersion() { if (isset($this->version)) { return (string)$this->version; } else { OsDetector::detect($this, $this->getUserAgent()); return (string)$this->version; } } /** * Set the version of the OS. * * @param string $version * * @return $this */ public function setVersion($version) { $this->version = (string)$version; return $this; } /** * Is the browser from a mobile device? * * @return bool */ public function getIsMobile() { if (!isset($this->name)) { OsDetector::detect($this, $this->getUserAgent()); } return $this->isMobile; } /** * @return bool */ public function isMobile() { return $this->getIsMobile(); } /** * Set the Browser to be mobile. * * @param bool $isMobile */ public function setIsMobile($isMobile = true) { $this->isMobile = (bool)$isMobile; } /** * @param UserAgent $userAgent * * @return $this */ public function setUserAgent(UserAgent $userAgent) { $this->userAgent = $userAgent; return $this; } /** * @return UserAgent */ public function getUserAgent() { return $this->userAgent; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/Browser.php
inc/modules/statistics/phpbrowserdetector/Browser.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; /** * Browser Detection. */ class Browser { const UNKNOWN = 'unknown'; const VIVALDI = 'Vivaldi'; const OPERA = 'Opera'; const OPERA_MINI = 'Opera Mini'; const WEBTV = 'WebTV'; const IE = 'Internet Explorer'; const POCKET_IE = 'Pocket Internet Explorer'; const KONQUEROR = 'Konqueror'; const ICAB = 'iCab'; const OMNIWEB = 'OmniWeb'; const FIREBIRD = 'Firebird'; const FIREFOX = 'Firefox'; const SEAMONKEY = 'SeaMonkey'; const ICEWEASEL = 'Iceweasel'; const SHIRETOKO = 'Shiretoko'; const MOZILLA = 'Mozilla'; const AMAYA = 'Amaya'; const LYNX = 'Lynx'; const WKHTMLTOPDF = 'wkhtmltopdf'; const SAFARI = 'Safari'; const SAMSUNG_BROWSER = 'SamsungBrowser'; const CHROME = 'Chrome'; const NAVIGATOR = 'Navigator'; const GOOGLEBOT = 'GoogleBot'; const SLURP = 'Yahoo! Slurp'; const W3CVALIDATOR = 'W3C Validator'; const BLACKBERRY = 'BlackBerry'; const ICECAT = 'IceCat'; const NOKIA_S60 = 'Nokia S60 OSS Browser'; const NOKIA = 'Nokia Browser'; const MSN = 'MSN Browser'; const MSNBOT = 'MSN Bot'; const NETSCAPE_NAVIGATOR = 'Netscape Navigator'; const GALEON = 'Galeon'; const NETPOSITIVE = 'NetPositive'; const PHOENIX = 'Phoenix'; const GSA = 'Google Search Appliance'; const YANDEX = 'Yandex'; const EDGE = 'Edge'; const DRAGON = 'Dragon'; const VERSION_UNKNOWN = 'unknown'; /** * @var UserAgent */ private $userAgent; /** * @var string */ private $name; /** * @var string */ private $version; /** * @var bool */ private $isRobot = false; /** * @var bool */ private $isChromeFrame = false; /** * @var bool */ private $isFacebookWebView = false; /** * @var bool */ private $isCompatibilityMode = false; /** * @param null|string|UserAgent $userAgent * * @throws \Inc\Modules\Statistics\PHPBrowserDetector\InvalidArgumentException */ public function __construct($userAgent = null) { if ($userAgent instanceof UserAgent) { $this->setUserAgent($userAgent); } elseif (null === $userAgent || is_string($userAgent)) { $this->setUserAgent(new UserAgent($userAgent)); } else { throw new InvalidArgumentException(); } } /** * Set the name of the OS. * * @param string $name * * @return $this */ public function setName($name) { $this->name = (string)$name; return $this; } /** * Return the name of the Browser. * * @return string */ public function getName() { if (!isset($this->name)) { BrowserDetector::detect($this, $this->getUserAgent()); } return $this->name; } /** * Check to see if the specific browser is valid. * * @param string $name * * @return bool */ public function isBrowser($name) { return (0 == strcasecmp($this->getName(), trim($name))); } /** * Set the version of the browser. * * @param string $version * * @return $this */ public function setVersion($version) { $this->version = (string)$version; return $this; } /** * The version of the browser. * * @return string */ public function getVersion() { if (!isset($this->name)) { BrowserDetector::detect($this, $this->getUserAgent()); } return (string) $this->version; } /** * Set the Browser to be a robot. * * @param bool $isRobot * * @return $this */ public function setIsRobot($isRobot) { $this->isRobot = (bool)$isRobot; return $this; } /** * Is the browser from a robot (ex Slurp,GoogleBot)? * * @return bool */ public function getIsRobot() { if (!isset($this->name)) { BrowserDetector::detect($this, $this->getUserAgent()); } return $this->isRobot; } /** * @return bool */ public function isRobot() { return $this->getIsRobot(); } /** * @param bool $isChromeFrame * * @return $this */ public function setIsChromeFrame($isChromeFrame) { $this->isChromeFrame = (bool)$isChromeFrame; return $this; } /** * Used to determine if the browser is actually "chromeframe". * * @return bool */ public function getIsChromeFrame() { if (!isset($this->name)) { BrowserDetector::detect($this, $this->getUserAgent()); } return $this->isChromeFrame; } /** * @return bool */ public function isChromeFrame() { return $this->getIsChromeFrame(); } /** * @param bool $isFacebookWebView * * @return $this */ public function setIsFacebookWebView($isFacebookWebView) { $this->isFacebookWebView = (bool) $isFacebookWebView; return $this; } /** * Used to determine if the browser is actually "facebook". * * @return bool */ public function getIsFacebookWebView() { if (!isset($this->name)) { BrowserDetector::detect($this, $this->getUserAgent()); } return $this->isFacebookWebView; } /** * @return bool */ public function isFacebookWebView() { return $this->getIsFacebookWebView(); } /** * @param UserAgent $userAgent * * @return $this */ public function setUserAgent(UserAgent $userAgent) { $this->userAgent = $userAgent; return $this; } /** * @return UserAgent */ public function getUserAgent() { return $this->userAgent; } /** * @param bool * * @return $this */ public function setIsCompatibilityMode($isCompatibilityMode) { $this->isCompatibilityMode = $isCompatibilityMode; return $this; } /** * @return bool */ public function isCompatibilityMode() { return $this->isCompatibilityMode; } /** * Render pages outside of IE's compatibility mode. */ public function endCompatibilityMode() { header('X-UA-Compatible: IE=edge'); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/Device.php
inc/modules/statistics/phpbrowserdetector/Device.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; class Device { const UNKNOWN = 'unknown'; const IPAD = 'iPad'; const IPHONE = 'iPhone'; const WINDOWS_PHONE = 'Windows Phone'; /** * @var string */ private $name; /** * @var UserAgent */ private $userAgent; /** * @param null|string|UserAgent $userAgent * * @throws \Inc\Modules\Statistics\PHPBrowserDetector\InvalidArgumentException */ public function __construct($userAgent = null) { if ($userAgent instanceof UserAgent) { $this->setUserAgent($userAgent); } elseif (null === $userAgent || is_string($userAgent)) { $this->setUserAgent(new UserAgent($userAgent)); } else { throw new InvalidArgumentException(); } } /** * @param UserAgent $userAgent * * @return $this */ public function setUserAgent(UserAgent $userAgent) { $this->userAgent = $userAgent; return $this; } /** * @return UserAgent */ public function getUserAgent() { return $this->userAgent; } /** * @return string */ public function getName() { if (!isset($this->name)) { DeviceDetector::detect($this, $this->getUserAgent()); } return $this->name; } /** * @param string $name * * @return $this */ public function setName($name) { $this->name = (string)$name; return $this; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/LanguageDetector.php
inc/modules/statistics/phpbrowserdetector/LanguageDetector.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; class LanguageDetector implements DetectorInterface { /** * Detect a user's languages and order them by priority. * * @param Language $language * @param AcceptLanguage $acceptLanguage * * @return null */ public static function detect(Language $language, AcceptLanguage $acceptLanguage) { $acceptLanguageString = $acceptLanguage->getAcceptLanguageString(); $languages = array(); $language->setLanguages($languages); if (!empty($acceptLanguageString)) { $httpLanguages = preg_split( '/q=([\d\.]*)/', $acceptLanguageString, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); $key = 0; foreach (array_reverse($httpLanguages) as $value) { $value = trim($value, ',; .'); if (is_numeric($value)) { $key = $value; } else { $languages[$key] = explode(',', $value); } } krsort($languages); foreach ($languages as $value) { $language->setLanguages(array_merge($language->getLanguages(), $value)); } } } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/UserAgent.php
inc/modules/statistics/phpbrowserdetector/UserAgent.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; class UserAgent { /** * @var string */ private $userAgentString; /** * @param string $userAgentString */ public function __construct($userAgentString = null) { if (null !== $userAgentString) { $this->setUserAgentString($userAgentString); } } /** * @param string $userAgentString * * @return $this */ public function setUserAgentString($userAgentString) { $this->userAgentString = (string)$userAgentString; return $this; } /** * @return string */ public function getUserAgentString() { if (null === $this->userAgentString) { $this->createUserAgentString(); } return $this->userAgentString; } /** * @return string */ public function createUserAgentString() { $userAgentString = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; $this->setUserAgentString($userAgentString); return $userAgentString; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/AcceptLanguage.php
inc/modules/statistics/phpbrowserdetector/AcceptLanguage.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; class AcceptLanguage { /** * @var string */ private $acceptLanguageString; /** * @param string $acceptLanguageString */ public function __construct($acceptLanguageString = null) { if (null !== $acceptLanguageString) { $this->setAcceptLanguageString($acceptLanguageString); } } /** * @param string $acceptLanguageString * * @return $this */ public function setAcceptLanguageString($acceptLanguageString) { $this->acceptLanguageString = $acceptLanguageString; return $this; } /** * @return string */ public function getAcceptLanguageString() { if (null === $this->acceptLanguageString) { $this->createAcceptLanguageString(); } return $this->acceptLanguageString; } /** * @return string */ public function createAcceptLanguageString() { $acceptLanguageString = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null; $this->setAcceptLanguageString($acceptLanguageString); return $acceptLanguageString; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/InvalidArgumentException.php
inc/modules/statistics/phpbrowserdetector/InvalidArgumentException.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; class InvalidArgumentException extends \InvalidArgumentException { }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/statistics/phpbrowserdetector/DetectorInterface.php
inc/modules/statistics/phpbrowserdetector/DetectorInterface.php
<?php namespace Inc\Modules\Statistics\PHPBrowserDetector; interface DetectorInterface { }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/blog/Admin.php
inc/modules/blog/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Blog; use Inc\Core\AdminModule; class Admin extends AdminModule { private $assign = []; public function navigation() { return [ $this->lang('manage', 'general') => 'manage', $this->lang('add_new') => 'add', $this->lang('settings') => 'settings' ]; } /** * list of posts */ public function anyManage($page = 1) { if (isset($_POST['delete'])) { if (isset($_POST['post-list']) && !empty($_POST['post-list'])) { foreach ($_POST['post-list'] as $item) { $row = $this->db('blog')->where('id', $item)->oneArray(); if ($this->db('blog')->delete($item) === 1) { if (!empty($row['cover_photo']) && file_exists(UPLOADS."/blog/".$row['cover_photo'])) { unlink(UPLOADS."/blog/".$row['cover_photo']); } $this->notify('success', $this->lang('delete_success')); } else { $this->notify('failure', $this->lang('delete_failure')); } } redirect(url([ADMIN, 'blog', 'manage'])); } } // lang if (!empty($_GET['lang'])) { $lang = $_GET['lang']; $_SESSION['blog']['last_lang'] = $lang; } elseif (!empty($_SESSION['blog']['last_lang'])) { $lang = $_SESSION['blog']['last_lang']; } else { $lang = $this->settings('settings.lang_site'); } // pagination $totalRecords = count($this->db('blog')->where('lang', $lang)->toArray()); $pagination = new \Inc\Core\Lib\Pagination($page, $totalRecords, 10, url([ADMIN, 'blog', 'manage', '%d'])); $this->assign['pagination'] = $pagination->nav(); // list $this->assign['newURL'] = url([ADMIN, 'blog', 'add']); $this->assign['postCount'] = 0; $rows = $this->db('blog') ->where('lang', $lang) ->limit($pagination->offset().', '.$pagination->getRecordsPerPage()) ->desc('published_at')->desc('created_at') ->toArray(); $this->assign['posts'] = []; if ($totalRecords) { $this->assign['postCount'] = $totalRecords; foreach ($rows as $row) { $row['editURL'] = url([ADMIN, 'blog', 'edit', $row['id']]); $row['delURL'] = url([ADMIN, 'blog', 'delete', $row['id']]); $row['viewURL'] = url(['blog', 'post', $row['slug']]); $fullname = $this->core->getUserInfo('fullname', $row['user_id'], true); $username = $this->core->getUserInfo('username', $row['user_id'], true); $row['user'] = !empty($fullname) ? $fullname.' ('.$username.')' : $username; $row['comments'] = $row['comments'] ? $this->lang('comments_on') : $this->lang('comments_off'); switch ($row['status']) { case 0: $row['type'] = $this->lang('post_sketch'); break; case 1: $row['type'] = $this->lang('post_hidden'); break; case 2: $row['type'] = $this->lang('post_published'); break; default: case 0: $row['type'] = "Unknown"; } $row['created_at'] = date("d-m-Y", $row['created_at']); $row['published_at'] = date("d-m-Y", $row['published_at']); $row = htmlspecialchars_array($row); $this->assign['posts'][] = $row; } } $this->assign['langs'] = $this->_getLanguages($lang); return $this->draw('manage.html', ['blog' => $this->assign]); } /** * add new post */ public function getAdd() { return $this->getEdit(null); } /** * edit post */ public function getEdit($id = null) { $this->assign['manageURL'] = url([ADMIN, 'blog', 'manage']); $this->assign['coverDeleteURL'] = url([ADMIN, 'blog', 'deleteCover', $id]); $this->assign['editor'] = $this->settings('settings.editor'); $this->_addHeaderFiles(); if ($id === null) { $blog = [ 'id' => null, 'title' => '', 'content' => '', 'slug' => '', 'intro' => '', 'lang' => $this->settings('settings.lang_site'), 'user_id' => $this->core->getUserInfo('id'), 'comments' => 1, 'cover_photo' => null, 'status' => 0, 'markdown' => 0, 'tags' => '', 'published_at' => time(), ]; } else { $blog = $this->db('blog')->where('id', $id)->oneArray(); } if (!empty($blog)) { $this->assign['langs'] = $this->_getLanguages($blog['lang'], 'selected'); $this->assign['form'] = htmlspecialchars_array($blog); $this->assign['form']['content'] = $this->tpl->noParse($this->assign['form']['content']); $this->assign['form']['date'] = date("Y-m-d\TH:i", $blog['published_at']); $tags_array = $this->db('blog_tags')->leftJoin('blog_tags_relationship', 'blog_tags.id = blog_tags_relationship.tag_id')->where('blog_tags_relationship.blog_id', $blog['id'])->select(['blog_tags.name'])->toArray(); $this->assign['form']['tags'] = $tags_array; $this->assign['users'] = $this->db('users')->toArray(); $this->assign['author'] = $this->core->getUserInfo('id', $blog['user_id'], true); $this->assign['title'] = ($blog['id'] === null) ? $this->lang('new_post') : $this->lang('edit_post'); return $this->draw('form.html', ['blog' => $this->assign]); } else { redirect(url([ADMIN, 'blog', 'manage'])); } } /** * Save post * * @param int $id * @return void */ public function postSave($id = null) { unset($_POST['save'], $_POST['files']); if (!empty($_POST['tags'])) { $tags = array_unique($_POST['tags']); } else { $tags = []; } unset($_POST['tags']); // redirect location if (!$id) { $location = url([ADMIN, 'blog', 'add']); } else { $location = url([ADMIN, 'blog', 'edit', $id]); } if (checkEmptyFields(['title', 'content'], $_POST)) { $this->notify('failure', $this->lang('empty_inputs', 'general')); $this->assign['form'] = htmlspecialchars_array($_POST); $this->assign['form']['content'] = $this->tpl->noParse($this->assign['form']['content']); redirect($location); } // slug if (empty($_POST['slug'])) { $_POST['slug'] = createSlug($_POST['title']); } else { $_POST['slug'] = createSlug($_POST['slug']); } // check slug and append with iterator $oldSlug = $_POST['slug']; $i = 2; if ($id === null) { $id = 0; } while ($this->db('blog')->where('slug', $_POST['slug'])->where('id', '!=', $id)->oneArray()) { $_POST['slug'] = $oldSlug.'-'.($i++); } // format conversion date $_POST['updated_at'] = strtotime(date('Y-m-d H:i:s')); $_POST['published_at'] = strtotime($_POST['published_at']); if (!isset($_POST['comments'])) { $_POST['comments'] = 0; } if (!isset($_POST['markdown'])) { $_POST['markdown'] = 0; } if (isset($_FILES['cover_photo']['tmp_name'])) { $img = new \Inc\Core\Lib\Image; if ($img->load($_FILES['cover_photo']['tmp_name'])) { if ($img->getInfos('width') > 1000) { $img->resize(1000); } elseif ($img->getInfos('width') < 600) { $img->resize(600); } $_POST['cover_photo'] = $_POST['slug'].".".$img->getInfos('type'); } } if (!$id) { // new $_POST['created_at'] = strtotime(date('Y-m-d H:i:s')); $query = $this->db('blog')->save($_POST); $location = url([ADMIN, 'blog', 'edit', $this->db()->pdo()->lastInsertId()]); } else { // edit $query = $this->db('blog')->where('id', $id)->save($_POST); } // detach tags from post if ($id) { $this->db('blog_tags_relationship')->delete('blog_id', $id); $blogId = $id; } else { $blogId = $id ? $id : $this->db()->pdo()->lastInsertId(); } // Attach or create new tag foreach ($tags as $tag) { if (preg_match("/[`~!@#$%^&*()_|+\-=?;:\'\",.<>\{\}\[\]\\\/]+/", $tag)) { continue; } $slug = createSlug($tag); if ($e = $this->db('blog_tags')->like('slug', $slug)->oneArray()) { $this->db('blog_tags_relationship')->save(['blog_id' => $blogId, 'tag_id' => $e['id']]); } else { $tagId = $this->db('blog_tags')->save(['name' => $tag, 'slug' => $slug]); $this->db('blog_tags_relationship')->save(['blog_id' => $blogId, 'tag_id' => $tagId]); } } if ($query) { if (!file_exists(UPLOADS."/blog")) { mkdir(UPLOADS."/blog", 0777, true); } if ($p = $img->getInfos('width')) { $img->save(UPLOADS."/blog/".$_POST['cover_photo']); } $this->notify('success', $this->lang('save_success')); } else { $this->notify('failure', $this->lang('save_failure')); } redirect($location); } /** * Remove post * * @param int $id * @return void */ public function getDelete($id) { if ($post = $this->db('blog')->where('id', $id)->oneArray() && $this->db('blog')->delete($id)) { if ($post['cover_photo']) { unlink(UPLOADS."/blog/".$post['cover_photo']); } $this->notify('success', $this->lang('delete_success')); } else { $this->notify('failure', $this->lang('delete_failure')); } redirect(url([ADMIN, 'blog', 'manage'])); } /** * remove post cover */ public function getDeleteCover($id) { if ($post = $this->db('blog')->where('id', $id)->oneArray()) { unlink(UPLOADS."/blog/".$post['cover_photo']); $this->db('blog')->where('id', $id)->save(['cover_photo' => null]); $this->notify('success', $this->lang('cover_deleted')); redirect(url([ADMIN, 'blog', 'edit', $id])); } } public function getSettings() { $assign = htmlspecialchars_array($this->settings('blog')); $assign['dateformats'] = [ [ 'value' => 'd-m-Y', 'name' => '01-01-2016' ], [ 'value' => 'd/m/Y', 'name' => '01/01/2016' ], [ 'value' => 'd Mx Y', 'name' => '01 '.$this->lang('janx').' 2016' ], [ 'value' => 'M d, Y', 'name' => $this->lang('jan').' 01, 2016' ], [ 'value' => 'd-m-Y H:i', 'name' => '01-01-2016 12:00' ], [ 'value' => 'd/m/Y H:i', 'name' => '01/01/2016 12:00' ], [ 'value' => 'd Mx Y, H:i', 'name' => '01 '.$this->lang('janx').' 2016, 12:00' ], ]; return $this->draw('settings.html', ['settings' => $assign]); } public function postSaveSettings() { foreach ($_POST['blog'] as $key => $val) { $this->settings('blog', $key, $val); } $this->notify('success', $this->lang('settings_saved')); redirect(url([ADMIN, 'blog', 'settings'])); } /** * image upload from WYSIWYG */ public function postEditorUpload() { header('Content-type: application/json'); $dir = UPLOADS.'/blog'; $error = null; if (!file_exists($dir)) { mkdir($dir, 0777, true); } if (isset($_FILES['file']['tmp_name'])) { $img = new \Inc\Core\Lib\Image; if ($img->load($_FILES['file']['tmp_name'])) { $imgPath = $dir.'/'.time().'.'.$img->getInfos('type'); $img->save($imgPath); echo json_encode(['status' => 'success', 'result' => url($imgPath)]); } else { $error = $this->lang('editor_upload_fail'); } if ($error) { echo json_encode(['status' => 'failure', 'result' => $error]); } } exit(); } /** * module JavaScript */ public function getJavascript() { header('Content-type: text/javascript'); echo $this->draw(MODULES.'/blog/js/admin/blog.js'); exit(); } public function getJsonTags($query = null) { header('Content-type: application/json'); if (!$query) { exit(json_encode([])); } $query = urldecode($query); $tags = $this->db('blog_tags')->like('name', $query.'%')->toArray(); if (array_search($query, array_column($tags, 'name')) === false) { $tags[] = ['id' => 0, 'slug' => createSlug($query), 'name' => $query]; } exit(json_encode($tags)); } private function _addHeaderFiles() { // WYSIWYG $this->core->addCSS(url('inc/jscripts/wysiwyg/summernote.min.css')); $this->core->addJS(url('inc/jscripts/wysiwyg/summernote.min.js')); if ($this->settings('settings.lang_admin') != 'en_english') { $this->core->addJS(url('inc/jscripts/wysiwyg/lang/'.$this->settings('settings.lang_admin').'.js')); } // HTML & MARKDOWN EDITOR $this->core->addCSS(url('/inc/jscripts/editor/markitup.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/markitup.highlight.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/sets/html/set.min.css')); $this->core->addCSS(url('/inc/jscripts/editor/sets/markdown/set.min.css')); $this->core->addJS(url('/inc/jscripts/editor/highlight.min.js')); $this->core->addJS(url('/inc/jscripts/editor/markitup.min.js')); $this->core->addJS(url('/inc/jscripts/editor/markitup.highlight.min.js')); $this->core->addJS(url('/inc/jscripts/editor/sets/html/set.min.js')); $this->core->addJS(url('/inc/jscripts/editor/sets/markdown/set.min.js')); // ARE YOU SURE? $this->core->addJS(url('inc/jscripts/are-you-sure.min.js')); // MODULE SCRIPTS $this->core->addJS(url([ADMIN, 'blog', 'javascript'])); // MODULE CSS $this->core->addCSS(url(MODULES.'/blog/css/admin/blog.css')); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/blog/Info.php
inc/modules/blog/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['blog']['module_name'], 'description' => $core->lang['blog']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.3', 'compatibility' => '1.3.*', 'icon' => 'pencil-square', 'pages' => ['Blog' => 'blog'], 'install' => function () use ($core) { $core->db()->pdo()->exec("CREATE TABLE IF NOT EXISTS `blog` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `title` TEXT NOT NULL, `slug` TEXT NOT NULL, `user_id` INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, `content` TEXT NOT NULL, `intro` TEXT DEFAULT NULL, `cover_photo` TEXT DEFAULT NULL, `status` INTEGER NOT NULL, `lang` TEXT NOT NULL, `comments` INTEGER DEFAULT 1, `markdown` INTEGER DEFAULT 0, `published_at` INTEGER DEFAULT 0, `updated_at` INTEGER NOT NULL, `created_at` INTEGER NOT NULL );"); $core->db()->pdo()->exec('CREATE TABLE "blog_tags" ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `name` TEXT, `slug` TEXT );'); $core->db()->pdo()->exec('CREATE TABLE `blog_tags_relationship` ( `blog_id` INTEGER NOT NULL REFERENCES blog(id) ON DELETE CASCADE, `tag_id` INTEGER NOT NULL REFERENCES blog_tags(id) ON DELETE CASCADE );'); $core->db()->pdo()->exec("INSERT INTO `blog` VALUES (1,'Let’s put a smile on that face','lets-put-a-smile-on-that-face',1,'<p>Every man who has lotted here over the centuries, has looked up to the light and imagined climbing to freedom. So easy, so simple! And like shipwrecked men turning to seawater foregoing uncontrollable thirst, many have died trying. And then here there can be no true despair without hope. So as I terrorize Gotham, I will feed its people hope to poison their souls. I will let them believe that they can survive so that you can watch them climbing over each other to stay in the sun. You can watch me torture an entire city. And then when you’ve truly understood the depth of your failure, we will fulfill Ra’s Al Ghul’s destiny. We will destroy Gotham. And then, when that is done, and Gotham is... ashes Then you have my permission to die.</p>','<p>You wanna know how I got these scars? My father was… a drinker, and a fiend. And one night, he goes off crazier than usual. Mommy gets the kitchen knife to defend herself. He doesn’t like that, not one bit. So, me watching he takes the knife to her, laughing while he does it.</p>','default.jpg',2,'en_english',1,0,".time().",".time().",".time().")"); $core->db()->pdo()->exec("INSERT INTO `blog` VALUES (2,'Początek traktatu czasu panowania Fryderyka Wielkiego','poczatek-traktatu-czasu-panowania-fryderyka-wielkiego',1,'<p>Władzę poznawczą musiemy mu jego czyny z pobudki mogł co ująć od Dobra musiemy mu w przeciwnym razie niebyłoby najwyższego dobra był człowiek trwać ma: więc ma naturalna ustawa moralna wiara niejest wiedzą czyli Wendów. Więc ja niejest biernym. Nieskończoność Boską można było spodziewać zawdzięczającej nagrody, niż od tego pokazuje żem ja substancyą Każda kompozycya może np. niebo jako człowiek walczyć musi być wzruszona. Ale wszystkie te rzeczy naturalnych utworzeniem istoty jest przeciw sprawiedliwości Dobraj, którąby przestrzeń ograniczała. Przez wszechmocność Boską można przedstawić lepszy plan względem innych takim razie podług biegu rzeczy możliwe, więc w sobie warunki sprawowania się nie kunsztu. Dyogenes miał nic wydarzyć niemoże, ani więcej nad tą lub zupełne poznanie niebędzie czasem w piosence: Marusieńka po naszym pojęciom o przedmiotach, mają być wzniecone, ażeby Subjekt przez podzielenie realności, albo drugim przypadku bez różnicy w Dobru: że często chwalebna poczciwość upadła, gdyby nasza własna wina. Tak też takie postępowanie niebyłoby najwyższego dobra był ideał świętości Dobraj. Kiedy więc nie było powszechne, tedyćby go czas ograniczał.</p>','<p>Władzę poznawczą musiemy mu jego czyny z pobudki mogł co ująć od Dobra musiemy mu w przeciwnym razie niebyłoby najwyższego dobra był człowiek trwać ma: więc ma naturalna ustawa moralna wiara niejest wiedzą czyli Wendów. Więc ja niejest biernym.','default2.jpg',2,'pl_polski',1,0,".time().",".time().",".time().")"); $core->db()->pdo()->exec("INSERT INTO `blog_tags` VALUES (1, 'hello world', 'hello-world'), (2, 'batflat', 'batflat'), (3, 'witaj świecie', 'witaj-swiecie')"); $core->db()->pdo()->exec("INSERT INTO `blog_tags_relationship` VALUES (1, 1), (1, 2), (2, 3), (2, 2)"); $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('blog', 'perpage', '5'), ('blog', 'disqus', ''), ('blog', 'dateformat', 'M d, Y'), ('blog', 'title', 'Blog'), ('blog', 'desc', '... Why so serious? ...'), ('blog', 'latestPostsCount', '5') "); if (!is_dir(UPLOADS."/blog")) { mkdir(UPLOADS."/blog", 0777); } copy(MODULES.'/blog/img/default.jpg', UPLOADS.'/blog/default.jpg'); copy(MODULES.'/blog/img/default.jpg', UPLOADS.'/blog/default2.jpg'); }, 'uninstall' => function () use ($core) { $core->db()->pdo()->exec("DROP TABLE `blog`"); $core->db()->pdo()->exec("DROP TABLE `blog_tags`"); $core->db()->pdo()->exec("DROP TABLE `blog_tags_relationship`"); $core->db()->pdo()->exec("DELETE FROM `settings` WHERE `module` = 'blog'"); deleteDir(UPLOADS."/blog"); } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/blog/Site.php
inc/modules/blog/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Blog; use Inc\Core\SiteModule; class Site extends SiteModule { public function init() { $slug = parseURL(); if (count($slug) == 3 && $slug[0] == 'blog' && $slug[1] == 'post') { $row = $this->db('blog')->where('status', '>=', 1)->where('published_at', '<=', time())->where('slug', $slug[2])->oneArray(); if ($row) { $this->core->loadLanguage($row['lang']); } } $this->tpl->set('latestPosts', function () { return $this->_getLatestPosts(); }); $this->tpl->set('allTags', function () { return $this->_getAllTags(); }); } public function routes() { $this->route('blog', '_importAllPosts'); $this->route('blog/(:int)', '_importAllPosts'); $this->route('blog/post/(:str)', '_importPost'); $this->route('blog/tag/(:str)', '_importTagPosts'); $this->route('blog/tag/(:str)/(:int)', '_importTagPosts'); $this->route('blog/feed/(:str)', '_generateRSS'); } public function _getLatestPosts() { $limit = $this->settings('blog.latestPostsCount'); $rows = $this->db('blog') ->leftJoin('users', 'users.id = blog.user_id') ->where('status', 2) ->where('published_at', '<=', time()) ->where('lang', $_SESSION['lang']) ->desc('published_at') ->limit($limit) ->select(['blog.id', 'blog.title', 'blog.slug', 'blog.intro', 'blog.content', 'users.username', 'users.fullname']) ->toArray(); foreach ($rows as &$row) { $this->filterRecord($row); } return $rows; } public function _getAllTags() { $rows = $this->db('blog_tags') ->leftJoin('blog_tags_relationship', 'blog_tags.id = blog_tags_relationship.tag_id') ->leftJoin('blog', 'blog.id = blog_tags_relationship.blog_id') ->where('blog.status', 2) ->where('blog.lang', $_SESSION['lang']) ->where('blog.published_at', '<=', time()) ->select(['blog_tags.name', 'blog_tags.slug', 'count' => 'COUNT(blog_tags.name)']) ->group('blog_tags.name') ->toArray(); return $rows; } /** * get single post data */ public function _importPost($slug = null) { $assign = []; if (!empty($slug)) { if ($this->core->loginCheck()) { $row = $this->db('blog')->where('slug', $slug)->oneArray(); } else { $row = $this->db('blog')->where('status', '>=', 1)->where('published_at', '<=', time())->where('slug', $slug)->oneArray(); } if (!empty($row)) { // get dependences $row['author'] = $this->db('users')->where('id', $row['user_id'])->oneArray(); $row['author']['name'] = !empty($row['author']['fullname']) ? $row['author']['fullname'] : $row['author']['username']; $row['author']['avatar'] = url(UPLOADS.'/users/'.$row['author']['avatar']); $row['cover_url'] = url(UPLOADS.'/blog/'.$row['cover_photo']).'?'.$row['published_at']; $row['url'] = url('blog/post/'.$row['slug']); $row['disqus_identifier'] = md5($row['id'].$row['url']); // tags $row['tags'] = $this->db('blog_tags') ->leftJoin('blog_tags_relationship', 'blog_tags.id = blog_tags_relationship.tag_id') ->where('blog_tags_relationship.blog_id', $row['id']) ->toArray(); if ($row['tags']) { array_walk($row['tags'], function (&$tag) { $tag['url'] = url('blog/tag/'.$tag['slug']); }); } $this->filterRecord($row); $assign = $row; // Markdown if (intval($assign['markdown'])) { $parsedown = new \Inc\Core\Lib\Parsedown(); $assign['content'] = $parsedown->text($assign['content']); $assign['intro'] = $parsedown->text($assign['intro']); } // Admin access only if ($this->core->loginCheck()) { if ($assign['published_at'] > time()) { $assign['content'] = '<div class="alert alert-warning">'.$this->lang('post_time').'</div>'.$assign['content']; } if ($assign['status'] == 0) { $assign['content'] = '<div class="alert alert-warning">'.$this->lang('post_draft').'</div>'.$assign['content']; } } // date formatting $assign['published_at'] = (new \DateTime(date("YmdHis", $assign['published_at'])))->format($this->settings('blog.dateformat')); $keys = array_keys($this->core->lang['blog']); $vals = array_values($this->core->lang['blog']); $assign['published_at'] = str_replace($keys, $vals, strtolower($assign['published_at'])); $this->setTemplate("post.html"); $this->tpl->set('page', ['title' => $assign['title'], 'desc' => trim(mb_strimwidth(htmlspecialchars(strip_tags(preg_replace('/\{(.*?)\}/', null, $assign['content']))), 0, 155, "...", "utf-8"))]); $this->tpl->set('post', $assign); $this->tpl->set('blog', [ 'title' => $this->settings('blog.title'), 'desc' => $this->settings('blog.desc') ]); } else { return $this->core->module->pages->get404(); } } $this->core->append('<link rel="alternate" type="application/rss+xml" title="RSS" href="'.url(['blog', 'feed', $row['lang']]).'">', 'header'); $this->core->append('<meta property="og:url" content="'.url(['blog', 'post', $row['slug']]).'">', 'header'); $this->core->append('<meta property="og:type" content="article">', 'header'); $this->core->append('<meta property="og:title" content="'.$row['title'].'">', 'header'); $this->core->append('<meta property="og:description" content="'.trim(mb_strimwidth(htmlspecialchars(strip_tags(preg_replace('/\{(.*?)\}/', null, $assign['content']))), 0, 155, "...", "utf-8")).'">', 'header'); if (!empty($row['cover_photo'])) { $this->core->append('<meta property="og:image" content="'.url(UPLOADS.'/blog/'.$row['cover_photo']).'?'.$row['published_at'].'">', 'header'); } $this->core->append($this->draw('disqus.html', ['isPost' => true]), 'footer'); } /** * get array with all posts */ public function _importAllPosts($page = 1) { $page = max($page, 1); $perpage = $this->settings('blog.perpage'); $rows = $this->db('blog') ->where('status', 2) ->where('published_at', '<=', time()) ->where('lang', $_SESSION['lang']) ->limit($perpage)->offset(($page-1)*$perpage) ->desc('published_at') ->toArray(); $assign = [ 'title' => $this->settings('blog.title'), 'desc' => $this->settings('blog.desc'), 'posts' => [] ]; foreach ($rows as $row) { // get dependences $row['author'] = $this->db('users')->where('id', $row['user_id'])->oneArray(); $row['author']['name'] = !empty($row['author']['fullname']) ? $row['author']['fullname'] : $row['author']['username']; $row['cover_url'] = url(UPLOADS.'/blog/'.$row['cover_photo']).'?'.$row['published_at']; // tags $row['tags'] = $this->db('blog_tags') ->leftJoin('blog_tags_relationship', 'blog_tags.id = blog_tags_relationship.tag_id') ->where('blog_tags_relationship.blog_id', $row['id']) ->toArray(); if ($row['tags']) { array_walk($row['tags'], function (&$tag) { $tag['url'] = url('blog/tag/'.$tag['slug']); }); } // date formatting $row['published_at'] = (new \DateTime(date("YmdHis", $row['published_at'])))->format($this->settings('blog.dateformat')); $keys = array_keys($this->core->lang['blog']); $vals = array_values($this->core->lang['blog']); $row['published_at'] = str_replace($keys, $vals, strtolower($row['published_at'])); // generating URLs $row['url'] = url('blog/post/'.$row['slug']); $row['disqus_identifier'] = md5($row['id'].$row['url']); if (!empty($row['intro'])) { $row['content'] = $row['intro']; } if (intval($row['markdown'])) { if (!isset($parsedown)) { $parsedown = new \Inc\Core\Lib\Parsedown(); } $row['content'] = $parsedown->text($row['content']); } $this->filterRecord($row); $assign['posts'][$row['id']] = $row; } $count = $this->db('blog')->where('status', 2)->where('published_at', '<=', time())->where('lang', $_SESSION['lang'])->count(); if ($page > 1) { $prev['url'] = url('blog/'.($page-1)); $this->tpl->set('prev', $prev); } if ($page < $count/$perpage) { $next['url'] = url('blog/'.($page+1)); $this->tpl->set('next', $next); } $this->setTemplate("blog.html"); $this->tpl->set('page', ['title' => $assign['title'], 'desc' => $assign['desc']]); $this->tpl->set('blog', $assign); $this->core->append('<link rel="alternate" type="application/rss+xml" title="RSS" href="'.url(['blog', 'feed', $_SESSION['lang']]).'">', 'header'); $this->core->append($this->draw('disqus.html', ['isBlog' => true]), 'footer'); } /** * get array with all posts */ public function _importTagPosts($slug, $page = 1) { $page = max($page, 1); $perpage = $this->settings('blog.perpage'); if (!($tag = $this->db('blog_tags')->oneArray('slug', $slug))) { return $this->core->module->pages->get404(); } $rows = $this->db('blog') ->leftJoin('blog_tags_relationship', 'blog_tags_relationship.blog_id = blog.id') ->where('blog_tags_relationship.tag_id', $tag['id']) ->where('lang', $_SESSION['lang']) ->where('status', 2)->where('published_at', '<=', time()) ->limit($perpage) ->offset(($page-1)*$perpage) ->desc('published_at') ->toArray(); $assign = [ 'title' => '#'.$tag['name'], 'desc' => $this->settings('blog.desc'), 'posts' => [] ]; foreach ($rows as $row) { // get dependences $row['author'] = $this->db('users')->where('id', $row['user_id'])->oneArray(); $row['author']['name'] = !empty($row['author']['fullname']) ? $row['author']['fullname'] : $row['author']['username']; $row['cover_url'] = url(UPLOADS.'/blog/'.$row['cover_photo']).'?'.$row['published_at']; // tags $row['tags'] = $this->db('blog_tags') ->leftJoin('blog_tags_relationship', 'blog_tags.id = blog_tags_relationship.tag_id') ->where('blog_tags_relationship.blog_id', $row['id']) ->toArray(); if ($row['tags']) { array_walk($row['tags'], function (&$tag) { $tag['url'] = url('blog/tag/'.$tag['slug']); }); } // date formatting $row['published_at'] = (new \DateTime(date("YmdHis", $row['published_at'])))->format($this->settings('blog.dateformat')); $keys = array_keys($this->core->lang['blog']); $vals = array_values($this->core->lang['blog']); $row['published_at'] = str_replace($keys, $vals, strtolower($row['published_at'])); // generating URLs $row['url'] = url('blog/post/'.$row['slug']); $row['disqus_identifier'] = md5($row['id'].$row['url']); if (!empty($row['intro'])) { $row['content'] = $row['intro']; } if (intval($row['markdown'])) { if (!isset($parsedown)) { $parsedown = new \Inc\Core\Lib\Parsedown(); } $row['content'] = $parsedown->text($row['content']); } $this->filterRecord($row); $assign['posts'][$row['id']] = $row; } $count = $this->db('blog')->leftJoin('blog_tags_relationship', 'blog_tags_relationship.blog_id = blog.id')->where('status', 2)->where('lang', $_SESSION['lang'])->where('published_at', '<=', time())->where('blog_tags_relationship.tag_id', $tag['id'])->count(); if ($page > 1) { $prev['url'] = url('blog/tag/'.$slug.'/'.($page-1)); $this->tpl->set('prev', $prev); } if ($page < $count/$perpage) { $next['url'] = url('blog/tag/'.$slug.'/'.($page+1)); $this->tpl->set('next', $next); } $this->setTemplate("blog.html"); $this->tpl->set('page', ['title' => $assign['title'] , 'desc' => $assign['desc']]); $this->tpl->set('blog', $assign); $this->core->append($this->draw('disqus.html', ['isBlog' => true]), 'footer'); } public function _generateRSS($lang) { header('Content-type: application/xml'); $this->setTemplate(false); $rows = $this->db('blog') ->where('status', 2) ->where('published_at', '<=', time()) ->where('lang', $lang) ->limit(5) ->desc('published_at') ->toArray(); if (!empty($rows)) { foreach ($rows as &$row) { if (!empty($row['intro'])) { $row['content'] = $row['intro']; } $row['content'] = preg_replace('/{(.*?)}/', '', html_entity_decode(strip_tags($row['content']))); $row['url'] = url('blog/post/'.$row['slug']); $row['cover_url'] = url(UPLOADS.'/blog/'.$row['cover_photo']).'?'.$row['published_at']; $row['published_at'] = (new \DateTime(date("YmdHis", $row['published_at'])))->format('D, d M Y H:i:s O'); $this->filterRecord($row); } echo $this->draw('feed.xml', ['posts' => $rows]); } } protected function filterRecord(array &$post) { $post['title'] = htmlspecialchars($post['title']); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/contact/Admin.php
inc/modules/contact/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Contact; use Inc\Core\AdminModule; class Admin extends AdminModule { public function navigation() { return [ $this->lang('settings', 'general') => 'settings', ]; } public function getSettings() { $value = $this->settings('contact'); if (is_numeric($value['email'])) { $assign['users'] = $this->_getUsers($value['email']); $assign['email'] = null; } else { $assign['users'] = $this->_getUsers(); $assign['email'] = $value['email']; } $assign['checkbox'] = [ 'switch' => $value['checkbox.switch'], 'content' => $this->tpl->noParse($value['checkbox.content']), ]; $assign['driver'] = $value['driver']; $assign['phpmailer'] = [ 'server' => $value['phpmailer.server'], 'port' => $value['phpmailer.port'], 'username' => $value['phpmailer.username'], 'password' => $value['phpmailer.password'], 'name' => $value['phpmailer.name'], ]; return $this->draw('settings.html', ['contact' => $assign]); } public function postSave() { $update = [ 'email' => ($_POST['user'] > 0 ? $_POST['user'] : $_POST['email']), 'checkbox.switch' => $_POST['checkbox']['switch'], 'checkbox.content' => $_POST['checkbox']['content'], 'driver' => $_POST['driver'], 'phpmailer.server' => $_POST['phpmailer']['server'], 'phpmailer.port' => $_POST['phpmailer']['port'], 'phpmailer.username' => $_POST['phpmailer']['username'], 'phpmailer.password' => $_POST['phpmailer']['password'], 'phpmailer.name' => $_POST['phpmailer']['name'], ]; $errors = 0; foreach ($update as $field => $value) { if (!$this->db('settings')->where('module', 'contact')->where('field', $field)->save(['value' => $value])) { $errors++; } } if (!$errors) { $this->notify('success', $this->lang('save_success')); } else { $this->notify('failure', $this->lang('save_failure')); } redirect(url([ADMIN, 'contact', 'settings'])); } private function _getUsers($id = null) { $rows = $this->db('users')->where('role', 'admin')->toArray(); if (count($rows)) { foreach ($rows as $row) { if ($id == $row['id']) { $attr = 'selected'; } else { $attr = null; } $result[] = $row + ['attr' => $attr]; } } return $result; } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/contact/Info.php
inc/modules/contact/Info.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ return [ 'name' => $core->lang['contact']['module_name'], 'description' => $core->lang['contact']['module_desc'], 'author' => 'Sruu.pl', 'version' => '1.2', 'compatibility' => '1.3.*', 'icon' => 'envelope', 'install' => function () use ($core) { $core->db()->pdo()->exec("INSERT INTO `settings` (`module`, `field`, `value`) VALUES ('contact', 'email', 1), ('contact', 'driver', 'mail'), ('contact', 'phpmailer.server', 'smtp.example.com'), ('contact', 'phpmailer.port', '587'), ('contact', 'phpmailer.username', 'login@example.com'), ('contact', 'phpmailer.name', 'Batflat contact'), ('contact', 'phpmailer.password', 'yourpassword'), ('contact', 'checkbox.switch', '0'), ('contact', 'checkbox.content', 'I agree to the processing of personal data...')"); }, 'uninstall' => function () use ($core) { $core->db()->pdo()->exec("DELETE FROM `settings` WHERE `module` = 'contact'"); } ];
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/contact/Site.php
inc/modules/contact/Site.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Contact; use Inc\Core\SiteModule; class Site extends SiteModule { private $_headers; private $_params; private $_error = null; private $mail = []; public function init() { $this->tpl->set('contact', function () { if (isset($_POST['send-email'])) { if ($this->_initDriver()) { if ($this->_sendEmail()) { $this->notify('success', $this->lang('send_success')); } else { $this->notify('failure', $this->_error); } } else { $this->notify('failure', $this->_error); } redirect(currentURL()); } return ['form' => $this->_insertForm()]; }); } private function _insertForm() { return $this->draw('form.html', [ 'checkbox' => [ 'switch' => $this->settings('contact', 'checkbox.switch'), 'content' => $this->settings('contact', 'checkbox.content'), ] ]); } private function _initDriver() { $settings = $this->settings('contact'); $this->email['driver'] = $settings['driver']; $data = $_POST; htmlspecialchars_array($data); if ($this->_checkErrors($data)) { return false; } $this->email['subject'] = $data['subject']; $this->email['from'] = $data['from']; if ($settings['driver'] == 'mail') { $this->email['sender'] = $this->settings('settings', 'title')." <no-reply@{$_SERVER['HTTP_HOST']}>"; } elseif ($settings['driver'] == 'phpmailer' && class_exists('PHPMailer\PHPMailer\PHPMailer')) { $this->email['sender'] = [ $this->settings('contact', 'phpmailer.username'), $this->settings('contact', 'phpmailer.name'), ]; } if (!is_numeric($settings['email'])) { $this->email['to'] = $settings['email']; } else { $user = $this->db('users')->where($settings['email'])->oneArray(); $this->email['to'] = $user['email']; } $this->email['message'] = $this->draw('mail.html', ['mail' => $data]); return true; } private function _checkErrors($array) { if (!filter_var($array['from'], FILTER_VALIDATE_EMAIL)) { $this->_error = $this->lang('wrong_email'); } if (checkEmptyFields(['name', 'subject', 'from', 'message'], $array)) { $this->_error = $this->lang('empty_inputs'); } // antibot field if (!empty($array['title'])) { exit(); } if (isset($_COOKIE['MailWasSend'])) { $this->_error = $this->lang('antiflood'); } if ($this->_error) { return true; } return false; } private function _sendEmail() { if ($this->email['driver'] == 'mail') { $headers = "From: {$this->email['sender']}\n"; $headers .= "Reply-To: {$this->email['from']}\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=utf-8\n"; if (@mail($this->email['to'], '=?UTF-8?B?'.base64_encode($this->email['subject']).'?=', $this->email['message'], $headers)) { // cookies antiflood $cookieParams = session_get_cookie_params(); setcookie("MailWasSend", 'BATFLAT', time()+360, $cookieParams["path"], $cookieParams["domain"], null, true); return true; } else { $this->_error = $this->lang('send_failure'); return false; } } elseif ($this->email['driver'] == 'phpmailer') { $settings = $this->settings('contact'); try { $mail = new \PHPMailer\PHPMailer\PHPMailer(true); $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = $settings['phpmailer.server']; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = $settings['phpmailer.username']; // SMTP username $mail->Password = $settings['phpmailer.password']; // SMTP password $mail->SMTPSecure = 'TLS'; // Enable TLS encryption, `ssl` also accepted $mail->Port = $settings['phpmailer.port']; // TCP port to connect to $mail->CharSet = 'UTF-8'; $mail->Subject = $this->email['subject']; $mail->Body = $this->email['message']; $mail->addReplyTo($this->email['from']); $mail->setFrom($this->email['sender'][0], $this->email['sender'][1]); $mail->addAddress($this->email['to']); $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $mail->isHTML(true); if ($mail->send()) { $cookieParams = session_get_cookie_params(); setcookie("MailWasSend", 'BATFLAT', time()+360, $cookieParams["path"], $cookieParams["domain"], null, true); } } catch (\Exception $e) { $this->_error = $e->errorMessage(); } catch (\Exception $e) { $this->_error = $e->getMessage(); } if ($this->_error) { return false; } return true; } } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false
sruupl/batflat
https://github.com/sruupl/batflat/blob/f64373702f9589cd02d203a1cae505f6668c51c5/inc/modules/sample/Admin.php
inc/modules/sample/Admin.php
<?php /** * This file is part of Batflat ~ the lightweight, fast and easy CMS * * @author Paweł Klockiewicz <klockiewicz@sruu.pl> * @author Wojciech Król <krol@sruu.pl> * @copyright 2017 Paweł Klockiewicz, Wojciech Król <Sruu.pl> * @license https://batflat.org/license * @link https://batflat.org */ namespace Inc\Modules\Sample; use Inc\Core\AdminModule; /** * Sample admin class */ class Admin extends AdminModule { /** * Module navigation * Items of the returned array will be displayed in the administration sidebar * * @return array */ public function navigation() { return [ $this->lang('index') => 'index', ]; } /** * GET: /admin/sample/index * Subpage method of the module * * @return string */ public function getIndex() { $text = 'Hello World'; return $this->draw('index.html', ['text' => $text]); } }
php
MIT
f64373702f9589cd02d203a1cae505f6668c51c5
2026-01-05T04:56:05.555415Z
false