function assetTreeConvertToOneRegionTemplate(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL)
{
    if (!isset($params['site-storage']) || !isset($params['global-link-script']) || !isset($params['page-title']) || !isset($params['search-form']) || !isset($params['content-type'])) {
        throw new \Exception("Some of the parameters are missing.");
    }
    $type = $child->getType();
    if ($type != a\Page::TYPE) {
        return;
    }
    // skip entire folder
    if (strpos($child->getPathPath(), "_extra/") !== false) {
        return;
    }
    if (strpos($child->getPathPath(), "_cascade/") !== false) {
        return;
    }
    $site_storage_block = $params['site-storage'];
    $global_link_script_block = $params['global-link-script'];
    $page_title_block = $params['page-title'];
    $search_form_block = $params['search-form'];
    $one_region_ct = $params['content-type'];
    $page = $service->getAsset($child->getType(), $child->getId());
    try {
        $page->setContentType($one_region_ct);
        $cur_sd = $page->getStructuredData();
        $new_sd = $cur_sd->mapData();
        $page->setStructuredData($new_sd);
        $page->setBlock("site-config-group;site-storage", $site_storage_block)->setBlock("site-config-group;global-link-script", $global_link_script_block)->setBlock("site-config-group;page-title", $page_title_block)->setBlock("site-config-group;search-form", $search_form_block)->edit();
    } catch (\Exception $e) {
        echo $page->getId(), BR;
        throw $e;
    }
}
コード例 #2
0
 public function retrieveAsset(p\Child $child)
 {
     $id = $child->getId();
     if (!isset($this->cache[$id])) {
         $this->cache[$id] = $child->getAsset(self::$service);
     }
     return $this->cache[$id];
 }
コード例 #3
0
function processPage(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL)
{
    // Get the next page to be processed
    $page = $child->getAsset($service);
    echo "<tr>\n";
    // get the full Page asset
    echo "<td><a href='" . $GLOBALS['url'] . $child->getId() . "'>" . $child->getPathPath() . "</a></td>\n<td>" . $page->getContentTypePath() . "</td>\n";
    echo "</tr>\n";
}
function assetTreeFindDDBlockPageWithIntialId(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL)
{
    if (!isset($params['partial-id'])) {
        throw new \Exception("The id is not included");
    }
    $partial_id = $params['partial-id'];
    $type = $child->getType();
    if ($type != a\DataBlock::TYPE && $type != a\Page::TYPE) {
        return;
    }
    $id = $child->getId();
    if (!u\StringUtility::startsWith($id, $partial_id)) {
        return;
    } else {
        echo $id;
    }
}
コード例 #5
0
function assetTreeRemoveAsset(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL)
{
    if (is_array($results) && is_array($results[c\F::REPORT_ORPHANS]) && in_array($child->getPathPath(), $results[c\F::REPORT_ORPHANS][$child->getType()])) {
        if (isset($params[c\F::REMOVE_ASSET][c\F::UNCONDITIONAL_REMOVAL]) && $params[c\F::REMOVE_ASSET][c\F::UNCONDITIONAL_REMOVAL] == true) {
            $service->delete($child->toStdClass());
        } else {
            if (!in_array($child->getId(), $params[c\F::REMOVE_ASSET][$child->getType()]) && !in_array($child->getPathPath(), $params[c\F::REMOVE_ASSET][$child->getType()])) {
                $service->delete($child->toStdClass());
            }
        }
    }
}
コード例 #6
0
function assetTreeSwitchPageContentType(aohs\AssetOperationHandlerService $service, p\Child $child, array $params = NULL, array &$results = NULL)
{
    if ($child->getType() != a\Page::TYPE) {
        return;
    }
    // make sure that there is a content type passed in
    if (!isset($params['ct'])) {
        throw new \Exception("No content type is supplied");
    }
    // make sure that there is a base page passed in
    if (!isset($params['bp'])) {
        throw new \Exception("No base page is supplied");
    }
    // make sure that there are global blocks passed in
    if (!isset($params['google-tag']) || !isset($params['site-storage']) || !isset($params['link-script']) || !isset($params['page-title']) || !isset($params['search-form'])) {
        throw new \Exception("No global blocks are supplied");
    }
    // pages to skip
    if (isset($params['skip'])) {
        $skip = $params['skip'];
    }
    // skip whatever that is supposed to be skipped
    if (isset($skip) && is_array($skip) && in_array($child->getPathPath(), $skip)) {
        return;
    }
    // retrieve all required assets
    $ct = $params['ct'];
    $bp = $params['bp'];
    $google_tag = $params['google-tag'];
    $site_storage = $params['site-storage'];
    $link_script = $params['link-script'];
    $page_title = $params['page-title'];
    $search_form = $params['search-form'];
    // can run into phantom nodes
    try {
        // retrieve page to be processed
        $p = $child->getAsset($service);
        // get number of content-group
        $identifier = "content-group;0";
        $num_of_groups = 1;
        // get the number of instances of the multiple node
        if ($p->hasIdentifier($identifier)) {
            $num_of_groups = $p->getNumberOfSiblings($identifier);
        }
        // get the current structured data with data
        $sd_old = $p->getStructuredData();
        if (!isset($sd_old)) {
            return;
        }
        // create enough instances of the multiple field
        if ($num_of_groups > 1) {
            $bp->createNInstancesForMultipleField($num_of_groups, $identifier);
        }
        // get the blank structured data with needed nodes
        $sd_new = clone $bp->getStructuredData();
        // roll back the base page
        if ($num_of_groups > 1) {
            $bp->createNInstancesForMultipleField(1, $identifier);
        }
        // switch the content type
        $p->setContentType($ct, false);
        // fix the data
        if (u\StringUtility::endsWith($p->getPath(), 'index')) {
            $sd_new->setText("right-column", "yes");
        } else {
            $sd_new->setText("right-column", "no");
        }
        $sd_new->setText("left-column", "yes");
        $sd_new->setText("left-column-group;left-setup", "default");
        // the H1
        echo "Title: ", $p->getMetadata()->getTitle(), BR;
        $title = $p->getMetadata()->getTitle() != "" ? $p->getMetadata()->getTitle() : "Title to be set";
        $sd_new->setText("main-content-title", $p->getMetadata()->getTitle());
        // main WYSIWYG
        $sd_new->setText("main-content-content", $sd_old->getText("main-content-content"));
        // multiple groups with choosers
        for ($i = 0; $i < $num_of_groups; $i++) {
            $identifier = "content-group;" . $i . ";content-group-chooser";
            // null the id for the upcoming round
            $block_id = NULL;
            // read the block
            if ($sd_old->hasIdentifier($identifier)) {
                $block_id = $sd_old->getBlockId($identifier);
            }
            // if there is a block attached
            if (isset($block_id) && $block_id != "") {
                $b = a\Block::getBlock($service, $block_id);
                $sd_new->setBlock($identifier, $b);
                $identifier = "content-group;" . $i . ";content-group-size";
                $size_str = strtolower($sd_old->getText($identifier));
                // fix the possible value for the new data definition
                if ($size_str != 'full') {
                    $size_str = 'half';
                }
                $sd_new->setText($identifier, $size_str);
                $identifier = "content-group;" . $i . ";content-group-block-floating";
                $sd_new->setText($identifier, strtolower($sd_old->getText($identifier)));
            }
            // WYSIWYGs in group
            $identifier = "content-group;" . $i . ";content-group-content";
            $sd_new->setText($identifier, $sd_old->getText($identifier));
        }
        // set the data
        $p->setStructuredData($sd_new);
    } catch (e\NoSuchFieldException $e) {
        $page_id = $child->getId();
        $phantom_page = new a\PagePhantom($service, $service->createId(a\PagePhantom::TYPE, $page_id));
        $dd = $phantom_page->getDataDefinition();
        $healthy_sd = new p\StructuredData($dd->getStructuredData(), $service, $dd->getId());
        $phantom_sd = $phantom_page->getStructuredDataPhantom();
        $healthy_sd = $healthy_sd->removePhantomNodes($phantom_sd);
        $phantom_page->setStructuredData($healthy_sd);
    }
    // attach the five global blocks
    $p->setBlock("site-config-group;google-tag-manager", $google_tag)->setBlock("site-config-group;site-storage", $site_storage)->setBlock("site-config-group;global-link-script", $link_script)->setBlock("site-config-group;page-title", $page_title)->setBlock("site-config-group;search-form", $search_form)->setBlock("site-config-group;global-script")->edit();
}