public static function getTags() { $ssArr = array(); $tagsCacheFile = self::$options['XML_ROOT'] . self::$options['tags.xml']; $xmlStr = file_exists($tagsCacheFile) ? file_get_contents($tagsCacheFile) : ''; if ($xmlStr) { $xmlFeed = Array_XML::xml2array($xmlStr, 'sections', true); if (isset($xmlFeed['section']) && is_array($xmlFeed['section'])) { Array_XML::makeListIfNotList($xmlFeed['section']); foreach ($xmlFeed['section'] as $section) { $name = !empty($section['@attributes']['name']) ? $section['@attributes']['name'] : false; if ($name && isset($section['tag']) && is_array($section['tag'])) { Array_XML::makeListIfNotList($section['tag']); $ssArr[$name] = array(); foreach ($section['tag'] as $subSection) { if (!empty($subSection['@attributes']['name']) && !empty($subSection['value'])) { $ssArr[$name][$subSection['@attributes']['name']] = array('title' => $subSection['value'], 'entry_count' => !empty($subSection['@attributes']['entry_count']) ? $subSection['@attributes']['entry_count'] : 0); } } } } } } return $ssArr; }
private function saveDo($settingsCopy) { $this->addCDATA($settingsCopy); if ($xml = Array_XML::array2xml($settingsCopy, 'settings')) { if (@file_put_contents(BertaBase::$options['XML_ROOT'] . $this->fileName, $xml) !== false) { @chmod(BertaBase::$options['XML_ROOT'] . $this->fileName, 0666); return true; } } return false; }
public static function getImagesArray($entry) { $imgs = array(); if (!empty($entry['mediaCacheData']['file']) && count($entry['mediaCacheData']['file']) > 0) { $imgs = array(); Array_XML::makeListIfNotList($entry['mediaCacheData']['file']); foreach ($entry['mediaCacheData']['file'] as $idx => $im) { if ((string) $idx == '@attributes') { continue; } $imgs[] = $im; } } return $imgs; }
public static function getImagesArray($entry) { $imgs = array(); if (!empty($entry['mediaCacheData']['file']) && count($entry['mediaCacheData']['file']) > 0) { $imgs = array(); Array_XML::makeListIfNotList($entry['mediaCacheData']['file']); foreach ($entry['mediaCacheData']['file'] as $idx => $im) { if ((string) $idx == '@attributes') { continue; } if ($im['@attributes']['type'] == 'image') { $imgs[] = $im; } elseif ($im['@attributes']['type'] == 'video' && !empty($im['@attributes']['poster_frame'])) { $imgs[] = $im; } } } return $imgs; }
public static function getRemoteFile($url, $type, $timeout = 7, $redirects = 2) { $o = self::$options; $streamOptions = array('http' => array('header' => "Content-Type: text/xml\r\n" . "Berta-User-Agent: {$_SERVER['HTTP_USER_AGENT']}\r\n" . "Berta-Version: Berta {$o['version']}\r\n" . "Berta-URI: {$o['SITE_HOST_ADDRESS']}{$o['SITE_ABS_ROOT']}\r\n" . "Berta-Content: {$type}\r\n", 'max_redirects' => $redirects, 'timeout' => $timeout)); $context = stream_context_create($streamOptions); $page = @file_get_contents($url, false, $context); $result = array(); if ($page && $type == 'newsticker') { $pContent = Array_XML::xml2array($page); $pContent = $pContent['messages']; if (self::updateBertaVersion($pContent['version'], $o['version'])) { $result['content'] = $pContent['update']; } elseif (!isset($_COOKIE['_berta_newsticker_news']) || $pContent['news'] != $_COOKIE['_berta_newsticker_news']) { setcookie('_berta_newsticker_news', $pContent['news'], time() + 60 * 60 * 12, '/'); $result['content'] = $pContent['news']; } else { $result['content'] = $pContent['tips']['tip'][rand(0, sizeof($pContent['tips']['tip']) - 1)]; } } else { if ($page && $type == 'videos') { $pContent = Array_XML::xml2array($page); $result['content'] = $pContent['videos']; } elseif (!isset($http_response_header)) { return null; } } // Bad url, timeout // Save the header $result['header'] = $http_response_header; // Get the *last* HTTP status code $nLines = count($http_response_header); for ($i = $nLines - 1; $i >= 0; $i--) { $line = $http_response_header[$i]; if (strncasecmp("HTTP", $line, 4) == 0) { $response = explode(' ', $line); $result['http_code'] = $response[1]; break; } } return $result; }
'</div>'; echo '<div class="xEntrySetImageSize">', '<a href="#" class="o2 xAction' . ($imageSize == 'small' ? ' selected' : '') . ' xCommand-SET_GALLERY_SIZE xParams-small" title="Small images"><span>Small images</span></a>', '<a href="#" class="o1 xAction' . ($imageSize == 'large' ? ' selected' : '') . ' xCommand-SET_GALLERY_SIZE xParams-large" title="Large images"><span>Large images</span></a>', '</div>'; echo '<div class="xEntryFullScreen">', '<a href="#" class="' . ($FullScreen == 'yes' ? 'selected ' : '') . 'xAction xCommand-SET_FULLSCREEN xParams-' . ($FullScreen == 'yes' ? 'yes' : 'no') . '" title="Lightbox"><span>yes/no</span></a>', '</div>'; echo '<a class="xEntryGalCloseLink xEditorLink" href="#" title="close image editor"><span>close image editor</span></a>'; echo '</div>'; echo '<div class="images"><ul>'; if(!empty($entry['mediaCacheData']['file']) && count($entry['mediaCacheData']['file']) > 0) { // if the xml tag is not a list tag, convert it. Array_XML::makeListIfNotList($entry['mediaCacheData']['file']); // print out images foreach($entry['mediaCacheData']['file'] as $idx => $im) { if((string) $idx == '@attributes') continue; $imageThumbSrc = false; $imageWidth = 'auto'; if($im['@attributes']['type'] == 'video') { if(!empty($im['@attributes']['poster_frame'])) { $imSrc = $options['MEDIA_ROOT'] . $entry['mediafolder']['value'] . '/' . (string) $im['@attributes']['poster_frame']; $imageThumbSrc = BertaEditor::images_getSmallThumbFor($imSrc); $imageSize = getimagesize($imageThumbSrc); $imageWidth = $imageSize[0] + 'px'; } echo '<li class="video" filename="' . (string) $im['@attributes']['src'] . '" fileinfo="' . '' . '">';
} // "updated" field for all entries if ($ver[1] < 6) { BertaEditor::setUpdateTimesForAll($blog); } if ($ver[1] = 6 && $ver[2] < 6) { // replace files with their _orig_ versions. BertaEditor::updateImageCacheFor($blog); foreach ($blog['entry'] as $eId => $e) { if ((string) $eId == '@attributes') { continue; } $mFolder = Berta::$options['MEDIA_ROOT'] . $e['mediafolder']['value'] . '/'; $entryCache =& $blog['entry'][$eId]['mediaCacheData']; if (count($entryCache)) { Array_XML::makeListIfNotList($entryCache['file']); foreach ($entryCache['file'] as $cacheIndex => $cacheIm) { $origSrc = '_orig_' . $cacheIm['@attributes']['src']; if (file_exists($mFolder . $origSrc)) { if (@unlink($mFolder . $cacheIm['@attributes']['src'])) { @rename($mFolder . $origSrc, $mFolder . $cacheIm['@attributes']['src']); } } } } } } // set version $blog['@attributes']['version'] = $options['version']; } // update some old settings ...
$returnUpdate = 'ok'; } else { $returnError = 'delete failed! check permissions.'; } } else { $returnError = 'file does not exist! media cache updated.'; } BertaEditor::updateImageCacheForSection($sectionsList[$sName]); BertaEditor::saveSections($sectionsList); } else { if ($decoded['property'] == 'galleryImageCaption') { // image / video caption $sectionsList = BertaEditor::getSections(); $sName = $decoded['section']; $imageCache =& $sectionsList[$sName]['mediaCacheData']['file']; Array_XML::makeListIfNotList($imageCache); foreach ($imageCache as $cacheIndex => $im) { if ($im['@attributes']['src'] == $decoded['params']) { $imageCache[$cacheIndex]['value'] = $decoded['value']; break; } } BertaEditor::updateImageCacheForSection($sectionsList[$sName]); BertaEditor::saveSections($sectionsList); } else { if ($decoded['action'] == 'SET_AUTOPLAY') { $sectionsList = BertaEditor::getSections(); $sName = $decoded['section']; if (empty($sectionsList[$sName]['mediaCacheData']['@attributes'])) { $sectionsList[$sName]['mediaCacheData']['@attributes'] = array(); }
echo '<div class="xBgSettings xHidden">'; echo '<div class="xBgNavigationSettings">', '<div class="caption">hide navigation arrows</div>', '<div class="xBgNavigation xFloatLeft xEditableSelectRC xCommand-SET_BG_NAVIGATION" x_options="no||yes">' . $bgHideNavigation . '</div>', '<div class="clear"></div>', '</div>'; echo '<div class="xBgAnimationSettings">', '<div class="caption">animation</div>', '<div class="xBgAnimation xEditableSelectRC xCommand-SET_BG_ANIMATION" x_options="enabled||disabled">' . $bgAnimation . '</div>', '<div class="clear"></div>', '</div>'; echo '<div class="xBgFadingSettings">', '<div class="caption">fade content</div>', '<div class="xBgFading xEditableSelectRC xCommand-SET_BG_FADE_CONTENT" x_options="enabled||disabled">' . $bgFading . '</div>', '<div class="clear"></div>', '</div>'; echo '<div class="xBgColorSettings">', '<div class="caption">background color</div>', '<div class="xBgColor xEditableColor xProperty-sectionBgColor xNoHTMLEntities xCSSUnits-0 xRequired-1 " title="' . $bgColor . '">' . $bgColorText . '</div>', '<div class="xBgColorReset xReset xCommand-sectionBgColorReset xParams-sectionBgColor"><a href="#"><span>remove</span></a></div>', '<div class="clear"></div>', '<div class="caption">caption text color</div>', '<div class="xBgColor xEditableColor xCommand-SET_BG_CAPTION_COLOR xNoHTMLEntities xCSSUnits-0 xRequired-1 " title="' . $bgCaptionColor . '">' . $bgCaptionColorText . '</div>', '<div class="xBgColorReset xReset xCommand-RESET_BG_CAPTION_COLOR xParams-SET_BG_CAPTION_COLOR"><a href="#"><span>remove</span></a></div>', '<div class="clear"></div>', '<div class="caption">caption background color</div>', '<div class="xBgColor xEditableColor xCommand-SET_BG_CAPTION_BACK_COLOR xNoHTMLEntities xCSSUnits-0 xRequired-1 " title="' . $bgCaptionBackColor . '">' . $bgCaptionBackColorText . '</div>', '<div class="xBgColorReset xReset xCommand-RESET_BG_CAPTION_BACK_COLOR xParams-SET_BG_CAPTION_BACK_COLOR"><a href="#"><span>remove</span></a></div>', '<div class="clear"></div>', '</div>'; echo '</div>'; echo '<div class="xBgImgSizeSettings xHidden">'; echo '<div class="caption">background image size</div>', '<div class="xBgImgSize xEditableSelectRC xCommand-SET_BG_IMG_SIZE" x_options="large||medium||small">' . $bgSize . '</div>', '<div class="clear"></div>'; echo '</div>'; echo '<div class="xBgSlideshowSettings xHidden">'; echo '<div class="caption">autoplay seconds</div>', '<div class="xBgAutoPlay xEditableRC xCommand-SET_AUTOPLAY xCaption-0" title="' . $autoPlay . '">' . $autoPlay . '</div>', '<div class="clear"></div>'; echo '</div>'; echo '<div class="images"><ul>'; if (!empty($section['mediaCacheData']['file']) && count($section['mediaCacheData']['file']) > 0) { // if the xml tag is not a list tag, convert it. Array_XML::makeListIfNotList($section['mediaCacheData']['file']); // print out images foreach ($section['mediaCacheData']['file'] as $idx => $im) { if ((string) $idx == '@attributes') { continue; } $imageThumbSrc = false; $imageWidth = 'auto'; if ($im['@attributes']['type'] == 'video') { if (!empty($im['@attributes']['poster_frame'])) { $imSrc = $options['MEDIA_ROOT'] . $section['mediafolder']['value'] . '/' . (string) $im['@attributes']['poster_frame']; $imageThumbSrc = BertaEditor::images_getSmallThumbFor($imSrc); $imageSize = getimagesize($imageThumbSrc); $imageWidth = $imageSize[0] + 'px'; } echo '<li class="video" filename="' . (string) $im['@attributes']['src'] . '" fileinfo="' . '' . '">';
function xml_download() { if (isset($_POST['wpsm-export-table'])) { $result = $this->db->get($_GET['table']); if (!$result) { return; } $converter = new Array_XML(); $xmlStr = $converter->convert($result); header("Content-type: txt/xml", true, 200); header("Content-Disposition: attachment; filename=" . $_POST['table_name'] . ".xml"); //header('Content-Length: ' . ob_get_length($xmlStr)); header("Pragma: no-cache"); header("Expires: 0"); echo $xmlStr; exit; } }
function addCDATA(&$array, $depth = 0) { foreach ($array as $aId => $child) { if ((string) $aId == '@attributes') { continue; } if (!is_array($child) && trim((string) $child) != '') { $array[$aId] = '<![CDATA[' . $child . ']]>'; } //echo $child . ', ' . count($child->children()) . "\r\n"; // echo str_repeat('-',$depth).">".$child->getName().": ".$subchild."<br />"; if (is_array($array[$aId])) { Array_XML::addCDATA($array[$aId], $depth + 1); } } }
public static function updateImageCacheFor(&$blog, $entryId = false) { if (!empty($blog['entry'])) { foreach ($blog['entry'] as $eId => $e) { if ((string) $eId == '@attributes') { continue; } if (!$entryId || !empty($e['id']['value']) && $entryId == $e['id']['value']) { $mediaFiles = array(); if (!empty($e['mediafolder']['value'])) { $mediaFiles = BertaEditor::gatherMediaFilesIn($e['mediafolder']['value']); } //var_dump($mediaFiles); if ($mediaFiles) { $entryCache =& $blog['entry'][$eId]['mediaCacheData']; if (!count($entryCache) || empty($entryCache['file'])) { // if the media cache is empty, create a fresh array $mediaCacheData = array('file' => array()); if (isset($blog['entry'][$eId]['mediaCacheData'])) { $mediaCacheData = array_merge($blog['entry'][$eId]['mediaCacheData'], $mediaCacheData); } $blog['entry'][$eId]['mediaCacheData'] = $mediaCacheData; $entryCache =& $blog['entry'][$eId]['mediaCacheData']; foreach ($mediaFiles as $im) { $attr = array('type' => $im['type'], 'src' => $im['src']); if (!empty($im['poster_frame'])) { $attr['poster_frame'] = $im['poster_frame']; } if (!empty($im['width'])) { $attr['width'] = $im['width']; } if (!empty($im['height'])) { $attr['height'] = $im['height']; } $entryCache['file'][] = array('value' => '', '@attributes' => $attr); } // if moving from an older version of XML unset($entryCache['images']); unset($entryCache['videos']); //echo "\n\n-----\n\n"; var_dump($entryCache); } else { Array_XML::makeListIfNotList($entryCache['file']); //echo "\n\n-----\n\n"; var_dump($entryCache); // first check if all items in cache are still inside the folder foreach ($entryCache['file'] as $cacheIndex => $cacheIm) { // try to find the entry among the files in the folder $foundIndex = false; foreach ($mediaFiles as $i => $im) { // *** compatibility with versions <= 0.5.5b $isFromOldVersion = empty($cacheIm['@attributes']['src']); $srcFromCache = $isFromOldVersion ? $cacheIm['value'] : $cacheIm['@attributes']['src']; // if image found in cache, update cache entry if ($srcFromCache == $im['src']) { $foundIndex = true; $entry = array('@attributes' => array()); if (!$isFromOldVersion) { $entry['value'] = !empty($cacheIm['value']) ? $cacheIm['value'] : ''; } if (!empty($cacheIm['@attributes'])) { $entry['@attributes'] = $cacheIm['@attributes']; } $entry['@attributes']['src'] = $im['src']; $entry['@attributes']['type'] = $im['type']; if (!empty($im['poster_frame'])) { $entry['@attributes']['poster_frame'] = $im['poster_frame']; } if (!empty($im['width'])) { $entry['@attributes']['width'] = $im['width']; } if (!empty($im['height'])) { $entry['@attributes']['height'] = $im['height']; } $entryCache['file'][$cacheIndex] = $entry; unset($mediaFiles[$i]); break; } } // if the file was not found in the folder, delete the entry if (!$foundIndex) { unset($entryCache['file'][$cacheIndex]); } } // loop through the rest of real files and add them to cache foreach ($mediaFiles as $im) { $attr = array('type' => $im['type'], 'src' => $im['src']); if (!empty($im['poster_frame'])) { $attr['poster_frame'] = $im['poster_frame']; } if (!empty($im['width'])) { $attr['width'] = $im['width']; } if (!empty($im['height'])) { $attr['height'] = $im['height']; } $entryCache['file'][] = array('value' => '', '@attributes' => $attr); } //echo "\n\n-----\n\n"; var_dump($entryCache); // compact arrays $entryCache['file'] = array_values($entryCache['file']); // if moving from an older version of XML unset($entryCache['images']); unset($entryCache['videos']); //echo "\n\n-----\n\n"; var_dump($entryCache); } } else { $mediaCacheData = array('file' => array()); if (isset($blog['entry'][$eId]['mediaCacheData'])) { $mediaCacheData = array_merge($blog['entry'][$eId]['mediaCacheData'], $mediaCacheData); } $blog['entry'][$eId]['mediaCacheData'] = $mediaCacheData; } } } } }
public static function entryForTemplate($p, $additionalValues = false) { $e = array(); // preset variables.. $e['__raw'] = $p; $e['id'] = $p['id']['value']; $e['uniqid'] = $p['uniqid']['value']; $e['date'] = !empty($p['date']) && !empty($p['date']['value']) ? $p['date']['value'] : ''; $e['mediafolder'] = $p['mediafolder']['value']; $e['marked'] = !empty($p['marked']['value']) ? '1' : '0'; if ($additionalValues) { foreach ($additionalValues as $key => $value) { if (!isset($e[$key])) { // don't overwrite $e[$key] = $value; } } } // entry content.. if (!empty($p['content'])) { foreach ($p['content'] as $key => $value) { if (!isset($e[$key])) { // don't overwrite $e[$key] = !empty($value['value']) ? $value['value'] : ''; } } } // tags.. $tagsList = array(); if (!empty($p['tags']['tag'])) { Array_XML::makeListIfNotList($p['tags']['tag']); foreach ($p['tags']['tag'] as $tName => $t) { if (!empty($t['value'])) { $tagsList[strtolower(BertaUtils::canonizeString($t['value']))] = $t['value']; } } } $e['tags'] = $tagsList; return $e; }