<?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"]) { ?>
function get($item) { if (!is_array($item)) { $item = sqlfetch(sqlquery("SELECT * FROM `" . $this->Table . "` WHERE id = '" . sqlescape($item) . "'")); } if (!$item) { return false; } foreach ($item as $key => $val) { if (is_array($val)) { $item[$key] = BigTree::untranslateArray($val); } elseif (is_array(json_decode($val, true))) { $item[$key] = BigTree::untranslateArray(json_decode($val, true)); } else { $item[$key] = BigTreeCMS::replaceInternalPageLinks($val); } } return $item; }
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); } }
static function getPendingItem($table, $id) { $status = "published"; $many_to_many = array(); $owner = false; // The entry is pending if there's a "p" prefix on the id if (substr($id, 0, 1) == "p") { $change = sqlfetch(sqlquery("SELECT * FROM bigtree_pending_changes WHERE id = '" . sqlescape(substr($id, 1)) . "'")); if (!$change) { return false; } $item = json_decode($change["changes"], true); $many_to_many = json_decode($change["mtm_changes"], true); $temp_tags = json_decode($change["tags_changes"], true); $tags = array(); if (!empty($temp_tags)) { foreach ($temp_tags as $tid) { $tags[] = sqlfetch(sqlquery("SELECT * FROM bigtree_tags WHERE id = '{$tid}'")); } } $status = "pending"; $owner = $change["user"]; // Otherwise it's a live entry } else { $item = sqlfetch(sqlquery("SELECT * FROM `{$table}` WHERE id = '" . sqlescape($id) . "'")); if (!$item) { return false; } // Apply changes that are pending $change = sqlfetch(sqlquery("SELECT * FROM bigtree_pending_changes WHERE `table` = '{$table}' AND `item_id` = '{$id}'")); if ($change) { $status = "updated"; $changes = json_decode($change["changes"], true); foreach ($changes as $key => $val) { $item[$key] = $val; } $many_to_many = json_decode($change["mtm_changes"], true); $temp_tags = json_decode($change["tags_changes"], true); $tags = array(); if (is_array($temp_tags)) { foreach ($temp_tags as $tid) { $tags[] = sqlfetch(sqlquery("SELECT * FROM bigtree_tags WHERE id = '{$tid}'")); } } // If there's no pending changes, just pull the tags } else { $tags = self::getTagsForEntry($table, $id); } } // Process the internal page links, turn json_encoded arrays into arrays. foreach ($item as $key => $val) { if (is_array($val)) { $item[$key] = BigTree::untranslateArray($val); } elseif (is_array(json_decode($val, true))) { $item[$key] = BigTree::untranslateArray(json_decode($val, true)); } else { $item[$key] = BigTreeCMS::replaceInternalPageLinks($val); } } return array("item" => $item, "mtm" => $many_to_many, "tags" => $tags, "status" => $status, "owner" => $owner); }
static function updateSettingValue($id, $value) { global $bigtree, $admin; $item = static::getSetting($id, false); $id = sqlescape(BigTreeCMS::extensionSettingCheck($id)); if (is_array($value)) { $value = BigTree::translateArray($value); } else { $value = static::autoIPL($value); } $value = BigTree::json($value, true); if ($item["encrypted"]) { sqlquery("UPDATE bigtree_settings SET `value` = AES_ENCRYPT('{$value}','" . sqlescape($bigtree["config"]["settings_key"]) . "') WHERE id = '{$id}'"); } else { sqlquery("UPDATE bigtree_settings SET `value` = '{$value}' WHERE id = '{$id}'"); } if ($admin && !$item["system"]) { // Audit trail. $admin->track("bigtree_settings", $id, "updated"); } }
static function untranslateArray($array) { foreach ($array as &$piece) { if (is_array($piece)) { $piece = static::untranslateArray($piece); } else { $piece = BigTreeCMS::replaceInternalPageLinks($piece); } } return $array; }
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; }