public function execute() { $data = waRequest::post(); // check required params $this->post('blog_id', true); $this->post('title', true); $blog_model = new blogBlogModel(); $blogs = $blog_model->getAvailable(); if (!isset($blogs[$data['blog_id']])) { throw new waAPIException('invalid_param', 'Blog not found', 404); } $blog = $blogs[$data['blog_id']]; if ($blog['rights'] < blogRightConfig::RIGHT_READ_WRITE) { throw new waAPIException('access_denied', 403); } $data = array_merge($data, array('blog_status' => $blog['status'], 'url' => '', 'text' => '', 'status' => blogPostModel::STATUS_PUBLISHED)); $post_model = new blogPostModel(); $options = array(); if (waRequest::post('transliterate', null)) { $options['transliterate'] = true; } $messages = $post_model->validate($data, array('transliterate' => true)); if ($messages) { throw new waAPIException('invalid_param', 'Validate messages: ' . implode("\n", $messages), 404); } $id = $post_model->updateItem(null, $data); $_GET['id'] = $id; $method = new blogPostGetInfoMethod(); $this->response = $method->getResponse(true); }
public function execute() { $query = trim(waRequest::post('q'), ' /'); $hash = '/search/' . $query; $collection = new photosCollection($hash); if ($query == 'rate>0') { $collection->orderBy('p.rate DESC, p.id'); } $this->template = 'templates/actions/photo/PhotoList.html'; $count = $this->getConfig()->getOption('photos_per_page'); $photos = $collection->getPhotos("*,thumb,thumb_crop,thumb_middle,thumb_big,tags,edit_rights", 0, $count); $photos = photosCollection::extendPhotos($photos); $frontend_link = $query == 'rate>0' ? photosCollection::getFrontendLink('favorites', false) : photosCollection::getFrontendLink($hash, false); /** * @event search_frontend_link * @param string $query * @return array of bool|string if false - default frontend_link isn't overridden, if string - override default frontend link */ $res = wa()->event('search_frontend_link', $query); foreach ($res as $r) { if (is_string($r)) { $frontend_link = $r; break; } } $config = $this->getConfig(); $this->view->assign('sidebar_width', $config->getSidebarWidth()); $this->view->assign('big_size', $config->getSize('big')); $this->view->assign('frontend_link', $frontend_link); $this->view->assign('photos', $photos); $this->view->assign('title', $query == 'rate>0' ? _w('Rated') : $collection->getTitle()); $this->view->assign('total_count', $collection->count()); $this->view->assign('sort_method', $query == 'rate>0' ? 'rate' : 'upload_datetime'); $this->view->assign('hash', $hash); }
public function execute() { try { $app_settings_model = new waAppSettingsModel(); if (waRequest::post('cancel')) { wa()->getStorage()->set('shop/discountcard', ''); } else { if ($discountcard_number = waRequest::post('discountcard')) { $model = new shopDiscountcardsPluginModel(); if ($app_settings_model->get(shopDiscountcardsPlugin::$plugin_id, 'binding_customer')) { $contact_id = wa()->getUser()->getId(); $discountcard = $model->getByField(array('contact_id' => $contact_id, 'discountcard' => $discountcard_number)); if (empty($discountcard)) { $discountcard = $model->getByField(array('contact_id' => 0, 'discountcard' => $discountcard_number)); } } else { $discountcard = $model->getByField('discountcard', $discountcard_number); } if ($discountcard) { wa()->getStorage()->set('shop/discountcard', $discountcard['discountcard']); } else { throw new waException('Дисконтная карта не найдена'); } } else { throw new waException('Укажите номер дисконтной карты'); } } } catch (Exception $ex) { $this->setError($ex->getMessage()); } }
public function execute() { $id = $this->get('id', true); $page_model = new sitePageModel(); $page = $page_model->getById($id); if ($page) { $data = waRequest::post(); $keys = array('name', 'title', 'content', 'status'); $update = array(); foreach ($keys as $k) { if (isset($data[$k])) { $update[$k] = $data[$k]; } } $r = true; if ($update || !empty($data['params'])) { if ($update) { $r = $page_model->update($id, $update); } if (!empty($data['params'])) { $page_model->setParams($id, $data['params']); } } if ($r) { $method = new sitePageGetInfoMethod(); $this->response = $method->getResponse(true); } else { throw new waAPIException('server_error', 500); } } else { throw new waAPIException('invalid_param', 'Page not found', 404); } }
public function execute() { try { $discountcard = waRequest::post('discountcard', array()); $model = new shopDiscountcardsPluginModel(); if (!empty($discountcard['id'])) { $model->updateById($discountcard['id'], $discountcard); $discountcard = $model->getById($discountcard['id']); } elseif (empty($discountcard['discountcard'])) { throw new waException('Ошибка: Не указан номер дисконтной карты'); } else { if ($model->getByField('discountcard', $discountcard['discountcard'])) { throw new waException('Ошибка: Номер дисконтной карты не уникален'); } $id = $model->insert($discountcard); $discountcard = $model->getById($id); } if (!empty($discountcard['contact_id'])) { $contact = new waContact($discountcard['contact_id']); $discountcard['contact_name'] = $contact->get('name'); } $discountcard['amount'] = shop_currency($discountcard['amount']); $this->response = $discountcard; } catch (Exception $ex) { $this->setError($ex->getMessage()); } }
public function execute() { $photo_id = $this->post('id', true); if (!is_array($photo_id)) { if (strpos($photo_id, ',') !== false) { $photo_id = array_map('intval', explode(',', $photo_id)); } else { $photo_id = array($photo_id); } } $album_id = waRequest::post('album_id', ''); if (!$album_id) { $album_id = array(); } if (!is_array($album_id)) { if (strpos($album_id, ',') !== false) { $album_id = explode(',', $album_id); } else { $album_id = array($album_id); } } $album_id = array_map('trim', $album_id); $album_photos_model = new photosAlbumPhotosModel(); $photo_rights_model = new photosPhotoRightsModel(); $allowed_photo_id = $photo_rights_model->filterAllowedPhotoIds($photo_id, true); if ($allowed_photo_id) { $album_photos_model->deletePhotos($album_id, $allowed_photo_id); $this->response = true; } else { throw new waAPIException('access_denied', 403); } }
public function getHash() { $order_ids = waRequest::post('order_id', null, waRequest::TYPE_ARRAY_INT); if ($order_ids !== null) { if ($order_ids) { return 'id/' . implode(',', $order_ids); } else { return null; } } $filter_params = waRequest::post('filter_params', null); if ($filter_params === null) { return null; } $hash = ''; if ($filter_params) { if (count($filter_params) == 1) { $k = key($filter_params); $v = $filter_params[$k]; if (is_array($v)) { $v = implode("||", $v); } if ($k == 'storefront') { $k = 'params.' . $k; if (substr($v, -1) == '*') { $v = substr($v, 0, -1); } } $hash = "search/{$k}={$v}"; } } return $hash; }
public function execute() { if (wa()->getAuth()->isAuth()) { $this->redirect(wa()->getAppUrl()); } // check auth config $auth = wa()->getAuthConfig(); if (!isset($auth['auth']) || !$auth['auth']) { throw new waException(_ws('Page not found'), 404); } // check auth app and url $signup_url = wa()->getRouteUrl((isset($auth['app']) ? $auth['app'] : '') . '/signup'); if (wa()->getConfig()->getRequestUrl(false) != $signup_url) { $this->redirect($signup_url); } $errors = array(); if (waRequest::method() == 'post') { // try sign up if ($contact = $this->signup(waRequest::post('data'), $errors)) { // assign new contact to view $this->view->assign('contact', $contact); } } $this->view->assign('errors', $errors); wa()->getResponse()->setTitle(_ws('Sign up')); }
public function execute() { $order_id = waRequest::post('order_id', null, waRequest::TYPE_INT); if ($order_id) { $order_model = new shopOrderModel(); $order = $order_model->getOrder($order_id); $customer_model = new shopCustomerModel(); $customer = $customer_model->getById($order['contact_id']); $customer_model->updateById($order['contact_id'], array('is_spamer' => 1)); $plugin = waSystem::getInstance()->getPlugin('orderantispam'); $action_id = $plugin->getSettings('action_id'); $workflow = new shopWorkflow(); $action = $workflow->getActionById($action_id); $action->run($order_id); // counters $state_counters = $order_model->getStateCounters(); $pending_counters = (!empty($state_counters['new']) ? $state_counters['new'] : 0) + (!empty($state_counters['processing']) ? $state_counters['processing'] : 0) + (!empty($state_counters['paid']) ? $state_counters['paid'] : 0); // update app coutner wa('shop')->getConfig()->setCount($state_counters['new']); $script = "<script>"; $script .= "\$.order_list.updateCounters(" . json_encode(array('state_counters' => $state_counters, 'common_counters' => array('pending_counters' => $pending_counters))) . ");"; $script .= "\$.order.reload();</script>"; $this->response['script'] = $script; } }
private function getContactData() { $contact_id = (int) $this->getUser()->getId(); $adapter = 'user'; if (!$contact_id) { $adapter = waRequest::post('auth_provider', 'guest', waRequest::TYPE_STRING_TRIM); if (!$adapter || $adapter == 'user') { $adapter = 'guest'; } } if ($adapter == 'guest') { $data['name'] = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM); $data['email'] = waRequest::post('email', '', waRequest::TYPE_STRING_TRIM); $data['site'] = waRequest::post('site', '', waRequest::TYPE_STRING_TRIM); $this->getStorage()->del('auth_user_data'); } else { if ($adapter != 'user') { $auth_adapters = wa()->getAuthAdapters(); if (!isset($auth_adapters[$adapter])) { $this->errors[] = _w('Invalid auth provider'); } elseif ($user_data = $this->getStorage()->get('auth_user_data')) { $data['name'] = $user_data['name']; $data['email'] = ''; $data['site'] = $user_data['url']; } else { $this->errors[] = _w('Invalid auth provider data'); } } } $data['auth_provider'] = $adapter; $data['contact_id'] = $contact_id; return $data; }
public function execute($params = null) { $result = array(); // from payment callback if (is_array($params)) { $order_id = $params['order_id']; $result['text'] = $params['plugin'] . ' (' . $params['view_data'] . ' - ' . $params['amount'] . ' ' . $params['currency_id'] . ')'; $result['update']['params'] = array('payment_transaction_id' => $params['id']); } else { $order_id = $params; $result['text'] = waRequest::post('text', ''); } $order_model = new shopOrderModel(); $order = $order_model->getById($order_id); $log_model = new waLogModel(); if (wa()->getEnv() == 'backend') { $log_model->add('order_pay', $order_id); } else { $log_model->add('order_pay_callback', $order_id, $order['contact_id']); } if (!$order['paid_year']) { shopAffiliate::applyBonus($order_id); if (wa('shop')->getConfig()->getOption('order_paid_date') == 'create') { $time = strtotime($order['create_datetime']); } else { $time = time(); } $result['update'] = array('paid_year' => date('Y', $time), 'paid_quarter' => floor((date('n', $time) - 1) / 3) + 1, 'paid_month' => date('n', $time), 'paid_date' => date('Y-m-d', $time)); if (!$order_model->where("contact_id = ? AND paid_date IS NOT NULL", $order['contact_id'])->limit(1)->fetch()) { $result['update']['is_first'] = 1; } } return $result; }
public function execute() { $enabled = waRequest::post('enabled'); $app_id = waRequest::post('app_id'); $domain = siteHelper::getDomain(); $config = wa()->getConfig()->getAuth(); if (!isset($config[$domain])) { if (!$enabled) { return; } $config[$domain] = array(); } if ($enabled && $app_id) { $config[$domain]['auth'] = true; $config[$domain]['app'] = $app_id; } else { if (isset($config[$domain]['auth'])) { unset($config[$domain]['auth']); } if (isset($config[$domain]['app'])) { unset($config[$domain]['app']); } } if (!$this->getConfig()->setAuth($config)) { $this->errors = sprintf(_w('File could not be saved due to the insufficient file write permissions for the "%s" folder.'), 'wa-config/'); } }
public function execute() { $this->plugin_id = 'category'; parent::execute(); if ($data = waRequest::post($this->plugin_id)) { $order = 0; $model = new blogCategoryModel(); foreach ($data as $id => &$row) { $id = intval($id); if (!empty($row['name'])) { $row['sort'] = $order++; if ($id > 0) { if (!empty($row['delete'])) { $model->deleteById($id); } else { $model->updateById($id, $row); $row['id'] = $id; } } elseif ($id < 0) { $row['id'] = $model->insert($row); } } } unset($row); } $categories = blogCategory::getAll(); $icons = $this->getConfig()->getIcons(); if (!$categories) { $categories[0] = array('url' => '', 'name' => '', 'icon' => current($icons), 'id' => 0, 'qty' => 0, 'sort' => 0); } $this->view->assign('categories', $categories); $this->view->assign('icons', $icons); }
public function execute() { $id = $this->get('id', true); $post_model = new blogPostModel(); $post = $post_model->getById($id); if (!$post) { throw new waAPIException('invalid_param', 'Post not found', 404); } //check rights if (blogHelper::checkRights($post['blog_id']) < blogRightConfig::RIGHT_FULL && $post['contact_id'] != wa()->getUser()->getId()) { throw new waAPIException('access_denied', 403); } $data = array_merge($post, waRequest::post()); $blog_model = new blogBlogModel(); $blogs = $blog_model->getAvailable(); if (!isset($blogs[$data['blog_id']])) { throw new waAPIException('invalid_param', 'Blog not found', 404); } $blog = $blogs[$data['blog_id']]; $data['blog_status'] = $blog['status']; $data['datetime'] = $this->formateDatetime($data['datetime']); $messages = $post_model->validate($data, array('transliterate' => true)); if ($messages) { throw new waAPIException('invalid_param', 'Validate messages: ' . implode("\n", $messages), 404); } $post_model->updateItem($data['id'], $data); $_GET['id'] = $id; $method = new blogPostGetInfoMethod(); $this->response = $method->getResponse(true); }
/** * @param array $settings */ protected function save(&$settings) { $settings['sharpen'] = waRequest::post('sharpen') ? 1 : 0; $settings['save_original'] = waRequest::post('save_original') ? 1 : 0; $settings['thumbs_on_demand'] = waRequest::post('thumbs_on_demand') ? 1 : 0; if ($settings['thumbs_on_demand']) { $settings['max_size'] = waRequest::post('max_size', 1000, 'int'); $big_size = $this->getConfig()->getSize('big'); if ($settings['max_size'] < $big_size) { $settings['max_size'] = $big_size; } } elseif (isset($settings['max_size'])) { unset($settings['max_size']); } // delete sizes if ($delete = waRequest::post('delete', array(), waRequest::TYPE_ARRAY_INT)) { foreach ($delete as $k) { if (isset($settings['sizes'][$k])) { unset($settings['sizes'][$k]); } } } // sizes if ($types = waRequest::post('size_type', array())) { $sizes = waRequest::post('size', array()); $width = waRequest::post('width', array()); $height = waRequest::post('height', array()); foreach ($types as $k => $type) { if ($type == 'rectangle') { $w = $this->checkSize($width[$k], $settings); $h = $this->checkSize($height[$k], $settings); if ($w && $h) { $settings['sizes'][] = $w . 'x' . $h; } } else { $size = $this->checkSize($sizes[$k], $settings); if (!$size) { continue; } switch ($type) { case 'crop': $settings['sizes'][] = $size . 'x' . $size; break; case 'height': $settings['sizes'][] = '0x' . $size; break; case 'width': $settings['sizes'][] = $size . 'x0'; break; case 'max': $settings['sizes'][] = $size; break; } } } } $settings['sizes'] = array_values($settings['sizes']); $config_file = $this->getConfig()->getConfigPath('config.php'); waUtils::varExportToFile($settings, $config_file); }
public function execute() { $ids = waRequest::request('id', array(), 'array_int'); if (!$ids) { throw new waException('Contact id not specified.'); } // only allowed to global admin if (!wa()->getUser()->getRights('webasyst', 'backend')) { throw new waRightsException(_w('Access denied')); } $groups = waRequest::post('groups', array(), 'array_int'); $counters = array(); $ugm = new waUserGroupsModel(); if ($this->getRequest()->request('set')) { foreach ($ids as $id) { $ugm->delete($id, array()); } } foreach ($ids as $id) { if ($groups) { $ugm->add(array_map(wa_lambda('$gid', 'return array(' . $id . ', $gid);'), $groups)); } } $gm = new waGroupModel(); foreach ($groups as $gid) { $cnt = $ugm->countByField(array('group_id' => $gid)); $gm->updateCount($gid, $cnt); $counters[$gid] = $cnt; } $this->response['counters'] = $counters; $this->response['message'] = _w("%d user has been added", "%d users have been added", count($ids)); $this->response['message'] .= ' '; $this->response['message'] .= _w("to %d group", "to %d groups", count($groups)); }
public function execute() { $f = waRequest::param('f'); $fid = waRequest::param('fid', waRequest::post('fid')); $prefix = waRequest::param('prefix', waRequest::post('prefix', 'options')); $full_parent = waRequest::param('parent', waRequest::post('parent', null)); $parent = explode('.', $full_parent); $parent = $parent[0]; $new_field = false; if ($f && $f instanceof waContactField) { $ftype = $f->getType(); if ($ftype == 'Select') { if ($f instanceof waContactBranchField) { $ftype = 'branch'; } else { if ($f instanceof waContactRadioSelectField) { $ftype = 'radio'; } } } } else { $ftype = strtolower(waRequest::param('ftype', waRequest::post('ftype', 'string'))); $f = self::getField($fid, $ftype); $new_field = true; } $ftype = strtolower($ftype); $this->view->assign('f', $f); $this->view->assign('fid', $fid); $this->view->assign('ftype', $ftype); $this->view->assign('prefix', $prefix); $this->view->assign('parent', $parent); $this->view->assign('uniqid', 'fe_' . uniqid()); $this->view->assign('new_field', $new_field); }
public function execute() { mb_internal_encoding("UTF-8"); $query = waRequest::post('query'); $query = strtolower($query); $collection_by_email = new waContactsCollection('/search/email*=' . $query . '/'); $contacts_by_email = $collection_by_email->getContacts('*'); $collection_by_name = new waContactsCollection('/search/name*=' . $query . '/'); $contacts_by_name = $collection_by_name->getContacts('*'); if (is_array($contacts_by_email) && is_array($contacts_by_name)) { $contacts = array_merge($contacts_by_email, $contacts_by_name); } else { if (is_array($contacts_by_email) || is_array($contacts_by_name)) { $contacts = is_array($contacts_by_email) ? $contacts_by_email : $contacts_by_name; } else { $contacts = array(); } } $modelContactCategory = new waContactCategoryModel(); $result = $modelContactCategory->getByField('name', $query); // query("SELECT * FROM wa_contact_category WHERE name LIKE '%".mysql_escape_string($query)."%'")->fetchAll(); if ($result) { $search['group'] = $result; $search['contacts'] = $contacts; } else { $search['group'] = array(); $search['contacts'] = $contacts; } $this->response['search'] = $search; }
public function execute() { $name = rtrim(waRequest::post('name'), '/'); $domain_model = new siteDomainModel(); $data = array(); if (!preg_match('!^[a-z0-9/\\._-]+$!i', $name)) { $data['title'] = $name; $idna = new waIdna(); $name = $idna->encode($name); } $data['name'] = $name; $this->response['id'] = $domain_model->insert($data); $this->log('site_add'); // add default routing $path = $this->getConfig()->getPath('config', 'routing'); if (file_exists($path)) { $routes = (include $path); } else { $routes = array(); } if (!isset($routes[$name])) { $routes[$name]['site'] = array('url' => '*', 'app' => 'site'); waUtils::varExportToFile($routes, $path); } }
public function execute() { $name = waRequest::post('name', '', waRequest::TYPE_STRING_TRIM); if (in_array($name, $this->availableFields) === false) { throw new waException(_w("Can't update album: unknown field")); } $album_rights_model = new photosAlbumRightsModel(); $id = waRequest::post('id', null, waRequest::TYPE_ARRAY_INT); if (is_array($id)) { $id = current($id); } if ($id) { $album_model = new photosAlbumModel(); $album = $album_model->getById($id); if (!$album) { throw new waException(_w('Unknown album')); } if (!$album_rights_model->checkRights($album, true)) { throw new waException(_w("You don't have sufficient access rights")); } $value = waRequest::post('value', '', waRequest::TYPE_STRING_TRIM); $album_model->updateById($id, array($name => $value)); $album['not_escaped_name'] = $value; $album['name'] = photosPhoto::escape($value); $this->response['album'] = $album; } }
public function execute() { $settings = waRequest::post('settings', array(), waRequest::TYPE_ARRAY); if (strlen($error = logsHelper::setPhpLogSetting(ifset($settings['php_log'], false)))) { $this->errors[] = $error; } }
public function execute() { if (!$this->getUser()->getRights('photos', 'edit')) { throw new waException(_w("Access denied")); } $moderation = waRequest::post('moderation', '', waRequest::TYPE_STRING_TRIM); $id = waRequest::post('id', '', waRequest::TYPE_INT); $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($id); if (!$photo) { $this->errors[] = _wp('Unknown photo'); } if ($moderation == 'approve') { $photo_model->updateById($id, array('moderation' => 1)); $photo_model->updateAccess($id, 1, array(0)); } if ($moderation == 'decline') { $photo_model->updateById($id, array('moderation' => -1)); $photo_model->updateAccess($id, 0, array(0)); } $this->response['photo'] = $photo_model->getById($id); // update for making inline-editable widget $this->response['frontend_link_template'] = photosFrontendPhoto::getLink(array('url' => '%url%')); $this->response['counters'] = array('declined' => $photo_model->countByField('moderation', -1), 'awaiting' => $photo_model->countByField('moderation', 0)); // l18n string $count = (int) waRequest::post('count'); $total_count = (int) waRequest::post('total_count'); $this->response['string'] = array('loaded' => _w('%d photo', '%d photos', $count), 'of' => sprintf(_w('of %d'), $total_count), 'chunk' => $count < $total_count ? _w('%d photo', '%d photos', min($this->getConfig()->getOption('photos_per_page'), $count - $total_count)) : false); }
protected function step() { $image_model = new shopProductImagesModel(); $create_thumbnails = waRequest::post('create_thumbnails'); $chunk_size = 50; if ($create_thumbnails) { $chunk_size = 10; } $sizes = wa('shop')->getConfig()->getImageSizes(); $images = $image_model->getAvailableImages($this->data['offset'], $chunk_size); foreach ($images as $i) { if ($this->data['product_id'] != $i['product_id']) { sleep(0.2); $this->data['product_id'] = $i['product_id']; $this->data['product_count'] += 1; } try { $path = shopImage::getThumbsPath($i); if (!waFiles::delete($path)) { throw new waException(sprintf(_w('Error when delete thumbnails for image %d'), $i['id'])); } if ($create_thumbnails) { shopImage::generateThumbs($i, $sizes); } $this->data['image_count'] += 1; // image count - count of successful progessed images } catch (Exception $e) { $this->error($e->getMessage()); } $this->data['offset'] += 1; } }
public function execute() { $product_tags_model = new shopProductTagsModel(); $tags = array(); $hash = waRequest::post('hash', ''); // get tags by products if (!$hash) { $product_ids = waRequest::post('product_id', array(), waRequest::TYPE_ARRAY_INT); if (!$product_ids) { return; } $tags = $product_tags_model->getTags($product_ids); // get tags by hash of collection } else { // add all products of collection with this hash $collection = new shopProductsCollection($hash); $offset = 0; $count = 100; $total_count = $collection->count(); while ($offset < $total_count) { $ids = array_keys($collection->getProducts('*', $offset, $count)); $tags += $product_tags_model->getTags($ids); $offset += count($ids); } } $tag_model = new shopTagModel(); $this->view->assign(array('tags' => $tags, 'popular_tags' => $tag_model->popularTags())); }
public function execute() { if (!$this->getUser()->getRights('shop', 'settings')) { throw new waRightsException(_w('Access denied')); } $model = new shopTypeModel(); $data = array(); $data['id'] = waRequest::post('id', 0, waRequest::TYPE_INT); switch (waRequest::post('source', 'custom')) { case 'custom': $data['name'] = waRequest::post('name'); $data['icon'] = waRequest::post('icon_url', false, waRequest::TYPE_STRING_TRIM); if (empty($data['icon'])) { $data['icon'] = waRequest::post('icon', 'icon.box', waRequest::TYPE_STRING_TRIM); } if (!empty($data['id'])) { $model->updateById($data['id'], $data); } else { $data['sort'] = $model->select('MAX(sort)+1 as max_sort')->fetchField('max_sort'); $data['id'] = $model->insert($data); } break; case 'template': $data = $model->insertTemplate(waRequest::post('template'), true); break; } if ($data) { $data['icon_html'] = shopHelper::getIcon($data['icon'], 'icon.box'); $data['name_html'] = '<span class="js-type-icon">' . $data['icon_html'] . '</span> <span class="js-type-name">' . htmlspecialchars($data['name'], ENT_QUOTES, 'utf-8') . '</span>'; } $this->response = $data; }
public function execute() { $path = rtrim(waRequest::post('path'), ' /'); $path = wa()->getDataPath($path, true, null, false); $hash = $new_path = waRequest::post('new_path'); $new_path = wa()->getDataPath($new_path, true, null, false) . ($new_path ? '' : '/'); if (!is_writable($new_path)) { $this->errors = sprintf(_w("Files could not bet moved due to the insufficient file write permissions for the %s folder."), rtrim($hash, '/')); return; } if ($file = waRequest::post('file')) { if (!is_array($file)) { $file = array($file); } foreach ($file as $f) { if (!@rename($path . "/" . $f, $new_path . $f)) { $this->errors[] = sprintf(_w("Can not move file “%s” to a new location"), $f); } } if ($this->errors && is_array($this->errors)) { $this->errors = implode(";\r\n", $this->errors); } } else { $new_path .= basename($path); $hash .= basename($path) . "/"; if (@rename($path, $new_path)) { $this->response['hash'] = $hash; } else { $this->errors = _w("Can not move to a new location"); } } }
public function execute() { $path = rtrim(waRequest::post('path'), ' /'); $path = wa()->getDataPath($path, true); if (!file_exists($path)) { throw new waException("File not found", 404); } $files = array(); $dh = opendir($path); $names = array(); while (($f = readdir($dh)) !== false) { if ($f !== '.' && $f !== '..' && is_file($path . '/' . $f)) { $t = filemtime($path . '/' . $f); $name = htmlspecialchars($f); $files[$name] = array('file' => $name, 'type' => $this->getType($f), 'size' => filesize($path . '/' . $f), 'timestamp' => $t, 'datetime' => waDateTime::format('humandatetime', $t)); $names[] = $name; } } natcasesort($names); $sorted_files = array(); foreach ($names as $name) { $sorted_files[] =& $files[$name]; } closedir($dh); $this->response = $sorted_files; }
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() { if (!$this->checkRequest()) { return; } $code = waRequest::post('code'); $auth_codes_model = new waApiAuthCodesModel(); $row = $auth_codes_model->getById($code); if ($row) { // check client_id if ($row['client_id'] != waRequest::post('client_id')) { $this->response(array('error' => 'invalid_grant')); return; } // check expire if (strtotime($row['expires']) < time()) { $this->response(array('error' => 'invalid_grant', 'error_description' => 'Authorization code expired')); return; } // create token $token_model = new waApiTokensModel(); $token = $token_model->getToken($row['client_id'], $row['contact_id'], $row['scope']); $this->response(array('access_token' => $token)); } else { $this->response(array('error' => 'invalid_grant', 'error_description' => 'Invalid code: ' . $code)); } }
public function execute() { $count = $this->getConfig()->getOption('photos_per_page'); $id = waRequest::post('id', 0, waRequest::TYPE_INT); $hash = waRequest::post('hash', '', waRequest::TYPE_STRING_TRIM); $offset = waRequest::post('offset', 1, waRequest::TYPE_INT); $direction = waRequest::post('direction', 1, waRequest::TYPE_INT); $this->collection = new photosCollection($hash); if (strstr($hash, 'rate>0') !== false) { $this->collection->orderBy('p.rate DESC, p.id'); } if ($id) { $photo_model = new photosPhotoModel(); $photo = $photo_model->getById($id); $offset = $this->collection->getPhotoOffset($photo); if ($direction > 0) { $offset += 1; } else { $offset -= $count; if ($offset < 0) { $count += $offset; $offset = 0; } } } $photos = array_values($this->getPhotos($offset, $count)); $photos = photosCollection::extendPhotos($photos); $loaded = count($photos) + $offset; $count = $this->collection->count(); $this->response['photos'] = $photos; $this->response['hash'] = $hash; $this->response['string'] = array('loaded' => _w('%d photo', '%d photos', $loaded), 'of' => sprintf(_w('of %d'), $count), 'chunk' => $loaded < $count ? _w('%d photo', '%d photos', min($this->getConfig()->getOption('photos_per_page'), $count - $loaded)) : false); }