Tak wygl±da zawarto¶æ pliku:
<?
class subpage extends core
{
private function preload($content)
{
return $content;
}
private function getArtParent ( $id )
{
$res = $this -> db -> query ( "SELECT parent FROM arts WHERE id = $id" );
return $res -> field ['parent'];
}
private function buildTypeSelector ( $selected = 0 )
{
$out = '';
$res = $this -> db -> query ( "SELECT * FROM art_types" );
$out .= '<select name="type">';
while ( !$res -> EOF )
{
$out .= '<option value="' . $res -> field ['id'] . '"' . (($selected == $res -> field ['id']) ? 'selected="selected"' : '') . '>' . $res -> field ['name'] . '</option>';
$res -> movenext();
}
$out .= '</select>';
return $out;
}
protected function buildArts($selected = 0)
{
$out = '<select name="parentart">';
$out .= '<option value="0">' . ($selected == 0 ? ' selected="selected"' : '') . '</option>';
$res = $this->db->query('SELECT id, title FROM `arts`');
while(!$res->EOF)
{
$out .= '<option value="' . $res->field['id'] . '"' . ($selected == $res->field['id'] ? ' selected="selected"' : '') . '>' . $res->field['title'] . '</option>';
}
$out .= '</select>';
return $out;
}
private function buildCatSelector ( $selected = 0 )
{
$out = '';
$out .= '<select name="cat_id">';
$cats = $this -> db -> query ( "SELECT * FROM cats WHERE root = 1 ORDER BY rorder ASC" );
while ( !$cats -> EOF )
{
$out .= '<optgroup class="selectRow" label="' . $cats -> field ['name'] . '">';
$subcats = $this -> db -> query ( "SELECT * FROM cats WHERE parent = " . $cats -> field ['id'] ." ORDER BY rorder ASC" );
while ( !$subcats -> EOF )
{
//$out .= '<optgroup class="selectSubRow" label=" ' . $subcats -> field ['name'] . '">';
$out .= '<option value="' . $subcats -> field ['id'] . '" class="selectSubRow" ' . (($selected == $subcats -> field ['id']) ? 'selected="selected"' : '') . '> ' . $subcats -> field ['name'] . '</option>';
$subsubcats = $this -> db -> query ( "SELECT * FROM cats WHERE parent = " . $subcats -> field ['id'] ." ORDER BY rorder ASC" );
while ( !$subsubcats -> EOF )
{
$out .= '<option value="' . $subsubcats -> field ['id'] . '" class="selectSubSubRow" ' . (($selected == $subsubcats -> field ['id']) ? 'selected="selected"' : '') . '> ' . $subsubcats -> field ['name'] . '</option>';
$subsubcats -> movenext();
}
//$out .= '</optgroup>';
$subcats -> movenext();
}
$out .= '</optgroup>';
$cats -> movenext();
}
$out .= '</select>';
return $out;
}
private function getParent ( $id )
{
$res = $this -> db -> query ( "SELECT parent,root FROM cats WHERE id = $id" );
if ( $res -> field ['root'] == 1 ) return false;
if ( $res -> field ['parent'] == 0 ) return false;
return $res -> field ['parent'];
}
private function getCatName ( $id )
{
$res = $this -> db -> query ( "SELECT name FROM cats WHERE id = $id" );
return $res -> field ['name'];
}
private function buildSafePath ( $parent )
{
$nodes = array(stripUnicode
($this->getCatName($parent))); $licz = 0;
while(($parent = $this->getParent($parent)) != false)
{
$licz++;
if ($licz != "2")
{
}
}
{
}
}
private function actions ()
{
if ( $this -> input
['act'] == 'save' && isset($this -> input
['id']) ) {
$this -> input
['id'] = intval($this -> input
['id']);
$safe_title = $this -> buildSafePath ( $this -> getArtParent( $this -> input ['id'] ) );
$safe_title .= '/' . stripUnicode( $this -> input_unsafe ['title'] ) . '/' . $this -> input ['id'];
$this -> db -> simple_update (
'arts',
array ( 'lastEdit' => time(), 'parentArt' => $this->input['parentart'] , 'showArt' => ($this->input['showart'] == 'yes' ?
1 : 0),'copyright' => ($this->input['copyright'] == 'yes' ?
1 : 0), 'author_id' => $this->input['author'] , 'parent' => $this -> input
['cat_id'] , 'content' => mysql_real_escape_string($this -> input_unsafe
['rte_content']) , 'precontent' => mysql_real_escape_string($this -> input_unsafe
['rte_precontent']) , 'title' => mysql_real_escape_string($this -> input_unsafe
['title']) , 'safe_title' => $safe_title , 'type' => $this -> input
['type'] , 'link' => $this -> input
['link'] ), 'id = ' . $this -> input['id']
);
$this->sendToLog('Zmieniono artyku³ (' . $this -> buildSafePath ( $this -> getArtParent( $this -> input ['id'] ) ) . ' » ' . $this -> input_unsafe ['title'] . ')');
$this -> redirect ( '../' . $safe_title . 'a' );
}
if ( $this -> input ['act'] == 'add' )
{
$this -> db -> simple_insert (
'arts',
array ( 'parentArt' => $this->input['parentart'] , 'showArt' => ($this->input['showart'] == 'yes' ?
1 : 0), 'copyright' => ($this->input['copyright'] == 'yes' ?
1 : 0), 'stamp' => time() , 'author_id' => $this ->input['author'] , 'parent' => $this -> input
['cat_id'] , 'content' => mysql_real_escape_string($this -> input_unsafe
['rte_content']) , 'precontent' => mysql_real_escape_string($this -> input_unsafe
['rte_precontent']) , 'title' => mysql_real_escape_string($this -> input_unsafe
['title']) , 'type' => $this -> input
['type'] , 'link' => $this -> input
['link'] ) );
$last = $this -> db -> query ( "SELECT MAX(id) AS last_id FROM arts" );
$safe_title = $this -> buildSafePath ( $this -> getArtParent( $last -> field ['last_id'] ) );
$safe_title .= '/' . stripUnicode
( trim($this -> input_unsafe
['title']) ) . '/' . $last -> field
['last_id'];
$this -> db
-> simple_update
( 'arts' , array ( 'safe_title' => $safe_title ) , 'id = ' . $last -> field
['last_id'] );
$this->sendToLog('Dodano artyku³ (' . $this -> buildSafePath ( $this -> getArtParent( $last -> field ['last_id'] ) ) . ' » ' . $this -> input_unsafe ['title'] . ')');
$this -> redirect ( '../' . $safe_title . 'a' );
}
}
?>
<?php
public function runSubPage()
{
if ( $this -> access ['mod_arts'] != 1 )
{
$this -> display ( 'Brak Uprawnieñ!' );
return 1;
}
$this -> subpage ['title'] = 'Edytor Tekstu';
$this -> actions ();
if ( $this -> input ['new'] )
{
$this -> display ( '<form action="?page=rte&act=add" method="POST">' );
$content = '';
$precontent = '';
$parent = 0;
$type = 0;
$id = 0;
$author = $this->sess->get('user_id');
$selected = '';
$show = ' checked="checked"';
$parentArt = '';
$link = '';
}
else
{
$text = $this -> db -> query ( "SELECT copyright, showArt, parentArt, author_id, content,precontent,title,t
ype,id,parent,link FROM arts WHERE id = " . $this -> input ['id'] );
//$content = $this -> preload ( $text -> field ['content'] );
//$precontent = $this -> preload ( $text -> field ['precontent'] );
$content = $text -> field ['content'];
$precontent = $text -> field ['precontent'];
$parent = $text -> field ['parent'];
$type = $text -> field ['type'];
$id = $text -> field ['id'];
$author = $text->field['author_id'];
$link = $text->field['link'];
$selected = ($text->field['copyright'] ? ' checked="checked"' : '');
$show = ($text->field['showArt'] ? ' checked="checked"' : '');
$parentArt = ($text->field['parentArt'] ? $text->field['parentArt'] : '');
$this -> display ( '<form action="?page=rte&act=save" method="POST">' );
}
$this -> display ( '
<div style="padding:10px; text-align:left; background-image:url(img/bg_frame_blue.png);">
Tytu³ : <input class="inputField" name="title" size="40" type="text" value="' . $text -> field ['title'] . '" />
Typ Tekstu : ' . $this -> buildTypeSelector( $type ) . '
Dzia³ : ' . $this -> buildCatSelector( $parent ) . '
<input type="submit" class="inputButton" value=" Zapisz ">
<input type="hidden" name="id" value="' . $id . '" />
<br /><input class="inputField" type="text" size="6" name="parentart" value="' . $parentArt . '" /> ID artyku³u nadrzêdnego
<br /><input class="inputField" type="text" size="6" name="author" value="' . $author . '" /> Numer ID autora
<br /><input type="checkbox" name="copyright" value="yes"' . $selected . ' /> Tekst nie nale¿y do nadsy³aj±cego?
<br /><input type="checkbox" name="showart" value="yes"' . $show . ' /> Wy¶wietliæ w menu kategorii?
<br /><input class="inputField" type="text" size="40" name="link" value="' . $link . '" /> URL docelowy
</div>
<div class="tableSubRow" style="text-align:left;">Wstêp tekstu [HTML]:</div>
<textarea name="rte_precontent" style="width:100%; height:150px">' . str_replace(' ', '', $precontent) . '</textarea>
<div class="tableSubRow" style="text-align:left;">Tre¶æ tekstu [HTML]:</div>
<textarea name="rte_content" style="width:100%; height:400px">' . str_replace(' ', '', $content) . '</textarea> </form>
' );
}
}
?>