public function getKeys() { if (!$this->_keys) { $key = new Api_Model_Key(); $this->_keys = $key->findAll(array('provider_id' => $this->getId())); } return $this->_keys; }
public function findallAction() { if ($value_id = $this->getRequest()->getParam("value_id")) { try { $video = new Media_Model_Gallery_Video(); $videos = $video->findAll(array('value_id' => $value_id)); $data = array("collection" => array()); $has_youtube_videos = false; foreach ($videos as $video) { $data["collection"][] = array("id" => $video->getId(), "name" => $video->getName(), "type" => $video->getTypeId(), "search_by" => $video->getType(), "search_keyword" => $video->getParam()); if ($video->getTypeId() == "youtube") { $has_youtube_videos = true; } } $data["page_title"] = $this->getCurrentOptionValue()->getTabbarName(); $data["displayed_per_page"] = Media_Model_Gallery_Video_Abstract::DISPLAYED_PER_PAGE; $data["header_right_button"]["picto_url"] = $this->_getColorizedImage($this->_getImage('pictos/more.png', true), $this->getApplication()->getBlock('subheader')->getColor()); if ($has_youtube_videos) { $data["youtube_key"] = Api_Model_Key::findKeysFor('youtube')->getApiKey(); } } catch (Exception $e) { $data = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($data); } }
public function constructUrl() { $client_id = Api_Model_Key::findKeysFor('instagram')->getClientId(); $token = Api_Model_Key::findKeysFor('instagram')->getToken(); $this->_endpointUrls = array('userSearch' => str_replace('%client_id%', $client_id, str_replace('%token%', $token, $this->_endpointUrls['userSearch'])), 'mediaSearch' => str_replace('%client_id%', $client_id, str_replace('%token%', $token, $this->_endpointUrls['mediaSearch']))); return $this; }
public function saveAction() { if ($datas = $this->getRequest()->getPost()) { try { if (empty($datas['key_id'])) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } $key = new Api_Model_Key(); $key->find($datas['key_id']); if (!$key->getId()) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } if (empty($datas['value'])) { $datas['value'] = null; } $key->setValue($datas['value'])->save(); $html = array('success' => '1', 'success_message' => $this->_('Infos successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
public function saveAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { try { $keysData = array(); foreach ($data as $api_provider) { foreach ($api_provider["keys"] as $key) { $keysData[$key["id"]] = $key; } } $key = new Api_Model_Key(); $keys = $key->findAll(); foreach ($keys as $key) { if (!empty($keysData[$key->getId()])) { $key->addData($keysData[$key->getId()])->save(); } } $data = array("success" => 1, "message" => $this->_("Api Keys successfully saved")); } catch (Exception $e) { $data = array("error" => 1, "message" => $this->_("An error occurred while saving. Please, try again later.")); } $this->_sendHtml($data); } }
/** * Récupère les vidéos youtube * * @param string $search * @return array */ public function getList($search) { if (!$this->_videos) { $this->_videos = array(); try { $video_id = $search; if (Zend_Uri::check($search)) { $params = Zend_Uri::factory($search)->getQueryAsArray(); if (!empty($params['v'])) { $video_id = $params['v']; } } $api_key = Api_Model_Key::findKeysFor('youtube')->getApiKey(); $url = "https://www.googleapis.com/youtube/v3/videos?id={$video_id}&key={$api_key}&part=snippet,contentDetails,status"; $datas = @file_get_contents($url); if ($datas && !empty($datas['pageInfo']['totalResults'])) { $datas = Zend_Json::decode($datas); $feed = array(); foreach ($datas['items'] as $item) { $feed[] = new Core_Model_Default(array('title' => !empty($item['snippet']['title']) ? $item['snippet']['title'] : null, 'content' => !empty($item['snippet']['description']) ? $item['snippet']['description'] : null, 'link' => "http://www.youtube.com/watch?v={$video_id}")); } } else { $this->_setYoutubeUrl($search); $feed = Zend_Feed_Reader::import($this->getLink()); } } catch (Exception $e) { $feed = array(); } foreach ($feed as $entry) { $params = Zend_Uri::factory($entry->getLink())->getQueryAsArray(); if (empty($params['v'])) { continue; } $video = new Core_Model_Default(array('id' => $params['v'], 'title' => $entry->getTitle(), 'description' => $entry->getContent(), 'link' => "http://www.youtube.com/embed/{$params['v']}", 'image' => "http://img.youtube.com/vi/{$params['v']}/0.jpg")); $this->_videos[] = $video; } } return $this->_videos; }
public function getFacebookKey() { return Api_Model_Key::findKeysFor('facebook')->getSecretKey(); }
<?php $this->query("\n CREATE TABLE `api_provider` (\n `provider_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n `code` varchar(30) NOT NULL,\n `name` varchar(60) NOT NULL,\n `icon` varchar(50) NULL DEFAULT NULL,\n `created_at` datetime NOT NULL,\n `updated_at` datetime NOT NULL,\n PRIMARY KEY (`provider_id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\n CREATE TABLE `api_key` (\n `key_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n `provider_id` int(11) unsigned NOT NULL,\n `key` varchar(30) NULL DEFAULT NULL,\n `value` varchar(255) NULL DEFAULT NULL,\n `created_at` datetime NOT NULL,\n `updated_at` datetime NOT NULL,\n PRIMARY KEY (`key_id`),\n KEY `KEY_PROVIDER_ID` (`provider_id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n"); $this->query("\n CREATE TABLE `api_user` (\n `user_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n `username` varchar(50) NOT NULL,\n `firstname` varchar(50) NULL DEFAULT NULL,\n `lastname` varchar(50) NULL DEFAULT NULL,\n `password` varchar(100) NOT NULL,\n `created_at` datetime NOT NULL,\n `updated_at` datetime NOT NULL,\n PRIMARY KEY (`user_id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n"); $this->query("\n ALTER TABLE `api_key`\n ADD FOREIGN KEY `FK_PROVIDER_ID` (`provider_id`) REFERENCES `api_provider` (`provider_id`) ON DELETE CASCADE ON UPDATE CASCADE;\n"); $apis = array(array("code" => "instagram", "icon" => "fa-instagram", "keys" => array("token", "client_id")), array("code" => "facebook", "icon" => "fa-facebook-square", "keys" => array("app_id", "secret_key")), array("code" => "youtube", "icon" => "fa-youtube", "keys" => array("api_key")), array("code" => "soundcloud", "icon" => "fa-soundcloud", "keys" => array("client_id", "secret_id"))); foreach ($apis as $provider_data) { $provider_name = ucfirst($provider_data["code"]); $provider = new Api_Model_Provider(); $provider->setData(array("code" => $provider_data["code"], "name" => $provider_name, "icon" => $provider_data["icon"]))->save(); foreach ($provider_data["keys"] as $key) { $data = array('provider_id' => $provider->getId(), 'key' => $key); $key = new Api_Model_Key(); $key->setData($data)->save(); } }
/** * Construit le lien * * @param string $search * @return \Cms_Model_Application_Page_Block_Youtube */ protected function _setYoutubeUrl($search, $type) { $api_key = Api_Model_Key::findKeysFor('youtube')->getApiKey(); $flux = $this->_flux[$type]; $search = str_replace(' ', '+', $search); $url = str_replace('%s1', $search, $flux); $url = str_replace('%s2', $api_key, $url); $url = str_replace('%d1', '1', $url); $url = str_replace('%d2', '24', $url); $this->setLink($url); return $this; }
public function getFacebookKey() { $facebook_key = $this->getData("facebook_key"); if (!$facebook_key) { $facebook_key = Api_Model_Key::findKeysFor('facebook')->getSecretKey(); } return $facebook_key; }