public function execute() { /** * @deprecated * For backward compatibility reason */ $this->view->assign('cron_schedule_time', waSystem::getSetting('cron_schedule', 0, 'blog')); $this->view->assign('last_emailsubscription_cron_time', waSystem::getSetting('last_emailsubscription_cron_time', 0, array('blog', 'emailsubscription'))); $this->view->assign('cron_command', 'php ' . wa()->getConfig()->getRootPath() . '/cli.php blog emailsubscription'); }
private function initImport() { $name = basename(waRequest::post('file')); if (empty($name)) { throw new waException('Empty import filename'); } $config = wa('shop')->getConfig(); /** * @var shopConfig $config ; */ //TODO detect emulate & type of control $file = wa()->getTempPath('csv/upload/' . $name); $this->data['emulate'] = waRequest::post('emulate') ? array() : null; $this->data['rights'] = $this->getUser()->getRights('shop', 'settings'); $this->data['new_features'] = array(); $this->data['currencies'] = $config->getCurrencies(); $this->data['type_id'] = waRequest::post('type_id', null, waRequest::TYPE_INT); if ($this->data['type_id'] && !in_array($this->data['type_id'], $this->data['types'])) { $this->data['type_id'] = reset($this->data['types']); } $map = waRequest::post('csv_map'); if ($this->emulate()) { $this->reader = shopCsvReader::snapshot($file); if (!$this->reader) { throw new waException('CSV file not found'); } $this->reader->rewind(); } else { /*, waRequest::post('encoding', 'utf-8')*/ //after upload encoding converted into utf-8 $this->reader = new shopCsvReader($file, waRequest::post('delimiter', ';')); $header = $this->reader->header(); foreach ($map as $id => &$target) { if (preg_match('@^f\\+:(.+)$@', $target, $matches)) { if ($this->data['rights']) { $id = preg_replace('@\\D.*$@', '', $id); $feature = array('name' => ifset($header[$id], 'csv feature'), 'type' => shopFeatureModel::TYPE_VARCHAR, 'multiple' => 0, 'selectable' => 0); list($feature['type'], $feature['multiple'], $feature['selectable']) = explode(':', $matches[1]); $feature['type'] = preg_replace('@([^\\.]+\\.)\\1@', '$1', $feature['type']); if (empty($feature_model)) { $feature_model = new shopFeatureModel(); } if (empty($type_features_model)) { $type_features_model = new shopTypeFeaturesModel(); } $feature['id'] = $feature_model->save($feature); if ($this->data['type_id']) { $type_features_model->updateByFeature($feature['id'], array($this->data['type_id']), false); } $target = 'features:' . $feature['code']; $this->data['new_features'][$feature['code']] = array('id' => $feature['id'], 'types' => (array) $this->data['type_id']); } else { unset($map[$id]); } } } unset($target); } $map = array_flip($map); $this->reader->setMap($map); $this->data['file'] = serialize($this->reader); $this->data['primary'] = waRequest::post('primary', 'name'); $this->data['secondary'] = waRequest::post('secondary', 'skus:-1:sku'); $this->data['extra_secondary'] = false; switch ($this->data['secondary']) { case 'skus:-1:sku': if (isset($map['skus:-1:name']) && intval($map['skus:-1:name']) >= 0) { $this->data['extra_secondary'] = 'skus:-1:name'; } break; case 'skus:-1:name': if (isset($map['skus:-1:sku']) && intval($map['skus:-1:sku']) >= 0) { $this->data['extra_secondary'] = 'skus:-1:sku'; } break; } $upload_app = waRequest::post('upload_app', 'shop', waRequest::TYPE_STRING_TRIM); if ($upload_app != 'site') { $upload_app = 'shop'; } $this->data['upload_path'] = preg_replace('@[\\\\/]+$@', '/', waRequest::post('upload_path', 'upload/images/') . '/'); $this->data['upload_path'] = preg_replace('@(^|/)(\\.\\.)/@', '$1/', $this->data['upload_path']); if (waSystem::getSetting('csv.upload_path') != $this->data['upload_path']) { $app_settings = new waAppSettingsModel(); $app_settings->set('shop', 'csv.upload_path', $this->data['upload_path']); } $this->data['virtual_sku_stock'] = waRequest::post('virtual_sku_stock', '', waRequest::TYPE_STRING_TRIM); if ($upload_app == 'site') { $this->data['upload_path'] = wa()->getDataPath($this->data['upload_path'], true, 'site'); } else { $this->data['upload_path'] = wa()->getDataPath($this->data['upload_path'], false, 'shop'); } if (waSystem::getSetting('csv.upload_app') != $upload_app) { if (empty($app_settings)) { $app_settings = new waAppSettingsModel(); } $app_settings->set('shop', 'csv.upload_app', $upload_app); } $this->data['ignore_category'] = !!waRequest::post('ignore_category', 0, waRequest::TYPE_INT); if (!in_array($this->data['primary'], array('name', 'url', 'null'))) { throw new waException(_w('Invalid primary field')); } if ($this->data['primary'] == 'null') { $this->data['primary'] = null; } if (!in_array($this->data['secondary'], array('skus:-1:sku', 'skus:-1:name'))) { throw new waException(_w('Invalid secondary field')); } $current = $this->reader->current(); if (!empty($this->data['primary']) && self::getData($current, $this->data['primary']) === null) { throw new waException(_w('Empty primary CSV column')); } if (empty($this->data['primary']) && self::getData($current, $this->data['secondary']) === null) { throw new waException(_w('Empty secondary CSV column')); } $this->data['count'] = array(self::STAGE_FILE => $this->reader ? $this->reader->size() : null, self::STAGE_CATEGORY => null, self::STAGE_PRODUCT => null, self::STAGE_SKU => null, self::STAGE_IMAGE => null); }
public function blogAction($params) { if (!empty($params['blog'])) { $blog_id = $params['blog']['id']; $model = new blogEmailsubscriptionModel(); $subscribed = $model->getByField(array('blog_id' => $blog_id, 'contact_id' => wa()->getUser()->getId())); /** * @deprecated * For backward compatibility reason */ $cron_schedule_time = waSystem::getSetting('cron_schedule', 0, 'blog'); $last_emailsubscription_cron_time = waSystem::getSetting('last_emailsubscription_cron_time', 0, array('blog', 'emailsubscription')); if (!$cron_schedule_time && !$last_emailsubscription_cron_time) { $msg = sprintf(_wp('WARNING: Email subscription works only if Cron scheduled task for the Blog app is properly configured (%s), and it appears that Cron was not setup for your Webasyst installation yet. Please contact your server administrator, or follow instructions given in the Plugins > Email subscription page of the Blog app. Click OK to subscribe anyway (subscription will be enabled, but will start to work only when Cron is enabled).'), 'cli.php blog emailsubscription'); $confirm_subscribe = "\n if (\$(this).is(':checked') && !confirm('" . $msg . "')) { \n \$(this).iButton('toggle', false);\n return false;\n }\n subscribe();\n "; } else { $confirm_subscribe = "subscribe();"; } $html = '<div class="b-ibutton-checkbox"> <ul class="menu-h"> <li style="margin-top: -3px;"><input type="checkbox" id="blog-emailsubscription-checkbox"' . ($subscribed ? ' checked="checked"' : '') . '></li> <li style="margin-top: -4px; padding-left: 0.3em; padding-right: 0.3em;"><span id="blog-emailsubscription-status"' . (!$subscribed ? ' class="b-unselected"' : '') . '>' . _wp('Email alerts') . '</span></li> </ul> </div> <script> $("#blog-emailsubscription-checkbox").iButton({ labelOn: "", labelOff: "", classContainer: "ibutton-container mini" }).change(function () { if ($(this).is(":checked")) { $("#blog-emailsubscription-status").removeClass("b-unselected"); } else { $("#blog-emailsubscription-status").addClass("b-unselected"); } var that = this; function subscribe() { $.post("?plugin=emailsubscription&module=subscribe", {blog_id:' . $blog_id . ', subscribe: $(that).is(":checked") ? 1 : 0}, function () { }, "json"); } ' . $confirm_subscribe . ' }); </script>'; return array('menu' => $html); } }
public function execute() { $post_id = waRequest::get('id', null, waRequest::TYPE_INT); $blog_model = new blogBlogModel(); $blogs = $blog_model->getAvailable(); if (!$blogs) { $this->setTemplate('BlogNotFound'); return; } $blogs = $blog_model->prepareView($blogs); if ($post_id) { // edit post $post_model = new blogPostModel(); $post = $post_model->getById($post_id); if (!$post) { throw new waException(_w('Post not found'), 404); } //check rights if (blogHelper::checkRights($post['blog_id']) < blogRightConfig::RIGHT_FULL && $post['contact_id'] != $this->getUser()->getId()) { throw new waRightsException(_w('Access denied')); } $post['datetime'] = $post['datetime'] >= 1971 ? $post['datetime'] : ''; $blog_id = $post['blog_id']; $blog = $blogs[$blog_id]; $title = trim(sprintf(_w('Editing post %s'), $post['title'])); } else { // add post $date = waRequest::get('date', ''); $blog = $this->getAllowedBlog($blogs, wa()->getStorage()->read('blog_last_id')); if (!$blog) { throw new waRightsException(_w('Access denied')); } $blog_id = $blog['id']; $post = array('title' => $this->getRequest()->post('title', '', waRequest::TYPE_STRING_TRIM), 'text' => $this->getRequest()->post('text', '', waRequest::TYPE_STRING_TRIM), 'continued_text' => null, 'categories' => array(), 'contact_id' => wa()->getUser()->getId(), 'url' => '', 'blog_id' => $blog_id, 'comments_allowed' => true); $post['id'] = ''; $post['status'] = $date ? blogPostModel::STATUS_DEADLINE : blogPostModel::STATUS_DRAFT; $post['datetime'] = ''; $post['meta_title'] = null; $post['meta_keywords'] = null; $post['meta_description'] = null; $title = _w('Adding new post'); } $all_links = blogPostModel::getPureUrls($post); $post['other_links'] = $all_links; $post['link'] = array_shift($post['other_links']); $post['remaining_time'] = null; if ($post['status'] == blogPostModel::STATUS_SCHEDULED && $post['datetime']) { $post['remaining_time'] = $this->calculateRemainingTime($post['datetime']); } if ($blog['rights'] >= blogRightConfig::RIGHT_FULL) { $users = blogHelper::getAuthors($post['blog_id']); } else { $user = $this->getUser(); $users = array($user->getId() => $user->getName()); } // preview hash for all type of drafts if ($post['status'] != blogPostModel::STATUS_PUBLISHED) { $options = array('contact_id' => $post['contact_id'], 'blog_id' => $blog_id, 'post_id' => $post['id'], 'user_id' => wa()->getUser()->getId()); $preview_hash = blogPostModel::getPreviewHash($options); $this->view->assign('preview_hash', base64_encode($preview_hash . $options['user_id'])); } $this->view->assign('no_settlements', empty($all_links) ? true : false); $this->view->assign('params', $this->getPostParams($post['id'])); $this->view->assign('blog', $blog); $this->view->assign('users', $users); $this->view->assign('blogs', $blogs); $allow_change_blog = 0; foreach ($blogs as $blog_item) { if ($blog_item['rights'] >= blogRightConfig::RIGHT_READ_WRITE) { ++$allow_change_blog; } } $this->view->assign('allow_change_blog', $allow_change_blog); $this->view->assign('post_id', $post_id); $this->view->assign('datetime_timezone', waDateTime::date("T", null, wa()->getUser()->getTimezone())); /** * Backend post edit page * UI hook allow extends post edit page * @event backend_post_edit * @param array[string]mixed $post * @param array[string]int $post['id'] * @param array[string]int $post['blog_id'] * @return array[string][string]string $return[%plugin_id%]['sidebar'] Plugin sidebar html output * @return array[string][string]string $return[%plugin_id%]['toolbar'] Plugin toolbar html output * @return array[string][string]string $return[%plugin_id%]['editor_tab'] Plugin editor tab html output */ $this->view->assign('backend_post_edit', wa()->event('backend_post_edit', $post, array('sidebar', 'toolbar', 'editor_tab'))); $app_settings = new waAppSettingsModel(); $show_comments = $app_settings->get($this->getApp(), 'show_comments', true); $this->view->assign('show_comments', $show_comments); $this->view->assign('post', $post); /** * @deprecated * For backward compatibility reason */ $this->view->assign('cron_schedule_time', waSystem::getSetting('cron_schedule', 0, 'blog')); $this->view->assign('last_schedule_cron_time', waSystem::getSetting('last_schedule_cron_time', 0, 'blog')); $this->view->assign('cron_command', 'php ' . wa()->getConfig()->getRootPath() . '/cli.php blog schedule'); $this->setLayout(new blogDefaultLayout()); $this->getResponse()->setTitle($title); }
public function execute() { $direction = waRequest::request('direction', 'import') == 'export' ? 'export' : 'import'; $profile_helper = new shopImportexportHelper('csv:product:' . $direction); $this->view->assign('profiles', $profile_helper->getList()); $profile = $profile_helper->getConfig(); if ($direction == 'export') { //export section TODO $profile['config'] += array('encoding' => 'UTF-8', 'images' => true, 'features' => true, 'domain' => null, 'delimiter' => ';', 'hash' => ''); $info = array(); if (!empty($profile['id'])) { $path = wa()->getTempPath('csv/download/' . $profile['id']); $files = waFiles::listdir($path); foreach ($files as $file) { $file_path = $path . '/' . $file; $info[] = array('name' => $file, 'mtime' => filemtime($file_path), 'size' => filesize($file_path)); } usort($info, create_function('$a, $b', 'return (max(-1, min(1, $a["mtime"] - $b["mtime"])));')); } $this->view->assign('info', array_slice($info, -5, 5, true)); $set_model = new shopSetModel(); $this->view->assign('sets', $set_model->getAll()); $routing = wa()->getRouting(); $settlements = array(); $current_domain = null; $domain_routes = $routing->getByApp('shop'); foreach ($domain_routes as $domain => $routes) { foreach ($routes as $route) { $settlement = $domain . '/' . $route['url']; if ($current_domain === null) { $current_domain = $settlement; } elseif ($settlement == $profile['config']['domain']) { $current_domain = $settlement; } $settlements[] = $settlement; } } $this->view->assign('current_domain', $current_domain); $this->view->assign('settlements', $settlements); } else { $profile['config'] += array('encoding' => 'UTF-8', 'delimiter' => ';', 'map' => array()); $base_path = wa()->getConfig()->getPath('root'); $app_path = array('shop' => wa()->getDataPath(null, false, 'shop'), 'site' => wa()->getDataPath(null, true, 'site')); foreach ($app_path as &$path) { $path = preg_replace('@^([\\\\/])@', '', str_replace($base_path, '', $path . '/')); } unset($path); $this->view->assign('upload_path', waSystem::getSetting('csv.upload_path', 'path/to/folder/with/source/images/')); $this->view->assign('upload_app', waSystem::getSetting('csv.upload_app', 'shop')); $this->view->assign('app_path', $app_path); } $this->view->assign('profile', $profile); $type_model = new shopTypeModel(); $this->view->assign('types', $type_model->getTypes()); $encoding = array_diff(mb_list_encodings(), array('pass', 'wchar', 'byte2be', 'byte2le', 'byte4be', 'byte4le', 'BASE64', 'UUENCODE', 'HTML-ENTITIES', 'Quoted-Printable', '7bit', '8bit', 'auto')); $popular = array_intersect(array('UTF-8', 'Windows-1251', 'ISO-8859-1'), $encoding); asort($encoding); $encoding = array_unique(array_merge($popular, $encoding)); $this->view->assign('encoding', $encoding); $plugins = wa()->getConfig()->getPlugins(); $this->view->assign('direction', $direction); $this->view->assign('plugin', ifempty($plugins['csvproducts'], array())); }