Ejemplo n.º 1
0
 /**
  * Index action method
  *
  * @return void
  */
 public function index()
 {
     // Complete one-click updating
     if ($this->request->getQuery('update') == 2) {
         clearstatcache();
         $updater = new Updater();
         $updater->runPost();
         $this->redirect(BASE_PATH . APP_URI . '/update/complete');
         // Else, compare versions
     } else {
         if (version_compare(\Phire\Module::VERSION, $this->sess->updates->phirecms) < 0) {
             // Get updates via one-click updating
             if ($this->request->getQuery('update') == 1 && is_writable(__DIR__ . '/../../../../') && is_writable(__DIR__ . '/../../../..' . APP_PATH)) {
                 $updater = new Updater();
                 $updater->getUpdate();
                 $this->redirect(BASE_PATH . APP_URI . '/update?update=2');
                 // Else, use FTP to get updates
             } else {
                 $this->prepareView('phire/update.phtml');
                 $this->view->title = 'Update Phire';
                 $this->view->url = 'http://updates.phirecms.org/releases/phire/phirecms.zip';
                 $this->view->phire_update_version = $this->sess->updates->phirecms;
                 // Detect one-click updating
                 if (is_writable(__DIR__ . '/../../../../') && is_writable(__DIR__ . '/../../../..' . APP_PATH)) {
                     $this->view->form = false;
                 } else {
                     $fields = $this->application->config()['forms']['Phire\\Form\\Update'];
                     $fields[1]['resource']['value'] = 'phirecms';
                     $this->view->form = new Form\Update($fields);
                 }
                 // Start update via FTP
                 if ($this->view->form !== false && $this->request->isPost()) {
                     $this->view->form->addFilter('strip_tags')->setFieldValues($this->request->getPost());
                     if ($this->view->form->isValid()) {
                         $fields = $this->view->form->getFields();
                         $curl = new Curl('http://updates.phirecms.org/fetch/' . $fields['resource']);
                         $curl->setFields($fields);
                         $curl->setPost(true);
                         $curl->send();
                         $json = json_decode($curl->getBody(), true);
                         if ($curl->getCode() == 401) {
                             $this->view->form = '<h4 class="error">' . $json['error'] . '</h4>';
                         } else {
                             clearstatcache();
                             $updater = new Updater();
                             $updater->runPost();
                             $this->redirect(BASE_PATH . APP_URI . '/update/complete');
                         }
                     }
                 }
                 $this->send();
             }
         } else {
             $this->redirect(BASE_PATH . APP_URI);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Update
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->resource) {
         $curl = new Curl('http://updates.phirecms.org/test');
         $curl->setFields($this->getFields());
         $curl->setPost(true);
         $curl->send();
         if ($curl->getCode() == 401) {
             $json = json_decode($curl->getBody(), true);
             $this->getElement('ftp_address')->addValidator(new Validator\NotEqual($this->ftp_address, $json['error']));
         }
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Send installation stats
  *
  * @param  string $name
  * @param  string $version
  * @return void
  */
 protected function sendStats($name, $version)
 {
     $headers = ['Authorization: ' . base64_encode('phire-stats-' . time()), 'User-Agent: ' . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0')];
     $curl = new Curl('http://stats.phirecms.org/theme', [CURLOPT_HTTPHEADER => $headers]);
     $curl->setPost(true);
     $curl->setFields(['name' => $name, 'version' => $version, 'domain' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 'os' => PHP_OS, 'server' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '', 'php' => PHP_VERSION, 'db' => DB_INTERFACE . (DB_INTERFACE == 'pdo' ? ' (' . DB_TYPE . ')' : '')]);
     $curl->send();
 }
Ejemplo n.º 4
0
 /**
  * Get update info
  *
  * @param  boolean $live
  * @return \ArrayObject
  */
 public function getUpdates($live = true)
 {
     $updates = ['phirecms' => null, 'modules' => []];
     if ($live) {
         $headers = ['Authorization: ' . base64_encode('phire-updater-' . time()), 'User-Agent: ' . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0')];
         $curl = new Curl('http://updates.phirecms.org/latest/phirecms', [CURLOPT_HTTPHEADER => $headers]);
         $curl->send();
         if ($curl->getCode() == 200) {
             $json = json_decode($curl->getBody(), true);
             $updates['phirecms'] = $json['version'];
         }
         $modules = Table\Modules::findAll();
         if ($modules->hasRows()) {
             foreach ($modules->rows() as $module) {
                 $curl = new Curl('http://updates.phirecms.org/latest/' . $module->name, [CURLOPT_HTTPHEADER => $headers]);
                 $curl->send();
                 if ($curl->getCode() == 200) {
                     $json = json_decode($curl->getBody(), true);
                     $updates['modules'][$module->name] = $json['version'];
                 }
             }
         }
     }
     return new \ArrayObject($updates, \ArrayObject::ARRAY_AS_PROPS);
 }
Ejemplo n.º 5
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();
 }
Ejemplo n.º 6
0
 public function index()
 {
     $this->console->write();
     $this->console->write('    Fetching: ' . $this->console->colorize('phirecms/phirecms', Console::BOLD_CYAN) . '...', false);
     // Get latest version of phirecms
     $url = $this->urls['phirecms'] . '?client_id=' . $this->clientId . '&client_secret=' . $this->clientSecret;
     $curl = new Curl($url, $this->options);
     $curl->send();
     if ($curl->getCode() == 200) {
         $body = json_decode($curl->getBody(), true);
         $this->json['phirecms'] = isset($body['tag_name']) ? $body['tag_name'] : $this->current['phirecms'];
         $this->console->write();
     } else {
         $this->console->write(' ' . $this->console->colorize('Error', Console::BOLD_RED) . '.');
     }
     // Get latest versions of modules
     foreach ($this->modules as $module) {
         // Get version
         $this->console->write('    Fetching: ' . $this->console->colorize($module, Console::BOLD_CYAN) . '...', false);
         $url = str_replace('[{module}]', $module, $this->urls['module']) . '?client_id=' . $this->clientId . '&client_secret=' . $this->clientSecret;
         $curl = new Curl($url, $this->options);
         $curl->send();
         if ($curl->getCode() == 200) {
             $body = json_decode($curl->getBody(), true);
             if (isset($body['tag_name'])) {
                 $this->json['modules'][$module] = $body['tag_name'];
                 // Get file
                 if (!isset($this->current['modules'][$module]) || isset($this->current['modules'][$module]) && version_compare($this->current['modules'][$module], $this->json['modules'][$module]) < 0) {
                     $this->console->write(' Downloading...', false);
                     if (file_exists(__DIR__ . '/../../public/releases/modules/' . $module . '.zip')) {
                         unlink(__DIR__ . '/../../public/releases/modules/' . $module . '.zip');
                     }
                     $file = str_replace(['[{file}]', '[{tag_name}]'], [$module, $body['tag_name']], $this->urls['file']);
                     file_put_contents(__DIR__ . '/../../public/releases/modules/' . $module . '-' . $body['tag_name'] . '.zip', file_get_contents($file));
                     chmod(__DIR__ . '/../../public/releases/modules/' . $module . '-' . $body['tag_name'] . '.zip', 0777);
                 }
                 $this->console->write(' Complete.');
             }
         } else {
             $this->console->write(' ' . $this->console->colorize('Error', Console::BOLD_RED) . '.');
         }
     }
     $this->console->write();
     // Get latest versions of themes
     foreach ($this->themes as $theme) {
         // Get version
         $this->console->write('    Fetching: ' . $this->console->colorize($theme, Console::BOLD_CYAN) . '...', false);
         $url = str_replace('[{theme}]', $theme, $this->urls['theme']) . '?client_id=' . $this->clientId . '&client_secret=' . $this->clientSecret;
         $curl = new Curl($url, $this->options);
         $curl->send();
         if ($curl->getCode() == 200) {
             $body = json_decode($curl->getBody(), true);
             if (isset($body['tag_name'])) {
                 $this->json['themes'][$theme] = $body['tag_name'];
                 // Get file
                 if (!isset($this->current['themes'][$theme]) || isset($this->current['themes'][$theme]) && version_compare($this->current['themes'][$theme], $this->json['themes'][$theme]) < 0) {
                     $this->console->write(' Downloading...', false);
                     if (file_exists(__DIR__ . '/../../public/releases/themes/' . $theme . '.zip')) {
                         unlink(__DIR__ . '/../../public/releases/themes/' . $theme . '.zip');
                     }
                     $file = str_replace(['[{file}]', '[{tag_name}]'], [$theme, $body['tag_name']], $this->urls['file']);
                     file_put_contents(__DIR__ . '/../../public/releases/themes/' . $theme . '-' . $body['tag_name'] . '.zip', file_get_contents($file));
                     chmod(__DIR__ . '/../../public/releases/themes/' . $theme . '-' . $body['tag_name'] . '.zip', 0777);
                 }
                 $this->console->write(' Complete.');
             }
         } else {
             $this->console->write(' ' . $this->console->colorize('Error', Console::BOLD_RED) . '.');
         }
     }
     // Write new 'updates.json' file
     if (file_exists(__DIR__ . '/../../data/updates.json')) {
         unlink(__DIR__ . '/../../data/updates.json');
     }
     file_put_contents(__DIR__ . '/../../data/updates.json', json_encode($this->json, JSON_PRETTY_PRINT));
     $this->console->write();
     $this->console->write('    Done!');
     $this->console->write();
 }