1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36:
37:
38: Yii::import('application.models.embedded.*');
39:
40: 41: 42: 43: 44:
45: class extends JSONEmbeddedModel implements AdminOwnedCredentials {
46:
47: public static function getAdminProperty () {
48: return 'twitterCredentialsId';
49: }
50:
51: public function getMetaData () {
52: return array (
53: 'private' => 1,
54: 'userId' => Credentials::SYS_ID,
55: 'name' => 'Twitter app',
56: );
57: }
58:
59: public $oauthAccessToken = '';
60: public $oauthAccessTokenSecret = '';
61: public $consumerKey = '';
62: public $consumerSecret = '';
63:
64: public function rules(){
65: return array(
66: array('oauthAccessToken,oauthAccessTokenSecret,consumerKey,consumerSecret', 'safe'),
67: );
68: }
69:
70: public function getProtectedFields () {
71: return array (
72: 'oauthAccessToken', 'oauthAccessTokenSecret', 'consumerSecret', 'consumerKey');
73: }
74:
75: public function renderForm () {
76: $this->renderInputs();
77: echo '<br />';
78: echo '<br />';
79: }
80:
81: public function attributeLabels(){
82: return array(
83: 'oauthAccessToken' => Yii::t('app','Access Token'),
84: 'oauthAccessTokenSecret' => Yii::t('app','Access Token Secret'),
85: 'consumerKey' => Yii::t('app','Consumer Key (API Key)'),
86: 'consumerSecret' => Yii::t('app','Consumer Secret (API Secret)'),
87: );
88: }
89:
90: public function getPageTitle () {
91: return $this->modelLabel ();
92: }
93:
94: public function modelLabel() {
95: return Yii::t('app','Twitter Integration');
96: }
97:
98: public function htmlOptions ($name, $options=array ()) {
99: return X2Html::mergeHtmlOptions (
100: parent::htmlOptions ($name, $options), array ('class' => 'twitter-credential-input'));
101: }
102:
103: public function renderInputs(){
104: echo $this->getInstructions ();
105: echo CHtml::tag ('h3', array (), $this->exoModel->getAttributeLabel ($this->exoAttr));
106: echo '<hr />';
107: echo CHtml::activeLabel($this, 'consumerKey');
108: $this->renderInput ('consumerKey');
109: echo CHtml::activeLabel($this, 'consumerSecret');
110: $this->renderInput ('consumerSecret');
111: echo CHtml::activeLabel($this, 'oauthAccessToken');
112: $this->renderInput ('oauthAccessToken');
113: echo CHtml::activeLabel($this, 'oauthAccessTokenSecret');
114: $this->renderInput ('oauthAccessTokenSecret');
115: echo CHtml::errorSummary($this);
116: echo '<br>';
117: echo '<br>';
118: }
119:
120: private function getInstructions () {
121: return
122: '
123: <h3>'.Yii::t('app', 'Configuring Twitter Integration').'</h3>
124: <hr>
125: <ol>
126: <li>'.Yii::t('app', 'Visit {link} and create a new Twitter app.', array (
127: '{link}' =>
128: '<a href="https://apps.twitter.com/">https://apps.twitter.com</a>'
129: )).'
130: </li>
131: <li>'.Yii::t ('app', 'From your app\'s management page, navigate to the "Keys and Access Tokens" tab.').'
132: </li>
133: <li>'.Yii::t('app', 'Click the button labelled "Create my access token".').'
134: </li>
135: <li>'.Yii::t('app', 'Copy your "Consumer Key", "Consumer Secret", "Access Token", and "Access Token Secret" into the corresponding fields below.').'
136: </li>
137: <li>'.Yii::t('app', 'Save your X2CRM Twitter Integration settings.').'</li>
138: </ol>
139: ';
140: }
141:
142: }
143:
144: ?>
145: