function __autoload($classname) { $array = utility\StringUtility::getExplodedStringArray("\\", $classname); $size = count($array); if ($size > 0) { $classname = $array[$size - 1]; } $root_path = dirname(__FILE__) . '/'; $asset_class_folder = "asset_classes/"; $helping_class_folder = "property_classes/"; $exception_class_folder = "exception_classes/"; $utility_class_folder = "utility_classes/"; $file = "{$classname}.class.php"; if (file_exists($root_path . $asset_class_folder . $file)) { require_once $root_path . $asset_class_folder . $file; } else { if (file_exists($root_path . $exception_class_folder . $file)) { require_once $root_path . $exception_class_folder . $file; } else { if (file_exists($root_path . $helping_class_folder . $file)) { require_once $root_path . $helping_class_folder . $file; } else { if (file_exists($root_path . $utility_class_folder . $file)) { require_once $root_path . $utility_class_folder . $file; } } } } }
function assetTreeRemoveUnwantedPage(aohs\AssetOperationHandlerService $service, p\Child $child, array $params = NULL, array &$results = NULL) { if ($child->getType() != a\Page::TYPE) { return; } $page_path = $child->getPathPath(); // junk page names if (u\StringUtility::endsWith($page_path, "/pdf") || u\StringUtility::endsWith($page_path, "/word") || u\StringUtility::endsWith($page_path, "/externallink") || u\StringUtility::endsWith($page_path, "/keytiny") || u\StringUtility::endsWith($page_path, "/index-2")) { $service->delete($child->toStdClass()); } }
public function addDynamicFieldDefinition($field_name, $type, $label, $required = false, $visibility = c\T::VISIBLE, $possible_values = "") { if ($this->hasDynamicMetadataFieldDefinition($field_name)) { throw new \Exception(S_SPAN . "The dynamic field definition {$field_name} already exists." . E_SPAN); } if ($type != c\T::TEXT && trim($possible_values) == "") { throw new e\EmptyValueException(S_SPAN . c\M::EMPTY_POSSIBLE_VALUES . E_SPAN); } $dmfd = AssetTemplate::getDynamicMetadataFieldDefinition(); $dmfd->dynamicMetadataFieldDefinition->name = $field_name; $dmfd->dynamicMetadataFieldDefinition->label = $label; $dmfd->dynamicMetadataFieldDefinition->fieldType = $type; $dmfd->dynamicMetadataFieldDefinition->required = $required; $dmfd->dynamicMetadataFieldDefinition->visibility = $visibility; if ($type != c\T::TEXT) { $dmfd->dynamicMetadataFieldDefinition->possibleValues = new \stdClass(); $values = u\StringUtility::getExplodedStringArray(";", $possible_values); $value_count = count($values); if ($value_count == 1) { $pv = new \stdClass(); $pv->value = $values[0]; $pv->selectedByDefault = false; $dmfd->dynamicMetadataFieldDefinition->possibleValues->possibleValue = $pv; } else { $dmfd->dynamicMetadataFieldDefinition->possibleValues->possibleValue = array(); foreach ($values as $value) { if (self::DEBUG) { u\DebugUtility::out($value); } $pv = new \stdClass(); $pv->value = $value; $pv->selectedByDefault = false; $dmfd->dynamicMetadataFieldDefinition->possibleValues->possibleValue[] = $pv; } } } if (self::DEBUG && self::DUMP) { u\DebugUtility::dump($dmfd); } $dmfd_obj = new p\DynamicMetadataFieldDefinition($dmfd->dynamicMetadataFieldDefinition); $this->dynamic_metadata_field_definitions[] = $dmfd_obj; if (self::DEBUG && self::DUMP) { u\DebugUtility::dump($dmfd_obj->toStdClass()); } $this->edit(); $this->processDynamicMetadataFieldDefinition(); return $this; }
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; } }
function revealInfo(a\MetadataSet $ms) { echo "<h1>", $ms->getName(), "</h1>", S_H2, "Wired Fields", E_H2, S_UL; foreach (a\MetadataSet::$wired_fields as $field_name) { $required_method_name = u\StringUtility::getMethodName($field_name) . "FieldRequired"; $visibility_method_name = u\StringUtility::getMethodName($field_name) . "FieldVisibility"; echo S_LI, $field_name . ", " . ($ms->{$required_method_name}() ? "required" : "not required") . ", " . $ms->{$visibility_method_name}(), E_LI; } echo E_UL; if ($ms->hasDynamicMetadataFieldDefinitions()) { echo S_H2, "Dynamic Fields", E_H2, S_UL; foreach ($ms->getDynamicMetadataFieldDefinitionNames() as $dmfs_name) { $dmfd = $ms->getDynamicMetadataFieldDefinition($dmfs_name); echo S_LI, $dmfd->getName(), " — ", "type: ", $dmfd->getFieldType(), "; ", !$dmfd->isText() ? "possible values: " . implode(";", $dmfd->getPossibleValueStrings()) . "; " : "", $dmfd->isRequired() ? "required" : "not required", "; ", E_LI; } echo E_UL; } else { echo "This MS does not have dynamic fields", BR; } }
function processFolder($dir, &$array) { global $host; if (is_dir($host . $dir . "/") && ($handle = opendir($host . $dir . "/"))) { while (false !== ($file = readdir($handle))) { if ($file == '.' || $file == '..') { continue; } else { if (is_file($host . $dir . "/" . $file)) { $name = $dir . "/" . $file; if (u\StringUtility::endsWith($name, ".php")) { $array[] = $name; } } else { if (is_dir($host . $dir . "/" . $file . "/")) { processFolder($dir . "/" . $file, $array); } } } } } }
echo u\StringUtility::getCoalescedString($t->getTargetId()), BR; echo u\StringUtility::getCoalescedString($t->getTargetPath()), BR; $f = $t->getFormat(); if ($f != NULL) { $f->display(); } echo S_PRE; //u\DebugUtility::dump( $t->getPageRegion( 'STORAGE' ) ); echo E_PRE; $block = $t->getPageRegionBlock('STORAGE'); if (isset($block)) { $block->dump(); } $format = $t->getPageRegionFormat('STORAGE'); //echo $t->getXml(), BR; echo u\StringUtility::boolToString($t->hasPageRegion('STORAGE')), BR; if (isset($format)) { $format->dump(); } //u\DebugUtility::dump( $t->getPageRegionNames() ); //u\DebugUtility::dump( $t->getPageRegions() ); //u\DebugUtility::dump( $t->getPageRegionStdForPageConfiguration() ); if ($mode != 'all') { break; } case 'set': $format_id = "4ad593f38b7f085600a28ff77fe83c04"; $format = $cascade->getAsset(a\XsltFormat::TYPE, $format_id); /* $xml = <<<XML <system-region name="DEFAULT"/>
/** * Create an id object for an asset * @param string $type The type of the asset * @param string $id_path Either the id or the path of an asset * @param string $siteName The site name * * @return stdClass The identifier */ public function createId($type, $id_path, $site_name = NULL) { if (!(is_string($type) && (is_string($id_path) || is_int($id_path)))) { throw new e\UnacceptableValueException("Only strings are accepted in createId."); } $non_digital_id_types = array(c\T::GROUP, c\T::ROLE, c\T::SITE, c\T::USER); $id_path = trim($id_path); if (strlen($id_path) > 1) { $id_path = trim($id_path); $id_path = trim($id_path, '/'); } $identifier = new \stdClass(); if ($this->isHexString($id_path)) { // if id string is passed in, ignore site name $identifier->id = $id_path; } else { if (in_array($type, $non_digital_id_types)) { if ($type != c\T::SITE) { $identifier->id = $id_path; } else { $identifier->path = new \stdClass(); $identifier->path->path = $id_path; } } else { if (u\StringUtility::startsWith($id_path, "ROOT_")) { $identifier->id = $id_path; } else { if ($site_name == NULL) { $identifier->path = new \stdClass(); $identifier->path->path = $id_path; $identifier->path->siteName = $site_name; } else { if (trim($site_name) == "") { throw new e\EmptyValueException(S_SPAN . c\M::EMPTY_SITE_NAME . E_SPAN); } $identifier->path = new \stdClass(); $identifier->path->path = $id_path; $identifier->path->siteName = $site_name; } } } } $identifier->type = $type; return $identifier; }
use cascade_ws_asset as a; use cascade_ws_property as p; use cascade_ws_utility as u; use cascade_ws_exception as e; $mode = 'all'; //$mode = 'display'; //$mode = 'dump'; //$mode = 'get'; //$mode = 'set'; //$mode = 'raw'; try { $id = "a14dd6578b7ffe830539acf0371e2f5f"; // Default $afc = $cascade->getAsset(a\AssetFactoryContainer::TYPE, $id)->dump(); //$afc->setDescription( "Upload" )->edit()->dump(); echo u\StringUtility::getCoalescedString($afc->getDescription()), BR; switch ($mode) { case 'all': case 'display': $afc->display(); if ($mode != 'all') { break; } case 'dump': $afc->dump(true); if ($mode != 'all') { break; } case 'get': echo c\L::ID . $afc->getId() . BR . c\L::NAME . $afc->getName() . BR . c\L::PATH . $afc->getPath() . BR . c\L::PROPERTY_NAME . $afc->getPropertyName() . BR . c\L::SITE_NAME . $afc->getSiteName() . BR . c\L::TYPE . $afc->getType() . BR . ""; $children = $afc->getChildren();
string(28) "group;group-multiple-first;0" [9]=> string(18) "group;group-single" [10]=> string(29) "group;group-multiple-second;0" } */ $block = $service->getAsset(a\DataBlock::TYPE, "1f21cf0c8b7ffe834c5fe91e6dde13c2"); $sd = $block->getStructuredData(); $sd->appendSibling("multiple-first;0")->createNInstancesForMultipleField(10, "multiple-first;0")->getHostAsset()->edit(); // renew the object $sd = $block->getStructuredData(); echo $sd->getNumberOfChildren(), BR; echo $sd->getNumberOfSiblings("multiple-first;0"), BR; echo u\StringUtility::boolToString($sd->isIdentifierOfFirstNode("multiple-second;1")), BR; echo u\StringUtility::boolToString($sd->isMultiple("multiple-second;1")), BR; $sd->removeLastSibling("multiple-first;0")->getHostAsset()->edit(); $sd = $block->getStructuredData(); $sd->swapData("multiple-first;0", "multiple-first;1")->getHostAsset()->edit(); $sd = $block->getStructuredData(); } catch (\Exception $e) { echo S_PRE . $e . E_PRE; } catch (\Error $er) { echo S_PRE . $er . E_PRE; } /* Useful code templates: u\ReflectionUtility::showMethodSignatures( "cascade_ws_utility\ReflectionUtility" ); u\ReflectionUtility::showMethodSignature(
<?php require_once 'auth_tutorial7.php'; use cascade_ws_AOHS as aohs; use cascade_ws_constants as c; use cascade_ws_asset as a; use cascade_ws_property as p; use cascade_ws_utility as u; use cascade_ws_exception as e; try { // test static method $id = "06e401898b7ffe83765c5582e367462b"; $block = a\Block::getBlock($service, $id); //->dump( true ); // no type info supplied echo a\Block::getBlockType($service, $id), BR; // get methods echo "Created by: ", $block->getCreatedBy(), BR, "Created on: ", $block->getCreatedDate(), BR, "Expiration folder ID: ", $block->getExpirationFolderId(), BR, "Expiration folder path: ", $block->getExpirationFolderPath(), BR, "Expiration folder recycled: ", u\StringUtility::boolToString($block->getExpirationFolderRecycled()), BR, "Last modified by: ", $block->getLastModifiedBy(), BR, "Last modified date: ", $block->getLastModifiedDate(), BR, "Metadata set ID: ", $block->getMetadataSetId(), BR, "Metadata set path: ", $block->getMetadataSetPath(), BR; u\DebugUtility::dump($block->getDynamicFields()); u\DebugUtility::dump($block->getMetadataStdClass()); echo u\ReflectionUtility::getClassDocumentation("cascade_ws_asset\\Block"); } catch (\Exception $e) { echo S_PRE . $e . E_PRE; } catch (\Error $er) { echo S_PRE . $er . E_PRE; }
function assetTreeSwitchDataDefinitionForBlock(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL) { global $common_assets_site_name; $type = $child->getType(); if ($type != a\DataBlock::TYPE) { return; } if (!isset($params["cascade"])) { throw new \Exception("The Cascade object is not supplied"); } else { $cascade = $params["cascade"]; } $block = $child->getAsset($service); $b_name = $block->getName(); if ($b_name == "_footer-contact") { $dd_name = "Footer Contact"; } elseif ($b_name == "_left-column") { $dd_name = "Left Column"; } elseif ($b_name == "_right-column") { $dd_name = "Right Column"; } elseif ($b_name == "_site-info") { $dd_name = "Site Info"; } else { return; } $dd = $cascade->getAsset(a\DataDefinition::TYPE, $dd_name, $common_assets_site_name); $st = new p\StructuredData($dd->getStructuredData(), $service, $dd->getId()); $identifiers = $block->getIdentifiers(); foreach ($identifiers as $identifier) { // create the correct number of instances for multiple field if (u\StringUtility::endsWith($identifier, ";0") && $st->hasIdentifier($identifier)) { $st->createNInstancesForMultipleField($block->getNumberOfSiblings($identifier), $identifier); } // map the data if ($st->hasNode($identifier) && $block->isTextNode($identifier)) { $st->setText($identifier, $block->getText($identifier)); } elseif ($st->hasNode($identifier) && $block->isAssetNode($identifier)) { $asset_node_type = $block->getAssetNodeType($identifier); if ($asset_node_type == "page" && $block->getPageId($identifier) != null) { $st->setPage($identifier, $cascade->getPage($block->getPageId($identifier))); } elseif ($asset_node_type == "file" && $block->getFileId($identifier) != null) { $st->setFile($identifier, $cascade->getFile($block->getFileId($identifier))); } elseif ($asset_node_type == "block" && $block->getBlockId($identifier) != null) { $st->setBlock($identifier, a\Block::getBlock($service, $block->getBlockId($identifier))); } elseif ($asset_node_type == "page,file,symlink" && $block->getLinkableId($identifier) != null) { $st->setLinkable($identifier, a\Linkable::getLinkable($service, $block->getLinkableId($identifier))); } } } $block->setStructuredData($st); }
$new_sd = $new_dd->getStructuredDataObject(); $map = array("header" => "content-group;h1", "wysiwyg" => "content-group;content", "sports" => "hobby-group;hobby"); foreach ($map as $old_node => $new_node) { // step 2: copy data from non-multiple nodes if ($dd_block->isText($old_node)) { if ($dd_block->isTextBox($old_node) || $dd_block->isWYSIWYG($old_node)) { $new_sd->setText($new_node, $dd_block->getText($old_node)); } elseif ($dd_block->isCheckbox($old_node)) { // get default value of the radio $attrs = $new_dd->getField($new_node); $default_val = $attrs["default"]; // use default if ($dd_block->getText($old_node) == "") { $new_sd->setText($default_val); } else { $str_array = u\StringUtility::getExplodedStringArray(";", $dd_block->getText($old_node)); $new_val = $str_array[0]; $new_val = substr($new_val, 24); // cut out prefix $new_sd->setText($new_node, $new_val); } } } } // step 3: multiple nodes $num_of_nodes = $dd_block->getNumberOfSiblings("text4;0"); $new_sd->createNInstancesForMultipleField($num_of_nodes, "hobby-group;text4;0"); for ($i = 0; $i < $num_of_nodes; $i++) { $new_sd->setText("hobby-group;text4;" . $i, $dd_block->getText("text4;" . $i)); } $dd_block->setStructuredData($new_sd);
function assetTreeSwitchPageContentType(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$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"); } // pages to skip if (isset($params['skip'])) { $skip = $params['skip']; } if (in_array($child->getPathPath(), $skip)) { return; } $ct = $params['ct']; $bp = $params['bp']; // 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($child->getPathPath(), '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 $sd_new->setText("main-content-title", $sd_old->getText("main-content-title")); // 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); }
require_once 'auth_tutorial7.php'; use cascade_ws_AOHS as aohs; use cascade_ws_constants as c; use cascade_ws_asset as a; use cascade_ws_property as p; use cascade_ws_utility as u; use cascade_ws_exception as e; try { $ms = $cascade->getAsset(a\MetadataSet::TYPE, "06d5db638b7ffe83765c5582062dd782"); $dmfd = $ms->getDynamicMetadataFieldDefinition("languages"); u\DebugUtility::dump($dmfd->getPossibleValues()); // multiselect $english = $dmfd->getPossibleValue("English"); echo u\StringUtility::boolToString($english->getSelectedByDefault()), BR; foreach ($dmfd->getPossibleValues() as $pv) { echo $pv->getValue(), BR; } $dmfd->getPossibleValue("Japanese")->setSelectedByDefault(true); u\DebugUtility::dump($dmfd->toStdClass()); echo u\StringUtility::boolToString($dmfd->hasPossibleValue("Spanish")), BR; // radio $dmfd = $ms->getDynamicMetadataFieldDefinition("gender"); $dmfd->getPossibleValue("Female")->setSelectedByDefault(false); $dmfd->getPossibleValue("Male")->setSelectedByDefault(true); u\DebugUtility::dump($dmfd->toStdClass()); u\DebugUtility::dump($dmfd->getPossibleValue("Female")->toStdClass()); } catch (\Exception $e) { echo S_PRE . $e . E_PRE; } catch (\Error $er) { echo S_PRE . $er . E_PRE; }
echo $af->setDescription("blah")->edit()->dump(); //u\DebugUtility::dump( $service->getLastResponse() ); switch ($mode) { case 'all': case 'display': $af->display(); if ($mode != 'all') { break; } case 'dump': $af->dump(true); if ($mode != 'all') { break; } case 'get': echo c\L::ID . $af->getId() . BR . c\L::NAME . $af->getName() . BR . c\L::PATH . $af->getPath() . BR . c\L::PROPERTY_NAME . $af->getPropertyName() . BR . c\L::SITE_NAME . $af->getSiteName() . BR . c\L::TYPE . $af->getType() . BR . "Allow subfolder placement: " . u\StringUtility::boolToString($af->getAllowSubfolderPlacement()) . BR . "Applicable groups: " . u\StringUtility::getCoalescedString($af->getApplicableGroups()) . BR . "Asset type: " . $af->getAssetType() . BR . "Base asset ID: " . u\StringUtility::getCoalescedString($af->getBaseAssetId()) . BR . "Base asset path: " . u\StringUtility::getCoalescedString($af->getBaseAssetPath()) . BR . "Base asset recycled: " . u\StringUtility::boolToString($af->getBaseAssetRecycled()) . BR . "Folder placement position: " . $af->getFolderPlacementPosition() . BR . "Overwrite: " . u\StringUtility::boolToString($af->getOverwrite()) . BR . c\L::PARENT_CONTAINER_ID . $af->getParentContainerId() . BR . c\L::PARENT_CONTAINER_PATH . $af->getParentContainerPath() . BR . "Placement folder ID: " . u\StringUtility::getCoalescedString($af->getPlacementFolderId()) . BR . "Placement folder path: " . u\StringUtility::getCoalescedString($af->getPlacementFolderPath()) . BR . "Placement folder recycled: " . u\StringUtility::boolToString($af->getPlacementFolderRecycled()) . BR . c\L::SITE_ID . $af->getSiteId() . BR . c\L::SITE_NAME . $af->getSiteName() . BR . "Workflow definition ID: " . u\StringUtility::getCoalescedString($af->getWorkflowDefinitionId()) . BR . "Workflow definition path: " . u\StringUtility::getCoalescedString($af->getWorkflowDefinitionPath()) . BR . "Workflow mode: " . $af->getWorkflowMode() . BR; if ($af->hasPlugin(a\AssetFactory::FILE_LIMIT_PLUGIN)) { u\DebugUtility::dump($af->getPlugin(a\AssetFactory::FILE_LIMIT_PLUGIN)); } u\DebugUtility::dump($af->getPluginNames()); u\DebugUtility::dump($af->getPluginStd()); if ($mode != 'all') { break; } case 'set': $group_name = "cru"; $group = a\Asset::getAsset($service, a\Group::TYPE, $group_name); $af->addGroup($group)->edit(); if ($af->isApplicableToGroup($group)) { echo "Applicable to ", $group->getName(), BR; } else {
public function isIdentifierOfFirstNode($identifier) { if ($this->isMultiple($identifier)) { return u\StringUtility::endsWith($identifier, ";0"); } return false; }
public function republishFailedJobs(Cascade $cascade, Destination $destination) { echo $this->type . BR; echo $this->num_jobs_with_errors . BR; if ($this->type == self::TYPE_PUBLISH && $this->num_jobs_with_errors > 0) { foreach ($this->msg_errors as $error) { try { list($destination, $site, $path) = u\StringUtility::getExplodedStringArray("\t", $error); //$destination = trim( $destination, "[]" ); $site = trim($site, ":"); // ignore destinations if ($site != "" && $path != "") { $cascade->getAsset(Page::TYPE, $path, $site)->publish($destination); } } catch (\Exception $e) { echo "Failed to republish failed job" . BR; echo S_PRE . $e . E_PRE; continue; } } } return $this; }
public static function assetTreeReportRelativeLink(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL) { if (!isset($params['cache'])) { throw new e\ReportException(S_SPAN . c\M::NULL_CACHE . E_SPAN); } $cache = $params['cache']; $type = $child->getType(); if ($type != DataDefinitionBlock::TYPE && $type != Page::TYPE && $type != File::TYPE) { return; } $asset = $cache->retrieveAsset($child); // .css and .js only // example: href="/com/index.php $pattern1 = "/href=[\"']\\/(\\S)+\\.php[\"']/"; // example: /com/index.php $pattern2 = "/^\\/(\\S)+\\.php\$/"; if ($type == File::TYPE) { $filename = $asset->getName(); if (u\StringUtility::endsWith($filename, '.css') || u\StringUtility::endsWith($filename, '.js')) { $pattern3 = "/url\\(\\//"; $pattern4 = "/url\\(\"\\//"; $pattern5 = "/url\\('\\//"; $matches = array(); preg_match($pattern3, $asset->getData(), $matches); if (isset($matches[0])) { $results[$type][] = $child->getPathPath(); return; } $matches = array(); preg_match($pattern4, $asset->getData(), $matches); if (isset($matches[0])) { $results[$type][] = $child->getPathPath(); return; } $matches = array(); preg_match($pattern5, $asset->getData(), $matches); if (isset($matches[0])) { $results[$type][] = $child->getPathPath(); return; } } } else { if ($asset->hasStructuredData()) { $identifiers = $asset->getIdentifiers(); $count = count($identifiers); if ($count > 0) { foreach ($identifiers as $identifier) { if ($asset->isWYSIWYG($identifier)) { $matches = array(); preg_match($pattern1, $asset->getText($identifier), $matches); if (isset($matches[0])) { $results[$type][] = $child->getPathPath(); return; } } else { $matches = array(); preg_match($pattern2, $asset->getText($identifier), $matches); if (isset($matches[0])) { $results[$type][] = $child->getPathPath(); return; } } } } } else { $matches = array(); preg_match($pattern1, $asset->getXhtml(), $matches); if (isset($matches[0])) { $results[$type][] = $child->getPathPath(); return; } } } }
// folder-index $ifb = $cascade->getAsset(a\IndexBlock::TYPE, $id); switch ($mode) { case 'all': case 'display': $ifb->display(); if ($mode != 'all') { break; } case 'dump': $ifb->dump(true); if ($mode != 'all') { break; } case 'get': echo c\L::ID . $ifb->getId() . BR . "Index type: " . $ifb->getIndexBlockType() . BR . "Append calling page data: " . u\StringUtility::boolToString($ifb->getAppendCallingPageData()) . BR . "Depth of index: " . $ifb->getDepthOfIndex() . BR . "Index access rights: " . u\StringUtility::boolToString($ifb->getIndexAccessRights()) . BR . "Index blocks: " . u\StringUtility::boolToString($ifb->getIndexBlocks()) . BR . "Indexed content type ID: " . u\StringUtility::getCoalescedString($ifb->getIndexedContentTypeId()) . BR . "Indexed content type path: " . u\StringUtility::getCoalescedString($ifb->getIndexedContentTypePath()) . BR . "Indexed folder ID: " . u\StringUtility::getCoalescedString($ifb->getIndexedFolderId()) . BR . "Indexed folder path: " . u\StringUtility::getCoalescedString($ifb->getIndexedFolderPath()) . BR . "Indexed folder recycled: " . u\StringUtility::boolToString($ifb->getIndexedFolderRecycled()) . BR . "Index files: " . u\StringUtility::boolToString($ifb->getIndexFiles()) . BR . "Index links: " . u\StringUtility::boolToString($ifb->getIndexLinks()) . BR . "Index pages: " . u\StringUtility::boolToString($ifb->getIndexPages()) . BR . "Index regular content: " . u\StringUtility::boolToString($ifb->getIndexRegularContent()) . BR . "Index system metadata: " . u\StringUtility::boolToString($ifb->getIndexSystemMetadata()) . BR . "Index user info: " . u\StringUtility::boolToString($ifb->getIndexUserInfo()) . BR . "Index user metadata: " . u\StringUtility::boolToString($ifb->getIndexUserMetadata()) . BR . "Index workflow info: " . u\StringUtility::boolToString($ifb->getIndexWorkflowInfo()) . BR . "Max rendered assets: " . $ifb->getMaxRenderedAssets() . BR . "Page xml: " . $ifb->getPageXML() . BR . "Rendering behavior: " . $ifb->getRenderingBehavior() . BR . "Sort method: " . $ifb->getSortMethod() . BR . "Sort order: " . $ifb->getSortOrder() . BR . "Is content: " . u\StringUtility::boolToString($ifb->isContent()) . BR . "Is folder: " . u\StringUtility::boolToString($ifb->isFolder()) . BR; $ifb->getFolder()->dump(); if ($mode != 'all') { break; } case 'set': //$fid = '980d6d088b7f0856015997e451c5e052'; //$folder = $cascade->getAsset( a\Folder::TYPE, $fid ); $ifb->setDepthOfIndex(3)->edit()->dump(true); if ($mode != 'all') { break; } case 'raw': $ifb = $service->retrieve($service->createId(c\T::INDEXBLOCK, $id), c\P::INDEXBLOCK); echo S_PRE; var_dump($ifb);
echo "Tis true", BR; } else { echo "Tis false", BR; } if (u\StringUtility::stringToBool(0)) { echo "Tis true", BR; } else { echo "Tis false", BR; } if (u\StringUtility::stringToBool("")) { echo "Tis true", BR; } else { echo "Tis false", BR; } echo u\StringUtility::boolToString(true), BR; echo u\StringUtility::startsWith("Hello", "He") ? "yes" : "no", BR; echo u\StringUtility::startsWith("Hello", "e") ? "yes" : "no", BR; echo u\StringUtility::removeSiteNameFromPath("site://cascade-admin/web-services/api/utility-classes/debug-utility"), BR; echo u\StringUtility::getParentPathFromPath("/web-services/api/utility-classes/debug-utility"), BR; echo u\StringUtility::getNameFromPath("/web-services/api/utility-classes/debug-utility"), BR; echo u\StringUtility::getMethodName("structuredData"), BR; u\DebugUtility::dump(u\StringUtility::getExplodedStringArray(";", "this;0;that;3;these")); echo u\StringUtility::getFullyQualifiedIdentifierWithoutPositions("this;0;that;3;these"), BR; echo u\StringUtility::endsWith("Hello", "lo") ? "yes" : "no", BR; echo u\StringUtility::endsWith("Hello", "l") ? "yes" : "no", BR; echo u\ReflectionUtility::getClassDocumentation("cascade_ws_utility\\StringUtility", true); } catch (\Exception $e) { echo S_PRE . $e . E_PRE; } catch (\Error $er) { echo S_PRE . $er . E_PRE; }
private function applyFunctionsToChild(aohs\AssetOperationHandlerService $service, p\Child $child, $function_array, $params = NULL, &$results = NULL) { $type = $child->getType(); // match the type first if (isset($function_array[$type])) { $functions = $function_array[$type]; $func_count = count($functions); for ($i = 0; $i < $func_count; $i++) { if ($functions[$i] == NULL) { continue; } // class static method if (strpos($functions[$i], "::") !== false) { $method_array = u\StringUtility::getExplodedStringArray(":", $functions[$i]); $class_name = $method_array[0]; $class_name = Asset::NAME_SPACE . "\\" . $class_name; $method_name = $method_array[1]; if (!method_exists($class_name, $method_name)) { throw new e\NoSuchFunctionException("The function " . $functions[$i] . " does not exist."); } } else { if (!function_exists($functions[$i])) { throw new e\NoSuchFunctionException("The function " . $functions[$i] . " does not exist."); } } } // apply function with parameters and results array for ($i = 0; $i < $func_count; $i++) { if ($functions[$i] == NULL) { continue; } if (strpos($functions[$i], "::") !== false) { $method_array = u\StringUtility::getExplodedStringArray(":", $functions[$i]); $class_name = $method_array[0]; $class_name = Asset::NAME_SPACE . "\\" . $class_name; $method_name = $method_array[1]; $class_name::$method_name($service, $child, $params, $results); } else { $func_name = $functions[$i]; $func_name($service, $child, $params, $results); } } } }
public static function setMetadataSet(Cascade $target_cascade, Site $source_site, Site $target_site, Asset $source_asset, Asset $target_asset, $exception_thrown = true) { // get metadata set $source_ms = $source_asset->getMetadataSet(); $source_ms_path = u\StringUtility::removeSiteNameFromPath($source_ms->getPath()); $source_ms_site = $source_ms->getSiteName(); $target_ms_site = $source_ms_site; if ($exception_thrown) { try { $ms = $target_cascade->getAsset(MetadataSet::TYPE, $source_ms_path, $target_ms_site); $target_asset->setMetadataSet($ms); } catch (\Exception $e) { $msg = "The metadata set {$source_ms_path} does not exist in {$target_ms_site}. "; throw new e\CascadeInstancesErrorException(S_SPAN . $msg . E_SPAN . $e); } } else { $ms = $target_cascade->getMetadataSet($source_ms_path, $target_ms_site); if (isset($ms)) { $target_asset->setMetadataSet($ms); } } // set metadata if (isset($ms)) { try { $m = $source_asset->getMetadata(); $target_asset->setMetadata($m); $source_metadata = $source_asset->getMetadata(); $target_metadata = $target_asset->getMetadata(); $target_metadata->setAuthor($source_metadata->getAuthor())->setDisplayName($source_metadata->getDisplayName())->setEndDate($source_metadata->getEndDate())->setKeywords($source_metadata->getKeywords())->setMetaDescription($source_metadata->getMetaDescription())->setReviewDate($source_metadata->getReviewDate())->setStartDate($source_metadata->getStartDate())->setSummary($source_metadata->getSummary())->setTeaser($source_metadata->getTeaser())->setTitle($source_metadata->getTitle()); $fields = $source_metadata->getDynamicFieldNames(); $count = count($fields); if ($count > 0) { foreach ($fields as $field) { $target_metadata->setDynamicField($field, $source_metadata->getDynamicFieldValues($field)); } } $target_asset->edit(); } catch (\Exception $e) { throw new e\CascadeInstancesErrorException($e . BR . S_SPAN . "Path: " . $source_asset->getPath() . E_SPAN); } } }
$rmsc = $cascade->getAsset(a\MetadataSetContainer::TYPE, $id); u\DebugUtility::dump($rmsc->getParentContainer()); // NULL // metadata set container $id = 'e10375238b7ffe8364375ac7a41ad6e3'; $msc = $cascade->getAsset(a\MetadataSetContainer::TYPE, $id); $msc->getParentContainer()->display(); // folder $id = '38906a9f8b7ffe83164c9314b9bdebfd'; $f = $cascade->getAsset(a\Folder::TYPE, $id); $f->getParentContainer()->display(); // data definition $id = '38a20d858b7ffe83164c931479486e6f'; $dd = $cascade->getAsset(a\DataDefinition::TYPE, $id); $dd->getParentContainer()->display(); echo $dd->getParentContainerId(), BR, $dd->getParentContainerPath(), BR; echo u\StringUtility::boolToString($dd->isDescendantOf($msc)), BR; if ($mode != 'all') { break; } case 'raw': if ($mode != 'all') { break; } } echo u\ReflectionUtility::getClassDocumentation("cascade_ws_asset\\ContainedAsset"); } catch (\Exception $e) { echo S_PRE . $e . E_PRE; } catch (\Error $er) { echo S_PRE . $er . E_PRE; }
$dmfd->appendValue("Chinese"); $ms->edit(); $dmfd->swapValues("Chinese", "Japanese"); $ms->edit(); if ($dmfd->hasDefaultValue()) { u\DebugUtility::dump($dmfd->getDefaultValue()->toStdClass()); u\DebugUtility::out($dmfd->getDefaultValueString()); } u\DebugUtility::out($dmfd->getFieldType()); u\DebugUtility::out($dmfd->getLabel()); u\DebugUtility::out($dmfd->getName()); u\DebugUtility::dump($dmfd->getPossibleValues()); u\DebugUtility::dump($dmfd->getPossibleValueStrings()); u\DebugUtility::dump(u\StringUtility::boolToString($dmfd->getRequired())); u\DebugUtility::dump($dmfd->getVisibility()); u\DebugUtility::dump(u\StringUtility::boolToString($dmfd->hasPossibleValue("Spanish"))); $dmfd->removeValue("Chinese"); $ms->edit()->dump(); $dmfd->setLabel("Languages"); $ms->edit()->dump(); $dmfd->setRequired(true); $ms->edit()->dump(); $dmfd->unsetSelectedByDefault("Japanese"); $ms->edit()->dump(); // radio $dmfd = $ms->getDynamicMetadataFieldDefinition("gender"); $dmfd->setSelectedByDefault("Male"); u\DebugUtility::dump($dmfd->toStdClass()); $ms->edit()->dump(); $dmfd->setVisibility(c\T::VISIBLE); $ms->edit()->dump();
echo $tb->getPropertyName() . BR; //u\DebugUtility::dump( $tb->getService() ); echo $tb->getSiteId() . BR; echo $tb->getSiteName() . BR; u\DebugUtility::dump($tb->getSubscribers()); echo $tb->getType() . BR; echo $tb->getText() . BR; echo $tb->getLastModifiedBy() . BR; echo $tb->getLastModifiedDate() . BR; // folder //$tb->getParentContainer()->dump( true ); echo $tb->getParentContainerId() . BR; echo $tb->getParentContainerPath() . BR; echo u\StringUtility::getCoalescedString($tb->getExpirationFolderId()), BR; echo u\StringUtility::getCoalescedString($tb->getExpirationFolderPath()), BR; echo u\StringUtility::boolToString($tb->getExpirationFolderRecycled()), BR; if ($mode != 'all') { break; } case 'metadata': echo $tb->getCreatedBy() . BR; echo $tb->getCreatedDate() . BR; $field_name = "text"; if ($tb->hasDynamicField($field_name)) { $df = $tb->getDynamicField($field_name); } else { echo "The dynamic field {$field_name} does not exist", BR; } if ($tb->hasDynamicFields()) { u\DebugUtility::dump($tb->getDynamicFields()); } else {
{ echo "The default config is publishable" . BR; } else { echo "The default config is not publishable" . BR; } */ //u\DebugUtility::dump( $pcs->getPageConfigurations() ); //$pcs->getPageConfigurationTemplate( "PDF" )->dump(); //u\DebugUtility::dump( $pcs->getPageRegionNames( "Mobile" ) ); //u\DebugUtility::dump( $pcs->getPageRegion( "Mobile", "DEFAULT" ) ); //u\DebugUtility::dump( $pcs->getPageRegion( "Mobile", "DEFAULT" ) ); //echo $pcs->getSerializationType( "PDF" ), BR; echo u\StringUtility::boolToString($pcs->hasPageConfiguration("XML")), BR; echo u\StringUtility::boolToString($pcs->hasPageRegion("Mobile", "DEFAULT")), BR; if ($mode != 'all') { break; } case 'set': /* $pcs->setConfigurationPageRegionBlock( 'Mobile', 'DEFAULT', $cascade->getAsset( a\DataBlock::TYPE, 'c23e62358b7f0856002a5e11909ccae3' ) )->edit(); $pcs->setConfigurationPageRegionFormat( 'Mobile', 'DEFAULT', $cascade->getAsset( a\XsltFormat::TYPE, '404872688b7f0856002a5e11bb8c8642' )
try { // create an identifier stdClass object $id_std = $service->createId(a\Folder::TYPE, "cc1e51808b7ffe8364375ac78ba27f05"); u\DebugUtility::dump($id_std); // create a Child object $id_child = new p\Child($id_std); u\DebugUtility::dump($id_child); u\DebugUtility::dump($id_child->toStdClass()); // read the asset $folder = $id_child->getAsset($service); // list the content of the folder $children = $folder->getChildren(); u\DebugUtility::dump($children); // display each child foreach ($children as $child) { $child->display(); echo $child->getId(), BR; echo $child->getType(), BR; echo $child->getPathPath(), BR; echo $child->getPathSiteId(), BR; echo u\StringUtility::getCoalescedString($child->getPathSiteName()), BR; echo u\StringUtility::boolToString($child->getRecycled()), BR; u\DebugUtility::dump($child->getPath()->toStdClass()); } u\ReflectionUtility::showMethodSignatures("cascade_ws_property\\Identifier"); u\ReflectionUtility::showMethodSignatures("cascade_ws_property\\Path"); } catch (\Exception $e) { echo S_PRE . $e . E_PRE; } catch (\Error $er) { echo S_PRE . $er . E_PRE; }
require_once 'auth_tutorial7.php'; use cascade_ws_constants as c; use cascade_ws_asset as a; use cascade_ws_property as p; use cascade_ws_utility as u; use cascade_ws_exception as e; try { $cascade->getAsset(a\Page::TYPE, "389b03188b7ffe83164c931405d3704f")->dump(); u\DebugUtility::out(u\StringUtility::boolToString($cascade->getAsset(a\DataBlock::TYPE, "ffa200f88b7ffe8330d802d73f3adfc3")->getMetadata()->isDynamicMetadataFieldRequired("checkbox"))); $block_id = "388f033b8b7ffe83164c9314c23a3f8f"; $block = $cascade->getAsset(a\FeedBlock::TYPE, $block_id); $m = $block->getMetadata(); u\DebugUtility::out(u\StringUtility::boolToString($m->isAuthorFieldRequired())); u\DebugUtility::out(u\StringUtility::boolToString($m->isDescriptionFieldRequired())); // wired fields echo "Author: ", $m->getAuthor(), BR, "Display name: ", $m->getDisplayName(), BR, "End date: ", u\StringUtility::getCoalescedString($m->getEndDate()), BR . HR; // dynamic fields $ms = $block->getMetadataSet(); // text $field_name = "text"; echo "Testing {$field_name}", BR; if ($m->hasDynamicField($field_name)) { $text = $m->getDynamicField($field_name); u\DebugUtility::dump($text->getFieldValue()->getValues()); // passing in a single string as value $m->setDynamicFieldValue($field_name, "New string used in text"); } // radio /* <radio> <item>Male</item>
// to prevent time-out set_time_limit(10000); // to prevent using up memory when traversing a large site ini_set('memory_limit', '2048M'); use cascade_ws_AOHS as aohs; use cascade_ws_constants as c; use cascade_ws_asset as a; use cascade_ws_property as p; use cascade_ws_utility as u; use cascade_ws_exception as e; try { $formats_folder = $cascade->getAsset(a\Folder::TYPE, "formats", $site_name); $velocity_folder = $cascade->getAsset(a\Folder::TYPE, "formats/library/velocity", $site_name); $library_format_names = array("chanw_database_utilities", "chanw_global_deque", "chanw_global_queue", "chanw_global_stack", "chanw_global_utility_objects", "chanw_global_values", "chanw_global_values_code", "chanw_global_velocity_code", "chanw_html_builder", "chanw_html_builder_with_deque", "chanw_library_import", "chanw_object_creator", "chanw_process_index_block", "chanw_process_xml", "chanw_reflect_utilities", "chanw_sorted_pages", "chanw_structured_data_worker", "upstate_database"); foreach ($library_format_names as $library_format_name) { if (u\StringUtility::endsWith($library_format_name, "_code")) { $asset = $cascade->getAsset(a\XmlBlock::TYPE, $velocity_folder->getPath() . "/" . $library_format_name, $site_name); $block = true; } else { $asset = $cascade->getAsset(a\ScriptFormat::TYPE, $velocity_folder->getPath() . "/" . $library_format_name, $site_name); $block = false; } $source_path = $source . $library_format_name . ".xml"; $source_content = file_get_contents($source_path); if ($source_content != "") { if ($block) { $source_content = str_replace("_common_assets", $site_name, $source_content); $asset->setXml($source_content)->edit(); } else { $source_content = str_replace("<code>", "", $source_content); $source_content = str_replace("</code>", "", $source_content);