This repository has been archived by the owner on Feb 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcp.fbphotos.php
108 lines (92 loc) · 3.88 KB
/
mcp.fbphotos.php
1
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once('fbphotos_base.php');
/** -----------------------------------------------
* Fbphotos MCP
* -----------------------------------------------
* Sets the control panel in the admin area for
* the module.
*
* @package Fbphotos
* @author Greg Whitworth
*/
class Fbphotos_mcp extends Fbphotos_base {
private $_base_url;
public function __construct()
{
parent::__construct();
$this->_base_url = 'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=fbphotos';
}
/** =================================================
// Index
// -------------------------------------------------
// Runs necessary functions for the index page of
// the control panel.
// -------------------------------------------------
// @return Index view
// ================================================= */
public function index()
{
$this->EE->cp->set_variable('cp_page_title', lang('Facebook Photos : Settings'));
$this->EE->load->helper('form');
$this->EE->load->library('table');
$this->data = array(
'form_action' => $this->_base_url . AMP . 'method=save_settings',
'facebook_id' => $this->facebook_id
);
if( $this->valid_fb_id )
{
$selected_albums = unserialize( parent::get_setting_value( 'facebook_albums' ) );
$this->get_facebook_photo_albums( $selected_albums );
}
return $this->EE->load->view('index', $this->data, TRUE);
}
/** =================================================
// Get Facebook Photo Albums
// -------------------------------------------------
// Returns an array of album information specific
// to our needs in the control panel.
// -------------------------------------------------
// @return array
// ================================================= */
private function get_facebook_photo_albums( $selected_albums )
{
$result = parent::get_facebook_graph_data( $this->facebook_id, 'albums' );
$albums = array();
if( $result )
{
foreach( $result->data as $info ) {
if( @in_array( $info->id, $selected_albums ))
{
$albums['checked'][$info->name] = $info->id;
}
else {
$albums['unchecked'][$info->name] = $info->id;
}
}
}
return $this->data['facebook_albums'] = $albums;
}
/** =================================================
// Save Settings
// -------------------------------------------------
// Saves the settings from the control panel
// -------------------------------------------------
// @return void
// ================================================= */
public function save_settings()
{
$post_items = array(
'facebook_id' => $this->EE->input->post('facebook_id'),
'facebook_albums' => serialize( $this->EE->input->post('facebook_albums') )
);
foreach( $post_items as $key => $value )
{
$data = array(
'setting_value' => $value
);
$this->EE->db->where('setting_name', $key);
$this->EE->db->update( 'exp_' . $this->fb_settings_table , $data);
}
$this->EE->functions->redirect( BASE . AMP . $this->_base_url );
}
}