Skip to content

Instantly share code, notes, and snippets.

View wojtha's full-sized avatar

Vojtěch Kusý wojtha

View GitHub Profile
@wojtha
wojtha / Drupal_6_fragments_in_menu_links_module.php
Created November 21, 2010 04:29
Use MYMODULE_theme_registry_alter for overriding theme_menu_item_link(). This is needed only when fragment is saved as a part of the link_path (not in the 'options' array).
@wojtha
wojtha / drupal_recreate_table.php
Created April 9, 2011 20:22
Snippet how to recreate table using Drupal Schema API
<?php
$module = 'my_module';
$table = 'my_table';
$ret = array();
db_drop_table($ret, $table);
$schema = drupal_get_schema_unprocessed($module);
db_create_table($ret, $table, $schema[$table]);
dpm($ret); // print return values - queries and success state
@wojtha
wojtha / change_db_prefix.php
Created April 11, 2011 14:43
Change Drupal DB table prefixes in a dirty way using Page with PHP filter
<form action="" method="get">
Old prefix: <input type="text" name="old" /> <br />
New prefix: <input type="text" name="new" /> <br />
<input type="submit" value="Rename" />
</form>
<?php
global $db_prefix;
if ($old = $_REQUEST['old'] || $new = $_REQUEST['new']) {
@wojtha
wojtha / drupal_form_state_redirect.php
Created May 1, 2011 17:33
Advanced Drupal $form_state['redirect']
function mymodule_wizard_submit($form, &$form_state) {
$wizard = $form_state['values']['wizard'];
// $form_state['redirect'] = lazy drupal_goto, has the same parameters
$path = trim(parse_url($form['#action'], PHP_URL_PATH), '/');
$query = array('sender' => $wizard['sender'], 'recipient' => $wizard['recipient']);
$form_state['redirect'] = array($path, $query);
}
@wojtha
wojtha / gist:969769
Created May 13, 2011 01:04
Replace non-existent files with empty file using Drupal {file} table.
// REPLACE?
$replace = FALSE;
// path to empty file
$source = 'files/empty.png';
// RUN
$result = db_query('SELECT fid, filename, filepath FROM {files}');
$src = file_create_path($source);
$src_exists = file_exists($src);
$i = 1;
Ok!
If you (like me) are wondering what's up with there being 3 separate OpenID critical issues between D8 and D7 and what on earth it all means, and more importantly how to fix it, you're in luck! wojtha kindly spent about an hour with me in IRC today walking me through the state of things.
Here's the skinny:
There are two main issues where core's OpenID module is violating spec, and this leads to consequences ranging from certain OpenID providers just plain not working to possible impersonation risks:
[#575810]: When you enter an OpenID provider like "webchick.openid.com", Drupal normalize it into a fully-qualified domain for you, like "http://webchick.openid.com", sets it as a user Claimed Ideintifier and sends a request to that URL to retrieve supported services from the provider and that kind of stuff. The problem is that all public providers (and probably all of the providers around the world) redirects "http://webchick.openid.com" to more secure https://webchick.openid.com or sometimes to completel
@wojtha
wojtha / drupal_array_merge.php
Created May 31, 2011 20:10
Drupal Array Merge - copied from swftools_array_merge().
<?php
/**
* Merges two multi-dimensional arrays.
*
* Taken from http://drupalcontrib.org/api/search/6/swftools_array_merge
*
* This function is used by players that filter their settings to strip out
* blanks or defaults. For the admin page we need a full set of values to prevent
* errors. Since the arrays might be multi-dimensional we cannot use a regular
* array_merge(). The values in the first array will be over-written by values in
@wojtha
wojtha / drupal_missing_files.php
Created June 13, 2011 22:18
Drupal snippet - report missing files
<?php
$purge = FALSE;
$result = db_query('SELECT fid, filename, filepath FROM {files}');
$i = 1;
$out = "MISSING FILES:\n";
while ($f = db_fetch_object($result)) {
$dest = file_create_path($f->filepath);
if (!file_exists($dest)) {
@wojtha
wojtha / gist:1034017
Created June 19, 2011 09:40
Git pre-commit hook for PHP syntax validation using Msysgit Bash
#!/bin/sh
php_syntax_check()
{
retval=0
for i in $(git diff-index --name-only --cached HEAD -- | grep -E '\.(php|engine|theme|install|inc|module|test)$'); do
if [ -f $i ]; then
output=$(/c/progra~2/zend/zendserver/bin/php.exe -l $i)
if [ "$output" == "No syntax errors detected in $i" ];
then
@wojtha
wojtha / gitutils.ps1
Created June 19, 2011 10:16 — forked from markembling/gitutils.ps1
Powershell functions for git information
# Git functions
# Mark Embling (http://www.markembling.info/)
# Is the current directory a git repository/working copy?
function isCurrentDirectoryGitRepository {
if ((Test-Path ".git") -eq $TRUE) {
return $TRUE
}
# Test within parent dirs