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;
                }
            }
        }
    }
}
 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;
 }
 public static function assetTreeUpdateXmlBlock(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL)
 {
     if (isset($params['target-cascade'])) {
         $target_cascade = $params['target-cascade'];
     } else {
         echo c\M::TARGET_CASCADE_NOT_SET . BR;
         return;
     }
     if (isset($params['source-site'])) {
         $source_site = $params['source-site'];
     } else {
         echo c\M::SOURCE_SITE_NOT_SET . BR;
         return;
     }
     if (isset($params['target-site'])) {
         $target_site = $params['target-site'];
     } else {
         echo c\M::TARGET_SITE_NOT_SET . BR;
         return;
     }
     if (isset($params['exception-thrown'])) {
         $exception_thrown = $params['exception-thrown'];
     } else {
         echo c\M::EXCEPTION_THROWN_NOT_SET . BR;
         return;
     }
     $source_block = $child->getAsset($service);
     $source_content = $source_block->getXml();
     $source_block_path = u\StringUtility::removeSiteNameFromPath($source_block->getPath());
     $source_block_path_array = u\StringUtility::getExplodedStringArray("/", $source_block_path);
     $source_block_path = $source_block_path_array[count($source_block_path_array) - 1];
     $source_block_parent_path = $source_block->getParentContainerPath();
     // create block
     $target_site_name = $target_site->getName();
     // parent must be there
     $target_parent = $target_cascade->getAsset(Folder::TYPE, $source_block_parent_path, $target_site_name);
     $target_block = $target_cascade->createXmlBlock($target_parent, $source_block_path, $source_content);
     // if asset already exists containing different xml, update xml
     $target_content = $target_block->getXml();
     try {
         if ($source_content != $target_content) {
             $target_block->setXml($source_content, $exception_thrown)->edit();
         }
     } catch (\Exception $e) {
         throw new e\CascadeInstancesErrorException($e . BR . S_SPAN . "Path: " . $target_block->getPath() . E_SPAN);
     }
     // metadata
     self::setMetadataSet($target_cascade, $source_site, $target_site, $source_block, $target_block, $exception_thrown);
 }
 $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);
        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 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 function removeUserName($u_name)
 {
     if ($this->hasUserName($u_name)) {
         $user_array = u\StringUtility::getExplodedStringArray(self::DELIMITER, $this->getUsers());
         $temp = array();
         foreach ($user_array as $user) {
             if ($user != $u_name) {
                 $temp[] = $user;
             }
         }
         $this->getProperty()->users = implode(self::DELIMITER, $temp);
     }
     return $this;
 }