Skip to content

Instantly share code, notes, and snippets.

View vojtasvoboda's full-sized avatar
🏠
Working from home

Vojta Svoboda vojtasvoboda

🏠
Working from home
View GitHub Profile
@vojtasvoboda
vojtasvoboda / .travis.yml
Last active February 22, 2016 09:41
OctoberCMS Travis config file
language: php
php:
- 5.5
- 5.6
- 7.0
- hhvm
matrix:
allow_failures:
@vojtasvoboda
vojtasvoboda / Plugin.php
Created January 6, 2016 14:01
Add new Sitemap type in OctoberCMS
<?php
public function boot()
{
// Add RainLab.Blog articles to sitemap
Event::listen('pages.menuitem.listTypes', function() {
return [
'blog-post' => 'Blog post',
'all-blog-posts' => 'All blog posts'
];
@vojtasvoboda
vojtasvoboda / Plugin.php
Last active July 28, 2022 15:49
Extend backend form in OctoberCMS
<?php
public function boot()
{
// Extend all backend form usage
Event::listen('backend.form.extendFields', function($widget) {
// Only for the Posts controller
if (!$widget->getController() instanceof \RainLab\Blog\Controllers\Posts)
return;
@vojtasvoboda
vojtasvoboda / Plugin.php
Created January 4, 2016 10:45
Listen on Eloquent events in OctoberCMS
<?php
// ...
public function boot()
{
// Event Listeners for RainLab Blog
Event::listen('eloquent.created: RainLab\Blog\Models\Post', function($model) {
// ... do something
});
@vojtasvoboda
vojtasvoboda / composer.json
Created January 4, 2016 10:41
composer.json example in OctoberCMS
{
"name": "rainlab/googleanalytics",
"type": "october-plugin",
"description": "Google Analytics integration plugin for OctoberCMS",
"homepage": "http://octobercms.com",
"keywords": ["october", "cms", "rainlab", "google", "analytics"],
"authors": [
{
"name": "Alexey Bobkov",
"email": "[email protected]"
@vojtasvoboda
vojtasvoboda / AnyClass.php
Created January 4, 2016 10:41
Is plugin active condition in OctoberCMS
<?php
use System\Classes\PluginManager;
protected function isPluginActive($pluginName)
{
$pluginManager = PluginManager::instance();
return array_key_exists($pluginName, $pluginManager->getPlugins());
}
@vojtasvoboda
vojtasvoboda / Plugin.php
Created January 4, 2016 10:40
Extending YAML and model class in OctoberCMS
<?php
// ...
public function boot()
{
UserModel::extend(function($model) {
$model->addFillable([
'phone',
'mobile',
@vojtasvoboda
vojtasvoboda / .travis.yml
Created January 4, 2016 10:39
Travis YML file example in OctoberCMS
# examle taken from https://github.com/krisawzm/demomanager-plugin
language: php
php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
@vojtasvoboda
vojtasvoboda / sender.php
Created January 4, 2016 10:36
Send mail with attachments in OctoberCMS
$email = '[email protected]';
$template = 'my.plugin::mail.recordform';
$templateParameters = ['site' => 'mysite.cz'];
$attachments = [];
foreach($record->images as $image) {
$attachments[] = $image;
}
Mail::send($template, $templateParameters, function($message) use ($email, $attachments)
@vojtasvoboda
vojtasvoboda / script.php
Created January 4, 2016 10:35
Deferred binding in OctoberCMS
// INIT: session key as transfer unique identifier
$sessionKey = 'abcdefghijklmnopqrstuvwxyz';
// PART ONE: receiving files
// receive first file
$file = new System\Models\File();
$file->fromFile(base_path() . '/storage/app/media/users/12905.jpg');
$file->save();