/** * Uploads a temp file which contains bookmarks to import * @global type $imported_bookmarks * @global type $repository_path * @global type $user_files_path * @global type $bookmarks_validation_file * @global type $album * @global type $asset */ function bookmarks_upload() { global $imported_bookmarks; global $repository_path; global $user_files_path; global $bookmarks_validation_file; global $album; global $asset; $album = $_POST['album']; // the album user wants to import in $asset = $_POST['asset']; // the asset user wants to import in $target = $_POST['target']; // personal bookmarks or table of contents $_SESSION['album'] = $album; $_SESSION['asset'] = $asset; $_SESSION['target'] = $target; // 1) Sanity checks if ($_FILES['XMLbookmarks']['error'] > 0) { error_print_message(template_get_message('upload_error', get_lang())); log_append('error', 'upload_bookmarks: an error occurred during file upload (code ' . $_FILES['XMLbookmarks']['error']); die; } if ($_FILES['XMLbookmarks']['type'] != 'text/xml') { error_print_message(template_get_message('error_mimetype', get_lang())); log_append('warning', 'upload_bookmarks: invalid mimetype for file ' . $_FILES['XMLbookmarks']['tmp_name']); die; } if ($_FILES['XMLbookmarks']['size'] > 2147483) { error_print_message(template_get_message('error_size', get_lang())); log_append('warning', 'upload_bookmarks: file too big ' . $_FILES['XMLbookmarks']['tmp_name']); die; } // 2) Validates the XML file and converts it in associative array if (file_exists($_FILES['XMLbookmarks']['tmp_name'])) { // Validates XML structure $xml_dom = new DOMDocument(); // trim heading and trailing white spaces // because blank lines in top and end of XML file lead to // validation error file_put_contents($_FILES['XMLbookmarks']['tmp_name'], trim(file_get_contents($_FILES['XMLbookmarks']['tmp_name']))); $xml_dom->load($_FILES['XMLbookmarks']['tmp_name']); if (!$xml_dom->schemaValidate($bookmarks_validation_file)) { include_once template_getpath('div_import_bookmarks.php'); error_print_message(template_get_message('error_structure', get_lang())); } // Converts XML file in SimpleXMLElement $xml = simplexml_load_file($_FILES['XMLbookmarks']['tmp_name']); $imported_bookmarks = xml_file2assoc_array($xml, 'bookmark'); } // init paths ezmam_repository_path($repository_path); user_prefs_repository_path($user_files_path); // Keeps only bookmarks from existing assets foreach ($imported_bookmarks as $index => $bookmark) { if (!ezmam_asset_exists($bookmark['album'], $bookmark['asset'])) { unset($imported_bookmarks[$index]); } } log_append('upload_bookmarks: file imported'); // lvl, action, album, asset, target (in official|personal bookmarks), number of bookmarks uploaded trace_append(array($asset != '' ? '3' : '2', 'bookmarks_upload', $album, $asset != '' ? $asset : '-', $target, count($imported_bookmarks))); echo '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>'; // echo "<script language='javascript' type='text/javascript'>window.top.window.document.getElementById('popup_import_bookmarks').innerHTML='$lapin';</script>"; include_once template_getpath('div_import_bookmarks.php'); }
function user_prefs_settings_get($user) { // Sanity check if (!isset($user) || $user == '') { return false; } // 1) set repository path $user_files_path = user_prefs_repository_path(); if ($user_files_path === false) { return false; } $settings = array(); // 2) set user's file path $user_path = $user_files_path . "/" . $user; // 3) if the xml file exists, it is converted in associative array if (file_exists($user_path . "/_settings.xml")) { $xml = simplexml_load_file($user_path . "/_settings.xml"); $settings = xml_file2assoc_array($xml); } return $settings; }
/** * converts a SimpleXMLElement in an associative array * @param SimpleXMLElement $xml * @anonymous_key the name of root tag we don't want to get for each item * @return type */ function xml_file2assoc_array($xml, $anonymous_key = 'anon') { if (is_string($xml)) { $xml = new SimpleXMLElement($xml); } $children = $xml->children(); if (!$children) { return (string) $xml; } $arr = array(); foreach ($children as $key => $node) { $node = xml_file2assoc_array($node); // support for 'anon' non-associative arrays if ($key == $anonymous_key) { $key = count($arr); } // if the node is already set, put it into an array if (isset($arr[$key])) { if (!is_array($arr[$key]) || $arr[$key][0] == null) { $arr[$key] = array($arr[$key]); } $arr[$key][] = $node; } else { $arr[$key] = $node; } } return $arr; }
/** * Returns the list of (official) bookmarks for a given album * @param type $album the name of the album * @return the list of bookmarks for a given album; false if an error occurs */ function toc_album_bookmarks_list_get($album) { // Sanity check if (!ezmam_album_exists($album)) { return false; } // 1) set repository path $toc_path = ezmam_repository_path(); if ($toc_path === false) { return false; } // 2) set user's file path $toc_path = $toc_path . "/" . $album; $assoc_album_bookmarks = array(); // 3) if the xml file exists, it is converted in associative array if (file_exists($toc_path . "/_bookmarks.xml")) { $xml = simplexml_load_file($toc_path . "/_bookmarks.xml"); if (!$xml) { return false; } $assoc_album_bookmarks = xml_file2assoc_array($xml, 'bookmark'); } return $assoc_album_bookmarks; }