public function onMove($typeProgress, $module, $name, $copy = FALSE) { $imgs = $this->getConfig('img'); foreach ($imgs as $img) { $oldPath = $img['name']; $imagePath = substr(strstr($oldPath, '/files/'), 7); $newPath = $module . '/files/' . $imagePath; if ($oldPath !== $newPath) { if (stream_resolve_include_path($newPath) !== FALSE) { /* check if an image with this path already exists in profile */ $fileInfo = pathinfo($imagePath); $extension = strtolower($fileInfo['extension']); $filename = $fileInfo['filename']; /* allow to not overload filename with name_0_3_2_0 ... */ $generatedPart = strrchr($filename, '_'); if ($generatedPart !== FALSE && is_numeric(substr($generatedPart, 1))) { $filename = substr($fileInfo['filename'], 0, -strlen($generatedPart)); } $nbn = 0; while (stream_resolve_include_path($newPath)) { $imagePath = $filename . '_' . $nbn . '.' . $extension; $newPath = $module . '/files/' . $imagePath; $nbn++; } } $this->setConfig('imgPath', $newPath); \tools::file_put_contents(PROFILE_PATH . $newPath, file_get_contents($oldPath, FILE_USE_INCLUDE_PATH)); } } }
public function setContent($html) { if (\app::getClass('user')->VerifyConnexion() && $_SESSION['permissions'] & 128) { /* perm 128 = configure blocks */ return \tools::file_put_contents(PROFILE_PATH . $this->getConfig('viewPath'), \tools::sanitize($html)); } return FALSE; }
/** * Get, decode base 64 & file put content * @param string $file * @param string $code * @return string */ protected function savePictureAction($file, $code) { return \tools::file_put_contents($file, base64_decode($code)); }
/** * Returns HTML view, manages cache of a block... * @return string */ public function display() { $html = ''; $balise = 'div'; $maxAge = 0; $headerTitle = $CSSclasses = $attributes = ''; $ajaxLoad = FALSE; foreach ($this->configs as $name => $config) { switch ($name) { case 'devices': if (is_array($config) && !in_array(DEVICE, $config)) { return ''; } break; case 'allowedModules': if (is_array($config) && !in_array(MODULE, $config)) { return ''; } break; case 'allowedRoles': if (is_array($config) && !in_array($_SESSION['id_role'], $config)) { return ''; } break; case 'tag': $balise = $config; break; case 'maxAge': $maxAge = (int) $config; break; case 'headerTitle': if ($config) { $headerTitle = '<h2 class="parsiTitle">' . t($config) . '</h2>'; } break; case 'cssClasses': $CSSclasses .= ' ' . $config; break; case 'attributes': $attributes .= ' ' . $config; break; case 'ajaxReload': if ((int) $config > 0 && \app::$request->isAjax() === FALSE) { \app::$response->head .= '<script>$(document).ready(function(){setInterval("loadBlock(\'' . $this->id . '\')", ' . $config . '000);});</script>'; } break; case 'ajaxLoad': if ($config == 1 && \app::$request->isAjax() === FALSE) { $ajaxLoad = TRUE; \app::$response->head .= '<script>$(document).ready(function(){loadBlock("' . $this->id . '")});</script>'; } break; case 'CSSFiles': foreach ($config as $file => $pos) { \app::$response->addCSSFile(strstr($file, '//') ? $file : $file, $pos); } break; case 'JSFiles': foreach ($config as $file => $pos) { \app::$response->addJSFile(strstr($file, '//') ? $file : $file, $pos); } break; default: break; } } $cacheFile = 'var/cache/' . PROFILE_PATH . $this->moduleName . '/blocks/' . $this->blockName . '/' . MODULE . '_' . $this->id . '.cache'; if ($maxAge > 0 && is_file($cacheFile) && filemtime($cacheFile) + $maxAge > time()) { ob_start(); include $cacheFile; $html .= ob_get_clean(); } else { $html .= '<' . $balise . ' id="' . $this->id . '" is="' . $this->moduleName . '-' . $this->blockName . '" class="parsiblock ' . $this->moduleName . '_' . $this->blockName . $CSSclasses . '"' . $attributes . '>' . $headerTitle; if ($ajaxLoad === FALSE) { /* Catch all exceptions or error in order to keep tha page structure in creation mode */ try { $view = $this->getView(); $html .= $view; } catch (\Exception $e) { if ($_SESSION['permissions'] > 0) { /* Display Error or exception just for the dev */ ob_clean(); $html .= '<div class="PHPError"><div class="titleError"><strong>Block </strong>#' . $this->getId() . ' </div>'; $html .= '<div class="error"> <strong>' . t('Error') . ' ' . t('in line') . ' </strong>' . $e->getLine() . ' : </strong>' . $e->getMessage() . '</div>'; $html .= '<div class="file"><strong>File : </strong>' . $e->getFile() . '</div></div>'; } unset($GLOBALS['lastError']); /* to avoid to display error at the end of page load*/ } } $html .= '</' . $balise . '>'; if ($maxAge > 0) { tools::file_put_contents($cacheFile, $html); } } return $html; }
/** * Put contents in file * @return bool */ public function save() { return tools::file_put_contents($this->file, $this->content); }
public function onMove($typeProgress, $module, $name, $copy = FALSE) { $oldPath = $this->getConfig('viewPath'); if ($typeProgress === 'theme') { $path = $module . '/themes/' . $name . '/views/' . $this->id . '.php'; } else { $path = $module . '/pages/views/' . $this->id . '.php'; } if (is_file(PROFILE_PATH . $path) === FALSE) { /* check if a view with this path already exists in profile */ $this->setConfig('viewPath', $path); /* save the new path */ if (!empty($oldPath) && stream_resolve_include_path($oldPath) !== FALSE) { /* Check if we have to move an old view : moveBlock */ \tools::file_put_contents(PROFILE_PATH . $path, file_get_contents($oldPath, FILE_USE_INCLUDE_PATH)); if (is_file(PROFILE_PATH . $oldPath) && $copy === FALSE) { rename(PROFILE_PATH . $oldPath, PROFILE_PATH . $oldPath . '.back'); } //do only for profile, not modules } else { /* add block */ \tools::file_put_contents(PROFILE_PATH . $path, '<h1>' . t('Start programming in this area') . '</h1>'); } } else { return FALSE; // a view with this ID already exists } }
/** * Serialize an object in a file * @param string $filename * @param object $obj * @return bool */ public static function serialize($filename, $obj) { $objCopy = clone $obj; /* to let used object awake => don't call _sleep on $obj */ $serial = serialize($objCopy); /* we save serialized objects with aliases names to allow to overreide classes and reduce file size */ foreach (\app::$aliasClasses as $alias => $className) { $serial = str_replace('O:' . strlen($className) . ':"' . $className . '"', 'O:' . strlen($alias) . ':"' . $alias . '"', $serial); } return \tools::file_put_contents($filename . '.obj', $serial); }
/** * Save file * @param string $selector * @return bool */ public function save() { $output = ''; $media = 'first'; $oldMedia = 'first'; foreach ($this->selectors as $selector) { $media = isset($selector['media']) ? $selector['media'] : ''; if ($oldMedia != $media) { if (!empty($output)) { if (!empty($oldMedia)) { $output .= PHP_EOL . '}'; } if (!empty($media)) { $output .= (isset($selector['bmedia']) ? $selector['bmedia'] : '') . $media . '{'; } } $oldMedia = $media; } if (!empty($selector['p'])) { $output .= $selector['b'] . $selector['s'] . ' {' . $selector['p'] . '}'; } } if (substr($media, 0, 1) == '@') { $output .= PHP_EOL . '}'; } return \tools::file_put_contents($this->path, $output); }
/** * Detetermine Locale from current HTTP request */ protected function determineLocale() { if (isset($_COOKIE['locale']) && isset(self::$locales[$_COOKIE['locale']])) { $this->locale = $_COOKIE['locale']; } else { $this->locale = app::$config['localization']['default_language']; } setlocale(LC_ALL, $this->locale); date_default_timezone_set(app::$config['localization']['timezone']); $pathCache = 'var/cache/' . $this->locale . '-lang'; $lang = ''; if (is_file($pathCache . '.php')) { include $pathCache . '.php'; } else { foreach (app::$activeModules as $moduleName => $type) { if (is_file('modules/' . $moduleName . '/locale/' . $this->locale . '.php')) { include 'modules/' . $moduleName . '/locale/' . $this->locale . '.php'; } } $config = new \config($pathCache . '.php', TRUE); $config->setVariable('lang'); $config->saveConfig($lang); \tools::file_put_contents($pathCache . '.js', substr($config->getContent(), 5, false)); } app::$lang = $lang; }