/** * generate a name for for a new copy of an object * * This function is used to generate a new name lyke "Copy of <old file_name> (1).ext". * Usually used when copy/pasting objects and pasted object should receive a new name. * * @param int $pid parent object/folder id * @param varchar $name old/existing object name * @param boolean $excludeExtension if true then characters after last "." will remain unchanged * @return varchar new name */ public function getNewCopyName($pid, $name, $excludeExtension = false) { $ext = ''; if ($excludeExtension) { $a = explode('.', $name); if (sizeof($a) > 1) { $ext = '.' . array_pop($a); } $name = implode('.', $a); } $id = null; $i = 0; $newName = ''; do { $newName = L\get('CopyOf') . ' ' . $name . ($i > 0 ? ' (' . $i . ')' : '') . $ext; $id = DM\Tree::toId($newName, 'name', $pid); $i++; } while (!empty($id)); return $newName; }