PHP code example of xanweb / c5-page-info

1. Go to this page and download the library: Download xanweb/c5-page-info library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xanweb / c5-page-info example snippets


$pageInfoFactory = new Xanweb\PageInfo\Factory(); // We can pass our own config (Check `Config Management` section), otherwise default config will be used.
foreach ($pages as $page) {
    $pageInfo = $pageInfoFactory->build($page);
    $pageName = $pageInfo->fetchPageName($truncateChars, $tail); // Page name with htmlentites applied
                                                                //  $truncateChars: an optional argument can be passed to truncate description
    $pageDescription = $pageInfo->fetchPageDescription($truncateChars, $tail); // $truncateChars: an optional argument can be passed to truncate description
    $thumbnail = $pageInfo->fetchThumbnail($defaultThumbnail); // By default uses 'thumbnail' attribute.
    $formattedPublishDate = $pageInfo->getPublishDate($format); // Optionally you can pass format argument ('full', 'long', 'medium' or 'short') or a php custom format
    $formattedPublishDateTime = $pageInfo->getPublishDateTime(); 
    $authorUserInfo = $pageInfo->getAuthor(); 
    $lastEditedByUserInfo = $pageInfo->getLastEditor(); 
    $lastEditedByUserName = $pageInfo->getLastEditorUserName(); 
    $tags = $pageInfo->getTags(); 
    
    $linkTag = \HtmlObject\Link::create($pageInfo->getURL(), $pageName, ['target' => $pageInfo->getTarget()]);
}

use Xanweb\PageInfo\Fetcher\AttributePropertyFetcher;
use Xanweb\PageInfo\Fetcher\BlockPropertyFetcher;
use Xanweb\PageInfo\Fetcher\PagePropertyFetcher;

// Order of registering fetchers is important.
// The first registered will be firstly fetched. 
$config = $app->make(Xanweb\PageInfo\Config::class);

// if display_name attribute is filled for the page then it will be used otherwise the page name will be used
$config->registerPageNameFetcher(new AttributePropertyFetcher('display_name'));  
$config->registerPageNameFetcher(new PagePropertyFetcher(PagePropertyFetcher::PAGE_NAME));
$config->registerPageDescriptionFetcher(new PagePropertyFetcher(PagePropertyFetcher::PAGE_DESCRIPTION));

// Fetch thumbnail from a custom attribute
$config->registerThumbnailFetcher(new AttributePropertyFetcher('my_thumbnail_ak'));
// Fetch thumbnail from a block within the page. (fig = $app->make(Xanweb\PageInfo\Config::class);
    $config->register...
    
    return $config;
});

$myConfig = $cfgManager->getConfig('my_cfg_key');

$myConfig = Xanweb\PageInfo\ConfigManager::getBasic();
$pageInfoFactory = new Xanweb\PageInfo\Factory($myConfig);

$pageInfoFactoryWithDefaultConfig = new Xanweb\PageInfo\Factory();
$pageInfoFactoryWithBasicConfig = $pageInfoFactoryWithDefaultConfig->withConfig('basic');

class MyPageInfo extends \Xanweb\PageInfo\PageInfo {
    
}
$pageInfoFactory = new Xanweb\PageInfo\Factory($myConfig, MyPageInfo::class);