Skip to content

Instantly share code, notes, and snippets.

@krschmidt
krschmidt / field-conversion.sql
Created March 24, 2018 06:22
Converting Drupal 7 field types
update field_config set type='text_long' where field_name='field_a' or field_name='field_b';
alter table field_data_field_a modify field_a_value longtext;
alter table field_data_field_b modify field_b_value longtext;
alter table field_revision_field_a modify field_a_value longtext;
alter table field_revision_field_b modify field_b_value longtext;
# adjust 4096 to your length, and change s to match the number of characters in the length.
update field_config set data=replace(data, 'a:1:{s:10:"max_length";s:4:"4096";}', 'a:0:{}') where field_name='field_a' or field_name='field_b';
update field_config_instance set data=replace(data,'s:14:"text_textfield";','s:13:"text_textarea";') where field_name='field_a' or field_name='field_b';
# adjust 60 to the edit field length, and change s to match the number of characters in that field length
update field_config_instance set data=replace(data,'s:4:"size";s:2:"60";','s:4:"rows";s:1:"5";') where field_name='field_a' or field_name='field_b';
@krschmidt
krschmidt / if no jquery.html
Created May 19, 2017 15:39
klcc-responsive
<script src="//static.lanecc.net/js/jquery-2.1.4.min.js"></script>
@krschmidt
krschmidt / klcc.html
Created May 19, 2017 15:26
KLCC Video Embed
<iframe src="https://www.lanecc.edu/custom/signvideo.php?player=laneccstream" width="600" height="350"></iframe>
@krschmidt
krschmidt / source.html
Last active May 19, 2017 19:10
Foundationg Giving fund setter
<script>
setTimeout(function() {
$.urlParam = function(name, url) {
if (!url) {
url = window.location.href;
}
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(url);
if (!results) {
return undefined;
}
@krschmidt
krschmidt / occurances.sql
Created January 10, 2017 16:41
Counts occurances of non-breaking spaces in the body field of a Drupal site
SELECT f.entity_id,
f.bundle,
Sum(f.counts) c
FROM (SELECT entity_id,
bundle,
Format((Length(body_value) - Length(REPLACE(body_value, '&nbsp;', ''))) / Length('&nbsp;'), 0) AS counts
FROM field_data_body) AS f
GROUP BY f.entity_id
ORDER BY c ASC;
@krschmidt
krschmidt / activeusers.sql
Created January 3, 2017 22:43
Find Drupal users with the most revisions over a period of time
SELECT c.count,
users.name
FROM (SELECT Count(*) count,
uid
FROM node_revision
WHERE From_unixtime(timestamp) > Date_sub(Curdate(), INTERVAL 2 month)
GROUP BY uid) c,
users
WHERE c.uid = users.uid
ORDER BY count;
function makeNumbers(s){
return parseInt(s.replace(/^\D+/g, ""));
}
if(jQuery(".wordlimit").length > 0){
jQuery('.form-submit').prop('disabled', true);
jQuery('.wordlimit').before("<div class='wordcount-status'>Wordcount: <span class='wc-count'>0</span></div>");
jQuery('.wordlimit').on('keyup blur', function(){
var limits = jQuery(this).attr('class').match(/wordlimit-([0-9]+)/g);
@krschmidt
krschmidt / head.html
Last active July 12, 2024 10:40
Set Canonical URL via Javascript
<script type='text/javascript'>
var link = !!document.querySelector("link[rel='canonical']") ? document.querySelector("link[rel='canonical']") : document.createElement('link');
link.setAttribute('rel', 'canonical');
link.setAttribute('href', location.protocol + '//' + location.host + location.pathname);
document.head.appendChild(link);
</script>
@krschmidt
krschmidt / text-search.php
Created November 19, 2015 05:10
Drupal Text Search
<?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();
@krschmidt
krschmidt / recent.py
Created November 7, 2015 23:33
Login Nag
#!/usr/bin/python
import MySQLdb
import smtplib
import re
import os
# list of users to exclude by usernames
exclusions = []
# DB stuff