public function __construct($coupon = array()) { waLocale::loadByDomain(array('shop', 'coupon')); waSystem::pushActivePlugin('coupon', 'shop'); $this->data['code'] = ifempty($coupon['code'], ''); $this->data['expire'] = ifempty($coupon['expire_datetime']); $curm = new shopCurrencyModel(); $currencies = $curm->getAll('code'); $this->data['discount'] = shopCouponPlugin::formatValue($coupon, $currencies); waSystem::popActivePlugin(); }
/** * @param array $params deleted contact_id * @return array|void */ public function execute(&$params) { waLocale::loadByDomain('blog'); $post_model = new blogPostModel(); $comment_model = new blogCommentModel(); $links = array(); foreach ($params as $contact_id) { $links[$contact_id] = array(); if ($count = $post_model->countByField('contact_id', $contact_id)) { $links[$contact_id][] = array('role' => _wd('blog', 'Posts author'), 'links_number' => $count); } if ($count = $comment_model->countByField('contact_id', $contact_id)) { $links[$contact_id][] = array('role' => _wd('blog', 'Comments author'), 'links_number' => $count); } } return $links; }
/** * @param array $params deleted contact_id * @return array|void */ public function execute(&$params) { waLocale::loadByDomain('shop'); // TODO: take a look to other models related with contacts $links = array(); $product_reviews_model = new shopProductReviewsModel(); $order_model = new shopOrderModel(); foreach ($params as $contact_id) { $links[$contact_id] = array(); if ($count = $product_reviews_model->countByField('contact_id', $contact_id)) { $links[$contact_id][] = array('role' => _wd('shop', 'Reviews author'), 'links_number' => $count); } if ($count = $order_model->countByField('contact_id', $contact_id)) { $links[$contact_id][] = array('role' => _wd('shop', 'Order customer'), 'links_number' => $count); } } return $links; }
public function getApps($system = false) { if (self::$apps === null) { $locale = $this->getUser()->getLocale(); $file = $this->config->getPath('cache', 'config/apps' . $locale); if (!file_exists($this->getConfig()->getPath('config', 'apps'))) { self::$apps = array(); throw new waException('File wa-config/apps.php not found.', 600); } if (!file_exists($file) || filemtime($file) < filemtime($this->getConfig()->getPath('config', 'apps')) || waSystemConfig::isDebug()) { waFiles::create($this->getConfig()->getPath('cache') . '/config'); $all_apps = (include $this->getConfig()->getPath('config', 'apps')); $all_apps['webasyst'] = true; self::$apps = array(); foreach ($all_apps as $app => $enabled) { if ($enabled) { waLocale::loadByDomain($app, $locale); $app_config = $this->getAppPath('lib/config/app.php', $app); if (!file_exists($app_config)) { if (false && SystemConfig::isDebug()) { throw new waException("Config not found. Create config by path " . $app_config); } continue; } $app_info = (include $app_config); $build_file = $app_config = $this->getAppPath('lib/config/build.php', $app); if (file_exists($build_file)) { $app_info['build'] = (include $build_file); } else { if (SystemConfig::isDebug()) { $app_info['build'] = time(); } else { $app_info['build'] = 0; } } $app_info['id'] = $app; $app_info['name'] = _wd($app, $app_info['name']); if (isset($app_info['icon'])) { if (is_array($app_info['icon'])) { foreach ($app_info['icon'] as $size => $url) { $app_info['icon'][$size] = 'wa-apps/' . $app . '/' . $url; } } else { $app_info['icon'] = array(48 => 'wa-apps/' . $app . '/' . $app_info['icon']); } } else { $app_info['icon'] = array(); } if (isset($app_info['img'])) { $app_info['img'] = 'wa-apps/' . $app . '/' . $app_info['img']; } else { $app_info['img'] = isset($app_info['icon'][48]) ? $app_info['icon'][48] : 'wa-apps/' . $app . '/img/' . $app . ".png"; } if (!isset($app_info['icon'][48])) { $app_info['icon'][48] = $app_info['img']; } if (!isset($app_info['icon'][24])) { $app_info['icon'][24] = $app_info['icon'][48]; } if (!isset($app_info['icon'][16])) { $app_info['icon'][16] = $app_info['icon'][24]; } self::$apps[$app] = $app_info; } } if (!file_exists($file) || filemtime($file) < filemtime($this->getConfig()->getPath('config', 'apps'))) { waUtils::varExportToFile(self::$apps, $file); } } else { self::$apps = (include $file); waLocale::loadByDomain('webasyst', $locale); } } if ($system) { return self::$apps; } else { $apps = self::$apps; unset($apps['webasyst']); return $apps; } }
protected function forgotPassword() { $error = ''; $auth = wa()->getAuth(); if (waRequest::method() == 'post' && !waRequest::post('ignore')) { if ($contact = $this->findContact(waRequest::post('login'), $auth)) { if ($contact->get('is_banned')) { $error = _ws('Password recovery for this email has been banned.'); } elseif ($email = $contact->get('email', 'default')) { if ($contact['locale']) { wa()->setLocale($contact['locale']); waLocale::loadByDomain('webasyst', wa()->getLocale()); } $hash = $this->getHash($contact['id'], true); if ($this->send($email, $this->getResetPasswordUrl($hash))) { $this->view->assign('sent', 1); } else { $error = _ws('Sorry, we can not recover password for this login name or email. Please refer to your system administrator.'); } } } else { if ($auth->getOption('login') == 'email') { $error = _ws('No user with this email has been found.'); } else { $error = _ws('No user with this login name or email has been found.'); } } } $this->view->assign('options', $auth->getOptions()); $this->view->assign('error', $error); if ($this->layout) { $this->layout->assign('error', $error); } wa()->getResponse()->setTitle(_ws('Password recovery')); }
/** * Returns time as string according to specified format. * * @see wa_date() * * @param string $format Date/time format. The following format strings are acceptable: * - 'humandatetime': adds words "yesterday", "today", "tomorrow" instead of appropriate dates relative to the * current user date * - 'humandate': returns the date in format 'd f Y' supported by method date (format strings listed below are * also supported by that method) * - 'date': returns date/time in format 'Y-m-d' * - 'time': returns date/time in format 'H:i' * - 'fulltime': returns date/time in format 'H:i:s' * - 'datetime': returns date/time in format 'Y-m-d H:i' * - 'fulldatetime': returns date/time in format 'Y-m-d H:i:s' * - 'timestamp': returns date/time in format 'U' * @param string|null $time Unix timestamp. If not specified, current timestamp is used. * @param string|null $timezone Time zone identifier. If not specified, the time zone is determined automatically. * @param string|null $locale Locale identifier. If not specifed, current user's locale is determined automatically. * @return string */ public static function format($format, $time = null, $timezone = null, $locale = null) { if (!$locale) { $locale = wa()->getLocale(); } if (!$timezone) { $timezone = wa()->getUser()->getTimezone(); } waLocale::loadByDomain("webasyst", $locale); $old_locale = waLocale::getLocale(); if ($locale != $old_locale) { wa()->setLocale($locale); } if ($format === 'humandatetime') { if (preg_match("/^[0-9]+\$/", $time)) { $time = date("Y-m-d H:i:s", $time); } $date_time = new DateTime($time); $base_date_time = new DateTime(date("Y-m-d H:i:s", strtotime('-1 day'))); if ($timezone) { $date_timezone = new DateTimeZone($timezone); $date_time->setTimezone($date_timezone); $base_date_time->setTimezone($date_timezone); } $day = $date_time->format('Y z'); if ($base_date_time->format('Y z') === $day) { $result = _ws('Yesterday'); } else { $base_date_time->modify('+1 day'); if ($base_date_time->format('Y z') === $day) { $result = _ws('Today'); } else { $base_date_time->modify('+1 day'); if ($base_date_time->format('Y z') === $day) { $result = _ws('Tomorrow'); } else { $result = self::date(self::getFormat('humandate', $locale), $time, $timezone, $locale); } } } $result = $result . ' ' . self::date(self::getFormat('time', $locale), $time, $timezone, $locale); } else { $result = self::date(self::getFormat($format, $locale), $time, $timezone, $locale); } if ($locale != $old_locale) { wa()->setLocale($old_locale); } return $result; }
/** * Format amount according to currency settings and current locale settings. * * TODO: document format string specifications. For now, see unit tests for some usage clues. * * @param string $format * @param float $n amount to format * @param string $currency 3-letter iso code * @param string $locale */ public static function format($format, $n, $currency, $locale = null) { $old_locale = waSystem::getInstance()->getLocale(); if ($locale === null) { $locale = $old_locale; } $currency = waCurrency::getInfo($currency); if ($format == '%w' || $format == '%W') { if ($locale !== $old_locale) { wa()->setLocale($locale); } waLocale::loadByDomain('webasyst', $locale); } $locale = waLocale::getInfo($locale); $result = preg_replace('/%([0-9]?\\.?[0-9]?)([iw]*)({[n|f|c|s][0-9]?})?/ie', 'self::extract($n, $currency, $locale, "$1", "$2", "$3")', $format); if ($locale !== $old_locale) { wa()->setLocale($old_locale); } return $result; }
/** * Returns formatted amount value with currency. * * @see wa_currency() * @see wa_currency_html() * * @param string $format Amount format. The format string must begin with % character and may contain the following * optional parts in the specified order: * - Precision (number of digits after decimal separator) expressed as an arbitrary integer value. If not * specified, then 2 decinal digits are displayed by default. * - Display type (as a number; e.g., "123456", or in words; e.g., 'one hundred and twenty-three thousand four * hundred and fifty-six"). To use the numerical format, specify i; for verbal format, use w. The verbal * expression of a number contains its integer part only, the decimal part is ignored. If the display type is * not specified, then the numerical format is used by default. * - Currency sign or name. To add it to the formatted amount value, specify one of the following identifiers in * curly brackets: * {n}: full cyrrency name; e.g., "dollar" * {s}: brief currency name or sign; e.g., "$" * {f}: name of the fractional currency unit; e.g., "cent/cents" * {c}: currency code; e.g., "USD". * @param float $n Original number to be formatted * @param string $currency Currency's ISO3 code * @param string $locale Locale id * @return string E.g., 'en_US' */ public static function format($format, $n, $currency, $locale = null) { $old_locale = waSystem::getInstance()->getLocale(); if ($locale === null) { $locale = $old_locale; } if ($locale !== $old_locale) { wa()->setLocale($locale); } $currency = self::getInfo($currency); waLocale::loadByDomain('webasyst', $locale); $locale = waLocale::getInfo($locale); self::$format_data['n'] = $n; self::$format_data['locale'] = $locale; self::$format_data['currency'] = $currency; $pattern = '/%([0-9]?\\.?[0-9]?)([iw]*)({[n|f|c|s|h][0-9]?})?/i'; $result = preg_replace_callback($pattern, array('self', 'replace_callback'), $format); if ($locale !== $old_locale) { wa()->setLocale($old_locale); } return $result; }
public function contactsLinks($params) { waLocale::loadByDomain('photos'); // TODO: take a look to other models related with contacts $links = array(); $comments_model = new photosCommentModel(); foreach ($params as $contact_id) { $links[$contact_id] = array(); if ($count = $comments_model->countByField('contact_id', $contact_id)) { $links[$contact_id][] = array('role' => _wd('photos', 'Comments author'), 'links_number' => $count); } } return $links; }