Skip to content
<?php
function file_devel_generate($object, $field, $instance, $bundle) {
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
return devel_generate_multiple('_file_devel_generate', $object, $field, $instance, $bundle);
}
else {
return _file_devel_generate($object, $field, $instance, $bundle);
}
}
function _file_devel_generate($object, $field, $instance, $bundle) {
static $file;
if (empty($file)) {
if ($path = devel_generate_textfile()) {
$source->uri = $path;
$source->uid = 1; // TODO: randomize? use case specific.
$source->filemime = 'text/plain';
$destination = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'] . '/' . basename($path);
$file = file_move($source, $destination);
}
else {
return FALSE;
}
}
$object_field['fid'] = $file->fid;
$object_field['display'] = $field['settings']['display_default'];
$object_field['description'] = devel_create_greeking(10);
return $object_field;
}
/**
* Private function for generating a random text file.
*/
function devel_generate_textfile($filesize = 1024) {
if ($tmp_file = drupal_tempnam('temporary://', 'filefield_')) {
$destination = $tmp_file . '.txt';
file_unmanaged_move($tmp_file, $destination);
$fp = fopen($destination, 'w');
fwrite($fp, str_repeat('01', $filesize/2));
fclose($fp);
return $destination;
}
}
<?php
define('DEVEL_GENERATE_IMAGE_MAX', 5);
function image_devel_generate($object, $field, $instance, $bundle) {
if (function_exists('imagejpeg')) {
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
return devel_generate_multiple('_image_devel_generate', $object, $field, $instance, $bundle);
}
else {
return _image_devel_generate($object, $field, $instance, $bundle);
}
}
}
function _image_devel_generate($object, $field, $instance, $bundle) {
$object_field = array();
static $images = array();
$min_resolution = empty($instance['settings']['min_resolution']) ? '100x100' : $instance['settings']['min_resolution'];
$max_resolution = empty($instance['settings']['max_resolution']) ? '600x600' : $instance['settings']['max_resolution'];
$extensions = array_intersect(explode(' ', $instance['settings']['file_extensions']), array('png', 'jpg'));
$extension = array_rand(drupal_map_assoc($extensions));
// Generate a max of 5 different images.
if (!isset($images[$extension][$min_resolution][$max_resolution]) || count($images[$extension][$min_resolution][$max_resolution]) <= DEVEL_GENERATE_IMAGE_MAX) {
if ($path = devel_generate_image($extension, $min_resolution, $max_resolution)) {
$source = new stdClass();
$source->uri = $path;
$source->uid = 1; // TODO: randomize? Use case specific.
$source->filemime = 'image/' . pathinfo($path, PATHINFO_EXTENSION);
$destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
$destination = $destination_dir . '/' . basename($path);
$file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
$images[$extension][$min_resolution][$max_resolution][$file->fid] = $file;
}
else {
return FALSE;
}
}
else {
// Select one of the images we've already generated for this field.
$file = new stdClass();
$file->fid = array_rand($images[$extension][$min_resolution][$max_resolution]);
}
$object_field['fid'] = $file->fid;
$object_field['alt'] = devel_create_greeking(4);
$object_field['title'] = devel_create_greeking(4);
return $object_field;
}
/**
* Private function for creating a random image.
*
* This function only works with the GD toolkit. ImageMagick is not supported.
*/
function devel_generate_image($extension = 'png', $min_resolution, $max_resolution) {
if ($tmp_file = drupal_tempnam('temporary://', 'imagefield_')) {
$destination = $tmp_file . '.' . $extension;
file_unmanaged_move($tmp_file, $destination, FILE_CREATE_DIRECTORY);
$min = explode('x', $min_resolution);
$max = explode('x', $max_resolution);
$width = rand((int)$min[0], (int)$max[0]);
$height = rand((int)$min[0], (int)$max[0]);
// Make a image split into 4 sections with random colors.
$im = imagecreate($width, $height);
for ($n = 0; $n < 4; $n++) {
$color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
$x = $width/2 * ($n % 2);
$y = $height/2 * (int) ($n >= 2);
imagefilledrectangle($im, $x, $y, $x + $width/2, $y + $height/2, $color);
}
// Make a perfect circle in the image middle.
$color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
$smaller_dimension = min($width, $height);
$smaller_dimension = ($smaller_dimension % 2) ? $smaller_dimension : $smaller_dimension;
imageellipse($im, $width/2, $height/2, $smaller_dimension, $smaller_dimension, $color);
$save_function = 'image'. ($extension == 'jpg' ? 'jpeg' : $extension);
$save_function($im, drupal_realpath($destination));
$images[$extension][$min_resolution][$max_resolution][$destination] = $destination;
}
return $destination;
}
<?php
// Id$
function list_devel_generate($object, $field, $instance, $bundle) {
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
return devel_generate_multiple('_list_devel_generate', $object, $field, $instance, $bundle);
}
else {
return _list_devel_generate($object, $field, $instance, $bundle);
}
}
function _list_devel_generate($object, $field, $instance, $bundle) {
$object_field = array();
if ($allowed_values = list_allowed_values($field)) {
$keys = array_keys($allowed_values);
$object_field['value'] = $keys[mt_rand(0, count($allowed_values) - 1)];
}
return $object_field;
}
<?php
// Id$
function number_devel_generate($object, $field, $instance, $bundle) {
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
return devel_generate_multiple('_number_devel_generate', $object, $field, $instance, $bundle);
}
else {
return _number_devel_generate($object, $field, $instance, $bundle);
}
}
function _number_devel_generate($object, $field, $instance, $bundle) {
$object_field = array();
// Make sure the instance settings are all set.
foreach (array('min', 'max', 'precision', 'scale') as $key) {
if (empty($instance['settings'][$key])) {
$instance['settings'][$key] = NULL;
}
}
$min = is_numeric($instance['settings']['min']) ? $instance['settings']['min'] : 0;
switch ($field['type']) {
case 'number_integer':
$max = is_numeric($instance['settings']['max']) ? $instance['settings']['max'] : 10000;
$decimal = 0;
$scale = 0;
break;
case 'number_decimal':
$precision = is_numeric($instance['settings']['precision']) ? $instance['settings']['precision'] : 10;
$scale = is_numeric($instance['settings']['scale']) ? $instance['settings']['scale'] : 2;
$max = is_numeric($instance['settings']['max']) ? $instance['settings']['max'] : pow(10, ($precision - $scale));
$decimal = rand(0, (10 * $scale)) / 100;
break;
case 'number_float':
$precision = rand(10, 32);
$scale = rand(0, 2);
$decimal = rand(0, (10 * $scale)) / 100;
$max = is_numeric($instance['settings']['max']) ? $instance['settings']['max'] : pow(10, ($precision - $scale));
break;
}
$object_field['value'] = round((rand($min, $max) + $decimal), $scale);
return $object_field;
}
<?php
function taxonomy_devel_generate($object, $field, $instance, $bundle) {
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
return devel_generate_multiple('_taxonomy_devel_generate', $object, $field, $instance, $bundle);
}
else {
return _taxonomy_devel_generate($object, $field, $instance, $bundle);
}
}
function _taxonomy_devel_generate($object, $field, $instance, $bundle) {
$object_field = array();
// TODO: For free tagging vocabularies that do not already have terms, this
// will not result in any tags being added.
$machine_name = $field['settings']['allowed_values'][0]['vocabulary'];
$vocabulary = taxonomy_vocabulary_machine_name_load($machine_name);
if ($max = db_query('SELECT MAX(tid) FROM {taxonomy_term_data} WHERE vid = :vid', array(':vid' => $vocabulary->vid))->fetchField()) {
$candidate = mt_rand(1, $max);
$query = db_select('taxonomy_term_data', 't');
$tid = $query
->fields('t', array('tid'))
->condition('t.vid', $vocabulary->vid, '=')
->condition('t.tid', $candidate, '>=')
->range(0,1)
->execute()
->fetchField();
// If there are no terms for the taxonomy, the query will fail, in which
// case we return NULL.
if ($tid === FALSE) {
return NULL;
}
$object_field['tid'] = (int) $tid;
return $object_field;
}
}
<?php
function text_devel_generate($object, $field, $instance, $bundle) {
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
return devel_generate_multiple('_text_devel_generate', $object, $field, $instance, $bundle);
}
else {
return _text_devel_generate($object, $field, $instance, $bundle);
}
}
function _text_devel_generate($object, $field, $instance, $bundle) {
$object_field = array();
if (!empty($instance['settings']['text_processing'])) {
$formats = filter_formats();
$format = array_rand($formats);
}
else {
$format = filter_fallback_format();
}
if ($instance['widget']['type'] != 'text_textfield') {
// Textarea handling
$object_field['value'] = devel_create_content($format);
if ($instance['widget']['type'] == 'text_textarea_with_summary' && !empty($instance['display_summary'])) {
$object_field['summary'] = devel_create_content($format);
}
}
else {
// Textfield handling.
// Generate a value that respects max_length.
if (empty($field['settings']['max_length'])) {
$field['settings']['max_length'] = 12;
}
$object_field['value'] = user_password($field['settings']['max_length']);
}
$object_field['format'] = $format;
return $object_field;
}
<?php
/**
* @file
* Hook provided by the Devel Node Access module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Explain your records in the {node_access} table.
*
* In order to help developers and administrators understand the forces
* that control access to any given node, the DNA module provides the
* Devel Node Access block, which lists all the grant records in the
* {node_access} table for that node.
*
* However, every Node Access module is free in how it defines and uses the
* 'realm' and 'gid' fields in its records in the {node_access} table, and
* it's often difficult to interpret them. This hook passes each record
* that DNA wants to display, and the owning module is expected to return
* an explanation of that record.
*
* The explanation should not be localized (not be passed through t()), so
* that administrators seeking help can present English explanations.
*
* @param $row
* The record from the {node_access} table, as object. The member fields are:
* nid, gid, realm, grant_view, grant_update, grant_delete.
*
* @return
* A string with a (short!) explanation of the given {node_access} row,
* to be displayed in DNA's 'Devel Node Access' block. It will be displayed
* as HTML; any variable parts must already be sanitized.
*
* @see hook_node_access_records()
* @see devel_node_access_node_access_explain()
*
* @ingroup node_access
*/
function hook_node_access_explain($row) {
if ($row->realm == 'mymodule_myrealm') {
if ($row->grant_view) {
$role = user_role_load($row->gid);
return 'Role ' . drupal_placeholder($role->name) . ' may view this node.';
}
else {
return 'No access.';
}
}
}
/**
* Acknowledge ownership of 'alien' grant records.
*
* Some node access modules store grant records directly into the {node_access}
* table rather than returning them through hook_node_access_records(). This
* practice is not recommended and DNA will flag all such records as 'alien'.
*
* If this is unavoidable, a module can confess to being the owner of these
* grant records, so that DNA can properly attribute them.
*
* @see hook_node_access_records()
*
* @ingroup node_access
*/
function hook_node_access_acknowledge($grant) {
if ($grant['realm'] == 'mymodule_all' && $grant['nid'] == 0) {
return TRUE;
}
}
/**
* @} End of "addtogroup hooks".
*/
name = Devel node access
description = Developer blocks and page illustrating relevant node_access records.
package = Development
dependencies[] = menu
core = 7.x
configure = admin/config/development/devel
tags[] = developer
<?php
/**
* Implements hook_uninstall().
*/
function devel_node_access_uninstall() {
variable_del('devel_node_access_debug_mode');
if (!module_exists('devel') && ($devel_menu = menu_load('devel'))) {
// Delete the development menu.
menu_delete($devel_menu);
}
}
This diff is collapsed.
This diff is collapsed.
------------------------------------------------------------------------------
SETUP: How to install Krumo ?
------------------------------------------------------------------------------
In order to use Krumo you have to put it on your (development) server, and
include it in your script. You can put it somewhere in the INCLUDE_PATH, or
specify the full path to the "class.krumo.php" file.
You have to modify the "krumo.ini" file too. It is the configuration file for
Krumo. The first option is choosing a skin:
[skin]
selected = "orange"
The value for this setting has to be the name of one of the sub-folders from the
"Krumo/skins/" folder. If the value provided for the skin results in not finding
the skin, the `default` skin will be used instead.
The second option is used to set the correct web path to the folder where Krumo
is installed. This is used in order to make the images from Krumo's CSS skins
web-accessible.
[css]
url = "http://www.example.com/Krumo/"
So far those two are the only configuration options.
All the CSS files ("skin.css") from the "Krumo/skins/" sub-folders must have the
proper permissions in order to be readable from Krumo. Same applies for
"krumo.ini" and "krumo.js" files.
\ No newline at end of file
This diff is collapsed.
=============================================================================
Krumo
version 0.2.1a
=============================================================================
You probably got this package from...
http://www.sourceforge.net/projects/krumo/
If there is no licence agreement with this package please download
a version from the location above. You must read and accept that
licence to use this software. The file is titled simply LICENSE.
OVERVIEW
------------------------------------------------------------------------------
To put it simply, Krumo is a replacement for print_r() and var_dump(). By
definition Krumo is a debugging tool (for PHP5), which displays structured
information about any PHP variable.
A lot of developers use print_r() and var_dump() in the means of debugging
tools. Although they were intended to present human readble information about a
variable, we can all agree that in general they are not. Krumo is an
alternative: it does the same job, but it presents the information beautified
using CSS and DHTML.
EXAMPLES
------------------------------------------------------------------------------
Here's a basic example, which will return a report on the array variable passed
as argument to it:
krumo(array('a1'=> 'A1', 3, 'red'));
You can dump simultaneously more then one variable - here's another example:
krumo($_SERVER, $_REQUEST);
You probably saw from the examples above that some of the nodes are expandable,
so if you want to inspect the nested information, click on them and they will
expand; if you do not need that information shown simply click again on it to
collapse it. Here's an example to test this:
$x1->x2->x3->x4->x5->x6->x7->x8->x9 = 'X10';
krumo($x1);
The krumo() is the only standalone function from the package, and this is
because basic dumps about variables (like print_r() or var_dump()) are the most
common tasks such functionality is used for. The rest of the functionality can
be called using static calls to the Krumo class. Here are several more examples:
// print a debug backgrace
krumo::backtrace();
// print all the included(or required) files
krumo::includes();
// print all the included functions
krumo::functions();
// print all the declared classes
krumo::classes();
// print all the defined constants
krumo::defines();
... and so on, etc.
A full PHPDocumenter API documentation exists both in this package and at the
project's website.
INSTALL
------------------------------------------------------------------------------
Read the INSTALL file.
DOCUMENTATION
------------------------------------------------------------------------------
As I said, a full PHPDocumenter API documentation can be found both in this
package and at the project's website.
SKINS
------------------------------------------------------------------------------
There are several skins pre-installed with this package, but if you wish you can
create skins of your own. The skins are simply CSS files that are prepended to
the result that Krumo prints. If you want to use images in your CSS (for
background, list-style, etc), you have to put "%URL%" in front of the image URL
in order hook it up to the skin folder and make the image web-accessible.
Here's an example:
ul.krumo-first {background: url(%url%bg.gif);}
TODO
------------------------------------------------------------------------------
You can find the list of stuff that is going to be added to this project in the
TODO file from this very package.
CONTRIBUTION
-----------------------------------------------------------------------------
If you download and use and possibly even extend this tool, please let us know.
Any feedback, even bad, is always welcome and your suggestions are going to be
considered for our next release. Please use our SourceForge page for that:
http://www.sourceforge.net/projects/krumo/
******************************************************************************
Krumo: TODO
******************************************************************************
BUGS
----------------
- watch the SourceForge.net Bug Tracker
Features: PHP
----------------
- Try to detect anonymous (lambda) functions
- Try to detect whether an array is indexed or associated
- Add var_export support for arrays and objects
- Add JSON support for arrays and objects
Features: GUI
----------------
- Nicer and friendlier skin(s)
- Add top-level links for collapsing and expanding the whole tree
- Add object & array -level links for collapsing and expanding all the
nested nodes
- Print all parent classes for the rendered objects
\ No newline at end of file
0.2.1a
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<html>
<head>
<title>Krumo</title>
<link rel="stylesheet" href="media/stylesheet.css" />
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
</head>
<body>
<div align="center"><h1>Krumo</h1></div>
<b>Welcome to Krumo!</b><br />
<br />
This documentation was generated by <a href="http://www.phpdoc.org">phpDocumentor v1.4.0a2</a><br />
</body>
</html>
\ No newline at end of file