Skip to content

Commit

Permalink
Upload files
Browse files Browse the repository at this point in the history
  • Loading branch information
RomaniukVadim committed May 8, 2018
0 parents commit da92f50
Show file tree
Hide file tree
Showing 5,653 changed files with 1,086,684 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
249 changes: 249 additions & 0 deletions Builder/_export.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
<?php
ob_start();
/* START: INCLUDE FOLDER SETTING & ASSETS */
$pathToAssets = array("elements/css", "elements/images", "elements/video", "elements/fonts", "elements/js", "elements/tz_mail");
$filename = "tmp/leadgen.zip"; //use the /tmp folder to circumvent any permission issues on the root folder
if (file_exists($filename)) {
unlink($filename);
}
/* END: INCLUDE FOLDER SETTING & ASSETS */
/* START: API KEYS & VARIABLES */
$export_type = $_POST['export_type'];
$recaptcha = $_POST['g-recaptcha-secret-key'];
$tz_email = $_POST['tz_email'];
$tz_from_email = $_POST['tz_email_from'];
$tz_subject = $_POST['tz_subject'];
$tz_cm_apikey = $_POST['cm_api_key'];
$tz_cm_listid = $_POST['cm_list_id'];
$tz_mc_apikey = $_POST['mailchimp_api_key'];
$tz_mc_listid = $_POST['mailchimp_api_listid'];
$tz_gr_apikey = $_POST['getresponse_api_key'];
$tz_gr_campaign = $_POST['getresponse_campaign_token'];
$tz_active_url = $_POST['ac_api_url'];
$tz_active_api_key = $_POST['ac_api_key'];
$tz_active_list_id = $_POST['ac_api_listid'];
$tz_aw_listname = $_POST['aweber_list_name'];
$tz_mailerlite_api_key = $_POST['ml_api_key'];
$tz_mailerlite_group_id = $_POST['ml_groupid'];
/* END: API KEYS & VARIABLES */
/* CONFIG SETTINGS */
$file_config = 'elements/export/api-config.php';
$get_config = htmlspecialchars(file_get_contents($file_config));
$arr_keys = array('export_type', 'custom_email','custom_from_email','custom_subject', 'g-recaptcha-secret-key', 'mc_config_apikey', 'mc_config_listid', 'cm_config_apikey', 'cm_config_listid', 'gr_config_apikey', 'gr_config_token', 'aw_config_listname', 'ac_config_url', 'ac_config_apikey', 'ac_config_listid', 'ml_config_apikey', 'ml_config_groupid', '&lt;', '&gt;');
$arr_values = array($export_type, $tz_email,$tz_from_email,$tz_subject, $recaptcha, $tz_mc_apikey, $tz_mc_listid, $tz_cm_apikey, $tz_cm_listid, $tz_gr_apikey, $tz_gr_campaign, $tz_aw_listname, $tz_active_url, $tz_active_api_key, $tz_active_list_id, $tz_mailerlite_api_key, $tz_mailerlite_group_id, '<', '>');
$themezaa_config = str_replace($arr_keys, $arr_values, $get_config);
/* END CONFIG SETTINGS */
/* JS SETTINGS */
$file_js = 'elements/export/main.js';
$get_js_config = htmlspecialchars(file_get_contents($file_js));
$arr_keys_js = array('&quot;', '&lt;', '&gt;','&amp;');
$arr_value_js = array('"', '<', '>','&');
$themezaa_config_js = str_replace($arr_keys_js, $arr_value_js, $get_js_config);
/* END JS SETTINGS */
$zip = new ZipArchive();
$zip->open($filename, ZipArchive::CREATE);
/* add folder structure */
foreach ($pathToAssets as $thePath) {
/* Create recursive directory iterator */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($thePath), RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file) {
if ($file->getFilename() != '.' && $file->getFilename() != '..') {
/* Get real path for current file */
$filePath = $file->getRealPath();
$temp = explode("/", $name);
array_shift($temp);
$newName = implode("/", $temp);
/* Add current file to archive */
$zip->addFile($filePath, $newName);
}
}
}
foreach ($_POST['pages'] as $page => $content) {
$html_header = htmlspecialchars(file_get_contents('elements/export/header.html'));
$html_footer = htmlspecialchars(file_get_contents('elements/export/footer.html'));
/* SEO Meta values */
$tz_seo_meta = $_POST['tz_seo'][$page];
$tz_fav_icon = $_POST['tz_favicon_icon'];
$tz_new_icon = explode('./elements/', $tz_fav_icon);
if ($tz_seo_meta) {
$tz_seo = explode('1_@_2_@', $tz_seo_meta);
$meta_keys = array('LeadGen - Multipurpose Marketing Landing Page Pack with Page Builder', 'lgdescription', 'lgkeywords', 'lgauthor', '&quot;', '&lt;', '&gt;','images/icon/favicon.png');
$meta_values = array($tz_seo[0], $tz_seo[1], $tz_seo[2], $tz_seo[3], '"', '<', '>',$tz_new_icon[1]);
$meta_seo_values = str_replace($meta_keys, $meta_values, $html_header);
}else{
$meta_keys = array('LeadGen - Multipurpose Marketing Landing Page Pack with Page Builder', 'lgdescription', 'lgkeywords', 'lgauthor', '&quot;', '&lt;', '&gt;','images/icon/favicon.png');
$meta_values = array('LeadGen - Multipurpose Marketing Landing Page Pack with Page Builder', 'lgdescription', 'lgkeywords', 'lgauthor', '"', '<', '>',$tz_new_icon[1]);
$meta_seo_values = str_replace($meta_keys, $meta_values, $html_header);
}

/* End SEO Meta values */
$tz_html_array = array('&quot;','%20','contact-submit');
$tz_html_keys = array("'","","tz_submit");
$tz_html_content = str_replace($tz_html_array, $tz_html_keys, $content);
$tz_footer_keys = array('&lt;','&gt;');
$tz_footer_values = array('<','>');
$tz_html_footer = str_replace($tz_footer_keys, $tz_footer_values, $html_footer);
$tz_content = $meta_seo_values . stripslashes($tz_html_content).$tz_html_footer;
$zip->addFromString($page . ".html", stripslashes($tz_content));
}
foreach ($_POST['pages'] as $page => $img_content) {
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($img_content);
$dom->preserveWhiteSpace = false;
$tags_videos = $dom->getElementsByTagName('video');
foreach($dom->getElementsByTagName('img') as $all_tags_img)
{
$images[] = $all_tags_img->getAttribute('src');
}
foreach($tags_videos as $all_tags_video)
{
$videos[] = $all_tags_video;
}
$files = glob('elements/images/*.{jpg,jpeg,png,gif,PNG,JPG,JPEG,GIF}', GLOB_BRACE);
foreach($files as $file) {
$img_folder[] = explode('/', $file);
}
$bg_reg = '/url\(([\'\"]?.*[\'\"]?)\)/i';
preg_match_all($bg_reg, $img_content,$matches);
foreach($matches[1] as $mat_value) {
$bg_mat_img[] = $mat_value;
}
}
if(empty($videos))
{
$folder_video_delete = 'video/';
for ($i = 0; $i < $zip->numFiles; $i++){
$video_info = $zip->statIndex($i);
if (substr($video_info["name"], 0, strlen($folder_video_delete)) == $folder_video_delete){
$zip->deleteIndex($i);
}
}
}
if(!empty($bg_mat_img))
{
foreach($bg_mat_img as $value) {
$char_val = array("&quot;","'");
$bg_value = str_replace($char_val,"",$value);
$bg_img = explode('/', $bg_value);
$bg_ex_img[] = $bg_img[2];

$bg_files = glob('elements/images/bg-image/*.{jpg,jpeg,png,gif,PNG,JPG,JPEG,GIF}', GLOB_BRACE);
foreach ($bg_files as $bg_file) {
$bg_folder = explode('/', $bg_file);
$bg_folder_img[] = $bg_folder[3];
}
}
if(!empty($bg_ex_img))
{
$bg_results = array_diff($bg_folder_img,$bg_ex_img);
foreach ($bg_results as $bg_res)
{
$bg_img_path = 'images/bg-image/' . $bg_res;
$zip->deleteName($bg_img_path);
}
}else{
$bg_files = glob('elements/images/bg-image/*.{jpg,jpeg,png,gif,PNG,JPG,JPEG,GIF}', GLOB_BRACE);
foreach ($bg_files as $bg_file) {
$bg_folder = explode('/', $bg_file);
$bg_img_path = 'images/bg-image/' . $bg_folder[3];
$zip->deleteName($bg_img_path);
}
}
}else{
$bg_files = glob('elements/images/bg-image/*.{jpg,jpeg,png,gif,PNG,JPG,JPEG,GIF}', GLOB_BRACE);
foreach ($bg_files as $bg_file) {
$bg_folder = explode('/', $bg_file);
$bg_img_path = 'images/bg-image/' . $bg_folder[3];
$zip->deleteName($bg_img_path);
}
}
if(!empty($images))
{
foreach($images as $img)
{
$img_ex = explode('/', $img);
if(empty($img_ex[2]))
{
$temp_img[] = $img_ex[1];
}else{
$temp_img[] = $img_ex[2];
}

foreach ($img_folder as $zip_folder) {
$exp_img[] = $zip_folder[2];
}
}
$result = array_diff($exp_img, $temp_img);
foreach ($result as $res)
{
$img_path = 'images/' . $res;
$zip->deleteName($img_path);
}
}else{
foreach($img_folder as $zip_folder)
{
$img_path = 'images/' . $zip_folder[2];
$zip->deleteName($img_path);
}
}
if(!empty($bg_ex_img) && !empty($temp_img))
{
$all_img = array_merge($bg_ex_img,$temp_img);
}elseif(!empty($bg_ex_img)){
$all_img = $bg_ex_img;
}else if(!empty($temp_img)){
$all_img = $temp_img;
}
if(!empty($all_img))
{
$upload_files = glob('elements/images/uploads/*.{jpg,jpeg,png,gif,PNG,JPG,JPEG,GIF}', GLOB_BRACE);
foreach ($upload_files as $upload_file) {
$upload_folder = explode('/', $upload_file);
$up_folder_img[] = $upload_folder[3];
}
if(!empty($up_folder_img))
{
$upload_results = array_diff($up_folder_img, $all_img);
foreach ($upload_results as $up_res)
{
$upload_folder = explode('/', $up_res);
$up_img_path = 'images/uploads/' . $up_res;
$zip->deleteName($up_img_path);
}
}
}else{
$upload_files = glob('elements/images/uploads/*.{jpg,jpeg,png,gif,PNG,JPG,JPEG,GIF}', GLOB_BRACE);
foreach ($upload_files as $upload_file) {
$upload_folder = explode('/', $upload_file);
$up_img_path = 'images/uploads/' . $upload_folder[3];
$zip->deleteName($up_img_path);
}
}
$folder_to_delete = 'images/thumbs/';
for ($i = 0; $i < $zip->numFiles; $i++) {
$image_info = $zip->statIndex($i);
if (substr($image_info["name"], 0, strlen($folder_to_delete)) == $folder_to_delete) {
$zip->deleteIndex($i);
}
}
$fileToModify = 'tz_mail/api-config.php';
$fileToJs = 'js/main.js';
$zip->deleteName($fileToJs);
$zip->deleteName($fileToModify);
$zip->addFromString($fileToJs, $themezaa_config_js);
$zip->addFromString($fileToModify, $themezaa_config);
$zip->close();
$yourfile = $filename;
$file_name = basename($yourfile);
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Length: " . filesize($yourfile));
ob_end_clean();
readfile($yourfile);
unlink('tmp/leadgen.zip');
exit;
?>
31 changes: 31 additions & 0 deletions Builder/_favicon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
$uploads_dir = 'elements/images/icon';
$relative_path = 'images/icon';
///echo '<pre>';print_r($_FILES);die;
if(isset($_FILES['formData'])){
$output['status']=FALSE;
$allowed_types = array("image/jpeg","image/pjpeg","image/png","image/vnd.microsoft.icon","image/x-png" );
if ($_FILES['formData']["error"] > 0) {
$output['error']= "Error in File";
}elseif (!in_array($_FILES['formData']['type'], $allowed_types)) {
$output['error']= "You can only upload JPG, PNG and ICO file";
}elseif (round($_FILES['formData']['size'] / 1024) > 4096) {
$output['error']= "You can upload file size up to 4 MB";
} else {
$path[0] = $_FILES['formData']['tmp_name'];
$name = $_FILES['formData']['name'];
$file_type = $_FILES['formData']['type'];

if(in_array($file_type, $allowed_types)) {
if (move_uploaded_file( $path[0], dirname($_SERVER['SCRIPT_FILENAME'])."/".$uploads_dir."/".$name ) ) {
//echo "yes";
} else {
$output['error'] = "The uploaded file couldn't be saved. Please make sure you have provided a correct upload folder and that the upload folder is writable.";
}
}
$output['status']=TRUE;
$output['favicon_icon'] = $relative_path."/".$name;
}
echo json_encode($output);die;
}
?>
16 changes: 16 additions & 0 deletions Builder/_preview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$filename = "elements/preview_".generateRandomString(20).".html";
$previewFile = fopen($filename, "w");
fwrite($previewFile, stripcslashes($_POST['page']));
fclose($previewFile);
header('Location: '.$filename);
?>
30 changes: 30 additions & 0 deletions Builder/_save.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
$return = [];

if( isset($_POST['data']) && $_POST['data'] != '' ) {

if( isset($_POST['data']['delete']) ) {

$myfile = fopen("site.json", "w");
fwrite($myfile, '{}');
fclose($myfile);

} else {

$myfile = fopen("site.json", "w");
fwrite($myfile, json_encode($_POST['data']));
fclose($myfile);

}

$return['responseCode'] = 1;
$return['responseHTML'] = '<h5>Hooray!</h5> <p>The site was saved successfully!</p>';

} else {

$return['responseCode'] = 0;
$return['responseHTML'] = '<h5>Ouch!</h5> <p>Something went wrong and the site could not be saved :(</p>';

}
echo json_encode($return);
?>
56 changes: 56 additions & 0 deletions Builder/_upload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

$uploads_dir = 'elements/images/uploads';//specify the upload folder, make sure it's writable!
$relative_path = 'images/uploads';//specify the relative path from your elements to the upload folder
$allowed_types = array("image/jpeg","image/jpg","image/gif", "image/png", "image/svg");

/* DON'T CHANGE ANYTHING HERE!! */
$return = array();

//does the folder exist?
if( !file_exists( $uploads_dir ) ) {
$return['code'] = 0;
$return['response'] = "The specified upload location does not exist. Please provide a correct folder in /_upload.php";
die( json_encode( $return ) );
}

//is the folder writable?
if( !is_writable( $uploads_dir ) ) {
$return['code'] = 0;
$return['response'] = "The specified upload location is not writable. Please make sure the specified folder has the correct write permissions set for it.";
die( json_encode( $return ) );
}

if ( !isset($_FILES['imageFileField']['error']) || is_array($_FILES['imageFileField']['error']) ) {
$return['code'] = 0;
$return['response'] = $_FILES['imageFileField']['error'];
die( json_encode( $return ) );
}

$name = $_FILES['imageFileField']['name'];
$array_char = array('%20','%');
$array_replace = array('-','-');
$new_name = str_replace($array_char,$array_replace,$name);
$file_type = $_FILES['imageFileField']['type'];

if(in_array($file_type, $allowed_types)) {
if (move_uploaded_file( $_FILES['imageFileField']['tmp_name'], dirname($_SERVER['SCRIPT_FILENAME'])."/".$uploads_dir."/".$new_name ) ) {
//echo "yes";
} else {
$return['code'] = 0;
$return['response'] = "The uploaded file couldn't be saved. Please make sure you have provided a correct upload folder and that the upload folder is writable.";
}

//print_r ($_FILES);
$return['code'] = 1;
$return['response'] = $relative_path."/".$new_name;

} else {

$return['code'] = 0;
$return['response'] = "File type not allowed, You can only upload image with extensions .jpeg, .jpg, .gif, .png or .svg";
}
echo json_encode( $return );
?>


Empty file added Builder/builder.json
Empty file.
Binary file added Builder/css/.DS_Store
Binary file not shown.
Loading

0 comments on commit da92f50

Please sign in to comment.