Exemplo n.º 1
0
 function add($keys, $vals, $enforce_unique = false, $ignore_cache = false)
 {
     $admin = new BigTreeAdmin();
     $existing_parts = $key_parts = $value_parts = array();
     $x = 0;
     // Get a bunch of query parts.
     foreach ($keys as $key) {
         $val = current($vals);
         $val = is_array($val) ? sqlescape(json_encode(BigTree::translateArray($val))) : sqlescape($admin->autoIPL($val));
         $existing_parts[] = "`{$key}` = '{$val}'";
         $key_parts[] = "`{$key}`";
         $value_parts[] = "'{$val}'";
         next($vals);
     }
     // Prevent Duplicates
     if ($enforce_unique) {
         $row = sqlfetch(sqlquery("SELECT id FROM `" . $this->Table . "` WHERE " . implode(" AND ", $existing_parts) . " LIMIT 1"));
         // If it's the same as an existing entry, return that entry's id
         if ($row) {
             return $row["id"];
         }
     }
     // Add the entry and cache it.
     sqlquery("INSERT INTO `" . $this->Table . "` (" . implode(",", $key_parts) . ") VALUES (" . implode(",", $value_parts) . ")");
     $id = sqlid();
     if (!$ignore_cache) {
         BigTreeAutoModule::cacheNewItem($id, $this->Table);
     }
     return $id;
 }
Exemplo n.º 2
0
 function add($fields, $values = false, $enforce_unique = false, $ignore_cache = false)
 {
     $existing_parts = $key_parts = $value_parts = array();
     // Single column/value add
     if (is_string($fields)) {
         $value = is_array($values) ? sqlescape(json_encode(BigTree::translateArray($values))) : sqlescape(BigTreeAdmin::autoIPL($values));
         $existing_parts[] = "`{$fields}` = '{$value}'";
         $key_parts[] = "`{$fields}`";
         $value_parts[] = "{$value}";
         // Multiple columns / values
     } else {
         // If we didn't pass in values (=== false) then we're using a key => value array
         if ($values === false) {
             foreach ($fields as $key => $value) {
                 $value = is_array($value) ? sqlescape(json_encode(BigTree::translateArray($value))) : sqlescape(BigTreeAdmin::autoIPL($value));
                 $existing_parts[] = "`{$key}` = '{$value}'";
                 $key_parts[] = "`{$key}`";
                 $value_parts[] = "'{$value}'";
             }
             // Separate arrays for keys and values
         } else {
             foreach ($fields as $key) {
                 $val = current($values);
                 $val = is_array($val) ? sqlescape(json_encode(BigTree::translateArray($val))) : sqlescape(BigTreeAdmin::autoIPL($val));
                 $existing_parts[] = "`{$key}` = '{$val}'";
                 $key_parts[] = "`{$key}`";
                 $value_parts[] = "'{$val}'";
                 next($values);
             }
         }
     }
     // Prevent Duplicates
     if ($enforce_unique) {
         $row = sqlfetch(sqlquery("SELECT id FROM `" . $this->Table . "` WHERE " . implode(" AND ", $existing_parts) . " LIMIT 1"));
         // If it's the same as an existing entry, return that entry's id
         if ($row) {
             return $row["id"];
         }
     }
     // Add the entry and cache it.
     sqlquery("INSERT INTO `" . $this->Table . "` (" . implode(",", $key_parts) . ") VALUES (" . implode(",", $value_parts) . ")");
     $id = sqlid();
     if (!$ignore_cache) {
         BigTreeAutoModule::cacheNewItem($id, $this->Table);
     }
     return $id;
 }
Exemplo n.º 3
0
}
// Import modules
foreach ($json["components"]["modules"] as &$module) {
    if ($module) {
        $group = $module["group"] && isset($bigtree["group_match"][$module["group"]]) ? $bigtree["group_match"][$module["group"]] : "NULL";
        $gbp = sqlescape(is_array($module["gbp"]) ? json_encode($module["gbp"]) : $module["gbp"]);
        // Find a unique route
        $oroute = $route = $module["route"];
        $x = 2;
        while (sqlrows(sqlquery("SELECT * FROM bigtree_modules WHERE route = '" . sqlescape($route) . "'"))) {
            $route = $oroute . "-{$x}";
            $x++;
        }
        // Create the module
        sqlquery("INSERT INTO bigtree_modules (`name`,`route`,`class`,`icon`,`group`,`gbp`) VALUES ('" . sqlescape($module["name"]) . "','" . sqlescape($route) . "','" . sqlescape($module["class"]) . "','" . sqlescape($module["icon"]) . "',{$group},'{$gbp}')");
        $module_id = sqlid();
        $bigtree["module_match"][$module["id"]] = $module_id;
        $bigtree["route_match"][$module["route"]] = $route;
        // Update the module ID since we're going to save this manifest locally for uninstalling
        $module["id"] = $module_id;
        // Create the embed forms
        foreach ($module["embed_forms"] as $form) {
            $admin->createModuleEmbedForm($module_id, $form["title"], $form["table"], is_array($form["fields"]) ? $form["fields"] : json_decode($form["fields"], true), $form["preprocess"], $form["callback"], $form["default_position"], $form["default_pending"], $form["css"], $form["redirect_url"], $form["thank_you_message"]);
        }
        // Create views
        foreach ($module["views"] as $view) {
            $bigtree["view_id_match"][$view["id"]] = $admin->createModuleView($module_id, $view["title"], $view["description"], $view["table"], $view["type"], is_array($view["options"]) ? $view["options"] : json_decode($view["options"], true), is_array($view["fields"]) ? $view["fields"] : json_decode($view["fields"], true), is_array($view["actions"]) ? $view["actions"] : json_decode($view["actions"], true), $view["related_form"], $view["preview_url"]);
        }
        // Create regular forms
        foreach ($module["forms"] as $form) {
            $bigtree["form_id_match"][$form["id"]] = $admin->createModuleForm($module_id, $form["title"], $form["table"], is_array($form["fields"]) ? $form["fields"] : json_decode($form["fields"], true), $form["preprocess"], $form["callback"], $form["default_position"], $form["return_view"] ? $bigtree["view_id_match"][$form["return_view"]] : false, $form["return_url"], $form["tagging"]);
Exemplo n.º 4
0
 static function submitChange($module, $table, $id, $data, $many_to_many = array(), $tags = array(), $publish_hook = null)
 {
     global $admin;
     if (!isset($admin) || get_class($admin) != "BigTreeAdmin" || !$admin->ID) {
         throw new Exception("BigTreeAutoModule::submitChange must be called by a logged in user.");
     }
     $id = sqlescape($id);
     $original = sqlfetch(sqlquery("SELECT * FROM `{$table}` WHERE id = '{$id}'"));
     foreach ($data as $key => $val) {
         if ($val === "NULL") {
             $data[$key] = "";
         }
         if ($original && $original[$key] === $val) {
             unset($data[$key]);
         }
     }
     $changes = sqlescape(json_encode($data));
     $many_data = sqlescape(json_encode($many_to_many));
     $tags_data = sqlescape(json_encode($tags));
     // Find out if there's already a change waiting
     if (substr($id, 0, 1) == "p") {
         $existing = sqlfetch(sqlquery("SELECT * FROM bigtree_pending_changes WHERE id = '" . substr($id, 1) . "'"));
     } else {
         $existing = sqlfetch(sqlquery("SELECT * FROM bigtree_pending_changes WHERE `table` = '{$table}' AND item_id = '{$id}'"));
     }
     if ($existing) {
         sqlquery("UPDATE bigtree_pending_changes SET changes = '{$changes}', mtm_changes = '{$many_data}', tags_changes = '{$tags_data}', date = NOW(), user = '******', type = 'EDIT' WHERE id = '" . $existing["id"] . "'");
         // If the id has a "p" it's still pending and we need to recache over the pending one.
         if (substr($id, 0, 1) == "p") {
             self::recacheItem(substr($id, 1), $table, true);
         } else {
             self::recacheItem($id, $table);
         }
         $admin->track($table, $id, "updated-draft");
         return $existing["id"];
     } else {
         $publish_hook = is_null($publish_hook) ? "NULL" : "'" . sqlescape($publish_hook) . "'";
         sqlquery("INSERT INTO bigtree_pending_changes (`user`,`date`,`table`,`item_id`,`changes`,`mtm_changes`,`tags_changes`,`module`,`type`,`publish_hook`) VALUES ('" . $admin->ID . "',NOW(),'{$table}','{$id}','{$changes}','{$many_data}','{$tags_data}','{$module}','EDIT',{$publish_hook})");
         self::recacheItem($id, $table);
         $admin->track($table, $id, "saved-draft");
         return sqlid();
     }
 }
Exemplo n.º 5
0
 function submitPageChange($page, $changes)
 {
     if ($page[0] == "p") {
         // It's still pending...
         $type = "NEW";
         $pending = true;
         $existing_page = array();
         $existing_pending_change = array("id" => substr($page, 1));
     } else {
         // It's an existing page
         $type = "EDIT";
         $pending = false;
         $existing_page = BigTreeCMS::getPage($page);
         $existing_pending_change = sqlfetch(sqlquery("SELECT id FROM bigtree_pending_changes WHERE `table` = 'bigtree_pages' AND item_id = '{$page}'"));
     }
     // Save tags separately
     $tags = BigTree::json($changes["_tags"], true);
     unset($changes["_tags"]);
     // Convert to an IPL
     if (!empty($changes["external"])) {
         $changes["external"] = $this->makeIPL($changes["external"]);
     }
     // Unset the trunk flag if the user isn't a developer
     if ($this->Level < 2) {
         unset($changes["trunk"]);
         // Make sure the value is changed -- since it's a check box it may not have come through
     } else {
         $changes["trunk"] = !empty($changes["trunk"]) ? "on" : "";
     }
     // Set the in_nav flag, since it's not in the post if the checkbox became unclicked
     $changes["in_nav"] = !empty($changes["in_nav"]) ? "on" : "";
     // If there's already a change in the queue, update it with this latest info.
     if ($existing_pending_change) {
         // If this is a pending page, just replace all the changes
         if ($pending) {
             $changes = BigTree::json($changes, true);
             // Otherwise, we need to check what's changed.
         } else {
             // We don't want to indiscriminately put post data in as changes, so we ensure it matches a column in the bigtree_pages table
             $diff = array();
             foreach ($changes as $key => $val) {
                 if (array_key_exists($key, $existing_page) && $existing_page[$key] != $val) {
                     $diff[$key] = $val;
                 }
             }
             $changes = BigTree::json($diff, true);
         }
         // Update existing draft and track
         sqlquery("UPDATE bigtree_pending_changes SET changes = '{$changes}', tags_changes = '{$tags}', date = NOW(), user = '******', type = '{$type}' WHERE id = '" . $existing_pending_change["id"] . "'");
         $this->track("bigtree_pages", $page, "updated-draft");
         // We're submitting a change to a presently published page with no pending changes.
     } else {
         $diff = array();
         foreach ($changes as $key => $val) {
             if (array_key_exists($key, $existing_page) && $val != $existing_page[$key]) {
                 $diff[$key] = $val;
             }
         }
         $changes = BigTree::json($diff, true);
         // Create draft and track
         sqlquery("INSERT INTO bigtree_pending_changes (`user`,`date`,`table`,`item_id`,`changes`,`tags_changes`,`type`,`title`) VALUES ('" . $this->ID . "',NOW(),'bigtree_pages','{$page}','{$changes}','{$tags}','EDIT','Page Change Pending')");
         $this->track("bigtree_pages", $page, "saved-draft");
     }
     return sqlid();
 }
Exemplo n.º 6
0
 static function submitChange($module, $table, $id, $data, $many_to_many = array(), $tags = array())
 {
     global $admin;
     $original = sqlfetch(sqlquery("SELECT * FROM `{$table}` WHERE id = '{$id}'"));
     foreach ($data as $key => $val) {
         if ($val === "NULL") {
             $data[$key] = "";
         }
         if ($original && $original[$key] === $val) {
             unset($data[$key]);
         }
     }
     $changes = sqlescape(json_encode($data));
     $many_data = sqlescape(json_encode($many_to_many));
     $tags_data = sqlescape(json_encode($tags));
     // Find out if there's already a change waiting
     if (substr($id, 0, 1) == "p") {
         $existing = sqlfetch(sqlquery("SELECT * FROM bigtree_pending_changes WHERE id = '" . substr($id, 1) . "'"));
     } else {
         $existing = sqlfetch(sqlquery("SELECT * FROM bigtree_pending_changes WHERE `table` = '{$table}' AND item_id = '{$id}'"));
     }
     if ($existing) {
         $comments = json_decode($existing["comments"], true);
         if ($existing["user"] == $admin->ID) {
             $comments[] = array("user" => "BigTree", "date" => date("F j, Y @ g:ia"), "comment" => "A new revision has been made.");
         } else {
             $user = $admin->getUser($admin->ID);
             $comments[] = array("user" => "BigTree", "date" => date("F j, Y @ g:ia"), "comment" => "A new revision has been made.  Owner switched to " . $user["name"] . ".");
         }
         $comments = sqlescape(json_encode($comments));
         sqlquery("UPDATE bigtree_pending_changes SET comments = '{$comments}', changes = '{$changes}', mtm_changes = '{$many_data}', tags_changes = '{$tags_data}', date = NOW(), user = '******', type = 'EDIT' WHERE id = '" . $existing["id"] . "'");
         // If the id has a "p" it's still pending and we need to recache over the pending one.
         if (substr($id, 0, 1) == "p") {
             self::recacheItem(substr($id, 1), $table, true);
         } else {
             self::recacheItem($id, $table);
         }
         if ($admin) {
             $admin->track($table, $id, "updated-draft");
         }
         return $existing["id"];
     } else {
         sqlquery("INSERT INTO bigtree_pending_changes (`user`,`date`,`table`,`item_id`,`changes`,`mtm_changes`,`tags_changes`,`module`,`type`) VALUES ('" . $admin->ID . "',NOW(),'{$table}','{$id}','{$changes}','{$many_data}','{$tags_data}','{$module}','EDIT')");
         self::recacheItem($id, $table);
         if ($admin) {
             $admin->track($table, $id, "saved-draft");
         }
         return sqlid();
     }
 }
Exemplo n.º 7
0
 function submitPageChange($page, $changes)
 {
     global $cms;
     if ($page[0] == "p") {
         // It's still pending...
         $existing_page = array();
         $pending = true;
         $type = "NEW";
     } else {
         // It's an existing page
         $pending = false;
         $existing_page = $cms->getPage($page);
         $type = "EDIT";
     }
     $template = $existing_page["template"];
     if (!$pending) {
         $existing_pending_change = sqlfetch(sqlquery("SELECT * FROM bigtree_pending_changes WHERE `table` = 'bigtree_pages' AND item_id = '{$page}'"));
     } else {
         $existing_pending_change = sqlfetch(sqlquery("SELECT * FROM bigtree_pending_changes WHERE id = '" . substr($page, 1) . "'"));
     }
     // Save tags separately
     $tags = sqlescape(json_encode($changes["_tags"]));
     unset($changes["_tags"]);
     // Unset the trunk flag if the user isn't a developer
     if ($this->Level < 2) {
         unset($changes["trunk"]);
         // Make sure the value is changed
     } else {
         $changes["trunk"] = $changes["trunk"];
     }
     // Set the in_nav flag, since it's not in the post if the checkbox became unclicked
     $changes["in_nav"] = $changes["in_nav"];
     // If there's already a change in the queue, update it with this latest info.
     if ($existing_pending_change) {
         $comments = json_decode($f["comments"], true);
         if ($existing_pending_change["user"] == $this->ID) {
             $comments[] = array("user" => "BigTree", "date" => date("F j, Y @ g:ia"), "comment" => "A new revision has been made.");
         } else {
             $user = $this->getUser($this->ID);
             $comments[] = array("user" => "BigTree", "date" => date("F j, Y @ g:ia"), "comment" => "A new revision has been made.  Owner switched to " . $user["name"] . ".");
         }
         // If this is a pending page, just replace all the changes
         if ($pending) {
             $changes = sqlescape(json_encode($changes));
             // Otherwise, we need to check what's changed.
         } else {
             $original_changes = json_decode($existing_pending_change["changes"], true);
             if (isset($original_changes["template"])) {
                 $template = $original_changes["template"];
             }
             if (isset($changes["external"])) {
                 $changes["external"] = $this->makeIPL($changes["external"]);
             }
             foreach ($changes as $key => $val) {
                 if ($val != $original_changes[$key] && array_key_exists($key, $existing_page)) {
                     $original_changes[$key] = $val;
                 }
             }
             $changes = sqlescape(json_encode($original_changes));
         }
         $comments = sqlescape(json_encode($comments));
         sqlquery("UPDATE bigtree_pending_changes SET comments = '{$comments}', changes = '{$changes}', tags_changes = '{$tags}', date = NOW(), user = '******', type = '{$type}' WHERE id = '" . $existing_pending_change["id"] . "'");
         $this->track("bigtree_pages", $page, "updated-draft");
         // We're submitting a change to a presently published page with no pending changes.
     } else {
         $original_changes = array();
         foreach ($changes as $key => $val) {
             if ($key == "external") {
                 $val = $this->makeIPL($val);
             }
             if (array_key_exists($key, $existing_page) && $val != $existing_page[$key]) {
                 $original_changes[$key] = $val;
             }
         }
         $changes = sqlescape(json_encode($original_changes));
         if ($type == "DELETE") {
             sqlquery("INSERT INTO bigtree_pending_changes (`user`,`date`,`table`,`item_id`,`changes`,`type`,`title`) VALUES ('" . $this->ID . "',NOW(),'bigtree_pages','{$page}','{$changes}','DELETE','Page Deletion Pending')");
         } else {
             sqlquery("INSERT INTO bigtree_pending_changes (`user`,`date`,`table`,`item_id`,`changes`,`tags_changes`,`type`,`title`) VALUES ('" . $this->ID . "',NOW(),'bigtree_pages','{$page}','{$changes}','{$tags}','EDIT','Page Change Pending')");
         }
         $this->track("bigtree_pages", $page, "saved-draft");
     }
     return sqlid();
 }
Exemplo n.º 8
0
 protected static function syncData($query, $service, $data)
 {
     if (is_array($data->Results)) {
         // If we have results, let's find out what categories they need to be tagged to.
         $categories = array();
         $cq = sqlquery("SELECT * FROM btx_social_feed_query_categories WHERE `query` = '" . $query["id"] . "'");
         while ($cf = sqlfetch($cq)) {
             $categories[] = $cf["category"];
         }
         foreach ($data->Results as $r) {
             $id = sqlescape($r->ID);
             // Check for existing
             $existing = sqlfetch(sqlquery("SELECT id FROM btx_social_feed_stream WHERE service = '{$service}' AND service_id = '{$id}'"));
             if (!$existing) {
                 $data = sqlescape(json_encode($r));
                 if ($r->Timestamp) {
                     $date = sqlescape($r->Timestamp);
                 } elseif ($r->CreatedAt) {
                     $date = sqlescape($r->CreatedAt);
                 } elseif ($r->Dates->Posted) {
                     $date = sqlescape($r->Dates->Posted);
                 } else {
                     $date = date("Y-m-d H:i:s");
                 }
                 sqlquery("INSERT INTO btx_social_feed_stream (`date`,`service`,`service_id`,`data`,`approved`) VALUES ('{$date}','{$service}','{$id}','{$data}','" . self::$DefaultApprovedState . "')");
                 $existing["id"] = sqlid();
                 self::$ItemsToCache[] = array("id" => sqlid(), "date" => $date, "service" => $service, "service_id" => $id, "data" => json_encode($r), "approved" => self::$DefaultApprovedState);
             }
             // Tag to categories
             foreach ($categories as $c) {
                 sqlquery("DELETE FROM btx_social_feed_stream_categories WHERE item = '" . $existing["id"] . "' AND category = '{$c}'");
                 sqlquery("INSERT INTO btx_social_feed_stream_categories (`item`,`category`) VALUES ('" . $existing["id"] . "','{$c}')");
             }
             // Tag to the query
             sqlquery("DELETE FROM btx_social_feed_stream_queries WHERE `item` = '" . $existing["id"] . "' AND `query` = '" . $query["id"] . "'");
             sqlquery("INSERT INTO btx_social_feed_stream_queries (`item`,`query`) VALUES ('" . $existing["id"] . "','" . $query["id"] . "')");
         }
     }
 }