Exemple #1
0
 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;
 }
 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);
 }
Exemple #3
0
 static function search404s($type, $query = "", $page = 1)
 {
     $items = array();
     if ($query) {
         $s = sqlescape(strtolower($query));
         if ($type == "301") {
             $where = "ignored = '' AND (LOWER(broken_url) LIKE '%{$s}%' OR LOWER(redirect_url) LIKE '%{$s}%') AND redirect_url != ''";
         } elseif ($type == "ignored") {
             $where = "ignored != '' AND (LOWER(broken_url) LIKE '%{$s}%' OR LOWER(redirect_url) LIKE '%{$s}%')";
         } else {
             $where = "ignored = '' AND LOWER(broken_url) LIKE '%{$s}%' AND redirect_url = ''";
         }
     } else {
         if ($type == "301") {
             $where = "ignored = '' AND redirect_url != ''";
         } elseif ($type == "ignored") {
             $where = "ignored != ''";
         } else {
             $where = "ignored = '' AND redirect_url = ''";
         }
     }
     // Get the page count
     $f = sqlfetch(sqlquery("SELECT COUNT(id) AS `count` FROM bigtree_404s WHERE {$where}"));
     $pages = ceil($f["count"] / 20);
     $pages = $pages < 1 ? 1 : $pages;
     // Get the results
     $q = sqlquery("SELECT * FROM bigtree_404s WHERE {$where} ORDER BY requests DESC LIMIT " . ($page - 1) * 20 . ",20");
     while ($f = sqlfetch($q)) {
         $f["redirect_url"] = BigTreeCMS::replaceInternalPageLinks($f["redirect_url"]);
         $items[] = $f;
     }
     return array($pages, $items);
 }
Exemple #4
0
 static function getSetting($id, $decode = true)
 {
     global $bigtree;
     $id = BigTreeCMS::extensionSettingCheck($id);
     $setting = sqlfetch(sqlquery("SELECT * FROM bigtree_settings WHERE id = '{$id}'"));
     // Setting doesn't exist
     if (!$setting) {
         return false;
     }
     // Encrypted setting
     if ($setting["encrypted"]) {
         $v = sqlfetch(sqlquery("SELECT AES_DECRYPT(`value`,'" . sqlescape($bigtree["config"]["settings_key"]) . "') AS `value` FROM bigtree_settings WHERE id = '{$id}'"));
         $setting["value"] = $v["value"];
     }
     // Decode the JSON value
     if ($decode) {
         $setting["value"] = json_decode($setting["value"], true);
         if (is_array($setting["value"])) {
             $setting["value"] = BigTree::untranslateArray($setting["value"]);
         } else {
             $setting["value"] = BigTreeCMS::replaceInternalPageLinks($setting["value"]);
         }
     }
     return $setting;
 }
Exemple #5
0
 static function untranslateArray($array)
 {
     foreach ($array as &$piece) {
         if (is_array($piece)) {
             $piece = static::untranslateArray($piece);
         } else {
             $piece = BigTreeCMS::replaceInternalPageLinks($piece);
         }
     }
     return $array;
 }