/** * Get instanz of the object (Singelton) * * @return ClipboardDatabase */ public static function getInstance() { if (!is_object(self::$objInstance)) { self::$objInstance = new ClipboardDatabase(); } return self::$objInstance; }
/** * Get pid and new sorting for new element * * @param string $strTable * @param int $intPid * @param string $strPastePos * @return array */ public function getNewPosition($strTable, $intPid, $strPastePos) { // Insert the current record at the beginning when inserting into the parent record if ($strPastePos == 'pasteInto') { $newPid = $intPid; $objSorting = $this->_objDatabase->getSorting($strTable, $intPid); // Select sorting value of the first record if ($objSorting->numRows) { $intCurSorting = $objSorting->sorting; // Resort if the new sorting value is not an integer or smaller than 1 if ($intCurSorting % 2 != 0 || $intCurSorting < 1) { $objNewSorting = $this->_objDatabase->getSortingElem($strTable, $intPid); $count = 2; $newSorting = 128; while ($objNewSorting->next()) { $this->_objDatabase->updateSorting($strTable, $count++ * 128, $objNewSorting->id); } } else { $newSorting = $intCurSorting / 2; } } else { $newSorting = 128; } } elseif ($strPastePos == 'pasteAfter' && $intPid > 0) { $objSorting = $this->_objDatabase->getDynamicObject($strTable, $intPid); // Set parent ID of the current record as new parent ID if ($objSorting->numRows) { $newPid = $objSorting->pid; $intCurSorting = $objSorting->sorting; // Do not proceed without a parent ID if (is_numeric($newPid)) { $objNextSorting = $this->_objDatabase->getNextSorting($strTable, $newPid, $intCurSorting); // Select sorting value of the next record if ($objNextSorting->sorting !== null) { $intNextSorting = $objNextSorting->sorting; // Resort if the new sorting value is no integer or bigger than a MySQL integer if (($intCurSorting + $intNextSorting) % 2 != 0 || $intNextSorting >= 4294967295) { $count = 1; $objNewSorting = $this->_objDatabase->getSortingElem($strTable, $newPid); while ($objNewSorting->next()) { $this->_objDatabase->updateSorting($strTable, $count++ * 128, $objNewSorting->id); if ($objNewSorting->sorting == $intCurSorting) { $newSorting = $count++ * 128; } } } else { $newSorting = ($intCurSorting + $intNextSorting) / 2; } } else { $newSorting = $intCurSorting + 128; } } } else { $newPid = $intPid; $newSorting = 128; } } return array('pid' => intval($newPid), 'sorting' => intval($newSorting)); }
/** * Create Content elements * * @param XMLReader $objXml * @param string $strTable * @param string $strPastePos * @param integer $intElemId * @param boolean $boolIsChild * @param boolean $isGrouped */ protected function createModule(&$objXml, $strTable, $strPastePos, $intElemId, $boolIsChild, $isGrouped = FALSE) { $arrIds = array(); if ($boolIsChild == TRUE) { $intId = $intElemId; } while ($objXml->read()) { switch ($objXml->nodeType) { case XMLReader::ELEMENT: switch ($objXml->localName) { case 'row': $arrSet = $this->createArrSetForRow($objXml, $intId, $strTable, $strPastePos, $intElemId, $boolIsChild); if (array_key_exists('type', $arrSet)) { if ($this->_objHelper->existsModuleType($arrSet)) { $objDb = $this->_objDatabase->insertInto($strTable, $arrSet); $intLastInsertId = $objDb->insertId; $this->loadDataContainer($strTable); $dataContainer = 'DC_' . $GLOBALS['TL_DCA'][$strTable]['config']['dataContainer']; $dc = new $dataContainer($strTable); if ($isGrouped) { $intElemId = $intLastInsertId; $strPastePos = 'pasteAfter'; $this->Input->setGet('act', 'copyAll'); } else { $this->Input->setGet('act', 'copy'); } if (is_array($GLOBALS['TL_DCA'][$strTable]['config']['oncopy_callback'])) { foreach ($GLOBALS['TL_DCA'][$strTable]['config']['oncopy_callback'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($intLastInsertId, $dc); } } // HOOK: call the hooks for clipboardCopy if (isset($GLOBALS['TL_HOOKS']['clipboardCopy']) && is_array($GLOBALS['TL_HOOKS']['clipboardCopy'])) { foreach ($GLOBALS['TL_HOOKS']['clipboardCopy'] as $arrCallback) { $this->import($arrCallback[0]); $this->{$arrCallback}[0]->{$arrCallback}[1]($intLastInsertId, $dc, $isGrouped); } } $objResult = $this->Database->prepare('SELECT pid FROM tl_module WHERE id = ?')->execute($intLastInsertId); $arrIds[$intLastInsertId] = $objResult->pid; $this->Input->setGet('act', NULL); } else { $strMessage = sprintf($GLOBALS['TL_LANG']['MSC']['clModulePasteInfo'], $arrSet['type']); $this->_objHelper->writeCustomerInfoMessage($strMessage); } } } break; case XMLReader::END_ELEMENT: switch ($objXml->localName) { case 'module': if ($isGrouped && count($arrIds) > 0) { // HOOK: call the hooks for clipboardCopyAll if (isset($GLOBALS['TL_HOOKS']['clipboardCopyAll']) && is_array($GLOBALS['TL_HOOKS']['clipboardCopyAll'])) { foreach ($GLOBALS['TL_HOOKS']['clipboardCopyAll'] as $arrCallback) { $this->import($arrCallback[0]); $this->{$arrCallback}[0]->{$arrCallback}[1]($arrIds); } } } return; break; } break; } } }
/** * Get checksum as md5 hash from all page, article and content elements * that need to save in xml * * @param array $arrSet * @return string */ protected function _createChecksum($arrSet) { $arrChecksum = array(); switch ($arrSet['table']) { case 'tl_page': $arrPages = $this->_objDatabase->getPageObject($arrSet['elem_id'])->fetchAllAssoc(); if ($arrSet['childs']) { $arrTmp = array($arrPages[0]['id']); $arrChecksum['page'][] = $arrPages[0]; for ($i = 0; TRUE; $i++) { if (!isset($arrTmp[$i])) { break; } $arrSubPages = $this->_objDatabase->getSubpagesObject($arrTmp[$i])->fetchAllAssoc(); foreach ($arrSubPages as $arrSubPage) { $arrTmp[] = $arrSubPage['id']; $arrChecksum['page'][] = $arrSubPage; } } } else { foreach ($arrPages as $arrPage) { $arrChecksum['page'][] = $arrPage; } } case 'tl_article': if (is_array($arrChecksum['page'])) { foreach ($arrChecksum['page'] as $arrPage) { $arrArticles = $this->_objDatabase->getArticleObjectFromPid($arrPage['id'])->fetchAllAssoc(); foreach ($arrArticles as $arrArticle) { $arrChecksum['article'][] = $arrArticle; } } } else { $arrArticles = $this->_objDatabase->getArticleObject($arrSet['elem_id'])->fetchAllAssoc(); foreach ($arrArticles as $arrArticle) { $arrChecksum['article'][] = $arrArticle; } } case 'tl_content': if (is_array($arrChecksum['article'])) { foreach ($arrChecksum['article'] as $arrArticle) { $arrContents = $this->_objDatabase->getContentObjectFromPid($arrArticle['id'])->fetchAllAssoc(); foreach ($arrContents as $arrContent) { $arrChecksum['content'][] = $arrContent; } } } else { $arrContents = $this->_objDatabase->getContentObject($arrSet['elem_id'])->fetchAllAssoc(); foreach ($arrContents as $arrContent) { $arrChecksum['content'][] = $arrContent; } } break; case 'tl_module': $arrModules = $this->_objDatabase->getModuleObject($arrSet['elem_id'])->fetchAllAssoc(); foreach ($arrModules as $arrModule) { $arrChecksum['module'][] = $arrModule; } break; } return md5(serialize($arrChecksum)); }
/** * Handle all main operations, clean up the url and redirect to itself */ public function init() { $arrSession = $this->Session->get('clipboardExt'); if ($arrSession['readXML']) { return; } if (stristr($this->Input->get('key'), 'cl_') || $this->Input->post('FORM_SUBMIT') == 'tl_select' && isset($_POST['cl_group'])) { $arrUnsetParams = array(); foreach (array_keys($_GET) as $strGetParam) { switch ($strGetParam) { case 'key': switch ($this->Input->get($strGetParam)) { // Set new favorite case 'cl_favor': if (strlen($this->Input->get('cl_id'))) { $this->favor($this->Input->get('cl_id')); } break; // Delete an element // Delete an element case 'cl_delete': if (strlen($this->Input->get('cl_id'))) { $this->delete($this->Input->get('cl_id')); } break; // Edit Element // Edit Element case 'cl_edit': $arrTitles = $this->Input->post('title'); if (is_array($arrTitles)) { $this->edit($arrTitles); } break; // Create new entry // Create new entry case 'cl_copy': $this->copy(); break; case 'cl_header_pastenew': case 'cl_paste_into': $this->pasteInto(); break; case 'cl_paste_after': $this->pasteAfter(); break; } $arrUnsetParams[$strGetParam] = $this->Input->get($strGetParam); break; case 'act': if ($this->Input->get('key') != 'cl_delete') { // Copy multi edit elements to clipboard $ids = deserialize($this->Input->post('IDS')); if (!is_array($ids) || empty($ids)) { $this->reload(); } $this->copy(TRUE, $ids); $arrUnsetParams[$strGetParam] = $this->Input->get($strGetParam); } break; case 'childs': case 'mode': case 'cl_id': $arrUnsetParams[$strGetParam] = $this->Input->get($strGetParam); break; } } foreach ($arrUnsetParams as $k => $v) { $this->Input->setGet($k, NULL); $this->Environment->request = str_replace("&{$k}={$v}", '', $this->Environment->request); $this->Environment->queryString = str_replace("&{$k}={$v}", '', $this->Environment->queryString); $this->Environment->requestUri = str_replace("&{$k}={$v}", '', $this->Environment->requestUri); } $arrUnsetKeyParams = array('cl_copy', 'cl_paste_into', 'cl_paste_after'); if (in_array($arrUnsetParams['key'], $arrUnsetKeyParams) && $this->_objHelper->getPageType() == 'content') { $objArticle = $this->_objDatabase->getArticleObjectFromContentId($this->Input->get('id')); $strRequestWithoutId = str_replace(substr($this->Environment->request, strpos($this->Environment->request, '&id')), '', $this->Environment->request); $this->redirect($strRequestWithoutId . '&id=' . $objArticle->id); } else { if (in_array($arrUnsetParams['key'], $arrUnsetKeyParams) && $this->_objHelper->getPageType() == 'module') { $objTheme = $this->_objDatabase->getThemeObjectFromModuleId($this->Input->get('id')); $strRequestWithoutId = str_replace(substr($this->Environment->request, strpos($this->Environment->request, '&id')), '', $this->Environment->request); $this->redirect($strRequestWithoutId . '&id=' . $objTheme->id); } } $this->redirect($this->Environment->request); } }