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);
     }
 }
Exemple #2
0
 /**
  * all method
  *
  * @param bool $includeCore false
  * @param array $exclude array()
  * @return void
  * @access public
  */
 public function all($types = null, $params = array())
 {
     $max = ini_get('max_execution_time');
     if ($max) {
         set_time_limit(30);
     }
     extract(am(array('includeCore' => false, 'plugin' => false, 'extension' => 'php', 'excludeFolders' => array('tests'), 'excludePattern' => '@jquery[\\\\/]|jquery-ui[\\\\/]|simpletest[\\\\/]|[\\\\/]index.php\\|[\\\\/]test.php@'), $params));
     if ($plugin && $plugin === basename(APP) && !is_dir(APP . DS . 'plugins')) {
         $plugin = false;
     }
     if (!$types) {
         $types = array('Component', 'Controller', 'Behavior', 'Datasource', 'Model', 'Helper', 'Shell', 'Vendor', 'Plugin');
     } elseif (!is_array($types)) {
         $types = array($types);
     }
     $allFiles = array();
     $files = array();
     $return = array();
     $pattern = '.*\\.(' . implode('|', (array) $extension) . ')';
     foreach ($types as $type) {
         if (isset(Mi::$extraExcludes[$type])) {
             $excludeFolders = array_unique(am($excludeFolders, Mi::$extraExcludes[$type]));
         }
         $files[$type] = array();
         $paths = Mi::paths($type, compact('plugin'));
         if (!$includeCore) {
             foreach ($paths as $i => $path) {
                 if (strpos($path, DS . 'cake' . DS . 'libs') !== false) {
                     unset($paths[$i]);
                 }
             }
         }
         if ($type === 'Shell') {
             $vPaths = Mi::paths('Vendor');
             foreach ($vPaths as &$vPath) {
                 $vPath = $vPath . 'shells' . DS;
             }
             $paths = am($vPaths, $paths);
         }
         foreach ($paths as $i => $path) {
             if (rtrim($path, DS) == rtrim(APP, DS)) {
                 $folder = new Folder(APP);
                 $tFiles = $folder->find(strtolower($type) . '.*php');
             } elseif ($type === 'View') {
                 $tFiles = Mi::files($path, $excludeFolders, '.*ctp');
             } else {
                 $tFiles = Mi::files($path, $excludeFolders, $pattern);
             }
             if ($allFiles) {
                 $tFiles = array_diff($tFiles, $allFiles);
             }
             foreach ($tFiles as $i => $file) {
                 if ($excludePattern && preg_match($excludePattern, $file)) {
                     unset($tFiles[$i]);
                 }
             }
             $allFiles = am($allFiles, $tFiles);
             $files[$type] = am($files[$type], $tFiles);
         }
         $folder = new Folder(APP);
         $tFiles = $folder->find($pattern);
         $tFiles = array_diff($tFiles, $allFiles);
         foreach ($tFiles as $i => $file) {
             if ($excludePattern && preg_match($excludePattern, $file)) {
                 unset($tFiles[$i]);
             }
         }
         $allFiles = am($allFiles, $tFiles);
         if ((array) $extension != array('php')) {
             foreach ($files[$type] as $file) {
                 $name = preg_replace('@.*vendors[\\\\/]@', '', $file);
                 if (isset($return[$name])) {
                     continue;
                 }
                 $return[$name] = $file;
             }
             return $return;
         }
         foreach ($files[$type] as $file) {
             if (strpos($file, '.ctp')) {
                 $name = str_replace('.ctp', '', $file);
                 $name = preg_replace('@.*views[\\\\/]@', '', $name);
             } else {
                 if ($type === 'Plugin') {
                     foreach ($types as $_type) {
                         if (strpos($file, strtolower($_type))) {
                             $suffix = $_type;
                             break;
                         }
                     }
                     if ($suffix === 'Model') {
                         $suffix = '';
                     }
                 } else {
                     $suffix = '';
                 }
                 $name = preg_replace('@.(' . implode('|', (array) $extension) . ')$@', '', basename($file));
                 $name = str_replace('_controller.', '.', $name);
                 $name = str_replace('_model.', '.', $name);
                 $name = str_replace('_helper.', '.', $name);
                 if ($type === 'Model') {
                     $type = '';
                 }
                 $name = Inflector::Camelize($name) . $type . $suffix;
             }
             if (isset($return[$name])) {
                 continue;
             }
             $return[$name] = $file;
         }
     }
     if ($includeCore) {
         $tFiles = Mi::files(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS, $excludeFolders);
         $tFiles = array_diff($tFiles, $allFiles);
         foreach ($tFiles as $i => $file) {
             if ($excludePattern && preg_match($excludePattern, $file)) {
                 unset($tFiles[$i]);
             }
         }
         $allFiles = am($allFiles, $tFiles);
         foreach ($tFiles as $file) {
             $name = str_replace('.php', '', basename($file));
             $name = str_replace('_controller', '', $name);
             $name = str_replace('_model', '', $name);
             $name = str_replace('_helper', '', $name);
             if ($type === 'Model') {
                 $type = '';
             }
             $name = Inflector::Camelize($name);
             if (isset($return[$name])) {
                 continue;
             }
             $return[$name] = $file;
         }
     }
     ksort($return);
     return array_flip($return);
 }
Exemple #3
0
 /**
  * get the parent for this object based on the nesting model types
  * @return SCAR_Generic or false
  **/
 public function getParent()
 {
     if (!$this->hasParent()) {
         return false;
     }
     // do sql
     $this->doSQL();
     // if we don't know who we are, throw an exception
     // can't multiplex children
     if (!$this->whoAmI()) {
         throw new SCAR_Method_Call_Exception('getParent', $this);
     }
     if ($this->_data['acts_as_materialized_path']) {
         $scar = call_user_func_array(array($this->getSCAR(), 'get'), array($this->getName()));
         $call = 'by' . Inflector::Camelize($this->_data['acts_as_materialized_path']);
         $path = substr($this->path, 0, strrpos($this->path, '/', -2) + 1);
         var_dump($this->id . ' ' . $path);
         $scar->{$call}($path);
         // path minus last node
         return $scar;
     }
 }
 function go($Plugin, $confirmed = false, $stuffList = array(), $excludeList = array())
 {
     $this->plugin = $Plugin;
     $this->PluginName = Inflector::Camelize($Plugin);
     // Plugin App controller handled seperately
     array_push($excludeList, 'plugins' . DS . $this->plugin . DS . $this->plugin . '_app_controller.php');
     // Include the components used to download the plugin, in the hope that other's might do the same :)
     array_push($stuffList, APP . 'controllers' . DS . 'components' . DS . 'download_plugin.php');
     array_push($stuffList, APP . 'controllers' . DS . 'components' . DS . 'zip.php');
     uses("Folder");
     if ($confirmed == false) {
         $this->controller->viewPath = '_generic';
         $this->controller->layout = 'flash';
         $this->controller->set('pause', 5);
         $this->controller->set('url', '/' . $this->PluginName . '/' . $this->controller->name . '/' . $this->controller->action . '/confirmed');
         $this->controller->set('message', 'Your download will begin in 5 seconds.');
         $this->controller->set('pluginUnderscore', $Plugin);
         $this->controller->set('pluginCamel', $this->PluginName);
         $this->controller->set('plugin', Inflector::Humanize($Plugin));
         $date = $this->getLastUpdated($Plugin, $stuffList);
         $this->controller->set('last_updated', $date);
         $this->controller->render('download');
         die;
     }
     $Folder = new Folder(APP . "plugins" . DS . $this->plugin . DS);
     $FileList = $Folder->findRecursive();
     $pattern = "@//--Private[^\\@]*//--Private End@U";
     // include adapated app controller
     $pluginApp = file_get_contents(APP . 'plugins' . DS . $this->plugin . DS . $this->plugin . '_app_controller.php');
     $pluginApp = r("<?php", "<?php\r\ninclude('noswad_controller.php');", $pluginApp);
     $pluginApp = r("extends AppController", "extends NoswadController", $pluginApp);
     $pluginApp = preg_replace($pattern, '', $pluginApp);
     $this->Zip->addData($pluginApp, 'plugins' . DS . $this->plugin . DS . $this->plugin . '_app_controller.php');
     // include every file from the stuff list, but put it in the plugin unless it's from the webroot
     foreach ($stuffList as $file) {
         if (strstr($file, APP_DIR)) {
             $relativePath = substr($file, strlen(APP));
             $relativePath = 'plugins' . DS . $this->plugin . DS . $relativePath;
         } else {
             $relativePath = "webroot" . DS . substr($file, strlen(WWW_ROOT));
         }
         if (!in_array($relativePath, $excludeList) && file_exists($file)) {
             $addedFiles[] = $relativePath;
             $FileContents = file_get_contents($file);
             $FileContents = preg_replace($pattern, '', $FileContents);
             $this->Zip->addData($FileContents, $relativePath);
             /*
             		        $this->Zip->addFile(
             	$file,
             					$relativePath
             );
             */
         }
     }
     // include every file from the plugin
     foreach ($FileList as $file) {
         $relativePath = substr($file, strlen(APP));
         if (!in_array($relativePath, $excludeList) && file_exists($file)) {
             $addedFiles[] = $relativePath;
             $FileContents = file_get_contents($file);
             $FileContents = preg_replace($pattern, '', $FileContents);
             $this->Zip->addData($FileContents, $relativePath);
             /*
             		        $this->Zip->addFile(
             	$file,
             					$relativePath
             );
             */
         }
     }
     // include every file from the generic include folder
     if ($this->genericPath) {
         $Folder = new Folder($this->genericPath);
         $FileList = $Folder->findRecursive();
         foreach ($FileList as $file) {
             $relativePath = substr($file, strlen($this->genericPath));
             if ($relativePath != 'read_me.txt') {
                 $relativePath = 'plugins' . DS . $this->plugin . DS . $relativePath;
             }
             if (!in_array($relativePath, $addedFiles)) {
                 // Allow for overriding of included content
                 $this->Zip->addFile($file, $relativePath);
             }
         }
     }
     $this->Zip->forceDownload($this->PluginName . '.zip');
 }