Skip to content

Instantly share code, notes, and snippets.

View vincenzo's full-sized avatar

Vinnie Russo vincenzo

  • Italy
View GitHub Profile
@vincenzo
vincenzo / gist:2043295
Created March 15, 2012 09:42
Programmatic CCK Content Type Updated - Step 2
<?php
$content['type'] = array(
'name' => 'Example CCK Content',
'type' => 'example_cck_content',
// ... cut code ...
$content['fields'] = array(
0 =>
array(
'label' => 'Box Image',
@vincenzo
vincenzo / gist:2043544
Created March 15, 2012 10:38
Programmatic CCK Content Type Updated - Step 3
<?php
function _example_cck_content_cck_export() {
// code of the exported content type goes here
return $content;
}
@vincenzo
vincenzo / gist:2043602
Created March 15, 2012 10:49
Programmatic CCK Content Type Updated - Step 4
<?php
function _example_cck_content_save_cck_node() {
module_load_include('inc', 'example_cck_content', 'example_cck_content.def');
$content = _example_cck_content_cck_export();
// we do not want too many modules enabled - the content_copy and
// alternate_content_copy modules are just needed in order to install the
// content type, so we just require them here (require_once prevent to
// include it more than once in case it is already enabled)
@vincenzo
vincenzo / gist:2043645
Created March 15, 2012 11:01
Programmatic CCK Content Type Updated - Step 5
<?php
/**
* Implementation of hook_install
*/
function example_cck_content_install() {
_example_cck_content_save_cck_node();
}
@vincenzo
vincenzo / gist:2043687
Created March 15, 2012 11:09
Programmatic CCK Content Type Updated - Step 6 - part 1
; $Id$
name = Example CCK Content
description = Provide an example CCK content type
dependencies[] = content
dependencies[] = filefield
dependencies[] = imagefield
dependencies[] = text
core = 6.x
@vincenzo
vincenzo / gist:2043713
Created March 15, 2012 11:16
Programmatic CCK Content Type Updated - Step 6 - part 2
<?php
/**
* Implementation of hook_requirements()
*/
function example_cck_content_requirements($phase) {
$requirements = array();
$t = get_t();
// an array of the dependencies
@vincenzo
vincenzo / gist:2053654
Created March 16, 2012 23:47
Programmatic CCK Content Type - Step 4
<?php
function _example_cck_content_save_cck_node($op = 'install') {
module_load_include('inc', 'example_cck_content', 'example_cck_content.def');
$content = _example_cck_content_cck_export();
// we do not want too many modules enabled - the content_copy module is just needed
// in order to install the content type, so we just require it here (require_once prevent to
// include it more than once in case it is already enabled)
require_once './' . drupal_get_path('module', 'content') . '/modules/content_copy/content_copy.module';
@vincenzo
vincenzo / correct.php
Last active October 1, 2015 20:58
Soundex - Correct and Train
<?php
function correct($word, $dic) {
if (array_key_exists($word, $dic)) {
return $word;
}
$search_result = $dic[soundex($word)];
foreach ($search_result as $key => &$res) {
@vincenzo
vincenzo / Match dependencies
Created January 12, 2013 23:30
Ok, Drupal. Imagine that, for whatever reason, you have a profile with a number of dependencies and you have to make sure you have all the modules in your codebase that match those dependencies. Here is a possible bash command to list modules that are not found. Fairly sure one can do better, but this was written on the fly and worked. Gotta lov…
cat yourprofile.info | grep "dependencies\[]" | cut -d "=" -f 2 | while read MODULE; do echo "${MODULE}: $(find /var/www/yoursite -iname ${MODULE}.module | wc -l)"; done | sort | grep ": 0" | cut -d ":" -f 1
@vincenzo
vincenzo / book-table.sql
Last active December 22, 2015 14:19
DRUPAL - Retrieve all nodes that were children in a Book and whose root parent was of a specific node type
mlid int(10) unsigned NO PRI 0
nid int(10) unsigned NO UNI 0
bid int(10) unsigned NO MUL 0