var $PageTree = array(); //directly from database. var $Pages = array(); //Page id's, sorted by title var $_categorytree = array(); var $categorytree = array(); //sorted by title, parent. for use with '; break; case 'textarea': $parent->{'input_'.$field['name']} = ''; break; case 'dropdown': $indices = explode("\n", $field['values_index']); $values = explode("\n", $field['values']); $parent->{'input_'.$field['name']} = ''; break; case 'checkbox': $parent->{'input_'.$field['name']} = 'custom_fields[$field['name']]? 'checked':'').'>'; break; case 'image': $value = ''; $media_id = 0; $media = $this->getMedia('media_type = \'image\' AND media_id = '.intval($parent->custom_fields[$field['name']])); $media_id = 0; if ($media){ $media = $media[0]; $media_id = $media->id; } $parent->{$field['name']} = $media; if ($media_id){ $value = ' [x]'; } $parent->{'input_'.$field['name']} = ''; $parent->{'input_'.$field['name']} .= 'Upload Image'; $parent->{'input_'.$field['name']} .= '
'.$value.'
'; break; case 'file': $value = ''; $media_id = 0; $media = $this->getMedia('media_type = \'file\' AND media_id = '.intval($parent->custom_fields[$field['name']])); $media_id = 0; if ($media){ $media = $media[0]; $media_id = $media->id; } $parent->{$field['name']} = $media; if ($media_id){ $value = ''.$media->title.' [x]'; } $parent->{'input_'.$field['name']} = ''; $parent->{'input_'.$field['name']} .= 'Upload File'; $parent->{'input_'.$field['name']} .= '
'.$value.'
'; break; default: break; } } } /** * Get Categories for use in html 'select' */ function getCategoryList($selectedCategoryId=0, $skipTop=0, $section_id=-1){ $result = ''; if ($section_id <= 0){ $section_id = $this->section_id; } if (!$skipTop){ $selected = ''; $section_name = '['.$this->Sections[$section_id]->name.']'; $result = '\n"; } foreach ($this->Sections[$section_id]->Categories as $tree){ $disabled = ''; $selected = ($selectedCategoryId == $tree->id? ' selected': ''); if ($selectedCategoryId == -1){ $selected = ' selected'; } $result .= '\n"; } return $result; } /* Paul's Simple Diff Algorithm v 0.1 (C) Paul Butler 2007 May be used and distributed under the zlib/libpng license. This code is intended for learning purposes; it was written with short code taking priority over performance. It could be used in a practical application, but there are a few ways it could be optimized. Given two arrays, the function diff will return an array of the changes. I won't describe the format of the array, but it will be obvious if you use print_r() on the result of a diff on some test data. htmlDiff is a wrapper for the diff command, it takes two strings and returns the differences in HTML. The tags used are and , which can easily be styled with CSS. */ function diff($old, $new){ if (!isset($maxlen)){ $maxlen = 0; } foreach($old as $oindex => $ovalue){ $nkeys = array_keys($new, $ovalue); foreach($nkeys as $nindex){ $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1; if($matrix[$oindex][$nindex] > $maxlen){ $maxlen = $matrix[$oindex][$nindex]; $omax = $oindex + 1 - $maxlen; $nmax = $nindex + 1 - $maxlen; } } } if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new)); return array_merge( $this->diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), array_slice($new, $nmax, $maxlen), $this->diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen))); } function htmlDiff($old, $new){ $ret = ''; $diff = $this->diff(explode(' ', $old), explode(' ', $new)); foreach($diff as $k){ if(is_array($k)) $ret .= (!empty($k['d'])?"".implode(' ',$k['d'])." ":''). (!empty($k['i'])?"".implode(' ',$k['i'])." ":''); else $ret .= $k . ' '; } return $ret; } function cleanupDiff($diff){ foreach ($diff as $key=>$val){ if(is_array($val)){ if (($val['d']) or ($val['i'])){ } else{ unset($diff[$key]); } } else{ unset($diff[$key]); } } return $diff; } function rollback( $new, $diff){ $old = explode(' ',$new); $offset = -1; foreach ($diff as $key=>$value) { array_splice ($old , $key+$offset , count($diff[$key]['i']) , $diff[$key]['d']); $offset += count($diff[$key]['d']) -1; } $old = implode(' ',$old); return $old; } function getIp(){ if( isset( $_SERVER ['HTTP_X_FORWARDED_FOR'] ) ){ $ip = $_SERVER ['HTTP_X_FORWARDED_FOR']; }elseif( isset( $_SERVER ['HTTP_VIA'] ) ){ $ip = $_SERVER ['HTTP_VIA']; }elseif( isset( $_SERVER ['REMOTE_ADDR'] ) ){ $ip = $_SERVER ['REMOTE_ADDR']; }else{ $ip = "Unknown" ; } return long2ip(ip2long($ip)); //clears invalid ip addresses } function refresh_article_comment_count($article_id){ $q = $this->db->fetch("SELECT comment_type FROM {$this->pre_section}comments WHERE comment_topic = ".intval($article_id)." LIMIT 1"); if ($q['comment_type'] != 'articles'){ return; } $q = $this->db->fetch("SELECT COUNT(*) AS comment_count FROM {$this->pre_section}comments WHERE comment_type = 'articles' AND comment_topic = ".intval($article_id)." AND comment_state = ".COMMENT_STATE_ACTIVE.""); $q_update = $this->db->query("UPDATE {$this->pre_section}articles SET article_comment_count = ".intval($q['comment_count'])." WHERE article_id = ".intval($article_id)." LIMIT 1"); } /** * Returns list of installed skins for use in 'Select' html box */ function getSkinList($selectedSkin='', $includeall=0){ if ($includeall){ $result = $this->db->query("SELECT skin_name FROM {$this->pre}amsskins"); } else{ $result = $this->db->query("SELECT skin_name FROM {$this->pre}amsskins WHERE skin_state = 1"); } $text = ''; while ($row = $this->db->nqfetch($result)){ $text .= '