/** * @see parent::getHtmlValue() */ function getHtmlValue($object, $smarty = null, $params = array()) { $value = $object->{$this->fieldName}; // Empty value: no paragraph if (!$value) { return ""; } // Truncate case: no breakers but inline bullets instead if ($truncate = CValue::read($params, "truncate")) { $value = CMbString::truncate($value, $truncate === true ? null : $truncate); $value = CMbString::nl2bull($value); return CMbString::htmlSpecialChars($value); } // Markdown case: full delegation if ($this->markdown) { // In order to prevent from double escaping $content = CMbString::markdown(html_entity_decode($value)); return "<div class='markdown'>{$content}</div>"; } // Standard case: breakers and paragraph enhancers $text = ""; $value = str_replace(array("\r\n", "\r"), "\n", $value); $paragraphs = preg_split("/\n{2,}/", $value); foreach ($paragraphs as $_paragraph) { if (!empty($_paragraph)) { $_paragraph = nl2br(CMbString::htmlSpecialChars($_paragraph)); $text .= "<p>{$_paragraph}</p>"; } } return $text; }
/** * @see parent::updateFormFields() */ function updateFormFields() { parent::updateFormFields(); $this->_view = CMbString::truncate($this->traitement, 40); }
/** * Truncate a string to a given maximum length * * @param string $string The string to truncate * * @return string The truncated string */ public static function truncate($string) { if (!is_string($string)) { return $string; } // Truncate $max = 1024; $result = CMbString::truncate($string, $max); // Indicate true size $length = strlen($string); if ($length > 1024) { $result .= " [{$length} bytes]"; } return $result; }
/** * @see parent::updateFormFields() */ function updateFormFields() { parent::updateFormFields(); $this->_view = $this->_name; $this->_shortview = CMbString::truncate($this->_name); $this->_cp_court = substr($this->cp, 0, 2); }
/** * Check all properties according to specification * * @return string|null Store-like message, null when no problem */ function check() { $debug = CAppUI::conf("debug"); $msg = ""; // Property level checking foreach ($this->_props as $name => $prop) { if ($name[0] !== '_') { if (!property_exists($this, $name)) { trigger_error("La spécification cible la propriété '{$name}' inexistante dans la classe '{$this->_class}'", E_USER_WARNING); } else { $value = $this->{$name}; if (!$this->_id || $value !== null) { $msgProp = $this->checkProperty($name); $truncated = CMbString::truncate($value); $debugInfo = $debug ? "(val:\"{$truncated}\", prop:\"{$prop}\")" : "(valeur: \"{$truncated}\")"; $fieldName = CAppUI::tr("{$this->_class}-{$name}"); $msg .= $msgProp ? " • <strong title='{$name}'>{$fieldName}</strong> : {$msgProp} {$debugInfo} <br/>" : null; } } } } if ($this->_merging) { return $msg; } // Class level unique checking foreach ($this->_spec->uniques as $unique => $names) { /** @var self $other */ $other = new $this->_class(); $values = array(); foreach ($names as $name) { $this->completeField($name); $other->{$name} = addslashes($this->{$name}); $value = ""; if ($this->_specs[$name] instanceof CRefSpec) { $fwd = $this->loadFwdRef($name); if ($fwd) { $value = $fwd->_view; } } else { $value = $this->{$name}; } $values[] = $value; } $other->loadMatchingObject(); if ($other->_id && $this->_id != $other->_id) { return CAppUI::tr("{$this->_class}-failed-{$unique}") . " : " . implode(", ", $values); } } // Class-level xor checking foreach ($this->_spec->xor as $xor => $names) { $n = 0; $fields = array(); foreach ($names as $name) { $this->completeField($name); $fields[] = CAppUI::tr("{$this->_class}-{$name}"); if ($this->{$name}) { $n++; } } if ($n != 1) { return CAppUI::tr("{$this->_class}-xorFailed-{$xor}") . ": " . implode(", ", $fields) . ")"; } } return $msg; }
/** * @see parent::updateFormFields() */ function updateFormFields() { parent::updateFormFields(); $this->_view = ucwords(strtolower($this->text)); $this->_shortview = CMbString::truncate($this->_view); }
/** * @see parent::updateFormFields() */ function updateFormFields() { parent::updateFormFields(); $this->_view = $this->title ? $this->title : CMbString::truncate($this->text, 30); $this->_no_size = true; }
/** * Check a parameter * * @param string $name Name of the parameter * @param string $prop Property specification of the parameter * @param string $value Value of the paramter * * @return any */ public static function checkParam($name, $prop, $value) { self::$params->{$name} =& $value; // Check the name if (in_array($name, self::$protected_names)) { $error = "View parameter '{$name}' is a protected name and should NOT be used."; trigger_error($error, E_USER_WARNING); } // Check duplicates if (array_key_exists($name, self::$props)) { $error = "View parameter '{$name}' is already in use."; trigger_error($error, E_USER_WARNING); } // Get Specification self::$props[$name] = $prop; $spec = CMbFieldSpecFact::getSpecWithClassName("stdClass", $name, $prop); // Defaults the value when available if (empty($value) && $spec->default) { $value = $spec->default; } // Could be null if ($value === "" || $value === null) { if (!$spec->notNull) { return $value; } } // Check the value if ($msg = $spec->checkPropertyValue(self::$params)) { $truncated = CMbString::truncate($value); $error = "View parameter '{$name}' with spec '{$prop}' has inproper value '{$truncated}': {$msg}"; trigger_error($error, E_USER_WARNING); } return $value; }