public function collectSnippets(BASE_CLASS_EventCollector $event)
 {
     $language = OW::getLanguage();
     $params = $event->getParams();
     if ($params["entityType"] != SNIPPETS_CLASS_EventHandler::ENTITY_TYPE_USER) {
         return;
     }
     $userId = $params["entityId"];
     $preview = $params["preview"];
     $snippet = new SNIPPETS_CMP_Snippet(self::WIDGET_NAME, $userId);
     if ($preview) {
         $snippet->setLabel($language->text("snippets", "snippet_virtual_gifts_preview"));
         $snippet->setIconClass("ow_ic_birthday");
         $event->add($snippet);
         return;
     }
     $service = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     $total = $service->countUserReceivedGifts($userId);
     $list = $service->findUserReceivedGifts($userId, 1, 4);
     if (empty($list)) {
         return;
     }
     $images = array();
     foreach ($list as $gift) {
         $images[] = $gift["imageUrl"];
     }
     $dispslayType = count($images) > 1 ? SNIPPETS_CMP_Snippet::DISPLAY_TYPE_4 : SNIPPETS_CMP_Snippet::DISPLAY_TYPE_1;
     $url = OW::getRouter()->urlForRoute('virtual_gifts_user_list', array("userName" => BOL_UserService::getInstance()->getUserName($userId)));
     $snippet->setImages($images);
     $snippet->setLabel($language->text("snippets", "snippet_virtual_gifts", array("count" => '<span class="ow_txt_value">' . $total . '</span>')));
     $snippet->setUrl($url);
     $snippet->setDisplayType($dispslayType);
     $event->add($snippet);
 }
Exemplo n.º 2
0
 public function import($params)
 {
     $importDir = $params['importDir'];
     $txtFile = $importDir . 'configs.txt';
     // import configs
     if (file_exists($txtFile)) {
         $string = file_get_contents($txtFile);
         $configs = json_decode($string, true);
     }
     if (!$configs) {
         return;
     }
     $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     $giftsDir = $giftService->getGiftUploadDir();
     $tpls = $giftService->getTemplateList();
     if (empty($tpls)) {
         return;
     }
     foreach ($tpls as $tpl) {
         $dto = $tpl['dto'];
         $path = $giftService->getGiftFilePath($dto->id, $dto->uploadTimestamp, $dto->extension);
         $name = str_replace($giftsDir, '', $path);
         $content = file_get_contents($configs['url'] . '/' . $name);
         if (mb_strlen($content)) {
             OW::getStorage()->fileSetContent($path, $content);
         }
     }
 }
Exemplo n.º 3
0
 public function templatesDeleteProcess()
 {
     $config = OW::getConfig();
     // check if uninstall is in progress
     if (!$config->getValue('virtualgifts', 'uninstall_inprogress')) {
         return;
     }
     // check if cron queue is not busy
     if ($config->getValue('virtualgifts', 'uninstall_cron_busy')) {
         return;
     }
     $config->saveConfig('virtualgifts', 'uninstall_cron_busy', 1);
     $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     $templates = $giftService->findAllTemplates();
     for ($i = 0; $i < self::TEMPLATE_DELETE_LIMIT; $i++) {
         if (!isset($templates[$i])) {
             break;
         }
         $giftService->deleteTemplate($templates[$i]->id);
     }
     $config->saveConfig('virtualgifts', 'uninstall_cron_busy', 0);
     $templates = $giftService->findAllTemplates();
     if (!$templates) {
         $config->saveConfig('virtualgifts', 'uninstall_inprogress', 0);
         BOL_PluginService::getInstance()->uninstall('virtualgifts');
         $giftService->setMaintenanceMode(false);
     }
 }
Exemplo n.º 4
0
 public static function process($data)
 {
     $resp = array();
     $lang = OW::getLanguage();
     if (!OW::getUser()->isAuthenticated()) {
         $resp['error'] = $lang->text('virtualgifts', 'not_authenticated');
         echo json_encode($resp);
         exit;
     }
     if (empty($data['tplId'])) {
         $resp['error'] = 'Error';
         echo json_encode($resp);
         exit;
     }
     if (empty($data['userIdList']) || !($idList = explode("|", $data['userIdList']))) {
         $resp['error'] = $lang->text('virtualgifts', 'no_users_selected');
         echo json_encode($resp);
         exit;
     }
     $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     $tpl = $giftService->findTemplateById($data['tplId']);
     if (!$tpl) {
         $resp['error'] = 'Gift not found';
         echo json_encode($resp);
         exit;
     }
     $senderId = OW::getUser()->getId();
     $count = 0;
     foreach ($idList as $userId) {
         if (!OW::getUser()->isAuthorized('virtualgifts', 'send_gift', array('tplId' => $tpl->id))) {
             $status = BOL_AuthorizationService::getInstance()->getActionStatus('virtualgifts', 'send_gift', array('tplId' => $tpl->id));
             $resp['error'] = $status['msg'];
             break;
         }
         $gift = new VIRTUALGIFTS_BOL_UserGift();
         $gift->senderId = $senderId;
         $gift->recipientId = $userId;
         $gift->private = $data['isPrivate'] == 'on' ? 1 : 0;
         $gift->message = strip_tags(trim($data['message']));
         $gift->templateId = $tpl->id;
         $gift->sendTimestamp = time();
         if ($giftId = $giftService->sendUserGift($gift)) {
             if (!$gift->private) {
                 // Newsfeed
                 $event = new OW_Event('feed.action', array('pluginKey' => 'virtualgifts', 'entityType' => 'user_gift', 'entityId' => $giftId, 'userId' => $userId));
                 OW::getEventManager()->trigger($event);
             }
             $event = new OW_Event('virtualgifts.send_gift', array('recipientId' => $userId, 'senderId' => $senderId, 'giftId' => $giftId));
             OW::getEventManager()->trigger($event);
             $count++;
             BOL_AuthorizationService::getInstance()->trackAction('virtualgifts', 'send_gift', null, array('tplId' => $tpl->id));
         }
     }
     if ($count) {
         $resp['message'] = $lang->text('virtualgifts', 'gift_sent_to', array('count' => $count));
     }
     echo json_encode($resp);
     exit;
 }
Exemplo n.º 5
0
 public function export($params)
 {
     $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     $url = OW::getStorage()->getFileUrl($giftService->getGiftUploadDir());
     /* @var $za ZipArchives */
     $za = $params['zipArchive'];
     $archiveDir = $params['archiveDir'];
     $string = json_encode(array('url' => $url));
     $za->addFromString($archiveDir . '/' . 'configs.txt', $string);
 }
Exemplo n.º 6
0
 public function __construct()
 {
     $this->actions[] = array('pluginKey' => 'virtualgifts', 'action' => 'send_virtual_gift', 'amount' => -1, 'settingsRoute' => 'virtual_gifts_templates');
     $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     $templates = $giftService->getTemplateList();
     if ($templates) {
         foreach ($templates as $tpl) {
             $this->actions[] = array('pluginKey' => 'virtualgifts', 'action' => 'template_' . $tpl['id'], 'amount' => $tpl['price'] == 0 ? 0 : -$tpl['price'], 'hidden' => 1);
         }
     }
 }
Exemplo n.º 7
0
 public function onCreditsUpdateActionDisabledStatus(OW_Event $e)
 {
     $params = $e->getParams();
     if ($params['pluginKey'] == 'virtualgifts' && $params['actionKey'] == 'send_virtual_gift') {
         $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
         $creditService = USERCREDITS_BOL_CreditsService::getInstance();
         $templates = $giftService->getTemplateList();
         foreach ($templates as $tpl) {
             $event = new BASE_CLASS_EventCollector('usercredits.action_update');
             $event->add(array('pluginKey' => 'virtualgifts', 'action' => 'template_' . $tpl['id'], 'amount' => $tpl['price'] == 0 ? 0 : -$tpl['price'], 'hidden' => 1, 'disabled' => (int) $params['disabled']));
             OW::getEventManager()->trigger($event);
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Class constructor
  */
 public function __construct(BASE_CLASS_WidgetParameter $paramObj)
 {
     parent::__construct();
     $this->giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     $userId = (int) $paramObj->additionalParamList['entityId'];
     $count = isset($paramObj->customParamList['giftsCount']) ? (int) $paramObj->customParamList['giftsCount'] : 4;
     $gifts = $this->giftService->findUserReceivedGifts($userId, 1, $count, true);
     if (!$gifts) {
         $this->setVisible(false);
         return;
     }
     $this->assign('gifts', $gifts);
     $username = BOL_UserService::getInstance()->getUserName($userId);
     $this->setSettingValue(self::SETTING_TOOLBAR, array(array('label' => OW::getLanguage()->text('base', 'view_all'), 'href' => OW::getRouter()->urlForRoute('virtual_gifts_user_list', array('userName' => $username)))));
     $url = OW::getPluginManager()->getPlugin('virtualgifts')->getStaticCssUrl() . 'style.css';
     OW::getDocument()->addStyleSheet($url);
 }
Exemplo n.º 9
0
 /**
  * Class constructor
  */
 public function __construct($tpls)
 {
     parent::__construct('edit-template-form');
     $this->setAction(OW::getRouter()->urlFor('VIRTUALGIFTS_CTRL_Admin', 'editTemplate'));
     $single = count($tpls) == 1;
     $this->setEnctype('multipart/form-data');
     $language = OW::getLanguage();
     $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     if ($single) {
         $file = new FileField('file');
         $file->setLabel($language->text('virtualgifts', 'gift_image'));
         $this->addElement($file);
         $tpl = $giftService->findTemplateById($tpls[0]);
     }
     $tplId = new HiddenField('tplId');
     $tplId->setRequired(true);
     $tplId->setValue(implode('|', $tpls));
     $this->addElement($tplId);
     if ($giftService->categoriesSetup()) {
         $categories = new Selectbox('category');
         $categories->setLabel($language->text('virtualgifts', 'category'));
         $categories->setOptions($giftService->getCategories());
         if ($single && isset($tpl)) {
             $categories->setValue($tpl->categoryId);
         }
         $this->addElement($categories);
     }
     if (OW::getPluginManager()->isPluginActive('usercredits')) {
         $price = new TextField('price');
         $price->setLabel($language->text('virtualgifts', 'gift_price'));
         if ($single && isset($tpl)) {
             $price->setValue($tpl->price);
         }
         $this->addElement($price);
     }
     // submit
     $submit = new Submit('save');
     $submit->setValue($language->text('virtualgifts', 'btn_save'));
     $this->addElement($submit);
 }
Exemplo n.º 10
0
 /**
  * Default action
  */
 public function index()
 {
     $language = OW::getLanguage();
     $giftsService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     $page = !empty($_GET['page']) && (int) $_GET['page'] ? abs((int) $_GET['page']) : 1;
     $perPage = $giftsService->getGiftsPerPageConfig();
     $gifts = $giftsService->findUserReceivedGifts(OW::getUser()->getId(), $page, $perPage, false);
     $toolbars = array();
     if ($gifts) {
         $users = array();
         foreach ($gifts as $gift) {
             if (!in_array($gift['dto']->senderId, $users)) {
                 array_push($users, $gift['dto']->senderId);
             }
         }
         $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars($users);
         $this->assign('avatars', $avatars);
         foreach ($gifts as $gift) {
             $giftId = $gift['dto']->id;
             $senderId = $gift['dto']->senderId;
             $toolbars[$giftId][] = array('class' => 'ow_icon_control ow_ic_user', 'href' => isset($avatars[$senderId]['url']) ? $avatars[$senderId]['url'] : null, 'label' => isset($avatars[$senderId]['title']) ? $avatars[$senderId]['title'] : null);
             if ($gift['dto']->private) {
                 $toolbars[$giftId][] = array('title' => $language->text('virtualgifts', 'private_gift_note'), 'label' => $language->text('virtualgifts', 'private_gift'));
             }
             $toolbars[$giftId][] = array('label' => UTIL_DateTime::formatSimpleDate($gift['dto']->sendTimestamp));
         }
     }
     $this->assign('gifts', $gifts);
     $this->assign('toolbars', $toolbars);
     $total = $giftsService->countUserReceivedGifts(OW::getUser()->getId(), false);
     $pages = (int) ceil($total / $perPage);
     $paging = new BASE_CMP_Paging($page, $pages, 10);
     $this->assign('paging', $paging->render());
     $this->setPageHeading(OW::getLanguage()->text('virtualgifts', 'my_gifts'));
     $this->setPageHeadingIconClass('ow_ic_heart');
     OW::getDocument()->setTitle($language->text('virtualgifts', 'meta_title_my_gifts'));
     OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, 'base', 'dashboard');
     $url = OW::getPluginManager()->getPlugin('virtualgifts')->getStaticCssUrl() . 'style.css';
     OW::getDocument()->addStyleSheet($url);
 }
Exemplo n.º 11
0
 public function sosialSharingGetGiftInfo(OW_Event $event)
 {
     $params = $event->getParams();
     $data = $event->getData();
     $data['display'] = false;
     if (empty($params['entityId'])) {
         return;
     }
     if ($params['entityType'] == 'virtualgifts') {
         $giftDto = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance()->findUserGiftById($params['entityId']);
         if (!empty($giftDto['dto'])) {
             $data['display'] = !$giftDto['dto']->private;
         }
         $event->setData($data);
     }
 }
Exemplo n.º 12
0
 /**
  * Class constructor
  */
 public function __construct()
 {
     parent::__construct('add-template-form');
     $this->setEnctype('multipart/form-data');
     $language = OW::getLanguage();
     $file = new FileField('file');
     $file->setLabel($language->text('virtualgifts', 'gift_image'));
     $this->addElement($file);
     $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     if ($giftService->categoriesSetup()) {
         $categories = new Selectbox('category');
         $categories->setLabel($language->text('virtualgifts', 'category'));
         $categories->setOptions($giftService->getCategories());
         $this->addElement($categories);
     }
     if (OW::getPluginManager()->isPluginActive('usercredits')) {
         $price = new TextField('price');
         $price->setLabel($language->text('virtualgifts', 'gift_price'));
         $this->addElement($price);
     }
     // submit
     $submit = new Submit('add');
     $submit->setValue($language->text('virtualgifts', 'btn_add'));
     $this->addElement($submit);
 }
Exemplo n.º 13
0
 public function ajaxDeleteGift()
 {
     $giftId = (int) $_POST['giftId'];
     $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     $gift = $giftService->findUserGiftById($giftId);
     $isModerator = OW::getUser()->isAuthorized('virtualgifts');
     if ($gift && ($gift['dto']->recipientId == OW::getUser()->getId() || $isModerator)) {
         $giftService->deleteUserGift($giftId);
         $resp['message'] = OW::getLanguage()->text('virtualgifts', 'gift_deleted');
         if ($gift['dto']->recipientId == OW::getUser()->getId()) {
             $resp['url'] = OW::getRouter()->urlForRoute('virtual_gifts_private_list');
         } else {
             $userName = BOL_UserService::getInstance()->getUserName($gift['dto']->recipientId);
             $resp['url'] = OW::getRouter()->urlForRoute('virtual_gifts_user_list', array('userName' => $userName));
         }
     } else {
         $resp['error'] = 'Not authorized';
     }
     echo json_encode($resp);
     exit;
 }
Exemplo n.º 14
0
 public static function process($data)
 {
     $resp = array();
     $lang = OW::getLanguage();
     $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     $authService = BOL_AuthorizationService::getInstance();
     if (!OW::getUser()->isAuthenticated()) {
         $resp['error'] = $lang->text('virtualgifts', 'not_authenticated');
         echo json_encode($resp);
         exit;
     }
     if (empty($data['tplId']) || !($tpl = $giftService->findTemplateById($data['tplId']))) {
         $resp['error'] = $lang->text('virtualgifts', 'gift_not_selected');
         echo json_encode($resp);
         exit;
     }
     $tplId = (int) $data['tplId'];
     $senderId = OW::getUser()->getId();
     $recipientId = (int) $data['recipientId'];
     if (!OW::getUser()->isAuthorized('virtualgifts', 'send_gift', array('tplId' => $tplId))) {
         $status = $authService->getActionStatus('virtualgifts', 'send_gift', array('tplId' => $tplId));
         $resp['error'] = $status['msg'];
         echo json_encode($resp);
         exit;
     }
     $gift = new VIRTUALGIFTS_BOL_UserGift();
     $gift->senderId = $senderId;
     $gift->recipientId = $recipientId;
     $gift->private = $data['isPrivate'] == 'on' ? 1 : 0;
     $gift->templateId = $tplId;
     if (!empty($data['message'])) {
         $gift->message = strip_tags(trim($data['message']));
     }
     $gift->sendTimestamp = time();
     if ($giftId = $giftService->sendUserGift($gift)) {
         $authService->trackAction('virtualgifts', 'send_gift', array('tplId' => $tplId));
         if (!$gift->private) {
             // Newsfeed
             $event = new OW_Event('feed.action', array('pluginKey' => 'virtualgifts', 'entityType' => 'user_gift', 'entityId' => $giftId, 'userId' => $recipientId));
             OW::getEventManager()->trigger($event);
         }
         $event = new OW_Event('virtualgifts.send_gift', array('recipientId' => $recipientId, 'senderId' => $senderId, 'giftId' => $giftId));
         OW::getEventManager()->trigger($event);
         $resp['message'] = $lang->text('virtualgifts', 'gift_sent');
         echo json_encode($resp);
     } else {
         $resp['error'] = $lang->text('virtualgifts', 'gift_not_sent');
         echo json_encode($resp);
     }
     exit;
 }