Skip to content

Instantly share code, notes, and snippets.

View sunnysideup's full-sized avatar
💭
developing Silverstripe Applications

Sunny Side Up sunnysideup

💭
developing Silverstripe Applications
View GitHub Profile
@sunnysideup
sunnysideup / DataObject_CMSEditor.php
Last active August 29, 2015 14:01
pseudo code for class that allows you to customise the edit form for any data model
<?php
/**
* Extend this class to create a customised one record editor
* for your model - within the framework of the
* Silverstripe CMS.
*
* In the model class you identify the preferred CMS Editor Class.
*
* In the class below, you can set up custom CMS fields, actions (buttons)
@sunnysideup
sunnysideup / gist:0eaa8af8651f0855be4b
Last active August 29, 2015 14:03
removing older versions from sitetree_versions
<?php
class Foo extends Bar {
function removePagesThatAreMoreThanOneYearOld(){
set_time_limit(600);
$dataClasses = array("SiteTree");
$allClasses = ClassInfo::subclassesFor("SiteTree");
foreach($allClasses as $class) {
$dataClasses += ClassInfo::dataClassesFor($class);
@sunnysideup
sunnysideup / gist:bd263a0aefacd4a5aa12
Last active August 29, 2015 14:14
Silverstripe jQuery javascript example
/**
* usage:
* PHP:
* Requirements::javascript("mymodules/javascript/MyJSFx.js");
* Requirements::customScript("
* var MyObject = new MyJSFx('MyForm')
* .setVar('mySelector', '.foo')
* .setVar('myMethod', function(){return "custom foo"};)
* .init();",
* "MyObjectCustomScript"
@sunnysideup
sunnysideup / gist:84a592745d100b0fa84c
Created February 23, 2015 03:44
how we change remove address
<?php
$ip = false;
if(!Session::get("MyIPAddress") || isset($_GET["ipfortestingonly"])) {
if(isset($_GET["ipfortestingonly"])) {
$ip = $_GET["ipfortestingonly"];
}
elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
@sunnysideup
sunnysideup / gist:5b9ea58d6b602ac8a3e2
Created April 2, 2015 21:23
redirection in e-commerce
<?php
class Foo {
/**
* Redirect users if found on incorrect domain
* Detects if $_GET['session'] is present, sets session
* and redirects back to "clean URL"
* Both _SECURE_URL and _STANDARD_URL must be defined,
* and include protocol (http(s)://mydomain.com) with no trailing slash
* @return null
@sunnysideup
sunnysideup / gist:b0442bf738236e7347fa
Last active August 29, 2015 14:18
Function to work out if a coupon is valid .... Returns false if the coupon is invalid and true if the coupon is valid.
<?php
function getIsValid() {
//we go through all the options that would make it invalid...
if(! $this->NumberOfTimesCouponCanBeUsed) {
return false;
}
if($this->getUseCount() > $this->NumberOfTimesCouponCanBeUsed) {
return false;
}
$now = strtotime("now");
@sunnysideup
sunnysideup / gist:96f6d8e9899cc8718266
Created April 9, 2015 08:34
resize font to fit width
/**
* Resizes page header font-size for the text to fit.
* basically we add a hidden span into the header,
* put the text into it and then keep reducing the super large font-size
* for as long as the height of the span exceeds the super
* tall line-height set for the test (indicating there is more than one line needed
* to show the text).
*/
setPageHeaderFontSize: function() {
<?php
class MyFancyPage extends Page {
private static $singular_name = "My Fancy Page";
function i18n_singular_name() { return self::$singular_name;}
private static $plural_name = "My Fancy Pages";
function i18n_plural_name() { return self::$plural_name;}
}
@sunnysideup
sunnysideup / ReplacementDataExample.php
Created October 12, 2015 00:26
ReplacementDataExample.php
<?php
class ReplacementData {
//...
private function getData($to) {
//...
$array = array();
@sunnysideup
sunnysideup / MyObject.php
Last active February 25, 2016 22:43
find or create
<?php
class MyObject extends DataObject {
/**
* finds or creates a MyObject based the value for MyObject.SomethingElse
*
* @param string $code
* @return MyObject
*/