/** * getPhotoInfo * * @return string */ private function getPhotoInfo() { $config = getInstagramConfigData(); $instagram = new Instagram($config['instagram_client_id'], $config['instagram_client_secret'], $this->accessToken); try { if (isset($_GET['show']) && $_GET['show'] == 'more') { $feed = $instagram->get('users/self/media/recent/'); } else { $feed = $instagram->get('users/self/media/recent/', array('count' => 8)); } } catch (InstagramApiError $e) { $this->fcmsError->add(array('type' => 'operation', 'message' => T_('Could not get Instagram User data.'), 'error' => $e->getMessage(), 'file' => __FILE__, 'line' => __LINE__)); return false; } $photos = ''; $automaticSelect = ''; if (!$this->autoUpload) { $photos .= '<h2>' . T_('Manual') . '</h2>'; $photos .= '<p>' . T_('Choose photo to add.') . '</p>'; $photos .= '<ul>'; $i = 1; foreach ($feed->data as $photo) { $sourceId = $photo->id; $thumbnail = $photo->images->thumbnail->url; $medium = $photo->images->low_resolution->url; $full = $photo->images->standard_resolution->url; $caption = isset($photo->caption) ? $photo->caption->text : ''; $caption .= ' [' . sprintf(T_('Instagram filter: %s.'), $photo->filter) . ']'; $value = "{$sourceId}|{$thumbnail}|{$medium}|{$full}|{$caption}"; $photos .= '<li>'; $photos .= '<label for="instagram' . $i . '">'; $photos .= '<img src="' . $thumbnail . '" alt="' . $caption . '"/><br/>'; $photos .= '<input type="checkbox" id="instagram' . $i . '" name="photos[]" value="' . $value . '"/>'; $photos .= '</label>'; $photos .= '</li>'; $i++; } // They probably have more if ($i == 8) { $photos .= '<li><a href="index.php?action=upload&type=instagram&show=more">' . T_('See more') . '</a></li>'; } $photos .= '</ul>'; } return $photos . ' <h2>' . T_('Automatic') . '</h2> <label> <input type="checkbox" id="automatic" name="automatic" value="1" ' . ($this->autoUpload ? 'checked="checked"' : '') . '/> ' . T_('Have all photos automatically imported.') . ' </label>'; }
/** * getUploadTypesNavigation * * @param string $currentType * * @return string */ protected function getUploadTypesNavigation($currentType) { $nav = ''; $types = array('upload', 'facebook', 'picasa', 'instagram'); foreach ($types as $type) { $url = ''; $class = $currentType == $type ? 'current' : ''; $text = ''; if ($type == 'upload') { $type = getUploaderType($this->fcmsUser->id); $url = '?action=upload&type=' . $type; $text = T_('Computer'); } elseif ($type == 'instagram') { $config = getInstagramConfigData(); if (empty($config['instagram_client_id']) || empty($config['instagram_client_secret'])) { continue; } $url = '?action=upload&type=instagram'; $text = 'Instagram'; } elseif ($type == 'picasa') { $url = '?action=upload&type=picasa'; $text = 'Picasa'; } elseif ($type == 'facebook') { $config = getFacebookConfigData(); if (empty($config['fb_app_id']) && empty($config['fb_secret'])) { continue; } $url = '?action=upload&type=facebook'; $text = 'Facebook'; } else { die('Invalid upload type.'); } $nav .= ' <li class="' . $class . '"><a href="' . $url . '">' . $text . '</a></li>'; } return $nav; }
/** * runInstagramJob * * @return void */ function runInstagramJob() { require_once 'inc/config_inc.php'; require_once 'inc/constants.php'; require_once 'inc/socialmedia.php'; require_once 'inc/utils.php'; require_once THIRDPARTY . 'gettext.inc'; require_once THIRDPARTY . 'Instagram.php'; $fcmsError = FCMS_Error::getInstance(); $fcmsDatabase = Database::getInstance($fcmsError); // Get user's access tokens $sql = "SELECT u.`id`, s.`instagram_access_token`\n FROM `fcms_user_settings` AS s, `fcms_users` AS u\n WHERE s.`user` = u.`id`\n AND s.`instagram_auto_upload` = 1\n AND s.`instagram_access_token` IS NOT NULL"; $rows = $fcmsDatabase->getRows($sql); if ($rows === false) { logError(__FILE__ . ' [' . __LINE__ . '] - Could not get instagram access tokens.'); die; } $accessTokens = array(); foreach ($rows as $row) { $accessTokens[$row['id']] = $row['instagram_access_token']; } $config = getInstagramConfigData(); $existingIds = getExistingInstagramIds(); // Get pics for each user foreach ($accessTokens as $userId => $token) { $categoryId = getUserInstagramCategory($userId); $instagram = new Instagram($config['instagram_client_id'], $config['instagram_client_secret'], $token); try { $feed = $instagram->get('users/self/media/recent'); } catch (InstagramApiError $e) { logError(__FILE__ . ' [' . __LINE__ . '] - Could not get user instagram data. - ' . $e->getMessage()); die; } $sql = "INSERT INTO `fcms_gallery_photos`\n (`date`, `path`, `caption`, `category`, `user`)\n VALUES "; foreach ($feed->data as $photo) { $sourceId = $photo->id; $thumbnail = $photo->images->thumbnail->url; $medium = $photo->images->low_resolution->url; $full = $photo->images->standard_resolution->url; $caption = $photo->caption->text; $caption .= ' [' . sprintf(T_('Filter: %s.'), $photo->filter) . ']'; // Skip existing photos if (isset($existingIds[$sourceId])) { continue; } // Save external paths $sql = "INSERT INTO `fcms_gallery_external_photo`\n (`source_id`, `thumbnail`, `medium`, `full`)\n VALUES\n (?, ?, ?, ?)"; $params = array($sourceId, $thumbnail, $medium, $full); $id = $fcmsDatabase->insert($sql, $params); if ($id === false) { logError(__FILE__ . ' [' . __LINE__ . '] - Could not save external photos.'); die; } // Insert new photo $sql = "INSERT INTO `fcms_gallery_photos`\n (`date`, `external_id`, `caption`, `category`, `user`)\n VALUES\n (NOW(), ?, ?, ?, ?)"; $params = array($id, $caption, $categoryId, $userId); if (!$fcmsDatabase->insert($sql, $params)) { logError(__FILE__ . ' [' . __LINE__ . '] - Could not insert new photo.'); die; } } } // Update date we last ran this job updateLastRun(date('Y-m-d H:i:s'), 'instagram'); }
/** * displayEditInstagramSubmit * * @return void */ function displayEditInstagramSubmit() { $config = getInstagramConfigData(); if (!empty($config['instagram_client_id']) && !empty($config['instagram_client_secret'])) { $callbackUrl = getDomainAndDir(); $callbackUrl .= 'settings.php?view=instagram'; $instagram = new Instagram($config['instagram_client_id'], $config['instagram_client_secret'], null); if (isset($_GET['error']) || isset($_GET['error_reason']) || isset($_GET['error_description'])) { $this->displayHeader(); echo ' <div class="error-alert"> <p>' . $_GET['error'] . '</p> <p>' . $_GET['error_reason'] . '</p> <p>' . $_GET['error_description'] . '</p> </div>'; $this->displayFooter(); return; } $response = $instagram->getAccessToken($_GET['code'], $callbackUrl); $accessToken = $response->access_token; $sql = "UPDATE `fcms_user_settings`\n SET `instagram_access_token` = ?\n WHERE `user` = ?"; $params = array($accessToken, $this->fcmsUser->id); if (!$this->fcmsDatabase->update($sql, $params)) { $this->displayHeader(); $this->fcmsError->displayError(); $this->displayFooter(); return; } } else { $this->displayHeader(); echo ' <div class="info-alert"> <h2>' . T_('Instagram isn\'t Configured Yet.') . '</h2> <p>' . T_('Unfortunately, your website administrator has not set up Instagram yet.') . '</p> </div>'; $this->displayFooter(); return; } header("Location: settings.php?view=instagram"); }
/** * displayFormPage * * Displays the form for configuring a instagram app. * * @return void */ function displayFormPage() { global $fcmsUser; $this->displayHeader(); if (isset($_SESSION['success'])) { echo ' <div class="alert-message success"> <a class="close" href="#" onclick="$(this).up(\'div\').hide(); return false;">×</a> ' . T_('Changes Updated Successfully') . ' </div>'; unset($_SESSION['success']); } $r = getInstagramConfigData(); $client_id = isset($r['instagram_client_id']) ? cleanOutput($r['instagram_client_id']) : ''; $client_secret = isset($r['instagram_client_secret']) ? cleanOutput($r['instagram_client_secret']) : ''; echo ' <div class="alert-message block-message info"> <h1>' . T_('Instagram Integration') . '</h1> <p> ' . T_('In order to integrate Family Connections with Instagram, you must create a new Instagram client as Instagram.com, and configure that client in Family Connections.') . ' </p> </div>'; if (empty($client_id) || empty($client_secret)) { echo ' <div class="row"> <div class="span4"> <h2>' . T_('Step 1') . '</h2> <p> ' . T_('Got to Instagram and register a new Instagram client.') . ' </p> </div> <div class="span12"> <h3> <a href="http://instagram.com/developer/clients/manage/">' . T_('Register new Instagram Client') . '</a><br/> </h3> <p> ' . T_('Make sure you add <code>settings.php?view=instagram</code> to your Callback URL.') . ' </p> </div><!-- /span12 --> </div><!-- /row --> <p> </p> <p> </p> <p> </p> <div class="row"> <div class="span4"> <h2>' . T_('Step 2') . '</h2> <p> ' . T_('Fill out the form below with the Instagram Client Id and Client Secret.') . ' </p> </div> <div class="span12">'; } echo ' <form method="post" action="instagram.php"> <fieldset> <legend>Instagram</legend> <div class="clearfix"> <label for="id">' . T_('Client ID') . '</label> <div class="input"> <input class="span6" type="text" name="id" id="id" value="' . $client_id . '"/> </div> </div> <div class="clearfix"> <label for="secret">' . T_('Client Secret') . '</label> <div class="input"> <input class="span6" type="text" name="secret" id="secret" value="' . $client_secret . '"/> </div> </div> <div class="actions"> <input class="btn primary" type="submit" name="submit" value="' . T_('Save') . '"/> </div> </fieldset> </form>'; if (empty($client_id) || empty($client_secret)) { echo ' </div><!-- /span12 --> </div><!-- /row -->'; } $this->displayFooter(); }