1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 12:48:24 +01:00

date convert: added generic string to timestamp converter (toTime()); admin UI: textareas autoexpand now available sitewide (back-end), multi table JOIN support, field (db table) aliases support, user auto-complete search should work fine now, example usage added on faqs administration

This commit is contained in:
secretr 2009-11-10 19:13:07 +00:00
parent 735734ebf4
commit 890bd0db44
9 changed files with 483 additions and 188 deletions

View File

@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_admin/comment.php,v $
| $Revision: 1.17 $
| $Date: 2009-11-09 16:54:30 $
| $Revision: 1.18 $
| $Date: 2009-11-10 19:13:07 $
| $Author: secretr $
+----------------------------------------------------------------------------+
*/
@ -65,7 +65,7 @@ class comments_admin_ui extends e_admin_ui
* @var array [optional]
*/
protected $tableJoin = array (
'user' => array('leftField' => 'comment_author_id', 'rightField' => 'user_id', 'fields' => '*'/*, 'leftTable' => '', 'joinType' => 'LEFT JOIN', 'whereJoin' => '', 'where' => ''*/)
'u.user' => array('leftField' => 'comment_author_id', 'rightField' => 'user_id', 'fields' => '*'/*, 'leftTable' => '', 'joinType' => 'LEFT JOIN', 'whereJoin' => 'AND u.user_ban=0', 'where' => ''*/)
);
//protected $listQry = "SELECT SQL_CALC_FOUND_ROWS * FROM #comments"; // without any Order or Limit.
@ -85,7 +85,7 @@ class comments_admin_ui extends e_admin_ui
'comment_comment' => array('title'=> "comment", 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name
'comment_author_id' => array('title'=> "authorID", 'type' => 'user', 'data' => 'int', 'width' => 'auto'), // User id
'comment_author_name' => array('title'=> "authorName", 'type' => 'text', 'width' => 'auto'), // User name
'user_name' => array('title'=> "System user", 'type' => 'text', 'width' => 'auto', 'table' => 'user', 'noedit' => true), // User name
'u.user_name' => array('title'=> "System user", 'type' => 'text', 'width' => 'auto', 'noedit' => true), // User name
'comment_datestamp' => array('title'=> "datestamp", 'type' => 'datestamp', 'width' => 'auto'), // User date
'comment_blocked' => array('title'=> "blocked", 'type' => 'boolean', 'data'=> 'int', 'thclass' => 'center', 'class'=>'center', 'filter' => true, 'batch' => true, 'width' => 'auto'), // Photo
'comment_ip' => array('title'=> "IP", 'type' => 'ip', 'width' => '10%', 'thclass' => 'center' ), // Real name (no real vetting)

View File

@ -8,8 +8,8 @@
* e107 Admin Helper
*
* $Source: /cvs_backup/e107_0.8/e107_files/jslib/core/admin.js,v $
* $Revision: 1.22 $
* $Date: 2009-11-09 16:55:41 $
* $Revision: 1.23 $
* $Date: 2009-11-10 19:13:07 $
* $Author: secretr $
*
*/
@ -63,6 +63,14 @@ e107Admin.Helper = {
var msg = el.readAttribute('delmsg') || e107.getModLan('delete_confirm');
if( !e107Helper.confirm(msg) ) e.stop();
});
element.select('textarea.e-autoheight').each( function (textarea) {
var options = {}, autoopt = '__' + textarea.name + 'autoheight_opt', autooptel = textarea.next('input[name=' + autoopt + ']');
if(autooptel) {
options['max_length'] = parseInt(autooptel.value);
}
new e107Admin.Nicearea(textarea, options);
});
},
/**

View File

@ -1885,6 +1885,7 @@ class e_admin_ui extends e_admin_controller_ui
protected $tableJoin;
protected $editQry;
protected $table;
protected $tableAlias;
protected $pid;
protected $pluginTitle;
@ -1935,7 +1936,7 @@ class e_admin_ui extends e_admin_controller_ui
$this->fieldpref = $ufieldpref;
}
$this->addTitle($this->pluginTitle, true);
$this->addTitle($this->pluginTitle, true)->parseAliases();
}
/**
@ -2050,17 +2051,7 @@ class e_admin_ui extends e_admin_controller_ui
function EditHeader()
{
// TODO - make it part of e_from::textarea/bbarea(), invoke it on className (not all textarea elements)
e107::getJs()->requireCoreLib('core/admin.js')
->footerInline("
\$\$('textarea').each(function(textarea) {
//auto options
var options = {}, autoopt = '__' + textarea.name + '_opt', autooptel = textarea.next('input[name=autoopt]');
if(autooptel) {
options['max_length'] = parseInt(autooptel.value);
}
new e107Admin.Nicearea(textarea, options);
});
");
e107::getJs()->requireCoreLib('core/admin.js');
}
/**
@ -2121,17 +2112,7 @@ class e_admin_ui extends e_admin_controller_ui
function CreateHeader()
{
// TODO - make it part of e_from::textarea/bbarea(), invoke it on className (not all textarea elements)
e107::getJs()->requireCoreLib('core/admin.js')
->footerInline("
\$\$('textarea').each(function(textarea) {
//auto options
var options = {}, autoopt = '__' + textarea.name + '_opt', autooptel = textarea.next('input[name=autoopt]');
if(autooptel) {
options['max_length'] = parseInt(autooptel.value);
}
new e107Admin.Nicearea(textarea, options);
});
");
e107::getJs()->requireCoreLib('core/admin.js');
}
/**
@ -2241,6 +2222,79 @@ class e_admin_ui extends e_admin_controller_ui
}
}
protected function parseAliases()
{
// parse table
if(strpos($this->table, '.') !== false)
{
$tmp = explode('.', $this->table, 2);
$this->table = $tmp[1];
$this->tableAlias = $tmp[0];
unset($tmp);
}
if($this->tableJoin)
{
foreach ($this->tableJoin as $table => $att)
{
if(strpos($table, '.') !== false)
{
$tmp = explode('.', $table, 2);
unset($this->tableJoin[$table]);
$att['alias'] = $tmp[0];
$att['table'] = $tmp[1];
$att['__tablePath'] = $att['alias'].'.';
$att['__tableFrom'] = '`#'.$att['table'].'` AS '.$att['alias'];
$this->tableJoin[$att['alias']] = $att;
unset($tmp);
continue;
}
$this->tableJoin[$table]['table'] = $table;
$this->tableJoin[$table]['alias'] = '';
$this->tableJoin[$table]['__tablePath'] = '`#'.$this->tableJoin[$table]['table'].'`.';
$this->tableJoin[$table]['__tableFrom'] = '`#'.$this->tableJoin[$table]['table'].'`';
}
}
// check for table aliases
$fields = array(); // preserve order
foreach ($this->fields as $field => $att)
{
if(strpos($field, '.') !== false)
{
$tmp = explode('.', $field, 2);
$att['alias'] = $tmp[0];
$fields[$tmp[1]] = $att;
$field = $tmp[1];
unset($tmp);
}
else
{
$att['alias'] = $this->tableAlias;
$fields[$field] = $att;
}
if($fields[$field]['alias'])
{
if($fields[$field]['alias'] == $this->tableAlias)
{
$fields[$field]['__tableField'] = $this->tableAlias.'.'.$field;
}
else
{
$fields[$field]['__tableField'] = $this->tableJoin[$fields[$field]['alias']]['__tablePath'].$field;
}
}
else
{
$fields[$field]['__tableField'] = '`#'.$this->table.'`.'.$field;
}
}
$this->fields = $fields;
return $this;
}
/**
* Take approproate action after successfull submit
*
@ -2303,7 +2357,7 @@ class e_admin_ui extends e_admin_controller_ui
{
$data[$key] = e107::getInstance()->ipEncode($data[$key]);
}
var_dump($data[$key]);
break;
//more to come
}
}
@ -2314,6 +2368,15 @@ class e_admin_ui extends e_admin_controller_ui
$searchQry = array();
$request = $this->getRequest();
$tp = e107::getParser();
$tablePath = '`#'.$this->table.'`.';
$tableFrom = '`#'.$this->table.'`';
$tableSFields = '`#'.$this->table.'`.*';
if($this->tableAlias)
{
$tablePath = $this->tableAlias.'.';
$tableFrom = '`#'.$this->table.'` AS '.$this->tableAlias;
$tableSFields = ''.$this->tableAlias.'.*';
}
$searchQuery = $tp->toDB($request->getQuery('searchquery', ''));
list($filterField, $filterValue) = $tp->toDB(explode('__', $request->getQuery('filter_options', '')));
@ -2321,49 +2384,45 @@ class e_admin_ui extends e_admin_controller_ui
// TODO - we have var types in current model, use them!
if($filterField && $filterValue !== '' && isset($this->fields[$filterField]))
{
$ftable = vartrue($this->fields[$filterField]['table'], $this->getTableName());
$searchQry[] = "`#{$ftable}`.`$filterField` = '".$filterValue."'";
$searchQry[] = $this->fields[$filterField]['__tableField']." = '".$filterValue."'";
}
$filter = array();
foreach($this->fields as $key=>$var)
{
$ftable = vartrue($var['table'], $this->getTableName());
if(($var['type'] == 'text' || $var['type'] == 'method') && $searchQuery)
{
$filter[] = "(`#{$ftable}`.`".$key."` REGEXP ('".$searchQuery."'))";
//$ftable = vartrue($var['alias'], '#'.$this->getTableName());
$filter[] = $var['__tableField']."` REGEXP ('".$searchQuery."'))";
}
}
//$qry = $this->listQry;
// We dont need list qry anymore!
$jwhere = array();
$joins = array();
if($this->tableJoin)
{
$qry = "SELECT `#".$this->getTableName()."`.*";
$qry = "SELECT SQL_CALC_FOUND_ROWS ".$tableSFields;
foreach ($this->tableJoin as $jtable => $tparams)
{
// Select fields
$fields = vartrue($tparams['fields']);
if('*' === $fields)
{
$qry .= ", `#{$jtable}`.*";
$qry .= ", {$tparams['__tablePath']}*";
}
else
{
$fields = array_map('trim', explode(',', $fields));
foreach ($fields as $field)
{
$qry .= ", `#{$jtable}`.`{$field}`";
$qry .= ", {$tparams['__tablePath']}`{$field}`";
}
}
// Prepare Joins
$joins[] = "
".vartrue($tparams['joinType'], 'LEFT JOIN')." `#{$jtable}` ON `#".vartrue($tparams['leftTable'], $this->getTableName())."`.`".vartrue($tparams['leftField'])."` = `#{$jtable}`.`".vartrue($tparams['rightField'])."`".(vartrue($tparams['whereJoin']) ? ' '.$tparams['whereJoin'] : '');
".vartrue($tparams['joinType'], 'LEFT JOIN')." {$tparams['__tableFrom']} ON ".(vartrue($tparams['leftTable']) ? $tparams['leftTable'].'.' : $tablePath)."`".vartrue($tparams['leftField'])."` = {$tparams['__tablePath']}`".vartrue($tparams['rightField'])."`".(vartrue($tparams['whereJoin']) ? ' '.$tparams['whereJoin'] : '');
// Prepare Where
if(vartrue($tparams['where']))
@ -2373,7 +2432,7 @@ class e_admin_ui extends e_admin_controller_ui
}
//From
$qry .= " FROM `#".$this->getTableName()."`";
$qry .= " FROM ".$tableFrom;
// Joins
if(count($joins) > 0)
@ -2383,7 +2442,7 @@ class e_admin_ui extends e_admin_controller_ui
}
else
{
$qry = "SELECT `#".$this->getTableName()."`.* FROM `#".$this->getTableName()."`";
$qry = $this->listQry ? $this->listQry : "SELECT SQL_CALC_FOUND_ROWS ".$tableSFields." FROM ".$tableFrom;
}
// join where
@ -2406,9 +2465,8 @@ class e_admin_ui extends e_admin_controller_ui
$orderField = $request->getQuery('field', $this->getPrimaryName());
if(isset($this->fields[$orderField]))
{
$ftable = vartrue($this->fields[$orderField]['table'], $this->getTableName());
// no need of sanitize - it's found in field array
$qry .= ' ORDER BY `#'.$ftable.'`.`'.$orderField.'` '.($request->getQuery('asc') == 'desc' ? 'DESC' : 'ASC');
$qry .= ' ORDER BY '.$this->fields[$orderField]['__tableField'].' '.($request->getQuery('asc') == 'desc' ? 'DESC' : 'ASC');
}
if($this->getPerPage())
@ -2417,6 +2475,7 @@ class e_admin_ui extends e_admin_controller_ui
//$startfrom = ($from-1) * intval($this->getPerPage());
$qry .= ' LIMIT '.$from.', '.intval($this->getPerPage());
}
return $qry;
}
@ -2446,9 +2505,16 @@ class e_admin_ui extends e_admin_controller_ui
return $this->pluginTitle;
}
public function getTableName()
public function getTableName($alias = false, $prefix = false)
{
return $this->table;
if($alias && $this->tableAlias) return $this->tableAlias;
return ($prefix ? '#.' : '').$this->table;
}
public function getJoinTable($alias = false, $prefix = false)
{
if($alias && $this->tableAlias) return $this->tableAlias;
return ($prefix ? '#.' : '').$this->table;
}
public function getBatchDelete()
@ -2568,11 +2634,10 @@ class e_admin_ui extends e_admin_controller_ui
$this->dataFields = array();
foreach ($this->fields as $key => $att)
{
if(null === $att['type'] || vartrue($att['noedit']) || !vartrue($att['data']))
if(null !== $att['type'] && !vartrue($att['noedit']))
{
continue;
$this->dataFields[$key] = vartrue($att['data'], 'str');
}
$this->dataFields[$key] = $att['data'];
}
}
// TODO - do it in one loop, or better - separate method(s) -> convertFields(validate), convertFields(data),...
@ -2589,10 +2654,10 @@ class e_admin_ui extends e_admin_controller_ui
{
$this->validationRules[$key] = array((true === $att['validate'] ? 'required' : $att['validate']), varset($att['rule']), $att['title'], varset($att['error'], $att['help']));
}
elseif(vartrue($att['check']))
/*elseif(vartrue($att['check'])) could go?
{
$this->checkRules[$key] = array($att['check'], varset($att['rule']), $att['title'], varset($att['error'], $att['help']));
}
}*/
}
}
@ -2681,7 +2746,8 @@ class e_admin_form_ui extends e_form
// protect current methods from conflict.
$this->preventConflict();
// user constructor
$this->init();
}
protected function preventConflict()
@ -2930,7 +2996,8 @@ class e_admin_form_ui extends e_form
case 'method':
$method = $key;
$list = call_user_func_array(array($this, $method), array('', $type));
$list = call_user_func_array(array($this, $method), array('', $type, $parms));
if(is_array($list))
{
//check for single option
@ -3209,17 +3276,18 @@ class e_admin_ui_dummy extends e_form
* 1. move abstract peaces of code to the proper classes
* 2. remove duplicated code (e_form & e_admin_form_ui), refactoring
* 3. make JS Manager handle Styles (.css files and inline CSS)
* 4. e_form is missing some methods used in e_admin_form_ui
* 5. date convert needs string-to-datestamp auto parsing, strptime() is the solution but needs support for
* 4. [DONE] e_form is missing some methods used in e_admin_form_ui
* 5. [DONE] date convert needs string-to-datestamp auto parsing, strptime() is the solution but needs support for
* Windows and PHP < 5.1.0 - build custom strptime() function (php_compatibility_handler.php) on this -
* http://sauron.lionel.free.fr/?page=php_lib_strptime (bad license so no copy/paste is allowed!)
* 6. [DONE - read/writeParms introduced ] $fields[parms] mess - fix it, separate list/edit mode parms somehow
* 7. clean up/document all object vars (e_admin_ui, e_admin_dispatcher)
* 8. clean up/document all parameters (get/setParm()) in controller and model classes
* 8. [DONE hopefully] clean up/document all parameters (get/setParm()) in controller and model classes
* 9. [DONE] 'ip' field type - convert to human readable format while showing/editing record
* 10. draggable ordering (list view)
* 11. realtime search filter (typing text) - like downloads currently
* 12. autosubmit when 'filter' dropdown is changed (quick fix?)
* 13. tablerender captions
* 14. [ALMOST - see Edit/CreateHeader() comments] textareas auto-height
* 14. [DONE] textareas auto-height
* 15. [DONE] multi JOIN table support (optional), aliases
*/

View File

@ -7,8 +7,8 @@
* GNU General Public License (http://gnu.org).
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/date_handler.php,v $
* $Revision: 1.10 $
* $Date: 2009-11-04 17:29:26 $
* $Revision: 1.11 $
* $Date: 2009-11-10 19:13:06 $
* $Author: secretr $
*
*/
@ -61,10 +61,48 @@ class convert
return strftime($mask, $datestamp);
}
function toTime($date_string, $mask = '')
/**
* Convert date string back to integer (unix timestamp)
* NOTE: after some tests, strptime (compat mode) is adding +1 sec. after parsing to time, investigate!
*
* @param object $date_string
* @param object $mask [optional]
* @return
*/
function toTime($date_string, $mask = 'input')
{
//TODO - convert string to datestamp, coming soon
return time();
switch($mask)
{
case 'long':
$mask = e107::getPref('longdate');
break;
case 'short':
$mask = e107::getPref('shortdate');
break;
case 'input': //New - use inputdate as mask; FIXME - add inputdate to Date site prefs
$mask = e107::getPref('inputdate', '%d/%m/%Y %H:%M:%S');
break;
}
// see php compat handler
$tdata = strptime($date_string, $mask);
if(empty($tdata))
{
return null;
}
$unxTimestamp = mktime(
$tdata['tm_hour'],
$tdata['tm_min'],
$tdata['tm_sec'],
$tdata['tm_mon'] + 1,
$tdata['tm_mday'],
$tdata['tm_year'] + 1900
);
//var_dump($tdata, $date_string, $this->convert_date($unxTimestamp, $mask), $unxTimestamp);
return $unxTimestamp;
}
function computeLapse($older_date, $newer_date = FALSE, $mode = FALSE, $show_secs = TRUE, $format = 'long')

View File

@ -9,8 +9,8 @@
* Form Handler
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $
* $Revision: 1.75 $
* $Date: 2009-11-09 16:54:29 $
* $Revision: 1.76 $
* $Date: 2009-11-10 19:13:06 $
* $Author: secretr $
*
*/
@ -166,6 +166,7 @@ class e_form
if ($datestamp)
{
$cal_attrib['value'] = e107::getDateConvert()->convert_date($datestamp, 'input'); //date("d/m/Y H:i:s", $datestamp);
// var_dump('date picker', $datestamp, $cal_attrib['value'], e107::getDateConvert()->toTime($cal_attrib['value']), e107::getDateConvert()->convert_date(e107::getDateConvert()->toTime($cal_attrib['value']), 'input'));
}
//JS manager to send JS/CSS to header if possible, if not - footer
e107::getJs()// FIXME - no CSS support yet!!! ->tryHeaderFile($cal->calendar_theme_file)
@ -177,16 +178,16 @@ class e_form
}
/**
* UNDER CONSTRUCTION!!!
* User auto-complete search
*
* @param object $name
* @param object $id_fld
* @param object $default_name
* @param object $default_id
* @param object $options [optional]
* @param string $name_fld field name for user name
* @param string $id_fld field name for user id
* @param string $default_name default user name value
* @param integer $default_id default user id
* @param array|string $options [optional] 'readonly' (make field read only), 'name' (db field name, default user_name)
* @return
*/
function userpicker($name, $id_fld, $default_name, $default_id, $options = array())
function userpicker($name_fld, $id_fld, $default_name, $default_id, $options = array())
{
if(!is_array($options)) parse_str($options, $options);
@ -201,7 +202,7 @@ class e_form
//'.$this->text($id_fld, $default_id, 10, array('id' => false, 'readonly'=>true, 'class'=>'tbox number')).'
$ret = '
<div class="e-autocomplete-c">
'.$this->text($name, $default_name, 150, array('id' => false, 'readonly' => vartrue($options['readonly']) ? true : false)).'
'.$this->text($name_fld, $default_name, 150, array('id' => false, 'readonly' => vartrue($options['readonly']) ? true : false)).'
'.$this->hidden($id_fld, $default_id, array('id' => false)).'
'.$reset.'
<span class="indicator" style="display: none;">
@ -215,7 +216,7 @@ class e_form
e107::getJs()->footerInline("
//autocomplete fields
\$\$('input[name={$name}]').each(function(el) {
\$\$('input[name={$name_fld}]').each(function(el) {
if(el.readOnly) {
el.observe('click', function(ev) { ev.stop(); var el1 = ev.findElement('input'); el1.blur(); } );
@ -224,7 +225,7 @@ class e_form
return;
}
new Ajax.Autocompleter(el, el.next('div.e-autocomplete'), '".e_FILE_ABS."e_ajax.php', {
paramName: '{$name}',
paramName: '{$name_fld}',
minChars: 2,
frequency: 0.5,
afterUpdateElement: function(txt, li) {
@ -237,7 +238,7 @@ class e_form
}
},
indicator: el.next('span.indicator'),
parameters: 'ajax_used=1&ajax_sc=usersearch=".rawurlencode('searchfld=user--srcfld='.$name)."'
parameters: 'ajax_used=1&ajax_sc=usersearch=".rawurlencode('searchfld='.str_replace('user_', '', vartrue($options['name'], 'user_name')).'--srcfld='.$name_fld)."'
});
});
");
@ -264,15 +265,22 @@ class e_form
return "<input type='password' name='{$name}' value='' maxlength='{$maxlength}'".$this->get_attributes($options, $name)." />";
}
//TODO make auto-expanding - like facebook.
function textarea($name, $value, $rows = 10, $cols = 80, $options = array())
// autoexpand done
function textarea($name, $value, $rows = 10, $cols = 80, $options = array(), $counter = false)
{
if(is_string($options)) parse_str($options, $options);
// auto-height support
if(!vartrue($options['noresize']))
{
$options['class'] = $options['class'] ? $options['class'].' e-autoheight' : 'tbox textarea e-autoheight';
}
$options = $this->format_options('textarea', $name, $options);
//never allow id in format name-value for text fields
return "<textarea name='{$name}' rows='{$rows}' cols='{$cols}'".$this->get_attributes($options, $name).">{$value}</textarea>";
return "<textarea name='{$name}' rows='{$rows}' cols='{$cols}'".$this->get_attributes($options, $name).">{$value}</textarea>".(false !== $counter ? $this->hidden('__'.$name.'autoheight_opt', $counter) : '');
}
function bbarea($name, $value, $help_mod = '', $help_tagid='', $size = 'large')
function bbarea($name, $value, $help_mod = '', $help_tagid='', $size = 'large', $counter = false)
{
//size - large|medium|small
//width should be explicit set by current admin theme
@ -292,7 +300,9 @@ class e_form
$size = 'large';
break;
}
$options = array('class' => 'tbox'.($size ? ' '.$size : '').' e-wysiwyg');
// auto-height support
$options = array('class' => 'tbox bbarea '.($size ? ' '.$size : '').' e-wysiwyg');
$bbbar = '';
// FIXME - see ren_help.php
if(!deftrue('e_WYSIWYG'))
@ -304,7 +314,7 @@ class e_form
$ret = "
<div class='bbarea {$size}'>
".$this->textarea($name, $value, $rows, 50, $options)."
".$this->textarea($name, $value, $rows, 50, $options, $counter)."
<div class='field-spacer'><!-- --></div>
{$bbbar}
</div>
@ -951,6 +961,15 @@ class e_form
$tdclass = vartrue($data['class']);
if($field == 'checkboxes') $tdclass = $tdclass ? $tdclass.' autocheck e-pointer' : 'autocheck e-pointer';
// there is no other way for now - prepare user data
if('user' == $data['type']/* && isset($data['readParms']['idField'])*/)
{
if(is_string($data['readParms'])) parse_str($data['readParms'], $data['readParms']);
if(isset($data['readParms']['idField']))
{
$data['readParms']['__idval'] = $fieldvalues[$data['readParms']['idField']];
}
}
$value = $this->renderValue($field, varset($fieldvalues[$field]), $data, varset($fieldvalues[$pid]));
if($tdclass)
@ -1110,12 +1129,13 @@ class e_form
$value = implode(vartrue($parms['separator']), $pieces);
break;
case 'user_name':
/*case 'user_name':
case 'user_loginname':
case 'user_login':
case 'user_customtitle':
case 'user_email':
if(is_numeric($value))
case 'user_email':*/
case 'user':
/*if(is_numeric($value))
{
$value = get_user_data($value);
if($value)
@ -1126,6 +1146,11 @@ class e_form
{
$value = 'not found';
}
}*/
// Dirty, but the only way for now
if(vartrue($parms['__idval']) && vartrue($parms['link']))
{
$value = '<a href="'.e107::getUrl()->createCoreUser('func=profile&id='.intval($parms['__idval'])).'" title="Go to user profile">'.$value.'</a>';
}
break;
@ -1191,11 +1216,11 @@ class e_form
break;
case 'textarea':
return $this->textarea($key, $value, vartrue($parms['rows'], 5), vartrue($parms['cols'], 40), vartrue($parms['__options']));
return $this->textarea($key, $value, vartrue($parms['rows'], 5), vartrue($parms['cols'], 40), vartrue($parms['__options']), vartrue($parms['counter'], false));
break;
case 'bbarea':
return $this->bbarea($key, $value, vartrue($parms['help']), vartrue($parms['helptag']), vartrue($parms['size'], 'medium'));
return $this->bbarea($key, $value, vartrue($parms['help']), vartrue($parms['helptag']), vartrue($parms['size'], 'medium'), vartrue($parms['counter'], false));
break;
case 'image': //TODO - thumb, image list shortcode, js tooltip...
@ -1237,7 +1262,7 @@ class e_form
case 'user_email':*/
case 'user':
//user_id expected
// Just temporary solution, will be changed soon
// Just temporary solution, could be changed soon
if(!is_array($value))
{
$value = get_user_data($value);
@ -1245,7 +1270,7 @@ class e_form
if(!$value) $value = array();
$uname = varset($value['user_name']);
$value = varset($value['user_id'], 0);
return $this->userpicker($key.'_usersearch', $key, $uname, $value, $parms);
return $this->userpicker(vartrue($parms['nameField'] ,$key.'_usersearch'), $key, $uname, $value, $parms);
break;
case 'boolean':
@ -1260,7 +1285,7 @@ class e_form
break;
default:
//unknown type
return $value;
break;
}
}

View File

@ -9,8 +9,8 @@
* e107 Base Model
*
* $Source: /cvs_backup/e107_0.8/e107_handlers/model_class.php,v $
* $Revision: 1.35 $
* $Date: 2009-11-09 12:21:17 $
* $Revision: 1.36 $
* $Date: 2009-11-10 19:13:06 $
* $Author: secretr $
*/
@ -1701,6 +1701,7 @@ class e_admin_model extends e_model
$this->_db_errno = 0;
if($this->hasError() || (!$this->data_has_changed && !$force))
{
$this->addMessageInfo(LAN_NO_CHANGE);
return 0;
}
$res = e107::getDb()->db_Update($this->getModelTable(), $this->toSqlQuery('update'));
@ -1713,6 +1714,7 @@ class e_admin_model extends e_model
$this->addMessageDebug('SQL Error #'.$this->_db_errno.': '.e107::getDb()->getLastErrorText());
return false;
}
$this->addMessageInfo(LAN_NO_CHANGE);
return 0;
}

View File

@ -1,6 +1,8 @@
<?php
if (!defined('e107_INIT')) { exit; }
<?php
if (!defined('e107_INIT'))
{
exit;
}
// e107 requires PHP > 4.3.0, all functions that are used in e107, introduced in newer
// versions than that should be recreated in here for compatabilty reasons..
@ -9,11 +11,11 @@ if (!defined('e107_INIT')) { exit; }
if (!function_exists('file_put_contents'))
{
/**
* @return int
* @param string $filename
* @param mixed $data
* @desc Write a string to a file
*/
* @return int
* @param string $filename
* @param mixed $data
* @desc Write a string to a file
*/
define('FILE_APPEND', 1);
function file_put_contents($filename, $data, $flag = false)
{
@ -22,7 +24,8 @@ if (!function_exists('file_put_contents'))
{
return false;
}
if (is_array($data)) $data = implode($data);
if (is_array($data))
$data = implode($data);
if (($bytes = @fwrite($h, $data)) === false)
{
return false;
@ -32,17 +35,15 @@ if (!function_exists('file_put_contents'))
}
}
if (!function_exists('stripos'))
{
function stripos($str,$needle,$offset=0)
function stripos($str, $needle, $offset = 0)
{
return strpos(strtolower($str), strtolower($needle), $offset);
}
}
if(!function_exists('simplexml_load_string'))
if (!function_exists('simplexml_load_string'))
{
//CXml class code found on php.net
@ -51,54 +52,56 @@ if(!function_exists('simplexml_load_string'))
var $xml_data;
var $obj_data;
var $pointer;
function CXml() { }
function Set_xml_data( &$xml_data )
function CXml()
{
}
function Set_xml_data(&$xml_data)
{
$this->index = 0;
$this->pointer[] = &$this->obj_data;
//strip white space between tags
$this->xml_data = preg_replace("/>[[:space:]]+</i", "><", $xml_data);
$this->xml_parser = xml_parser_create( "UTF-8" );
xml_parser_set_option( $this->xml_parser, XML_OPTION_CASE_FOLDING, false );
xml_set_object( $this->xml_parser, $this );
xml_set_element_handler( $this->xml_parser, "_startElement", "_endElement");
xml_set_character_data_handler( $this->xml_parser, "_cData" );
xml_parse( $this->xml_parser, $this->xml_data, true );
xml_parser_free( $this->xml_parser );
$this->xml_parser = xml_parser_create("UTF-8");
xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false);
xml_set_object($this->xml_parser, $this);
xml_set_element_handler($this->xml_parser, "_startElement", "_endElement");
xml_set_character_data_handler($this->xml_parser, "_cData");
xml_parse($this->xml_parser, $this->xml_data, true);
xml_parser_free($this->xml_parser);
}
function _startElement( $parser, $tag, $attributeList )
function _startElement($parser, $tag, $attributeList)
{
$attributes = '@attributes';
foreach( $attributeList as $name => $value )
foreach ($attributeList as $name=>$value)
{
$value = $this->_cleanString( $value );
$object->{$attributes}[$name] = $value;
$value = $this->_cleanString($value);
$object-> {$attributes} [$name] = $value;
// $object->$name = $value;
}
//replaces the special characters with the underscore (_) in tag name
$tag = preg_replace("/[:\-\. ]/", "_", $tag);
eval( "\$this->pointer[\$this->index]->" . $tag . "[] = \$object;" );
eval( "\$size = sizeof( \$this->pointer[\$this->index]->" . $tag . " );" );
eval( "\$this->pointer[] = &\$this->pointer[\$this->index]->" . $tag . "[\$size-1];" );
eval("\$this->pointer[\$this->index]->".$tag."[] = \$object;");
eval("\$size = sizeof( \$this->pointer[\$this->index]->".$tag." );");
eval("\$this->pointer[] = &\$this->pointer[\$this->index]->".$tag."[\$size-1];");
$this->index++;
}
function _endElement( $parser, $tag )
function _endElement($parser, $tag)
{
array_pop( $this->pointer );
array_pop($this->pointer);
$this->index--;
}
function _cData( $parser, $data )
function _cData($parser, $data)
{
if (empty($this->pointer[$this->index]))
if ( empty($this->pointer[$this->index]))
{
if (rtrim($data, "\n"))
{
@ -110,10 +113,10 @@ if(!function_exists('simplexml_load_string'))
$this->pointer[$this->index] .= $data;
}
}
function _cleanString( $string )
function _cleanString($string)
{
return utf8_decode( trim( $string ) );
return utf8_decode(trim($string));
}
}
@ -121,11 +124,109 @@ if(!function_exists('simplexml_load_string'))
{
$xmlClass = new CXml;
$xmlClass->Set_xml_data($xml);
$data = (array)$xmlClass->obj_data;
$data = (array) $xmlClass->obj_data;
$tmp = array_keys($data);
$data = $data[$tmp[0]][0];
return $data;
}
}
/*
* This work of Lionel SAURON (http://sauron.lionel.free.fr:80) is licensed under the
* Creative Commons Attribution-Noncommercial-Share Alike 2.0 France License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.0/fr/
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*/
/**
* http://snipplr.com/view/4964/emulate-php-5-for-backwards-compatibility/
*
* Parse a date generated with strftime().
* PHP Compatibility *nix v5.1.0+, all $M
*
* This function is the same as the original one defined by PHP (Linux/Unix only),
* but now you can use it on Windows too.
* Limitation : Only this format can be parsed %S, %M, %H, %d, %m, %Y
*
* @author Lionel SAURON
* @version 1.0
* @public
*
* @param string $str date string to parse (e.g. returned from strftime()).
* @param string $sFormat strftime format used to create the date
* @return array Returns an array with the <code>$str</code> parsed, or <code>false</code> on error.
*/
if (!function_exists('strptime'))
{
define('STRPTIME_COMPAT', true);
function strptime($str, $format)
{
static $expand = array('%D'=>'%m/%d/%y', '%T'=>'%H:%M:%S', );
static $map_r = array('%S'=>'tm_sec', '%M'=>'tm_min', '%H'=>'tm_hour', '%d'=>'tm_mday', '%m'=>'tm_mon', '%Y'=>'tm_year', '%y'=>'tm_year', /*'%W'=>'tm_wday', '%D'=>'tm_yday',*/ '%u'=>'unparsed', );
#-- TODO - not so useful, locale is breaking it, so use date() and mktime() to generate the array below
static $names = array('Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, 'May'=>5, 'Jun'=>6, 'Jul'=>7, 'Aug'=>8, 'Sep'=>9, 'Oct'=>10, 'Nov'=>11, 'Dec'=>12, 'Sun'=>0, 'Mon'=>1, 'Tue'=>2, 'Wed'=>3, 'Thu'=>4, 'Fri'=>5, 'Sat'=>6 );
#-- transform $format into extraction regex
$format = str_replace(array_keys($expand), array_values($expand), $format);
$preg = preg_replace('/(%\w)/', '(\w+)', preg_quote($format));
#-- record the positions of all STRFCMD-placeholders
preg_match_all('/(%\w)/', $format, $positions);
$positions = $positions[1];
#-- get individual values
if (preg_match("#$preg#", $str, $extracted))
{
#-- get values
foreach ($positions as $pos => $strfc)
{
$v = $extracted[$pos + 1];
#-- add
if (isset($map_r[$strfc]))
{
$n = $map_r[$strfc];
$vals[$n] = ($v > 0) ? (int) $v : $v;
}
else
{
$vals['unparsed'] .= $v.' ';
}
}
#-- fixup some entries
//$vals["tm_wday"] = $names[ substr($vals["tm_wday"], 0, 3) ];
if ($vals['tm_year'] >= 1900)
{
$vals['tm_year'] -= 1900;
}
elseif ($vals['tm_year'] > 0)
{
$vals['tm_year'] += 100;
}
if ($vals['tm_mon'])
{
$vals['tm_mon'] -= 1;
}
else
{
$vals['tm_mon'] = $names[substr($vals['tm_mon'], 0, 3)] - 1;
}
//$vals['tm_sec'] -= 1; always increasing tm_sec + 1 ??????
#-- calculate wday/yday
$unxTimestamp = mktime($vals['tm_hour'], $vals['tm_min'], $vals['tm_sec'], ($vals['tm_mon'] + 1), $vals['tm_mday'], ($vals['tm_year'] + 1900));
$vals['tm_wday'] = (int) strftime('%w', $unxTimestamp); // Days since Sunday (0-6)
$vals['tm_yday'] = (strftime('%j', $unxTimestamp) - 1); // Days since January 1 (0-365)
//var_dump($vals, $str, strftime($format, $unxTimestamp), $unxTimestamp);
}
return isset($vals) ? $vals : false;
}
}

View File

@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/faqs/admin_config.php,v $
| $Revision: 1.2 $
| $Date: 2009-11-09 16:54:28 $
| $Revision: 1.3 $
| $Date: 2009-11-10 19:13:05 $
| $Author: secretr $
+----------------------------------------------------------------------------+
*/
@ -88,6 +88,10 @@ class faq_main_ui extends e_admin_ui
protected $pluginName = 'faqs';
protected $table = "faqs";
protected $tableJoin = array(
'u.user' => array('leftField' => 'faq_author', 'rightField' => 'user_id', 'fields' => 'user_id,user_loginname,user_name')
);
protected $listQry = "SELECT * FROM #faqs"; // without any Order or Limit.
protected $editQry = "SELECT * FROM #faqs WHERE faq_id = {ID}";
@ -100,14 +104,15 @@ class faq_main_ui extends e_admin_ui
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'faq_id' => array('title'=> LAN_ID, 'type' => 'int', 'width' =>'5%', 'forced'=> TRUE),
'faq_question' => array('title'=> "Question", 'type' => 'text', 'data'=> 'str', 'width' => 'auto', 'thclass' => 'left first'), // Display name
'faq_answer' => array('title'=> "Answer", 'type' => 'bbarea', 'data'=> 'str','width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name
'faq_question' => array('title'=> "Question", 'type' => 'text', 'width' => 'auto', 'thclass' => 'left first'), // Display name
'faq_answer' => array('title'=> "Answer", 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name
'faq_parent' => array('title'=> "Category", 'type' => 'method', 'data'=> 'int','width' => '5%', 'filter'=>TRUE, 'batch'=>TRUE),
'faq_comment' => array('title'=> "Comment", 'type' => 'userclass', 'data' => 'int', 'width' => 'auto'), // User id
'faq_datestamp' => array('title'=> "datestamp", 'type' => 'datestamp', 'data'=> 'int','width' => 'auto'), // User date
'faq_author' => array('title'=> LAN_USER, 'type' => 'user', 'data'=> 'int', 'thclass' => 'center', 'class'=>'center', 'filter' => true, 'batch' => true, 'width' => 'auto'), // Photo
'faq_order' => array('title'=> "Order", 'type' => 'int', 'data'=> 'int','width' => '5%', 'thclass' => 'center' ), // Real name (no real vetting)
'faq_author' => array('title'=> LAN_USER, 'type' => 'user', 'data'=> 'int', 'thclass' => 'center', 'class'=>'center', 'filter' => true, 'batch' => true, 'width' => 'auto'), // Photo
'u.user_name' => array('title'=> "User name", 'type' => 'user', 'width' => 'auto', 'noedit' => true, 'readParms'=>'idField=faq_author&link=1'), // User name
'u.user_loginname' => array('title'=> "User login", 'type' => 'user', 'width' => 'auto', 'noedit' => true, 'readParms'=>'idField=faq_author&link=1'), // User login name
'faq_order' => array('title'=> "Order", 'type' => 'number', 'data'=> 'int','width' => '5%', 'thclass' => 'center' ), // Real name (no real vetting)
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center')
);
@ -121,44 +126,73 @@ class faq_main_ui extends e_admin_ui
'classic_look' => array('title'=> 'Use Classic Layout', 'type'=>'boolean')
);
/**
* FAQ categories
* @var array
*/
protected $categories = null;
/**
* Get FAQ Category data
* @param integer $id [optional] get category title, false - return whole array
* @param object $default [optional] default value if not found (default 'n/a')
* @return
*/
function getFaqCategory($id = false, $default = 'n/a')
{
if(null === $this->categories) //auto-retrieve on first call
{
$sql = e107::getDb();
if($sql->db_Select('faqs_info'))
{
while ($row = $sql->db_Fetch())
{
$this->categories[$row['faq_info_id']] = $row['faq_info_title'];
}
}
else
{
$this->categories = array(); //prevent PHP warnings
}
}
if(false === $id)
{
return $this->categories;
}
return vartrue($this->categories[$id], $default);
}
}
//TODO Block and Unblock buttons, moderated comments?
class faq_admin_form_ui extends e_admin_form_ui
{
var $categories = array('hello','hello2','hello3');
//FIXME Breaks everything!!!
/*
function __construct()
{
$sql = e107::getDb();
$sql->db_Select('faq_info');
while ($row = $sql->db_Fetch())
{
$id = $row['faq_info_id'];
$this->categories[$id] = $row['faq_info_title'];
echo "hello";
}
}
*/
/**
* faq_parent field method
*
* @param integer $curVal
* @param string $mode
* @return mixed
*/
function faq_parent($curVal,$mode)
{
if($mode == 'read')
{
return $curVal.' (custom!)';
}
// Get UI instance
$controller = $this->getController();
if($mode == 'filter') // Custom Filter List for release_type
switch($mode)
{
return array(1=>'Category 1',2=>'Category 2',3=>'Category 3');
}
if($mode == 'batch')
{
case 'read':
return e107::getParser()->toHTML($controller->getFaqCategory($curVal), false, 'TITLE');
break;
case 'write':
return $this->selectbox('faq_parent', $controller->getFaqCategory(), $curVal);
break;
case 'filter':
case 'batch':
return $controller->getFaqCategory();
break;
}
}
}

View File

@ -9,8 +9,8 @@
* Release Plugin Administration UI
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/release/includes/admin.php,v $
* $Revision: 1.7 $
* $Date: 2009-11-09 16:54:28 $
* $Revision: 1.8 $
* $Date: 2009-11-10 19:13:06 $
* $Author: secretr $
*/
@ -70,24 +70,38 @@ class plugin_release_admin_ui extends e_admin_ui
*/
protected $pluginName = 'release';
// required
/**
* DB Table, table alias is supported
* Example: 'r.release'
* @var string
*/
protected $table = "release";
/**
* If present this array will be used to build your list query
* You can link fileds from $field array with 'table' parameter, which should equal to a key (table) from this array
* 'leftField', 'rightField' and 'fields' attributes here are required, the rest is optional
* Table alias is supported
* Note:
* - 'leftTable' could contain only table alias
* - 'leftField' and 'rightField' shouldn't contain table aliases, they will be auto-added
* - 'whereJoin' and 'where' should contain table aliases e.g. 'whereJoin' => 'AND u.user_ban=0'
*
* @var array [optional] table_name => array join parameters
*/
protected $tableJoin = array(
//'user' => array('leftField' => 'user_id', 'rightField' => 'comment_author_id', 'fields' => '*'/*, 'joinType' => 'LEFT JOIN', 'whereJoin' => '', 'where' => ''*/)
//'u.user' => array('leftField' => 'comment_author_id', 'rightField' => 'user_id', 'fields' => '*'/*, 'leftTable' => '', 'joinType' => 'LEFT JOIN', 'whereJoin' => '', 'where' => ''*/)
);
// required if no custom tree model is set in init()
// NOT NEEDED ANYMORE!!!
//protected $listQry = "SELECT * FROM #release";
// without any Order or Limit.
/**
* This is only needed if you need to JOIN tables AND don't wanna use $tableJoin
* Write your list query without any Order or Limit.
* NOTE: $tableJoin array is recommended join method
*
* @var string [optional]
*/
protected $listQry = "";
//
// optional - required only in case of e.g. tables JOIN. This also could be done with custom model (set it in init())
// NOT NEEDED ANYMORE!!!
@ -114,6 +128,9 @@ class plugin_release_admin_ui extends e_admin_ui
* (use this as starting point for wiki documentation)
* $fields format (string) $field_name => (array) $attributes
*
* $field_name format:
* 'table_alias.field_name' (if JOIN support is needed) OR just 'field_name'
*
* $attributes format:
* - title (string) Human readable field title, constant name will be accpeted as well (multi-language support
*
@ -123,12 +140,11 @@ class plugin_release_admin_ui extends e_admin_ui
* for list of possible read/writeParms per type see below
*
* - data (string) Data type, one of the following: int, integer, string, str, float, bool, boolean, model, null
* Default is 'str'
* Used only if $dataFields is not set
* full/most recent reference list - e_admin_model::sanitize(), db::_getFieldValue()
* - primary (boolean) primary field (obsolete, $pid is now used)
*
* - table (string) if there and non-empty - value is coming from another table, which SHOULD be found in $tableJoin (see above)
*
* - help (string) edit/create table - inline help, constant name will be accpeted as well, optional
* - note (string) edit/create table - text shown below the field title (left column), constant name will be accpeted as well, optional
*
@ -161,6 +177,9 @@ class plugin_release_admin_ui extends e_admin_ui
* - null -> read: n/a
* -> write: n/a
*
* - user -> read: [optional] 'link' => true - create link to user profile, 'idField' => 'author_id' - tells to renderValue() where to search for user id (used when 'link' is true)
* -> write: [optional] 'nameField' => 'comment_author_name' the name of a 'user_name' field;
*
* - number -> read: (array) [optional] 'point' => '.', [optional] 'sep' => ' ', [optional] 'decimals' => 2, [optional] 'pre' => '&euro; ', [optional] 'post' => 'LAN_CURRENCY'
* -> write: (array) [optional] 'pre' => '&euro; ', [optional] 'post' => 'LAN_CURRENCY', [optional] 'maxlength' => 50, [optional] '__options' => array(...) see e_form class description for __options format
*