/** * Static method to get current site * * @param int $id * @return \ArrayObject */ public static function getSite($id = null) { $siteAry = array(); if (null !== $id) { $site = (int) $id > 0 ? static::findById((int) $id) : static::findBy(array('document_root' => $_SERVER['DOCUMENT_ROOT'])); } else { $site = static::findBy(array('document_root' => $_SERVER['DOCUMENT_ROOT'])); } if (isset($site->id)) { $siteAry['id'] = $site->id; $siteAry['domain'] = $site->domain; $siteAry['document_root'] = $site->document_root; $siteAry['base_path'] = $site->base_path; $siteAry['force_ssl'] = $site->force_ssl; $siteAry['live'] = $site->live; } else { $siteAry['id'] = 0; $siteAry['domain'] = $_SERVER['HTTP_HOST']; $siteAry['document_root'] = $_SERVER['DOCUMENT_ROOT']; $siteAry['base_path'] = BASE_PATH; $siteAry['force_ssl'] = (int) \Phire\Table\Config::findById('force_ssl')->value; $siteAry['live'] = (int) \Phire\Table\Config::findById('live')->value; } return new \ArrayObject($siteAry, \ArrayObject::ARRAY_AS_PROPS); }
/** * Instantiate the model object. * * @param array $data * @return self */ public function __construct(array $data = null) { if (null !== $data) { $this->data = $data; } $this->config = \Phire\Table\Config::getSystemConfig(); if (!headers_sent()) { $sess = \Pop\Web\Session::getInstance(); } $this->i18n = Table\Config::getI18n(); if (isset($sess->user)) { $this->data['user'] = $sess->user; $this->data['role'] = \Phire\Table\UserRoles::getRole($sess->user->role_id); $this->data['globalAccess'] = $sess->user->global_access; } }
/** * Initialize the application * * @param Application $application * @throws Exception * @return Module */ public function register(Application $application) { parent::register($application); // Set the database if ($this->application->services()->isAvailable('database')) { Record::setDb($this->application->getService('database')); $db = count($this->application->getService('database')->getTables()) > 0; } else { $db = false; } $this->application->mergeConfig(['db' => $db]); // Load assets, if they haven't been loaded already $this->loadAssets(__DIR__ . '/../data/assets', 'phire'); if ($db) { $systemTheme = Table\Config::findById('system_theme')->value; if (file_exists(CONTENT_ABS_PATH . '/phire/themes/' . $systemTheme)) { $this->loadAssets(CONTENT_ABS_PATH . '/phire/themes/' . $systemTheme, $systemTheme); } else { if (file_exists(__DIR__ . '/../data/themes/' . $systemTheme)) { $this->loadAssets(__DIR__ . '/../data/themes/' . $systemTheme, $systemTheme); } } } else { $this->loadAssets(__DIR__ . '/../data/themes/default', 'default'); } sort($this->assets['js']); sort($this->assets['css']['link']); sort($this->assets['css']['import']); // Load any custom/override assets $this->loadAssets(CONTENT_ABS_PATH . '/phire/assets', 'phire-custom', true); // Check PHP version if (version_compare(PHP_VERSION, '5.4.0') < 0) { throw new Exception('Error: Phire CMS requires PHP 5.4.0 or greater.'); } // Add route params for the controllers if (null !== $this->application->router()) { $this->application->router()->addControllerParams('*', ['application' => $this->application, 'request' => new Request(), 'response' => new Response()]); } // Set up triggers to check the application session $this->application->on('app.route.pre', 'Phire\\Event\\Ssl::check', 1000)->on('app.route.post', 'Phire\\Event\\Db::check', 1000)->on('app.dispatch.pre', 'Phire\\Event\\Session::check', 1001)->on('app.dispatch.pre', 'Phire\\Event\\Acl::check', 1000); // Add roles to user nav $this->addRoles(); // Register modules $this->registerModules(); return $this; }
<?php /** * Module Name: phire-cache * Author: Nick Sagona * Description: This is the cache module for Phire CMS 2 * Version: 1.0 */ return ['phire-cache' => ['prefix' => 'Phire\\Cache\\', 'src' => __DIR__ . '/../src', 'routes' => include 'routes.php', 'resources' => include 'resources.php', 'nav.module' => ['name' => 'Cache Config', 'href' => '/cache', 'acl' => ['resource' => 'cache', 'permission' => 'index']], 'events' => [['name' => 'app.route.post', 'action' => 'Phire\\Cache\\Event\\Cache::load', 'priority' => 1000], ['name' => 'app.dispatch.post', 'action' => 'Phire\\Cache\\Event\\Cache::save', 'priority' => 1000]], 'install' => function () { mkdir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache'); chmod($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache', 0777); copy($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/index.html', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache/index.html'); chmod($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache/index.html', 0777); }, 'uninstall' => function () { $config = \Phire\Table\Config::findById('cache_adapter'); if (isset($config->setting)) { $config->delete(); } $config = \Phire\Table\Config::findById('cache_lifetime'); if (isset($config->setting)) { $config->delete(); } if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache')) { $dir = new \Pop\File\Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache'); $dir->emptyDir(true); } }, 'exclude' => []]];
<?php /** * Module Name: phire-seo * Author: Nick Sagona * Description: This is the SEO media module for Phire CMS 2 * Version: 1.0 */ return ['phire-seo' => ['prefix' => 'Phire\\Seo\\', 'src' => __DIR__ . '/../src', 'routes' => include 'routes.php', 'resources' => include 'resources.php', 'nav.module' => ['name' => 'SEO', 'href' => '/seo', 'acl' => ['resource' => 'seo', 'permission' => 'index']], 'events' => [['name' => 'app.route.pre', 'action' => 'Phire\\Seo\\Event\\Seo::bootstrap', 'priority' => 1000], ['name' => 'app.send.pre', 'action' => 'Phire\\Seo\\Event\\Seo::init', 'priority' => 1000], ['name' => 'app.send.post', 'action' => 'Phire\\Seo\\Event\\Seo::parse', 'priority' => 1000]], 'exclude' => [], 'install' => function () { $config = new \Phire\Table\Config(['setting' => 'seo_config', 'value' => '']); $config->save(); $config = new \Phire\Table\Config(['setting' => 'seo_analysis', 'value' => '']); $config->save(); }, 'uninstall' => function () { $config = \Phire\Table\Config::findById('seo_config'); if (isset($config->setting)) { $config->delete(); } $config = \Phire\Table\Config::findById('seo_analysis'); if (isset($config->setting)) { $config->delete(); } }]];
/** * Save the config data * * @param array $post * @return void */ public function save(array $post) { $config = Table\Config::findById('domain'); if (isset($_SERVER['HTTP_HOST']) && $config->value != $_SERVER['HTTP_HOST']) { $config->value = $_SERVER['HTTP_HOST']; $config->save(); } $config = Table\Config::findById('document_root'); if (isset($_SERVER['DOCUMENT_ROOT']) && $config->value != $_SERVER['DOCUMENT_ROOT']) { $config->value = $_SERVER['DOCUMENT_ROOT']; $config->save(); } if (!empty($post['datetime_format_custom']) && $post['datetime_format'] == 'custom') { $dateFormatValue = str_replace(['"', "'"], ['', ''], strip_tags($post['datetime_format_custom'])); } else { if (!empty($post['datetime_format']) && $post['datetime_format'] != 'custom') { $dateFormatValue = $post['datetime_format']; } else { $dateFormatValue = 'M j Y'; } } $config = Table\Config::findById('datetime_format'); $config->value = $dateFormatValue; $config->save(); $config = Table\Config::findById('pagination'); $config->value = (int) $post['pagination']; $config->save(); $config = Table\Config::findById('system_theme'); $oldValue = $config->value; $config->value = $post['system_theme']; $config->save(); if (isset($_SERVER['DOCUMENT_ROOT']) && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $oldValue)) { $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $oldValue); $dir->emptyDir(true); } }
/** * Send installation confirmation * * @param Table\Users * @return void */ public function sendConfirmation($user) { $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']); $schema = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://'; // Set the recipient $rcpt = ['name' => $user->username, 'email' => $user->email, 'login' => $schema . $_SERVER['HTTP_HOST'] . BASE_PATH . APP_URI . '/login', 'domain' => $domain]; // Check for an override template $mailTemplate = file_exists(CONTENT_ABS_PATH . '/phire/view/phire/mail/install.txt') ? CONTENT_ABS_PATH . '/phire/view/phire/mail/install.txt' : __DIR__ . '/../../view/phire/mail/install.txt'; // Send email verification $mail = new Mail($domain . ' - Phire CMS Installation', $rcpt); $mail->from('noreply@' . $domain); $mail->setText(file_get_contents($mailTemplate)); $mail->send(); // Save domain $config = Table\Config::findById('domain'); $config->value = $_SERVER['HTTP_HOST']; $config->save(); // Save document root $config = Table\Config::findById('document_root'); $config->value = $_SERVER['DOCUMENT_ROOT']; $config->save(); // Save install timestamp $config = Table\Config::findById('installed_on'); $config->value = (string) date('Y-m-d H:i:s'); $config->save(); $this->sendStats(); }
/** * Method for post update code for Phire or for a module, * usually for database modification or file cleanup * * @return void */ public function runPost() { $i = count($this->previousUpdates) > 0 ? max($this->previousUpdates) + 1 : 1; $method = 'update' . $i; while (method_exists($this, $method)) { $this->{$method}(); $this->previousUpdates[] = $i; $i++; $method = 'update' . $i; } if (null === $this->module) { $updates = Table\Config::findById('updates'); $updates->value = implode('|', $this->previousUpdates); $updates->save(); $updated = Table\Config::findById('updated_on'); $updated->value = date('Y-m-d H:i:s'); $updated->save(); } else { $module = Table\Modules::findBy(['name' => $this->module]); if (isset($module->id)) { $module->updates = implode('|', $this->previousUpdates); $module->updated_on = date('Y-m-d H:i:s'); $module->save(); } } }
<?php /** * Module Name: phire-social * Author: Nick Sagona * Description: This is the social media module for Phire CMS 2 * Version: 1.0 */ return ['phire-social' => ['prefix' => 'Phire\\Social\\', 'src' => __DIR__ . '/../src', 'routes' => include 'routes.php', 'resources' => include 'resources.php', 'nav.module' => ['name' => 'Social Media', 'href' => '/social', 'acl' => ['resource' => 'social', 'permission' => 'index']], 'events' => [['name' => 'app.send.pre', 'action' => 'Phire\\Social\\Event\\Social::init', 'priority' => 1000], ['name' => 'app.send.post', 'action' => 'Phire\\Social\\Event\\Social::parse', 'priority' => 1000]], 'install' => function () { $config = new \Phire\Table\Config(['setting' => 'social_config', 'value' => '']); $config->save(); }, 'uninstall' => function () { $config = \Phire\Table\Config::findById('social_config'); if (isset($config->setting)) { $config->delete(); } }]];
/** * Prepare view method * * @param string $template * @param array $data * @return void */ public function prepareView($template = null, array $data = array()) { $site = \Phire\Table\Sites::getSite(); if (null !== $template) { $template = $this->getCustomView($template, $site); } $sess = \Pop\Web\Session::getInstance(); $config = \Phire\Table\Config::getSystemConfig(); $i18n = \Phire\Table\Config::getI18n(); $this->live = (bool) $config->live; $jsVars = null; $this->view = View::factory($template, $data); $this->view->set('base_path', $site->base_path)->set('content_path', CONTENT_PATH); // Check for an override Phire theme for the header/footer if (file_exists($site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/header.phtml') && file_exists($site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/footer.phtml')) { $this->view->set('phireHeader', $site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/header.phtml')->set('phireFooter', $site->document_root . $site->base_path . CONTENT_PATH . '/extensions/themes/phire/footer.phtml'); // Else, just use the default header/footer } else { $this->view->set('phireHeader', $site->document_root . $site->base_path . APP_PATH . '/vendor/Phire/view/phire/header.phtml')->set('phireFooter', $site->document_root . $site->base_path . APP_PATH . '/vendor/Phire/view/phire/footer.phtml'); } if (isset($this->view->assets)) { $jsVars = '?lang=' . $config->default_language; } if (isset($sess->user)) { if (isset($this->sess->user->last_action)) { $this->sess->user->last_action = date('Y-m-d H:i:s'); } // Set the timeout warning, giving a 30 second buffer to act if (isset($this->view->assets)) { if (isset($this->view->acl) && $this->view->acl->getType()->session_expiration > 0 && $this->view->acl->getType()->timeout_warning) { $exp = $this->view->acl->getType()->session_expiration * 60 - 30; $uri = $site->base_path . (strtolower($this->view->acl->getType()->type) != 'user' ? '/' . strtolower($this->view->acl->getType()->type) : APP_URI); $jsVars .= '&_exp=' . $exp . '&_base=' . urlencode($uri); } } $this->view->set('user', $sess->user)->set('role', \Phire\Table\UserRoles::getRole($sess->user->role_id))->set('globalAccess', $sess->user->global_access); if (isset($this->view->phireNav) && isset($this->view->acl) && $this->view->acl->hasRole($this->view->role->getName())) { $this->view->phireNav->setConfig(array('top' => array('node' => 'ul', 'id' => 'phire-nav'))); $this->view->phireNav->setAcl($this->view->acl); $this->view->phireNav->setRole($this->view->role); $tree = $this->view->phireNav->getTree(); // If the sub-children haven't been added yet if (isset($tree[0])) { // And any user types to the main phire nav $userTypes = \Phire\Table\UserTypes::findAll('id ASC'); if (isset($userTypes->rows)) { foreach ($userTypes->rows as $type) { $perm = 'index_' . $type->id; if ($this->view->acl->isAuth('Phire\\Controller\\Phire\\User\\IndexController', 'index') && $this->view->acl->isAuth('Phire\\Controller\\Phire\\User\\IndexController', 'index_' . $type->id)) { $perm = 'index'; } $this->view->phireNav->addLeaf('Users', array('name' => ucwords(str_replace('-', ' ', $type->type)), 'href' => 'index/' . $type->id, 'acl' => array('resource' => 'Phire\\Controller\\Phire\\User\\IndexController', 'permission' => $perm)), 1); } } // Set the language $tree = $this->view->phireNav->getTree(); foreach ($tree as $key => $value) { if (isset($value['name'])) { $tree[$key]['name'] = $i18n->__($value['name']); if (isset($value['children']) && count($value['children']) > 0) { foreach ($value['children'] as $k => $v) { if ($v['name'] == 'Fields' && isset($tree[$key]['children'][$k]['children'][0]['name'])) { $tree[$key]['children'][$k]['children'][0]['name'] = $i18n->__($tree[$key]['children'][$k]['children'][0]['name']); } $tree[$key]['children'][$k]['name'] = $i18n->__($v['name']); } } } } $this->view->phireNav->setTree($tree); } $this->view->phireNav->rebuild(); $this->view->phireNav->nav()->setIndent(' '); } } if (isset($this->view->assets)) { $this->view->assets = str_replace('jax.3.2.0.min.js', 'jax.3.2.0.min.js' . $jsVars, $this->view->assets); } if (isset($sess->errors)) { $this->view->set('errors', $sess->errors); } // Set config object and system/site default data $this->view->set('i18n', $i18n)->set('system_title', $config->system_title)->set('system_email', $config->system_email)->set('site_title', $config->site_title)->set('base_path', $config->base_path)->set('separator', $config->separator)->set('default_language', $config->default_language)->set('datetime_format', $config->datetime_format); }
/** * Build social nav * * @return mixed */ public function buildNav() { $nav = null; $hasUrl = false; $config = Table\Config::findById('social_config'); if (isset($config->value) && !empty($config->value) && $config->value != '') { $cfg = unserialize($config->value); $style = $cfg['style']; $this->data = array_merge($this->data, $cfg); switch ($cfg['size']) { case 'large': $size = 64; break; case 'medium': $size = 48; break; default: $size = 32; } $nav = new Child('nav'); $nav->setAttribute('class', 'social-media-' . $size); foreach ($cfg['order'] as $name) { if (!empty($cfg['urls'][$name]['url']) && $cfg['urls'][$name]['url'] != '') { $a = new Child('a', ucfirst($name)); $a->setAttributes(['class' => $name . '-' . $size . '-' . $style, 'href' => $cfg['urls'][$name]['url']]); if ($cfg['urls'][$name]['new']) { $a->setAttribute('target', '_blank'); } $nav->addChild($a); $hasUrl = true; } } if (!$hasUrl) { $nav = null; } } return $nav; }
/** * Save cache config * * @param array $post * @return void */ public function save(array $post) { if (isset($post['cache_status'])) { $config = Table\Config::findById('cache_status'); if (isset($config->value)) { $config->value = (int) $post['cache_status']; } else { $config = new Table\Config(['setting' => 'cache_status', 'value' => (int) $post['cache_status']]); } $config->save(); } $oldAdapter = null; if (isset($post['cache_adapter']) && !empty($post['cache_adapter'])) { $config = Table\Config::findById('cache_adapter'); if (isset($config->value)) { $oldAdapter = $config->value; $config->value = $post['cache_adapter']; if ($oldAdapter != $post['cache_adapter']) { $this->clear(); } } else { $config = new Table\Config(['setting' => 'cache_adapter', 'value' => $post['cache_adapter']]); } $config->save(); } $lifetime = null; if (isset($post['cache_lifetime_value']) && !empty($post['cache_lifetime_value']) && isset($post['cache_lifetime_unit']) && !empty($post['cache_lifetime_unit'])) { switch ($post['cache_lifetime_unit']) { case 'Days': $lifetime = round($post['cache_lifetime_value'] * 86400, 1); break; case 'Hours': $lifetime = round($post['cache_lifetime_value'] * 3600, 1); break; case 'Minutes': $lifetime = round($post['cache_lifetime_value'] * 60, 1); break; } } if (null !== $lifetime) { $config = Table\Config::findById('cache_lifetime'); if (isset($config->value)) { $config->value = $lifetime; } else { $config = new Table\Config(['setting' => 'cache_lifetime', 'value' => $lifetime]); } $config->save(); } if (isset($post['cache_clear']) && $post['cache_clear']) { $this->clear(); } }
/** * Event-based route error check * * @param \Pop\Mvc\Router $router * @return void */ public static function error($router) { $view = \Pop\Mvc\View::factory(__DIR__ . '/../../view/route.phtml', array('i18n' => \Phire\Table\Config::getI18n(), 'title' => 'Routing Error', 'msg' => ' <p>There was no controller assigned for this route.</p>')); $response = new \Pop\Http\Response(404); $response->setBody($view->render(true)); $response->send(); }
/** * Build social nav * * @param string $description * @param string $keywords * @return mixed */ public function buildMetaTags($description = null, $keywords = null) { $metas = null; $hasDesc = false; $hasKeys = false; $config = Table\Config::findById('seo_config'); if (isset($config->value) && !empty($config->value) && $config->value != '') { $cfg = unserialize($config->value); if (count($cfg['meta']) > 0) { foreach ($cfg['meta'] as $meta) { $content = $meta['content']; if ($meta['name'] == 'description') { $hasDesc = true; if (null !== $description && $description != '') { $content = $description; } } if ($meta['name'] == 'keywords') { $hasKeys = true; if (null !== $keywords && $keywords != '') { $content = $keywords; } } $m = new Child('meta'); $m->setAttributes(['name' => $meta['name'], 'content' => htmlentities($content, ENT_QUOTES, 'UTF-8')]); $metas .= ' ' . (string) $m; } if (!$hasDesc && null !== $description && $description != '') { $m = new Child('meta'); $m->setAttributes(['name' => 'description', 'content' => htmlentities($description, ENT_QUOTES, 'UTF-8')]); $metas .= ' ' . (string) $m; } if (!$hasKeys && null !== $keywords && $keywords != '') { $m = new Child('meta'); $m->setAttributes(['name' => 'keywords', 'content' => htmlentities($keywords, ENT_QUOTES, 'UTF-8')]); $metas .= ' ' . (string) $m; } } } if (null === $metas) { if (null !== $description && $description != '') { $m = new Child('meta'); $m->setAttributes(['name' => 'description', 'content' => htmlentities($description, ENT_QUOTES, 'UTF-8')]); $metas .= ' ' . (string) $m; } if (null !== $keywords && $keywords != '') { $m = new Child('meta'); $m->setAttributes(['name' => 'keywords', 'content' => htmlentities($keywords, ENT_QUOTES, 'UTF-8')]); $metas .= ' ' . (string) $m; } } return $metas; }
/** * Log a user login * * @param \Phire\Table\UserTypes $type * @param \Phire\Table\Users $user * @return void */ protected function log($type, $user) { $exclude = array(); if ($type->log_exclude != '') { $exclude = explode(',', $type->log_exclude); } $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']); if (!in_array($_SERVER['REMOTE_ADDR'], $exclude)) { $emails = explode(',', $type->log_emails); $noreply = Table\Config::findById('reply_email')->value; $options = array('subject' => 'Phire CMS ' . ucfirst(strtolower($type->type)) . ' ' . $this->i18n->__('Login Notification') . ' (' . $domain . ')', 'headers' => array('From' => $noreply . ' <' . $noreply . '>', 'Reply-To' => $noreply . ' <' . $noreply . '>')); $msg = $this->i18n->__('Someone has logged in as a %1 from %2 using %3.', array(strtolower($type->type), $_SERVER['REMOTE_ADDR'], $user->username)); $logger = new Log\Logger(new Log\Writer\Mail($emails)); $logger->notice($msg, $options); } }
/** * Perform update * * @param array $post * @param boolean $cli * @return void */ public function getUpdate($post = array(), $cli = false) { $docRoot = __DIR__ . '/../../../../../..'; // If system is writable for updates if (!isset($post['submit'])) { switch ($post['type']) { case 'system': $remoteFile = 'http://update.phirecms.org/system/latest.' . $post['format']; break; case 'module': $remoteFile = 'http://update.phirecms.org/modules/' . strtolower($post['name']) . '/latest.' . $post['format']; break; case 'theme': $remoteFile = 'http://update.phirecms.org/themes/' . strtolower($post['name']) . '/latest.' . $post['format']; break; } $remoteContents = @file_get_contents($remoteFile); if ($remoteContents !== false) { $localFile = $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']; file_put_contents($localFile, $remoteContents); $arc = new \Pop\Archive\Archive($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']); $arc->extract($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update'); unlink($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']); $msg = null; if ($post['type'] == 'module') { if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name'])) { $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']); $dir->emptyDir(null, true); rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']); } $msg = $this->i18n->__('The %1 module has been updated.', $post['name']); } else { if ($post['type'] == 'theme') { if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name'])) { $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']); $dir->emptyDir(null, true); rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']); } $msg = $this->i18n->__('The %1 theme has been updated.', $post['name']); } else { if ($post['type'] == 'system') { if ($cli) { rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms', $docRoot . DIRECTORY_SEPARATOR . 'phire-cms-new'); $config = Table\Config::findById('updated_on'); $config->value = date('Y-m-d H:i:s'); $config->update(); $msg = $this->i18n->__('The system has been updated.'); } else { $time = time(); mkdir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time); // Move old files into archive folder rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'config', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'config'); rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'module', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'module'); rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'script', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'script'); rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'vendor', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'vendor'); // Move new files into main application path rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'config', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'config'); rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'module', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'module'); rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'script', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'script'); rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'vendor', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'vendor'); $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms'); $dir->emptyDir(null, true); $config = Table\Config::findById('updated_on'); $config->value = date('Y-m-d H:i:s'); $config->update(); $msg = $this->i18n->__('The system has been updated.'); } } } } $this->data['msg'] = '<span style="color: #347703">' . $msg . '</span>'; } else { $this->data['error'] = '<span style="color: #a00b0b">' . $this->i18n->__('The update file was not found.') . '</span>'; } // Else use cURL/FTP } else { unset($post['submit']); $curl = new \Pop\Curl\Curl('http://update.phirecms.org/update.php'); $curl->setPost(true); $curl->setFields($post); $curl->execute(); $response = json_decode($curl->getBody()); unset($curl); if ($response->error == 0) { $arc = new \Pop\Archive\Archive($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']); $arc->extract($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update'); unlink($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']); if ($post['type'] == 'system') { chmod($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/phire-cms', 0777); } else { if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'])) { chmod($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], 0777); } } $post['complete'] = 1; $curl = new \Pop\Curl\Curl('http://update.phirecms.org/update.php'); $curl->setPost(true); $curl->setFields($post); $curl->execute(); $complete = json_decode($curl->getBody()); if ($complete->error == 0) { switch ($complete->type) { case 'system': $config = Table\Config::findById('updated_on'); $config->value = date('Y-m-d H:i:s'); $config->update(); $msg = $this->i18n->__('The system has been updated.'); chmod($docRoot . APP_PATH, 0755); break; case 'module': if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name'])) { $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']); $dir->emptyDir(null, true); rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']); } $msg = $this->i18n->__('The %1 module has been updated.', $complete->name); break; case 'theme': if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name'])) { $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']); $dir->emptyDir(null, true); rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']); } $msg = $this->i18n->__('The %1 theme has been updated.', $complete->name); break; } $this->data['msg'] = '<span style="color: #347703">' . $msg . '</span>'; } else { $this->data['error'] = '<span style="color: #a00b0b">' . $complete->message . '</span>'; } } else { $this->data['error'] = '<span style="color: #a00b0b">' . $response->message . '</span>'; } } $this->postUpdate($post); }
/** * Send user unsubscribe notification * * @param Table\Users $user * @return void */ protected function sendUnsubscribe(Table\Users $user) { $host = Table\Config::findById('domain')->value; $domain = str_replace('www.', '', $host); // Set the recipient $rcpt = ['name' => $user->username, 'email' => $user->email, 'domain' => $domain]; // Check for an override template $mailTemplate = file_exists(CONTENT_ABS_PATH . '/phire/view/phire/mail/unsubscribe.txt') ? CONTENT_ABS_PATH . '/phire/view/phire/mail/unsubscribe.txt' : __DIR__ . '/../../view/phire/mail/unsubscribe.txt'; // Send email verification $mail = new Mail($domain . ' - Unsubscribed', $rcpt); $mail->from('noreply@' . $domain); $mail->setText(file_get_contents($mailTemplate)); $mail->send(); }
/** * Send install notification email to user * * @param \Phire\Form\User $form * @return void */ public static function send(\Phire\Form\User $form) { $i18n = Table\Config::getI18n(); // Get the domain $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']); // Set the recipient $rcpt = array('name' => $form->username, 'email' => $form->email1, 'url' => 'http://' . $_SERVER['HTTP_HOST'] . BASE_PATH, 'login' => 'http://' . $_SERVER['HTTP_HOST'] . BASE_PATH . APP_URI, 'domain' => $domain); $config = \Phire\Table\Config::findById('system_email'); $config->value = $form->email1; $config->update(); $config = \Phire\Table\Config::findById('reply_email'); $config->value = 'noreply@' . $domain; $config->update(); if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/mail')) { $mailTmpl = file_get_contents($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/mail/install.txt'); } else { $mailTmpl = file_get_contents(__DIR__ . '/../../../view/phire/mail/install.txt'); } $mailTmpl = str_replace(array('Dear', 'Thank you for installing Phire CMS for', 'The website will be viewable here:', 'To manage the website, you can login to Phire here:', 'Thank You'), array($i18n->__('Dear'), $i18n->__('Thank you for installing Phire CMS for'), $i18n->__('The website will be viewable here:'), $i18n->__('To manage the website, you can login to Phire here:'), $i18n->__('Thank You')), $mailTmpl); // Send email verification $mail = new Mail($domain . ' - ' . $i18n->__('Phire CMS Installation'), $rcpt); $mail->from('noreply@' . $domain); $mail->setText($mailTmpl); $mail->send(); }
/** * Static method to get field definitions by model and * return them for consumption by a Pop\Form\Form object * * @param string $model * @param int $tid * @param int $mid * @return array */ public static function getByModel($model, $tid = 0, $mid = 0) { $fieldsAry = array(); $curFields = array(); $groups = array(); $dynamic = false; $hasFile = false; $i18n = Table\Config::getI18n(); // Get fields $fields = array(); $flds = Table\Fields::findAll('order ASC'); foreach ($flds->rows as $f) { $models = null !== $f->models ? unserialize($f->models) : array(); foreach ($models as $m) { if ($m['model'] == $model && ($m['type_id'] == $tid || $m['type_id'] == 0)) { $fields[] = $f; } } } // If fields exist if (count($fields) > 0) { foreach ($fields as $field) { // Get field group, if applicable $groupAryResults = Table\Fields::getFieldGroup($field->id); $groupAry = $groupAryResults['fields']; $isDynamic = $groupAryResults['dynamic']; if ($isDynamic) { $dynamic = true; } if (count($groupAry) > 0 && !in_array($groupAry, $groups)) { $groups[$groupAryResults['group_id']] = $groupAry; } $rmFile = null; $fld = array('type' => strpos($field->type, '-') !== false ? substr($field->type, 0, strpos($field->type, '-')) : $field->type); // Get field label if ($field->label != '') { if (isset($groupAry[0]) && $groupAry[0] == $field->id && $isDynamic) { $fld['label'] = '<a href="#" onclick="phire.addFields([' . implode(', ', $groupAry) . ']); return false;">[+]</a> ' . $field->label; } else { $fld['label'] = $field->label; } } $fld['name'] = $field->name; $fld['required'] = (bool) $field->required; // Get field values and default values if ($field->type == 'select' || $field->type == 'checkbox' || $field->type == 'radio') { if ($field->values != '') { // Get fields values of a multiple value field if (strpos($field->values, '[') !== false && strpos($field->values, ']') !== false) { $valsAry = explode('|', $field->values); $fieldValues = []; foreach ($valsAry as $vals) { $key = substr($vals, 0, strpos($vals, '[')); $vls = substr($vals, strpos($vals, '[') + 1); $vls = substr($vls, 0, strpos($vls, ']')); $vls = str_replace('::', '|', $vls); $vlsAry = explode('|', $vls); $vs = []; foreach ($vlsAry as $va) { // If the values are a name/value pair if (strpos($va, ',') !== false) { $vAry = explode(',', $va); if (count($vAry) >= 2) { // If the values are to be pulled from a database table if (strpos($vAry[0], 'Table') !== false) { $class = $vAry[0]; $order = $vAry[1] . (isset($vAry[2]) ? ', ' . $vAry[2] : null); $order .= ' ' . (isset($vAry[3]) ? $vAry[3] : 'ASC'); $id = $vAry[1]; $name = isset($vAry[2]) ? $vAry[2] : $vAry[1]; $valRows = $class::findAll($order); if (isset($valRows->rows[0])) { foreach ($valRows->rows as $vRow) { $vs[$vRow->{$id}] = $vRow->{$name}; } } // Else, if the value is a simple name/value pair } else { $vs[$vAry[0]] = $vAry[1]; } } } else { $vs[$va] = $va; } } $fieldValues[$key] = $vs; } $fld['value'] = $fieldValues; } else { if (strpos($field->values, '|') !== false) { $vals = explode('|', $field->values); $valAry = array(); foreach ($vals as $v) { // If the values are a name/value pair if (strpos($v, ',') !== false) { $vAry = explode(',', $v); if (count($vAry) >= 2) { // If the values are to be pulled from a database table if (strpos($vAry[0], 'Table') !== false) { $class = $vAry[0]; $order = $vAry[1] . (isset($vAry[2]) ? ', ' . $vAry[2] : null); $order .= ' ' . (isset($vAry[3]) ? $vAry[3] : 'ASC'); $id = $vAry[1]; $name = isset($vAry[2]) ? $vAry[2] : $vAry[1]; $valRows = $class::findAll($order); if (isset($valRows->rows[0])) { foreach ($valRows->rows as $vRow) { $valAry[$vRow->{$id}] = $vRow->{$name}; } } // Else, if the value is a simple name/value pair } else { $valAry[$vAry[0]] = $vAry[1]; } } } else { $valAry[$v] = $v; } } $fld['value'] = $valAry; // If the values are to be pulled from a database table } else { if (strpos($field->values, 'Table') !== false) { $valAry = array(); if (strpos($field->values, ',') !== false) { $vAry = explode(',', $field->values); $class = $vAry[0]; $order = $vAry[1] . (isset($vAry[2]) ? ', ' . $vAry[2] : null); $order .= ' ' . (isset($vAry[3]) ? $vAry[3] : 'ASC'); $id = $vAry[1]; $name = isset($vAry[2]) ? $vAry[2] : $vAry[1]; } else { $class = $field->values; $order = null; $id = 'id'; $name = 'id'; } $valRows = $class::findAll($order); if (isset($valRows->rows[0])) { foreach ($valRows->rows as $vRow) { $valAry[$vRow->{$id}] = $vRow->{$name}; } } $fld['value'] = $valAry; // Else, if the value is Select constant } else { if (strpos($field->values, 'Select::') !== false) { $fld['value'] = str_replace('Select::', '', $field->values); // Else, the value is a simple value } else { $aryValues = array(); if (strpos($field->values, ',') !== false) { $vls = explode(',', $field->values); $aryValues[$vls[0]] = $vls[1]; } else { $aryValues[$field->values] = $field->values; } $fld['value'] = $aryValues; } } } } } // Set default values if ($field->default_values != '') { $fld['marked'] = strpos($field->default_values, '|') !== false ? explode('|', $field->default_values) : $field->default_values; } // If field is a file field } else { if ($field->type == 'file' && count($groupAry) == 0) { $dynamic = true; $hasFile = true; if ($mid != 0) { $fileValue = Table\FieldValues::findById(array($field->id, $mid)); if (isset($fileValue->field_id)) { $fileName = json_decode($fileValue->value, true); $fileInfo = \Phire\Model\Media::getFileIcon($fileName); $fld['label'] .= '<br /><a href="' . BASE_PATH . CONTENT_PATH . '/media/' . $fileName . '" target="_blank"><img style="padding-top: 3px;" src="' . BASE_PATH . CONTENT_PATH . $fileInfo['fileIcon'] . '" width="50" /></a><br /><a href="' . BASE_PATH . CONTENT_PATH . '/media/' . $fileName . '" target="_blank">' . $fileName . '</a><br /><span style="font-size: 0.9em;">(' . $fileInfo['fileSize'] . ')</span><br /><em style="font-size: 0.9em; font-weight:normal;">' . $i18n->__('Replace?') . '</em>'; $fld['required'] = false; $rmFile = array('rm_file_' . $field->id => array('type' => 'checkbox', 'value' => array($fileName => $i18n->__('Remove') . '?'))); } } // Else, if the field is a normal field } else { if ($field->default_values != '') { $fld['value'] = $field->default_values; } } } // Get field attributes if ($field->attributes != '') { $attAry = array(); $attributes = explode('" ', $field->attributes); foreach ($attributes as $attrib) { $att = explode('=', $attrib); $attAry[$att[0]] = str_replace('"', '', $att[1]); } $fld['attributes'] = $attAry; } // Get field validators if ($field->validators != '') { $valAry = array(); $validators = unserialize($field->validators); foreach ($validators as $key => $value) { $valClass = '\\Pop\\Validator\\' . $key; if ($value['value'] != '') { $v = new $valClass($value['value']); } else { $v = new $valClass(); } if ($value['message'] != '') { $v->setMessage($value['message']); } $valAry[] = $v; } $fld['validators'] = $valAry; } // Detect any dynamic field group values $values = Table\FieldValues::findAll(null, array('field_id' => $field->id)); if (isset($values->rows[0])) { foreach ($values->rows as $value) { $val = json_decode($value->value); if (count($groupAry) > 0 && $value->model_id == $mid) { if (is_array($val)) { foreach ($val as $k => $v) { $curFld = $fld; if ($field->type == 'select' || $field->type == 'checkbox' || $field->type == 'radio') { $curFld['marked'] = $v; } else { $curFld['value'] = $v; } if (isset($curFld['label']) && $dynamic) { $curFld['label'] = ' '; } if (!isset($curFields[$field->id])) { $curFields[$field->id] = array('field_' . $field->id . '_cur_' . ($k + 1) => $curFld); } else { $curFields[$field->id]['field_' . $field->id . '_cur_' . ($k + 1)] = $curFld; } } } else { $curFld = $fld; if ($field->type == 'select' || $field->type == 'checkbox' || $field->type == 'radio') { $curFld['marked'] = $val; } else { $curFld['value'] = $val; } if (isset($curFld['label']) && $dynamic) { $curFld['label'] = ' '; } if (!isset($curFields[$field->id])) { $curFields[$field->id] = array('field_' . $field->id => $curFld); } else { $curFields[$field->id]['field_' . $field->id] = $curFld; } } } } } // If field is assigned to a dynamic field group, set field name accordingly if (count($groupAry) > 0 && $isDynamic) { $fieldName = 'field_' . $field->id . '_new_1'; } else { $fieldName = 'field_' . $field->id; } // Add field to the field array $fieldsAry[$fieldName] = $fld; // If in the system back end, and the field is a textarea, add history select field if ($mid != 0 && strpos($field->type, '-history') !== false && count($groupAry) == 0 && strpos($_SERVER['REQUEST_URI'], APP_URI) !== false) { $fv = Table\FieldValues::findById(array($field->id, $mid)); if (isset($fv->field_id) && null !== $fv->history) { $history = array(0 => '(' . $i18n->__('Current') . ')'); $historyAry = json_decode($fv->history, true); krsort($historyAry); foreach ($historyAry as $time => $fieldValue) { $history[$time] = date('M j, Y H:i:s', $time); } $fieldsAry['history_' . $mid . '_' . $field->id] = array('type' => 'select', 'label' => $i18n->__('Select Revision'), 'value' => $history, 'marked' => 0, 'attributes' => array('onchange' => "phire.changeHistory(this, '" . BASE_PATH . APP_URI . "');", 'style' => 'width: 160px;')); } } if (strpos($field->type, 'textarea') !== false) { if (null !== $field->editor && $field->editor != 'source') { $fieldsAry[$fieldName]['label'] .= ' <span style="float: right; margin-right: 4%; font-weight: normal;">[ <a href="#" class="editor-link" id="editor-' . $field->id . '" data-editor="' . $field->editor . '" data-editor-status="on" onclick="phire.changeEditor(this); return false;">' . $i18n->__('Source') . '</a> ]</span>'; } } // Add a remove field if (null !== $rmFile) { foreach ($rmFile as $rmKey => $rmValue) { $fieldsAry[$rmKey] = $rmValue; } } if (isset($group) && count($group) > 0) { if (isset($group[count($group) - 1]) && $field->id == $group[count($group) - 1]) { $fieldsAry[implode('_', $group)] = null; $group = array(); } } } } // Add fields from dynamic field group in the correct order $realCurFields = array(); $groupRmAry = array(); if (count($curFields) > 0) { $fieldCount = count($curFields); $keys = array_keys($curFields); $valueCounts = array(); foreach ($groups as $key => $value) { foreach ($curFields as $k => $v) { if (in_array($k, $value)) { $valueCounts[$key] = count($v); } } } foreach ($valueCounts as $gKey => $valueCount) { for ($i = 0; $i < $valueCount; $i++) { $fileName = null; $gDynamic = false; for ($j = 0; $j < $fieldCount; $j++) { if (in_array($keys[$j], $groups[$gKey])) { if (isset($curFields[$keys[$j]]['field_' . $keys[$j] . '_cur_' . ($i + 1)])) { $gDynamic = true; $f = $curFields[$keys[$j]]['field_' . $keys[$j] . '_cur_' . ($i + 1)]; if ($f['type'] == 'file') { $hasFile = true; $dynamic = true; $fileName = $f['value']; // Calculate file icon, set label if (!empty($fileName)) { $fileInfo = \Phire\Model\Media::getFileIcon($fileName); $f['label'] = '<br /><a href="' . BASE_PATH . CONTENT_PATH . '/media/' . $fileName . '" target="_blank"><img style="padding-top: 3px;" src="' . BASE_PATH . CONTENT_PATH . $fileInfo['fileIcon'] . '" width="50" /></a><br /><a href="' . BASE_PATH . CONTENT_PATH . '/media/' . $fileName . '" target="_blank">' . $fileName . '</a><br /><span style="font-size: 0.9em;">(' . $fileInfo['fileSize'] . ')</span><br /><em style="font-size: 0.9em; font-weight:normal;">' . $i18n->__('Replace?') . '</em>'; } else { $f['label'] = $i18n->__('Replace?'); } $fld['required'] = false; } $realCurFields['field_' . $keys[$j] . '_cur_' . ($i + 1)] = $f; } else { if (isset($curFields[$keys[$j]]['field_' . $keys[$j]])) { $gDynamic = false; $f = $curFields[$keys[$j]]['field_' . $keys[$j]]; if ($f['type'] == 'file') { $hasFile = true; $dynamic = true; $fileName = $f['value']; // Calculate file icon, set label if (!empty($fileName)) { $fileInfo = \Phire\Model\Media::getFileIcon($fileName); $f['label'] = '<br /><a href="' . BASE_PATH . CONTENT_PATH . '/media/' . $fileName . '" target="_blank"><img style="padding-top: 3px;" src="' . BASE_PATH . CONTENT_PATH . $fileInfo['fileIcon'] . '" width="50" /></a><br /><a href="' . BASE_PATH . CONTENT_PATH . '/media/' . $fileName . '" target="_blank">' . $fileName . '</a><br /><span style="font-size: 0.9em;">(' . $fileInfo['fileSize'] . ')</span><br /><em style="font-size: 0.9em; font-weight:normal;">' . $i18n->__('Replace?') . '</em>'; } else { $f['label'] = $i18n->__('Replace?'); } $fld['required'] = false; } $fieldsAry['field_' . $keys[$j]] = $f; } } } } // Add a remove field if ($gDynamic) { $fieldId = implode('_', $groups[$gKey]) . '_' . ($i + 1); $realCurFields['rm_fields_' . $fieldId] = array('type' => 'checkbox', 'value' => array($fieldId => $i18n->__('Remove') . '?')); } else { $fieldId = implode('_', $groups[$gKey]); $groupRmAry[$key] = array('type' => 'checkbox', 'value' => array($fieldId => $i18n->__('Remove') . '?')); } } } } // Merge new fields and current fields together in the right order. $realFieldsAry = array('dynamic' => $dynamic, 'hasFile' => $hasFile, '0' => array()); if (count($groups) > 0) { foreach ($groups as $id => $fields) { $realFieldsAry[$id] = array(); } } $cnt = 0; foreach ($fieldsAry as $key => $value) { $id = substr($key, strpos($key, '_') + 1); if (strpos($id, '_') !== false) { $id = substr($id, 0, strpos($id, '_')); } $curGroupId = 0; foreach ($groups as $gId => $gFields) { if (in_array($id, $gFields)) { $curGroupId = $gId; } } if (strpos($key, 'new_') !== false) { $cnt = 0; $curGroup = null; foreach ($groups as $group) { if (in_array($id, $group)) { $curGroup = $group; } } $realFieldsAry[$curGroupId][$key] = $value; if (null !== $curGroup && $id == $curGroup[count($curGroup) - 1]) { foreach ($realCurFields as $k => $v) { if (strpos($k, 'rm_field') === false) { $i = substr($k, strpos($k, '_') + 1); $i = substr($i, 0, strpos($i, '_')); if (in_array($i, $curGroup)) { $realFieldsAry[$curGroupId][$k] = $v; } } else { $i = substr($k, strpos($k, 'rm_fields_') + 10); $i = substr($i, 0, strrpos($i, '_')); $grp = explode('_', $i); if ($grp == $curGroup) { $realFieldsAry[$curGroupId][$k] = $v; } } } } } else { $cnt++; $realFieldsAry[$curGroupId][$key] = $value; if (isset($groupRmAry[$curGroupId]) && $cnt == count($groups[$curGroupId])) { $realFieldsAry[$curGroupId]['rm_fields_' . implode('_', $groups[$curGroupId])] = $groupRmAry[$curGroupId]; } } } return $realFieldsAry; }