Skip to content

Commit

Permalink
Use mb_substr if available for prepareTableValue. Manually set connec…
Browse files Browse the repository at this point in the history
…tion charset parameters
  • Loading branch information
brendo committed Dec 22, 2010
1 parent 53bed4e commit 69a7334
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 41 deletions.
24 changes: 12 additions & 12 deletions symphony/lib/boot/bundle.php
Expand Up @@ -5,30 +5,30 @@
*/

if(!defined('PHP_VERSION_ID')){
$version = PHP_VERSION;
define('PHP_VERSION_ID', ($version{0} * 10000 + $version{2} * 100 + $version{4}));
$version = PHP_VERSION;
define('PHP_VERSION_ID', ($version{0} * 10000 + $version{2} * 100 + $version{4}));
}

if (PHP_VERSION_ID >= 50300){
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
}
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
}
else{
error_reporting(E_ALL & ~E_NOTICE);
error_reporting(E_ALL & ~E_NOTICE);
}

set_magic_quotes_runtime(0);
require_once(DOCROOT . '/symphony/lib/boot/func.utilities.php');

require_once(DOCROOT . '/symphony/lib/boot/func.utilities.php');
require_once(DOCROOT . '/symphony/lib/boot/defines.php');

if (!file_exists(CONFIG)) {

if (file_exists(DOCROOT . '/install.php')) {
header(sprintf('Location: %s/install.php', URL));
exit();
}

die('<h2>Error</h2><p>Could not locate Symphony configuration file. Please check <code>manifest/config.php</code> exists.</p>');
}

include(CONFIG);
7 changes: 2 additions & 5 deletions symphony/lib/core/class.symphony.php
Expand Up @@ -105,8 +105,8 @@ protected function __construct(){
General::cleanArray($_POST);
}

// Includes the existing CONFIG file and initialises the Configuration
// by setting the values with the setArray function.
// Includes the existing CONFIG file and initialises the Configuration
// by setting the values with the setArray function.
include(CONFIG);
self::$Configuration = new Configuration(true);
self::$Configuration->setArray($settings);
Expand Down Expand Up @@ -399,9 +399,6 @@ public function logout(){
* @see core.Cookie#expire()
*/
public function isLoggedIn(){
// Ensures that we're in the real world.. Also reduces three queries from database
if (is_null(self::$_instance)) return;

if ($this->Author) return true;

$username = self::$Database->cleanValue($this->Cookie->get('username'));
Expand Down
15 changes: 12 additions & 3 deletions symphony/lib/toolkit/class.field.php
Expand Up @@ -693,10 +693,13 @@ public function checkFields(Array &$errors, $checkForDuplicates = true) {
}

/**
* Format this field value for display in the administration pages summary tables.
* Format this field value for display in the publish index tables. By default,
* Symphony will truncate the value to the configuration setting `cell_truncation_length`.
* This function will attempt to use PHP's mbstring functions if they are available.
*
* @param array $data
* the data to use to generate the summary string.
* an associative array of data for this string. At minimum this requires a
* key of 'value'.
* @param XMLElement $link (optional)
* an xml link structure to append the content of this to provided it is not
* null. it defaults to null.
Expand All @@ -708,7 +711,13 @@ public function prepareTableValue($data, XMLElement $link = null) {
$max_length = ($max_length ? $max_length : 75);

$value = strip_tags($data['value']);
$value = (strlen($value) <= $max_length ? $value : substr($value, 0, $max_length) . '...');

if(function_exists('mb_substr')) {
$value = (strlen($value) <= $max_length ? $value : mb_substr($value, 0, $max_length, 'utf-8') . '...');
}
else {
$value = (strlen($value) <= $max_length ? $value : substr($value, 0, $max_length) . '...');
}

if (strlen($value) == 0) $value = __('None');

Expand Down
37 changes: 19 additions & 18 deletions symphony/lib/toolkit/class.mysql.php
Expand Up @@ -283,21 +283,6 @@ public function connect($host = null, $user = null, $password = null, $port ='33
return true;
}

/**
* This will set the character encoding of the connection for sending and
* receiving data. This function will only run if 'runtime_character_set_alter'
* is set to 'true' in the Sympony config. This is set to true by default during
* the Symphony installation. If no character encoding is provided, UTF-8
* is assumed.
*
* @link http://au2.php.net/manual/en/function.mysql-set-charset.php
* @param string $set
* The character encoding to use, by default this 'utf8'
*/
public function setCharacterEncoding($set='utf8'){
mysql_set_charset($set, MySQL::$_connection['id']);
}

/**
* This function selects a MySQL database. Only used by installation
* and must exists for compatibility reasons. But might be removed
Expand All @@ -319,6 +304,21 @@ public function select($db=NULL){
return true;
}

/**
* This will set the character encoding of the connection for sending and
* receiving data. This function will only run if 'runtime_character_set_alter'
* is set to 'true' in the Sympony config. This is set to true by default during
* the Symphony installation. If no character encoding is provided, UTF-8
* is assumed.
*
* @link http://au2.php.net/manual/en/function.mysql-set-charset.php
* @param string $set
* The character encoding to use, by default this 'utf8'
*/
public function setCharacterEncoding($set='utf8'){
mysql_set_charset($set, MySQL::$_connection['id']);
}

/**
* This function will set the character encoding of the database so that any
* new tables that are created by Symphony use this character encoding
Expand All @@ -327,9 +327,10 @@ public function select($db=NULL){
* @param string $set
* The character encoding to use, by default this 'utf8'
*/
public function setCharacterSet($set='utf8'){
$this->query("SET CHARACTER SET '$set'");
}
public function setCharacterSet($set='utf8'){
$this->query("SET character_set_connection = '$set', character_set_database = '$set', character_set_server = '$set'");
$this->query("SET CHARACTER SET '$set'");
}

/**
* This function will clean a string using the mysql_real_escape_string function
Expand Down
3 changes: 0 additions & 3 deletions symphony/lib/toolkit/fields/field.input.php
Expand Up @@ -155,8 +155,6 @@ public function checkPostFieldData($data, &$message, $entry_id=NULL){

$message = NULL;

$handle = Lang::createHandle($data);

if($this->get('required') == 'yes' && strlen($data) == 0){
$message = __("'%s' is a required field.", array($this->get('label')));
return self::__MISSING_FIELDS__;
Expand Down Expand Up @@ -191,7 +189,6 @@ public function canPrePopulate(){
}

public function appendFormattedElement(&$wrapper, $data, $encode=false){

$value = $data['value'];

if($encode === true){
Expand Down

0 comments on commit 69a7334

Please sign in to comment.