Skip to content

Instantly share code, notes, and snippets.

View smichaelsen's full-sized avatar
🥋
Changing the world in code

Sebastian Michaelsen smichaelsen

🥋
Changing the world in code
View GitHub Profile
@smichaelsen
smichaelsen / gist:3904298
Created October 17, 2012 07:59
Define a tolerance value for the pagebrowser. If the last page would have less or equal items than the tolerance value, the last page will be merged with the previous page. The user shouldn't have to use the pagebrowser to display 1 more item.
# calculate totalPages
$pagebrowser{'totalPages'} = int($pagebrowser{'itemsCount'} / $pagebrowser{'itemsPerPage'}) + 1;
my $leap = ($pagebrowser{'itemsCount'} % $pagebrowser{'itemsPerPage'});
if ($pagebrowser{'totalPages'} > 1 && ($leap <= $pagebrowser{'tolerance'})) { # tolerance mode
$pagebrowser{'totalPages'}--;
}
# validate currentPage & calculate offset
if ($pagebrowser{'currentPage'} > $pagebrowser{'totalPages'}) { # currentPage is higher than allowed
$pagebrowser{'currentPage'} = $pagebrowser{'totalPages'};
@smichaelsen
smichaelsen / levelFieldCondition.php
Created November 2, 2012 14:02
Typoscript Condition that checks field up in rootline
<?php
/**
* Usage example: [userFunc = levelFieldCondition(layout=1)]
*
* @param string $assumption
* @return bool
*/
function levelFieldCondition($assumption) {
list($fieldname, $value) = t3lib_div::trimExplode('=', $assumption);
@smichaelsen
smichaelsen / ShowHiddenElements.php
Created November 15, 2012 14:25
Show hidden records with Typoscript
<?php
class Tx_MyExt_UserFunction_ShowHiddenElements {
/**
* Usage:
*
* lib.hiddenrecords = COA
* lib.hiddenrecords {
* 10 = USER
@smichaelsen
smichaelsen / BeCobj.php
Created November 27, 2012 10:16
cObject in Backend
<?php
define('PATH_tslib', PATH_site . 'typo3/sysext/cms/tslib/');
class Tx_MyExt_Utility_BeCobj {
/**
* @var tslib_fe
*/
protected static $tsfe;
@smichaelsen
smichaelsen / VersionedTypo3DbBackend.php
Created December 6, 2012 11:41
Extbase Storage Backend that writes the changes to sys_history and sys_log
<?php
class Tx_OrderTracker_Persistence_Storage_VersionedTypo3DbBackend extends Tx_Extbase_Persistence_Storage_Typo3DbBackend {
/**
* @var t3lib_TCEmain
* @inject
*/
protected $tcemain;
# This snippet is made to reprodue the following bug:
# http://forge.typo3.org/issues/44879
lib.blockquoteoutput = TEXT
lib.blockquoteoutput {
value = Never trust quotes on the internet, they might be fake. - Abraham Lincoln
stdWrap.wrap = <blockquote class="myclass">|</blockquote>
parseFunc < lib.parseFunc_RTE
}
<?
class MyClass {
/**
* @publicCallDeprecated Since 6.1. Will be protected 2 versions later
*/
public function doStuff() {
\TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedPublicMethodCall();
// do stuff
@smichaelsen
smichaelsen / gist:4706112
Created February 4, 2013 10:51
String concatenation done right
/* PHP: dot */
$name = 'Sebastian ' . $lastname;
/* JS: plus */
var name = 'Sebastian ' + lastname;
/* CSS: whitespace */
content: 'Sebastian ' attr(lastname)
@smichaelsen
smichaelsen / GroupedForViewHelper.php
Last active December 13, 2015 23:59
Enhanced GroupedForViewHelper
<?php
/**
* Extends the Fluid GroupedByViewHelper with two features:
* - support to group by a DateTime property
* - new attribute "order", to sort the resulting groups
*/
class Tx_MyExt_ViewHelpers_GroupedForViewHelper extends Tx_Fluid_ViewHelpers_GroupedForViewHelper {
/**
@smichaelsen
smichaelsen / Versionsverwaltung für TYPO3-Extensions.md
Last active December 16, 2015 01:09
Versionsverwaltung für TYPO3-Extensions

Versionsverwaltung für TYPO3-Extensions

TYPO3-Extensions die bei mir zur Programmierung in Auftrag gegeben werden, werden mit git versioniert, wobei Github als Hosting-Plattform zum Einsatz kommt.

Warum Versionsverwaltung?

Ein Versionsverwaltungssystem wie git bringt verschiedene Vorteile. Einige davon sind:

  • Nachvollziehbarkeit von Änderungen für Entwickler
  • Bessere Möglichkeit der Zusammenarbeit
  • Schutz vor Datenverlust