Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente | |||
| info:concrete5:cheatsheet_concretecms [2025/09/19 05:06] – radeff | info:concrete5:cheatsheet_concretecms [2026/03/26 14:01] (Version actuelle) – supprimée radeff | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== Radeff' | ||
| - | <note important> | ||
| - | ===== Get Style Sheet ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $this-> | ||
| - | Load stylesheet in header | ||
| - | |||
| - | <?php echo $this-> | ||
| - | </ | ||
| - | ===== Get Theme Path ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $this-> | ||
| - | |||
| - | Use to load an image from theme image directory | ||
| - | |||
| - | <img src="<? | ||
| - | |||
| - | OR | ||
| - | |||
| - | <?php | ||
| - | $v = View:: | ||
| - | $v-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Set Theme Path ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | Use a Theme Path In a Block | ||
| - | |||
| - | <?php | ||
| - | $v = View:: | ||
| - | $themePath = $v-> | ||
| - | ?> | ||
| - | |||
| - | To display an image from your themes image directory | ||
| - | | ||
| - | <img src="<? | ||
| - | </ | ||
| - | ====== Working With Blocks ====== | ||
| - | |||
| - | ===== Add a Block Area ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <? | ||
| - | $a = new Area(' | ||
| - | $a-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Wrap Each Block In An Area With Divs ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <? | ||
| - | $a = new Area(' | ||
| - | $a-> | ||
| - | $a-> | ||
| - | $a-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Add Space Between Blocks In Edit Mode ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <? | ||
| - | if ($c-> | ||
| - | <div style=" | ||
| - | <?php } ?> | ||
| - | </ | ||
| - | ===== Add a Global Area for a Stack In a Page ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | |||
| - | <?php | ||
| - | $a = new GlobalArea(' | ||
| - | $a-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Add a Stack In a Page ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | |||
| - | <?php | ||
| - | $stack = Stack:: | ||
| - | $stack-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Get Stack Names (or Handles) ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | |||
| - | <?php | ||
| - | Loader:: | ||
| - | $stm = new StackList(); | ||
| - | $stm-> | ||
| - | // Use filterByGlobalAreas() or filterByUserAdded() | ||
| - | $stacks = $stm-> | ||
| - | |||
| - | foreach($stacks as $st) { | ||
| - | print $st-> | ||
| - | // Use $st-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | |||
| - | <?php | ||
| - | $stm = new StackList(); | ||
| - | $stm-> | ||
| - | // Use filterByGlobalAreas() or filterByUserAdded() | ||
| - | $stacks = $stm-> | ||
| - | |||
| - | foreach($stacks as $st) { | ||
| - | print $st-> | ||
| - | // Use $st-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Get URL for Block Directory ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <img src="<? | ||
| - | </ | ||
| - | ====== Working with Pages in Blocks and Themes ====== | ||
| - | |||
| - | ===== Add a Page Type ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | /* Check if page exists. */ | ||
| - | | ||
| - | Loader:: | ||
| - | $pageType = CollectionType:: | ||
| - | |||
| - | /* Addd new page if does not exist. */ | ||
| - | | ||
| - | if(!is_object($pageType)) { | ||
| - | $data[' | ||
| - | $data[' | ||
| - | $newPage = CollectionType:: | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Display a Page's Parent Page Name ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $page=Page:: | ||
| - | echo $page-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Display Top Level Parent Name ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <? | ||
| - | global $c; | ||
| - | $nh = Loader:: | ||
| - | $cobj = $nh-> | ||
| - | |||
| - | $rcobj = array_reverse($cobj); | ||
| - | if(is_object($rcobj[1])) { | ||
| - | $pID = $rcobj[1]-> | ||
| - | $page = Page:: | ||
| - | echo $page-> | ||
| - | }else{ | ||
| - | echo $c-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <? | ||
| - | $c = Page:: | ||
| - | $nh = Core:: | ||
| - | $cobj = $nh-> | ||
| - | |||
| - | $rcobj = array_reverse($cobj); | ||
| - | if(is_object($rcobj[1])) { | ||
| - | $pID = $rcobj[1]-> | ||
| - | $page = Page:: | ||
| - | echo $page-> | ||
| - | }else{ | ||
| - | echo $c-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Get Current Page Object ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | global $c; | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $page = Page:: | ||
| - | </ | ||
| - | ===== Get Date The Page Was Added/ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $c-> | ||
| - | ?> | ||
| - | |||
| - | Display date page was added. | ||
| - | |||
| - | <?php echo $c-> | ||
| - | </ | ||
| - | ===== Get Handle of Parent Page and Do Something ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $page=Page:: | ||
| - | | ||
| - | if ( $page-> | ||
| - | echo '<a href="/ | ||
| - | } else { | ||
| - | echo '<a href="/ | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Get a Page's Description ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $c-> | ||
| - | | ||
| - | Display page description | ||
| - | |||
| - | <?php echo $c-> | ||
| - | </ | ||
| - | ===== Get a Page's Handle ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $c-> | ||
| - | |||
| - | Create a div for adding styles to individual pages | ||
| - | | ||
| - | <div id="<? | ||
| - | |||
| - | Add a class to a div based on page handle | ||
| - | | ||
| - | <div id=" | ||
| - | </ | ||
| - | ===== Get a Page's ID ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $c-> | ||
| - | | ||
| - | Display page ID | ||
| - | | ||
| - | <?php echo $c-> | ||
| - | </ | ||
| - | ===== Get a Page's Name ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $c-> | ||
| - | | ||
| - | Display page name | ||
| - | | ||
| - | <?php echo $c-> | ||
| - | |||
| - | </ | ||
| - | ===== Get a Page's Parent Page ID ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $c-> | ||
| - | | ||
| - | Display parent page page ID | ||
| - | | ||
| - | <?php echo $c-> | ||
| - | </ | ||
| - | ===== Get a Pages Owner ID ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $pageOwner = $c-> | ||
| - | </ | ||
| - | ===== Get Current Page URL ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $nh = Loader:: | ||
| - | $URL = $nh-> | ||
| - | ?> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | < | ||
| - | <?php | ||
| - | $nh = Core:: | ||
| - | $URL = $nh-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Get a Page Type's Name ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $c-> | ||
| - | | ||
| - | Set a class to a page types name. | ||
| - | | ||
| - | <? | ||
| - | if($c-> | ||
| - | echo ' | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Get Site Name ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | echo SITE; | ||
| - | ?> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | echo Config:: | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Get Public Date/Time In Page Properties ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $c-> | ||
| - | | ||
| - | Display Public Date | ||
| - | |||
| - | <?php echo $c-> | ||
| - | </ | ||
| - | |||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $dateHelper = Core:: | ||
| - | |||
| - | echo $dateHelper-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Get Date Last Edited ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | // Load Date Helper | ||
| - | $date = Loader:: | ||
| - | | ||
| - | // Get Blocks in Main area | ||
| - | foreach($c-> | ||
| - | | ||
| - | $i ++; | ||
| - | } | ||
| - | |||
| - | // Reverse Sort Date Array | ||
| - | rsort( $bDate ); | ||
| - | |||
| - | //Echo Date and Time Page last Edited | ||
| - | echo $date-> | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | {{wiki: | ||
| - | |||
| - | <code php> | ||
| - | <?php | ||
| - | // Load Date Helper | ||
| - | $date = Core:: | ||
| - | |||
| - | // Get Blocks in Main area | ||
| - | foreach($c-> | ||
| - | | ||
| - | $i ++; | ||
| - | } | ||
| - | |||
| - | // Reverse Sort Date Array | ||
| - | rsort( $bDate ); | ||
| - | |||
| - | //Echo Date and Time Page last Edited | ||
| - | echo $date-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Embed Autonav in a Theme Page ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $bt = BlockType:: | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | ?> | ||
| - | </ | ||
| - | ====== Working With Page Attributes ====== | ||
| - | |||
| - | ===== Add a Page Attribute Programmatically ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | Loader:: | ||
| - | |||
| - | // add checkbox attribute | ||
| - | $att = AttributeType:: | ||
| - | $testAttribute3=CollectionAttributeKey:: | ||
| - | if( !is_object($testAttribute3) ) { | ||
| - | CollectionAttributeKey:: | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | namespace | ||
| - | use \Concrete\Core\Attribute\Type as AttributeType; | ||
| - | use CollectionAttributeKey; | ||
| - | |||
| - | // add checkbox attribute | ||
| - | $att = AttributeType:: | ||
| - | $testAttribute3=CollectionAttributeKey:: | ||
| - | if( !is_object($testAttribute3) ) { | ||
| - | CollectionAttributeKey:: | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Test That a Value Is Set in an Attribute ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | if ($c-> | ||
| - | Do Something Here; | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Get a Page Attribute Value ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $c-> | ||
| - | | ||
| - | Display a page text attribute | ||
| - | | ||
| - | <?php echo $c-> | ||
| - | |||
| - | *In some blocks you may need to substitute with $cobj | ||
| - | </ | ||
| - | ===== Get an Attribute Key by Handle ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | Loader:: | ||
| - | $atKey = CollectionAttributeKey:: | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | $atKey = CollectionAttributeKey:: | ||
| - | </ | ||
| - | ===== Display An Image From Page Attribute ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <img src="<? | ||
| - | </ | ||
| - | ===== If a Page File/Image Attribute Is Set, Display Download Link ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | if($c-> | ||
| - | echo '<a href="' | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Get a File/Image Atributes File Name ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $c-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Get All Page Attributes ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | $atKeys = AttributeKey:: | ||
| - | |||
| - | foreach($atKeys as $ak) { | ||
| - | echo $ak-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | (in view.php) | ||
| - | <?php | ||
| - | $atKeys = CollectionAttributeKey:: | ||
| - | |||
| - | foreach($atKeys as $ak) { | ||
| - | echo $ak-> | ||
| - | } | ||
| - | ?> | ||
| - | |||
| - | (in controller.php) | ||
| - | |||
| - | <?php | ||
| - | namespace | ||
| - | use View; | ||
| - | |||
| - | $atKeys = CollectionAttributeKey:: | ||
| - | |||
| - | foreach($atKeys as $ak) { | ||
| - | pageAttributes[] = $ak-> | ||
| - | } | ||
| - | |||
| - | </ | ||
| - | |||
| - | {{wiki: | ||
| - | <code php> | ||
| - | (in view.php) | ||
| - | <?php | ||
| - | $atKeys = CollectionAttributeKey:: | ||
| - | |||
| - | foreach($atKeys as $ak) { | ||
| - | echo $ak-> | ||
| - | } | ||
| - | ?> | ||
| - | |||
| - | (in controller.php) | ||
| - | |||
| - | <?php | ||
| - | namespace | ||
| - | use View; | ||
| - | |||
| - | $atKeys = CollectionAttributeKey:: | ||
| - | |||
| - | foreach($atKeys as $ak) { | ||
| - | pageAttributes[] = $ak-> | ||
| - | } | ||
| - | |||
| - | </ | ||
| - | ---- | ||
| - | ===== Get all Attributes in a Set ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | Loader:: | ||
| - | |||
| - | $atSet = AttributeSet:: | ||
| - | $atKeys = $atSet-> | ||
| - | |||
| - | foreach($atKeys as $ak) { | ||
| - | echo $ak-> | ||
| - | } | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | (in view.php) | ||
| - | $atSet = AttributeSet:: | ||
| - | $atKeys = $atSet-> | ||
| - | |||
| - | foreach($atKeys as $ak) { | ||
| - | echo $ak-> | ||
| - | } | ||
| - | |||
| - | (in controller.php) | ||
| - | |||
| - | namespace | ||
| - | use \Concrete\Core\Attribute\Set as AttributeSet; | ||
| - | |||
| - | $atSet = AttributeSet:: | ||
| - | $atKeys = $atSet-> | ||
| - | |||
| - | foreach($atKeys as $ak) { | ||
| - | $setNmes[] = $ak-> | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | |||
| - | {{wiki: | ||
| - | <code php> | ||
| - | (in view.php) | ||
| - | $atSet = AttributeSet:: | ||
| - | $atKeys = $atSet-> | ||
| - | |||
| - | foreach($atKeys as $ak) { | ||
| - | echo $ak-> | ||
| - | } | ||
| - | |||
| - | (in controller.php) | ||
| - | |||
| - | namespace | ||
| - | use \Concrete\Core\Attribute\Set as AttributeSet; | ||
| - | |||
| - | $atSet = AttributeSet:: | ||
| - | $atKeys = $atSet-> | ||
| - | |||
| - | foreach($atKeys as $ak) { | ||
| - | $setNmes[] = $ak-> | ||
| - | } | ||
| - | </ | ||
| - | ===== Display/Get Options From a Select Attribute ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <? | ||
| - | Loader:: | ||
| - | Loader:: | ||
| - | |||
| - | $ak = CollectionAttributeKey:: | ||
| - | $sa = new SelectAttributeTypeController(AttributeType:: | ||
| - | $sa-> | ||
| - | $values = $sa-> | ||
| - | |||
| - | foreach ($values as $v) { | ||
| - | echo $v-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Display/Get Options From a Select Attribute ===== | ||
| - | {{wiki: | ||
| - | |||
| - | <code php> | ||
| - | <? | ||
| - | use CollectionAttributeKey; | ||
| - | | ||
| - | $ak = CollectionAttributeKey:: | ||
| - | if ( is_object($ak)) { | ||
| - | $type = $ak-> | ||
| - | $controller = $type-> | ||
| - | $controller-> | ||
| - | $options = $controller-> | ||
| - | |||
| - | foreach($options as $option){ | ||
| - | print $option . '< | ||
| - | } | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Display/Get multiple Values From a Select Page Attribute ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | |||
| - | $selectedOptions = $c-> | ||
| - | if (is_object($selectedOptions)) { | ||
| - | foreach ($selectedOptions as $opt) { | ||
| - | echo $opt; | ||
| - | } | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Add select attribute with attribute set ===== | ||
| - | <code php> | ||
| - | <? | ||
| - | // add select with attribute set page attributes | ||
| - | | ||
| - | // Set attribute category | ||
| - | $akCat = AttributeKeyCategory:: | ||
| - | $akCat-> | ||
| - | $akCatSet = $akCat-> | ||
| - | |||
| - | $atType = AttributeType:: | ||
| - | |||
| - | // test for existing attribute | ||
| - | $myAttribute = CollectionAttributeKey:: | ||
| - | |||
| - | // Add attribute | ||
| - | if( !is_object($myAttribute) ) { | ||
| - | |||
| - | CollectionAttributeKey:: | ||
| - | array(' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ), | ||
| - | |||
| - | //Add option values | ||
| - | $myAttribute = CollectionAttributeKey:: | ||
| - | SelectAttributeTypeOption:: | ||
| - | SelectAttributeTypeOption:: | ||
| - | SelectAttributeTypeOption:: | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Select Nav Based On Page Attributes ===== | ||
| - | <code php> | ||
| - | (See language Switching) | ||
| - | |||
| - | <?php | ||
| - | if ($c-> | ||
| - | $block = Block:: | ||
| - | if( is_object($block) ) $block-> | ||
| - | } else { | ||
| - | $block = Block:: | ||
| - | if( is_object($block) ) $block-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ====== Working With Users ====== | ||
| - | |||
| - | ===== Add a User Attribute Programmatically ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | //add boolean type user attribute | ||
| - | $boolt = AttributeType:: | ||
| - | $attributeHandle=UserAttributeKey:: | ||
| - | |||
| - | if( !is_object($attributeHandle) ) | ||
| - | UserAttributeKey:: | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Delete User Attribute Programmatically ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | $attributeHandle = UserAttributeKey:: | ||
| - | if( is_object($attributeHandle) ) | ||
| - | | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Get a User Attribute for Person Logged In ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | $u = new User(); | ||
| - | if($u-> | ||
| - | $ui = UserInfo:: | ||
| - | echo $ui-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Set a User Attribute for Person Logged In ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | $u = new user(); | ||
| - | $ui = UserInfo:: | ||
| - | $ui-> | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Delete a User Attribute ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | $attributeKey = UserAttributeKey:: | ||
| - | if( is_object($attributeKey) ) | ||
| - | $attributeKey-> | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Display/Get Options From a User Select Attribute ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | Loader:: | ||
| - | |||
| - | $ak = UserAttributeKey:: | ||
| - | $sa = new SelectAttributeTypeController(AttributeType:: | ||
| - | $sa-> | ||
| - | $values = $sa-> | ||
| - | |||
| - | foreach ($values as $v) { | ||
| - | echo $v-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Add a User To a Group ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | $u = new User(); | ||
| - | $u-> | ||
| - | $groupName = Group:: | ||
| - | $u-> | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Get All User Group Names ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | |||
| - | $gl = new GroupSearch(); | ||
| - | $gResults = $gl-> | ||
| - | |||
| - | foreach ($gResults as $g) { | ||
| - | echo $g[' | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Display a Users Name ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $u = new User(); | ||
| - | echo $u-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== If Logged in Adjust Background Position ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <? | ||
| - | $u = new User(); | ||
| - | |||
| - | if ($u-> | ||
| - | <style type=" | ||
| - | body { background-position: | ||
| - | </ | ||
| - | <?php } ?> | ||
| - | </ | ||
| - | ===== If a User is Logged In Do Something ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $u = new User(); | ||
| - | if($u-> | ||
| - | echo 'Hello ' | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | ===== If Logged in User is Admin Do Something ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $u = new user(); | ||
| - | $g = Group:: | ||
| - | |||
| - | if ($u-> | ||
| - | //do something here | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ====== Working With Files and Sets ====== | ||
| - | |||
| - | ===== Get Path to File ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $f = File:: | ||
| - | $fv = $f-> | ||
| - | $path = $fv-> | ||
| - | ?> | ||
| - | </ | ||
| - | ] | ||
| - | ===== Get File Set Names ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | $fileSets = FileSet:: | ||
| - | foreach ($fileSets as $fs) { | ||
| - | echo fs-> | ||
| - | } | ||
| - | ?> | ||
| - | |||
| - | $fs-> | ||
| - | $fs-> | ||
| - | $fs-> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | (in view.php) | ||
| - | <?php | ||
| - | $fileSets = FileSet:: | ||
| - | foreach ($fileSets as $fs) { | ||
| - | echo $fs-> | ||
| - | } | ||
| - | ?> | ||
| - | |||
| - | $fs-> | ||
| - | $fs-> | ||
| - | $fs-> | ||
| - | |||
| - | (in controller.php | ||
| - | |||
| - | <?php | ||
| - | namespace | ||
| - | use FileSet; | ||
| - | use FileList; | ||
| - | |||
| - | $fileSets = FileSet:: | ||
| - | foreach ($fileSets as $fs) { | ||
| - | | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Add a File Set ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | $fs = FileSet:: | ||
| - | ?> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <? | ||
| - | $fs = FileSet:: | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Get File Attribute Value ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | $f = File:: | ||
| - | echo $f-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Add a File Attribute ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | // add file attribute programmatically (text) | ||
| - | Loader:: | ||
| - | $textt = AttributeType:: | ||
| - | $attribute=FileAttributeKey:: | ||
| - | |||
| - | if( !is_object($attribute) ) | ||
| - | FileAttributeKey:: | ||
| - | |||
| - | |||
| - | // when uploading with a form | ||
| - | function action_file_upload() { | ||
| - | Loader:: | ||
| - | $fi = new FileImporter(); | ||
| - | $newFile = $fi-> | ||
| - | $_FILES[' | ||
| - | | ||
| - | // add attriubute | ||
| - | | ||
| - | $f = $newFile-> | ||
| - | $fv = $f-> | ||
| - | | ||
| - | } | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | // in a package | ||
| - | use Concrete\Core\Attribute\Key\CollectionKey as CollectionAttributeKey; | ||
| - | use \Concrete\Core\Attribute\Type as AttributeType; | ||
| - | |||
| - | $attribute = CollectionAttributeKey:: | ||
| - | if ( !is_object($attribute)) { | ||
| - | $att = AttributeType:: | ||
| - | // add attribute | ||
| - | CollectionAttributeKey:: | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | ' | ||
| - | |||
| - | // or add to attribute and assign to an attribute set | ||
| - | // CollectionAttributeKey:: | ||
| - | // ' | ||
| - | // ' | ||
| - | // ' | ||
| - | // ' | ||
| - | // ' | ||
| - | // ' | ||
| - | $addAttribute = CollectionAttributeKey:: | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ===== Add a File Attribute Set===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | use \Concrete\Core\Attribute\Key\Category as AttributeKeyCategory; | ||
| - | |||
| - | $akCat = AttributeKeyCategory:: | ||
| - | $akCat-> | ||
| - | $akCatSet = $akCat-> | ||
| - | </ | ||
| - | |||
| - | ===== Display / Get File Info from File Sets===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | Loader:: | ||
| - | |||
| - | $fs = FileSet:: | ||
| - | $fl = new FileList(); | ||
| - | $fl-> | ||
| - | $fl-> | ||
| - | $files = $fl-> | ||
| - | |||
| - | foreach($files as $f) { | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | (in view.php) | ||
| - | <?php | ||
| - | $fs = FileSet:: | ||
| - | $fl = new FileList(); | ||
| - | $fl-> | ||
| - | $fl-> | ||
| - | $files = $fl-> | ||
| - | |||
| - | foreach($files as $f) { | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | echo $f-> | ||
| - | } | ||
| - | ?> | ||
| - | |||
| - | (in controller.php) | ||
| - | <?php | ||
| - | namespace | ||
| - | use FileSet; | ||
| - | use FileList; | ||
| - | |||
| - | $fs = FileSet:: | ||
| - | $fl = new FileList(); | ||
| - | $fl-> | ||
| - | $fl-> | ||
| - | $files = $fl-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Add a File ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | $fi = new FileImporter(); | ||
| - | $newFile = $fi-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Add a File From a Form ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | // function in controller | ||
| - | function action_file_upload() { | ||
| - | Loader:: | ||
| - | $fi = new FileImporter(); | ||
| - | $newFile = $fi-> | ||
| - | $_FILES[' | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Add a File to a file Set ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | // when uploading with a form | ||
| - | function action_file_upload() { | ||
| - | Loader:: | ||
| - | $fi = new FileImporter(); | ||
| - | $newFile = $fi-> | ||
| - | $_FILES[' | ||
| - | |||
| - | // add file to file set | ||
| - | Loader:: | ||
| - | $fs = FileSet:: | ||
| - | $uID = false); | ||
| - | $fsf = $fs-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ====== Working With Page Lists ====== | ||
| - | |||
| - | ===== Initiating a Page List ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | Loader:: | ||
| - | | ||
| - | $pl = new PageList(); | ||
| - | | ||
| - | ... Filtering and Sorting Options ... | ||
| - | | ||
| - | // Get the page List Results | ||
| - | $pages = $pl-> | ||
| - | |||
| - | Or | ||
| - | | ||
| - | $pages = $pl-> | ||
| - | ?> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | |||
| - | (in view.php) | ||
| - | |||
| - | <?php | ||
| - | $pl = Core:: | ||
| - | | ||
| - | $pl = new PageList(); | ||
| - | | ||
| - | ... Filtering and Sorting Options ... | ||
| - | | ||
| - | // Get the page List Results | ||
| - | $pages = $pl-> | ||
| - | ?> | ||
| - | |||
| - | (in controller.php) | ||
| - | |||
| - | <?php | ||
| - | namespace | ||
| - | use Concrete\Core\Page\PageList; | ||
| - | |||
| - | $pl = new PageList(); | ||
| - | | ||
| - | ... Filtering and Sorting Options ... | ||
| - | | ||
| - | // Get the page List Results | ||
| - | $pages = $pl-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Page List Filters / Sorting ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | // Available Filters | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | |||
| - | // Sorting Options | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | === Get Page List based on Collection Type Handle === | ||
| - | <code php> | ||
| - | <?php | ||
| - | $pl = new PageList(); | ||
| - | $pl-> | ||
| - | $pl-> | ||
| - | | ||
| - | $pages = $pl-> | ||
| - | | ||
| - | // Display Page Name and Description | ||
| - | foreach ($pages as $page){ | ||
| - | echo $page-> | ||
| - | echo $page-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Embed Page List Block in Theme ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | $bt = BlockType:: | ||
| - | | ||
| - | //Set Options | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | $bt-> | ||
| - | | ||
| - | // Render the block | ||
| - | $bt-> | ||
| - | ?> | ||
| - | </ | ||
| - | ===== Re-Sort Page List Block $pages Array ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | // Re-sort in view.php by an end date page attribute | ||
| - | usort($pages, | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ====== Controllers ====== | ||
| - | |||
| - | ===== Single Page Controllers ===== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | Create single page file: applications/ | ||
| - | |||
| - | Create a controller file: applications/ | ||
| - | |||
| - | Namespace and class for controller | ||
| - | |||
| - | <? | ||
| - | 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 ===== | ||
| - | <code php> | ||
| - | <?php | ||
| - | $db = Loader:: | ||
| - | |||
| - | $sql = " | ||
| - | $vals = array(' | ||
| - | $r = $db-> | ||
| - | $row = $r-> | ||
| - | |||
| - | echo $row[column name]; | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Update Database ===== | ||
| - | <code php> | ||
| - | <? | ||
| - | $db = Loader:: | ||
| - | |||
| - | $sql = " | ||
| - | $vals = array(' | ||
| - | $update = $db-> | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ====== Helpers ====== | ||
| - | |||
| - | ===== Date/Time Helper ===== | ||
| - | |||
| - | ==== Load Date/Time Helper ==== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $date = Loader:: | ||
| - | ?> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $date = Core:: | ||
| - | ?> | ||
| - | </ | ||
| - | ==== Compare Today' | ||
| - | <code php> | ||
| - | Using Date Helper to format ($mask=) display of date and time. | ||
| - | |||
| - | <?php | ||
| - | | ||
| - | if($date-> | ||
| - | echo 'End date is greater than today'; | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ==== Display Date/Time In dd-mm-yyyy 00:00 Format. ==== | ||
| - | <code php> | ||
| - | <?php | ||
| - | $date = Loader:: | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ==== Display Page Attribute " | ||
| - | <code php> | ||
| - | <?php | ||
| - | echo $date-> | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ==== Get Date The Page Was Last Edited ==== | ||
| - | <code php> | ||
| - | <?php | ||
| - | foreach($c-> | ||
| - | $bDate[$i] = $b-> | ||
| - | $i ++; | ||
| - | } | ||
| - | | ||
| - | rsort( $bDate ); | ||
| - | | ||
| - | echo $date-> | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ==== If Page Attribute " | ||
| - | <code php> | ||
| - | <?php | ||
| - | if($date-> | ||
| - | |||
| - | [do something here] | ||
| - | |||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ==== PHP Date Formatting For Mask ==== | ||
| - | <code php> | ||
| - | a ' | ||
| - | A ' | ||
| - | B Swatch Internet time | ||
| - | d day of the month, 2 digits with leading zeros; i.e. ' | ||
| - | D day of the week, textual, 3 letters; i.e. ' | ||
| - | F month, textual, long; i.e. ' | ||
| - | g hour, 12-hour format without leading zeros; i.e. ' | ||
| - | G hour, 24-hour format without leading zeros; i.e. ' | ||
| - | h hour, 12-hour format; i.e. ' | ||
| - | H hour, 24-hour format; i.e. ' | ||
| - | i minutes; i.e. ' | ||
| - | I (capital i) ' | ||
| - | j day of the month without leading zeros; i.e. ' | ||
| - | l (lowercase ' | ||
| - | L boolean for whether it is a leap year; i.e. ' | ||
| - | m month; i.e. ' | ||
| - | M month, textual, 3 letters; i.e. ' | ||
| - | n month without leading zeros; i.e. ' | ||
| - | 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. ' | ||
| - | S English ordinal suffix, textual, 2 characters; i.e. ' | ||
| - | t number of days in the given month; i.e. ' | ||
| - | T Timezone setting of this machine; i.e. ' | ||
| - | U seconds since the epoch | ||
| - | w day of the week, numeric, i.e. ' | ||
| - | Y year, 4 digits; i.e. ' | ||
| - | y year, 2 digits; i.e. ' | ||
| - | z day of the year; i.e. ' | ||
| - | Z timezone offset in seconds (i.e. ' | ||
| - | </ | ||
| - | ===== Image Helper ===== | ||
| - | |||
| - | ==== Load Image Helper ==== | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $imageHelper = Loader:: | ||
| - | ?> | ||
| - | </ | ||
| - | {{wiki: | ||
| - | <code php> | ||
| - | <?php | ||
| - | $imageHelper = Core:: | ||
| - | ?> | ||
| - | </ | ||
| - | ==== Output Thumbnail from Page Attribute ==== | ||
| - | <code php> | ||
| - | If image exists in Image/File Attribute " | ||
| - | |||
| - | <?php | ||
| - | if($c-> | ||
| - | $imageHelper-> | ||
| - | } | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ==== Get Thumbnail Info with Image Helper ==== | ||
| - | <code php> | ||
| - | <?php | ||
| - | $file = File:: | ||
| - | $img = $imageHelper-> | ||
| - | ?> | ||
| - | |||
| - | <img src="<? | ||
| - | </ | ||
| - | |||
| - | ===== Multilingual Helper ===== | ||
| - | |||
| - | ==== Load Multilingual Helper ==== | ||
| - | <code php> | ||
| - | <?php | ||
| - | $lh = Loader:: | ||
| - | <? | ||
| - | </ | ||
| - | |||
| - | ==== Return Two Language Code ==== | ||
| - | <code php> | ||
| - | <?php | ||
| - | $lh = Loader:: | ||
| - | echo $lh-> | ||
| - | ?> | ||
| - | </ | ||
| - | |||
| - | ===== Site.php ===== | ||
| - | |||
| - | ==== Common Settings ==== | ||
| - | <code php> | ||
| - | Set advanced permissions on | ||
| - | define(' | ||
| - | |||
| - | Use APC Caching (you need APC installed) | ||
| - | define(' | ||
| - | |||
| - | Disable Zend Cache Cleaning (may improve performance) | ||
| - | define(' | ||
| - | serialize(array(' | ||
| - | |||
| - | Set time to 24 hour format | ||
| - | define(' | ||
| - | |||
| - | Date Formatting | ||
| - | define(' | ||
| - | define(' | ||
| - | define(' | ||
| - | define(' | ||
| - | |||
| - | Change minimum user name length from default value 3 | ||
| - | define(' | ||
| - | |||
| - | Change maximum username length from default value 64 | ||
| - | define(' | ||
| - | |||
| - | Change minimum password length from default value 3 | ||
| - | define(' | ||
| - | |||
| - | Change maximum password length from default value 64 | ||
| - | define(' | ||
| - | |||
| - | Change session time from default of 2 hours | ||
| - | define(' | ||
| - | |||
| - | Set registration email notification address | ||
| - | define(' | ||
| - | ' | ||
| - | |||
| - | Set registration email notification from address | ||
| - | define(' | ||
| - | ' | ||
| - | </ | ||
| - | |||
| - | ==== White Label Configuration ==== | ||
| - | <code php> | ||
| - | Disable concrete5 marketplace integration. | ||
| - | define(' | ||
| - | |||
| - | Disable help searches in the intelligent search. | ||
| - | define(' | ||
| - | |||
| - | Disable marketplace add-ons appear in intelligent | ||
| - | search results. | ||
| - | define(' | ||
| - | |||
| - | Disable newsflow | ||
| - | define(' | ||
| - | |||
| - | Path to the logo image. This can also be a full URL. | ||
| - | This file should be 49x49 pixels. | ||
| - | define(' | ||
| - | |||
| - | Alt text for the logo | ||
| - | define(' | ||
| - | |||
| - | Disable Layouts. | ||
| - | define(' | ||
| - | |||
| - | Disable Custom Design for blocks or areas. | ||
| - | define(' | ||
| - | |||
| - | Disable Newsflow connect to concrete5.org to retrieve | ||
| - | latest updates. | ||
| - | define(' | ||
| - | |||
| - | Set to a valid image (either local or a remote URL), or none. | ||
| - | define(' | ||
| - | |||
| - | Web address for today' | ||
| - | define(' | ||
| - | </ | ||
| - | |||
| - | Credits: https:// | ||