[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: plugin_api.inc.php 1168 2006-04-29 13:06:11Z garvinhicking $ 2 # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team) 3 # All rights reserved. See LICENSE file for licensing details 4 5 if (IN_serendipity !== true) { 6 die ('Don\'t hack!'); 7 } 8 9 if (defined('S9Y_FRAMEWORK_PLUGIN_API_EXTENSION')) { 10 return; 11 } 12 @define('S9Y_FRAMEWORK_PLUGIN_API_EXTENSION', true); 13 14 class serendipity_plugin_api_extension extends serendipity_plugin_api 15 { 16 /** 17 * Prepare a given one dimension array for reordering 18 * 19 * @access public 20 * @author Falk Doering 21 * @param array the array 22 * @param string the key of the parent id 23 * @return array the final array with two new keys: 'up' and 'down' 24 */ 25 26 function prepareReorder($array, $parent_id = 'parent_id') 27 { 28 if (is_array($array)) { 29 for ($i = 0, $ii = count($array); $i < $ii; $i++) { 30 $array[$i]['down'] = (isset($array[$i]['down']) ? $array[$i]['down'] : false); 31 $array[$i]['up'] = (isset($array[$i]['up']) ? $array[$i]['up'] : false); 32 for ($j = ($i + 1); $j < $ii; $j++) { 33 if ($array[$j][$parent_id] == $array[$i][$parent_id]) { 34 $array[$i]['down'] = true; 35 $array[$j]['up'] = true; 36 } 37 } 38 } 39 return $array; 40 } 41 return $array; 42 } 43 44 /** 45 * Prepare a given one dimension array for deleting 46 * 47 * @access public 48 * @author Falk Doering 49 * @param array the array 50 * @param string the key of the main id 51 * @param string the key of the parent id 52 * @return array the final array with one new keys: 'delete' with true or false 53 */ 54 function prepareDelete($array, $this_id = 'id', $parent_id = 'parent_id') 55 { 56 global $serendipity; 57 58 if (is_array($array)) { 59 for ($i = 0, $ii = count($array); $i < $ii; $i++) { 60 if (isset($array[$i+1]) && ($array[$i+1][$parent_id] == $array[$i][$this_id])) { 61 $array[$i]['delete'] = false; 62 } else { 63 $array[$i]['delete'] = true; 64 } 65 } 66 } 67 return $array; 68 } 69 70 71 /** 72 * Update table for re-ordering 73 * 74 * @access public 75 * @author Falk Doering 76 * @param string Name of the table 77 * @param string The direction ('up' or 'down') 78 * @param array The update array 79 * @param array The array containing the where clause 80 * @return boolean 81 */ 82 83 function doReorder($table, $moveto, $update_array, $where_array) 84 { 85 global $serendipity; 86 87 if (is_array($update_array) && is_array($where_array)) { 88 $where = ''; 89 foreach ($where_array as $key => $value) { 90 if (strlen($where)) { 91 $where .= ' AND '; 92 } 93 $where .= $key . ' = ' . $value; 94 } 95 $q = 'SELECT '.implode(", ", array_keys($update_array)).' 96 FROM '. $serendipity['dbPrefix'] . $table .' 97 WHERE '.$where; 98 $old = serendipity_db_query($q, true, 'assoc'); 99 100 if (is_array($old)) { 101 $where = array(); 102 $update = array(); 103 switch ($moveto) { 104 case 'up': 105 foreach ($update_array as $key => $value) { 106 if ($value) { 107 $where[$key] = ($old[$key] - 1); 108 $update[$key] = $old[$key]; 109 $update_1[$key] = ($old[$key] - 1); 110 } else { 111 $where[$key] = $old[$key]; 112 } 113 } 114 break; 115 case 'down': 116 foreach ($update_array as $key => $value) { 117 if ($value) { 118 $where[$key] = ($old[$key] + 1); 119 $update[$key] = $old[$key]; 120 $update_1[$key] = ($old[$key] + 1); 121 } else { 122 $where[$key] = $old[$key]; 123 } 124 } 125 break; 126 default: 127 return false; 128 } 129 serendipity_db_update($table, $where, $update); 130 serendipity_db_update($table, $where_array, $update_1); 131 return true; 132 } 133 } 134 return false; 135 } 136 137 /** 138 * 139 * Check if a string is a valid email 140 * 141 * @access public 142 * @author Falk Doering 143 * @param string The email string 144 * @return bool is valid email true, else false 145 * 146 */ 147 148 function isEmail($email) 149 { 150 $preg = '/^[a-zA-Z0-9](([_\.-][a-zA-Z0-9]+)*)@([a-zA-Z0-9]+)(([\.-]?[a-zA-Z0-9]+)*)\.([a-zA-Z]{2,6})|localhost$/'; 151 return (preg_match($preg, $email) != 0); 152 } 153 154 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |