コード例 #1
0
ファイル: inflector.php プロジェクト: benjaminoakes/snippets
function humanize($value)
{
    $value = ucfirst(str_replace('_', ' ', $value));
    $value = strip_extension($value);
    if (str_contains(' ', $value)) {
        return $value;
    } else {
        return decamelize($value);
    }
}
コード例 #2
0
     }
     if (strlen($origfile) > 0) {
         # do an extra check to see if the original filename might have uppercase extension that can be preserved.
         $pathparts = pathinfo($origfile);
         if (isset($pathparts['extension'])) {
             if (strtolower($pathparts['extension']) == $ext) {
                 $ext = $pathparts['extension'];
             }
         }
         # Use the original filename if one has been set.
         # Strip any path information (e.g. if the staticsync.php is used).
         # append preview size to base name if not the original
         if ($size != "") {
             $filename = strip_extension(mb_basename($origfile)) . "-" . $size . "." . $ext;
         } else {
             $filename = strip_extension(mb_basename($origfile)) . "." . $ext;
         }
         if ($prefix_resource_id_to_filename) {
             $filename = $prefix_filename_string . $ref . "_" . $filename;
         }
     }
 }
 if ($download_filename_id_only) {
     if (!hook('customdownloadidonly', '', array($ref, $ext, $alternative))) {
         $filename = $ref . "." . $ext;
     }
 }
 if (isset($download_filename_field)) {
     $newfilename = get_data_by_field($ref, $download_filename_field);
     if ($newfilename) {
         $filename = trim(nl2br(strip_tags($newfilename)));
コード例 #3
0
                 $task = '';
             }
         }
     }
     break;
 case 'upload':
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $active_tab = 2;
         $task = 'list';
         if (isset($_FILES['file'])) {
             for ($i = 0; $i < count($_FILES['file']['tmp_name']); $i++) {
                 if (is_uploaded_file($_FILES['file']['tmp_name'][$i])) {
                     $name = $_FILES['file']['name'][$i];
                     while ($cms->template_file_exists($template_id, $name)) {
                         $x++;
                         $name = strip_extension($_FILES['file']['name'][$i]) . ' (' . $x . ').' . get_extension($_FILES['file']['name'][$i]);
                     }
                     $fp = fopen($_FILES['file']['tmp_name'][$i], 'r');
                     $content = addslashes(fread($fp, $_FILES['file']['size'][$i]));
                     fclose($fp);
                     unlink($_FILES['file']['tmp_name'][$i]);
                     $file_id = $cms->add_template_file($template_id, $name, $content);
                 }
             }
         }
     }
     break;
 case "files":
     $active_tab = 2;
     break;
 case 'save_main_template_item':
コード例 #4
0
function extract_exif_comment($ref, $extension = "")
{
    # Extract the EXIF comment from either the ImageDescription field or the UserComment
    # Also parse IPTC headers and insert
    # EXIF headers
    $exifoption = getval("no_exif", "");
    // This may have been set to a non-standard value if allowing per field selection
    if ($exifoption == "yes") {
        $exifoption = "no";
    }
    // Sounds odd but previously was no_exif so logic reversed
    if ($exifoption == "") {
        $exifoption = "yes";
    }
    $image = get_resource_path($ref, true, "", false, $extension);
    if (!file_exists($image)) {
        return false;
    }
    hook("pdfsearch");
    global $exif_comment, $exiftool_no_process, $exiftool_resolution_calc, $disable_geocoding, $embedded_data_user_select_fields, $filename_field;
    $exiftool_fullpath = get_utility_path("exiftool");
    if ($exiftool_fullpath != false && !in_array($extension, $exiftool_no_process)) {
        $resource = get_resource_data($ref);
        # Field 8 is used in a special way for staticsync; don't overwrite.
        if ($resource['file_path'] != "") {
            $omit_title_for_staticsync = true;
        } else {
            $omit_title_for_staticsync = false;
        }
        hook("beforeexiftoolextraction");
        if ($exiftool_resolution_calc) {
            # see if we can use exiftool to get resolution/units, and dimensions here.
            # Dimensions are normally extracted once from the view page, but for the original file, it should be done here if possible,
            # and exiftool can provide more data.
            $command = $exiftool_fullpath . " -s -s -s -t -composite:imagesize -xresolution -resolutionunit " . escapeshellarg($image);
            $dimensions_resolution_unit = explode("\t", run_command($command));
            # if dimensions resolution and unit could be extracted, add them to the database.
            # they can be used in view.php to give more accurate data.
            if (count($dimensions_resolution_unit) == 3) {
                $dru = $dimensions_resolution_unit;
                $filesize = filesize_unlimited($image);
                $wh = explode("x", $dru[0]);
                $width = $wh[0];
                $height = $wh[1];
                $resolution = $dru[1];
                $unit = $dru[2];
                sql_query("insert into resource_dimensions (resource, width, height, resolution, unit, file_size) values ('{$ref}', '{$width}', '{$height}', '{$resolution}', '{$unit}', '{$filesize}')");
            }
        }
        $read_from = get_exiftool_fields($resource['resource_type']);
        # run exiftool to get all the valid fields. Use -s -s option so that
        # the command result isn't printed in columns, which will help in parsing
        # We then split the lines in the result into an array
        $command = $exiftool_fullpath . " -s -s -f -m -d \"%Y-%m-%d %H:%M:%S\" -G " . escapeshellarg($image);
        $metalines = explode("\n", run_command($command));
        $metadata = array();
        # an associative array to hold metadata field/value pairs
        # go through each line and split field/value using the first
        # occurrance of ": ".  The keys in the associative array is converted
        # into uppercase for easier lookup later
        foreach ($metalines as $metaline) {
            # Use stripos() if available, but support earlier PHP versions if not.
            if (function_exists("stripos")) {
                $pos = stripos($metaline, ": ");
            } else {
                $pos = strpos($metaline, ": ");
            }
            if ($pos) {
                # add to the associative array, also clean up leading/trailing space & single quote (on windows sometimes)
                # Extract group name and tag name.
                $s = explode("]", substr($metaline, 0, $pos));
                if (count($s) > 1 && strlen($s[0]) > 1) {
                    # Extract value
                    $value = trim(substr($metaline, $pos + 2));
                    # Replace '..' with line feed - either Exiftool itself or Adobe Bridge replaces line feeds with '..'
                    $value = str_replace('....', '\\n\\n', $value);
                    // Two new line feeds in ExifPro are replaced with 4 dots '....'
                    $value = str_replace('...', '.\\n', $value);
                    # Three dots together is interpreted as a full stop then line feed, not the other way round
                    $value = str_replace('..', '\\n', $value);
                    # Extract group name and tag name
                    $groupname = strtoupper(substr($s[0], 1));
                    $tagname = strtoupper(trim($s[1]));
                    # Store both tag data under both tagname and groupname:tagname, to support both formats when mapping fields.
                    $metadata[$tagname] = $value;
                    $metadata[$groupname . ":" . $tagname] = $value;
                    debug("Exiftool: extracted field '{$groupname}:{$tagname}', value is '{$value}'");
                }
            }
        }
        // We try to fetch the original filename from database.
        $resources = sql_query("SELECT resource.file_path FROM resource WHERE resource.ref = " . $ref);
        if ($resources) {
            $resource = $resources[0];
            if ($resource['file_path']) {
                $metadata['FILENAME'] = mb_basename($resource['file_path']);
            }
        }
        if (isset($metadata['FILENAME'])) {
            $metadata['STRIPPEDFILENAME'] = strip_extension($metadata['FILENAME']);
        }
        # Geolocation Metadata Support
        if (!$disable_geocoding && isset($metadata['GPSLATITUDE'])) {
            # Set vars
            $dec_long = 0;
            $dec_lat = 0;
            #Convert latititude to decimal.
            if (preg_match("/^(?<degrees>\\d+) deg (?<minutes>\\d+)' (?<seconds>\\d+\\.?\\d*)\"/", $metadata['GPSLATITUDE'], $latitude)) {
                $dec_lat = $latitude['degrees'] + $latitude['minutes'] / 60 + $latitude['seconds'] / (60 * 60);
            }
            if (preg_match("/^(?<degrees>\\d+) deg (?<minutes>\\d+)' (?<seconds>\\d+\\.?\\d*)\"/", $metadata['GPSLONGITUDE'], $longitude)) {
                $dec_long = $longitude['degrees'] + $longitude['minutes'] / 60 + $longitude['seconds'] / (60 * 60);
            }
            if (strpos($metadata['GPSLATITUDE'], 'S') !== false) {
                $dec_lat = -1 * $dec_lat;
            }
            if (strpos($metadata['GPSLONGITUDE'], 'W') !== false) {
                $dec_long = -1 * $dec_long;
            }
            if ($dec_long != 0 && $dec_lat != 0) {
                sql_query("update resource set geo_long='" . escape_check($dec_long) . "',geo_lat='" . escape_check($dec_lat) . "' where ref='{$ref}'");
            }
        }
        # Update portrait_landscape_field (when reverting metadata this was getting lost)
        update_portrait_landscape_field($ref);
        # now we lookup fields from the database to see if a corresponding value
        # exists in the uploaded file
        $exif_updated_fields = array();
        for ($i = 0; $i < count($read_from); $i++) {
            $field = explode(",", $read_from[$i]['exiftool_field']);
            foreach ($field as $subfield) {
                $subfield = strtoupper($subfield);
                // convert to upper case for easier comparision
                if (in_array($subfield, array_keys($metadata)) && $metadata[$subfield] != "-" && trim($metadata[$subfield]) != "") {
                    $read = true;
                    $value = $metadata[$subfield];
                    # Dropdown box or checkbox list?
                    if ($read_from[$i]["type"] == 2 || $read_from[$i]["type"] == 3) {
                        # Check that the value is one of the options and only insert if it is an exact match.
                        # The use of safe_file_name and strtolower ensures matching takes place on alphanumeric characters only and ignores case.
                        # First fetch all options in all languages
                        $options = trim_array(explode(",", strtolower($read_from[$i]["options"])));
                        for ($n = 0; $n < count($options); $n++) {
                            $options[$n] = $options[$n];
                        }
                        # If not in the options list, do not read this value
                        $s = trim_array(explode(",", $value));
                        $value = "";
                        # blank value
                        for ($n = 0; $n < count($s); $n++) {
                            if (trim($s[0]) != "" && in_array(strtolower($s[$n]), $options)) {
                                $value .= "," . $s[$n];
                            }
                        }
                        #echo($read_from[$i]["ref"] . " = " . $value . "<br>");
                    }
                    # Read the data.
                    if ($read) {
                        $plugin = dirname(__FILE__) . "/../plugins/exiftool_filter_" . $read_from[$i]['name'] . ".php";
                        if ($read_from[$i]['exiftool_filter'] != "") {
                            eval($read_from[$i]['exiftool_filter']);
                        }
                        if (file_exists($plugin)) {
                            include $plugin;
                        }
                        # Field 8 is used in a special way for staticsync; don't overwrite field 8 in this case
                        if (!($omit_title_for_staticsync && $read_from[$i]['ref'] == 8)) {
                            $exiffieldoption = $exifoption;
                            if ($exifoption == "custom" || isset($embedded_data_user_select_fields) && in_array($read_from[$i]['ref'], $embedded_data_user_select_fields)) {
                                debug("EXIF - custom option for field " . $read_from[$i]['ref'] . " : " . $exifoption);
                                $exiffieldoption = getval("exif_option_" . $read_from[$i]['ref'], $exifoption);
                            }
                            debug("EXIF - option for field " . $read_from[$i]['ref'] . " : " . $exiffieldoption);
                            if ($exiffieldoption == "no") {
                                continue;
                            } elseif ($exiffieldoption == "append") {
                                $spacechar = $read_from[$i]["type"] == 2 || $read_from[$i]["type"] == 3 ? ", " : " ";
                                $oldval = get_data_by_field($ref, $read_from[$i]['ref']);
                                if (strpos($oldval, $value) !== false) {
                                    continue;
                                }
                                $newval = $oldval . $spacechar . iptc_return_utf8($value);
                            } elseif ($exiffieldoption == "prepend") {
                                $spacechar = $read_from[$i]["type"] == 2 || $read_from[$i]["type"] == 3 ? ", " : " ";
                                $oldval = get_data_by_field($ref, $read_from[$i]['ref']);
                                if (strpos($oldval, $value) !== false) {
                                    continue;
                                }
                                $newval = iptc_return_utf8($value) . $spacechar . $oldval;
                            } else {
                                $newval = iptc_return_utf8($value);
                            }
                            global $merge_filename_with_title, $lang;
                            if ($merge_filename_with_title) {
                                $merge_filename_with_title_option = urlencode(getval('merge_filename_with_title_option', ''));
                                $merge_filename_with_title_include_extensions = urlencode(getval('merge_filename_with_title_include_extensions', ''));
                                $merge_filename_with_title_spacer = urlencode(getval('merge_filename_with_title_spacer', ''));
                                $original_filename = '';
                                if (isset($_REQUEST['name'])) {
                                    $original_filename = $_REQUEST['name'];
                                } else {
                                    $original_filename = $processfile['name'];
                                }
                                if ($merge_filename_with_title_include_extensions == 'yes') {
                                    $merged_filename = $original_filename;
                                } else {
                                    $merged_filename = strip_extension($original_filename);
                                }
                                $oldval = get_data_by_field($ref, $read_from[$i]['ref']);
                                if (strpos($oldval, $value) !== FALSE) {
                                    continue;
                                }
                                switch ($merge_filename_with_title_option) {
                                    case $lang['merge_filename_title_do_not_use']:
                                        // Do nothing since the user doesn't want to use this feature
                                        break;
                                    case $lang['merge_filename_title_replace']:
                                        $newval = $merged_filename;
                                        break;
                                    case $lang['merge_filename_title_prefix']:
                                        $newval = $merged_filename . $merge_filename_with_title_spacer . $oldval;
                                        if ($oldval == '') {
                                            $newval = $merged_filename;
                                        }
                                        break;
                                    case $lang['merge_filename_title_suffix']:
                                        $newval = $oldval . $merge_filename_with_title_spacer . $merged_filename;
                                        if ($oldval == '') {
                                            $newval = $merged_filename;
                                        }
                                        break;
                                    default:
                                        // Do nothing
                                        break;
                                }
                            }
                            update_field($ref, $read_from[$i]['ref'], $newval);
                            $exif_updated_fields[] = $read_from[$i]['ref'];
                            hook("metadata_extract_addition", "all", array($ref, $newval, $read_from, $i));
                        }
                    }
                } else {
                    // Process if no embedded title is found:
                    global $merge_filename_with_title, $lang;
                    if ($merge_filename_with_title && $read_from[$i]['ref'] == 8) {
                        $merge_filename_with_title_option = urlencode(getval('merge_filename_with_title_option', ''));
                        $merge_filename_with_title_include_extensions = urlencode(getval('merge_filename_with_title_include_extensions', ''));
                        $merge_filename_with_title_spacer = urlencode(getval('merge_filename_with_title_spacer', ''));
                        $original_filename = '';
                        if (isset($_REQUEST['name'])) {
                            $original_filename = $_REQUEST['name'];
                        } else {
                            $original_filename = $processfile['name'];
                        }
                        if ($merge_filename_with_title_include_extensions == 'yes') {
                            $merged_filename = $original_filename;
                        } else {
                            $merged_filename = strip_extension($original_filename);
                        }
                        $oldval = get_data_by_field($ref, $read_from[$i]['ref']);
                        if (strpos($oldval, $value) !== FALSE) {
                            continue;
                        }
                        switch ($merge_filename_with_title_option) {
                            case $lang['merge_filename_title_do_not_use']:
                                // Do nothing since the user doesn't want to use this feature
                                break;
                            case $lang['merge_filename_title_replace']:
                                $newval = $merged_filename;
                                break;
                            case $lang['merge_filename_title_prefix']:
                                $newval = $merged_filename . $merge_filename_with_title_spacer . $oldval;
                                if ($oldval == '') {
                                    $newval = $merged_filename;
                                }
                                break;
                            case $lang['merge_filename_title_suffix']:
                                $newval = $oldval . $merge_filename_with_title_spacer . $merged_filename;
                                if ($oldval == '') {
                                    $newval = $merged_filename;
                                }
                                break;
                            default:
                                // Do nothing
                                break;
                        }
                        update_field($ref, $read_from[$i]['ref'], $newval);
                        $exif_updated_fields[] = $read_from[$i]['ref'];
                    }
                }
            }
        }
        if (!in_array($filename_field, $exif_updated_fields)) {
            $exiffilenameoption = getval("exif_option_" . $filename_field, $exifoption);
            debug("EXIF - custom option for filename field " . $filename_field . " : " . $exiffilenameoption);
            if ($exiffilenameoption != "yes") {
                $uploadedfilename = isset($_REQUEST['name']) ? $_REQUEST['name'] : $processfile['name'];
                global $userref, $amended_filename;
                $entered_filename = get_data_by_field(-$userref, $filename_field);
                debug("EXIF - got entered file name " . $entered_filename);
                if ($exiffilenameoption == "no") {
                    $amended_filename = $entered_filename;
                    if (trim($amended_filename) == '') {
                        $amended_filename = $uploadedfilename;
                    }
                    if (strpos($amended_filename, $extension) === FALSE) {
                        $amended_filename .= '.' . $extension;
                    }
                } elseif ($exiffilenameoption == "append") {
                    $amended_filename = $entered_filename . $uploadedfilename;
                } elseif ($exiffilenameoption == "prepend") {
                    $amended_filename = strip_extension($uploadedfilename) . $entered_filename . "." . $extension;
                }
                debug("EXIF - created new file name " . $amended_filename);
            }
        }
    } elseif (isset($exif_comment)) {
        #
        # Exiftool is not installed. As a fallback we grab some predefined basic fields using the PHP function
        # exif_read_data()
        #
        if (function_exists("exif_read_data")) {
            $data = @exif_read_data($image);
        } else {
            $data = false;
        }
        if ($data !== false) {
            $comment = "";
            #echo "<pre>EXIF\n";print_r($data);exit();
            if (isset($data["ImageDescription"])) {
                $comment = $data["ImageDescription"];
            }
            if ($comment == "" && isset($data["COMPUTED"]["UserComment"])) {
                $comment = $data["COMPUTED"]["UserComment"];
            }
            if ($comment != "") {
                # Convert to UTF-8
                $comment = iptc_return_utf8($comment);
                # Save comment
                global $exif_comment;
                update_field($ref, $exif_comment, $comment);
            }
            if (isset($data["Model"])) {
                # Save camera make/model
                global $exif_model;
                update_field($ref, $exif_model, $data["Model"]);
            }
            if (isset($data["DateTimeOriginal"])) {
                # Save camera date/time
                global $exif_date;
                $date = $data["DateTimeOriginal"];
                # Reformat date to ISO standard
                $date = substr($date, 0, 4) . "-" . substr($date, 5, 2) . "-" . substr($date, 8, 11);
                update_field($ref, $exif_date, $date);
            }
        }
        # Try IPTC headers
        $size = getimagesize($image, $info);
        if (isset($info["APP13"])) {
            $iptc = iptcparse($info["APP13"]);
            #echo "<pre>IPTC\n";print_r($iptc);exit();
            # Look for iptc fields, and insert.
            $fields = sql_query("select * from resource_type_field where length(iptc_equiv)>0");
            for ($n = 0; $n < count($fields); $n++) {
                $iptc_equiv = $fields[$n]["iptc_equiv"];
                if (isset($iptc[$iptc_equiv][0])) {
                    # Found the field
                    if (count($iptc[$iptc_equiv]) > 1) {
                        # Multiple values (keywords)
                        $value = "";
                        for ($m = 0; $m < count($iptc[$iptc_equiv]); $m++) {
                            if ($m > 0) {
                                $value .= ", ";
                            }
                            $value .= $iptc[$iptc_equiv][$m];
                        }
                    } else {
                        $value = $iptc[$iptc_equiv][0];
                    }
                    $value = iptc_return_utf8($value);
                    # Date parsing
                    if ($fields[$n]["type"] == 4) {
                        $value = substr($value, 0, 4) . "-" . substr($value, 4, 2) . "-" . substr($value, 6, 2);
                    }
                    if (trim($value) != "") {
                        update_field($ref, $fields[$n]["ref"], $value);
                    }
                }
            }
        }
    }
    # Update the XML metadata dump file.
    update_xml_metadump($ref);
    # Auto fill any blank fields.
    autocomplete_blank_fields($ref);
}
コード例 #5
0
}
//list the files
$count_files = $cms->get_files($folder_id, $cms_settings['sort_field'], $cms_settings['sort_order']);
while ($cms->next_record()) {
    $total_size += $cms->f('size');
    $short_name = strip_extension(cut_string($cms->f('name'), 30));
    echo '<tr id="file_' . $cms->f('id') . '" class="Table1">';
    echo '<td><input onclick="javascript:file_click(this)" type="checkbox" name="files[]" value="' . $cms->f('id') . '" id="' . $cms->f('name') . '" /></td>';
    echo '<td nowrap>';
    if (in_array($cms->f('extension'), $image_filter)) {
        echo '<a href=\'javascript:_insertImage("' . $GO_MODULES->full_url . 'download.php?site_id=' . $site_id . '&file_id=' . $cms->f('id') . '");\' title="' . $cms->f('name') . '">';
    } else {
        if ($cms->f('title') != '') {
            $link_name = $cms->f('title');
        } else {
            $link_name = strip_extension($cms->f('name'));
        }
        echo '<a href=\'javascript:_insertHyperlink("' . $GO_MODULES->full_url . 'view.php?site_id=' . $site_id . '&file_id=' . $cms->f('id') . '", "' . $link_name . '");\' title="' . $cms->f('name') . '">';
    }
    echo '<img width="16" height="16" border="0" src="' . $GO_CONFIG->full_url . 'controls/icon.php?extension=' . $cms->f('extension') . '" align="absmiddle" />&nbsp;&nbsp;';
    if (isset($cut_files) && in_array($cms->f('id'), $cut_files)) {
        echo '<font color="#7d7d7d">' . $short_name . '</font></a>&nbsp;&nbsp;</td>';
    } else {
        echo $short_name . '</a>&nbsp;&nbsp;</td>';
    }
    echo '<td nowrap>' . $cms->f('friendly') . '&nbsp;&nbsp;</td>';
    /*
      echo '<td nowrap align="right">'.format_size($cms->f('size')).'&nbsp;&nbsp;</td>';
      echo '<td nowrap>'.date($_SESSION['GO_SESSION']['date_format'], $cms->f('mtime')).'&nbsp;&nbsp;</td>';
    */
    echo '<td nowrap align="center">' . $cms->f('priority') . '</td>';
コード例 #6
0
//see if the user has access to this module
//for this to work there must be a module named 'example'
$GO_MODULES->authenticate('cms');
require $GO_THEME->theme_path . "header.inc";
require $GO_CONFIG->class_path . 'filesystem.class.inc';
$fs = new filesystem(true);
$plugin = $GO_MODULES->get_plugin('components');
$files = $fs->get_files($plugin['path']);
echo '<table border="0">';
echo '<tr><td width="16"></td>';
echo '<td><h3>' . $strName . '</h3></td>';
echo '<td colspan="2"></td></tr>';
while ($file = array_shift($files)) {
    if ($file['name'] != 'select.php') {
        echo '<tr><td width="16" height="16"><img src="' . $GO_THEME->images['site'] . '" border="0" widht="16" height="16" /></td>';
        echo '<td><a class="normal" href="javascript:insert_file(\'' . urlencode($plugin['url'] . $file['name'] . '?site_id=' . $_REQUEST['site_id']) . '\');">' . strip_extension($file['name']) . '</a></td>';
    }
}
echo '</table><br />';
$button = new button($cmdClose, "javascript:window.close();");
?>
<script type="text/javascript">

function insert_file(url)
{
	opener.editor.insertHTML('<iframe frameborder="0" src="'+url+'" style="width:500px;height:400px;border:0px;"></iframe>');
	window.close();
}
</script>

<?php 
コード例 #7
0
            echo $feedback;
        }
        ?>
&nbsp;</td>
      </tr>
      <tr>
      <td>
      <?php 
        echo $strName;
        ?>
:
      </td>
      <td>
      <?php 
        if ($task == 'file_properties') {
            echo '<input type="text" class="textbox" name="name" value="' . strip_extension(htmlspecialchars($item['name'])) . '" maxlength="100" size="30" />';
            echo '<input type="hidden" name="extension" value="' . get_extension($item['name']) . '" />';
        } else {
            echo '<input type="text" class="textbox" name="name" value="' . htmlspecialchars($item['name']) . '" maxlength="100" size="30" />';
        }
        ?>
	</td>
	</tr>
	<tr>
	<td>
	<?php 
        echo $fbLocation;
        ?>
:
	</td>
	<td>