/**
  * tx_dam_db::getPid()
  */
 public function test_getPID()
 {
     $pid = tx_dam_db::getPid();
     self::assertTrue($pid > 0, 'No DAM sysfolder detected/created');
     $pid = tx_dam_db::getPidList();
     self::assertTrue(!($pid == '0'), 'No DAM sysfolder detected/created');
 }
 /**
  * Class constructor.
  */
 function __construct()
 {
     parent::__construct();
     $this->local = new tx_gopibase_local($this);
     $this->img = new imageResize();
     if (t3lib_extMgm::isLoaded('dam')) {
         foreach (explode(',', tx_dam_db::getPidList()) as $damPid) {
             $this->damMediaPid = $damPid;
             break;
         }
     }
 }
 /**
  * Render statistics about lostrecords
  *
  * @return	array		array($countTotal, $content)
  */
 function statisticsLostRecords()
 {
     global $LANG, $TCA;
     $content = '';
     $countTotal = 0;
     // init table layout
     $tableLayout = array('table' => array('<table border="0" cellspacing="1" cellpadding="2" style="width:auto;">', '</table>'), '0' => array('tr' => array('<tr class="bgColor2">', '</tr>'), 'defCol' => array('<td align="center">', '</td>')), 'defRow' => array('tr' => array('<tr class="bgColor3-20">', '</tr>'), '1' => array('<td align="center">', '</td>'), 'defCol' => array('<td>', '</td>')));
     $tableOutput = array();
     $tr = 0;
     // add header row
     $tableOutput[$tr][] = 'Table';
     $tableOutput[$tr][] = 'Count';
     $mediaTables = tx_dam::register_getEntries('mediaTable');
     foreach ($mediaTables as $table) {
         $count = 0;
         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('COUNT(uid) as count', $table, $table . '.pid NOT IN (' . tx_dam_db::getPidList() . ')');
         if ($res) {
             $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
             $count = $row['count'];
             $countTotal += $count;
         }
         $title = is_array($TCA[$table]) ? $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']) : $table;
         $icon = t3lib_iconWorks::getIconImage($table, array(), $GLOBALS['BACK_PATH'], ' align="top"');
         // add row to table
         $tr++;
         $tableOutput[$tr][] = $icon . $title . ' (' . $table . ')';
         $tableOutput[$tr][] = $count;
     }
     $content .= $this->pObj->doc->table($tableOutput, $tableLayout);
     return array($countTotal, $content);
 }
 /**
  * Initializes the backend module by setting internal variables
  *
  * @return	void
  */
 function init()
 {
     global $TYPO3_CONF_VARS, $FILEMOUNTS;
     // name might be set from outside
     if (!$this->MCONF['name']) {
         $this->MCONF = $GLOBALS['MCONF'];
     }
     tx_dam::config_init();
     # tx_dam::config_setValue('setup.devel', '1');
     $this->defaultPid = tx_dam_db::getPid();
     $this->id = $this->defaultPid;
     // from parent::init();
     $this->CMD = t3lib_div::_GP('CMD');
     $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
     $this->menuConfig();
     $this->handleExternalFunctionValue();
     // include the default language file
     $GLOBALS['LANG']->includeLLFile('EXT:dam/lib/locallang.xml');
     //
     // Get current folder
     //
     // tx_dam_folder could be set by GP or stored in module conf
     $SET = t3lib_div::_GP('SET');
     $this->path = $this->MOD_SETTINGS['tx_dam_folder'];
     // check if tx_dam_folder was set by GP which takes precedence, if not use command sent by navframe
     // order: GP (script), SLCMD (navframe), MOD_SETTINGS (stored)
     $SLCMD = t3lib_div::_GPmerged('SLCMD');
     if (!$SET['tx_dam_folder'] and is_array($SLCMD['SELECT']) and is_array($SLCMD['SELECT']['txdamFolder'])) {
         $this->path = tx_dam::path_makeRelative(key($SLCMD['SELECT']['txdamFolder']));
     }
     $this->checkOrSetPath();
     $this->pageinfo = t3lib_BEfunc::readPageAccess($this->defaultPid, $this->perms_clause);
     $this->calcPerms = $GLOBALS['BE_USER']->calcPerms($this->pageinfo);
     //
     // Detect and set forced single function and set params
     //
     // remove selection command from any params
     $this->addParams['SLCMD'] = '';
     $this->addParams['SET'] = '';
     // forced a module function?
     $forcedFunction = t3lib_div::_GP('forcedFunction');
     if ($this->MOD_MENU['function'][$forcedFunction]) {
         $this->forcedFunction = $forcedFunction;
         $this->addParams['forcedFunction'] = $this->forcedFunction;
         $this->handleExternalFunctionValue('function', $this->forcedFunction);
     }
     //
     // Init selection
     //
     $this->selection = t3lib_div::makeInstance('tx_dam_selectionQuery');
     $maxPages = $this->config_checkValueEnabled('browserMaxPages', 20);
     $this->MOD_SETTINGS['tx_dam_resultPointer'] = $this->selection->initPointer($this->MOD_SETTINGS['tx_dam_resultPointer'], $this->MOD_SETTINGS['tx_dam_resultsPerPage'], $maxPages);
     $this->selection->initSelection($this, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dam']['selectionClasses'], 'tx_dam', 'tx_dam_select');
     $this->selection->initQueryGen();
     $this->selection->qg->initBESelect('tx_dam', tx_dam_db::getPidList());
     $this->selection->addFilemountsToQuerygen();
     // debug output
     if (tx_dam::config_getValue('setup.devel')) {
         $this->debugContent['MOD_SETTINGS'] = '<h4>MOD_SETTINGS</h4>' . t3lib_div::view_array($this->MOD_SETTINGS);
     }
     // BE Info output
     if (tx_dam::config_getValue('setup.devel') and t3lib_extMgm::isLoaded('cc_beinfo')) {
         require_once t3lib_extMgm::extPath('cc_beinfo') . 'class.tx_ccbeinfo.php';
         $beinfo = t3lib_div::makeInstance('tx_ccbeinfo');
         $beinfoContent = $beinfo->makeInfo($this);
         $this->debugContent['beinfo'] = '<h4>BE Info</h4>' . $beinfoContent;
     }
 }
 /**
  * Fille a where clase array with default values
  *
  * @param	array		$whereClauses WHERE clauses as array with associative keys (which can be used to overwrite 'enableFields' or 'pidList') or a single one as string.
  * @return	array		WHERE clauses as array
  */
 function fillWhereClauseArray($whereClauses = array())
 {
     if (!is_array($whereClauses)) {
         $whereClauses = array('where' => preg_replace('/^AND /', '', trim($whereClauses)));
     }
     $where = array();
     if (!isset($whereClauses['deleted']) and !isset($whereClauses['enableFields'])) {
         $where['enableFields'] = tx_dam_db::enableFields('tx_dam');
     }
     if (!isset($whereClauses['pidList'])) {
         $where['pidList'] = 'tx_dam.pid IN (' . tx_dam_db::getPidList() . ')';
     }
     $where = array_merge($where, $whereClauses);
     while ($key = array_search('', $where)) {
         unset($where[$key]);
     }
     return $where;
 }
 /**
  * Returns an fixture which is a random already indexed file.
  * @return mixed Is false when no indexed file available or: array('meta' => $row, 'filename' => $filename)
  */
 protected function getFixtureRandomIndexedFilename()
 {
     $select_fields = '*';
     #uid,file_name,file_path,file_hash';
     $where = array();
     $where['deleted'] = 'deleted=0';
     $where['pidList'] = 'pid IN (' . tx_dam_db::getPidList() . ')';
     $where['file_hash'] = 'file_hash';
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select_fields, 'tx_dam', implode(' AND ', $where), '', 'RAND()', 50);
     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         if (is_file($filename = tx_dam::file_absolutePath($row))) {
             return array('meta' => $row, 'filename' => $filename);
         }
     }
     return false;
 }
 /**
  * prüfen ob alles gelöscht wird, auch die bilder da sie keine
  * verwendung mehr haben
  * @group integration
  */
 public function testHandleDeleteWhenNoReference()
 {
     $this->importDataSet(tx_mklib_tests_Util::getFixturePath('db/wordlist.xml'));
     //wir müssen nachträglich noch die richtige pid in die dam datensätze einfügen damit
     //diese auch gefunden werden über tx_mklib_util_DAM::getRecords
     require_once PATH_txdam . 'lib/class.tx_dam_db.php';
     tx_rnbase_util_DB::doUpdate('tx_dam', '', array('pid' => tx_dam_db::getPidList()));
     $result = tx_mklib_util_DAM::handleDelete('tx_mklib_wordlist', 2, 'blacklisted', 1, true);
     //richtige Anzahl gelöscht?
     $this->assertEquals(0, $result['deletedReferences'], 'deletedReferences ist falsch!');
     $this->assertEquals(0, $result['deletedRecords'], 'deletedRecords ist falsch!');
     //bild nicht gelöscht?
     $this->assertFileExists($this->sAbsoluteImagePath, 'Das Bild der tempoäreren Anzeigen 4 und 20 wurde nicht gelöscht!');
     //eintrag in dam auf hidden gesetzt?
     $res = tx_rnbase_util_DB::doSelect('*', 'tx_dam', array('enablefieldsoff' => true));
     $this->assertEquals(1, count($res), 'Es wurde nicht die korrekte Anzahl von DAM Einträgen gefunden!');
     $this->assertEquals(1, $res[0]['uid'], 'Es wurde scheinbar eine falscher DAM Eintrag gelöscht!!');
     $this->assertEquals(0, $res[0]['hidden'], 'hidden falsch!');
     $this->assertEquals(0, $res[0]['deleted'], 'deleted falsch!');
 }
 /**
  * Insert a log entry
  *
  * The $addInfo array can override the defaults/detected values except the user_group which cannot be guessed.
  *
  * @param 	mixed  		$fileInfo see tx_dam.
  * @param 	integer 	$bytes_downloaded
  * @param 	boolean 	$protected Defines if it is a secure download
  * @param 	array 		$addInfo Additional infos to be written: host, user_id, user_name, user_group, page_id
  * @return 	integer 	Log id. See update().
  */
 function insert($fileInfo, $bytes_downloaded = 0, $protected = 0, $addInfo = array())
 {
     if (is_object($fileInfo)) {
         $fileInfo = $fileInfo->getMetaArray();
     } elseif (!is_array($fileInfo)) {
         $fileInfo = tx_dam::file_compileInfo($fileInfo);
     }
     $addInfo['host'] = $addInfo['host'] ? $addInfo['host'] : t3lib_div::getIndpEnv('REMOTE_ADDR');
     if (!$addInfo['user_id']) {
         if (is_object($GLOBALS['TSFE'])) {
             $addInfo['user_id'] = $GLOBALS['TSFE']->fe_user->user['uid'];
         } elseif (is_object($GLOBALS['BE_USER'])) {
             $addInfo['user_id'] = $GLOBALS['BE_USER']->user['uid'];
         }
     }
     // to be set from outside: $info['user_group']
     if (!$addInfo['page_id'] and is_object($GLOBALS['TSFE'])) {
         $addInfo['page_id'] = $GLOBALS['TSFE']->id;
     }
     $info = array_merge($fileInfo, $addInfo);
     $time = time();
     $row = array('pid' => tx_dam_db::getPidList(), 'tstamp' => intval($addInfo['tstamp']) ? intval($addInfo['tstamp']) : $time, 'crdate' => intval($addInfo['crdate']) ? intval($addInfo['crdate']) : $time, 'cruser_id' => intval($addInfo['cruser_id']), 'file_id' => intval($info['uid']), 'file_name' => $info['file_name'], 'file_path' => $info['file_path'], 'file_type' => $info['file_type'], 'media_type' => $info['media_type'], 'file_size' => $info['file_size'], 'bytes_downloaded' => $bytes_downloaded === true ? $info['file_size'] : intval($bytes_downloaded), 'protected' => $protected ? 1 : 0, 'host' => $info['host'], 'user_id' => $info['user_id'], 'user_name' => $info['user_name'], 'user_group' => $info['user_group'], 'page_id' => $info['page_id'], 'app_id' => $this->app_id, 'sitetitle' => $this->sitetitle, 'typo3_mode' => TYPO3_MODE);
     if ($res = $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_dam_log_download', $row)) {
         $id = $GLOBALS['TYPO3_DB']->sql_insert_id($res);
     }
     return $id;
 }