Created
November 19, 2015 05:10
-
-
Save krschmidt/214bb766b51c05c700ec to your computer and use it in GitHub Desktop.
Drupal Text Search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('DRUPAL_ROOT', $_SERVER['DOCUMENT_ROOT']); | |
$base_url = 'http://'.$_SERVER['HTTP_HOST']; | |
require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); | |
global $user; | |
if (!in_array('administrator', array_values($user->roles)) && !in_array('Admin Lite', array_values($user->roles))) { | |
echo "You do not have sufficient permissions to view this page. <a href='/user'>Log in</a>, or verify that you have an administrative role"; | |
die(); | |
} | |
?> | |
<html> | |
<head> | |
<title>Quick Text Search</title> | |
<style> | |
td { | |
border-top: black solid 1px; | |
padding: 2px; | |
} | |
</style> | |
</head> | |
<body> | |
<?php | |
if (!empty($_GET['q'])){ | |
echo "<table cellspacing=0>"; | |
$result = db_query("SELECT entity_id FROM {field_data_body} WHERE body_value like :q", array(':q' => "%". db_like($_GET['q']) . "%")); | |
foreach ($result as $record){ | |
echo "<tr><td>Node</td><td><a href='/node/{$record->entity_id}'>{$record->entity_id}</a></td></tr>"; | |
} | |
$result = db_query("SELECT menu_name FROM {menu_links} WHERE link_path like :q", array(':q' => "%". db_like($_GET['q']) . "%")); | |
foreach ($result as $record){ | |
echo "<tr><td>Menu</td><td>{$record->menu_name}</td></tr>"; | |
} | |
echo "</table>"; | |
if ($result->rowCount() == 0){ | |
echo "<p>No results found</p>"; | |
} | |
} | |
?> | |
<br> | |
<p>To search for links to a node, enter "node/number", where number is the node number you're looking for.</p> | |
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="get"> | |
<label for="q">Search for a Node: <input type="text" name="q"></label> | |
<input type="submit"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment