function fmGetContainer($fm_databases) { // Determine the resource that is being requested via the _SERVER scope. // ex: http://localhost/dynamic-containers/530f982c01733/1393530924/Sample.pdf if (isset($_SERVER['SCRIPT_URI'])) { $resource_requested = $_SERVER['SCRIPT_URI']; } elseif (isset($_SERVER['REDIRECT_URL'])) { $resource_requested = $_SERVER['REDIRECT_URL']; } else { die('fmGetContainer: Unable to determine the resource that was requested.'); } // Remove the Root URL from the resource requested. // This resolves issues encountered when the Web app is in a sub-folder. // Example: /containers/macmini.png $resource_requested = fmSubstitute($resource_requested, HTTP_ROOT_URL, ''); // Remove the virtual container folder from the resource requested. // This resolves issues encountered when the Web app is in a sub-folder. // Example: /macmini.png $resource_requested = fmSubstitute($resource_requested, CONTAINER_FOLDER, ''); // fmDump ( $resource_requested, TRUE, 'resource_requested' ); // Get the resource's info file name. // Example: macmini.png.info $info_file_name = fmSubstitute($resource_requested, '/', '-'); $info_file_name = fmRight($info_file_name, fmLength($info_file_name) - 1); $info_file_name .= '.info'; // fmDump ( $info_file_name, TRUE, 'info_file_name' ); // Get the OS path that was used to store the container's info file. // Example: /domains/demo.fmwebframe.com/html/FMWebFrame/../temp/macmini.png.info $physical_path_container_info_file = CONTAINER_PATH . '/' . $info_file_name; // fmDump ( $physical_path_container_info_file, TRUE, 'physical_path_container_info_file' ); // If the info file wasn't found... if (!file_exists($physical_path_container_info_file)) { // Return control to the 404 error handler. return; } // Read the info file. $info_file_contents = @file_get_contents($physical_path_container_info_file); // fmDump ( $info_file_contents, TRUE, 'info_file_contents' ); // Convert the contents of the info file into an array. $container_info_array = preg_split("/\n/", $info_file_contents); // fmDump ( $container_info_array, TRUE, 'container_info_array' ); // Break the array up into variables for easier reference. $container_field_as_text = $container_info_array[0]; $maximum_age = $container_info_array[1]; $access_rule = $container_info_array[2]; // Get the OS path that will be used to get/save the container's binary contents. // Example: /domains/demo.fmwebframe.com/html/FMWebFrame/../temp/macmini.png $physical_path_container_contents_file = fmLeft($physical_path_container_info_file, fmLength($physical_path_container_info_file) - 5); // fmDump ( $physical_path_container_contents_file, TRUE, 'physical_path_container_contents_file' ); // If the URL is only valid for a certain amount of time... if ($maximum_age > 0) { // Get the age of the info file. $file_age = time() - filemtime($physical_path_container_info_file); // fmDump ( $file_age, TRUE, 'file_age' ); // If the URL has expired... if ($file_age >= $maximum_age) { // Delete the "stale" files. @unlink($physical_path_container_contents_file); @unlink($physical_path_container_info_file); // Return control to the 404 error handler. return; } } // If an access rule was specified... if ($access_rule !== '') { // Evaluate the rule. $allow_access = eval('return (' . $access_rule . ');'); //fmDump ( $access_rule, FALSE, 'access_rule' ); //fmDump ( $allow_access, TRUE, 'allow_access' ); // If the rule failed... if (!$allow_access) { // Replace the 404 response with a "403 Forbidden" and die. header('Status: 403', TRUE, 403); die; } } // Split the container's text value into an array so that we can isolate the file name & container info. $container_field_array = explode('?', $container_field_as_text); // fmDump ( $container_field_array, TRUE, 'container_field_array' ); // Get the file name (the first element of the "container_field_array" array). $filename = $container_field_array[0]; $filename = fmsubstitute($filename, '/fmi/xml/cnt/', ''); $filename = urldecode($filename); $filename = fmsubstitute($filename, ' ', '-'); // fmDump ( $filename, TRUE, 'filename' ); // Parse the second element of the "container_field_array" array into individual variables. // Note: parse_str parses a query string into variables. // ex: -db=FMWebFrame_Demo&-lay=Resource%20-%20Form&-recid=2&-field=Resource(1) // ---> db = FMWebFrame_Demo // ---> lay = Resource - Form // ---> recid = 2 // ---> field = Resource(1) // Note that we're most interested in the database name, which we need in order to // determine the database connection info to use should we need to refer back to // the record that the container was pulled from. $container_info = html_entity_decode($container_field_array[1]); $container_info = fmsubstitute($container_info, '-db', 'db'); $container_info = fmsubstitute($container_info, '&-', '&'); parse_str($container_info); // fmDump ( $db, TRUE, 'db' ); // If the container contents file is available... if (file_exists($physical_path_container_contents_file)) { // Read the file. $container_data = @file_get_contents($physical_path_container_contents_file); } else { // Using the database name, find the database connection to use... foreach ($fm_databases as $fm_database) { // If the connection was found... if ($fm_database['database'] == $db) { // Create a connection to the database. $fm = new FileMaker(); $fm->setProperty('hostspec', $fm_database['hostspec']); $fm->setProperty('database', $fm_database['database']); $fm->setProperty('username', $fm_database['username']); $fm->setProperty('password', $fm_database['password']); break; } } if (!isset($fm)) { // Return control to the 404 error handler. return; } // fmDump ( $fm, TRUE, 'fm' ); // Get the record that the container was pulled from. $container_record = $fm->getRecordById($lay, $recid); // fmDump ( $container_record, TRUE, 'container_record' ); // Get the container data. $container_data = $fm->getContainerData($container_field_as_text); if (FileMaker::isError($container_data)) { die; } // fmDump ( $container_data, FALSE, 'container_data' ); // Save the container's contents on the server. @file_put_contents($physical_path_container_contents_file, $container_data); } // If we have the container's content... if (isset($container_data)) { // Update the http response header, so that this does not appear to be a "404." header('Status: 200', TRUE, 200); // Explode the filename to get the extension. $filename_parts = explode('.', $filename); $extension = $filename_parts[1]; // If the extension includes a URL request... if (fmPatternCount($extension, '?')) { $extension_parts = explode('?', $extension); $extension = $extension_parts[0]; } // Setup the headers to use, based on the file type (extension). switch ($extension) { case 'gif': header('Content-type: image/gif'); header('Content-Disposition: filename="' . $filename . '"'); break; case 'jpeg': header('Content-type: image/jpeg'); header('Content-Disposition: filename="' . $filename . '"'); break; case 'jpg': header('Content-type: image/jpeg'); header('Content-Disposition: filename="' . $filename . '"'); break; case 'mov': header('Content-type: video/quicktime'); header('Content-Disposition: filename="' . $filename . '"'); break; case 'mp3': header('Content-type: audio/mpeg'); header('Content-Disposition: filename="' . $filename . '"'); break; case 'mp4': header('Content-type: video/mp4'); header('Content-Disposition: filename="' . $filename . '"'); break; case 'ogg': header('Content-type: application/ogg'); header('Content-Disposition: filename="' . $filename . '"'); break; case 'pdf': header('Content-type: application/pdf'); header('Content-Disposition: filename="' . $filename . '"'); break; case 'png': header('Content-type: image/png'); header('Content-Disposition: filename="' . $filename . '"'); break; default: header('Content-type: application/force-download'); header('Content-Transfer-Encoding: Binary'); header('Content-Disposition: attachment; filename="' . $filename . '"'); } // Send additional headers. header('Content-Length: ' . strlen($container_data)); header('Cache-Control: private'); // Send the container's binary data. echo $container_data; die; } }
function fmCacheList($cache_path = CACHE_PATH) { $cache_files = array(); if (is_dir($cache_path)) { if ($dh = opendir($cache_path)) { while (($file = readdir($dh)) !== false) { if (filetype($cache_path . '/' . $file) == 'file') { $a = array(); $a['filename'] = fmSubstitute($file, '.fmcache', ''); $a['size_kb'] = number_format(filesize($cache_path . '/' . $file) / 1024, 2); $a['date_created'] = date("m/d/Y H:i:s", filemtime($cache_path . '/' . $file)); $a['age_seconds'] = time() - filemtime($cache_path . '/' . $file); $cache_files[] = $a; } } closedir($dh); } } return $cache_files; }
function fmQuickFind($connection, $quickfind_layout, $query, $result_layout = null, $sort = null, $start_row = 1, $max_rows = 999999999) { // If the specified database connection isn't valid... if (!isset($connection)) { $error_message = 'fmQuickFind failed. It looks like the database connection that was specified is invalid.'; die($error_message); } // Create the FileMaker script paramater. $params = "Quick Find\n"; $params .= $query . "\n"; // Find any record. $fm_request = $connection->newFindAnyCommand($quickfind_layout); // Call the FMWebFrame script as the pre-sort script. $fm_request->setPreSortScript('FMWebFrame', $params); // Specify the starting record to be returned, and the maximum number of records to be returned. $fm_request->setRange($start_row - 1, $max_rows); // If a result layout was specified... if ($result_layout !== null) { $fm_request->setResultLayout($result_layout); } // If a sort order was specified... if ($sort !== null) { // Remove extra spaces after commas. $sort = fmSubstitute($sort, ', ', ','); // Convert the string to an array. $sort_array = explode(',', $sort); // Loop over the array to add the sort rules... for ($i = 0; $i < count($sort_array); $i++) { $sort_spec = explode(' ', $sort_array[$i]); $direction = $sort_spec[count($sort_spec) - 1]; $field = implode(' ', array_slice($sort_spec, 0, count($sort_spec) - 1)); $fm_request->addSortRule($field, $i + 1, fmlower($direction) . 'end'); } } // Execute the request. $fm_result = $fm_request->execute(); // Return the result. return $fm_result; }
// Build the SELECT statement. $query = 'SELECT Last_Name, First_Name, City, State, Zip_Code FROM Contacts WHERE'; if ($_GET['first_name'] !== '') { $query .= ' First_Name LIKE \'' . fmSubstitute($_GET['first_name'], '\'', '\'\'') . '%\''; } if ($_GET['last_name'] !== '') { if ($_GET['first_name'] !== '') { $query .= ' AND'; } $query .= ' Last_Name LIKE \'' . fmSubstitute($_GET['last_name'], '\'', '\'\'') . '%\''; } if ($_GET['state'] !== '') { if ($_GET['first_name'] !== '' or $_GET['last_name'] !== '') { $query .= ' AND'; } $query .= ' State = \'' . fmSubstitute($_GET['state'], '\'', '\'\'') . '\''; } $query .= ' ORDER BY Last_Name, First_Name'; // Execute the query. $contacts = fmExecuteSQL($fmDemo, $query); // Set page title. $ui_title = "FMWebFrame Demo | ExecuteSQL"; // Start output buffering. ob_start(); // Page header. echo '<h1>ExecuteSQL</h1>'; // If there was a problem with the query... if ($contacts == '?') { echo '<p>Oops! An unexpected error occurred.</p>'; echo '<p><a href="executesql-form.php">Click here</a> to try again.</p>'; } elseif ($contacts == '') {
function fmGetContainerURL($connection = null, $record = null, $field_name = null, $use_uuid = FALSE, $virtual_subfolder = null, $maximum_age = 30, $access_rule = null) { // Get the value of the container as a string. // This is the same value that you would normally pass to the "getContainerData" method to // get a container's binary contents. // Example: /fmi/xml/cnt/Sample.pdf?-db=FMWebFrame_Demo&-lay=Resource%20-%20Form&-recid=2&-field=Resource(1) $container_field_as_text = $record->getField($field_name); // fmDump ( $container_field_as_text, FALSE ); // Split the text value into an array so that we can isolate the file name. $container_field_array = explode('?', $container_field_as_text); // fmDump ( $container_field_array, FALSE ); // Get the filename from the first element of the array. // Ex: /fmi/xml/cnt/Sample.pdf ---> Sample.pdf $filename = $container_field_array[0]; $filename = fmsubstitute($filename, '/fmi/xml/cnt/', ''); $filename = urldecode($filename); $filename = fmsubstitute($filename, ' ', '-'); // fmDump ( $filename, FALSE, 'FileName' ); // Parse the second element of the array into individual variables. // Note: parse_str parses a query string into variables. // ex: -db=FMWebFrame_Demo&-lay=Resource%20-%20Form&-recid=2&-field=Resource(1) // ---> db = FMWebFrame_Demo // ---> lay = Resource - Form // ---> recid = 2 // ---> field = Resource(1) $container_info = html_entity_decode($container_field_array[1]); $container_info = fmsubstitute($container_info, '-db', 'db'); $container_info = fmsubstitute($container_info, '&-', '&'); parse_str($container_info); // Create the OS path that will be used to store the container's info file. $physical_path_info_file = CONTAINER_PATH . '/'; if ($use_uuid) { $uuid = uniqid() . '-' . time(); $physical_path_info_file .= $uuid . '-'; } if ($virtual_subfolder !== NULL) { $physical_path_info_file .= fmSubstitute($virtual_subfolder, '/', '-') . '-'; } $physical_path_info_file .= $filename . '.info'; // fmDump ( $physical_path_info_file, TRUE, 'physical_path_info_file' ); // Prepare the contents of the info file. $info_file_contents = $container_field_as_text . "\n"; $info_file_contents .= $maximum_age . "\n"; $info_file_contents .= $access_rule . "\n"; // Save the info file. @file_put_contents($physical_path_info_file, $info_file_contents); // Create the virtual URL that will be used to serve up the file. $virtual_url = HTTP_ROOT_URL . CONTAINER_FOLDER . '/'; if ($use_uuid) { $virtual_url .= fmSubstitute($uuid, '-', '/') . '/'; } if ($virtual_subfolder !== NULL) { $virtual_url .= fmSubstitute($virtual_subfolder, '-', '/') . '/'; } $virtual_url .= $filename; // fmDump ( $virtual_url, TRUE, 'virtual_url' ); // Return the URL to the caller. return $virtual_url; }
echo '<p>• fmPosition ( \'Xframe\', "r" ) = ' . fmPosition('Xframe', "r") . '</p>'; echo '<p>• fmPosition ( \'Xframe\', \'Z\' ) = ' . fmPosition('Xframe', 'Z') . '</p>'; echo '<p>• fmProper ( \'this is a test.\' ) = ' . fmProper('this is a test.') . '</p>'; echo '<p>• fmRandom ( 1, 100 ) = ' . fmRandom(1, 100) . '</p>'; echo '<p>• fmRight ( \'Xframe\', 3 ) = ' . fmRight('Xframe', 3) . '</p>'; echo '<p>• fmRightWords ( \'This is a test.\', 2 ) = ' . fmRightWords('This is a test.', 2) . '</p>'; echo '<p>• fmRound ( 123.456, 2 ) = ' . fmRound(123.456, 2) . '</p>'; echo '<p>• fmRound ( 123.456, -2 ) = ' . fmRound(123.456, -2) . '</p>'; echo '<p>• fmSeconds ( \'3:51:22 PM\' ) = ' . fmSeconds('3:51:22 PM') . '</p>'; echo '<p>• fmSerialIncrement ( \'abc12\', 1 ) = ' . fmSerialIncrement('abc12', 1) . '</p>'; echo '<p>• fmSerialIncrement ( \'abc12\', 7 ) = ' . fmSerialIncrement('abc12', 7) . '</p>'; echo '<p>• fmSerialIncrement ( \'abc12\', -1 ) = ' . fmSerialIncrement('abc12', -1) . '</p>'; echo '<p>• fmSerialIncrement ( \'abc12\', 1.2 ) = ' . fmSerialIncrement('abc12', 1.2) . '</p>'; echo '<p>• fmStripTags ( \'This is <bold>bold text</bold>. Or not.\' ) = ' . fmStripTags('This is <bold>bold text</bold>. Or not.') . '</p>'; echo '<p>• fmStripTags ( \'This is a <a href="http://www.test.com/">link</a>. Or not.\' ) = ' . fmStripTags('This is <a href="http://www.test.com/">link</a>. Or not.') . '</p>'; echo '<p>• fmSubstitute ( \'Xframe\', "ram", "stu" ) = ' . fmSubstitute('Xframe', "ram", "stu") . '</p>'; echo '<p>• fmTime ( 10, 51, 22 ) = ' . fmTime(10, 51, 22) . '</p>'; echo '<p>• fmTimestamp ( fmGetAsDate ( \'5/1/2007\' ), fmGetAsTime ( \'10:51:22\' ) ) = ' . fmTimestamp(fmGetAsDate('5/1/2007'), fmGetAsTime('10:51:22')) . '</p>'; echo '<p>• fmTrim ( \' This is a test. \' ) = ' . fmTrim(' This is a test. ') . '</p>'; echo '<p>• fmTruncate ( -14.6, 0 ) = ' . fmTruncate(-14.6, 0) . '</p>'; echo '<p>• fmTruncate ( 123.456, 2 ) = ' . fmTruncate(123.456, 2) . '</p>'; echo '<p>• fmTruncate ( 123.456, 4 ) = ' . fmTruncate(123.456, 4) . '</p>'; echo '<p>• fmTruncate ( 29343.98, -3 ) = ' . fmTruncate(29343.98, -3) . '</p>'; echo '<p>• fmUpper ( \'This is a test.\' ) = ' . fmUpper('This is a test.') . '</p>'; echo '<p>• fmWeekOfYear ( \'11/27/1968\' ) = ' . fmWeekOfYear('11/27/1968') . '</p>'; echo '<p>• fmWordCount ( \'This is a test.\' ) = ' . fmWordCount('This is a test.') . '</p>'; echo '<p>• fmYear ( \'11/27/1968\' ) = ' . fmYear('11/27/1968') . '</p>'; // Grab the contents of the output buffer. $ui_body_content = ob_get_contents(); // End output buffering, and erase the contents. ob_end_clean();
function fmGetUUID() { return fmSubstitute(uniqid('fmwf-', true), '.', '-'); }