本文整理汇总了PHP中caGetTempDirPath函数的典型用法代码示例。如果您正苦于以下问题:PHP caGetTempDirPath函数的具体用法?PHP caGetTempDirPath怎么用?PHP caGetTempDirPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了caGetTempDirPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatchLoopShutdown
public function dispatchLoopShutdown()
{
//
// Force output to be sent - we need the client to have the page before
// we start flushing progress bar updates
//
$app = AppController::getInstance();
$req = $app->getRequest();
$resp = $app->getResponse();
$resp->sendResponse();
$resp->clearContent();
//
// Do export
//
if ($req->isLoggedIn()) {
set_time_limit(3600 * 24);
// if it takes more than 24 hours we're in trouble
$vn_id = $req->getParameter('exporter_id', pInteger);
$vs_search = $req->getParameter('search', pString);
$t_exporter = new ca_data_exporters($vn_id);
$vs_file = tempnam(caGetTempDirPath(), 'export');
ca_data_exporters::exportRecordsFromSearchExpression($t_exporter->get('exporter_code'), $vs_search, $vs_file, array('request' => $req, 'progressCallback' => 'caIncrementBatchMetadataExportProgress'));
}
// export done, move file to application tmp dir and create download link (separate action in the export controller)
if (filesize($vs_file)) {
$vs_new_filename = $vn_id . "_" . md5($vs_file);
rename($vs_file, __CA_APP_DIR__ . '/tmp/' . $vs_new_filename);
caExportAddDownloadLink($req, $vs_new_filename);
}
}
示例2: loadListIntoTemporaryResultTable
/**
* Quickly loads list of row_ids in $pa_hits into a temporary database table uniquely identified by $ps_key
* Only one temporary table can exist at a time for a given instance. If you call loadListIntoTemporaryResultTable()
* on an instance for which a temporary table has already been loaded the previously created table will be discarded
* before the new one is created.
*
* @param array $pa_hits Array of row_id values
* @param string $ps_key Unique alphanumeric identifier for the temporary table. Should only contain letters, numbers and underscores.
* @return string The name of the temporary table created
*/
public function loadListIntoTemporaryResultTable($pa_hits, $ps_key)
{
global $g_mysql_has_file_priv;
$ps_key = preg_replace('![^A-Za-z0-9_]+!', '_', $ps_key);
if ($this->ops_tmp_table_name == "caResultTmp{$ps_key}") {
return $this->ops_tmp_table_name;
}
if ($this->ops_tmp_file_path) {
$this->cleanupTemporaryResultTable();
}
$this->ops_tmp_file_path = tempnam(caGetTempDirPath(), 'caResultTmp');
$this->ops_tmp_table_name = "caResultTmp{$ps_key}";
$this->opo_db->query("\n\t\t\t\tCREATE TEMPORARY TABLE {$this->ops_tmp_table_name} (\n\t\t\t\t\trow_id int unsigned not null,\n\t\t\t\t\tkey (row_id)\n\t\t\t\t) engine=memory;\n\t\t\t");
if (!sizeof($pa_hits)) {
return $this->ops_tmp_table_name;
}
if (is_null($g_mysql_has_file_priv)) {
// Figure out if user has FILE priv
$qr_grants = $this->opo_db->query("\n\t\t\t\t\tSHOW GRANTS;\n\t\t\t\t");
$g_mysql_has_file_priv = false;
while ($qr_grants->nextRow()) {
$va_grants = array_values($qr_grants->getRow());
$vs_grant = array_shift($va_grants);
if (preg_match('!^GRANT FILE!', $vs_grant)) {
$g_mysql_has_file_priv = true;
break;
}
}
}
if ($g_mysql_has_file_priv === true) {
// Benchmarking has show that using "LOAD DATA INFILE" with an on-disk tmp file performs best
// The downside is that it requires the MySQL global FILE priv, which often is not granted, especially in shared environments
file_put_contents($this->ops_tmp_file_path, join("\n", $pa_hits));
chmod($this->ops_tmp_file_path, 0755);
$this->opo_db->query("LOAD DATA INFILE '{$this->ops_tmp_file_path}' INTO TABLE {$this->ops_tmp_table_name} (row_id)");
} else {
// Fallback when database login does not have FILE priv
$vs_sql = "INSERT IGNORE INTO {$this->ops_tmp_table_name} (row_id) VALUES ";
foreach ($pa_hits as $vn_row_id) {
$vs_sql .= "(" . (int) $vn_row_id . "),";
}
$this->opo_db->query(substr($vs_sql, 0, strlen($vs_sql) - 1));
}
return $this->ops_tmp_table_name;
}
示例3: getClient
/**
* @return Guzzle\Http\Client
*/
public function getClient()
{
if (!isset($this->o_client)) {
$this->o_client = new \Guzzle\Http\Client(self::NSL_SERVICES_URL, array('request.params' => array('cache.override_ttl' => 3600, 'params.cache.revalidate' => 'skip')));
// can_cache needs to be callable
$this->o_client->addSubscriber(new CachePlugin(array('storage' => new DefaultCacheStorage(new DoctrineCacheAdapter(new FilesystemCache(caGetTempDirPath()))), 'can_cache' => function () {
// let's just cache for the above ttl
return true;
})));
$o_conf = Configuration::load();
if ($vs_proxy = $o_conf->get('web_services_proxy_url')) {
/* proxy server is configured */
$vo_config = $this->o_client->getConfig()->add('proxy', $vs_proxy);
if (($vs_proxy_user = $o_conf->get('web_services_proxy_auth_user')) && ($vs_proxy_pass = $o_conf->get('web_services_proxy_auth_pw'))) {
$vo_config->add('curl.options', array(CURLOPT_PROXYUSERPWD => "{$vs_proxy_user}:{$vs_proxy_pass}"));
}
}
}
return $this->o_client;
}
示例4: UploadFiles
/**
* Handle ajax media uploads from editor
*/
public function UploadFiles($pa_options = null)
{
if (!$this->request->isLoggedIn() || (int) $this->request->user->get('userclass') !== 0) {
$this->response->setRedirect($this->request->config->get('error_display_url') . '/n/2320?r=' . urlencode($this->request->getFullUrlPath()));
return;
}
// use configured directory to dump media with fallback to standard tmp directory
if (!is_writeable($vs_tmp_directory = $this->request->config->get('ajax_media_upload_tmp_directory'))) {
$vs_tmp_directory = caGetTempDirPath();
}
$vn_user_id = $this->request->getUserID();
$vs_user_dir = $vs_tmp_directory . "/userMedia{$vn_user_id}";
if (!file_exists($vs_user_dir)) {
mkdir($vs_user_dir);
}
if (!($vn_timeout = (int) $this->request->config->get('ajax_media_upload_tmp_directory_timeout'))) {
$vn_timeout = 24 * 60 * 60;
}
// Cleanup any old files here
$va_files_to_delete = caGetDirectoryContentsAsList($vs_user_dir, true, false, false, true, array('modifiedSince' => time() - $vn_timeout));
foreach ($va_files_to_delete as $vs_file_to_delete) {
@unlink($vs_file_to_delete);
}
$va_stored_files = array();
foreach ($_FILES as $vn_i => $va_file) {
$vs_dest_filename = pathinfo($va_file['tmp_name'], PATHINFO_FILENAME);
copy($va_file['tmp_name'], $vs_dest_path = $vs_tmp_directory . "/userMedia{$vn_user_id}/{$vs_dest_filename}");
// write file metadata
file_put_contents("{$vs_dest_path}_metadata", json_encode(array('original_filename' => $va_file['name'], 'size' => filesize($vs_dest_path))));
$va_stored_files[$vn_i] = "userMedia{$vn_user_id}/{$vs_dest_filename}";
// only return the user directory and file name, not the entire path
}
print json_encode($va_stored_files);
}
示例5: _gmagickRead
private function _gmagickRead($ps_filepath)
{
try {
$handle = new Gmagick($ps_filepath);
$this->setResourceLimits($handle);
$handle->setimageindex(0);
// force use of first image in multi-page TIFF
$this->handle = $handle;
$this->filepath = $ps_filepath;
$this->metadata = array();
// handle metadata
/* EXIF */
if (function_exists('exif_read_data') && !$this->opo_config->get('dont_use_exif_read_data')) {
if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
$va_metadata['EXIF'] = $va_exif;
}
}
// if the builtin EXIF extraction is not used or failed for some reason, try ExifTool
if (!isset($va_metadata['EXIF']) || !is_array($va_metadata['EXIF'])) {
if (caExifToolInstalled()) {
$va_metadata['EXIF'] = caExtractMetadataWithExifTool($ps_filepath, true);
}
}
// Rotate incoming image as needed
if (isset($va_metadata['EXIF']['IFD0']['Orientation'])) {
$vn_orientation = $va_metadata['EXIF']['IFD0']['Orientation'];
$vs_tmp_basename = tempnam(caGetTempDirPath(), 'ca_image_tmp');
$vb_is_rotated = false;
switch ($vn_orientation) {
case 3:
$this->handle->rotateimage("#FFFFFF", 180);
unset($va_metadata['EXIF']['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
case 6:
$this->handle->rotateimage("#FFFFFF", 90);
unset($va_metadata['EXIF']['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
case 8:
$this->handle->rotateimage("#FFFFFF", -90);
unset($va_metadata['EXIF']['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
}
if ($vb_is_rotated) {
if ($this->handle->writeimage($vs_tmp_basename)) {
$va_tmp = $this->handle->getimagegeometry();
$this->properties["faces"] = $this->opa_faces = caDetectFaces($vs_tmp_basename, $va_tmp['width'], $va_tmp['height']);
}
@unlink($vs_tmp_basename);
}
}
// get XMP
$o_xmp = new XMPParser();
if ($o_xmp->parse($ps_filepath)) {
if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
$va_metadata['XMP'] = array();
foreach ($va_xmp_metadata as $vs_xmp_tag => $va_xmp_values) {
$va_metadata['XMP'][$vs_xmp_tag] = join('; ', $va_xmp_values);
}
}
}
// try to get IPTC and DPX with GraphicsMagick, if available
if (caMediaPluginGraphicsMagickInstalled()) {
/* IPTC metadata */
$vs_iptc_file = tempnam(caGetTempDirPath(), 'gmiptc');
@rename($vs_iptc_file, $vs_iptc_file . '.iptc');
// GM uses the file extension to figure out what we want
$vs_iptc_file .= '.iptc';
exec($this->ops_graphicsmagick_path . " convert " . caEscapeShellArg($ps_filepath) . " " . caEscapeShellArg($vs_iptc_file) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
$vs_iptc_data = file_get_contents($vs_iptc_file);
@unlink($vs_iptc_file);
$va_iptc_raw = iptcparse($vs_iptc_data);
$va_iptc_tags = array('2#004' => 'Genre', '2#005' => 'DocumentTitle', '2#010' => 'Urgency', '2#015' => 'Category', '2#020' => 'Subcategories', '2#025' => 'Keywords', '2#040' => 'SpecialInstructions', '2#055' => 'CreationDate', '2#060' => 'TimeCreated', '2#080' => 'AuthorByline', '2#085' => 'AuthorTitle', '2#090' => 'City', '2#095' => 'State', '2#100' => 'CountryCode', '2#101' => 'Country', '2#103' => 'OTR', '2#105' => 'Headline', '2#110' => 'Credit', '2#115' => 'PhotoSource', '2#116' => 'Copyright', '2#120' => 'Caption', '2#122' => 'CaptionWriter');
$va_iptc = array();
if (is_array($va_iptc_raw)) {
foreach ($va_iptc_raw as $vs_iptc_tag => $va_iptc_tag_data) {
if (isset($va_iptc_tags[$vs_iptc_tag])) {
$va_iptc[$va_iptc_tags[$vs_iptc_tag]] = join('; ', $va_iptc_tag_data);
}
}
}
if (sizeof($va_iptc)) {
$va_metadata['IPTC'] = $va_iptc;
}
/* DPX metadata */
exec($this->ops_graphicsmagick_path . " identify -format '%[DPX:*]' " . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
if ($va_output[0]) {
$va_metadata['DPX'] = $va_output;
}
}
$this->metadata = $va_metadata;
return $handle;
} catch (Exception $e) {
$this->postError(1610, _t("Could not read image file"), "WLPlugGmagick->read()");
return false;
// gmagick couldn't read file, presumably
}
}
示例6: _graphicsMagickGetMetadata
private function _graphicsMagickGetMetadata($ps_filepath)
{
$va_metadata = array();
/* EXIF metadata */
if (function_exists('exif_read_data') && !$this->opo_config->get('dont_use_exif_read_data')) {
if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
$va_metadata['EXIF'] = $va_exif;
}
}
// if the builtin EXIF extraction is not used or failed for some reason, try ExifTool
if (!isset($va_metadata['EXIF']) || !is_array($va_metadata['EXIF'])) {
if (caExifToolInstalled()) {
$va_metadata['EXIF'] = caExtractMetadataWithExifTool($ps_filepath, true);
}
}
// else try GraphicsMagick
if (!isset($va_metadata['EXIF']) || !is_array($va_metadata['EXIF'])) {
exec($this->ops_graphicsmagick_path . ' identify -format "%[EXIF:*]" ' . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
if (is_array($va_output) && sizeof($va_output) > 1) {
foreach ($va_output as $vs_output_line) {
$va_tmp = explode('=', $vs_output_line);
// format is "Make=NIKON CORPORATION"
if (isset($va_tmp[0]) && isset($va_tmp[1])) {
$va_metadata['EXIF'][$va_tmp[0]] = $va_tmp[1];
}
}
}
$va_output = array();
}
$o_xmp = new XMPParser();
if ($o_xmp->parse($ps_filepath)) {
if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
$va_metadata['XMP'] = array();
foreach ($va_xmp_metadata as $vs_xmp_tag => $va_xmp_values) {
$va_metadata['XMP'][$vs_xmp_tag] = join('; ', $va_xmp_values);
}
}
}
/* IPTC metadata */
$vs_iptc_file = tempnam(caGetTempDirPath(), 'gmiptc');
@rename($vs_iptc_file, $vs_iptc_file . '.iptc');
// GM uses the file extension to figure out what we want
$vs_iptc_file .= '.iptc';
exec($this->ops_graphicsmagick_path . " convert " . caEscapeShellArg($ps_filepath) . " " . caEscapeShellArg($vs_iptc_file) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
$vs_iptc_data = file_get_contents($vs_iptc_file);
@unlink($vs_iptc_file);
$va_iptc_raw = iptcparse($vs_iptc_data);
$va_iptc_tags = array('2#004' => 'Genre', '2#005' => 'DocumentTitle', '2#010' => 'Urgency', '2#015' => 'Category', '2#020' => 'Subcategories', '2#025' => 'Keywords', '2#040' => 'SpecialInstructions', '2#055' => 'CreationDate', '2#060' => 'TimeCreated', '2#080' => 'AuthorByline', '2#085' => 'AuthorTitle', '2#090' => 'City', '2#095' => 'State', '2#100' => 'CountryCode', '2#101' => 'Country', '2#103' => 'OTR', '2#105' => 'Headline', '2#110' => 'Credit', '2#115' => 'PhotoSource', '2#116' => 'Copyright', '2#120' => 'Caption', '2#122' => 'CaptionWriter');
$va_iptc = array();
if (is_array($va_iptc_raw)) {
foreach ($va_iptc_raw as $vs_iptc_tag => $va_iptc_tag_data) {
if (isset($va_iptc_tags[$vs_iptc_tag])) {
$va_iptc[$va_iptc_tags[$vs_iptc_tag]] = join('; ', $va_iptc_tag_data);
}
}
}
if (sizeof($va_iptc)) {
$va_metadata['IPTC'] = $va_iptc;
}
/* DPX metadata */
exec($this->ops_graphicsmagick_path . " identify -format '%[DPX:*]' " . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
if ($va_output[0]) {
$va_metadata['DPX'] = $va_output;
}
return $va_metadata;
}
示例7: _genExportWithMapping
protected function _genExportWithMapping($po_result, $pn_exporter_id)
{
// Can user batch export?
if (!$this->request->user->canDoAction('can_batch_export_metadata')) {
$this->response->setRedirect($this->request->config->get('error_display_url') . '/n/3440?r=' . urlencode($this->request->getFullUrlPath()));
return;
}
// Can user export records of this type?
if (!$this->request->user->canDoAction('can_export_' . $this->ops_tablename)) {
$this->response->setRedirect($this->request->config->get('error_display_url') . '/n/3430?r=' . urlencode($this->request->getFullUrlPath()));
return;
}
$t_exporter = new ca_data_exporters($pn_exporter_id);
if (!($t_exporter->getPrimaryKey() > 0)) {
$this->postError(3420, _t("Could not load export mapping"), "BaseFindController->_genExportWithMapping()");
return;
}
if (substr(get_class($this), 0, 6) == 'Browse') {
$vs_export_filename = Configuration::load()->get($this->ops_tablename . '_batch_export_filename');
} else {
$vs_export_filename = preg_replace("/[^\\p{L}\\p{N}\\-]/", '_', $this->opo_result_context->getSearchExpression());
$vs_export_filename = preg_replace("/[\\_]+/", '_', $vs_export_filename);
}
$vs_tmp_file = tempnam(caGetTempDirPath(), 'export');
ca_data_exporters::exportRecordsFromSearchResult($t_exporter->get('exporter_code'), $po_result, $vs_tmp_file);
header('Content-Type: ' . $t_exporter->getContentType() . '; charset=UTF-8');
header('Content-Disposition: attachment; filename="' . $vs_export_filename . '.' . $t_exporter->getFileExtension() . '"');
header('Content-Transfer-Encoding: binary');
readfile($vs_tmp_file);
@unlink($vs_tmp_file);
exit;
}
示例8: joinArchiveContents
public function joinArchiveContents($pa_files, $pa_options = array())
{
if (!is_array($pa_files)) {
return false;
}
$vs_archive_original = tempnam(caGetTempDirPath(), "caArchiveOriginal");
@rename($vs_archive_original, $vs_archive_original . ".tif");
$vs_archive_original = $vs_archive_original . ".tif";
$vo_orig = new Imagick();
foreach ($pa_files as $vs_file) {
if (file_exists($vs_file)) {
$vo_imagick = new Imagick();
if ($vo_imagick->readImage($vs_file)) {
$vo_orig->addImage($vo_imagick);
}
}
}
if ($vo_orig->getNumberImages() > 0) {
if ($vo_orig->writeImages($vs_archive_original, true)) {
return $vs_archive_original;
}
}
return false;
}
示例9: lockRelease
public static function lockRelease()
{
if (function_exists('sem_get') && caGetOSFamily() == OS_POSIX) {
if (!self::$s_lock_resource) {
self::$s_lock_resource = sem_get(ftok(__FILE__, 'CASearchIndexingQueue'));
}
sem_release(self::$s_lock_resource);
} else {
if (is_resource(self::$s_lock_resource)) {
@fclose(self::$s_lock_resource);
}
@unlink(caGetTempDirPath() . DIRECTORY_SEPARATOR . 'search_indexing_queue.lock');
}
}
示例10: loadListIntoTemporaryResultTable
/**
* Quickly loads list of row_ids in $pa_hits into a temporary database table uniquely identified by $ps_key
* Only one temporary table can exist at a time for a given instance. If you call loadListIntoTemporaryResultTable()
* on an instance for which a temporary table has already been loaded the previously created table will be discarded
* before the new one is created.
*
* @param array $pa_hits Array of row_id values
* @param string $ps_key Unique alphanumeric identifier for the temporary table. Should only contain letters, numbers and underscores.
* @param array $pa_options
* @return string The name of the temporary table created
*/
public function loadListIntoTemporaryResultTable($pa_hits, $ps_key, $pa_options = null)
{
global $g_mysql_has_file_priv;
$ps_key = preg_replace('![^A-Za-z0-9_]+!', '_', $ps_key);
if ($this->ops_tmp_table_name == "caResultTmp{$ps_key}") {
return $this->ops_tmp_table_name;
}
if ($this->ops_tmp_table_name) {
$this->cleanupTemporaryResultTable();
}
$this->ops_tmp_file_path = tempnam(caGetTempDirPath(), 'caResultTmp');
$this->ops_tmp_table_name = "caResultTmp{$ps_key}";
if (is_array($va_sortable_values = caGetOption('sortableValues', $pa_options, false))) {
$this->opo_db->query("\n\t\t\t\t\tCREATE TEMPORARY TABLE {$this->ops_tmp_table_name} (\n\t\t\t\t\t\trow_id int unsigned not null,\n\t\t\t\t\t\tsort_key1 varchar(255) not null default '',\n\t\t\t\t\t\tsort_key2 varchar(255) not null default '',\n\t\t\t\t\t\tsort_key3 varchar(255) not null default '',\n\t\t\t\t\t\tkey (row_id)\n\t\t\t\t\t) engine=memory;\n\t\t\t\t");
} else {
$this->opo_db->query("\n\t\t\t\t\tCREATE TEMPORARY TABLE {$this->ops_tmp_table_name} (\n\t\t\t\t\t\trow_id int unsigned not null,\n\t\t\t\t\t\tkey (row_id)\n\t\t\t\t\t) engine=memory;\n\t\t\t\t");
}
if (!sizeof($pa_hits)) {
return $this->ops_tmp_table_name;
}
if (is_null($g_mysql_has_file_priv)) {
// Figure out if user has FILE priv
$qr_grants = $this->opo_db->query("\n\t\t\t\t\tSHOW GRANTS;\n\t\t\t\t");
$g_mysql_has_file_priv = false;
while ($qr_grants->nextRow()) {
$va_grants = array_values($qr_grants->getRow());
$vs_grant = array_shift($va_grants);
if (preg_match('!^GRANT FILE!', $vs_grant)) {
$g_mysql_has_file_priv = true;
break;
}
}
}
if ($g_mysql_has_file_priv === true && sizeof($pa_hits) > 500) {
// Benchmarking has show that using "LOAD DATA INFILE" with an on-disk tmp file performs best with large result sets
// The downside is that it requires the MySQL global FILE priv, which often is not granted, especially in shared environments
$vs_data = '';
if (is_array($va_sortable_values)) {
foreach ($pa_hits as $vn_hit) {
if (!($vs_sort_key_1 = $va_sortable_values[0][$vn_hit])) {
$vs_sort_key_1 = '';
}
if (!($vs_sort_key_2 = $va_sortable_values[1][$vn_hit])) {
$vs_sort_key_2 = '';
}
if (!($vs_sort_key_3 = $va_sortable_values[2][$vn_hit])) {
$vs_sort_key_3 = '';
}
if (is_numeric($vs_sort_key_1)) {
$vs_sort_key_1 = str_pad($vs_sort_key_1, 12, '0', STR_PAD_LEFT);
}
if (is_numeric($vs_sort_key_2)) {
$vs_sort_key_2 = str_pad($vs_sort_key_2, 12, '0', STR_PAD_LEFT);
}
if (is_numeric($vs_sort_key_3)) {
$vs_sort_key_3 = str_pad($vs_sort_key_3, 12, '0', STR_PAD_LEFT);
}
$vs_data .= $vn_hit . ',' . $vs_sort_key_1 . ',' . $vs_sort_key_2 . ',' . $vs_sort_key_3 . "\n";
}
} else {
$vs_data = join("\n", $pa_hits);
}
file_put_contents($this->ops_tmp_file_path, $vs_data);
chmod($this->ops_tmp_file_path, 0755);
if (is_array($va_sortable_values)) {
$vs_sql = "LOAD DATA INFILE '{$this->ops_tmp_file_path}' INTO TABLE {$this->ops_tmp_table_name} FIELDS TERMINATED BY ',' (row_id, sort_key1, sort_key2, sort_key3)";
$this->opo_db->query($vs_sql);
} else {
$this->opo_db->query("LOAD DATA INFILE '{$this->ops_tmp_file_path}' INTO TABLE {$this->ops_tmp_table_name} (row_id)");
}
} else {
// Fallback when database login does not have FILE priv
if (is_array($va_sortable_values)) {
$vs_sql = "INSERT IGNORE INTO {$this->ops_tmp_table_name} (row_id, sort_key1, sort_key2, sort_key3) VALUES ";
foreach ($pa_hits as $vn_hit) {
if (!($vs_sort_key_1 = $va_sortable_values[0][$vn_hit])) {
$vs_sort_key_1 = '';
} else {
$vs_sort_key_1 = preg_replace("/[^[:alnum:][:space:]]/ui", '', $vs_sort_key_1);
}
if (!($vs_sort_key_2 = $va_sortable_values[1][$vn_hit])) {
$vs_sort_key_2 = '';
} else {
$vs_sort_key_2 = preg_replace("/[^[:alnum:][:space:]]/ui", '', $vs_sort_key_2);
}
if (!($vs_sort_key_3 = $va_sortable_values[2][$vn_hit])) {
$vs_sort_key_3 = '';
} else {
$vs_sort_key_3 = preg_replace("/[^[:alnum:][:space:]]/ui", '', $vs_sort_key_3);
//.........这里部分代码省略.........
示例11: read
public function read($ps_filepath, $mimetype = "")
{
if (!($this->handle && ${$ps_filepath} === $this->filepath)) {
if ($mimetype == 'image/tilepic') {
#
# Read in Tilepic format image
#
$this->handle = new TilepicParser($ps_filepath);
if (!$this->handle->error) {
$this->filepath = $ps_filepath;
foreach ($this->handle->properties as $k => $v) {
if (isset($this->properties[$k])) {
$this->properties[$k] = $v;
}
}
$this->properties["mimetype"] = "image/tilepic";
$this->properties["typename"] = "Tilepic";
return 1;
} else {
$this->postError(1610, $this->handle->error, "WLPlugGmagick->read()");
return false;
}
} else {
$this->handle = "";
$this->filepath = "";
if ($mimetype == 'image/x-dcraw') {
if ($this->filepath_conv) {
@unlink($this->filepath_conv);
}
if (!caMediaPluginDcrawInstalled($this->ops_dcraw_path)) {
$this->postError(1610, _t("Could not convert Camera RAW format file because conversion tool (dcraw) is not installed"), "WLPlugGmagick->read()");
return false;
}
$vs_tmp_name = tempnam(caGetTempDirPath(), "rawtmp");
if (!copy($ps_filepath, $vs_tmp_name)) {
$this->postError(1610, _t("Could not copy Camera RAW file to temporary directory"), "WLPlugGmagick->read()");
return false;
}
exec($this->ops_dcraw_path . " -T " . caEscapeShellArg($vs_tmp_name), $va_output, $vn_return);
if ($vn_return != 0) {
$this->postError(1610, _t("Camera RAW file conversion failed: %1", $vn_return), "WLPlugGmagick->read()");
return false;
}
if (!(file_exists($vs_tmp_name . '.tiff') && filesize($vs_tmp_name . '.tiff') > 0)) {
$this->postError(1610, _t("Translation from Camera RAW to TIFF failed"), "WLPlugGmagick->read()");
return false;
}
$ps_filepath = $this->filepath_conv = $vs_tmp_name . '.tiff';
@unlink($vs_tmp_name);
}
try {
$handle = new Gmagick($ps_filepath);
$handle->setimageindex(0);
// force use of first image in multi-page TIFF
$this->handle = $handle;
$this->filepath = $ps_filepath;
$this->metadata = array();
// exif
if (function_exists('exif_read_data')) {
if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
//
// Rotate incoming image as needed
//
if (isset($va_exif['IFD0']['Orientation'])) {
$vn_orientation = $va_exif['IFD0']['Orientation'];
$vs_tmp_basename = tempnam(caGetTempDirPath(), 'ca_image_tmp');
$vb_is_rotated = false;
switch ($vn_orientation) {
case 3:
$this->handle->rotateimage("#FFFFFF", 180);
unset($va_exif['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
case 6:
$this->handle->rotateimage("#FFFFFF", 90);
unset($va_exif['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
case 8:
$this->handle->rotateimage("#FFFFFF", -90);
unset($va_exif['IFD0']['Orientation']);
$vb_is_rotated = true;
break;
}
if ($vb_is_rotated) {
if ($this->handle->writeimage($vs_tmp_basename)) {
$va_tmp = $this->handle->getimagegeometry();
$this->properties["faces"] = $this->opa_faces = caDetectFaces($vs_tmp_basename, $va_tmp['width'], $va_tmp['height']);
}
@unlink($vs_tmp_basename);
}
}
$this->metadata['EXIF'] = $va_exif;
}
}
// XMP
$o_xmp = new XMPParser();
if ($o_xmp->parse($ps_filepath)) {
if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
$this->metadata['XMP'] = $va_xmp_metadata;
//.........这里部分代码省略.........
示例12: hookPeriodicTask
/**
* Perform periodic tasks
*
* @return boolean true because otherwise it disables subsequent plugins
*/
public function hookPeriodicTask(&$pa_params)
{
global $AUTH_CURRENT_USER_ID;
$t_log = new Eventlog();
$o_db = new Db();
//$t_log->log(array('CODE' => 'ERR', 'MESSAGE' => _t('Could not authenticate to remote system %1', $vs_base_url), 'SOURCE' => 'traveloguePlugin->hookPeriodicTask'));
// Get new email
$pn_locale_id = 1;
// US
$vs_server = $this->opo_config->get('imap_server');
$vs_username = $this->opo_config->get('username');
$vs_password = $this->opo_config->get('password');
$vs_ssl = $this->opo_config->get('ssl');
if (!$vs_server) {
return true;
}
if (!$vs_username) {
return true;
}
try {
$o_mail = new Zend_Mail_Storage_Imap(array('host' => $vs_server, 'user' => $vs_username, 'password' => $vs_password, 'ssl' => $vs_ssl));
} catch (Exception $e) {
return true;
}
$va_mimetypes = $this->opo_config->getList('mimetypes');
$va_mail_to_delete = array();
foreach ($o_mail as $vn_message_num => $o_message) {
$va_mail_to_delete[$vn_message_num] = true;
// Extract title from subject line of email
$vs_subject = $o_message->subject;
$vs_from = $o_message->headerExists('from') ? $o_message->from : "";
print "PROCESSING {$vs_subject} FROM {$vs_from}\n";
// Extract media from email attachments
// Extract caption from email body
$va_images = array();
$va_texts = array();
foreach (new RecursiveIteratorIterator($o_message) as $o_part) {
try {
if (in_array(strtok($o_part->contentType, ';'), $va_mimetypes)) {
$va_images[] = $o_part;
} else {
if (in_array(strtok($o_part->contentType, ';'), array("text/plain", "text/html"))) {
$va_texts[] = (string) $o_part;
}
}
} catch (Zend_Mail_Exception $e) {
// ignore
}
}
if (!sizeof($va_images)) {
continue;
}
// Get user by email address
if (preg_match('!<([^>]+)>!', $vs_from, $va_matches)) {
// extract raw address from "from" header
$vs_from = $va_matches[1];
}
$t_user = new ca_users();
if ($t_user->load(array('email' => $vs_from))) {
$AUTH_CURRENT_USER_ID = $vn_user_id = $t_user->getPrimaryKey();
// force libs to consider matched user as logged in; change log will reflect this name
} else {
$vn_user_id = null;
}
// Create object
$t_object = new ca_objects();
$t_object->setMode(ACCESS_WRITE);
$t_object->set('type_id', $this->opo_config->get('object_type'));
// TODO: set idno to autogenerated # and/or allow for configurable policy
$t_object->set('idno', '');
$t_object->set('access', $this->opo_config->get('default_access'));
$t_object->set('status', $this->opo_config->get('default_status'));
// TODO: make this a configurable mapping ala how media metadata is done
$t_object->addAttribute(array('locale_id' => $pn_locale_id, 'generalNotes' => join("\n\n", $va_texts)), 'generalNotes');
$t_object->insert();
DataMigrationUtils::postError($t_object, "While adding object", "traveloguePlugin");
// TODO: log this
$t_object->addLabel(array('name' => $vs_subject), $pn_locale_id, null, true);
DataMigrationUtils::postError($t_object, "While adding label", "traveloguePlugin");
// TODO: log this
// Add representation
$vs_tmp_file_path = tempnam(caGetTempDirPath(), 'travelogue_');
foreach ($va_images as $vn_i => $vs_file_content) {
if (file_put_contents($vs_tmp_file_path, base64_decode((string) $vs_file_content))) {
$t_object->addRepresentation($vs_tmp_file_path, $this->opo_config->get('representation_type'), 1, $this->opo_config->get('default_status'), $this->opo_config->get('default_access'), true);
DataMigrationUtils::postError($t_object, "While adding media", "traveloguePlugin");
// TODO: log this
}
}
// TODO: add option to link user-as-entity to image (probably as creator)
}
foreach (array_reverse(array_keys($va_mail_to_delete)) as $vn_message_num) {
$o_mail->removeMessage($vn_message_num);
}
return true;
//.........这里部分代码省略.........
示例13: importMediaFromDirectory
/**
* @param RequestHTTP $po_request
* @param null|array $pa_options
* progressCallback =
* reportCallback =
* sendMail =
* log = log directory path
* logLevel = KLogger constant for minimum log level to record. Default is KLogger::INFO. Constants are, in descending order of shrillness:
* KLogger::EMERG = Emergency messages (system is unusable)
* KLogger::ALERT = Alert messages (action must be taken immediately)
* KLogger::CRIT = Critical conditions
* KLogger::ERR = Error conditions
* KLogger::WARN = Warnings
* KLogger::NOTICE = Notices (normal but significant conditions)
* KLogger::INFO = Informational messages
* KLogger::DEBUG = Debugging messages
* @return array
*/
public static function importMediaFromDirectory($po_request, $pa_options = null)
{
global $g_ui_locale_id;
$vs_log_dir = caGetOption('log', $pa_options, __CA_APP_DIR__ . "/log");
$vs_log_level = caGetOption('logLevel', $pa_options, "INFO");
if (!is_writeable($vs_log_dir)) {
$vs_log_dir = caGetTempDirPath();
}
$vn_log_level = BatchProcessor::_logLevelStringToNumber($vs_log_level);
$o_log = new KLogger($vs_log_dir, $vn_log_level);
$vs_import_target = caGetOption('importTarget', $pa_options, 'ca_objects');
$t_instance = $po_request->getAppDatamodel()->getInstance($vs_import_target);
$o_eventlog = new Eventlog();
$t_set = new ca_sets();
$va_notices = $va_errors = array();
$vb_we_set_transaction = false;
$o_trans = isset($pa_options['transaction']) && $pa_options['transaction'] ? $pa_options['transaction'] : null;
if (!$o_trans) {
$vb_we_set_transaction = true;
$o_trans = new Transaction($t_set->getDb());
}
$o_batch_log = new Batchlog(array('user_id' => $po_request->getUserID(), 'batch_type' => 'MI', 'table_num' => (int) $t_instance->tableNum(), 'notes' => '', 'transaction' => $o_trans));
if (!is_dir($pa_options['importFromDirectory'])) {
$o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => $vs_msg = _t("Specified import directory '%1' is invalid", $pa_options['importFromDirectory'])));
$o_log->logError($vs_msg);
return null;
}
$vs_batch_media_import_root_directory = $po_request->config->get('batch_media_import_root_directory');
if (!preg_match("!^{$vs_batch_media_import_root_directory}!", $pa_options['importFromDirectory'])) {
$o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => $vs_msg = _t("Specified import directory '%1' is invalid", $pa_options['importFromDirectory'])));
$o_log->logError($vs_msg);
return null;
}
if (preg_match("!\\.\\./!", $pa_options['importFromDirectory'])) {
$o_eventlog->log(array("CODE" => 'ERR', "SOURCE" => "mediaImport", "MESSAGE" => $vs_msg = _t("Specified import directory '%1' is invalid", $pa_options['importFromDirectory'])));
$o_log->logError($vs_msg);
return null;
}
$vb_include_subdirectories = (bool) $pa_options['includeSubDirectories'];
$vb_delete_media_on_import = (bool) $pa_options['deleteMediaOnImport'];
$vs_import_mode = $pa_options['importMode'];
$vs_match_mode = $pa_options['matchMode'];
$vn_type_id = $pa_options[$vs_import_target . '_type_id'];
$vn_rep_type_id = $pa_options['ca_object_representations_type_id'];
$va_limit_matching_to_type_ids = $pa_options[$vs_import_target . '_limit_matching_to_type_ids'];
$vn_access = $pa_options[$vs_import_target . '_access'];
$vn_object_representation_access = $pa_options['ca_object_representations_access'];
$vn_status = $pa_options[$vs_import_target . '_status'];
$vn_object_representation_status = $pa_options['ca_object_representations_status'];
$vn_rel_type_id = isset($pa_options[$vs_import_target . '_representation_relationship_type']) ? $pa_options[$vs_import_target . '_representation_relationship_type'] : null;
$vn_mapping_id = $pa_options[$vs_import_target . '_mapping_id'];
$vn_object_representation_mapping_id = $pa_options['ca_object_representations_mapping_id'];
$vs_idno_mode = $pa_options['idnoMode'];
$vs_idno = $pa_options['idno'];
$vs_representation_idno_mode = $pa_options['representationIdnoMode'];
$vs_representation_idno = $pa_options['representation_idno'];
$vs_set_mode = $pa_options['setMode'];
$vs_set_create_name = $pa_options['setCreateName'];
$vn_set_id = $pa_options['set_id'];
$vn_locale_id = $pa_options['locale_id'];
$vs_skip_file_list = $pa_options['skipFileList'];
$vs_skip_file_list = $pa_options['skipFileList'];
$vb_allow_duplicate_media = $pa_options['allowDuplicateMedia'];
$va_relationship_type_id_for = array();
if (is_array($va_create_relationship_for = $pa_options['create_relationship_for'])) {
foreach ($va_create_relationship_for as $vs_rel_table) {
$va_relationship_type_id_for[$vs_rel_table] = $pa_options['relationship_type_id_for_' . $vs_rel_table];
}
}
if (!$vn_locale_id) {
$vn_locale_id = $g_ui_locale_id;
}
$va_files_to_process = caGetDirectoryContentsAsList($pa_options['importFromDirectory'], $vb_include_subdirectories);
$o_log->logInfo(_t('Found %1 files in directory \'%2\'', sizeof($va_files_to_process), $pa_options['importFromDirectory']));
if ($vs_set_mode == 'add') {
$t_set->load($vn_set_id);
} else {
if ($vs_set_mode == 'create' && $vs_set_create_name) {
$va_set_ids = $t_set->getSets(array('user_id' => $po_request->getUserID(), 'table' => $t_instance->tableName(), 'access' => __CA_SET_EDIT_ACCESS__, 'setIDsOnly' => true, 'name' => $vs_set_create_name));
$vn_set_id = null;
if (is_array($va_set_ids) && sizeof($va_set_ids) > 0) {
$vn_possible_set_id = array_shift($va_set_ids);
//.........这里部分代码省略.........
示例14: write
/**
* @param array $pa_options Options include:
* dontUseDefaultIcons = If set to true, write will fail rather than use default icons when preview can't be generated. Default is false – to use default icons.
*
*/
public function write($ps_filepath, $ps_mimetype, $pa_options = null)
{
if (!$this->handle) {
return false;
}
$vb_dont_allow_default_icons = isset($pa_options['dontUseDefaultIcons']) && $pa_options['dontUseDefaultIcons'] ? true : false;
# is mimetype valid?
if (!($vs_ext = $this->info["EXPORT"][$ps_mimetype])) {
$this->postError(1610, _t("Can't convert file to %1", $ps_mimetype), "WLPlugMediaOffice->write()");
return false;
}
# write the file
if ($ps_mimetype == "application/msword") {
if (!copy($this->filepath, $ps_filepath . ".doc")) {
$this->postError(1610, _t("Couldn't write file to '%1'", $ps_filepath), "WLPlugMediaOffice->write()");
return false;
}
} else {
if (!isset(WLPlugMediaOffice::$s_pdf_conv_cache[$this->filepath]) && $this->opb_libre_office_installed) {
$vs_tmp_dir_path = caGetTempDirPath();
$va_tmp = explode("/", $this->filepath);
$vs_out_file = array_pop($va_tmp);
putenv("HOME={$vs_tmp_dir_path}");
// libreoffice will fail silently if you don't set this environment variable to a directory it can write to. Nice way to waste a day debugging. Yay!
exec($this->ops_libreoffice_path . " --nologo --nofirststartwizard --headless -convert-to pdf " . caEscapeShellArg($this->filepath) . " -outdir " . caEscapeShellArg($vs_tmp_dir_path) . " 2>&1", $va_output, $vn_return);
exec($this->ops_libreoffice_path . " --nologo --nofirststartwizard --headless -convert-to html " . caEscapeShellArg($this->filepath) . " -outdir " . caEscapeShellArg($vs_tmp_dir_path) . " 2>&1", $va_output, $vn_return);
$va_out_file = explode(".", $vs_out_file);
if (sizeof($va_out_file) > 1) {
array_pop($va_out_file);
}
$this->handle['content'] = strip_tags(file_get_contents("{$vs_tmp_dir_path}/" . join(".", $va_out_file) . ".html"));
$va_out_file[] = 'pdf';
WLPlugMediaOffice::$s_pdf_conv_cache[$this->filepath] = "{$vs_tmp_dir_path}/" . join(".", $va_out_file);
$o_media = new Media();
if ($o_media->read(WLPlugMediaOffice::$s_pdf_conv_cache[$this->filepath])) {
$this->set('width', $this->ohandle["width"] = $o_media->get('width'));
$this->set('height', $this->ohandle["height"] = $o_media->get('height'));
$this->set('resolution', $this->ohandle["resolution"] = $o_media->get('resolution'));
}
}
if ($vs_media = WLPlugMediaOffice::$s_pdf_conv_cache[$this->filepath]) {
switch ($ps_mimetype) {
case 'application/pdf':
$o_media = new Media();
$o_media->read($vs_media);
$o_media->set('version', $this->get('version'));
$o_media->write($ps_filepath, $ps_mimetype, array());
$vs_filepath_with_extension = $ps_filepath . ".pdf";
break;
case 'image/jpeg':
$o_media = new Media();
$o_media->read($vs_media);
$o_media->set('version', $this->get('version'));
foreach ($this->opa_transformations as $va_transform) {
$o_media->transform($va_transform['op'], $va_transform['params']);
}
$o_media->write($ps_filepath, $ps_mimetype, array());
$this->set('width', $o_media->get('width'));
$this->set('height', $o_media->get('height'));
$vs_filepath_with_extension = $ps_filepath . ".jpg";
break;
}
}
# use default media icons
if (!file_exists($vs_filepath_with_extension)) {
// always jpegs
return $vb_dont_allow_default_icons ? null : __CA_MEDIA_DOCUMENT_DEFAULT_ICON__;
}
}
$this->properties["mimetype"] = $ps_mimetype;
$this->properties["filesize"] = filesize($ps_filepath . "." . $vs_ext);
//$this->properties["typename"] = $this->typenames[$ps_mimetype];
return $ps_filepath . "." . $vs_ext;
}
示例15: parse
public function parse($ps_filepath)
{
if (!function_exists("simplexml_load_file")) {
return null;
}
$this->init();
// Is file a KMZ file?
$o_unzip = new UnZipFile($ps_filepath);
$vs_tmp_dirname = tempnam(caGetTempDirPath(), 'kml');
@unlink($vs_tmp_dirname);
@mkdir($vs_tmp_dirname);
if ($o_unzip->extract($vs_tmp_dirname, 'doc.kml')) {
if (file_exists($vs_tmp_dirname . '/doc.kml')) {
$ps_filepath = $vs_tmp_dirname . '/doc.kml';
} else {
return false;
}
}
$o_kml = @simplexml_load_file($ps_filepath);
if (!$o_kml) {
return false;
}
caRemoveDirectory($vs_tmp_dirname, true);
//
// Placemarks
//
$va_namespaces = $o_kml->getNamespaces(true);
foreach ($va_namespaces as $vs_prefix => $vs_schema_url) {
$o_kml->registerXPathNamespace($vs_prefix ? $vs_prefix : 'g', $vs_schema_url);
}
$va_placemarks = $o_kml->xpath('//g:Placemark');
$this->opa_filedata['placemarks'] = array();
foreach ($va_placemarks as $va_placemark) {
$vs_name = '' . $va_placemark->name[0];
$vs_description = '' . $va_placemark->description[0];
if (isset($va_placemark->Point)) {
$vs_coord = $va_placemark->Point->coordinates;
$va_tmp = explode(',', $vs_coord);
$this->opa_filedata['placemarks'][] = array('name' => $vs_name, 'type' => 'POINT', 'description' => $vs_description, 'latitude' => $va_tmp[1], 'longitude' => $va_tmp[0]);
} else {
if (isset($va_placemark->LineString) && isset($va_placemark->LineString->coordinates)) {
$vs_coords = trim($va_placemark->LineString->coordinates);
$va_coord_lines = preg_split("/[ \n\r]+/", $vs_coords);
} else {
if (isset($va_placemark->Polygon) && isset($va_placemark->Polygon->outerBoundaryIs) && isset($va_placemark->Polygon->outerBoundaryIs->LinearRing) && isset($va_placemark->Polygon->outerBoundaryIs->LinearRing->coordinates)) {
$vs_coords = trim($va_placemark->Polygon->outerBoundaryIs->LinearRing->coordinates);
$va_coord_lines = preg_split("/[ \n\r]+/", $vs_coords);
}
}
if (sizeof($va_coord_lines) > 0) {
$va_coord_list = array();
foreach ($va_coord_lines as $vs_coord_line) {
$va_tmp = explode(',', $vs_coord_line);
$va_coord_list[] = array('latitude' => $va_tmp[1], 'longitude' => $va_tmp[0]);
}
$this->opa_filedata['placemarks'][] = array('name' => $vs_name, 'type' => 'PATH', 'description' => $vs_description, 'coordinates' => $va_coord_list);
}
}
}
return true;
}