<?php

/*
 * populateCountryShortNames.php
 * populate country short names where they don't already exist
 *
 * (the only reason they wouldn't exist is because the GNS dataset from the NGA didn't have
 * 	City listing data records in the dataset we're using for international geocoding by city name)
 * (so all these countries without pre-existing short_names come from Irene's excel spreadsheet)
 */
require '../inc.php';
$sqlGetNullShortNamedCountries = "SELECT id, name FROM countries WHERE short_name = ''";
$resultNullShortNamedCountries = mysql_query($sqlGetNullShortNamedCountries) or die('died getting null short_named country listings: ' . mysql_error);
while ($countryRow = mysql_fetch_object($resultNullShortNamedCountries)) {
    echo "working with: " . $countryRow->name . "<br />";
    $shortName = generateShortName($countryRow->name);
    echo "short name for this record is: " . $shortName . "<br /><br />";
    $sqlInsertNewShortName = "UPDATE countries SET short_name = '" . $shortName . "' WHERE id = '" . $countryRow->id . "' OR name = short_name";
    mysql_query($sqlInsertNewShortName) or die('died trying to update the country\'s short name: ' . mysql_error());
}
function generateShortName($longName)
{
    $explodedName = explode(' ', $longName);
    $shortName = '';
    // more than one word for the country name
    foreach ($explodedName as $subStr) {
        if ($subStr != 'and' && $subStr != 'del' && $subStr != '/' && $subStr != 'of' && $subStr != 'the') {
            if (substr($subStr, 0, 1) != "(") {
                $shortName .= substr($subStr, 0, 1);
            } else {
                $shortName .= substr($subStr, 1, 1);
Example #2
0
     exit;
 }
 //Check file extensions for php files
 foreach ($blacklist as $item) {
     if (preg_match("/{$item}\$/i", $_FILES["video"]['tmp_name'])) {
         header("Location: /post.php?message=" . urldecode("File format not supported"));
         exit;
     }
 }
 // generate unique shortname for upload
 $shortname = generateShortName();
 $extension = pathinfo($_FILES["video"]["name"], PATHINFO_EXTENSION);
 $checkFile = md5($shortname . "salt");
 //Add video3 check later
 while (file_exists("http://video2/media/video2/{$checkFile}.{$extension}") or file_exists("http://video1/media/video1/{$checkFile}.{$extension}")) {
     $shortname = generateShortName();
     $checkFile = md5($shortname . "salt");
 }
 $hashedShort = md5($shortname . "salt");
 $filename = md5($shortname . "salt") . "." . $extension;
 // move file to upload directory
 if (!move_uploaded_file($_FILES["video"]["tmp_name"], "media/{$APPLICATION_HOSTNAME}/{$filename}")) {
     header("Location: /post.php?message=" . urldecode("Upload failed"));
     exit;
 }
 // check upload success
 if (!file_exists("media/{$APPLICATION_HOSTNAME}/{$filename}")) {
     header("Location: /post.php?message=" . urlencode("Upload failed."));
     exit;
 }
 // generate video thumbnail