Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [PHP][MYSQL] Ucinanie tekstu
Forum PHP.pl > Forum > Przedszkole
Orish
Po wgraniu artyku³ów do bazy na nowym CMSie stwierdzi³em, ¿e kilka z nich zosta³o uciêtych. Stwierdzi³em, ¿e wina le¿y w typie pola przeznaczonego na content (text), zmieni³em wiêc na mediumtext. Ale nadal mi nie przyjmuje tekstów d³u¿szych ni¿ te 65k bajtów! W czym mo¿e byæ problem?
Shili
W ograniczeniu liczby znaków ju¿ na poziomie php?
Ciê¿ko stwierdziæ nie widz±c kodu i tak dalej.
Orish
Tak wygl±da zawarto¶æ pliku:

  1. <?
  2.  
  3.  
  4. class subpage extends core
  5. {
  6.  private function preload($content) 
  7.  {
  8.   $content = str_replace(chr(10), " ", $content);
  9.   $content = str_replace(chr(13), " ", $content);
  10.   $content = str_replace(chr(145), chr(39), $content);
  11.   $content = str_replace(chr(146), chr(39), $content);
  12.   $content = str_replace( "'", "'" , $content);
  13.  
  14.   return $content;
  15.  }
  16.  
  17.  private function getArtParent ( $id )
  18.  {
  19.   $res = $this -> db -> query ( "SELECT parent FROM arts WHERE id = $id" );
  20.   return $res -> field ['parent'];
  21.  }
  22.  
  23.  private function buildTypeSelector ( $selected = 0 )
  24.  {
  25.   $out = '';
  26.   
  27.   $res = $this -> db -> query ( "SELECT * FROM art_types" );
  28.   
  29.   $out .= '<select name="type">';
  30.   
  31.   while ( !$res -> EOF )
  32.   {
  33.   $out .= '<option value="' . $res -> field ['id'] . '"' . (($selected == $res -> field ['id']) ? 'selected="selected"' : '') . '>' . $res -> field ['name'] . '</option>';
  34.  
  35.   $res -> movenext();
  36.   }
  37.   
  38.   $out .= '</select>';
  39.   
  40.   return $out;
  41.  }
  42.  
  43.  protected function buildArts($selected = 0)
  44.  {
  45.   $out = '<select name="parentart">';
  46.   
  47.   $out .= '<option value="0">' . ($selected == 0 ? ' selected="selected"' : '') . '</option>';
  48.   
  49.   $res = $this->db->query('SELECT id, title FROM `arts`');
  50.   
  51.   while(!$res->EOF)
  52.   {
  53.   $out .= '<option value="' . $res->field['id'] . '"' . ($selected == $res->field['id'] ? ' selected="selected"' : '') . '>' . $res->field['title'] . '</option>';
  54.   }
  55.   
  56.   $out .= '</select>';
  57.   
  58.   return $out;
  59.  }
  60.  
  61.  private function buildCatSelector ( $selected = 0 )
  62.  {
  63.   $out = '';
  64.   $out .= '<select name="cat_id">';
  65.   
  66.   $cats = $this -> db -> query ( "SELECT * FROM cats WHERE root = 1 ORDER BY rorder ASC" );
  67.   
  68.   while ( !$cats -> EOF )
  69.   {
  70.   $out .= '<optgroup class="selectRow" label="' . $cats -> field ['name'] . '">';
  71.    
  72.   $subcats = $this -> db -> query ( "SELECT * FROM cats WHERE parent = " . $cats -> field ['id'] ." ORDER BY rorder ASC" );
  73.   while ( !$subcats -> EOF )
  74.   {
  75.   //$out .= '<optgroup class="selectSubRow" label="&nbsp;&nbsp;' . $subcats -> field ['name'] . '">';
  76.   $out .= '<option value="' . $subcats -> field ['id'] . '" class="selectSubRow" ' . (($selected == $subcats -> field ['id']) ? 'selected="selected"' : '') . '>&nbsp;&nbsp;&nbsp;' . $subcats -> field ['name'] . '</option>';
  77.    
  78.   $subsubcats = $this -> db -> query ( "SELECT * FROM cats WHERE parent = " . $subcats -> field ['id'] ." ORDER BY rorder ASC" );
  79.   while ( !$subsubcats -> EOF )
  80.   {
  81.   $out .= '<option value="' . $subsubcats -> field ['id'] . '" class="selectSubSubRow" ' . (($selected == $subsubcats -> field ['id']) ? 'selected="selected"' : '') . '>&nbsp;&nbsp;&nbsp;' . $subsubcats -> field ['name'] . '</option>';
  82.   $subsubcats -> movenext();
  83.   }
  84.   //$out .= '</optgroup>';
  85.    
  86.   $subcats -> movenext();
  87.   }
  88.    
  89.   $out .= '</optgroup>';
  90.    
  91.   $cats -> movenext();
  92.   }
  93.   
  94.   $out .= '</select>';
  95.   return $out;
  96.  }
  97.  
  98.  private function getParent ( $id )
  99.  {
  100.   $res = $this -> db -> query ( "SELECT parent,root FROM cats WHERE id = $id" );
  101.  
  102.   if ( $res -> field ['root'] == 1 ) return false;
  103.   if ( $res -> field ['parent'] == 0 ) return false;
  104.   return $res -> field ['parent'];
  105.  }
  106.  
  107.  private function getCatName ( $id )
  108.  {
  109.   $res = $this -> db -> query ( "SELECT name FROM cats WHERE id = $id" );
  110.   return $res -> field ['name'];
  111.  }
  112.    
  113.  private function buildSafePath ( $parent )
  114.  {  
  115.   $nodes = array(stripUnicode($this->getCatName($parent)));
  116.   $licz = 0;
  117.   while(($parent = $this->getParent($parent)) != false)
  118.   {
  119.    $licz++;
  120.   if ($licz != "2")
  121.   {
  122.    array_unshift($nodes, stripUnicode($this->getCatName($parent)));
  123.   }
  124.   }
  125.   
  126.   if(count($nodes) > 1)
  127.   {
  128.   array_pop($nodes);
  129.   }
  130.    
  131.   return implode('/', $nodes);
  132.  }
  133.   
  134.  private function actions ()
  135.  {
  136.   if ( $this -> input ['act'] == 'save' && isset($this -> input ['id']) )
  137.   {
  138.   $this -> input ['id'] = intval($this -> input ['id']);
  139.    
  140.   $safe_title = $this -> buildSafePath ( $this -> getArtParent( $this -> input ['id'] ) );
  141.   $safe_title .= '/' . stripUnicode( $this -> input_unsafe ['title'] ) . '/' . $this -> input ['id'];
  142.    
  143.   $this -> db -> simple_update (
  144.   'arts',
  145.   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'] ),
  146.   'id = ' . $this -> input['id']
  147.   );
  148.    
  149.   $this->sendToLog('Zmieniono artyku³ (' . $this -> buildSafePath ( $this -> getArtParent( $this -> input ['id'] ) ) . ' &raquo; ' . $this -> input_unsafe ['title'] . ')');
  150.    
  151.   $this -> redirect ( '../' . $safe_title . 'a' );
  152.   } 
  153.    
  154.   if ( $this -> input ['act'] == 'add' )
  155.   {
  156.   $this -> db -> simple_insert (
  157.   'arts',
  158.   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'] )
  159.   );
  160.    
  161.   $last = $this -> db -> query ( "SELECT MAX(id) AS last_id FROM arts" );
  162.   $safe_title = $this -> buildSafePath ( $this -> getArtParent( $last -> field ['last_id'] ) );
  163.   $safe_title .= '/' . stripUnicode( trim($this -> input_unsafe ['title']) ) . '/' . $last -> field ['last_id'];
  164.    
  165.   $this -> db -> simple_update ( 'arts' , array ( 'safe_title' => $safe_title ) , 'id = ' . $last -> field ['last_id'] );
  166.    
  167.   $this->sendToLog('Dodano artyku³ (' . $this -> buildSafePath ( $this -> getArtParent( $last -> field ['last_id'] ) ) . ' &raquo; ' . $this -> input_unsafe ['title'] . ')');
  168.    
  169.   $this -> redirect ( '../' . $safe_title . 'a' );
  170.   }
  171.  }
  172.  
  173. ?>


  1. <?php
  2.  
  3.  public function runSubPage()
  4.  {
  5.   if ( $this -> access ['mod_arts'] != 1 )
  6.   {
  7.   $this -> display ( 'Brak Uprawnieñ!' );
  8.   return 1;
  9.   }
  10.  
  11.   $this -> subpage ['title'] = 'Edytor Tekstu';
  12.   $this -> actions ();
  13.   
  14.   if ( $this -> input ['new'] )
  15.   {
  16.   $this -> display ( '<form action="?page=rte&act=add" method="POST">' );
  17.   $content = '';
  18.   $precontent = '';
  19.   $parent = 0;
  20.   $type = 0;
  21.   $id = 0;
  22.   $author = $this->sess->get('user_id');
  23.   $selected = '';
  24.   $show = ' checked="checked"';
  25.   $parentArt = '';
  26.   $link = '';
  27.   }
  28.   else
  29.   {
  30.   $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'] );
  31.   //$content = $this -> preload ( $text -> field ['content'] );
  32.   //$precontent = $this -> preload ( $text -> field ['precontent'] );
  33.    
  34.   $content = $text -> field ['content'];
  35.   $precontent = $text -> field ['precontent'];
  36.    
  37.   $parent = $text -> field ['parent'];
  38.   $type = $text -> field ['type'];
  39.   $id = $text -> field ['id'];
  40.   $author = $text->field['author_id'];
  41.   $link = $text->field['link'];
  42.    
  43.   $selected = ($text->field['copyright'] ? ' checked="checked"' : '');
  44.   $show = ($text->field['showArt'] ? ' checked="checked"' : '');
  45.   $parentArt = ($text->field['parentArt'] ? $text->field['parentArt'] : '');
  46.    
  47.   $this -> display ( '<form action="?page=rte&act=save" method="POST">' );
  48.   }
  49.   
  50.   $this -> display ( '
  51.   <div style="padding:10px; text-align:left; background-image:url(img/bg_frame_blue.png);">
  52.   Tytu³ : <input class="inputField" name="title" size="40" type="text" value="' . $text -> field ['title'] . '" />
  53.   Typ Tekstu : ' . $this -> buildTypeSelector( $type ) . '
  54.   Dzia³ : ' . $this -> buildCatSelector( $parent ) . '
  55.   <input type="submit" class="inputButton" value="  Zapisz  ">
  56.   <input type="hidden" name="id" value="' . $id . '" />
  57.   <br /><input class="inputField" type="text" size="6" name="parentart" value="' . $parentArt . '" /> ID artyku³u nadrzêdnego
  58.   <br /><input class="inputField" type="text" size="6" name="author" value="' . $author . '" /> Numer ID autora
  59.   <br /><input type="checkbox" name="copyright" value="yes"' . $selected . ' /> Tekst nie nale¿y do nadsy³aj±cego?
  60.   <br /><input type="checkbox" name="showart" value="yes"' . $show . ' /> Wy¶wietliæ w menu kategorii?
  61.   <br /><input class="inputField" type="text" size="40" name="link" value="' . $link . '" /> URL docelowy
  62.   </div>
  63.    
  64.   <div class="tableSubRow" style="text-align:left;">Wstêp tekstu [HTML]:</div>
  65.   <textarea name="rte_precontent" style="width:100%; height:150px">' . str_replace(' ', '', $precontent) . '</textarea>
  66.    
  67.   <div class="tableSubRow" style="text-align:left;">Tre¶æ tekstu [HTML]:</div>
  68.   <textarea name="rte_content" style="width:100%; height:400px">' . str_replace(' ', '', $content) . '</textarea>
  69.   </form> 
  70.   ' );
  71.  }
  72.  
  73. }
  74. ?>
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.