/[drupal]/contributions/modules/project_issue_file_review/pifr.module
ViewVC logotype

Contents of /contributions/modules/project_issue_file_review/pifr.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.63 - (show annotations) (download) (as text)
Fri Oct 9 23:14:42 2009 UTC (6 weeks, 4 days ago) by boombatower
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-7--1
Changes since 1.62: +37 -1 lines
File MIME type: text/x-php
#522858: Abstract review API and re-implement SimpleTest review.
1 <?php
2 // $Id: pifr.module,v 1.62 2009/07/09 01:39:47 boombatower Exp $
3 /**
4 * @file
5 * Automatically review patches attached to issues.
6 *
7 * Copyright 2008-2009 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
8 */
9
10 /*
11 * Variables loaded as constants.
12 */
13 define('PIFR_ACTIVE', variable_get('pifr_active', FALSE));
14 define('PIFR_DEBUG', variable_get('pifr_debug', FALSE) || module_exists('simpletest'));
15
16 /*
17 * XML-RPC response codes.
18 */
19 define('PIFR_RESPONSE_ACCEPTED', 1);
20 define('PIFR_RESPONSE_INVALID_SERVER', 2);
21 define('PIFR_RESPONSE_DENIED', 3);
22
23 module_load_include('inc', 'pifr', 'pifr.file');
24 module_load_include('inc', 'pifr', 'pifr.server');
25 module_load_include('inc', 'pifr', 'pifr.log');
26
27 /**
28 * Implementation of hook_menu().
29 */
30 function pifr_menu() {
31 $items = array();
32
33 $items['admin/pifr'] = array(
34 'title' => 'PIFR management',
35 'description' => 'Manage PIFR configuration and clients.',
36 'page callback' => 'drupal_get_form',
37 'page arguments' => array('pifr_admin_dashboard_form'),
38 'access arguments' => array('pifr administer'),
39 'file' => 'pifr.admin.inc',
40 );
41 $items['admin/pifr/configuration'] = array(
42 'title' => 'Configuration',
43 'description' => 'Configure PIFR options.',
44 'page callback' => 'drupal_get_form',
45 'page arguments' => array('pifr_admin_configuration_form'),
46 'access arguments' => array('pifr administer'),
47 'file' => 'pifr.admin.inc',
48 );
49
50 return $items;
51 }
52
53 /**
54 * Implementation of hook_perm().
55 */
56 function pifr_perm() {
57 return array(
58 'pifr administer'
59 );
60 }
61
62 /**
63 * Implementation of hook_theme().
64 */
65 function pifr_theme() {
66 return array(
67 'pifr_state' => array(
68 'arguments' => array('enabled' => FALSE, 'severity' => 'error'),
69 'file' => 'pifr.admin.inc'
70 ),
71 );
72 }
73
74 /**
75 * Get the response from the code.
76 *
77 * @param integer $response_code Response code.
78 * @return string Representation of reponse code.
79 */
80 function pifr_response_code($response_code) {
81 switch ($response_code) {
82 case PIFR_RESPONSE_ACCEPTED:
83 return t('Accepted');
84 case PIFR_RESPONSE_INVALID_SERVER:
85 return t('Invalid server (client key may have been disabled)');
86 case PIFR_RESPONSE_DENIED:
87 return t('Denied');
88 default:
89 return 'Unknown';
90 }
91 }
92
93 /**
94 * Output debug message via watchdog when enabled.
95 *
96 * @param string $message Debug message.
97 */
98 function pifr_debug($message) {
99 if (PIFR_DEBUG) {
100 watchdog('pifr_debug', $message);
101 }
102 }
103
104 /*
105 * Provide PHP 5.3.0 array_replace_recursive().
106 */
107 if (!function_exists('array_replace_recursive')) {
108 function recurse($array, $array1) {
109 foreach ($array1 as $key => $value) {
110 // Create new key in $array, if it is empty or not an array.
111 if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key]))) {
112 $array[$key] = array();
113 }
114
115 // overwrite the value in the base array
116 if (is_array($value)) {
117 $value = recurse($array[$key], $value);
118 }
119 $array[$key] = $value;
120 }
121 return $array;
122 }
123
124 function array_replace_recursive($array, $array1) {
125 // handle the arguments, merge one by one
126 $args = func_get_args();
127 $array = $args[0];
128 if (!is_array($array)) {
129 return $array;
130 }
131 for ($i = 1; $i < count($args); $i++) {
132 if (is_array($args[$i])) {
133 $array = recurse($array, $args[$i]);
134 }
135 }
136 return $array;
137 }
138 }

  ViewVC Help
Powered by ViewVC 1.1.2