getFiles() публичный Метод

Get the files.
public getFiles ( ) : array
Результат array
Пример #1
0
 /**
  * Create a new config model object
  *
  * @param array $data
  * @return Config
  */
 public function __construct(array $data = [])
 {
     parent::__construct($data);
     $server = new Server();
     $config = Table\Config::getConfig();
     $distro = $server->getDistro();
     $this->data['overview'] = ['version' => \Phire\Module::VERSION, 'domain' => $config['domain'], 'document_root' => $config['document_root'], 'base_path' => BASE_PATH == '' ? ' ' : BASE_PATH, 'application_path' => APP_PATH == '' ? ' ' : APP_PATH, 'content_path' => CONTENT_PATH, 'modules_path' => MODULES_PATH, 'operating_system' => $server->getOs() . (!empty($distro) ? ' (' . $distro . ')' : null), 'software' => $server->getServer() . ' ' . $server->getServerVersion(), 'database_version' => Table\Config::db()->version(), 'php_version' => $server->getPhp(), 'installed_on' => $config['installed_on'] != '0000-00-00 00:00:00' ? date($config['datetime_format'], strtotime($config['installed_on'])) : '', 'updated_on' => $config['updated_on'] != '0000-00-00 00:00:00' ? date($config['datetime_format'], strtotime($config['updated_on'])) : ''];
     $config['datetime_formats'] = ['M j Y', 'F d, Y', 'm/d/Y', 'Y/m/d', 'F d, Y g:i A', 'M j Y g:i A', 'm/d/Y g:i A', 'Y/m/d g:i A'];
     $config['system_themes'] = [];
     $config['custom_system_themes'] = [];
     $dir = new Dir(__DIR__ . '/../../data/themes');
     foreach ($dir->getFiles() as $file) {
         if ($file != 'index.html') {
             $config['system_themes'][$file] = $file;
         }
     }
     if (isset($_SERVER['DOCUMENT_ROOT'])) {
         $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/phire/themes');
         foreach ($dir->getFiles() as $file) {
             if ($file != 'index.html') {
                 $config['custom_system_themes'][$file] = $file;
             }
         }
     }
     sort($config['system_themes']);
     sort($config['custom_system_themes']);
     $this->data['config'] = $config;
     $this->data['modules'] = Table\Modules::findAll(['order' => 'id DESC', 'limit' => 5])->rows();
 }
Пример #2
0
 public function testFiles()
 {
     $d = new Dir(__DIR__ . '/../tmp/');
     $this->assertEquals(15, count($d->getFiles()));
     $d = new Dir(__DIR__ . '/../tmp/', true);
     $this->assertEquals(15, count($d->getFiles()));
     $d = new Dir(__DIR__ . '/../tmp/', true, true);
     $this->assertEquals(15, count($d->getFiles()));
     $d = new Dir(__DIR__ . '/../tmp/', true, true, true);
     $this->assertEquals(15, count($d->getFiles()));
 }
Пример #3
0
 public function testZipExtract()
 {
     if (class_exists('ZipArchive', false)) {
         $a = new Archive(__DIR__ . '/../tmp/test.zip');
         $a->addFiles(__DIR__ . '/../tmp');
         mkdir(__DIR__ . '/../tmp/test');
         chmod(__DIR__ . '/../tmp/test', 0777);
         chmod(__DIR__ . '/../tmp/test.zip', 0777);
         $a->extract(__DIR__ . '/../tmp/test');
         unset($a);
         $dir = new Dir(__DIR__ . '/../tmp/test');
         $this->assertGreaterThan(0, count($dir->getFiles()));
         $dir->emptyDir();
         rmdir(__DIR__ . '/../tmp/test');
         if (file_exists(__DIR__ . '/../tmp/test.zip')) {
             unlink(__DIR__ . '/../tmp/test.zip');
         }
     }
 }
Пример #4
0
 /**
  * Bootstrap the module
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     if ($application->isRegistered('phire-content')) {
         $theme = Table\Themes::findBy(['active' => 1]);
         if (isset($theme->id)) {
             $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $theme->folder, ['filesOnly' => true]);
             $parentDir = null;
             if (null !== $theme->parent_id) {
                 $parentTheme = Table\Themes::findById($theme->parent_id);
                 if (isset($parentTheme->id)) {
                     $parentDir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $parentTheme->folder, ['filesOnly' => true]);
                 }
             }
             $forms = $application->config()['forms'];
             if (null !== $parentDir) {
                 $dirFiles = $dir->getFiles();
                 foreach ($dirFiles as $file) {
                     if (strpos($file, '.ph') !== false && !in_array($file, $application->module('phire-themes')['invisible'])) {
                         $forms['Phire\\Content\\Form\\Content'][0]['content_template']['value'][$file] = $file;
                     }
                 }
                 foreach ($parentDir->getFiles() as $file) {
                     if (!in_array($file, $dirFiles) && strpos($file, '.ph') !== false && !in_array($file, $application->module('phire-themes')['invisible'])) {
                         $forms['Phire\\Content\\Form\\Content'][0]['content_template']['value'][$file] = $file . ' (parent)';
                     }
                 }
             } else {
                 foreach ($dir->getFiles() as $file) {
                     if (strpos($file, '.ph') !== false && !in_array($file, $application->module('phire-themes')['invisible'])) {
                         $forms['Phire\\Content\\Form\\Content'][0]['content_template']['value'][$file] = $file;
                     }
                 }
             }
             $application->mergeConfig(['forms' => $forms], true);
         }
     }
 }
Пример #5
0
 public function testSaveTo()
 {
     $m = new Mail('Subject', array('name' => 'Bob Smith', 'email' => '*****@*****.**'), 'Hello World');
     $m->setHtml('Hello');
     $m->setText('Hello');
     $m->saveTo(__DIR__ . '/../tmp');
     $d = new Dir(__DIR__ . '/../tmp');
     $files = $d->getFiles();
     $exists = false;
     foreach ($files as $file) {
         if (strpos($file, 'popphpmail') !== false) {
             $exists = true;
             unlink(__DIR__ . '/../tmp/' . $file);
         }
     }
     $this->assertTrue($exists);
 }
Пример #6
0
 public function getHistory($filename)
 {
     $history = [];
     $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/image-history');
     foreach ($dir->getFiles() as $file) {
         if ($file == $filename) {
             $history[] = $file;
         } else {
             if (strpos($file, '_') !== false) {
                 $basename = str_replace(['-', '_'], ['\\-', '\\_'], substr($filename, 0, strrpos($filename, '.')));
                 $ext = substr($filename, strrpos($filename, '.') + 1);
                 $regex = '/(' . $basename . ')\\_+(\\d.*)\\.' . $ext . '/';
                 if (preg_match($regex, $file)) {
                     $history[] = $file;
                 }
             }
         }
     }
     sort($history, SORT_NATURAL);
     return $history;
 }
Пример #7
0
 /**
  * Static method to get a file icon
  *
  * @param string $fileName
  * @param string $dir
  * @return array
  */
 public static function getFileIcon($fileName, $dir = null)
 {
     if (null === $dir) {
         $dir = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/media';
     }
     $iconDir = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/img/';
     $ext = strtolower(substr($fileName, strrpos($fileName, '.') + 1));
     if ($ext == 'docx' || $ext == 'pptx' || $ext == 'xlsx') {
         $ext = substr($ext, 0, 3);
     }
     // If the file type is an image file type
     if (preg_match(self::$imageRegex, $fileName)) {
         $ext = strtolower(substr($fileName, strrpos($fileName, '.') + 1));
         if ($ext == 'ai' || $ext == 'eps' || $ext == 'pdf' || $ext == 'psd') {
             $newFileName = $fileName . '.jpg';
         } else {
             $newFileName = $fileName;
         }
         // Get the icon or the image file, searching for the smallest image file
         $dirs = new Dir($dir, true);
         $fileSizes = array();
         foreach ($dirs->getFiles() as $d) {
             if (is_dir($d)) {
                 $f = $d . $newFileName;
                 if (file_exists($f)) {
                     $f = str_replace('\\', '//', $f);
                     $fileSizes[filesize($f)] = substr($f, strpos($f, '/media') + 6);
                 }
             }
         }
         // If image files are found, get smallest image file
         if (count($fileSizes) > 0) {
             ksort($fileSizes);
             $vals = array_values($fileSizes);
             $smallest = array_shift($vals);
             $fileIcon = '/media' . $smallest;
             // Else, use filetype icon
         } else {
             if (file_exists($iconDir . 'icons/50x50/' . $ext . '.png')) {
                 $fileIcon = '/assets/img/icons/50x50/' . $ext . '.png';
                 // Else, use generic file icon
             } else {
                 $fileIcon = '/assets/img/icons/50x50/img.png';
             }
         }
         // Else, if file type is a file type with an available icon
     } else {
         if (file_exists($iconDir . 'icons/50x50/' . $ext . '.png')) {
             $fileIcon = '/assets/img/icons/50x50/' . $ext . '.png';
             // Else, if file type is an audio file type with an available icon
         } else {
             if ($ext == 'wav' || $ext == 'aif' || $ext == 'aiff' || $ext == 'mp3' || $ext == 'mp2' || $ext == 'flac' || $ext == 'wma' || $ext == 'aac' || $ext == 'swa') {
                 $fileIcon = '/assets/img/icons/50x50/aud.png';
                 // Else, if file type is an video file type with an available icon
             } else {
                 if ($ext == '3gp' || $ext == 'asf' || $ext == 'avi' || $ext == 'mpg' || $ext == 'm4v' || $ext == 'mov' || $ext == 'mpeg' || $ext == 'wmv') {
                     $fileIcon = '/assets/img/icons/50x50/vid.png';
                     // Else, if file type is a generic image file type with an available icon
                 } else {
                     if ($ext == 'bmp' || $ext == 'ico' || $ext == 'tiff' || $ext == 'tif') {
                         $fileIcon = '/assets/img/icons/50x50/img.png';
                         // Else, use the generic file icon
                     } else {
                         $fileIcon = '/assets/img/icons/50x50/file.png';
                     }
                 }
             }
         }
     }
     // Get file size
     if (file_exists($dir . DIRECTORY_SEPARATOR . $fileName)) {
         $fileSize = filesize($dir . DIRECTORY_SEPARATOR . $fileName);
         if ($fileSize > 999999) {
             $fileSize = round($fileSize / 1000000, 2) . ' MB';
         } else {
             if ($fileSize > 999) {
                 $fileSize = round($fileSize / 1000, 2) . ' KB';
             } else {
                 $fileSize = ' < 1 KB';
             }
         }
     } else {
         $fileSize = '';
     }
     return array('fileIcon' => $fileIcon, 'fileSize' => $fileSize);
 }
Пример #8
0
 public function testTbz2Extract()
 {
     $tar = false;
     $includePath = explode(PATH_SEPARATOR, get_include_path());
     foreach ($includePath as $path) {
         if (file_exists($path . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . 'Tar.php')) {
             $tar = true;
         }
     }
     if ($tar && function_exists('bzopen')) {
         $a = new Archive(__DIR__ . '/../tmp/test.tar');
         $a->addFiles(__DIR__ . '/../tmp');
         $a->compress('bz2');
         chmod(__DIR__ . '/../tmp/test.tar.bz2', 0777);
         unset($a);
         $a = new Archive(__DIR__ . '/../tmp/test.tar.bz2');
         mkdir(__DIR__ . '/../tmp/test');
         chmod(__DIR__ . '/../tmp/test', 0777);
         $a->extract(__DIR__ . '/../tmp/test');
         $dir = new Dir(__DIR__ . '/../tmp/test');
         $this->assertGreaterThan(0, count($dir->getFiles()));
         $dir->emptyDir();
         rmdir(__DIR__ . '/../tmp/test');
         if (file_exists(__DIR__ . '/../tmp/test.tar')) {
             unlink(__DIR__ . '/../tmp/test.tar');
         }
         if (file_exists(__DIR__ . '/../tmp/test.tar.bz2')) {
             unlink(__DIR__ . '/../tmp/test.tar.bz2');
         }
     }
 }
Пример #9
0
 /**
  * Method to create an archive file
  *
  * @param  string|array $files
  * @return void
  */
 public function addFiles($files)
 {
     if (!is_array($files)) {
         $files = array($files);
     }
     foreach ($files as $file) {
         // If file is a directory, loop through and add the files.
         if (file_exists($file) && is_dir($file)) {
             $realpath = realpath($file);
             $dir = new Dir($file, true, true);
             $dirFiles = $dir->getFiles();
             foreach ($dirFiles as $fle) {
                 if (file_exists($fle) && !is_dir($fle)) {
                     $fle = $file . DIRECTORY_SEPARATOR . str_replace($realpath . DIRECTORY_SEPARATOR, '', $fle);
                     $this->archive->add($fle);
                 }
             }
             // Else, just add the file.
         } else {
             if (file_exists($file)) {
                 $this->archive->add($file);
             }
         }
     }
 }
Пример #10
0
 /**
  * Upload template
  *
  * @param  array $file
  * @return void
  */
 public function upload($file)
 {
     $templatePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/templates';
     if (!file_exists($templatePath)) {
         mkdir($templatePath);
         chmod($templatePath, 0777);
         if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/index.html')) {
             copy($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/index.html', $templatePath . '/index.html');
             chmod($templatePath . '/index.html', 0777);
         }
     }
     $upload = new Upload($templatePath);
     $template = $upload->upload($file);
     $formats = Archive::getFormats();
     if (file_exists($templatePath . '/' . $template)) {
         $ext = null;
         $name = null;
         if (substr($template, -4) == '.zip') {
             $ext = 'zip';
             $name = substr($template, 0, -4);
         } else {
             if (substr($template, -4) == '.tgz') {
                 $ext = 'tgz';
                 $name = substr($template, 0, -4);
             } else {
                 if (substr($template, -7) == '.tar.gz') {
                     $ext = 'tar.gz';
                     $name = substr($template, 0, -7);
                 }
             }
         }
         if (null !== $ext && null !== $name && array_key_exists($ext, $formats)) {
             $archive = new Archive($templatePath . '/' . $template);
             $archive->extract($templatePath);
             if (stripos($template, 'gz') !== false && file_exists($templatePath . '/' . $name . '.tar')) {
                 unlink($templatePath . '/' . $name . '.tar');
             }
             if (file_exists($templatePath . '/' . $name)) {
                 $dir = new Dir($templatePath . '/' . $name, ['filesOnly' => true]);
                 foreach ($dir->getFiles() as $file) {
                     if (substr($file, -5) == '.html') {
                         $isVisible = stripos($file, 'category') === false && stripos($file, 'error') === false && stripos($file, 'tag') === false && stripos($file, 'search') === false && stripos($file, 'sidebar') === false && stripos($file, 'header') === false && stripos($file, 'footer') === false;
                         $template = new Table\Templates(['parent_id' => null, 'name' => ucwords(str_replace(['-', '_'], [' ', ' '], substr(strtolower($file), 0, -5))), 'device' => 'desktop', 'template' => file_get_contents($templatePath . '/' . $name . '/' . $file), 'history' => null, 'visible' => (int) $isVisible]);
                         $template->save();
                     }
                 }
             }
         }
     }
 }
Пример #11
0
 /**
  * Detect new modules
  *
  * @param  boolean $count
  * @return mixed
  */
 public function detectNew($count = true)
 {
     $modulesPath = MODULES_ABS_PATH;
     $installed = [];
     $newModules = [];
     if (file_exists($modulesPath)) {
         $modules = Table\Modules::findAll();
         if (strpos($modulesPath, 'vendor') !== false) {
             foreach ($modules->rows() as $module) {
                 $installed[] = $module->folder;
             }
             $dir = new Dir($modulesPath);
             foreach ($dir->getFiles() as $file) {
                 if (!in_array($file, $installed)) {
                     $newModules[] = $file;
                 }
             }
         } else {
             foreach ($modules->rows() as $module) {
                 $installed[] = $module->file;
             }
             $dir = new Dir($modulesPath, ['filesOnly' => true]);
             foreach ($dir->getFiles() as $file) {
                 if ((substr($file, -4) == '.zip' || substr($file, -4) == '.tgz' || substr($file, -7) == '.tar.gz') && !in_array($file, $installed)) {
                     $newModules[] = $file;
                 }
             }
         }
     }
     if (count($newModules) > 0) {
         $priority = [];
         foreach ($newModules as $i => $new) {
             $newMod = substr($new, 0, strrpos($new, '-'));
             if (in_array($newMod, $this->priority)) {
                 $priority[] = $new;
                 unset($newModules[$i]);
             }
         }
         if (count($priority) > 0) {
             $newModules = array_merge($priority, $newModules);
         }
     }
     return $count ? count($newModules) : $newModules;
 }
Пример #12
0
 /**
  * Parse actions
  *
  * @param  string $folder
  * @return array
  */
 protected function parseActions($folder)
 {
     $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder);
     $curDirs = [];
     $newDirs = [];
     foreach ($dir->getFiles() as $file) {
         if (is_dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $file)) {
             $curDirs[] = $file;
         }
     }
     $actions = [];
     foreach ($_POST as $key => $value) {
         if (substr($key, 0, 12) == 'action_name_') {
             $id = substr($key, strrpos($key, '_') + 1);
             if (!empty($_POST['action_name_' . $id]) && $_POST['action_method_' . $id] != '----' && !empty($_POST['action_params_' . $id])) {
                 $actions[$_POST['action_name_' . $id]] = ['method' => $_POST['action_method_' . $id], 'params' => $_POST['action_params_' . $id], 'quality' => !empty($_POST['action_quality_' . $id]) ? (int) $_POST['action_quality_' . $id] : 80];
                 if (!file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $_POST['action_name_' . $id])) {
                     mkdir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $_POST['action_name_' . $id]);
                     chmod($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $_POST['action_name_' . $id], 0777);
                     copy($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'index.html', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $_POST['action_name_' . $id] . DIRECTORY_SEPARATOR . 'index.html');
                 }
                 $newDirs[] = $_POST['action_name_' . $id];
             }
         }
     }
     // Clean up directories
     foreach ($curDirs as $dir) {
         if (!in_array($dir, $newDirs)) {
             $d = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $dir);
             $d->emptyDir(true);
         }
     }
     return $actions;
 }
Пример #13
0
 /**
  * Process and save seo config
  *
  * @param  array $exclude
  * @return void
  */
 public function saveAnalysis(array $exclude = [])
 {
     $config = Table\Config::findById('seo_config');
     $cfg = isset($config->value) && !empty($config->value) && $config->value != '' ? unserialize($config->value) : [];
     $analysis = ['tracking' => false, 'sitemap' => false, 'robots' => false, 'caching' => false, 'site-verify' => false, 'content' => ['good' => [], 'bad' => []]];
     if (!empty($cfg['tracking']) && $cfg['tracking'] != '') {
         $analysis['tracking'] = true;
     }
     $sitemap = \Phire\Table\Modules::findBy(['name' => 'phire-sitemap']);
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . '/sitemap.xml') || isset($sitemap->id) && $sitemap->active) {
         $analysis['sitemap'] = true;
     }
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . '/robots.txt') || isset($cfg['robots']) && !empty($cfg['robots']) && $cfg['robots'] != '') {
         $analysis['robots'] = true;
     }
     $cacheDetect = false;
     $curl = new Curl('http://' . $_SERVER['HTTP_HOST'] . BASE_PATH);
     if ($curl->getCode() == 200 && null !== $curl->getHeader('Cache-Control') && null !== $curl->getHeader('Expires') && null !== $curl->getHeader('Last-Modified') && null !== $curl->getHeader('Etag')) {
         $cacheDetect = true;
     }
     $cache = \Phire\Table\Modules::findBy(['name' => 'phire-cache']);
     if ($cacheDetect || isset($cache->id) && $cache->active) {
         $analysis['caching'] = true;
     }
     $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH, ['relative' => true, 'filesOnly' => true]);
     $googleFileDetect = false;
     foreach ($dir->getFiles() as $file) {
         if (substr($file, 0, 6) == 'google' && strpos(file_get_contents($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . '/' . $file), 'google-site-verification') !== false) {
             $googleFileDetect = true;
         }
     }
     $googleMetaDetect = false;
     if (isset($cfg['meta'])) {
         foreach ($cfg['meta'] as $meta) {
             if ($meta['name'] == 'google-site-verification') {
                 $googleMetaDetect = true;
             }
         }
     }
     if ($googleFileDetect || $googleMetaDetect) {
         $analysis['site-verify'] = true;
     } else {
         if (function_exists('dns_get_record') && $_SERVER['HTTP_HOST'] != 'localhost') {
             $dns = dns_get_record($_SERVER['HTTP_HOST'], DNS_TXT);
             if (count($dns) > 0) {
                 foreach ($dns as $record) {
                     if (isset($record['txt']) && strpos($record['txt'], 'google-site-verification') !== false) {
                         $analysis['site-verify'] = true;
                     }
                 }
             }
         }
     }
     $fields = ['seo_title' => '', 'description' => '', 'keywords' => ''];
     $seoTitle = \Phire\Fields\Table\Fields::findBy(['name' => 'seo_title']);
     $description = \Phire\Fields\Table\Fields::findBy(['name' => 'description']);
     $keywords = \Phire\Fields\Table\Fields::findBy(['name' => 'keywords']);
     if (isset($seoTitle->id)) {
         $fields['seo_title'] = $seoTitle->id;
     }
     if (isset($description->id)) {
         $fields['description'] = $description->id;
     }
     if (isset($keywords->id)) {
         $fields['keywords'] = $keywords->id;
     }
     $content = \Phire\Content\Table\Content::findAll();
     foreach ($content->rows() as $c) {
         if (!in_array($c->type_id, $exclude)) {
             $seoTitle = '';
             $metaDesc = '';
             $metaKeys = '';
             if ($fields['seo_title'] != '') {
                 $seoTitleField = \Phire\Fields\Table\FieldValues::findById([$fields['seo_title'], $c->id, "Phire\\Content\\Model\\Content"]);
                 if (isset($seoTitleField->field_id)) {
                     $seoTitle = json_decode($seoTitleField->value);
                 }
             }
             if ($fields['description'] != '') {
                 $descriptionField = \Phire\Fields\Table\FieldValues::findById([$fields['description'], $c->id, "Phire\\Content\\Model\\Content"]);
                 if (isset($descriptionField->field_id)) {
                     $metaDesc = json_decode($descriptionField->value);
                 }
             }
             if ($fields['keywords'] != '') {
                 $keywordsField = \Phire\Fields\Table\FieldValues::findById([$fields['keywords'], $c->id, "Phire\\Content\\Model\\Content"]);
                 if (isset($keywordsField->field_id)) {
                     $metaKeys = json_decode($keywordsField->value);
                 }
             }
             if (strlen($seoTitle) > 0 && strlen($seoTitle) <= 60 && strlen($metaDesc) > 0 && strlen($metaDesc) <= 160 && strlen($metaKeys) > 0 && strlen($metaKeys) <= 255) {
                 $analysis['content']['good'][$c->id] = ['title' => $c->title, 'uri' => $c->uri];
             } else {
                 $analysis['content']['bad'][$c->id] = ['title' => $c->title, 'type_id' => $c->type_id, 'uri' => $c->uri, 'issues' => []];
                 if (strlen($seoTitle) == 0) {
                     $analysis['content']['bad'][$c->id]['issues'][] = 'No SEO Title';
                 } else {
                     if (strlen($seoTitle) > 60) {
                         $analysis['content']['bad'][$c->id]['issues'][] = 'SEO Title is too long';
                     }
                 }
                 if (strlen($metaDesc) == 0) {
                     $analysis['content']['bad'][$c->id]['issues'][] = 'No description meta tag';
                 } else {
                     if (strlen($metaDesc) > 160) {
                         $analysis['content']['bad'][$c->id]['issues'][] = 'Description meta tag is too long';
                     }
                 }
                 if (strlen($metaKeys) == 0) {
                     $analysis['content']['bad'][$c->id]['issues'][] = 'No keywords meta tag';
                 } else {
                     if (strlen($metaKeys) > 255) {
                         $analysis['content']['bad'][$c->id]['issues'][] = 'Keywords meta tag is too long';
                     }
                 }
             }
         }
     }
     $config = Table\Config::findById('seo_analysis');
     $config->value = serialize($analysis);
     $config->save();
 }
Пример #14
0
 /**
  * Method to create an archive file
  *
  * @param  string|array $files
  * @return void
  */
 public function addFiles($files)
 {
     if (!is_array($files)) {
         $files = array($files);
     }
     // Directory separator clean up
     $search = array('\\', '../', './');
     $replace = array('/', '', '');
     foreach ($files as $file) {
         // If file is a directory, loop through and add the files.
         if (file_exists($file) && is_dir($file)) {
             $dir = new Dir($file, true, true);
             $this->archive->addEmptyDir(str_replace($search, $replace, $dir->getPath()));
             $dirFiles = $dir->getFiles();
             foreach ($dirFiles as $fle) {
                 if (file_exists($fle) && is_dir($fle)) {
                     $this->archive->addEmptyDir(str_replace($search, $replace, $fle));
                 } else {
                     if (file_exists($fle)) {
                         $this->archive->addFile($fle, str_replace($search, $replace, $fle));
                     }
                 }
             }
             // Else, just add the file.
         } else {
             if (file_exists($file)) {
                 $this->archive->addFile($file, str_replace('\\', '/', $file));
             }
         }
     }
 }
Пример #15
0
 /**
  * Static method to get model types
  *
  * @param  \Pop\Config $config
  * @return array
  */
 public static function getResources($config = null)
 {
     $resources = array();
     $exclude = array();
     $override = null;
     // Get any exclude or override config values
     if (null !== $config) {
         $configAry = $config->asArray();
         if (isset($configAry['exclude_controllers'])) {
             $exclude = $configAry['exclude_controllers'];
         }
         if (isset($configAry['override'])) {
             $override = $configAry['override'];
         }
     }
     // If override, set overridden resources
     if (null !== $override) {
         foreach ($override as $resource) {
             $resources[] = $resource;
         }
         // Else, get all controllers from the system and module directories
     } else {
         $systemDirectory = new Dir(realpath(__DIR__ . '/../../../../'), true);
         $systemModuleDirectory = new Dir(realpath(__DIR__ . '/../../../../../module/'), true);
         $moduleDirectory = new Dir(realpath($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules'), true);
         $dirs = array_merge($systemDirectory->getFiles(), $systemModuleDirectory->getFiles(), $moduleDirectory->getFiles());
         sort($dirs);
         // Dir clean up
         foreach ($dirs as $key => $dir) {
             unset($dirs[$key]);
             if (!(strpos($dir, 'config') !== false || strpos($dir, 'index.html') !== false)) {
                 $k = $dir;
                 if (substr($dir, -1) == DIRECTORY_SEPARATOR) {
                     $k = substr($k, 0, -1);
                 }
                 $k = substr($k, strrpos($k, DIRECTORY_SEPARATOR) + 1);
                 $dirs[$k] = $dir;
             }
         }
         // Loop through each directory, looking for controller class files
         foreach ($dirs as $mod => $dir) {
             if (file_exists($dir . 'src/' . $mod . '/Controller')) {
                 $d = new Dir($dir . 'src/' . $mod . '/Controller', true, true, false);
                 $dFiles = $d->getFiles();
                 sort($dFiles);
                 // If found, loop through the files, getting the methods as the "permissions"
                 foreach ($dFiles as $c) {
                     if (strpos($c, 'index.html') === false && strpos($c, 'Abstract') === false) {
                         // Get all public methods from class
                         $class = str_replace(array('.php', DIRECTORY_SEPARATOR), array('', '\\'), substr($c, strpos($c, 'src') + 4));
                         $code = new \ReflectionClass($class);
                         $methods = $code->getMethods(\ReflectionMethod::IS_PUBLIC);
                         $actions = array();
                         foreach ($methods as $value) {
                             if ($value->getName() !== '__construct' && $value->class == $class) {
                                 $action = $value->getName();
                                 if (!isset($exclude[$class]) || isset($exclude[$class]) && is_array($exclude[$class]) && !in_array($action, $exclude[$class])) {
                                     $actions[] = $action;
                                 }
                             }
                         }
                         $types = array(0 => '(All)');
                         if (strpos($class, "\\Controller\\IndexController") === false) {
                             $classAry = explode('\\', $class);
                             $end1 = count($classAry) - 2;
                             $end2 = count($classAry) - 1;
                             $model = $classAry[0] . '_Model_';
                             if (stripos($classAry[$end2], 'index') !== false) {
                                 $model .= $classAry[$end1];
                             } else {
                                 if (substr($classAry[$end2], 0, 4) == 'Type') {
                                     $model .= $classAry[$end1] . 'Type';
                                 } else {
                                     $model .= str_replace('Controller', '', $classAry[$end2]);
                                 }
                             }
                             if (substr($model, -3) == 'ies') {
                                 $model = substr($model, 0, -3) . 'y';
                             } else {
                                 if (substr($model, -1) == 's') {
                                     $model = substr($model, 0, -1);
                                 }
                             }
                             $types = \Phire\Project::getModelTypes($model);
                             // Format the resource and permissions
                             $c = str_replace(array('Controller.php', '\\'), array('', '/'), $c);
                             $c = substr($c, strpos($c, 'Controller') + 11);
                             $c = str_replace('Phire/', '', $c);
                             if (!in_array($class, $exclude) || isset($exclude[$class]) && is_array($exclude[$class])) {
                                 $resources[$class] = array('name' => $c, 'types' => $types, 'actions' => $actions);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $resources;
 }
Пример #16
0
 /**
  * Load application assets to a public folder
  *
  * @param  string  $from
  * @param  string  $to
  * @param  boolean $import
  * @return Module
  */
 public function loadAssets($from, $to, $import = false)
 {
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets') && is_writable($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets')) {
         $toDir = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $to;
         if (!file_exists($toDir)) {
             mkdir($toDir);
             $dir = new Dir($from, ['absolute' => true, 'recursive' => true]);
             $dir->copyDir($toDir, false);
         }
         $cssDirs = ['css', 'styles', 'style'];
         $jsDirs = ['js', 'scripts', 'script', 'scr'];
         $cssType = $import ? 'import' : 'link';
         foreach ($cssDirs as $cssDir) {
             if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $cssDir)) {
                 $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $cssDir);
                 foreach ($dir->getFiles() as $cssFile) {
                     if ($cssFile != 'index.html') {
                         $css = BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $cssDir . '/' . $cssFile;
                         if (!in_array($css, $this->assets['css'][$cssType]) && substr($css, -4) == '.css' && stripos($css, 'public') === false) {
                             $this->assets['css'][$cssType][] = $css;
                         }
                     }
                 }
             }
         }
         foreach ($jsDirs as $jsDir) {
             if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $jsDir)) {
                 $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $jsDir);
                 foreach ($dir->getFiles() as $jsFile) {
                     if ($jsFile != 'index.html') {
                         $js = BASE_PATH . CONTENT_PATH . '/assets/' . $to . '/' . $jsDir . '/' . $jsFile;
                         if (!in_array($js, $this->assets['js']) && substr($js, -3) == '.js' && stripos($js, 'public') === false) {
                             $this->assets['js'][] = $js;
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
Пример #17
0
 /**
  * Detect new themes
  *
  * @param  boolean $count
  * @return mixed
  */
 public function detectNew($count = true)
 {
     $themePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes';
     $installed = [];
     $newThemes = [];
     if (file_exists($themePath)) {
         $themes = Table\Themes::findAll();
         foreach ($themes->rows() as $theme) {
             $installed[] = $theme->file;
         }
         $dir = new Dir($themePath, ['filesOnly' => true]);
         foreach ($dir->getFiles() as $file) {
             if ((substr($file, -4) == '.zip' || substr($file, -4) == '.tgz' || substr($file, -7) == '.tar.gz') && !in_array($file, $installed)) {
                 $newThemes[] = $file;
             }
         }
     }
     return $count ? count($newThemes) : $newThemes;
 }
Пример #18
0
 /**
  * Determine whether or not the necessary system directories are writable or not.
  *
  * @param  string  $contentDir
  * @param  boolean $msgs
  * @param  string  $docRoot
  * @return boolean|array
  */
 public static function checkDirs($contentDir, $msgs = false, $docRoot = null)
 {
     if (null === $docRoot) {
         $docRoot = $_SERVER['DOCUMENT_ROOT'];
     }
     $dir = new Dir($contentDir, true, true);
     $files = $dir->getFiles();
     $errorMsgs = array();
     // Check if the necessary directories are writable for Windows.
     if (stripos(PHP_OS, 'win') !== false) {
         if (@touch($contentDir . '/writetest.txt') == false) {
             $errorMsgs[] = "The directory " . str_replace($docRoot, '', $contentDir) . " is not writable.";
         } else {
             unlink($contentDir . '/writetest.txt');
             clearstatcache();
         }
         foreach ($files as $value) {
             if (strpos($value, 'data') === false && strpos($value, 'ckeditor') === false && strpos($value, 'tinymce') === false && is_dir($value)) {
                 if (@touch($value . '/writetest.txt') == false) {
                     $errorMsgs[] = "The directory " . str_replace($docRoot, '', $value) . " is not writable.";
                 } else {
                     unlink($value . '/writetest.txt');
                     clearstatcache();
                 }
             }
         }
         // Check if the necessary directories are writable for Unix/Linux.
     } else {
         clearstatcache();
         if (!is_writable($contentDir)) {
             $errorMsgs[] = "The directory " . str_replace($docRoot, '', $contentDir) . " is not writable.";
         }
         foreach ($files as $value) {
             if (strpos($value, 'data') === false && strpos($value, 'ckeditor') === false && strpos($value, 'tinymce') === false && is_dir($value)) {
                 clearstatcache();
                 if (!is_writable($value)) {
                     $errorMsgs[] = "The directory " . str_replace($docRoot, '', $value) . " is not writable.";
                 }
             }
         }
     }
     // If the messaging flag was passed, return any
     // error messages, else return true/false.
     if ($msgs) {
         return $errorMsgs;
     } else {
         return count($errorMsgs) == 0 ? true : false;
     }
 }
Пример #19
0
 /**
  * Get uploaded images
  *
  * @param  string $dir
  * @return array
  */
 public function getAllImages($dir)
 {
     $images = [];
     $d = new Dir($_SERVER['DOCUMENT_ROOT'] . $dir, ['filesOnly' => true]);
     foreach ($d->getFiles() as $file) {
         if ($file != 'index.html' && preg_match('/^.*\\.(jpg|jpeg|png|gif)$/i', $file) == 1) {
             $images[$dir . '/' . $file] = $file;
         }
     }
     return $images;
 }
Пример #20
0
 /**
  * Process batch archive file
  *
  * @param  string $file
  * @param  array  $fields
  * @return void
  */
 public function processBatch($file, array $fields)
 {
     $tmp = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp';
     mkdir($tmp);
     chmod($tmp, 0777);
     $batchFileName = (new Upload($tmp))->upload($file);
     $archive = new Archive($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $batchFileName);
     $archive->extract($tmp);
     if (stripos($archive->getFilename(), '.tar') !== false && $archive->getFilename() != $batchFileName && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $archive->getFilename())) {
         unlink($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $archive->getFilename());
     }
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $batchFileName)) {
         unlink($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $batchFileName);
     }
     $library = new MediaLibrary();
     $library->getById($fields['library_id']);
     $settings = $library->getSettings();
     $dir = new Dir($tmp, ['absolute' => true, 'recursive' => true, 'filesOnly' => true]);
     $upload = new Upload($settings['folder'], $settings['max_filesize'], $settings['disallowed_types'], $settings['allowed_types']);
     foreach ($dir->getFiles() as $file) {
         $basename = basename($file);
         $testFile = ['name' => $basename, 'size' => filesize($file), 'error' => 0];
         if ($upload->test($testFile)) {
             $fileName = $upload->checkFilename($basename);
             copy($file, $settings['folder'] . '/' . $fileName);
             $title = ucwords(str_replace(['_', '-'], [' ', ' '], substr($fileName, 0, strrpos($fileName, '.'))));
             if (null !== $library->adapter) {
                 $class = 'Pop\\Image\\' . $library->adapter;
                 $formats = array_keys($class::getFormats());
                 $fileParts = pathinfo($fileName);
                 if (!empty($fileParts['extension']) && in_array(strtolower($fileParts['extension']), $formats)) {
                     $this->processImage($fileName, $library);
                 }
             }
             $media = new Table\Media(['library_id' => $fields['library_id'], 'title' => $title, 'file' => $fileName, 'size' => filesize($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $library->folder . DIRECTORY_SEPARATOR . $fileName), 'uploaded' => date('Y-m-d H:i:s'), 'order' => 0]);
             $media->save();
             $this->data['ids'][] = $media->id;
         }
     }
     $dir->emptyDir(true);
 }
Пример #21
0
 /**
  * Get all modules method
  *
  * @param  \Phire\Project $project
  * @return void
  */
 public function getModules(\Phire\Project $project = null)
 {
     $modules = Table\Extensions::findAll('id ASC', array('type' => 1));
     $moduleRows = $modules->rows;
     $moduleDir1 = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules', false, false, false);
     $moduleDir2 = new Dir(__DIR__ . '/../../../../../module', false, false, false);
     $dirs = array_merge($moduleDir1->getFiles(), $moduleDir2->getFiles());
     $moduleFiles = array();
     $formats = Archive::formats();
     foreach ($dirs as $file) {
         if (array_key_exists(substr($file, strrpos($file, '.') + 1), $formats)) {
             $moduleFiles[substr($file, 0, strpos($file, '.'))] = $file;
         }
     }
     foreach ($moduleRows as $key => $module) {
         $moduleName = $module->name;
         if (null !== $project) {
             $cfg = $project->module($module->name);
             if (null !== $cfg && null !== $cfg->module_nav) {
                 $n = !is_array($cfg->module_nav) ? $cfg->module_nav->asArray() : $cfg->module_nav;
                 $modNav = new Nav($n, array('top' => array('id' => strtolower($module->name) . '-nav', 'class' => 'module-nav')));
                 $modNav->setAcl($this->data['acl']);
                 $modNav->setRole($this->data['role']);
                 $moduleRows[$key]->module_nav = $modNav;
             }
         }
         if (isset($moduleFiles[$module->name])) {
             unset($moduleFiles[$module->name]);
         }
         // Get module info
         $assets = unserialize($module->assets);
         $moduleRows[$key]->author = '';
         $moduleRows[$key]->desc = '';
         $moduleRows[$key]->version = '';
         foreach ($assets['info'] as $k => $v) {
             if (stripos($k, 'name') !== false) {
                 $moduleRows[$key]->name = $v;
             } else {
                 if (stripos($k, 'author') !== false) {
                     $moduleRows[$key]->author = $v;
                 } else {
                     if (stripos($k, 'desc') !== false) {
                         $moduleRows[$key]->desc = $v;
                     } else {
                         if (stripos($k, 'version') !== false) {
                             $moduleRows[$key]->version = $v;
                         }
                     }
                 }
             }
         }
         $latest = '';
         $handle = @fopen('http://update.phirecms.org/modules/' . strtolower($moduleName) . '/version', 'r');
         if ($handle !== false) {
             $latest = trim(stream_get_contents($handle));
             fclose($handle);
         }
         if (version_compare($moduleRows[$key]->version, $latest) < 0 && $this->data['acl']->isAuth('Phire\\Controller\\Phire\\Config\\IndexController', 'update')) {
             $moduleRows[$key]->version .= ' (<a href="' . BASE_PATH . APP_URI . '/config/update?module=' . $moduleName . '">' . $this->i18n->__('Update to') . ' ' . $latest . '</a>?)';
         }
     }
     $this->data['modules'] = $moduleRows;
     $this->data['new'] = $moduleFiles;
 }
Пример #22
0
 /**
  * Get available model objects
  *
  * @param  \Pop\Config $config
  * @return array
  */
 public static function getModels($config = null)
 {
     $models = array('0' => '----');
     $exclude = array();
     $override = null;
     // Get any exclude or override config values
     if (null !== $config) {
         $configAry = $config->asArray();
         if (isset($configAry['exclude_models'])) {
             $exclude = $configAry['exclude_models'];
         }
         if (isset($configAry['override'])) {
             $override = $configAry['override'];
         }
     }
     // If override, set overridden models
     if (null !== $override) {
         foreach ($override as $model) {
             $models[$model] = $model;
         }
         // Else, get all modules from the system and module directories
     } else {
         $systemDirectory = new Dir(realpath($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . '/vendor'), true);
         $sysModuleDirectory = new Dir(realpath($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . '/module'), true);
         $moduleDirectory = new Dir(realpath($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules'), true);
         $dirs = array_merge($systemDirectory->getFiles(), $sysModuleDirectory->getFiles(), $moduleDirectory->getFiles());
         sort($dirs);
         // Dir clean up
         foreach ($dirs as $key => $dir) {
             unset($dirs[$key]);
             if (!(strpos($dir, 'PopPHPFramework') !== false || strpos($dir, 'config') !== false || strpos($dir, 'index.html') !== false)) {
                 $k = $dir;
                 if (substr($dir, -1) == DIRECTORY_SEPARATOR) {
                     $k = substr($k, 0, -1);
                 }
                 $k = substr($k, strrpos($k, DIRECTORY_SEPARATOR) + 1);
                 $dirs[$k] = $dir;
             }
         }
         // Loop through each directory, looking for model class files
         foreach ($dirs as $mod => $dir) {
             if (file_exists($dir . 'src/' . $mod . '/Model')) {
                 $d = new Dir($dir . 'src/' . $mod . '/Model');
                 $dFiles = $d->getFiles();
                 sort($dFiles);
                 foreach ($dFiles as $m) {
                     if (substr($m, 0, 8) !== 'Abstract') {
                         $model = str_replace('.php', '', $mod . '\\Model\\' . $m);
                         $wildcardModel = '*' . substr($model, strpos($model, '\\'));
                         if (!in_array($model, $exclude) && !in_array($wildcardModel, $exclude) && strpos($model, 'index.html') === false) {
                             $models[$model] = strpos($model, '\\') !== false ? substr($model, strrpos($model, '\\') + 1) : $model;
                         }
                     }
                 }
             }
         }
     }
     return $models;
 }