Back to CoreContent class

Method check

public bool
check
()
Overloaded check function
Returns
  • bool True on success, false on failure
Since
  • 3.1
-
  • \Joomla\CMS\Table\Table::check()
Class: CoreContent
Project: Joomla

Method check - Source code

/**
 * Overloaded check function
 *
 * @return  boolean  True on success, false on failure
 *
 * @see     Table::check()
 * @since   3.1
 */
public function check()
{
    try {
        parent::check();
    } catch (\Exception $e) {
        $this->setError($e->getMessage());
        return false;
    }
    if (trim($this->core_title) === '') {
        $this->setError(Text::_('JLIB_CMS_WARNING_PROVIDE_VALID_NAME'));
        return false;
    }
    if (trim($this->core_alias) === '') {
        $this->core_alias = $this->core_title;
    }
    $this->core_alias = ApplicationHelper::stringURLSafe($this->core_alias);
    if (trim(str_replace('-', '', $this->core_alias)) === '') {
        $this->core_alias = Factory::getDate()->format('Y-m-d-H-i-s');
    }
    // Not Null sanity check
    if (empty($this->core_images)) {
        $this->core_images = '{}';
    }
    if (empty($this->core_urls)) {
        $this->core_urls = '{}';
    }
    // Check the publish down date is not earlier than publish up.
    if ($this->core_publish_up !== null && $this->core_publish_down !== null && $this->core_publish_down < $this->core_publish_up && $this->core_publish_down > $this->_db->getNullDate()) {
        // Swap the dates.
        $temp = $this->core_publish_up;
        $this->core_publish_up = $this->core_publish_down;
        $this->core_publish_down = $temp;
    }
    // Clean up keywords -- eliminate extra spaces between phrases
    // and cr (\r) and lf (\n) characters from string
    if (!empty($this->core_metakey)) {
        // Only process if not empty
        // Array of characters to remove
        $bad_characters = array("\n", "\r", "\"", '<', '>');
        // Remove bad characters
        $after_clean = StringHelper::str_ireplace($bad_characters, '', $this->core_metakey);
        // Create array using commas as delimiter
        $keys = explode(',', $after_clean);
        $clean_keys = array();
        foreach ($keys as $key) {
            if (trim($key)) {
                // Ignore blank keywords
                $clean_keys[] = trim($key);
            }
        }
        // Put array back together delimited by ", "
        $this->core_metakey = implode(', ', $clean_keys);
    }
    return true;
}