throw new Exception(Loco::__('Invalid data posted to server'), 422); } // path is allowed to not exist yet if ('/' !== $path[0]) { $path = WP_CONTENT_DIR . '/' . $path; } // but package must exist so we can get POT or source /* @var $package LocoPackage */ loco_require('loco-packages', 'loco-locales'); $package = LocoPackage::get($name, $type); if (!$package) { throw new Exception(sprintf(Loco::__('Package not found called %s'), $name), 404); } while (true) { // If file we're syncing is POT, we can only sync from sources if (!LocoAdmin::is_pot($path)) { // if a POT file exists, sync from that $domain = LocoAdmin::resolve_file_domain($path) or $domain = $package->get_domain(); if ($pot_path = $package->get_pot($domain)) { $exp = LocoAdmin::parse_po($pot_path); if (!$exp || 1 === count($exp) && '' === $exp[0]['source']) { // throw new Exception( Loco::__('POT file is empty').' - '.basename($pot_path) ); // fall through to try source code } else { $pot = basename($pot_path); break; } } } // Extract from sources by default if (!$package->has_source_dirs()) {
} // path is allowed to not exist yet if ('/' !== $path[0]) { $path = WP_CONTENT_DIR . '/' . $path; } // but package must exist so we can get POT or source /* @var $package LocoPackage */ loco_require('loco-packages', 'loco-locales'); $package = LocoPackage::get($name, $type); if (!$package) { throw new Exception(sprintf(Loco::__('Package not found called %s'), $name), 404); } $fname = basename($path); $podir = dirname($path); $dname = basename($podir); $ispot = LocoAdmin::is_pot($fname); $ftype = $ispot ? 'POT' : 'PO'; // handle file backups if file exists and enabled if (file_exists($path)) { $conf = Loco::config(); $num = (int) $conf['num_backups']; if (is_writable($podir)) { $dest = preg_replace('/\\.(pot?)$/i', '-backup-', $path); // delete oldest backups until we have $num-1 remaining if ($prev = glob($dest . '*')) { function _loco_sort_backups($f1, $f2) { $t1 = filemtime($f1); $t2 = filemtime($f2); return $t1 < $t2 ? -1 : ($t2 < $t1 ? 1 : 0); }