コード例 #1
0
ファイル: article.php プロジェクト: adjaika/J3Base
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success.
  *
  * @since   1.6
  */
 public function save($data)
 {
     $input = JFactory::getApplication()->input;
     $filter = JFilterInput::getInstance();
     if (isset($data['metadata']) && isset($data['metadata']['author'])) {
         $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');
     }
     if (isset($data['created_by_alias'])) {
         $data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM');
     }
     if (isset($data['images']) && is_array($data['images'])) {
         $registry = new Registry();
         $registry->loadArray($data['images']);
         $data['images'] = (string) $registry;
     }
     JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
     // Cast catid to integer for comparison
     $catid = (int) $data['catid'];
     // Check if New Category exists
     if ($catid > 0) {
         $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_content');
     }
     // Save New Categoryg
     if ($catid == 0 && $this->canCreateCategory()) {
         $table = array();
         $table['title'] = $data['catid'];
         $table['parent_id'] = 1;
         $table['extension'] = 'com_content';
         $table['language'] = $data['language'];
         $table['published'] = 1;
         // Create new category and get catid back
         $data['catid'] = CategoriesHelper::createCategory($table);
     }
     if (isset($data['urls']) && is_array($data['urls'])) {
         $check = $input->post->get('jform', array(), 'array');
         foreach ($data['urls'] as $i => $url) {
             if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) {
                 if (preg_match('~^#[a-zA-Z]{1}[a-zA-Z0-9-_:.]*$~', $check['urls'][$i]) == 1) {
                     $data['urls'][$i] = $check['urls'][$i];
                 } else {
                     $data['urls'][$i] = JStringPunycode::urlToPunycode($url);
                 }
             }
         }
         unset($check);
         $registry = new Registry();
         $registry->loadArray($data['urls']);
         $data['urls'] = (string) $registry;
     }
     // Alter the title for save as copy
     if ($input->get('task') == 'save2copy') {
         $origTable = clone $this->getTable();
         $origTable->load($input->getInt('id'));
         if ($data['title'] == $origTable->title) {
             list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
             $data['title'] = $title;
             $data['alias'] = $alias;
         } else {
             if ($data['alias'] == $origTable->alias) {
                 $data['alias'] = '';
             }
         }
         $data['state'] = 0;
     }
     // Automatic handling of alias for empty fields
     if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (!isset($data['id']) || (int) $data['id'] == 0)) {
         if ($data['alias'] == null) {
             if (JFactory::getConfig()->get('unicodeslugs') == 1) {
                 $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']);
             } else {
                 $data['alias'] = JFilterOutput::stringURLSafe($data['title']);
             }
             $table = JTable::getInstance('Content', 'JTable');
             if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) {
                 $msg = JText::_('COM_CONTENT_SAVE_WARNING');
             }
             list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
             $data['alias'] = $alias;
             if (isset($msg)) {
                 JFactory::getApplication()->enqueueMessage($msg, 'warning');
             }
         }
     }
     if (parent::save($data)) {
         if (isset($data['featured'])) {
             $this->featured($this->getState($this->getName() . '.id'), $data['featured']);
         }
         return true;
     }
     return false;
 }
コード例 #2
0
ファイル: weblink.php プロジェクト: Bakual/weblinks
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success.
  *
  * @since	3.1
  */
 public function save($data)
 {
     $app = JFactory::getApplication();
     JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
     // Cast catid to integer for comparison
     $catid = (int) $data['catid'];
     // Check if New Category exists
     if ($catid > 0) {
         $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks');
     }
     // Save New Category
     if ($catid == 0 && $this->canCreateCategory()) {
         $table = array();
         $table['title'] = $data['catid'];
         $table['parent_id'] = 1;
         $table['extension'] = 'com_weblinks';
         $table['language'] = $data['language'];
         $table['published'] = 1;
         // Create new category and get catid back
         $data['catid'] = CategoriesHelper::createCategory($table);
     }
     // Alter the title for save as copy
     if ($app->input->get('task') == 'save2copy') {
         list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
         $data['title'] = $name;
         $data['alias'] = $alias;
         $data['state'] = 0;
     }
     return parent::save($data);
 }
コード例 #3
0
ファイル: contact.php プロジェクト: Rai-Ka/joomla-cms
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success.
  *
  * @since   3.0
  */
 public function save($data)
 {
     $input = JFactory::getApplication()->input;
     JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
     // Cast catid to integer for comparison
     $catid = (int) $data['catid'];
     // Check if New Category exists
     if ($catid > 0) {
         $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_contact');
     }
     // Save New Category
     if ($catid == 0 && $this->canCreateCategory()) {
         $table = array();
         $table['title'] = $data['catid'];
         $table['parent_id'] = 1;
         $table['extension'] = 'com_contact';
         $table['language'] = $data['language'];
         $table['published'] = 1;
         // Create new category and get catid back
         $data['catid'] = CategoriesHelper::createCategory($table);
     }
     // Alter the name for save as copy
     if ($input->get('task') == 'save2copy') {
         $origTable = clone $this->getTable();
         $origTable->load($input->getInt('id'));
         if ($data['name'] == $origTable->name) {
             list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']);
             $data['name'] = $name;
             $data['alias'] = $alias;
         } else {
             if ($data['alias'] == $origTable->alias) {
                 $data['alias'] = '';
             }
         }
         $data['published'] = 0;
     }
     $links = array('linka', 'linkb', 'linkc', 'linkd', 'linke');
     foreach ($links as $link) {
         if ($data['params'][$link]) {
             $data['params'][$link] = JStringPunycode::urlToPunycode($data['params'][$link]);
         }
     }
     return parent::save($data);
 }
コード例 #4
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success.
  *
  * @since   1.6
  */
 public function save($data)
 {
     $input = JFactory::getApplication()->input;
     JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
     // Cast catid to integer for comparison
     $catid = (int) $data['catid'];
     // Check if New Category exists
     if ($catid > 0) {
         $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_banners');
     }
     // Save New Category
     if ($catid == 0) {
         $table = array();
         $table['title'] = $data['catid'];
         $table['parent_id'] = 1;
         $table['extension'] = 'com_banners';
         $table['language'] = $data['language'];
         $table['published'] = 1;
         // Create new category and get catid back
         $data['catid'] = CategoriesHelper::createCategory($table);
     }
     // Alter the name for save as copy
     if ($input->get('task') == 'save2copy') {
         /** @var BannersTableBanner $origTable */
         $origTable = clone $this->getTable();
         $origTable->load($input->getInt('id'));
         if ($data['name'] == $origTable->name) {
             list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']);
             $data['name'] = $name;
             $data['alias'] = $alias;
         } else {
             if ($data['alias'] == $origTable->alias) {
                 $data['alias'] = '';
             }
         }
         $data['state'] = 0;
     }
     return parent::save($data);
 }