diff --git bulk_export/bulk_export.module bulk_export/bulk_export.module
index 3c9c975..9c28a6d 100644
--- bulk_export/bulk_export.module
+++ bulk_export/bulk_export.module
@@ -9,15 +9,21 @@
/**
* Implementation of hook_perm().
*/
-function bulk_export_perm() {
- return array('use bulk exporter');
+function bulk_export_permission() {
+ return array(
+ 'use bulk exporter' => array(
+ 'title' => t('Access Bulk Exporter'),
+ 'description' => t('Export various system objects into code.'),
+ ),
+ );
}
/**
* Implementation of hook_theme().
*/
function bulk_export_theme() {
- return array('bulk_export_export_form' => array(
+ return array(
+ 'bulk_export_export_form' => array(
'arguments' => array('form' => NULL),
),
);
@@ -56,14 +62,13 @@ function bulk_export_export() {
}
}
if ($exportables) {
- ctools_include('form');
$form_state = array(
're_render' => FALSE,
'no_redirect' => TRUE,
'exportables' => $exportables,
'export_tables' => $export_tables,
);
- $output = ctools_build_form('bulk_export_export_form', $form_state);
+ $output = drupal_build_form('bulk_export_export_form', $form_state);
if (!$output) {
drupal_set_title(t('Bulk export results'));
$output = '';
@@ -138,8 +143,7 @@ function bulk_export_export() {
* FAPI definition for the bulk exporter form.
*
*/
-function bulk_export_export_form(&$form_state) {
- $form = array();
+function bulk_export_export_form($form, &$form_state) {
$form['tables'] = array(
'#prefix' => '
',
'#suffix' => '
',
diff --git ctools.install ctools.install
index 9994fc0..1439fff 100644
--- ctools.install
+++ ctools.install
@@ -13,22 +13,15 @@
function ctools_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
- $path = file_create_path('ctools/css');
- if (!file_check_directory($path)) {
- $path = file_directory_path() . '/ctools';
- file_check_directory($path, FILE_CREATE_DIRECTORY);
- $path .= '/css';
- file_check_directory($path, FILE_CREATE_DIRECTORY);
- }
-
$requirements['ctools_css_cache'] = array(
'title' => t('CTools CSS Cache'),
'severity' => REQUIREMENT_OK,
'value' => t('Exists'),
);
- if (!file_check_directory($path)) {
- $requirements['ctools_css_cache']['description'] = t('The CTools CSS cache directory, %path could not be created due to a misconfigured files directory. Please ensure that the files directory is correctly configured and that the webserver has permission to create directories.', array('%path' => $path));
+ $path = 'public://ctools/css';
+ if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
+ $requirements['ctools_css_cache']['description'] = t('The CTools CSS cache directory, %path could not be created due to a misconfigured files directory. Please ensure that the files directory is correctly configured and that the webserver has permission to create directories.', array('%path' => file_uri_target($path)));
$requirements['ctools_css_cache']['severity'] = REQUIREMENT_ERROR;
$requirements['ctools_css_cache']['value'] = t('Unable to create');
}
@@ -141,50 +134,37 @@ function ctools_schema_1() {
* errors.
*/
function ctools_update_6001() {
- $ret = array();
-
// Perform updates like this to reduce code duplication.
$schema = ctools_schema_2();
- db_change_field($ret, 'ctools_object_cache', 'name', 'name', $schema['ctools_object_cache']['fields']['name']);
-
- return $ret;
+ db_change_field('ctools_object_cache', 'name', 'name', $schema['ctools_object_cache']['fields']['name']);
}
/**
* Add the new css cache table.
*/
function ctools_update_6002() {
- $ret = array();
-
// Schema 2 is locked and should not be changed.
$schema = ctools_schema_2();
- db_create_table($ret, 'ctools_css_cache', $schema['ctools_css_cache']);
- return $ret;
+ db_create_table('ctools_css_cache', $schema['ctools_css_cache']);
}
/**
* Take over for the panels_views module if it was on.
*/
function ctools_update_6003() {
- $ret = array();
-
- $result = db_result(db_query("SELECT status FROM {system} WHERE name = 'panels_views'"));
+ $result = db_query('SELECT status FROM {system} WHERE name = :name', array(':name' => 'panels_views'))->fetchField();
if ($result) {
- $ret[] = update_sql("DELETE from {system} WHERE name = 'panels_views'");
+ db_delete('system')->condition('name', 'panels_views')->execute();
drupal_install_modules(array('views_content'));
}
-
- return $ret;
}
/**
* Add primary key to the ctools_object_cache table.
*/
function ctools_update_6004() {
- $ret = array();
- db_add_primary_key($ret, 'ctools_object_cache', array('sid', 'obj', 'name'));
- db_drop_index($ret, 'ctools_object_cache', 'sid_obj_name');
- return $ret;
+ db_add_primary_key('ctools_object_cache', array('sid', 'obj', 'name'));
+ db_drop_index('ctools_object_cache', 'sid_obj_name');
}
diff --git ctools.module ctools.module
index 93cebce..fc4e6c7 100644
--- ctools.module
+++ ctools.module
@@ -10,7 +10,7 @@
* must be implemented in the module file.
*/
-define('CTOOLS_API_VERSION', '1.1.1');
+define('CTOOLS_API_VERSION', '2.0.0');
/**
* Test the CTools API version.
@@ -81,7 +81,7 @@ function ctools_api_version($minimum, $maximum = NULL) {
function ctools_include($file) {
static $used = array();
if (!isset($used[$file])) {
- require_once './' . drupal_get_path('module', 'ctools') . "/includes/$file.inc";
+ require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'ctools') . "/includes/$file.inc";
}
$used[$file] = TRUE;
@@ -116,56 +116,6 @@ function ctools_init() {
}
/**
- * Central static variable storage. Modeled after Drupal 7's drupal_static().
- *
- * @param $name
- * Globally unique name for the variable. For a function with only one static,
- * variable, the function name (e.g. via the PHP magic __FUNCTION__ constant)
- * is recommended. For a function with multiple static variables add a
- * distinguishing suffix to the function name for each one.
- * @param $default_value
- * Optional default value.
- * @return $reset
- * TRUE to reset a specific named variable, or all variables if $name is NULL.
- * Resetting every variable should only be used, for example, for running unit
- * tests with a clean environment. Should be used only though via function
- * ctools_static_reset().
- */
-function &ctools_static($name, $default_value = NULL, $reset = FALSE) {
- static $data = array();
-
- // Reset a single value, or all values.
- if ($reset) {
- if (isset($name)) {
- unset($data[$name]);
- }
- else {
- $data = array();
- }
- // We must return a reference to a variable.
- $dummy = NULL;
- return $dummy;
- }
-
- if (!isset($data[$name])) {
- $data[$name] = $default_value;
- }
-
- return $data[$name];
-}
-
-/**
- * Reset one or all centrally stored static variable(s).
- * Modeled after Drupal 7's drupal_static_reset().
- *
- * @param $name
- * Name of the static variable to reset. Omit to reset all variables.
- */
-function ctools_static_reset($name) {
- ctools_static($name, NULL, TRUE);
-}
-
-/**
* Provide a hook passthrough to included files.
*
* To organize things neatly, each CTools tool gets its own toolname.$type.inc
@@ -174,9 +124,9 @@ function ctools_static_reset($name) {
* addition. It modifies the array by reference and doesn't need to return it.
*/
function _ctools_passthrough(&$items, $type = 'theme') {
- $files = drupal_system_listing('.' . $type . '.inc$', drupal_get_path('module', 'ctools') . '/includes', 'name', 0);
+ $files = drupal_system_listing('/\.' . $type . '\.inc$/', drupal_get_path('module', 'ctools') . '/includes', 'name', 0);
foreach ($files as $file) {
- require_once './' . $file->filename;
+ require_once DRUPAL_ROOT . '/' . $file->uri;
list($tool) = explode('.', $file->name, 2);
$function = 'ctools_' . $tool . '_' . $type;
@@ -186,6 +136,9 @@ function _ctools_passthrough(&$items, $type = 'theme') {
}
}
+/**
+ * Implementation of hook_theme_registry_alter()
+ */
function ctools_theme_registry_alter(&$registry) {
if ($registry['menu_local_tasks']['function'] == 'theme_menu_local_tasks') {
$registry['menu_local_tasks'] = array(
@@ -203,6 +156,7 @@ function ctools_theme_registry_alter(&$registry) {
) + $registry['help'];
}
+/*
// Handle a special override for garland because it's cute and does its own
// thing with tabs and we can't ask users to edit a core theme for us.
if ($registry['menu_local_tasks']['function'] == 'phptemplate_menu_local_tasks' &&
@@ -219,6 +173,7 @@ function ctools_theme_registry_alter(&$registry) {
$registry['page']['theme paths'][1] == 'themes/garland') {
$registry['page']['preprocess functions'][2] = 'ctools_garland_preprocess_page';
}
+*/
}
@@ -271,13 +226,8 @@ function ctools_ctools_plugin_directory($module, $plugin) {
function ctools_get_roles() {
static $roles = NULL;
if (!isset($roles)) {
- $roles = array();
- $result = db_query("SELECT r.rid, r.name FROM {role} r ORDER BY r.name");
- while ($obj = db_fetch_object($result)) {
- $roles[$obj->rid] = $obj->name;
- }
+ $roles = db_query('SELECT r.rid, r.name FROM {role} r ORDER BY r.name')->fetchAllKeyed();
}
-
return $roles;
}
@@ -325,8 +275,9 @@ function ctools_access_menu($access) {
* Implementation of hook_cron. Clean up old caches.
*/
function ctools_cron() {
- if (variable_get('ctools_last_cron', 0) < time() - 86400) {
- variable_set('ctools_last_cron', time());
+ // TODO: Should this use the passthrough?
+ if (variable_get('ctools_last_cron', 0) < REQUEST_TIME - 86400) {
+ variable_set('ctools_last_cron', REQUEST_TIME);
ctools_include('object-cache');
ctools_object_cache_clean();
}
@@ -392,6 +343,7 @@ function ctools_preprocess_node(&$vars) {
* Ensure the CTools CSS cache is flushed whenever hook_flush_caches is invoked.
*/
function ctools_flush_caches() {
+ // TODO: Should this use the passthrough mechanism?
ctools_include('css');
ctools_css_flush_caches();
}
diff --git includes/content.inc includes/content.inc
index 3523c26..81c0605 100644
--- includes/content.inc
+++ includes/content.inc
@@ -299,7 +299,7 @@ function ctools_content_render($type, $subtype, $conf, $keywords = array(), $arg
$url = $content->title_link;
}
// set defaults so we don't bring up notices
- $url += array('href' => '', 'attributes' => NULL, 'query' => NULL, 'fragment' => NULL, 'absolute' => NULL, 'html' => TRUE);
+ $url += array('href' => '', 'attributes' => array(), 'query' => array(), 'fragment' => '', 'absolute' => NULL, 'html' => TRUE);
$content->title = l($content->title, $url['href'], $url);
}
}
@@ -420,7 +420,7 @@ function ctools_content_admin_info($type, $subtype, $conf, $context = NULL) {
if (empty($output) || !is_object($output)) {
$output = new stdClass();
$output->title = t('No info');
- $output->content =t ('No info available.');
+ $output->content = t('No info available.');
}
return $output;
}
diff --git includes/content.menu.inc includes/content.menu.inc
index 7185779..40ab77c 100644
--- includes/content.menu.inc
+++ includes/content.menu.inc
@@ -31,20 +31,20 @@ function ctools_content_autocomplete_node($string) {
$match = preg_match('/^nid: (\d+)/', $string, $preg_matches);
}
if ($match) {
- $arg = $preg_matches[1];
- $where = "n.nid = %d";
+ $arg = array(':nid' => $preg_matches[1]);
+ $where = "n.nid = :nid";
}
else {
- $arg = $string;
- $where = "LOWER(n.title) LIKE LOWER('%%%s%%')";
+ $arg = array(':title' => '%' . $string . '%');
+ $where = "LOWER(n.title) LIKE LOWER(:title)";
}
- $result = db_query_range("SELECT n.nid, n.title, u.name FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE $where", $arg, 0, 10);
+ $result = db_query_range('SELECT n.nid, n.title, u.name FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE $where', 0, 10, $arg);
$matches = array();
- while ($node = db_fetch_object($result)) {
+ foreach ($result as $node) {
$name = empty($node->name) ? variable_get('anonymous', t('Anonymous')) : check_plain($node->name);
$matches[$node->title . " [nid: $node->nid]"] = '' . check_plain($node->title) . ' (' . t('by @user', array('@user' => $name)) . ')';
}
- drupal_json($matches);
+ drupal_json_output($matches);
}
}
diff --git includes/context-access-admin.inc includes/context-access-admin.inc
index c4fc9ca..a30edc1 100644
--- includes/context-access-admin.inc
+++ includes/context-access-admin.inc
@@ -113,7 +113,7 @@
/**
* Administrative form for access control.
*/
-function ctools_access_admin_form(&$form_state) {
+function ctools_access_admin_form($form, &$form_state) {
ctools_include('context');
$argument = isset($form_state['callback argument']) ? $form_state['callback argument'] : '';
$fragment = $form_state['module'];
@@ -387,7 +387,7 @@ function ctools_access_ajax_edit($fragment = NULL, $id = NULL) {
/**
* From to edit the settings of an access test.
*/
-function ctools_access_ajax_edit_item(&$form_state) {
+function ctools_access_ajax_edit_item($form, &$form_state) {
$test = &$form_state['test'];
$plugin = &$form_state['plugin'];
@@ -411,7 +411,7 @@ function ctools_access_ajax_edit_item(&$form_state) {
/**
* Validate handler for argument settings.
*/
-function ctools_access_ajax_edit_item_validate(&$form, &$form_state) {
+function ctools_access_ajax_edit_item_validate($form, &$form_state) {
if ($function = ctools_plugin_get_function($form_state['plugin'], 'settings form validate')) {
$function($form, $form_state);
}
@@ -420,7 +420,7 @@ function ctools_access_ajax_edit_item_validate(&$form, &$form_state) {
/**
* Submit handler for argument settings.
*/
-function ctools_access_ajax_edit_item_submit(&$form, &$form_state) {
+function ctools_access_ajax_edit_item_submit($form, &$form_state) {
if ($function = ctools_plugin_get_function($form_state['plugin'], 'settings form submit')) {
$function($form, $form_state);
}
diff --git includes/context-task-handler.inc includes/context-task-handler.inc
index 0cfe09e..27e7071 100644
--- includes/context-task-handler.inc
+++ includes/context-task-handler.inc
@@ -71,7 +71,7 @@ function ctools_context_handler_render($task, $subtask, $contexts, $args, $page
// such as a book.
if (menu_get_active_menu_name() == 'navigation') {
$item = menu_get_item();
- $mlink = db_fetch_object(db_query("SELECT * FROM {menu_links} WHERE link_path = '%s'", $item['href']));
+ $mlink = db_query('SELECT * FROM {menu_links} WHERE link_path = :path', array(':path' => $item['href']))->fetchObject();
if ($mlink && isset($mlink->menu_name)) {
menu_set_active_menu_name($mlink->menu_name);
diff --git includes/css.inc includes/css.inc
index 77a4276..150c263 100644
--- includes/css.inc
+++ includes/css.inc
@@ -67,16 +67,25 @@
* ctools_css_retrieve.
*/
function ctools_css_store($id, $css, $filter = TRUE) {
- $filename = db_result(db_query("SELECT filename FROM {ctools_css_cache} WHERE cid = '%s'", $id));
+ $filename = db_query('SELECT filename FROM {ctools_css_cache} WHERE cid = :cid', array(':cid' => $id))->fetchField();
if ($filename && file_exists($filename)) {
- file_delete($filename);
+ file_unmanaged_delete($filename);
}
// Remove any previous records.
- db_query("DELETE FROM {ctools_css_cache} WHERE cid = '%s'", $id);
+ db_delete('ctools_css_cache')
+ ->condition('cid', $id)
+ ->execute();
$filename = ctools_css_cache($css, $filter);
- db_query("INSERT INTO {ctools_css_cache} (cid, filename, css, filter) VALUES ('%s', '%s', '%s', %d)", $id, $filename, $css, $filter);
+ db_insert('ctools_css_cache')
+ ->fields(array(
+ 'cid' => $id,
+ 'filename' => $filename,
+ 'css' => $css,
+ 'filter' => $filter,
+ ))
+ ->execute();
return $filename;
}
@@ -87,7 +96,7 @@ function ctools_css_store($id, $css, $filter = TRUE) {
* This will ensure the file still exists and, if not, create it.
*/
function ctools_css_retrieve($id) {
- $cache = db_fetch_object(db_query("SELECT * FROM {ctools_css_cache} WHERE cid = '%s'", $id));
+ $cache = db_query('SELECT * FROM {ctools_css_cache} WHERE cid = :cid', array(':cid' => $id))->fetchObject();
if (!$cache) {
return;
}
@@ -95,7 +104,10 @@ function ctools_css_retrieve($id) {
if (!file_exists($cache->filename)) {
$filename = ctools_css_cache($cache->css, $cache->filter);
if ($filename != $cache->filename) {
- db_query("UPDATE {ctools_css_cache} SET filename = '%s' WHERE cid = '%s'", $filename, $id);
+ db_update('ctools_css_cache')
+ ->fields(array('filename' => $filename))
+ ->condition('cid', $id)
+ ->execute();
$cache->filename = $filename;
}
}
@@ -107,19 +119,18 @@ function ctools_css_retrieve($id) {
* Remove stored CSS and any associated file.
*/
function ctools_css_clear($id) {
- $cache = db_fetch_object(db_query("SELECT * FROM {ctools_css_cache} WHERE cid = '%s'", $id));
+ $cache = db_query('SELECT * FROM {ctools_css_cache} WHERE cid = :cid', array(':cid' => $id))->fetchObject();
if (!$cache) {
return;
}
if (file_exists($cache->filename)) {
- file_delete($cache->filename);
- // If we remove an existing file, there may be cached pages that refer
- // to it. We must get rid of them:
- cache_clear_all();
+ file_unmanaged_delete($cache->filename);
}
- db_query("DELETE FROM {ctools_css_cache} WHERE cid = '%s'", $id);
+ db_delete('ctools_css_cache')
+ ->condition('cid', $id)
+ ->execute();
}
@@ -150,15 +161,8 @@ function ctools_css_cache($css, $filter = TRUE) {
}
// Create the css/ within the files folder.
- $path = file_create_path('ctools/css');
- if (!file_check_directory($path)) {
- $path = file_directory_path() . '/ctools';
- file_check_directory($path, FILE_CREATE_DIRECTORY);
- $path .= '/css';
- file_check_directory($path, FILE_CREATE_DIRECTORY);
- }
-
- if (!file_check_directory($path)) {
+ $path = 'public://ctools/css';
+ if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
drupal_set_message(t('Unable to create CTools CSS cache directory. Check the permissions on your files directory.'), 'error');
return;
}
@@ -169,7 +173,7 @@ function ctools_css_cache($css, $filter = TRUE) {
// This will do renames if the file already exists, ensuring we don't
// accidentally overwrite other files who share the same md5. Yes this
// is a very miniscule chance but it's safe.
- $filename = file_save_data($css, $filename);
+ $filename = file_unmanaged_save_data($css, $filename);
return $filename;
}
@@ -541,6 +545,11 @@ function ctools_css_filter_default_allowed_values() {
* Delegated implementation of hook_flush_caches()
*/
function ctools_css_flush_caches() {
- file_scan_directory(file_create_path('ctools/css'), '.*', array('.', '..', 'CVS'), 'file_delete', TRUE);
- db_query("DELETE FROM {ctools_css_cache}");
+ // Remove all generated files.
+ // @see http://drupal.org/node/573292
+ // file_unmanaged_delete_recursive('public://render');
+ $filedir = file_directory_path('public') . '/ctools/css';
+ file_unmanaged_delete_recursive($filedir);
+
+ db_delete('ctools_css_cache')->execute();
}
diff --git includes/export.inc includes/export.inc
index a423abf..9bb4ad9 100644
--- includes/export.inc
+++ includes/export.inc
@@ -113,34 +113,27 @@ function ctools_export_load_object($table, $type = 'all', $args = array()) {
}
// Build the query
- $query = "SELECT * FROM {" . $table . "}";
+ $query = db_select($table);
$conditions = array();
$query_args = array();
// If they passed in names, add them to the query.
if ($type == 'names') {
- $conditions[] = "$export[key] IN (" . db_placeholders($args, $schema['fields'][$export['key']]['type']) . ")";
- $query_args = $args;
+ $query->condition($export['key'], $args, 'IN');
}
else if ($type == 'conditions') {
foreach ($args as $key => $value) {
if (isset($schema['fields'][$key])) {
- $conditions[] = "$key = " . db_type_placeholder($schema['fields'][$key]['type']);
- $query_args[] = $value;
+ $query->condition($key, $value);
}
}
}
- // Make a string out of the conditions.
- if ($conditions) {
- $query .= " WHERE " . implode(' AND ', $conditions);
- }
-
- $result = db_query($query, $query_args);
+ $result = $query->execute();
$status = variable_get($export['status'], array());
// Unpack the results of the query onto objects and cache them.
- while ($data = db_fetch_object($result)) {
+ foreach ($result as $data) {
$object = _ctools_export_unpack_object($schema, $data, $export['object']);
$object->table = $table;
$object->type = t('Normal');
@@ -333,7 +326,7 @@ function _ctools_export_get_defaults($table, $export) {
* @param $schema
* The schema from drupal_get_schema().
* @param $data
- * The data as loaded by db_fetch_object().
+ * The data as loaded from the database.
* @param $object
* If an object, data will be unpacked onto it. If a string
* an object of that type will be created.
@@ -350,7 +343,7 @@ function _ctools_export_unpack_object($schema, $data, $object = 'stdClass') {
// Go through our schema and build correlations.
foreach ($schema['fields'] as $field => $info) {
- $object->$field = empty($info['serialize']) ? $data->$field : unserialize(db_decode_blob($data->$field));
+ $object->$field = empty($info['serialize']) ? $data->$field : unserialize($data->$field);
}
return $object;
@@ -362,7 +355,7 @@ function _ctools_export_unpack_object($schema, $data, $object = 'stdClass') {
* @param $table
* The name of the table this object represents.
* @param $data
- * The data as loaded by db_fetch_object().
+ * The data as loaded from the database.
*/
function ctools_export_unpack_object($table, $data) {
$schema = ctools_export_get_schema($table);
diff --git includes/menu.inc includes/menu.inc
index dc11a3b..7806b23 100644
--- includes/menu.inc
+++ includes/menu.inc
@@ -145,32 +145,29 @@ function ctools_menu_tree_page_data($item, $menu_name = 'navigation') {
// Build and run the query, and build the tree.
if ($item['access']) {
// Check whether a menu link exists that corresponds to the current path.
- $args = array($menu_name, $item['href']);
- $placeholders = "'%s'";
+ $args = array($item['href']);
if (drupal_is_front_page()) {
$args[] = '';
- $placeholders .= ", '%s'";
}
- $parents = db_fetch_array(db_query("SELECT p1, p2, p3, p4, p5, p6, p7, p8 FROM {menu_links} WHERE menu_name = '%s' AND link_path IN (". $placeholders .")", $args));
+ $parents = db_query("SELECT p1, p2, p3, p4, p5, p6, p7, p8 FROM {menu_links} WHERE menu_name = :menu_name AND link_path IN (:href)", array(':menu_name' => $menu_name, ':href' => $args))->fetchAll(PDO::FETCH_ASSOC);
if (empty($parents)) {
// If no link exists, we may be on a local task that's not in the links.
// TODO: Handle the case like a local task on a specific node in the menu.
- $parents = db_fetch_array(db_query("SELECT p1, p2, p3, p4, p5, p6, p7, p8 FROM {menu_links} WHERE menu_name = '%s' AND link_path = '%s'", $menu_name, $item['tab_root']));
+ $parents = db_query("SELECT p1, p2, p3, p4, p5, p6, p7, p8 FROM {menu_links} WHERE menu_name = :menu_name AND link_path = :path", array(':menu_name' => $menu_name, ':path' => $item['tab_root']))->fetchAll(PDO::FETCH_ASSOC);
}
// We always want all the top-level links with plid == 0.
$parents[] = '0';
// Use array_values() so that the indices are numeric for array_merge().
$args = $parents = array_unique(array_values($parents));
- $placeholders = implode(', ', array_fill(0, count($args), '%d'));
$expanded = variable_get('menu_expanded', array());
// Check whether the current menu has any links set to be expanded.
if (in_array($menu_name, $expanded)) {
// Collect all the links set to be expanded, and then add all of
// their children to the list as well.
do {
- $result = db_query("SELECT mlid FROM {menu_links} WHERE menu_name = '%s' AND expanded = 1 AND has_children = 1 AND plid IN (". $placeholders .') AND mlid NOT IN ('. $placeholders .')', array_merge(array($menu_name), $args, $args));
+ $result = db_query('SELECT mlid FROM {menu_links} WHERE menu_name = :menu_name AND expanded = 1 AND has_children = 1 AND plid IN (:args) AND mlid NOT IN (:args)', array(':menu_name' => $menu_name, ':args' => $args))->fetchAll(PDO::FETCH_ASSOC);
$num_rows = FALSE;
while ($item = db_fetch_array($result)) {
$args[] = $item['mlid'];
diff --git includes/object-cache.inc includes/object-cache.inc
index 54a888a..13e4d98 100644
--- includes/object-cache.inc
+++ includes/object-cache.inc
@@ -35,9 +35,9 @@ function ctools_object_cache_get($obj, $name, $skip_cache = FALSE) {
}
if (!array_key_exists($key, $cache)) {
- $data = db_fetch_object(db_query("SELECT * FROM {ctools_object_cache} WHERE sid = '%s' AND obj = '%s' AND name = '%s'", session_id(), $obj, $name));
+ $data = db_query('SELECT * FROM {ctools_object_cache} WHERE sid = :session_id AND obj = :object AND name = :name', array(':session_id' => session_id(), ':object' => $obj, ':name' => $name))->fetchObject();
if ($data) {
- $cache[$key] = unserialize(db_decode_blob($data->data));
+ $cache[$key] = unserialize($data->data);
}
}
return isset($cache[$key]) ? $cache[$key] : NULL;
@@ -56,7 +56,15 @@ function ctools_object_cache_get($obj, $name, $skip_cache = FALSE) {
*/
function ctools_object_cache_set($obj, $name, $cache) {
ctools_object_cache_clear($obj, $name);
- db_query("INSERT INTO {ctools_object_cache} (sid, obj, name, data, updated) VALUES ('%s', '%s', '%s', %b, %d)", session_id(), $obj, $name, serialize($cache), REQUEST_TIME);
+ db_insert('ctools_object_cache')
+ ->fields(array(
+ 'sid' => session_id(),
+ 'obj' => $obj,
+ 'name' => $name,
+ 'data' => serialize($cache),
+ 'updated' => REQUEST_TIME,
+ ))
+ ->execute();
}
/**
@@ -69,7 +77,11 @@ function ctools_object_cache_set($obj, $name, $cache) {
* The name of the object being removed.
*/
function ctools_object_cache_clear($obj, $name) {
- db_query("DELETE FROM {ctools_object_cache} WHERE sid = '%s' AND obj = '%s' AND name = '%s'", session_id(), $obj, $name);
+ db_delete('ctools_object_cache')
+ ->condition('sid', session_id())
+ ->condition('obj', $obj)
+ ->condition('name', $name)
+ ->execute();
}
@@ -89,7 +101,7 @@ function ctools_object_cache_clear($obj, $name) {
* An object containing the UID and updated date if found; NULL if not.
*/
function ctools_object_cache_test($obj, $name) {
- return db_fetch_object(db_query("SELECT s.uid, c.updated FROM {ctools_object_cache} c INNER JOIN {sessions} s ON c.sid = s.sid WHERE s.sid != '%s' AND c.obj = '%s' AND c.name = '%s' ORDER BY c.updated ASC", session_id(), $obj, $name));
+ return db_query('SELECT s.uid, c.updated FROM {ctools_object_cache} c INNER JOIN {sessions} s ON c.sid = s.sid WHERE s.sid <> :session_id AND c.obj = :obj AND c.name = :name ORDER BY c.updated ASC', array(':session_id' => session_id(), ':obj' => $obj, ':name' => $name))->fetchObject();
}
/**
@@ -104,7 +116,10 @@ function ctools_object_cache_test($obj, $name) {
* The name of the object being removed.
*/
function ctools_object_cache_clear_all($obj, $name) {
- db_query("DELETE FROM {ctools_object_cache} WHERE obj = '%s' AND name = '%s'", $obj, $name);
+ db_delete('ctools_object_cache')
+ ->condition('obj', $obj)
+ ->condition('name', $name)
+ ->execute();
}
/**
@@ -119,5 +134,7 @@ function ctools_object_cache_clean($age = NULL) {
if (empty($age)) {
$age = 86400 * 7; // 7 days
}
- db_query("DELETE FROM {ctools_object_cache} WHERE updated < %d", REQUEST_TIME - $age);
+ db_delete('ctools_object_cache')
+ ->condition('updated', REQUEST_TIME - $age, '<')
+ ->execute();
}
diff --git includes/plugins.inc includes/plugins.inc
index ec61564..ab43cf1 100644
--- includes/plugins.inc
+++ includes/plugins.inc
@@ -232,7 +232,7 @@ function ctools_plugin_load_includes($info, $file = NULL) {
$extension = 'inc';
}
foreach ($directories as $module => $path) {
- $file_list[$module] = drupal_system_listing("$file." . $extension . '$', $path, 'name', 0);
+ $file_list[$module] = drupal_system_listing("/$file." . $extension . '$/', $path, 'name', 0);
}
$plugins = array();
@@ -246,12 +246,12 @@ function ctools_plugin_load_includes($info, $file = NULL) {
}
else {
// Parse a hook.
- require_once './' . $file->filename;
+ require_once DRUPAL_ROOT . '/' . $file->uri;
// .inc files have a special format for the hook identifier.
// For example, 'foo.inc' in the module 'mogul' using the plugin
// whose hook is named 'borg_type' should have a function named (deep breath)
// mogul_foo_borg_type()
- $result = ctools_plugin_process($info, $module, $module . '_' . $file->name, dirname($file->filename), basename($file->filename), $file->name);
+ $result = ctools_plugin_process($info, $module, $module . '_' . $file->name, dirname($file->uri), basename($file->uri), $file->name);
}
if (is_array($result)) {
$plugins = array_merge($plugins, $result);
@@ -449,7 +449,7 @@ function ctools_plugin_get_function($plugin, $function_name) {
// $plugin['file']. Don't try to run those.
$info = ctools_plugin_get_info($plugin['plugin module'], $plugin['plugin type']);
if (empty($info['info file'])) {
- require_once './' . $plugin['path'] . '/' . $plugin['file'];
+ require_once DRUPAL_ROOT . '/' . $plugin['path'] . '/' . $plugin['file'];
}
}
@@ -464,7 +464,7 @@ function ctools_plugin_get_function($plugin, $function_name) {
if (isset($plugin[$function_name]['path'])) {
$file = $plugin[$function_name]['path'] . '/' . $file;
}
- require_once './' . $file;
+ require_once DRUPAL_ROOT . '/' . $file;
}
}
else {
@@ -518,7 +518,7 @@ function ctools_plugin_get_class($plugin, $class_name) {
// $plugin['file']. Don't try to run those.
$info = ctools_plugin_get_info($plugin['plugin module'], $plugin['plugin type']);
if (empty($info['info file'])) {
- require_once './' . $plugin['path'] . '/' . $plugin['file'];
+ require_once DRUPAL_ROOT . '/' . $plugin['path'] . '/' . $plugin['file'];
}
}
@@ -537,13 +537,13 @@ function ctools_plugin_get_class($plugin, $class_name) {
if (isset($plugin[$class_name]['path'])) {
$file = $plugin[$class_name]['path'] . '/' . $file;
}
- require_once './' . $file;
+ require_once DRUPAL_ROOT . '/' . $file;
}
}
else {
$class = $plugin[$class_name];
}
-
+
// If we didn't explicitly include a file above, try autoloading a file
// based on the class' name.
if (!isset($file) && file_exists($plugin['path'] . "/$class.class.php")) {
diff --git page_manager/page_manager.install page_manager/page_manager.install
index 62ede6a..865b9b2 100644
--- page_manager/page_manager.install
+++ page_manager/page_manager.install
@@ -195,7 +195,10 @@ function page_manager_schema_1() {
* Implementation of hook_install().
*/
function page_manager_install() {
- db_query("UPDATE {system} SET weight = 99 WHERE name = 'page_manager'");
+ db_update('system')
+ ->fields(array('weight' => 99))
+ ->condition('name', 'page_manager')
+ ->execute();
}
function page_manager_update_6101() {
diff --git page_manager/page_manager.module page_manager/page_manager.module
index 8fe05eb..cb26295 100644
--- page_manager/page_manager.module
+++ page_manager/page_manager.module
@@ -443,8 +443,8 @@ function page_manager_load_task_handlers($task, $subtask_id = NULL, $default_han
$placeholders[] = "'%s'";
}
- $result = db_query("SELECT name, weight FROM {page_manager_weights} WHERE name IN (" . implode(', ', $placeholders) . ")", $names);
- while ($weight = db_fetch_object($result)) {
+ $result = db_query('SELECT name, weight FROM {page_manager_weights} WHERE name IN :names', array(':names' => $names));
+ foreach ($result as $weight) {
$handlers[$weight->name]->weight = $weight->weight;
}
}
@@ -568,7 +568,9 @@ function page_manager_save_task_handler(&$handler) {
}
drupal_write_record('page_manager_handlers', $handler, $update);
- db_query("DELETE FROM {page_manager_weights} WHERE name = '%s'", $handler->name);
+ db_delete('page_manager_weights')
+ ->condition('name', $handler->name)
+ ->execute();
// If this was previously a default handler, we may have to write task handlers.
if (!$update) {
@@ -585,8 +587,12 @@ function page_manager_delete_task_handler($handler) {
if ($function = ctools_plugin_load_function('page_manager', 'task_handlers', $handler->handler, 'delete')) {
$function($handler);
}
- db_query("DELETE FROM {page_manager_handlers} WHERE name = '%s'", $handler->name);
- db_query("DELETE FROM {page_manager_weights} WHERE name = '%s'", $handler->name);
+ db_delete('page_manager_handlers')
+ ->condition('name', $handler->name)
+ ->execute();
+ db_delete('page_manager_weights')
+ ->condition('name', $handler->name)
+ ->execute();
}
/**
@@ -654,8 +660,15 @@ function page_manager_new_task_handler($plugin) {
* to the database just because they have their weight changed.
*/
function page_manager_update_task_handler_weight($handler, $weight) {
- db_query("DELETE FROM {page_manager_weights} WHERE name = '%s'", $handler->name);
- db_query("INSERT INTO {page_manager_weights} (name, weight) VALUES ('%s', %d)", $handler->name, $weight);
+ db_delete('page_manager_weights')
+ ->condition('name', $handler->name)
+ ->execute();
+ db_insert('page_manager_weights')
+ ->fields(array(
+ 'name' => $handler->name,
+ 'weight' => $weight,
+ ))
+ ->execute();
}
@@ -1006,7 +1019,7 @@ function page_manager_menu_link_alter(&$item, $menu) {
}
else {
// Since we didn't already see an mlid, let's check the database for one.
- $mlid = db_result(db_query("SELECT mlid FROM {menu_links} WHERE router_path = '%s'", $item['parent_path']));
+ $mlid = db_query('SELECT mlid FROM {menu_links} WHERE router_path = :path', array('path' => $item['parent_path']))->fetchField();
if ($mlid) {
$item['plid'] = $mlid;
}
diff --git page_manager/plugins/tasks/page.admin.inc page_manager/plugins/tasks/page.admin.inc
index e33a83d..fe4bda6 100644
--- page_manager/plugins/tasks/page.admin.inc
+++ page_manager/plugins/tasks/page.admin.inc
@@ -516,8 +516,8 @@ function page_manager_page_form_basic_validate(&$form, &$form_state) {
// Check to see if something that isn't a page manager page is using the path.
$path = implode('/', $path);
- $result = db_query("SELECT * FROM {menu_router} WHERE path = '%s'", $path);
- while ($router = db_fetch_object($result)) {
+ $result = db_query('SELECT * FROM {menu_router} WHERE path = :path', array(':path' => $path));
+ foreach ($result as $router) {
if ($router->page_callback != 'page_manager_page_execute') {
form_error($form['path'], t('That path is already in used. This system cannot override existing paths.'));
}
@@ -525,8 +525,8 @@ function page_manager_page_form_basic_validate(&$form, &$form_state) {
// Ensure the path is not already an alias to something else.
if (strpos($path, '%') === FALSE) {
- $result = db_query("SELECT src, dst FROM {url_alias} WHERE dst = '%s'", $path);
- if ($alias = db_fetch_object($result)) {
+ $alias = db_query('SELECT src, dst FROM {url_alias} WHERE dst = :path', array(':path' => $path))->fetchObject();
+ if ($alias) {
form_error($form['path'], t('That path is currently assigned to be an alias for @alias. This system cannot override existing aliases.', array('@alias' => $alias->src)));
}
}
diff --git page_manager/plugins/tasks/page.inc page_manager/plugins/tasks/page.inc
index 6987adf..262d885 100644
--- page_manager/plugins/tasks/page.inc
+++ page_manager/plugins/tasks/page.inc
@@ -456,7 +456,9 @@ function page_manager_page_delete($page) {
page_manager_delete_task_handler($handler);
}
}
- db_query("DELETE FROM {page_manager_pages} WHERE name = '%s'", $page->name);
+ db_delete('page_manager_pages')
+ ->condition('name', $page->name)
+ ->execute();
// Check to see if this was the site frontpage. If so, reset the site
// frontpage to default.
diff --git plugins/content_types/block/block.inc plugins/content_types/block/block.inc
index f1b5cf5..0f1dc5f 100644
--- plugins/content_types/block/block.inc
+++ plugins/content_types/block/block.inc
@@ -75,7 +75,7 @@ function ctools_block_content_type_render($subtype, $conf) {
$block->delta = $delta;
if ($module == 'block' && empty($conf['override_title'])) {
- $block->subject = db_result(db_query("SELECT title FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'block', $delta));
+ $block->subject = db_query('SELECT title FROM {blocks} WHERE module = :module AND delta = :delta', array(':module' => 'block', ':delta' => $delta))->fetchField();
}
if (isset($block->subject)) {
@@ -106,9 +106,7 @@ function ctools_block_content_type_render($subtype, $conf) {
}
// Test for block visibility
-
- $result = db_query("SELECT title, pages, visibility FROM {blocks} WHERE module = '%s' AND delta = '%s'", $block->module, $block->delta);
- $block_visibility = db_fetch_object($result);
+ $block_visibility = db_query('SELECT title, pages, visibility FROM {blocks} WHERE module = :module AND delta = :delta', array(':module' => $block->module, ':delta' => $block->delta))->fetchObject();
if ($block->module == 'block') {
$block->title = $block_visibility->title;
diff --git plugins/content_types/node/node.inc plugins/content_types/node/node.inc
index 3a47183..2840226 100644
--- plugins/content_types/node/node.inc
+++ plugins/content_types/node/node.inc
@@ -166,10 +166,10 @@ function ctools_node_content_type_edit_form_validate(&$form, &$form_state) {
$nid = $preg_matches[1];
}
if (is_numeric($nid)) {
- $node = db_fetch_object(db_query("SELECT n.nid FROM {node} n WHERE n.nid = %d", $nid));
+ $node = db_query('SELECT nid FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
}
else {
- $node = db_fetch_object(db_query("SELECT n.nid FROM {node} n WHERE LOWER(n.title) = LOWER('%s')", $nid));
+ $node = db_query('SELECT nid FROM {node} WHERE LOWER(title) = LOWER(:title)', array(':title' => $nid))->fetchObject();
}
if ($node) {
$form_state['values']['nid'] = $node->nid;
diff --git plugins/content_types/node_context/node_comments.inc plugins/content_types/node_context/node_comments.inc
index b0916f9..b6345a2 100644
--- plugins/content_types/node_context/node_comments.inc
+++ plugins/content_types/node_context/node_comments.inc
@@ -96,41 +96,43 @@ function ctools_comment_render($node, $conf) {
$comments_per_page = $conf['comments_per_page'];
// Multiple comment view
- $query_count = 'SELECT COUNT(*) FROM {comments} WHERE nid = %d';
- $query = 'SELECT c.cid AS cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.thread, c.status, parent_user.uid as parent_uid, parent_user.data as parent_data, parent_user.name as parent_name, parent_user.picture as parent_picture FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid LEFT OUTER JOIN {comments} parent ON c.pid = parent.cid LEFT OUTER JOIN {users} parent_user ON parent.uid = parent_user.uid WHERE c.nid = %d';
+ $query = db_select('comment', 'c')->extend('PagerDefault');
+ $query->addField('c', 'cid');
+ $query
+ ->condition('c.nid', $node->nid)
+ ->addTag('node_access')
+ ->limit($comments_per_page);
+
+ $count_query = db_select('comment', 'c');
+ $count_query->addExpression('COUNT(*)');
+ $count_query
+ ->condition('c.nid', $node->nid)
+ ->addTag('node_access');
- $query_args = array($node->nid);
if (!user_access('administer comments')) {
- $query .= ' AND c.status = %d';
- $query_count .= ' AND status = %d';
- $query_args[] = COMMENT_PUBLISHED;
+ $query->condition('c.status', COMMENT_PUBLISHED);
+ $count_query->condition('c.status', COMMENT_PUBLISHED);
}
-
- if ($order == COMMENT_ORDER_NEWEST_FIRST) {
- if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
- $query .= ' ORDER BY c.timestamp DESC';
- }
- else {
- $query .= ' ORDER BY c.thread DESC';
- }
+ if ($mode === COMMENT_MODE_FLAT) {
+ $query->orderBy('c.cid', 'ASC');
}
- else if ($order == COMMENT_ORDER_OLDEST_FIRST) {
- if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {
- $query .= ' ORDER BY c.timestamp';
- }
- else {
- $query .= ' ORDER BY SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))';
- }
+ else {
+ // See comment above. Analysis reveals that this doesn't cost too
+ // much. It scales much much better than having the whole comment
+ // structure.
+ $query->orderBy('SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))', 'ASC');
}
- // Start a form, for use with comment control.
- $result = pager_query($query, $comments_per_page, 0, $query_count, $query_args);
+ $query->setCountQuery($count_query);
+ $cids = $query->execute()->fetchCol();
+
+ $comments = comment_load_multiple($cids);
$divs = 0;
$last_depth = 0;
drupal_add_css(drupal_get_path('module', 'comment') .'/comment.css');
- while ($comment = db_fetch_object($result)) {
- $comment = drupal_unpack($comment);
+ foreach ($comments as $comment) {
+ // @todo Not sure about what of this is still needed. 09/10/2009 sun
$comment->name = $comment->uid ? $comment->registered_name : $comment->name;
$comment->depth = count(explode('.', $comment->thread)) - 1;
diff --git plugins/content_types/term_context/term_list.inc plugins/content_types/term_context/term_list.inc
index bcd79f0..24f4964 100644
--- plugins/content_types/term_context/term_list.inc
+++ plugins/content_types/term_context/term_list.inc
@@ -40,7 +40,7 @@ function ctools_term_list_content_type_render($subtype, $conf, $panel_args, $con
break;
case 'sibling':
- $parent = db_result(db_query("SELECT parent FROM {taxonomy_term_hierarchy} WHERE tid = %d", $term->tid));
+ $parent = db_query('SELECT parent FROM {taxonomy_term_hierarchy} WHERE tid = :tid', array(':tid' => $term->tid))->fetchField();
$terms = taxonomy_get_children($parent, $term->vid);
// Remove the term that started this.
unset($terms[$term->tid]);
diff --git plugins/content_types/vocabulary_context/vocabulary_terms.inc plugins/content_types/vocabulary_context/vocabulary_terms.inc
index 8d679ac..509de09 100644
--- plugins/content_types/vocabulary_context/vocabulary_terms.inc
+++ plugins/content_types/vocabulary_context/vocabulary_terms.inc
@@ -52,11 +52,11 @@ function _ctools_content_vocabulary_terms($vid, $max_depth, $depth = -1, $tid =
return array();
}
$return = array();
- $query = db_query('SELECT t.name, t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d AND h.parent = %d ORDER BY t.weight ASC, t.name ASC', $vid, $tid);
- while ($result = db_fetch_object($query)) {
+ $result = db_query('SELECT t.name, t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} h ON t.tid = h.tid WHERE t.vid = :vid AND h.parent = :parent ORDER BY t.weight ASC, t.name ASC', array(':vid' => $vid, ':parent' => $tid));
+ foreach ($result as $term) {
$return[] = array(
- 'data' => l($result->name, 'taxonomy/term/'. $result->tid),
- 'children' => _ctools_content_vocabulary_terms($vid, $max_depth, $depth, $result->tid),
+ 'data' => l($term->name, 'taxonomy/term/'. $term->tid),
+ 'children' => _ctools_content_vocabulary_terms($vid, $max_depth, $depth, $term->tid),
);
}
return $return;
diff --git plugins/contexts/node.inc plugins/contexts/node.inc
index ba6d019..f92c242 100644
--- plugins/contexts/node.inc
+++ plugins/contexts/node.inc
@@ -12,7 +12,7 @@
* Implementation of specially named hook_ctools_contexts().
*/
function ctools_node_ctools_contexts() {
- return array(
+ $args['node'] = array(
'title' => t("Node"),
'description' => t('A node object.'),
'context' => 'ctools_context_create_node',
@@ -29,6 +29,7 @@ function ctools_node_ctools_contexts() {
'#description' => t('Enter the node ID of a node for this context.'),
),
);
+ return $args;
}
/**
@@ -86,7 +87,7 @@ function ctools_context_node_settings_form($conf) {
);
if (!empty($conf['nid'])) {
- $info = db_fetch_object(db_query("SELECT * FROM {node} n WHERE n.nid = %d", $conf['nid']));
+ $info = db_query('SELECT * FROM {node} WHERE nid = :nid', array(':nid' => $conf['nid']))->fetchObject();
if ($info) {
$link = l(t("'%title' [node id %nid]", array('%title' => $info->title, '%nid' => $info->nid)), "node/$info->nid", array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE));
$form['node']['#description'] = t('Currently set to !link', array('!link' => $link));
@@ -133,10 +134,10 @@ function ctools_context_node_settings_form_validate($form, &$form_values, &$form
$nid = $preg_matches[1];
}
if (is_numeric($nid)) {
- $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.nid = %d"), $nid));
+ $node = db_query('SELECT nid FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
}
else {
- $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE LOWER(n.title) = LOWER('%s')"), $nid));
+ $node = db_query('SELECT nid FROM {node} WHERE LOWER(title) = LOWER(:title)', array(':title' => $nid))->fetchObject();
}
if (!$node) {
diff --git plugins/contexts/node_edit_form.inc plugins/contexts/node_edit_form.inc
index fb07183..bd153b0 100644
--- plugins/contexts/node_edit_form.inc
+++ plugins/contexts/node_edit_form.inc
@@ -64,7 +64,7 @@ function ctools_context_create_node_edit_form($empty, $node = NULL, $conf = FALS
$form_state = array('want form' => TRUE, 'args' => array($node));
$file = drupal_get_path('module', 'node') . '/node.pages.inc';
- include_once './' . $file;
+ require_once DRUPAL_ROOT . '/' . $file;
// This piece of information can let other modules know that more files
// need to be included if this form is loaded from cache:
$form_state['form_load_files'] = array($file);
@@ -104,9 +104,9 @@ function ctools_context_node_edit_form_settings_form($conf) {
);
if (!empty($conf['nid'])) {
- $info = db_fetch_object(db_query("SELECT * FROM {node} n WHERE n.nid = %d", $conf['nid']));
+ $info = db_query('SELECT * FROM {node} WHERE nid = :nid', array(':nid' => $conf['nid']))->fetchObject();
if ($info) {
- $link = l(t("'%title' [node id %nid]", array('%title' => $info->title, '%nid' => $info->nid)), "node/$info->nid", array('attributes' => array('target' => '_blank', 'title' => t('Open in new window')), 'html' => TRUE));
+ $link = l(t("'%title' [node id %nid]", array('%title' => $info->title, '%nid' => $info->nid)), "node/$info->nid", array('target' => '_blank', 'title' => t('Open in new window')));
$form['node']['#description'] = t('Currently set to !link', array('!link' => $link));
}
}
@@ -151,10 +151,13 @@ function ctools_context_node_edit_form_settings_form_validate($form, &$form_valu
$nid = $preg_matches[1];
}
if (is_numeric($nid)) {
- $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.nid = %d"), $nid));
+ $node = db_query('SELECT nid FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
}
else {
- $node = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE LOWER(n.title) = LOWER('%s')"), $nid));
+ $node = db_query('SELECT nid FROM {node} WHERE LOWER(title) = LOWER(:title)', array(':title' => $nid))->fetchObject();
+ if ($node) {
+ form_set_value($form['nid'], $node->nid, $form_state);
+ }
}
if (!$node) {
diff --git plugins/contexts/term.inc plugins/contexts/term.inc
index 1349ac5..2ba7714 100644
--- plugins/contexts/term.inc
+++ plugins/contexts/term.inc
@@ -43,7 +43,7 @@ function ctools_context_create_term($empty, $data = NULL, $conf = FALSE) {
}
if ($conf && isset($data['tid'])) {
- $data = taxonomy_get_term($data['tid']);
+ $data = taxonomy_term_load($data['tid']);
}
if (!empty($data)) {
@@ -74,7 +74,7 @@ function ctools_context_term_settings_form($conf) {
$description = '';
if (!empty($conf['tid'])) {
- $info = db_fetch_object(db_query("SELECT * FROM {term_data} n WHERE n.tid = %d", $conf['tid']));
+ $info = db_query('SELECT * FROM {taxonomy_term_data} WHERE tid = :tid', array(':tid' => $conf['tid']))->fetchObject();
if ($info) {
$description = ' ' . t('Currently set to @term. Enter another term if you wish to change the term.', array('@term' => $info->name));
}
@@ -133,7 +133,7 @@ function ctools_context_term_settings_form_validate($form, &$form_values, &$form
return;
}
- $term = db_fetch_object(db_query("SELECT t.tid FROM {term_data} t WHERE LOWER(t.name) = LOWER('%s') AND t.vid = %d", $form_values['taxonomy'][$vid], $vid));
+ $term = db_query('SELECT tid FROM {taxonomy_term_data} WHERE LOWER(name) = LOWER(:name) AND t.vid = :vid', array(':name' => $form_values['taxonomy'][$vid], ':vid' => $vid))->fetchObject();
if (!$term) {
form_error($form['taxonomy'][$vid], t('Invalid term selected.'));
@@ -145,7 +145,7 @@ function ctools_context_term_settings_form_validate($form, &$form_values, &$form
function ctools_context_term_settings_form_submit($form, &$form_values, &$form_state) {
if ($form_values['set_identifier']) {
- $term = db_fetch_object(db_query("SELECT t.tid, t.name FROM {term_data} t WHERE LOWER(t.tid) = %d", $form_values['tid']));
+ $term = db_query('SELECT tid, name FROM {taxonomy_term_data} WHERE LOWER(tid) = :tid', array(':tid' => $form_values['tid']))->fetchObject();
$form_state['values']['context']['identifier'] = $term->name;
}
diff --git plugins/contexts/terms.inc plugins/contexts/terms.inc
index f698dc4..9424b4c 100644
--- plugins/contexts/terms.inc
+++ plugins/contexts/terms.inc
@@ -53,7 +53,7 @@ function ctools_context_create_terms($empty, $data = NULL, $conf = FALSE) {
if (!isset($data->term)) {
// load the first term:
reset($context->tids);
- $data->term = taxonomy_get_term(current($context->tids));
+ $data->term = taxonomy_term_load(current($context->tids));
}
$context->data = $data->term;
$context->title = $data->term->name;
@@ -80,8 +80,8 @@ function ctools_context_terms_convert($context, $type) {
$context->names = '';
}
else {
- $result = db_query("SELECT tid, name FROM {term_data} WHERE tid IN (" . db_placeholders($context->tids) . ")", $context->tids);
- while ($term = db_fetch_object($result)) {
+ $result = db_query('SELECT tid, name FROM {taxonomy_term_data} WHERE tid IN :tids', array(':tids' => $context->tids));
+ foreach ($result as $term) {
$names[$term->tid] = $term->name;
}
$context->names = implode($context->operator == 'or' ? ' + ' : ', ', $names);
diff --git plugins/relationships/book_parent.inc plugins/relationships/book_parent.inc
index edddb82..076f8bc 100644
--- plugins/relationships/book_parent.inc
+++ plugins/relationships/book_parent.inc
@@ -36,7 +36,7 @@ function ctools_book_parent_context($context, $conf) {
// Search through the book tree to load the top level.
$result = array('nid' => $context->data->nid, 'vid' => $context->data->vid, 'parent' => $context->data->parent);
while (!empty($result['parent'])) {
- $result = db_fetch_array(db_query("SELECT * FROM {book} b INNER JOIN {node} n ON b.vid = n.nid WHERE b.nid = %d", $result['parent']));
+ $result = db_query('SELECT * FROM {book} b INNER JOIN {node} n ON b.vid = n.nid WHERE b.nid = :nid', array(':nid' => $result['parent']))->fetchAssoc();
}
$nid = $result['nid'];
}
diff --git plugins/relationships/term_parent.inc plugins/relationships/term_parent.inc
index 8d13cb3..5be9d33 100644
--- plugins/relationships/term_parent.inc
+++ plugins/relationships/term_parent.inc
@@ -32,7 +32,7 @@ function ctools_term_parent_context($context, $conf) {
}
if (isset($context->data)) {
- $result = db_fetch_array(db_query("SELECT t1.* FROM {term_hierarchy} t1 INNER JOIN {term_hierarchy} t2 ON t1.tid = t2.parent WHERE t2.tid = %d", $context->data->tid));
+ $result = db_query('SELECT t1.* FROM {taxonomy_term_hierarchy} t1 INNER JOIN {taxonomy_term_hierarchy} t2 ON t1.tid = t2.parent WHERE t2.tid = :tid', array(':tid' => $context->data->tid))->fetchAssoc();
// If top level term, keep looking up until we see a top level.
if ($conf['type'] == 'top') {
@@ -42,13 +42,13 @@ function ctools_term_parent_context($context, $conf) {
$result['tid'] = $context->data->tid;
}
while (!empty($result['parent'])) {
- $result = db_fetch_array(db_query("SELECT * FROM {term_hierarchy} WHERE tid = %d", $result['parent']));
+ $result = db_query('SELECT * FROM {taxonomy_term_hierarchy} WHERE tid = :tid', array(':tid' => $result['parent']))->fetchAssoc();
}
}
// Load the term.
if ($result) {
- $term = taxonomy_get_term($result['tid']);
+ $term = taxonomy_term_load($result['tid']);
return ctools_context_create('term', $term);
}
}