<commit_before><?php
/*
Copyright 2002-2012 MarkLogic Corporation.  All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
use MarkLogic\MLPHP as MLPHP;

session_start();
require_once ('setup.php');
require_once ('options.php');
$mapsKey = (!empty($mlphp['maps_key'])) ? ('key=' . $mlphp['maps_key'] . '&') : '';
?>
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>MLPHP: iPhone Photomap</title>
<link type="text/css" href="styles.css" rel="stylesheet">
<script type="text/javascript" src="../external/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?<?php echo $mapsKey ?>sensor=false"></script>
<script type="text/javascript" src="scripts.js"></script>
</head>
<?php

$client = new MLPHP\RESTClient($mlphp['host'], $mlphp['port'], $mlphp['path'], $mlphp['version'],
                               $mlphp['username'], $mlphp['password'], $mlphp['auth']);

if (isset($_FILES['upload'])) {
    try {
        // Check folder permissions
        if (!is_readable($mlphp['uploads_dir']) || !is_writable($mlphp['uploads_dir']) || !is_executable($mlphp['uploads_dir'])) {
            throw new Exception('Error: Photo uploads directory not readable, writable, and executable.');
        } else {
            // Load files
            foreach ($_FILES['upload']['error'] as $key => $error) {
                if ($error == UPLOAD_ERR_OK) {
                    // Move file to upload directory
                    $tmpName = $_FILES['upload']['tmp_name'][$key];
                    $name = $_FILES['upload']['name'][$key];
                    $dest = $mlphp['uploads_dir'] . '/' . $name;
                    move_uploaded_file($tmpName, $dest);
                    try {
                        // Write image file
                        require_once ('IPhoneImageDocument.php');
                        $image = new MLPHP\IPhoneImageDocument($client);
                        $image->setContentFile($dest);
                        $image->write($name);
                        // Write image metadata
                        $metadata = new MLPHP\Metadata();
                        $metadata->addProperties(array(
                            'latitude' => $image->getLatitude(),
                            'longitude' => $image->getLongitude(),
                            'height' => $image->getHeight(),
                            'width' => $image->getWidth(),
                            'filename' => $image->getFilename()
                        ));
                        $image->writeMetadata($metadata);
                    } catch(Exception $e) {
                        echo 'Error: ' . $e->getMessage();
                    }
                }
            }
        }
    } catch (Exception $e) {
        echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . PHP_EOL;
    }
}

// Get search results
$search = new MLPHP\Search($client);
$params = array(
    'pageLength' => 1000,
    'view' => 'all',
    'options' => 'photomap',
    'format' => 'xml'
);
$searchResults = $search->retrieve('', $params);

// Write JavaScript data for map.js
echo '<script>' . PHP_EOL;
echo 'var locations = { ' . PHP_EOL;
$lines = array();
foreach ($searchResults->getResults() as $result) {
    $line = '"' . $result->getURI() . '" : { ';
    $props = array();
    foreach ($result->getMetadataKeys() as $key) {
        $props[] = ' "' . $key . '" : "' . $result->getMetadata($key) . '"';
    }
    $line .= implode(',', $props);
    $line .= ' }';<commit_msg>is_executable() check is unreliable on Windows. Remove specific permissions error checking for uploads folder.<commit_after><?php
/*
Copyright 2002-2012 MarkLogic Corporation.  All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
use MarkLogic\MLPHP as MLPHP;

session_start();
require_once ('setup.php');
require_once ('options.php');
$mapsKey = (!empty($mlphp['maps_key'])) ? ('key=' . $mlphp['maps_key'] . '&') : '';
?>
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<title>MLPHP: iPhone Photomap</title>
<link type="text/css" href="styles.css" rel="stylesheet">
<script type="text/javascript" src="../external/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?<?php echo $mapsKey ?>sensor=false"></script>
<script type="text/javascript" src="scripts.js"></script>
</head>
<?php

$client = new MLPHP\RESTClient($mlphp['host'], $mlphp['port'], $mlphp['path'], $mlphp['version'],
                               $mlphp['username'], $mlphp['password'], $mlphp['auth']);

if (isset($_FILES['upload'])) {
    try {
    	// Load files
    	foreach ($_FILES['upload']['error'] as $key => $error) {
			if ($error == UPLOAD_ERR_OK) {
				// Move file to upload directory
				$tmpName = $_FILES['upload']['tmp_name'][$key];
				$name = $_FILES['upload']['name'][$key];
				$dest = $mlphp['uploads_dir'] . '/' . $name;
				move_uploaded_file($tmpName, $dest);
				try {
					// Write image file
					require_once ('IPhoneImageDocument.php');
					$image = new MLPHP\IPhoneImageDocument($client);
					$image->setContentFile($dest);
					$image->write($name);
					// Write image metadata
					$metadata = new MLPHP\Metadata();
					$metadata->addProperties(array(
						'latitude' => $image->getLatitude(),
						'longitude' => $image->getLongitude(),
						'height' => $image->getHeight(),
						'width' => $image->getWidth(),
						'filename' => $image->getFilename()
					));
					$image->writeMetadata($metadata);
				} catch(Exception $e) {
					echo 'Error: ' . $e->getMessage();
				}
			}
    	}
    } catch (Exception $e) {
        echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() . PHP_EOL;
    }
}

// Get search results
$search = new MLPHP\Search($client);
$params = array(
    'pageLength' => 1000,
    'view' => 'all',
    'options' => 'photomap',
    'format' => 'xml'
);
$searchResults = $search->retrieve('', $params);

// Write JavaScript data for map.js
echo '<script>' . PHP_EOL;
echo 'var locations = { ' . PHP_EOL;
$lines = array();
foreach ($searchResults->getResults() as $result) {
    $line = '"' . $result->getURI() . '" : { ';
    $props = array();
    foreach ($result->getMetadataKeys() as $key) {
        $props[] = ' "' . $key . '" : "' . $result->getMetadata($key) . '"';
    }
    $line .= implode(',', $props);
    $line .= ' }';
{'fraction_non_alphanumeric': 0.17751079913606913, 'fraction_numerical': 0.005399568034557235, 'mean_word_length': 2.680576254346746, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5856778', 'n_tokens_mistral': 2353, 'n_tokens_neox': 2173, 'n_words': 552}