/** * * @return * @param string $rootDir * @param array $allowedExtensions * @param array $invisibleFileNames * @param integer $modus[optional] * @param bool $rekursiv[optional] */ function getFolderData($rootDir, $allowedExtensions, $invisibleFileNames, $modus = 1, $rekursiv = true) { $daten = array(); $daten = scanDirectories($rootDir, $allowedExtensions, $invisibleFileNames, $modus, $rekursiv); foreach ($daten as &$value) { $value = str_replace($rootDir, '', $value); } return $daten; }
function createLinks() { $basepath = "./"; // Current working Directory as absolute path $extensions = array("php", "html"); // Scan for these $subdirectories = scanDirectories($basepath); foreach ($subdirectories as $directory) { if ($file = loadIndex($basepath . $directory, $extensions)) { // Locate index for each subdirectory echo "<li><a href=" . $basepath . $directory . "/" . $file . "> {$directory} </a></li>"; // generate link as list item } } }
function scanDirectories($rootDir, $allowext, &$allData = array()) { $dirContent = scandir($rootDir); foreach ($dirContent as $key => $content) { if ($content == '.' || $content == '..') { continue; } $path = $rootDir . DIRECTORY_SEPARATOR . $content; $ext = substr($content, strrpos($content, '.') + 1); if (in_array($ext, $allowext) && is_file($path) && is_readable($path)) { $allData[] = $path; } else { if (is_dir($path) && is_readable($path)) { scanDirectories($path, $allowext, $allData); } } } return $allData; }
/** * @param $post_content * @param $postID * @return array */ public function capture_all_shortcodes($post_content, $postID) { $result = array(); $pattern = "/([WPIMPINLINE:([\\w]+)(.*?)(])/"; $shortcode_prefix = "[WPIMPINLINE:"; $post_content = str_replace("\n", "<br />", $post_content); preg_match_all($pattern, $post_content, $results, PREG_PATTERN_ORDER); $inlineimg_shortcodes = array(); $inline_shortcode_count = 0; for ($i = 0; $i < count($results[0]); $i++) { $get_shortcode_pos = strpos($results[0][$i], $shortcode_prefix); $inlineimg_shortcodes[] = substr($results[0][$i], $get_shortcode_pos); } $inline_shortcode_count = count($inlineimg_shortcodes); if (!empty($inlineimg_shortcodes) && is_array($inlineimg_shortcodes)) { foreach ($inlineimg_shortcodes as $shortkey => $shortcode) { $get_inlineimage_val = substr($shortcode, "13", -1); $image_attribute = explode('|', $get_inlineimage_val); $get_inlineimage_val = $image_attribute[0]; $uploadDir = wp_upload_dir(); $inlineimageDir = $uploadDir['basedir'] . '/smack_inline_images'; $inlineimageURL = $uploadDir['baseurl'] . '/smack_inline_images'; $wp_media_url = $uploadDir['baseurl']; $get_media_settings = get_option('uploads_use_yearmonth_folders'); if ($get_media_settings == 1) { $dirname = date('Y') . '/' . date('m'); $full_path = $uploadDir['basedir'] . '/' . $dirname; $baseurl = $uploadDir['baseurl'] . '/' . $dirname; } else { $full_path = $uploadDir['basedir']; $baseurl = $uploadDir['baseurl']; } $wp_media_path = $full_path; $eventKey = sanitize_text_field($_POST['postdata']['uploadedFile']); $inlineimageDirpath = $inlineimageDir . '/' . $eventKey; $imagelist = scanDirectories($inlineimageDirpath); $currentLoc = ''; if (!$imagelist) { $noimage = WP_CONST_ULTIMATE_CSV_IMP_DIR . "images/noimage.png"; $oldWord = $shortcode; $newWord = '<img src="' . $noimage . '" />'; $post_content = str_replace($oldWord, $newWord, $post_content); $result['post_content'] = $post_content; $result['inlineimage_shortcode'] = "No-Image-count:" . $inline_shortcode_count; } else { if (!empty($imagelist)) { foreach ($imagelist as $imgwithloc) { if (strpos($imgwithloc, $get_inlineimage_val)) { $currentLoc = $imgwithloc; } } } $exploded_currentLoc = explode("{$eventKey}", $currentLoc); if (!empty($exploded_currentLoc) && isset($exploded_currentLoc[1])) { $inlimg_curr_loc = $exploded_currentLoc[1]; } else { $inlimg_curr_loc = ''; } $inlineimageURL = $inlineimageURL . '/' . $eventKey . $inlimg_curr_loc; $helperObj = new WPImporter_includes_helper(); $helperObj->get_fimg_from_URL($inlineimageURL, $wp_media_path, $get_inlineimage_val, '', '', ''); $wp_media_path = $wp_media_path . "/" . $get_inlineimage_val; if (@getimagesize($wp_media_path)) { $img = wp_get_image_editor($wp_media_path); if (!is_wp_error($img)) { $sizes_array = array(array('width' => 1024, 'height' => 768, 'crop' => true), array('width' => 100, 'height' => 100, 'crop' => false), array('width' => 300, 'height' => 100, 'crop' => false), array('width' => 624, 'height' => 468, 'crop' => false)); $resize = $img->multi_resize($sizes_array); } $get_inline_guid = str_replace(' ', '-', $get_inlineimage_val); $inline_file['guid'] = $baseurl . "/" . $get_inlineimage_val; $inline_file['post_title'] = $get_inlineimage_val; $inline_file['post_content'] = ''; $inline_file['post_status'] = 'attachment'; $wp_upload_dir = wp_upload_dir(); $attachment = array('guid' => $inline_file['guid'], 'post_mime_type' => 'image/jpeg', 'post_title' => preg_replace('/\\.[^.]+$/', '', @basename($inline_file['guid'])), 'post_content' => '', 'post_status' => 'inherit'); if ($get_media_settings == 1) { $generate_attachment = $dirname . '/' . $get_inline_guid; } else { $generate_attachment = $get_inline_guid; } $uploadedImage = $wp_upload_dir['path'] . '/' . $get_inlineimage_val; //duplicate check global $wpdb; $existing_attachment = array(); //$query = $wpdb->get_results("select post_title from $wpdb->posts where post_type = 'attachment' and post_mime_type = 'image/jpeg'"); $query = $wpdb->get_results($wpdb->prepare("select post_title from {$wpdb->posts} where post_type = %s and post_mime_type = %s", 'attachment', 'image/jpeg')); if (!empty($query)) { foreach ($query as $key) { $existing_attachment[] = $key->post_title; } } //duplicate check if (!in_array($attachment['post_title'], $existing_attachment)) { $attach_id = wp_insert_attachment($attachment, $generate_attachment, $postID); $attach_data = wp_generate_attachment_metadata($attach_id, $uploadedImage); wp_update_attachment_metadata($attach_id, $attach_data); //set_post_thumbnail($postID, $attach_id); } // if($shortcode_mode == 'Inline') { $oldWord = $shortcode; $image_attribute[1] = isset($image_attribute[1]) ? $image_attribute[1] : ''; $image_attribute[2] = isset($image_attribute[2]) ? $image_attribute[2] : ''; $image_attribute[3] = isset($image_attribute[3]) ? $image_attribute[3] : ''; $newWord = '<img src="' . $inline_file['guid'] . '" ' . $image_attribute[1] . ' ' . $image_attribute[2] . ' ' . $image_attribute[3] . ' />'; $post_content = str_replace($oldWord, $newWord, $post_content); $result['post_content'] = $post_content; $result['inlineimage_shortcode'] = $inline_shortcode_count; // } } } } } return $result; }
global $allMatches; global $allowedExtensions; $filename = basename($path); if (!in_array(substr($filename, strrpos($filename, '.') + 1), $allowedExtensions)) { return; } echo 'PARSING ' . $path . "\n"; $regex = "/([\"][^\"|.]+[\"]).l\\(\\)|([\\'][^'|.]+[\\']).l\\(/"; $content = file_get_contents($path); $matches = array(); if (preg_match_all($regex, $content, $matches) != 0) { $matches[1] = array_filter($matches[1]); $matches[2] = array_filter($matches[2]); foreach ($matches[1] as $string) { $string = str_replace('"', "'", $string); $allMatches[$string] = $string; } foreach ($matches[2] as $string) { $allMatches[$string] = $string; } } } scanDirectories($directories); $content = "Locale.module('{$module}', {\n"; foreach ($allMatches as $string) { $content .= ' ' . $string . ': ' . $string . ",\n"; } if (count($allMatches)) { $content = substr($content, 0, -2); } file_put_contents($output, $content . "\n});");
function scanDirectories($rootDir, $allData = array()) { // set filenames invisible if you want $invisibleFileNames = array(".", "..", ".htaccess", ".htpasswd", "index.php", ".DS_Store"); // run through content of root directory $dirContent = scandir($rootDir); foreach ($dirContent as $key => $content) { // filter all files not accessible if ($rootDir != _PS_PROD_IMG_DIR_) { $path = $rootDir . '/' . $content; } else { $path = $rootDir . $content; } if (!in_array($content, $invisibleFileNames)) { // if content is file & readable, add to array if (is_file($path) && is_readable($path)) { // save file name with path //exclure les fichiers placés à la racine du dossier img/p/ (mode legacy) if ($rootDir != _PS_PROD_IMG_DIR_) { $allData[] = $path; } // if content is a directory and readable, add path and name } elseif (is_dir($path) && is_readable($path)) { // recursive callback to open new directory $allData = scanDirectories($path, $allData); } } } return $allData; }
function scanDirectories($rootDir, $allowext, $hideFolder) { $dirContent = scandir($rootDir); // $allData = array(); foreach ($dirContent as $key => $content) { $path = $rootDir . $content; $ext = strtolower(substr($content, strrpos($content, '.') + 1)); if (in_array($ext, $allowext)) { if (is_file($path) && is_readable($path)) { // $allData[] = $content; if ($hideFolder) { $folder = ""; } else { $folder = $rootDir; } $allData[] = $folder . $content; } elseif (is_dir($path) && is_readable($path)) { // recursive callback to open new directory $allData = scanDirectories($path, $allData); } } } return $allData; }