コード例 #1
0
ファイル: modules.php プロジェクト: matthisamoto/Graphfan
 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;
 }
コード例 #2
0
ファイル: modules.php プロジェクト: kurt-planet/BigTree-CMS
 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;
 }