/** * Find all defined callbacks in the app or other plugins * * @param undefined $cached * @return void * @access public */ public function load() { $cached = Cache::read('_plugin_callbacks_', '_cake_models_'); if ($cached !== false) { $this->settings = $cached; return $cached; } App::import('Folder'); $Folder = new Folder($this->path . 'plugins'); $folders = current($Folder->ls()); $files = array(); foreach ($folders as $folder) { if ($Folder->cd($this->path . 'models' . DS . 'callbacks')) { $files = $Folder->findRecursive('([a-z_]+)_' . $folder . '.php'); } $files = array_flip($files); foreach ($folders as $_folder) { if ($Folder->cd($this->path . 'plugins' . DS . $_folder . DS . 'models' . DS . 'callbacks')) { $files = array_merge($files, array_flip($Folder->findRecursive('([a-z_]+)_' . $folder . '.php'))); } } foreach (array_keys($files) as $k => $file) { if (!preg_match_all('/models\\/callbacks\\/([a-z_]+)_' . $folder . '\\.php/i', $file, $matches)) { continue; } $plugin = current($matches[1]); if (empty($plugin)) { $plugin = 'app'; } $callbackName = Inflector::camelize(sprintf('%s_%s', $plugin, $folder)); $this->settings[$folder][$plugin] = $callbackName; } } Cache::write('_plugin_callbacks_', $this->settings, '_cake_models_'); }
function getPlugins() { $pluginFolder = new Folder(APP . 'plugins'); $plugins = $pluginFolder->ls(); $result = array(); if (count($plugins) > 0) { foreach ($plugins[0] as $plugin) { $result[] = $plugin; } } return $result; }
function index() { $lang_folder = new Folder(APP . DS . 'locale'); $langs = $lang_folder->ls(true, false); $actual = array(); foreach ($langs[0] as $l) { if ($l != 'eng' && $l != 'SAMPLE' && file_exists(APP . DS . 'locale' . DS . $l . DS . 'LC_MESSAGES' . DS . 'welcome.po')) { $contents = file_get_contents(APP . DS . 'locale' . DS . $l . DS . 'LC_MESSAGES' . DS . 'welcome.po'); preg_match_all('/msgstr "(.*)"/', $contents, $matches); $actual[] = array('locale' => $l, 'welcome' => $matches[1][0], 'action' => $matches[1][1]); } } if (empty($actual)) { $this->Session->write('Language', 'eng'); $this->redirect('/install/license'); exit; } $this->set('langs', $actual); }
function beforeRender() { if (!isset($this->viewVars['data'])) { $this->set('data', $this->data); } if (!$this->_isRequestAction()) { if (!$this->menuItems) { $this->menuItems['Home'] = array('url' => '/'); if ($this->plugin) { $Human = Inflector::humanize($this->plugin); $this->menuItems[$Human]['url'] = '/' . $this->PluginName; $this->menuItems[$Human]['active'] = true; $FileList = listClasses(APP . "plugins" . DS . $this->plugin . DS . "controllers"); foreach ($FileList as $file) { $list = explode("_", $file); unset($list[count($list) - 1]); $controller = implode($list, "_"); if (up($controller) != up($this->plugin)) { $array = array("url" => '/' . $this->PluginName . '/' . Inflector::camelize($controller)); if (Inflector::underscore($this->name) == $controller) { $array['active'] = true; } $this->menuItems[Inflector::humanize($controller)] = $array; } } } else { $this->menuItems['Home']['active'] = true; uses('Folder'); $Folder = new Folder(APP . DS . "plugins"); list($Plugins) = $Folder->ls(); foreach ($Plugins as $Plugin) { $Camel = Inflector::Camelize($Plugin); $Human = Inflector::humanize($Plugin); $this->menuItems[$Human] = array('url' => '/' . $Camel); } } } $this->set('Menu', $this->menuItems); $this->set('javascripts', $this->javascripts); } }
private static function _zipDir(Folder $dir, \ZipArchive $zip, $relative_path) { $items = $dir->ls(); if (count($items)) { foreach ($items as $item) { if ($item->isFile()) { $name = $relative_path . $item->name(); $name = @iconv('UTF-8', 'CP850//TRANSLIT', $name); \GO::debug("Add file: " . $name); $zip->addFile($dir->path() . '/' . $item->name(), $name); } else { self::_zipDir($item, $zip, $relative_path . $item->name() . '/'); } } } else { \GO::debug("Add empty dir: " . $relative_path); if (!$zip->addEmptyDir(rtrim($relative_path, '/'))) { throw new \Exception("Could not add emty directory " . $relative_path); } } }
/** * testNoTestCaseSupplied method * * @access public * @return void */ function testNoTestCaseSupplied() { if (php_sapi_name() != 'cli') { unset($_GET['group']); CodeCoverageManager::start(substr(md5(microtime()), 0, 5), new CakeHtmlReporter()); CodeCoverageManager::report(false); $this->assertError(); CodeCoverageManager::start('libs/' . basename(__FILE__), new CakeHtmlReporter()); CodeCoverageManager::report(false); $this->assertError(); $path = LIBS; if (strpos(LIBS, ROOT) === false) { $path = ROOT . DS . LIBS; } App::import('Core', 'Folder'); $folder = new Folder(); $folder->cd($path); $contents = $folder->ls(); /** * remove method * * @param mixed $var * @access public * @return void */ function remove($var) { return $var != basename(__FILE__); } $contents[1] = array_filter($contents[1], "remove"); foreach ($contents[1] as $file) { CodeCoverageManager::start('libs' . DS . $file, new CakeHtmlReporter()); CodeCoverageManager::report(false); $this->assertNoErrors('libs' . DS . $file); } } }
function settings($id = null) { $folder = new Folder(APP . 'locale'); $tmp = $folder->ls(true, array(".svn", ".", "..")); $availableLanguages = array(); foreach ($tmp[0] as $value) { $lang = substr($value, 0, 2); $availableLanguages[$lang] = $lang; } if (empty($this->data)) { if (!$id or !$this->User->read(null, $id)) { $this->Session->setFlash(__('Invalid id.', true)); $this->redirect($this->referer()); exit; } $this->data = $this->User->read(null, $id); } else { $this->User->Profile->save($this->data); $this->Session->write('User.Profile.lang', $this->data['Profile']['lang']); $this->Session->setFlash(__('Settings saved.', true)); $this->redirect($this->referer()); exit; } $this->set('availableLanguages', $availableLanguages); }
/** * Loads a list of plugins in the current app. * * @return array * @author John David Anderson */ function __listPlugins() { $pluginsFolder = new Folder(APP . 'plugins'); $filesAndDirectories = $pluginsFolder->ls(true, true); return $filesAndDirectories[0]; }
function profile($id = null) { $viewer = $this->Session->read('User'); if (is_null($id)) { $id = $this->Session->read('User.id'); } $this->data = $this->User->read(null, $id); // Admins can't view/edit master account if ($viewer['perms'] == 3 && $this->data['User']['perms'] == 4) { $this->redirect('/users'); } uses('Folder'); $themes_folder = new Folder(THEMES); $themes = $themes_folder->ls(true, false); $this->set('themes', $themes[0]); $custom_themes_folder = new Folder(USER_THEMES); $custom_themes_templates = $custom_themes_folder->ls(true, array('sample', '.', '..', '.svn')); $this->set('custom_themes', $custom_themes_templates[0]); $lang_folder = new Folder(APP . DS . 'locale'); $langs = $lang_folder->ls(true, false); $this->set('langs', $langs[0]); $this->pageTitle = __('User Profile', true); $this->set('viewer', $viewer); }
function _getSections($AclMode = 'full', $getChildren = true) { if ($AclMode == 'full') { $acos = $this->Aco->findByAlias(low(APP_DIR)); } else { $acos = $this->Aco->findByAlias(low('ROOT')); } if (empty($acos['Aco']['alias'])) { $status = 'off'; $type = 'off'; } else { $status = 'on'; $noChildren = ($acos['Aco']['rght'] - $acos['Aco']['lft']) / 2; if ($noChildren > 1) { $type = 'granular'; } else { $type = 'global'; } } if ($getChildren && !empty($acos['Aco']['alias'])) { $controllers = $this->_getControllers(APP_DIR, $status, $AclMode); } else { $controllers = array(); } $sections[low(APP_DIR)] = array("status" => $status, "type" => $type, "children" => $controllers); if ($AclMode == 'full') { uses('Folder'); $Folder = new Folder(APP . DS . "plugins"); list($Plugins) = $Folder->ls(); foreach ($Plugins as $Plugin) { $Plugin = low($Plugin); $acos = $this->Aco->findByAlias($Plugin); if (empty($acos['Aco']['alias'])) { $status = 'off'; $type = 'off'; } else { $status = 'on'; $noChildren = ($acos['Aco']['rght'] - $acos['Aco']['lft']) / 2; if ($noChildren > 1) { $type = 'granular'; } else { $type = 'global'; } } if ($getChildren && !empty($acos['Aco']['alias'])) { $controllers = $this->_getControllers($Plugin, $status, $AclMode); } else { $controllers = array(); } $sections[low($Plugin)] = array("status" => $status, "type" => $type, "children" => $controllers); } } return $sections; }
/** * Walk through all directories and search for listener classes * Returns a array with classname as key and full path as value * * @param string $dir Currently: 'controllers' and 'models' * @return array */ public function eventFilePaths($dir = 'controllers') { App::import('Core', 'Folder'); $eventFilePaths = array(); // Lookup APP events $events = new Folder(EVENTS . $dir); list($folders, $files) = $events->ls(); foreach ($files as $listenerClassFile) { $eventFilePaths[self::file2class($listenerClassFile)] = $events->path . DS . $listenerClassFile; } // Lookup PLUGIN events $plugins = new Folder(PLUGINS); list($folders, $files) = $plugins->ls(); if (count($folders) > 1) { foreach ($folders as $pluginsFolder) { if ($pluginsFolder == 'eventful') { continue; } $pluginEvents = new Folder(PLUGINS . $pluginsFolder . DS . EVENTS_DIR . DS . $dir); list($folders, $files) = $pluginEvents->ls(); foreach ($files as $listenerClassFile) { $eventFilePaths[self::file2class($listenerClassFile)] = $pluginEvents->path . DS . $listenerClassFile; } } } return $eventFilePaths; }
/** * Callback * * Deletes file corresponding to record as well as generated versions of that file. * * If the file couldn't be deleted the callback won't stop the * delete operation to continue to delete the record. * * @param Model $Model * @param boolean $cascade * @return boolean */ function beforeDelete(&$Model, $cascade = true) { extract($this->settings[$Model->alias]); $query = array('conditions' => array('id' => $Model->id), 'fields' => array('dirname', 'basename'), 'recursive' => -1); $result = $Model->find('first', $query); if (empty($result)) { return false; /* Record did not pass verification? */ } $file = $baseDirectory; $file .= $result[$Model->alias]['dirname']; $file .= DS . $result[$Model->alias]['basename']; $File = new File($file); $Folder = new Folder($filterDirectory); list($versions, ) = $Folder->ls(); foreach ($versions as $version) { $Folder->cd($filterDirectory . $version . DS . $result[$Model->alias]['dirname'] . DS); $basenames = $Folder->find($File->name() . '\\..*'); if (count($basenames) > 1) { $message = "MediaBehavior::beforeDelete - Ambiguous filename "; $message .= "`" . $File->name() . "` in `" . $Folder->pwd() . "`."; trigger_error($message, E_USER_NOTICE); continue; } elseif (!isset($basenames[0])) { continue; } $FilterFile = new File($Folder->pwd() . $basenames[0]); $FilterFile->delete(); } $File->delete(); return true; }
/** * Reads from the app/locale/default.pot and creates a record for every lanuage * (obtained from folders in app/locale) and msgid. Ideally to be used once development * is finished and the translations should be quickly changeable via db. * * All strings picked up will go in the default domain. * * We don't really need to write to the file, as if they want to make any changes the db save * will write the file. * */ function translations() { // Always use default domain. $domain = 'default'; // Get list of languages. $folder = new Folder(APP . 'locale'); $ls = $folder->ls(true); $languages = $ls[0]; // Read default.pot $file = new File(APP . 'locale' . DS . 'default.pot'); $lines = explode("\n", $file->read()); $totalLines = count($lines); for ($i = 0; $i < $totalLines; $i++) { $line = $lines[$i]; if (strpos($line, 'msgid') === false) { continue; } // Get term $str = preg_match('@msgid "([^"]+)"@', $line, $matches); if (empty($matches[1])) { continue; } $name = $matches[1]; // Save foreach ($languages as $language) { $this->Translation->create(); $conditions = compact('name', 'language', 'domain'); if ($translation = $this->Translation->find('first', compact('conditions'))) { $this->Translation->id = $translation['Translation']['id']; } $this->Translation->save(compact('name', 'language', 'domain')); } } }
function settings() { @($account = $this->data = $this->account); $this->set('account', $account); uses('Folder'); $themes_folder = new Folder(THEMES); $themes = $themes_folder->ls(true, false); $this->set('themes', $themes[0]); $custom_themes_folder = new Folder(USER_THEMES); $custom_themes_templates = $custom_themes_folder->ls(true, array('sample', '.', '..', '.svn')); $this->set('custom_themes', $custom_themes_templates[0]); $lang_folder = new Folder(APP . DS . 'locale'); $langs = $lang_folder->ls(true, false); $this->set('langs', $langs[0]); $templates_folder = new Folder(PLUGS . DS . 'links'); $link_templates = $templates_folder->ls(true, false); $this->set('link_templates', $link_templates[1]); $custom_templates_folder = new Folder(CUSTOM_PLUGS . DS . 'links'); $custom_link_templates = $custom_templates_folder->ls(true, array('sample', '.', '..', '.svn')); $this->set('custom_link_templates', $custom_link_templates[0]); $iptcs = $this->Director->iptcTags; natsort($iptcs); $exifs = $this->Director->exifTags; natsort($exifs); $dirs = $this->Director->dirTags; natsort($dirs); $this->loadModel('Watermark'); $this->set('watermarks', $this->Watermark->find('all')); $this->set('iptcs', $iptcs); $this->set('exifs', $exifs); $this->set('dirs', $dirs); }
function edit($id, $tab = 'settings', $part_id = 0) { $this->cacheAction = 30000; $this->pageTitle = __('Albums', true); $this->Album->id = $id; $this->data = $this->Album->find('first', array('conditions' => array('Album.id' => $id))); if (empty($this->data)) { $this->redirect('/albums'); } switch ($tab) { case 'summary': $this->redirect('/albums/edit/' . $id); break; case 'settings': $this->loadModel('Watermark'); $this->set('watermarks', $this->Watermark->find('all', array('order' => 'main DESC'))); $this->set('galleries', $this->Album->Tag->Gallery->find('all', array('fields' => 'Gallery.id, Gallery.name, Gallery.description', 'order' => 'Gallery.name', 'conditions' => 'Gallery.smart = 0', 'recursive' => -1))); $templates_folder = new Folder(PLUGS . DS . 'links'); $link_templates = $templates_folder->ls(true, false); $this->set('link_templates', $link_templates[1]); $custom_templates_folder = new Folder(CUSTOM_PLUGS . DS . 'links'); $custom_link_templates = $custom_templates_folder->ls(true, array('sample', '.', '..', '.svn')); $this->set('custom_link_templates', $custom_link_templates[0]); $iptcs = $this->Director->iptcTags; natsort($iptcs); $exifs = $this->Director->exifTags; natsort($exifs); $dirs = $this->Director->dirTags; if ($this->data['Album']['smart']) { $dirs = array_merge($dirs, $this->Director->smartTags); } natsort($dirs); $this->set('iptcs', $iptcs); $this->set('exifs', $exifs); $this->set('dirs', $dirs); if ($this->data['Album']['smart']) { list($images, ) = $this->_smart_content(unserialize($this->data['Album']['smart_query'])); $this->set('images', $images); } else { $this->set('images', $this->data['Image']); } break; case 'content': $this->set('load_maps_js', true); $this->set('mp3s', $this->Director->directory(AUDIO, 'mp3,MP3')); if ($this->data['Album']['smart']) { list($images, ) = $this->_smart_content(unserialize($this->data['Album']['smart_query'])); $this->set('images', $images); $this->set('options', unserialize($this->data['Album']['smart_query'])); $this->set('active_dummies', $this->Album->find('all', array('conditions' => array('smart' => 0, 'active' => '1'), 'order' => 'name', 'recursive' => -1, 'fields' => 'Album.id, Album.name'))); } else { $this->set('images', $this->data['Image']); $this->set('other_albums', $this->Album->find('all', array('conditions' => array('not' => array('Album.id' => $id, 'Album.smart' => 1)), 'recursive' => -1, 'fields' => 'Album.id, Album.name', 'order' => 'name'))); $preview_ids = array(); foreach ($this->data['Image'] as $i) { if ($i['is_video']) { if (!empty($i['lg_preview_id'])) { $preview_ids[] = $i['lg_preview_id']; } if (!empty($i['tn_preview_id'])) { $preview_ids[] = $i['tn_preview_id']; } } } $this->set('preview_ids', $preview_ids); } $this->set('selected_id', $part_id); if (function_exists('imagerotate') || $this->Kodak->gdVersion() >= 3) { $rotate = true; } else { $rotate = false; } $this->set('rotate', $rotate); break; case 'upload': if ($this->data['Album']['smart']) { $this->redirect('/albums/edit/' . $this->data['Album']['id'] . '/content'); } $this->set('writable', $this->Director->setAlbumPerms($this->data['Album']['id'])); $this->set('other_writable', $this->Director->setOtherPerms()); if (!TRIAL_STATE) { // Check if any new files have been uploaded via FTP $files = $this->Director->directory(ALBUMS . DS . 'album-' . $this->data['Album']['id'] . DS . 'lg', 'accepted'); $count = count($this->data['Image']); if (count($files) > $count) { set_time_limit(0); $noobs = array(); $n = 1; foreach ($files as $file) { if (strpos($file, '___tn___') === false && strpos($file, '__vidtn__') === false) { $this->Album->Image->recursive = -1; $this->Album->Image->coldSave = true; $img = $this->Album->Image->find(aa('src', $file, 'aid', $id)); if (empty($img)) { $clean = str_replace(" ", "_", $file); $clean = ereg_replace("[^A-Za-z0-9._-]", "_", $clean); $path = ALBUMS . DS . 'album-' . $this->data['Album']['id'] . DS . 'lg' . DS . $file; $clean_path = ALBUMS . DS . 'album-' . $this->data['Album']['id'] . DS . 'lg' . DS . $clean; if (rename($path, $clean_path)) { $path = $clean_path; $file = $clean; } list($meta, $captured_on) = $this->Director->imageMetadata($path); $keywords = $this->Director->parseMetaTags('iptc:keywords', $meta); $keywords = str_replace(' ', ',', urldecode($keywords)); $keywords = ereg_replace("[^,A-Za-z0-9._-]", "", $keywords); $new['Image']['tags'] = $keywords; $new['Image']['aid'] = $id; $new['Image']['src'] = $file; $new['Image']['seq'] = $count + $n; $new['Image']['filesize'] = filesize($path); $new['Image']['captured_on'] = (int) $captured_on; $new['Image']['is_video'] = isVideo($file); $new['Image']['album_active'] = $this->data['Album']['active']; $this->Album->Image->create(); if ($this->Album->Image->save($new)) { $noobs[] = $file; $image_id = $this->Album->Image->getLastInsertId(); } if (is_numeric($this->account['Account']['archive_w'])) { $this->Kodak->develop($path, $path, $this->account['Account']['archive_w'], $this->account['Account']['archive_w'], 100); } if (isVideo($file)) { $ffmpeg = $this->Director->ffmpeg(); if ($ffmpeg) { $info = pathinfo($file); $ext = $info['extension']; $lg_path = $path; exec(FFMPEG_PATH_FINAL . " -i {$lg_path} 2>&1", $out); foreach ($out as $line) { if (strpos($line, 'Duration') !== false) { preg_match('/Duration: ([0-9]{2}):([0-9]{2}):([0-9]{2})/', $line, $matches); list(, $h, $m, $s) = $matches; $duration = $h * 60 * 60 + $m * 60 + $s; continue; } } $duration = $duration - 2; $bits = ceil($duration / 12); if ($bits == 0) { $bits = 1; } $rate = 1 / $bits; if ($rate < 0.1) { $rate = 0.1; } $dir = dirname($lg_path); $i = 1; $cmd = array(); while ($i < $duration) { $i_str = str_pad($i, 5, '0', STR_PAD_LEFT); $cmd[] = FFMPEG_PATH_FINAL . " -ss {$i} -r 1 -i {$lg_path} -vframes 1 -an -f mjpeg {$dir}/__vidtn__{$image_id}_{$i_str}.jpg"; $i += $bits; } $cmd = join(' && ', $cmd); exec($cmd); $thumbs = glob($dir . DS . "__vidtn__{$image_id}_*.jpg"); $tn_file = $lg_path . '.jpg'; if (!empty($thumbs)) { copy($thumbs[0], $tn_file); } if (file_exists($tn_file)) { $n++; $vdata = array(); $vdata['Image']['src'] = $file . '.jpg'; $vdata['Image']['aid'] = $id; $vdata['Image']['seq'] = $count + $n; $vdata['Image']['filesize'] = filesize($tn_file); $vdata['Image']['active'] = 0; $vdata['Image']['is_video'] = 0; $this->Album->Image->create(); $this->Album->Image->save($vdata); $pdata = array(); $pdata['Image']['lg_preview_id'] = $this->Album->Image->getLastInsertId(); $pdata['Image']['lg_preview'] = $file . '.jpg:50:50'; $this->Album->Image->create(null); $this->Album->Image->id = $image_id; $this->Album->Image->save($pdata); } } } $n++; } $this->Album->Image->coldSave = false; } } if (count($noobs) > 0) { $this->Album->id = $this->data['Album']['id']; $this->Album->reorder($id); $this->Album->cacheQueries = false; $this->data = $this->Album->read(); $this->Album->saveField('images_count', $count + count($noobs)); $this->Album->refreshSmartCounts(); $this->set('noobs', $noobs); } } } break; } $this->set('all_albums', $this->Album->find('all', array('order' => 'name', 'recursive' => -1, 'fields' => 'Album.id, Album.name'))); $this->set('all_count', $this->Album->find('count', array('conditions' => array('not' => array('Album.id' => $id)), 'recursive' => -1, 'fields' => 'id'))); $this->set('album', $this->data); $this->set('tab', $tab); }
/** * Checks to see if the temporary plugin folder exists * and creates it if it does not * * @return void * @author Jose Diaz-Gonzalez **/ function __checkPluginFolder() { $tempHandler = new Folder(); $tempPath = trim(TMP); $pluginPath = trim(TMP . 'plugins'); $tempHandler->cd($tempPath); $temp = $tempHandler->ls(); foreach ($temp[0] as $tempFolder) { if ($tempFolder !== 'plugins') { $tempHandler->create($pluginPath); } } }
/** * moves the file to the desired location from the temp directory * @return boolean true if the file was successfully moved from the temporary directory to the desired destination on the filesystem */ function write() { // Include libraries if (!class_exists('Folder')) { uses('folder'); } $moved = false; $folder = new Folder($this->uploadpath, true, 0755); if (!$folder) { $this->setError(1500, 'File system save failed.', 'Could not create requested directory: ' . $this->uploadpath); } else { if (!$this->overwrite) { $contents = $folder->ls(); //get directory contents $this->filename = $this->findUniqueFilename($contents[1]); //pass the file list as an array } if (!($moved = move_uploaded_file($this->params['form']['Filedata']['tmp_name'], $this->uploadpath . $this->filename))) { $this->setError(1000, 'File system save failed.'); } } return $moved; }
/** * Retorna um array com todos os plugins instalados */ function _list() { $Folder = new Folder($this->params['working'] . DS . 'plugins'); $listPluginsFolder = $Folder->ls(); return $listPluginsFolder[0]; }