/** * Generates automatic title form filename. Removes suffix, * replaces underscores by spaces and capitalizes only first * letter of any word. * * @param string $filename * @return string */ function makeAutoTitle($filename) { //remove custom stuff $title = preg_replace('/' . stripslashes($this->_oc->getValue('autoTitleRegex')) . '/', '', $filename); //remove suffix $title = preg_replace('/\\..*?$/', '', $title); //replace underscores and hyphens with spaces $replaceWithWhiteSpace = array('-', '_'); $title = str_replace($replaceWithWhiteSpace, ' ', $title); //proper capitalization $title = ucwords(strtolower($title)); PhotoQHelper::debug('makeAutoTitle: standard stuff and custom filter done ' . $title); //uncapitalize user defined words $noCaps = explode(',', str_replace(' ', '', $this->_oc->getValue('autoTitleNoCaps'))); foreach ($noCaps as $toLower) { $title = PhotoQHelper::strIReplace(' ' . $toLower . ' ', strtolower(' ' . $toLower . ' '), $title); } PhotoQHelper::debug('makeAutoTitle: uncapped user defined ' . $title); //uncapitalize short words $words = explode(' ', $title); $titleLen = count($words); for ($i = 0; $i < $titleLen; $i++) { if (strlen($words[$i]) <= $this->_oc->getValue('autoTitleNoCapsShortWords')) { $words[$i] = strtolower($words[$i]); } if ($i == $titleLen - 1) { //capitalize last word $words[$i] = ucfirst($words[$i]); } } $title = implode(' ', $words); PhotoQHelper::debug('makeAutoTitle: uncapped short ' . $title); //recapitalize user defined excepted words $caps = explode(',', str_replace(' ', '', $this->_oc->getValue('autoTitleCaps'))); foreach ($caps as $toUpper) { $title = PhotoQHelper::strIReplace(' ' . $toUpper . ' ', strtoupper(' ' . $toUpper . ' '), $title); } PhotoQHelper::debug('makeAutoTitle: leaving now ' . $title); //recapitalize first letter of name return ucfirst($title); }