Beispiel #1
0
 public function addTemplate($fileName, $roleIds = null, $default = false)
 {
     $canvasWidth = self::CANVAS_WIDTH;
     $canvasHeight = $this->config['cover_height'];
     $coverImage = new UTIL_Image($fileName);
     $imageHeight = $coverImage->getHeight();
     $imageWidth = $coverImage->getWidth();
     $css = array('width' => 'auto', 'height' => 'auto');
     $tmp = $canvasWidth * $imageHeight / $imageWidth;
     if ($tmp >= $canvasHeight) {
         $css['width'] = '100%';
     } else {
         $css['height'] = '100%';
     }
     $template = new UHEADER_BOL_Template();
     $extension = UTIL_File::getExtension($fileName);
     $template->file = uniqid('template-') . '.' . $extension;
     $template->default = $default;
     $template->timeStamp = time();
     $dimensions = array('height' => $imageHeight, 'width' => $imageWidth);
     $template->setSettings(array('dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0)));
     $this->service->saveTemplate($template);
     if ($roleIds !== null) {
         $this->service->saveRoleIdsForTemplateId($template->id, $roleIds);
     }
     $templatePath = $this->service->getTemplatePath($template);
     OW::getStorage()->copyFile($fileName, $templatePath);
 }
Beispiel #2
0
 protected function getTabs()
 {
     $language = OW::getLanguage();
     $service = UHEADER_BOL_Service::getInstance();
     $photoBridge = UHEADER_CLASS_PhotoBridge::getInstance();
     $templatesCount = $service->findTemplatesCountForUser($this->userId);
     if ($templatesCount > 0 || !$photoBridge->isActive()) {
         $activeTab = "gallery";
     } else {
         $activeTab = "photos";
     }
     $tabs = array();
     if ($templatesCount > 0) {
         $tabKey = "gallery";
         $dimensions = $this->getDimensions();
         //$dimensions["height"] -= 45;
         if (OW::getConfig()->getValue('uheader', 'tpl_view_mode') == "list") {
             $coverGallery = new UHEADER_CMP_CoverGallery($this->userId, $tabKey, $dimensions);
         } else {
             $coverGallery = new UHEADER_CMP_CoverPreviewGallery($this->userId, $tabKey, $dimensions);
         }
         $coverGallery->assign("dimensions", $this->getDimensions());
         $tabs[] = array("label" => $language->text("uheader", "gallery_tab_gallery"), "key" => $tabKey, "active" => $tabKey == $activeTab, "content" => $coverGallery->render());
     }
     $tabKey = "photos";
     $photoList = new UHEADER_CMP_MyPhotos($this->userId, $tabKey);
     $tabs[] = array("label" => $language->text("uheader", "gallery_tab_photos"), "key" => $tabKey, "active" => $tabKey == $activeTab, "content" => $photoList->render());
     return $tabs;
 }
Beispiel #3
0
 public function getCoverUrl(UHEADER_BOL_Cover $cover)
 {
     if (!$this->isActive()) {
         return null;
     }
     return UHEADER_BOL_Service::getInstance()->getCoverUrl($cover);
 }
Beispiel #4
0
 public function chooseTemplate($params)
 {
     $userId = (int) $params['userId'];
     $this->checkCredits();
     $templateId = (int) $params['templateId'];
     $reposition = false;
     //(bool) $params['reposition'];
     $template = $this->service->findTemplateById($templateId);
     if ($template === null) {
         return array("error" => "Template was not found!");
     }
     $status = $reposition ? UHEADER_BOL_Cover::STATUS_TMP : UHEADER_BOL_Cover::STATUS_ACTIVE;
     $cover = $template->createCover($userId, $status);
     $eventName = null;
     if (!$reposition) {
         $activeCover = $this->service->findCoverByUserId($userId, UHEADER_BOL_Cover::STATUS_ACTIVE);
         $eventName = $activeCover === null ? UHEADER_BOL_Service::EVENT_ADD : UHEADER_BOL_Service::EVENT_CHANGE;
     }
     $this->service->deleteCoverByUserId($userId, $status);
     $this->service->saveCover($cover);
     if ($eventName !== null) {
         $src = $cover->getSrc();
         $event = new OW_Event($eventName, array('userId' => $userId, 'id' => $cover->id, 'file' => $cover->file, 'path' => $this->service->getCoverPath($cover), 'src' => $src, 'data' => $cover->getSettings()), $cover->getSettings());
         OW::getEventManager()->trigger($event);
     }
     return array('src' => $cover->getSrc(), 'data' => $cover->getSettings(), 'ratio' => $cover->getRatio(), "mode" => $reposition ? "reposition" : "view");
 }
Beispiel #5
0
 /**
  * Returns class instance
  *
  * @return UHEADER_BOL_Service
  */
 public static function getInstance()
 {
     if (null === self::$classInstance) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
Beispiel #6
0
 public function onItemRender(OW_Event $event)
 {
     $params = $event->getParams();
     $data = $params["data"];
     if (!in_array($params['entityType'], array(self::TYPE_COMMENT, self::TYPE_LIKE))) {
         return;
     }
     $coverId = null;
     if (empty($params["data"]["coverId"])) {
         $cover = UHEADER_BOL_Service::getInstance()->findCoverByUserId(OW::getUser()->getId());
         if (!empty($cover)) {
             $coverId = $cover->id;
         }
     } else {
         $coverId = $params["data"]["coverId"];
     }
     $url = null;
     if (!empty($coverId)) {
         $url = UHEADER_MCLASS_NewsfeedBridge::getInstance()->getCoverUrl($coverId);
     }
     if (!empty($url)) {
         $data["url"] = $url;
     }
     $event->setData($data);
 }
Beispiel #7
0
 public function __construct($userId)
 {
     parent::__construct();
     $cover = UHEADER_BOL_Service::getInstance()->findCoverByUserId($userId);
     if (empty($cover)) {
         $this->assign('error', OW::getLanguage()->text('uheader', 'cover_not_found'));
         return;
     }
     $src = UHEADER_BOL_Service::getInstance()->getCoverUrl($cover);
     $settings = $cover->getSettings();
     $height = $settings['dimensions']['height'];
     $width = $settings['dimensions']['width'];
     $top = 0;
     if ($height < self::MIN_HEIGHT) {
         $top = (self::MIN_HEIGHT - $height) / 2;
     }
     $avatarsData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($userId));
     $this->assign('user', $avatarsData[$userId]);
     $this->assign('src', $src);
     $this->assign('top', $top);
     $this->assign('dimensions', $settings['dimensions']);
     $cmtParams = new BASE_CommentsParams('uheader', UHEADER_CLASS_CommentsBridge::ENTITY_TYPE);
     $cmtParams->setWrapInBox(false);
     $cmtParams->setEntityId($cover->id);
     $cmtParams->setOwnerId($userId);
     $cmtParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
     $photoCmts = new BASE_CMP_Comments($cmtParams);
     $this->addComponent('comments', $photoCmts);
 }
Beispiel #8
0
 public function onBeforeRender()
 {
     parent::onBeforeRender();
     $templateList = $this->service->findTemplateListForUserId($this->userId);
     $tplTemplates = array();
     foreach ($templateList as $tpl) {
         /*@var $tpl UHEADER_BOL_Template */
         $settings = $tpl->getSettings();
         $template = array("id" => $tpl->id, "src" => $this->service->getTemplateUrl($tpl), "css" => $tpl->getCssString(), "canvas" => $tpl->getCanvas(self::ITEM_WIDTH));
         $tplTemplates[] = $template;
     }
     $this->assign("templates", $tplTemplates);
     $this->assign("dimensions", $this->dimensions);
     $js = UTIL_JsGenerator::composeJsString('UHEADER.GallerySwitcher.registerTab({$tabKey}, new UHEADER.TemplateGallery({$params}, _scope));', array('params' => array('userId' => $this->userId, 'tabKey' => $this->tabKey, "dimensions" => $this->dimensions), "tabKey" => $this->tabKey));
     OW::getDocument()->addOnloadScript($js);
 }
Beispiel #9
0
 public function getCover(OW_Event $event)
 {
     $params = $event->getParams();
     $userId = $params["userId"];
     $forWidth = empty($params["forWidth"]) ? null : $params["forWidth"];
     $permited = UHEADER_CLASS_PrivacyBridge::getInstance()->checkPrivacy($userId);
     if (!$permited) {
         return null;
     }
     $cover = $this->service->findCoverByUserId($userId, UHEADER_BOL_Cover::STATUS_ACTIVE);
     if ($cover === null) {
         $cover = $this->service->findDefaultTemplateForUser($userId);
     }
     if ($cover === null) {
         return null;
     }
     $out = array("userId" => $userId, "src" => $cover->getSrc(), "data" => $cover->getSettings(), "canvas" => $cover->getCanvas($forWidth), "css" => $cover->getCss(), "cssString" => $cover->getCssString());
     $event->setData($out);
     return $out;
 }
Beispiel #10
0
 public function onBeforeRender()
 {
     parent::onBeforeRender();
     $coverId = $this->vars["coverId"];
     $cover = UHEADER_BOL_Service::getInstance()->findCoverById($coverId);
     if ($cover === null) {
         $this->setVisible(false);
         return;
     }
     UHEADER_CLASS_Plugin::getInstance()->includeStaticFile("uheader.css");
     $src = UHEADER_BOL_Service::getInstance()->getCoverUrl($cover);
     $this->assign('src', $src);
     $this->assign('imageCss', $cover->getCssString());
     $this->assign("scale", $cover->getRatio());
     $this->assign("url", BOL_UserService::getInstance()->getUserUrl($cover->userId));
 }
Beispiel #11
0
 public function __construct($userId)
 {
     parent::__construct();
     $cover = UHEADER_BOL_Service::getInstance()->findCoverByUserId($userId);
     if (empty($cover)) {
         $this->setVisible(false);
         return;
     }
     UHEADER_CLASS_Plugin::getInstance()->includeStaticFile("uheader.css");
     $uniqId = uniqid('uheader-');
     $this->assign('uniqId', $uniqId);
     $js = UTIL_JsGenerator::newInstance()->jQueryEvent('#' . $uniqId, 'click', 'OW.ajaxFloatBox("UHEADER_CMP_CoverView", [e.data.userId], {
             layout: "empty",
             top: 50
         });
         return false;', array('e'), array('userId' => $userId));
     OW::getDocument()->addOnloadScript($js);
     $src = UHEADER_BOL_Service::getInstance()->getCoverUrl($cover);
     $this->assign('src', $src);
     $cavas = $cover->getCanvas(self::ITEM_WIDTH);
     $this->assign('imageCss', $cover->getCssString());
     $this->assign('height', $cavas["height"]);
 }
Beispiel #12
0
 private function addTemplate($file, $roleId = null)
 {
     $canvasWidth = self::CANVAS_WIDTH;
     $canvasHeight = $this->config['cover_height'];
     $this->validateFile($file);
     $pluginfilesDir = OW::getPluginManager()->getPlugin('uheader')->getPluginFilesDir();
     $tmpTplPath = $pluginfilesDir . uniqid('tmp_') . '.jpg';
     if (!move_uploaded_file($file['tmp_name'], $tmpTplPath)) {
         throw new InvalidArgumentException('Moving uploaded file faild');
     }
     $coverImage = new UTIL_Image($tmpTplPath);
     $imageHeight = $coverImage->getHeight();
     $imageWidth = $coverImage->getWidth();
     $css = array('width' => 'auto', 'height' => 'auto');
     $tmp = $canvasWidth * $imageHeight / $imageWidth;
     if ($tmp >= $canvasHeight) {
         $css['width'] = '100%';
     } else {
         $css['height'] = '100%';
     }
     $this->validateImage($coverImage, $canvasWidth, $canvasHeight);
     $template = new UHEADER_BOL_Template();
     $extension = UTIL_File::getExtension($file['name']);
     $template->file = uniqid('template-') . '.' . $extension;
     $template->default = false;
     $template->timeStamp = time();
     $dimensions = array('height' => $imageHeight, 'width' => $imageWidth);
     $template->setSettings(array('dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0)));
     $this->service->saveTemplate($template);
     if ($roleId !== null) {
         $this->service->saveRoleIdsForTemplateId($template->id, array($roleId));
     }
     $templatePath = $this->service->getTemplatePath($template);
     OW::getStorage()->copyFile($tmpTplPath, $templatePath);
     @unlink($tmpTplPath);
 }
Beispiel #13
0
 public function onBeforeRender()
 {
     parent::onBeforeRender();
     $service = UHEADER_BOL_Service::getInstance();
     $cover = $service->findCoverByUserId($this->user->id, UHEADER_BOL_Cover::STATUS_ACTIVE);
     if ($cover === null) {
         $removedCover = $service->findCoverByUserId($this->user->id, UHEADER_BOL_Cover::STATUS_REMOVED);
         if ($removedCover === null) {
             $template = $service->findDefaultTemplateForUser($this->user->id);
             if ($template !== null) {
                 $cover = $template->createCover($this->user->id);
             }
         }
     }
     if ($cover === null) {
         return;
     }
     UHEADER_CLASS_Plugin::getInstance()->includeStaticFile("uheader.css");
     $tplCover = array();
     $tplCover["src"] = UHEADER_BOL_Service::getInstance()->getCoverUrl($cover);
     $tplCover['imageCss'] = $cover->getCssString();
     $tplCover["scale"] = $cover->getRatio();
     $this->assign("cover", $tplCover);
 }
Beispiel #14
0
 public function getSrc()
 {
     return UHEADER_BOL_Service::getInstance()->getTemplateUrl($this);
 }
Beispiel #15
0
 public function onLike(OW_Event $event)
 {
     $params = $event->getParams();
     if ($params['entityType'] != UHEADER_CLASS_CommentsBridge::ENTITY_TYPE) {
         return;
     }
     $userId = $params['userId'];
     $coverId = $params['entityId'];
     $cover = UHEADER_BOL_Service::getInstance()->findCoverById($coverId);
     $string = null;
     if ($cover->userId == $userId) {
         $string = array("key" => 'uheader+activity_string_cover_like_self');
     } else {
         $userName = BOL_UserService::getInstance()->getDisplayName($cover->userId);
         $userUrl = BOL_UserService::getInstance()->getUserUrl($cover->userId);
         $userEmbed = '<a href="' . $userUrl . '">' . $userName . '</a>';
         $string = array("key" => 'uheader+activity_string_cover_like', "vars" => array('user' => $userEmbed));
     }
     OW::getEventManager()->trigger(new OW_Event('feed.activity', array('activityType' => 'like', 'activityId' => $userId, 'entityId' => $params['entityId'], 'entityType' => $params['entityType'], 'userId' => $userId, 'pluginKey' => $this->plugin->getKey()), array('string' => $string)));
 }
Beispiel #16
0
<?php

Updater::getLanguageService()->importPrefixFromZip(dirname(__FILE__) . DS . 'langs.zip', 'uheader');
$sql = array();
$sql[] = "ALTER TABLE `" . OW_DB_PREFIX . "uheader_cover` ADD `templateId` int(11) DEFAULT NULL";
$sql[] = "CREATE TABLE IF NOT EXISTS `" . OW_DB_PREFIX . "uheader_template` (\n  `id` int(11) NOT NULL AUTO_INCREMENT,\n  `file` varchar(255) NOT NULL,\n  `settings` text NOT NULL,\n  `default` int(11) NOT NULL DEFAULT '0',\n  `timeStamp` int(11) NOT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
$sql[] = "CREATE TABLE IF NOT EXISTS `" . OW_DB_PREFIX . "uheader_template_role` (\n  `id` int(11) NOT NULL AUTO_INCREMENT,\n  `templateId` int(11) NOT NULL,\n  `roleId` int(11) NOT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `templateId` (`templateId`,`roleid`)\n) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
foreach ($sql as $query) {
    Updater::getDbo()->query($query);
}
Updater::getConfigService()->addConfig('uheader', 'tpl_view_mode', 'list', 'Cover gallery view mode');
try {
    $plugin = OW::getPluginManager()->getPlugin("uheader");
    $basePlugin = OW::getPluginManager()->getPlugin("base");
    spl_autoload_register(array('OW_Autoload', 'autoload'));
    OW::getAutoloader()->addPackagePointer("UHEADER_BOL", $plugin->getBolDir());
    OW::getAutoloader()->addPackagePointer("UHEADER_CLASS", $plugin->getClassesDir());
    OW::getAutoloader()->addPackagePointer("BASE_CLASS", $basePlugin->getClassesDir());
} catch (Exception $e) {
}
try {
    //Add default templates
    $templatesBridge = UHEADER_CLASS_TemplatesBridge::getInstance();
    $templatesBridge->addBuiltInCovers();
} catch (Exception $e) {
}
try {
    UHEADER_BOL_Service::getInstance()->saveInfoConfig(UHEADER_BOL_Service::INFO_LINE1, "base-gender-age");
    UHEADER_BOL_Service::getInstance()->saveInfoConfig(UHEADER_BOL_Service::INFO_LINE2, "base-about");
} catch (Exception $e) {
}
Beispiel #17
0
 public function onLike(OW_Event $event)
 {
     $params = $event->getParams();
     if ($params['entityType'] != UHEADER_CLASS_CommentsBridge::ENTITY_TYPE) {
         return;
     }
     $userId = OW::getUser()->getId();
     $cover = UHEADER_BOL_Service::getInstance()->findCoverById($params['entityId']);
     if ($cover->userId == $userId) {
         return;
     }
     $userUrl = BOL_UserService::getInstance()->getUserUrl($cover->userId);
     $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($userId));
     $avatar = $avatars[$userId];
     $previewImage = null;
     $notificationParams = array('pluginKey' => $this->plugin->getKey(), 'action' => self::ACTION_LIKE, 'entityType' => self::TYPE_LIKE, 'entityId' => $cover->userId, 'userId' => $cover->userId, 'time' => time());
     $users = array();
     $users[] = array('userId' => $userId, 'userName' => $avatar['title'], 'userUrl' => $avatar['url']);
     $notificationData = array('string' => array('key' => 'uheader+notifications_like_1', 'vars' => array('user' => '<a href="' . $users[0]['userUrl'] . '">' . $users[0]['userName'] . '</a>')), 'users' => $users, 'userIds' => array($userId), 'avatar' => $avatar, 'contentImage' => $previewImage, 'url' => $userUrl, "coverId" => $cover->id);
     $event = new OW_Event('notifications.add', $notificationParams, $notificationData);
     OW::getEventManager()->trigger($event);
 }
Beispiel #18
0
 public function getInfoLines()
 {
     return array(UHEADER_BOL_Service::INFO_LINE1 => UHEADER_BOL_Service::getInstance()->getInfoLine($this->userId, UHEADER_BOL_Service::INFO_LINE1), UHEADER_BOL_Service::INFO_LINE2 => UHEADER_BOL_Service::getInstance()->getInfoLine($this->userId, UHEADER_BOL_Service::INFO_LINE2));
 }