function copy_images($src, $dest, &$count) { if (is_dir($src)) { if ($handle = opendir($src)) { chdir($src); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != "CVS" && $file != '.svn') { $fulldest = $dest . substr(getcwd(), strpos(getcwd(), 'images') - 1) . "/{$file}"; if (is_dir($file)) { if (!file_exists($fulldest)) { mkdir($fulldest, 0777); } copy_images(realpath($file), $dest, $count); } else { copy($file, $fulldest); $count++; echo '>>'; } } } chdir("../"); } closedir($handle); } return $count; }
output_success("Inserted all community page options."); //fetch all of the top level parent community pages from the community to copy $query = "\tSELECT *\n\t\t\tFROM " . DATABASE_NAME . ".`community_pages`\n\t\t\tWHERE `community_id` = " . $COMMUNITY_ID . "\n\t\t\tAND `parent_id` = '0'\n\t\t\tORDER BY cpage_id ASC"; $community_pages_arr = $db->GetAll($query); //insert each community page with the new community id. if ($community_pages_arr) { foreach ($community_pages_arr as $page) { //Insert new page if it is active if ($page["page_active"] != 0) { $new_parent_id = insert_community_page($db, $page, $new_community_id, $user_data["id"]); //create the new gallery and copy the images if ($page["page_type"] == "galleries") { $gallery_id = array(); $gallery_id = create_gallery($db, $COMMUNITY_ID, $page["cpage_id"], $new_community_id, $new_parent_id, $user_data["id"]); if (is_array($gallery_id)) { copy_images($db, $COMMUNITY_ID, $gallery_id["old_gallery_id"], $new_community_id, $gallery_id["new_gallery_id"], $user_data["id"]); } } //add all of the child pages for this page. create_child_pages($db, $page["cpage_id"], $COMMUNITY_ID, $new_parent_id, $new_community_id, $user_data["id"]); } } } //Validate that all pages were copied by comparing the given community ID to the new community ID. $query = "\tSELECT *\n\t\t\tFROM " . DATABASE_NAME . ".`community_pages`\n\t\t\tWHERE `community_id` = " . $COMMUNITY_ID . "\n\t\t\tAND page_active = 1"; $old_community_pages_arr = $db->GetAll($query); $query = "\tSELECT *\n\t\t\tFROM " . DATABASE_NAME . ".`community_pages`\n\t\t\tWHERE `community_id` = " . $new_community_id . "\n\t\t\tAND page_active = 1"; $new_community_pages_arr = $db->GetAll($query); $old_num_of_pages = sizeof($old_community_pages_arr); $new_num_of_pages = sizeof($new_community_pages_arr); if ($old_num_of_pages != $new_num_of_pages) {