public function index() { $this->setPageTitle(OW::getLanguage()->text("ynmediaimporter", "facebook") . " - " . OW::getLanguage()->text("ynmediaimporter", "index_page_title")); $this->setPageHeading(OW::getLanguage()->text("ynmediaimporter", "index_page_heading")); $this->facebook(); //gender facebook page template $facebookProfile = new YNMEDIAIMPORTER_CMP_FacebookProfile(); $this->addComponent('facebookProfile', $facebookProfile); $mediaBrowse = new YNMEDIAIMPORTER_CMP_MediaBrowse(array('service' => 'facebook')); $this->addComponent('mediaBrowse', $mediaBrowse); $provider = Ynmediaimporter::getProvider($this->_serviceName); $configs = OW::getConfig()->getValues('ynmediaimporter'); if ($configs['enable_facebook'] == 0) { $url = OW::getRouter()->urlForRoute('ynmediaimporter.index'); $this->redirect($url); exit; } if (!$provider->isAlive()) { $this->redirect($provider->getConnectUrl()); exit; } if (!OW::getPluginManager()->isPluginActive('ynsocialbridge')) { return; } }
public function __construct() { parent::__construct(); $provider = Ynmediaimporter::getProvider('flickr'); $userThumb = $provider->getUserSquareAvatarUrl(); $userProfileUrl = $provider->getUserProfileUrl(); $userDisplayName = $provider->getUserDisplayname(); $disconnectUrl = $provider->getDisconnectUrl(); $this->assign('userThumb', $userThumb); $this->assign('userProfileUrl', $userProfileUrl); $this->assign('userDisplayName', $userDisplayName); $this->assign('disconnectUrl', $disconnectUrl); }
public function postimport() { $json = $_POST['json']; $items = (array) json_decode($json, 1); $albumName = ''; $photo = 0; $photos = array(); $albums = array(); $photosId = array(); $albumsId = array(); $provider = 'facebook'; foreach ($items as $item) { $data = json_decode($item['data'], 1); $media = $item['media']; $provider = $item['provider']; if ('photo' == $media) { $photos[] = $data; } else { $albums[] = $data; $albumName = $data['title_decode']; $rows = Ynmediaimporter::getProvider($provider)->getAllPhoto(array('media' => $media, 'aid' => $data['aid'], 'media_parent' => $data['media_parent'], 'photo_count' => $data['photo_count'])); foreach ($rows as $item) { $photos[] = $item; } } } $schedulerId = 0; $tableName = OW_DB_PREFIX . 'ynmediaimporter_nodes'; $sql = "INSERT IGNORE INTO {$tableName} (\n \tnid, user_id, owner_id,owner_type, `key`, uid, aid, media, provider,\n \tphoto_count,`status`,title, src_thumb, src_small,src_medium,src_big, description\n \t) VALUES "; $pieces = array(); $status = 0; $userId = OW::getUser()->getId(); $ownerId = $userId; $ownerType = 'user'; $deleteSql = "DELETE FROM {$tableName} WHERE `user_id` = '{$userId}' AND `scheduler_id` = '0'"; OW::getDbo()->query($deleteSql); $flag = 0; foreach ($photos as $item) { $photosId[] = $item['nid']; $pieces[] = '(' . implode(',', array_map(array($this, 'quote'), array($item['nid'], $userId, $ownerId, $ownerType, $item['id'], $item['uid'], $item['aid'], $item['media'], $item['provider'], $item['photo_count'], $item['status'] ? $item['status'] : 0, is_array($item['title']) && isset($item['title']['text']) ? mysql_real_escape_string($item['title']['text']) : mysql_real_escape_string($item['title']), $item['src_thumb'], $item['src_small'], $item['src_medium'], $item['src_big'], $item['description']))) . ')'; } foreach ($albums as $item) { $albumsId[] = $item['nid']; $pieces[] = '(' . implode(',', array_map(array($this, 'quote'), array($item['nid'], $userId, $ownerId, $ownerType, $item['id'], $item['uid'], $item['aid'], $item['media'], $item['provider'], $item['photo_count'], $item['status'] ? $item['status'] : 0, mysql_real_escape_string(urldecode($item['title'])), $item['src_thumb'], $item['src_small'], $item['src_medium'], $item['src_big'], $item['description']))) . ')'; } $sql .= implode(',', $pieces); OW::getDbo()->query($sql); $numphoto = intval(OW::getDbo()->queryForColumn("select count(*) from {$tableName} where user_id={$userId} and scheduler_id=0 and media='photo'")); $count_photo = count($photosId); $count_album = count($albumsId); $message = ''; if ($numphoto == 0) { $message = 'It seem all selected photos is set to queue. So the current request will be canceled.'; } else { if ($count_album && $count_photo) { $message = "Import <strong>{$count_photo}</strong> photo(s) in <strong>{$count_album}</strong> album(s)."; } else { if ($count_photo) { $message = "Import {$count_photo} photo(s)."; } else { $message = 'Sorry, Your request can not be executed.'; } } } $aOutput = array('scheduler' => $schedulerId, 'photos' => $photosId, 'numphoto' => $numphoto, 'albums' => $albumsId, 'message' => $message, 'photo_count' => $count_photo, 'provider' => $provider, 'album_count' => $count_album); $addPhotoForm = new YNMEDIAIMPORTER_CMP_AddPhoto(array('json_data' => json_encode($aOutput))); $responderUrl = OW::getRouter()->urlFor('PHOTO_CTRL_Upload', 'suggestAlbum', array('userId' => $userId)); $aOutput['form'] = $addPhotoForm->render(); $aOutput['responder_url'] = $responderUrl; $aOutput['album_name'] = $albumName; echo json_encode($aOutput); exit(0); }