protected function create($app_id, $module, $action_type, $action_names) { $files_created = array(); // Generate PHP controller contents $php_wrap = $this->getPhpWrap($app_id, $module, $action_type, $action_names); $php_inner = $this->getPhpInner($action_type, $action_names); $php = str_replace('%CLASS_CONTENT%', $php_inner, $php_wrap); // Save PHP controller into a file $action_path = wa()->getAppPath('lib/actions/' . $module . '/', $app_id); $action_filename = $this->getPhpFilename($app_id, $module, $action_type, $action_names); waFiles::create($action_path); file_put_contents($action_path . $action_filename, $php); $files_created[] = $action_path . $action_filename; // Save templates if ($action_type == 'action' || $action_type == 'actions') { $template_path = wa()->getAppPath('templates/actions/' . $module . '/', $app_id); waFiles::create($template_path); foreach ($action_names as $action_name) { $template_filename = $this->getTemplateFilename($module, $action_type, $action_name); file_put_contents($template_path . $template_filename, "<h1>Hello, World!</h1> <!-- !!! TODO FIXME -->\n\n<p>{$action_path}{$action_filename}</p>\n<p>{$template_path}{$template_filename}</p>"); $files_created[] = $template_path . $template_filename; } } print "Successfully created the following files:\n" . join("\n", $files_created); }
public static function log($message, $file = 'error.log') { $path = waConfig::get('wa_path_log'); if (!$path) { $path = dirname(dirname(dirname(__FILE__))); } $path .= '/' . $file; if (!file_exists($path)) { waFiles::create(dirname($path)); touch($path); chmod($path, 0666); } elseif (!is_writable($path)) { return false; } $fd = fopen($path, 'a'); if (!flock($fd, LOCK_EX)) { throw new waException('Unable to lock ' . $path); } fwrite($fd, "\n"); fwrite($fd, date('Y-m-d H:i:s: ')); fwrite($fd, $message); fflush($fd); flock($fd, LOCK_UN); fclose($fd); return true; }
public function execute() { $path = null; $photo_rights_model = new photosPhotoRightsModel(); $photo_id = waRequest::get('photo_id', null, waRequest::TYPE_INT); if ($photo_rights_model->checkRights($photo_id, true)) { $photo_model = new photosPhotoModel(); if ($photo = $photo_model->getById($photo_id)) { if (waRequest::get('original')) { $path = photosPhoto::getOriginalPhotoPath($photo); } else { $path = photosPhoto::getPhotoPath($photo); } } } if ($path) { if ($attach = waRequest::get('attach') ? true : false) { $response = $this->getResponse(); $response->addHeader('Expires', 'tomorrow'); $response->addHeader('Cache-Control', ($photo['status'] == 1 ? 'public' : 'private') . ', max-age=' . 86400 * 30); } waFiles::readFile($path, $attach ? null : basename($photo['name'] . '.' . $photo['ext']), true, !$attach); } else { throw new waException(_w("Photo not found"), 404); } }
public function execute() { $p = $path = rtrim(waRequest::post('path'), ' /'); $file = waRequest::post('file'); try { if ($file) { if (!is_array($file)) { $file = array($file); } foreach ($file as $f) { $f = $path . '/' . $f; waFiles::delete(wa()->getDataPath($f, true, null, false)); } $this->log('file_delete', count($file)); } else { $path = wa()->getDataPath($path, true, null, false); if (!is_writable($path)) { $this->errors = sprintf(_w("Folder could not bet deleted due to the insufficient permissions."), $p); } else { waFiles::delete($path); $this->log('file_delete', 1); } } } catch (Exception $e) { $this->errors = $e->getMessage(); } }
public function execute() { $path = $this->getConfig()->getConfigPath('data/welcome/', false); if (file_exists($path)) { $files = waFiles::listdir($path, false); $this->types = shopTypeModel::getTemplates(); foreach ($files as $file) { if (preg_match('/^country_([a-z]{3})\\.php$/', $file, $matches)) { $this->countries[$matches[1]] = $matches[1]; } } } $locale_path = $path . 'locale/' . $this->getUser()->getLocale() . '.php'; if (file_exists($locale_path)) { $this->translate = (include $locale_path); if (!is_array($this->translate)) { $this->translate = array(); } } if (waRequest::post()) { $app_settings_model = new waAppSettingsModel(); $app_settings_model->del('shop', 'welcome'); $this->setup(); } else { $this->overview(); } }
public function execute() { $product_id = $this->get('product_id', true); $this->getProduct($product_id); $file = waRequest::file('file'); $image = $file->waImage(); if ($file->uploaded()) { $data = array('product_id' => $product_id, 'upload_datetime' => date('Y-m-d H:i:s'), 'width' => $image->width, 'height' => $image->height, 'size' => $file->size, 'original_filename' => basename($file->name), 'ext' => $file->extension, 'description' => waRequest::post('description')); $product_images_model = new shopProductImagesModel(); $image_id = $data['id'] = $product_images_model->add($data); if (!$image_id) { throw new waAPIException('server_error', 500); } /** * @var shopConfig $config */ $config = wa('shop')->getConfig(); $image_path = shopImage::getPath($data); if (file_exists($image_path) && !is_writable($image_path) || !file_exists($image_path) && !waFiles::create($image_path)) { $product_images_model->deleteById($image_id); throw new waAPIException(sprintf("The insufficient file write permissions for the %s folder.", substr($image_path, strlen($config->getRootPath())))); } $file->moveTo($image_path); unset($image); shopImage::generateThumbs($data, $config->getImageSizes()); $method = new shopProductImagesGetInfoMethod(); $_GET['id'] = $image_id; $this->response = $method->getResponse(true); } else { throw new waAPIException('server_error', $file->error); } }
public function execute() { $name = basename(waRequest::get('file', 'export.csv')); $profile = waRequest::get('profile', 0, waRequest::TYPE_INT); $file = wa()->getTempPath('csv/download/' . $profile . '/' . $name); waFiles::readFile($file, $name); }
public function execute() { ob_start(); $app = $this->getApp(); $app_settings_model = new waAppSettingsModel(); $app_settings_model->set($app, 'cron_schedule', time()); waFiles::create($this->getConfig()->getPath('log') . '/' . $app . '/'); $log_file = "{$app}/cron.txt"; $post_model = new blogPostModel(); $params = array('datetime' => date("Y-m-d H:i:s"), 'status' => blogPostModel::STATUS_SCHEDULED); $posts_schedule = $post_model->select("id,blog_id,contact_id,status,datetime")->where('datetime <= s:datetime AND status=s:status', $params)->fetchAll(); if ($posts_schedule) { foreach ($posts_schedule as $post) { try { waLog::log("Attempt publishing post with id [{$post['id']}]", $log_file); $data = array("status" => blogPostModel::STATUS_PUBLISHED); waLog::log($post_model->updateItem($post['id'], $data, $post) ? "success" : "fail", $log_file); } catch (Exception $ex) { waLog::log($ex->getMessage(), $log_file); waLog::log($ex->getTraceAsString(), $log_file); } } } $action = __FUNCTION__; /** * @event cron_action * @param string $action * @return void */ wa()->event('cron_action', $action); if ($log = ob_get_clean()) { waLog::log($log, $log_file); } }
protected function removeExtras($app_id, $extras_id, $info) { try { $paths = array(); $plugin_instance = waSystem::getInstance($app_id)->getPlugin($extras_id); if (!$plugin_instance) { return false; } $plugin_instance->uninstall(); $this->installer->updateAppPluginsConfig($app_id, $extras_id, null); //wa-apps/$app_id/plugins/$slug $paths[] = wa()->getAppPath("{$this->extras_type}/{$extras_id}", $app_id); $paths[] = wa()->getTempPath(null, $app_id); //wa-cache/temp/$app_id/ $paths[] = wa()->getAppCachePath(null, $app_id); //wa-cache/apps/$app_id/ foreach ($paths as $path) { waFiles::delete($path, true); } return true; } catch (Exception $ex) { //TODO check config $this->installer->updateAppPluginsConfig($app_id, $extras_id, true); throw $ex; } }
/** * Write message into log file. * * @return bool */ public static function log($message, $file = 'error.log') { if (!self::$path) { self::$path = waConfig::get('wa_path_log'); if (!self::$path) { self::$path = wa()->getConfig()->getRootPath() . DIRECTORY_SEPARATOR . 'wa-log'; } self::$path .= DIRECTORY_SEPARATOR; } $file = self::$path . $file; if (!file_exists($file)) { waFiles::create($file); touch($file); chmod($file, 0666); } elseif (!is_writable($file)) { return false; } $fd = fopen($file, 'a'); if (flock($fd, LOCK_EX)) { fwrite($fd, PHP_EOL . date('Y-m-d H:i:s:') . PHP_EOL . $message); fflush($fd); flock($fd, LOCK_UN); } fclose($fd); return true; }
function execute() { try { $message = array(); $settings = waRequest::get('setting'); if ($settings) { $model = new waAppSettingsModel(); $changed = false; foreach ((array) $settings as $setting) { if (in_array($setting, array('auth_form_background'))) { if ($value = $model->get('webasyst', $setting)) { waFiles::delete(wa()->getDataPath($value, true, 'webasyst')); $message[] = _w('Image deleted'); } } else { $changed = true; } $model->set('webasyst', $setting, false); } if ($changed) { $message[] = _w('Settings saved'); } } $params = array('module' => 'settings', 'msg' => installerMessage::getInstance()->raiseMessage(implode(', ', $message))); $this->redirect($params); } catch (waException $ex) { $msg = installerMessage::getInstance()->raiseMessage($ex->getMessage(), installerMessage::R_FAIL); $params = array('module' => 'settings', 'msg' => $msg); $this->redirect($params); } }
public function load($locale, $locale_path, $domain, $textdomain = true) { $file = $locale_path . '/' . $locale . '/LC_MESSAGES/' . $domain . '.po'; $cache_file = waSystem::getInstance()->getConfig()->getPath('cache') . '/apps/' . $domain . '/locale/' . $locale . '.php'; if (isset(self::$cache[$locale][$domain])) { } elseif (!file_exists($file)) { self::$cache[$locale][$domain] = array(); } elseif (file_exists($cache_file) && filemtime($cache_file) > filemtime($file)) { self::$cache[$locale][$domain] = (include $cache_file); } else { if (file_exists($file)) { $gettext = new waGettext($file); self::$cache[$locale][$domain] = $gettext->read(); } else { self::$cache[$locale][$domain] = array(); } waFiles::create($cache_file); waUtils::varExportToFile(self::$cache[$locale][$domain], $cache_file); } if (isset(self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']) && self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']) { self::$cache[$locale][$domain]['meta']['f'] = create_function('$n', self::$cache[$locale][$domain]['meta']['Plural-Forms']['plural']); } if ($textdomain) { self::$domain = $domain; self::$locale = $locale; } if (!self::$locale) { self::$locale = $locale; } }
public function execute() { $filepath = wa()->getCachePath('plugins/discountcards/export-discountcards.csv', 'shop'); if (!file_exists($filepath)) { throw new waException(_ws("Page not found"), 404); } waFiles::readFile($filepath, 'export-discountcards.csv'); }
public static function delete($file) { self::loadPath(); $file = preg_replace('!\\.\\.[/\\\\]!', '', $file); $file = self::$path . $file; if (file_exists($file)) { waFiles::delete($file); } }
protected function save(waRequestFile $file) { $product_id = waRequest::post('product_id', null, waRequest::TYPE_INT); $product_model = new shopProductModel(); if (!$product_model->checkRights($product_id)) { throw new waException(_w("Access denied")); } // check image if (!($image = $file->waImage())) { throw new waException('Incorrect image'); } $image_changed = false; /** * Extend upload proccess * Make extra workup * @event image_upload */ $event = wa()->event('image_upload', $image); if ($event) { foreach ($event as $plugin_id => $result) { if ($result) { $image_changed = true; } } } if (!$this->model) { $this->model = new shopProductImagesModel(); } $data = array('product_id' => $product_id, 'upload_datetime' => date('Y-m-d H:i:s'), 'width' => $image->width, 'height' => $image->height, 'size' => $file->size, 'original_filename' => basename($file->name), 'ext' => $file->extension); $image_id = $data['id'] = $this->model->add($data); if (!$image_id) { throw new waException("Database error"); } /** * @var shopConfig $config */ $config = $this->getConfig(); $image_path = shopImage::getPath($data); if (file_exists($image_path) && !is_writable($image_path) || !file_exists($image_path) && !waFiles::create($image_path)) { $this->model->deleteById($image_id); throw new waException(sprintf("The insufficient file write permissions for the %s folder.", substr($image_path, strlen($config->getRootPath())))); } if ($image_changed) { $image->save($image_path); // save original $original_file = shopImage::getOriginalPath($data); if ($config->getOption('image_save_original') && $original_file) { $file->moveTo($original_file); } } else { $file->moveTo($image_path); } unset($image); // free variable shopImage::generateThumbs($data, $config->getImageSizes()); return array('id' => $image_id, 'name' => $file->name, 'type' => $file->type, 'size' => $file->size, 'url_thumb' => shopImage::getUrl($data, $config->getImageSize('thumb')), 'url_crop' => shopImage::getUrl($data, $config->getImageSize('crop')), 'url_crop_small' => shopImage::getUrl($data, $config->getImageSize('crop_small')), 'description' => ''); }
/** * Список доступных плагинов * @param $options array * @return array */ public static function enumerate($options = array(), $type = null) { $plugins = array(); foreach (waFiles::listdir(self::getPath($type)) as $id) { if ($info = self::info($id, $options = array(), $type)) { $plugins[$id] = $info; } } return $plugins; }
public function execute() { $contact = wa()->getUser(); $contact['photo'] = 0; $contact->save(); $oldDir = wa()->getDataPath(waContact::getPhotoDir($contact->getId()), true, 'contacts', false); if (file_exists($oldDir)) { waFiles::delete($oldDir); } $this->response = array('done' => 1); }
public function execute() { $app_id = $this->getRequest()->get('app'); $path = $this->getRequest()->get('path'); if ($this->getRequest()->get('temp')) { $file = waSystem::getInstance()->getTempPath($path, $app_id); } else { $file = waSystem::getInstance()->getDataPath($path, false, $app_id); } waFiles::readFile($file); }
public function execute() { $path = waRequest::get('path'); $full_path = logsHelper::getAbsolutePath($path); $available = logsHelper::checkPath($full_path, false); if ($available) { $file_name = basename($full_path); waFiles::readFile($full_path, $file_name); } else { $this->redirect(wa()->getAppUrl()); } }
public function execute() { $path = rtrim(waRequest::get('path'), ' /'); $path = wa()->getDataPath($path, true, null, false); $file = waRequest::get('file'); $path .= '/' . $file; if (file_exists($path) && is_file($path) && !in_array(waFiles::extension($path, array('php', 'phtml')))) { waFiles::readFile($path, $file); } else { throw new waException("File not found", 404); } }
public function execute() { $id = waRequest::post('id'); if (is_numeric($id)) { $modelNotifierTemplate = new shopNotifierTemplateModel(); $path = shopNotifierPlugin::path($id); waFiles::delete($path); $modelNotifierTemplate->deleteById($id); $this->response['message'] = 'ok'; } else { $this->response['message'] = 'fail'; } }
protected function removeExtras($app_id, $extras_id, $info) { $paths = array(); $paths[] = wa()->getTempPath(null, $app_id); //wa-cache/temp/$app_id/ //wa-apps/$app_id/extrass/$slug $paths[] = wa()->getAppPath("{$this->extras_type}/{$extras_id}", $app_id); $paths[] = wa()->getAppCachePath(null, $app_id); //wa-cache/apps/$app_id/ foreach ($paths as $path) { waFiles::delete($path, true); } return true; }
/** * @param string $file CSV file path * @param string $delimiter * @param string $encoding * @param string $method mb or iconv encoding method (default is iconv) */ public function __construct($file, $delimiter = ';', $encoding = 'utf-8', $method = 'iconv') { $this->file = ifempty($file); $this->delimiter = ifempty($delimiter, ';'); if ($this->delimiter == 'tab') { $this->delimiter = "\t"; } $this->encoding = ifempty($encoding, 'utf-8'); $this->method = in_array($method, array('mb', 'icon'), true) ? $method : 'iconv'; if ($this->file()) { waFiles::create($this->file); } $this->restore(); }
protected function create($app_id, $class_name, $table) { $files_created = array(); // Save PHP into a file $path = wa()->getAppPath('lib/model/', $app_id); if (!file_exists($path)) { // shop and helpdesk use `model` dir instead of `models` for some reason $path = wa()->getAppPath('lib/models/', $app_id); } $filename = preg_replace('~Model$~', '', $class_name) . '.model.php'; waFiles::create($path); file_put_contents($path . $filename, $this->getPhp($app_id, $class_name, $table)); $files_created[] = $path . $filename; print "Successfully created:\n" . join("\n", $files_created); }
/** * Userpic */ public function photoAction() { $id = (int) waRequest::get('id'); if (!$id) { $id = $this->getUser()->getId(); } $contact = new waContact($id); $rand = $contact['photo']; $file = wa()->getDataPath("photo/{$id}/{$rand}.original.jpg", TRUE, 'contacts'); $size = waRequest::get('size'); if (!file_exists($file)) { $size = (int) $size; if (!in_array($size, array(20, 32, 50, 96))) { $size = 96; } waFiles::readFile($this->getConfig()->getRootPath() . '/wa-content/img/userpic' . $size . '.jpg'); } else { // original file if ($size == 'original') { waFiles::readFile($file); } elseif ($size == 'full') { $file = str_replace('.original.jpg', '.jpg', $file); waFiles::readFile($file); } else { if (!$size) { $size = '96x96'; } $size_parts = explode('x', $size, 2); $size_parts[0] = (int) $size_parts[0]; if (!isset($size_parts[1])) { $size_parts[1] = $size_parts[0]; } else { $size_parts[1] = (int) $size_parts[1]; } if (!$size_parts[0] || !$size_parts[1]) { $size_parts = array(96, 96); } $size = $size_parts[0] . 'x' . $size_parts[1]; $thumb_file = str_replace('.original.jpg', '.' . $size . '.jpg', $file); $file = str_replace('.original.jpg', '.jpg', $file); if (!file_exists($thumb_file) || filemtime($thumb_file) < filemtime($file)) { waImage::factory($file)->resize($size_parts[0], $size_parts[1])->save($thumb_file); clearstatcache(); } waFiles::readFile($thumb_file); } } }
protected function create($app_id, $layout) { $files_created = array(); // Save PHP into a file $layout_path = wa()->getAppPath('lib/layouts/', $app_id); $layout_filename = $app_id . ucfirst($layout) . '.layout.php'; waFiles::create($layout_path); file_put_contents($layout_path . $layout_filename, $this->getPhp($app_id, $layout)); $files_created[] = $layout_path . $layout_filename; // Save template into a file $template_path = wa()->getAppPath('templates/layouts/' . ucfirst($layout) . '.html', $app_id); waFiles::create($template_path); file_put_contents($template_path, $this->getHtml($app_id, $layout)); $files_created[] = $template_path; print "Successfully created the following files:\n" . join("\n", $files_created); }
public function execute() { $path = dirname(__FILE__); $files = waFiles::listdir($path); print "available CLI actions:\n"; $callback = create_function('$m', 'return strtolower($m[1]);'); $actions = array(); foreach ($files as $file) { if (preg_match('/^webasyst(\\w+)\\.cli\\.php$/', $file, $matches)) { $action = preg_replace_callback('/^([\\w]{1})/', $callback, $matches[1]); $actions[] = $action; } } asort($actions); print implode("\n", $actions); }
protected function save(waRequestFile $file) { if (!$this->model) { $this->model = new shopProductSkusModel(); } $field = array('id' => waRequest::post('sku_id', null, waRequest::TYPE_INT), 'product_id' => waRequest::post('product_id', null, waRequest::TYPE_INT)); $data = array('file_size' => $file->size, 'file_name' => $file->name); $this->model->updateByField($field, $data); $file_path = shopProduct::getPath($field['product_id'], "sku_file/{$field['id']}." . pathinfo($file->name, PATHINFO_EXTENSION)); if (file_exists($file_path) && !is_writable($file_path) || !file_exists($file_path) && !waFiles::create($file_path)) { $data = array('file_size' => 0, 'file_name' => ''); $this->model->updateByField($field, $data); throw new waException(sprintf("The insufficient file write permissions for the %s folder.", substr($file_path, strlen($this->getConfig()->getRootPath())))); } $file->moveTo($file_path); return array('name' => $file->name, 'size' => waFiles::formatSize($file->size)); }
public function execute() { $p = $path = rtrim(waRequest::post('path'), ' /'); if ($file = waRequest::post('file')) { $path .= '/' . $file; } $path = wa()->getDataPath($path, true, null, false); $name = trim(waRequest::post('name')); $name = preg_replace('!\\.\\.[/\\\\]!', '', $name); if ($file) { $name_ext = waFiles::extension($name); if ($name_ext != waFiles::extension($file) || !$name_ext) { if (strpos(strtolower($name), '.php') !== false) { if ($name_ext != 'php') { $name_ext = 'php'; } } if (in_array($name_ext, array('php', 'phtml'))) { $this->errors = sprintf(_w("Files with extension .%s are not allowed to security considerations."), $name_ext); return; } } } if (file_exists($path) && strlen($name)) { if (!is_writable(dirname($path))) { $this->errors = sprintf(_w("Folder or file could not bet renamed due to the insufficient file write permissions for the %s folder."), $p); } elseif (@rename($path, dirname($path) . '/' . $name)) { if ($file) { $this->response = $name; } else { $this->response = array('name' => $name, 'hash' => '#/files' . substr(dirname($path) . '/' . $name . '/', strlen(wa()->getDataPath('', true, null, false)))); } } else { $this->errors = _w("File (folder) can not be renamed"); } } else { if (!strlen($name)) { $this->errors = _w("Enter the new name"); } else { $this->errors = _w("Selected folder (file) does not exist anymore"); } } }
public function execute() { $id = $this->getId(); // Delete the old photos if they exist $oldDir = wa()->getDataPath(waContact::getPhotoDir($id), TRUE); if (file_exists($oldDir)) { waFiles::delete($oldDir); } // Update record in DB for this user $contact = new waContact($id); $contact['photo'] = 0; $contact->save(); // Update recent history to reload thumbnail correctly (if not called from personal account) if (wa()->getUser()->get('is_user')) { $history = new contactsHistoryModel(); $history->save('/contact/' . $id, null, null, '--'); } $this->response = array('done' => 1, 'url' => $contact->getPhoto()); }