cheatsheet
Table of Contents
Themes and Style Sheets
Get Style Sheet
$this->getStyleSheet(); Load stylesheet in header <?php echo $this->getStyleSheet('main.css')?>
Get Theme Path
$this->getThemePath(); Use to load an image from theme image directory <img src="<?=$this->getThemePath()?>/images/photo.png"> OR <?php $v = View::getInstance(); $v->getThemePath(); ?>
Set Theme Path
Use a Theme Path In a Block <?php $v = View::getInstance(); $themePath = $v->getThemePath(); ?> To display an image from your themes image directory <img src="<?php echo $themePath ?>/images/photo.png">
Working With Blocks
Add a Block Area
<?php $a = new Area('Area Name'); $a->display($c); ?>
Add an Area with Block Limit
<?php $a = new Area('Area Name'); $a->setBlockLimit(1); $a->display($c); ?>
Add an Area with wrapper
<?php $a = new Area('Area Name'); $a->setBlockWrapperStart('<div class="CLASS_NAME">'); $a->setBlockWrapperEnd('</div>'); $a->display($c); ?> <
Add Space Between Blocks In Edit Mode
<?php if ($c->isEditMode()) { ?> <div style="min-height: 20px;"> </div> <?php } ?>
Get Block Path
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $urlHelper = $app->Make('helper/concrete/urls'); $blockType = BlockType::getByHandle('heat_calculator'); $localPath = $urlHelper->getBlockTypeAssetsURL($blockType);
Add a Stack In a Page
<?php $stack = Stack::getByName('STACK_NAME'); $stack->display(); ?>
Get Stack Names (or Handles)
<?php $stm = new StackList(); $stm->filterByGlobalAreas(); // Use filterByGlobalAreas() or filterByUserAdded() $stacks = $stm->get(); foreach($stacks as $st) { print $st->getCollectionName(); // Use $st->getCollectionName(), $st->getCollectionHandle(), etc. } ?>
Get URL for Block Directory
<img src="<?php echo $this->getBlockURL() ?>/images/image.png">
Working with Pages in Blocks and Themes
Add a Page Type
<?php /* Check if page exists. */ use PageType; $pageType = PageType::getByHandle('[page_type_handle]'); /* Addd new page if does not exist. */ if(!is_object($pageType)) { $data['ctHandle'] = '[page_type_handle]'; $data['ctName'] = t('[page_type_name]'); $newPage = PageType::add($data, $pkg); } ?>
Display a Page's Parent Page Name
<?php $page=Page::getByID($c->getCollectionParentID()); echo $page->getCollectionName(); ?>
Display Top Level Parent Name
<?php $c = Page::getCurrentPage(); $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $nh = $app->Make('helper/navigation'); $cobj = $nh->getTrailToCollection($c); $rcobj = array_reverse($cobj); if(is_object($rcobj[1])) { $pID = $rcobj[1]->getCollectionID(); $page = Page::getByID($pID); echo $page->getCollectionName(); }else{ echo $c->getCollectionName(); } ?>
Link to Parent Page
<?php $parent = Page::getByID($c->getCollectionParentID()); $parentLink = $parent->getCollectionLink(); ?> <a href="<?php echo $parentLink; ?>">Up</a>
Get Current Page Object
$page = Page::getCurrentPage();
Get Date The Page Was Added/Created
<?php $c->getCollectionDateAdded('F j, Y') ?> Display date page was added. <?php echo $c->getCollectionDateAdded('F j, Y') ?>
Get Handle of Parent Page and Do Something
<?php $page=Page::getByID($c->getCollectionParentID()); if ( $page->getCollectionName() == 'es' ) { echo '<a href="/index.php/gallery">Galería</a>'; } else { echo '<a href="/index.php/gallery">Gallery</a>'; } ?>
Get a Page's Description
$c->getCollectionDescription(); Display page description <?php echo $c->getCollectionDescription() ?>
Get a Page's Handle
$c->getCollectionHandle(); Create a div for adding styles to individual pages <div id="<?php echo $c->getCollectionHandle() ?> "> </div> Add a class to a div based on page handle <div id="header" class="<?php echo $c->getCollectionHandle() ?>"> </div>
Get a Page's ID
$c->getCollectionID(); Display page ID <?php echo $c->getCollectionID() ?>
Get a Page's Name
$c->getCollectionName(); Display page name <?php echo $c->getCollectionName() ?>
Get a Page's Parent Page ID
$c->getCollectionParentID(); Display parent page page ID <?php echo $c->getCollectionParentID() ?>
Get a Pages Owner ID
$pageOwner = $c->getCollectionUserID()
Get Current Page URL
<?php $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $nh = $app->Make('helper/navigation'); $URL = $nh->getCollectionURL($c); ?>
Get a Page Type's Name
$c->getCollectionTypeName(); Set a class to a page types name. <?php if($c->getCollectionTypeName() == 'Full Width'){ echo 'class="full-width"'; } ?>
Get Site Name
<?php echo Config::get('concrete.site'); ?>
Get Page Template Handle
<?php echo $c->getPageTemplateHandle() ?>
Get Public Date/Time In Page Properties
<?php $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $dateHelper = $app->Make('helper/date'); echo $dateHelper->getSystemDateTime($c->getCollectionDatePublic(), $mask = 'l, F d, Y g:ia') ?>
Get Date Last Edited
<?php // Load Date Helper $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $date = $app->Make('helper/date'); // Get Blocks in Main area foreach($c->getBlocks('Main') as $b) { $bDate[$i] = $b->getBlockDateLastModified(); $i ++; } // Reverse Sort Date Array rsort( $bDate ); //Echo Date and Time Page last Edited echo $date->getLocalDateTime($bDate[0],$mask = 'm-d-Y g:i:s'); ?>
Embed Autonav in a Theme Page
<?php $bt = BlockType::getByHandle('autonav'); $bt->controller->displayPages = 'top'; // 'top', 'above', 'below', 'second_level', 'third_level', 'custom', 'current' $bt->controller->displayPagesCID = ''; // if display pages is set ‘custom’ $bt->controller->orderBy = 'display_asc'; // 'chrono_desc', 'chrono_asc', 'alpha_asc', 'alpha_desc', 'display_desc','display_asc' $bt->controller->displaySubPages = 'all'; //none', 'all, 'relevant_breadcrumb', 'relevant' $bt->controller->displaySubPageLevels = 'all'; // 'enough', 'enough_plus1', 'all', 'custom' $bt->controller->displaySubPageLevelsNum = ''; // if displaySubPages is set 'custom' $bt->render('view'); // for template 'templates/template_name'; ?>
Working With Page Attributes
Add a Page Attribute Programmatically
<?php namespace use \Concrete\Core\Attribute\Type as AttributeType; use CollectionAttributeKey; // add checkbox attribute $att = AttributeType::getByHandle('boolean'); $testAttribute3=CollectionAttributeKey::getByHandle('attribute_handle'); if( !is_object($testAttribute3) ) { CollectionAttributeKey::add($att, array('akHandle' => 'attribute_handle', 'akName' => t('Attribute Name'), 'akIsSearchable' => true, 'akCheckedByDefault' => true), $pkg); } ?>
Test That a Value Is Set in an Attribute
<?php if ($c->getCollectionAttributeValue(attribute_hande)) { Do Something Here; } ?>
Get a Page Attribute Value
$c->getCollectionAttributeValue() Display a page text attribute <?php echo $c->getCollectionAttributeValue('attribute_hande') ?> *In some blocks you may need to substitute with $cobj
Get an Attribute Key by Handle
$atKey = CollectionAttributeKey::getByHandle('handle');
Display An Image From Page Attribute
<img src="<?php echo ($c->getAttribute('attribute_handle')->getVersion()->getRelativePath());?>" width="120px" height="160px">
If a Page File/Image Attribute Is Set, Display Download Link
<?php if($c->getAttribute('attribute_name')) { echo '<a href="' . $c->getAttribute('attribute_handle')->getVersion()->getRelativePath() .' ">Download PDF</a>'; } ?>
Get a File/Image Atributes File Name
<?php $c->getAttribute('attribute_handle')->getFileName() ?>
Get All Page Attributes
(in view.php) <?php $atKeys = CollectionAttributeKey::getList(); foreach($atKeys as $ak) { echo $ak->akName . '<br/>'; } ?> (in controller.php) <?php namespace use View; $atKeys = CollectionAttributeKey::getList(); foreach($atKeys as $ak) { pageAttributes[] = $ak->akName; }
(in view.php) <?php $atKeys = CollectionAttributeKey::getList(); foreach($atKeys as $ak) { echo $ak->getAttributeKeyName() . '<br/>'; } ?> (in controller.php) <?php namespace use View; $atKeys = CollectionAttributeKey::getList(); foreach($atKeys as $ak) { pageAttributes[] = $ak->getAttributeKeyName(); }
Get all Attributes in a Set
(in view.php) $atSet = AttributeSet::getByHandle('attribute_set_handle'); $atKeys = $atSet->getAttributeKeys(); foreach($atKeys as $ak) { echo $ak->akName; } (in controller.php) namespace use \Concrete\Core\Attribute\Set as AttributeSet; $atSet = AttributeSet::getByHandle('attribute_set_handle'); $atKeys = $atSet->getAttributeKeys(); foreach($atKeys as $ak) { $setNmes[] = $ak->akName; }
(in view.php) $atSet = AttributeSet::getByHandle('attribute_set_handle'); $atKeys = $atSet->getAttributeKeys(); foreach($atKeys as $ak) { echo $ak->getAttributeKeyName(); } (in controller.php) namespace use \Concrete\Core\Attribute\Set as AttributeSet; $atSet = AttributeSet::getByHandle('attribute_set_handle'); $atKeys = $atSet->getAttributeKeys(); foreach($atKeys as $ak) { $setNmes[] = $ak->getAttributeKeyName(); }
Display/Get Options From a Select Attribute
<?php use CollectionAttributeKey; $ak = CollectionAttributeKey::getByHandle('attribute_handle'); if ( is_object($ak)) { $type = $ak->getAttributeType(); $controller = $type->getController(); $controller->setAttributeKey($ak); $options = $controller->getOptions(); foreach($options as $option){ print $option . '<br/>'; } } ?>
Display/Get multiple Values From a Select Page Attribute
<?php $selectedOptions = $c->getCollectionAttributeValue('attribute_handle'); if (is_object($selectedOptions)) { foreach ($selectedOptions as $opt) { echo $opt; } } ?>
Add select attribute with attribute set
<?php // add select with attribute set page attributes // Set attribute category $akCat = AttributeKeyCategory::getByHandle('collection'); $akCat->setAllowAttributeSets(AttributeKeyCategory::ASET_ALLOW_SINGLE); $akCatSet = $akCat->addSet('attribute_set_handle', t('Attribute Set Name'),$pkg); $atType = AttributeType::getByHandle('select'); // test for existing attribute $myAttribute = CollectionAttributeKey::getByHandle('attribute_handle'); // Add attribute if( !is_object($myAttribute) ) { CollectionAttributeKey::add($atType, array('akHandle' => 'attribute_hande', 'akName' => t('Attribute Name'), 'akIsSearchable' => true, 'akIsSearchableIndexed' => true, 'akSelectAllowMultipleValues' => false, 'akSelectAllowOtherValues' => false, 'akSelectOptionDisplayOrder' => 'alpha_asc', // alpha_asc or popularity_desc ),$pkg)->setAttributeSet($akCatSet); //Add option values $myAttribute = CollectionAttributeKey::getByHandle('attribute_handle'); SelectAttributeTypeOption::add( $mMakerAttribute, 'Select Option One'); SelectAttributeTypeOption::add( $mMakerAttribute, 'Select Option Two'); SelectAttributeTypeOption::add( $mMakerAttribute, 'Select Option Three'); } ?>
Render Attribute
useConcrete\Core\Attribute\Context\FrontendFormContext; use Concrete\Core\Attribute\Form\Renderer; use Concrete\Core\Attribute\Category\CategoryService; use Concrete\Core\Support\Facade\Application; use Concrete\Core\Page\Page; $app = Application::getFacadeApplication(); $service = $app->make(CategoryService::class); $categoryEntity = $service->getByHandle('collection'); $category = $categoryEntity->getController(); $attribute_key = 'exclude_nav'; $akt = $category->getByHandle($attribute_key); $renderer = new Renderer(new FrontendFormContext(), Page::getCurrentPage()); $renderer->buildView($akt)->render();
Working With Users
Get User Info
$u = new User(); $ui = $app->make(\Concrete\Core\User\UserInfoRepository::class)->getByID($u->getUserID()); $ui->getUserName() $ui->getUserEmail() $ui->getUserPublicProfileURL() $ui->getUserID() $ui->getUserDateAdded() $ui->getNumLogins() $ui->getLastLogin() $ui->getLastIPAddress() $ui->getUserTimezone() $ui->getUserBadges()
Add a User Attribute Programmatically
<?php use UserAttributeKey; //add boolean type user attribute $boolt = AttributeType::getByHandle('boolean'); $attributeHandle=UserAttributeKey::getByHandle('attribute_handle'); if( !is_object($attributeHandle) ) UserAttributeKey::add($boolt, array('akHandle' => 'atribute_handle', 'akName' => t('Attribute name'), 'akIsSearchable' => false, 'uakProfileEdit' => false, 'uakRegisterEdit' => false, 'akCheckedByDefault' => false)); } ?>
Delete User Attribute Programmatically
<?php use UserAttributeKey; $attributeHandle = UserAttributeKey::getByHandle('atribute_handle'); if( is_object($attributeHandle) ) $attributeHandle->delete(); } ?>
Get a User Attribute for Person Logged In
<?php $u = new User(); if($u->isLoggedIn()) { $ui = UserInfo::getByID($u->getUserID()); echo $ui->getAttribute('attribute_name'); } ?>
Set a User Attribute for Person Logged In
<?php $u = new user(); $ui = UserInfo::getByID($u->getUserID()); $ui->setAttribute('attributenName', 'value'); ?>
Delete a User Attribute
<?php use UserAttributeKey; $attributeKey = UserAttributeKey::getByHandle('user_attribute_name'); if( is_object($attributeKey) ) $attributeKey->delete(); ?>
Display/Get Options From a User Select Attribute
<?php use \Concrete\Core\Attribute\Type as AttributeType; use UserAttributeKey; $ak = UserAttributeKey::getByHandle('project_name'); $sa = new SelectAttributeTypeController(AttributeType::getByHandle('select')); $sa->setAttributeKey($ak); $values = $sa->getOptions(); foreach ($values as $v) { echo $v->value; } ?>
Add a User To a Group
<?php $u = new User(); $u->getByUserID($uID); $groupName = Group::getByName('Name_Of_Your_Group'); $u->enterGroup($groupName); ?>
Get All User Group Names
<?php use Group; use GroupList; $groupList = new GroupList(); $groups = $groupList->get(); foreach($groups as $g){ echo Group::getByID($g)->getGroupName(); echo '<br/>'; } ?>
Display a Users Name
<?php $u = new User(); echo $u->getUserName(); ?>
If Logged in Adjust Background Position
<?php $u = new User(); if ($u->isLoggedIn()) { ?> <style type="text/css"> body { background-position: 0px 49px; } </style> <?php } ?>
If a User is Logged In Do Something
<?php $u = new User(); if($u->isLoggedIn()) { echo 'Hello '.$u->getUserName(); } ?>
If Logged in User is Admin Do Something
<?php $u = new user(); $g = Group::getByName('Administrators'); if ($u->inGroup($g)||$u->isSuperUser()) { //do something here } ?>
Working With Files and Sets
Get Path to File
<?php $f = File::getByID(FILE_ID); $fv = $f->getApprovedVersion(); $path = $fv->getRelativePath(); ?>
]
Get File Set Names
(in view.php) <?php $fileSets = FileSet::getMySets(); foreach ($fileSets as $fs) { echo $fs->getFileSetName(); } ?> $fs->getFileSetID() $fs->getFileSetName() $fs->getFileSetType() (in controller.php <?php namespace use FileSet; use FileList; $fileSets = FileSet::getMySets(); foreach ($fileSets as $fs) { $filesets('id' => $fs->getFileSetID(), 'name' => $fs->getFileSetName()); } ?>
Add a File Set
<?php $fs = FileSet::createAndGetSet('FILESET_NAME', FileSet::TYPE_PUBLIC, $uID = false); ?>
Get File Attribute Value
Add a File Attribute
<?php // in a package use Concrete\Core\Attribute\Key\CollectionKey as CollectionAttributeKey; use \Concrete\Core\Attribute\Type as AttributeType; $attribute = CollectionAttributeKey::getByHandle('my_attribute'); if ( !is_object($attribute)) { $att = AttributeType::getByHandle('select'); // add attribute CollectionAttributeKey::add($att, array('akHandle' => 'my_attribute', 'akName' => t('My Attribute'), 'akIsSearchableIndexed' => true, 'akIsSearchable' => true, 'akSelectAllowMultipleValues' => true, 'akSelectAllowOtherValues' => true, 'akSelectOptionDisplayOrder' => 'alpha_asc'),$pkg); // or add to attribute and assign to an attribute set // CollectionAttributeKey::add($att, array('akHandle' => 'my_attribute', // 'akName' => t('My Attribute'), // 'akIsSearchableIndexed' => true, // 'akIsSearchable' => true, // 'akSelectAllowMultipleValues' => true, // 'akSelectAllowOtherValues' => true, // 'akSelectOptionDisplayOrder' => 'alpha_asc'),$pkg)->setAttributeSet($akCatSet); $addAttribute = CollectionAttributeKey::getByHandle('my_attribute'); }
Add a File Attribute Set
<?php use \Concrete\Core\Attribute\Key\Category as AttributeKeyCategory; $akCat = AttributeKeyCategory::getByHandle('collection'); $akCat->setAllowAttributeSets(AttributeKeyCategory::ASET_ALLOW_SINGLE); $akCatSet = $akCat->addSet('my_attribute_set', t('My Attribute Set'),$pkg);
Display / Get File Info from File Sets
(in view.php) <?php $fs = FileSet::getByName('Your File Set'); $fl = new FileList(); $fl->filterBySet($fs); $fl->sortBy('fsDisplayOrder', 'asc'); $files = $fl->get(); foreach($files as $f) { echo $f->getFileName(); echo $f->getTitle(); echo $f->getAttribute("width"); echo $f->getDownloadURL(); echo $f->getRelativePath(); echo $f->getDescription(); echo $f->getAttribute('attribute_name'); } ?> (in controller.php) <?php namespace use FileSet; use FileList; $fs = FileSet::getByName('Your File Set'); $fl = new FileList(); $fl->filterBySet($fs); $fl->sortBy('fsDisplayOrder', 'asc'); $files = $fl->get(); ?>
Add a File
<?php use FileImporter; $fi = new FileImporter(); $newFile = $fi->import($pathToFile, $nameOfFile, $fileObject); } ?>
Add a File From a Form
<?php // function in controller use FileImporter; $fi = new FileImporter(); $newFile = $fi->import($_FILES['fileName']['tmp_name'], $_FILES['fileName']['name']); } ?>
Add a File to a file Set
<?php // when uploading with a form function action_file_upload() { use FileImporter; $fi = new FileImporter(); $newFile = $fi->import($_FILES['fileName']['tmp_name'], $_FILES['fileName']['name']); // add file to file set use FileSet; $fs = FileSet::createAndGetSet('FILE_SET_NAME', FileSet::TYPE_PUBLIC, $uID = false); $fsf = $fs->addFileToSet($newFile); } ?>
Working With Page Lists
Initiating a Page List
(in view.php) <?php use Pagelist; $pl = new PageList(); ... Filtering and Sorting Options ... // Get the page List Results $pages = $pl->get() Get all pages that match filter/sort criteria. ?> (in controller.php) <?php namespace use Concrete\Core\Page\PageList; $pl = new PageList(); ... Filtering and Sorting Options ... // Get the page List Results $pages = $pl->get() Get all pages that match filter/sort criteria. ?>
Page List Filters / Sorting
<?php // Available Filters $pl->ignorePermissions(); // Don't check the permissions of the logged-in user. $pl->ignoreAliases(); // Ignore aliased pages. $pl->includeSystemPages(); // Include system pages $pl->displayUnapprovedPages(); // Include pages that have not been approved. $pl->filterByKeywords($keywords); // Filters files by keywords. $pl->filterByName($name, $exact = false); // Filter page name. $pl->filterByPath($path, $includeAllChildren = true); // Filters pages by path, children true/false $pl->filterByParentID($cParentID); //Filters by the parent ID. $pl->filterByCollectionTypeID($ctID); //Displays pages of a certain page type. $pl->filterByUserID($userID); //Displays pages owned by a particular user ID. $pl->filterByIsApproved($isApproved); //Only display approved pages. $pl->filterByIsAlias($ia); //Filters by whether an item is an alias or not. $pl->filterByCollectionTypeHandle($ctHandle); //Filters by page type handles. $ctHandle can be array of page type handles. $pl->filterByDateAdded($date, $comparison = '='); //Filters by date the page was added. $comparison can be any MySQL comparison operator. $pl->filterByPublicDate($date, $comparison = '='); //Filters by public date. $comparison can be any MySQL comparison operator. $pl->filterByDateLastModified($date, $comparison = '='); //Filters by date the page was last modified. $comparison can be any MySQL comparison operator. $pl->filterByNumberOfChildren($number, $comparison = '='); //Filters by number of page children. $comparison can be any MySQL comparison operator. $pl->filterByAttribute($attributeKeyHandle, $value, $comparison); //Filters by attribute. $pl->filter($column, $value, $comparison); //Filter by MySql "WHERE" clause // Sorting Options $pl->sortByRelevance(); //Orders by index score descending. Only available when searching by keywords. $pl->sortByDisplayOrder(); //Orders by sitemap display order ascending. $pl->sortByDisplayOrderDescending(); // Orders by sitemap display order descending. $pl->sortByPublicDate(); //Orders by public date ascending. $pl->sortByPublicDateDescending(); //Orders by public date descending. $pl->sortByName(); //Orders by page name ascending. $pl->sortByNameDescending(); // Order by name descending $pl->sortBy('ak_ATTRIBUTE_HANDLE'); // Order by a page attribute ?>
Get Page List based on Collection Type Handle
<?php $pl = new PageList(); $pl->filterByCollectionTypeHandle('COLLECTION_HANDLE'); $pl->sortByDisplayOrder('alpha_asc'); // Sort alphebetically $pages = $pl->getPage(); // Display Page Name and Description foreach ($pages as $page){ echo $page->getCollectionName(); echo $page->getCollectionDescription(); } ?>
Embed Page List Block in Theme
<?php $bt = BlockType::getByHandle('page_list'); //Set Options $bt->controller->orderBy = 'display_asc'; // 'display_asc', 'chrono_desc', 'chrono_asc', 'alpha_asc', 'alpha_desc' $bt->controller->ctID = ''; // Filter by Collection Page Type ID $bt->controller->displayFeaturedOnly = 'false'; // If Featured Page attribute 'true', 'false' $bt->controller->displayAliases = 'false'; // Display aliase pages 'true', 'false' $bt->controller->paginate = 'true'; // 'true', 'false' $bt->controller->cParentID = '6149'; // Display pages beneath this page ID $bt->controller->includeAllDescendents = 'true'; // 'true', 'false' $bt->controller->orderBy = 'display_asc'; // 'display_asc', 'chrono_desc', 'chrono_asc', 'alpha_asc', 'alpha_desc' $bt->controller->showrss = 'false'; // Display RSS feed 'true', 'false' $bt->controller->truncateSummaries = 'true'; // 'true', 'false' $bt->controller->truncateChars = '128'; // Truncate length if summaries 'true' $bt->controller->paginate = 'true'; // 'true', 'false' // Render the block $bt->render('view'); // for template 'templates/template_name' ?>
Re-Sort Page List Block $pages Array
<?php // Re-sort in view.php by an end date page attribute usort($pages, create_function('$a, $b', 'return $a->getAttribute("end_date") > $b->getAttribute("end_date");')); ?>
Working With Languages
Get Active Language
$lang = \Localization::activeLocale();
Get Default Language
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $site = $app->make('site')->getSite(); $defaultLang = $site->getDefaultLocale()->getLocale();
Controllers
Single Page Controllers
Create single page file: applications/single_pages/test_page.php Create a controller file: applications/controllers/test_page.php Namespace and class for controller <?php namespace Application\Controller\SinglePage; use PageController; class TestPage extends PageController { // Add functions public function view() { // Whatever code you need for functions echo 'Hello World'; } } ?>
Database
Fetch Data From Database
<?php use Database; $db = Database::connection(); $sql = "SELECT * FROM [table] WHERE [column1] = ? AND [column2] = ?"; $vals = array('[value1]', '[value2]'); $r = $db->Execute($sql, $vals); $row = $r->FetchRow(); echo $row[column name]; ?>
Update Database
<?php use Database; $db = Database::connection(); $sql = "UPDATE [table] SET [column] = ? WHERE bID = $this->bID"; $vals = array('[value]'); $update = $db->Execute($sql, $vals); ?>
Helpers
Date/Time Helper
Load Date/Time Helper
<?php $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $date = $app->Make('helper/date'); ?>
Compare Today's Date With a Pages Date/Time Attribute (end_date) And Do Something
Using Date Helper to format ($mask=) display of date and time. <?php if($date->getSystemDateTime($c->getCollectionAttributeValue('end_date'), $mask = 'd-m-Y G:i') > $date->getLocalDateTime('now',$mask = 'd-m-Y G:i')) { echo 'End date is greater than today'; } ?>
Display Date/Time In dd-mm-yyyy 00:00 Format.
<?php $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $date = $app->Make("helper/date"); echo $date->getLocalDateTime('now',$mask = 'd-m-Y G:i') ?>
Display Page Attribute "end_date" In mm/dd/yy Format
<?php echo $date->getSystemDateTime($c->getCollectionAttributeValue('end_date'), $mask = 'm/d/y') ?>
Get Date The Page Was Last Edited
<?php foreach($c->getBlocks('Main') as $b) { $bDate[$i] = $b->getBlockDateLastModified(); $i ++; } rsort( $bDate ); echo $date->getLocalDateTime($bDate[0],$mask = 'm-d-Y g:i:s'); ?>
If Page Attribute "end_date Is Greater Than Current Time, Do Something.
<?php if($date->getSystemDateTime($c->getCollectionAttributeValue('end_date'), $mask = 'd-m-Y G:i') > $date->getLocalDateTime('now',$mask = 'd-m-Y G:i')) { [do something here] } ?>
PHP Date Formatting For Mask
a 'am' or 'pm' A 'AM' or 'PM' B Swatch Internet time d day of the month, 2 digits with leading zeros; i.e. '01' to '31' D day of the week, textual, 3 letters; i.e. 'Fri' F month, textual, long; i.e. 'January' g hour, 12-hour format without leading zeros; i.e. '1' to '12' G hour, 24-hour format without leading zeros; i.e. '0' to '23' h hour, 12-hour format; i.e. '01' to '12' H hour, 24-hour format; i.e. '00' to '23' i minutes; i.e. '00' to '59' I (capital i) '1' if Daylight Savings Time, '0' otherwise. j day of the month without leading zeros; i.e. '1' to '31' l (lowercase 'L') day of the week, textual, long; i.e. 'Friday' L boolean for whether it is a leap year; i.e. '0' or '1' m month; i.e. '01' to '12' M month, textual, 3 letters; i.e. 'Jan' n month without leading zeros; i.e. '1' to '12' r RFC 822 formatted date; i.e. 'Thu, 21 Dec 2000 16:01:07 +0200' (added in PHP 4.0.4) s seconds; i.e. '00' to '59' S English ordinal suffix, textual, 2 characters; i.e. 'th', 'nd' t number of days in the given month; i.e. '28' to '31' T Timezone setting of this machine; i.e. 'MDT' U seconds since the epoch w day of the week, numeric, i.e. '0' (Sunday) to '6' (Saturday) Y year, 4 digits; i.e. '1999' y year, 2 digits; i.e. '99' z day of the year; i.e. '0' to '365' Z timezone offset in seconds (i.e. '-43200' to '43200'). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.
Image Helper
<?php $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $imageHelper = $app->Make('helper/image'); ?>
Date Helper
<?php $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $dh = $app->Make('helper/date'); ?>
Form Helper
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $form = $app->Make('helper/form');
Navigation Helper
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $nh = $app->Make('helper/navigation'); $page = Page::getByPath('/contact'); echo $nh->getCollectionURL($page) getCollectionURL(), getLinkToCollection(), getTrailToCollection()
Text Editor
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); <?php echo $app->Make('editor')->outputStandardEditor('value_name', $valuet) ?>
Text Helper
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $th = $app->Make("helper/text"); $desc = $th->shortenTextWord($product->getDesc(), 160); alphanum(), appendXML(), asciify(), autolink(), camelcase(), decodeEntities(), email(), entities(), filterNonAlphaNum(), fnmatch(), formatXML(), handle(), highlightSearch(), makenice(), sanitize(), sanitizeFileSystem(), shortText(), shorten(), shortenTextWord(), specialchars(), twitterAutolink(), uncamelcase(), unhandle(), urlify(), wordSafeShortText()
Generate Token
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); $token = $app->make('token'); if($token->validate('handle_names')) {
Output Thumbnail from Page Attribute
If image exists in Image/File Attribute "product_image", display the image scaled to 100px. <?php if($c->getAttribute('product_image')) { $imageHelper->outputThumbnail($c->getAttribute('product_image'),100 ,100); } ?>
Get Thumbnail Info with Image Helper
<?php $file = File::getByID(id_number); $img = $imageHelper->getThumbnail($file, 100, 100); ?> <img src="<?php echo $img->src; ?>" width="<?php echo $img->width; ?>" height="<?php echo $img->height; ?>">
Get Site Attribute
$site = Site::getSite(); <?php echo $site->getAttribute('attribute_handle') ?>
Site.php
Common Settings
Set advanced permissions on define('PERMISSIONS_MODEL', 'advanced'); Use APC Caching (you need APC installed) define('CACHE_LIBRARY', 'apc'); Disable Zend Cache Cleaning (may improve performance) define('CACHE_FRONTEND_OPTIONS', serialize(array('automatic_cleaning_factor' => 0))); Set time to 24 hour format define('DATE_FORM_HELPER_FORMAT_HOUR', '24'); Date Formatting define('DATE_APP_GENERIC_MDYT_FULL', 'F d, Y \a\t g:i A'); define('DATE_APP_GENERIC_MDYT', 'n/j/Y \a\t g:i A'); define('DATE_APP_GENERIC_MDY', 'n/j/Y'); define('DATE_APP_GENERIC_MDY_FULL', 'F d, Y'); Change minimum user name length from default value 3 define('USER_USERNAME_MINIMUM', 3); Change maximum username length from default value 64 define('USER_USERNAME_MAXIMUM', 64); Change minimum password length from default value 3 define('USER_PASSWORD_MINIMUM', 5); Change maximum password length from default value 64 define('USER_PASSWORD_MAXIMUM', 64); Change session time from default of 2 hours define('SESSION_MAX_LIFETIME', 7200); // 2 hours Set registration email notification address define('EMAIL_ADDRESS_REGISTER_NOTIFICATION', 'example@domain.com'); Set registration email notification from address define('EMAIL_ADDRESS_REGISTER_NOTIFICATION_FROM', 'example@domain.com');
White Label Configuration
Disable concrete5 marketplace integration. define('ENABLE_MARKETPLACE_SUPPORT', false); Disable help searches in the intelligent search. define('ENABLE_INTELLIGENT_SEARCH_HELP', false); Disable marketplace add-ons appear in intelligent search results. define('ENABLE_INTELLIGENT_SEARCH_MARKETPLACE', false); Disable newsflow define('ENABLE_NEWSFLOW_OVERLAY', false); Path to the logo image. This can also be a full URL. This file should be 49x49 pixels. define('WHITE_LABEL_LOGO_SRC', 'PATH TO FILE'); Alt text for the logo define('WHITE_LABEL_APP_NAME', 'TEXT'); Disable Layouts. define('ENABLE_AREA_LAYOUTS', false); Disable Custom Design for blocks or areas. define('ENABLE_CUSTOM_DESIGN', false); Disable Newsflow connect to concrete5.org to retrieve latest updates. define('ENABLE_APP_NEWS', false); Set to a valid image (either local or a remote URL), or none. define('WHITE_LABEL_DASHBOARD_BACKGROUND_SRC', 'none'); Web address for today's Image define('WHITE_LABEL_DASHBOARD_BACKGROUND_FEED', false);
cheatsheet.txt · Last modified: 2023/08/29 13:16 by 127.0.0.1