Ejemplo n.º 1
0
<?php

$settings = BigTreeCMS::getSetting("bigtree-internal-media-settings");
$data = isset($data["preset"]) ? $settings["presets"][$data["preset"]] : $settings["presets"][$_POST["id"]];
?>
<fieldset>
	<label>Minimum Width <small>(numeric value in pixels)</small></label>
	<input type="text" name="min_width" value="<?php 
echo htmlspecialchars($data["min_width"]);
?>
" disabled="disabled" />
</fieldset>
<fieldset>
	<label>Minimum Height <small>(numeric value in pixels)</small></label>
	<input type="text" name="min_height" value="<?php 
echo htmlspecialchars($data["min_height"]);
?>
" disabled="disabled" />
</fieldset>
<fieldset>
	<label>Preview Prefix <small>(for forms)</small></label>
	<input type="text" name="preview_prefix" value="<?php 
echo htmlspecialchars($data["preview_prefix"]);
?>
" disabled="disabled" />
</fieldset>
<fieldset>
	<label>Create Hi-Resolution Retina Images <small><a href="http://www.bigtreecms.org/docs/dev-guide/field-types/retina-images/" target="_blank">(learn more)</a></small></label>
	<input type="checkbox" name="retina" <?php 
if ($data["retina"]) {
    ?>
Ejemplo n.º 2
0
 static function processImageUpload($field)
 {
     global $bigtree;
     $failed = false;
     $name = $field["file_input"]["name"];
     $temp_name = $field["file_input"]["tmp_name"];
     $error = $field["file_input"]["error"];
     // If a file upload error occurred, return the old image and set errors
     if ($error == 1 || $error == 2) {
         $bigtree["errors"][] = array("field" => $field["title"], "error" => "The file you uploaded ({$name}) was too large &mdash; <strong>Max file size: " . ini_get("upload_max_filesize") . "</strong>");
         return false;
     } elseif ($error == 3) {
         $bigtree["errors"][] = array("field" => $field["title"], "error" => "The file upload failed ({$name}).");
         return false;
     }
     // We're going to tell BigTreeStorage to handle forcing images into JPEGs instead of writing the code 20x
     $storage = new BigTreeStorage();
     $storage->AutoJPEG = $bigtree["config"]["image_force_jpeg"];
     // Let's check the minimum requirements for the image first before we store it anywhere.
     $image_info = @getimagesize($temp_name);
     $iwidth = $image_info[0];
     $iheight = $image_info[1];
     $itype = $image_info[2];
     $channels = $image_info["channels"];
     // See if we're using image presets
     if ($field["options"]["preset"]) {
         $media_settings = BigTreeCMS::getSetting("bigtree-internal-media-settings");
         $preset = $media_settings["presets"][$field["options"]["preset"]];
         // If the preset still exists, copy its properties over to our options
         if ($preset) {
             foreach ($preset as $key => $val) {
                 $field["options"][$key] = $val;
             }
         }
     }
     // If the minimum height or width is not meant, do NOT let the image through.  Erase the change or update from the database.
     if (isset($field["options"]["min_height"]) && $iheight < $field["options"]["min_height"] || isset($field["options"]["min_width"]) && $iwidth < $field["options"]["min_width"]) {
         $error = "Image uploaded (" . htmlspecialchars($name) . ") did not meet the minimum size of ";
         if ($field["options"]["min_height"] && $field["options"]["min_width"]) {
             $error .= $field["options"]["min_width"] . "x" . $field["options"]["min_height"] . " pixels.";
         } elseif ($field["options"]["min_height"]) {
             $error .= $field["options"]["min_height"] . " pixels tall.";
         } elseif ($field["options"]["min_width"]) {
             $error .= $field["options"]["min_width"] . " pixels wide.";
         }
         $bigtree["errors"][] = array("field" => $field["title"], "error" => $error);
         $failed = true;
     }
     // If it's not a valid image, throw it out!
     if ($itype != IMAGETYPE_GIF && $itype != IMAGETYPE_JPEG && $itype != IMAGETYPE_PNG) {
         $bigtree["errors"][] = array("field" => $field["title"], "error" => "An invalid file was uploaded. Valid file types: JPG, GIF, PNG.");
         $failed = true;
     }
     // See if it's CMYK
     if ($channels == 4) {
         $bigtree["errors"][] = array("field" => $field["title"], "error" => "A CMYK encoded file was uploaded. Please upload an RBG image.");
         $failed = true;
     }
     // See if we have enough memory for all our crops and thumbnails
     if (!$failed && (is_array($field["options"]["crops"]) && count($field["options"]["crops"]) || is_array($field["options"]["thumbs"]) && count($field["options"]["thumbs"]))) {
         if (is_array($field["options"]["crops"])) {
             foreach ($field["options"]["crops"] as $crop) {
                 if (!$failed && is_array($crop) && array_filter($crop)) {
                     if ($field["options"]["retina"]) {
                         $crop["width"] *= 2;
                         $crop["height"] *= 2;
                     }
                     // We don't want to add multiple errors so we check if we've already failed
                     if (!BigTree::imageManipulationMemoryAvailable($temp_name, $crop["width"], $crop["height"], $iwidth, $iheight)) {
                         $bigtree["errors"][] = array("field" => $field["title"], "error" => "Image uploaded is too large for the server to manipulate. Please upload a smaller version of this image.");
                         $failed = true;
                     }
                 }
             }
         }
         if (is_array($field["options"]["thumbs"])) {
             foreach ($field["options"]["thumbs"] as $thumb) {
                 // We don't want to add multiple errors and we also don't want to waste effort getting thumbnail sizes if we already failed.
                 if (!$failed && is_array($thumb) && array_filter($thumb)) {
                     if ($field["options"]["retina"]) {
                         $thumb["width"] *= 2;
                         $thumb["height"] *= 2;
                     }
                     $sizes = BigTree::getThumbnailSizes($temp_name, $thumb["width"], $thumb["height"]);
                     if (!BigTree::imageManipulationMemoryAvailable($temp_name, $sizes[3], $sizes[4], $iwidth, $iheight)) {
                         $bigtree["errors"][] = array("field" => $field["title"], "error" => "Image uploaded is too large for the server to manipulate. Please upload a smaller version of this image.");
                         $failed = true;
                     }
                 }
             }
         }
         if (is_array($field["options"]["center_crops"])) {
             foreach ($field["options"]["center_crops"] as $crop) {
                 // We don't want to add multiple errors and we also don't want to waste effort getting thumbnail sizes if we already failed.
                 if (!$failed && is_array($crop) && array_filter($crop)) {
                     list($w, $h) = getimagesize($temp_name);
                     if (!BigTree::imageManipulationMemoryAvailable($temp_name, $w, $h, $crop["width"], $crop["height"])) {
                         $bigtree["errors"][] = array("field" => $field["title"], "error" => "Image uploaded is too large for the server to manipulate. Please upload a smaller version of this image.");
                         $failed = true;
                     }
                 }
             }
         }
     }
     if (!$failed) {
         // Make a temporary copy to be used for thumbnails and crops.
         $itype_exts = array(IMAGETYPE_PNG => ".png", IMAGETYPE_JPEG => ".jpg", IMAGETYPE_GIF => ".gif");
         // Make a first copy
         $first_copy = SITE_ROOT . "files/" . uniqid("temp-") . $itype_exts[$itype];
         BigTree::moveFile($temp_name, $first_copy);
         // Do EXIF Image Rotation
         if ($itype == IMAGETYPE_JPEG && function_exists("exif_read_data")) {
             $exif = @exif_read_data($first_copy);
             $o = $exif['Orientation'];
             if ($o == 3 || $o == 6 || $o == 8) {
                 $source = imagecreatefromjpeg($first_copy);
                 if ($o == 3) {
                     $source = imagerotate($source, 180, 0);
                 } elseif ($o == 6) {
                     $source = imagerotate($source, 270, 0);
                 } else {
                     $source = imagerotate($source, 90, 0);
                 }
                 // We're going to create a PNG so that we don't lose quality when we resave
                 imagepng($source, $first_copy);
                 rename($first_copy, substr($first_copy, 0, -3) . "png");
                 $first_copy = substr($first_copy, 0, -3) . "png";
                 // Force JPEG since we made the first copy a PNG
                 $storage->AutoJPEG = true;
                 // Clean up memory
                 imagedestroy($source);
                 // Get new width/height/type
                 list($iwidth, $iheight, $itype, $iattr) = getimagesize($first_copy);
             }
         }
         // Create a temporary copy that we will use later for crops and thumbnails
         $temp_copy = SITE_ROOT . "files/" . uniqid("temp-") . $itype_exts[$itype];
         BigTree::copyFile($first_copy, $temp_copy);
         // Gather up an array of file prefixes
         $prefixes = array();
         if (is_array($field["options"]["thumbs"])) {
             foreach ($field["options"]["thumbs"] as $thumb) {
                 if (!empty($thumb["prefix"])) {
                     $prefixes[] = $thumb["prefix"];
                 }
             }
         }
         if (is_array($field["options"]["center_crops"])) {
             foreach ($field["options"]["center_crops"] as $crop) {
                 if (!empty($crop["prefix"])) {
                     $prefixes[] = $crop["prefix"];
                 }
             }
         }
         if (is_array($field["options"]["crops"])) {
             foreach ($field["options"]["crops"] as $crop) {
                 if (is_array($crop)) {
                     if (!empty($crop["prefix"])) {
                         $prefixes[] = $crop["prefix"];
                     }
                     if (is_array($crop["thumbs"])) {
                         foreach ($crop["thumbs"] as $thumb) {
                             if (!empty($thumb["prefix"])) {
                                 $prefixes[] = $thumb["prefix"];
                             }
                         }
                     }
                     if (is_array($crop["center_crops"])) {
                         foreach ($crop["center_crops"] as $center_crop) {
                             if (!empty($center_crop["prefix"])) {
                                 $prefixes[] = $center_crop["prefix"];
                             }
                         }
                     }
                 }
             }
         }
         // Upload the original to the proper place.
         $field["output"] = $storage->store($first_copy, $name, $field["options"]["directory"], true, $prefixes);
         // If the upload service didn't return a value, we failed to upload it for one reason or another.
         if (!$field["output"]) {
             if ($storage->DisabledFileError) {
                 $bigtree["errors"][] = array("field" => $field["title"], "error" => "Could not upload file. The file extension is not allowed.");
             } else {
                 $bigtree["errors"][] = array("field" => $field["title"], "error" => "Could not upload file. The destination is not writable.");
             }
             unlink($temp_copy);
             unlink($first_copy);
             // Failed, we keep the current value
             return false;
             // If we did upload it successfully, check on thumbs and crops.
         } else {
             // Get path info on the file.
             $pinfo = BigTree::pathInfo($field["output"]);
             // Handle Crops
             if (is_array($field["options"]["crops"])) {
                 foreach ($field["options"]["crops"] as $crop) {
                     if (is_array($crop)) {
                         // Make sure the crops have a width/height and it's numeric
                         if ($crop["width"] && $crop["height"] && is_numeric($crop["width"]) && is_numeric($crop["height"])) {
                             $cwidth = $crop["width"];
                             $cheight = $crop["height"];
                             // Check to make sure each dimension is greater then or equal to, but not both equal to the crop.
                             if ($iheight >= $cheight && $iwidth > $cwidth || $iwidth >= $cwidth && $iheight > $cheight) {
                                 // Make a square if for some reason someone only entered one dimension for a crop.
                                 if (!$cwidth) {
                                     $cwidth = $cheight;
                                 } elseif (!$cheight) {
                                     $cheight = $cwidth;
                                 }
                                 $bigtree["crops"][] = array("image" => $temp_copy, "directory" => $field["options"]["directory"], "retina" => $field["options"]["retina"], "name" => $pinfo["basename"], "width" => $cwidth, "height" => $cheight, "prefix" => $crop["prefix"], "thumbs" => $crop["thumbs"], "center_crops" => $crop["center_crops"], "grayscale" => $crop["grayscale"]);
                                 // If it's the same dimensions, let's see if they're looking for a prefix for whatever reason...
                             } elseif ($iheight == $cheight && $iwidth == $cwidth) {
                                 // See if we want thumbnails
                                 if (is_array($crop["thumbs"])) {
                                     foreach ($crop["thumbs"] as $thumb) {
                                         // Make sure the thumbnail has a width or height and it's numeric
                                         if ($thumb["width"] && is_numeric($thumb["width"]) || $thumb["height"] && is_numeric($thumb["height"])) {
                                             // Create a temporary thumbnail of the image on the server before moving it to it's destination.
                                             $temp_thumb = SITE_ROOT . "files/" . uniqid("temp-") . $itype_exts[$itype];
                                             BigTree::createThumbnail($temp_copy, $temp_thumb, $thumb["width"], $thumb["height"], $field["options"]["retina"], $thumb["grayscale"]);
                                             // We use replace here instead of upload because we want to be 100% sure that this file name doesn't change.
                                             $storage->replace($temp_thumb, $thumb["prefix"] . $pinfo["basename"], $field["options"]["directory"]);
                                         }
                                     }
                                 }
                                 // See if we want center crops
                                 if (is_array($crop["center_crops"])) {
                                     foreach ($crop["center_crops"] as $center_crop) {
                                         // Make sure the crop has a width and height and it's numeric
                                         if ($center_crop["width"] && is_numeric($center_crop["width"]) && $center_crop["height"] && is_numeric($center_crop["height"])) {
                                             // Create a temporary crop of the image on the server before moving it to it's destination.
                                             $temp_crop = SITE_ROOT . "files/" . uniqid("temp-") . $itype_exts[$itype];
                                             BigTree::centerCrop($temp_copy, $temp_crop, $center_crop["width"], $center_crop["height"], $field["options"]["retina"], $center_crop["grayscale"]);
                                             // We use replace here instead of upload because we want to be 100% sure that this file name doesn't change.
                                             $storage->replace($temp_crop, $center_crop["prefix"] . $pinfo["basename"], $field["options"]["directory"]);
                                         }
                                     }
                                 }
                                 $storage->store($temp_copy, $crop["prefix"] . $pinfo["basename"], $field["options"]["directory"], false);
                             }
                         }
                     }
                 }
             }
             // Handle thumbnailing
             if (is_array($field["options"]["thumbs"])) {
                 foreach ($field["options"]["thumbs"] as $thumb) {
                     // Make sure the thumbnail has a width or height and it's numeric
                     if ($thumb["width"] && is_numeric($thumb["width"]) || $thumb["height"] && is_numeric($thumb["height"])) {
                         $temp_thumb = SITE_ROOT . "files/" . uniqid("temp-") . $itype_exts[$itype];
                         BigTree::createThumbnail($temp_copy, $temp_thumb, $thumb["width"], $thumb["height"], $field["options"]["retina"], $thumb["grayscale"]);
                         // We use replace here instead of upload because we want to be 100% sure that this file name doesn't change.
                         $storage->replace($temp_thumb, $thumb["prefix"] . $pinfo["basename"], $field["options"]["directory"]);
                     }
                 }
             }
             // Handle center crops
             if (is_array($field["options"]["center_crops"])) {
                 foreach ($field["options"]["center_crops"] as $crop) {
                     // Make sure the crop has a width and height and it's numeric
                     if ($crop["width"] && is_numeric($crop["width"]) && $crop["height"] && is_numeric($crop["height"])) {
                         $temp_crop = SITE_ROOT . "files/" . uniqid("temp-") . $itype_exts[$itype];
                         BigTree::centerCrop($temp_copy, $temp_crop, $crop["width"], $crop["height"], $field["options"]["retina"], $crop["grayscale"]);
                         // We use replace here instead of upload because we want to be 100% sure that this file name doesn't change.
                         $storage->replace($temp_crop, $crop["prefix"] . $pinfo["basename"], $field["options"]["directory"]);
                     }
                 }
             }
             // If we don't have any crops, get rid of the temporary image we made.
             if (!count($bigtree["crops"])) {
                 unlink($temp_copy);
             }
         }
         // We failed, keep the current value.
     } else {
         return false;
     }
     return $field["output"];
 }
Ejemplo n.º 3
0
function _local_bigtree_update_200()
{
    global $cms, $admin;
    // Drop unused comments column
    sqlquery("ALTER TABLE bigtree_pending_changes DROP COLUMN `comments`");
    // Add extension columns
    sqlquery("ALTER TABLE bigtree_callouts ADD COLUMN `extension` VARCHAR(255)");
    sqlquery("ALTER TABLE bigtree_callouts ADD FOREIGN KEY (extension) REFERENCES `bigtree_extensions` (id) ON DELETE CASCADE");
    sqlquery("ALTER TABLE bigtree_feeds ADD COLUMN `extension` VARCHAR(255)");
    sqlquery("ALTER TABLE bigtree_feeds ADD FOREIGN KEY (extension) REFERENCES `bigtree_extensions` (id) ON DELETE CASCADE");
    sqlquery("ALTER TABLE bigtree_field_types ADD COLUMN `extension` VARCHAR(255)");
    sqlquery("ALTER TABLE bigtree_field_types ADD FOREIGN KEY (extension) REFERENCES `bigtree_extensions` (id) ON DELETE CASCADE");
    sqlquery("ALTER TABLE bigtree_modules ADD COLUMN `extension` VARCHAR(255)");
    sqlquery("ALTER TABLE bigtree_modules ADD FOREIGN KEY (extension) REFERENCES `bigtree_extensions` (id) ON DELETE CASCADE");
    sqlquery("ALTER TABLE bigtree_module_groups ADD COLUMN `extension` VARCHAR(255)");
    sqlquery("ALTER TABLE bigtree_module_groups ADD FOREIGN KEY (extension) REFERENCES `bigtree_extensions` (id) ON DELETE CASCADE");
    sqlquery("ALTER TABLE bigtree_settings ADD COLUMN `extension` VARCHAR(255)");
    sqlquery("ALTER TABLE bigtree_settings ADD FOREIGN KEY (extension) REFERENCES `bigtree_extensions` (id) ON DELETE CASCADE");
    sqlquery("ALTER TABLE bigtree_templates ADD COLUMN `extension` VARCHAR(255)");
    sqlquery("ALTER TABLE bigtree_templates ADD FOREIGN KEY (extension) REFERENCES `bigtree_extensions` (id) ON DELETE CASCADE");
    // New publish_hook column, consolidate other hooks into one column
    sqlquery("ALTER TABLE bigtree_pending_changes ADD COLUMN `publish_hook` VARCHAR(255)");
    sqlquery("ALTER TABLE bigtree_module_forms ADD COLUMN `hooks` TEXT");
    sqlquery("ALTER TABLE bigtree_module_embeds ADD COLUMN `hooks` TEXT");
    $q = sqlquery("SELECT * FROM bigtree_module_forms");
    while ($f = sqlfetch($q)) {
        $hooks = array();
        $hooks["pre"] = $f["preprocess"];
        $hooks["post"] = $f["callback"];
        $hooks["publish"] = "";
        sqlquery("UPDATE bigtree_module_forms SET hooks = '" . BigTree::json($hooks, true) . "' WHERE id = '" . $f["id"] . "'");
    }
    $q = sqlquery("SELECT * FROM bigtree_module_embeds");
    while ($f = sqlfetch($q)) {
        $hooks = array();
        $hooks["pre"] = $f["preprocess"];
        $hooks["post"] = $f["callback"];
        $hooks["publish"] = "";
        sqlquery("UPDATE bigtree_module_embeds SET hooks = '" . BigTree::json($hooks, true) . "' WHERE id = '" . $f["id"] . "'");
    }
    sqlquery("ALTER TABLE bigtree_module_forms DROP COLUMN `preprocess`");
    sqlquery("ALTER TABLE bigtree_module_forms DROP COLUMN `callback`");
    sqlquery("ALTER TABLE bigtree_module_embeds DROP COLUMN `preprocess`");
    sqlquery("ALTER TABLE bigtree_module_embeds DROP COLUMN `callback`");
    // Adjust groups/callouts for multi-support -- first we drop the foreign key
    $table_desc = BigTree::describeTable("bigtree_callouts");
    foreach ($table_desc["foreign_keys"] as $name => $definition) {
        if ($definition["local_columns"][0] === "group") {
            sqlquery("ALTER TABLE bigtree_callouts DROP FOREIGN KEY `{$name}`");
        }
    }
    // Add the field to the groups
    sqlquery("ALTER TABLE bigtree_callout_groups ADD COLUMN `callouts` TEXT AFTER `name`");
    // Find all the callouts in each group
    $q = sqlquery("SELECT * FROM bigtree_callout_groups");
    while ($f = sqlfetch($q)) {
        $callouts = array();
        $qq = sqlquery("SELECT * FROM bigtree_callouts WHERE `group` = '" . $f["id"] . "' ORDER BY position DESC, id ASC");
        while ($ff = sqlfetch($qq)) {
            $callouts[] = $ff["id"];
        }
        sqlquery("UPDATE bigtree_callout_groups SET `callouts` = '" . BigTree::json($callouts, true) . "' WHERE id = '" . $f["id"] . "'");
    }
    // Drop the group column
    sqlquery("ALTER TABLE bigtree_callouts DROP COLUMN `group`");
    // Security policy setting
    sqlquery("INSERT INTO `bigtree_settings` (`id`,`value`,`system`) VALUES ('bigtree-internal-security-policy','{}','on')");
    sqlquery("CREATE TABLE `bigtree_login_attempts` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `ip` int(11) DEFAULT NULL, `user` int(11) DEFAULT NULL, `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
    sqlquery("CREATE TABLE `bigtree_login_bans` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT, `ip` int(11) DEFAULT NULL, `user` int(11) DEFAULT NULL, `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `expires` datetime DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
    // Media settings
    sqlquery("INSERT INTO `bigtree_settings` (`id`,`value`,`system`) VALUES ('bigtree-internal-media-settings','{}','on')");
    // New field types
    @unlink(SERVER_ROOT . "cache/bigtree-form-field-types.json");
    // Setup an anonymous function for converting a resource set
    $resource_converter = function ($resources) {
        $new_resources = array();
        foreach ($resources as $item) {
            // Array of Items no longer exists, switching to Matrix
            if ($item["type"] == "array") {
                $item["type"] = "matrix";
                $item["columns"] = array();
                $x = 0;
                foreach ($item["fields"] as $field) {
                    $x++;
                    $item["columns"][] = array("id" => $field["key"], "type" => $field["type"], "title" => $field["title"], "display_title" => $x == 1 ? "on" : "");
                }
                unset($item["fields"]);
            }
            $r = array("id" => $item["id"], "type" => $item["type"], "title" => $item["title"], "subtitle" => $item["subtitle"], "options" => array());
            foreach ($item as $key => $val) {
                if ($key != "id" && $key != "title" && $key != "subtitle" && $key != "type") {
                    $r["options"][$key] = $val;
                }
            }
            $new_resources[] = $r;
        }
        return BigTree::json($new_resources, true);
    };
    $field_converter = function ($fields) {
        $new_fields = array();
        foreach ($fields as $id => $field) {
            // Array of Items no longer exists, switching to Matrix
            if ($field["type"] == "array") {
                $field["type"] = "matrix";
                $field["columns"] = array();
                $x = 0;
                foreach ($field["fields"] as $subfield) {
                    $x++;
                    $field["columns"][] = array("id" => $subfield["key"], "type" => $subfield["type"], "title" => $subfield["title"], "display_title" => $x == 1 ? "on" : "");
                }
                unset($field["fields"]);
            }
            $r = array("column" => $id, "type" => $field["type"], "title" => $field["title"], "subtitle" => $field["subtitle"], "options" => array());
            foreach ($field as $key => $val) {
                if ($key != "id" && $key != "title" && $key != "subtitle" && $key != "type") {
                    $r["options"][$key] = $val;
                }
            }
            $new_fields[] = $r;
        }
        return $new_fields;
    };
    // New resource format to be less restrictive on option names
    $q = sqlquery("SELECT * FROM bigtree_callouts");
    while ($f = sqlfetch($q)) {
        $resources = $resource_converter(json_decode($f["resources"], true));
        sqlquery("UPDATE bigtree_callouts SET resources = '{$resources}' WHERE id = '" . $f["id"] . "'");
    }
    $q = sqlquery("SELECT * FROM bigtree_templates");
    while ($f = sqlfetch($q)) {
        $resources = $resource_converter(json_decode($f["resources"], true));
        sqlquery("UPDATE bigtree_templates SET resources = '{$resources}' WHERE id = '" . $f["id"] . "'");
    }
    // Forms and Embedded Forms
    $q = sqlquery("SELECT * FROM bigtree_module_forms");
    while ($f = sqlfetch($q)) {
        $fields = $field_converter(json_decode($f["fields"], true));
        sqlquery("UPDATE bigtree_module_forms SET fields = '" . BigTree::json($fields, true) . "' WHERE id = '" . $f["id"] . "'");
    }
    $q = sqlquery("SELECT * FROM bigtree_module_embeds");
    while ($f = sqlfetch($q)) {
        $fields = $field_converter(json_decode($f["fields"], true));
        sqlquery("UPDATE bigtree_module_embeds SET fields = '" . BigTree::json($fields, true) . "' WHERE id = '" . $f["id"] . "'");
    }
    // Settings
    $q = sqlquery("SELECT * FROM bigtree_settings WHERE type = 'array'");
    while ($f = sqlfetch($q)) {
        // Update settings options to turn array into matrix
        $options = json_decode($f["options"], true);
        $options["columns"] = array();
        $x = 0;
        foreach ($options["fields"] as $field) {
            $x++;
            $options["columns"][] = array("id" => $field["key"], "type" => $field["type"], "title" => $field["title"], "display_title" => $x == 1 ? "on" : "");
            if ($x == 1) {
                $display_key = $field["key"];
            }
        }
        unset($options["fields"]);
        // Update the value to set an internal title key
        $value = BigTreeCMS::getSetting($f["id"]);
        foreach ($value as &$entry) {
            $entry["__internal-title"] = $entry[$display_key];
        }
        unset($entry);
        // Update type/options
        sqlquery("UPDATE bigtree_settings SET type = 'matrix', options = '" . BigTree::json($options, true) . "' WHERE id = '" . $f["id"] . "'");
        // Update value separately
        BigTreeAdmin::updateSettingValue($f["id"], $value);
    }
}
Ejemplo n.º 4
0
 function getFTPRoot($user, $password)
 {
     if (!$this->Connection->login($user, $password)) {
         return false;
     }
     // Try to determine the FTP root.
     $ftp_root = false;
     $saved_root = BigTreeCMS::getSetting("bigtree-internal-ftp-upgrade-root");
     if ($saved_root !== false && $this->Connection->changeDirectory($saved_root) . "core/inc/bigtree/") {
         $ftp_root = $saved_root;
     } elseif ($this->Connection->changeDirectory(SERVER_ROOT . "core/inc/bigtree/")) {
         $ftp_root = SERVER_ROOT;
     } elseif ($this->Connection->changeDirectory("/core/inc/bigtree")) {
         $ftp_root = "/";
     } elseif ($this->Connection->changeDirectory("/httpdocs/core/inc/bigtree")) {
         $ftp_root = "/httpdocs";
     } elseif ($this->Connection->changeDirectory("/public_html/core/inc/bigtree")) {
         $ftp_root = "/public_html";
     } elseif ($this->Connection->changeDirectory("/" . str_replace(array("http://", "https://"), "", DOMAIN) . "inc/bigtree/")) {
         $ftp_root = "/" . str_replace(array("http://", "https://"), "", DOMAIN);
     }
     return $ftp_root;
 }