Skip to content

Instantly share code, notes, and snippets.

View ChVuagniaux's full-sized avatar

Christophe Vuagniaux ChVuagniaux

View GitHub Profile
@ChVuagniaux
ChVuagniaux / k2helper.php
Created December 19, 2016 08:40
Joomla - K2 extrafield formating helper
<?php
class K2Helper
{
/**
* Convert K2 extra fields to an object
*
* Selectable extra fields ever return values inside an array
* same if only one value is selected
*

Keybase proof

I hereby claim:

  • I am ChVuagniaux on github.
  • I am chvuagniaux (https://keybase.io/chvuagniaux) on keybase.
  • I have a public key whose fingerprint is 7475 D4C9 3F61 946A 4046 24E3 5567 8CE8 E56B 1DD7

To claim this, I am signing this object:

@ChVuagniaux
ChVuagniaux / strHelper.php
Last active April 25, 2017 14:37
Cut HTML strings without breaking words and markup
<?php
/**
* Cut HTML string before a max number of X chars without cutting a words or breaking the HTML markup.
*
* Try to cut after a </p> tag after 2/3 of the max length (for avoid to display only the first paraph) and if
* this fail Cut after the position of the last char of the last word just before the max length and add '...'
* at the end of the string
*
* usage : StrHelper::splitHtmlString($html, 1000); // For get a string that will never be bigger than 1000 chars
*
@ChVuagniaux
ChVuagniaux / oc-blog-pagination.htm
Created November 23, 2017 08:28
OctoberCMS blog pagination that use "/post" instead of "/posts/1"
{% if posts.lastPage > 1 %}
<ul class="pagination">
{% if posts.currentPage > 1 %}
{% if (posts.currentPage == 2) %}
<li><a href="{{ listPage|page({ (pageParam): null }) }}">&larr; </a></li>
{% else %}
<li><a href="{{ listPage|page({ (pageParam): (posts.currentPage - 1) }) }}">&larr; </a></li>
{% endif %}
{% endif %}
@ChVuagniaux
ChVuagniaux / _relation_render.htm
Created November 28, 2017 14:36
Generic relation render for OctoberCMS forms
<?= $this->relationRender($field->fieldName, ['readOnly' => $formContext == 'preview']) ?>
@ChVuagniaux
ChVuagniaux / AjaxButton.vue
Last active January 17, 2018 12:38
VueJS code for make buttons that do Ajax Calls
<template>
<button v-on:click="click">
<slot></slot>
</button>
</template>
<script>
export default {
props: {
'url': {type: String},
@ChVuagniaux
ChVuagniaux / csv-download.php
Last active March 9, 2018 07:53
CSV export for Excel
<?php
use League\Csv\Writer;
use League\Csv\AbstractCsv;
$csv = Writer::createFromFileObject(new \SplTempFileObject());
$csv->setDelimiter(';');
$csv->setOutputBOM(AbstractCsv::BOM_UTF8); // compatibility with Excel
$csv->insertOne(['1', 'é', 'à']);
<?php
/**
* This script convert a model using
* \October\Rain\Database\Traits\SimpleTree to
* \October\Rain\Database\Traits\NestedTree
*
* Before run create required fields in your DB for NestedTree
* ( https://octobercms.com/docs/database/traits#nested-tree )
*/
@ChVuagniaux
ChVuagniaux / horizon-supervisor.sh
Created February 7, 2018 08:58
Run Horizon with cron
#!/bin/bash
# Start horizon supervisord if not already started
if pgrep -f 'php /var/www/artisan horizon'; then
echo "Horizon already run"
else
@ChVuagniaux
ChVuagniaux / .env.example
Created April 16, 2018 19:33 — forked from LukeTowers/.0 - cheatsheet.sh
Introduction to OctoberCMS
APP_DEBUG=true
APP_URL=http://example.local
APP_KEY=
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=website-oc-example-LOCAL
DB_USERNAME=homestead
DB_PASSWORD=secret