本文整理汇总了PHP中XMLParser::getXMLdataValues方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLParser::getXMLdataValues方法的具体用法?PHP XMLParser::getXMLdataValues怎么用?PHP XMLParser::getXMLdataValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMLParser
的用法示例。
在下文中一共展示了XMLParser::getXMLdataValues方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRootfolderByModule
public static function getRootfolderByModule($module)
{
$found = false;
$searchModule = $module;
if (strtolower($searchModule) == 'tag') {
$searchModule = 'admin';
}
$formFile = sfConfig::get('sf_root_dir') . "/config/form.xml";
if (is_readable($formFile)) {
$objects = XMLParser::getXMLdataValues($formFile);
foreach ($objects as $obj) {
if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'open') {
if (strtoupper($obj['attributes']['MODULE']) == strtoupper($searchModule)) {
$found = true;
break;
}
}
}
}
if (!$found) {
//echo "getRootfolderByModule($module): not_found!";
return null;
}
try {
$c = new Criteria();
$c->add(RootfolderPeer::LABEL, $module);
$c->addOr(RootfolderPeer::LABEL, ucfirst($module));
$rootFolder = RootfolderPeer::doSelectOne($c);
if (!$rootFolder) {
$rootFolder = new Rootfolder();
$rootFolder->setLabel(ucfirst($module));
$rootFolder->save();
}
return $rootFolder;
} catch (Exception $e) {
throw $e;
}
}
示例2: executeIndex
public function executeIndex()
{
$this->setLayout("backend");
$subscriber = $this->getUser()->getSubscriber();
if (!$subscriber || $subscriber->getBackend() != 1) {
$this->forward("user", "login");
}
$this->refresh = $this->getRequestParameter("refresh");
$this->model = $this->getRequestParameter("model");
$this->id = $this->getRequestParameter("id");
$this->parent = $this->getRequestParameter("parent");
$this->err = $this->getRequestParameter("err");
$this->mainMenu = $this->getPresentationFor('admin', 'backendMainMenu');
$this->contextMenus = $this->getPresentationFor('admin', 'contextMenus');
$this->currentModule = $this->getUser()->getAttribute('currentModule');
$filters = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/apps/backend/config/backendFilters.xml");
$i = 0;
$y = 0;
$moduleFilters = array();
foreach ($filters as $filter) {
if ($filter['tag'] == 'MODULE' && $filter['type'] == 'open') {
$i++;
$y = 0;
$f = array();
$name = null;
$name = $filter['attributes']['NAME'];
}
if ($filter['tag'] == 'FILTER' && $filter['type'] == 'complete') {
$y++;
$f[$y]['name'] = $filter['attributes']['NAME'];
$f[$y]['pop'] = $filter['attributes']['POP'];
$f[$y]['value'] = str_replace("\"", "'", $filter['value']);
}
if ($filter['tag'] == 'MODULE' && $filter['type'] == 'close') {
$moduleFilters[$i]['moduleName'] = $name;
$moduleFilters[$i]['filters'] = $f;
}
}
$this->moduleFilters = $moduleFilters;
}
示例3: run_generate_cache
function run_generate_cache($task, $args)
{
ini_set("memory_limit", "2048M");
ini_set("display_errors", 1);
define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
define('SF_APP', 'frontend');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', false);
sfConfig::set("sf_use_relations_cache", false);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();
run_url_relations($task, $args);
run_tags_relations($task, $args);
echo_cms_title("GENERATING CACHE...");
if (!class_exists("XMLParser")) {
include sfConfig::get('sf_root_dir') . "/lib/tools/XMLParser.class.php";
}
if (!class_exists("FileHelper")) {
include sfConfig::get('sf_root_dir') . "/lib/helper/FileHelper.php";
}
//echo_cms_sep();
echo_cms("sf_cache_objects = " . sfConfig::get('sf_cache_objects'));
echo_cms("sf_cache_relations = " . sfConfig::get('sf_cache_relations'));
echo_cms("sf_cache_trees = " . sfConfig::get('sf_cache_trees'));
//echo_cms_sep();
if (count($args) > 0) {
$relationsFlag = substr($args[0], 0, 3) == "rel";
$listsFlag = substr($args[0], 0, 4) == "list";
$cacheModel = $args[0];
if (is_numeric($cacheModel)) {
$obj = Document::getDocumentInstance($cacheModel);
if ($obj) {
$phpName = get_class($obj);
} else {
echo_cms_error("Object with ID=" . $cacheModel . " not found!");
exit;
}
}
}
// parse schema file to make Schema.class.php
$objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/schema.xml");
$schemaFile = sfConfig::get('sf_root_dir') . "/config/Schema.class.php";
$content = $content = "<?php\n class Schema\n{\n\n";
echo_cms("Building " . $schemaFile . "... ");
foreach ($objects as $obj) {
if ($obj['tag'] == 'TABLE' && $obj['type'] == 'open') {
$table = $obj['attributes']['PHPNAME'];
if ($phpName && $phpName == $table) {
$tableName = $obj['attributes']['NAME'];
}
$trees = explode(",", $obj['attributes']['TREE']);
$content .= "\tpublic static function get" . $table . "Trees()\n\t{\n";
$content .= "\t\treturn array(";
foreach ($trees as $tree) {
$content .= "'" . strtolower($tree) . "', ";
}
$content = substr($content, 0, -2);
$content .= ");\n\t}\n\n";
$content .= "\tpublic static function get" . $table . "Properties()\n\t{\n";
$content .= "\t\treturn array(";
}
if ($obj['tag'] == 'COLUMN' && $obj['type'] == 'complete') {
$property = $obj['attributes']['NAME'];
$getProperty = UtilsHelper::convertFieldName($property);
$content .= "'" . $getProperty . "', ";
}
if ($obj['tag'] == 'TABLE' && $obj['type'] == 'close') {
$content = substr($content, 0, -2);
$content .= ");\n\t}\n\n";
}
}
$content .= "\n}";
//echo_cms_sep();
if (FileHelper::writeFile($schemaFile, $content)) {
echo_cms($schemaFile . " writen successfully!");
} else {
echo_cms_error("Error writing " . $schemaFile . "!");
}
echo "\n";
//echo_cms_sep();
if (substr($args[0], 0, 5) == "schema") {
echo_cms(" Done!");
exit;
}
if (!$relationsFlag && !$listsFlag) {
try {
if (is_numeric($cacheModel)) {
$obj = array();
$obj['tag'] = 'OBJECT';
$obj['type'] = 'complete';
$obj['id'] = $cacheModel;
$objects = array($obj);
$exit = true;
} elseif ($cacheModel) {
$obj = array();
$obj['tag'] = 'OBJECT';
$obj['type'] = 'complete';
$obj['value'] = $cacheModel;
$objects = array($obj);
//.........这里部分代码省略.........
示例4: executeGetRichtextFields
public function executeGetRichtextFields()
{
$this->setLayout(false);
$template = $this->getRequestParameter('template');
$templateFile = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'website' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.xml';
if (!is_file($templateFile)) {
$templateFile = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'website' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $template . '.xml';
}
$tags = XMLParser::getXMLdataValues($templateFile);
// CREATING PREDEFINED RICHTEXT FIELDS
$richtextCnt = 0;
$richtextBoxes = array();
foreach ($tags as $tag) {
if ($tag['tag'] == 'DESTINATION' && $tag['type'] == 'complete' && $tag['attributes']['TYPE'] == 'richtext') {
$richtextCnt++;
$richtextBoxes[$richtextCnt] = $tag['attributes']['ID'];
}
}
$obj = Document::getDocumentInstance($this->getRequestParameter('id'));
if ($obj) {
$this->richtext = self::get_richtext($obj->getContent());
}
$this->obj = $obj;
$this->boxes = $richtextBoxes;
}
示例5: cacheObj
public static function cacheObj($document, $documentModel = null, $refreshTree = true, $parentId = null)
{
if (sfConfig::get('sf_cache_objects')) {
// parse cachedObjects and cache objects
$objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/cachedObjects.xml");
// check if documentModel is Cached
$foundModel = false;
if (is_null($documentModel)) {
$documentModel = get_class($document);
}
foreach ($objects as $obj) {
if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') {
if ($documentModel == $obj['value']) {
$foundModel = true;
}
}
}
// Caching Object if it's model is in "cachedObjects.xml" file
if ($foundModel) {
$docId = $document->getId();
$path = self::getCachePath($docId, true);
include_once sfConfig::get('sf_root_dir') . "/config/" . "/Schema.class.php";
$m = "get" . $documentModel . "Properties";
$properties = Schema::$m();
$content = "<?php\nclass CachedObj" . $docId . "\n{\n";
$content .= "\tpublic function __getDocumentModel(){\n\t\treturn \"" . $documentModel . "\";\n\t}\n";
foreach ($properties as $getProperty) {
$getter = "get" . ucfirst($getProperty);
$v = $document->{$getter}();
if (is_null($v)) {
$content .= "\tpublic function " . $getter . "(){\n\t\treturn NULL;\n\t}\n";
} else {
if ($documentModel == "Page" && $getProperty == "Content") {
$content .= "\tpublic function " . $getter . "(){\n\t\treturn \"" . str_replace(array('\\', '"'), array('\\\\', '\\"'), $v) . "\";\n\t}\n";
} else {
// delete <script> tags !!!
$v = preg_replace('@(<[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $v);
$v = preg_replace('@(<[ \\n\\r\\t]*/[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $v);
$content .= "\tpublic function " . $getter . "(){\n\t\treturn \"" . str_replace(array('\\', '"'), array('\\\\', '\\"'), $v) . "\";\n\t}\n";
}
}
/* else
{
$content .= "\tpublic function ".$getter."(){\n\t\treturn ".$v.";\n\t}\n";
}*/
}
if (!$parentId) {
$parentId = intval(self::getParentOf($docId, null, false, false));
}
$content .= "\tpublic function getParent(){\n\t\treturn {$parentId};\n\t}\n";
$content .= "}";
$cachefile = $path . "doc" . $docId . ".php";
if (file_exists($cachefile)) {
unlink($cachefile);
}
FileHelper::writeFile($cachefile, $content);
chmod($cachefile, 0777);
}
}
// Refreshing Tree - not related to CacheObject !!!
if (sfConfig::get('sf_cache_trees') && $refreshTree) {
/*
$modules = FileHelper::getSubElements(sfConfig::get('sf_root_dir')."/apps/backend/modules", "folder");
foreach ($modules as $module => $path)
*/
include_once sfConfig::get('sf_root_dir') . "/config/" . "/Schema.class.php";
$documentModel = get_class($document);
$getTree = "get" . $documentModel . "Trees";
$trees = Schema::$getTree();
foreach ($trees as $module) {
$module = strtolower($module);
// Caching Left, Right and MCE tree
BackendService::updateTree($module, $document, "UPDATE");
//BackendService::updateTree($module, $document, "UPDATE", "right");
BackendService::updateTree($module, $document, "UPDATE", "mce");
}
}
}
示例6: getMceTree
public static function getMceTree($moduleName)
{
$lmn = strtolower($moduleName);
$moduleName = ucfirst($lmn);
$htmlCacheFile = sfConfig::get('sf_root_dir') . "/cache/backend/" . $moduleName . "_mceTree.html";
if (is_readable($htmlCacheFile)) {
$content = file_get_contents($htmlCacheFile);
return $content;
}
$phpFile = sfConfig::get('sf_root_dir') . "/cache/backend/" . $moduleName . "_mceTree.php";
if (is_readable($phpFile)) {
return self::makeHtmlCache($moduleName, "mce");
}
$rightTree = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/apps/backend/modules/" . $lmn . "/config/mceTree.xml");
$displayedObjects = array();
foreach ($rightTree as $obj) {
if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') {
$displayedObjects[] = $obj['value'];
}
}
$document = Rootfolder::getRootfolderByModule($moduleName);
$docId = $document->getId();
$contentArr = self::makePhpArray($docId, $lmn, $displayedObjects);
// make Root element
$rootItem = array();
$rootItem[$docId]['id'] = $document->getId();
$rootItem[$docId]['model'] = 'rootfolder';
$rootItem[$docId]['class'] = $lmn . '_rootfolder';
$rootItem[$docId]['level'] = 0;
$rootItem[$docId]['label'] = addslashes($document->getLabel());
$contentArr = array_merge($rootItem, $contentArr);
return self::makePhpCache($contentArr, $moduleName, "mce");
}
示例7: getMainList
public static function getMainList(&$documentId, $moduleName, $page = 1)
{
$moduleName = strtolower($moduleName);
try {
if ($moduleName == "settings") {
$settingsArr = array();
if (is_readable(sfConfig::get('sf_root_dir') . "/config/settings.xml")) {
$objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/settings.xml");
}
foreach ($objects as $obj) {
if ($obj['tag'] == 'ELEMENT' && $obj['type'] == 'open') {
$objName = $obj['attributes']['LABEL'];
$objDescription = $obj['attributes']['DESCRIPTION'];
}
if ($obj['tag'] == 'ITEM' && $obj['type'] == 'complete') {
//$val = $obj['attributes']['VALUE'];
$settingName = $objName;
//$settingName = strtolower($objName);
$settingsArr[$settingName] = $objDescription;
}
}
$pager = new sfPropelPager("Relation", 20);
$pager->setResults($settingsArr);
$pager->setPage($page);
$pager->init();
foreach ($pager->getResults() as $name => $label) {
$res['children'][$name] = $label;
}
$res['paging'] = $pager->paging(true);
return $res;
}
if ($moduleName == "labels") {
$localesArr = array();
if (is_readable(sfConfig::get('sf_root_dir') . "/config/locales.xml")) {
$objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/locales.xml");
foreach ($objects as $obj) {
if ($obj['tag'] == 'LOCALE' && $obj['type'] == 'open') {
$objName = $obj['attributes']['LABEL'];
if ($obj['attributes']['DESCRIPTION']) {
$objDescription = $obj['attributes']['DESCRIPTION'];
} else {
$objDescription = '[' . $obj['attributes']['LABEL'] . ']';
}
}
if ($obj['tag'] == 'ITEM' && $obj['type'] == 'complete') {
//$val = $obj['attributes']['VALUE'];
$localeName = $objName;
//$localeName = strtolower($objName);
$localesArr[$localeName] = $objDescription;
}
}
}
$pager = new sfPropelPager("Relation", 20);
$pager->setResults($localesArr);
$pager->setPage($page);
$pager->init();
foreach ($pager->getResults() as $name => $label) {
$res['children'][$name] = $label;
}
$res['paging'] = $pager->paging(true);
return $res;
}
$mainList = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/apps/panel/modules/" . $moduleName . "/config/mainList.xml");
$displayedObjects = array();
$rootId = null;
foreach ($mainList as $obj) {
if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') {
$displayedObjects[] = $obj['value'];
}
// check overwrite RootID
if ($obj['tag'] == 'OBJECTS' && $obj['type'] == 'open') {
if (array_key_exists("attributes", $obj) && array_key_exists("PARENT", $obj['attributes'])) {
$rootName = $obj['attributes']['PARENT'];
$rootDocument = Rootfolder::getRootfolderByModule($rootName);
if ($rootDocument) {
$rootId = $rootDocument->getId();
}
}
if (array_key_exists("attributes", $obj) && array_key_exists("TAG", $obj['attributes'])) {
$tag = $obj['attributes']['TAG'];
$rootDocument = Document::getDocumentByExclusiveTag($tag);
if ($rootDocument) {
$rootId = $rootDocument->getId();
}
}
}
}
$children = array();
$res = array('children' => array(), 'paging' => '');
$c = new Criteria();
if (!$documentId) {
if ($rootId) {
$documentId = $rootId;
} else {
$document = Rootfolder::getRootfolderByModule($moduleName);
if ($document) {
$documentId = $document->getId();
}
}
}
//.........这里部分代码省略.........
示例8: getContent
private function getContent($backend = false)
{
$templateFile = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'website' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $this->pageDocument->getTemplate() . '.xml';
if (!is_file($templateFile)) {
$templateFile = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'website' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $this->pageDocument->getTemplate() . '.xml';
}
$tags = XMLParser::getXMLdataValues($templateFile, true, true);
$targets = XMLParser::getTargetsForTemplateBlocks($tags);
$content = '';
$processContent = false;
$freeCnt = 0;
if ($backend) {
$freeContentStr = 'free content...';
$richTextStr = 'Click here to edit richtext content...';
} else {
$freeContentStr = '';
}
// CREATING PREDEFINED RICHTEXT FIELDS
if ($this->pageDocument->getContent() === null) {
$richtextCnt = 0;
$richrextBoxes = '';
foreach ($tags as $tag) {
if ($tag['tag'] == 'LAYOUT' && $tag['type'] == 'open') {
$processContent = true;
continue;
}
if ($tag['tag'] == 'LAYOUT' && $tag['type'] == 'close') {
$processContent = false;
continue;
}
if ($processContent) {
if ($tag['type'] == 'complete') {
if (array_key_exists("attributes", $tag) && array_key_exists('ID', $tag['attributes']) && isset($targets[$tag['attributes']['ID']])) {
$templateType = $targets[$tag['attributes']['ID']]['type'];
if ($templateType == 'richtext') {
$richtextCnt++;
$richrextBoxes .= '<block id="richtext' . $richtextCnt . '" target="' . $tag['attributes']["ID"] . '" action="richtext"><![CDATA[<p></p>Click here to edit richtext content...<p></p>]]></block>';
}
}
}
}
}
if ($richrextBoxes) {
$richrextBoxes = '<?xml version="1.0" encoding="UTF-8"?><blocks>' . $richrextBoxes . '</blocks>';
}
$this->pageDocument->setContent($richrextBoxes);
$this->pageDocument->save();
}
foreach ($tags as $tag) {
if ($tag['tag'] == 'LAYOUT' && $tag['type'] == 'open') {
$processContent = true;
continue;
}
if ($tag['tag'] == 'LAYOUT' && $tag['type'] == 'close') {
$processContent = false;
continue;
}
if ($processContent) {
if ($tag['type'] == 'open') {
$content .= str_repeat(chr(9), $tag['level'] - 3) . '<' . $tag['tag'];
if (array_key_exists('attributes', $tag)) {
foreach ($tag['attributes'] as $key => $val) {
$content .= ' ' . strtolower($key) . '="' . $val . '"';
}
}
$content .= '>' . chr(10);
}
if ($tag['type'] == 'complete') {
$content .= str_repeat(chr(9), $tag['level'] - 3) . '<' . $tag['tag'];
if (array_key_exists("attributes", $tag)) {
foreach ($tag['attributes'] as $key => $val) {
$content .= ' ' . strtolower($key) . '="' . $val . '"';
}
}
$content .= '>' . chr(10);
//content here
if (array_key_exists("attributes", $tag) && array_key_exists('ID', $tag['attributes']) && isset($targets[$tag['attributes']['ID']])) {
if ($targets[$tag['attributes']['ID']]['type'] != 'free' && $targets[$tag['attributes']['ID']]['type'] != 'richtext') {
$component = explode('/', $targets[$tag['attributes']['ID']]['type']);
// check if defined BLOCK exists ---> checking if "execute<BlockName>" method exist in <module> class
$controler = $this->getController();
if ($controler->actionExists($component[0], $component[1])) {
// render block params
if (isset($targets[$tag['attributes']['ID']]['parameters'])) {
$arr = array();
$parameters = explode(' ', $targets[$tag['attributes']['ID']]['parameters']);
foreach ($parameters as $parameter) {
$param = explode('=', $parameter);
$arr[$param[0]] = $param[1];
}
$this->getRequest()->setParameter('params', $arr);
}
$content .= $this->getPresentationFor($component[0], $component[1]);
} else {
$content .= "<br>Block '" . $component[0] . "/" . $component[1] . "' doesn't exist!<br>";
}
} else {
$freeCnt++;
$blobData = $this->pageDocument->getContent();
if (!empty($blobData)) {
//.........这里部分代码省略.........
示例9: executeSavePageContent
public function executeSavePageContent()
{
$this->page = Document::getDocumentInstance($this->getRequestParameter('id'));
$content = '<?xml version="1.0" encoding="UTF-8"?>';
$content .= '<blocks>';
$data = $this->page->getContent();
if (!empty($data)) {
$blockContentsTags = XMLParser::getXMLdataValues($data, false, false);
}
foreach ($blockContentsTags as $block) {
if ($block["tag"] == "BLOCK") {
$content .= '<block id="' . $block['attributes']["ID"] . '" target="' . $block['attributes']["TARGET"] . '" action="' . $block['attributes']["ACTION"] . '"';
if (isset($block['attributes']["PARAMETERS"])) {
$content .= ' parameters="' . $block['attributes']["PARAMETERS"] . '"';
}
$content .= '>';
if ($this->getRequestParameter($block['attributes']["ID"])) {
$blockContent = $this->getRequestParameter($block['attributes']["ID"]);
if (substr($block['attributes']["ID"], 0, 8) == "richtext") {
$imgTags = explode('<img', $blockContent);
$imageFound = false;
$thumbDir = "richtext/" . $this->getRequestParameter('id') . "/" . substr($block['attributes']["ID"], 8);
$usedImg = array();
for ($i = 0; $i < count($imgTags); $i++) {
$imgParams = explode('/>', $imgTags[$i]);
$id = 0;
$thumb = "richtext";
foreach ($imgParams as $paramStr) {
$width = null;
$height = null;
$id = false;
if (strstr($paramStr, "width")) {
$width = strstr($paramStr, "width");
$width = substr($width, 7);
$pos = strpos($width, '"');
$width = substr($width, 0, $pos);
}
if (strstr($paramStr, "height")) {
$height = strstr($paramStr, "height");
$height = substr($height, 8);
$pos = strpos($height, '"');
$height = substr($height, 0, $pos);
}
if (strstr($paramStr, "id")) {
$id = strstr($paramStr, "id");
$id = substr($id, 4);
$pos = strpos($id, '"');
$id = substr($id, 0, $pos);
}
if ($id) {
$prefix = time();
if (strstr($paramStr, "src")) {
$src = strstr($paramStr, "src");
$src = substr($src, 5);
$pos = strpos($src, '"');
$src = substr($src, 0, $pos);
$parts = explode("/", $src);
if ($parts[6]) {
$prefix = $parts[6];
}
}
$img = Document::getDocumentInstance($id);
if ($img && get_class($img) == "Media" && $img->isImage()) {
if (empty($height) && empty($width)) {
list($width, $height) = getimagesize($img->getServerAbsoluteUrl());
}
$img->resizeImage($thumbDir, $height, $width, $prefix);
$imageFound = true;
$usedImg[] = SF_ROOT_DIR . "/www/media/upload/thumbs/" . $thumbDir . "/" . $id . "-" . $prefix . "." . $img->getExtention();
}
}
$id++;
}
$thumb = str_replace("/", "-", $thumbDir);
$replaceStr = 'src="/media/display/thumb/' . $thumb . '/freeimg/' . $prefix . '/id/';
$find = array('src="/media/display/id/', 'src="/media/display/thumb/thumbs/id/');
$replace = array($replaceStr, $replaceStr);
$blockParts[] = str_replace($find, $replace, $imgTags[$i]);
}
if ($imageFound) {
$blockContent = implode("<img ", $blockParts);
}
$blockContent = preg_replace('@(<[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $blockContent);
$blockContent = preg_replace('@(<[ \\n\\r\\t]*/[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $blockContent);
$files = FileHelper::getSubElements(SF_ROOT_DIR . "/www/media/upload/thumbs/" . $thumbDir, "file");
foreach ($files as $file) {
if (!in_array($file, $usedImg)) {
// delete RICHTEXT media
unlink($file);
// delete ORIGINAL media
$parts = explode(DIRECTORY_SEPARATOR, $file);
$delFile = array_pop($parts);
$delIdArr = explode("-", $delFile);
$delId = $delIdArr[0];
$imageToDelete = Document::getDocumentInstance($delId);
if ($imageToDelete) {
$imageToDelete->delete();
}
}
}
//.........这里部分代码省略.........