private function initInstagram(&$instagramoauth)
 {
     if ($this->user_data) {
         return true;
     }
     $instagramoauth = new Helper_Modules_Instagram();
     $InstagramAccessToken = $instagramoauth->getAccessToken();
     $user_data = JO_Json::decode($instagramoauth->getUser(), true);
     if (isset($user_data['meta']['code']) && $user_data['meta']['code'] == 200) {
         JO_Session::set('InstagramAccessToken', $InstagramAccessToken);
         $this->user_data = $user_data['data'];
     } elseif ($InstagramAccessToken) {
         JO_Session::set('InstagramAccessToken', $InstagramAccessToken);
         $instagramoauth->setAccessToken($InstagramAccessToken);
     } elseif (JO_Session::get('InstagramAccessToken')) {
         $instagramoauth->setAccessToken(JO_Session::get('InstagramAccessToken'));
     }
     if (!$this->user_data) {
         $user_data = JO_Json::decode($instagramoauth->getUser(), true);
         if (isset($user_data['meta']['code']) && $user_data['meta']['code'] == 200) {
             $this->user_data = $user_data['data'];
         }
     }
     return $this->user_data ? true : false;
 }
 public function countAction()
 {
     $request = $this->getRequest();
     $json = array('count' => 0);
     $url = urldecode($request->getQuery('url'));
     if ($url && JO_Validate::validateHost($url)) {
         $source_id = Model_Source::getSourceByUrl($url, false);
         if ($source_id) {
             $total_pins = Model_Pins::getTotalPinsLikes(array('filter_source_id' => $source_id, 'filter_from_md5' => md5($url)));
             $json['count'] = $total_pins;
         } else {
             $json['count'] = 0;
         }
     } else {
         $json['error'] = $this->translate('Invalid Url');
     }
     $json['url'] = $url;
     //		$json['count'] = 1212;
     //		$json['error'] = $this->translate('Invalid Url');
     if ($request->getQuery('callback')) {
         $response = $this->getResponse();
         $response->addHeader('Cache-Control: no-cache, must-revalidate');
         $response->addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
         $response->addHeader('Content-type: application/json');
         echo 'receiveCount(' . JO_Json::encode($json) . ');';
         exit;
     } else {
         foreach ($json as $k => $v) {
             $this->view->{$k} = $v;
         }
         echo $this->renderScript('json');
     }
 }
Exemple #3
0
    public function fatal_error_handler($buffer)
    {
        $error = error_get_last();
        if ($error['type'] == 1) {
            $request = JO_Request::getInstance();
            if ($request->isXmlHttpRequest()) {
                $callback = $request->getRequest('callback');
                if (!preg_match('/^([a-z0-9_.]{1,})$/i', $callback)) {
                    $callback = false;
                }
                if ($callback) {
                    $return = $callback . '(' . JO_Json::encode(array('error' => $error)) . ')';
                } else {
                    $return = JO_Json::encode(array('error' => $error));
                }
                return $return;
            }
            // type, message, file, line
            $newBuffer = '<html><header><title>Fatal Error </title></header>
	                    <style>                 
	                    .error_content{                     
	                        background: ghostwhite;
	                        vertical-align: middle;
	                        margin:0 auto;
	                        padding:10px;
	                        width:80%;                              
	                     } 
	                     .error_content label{color: red;font-family: Georgia;font-size: 16pt;font-style: italic;}
	                     .error_content ul li{ background: none repeat scroll 0 0 FloralWhite;                   
	                                border: 1px solid AliceBlue;
	                                display: block;
	                                font-family: monospace;
	                                padding: 8px 10px;
	                                text-align: left;
	                      }
	                    </style>
	                    <body style="text-align: center;">  
	                      <div class="error_content">
	                          <label >Fatal Error </label>
	                          <ul>
	                          	<li><b>Type:</b> ' . $error['type'] . '</li>
	                            <li><b>Line:</b> ' . $error['line'] . '</li>
	                            <li><b>Message:</b> ' . $error['message'] . '</li>
	                            <li><b>File:</b> ' . $error['file'] . '</li>                             
	                          </ul>
	
	                          <a href="javascript:history.back()"> Back </a>                          
	                      </div>
	                    </body></html>';
            return $newBuffer;
        }
        return $buffer;
    }
Exemple #4
0
 public static function getCordinatesByPlace($place)
 {
     $old_agent = ini_get('user_agent');
     ini_set('user_agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110303 SUSE/3.6.15-0.2.2 Firefox/3.6.15');
     $url = 'http://maps.google.com/maps/geo?q=' . urlencode($place) . '&output=json&oe=utf8&sensor=false&key=' . JO_Registry::get('config_google_map');
     if (ini_get('allow_url_fopen')) {
         $code = file_get_contents($url);
     } else {
         $code = self::file_get_contents_curl($url);
     }
     ini_set('user_agent', $old_agent);
     if (!$code) {
         return array('Lat' => 0, 'Lng' => 0);
     }
     $result = JO_Json::decode($code, true);
     if (isset($result['Placemark'][0]['Point']['coordinates'][1])) {
         return array('Lat' => $result['Placemark'][0]['Point']['coordinates'][1], 'Lng' => $result['Placemark'][0]['Point']['coordinates'][0]);
     }
     return array('Lat' => 0, 'Lng' => 0);
 }
Exemple #5
0
 public function liveSearchAction()
 {
     $this->noViewRenderer();
     $request = $this->getRequest();
     $type = $request->getQuery('filter');
     $json = array();
     $tags = Model_Tags::getTags(array('start' => 0, 'limit' => 100, 'filter_name' => $request->getQuery('term')));
     if ($tags) {
         $cache = array();
         foreach ($tags as $tag) {
             if (!isset($cache[$tag['name']])) {
                 $json[] = array('id' => $tag['id'], 'label' => $tag['name'], 'value' => $tag['name']);
                 $cache[$tag['name']] = true;
             }
         }
     }
     $response = $this->getResponse();
     $response->addHeader('Cache-Control: no-cache, must-revalidate');
     $response->addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     $response->addHeader('Content-type: application/json');
     echo JO_Json::encode($json);
 }
Exemple #6
0
 public function indexAction()
 {
     $request = $this->getRequest();
     $this->view->base_url = $request->getBaseUrl();
     #LINKS FOR HEAD PARTS IN BOX
     $this->view->finance_href = $request->getModule() . '/reports/';
     $this->view->sales_href = $request->getModule() . '/orders/';
     $this->view->users_href = $request->getModule() . '/users/';
     $this->view->approval_href = $request->getModule() . '/queueitems/';
     $this->view->queue_href = $request->getModule() . '/queueupdateditems/';
     $this->view->contacts_href = $request->getModule() . '/contacts/';
     $this->view->gainpayingup_href = $request->getModule() . '/gainpayingup/';
     $this->view->tags_href = $request->getModule() . '/tags/?filter_visible=false';
     #LOAD ORDERS COUNT
     $this->view->total = Model_Orders::getSalesStatus();
     if ($this->view->total) {
         $this->view->total['total_f'] = WM_Currency::format($this->view->total['total']);
     }
     $ref = Model_Orders::getSalesStatus(" AND `datetime` > '" . date('Y-m') . "-01 00:00:00' ", 'referal');
     $sales = Model_Orders::getSalesStatus(" AND `datetime` > '" . date('Y-m') . "-01 00:00:00' ");
     if ($sales) {
         if ($ref) {
             $sales['referal'] = $ref['receive'];
         } else {
             $sales['referal'] = 0;
         }
         $sales['win'] = floatval($sales['total']) - floatval($sales['receive']) - floatval($sales['referal']);
         $sales['total_f'] = WM_Currency::format($sales['total']);
         $sales['receive_f'] = WM_Currency::format($sales['receive']);
         $sales['referal_f'] = WM_Currency::format($sales['referal']);
         $sales['win_f'] = WM_Currency::format($sales['win']);
     }
     $this->view->sales = $sales;
     unset($ref);
     $ref = Model_Orders::getSalesStatus("", 'referal');
     $sales = Model_Orders::getSalesStatus("");
     if ($sales) {
         if ($ref) {
             $sales['referal'] = $ref['receive'];
         } else {
             $sales['referal'] = 0;
         }
         $sales['win'] = floatval($sales['total']) - floatval($sales['receive']) - floatval($sales['referal']);
         $sales['total_f'] = WM_Currency::format($sales['total']);
         $sales['receive_f'] = WM_Currency::format($sales['receive']);
         $sales['referal_f'] = WM_Currency::format($sales['referal']);
         $sales['win_f'] = WM_Currency::format($sales['win']);
     }
     $this->view->sales2 = $sales;
     unset($ref);
     #LOAD USERS COUNT
     $this->view->users = array();
     $this->view->users['month'] = Model_Users::getUsersCount(" `register_datetime` > '" . date('Y-m') . "-01 00:00:00' AND `status` = 'activate' ");
     $this->view->users['total'] = Model_Users::getUsersCount(" `status` = 'activate' ");
     $this->view->topAuthors = array();
     $topAuthors = Model_Users::getAll(0, 5, " `status` = 'activate' ", "`sales` DESC");
     if ($topAuthors) {
         $percentsClass = new Model_Percents();
         foreach ($topAuthors as $user) {
             $user['deposit'] = WM_Currency::format($user['deposit']);
             $user['earning'] = WM_Currency::format($user['earning']);
             $user['total'] = WM_Currency::format($user['total']);
             $user['sold'] = WM_Currency::format($user['sold']);
             $user['referal_money'] = WM_Currency::format($user['referal_money']);
             $comision = $percentsClass->getPercentRow($user['user_id']);
             $user['commission'] = round($comision['percent']);
             $user['sum'] = Model_Balance::getTotalUserBalanceByType($user['user_id']);
             $user['web_profit'] = WM_Currency::format($user['web_profit']);
             $user['web_profit2'] = WM_Currency::format($user['web_profit2']);
             $user['has_referral_sum'] = $user['referral_sum'];
             $user['referral_sum'] = WM_Currency::format($user['referral_sum']);
             $user['edit_href'] = $request->getModule() . '/users/edite/?id=' . $user['user_id'];
             $user['balance_href'] = $request->getModule() . '/users/balance/?id=' . $user['user_id'];
             $this->view->topAuthors[] = $user;
         }
     }
     #LOAD WITHDRAW
     $this->view->withdraw = array();
     $this->view->withdraw['no'] = Model_Deposit::getWithdrawCount(" `paid` = 'false' AND `datetime` > '" . date('Y-m') . "-01 00:00:00' ");
     if ($this->view->withdraw['no']) {
         $this->view->withdraw['no']['total_f'] = WM_Currency::format($this->view->withdraw['no']['total']);
     }
     $this->view->withdraw['paid'] = Model_Deposit::getWithdrawCount(" `paid` = 'true' AND `paid_datetime` > '" . date('Y-m') . "-01 00:00:00' ");
     if ($this->view->withdraw['paid']) {
         $this->view->withdraw['paid']['total_f'] = WM_Currency::format($this->view->withdraw['paid']['total']);
     }
     #LOAD THEMES
     $this->view->items = Model_Items::getItems(array('filter_status' => 'queue', 'start' => 0, 'limit' => 5));
     $this->view->updated_items = Model_Items::getItems(array('filter_update' => true, 'start' => 0, 'limit' => 5));
     #LOAD LAST REQUEST
     $this->view->contacts = array();
     $contacts = Model_Contacts::getContacts(array('filter_answer_datetime' => '0000-00-00', 'start' => 0, 'limit' => 5));
     if ($contacts) {
         foreach ($contacts as $contact) {
             $data = new JO_Date($contact['datetime'], 'dd MM yy');
             $contact['datetime'] = $data->toString();
             $contact['has_response'] = $contact['answer_datetime'] != '0000-00-00 00:00:00';
             if ($contact['answer_datetime'] != '0000-00-00 00:00:00') {
                 $data = new JO_Date($contact['answer_datetime'], 'dd MM yy');
                 $contact['answer_datetime'] = $data->toString();
             } else {
                 $contact['answer_datetime'] = '';
             }
             $this->view->contacts[] = $contact;
         }
     }
     #Withdrawals
     $this->view->withdraws = array();
     $withdraws = Model_Users::getWithdraws(array('start' => 0, 'limit' => 5));
     if ($withdraws) {
         foreach ($withdraws as $withdraw) {
             $withdraw['earning'] = WM_Currency::format($withdraw['earning']);
             $date = new JO_Date($withdraw['datetime'], 'dd MM yy');
             $withdraw['datetime'] = $date->toString();
             if ($withdraw['paid'] == 'true') {
                 $date = new JO_Date($withdraw['paid_datetime'], 'dd MM yy');
                 $withdraw['paid_datetime'] = $date->toString();
             } else {
                 $withdraw['paid_datetime'] = '';
             }
             $withdraw['amount'] = WM_Currency::format($withdraw['amount']);
             $this->view->withdraws[] = $withdraw;
         }
     }
     #TAGS NO ACTIVE
     $this->view->tags = Model_Tags::getTags(array('filter_visible' => 'false', 'start' => 0, 'limit' => 20));
     #DRAW GRAPHCS
     $referal_sum = Model_Orders::getSalesStatusByDay(" AND `datetime` > '" . date('Y-m') . "-01 00:00:00' ", 'referal');
     $sales_sum = Model_Orders::getSalesStatusByDay(" AND `datetime` > '" . date('Y-m') . "-01 00:00:00' ");
     $referal_money = array();
     $sales_money = array();
     $user_money = array();
     $win_money = array();
     $sales_num = array();
     $referal_num = array();
     $days = array();
     //		for($i=1; $i<= date('t'); $i++) {
     //			if(isset($referal_sum[date("Y-m-") . sprintf('%02d', $i)])) {
     //				$referal_money[] = number_format($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'], 2, '.', '');
     //			} else {
     //				$referal_money[] = 0;
     //			}
     //			if(isset($sales_sum[date("Y-m-") . sprintf('%02d', $i)])) {
     //				$sales_money[] = number_format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total'], 2, '.', '');
     //				$user_money[] = number_format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'], 2, '.', '');
     //				if(isset($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'])) {
     //					$sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'] = $referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'];
     //				}
     //				if(!isset($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'])) {
     //					$sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'] = 0;
     //				}
     //				$sales_num[] = $sales_sum[date("Y-m-") . sprintf('%02d', $i)]['num'];
     //				$win_money[] = number_format( floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total']) - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']) - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal']), 2, '.', '');
     //			} else {
     //				$sales_money[] = 0;
     //				$user_money[] = 0;
     //				$win_money[] = 0;
     //				$sales_num[] = 0;
     //			}
     //			$days[] = $i;
     //		}
     for ($i = 1; $i <= date('t'); $i++) {
         if (isset($referal_sum[date("Y-m-") . sprintf('%02d', $i)])) {
             $referal_money[] = array(WM_Currency::format($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']), (double) WM_Currency::format($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'], '', '', false));
         } else {
             $referal_money[] = array(WM_Currency::format(0), 0);
         }
         if (isset($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['num'])) {
             $referal_num[] = array($i, $referal_sum[date("Y-m-") . sprintf('%02d', $i)]['num']);
         } else {
             $referal_num[] = array($i, 0);
         }
         if (isset($sales_sum[date("Y-m-") . sprintf('%02d', $i)])) {
             $sales_money[] = array(WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total']), (double) WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total'], '', '', false));
             $user_money[] = array(WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']), (double) WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'], '', '', false));
             if (isset($referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'])) {
                 $sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'] = $referal_sum[date("Y-m-") . sprintf('%02d', $i)]['receive'];
             }
             if (!isset($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'])) {
                 $sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'] = 0;
             }
             $sales_num[] = array($i, $sales_sum[date("Y-m-") . sprintf('%02d', $i)]['num']);
             $win_money[] = array(WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total'] - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']) - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal'])), (double) WM_Currency::format($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['total'] - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['receive']) - floatval($sales_sum[date("Y-m-") . sprintf('%02d', $i)]['referal']), '', '', false));
         } else {
             $sales_money[] = array(WM_Currency::format(0), 0);
             $user_money[] = array(WM_Currency::format(0), 0);
             $win_money[] = array(WM_Currency::format(0), 0);
             $sales_num[] = array($i, 0);
         }
         $days[] = $i;
     }
     $new_array = array();
     $new_array[] = array('name' => $this->translate('Total'), 'data' => $sales_money);
     $new_array[] = array('name' => $this->translate('User\'s profit'), 'data' => $user_money);
     $new_array[] = array('name' => $this->translate('Net total'), 'data' => $win_money);
     $new_array[] = array('name' => $this->translate('Referent'), 'data' => $referal_money);
     $new_array2 = array();
     $new_array2[] = array('name' => $this->translate('Referent'), 'data' => $referal_num);
     $new_array2[] = array('name' => $this->translate('Sales'), 'data' => $sales_num);
     $this->view->finance_array = JO_Json::encode($new_array);
     $this->view->sales_array = JO_Json::encode($new_array2);
     $this->view->days = JO_Json::encode($days);
     $this->view->currency = WM_Currency::getCurrency();
 }
Exemple #7
0
 public function uploadAction()
 {
     $json = array();
     $directoryp = $this->getRequest()->getPost('directory');
     if ($directoryp !== null) {
         $file = $this->getRequest()->getFile('image');
         if ($file !== null && $file['tmp_name']) {
             if (strlen(utf8_decode($file['name'])) < 3 || strlen(utf8_decode($file['name'])) > 255) {
                 $json['error'] = $this->translate('The name must be from 3 to 255 characters');
             }
             $directory = rtrim($this->upload_folder . str_replace('../', '', $directoryp), '/');
             if (!is_dir($directory)) {
                 $json['error'] = $this->translate('Directory not found');
             }
             if ($file['size'] > 2097152000000.0) {
                 $json['error'] = $this->translate('The size must be less than') . ' ' . $this->format_bytes(2097152000000.0);
             }
             //				$allowed = array(
             //					'image/jpeg',
             //					'image/pjpeg',
             //					'image/png',
             //					'image/x-png',
             //					'image/gif'
             //				);
             //
             //				if (!in_array($file['type'], $allowed)) {
             //					$json['error'] = 'Файлът не е валидна снимка';
             //				}
             $allowed = array('.jpg', '.jpeg', '.gif', '.png', '.doc', '.docx', '.rtf', '.txt', '.pdf', '.flv', '.mp4');
             if (!in_array(strtolower(strrchr($file['name'], '.')), $allowed)) {
                 $json['error'] = $this->translate('Extensions are permitted:') . ' ' . implode($allowed);
             }
             if ($file['error'] != UPLOAD_ERR_OK) {
                 $json['error'] = 'error_upload_' . $file['error'];
             }
         } else {
             $json['error'] = $this->translate('Not selected a file to upload');
         }
     } else {
         $json['error'] = $this->translate('Not selected folder');
     }
     $file_name = self::rename_if_exists($directory . '/', basename($file['name']));
     if (@move_uploaded_file($file['tmp_name'], $directory . '/' . $file_name)) {
         $json['success'] = $this->translate('Upload is successful');
         if ($file_name != basename($file['name'])) {
             $json['success'] .= "\n" . $this->translate('The file name was changed to:') . " " . $file_name;
         }
     } else {
         $json['error'] = $this->translate('Upload failed');
     }
     $response = $this->getResponse();
     $response->addHeader('Cache-Control: no-cache, must-revalidate');
     $response->addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     //    	$response->addHeader('Content-type: application/json');
     $this->setInvokeArg('noViewRenderer', true);
     echo JO_Json::encode($json);
 }
Exemple #8
0
 public function usertypesAction()
 {
     //echo"entrando";
     $this->noViewRenderer(true);
     $request = $this->getRequest();
     $response = $this->getResponse();
     $page = (int) $request->getRequest('page');
     if ($page < 1) {
         $page = 1;
     }
     $callback = $request->getRequest('callback');
     if (!preg_match('/^([a-z0-9_.]{1,})$/', $callback)) {
         $callback = false;
     }
     $return = array();
     //////////// User Type ////////////
     $user_tipos = array();
     $user_types = Model_Users::getUserType(array('filter_status' => 1));
     foreach ($user_types as $user_type) {
         $user_type['subuser_types'] = Model_Users::getSubUserType($user_type['user_type_id']);
         $user_tipos[] = $user_type;
     }
     $return = array($user_tipos);
     if ($callback) {
         $return = $callback . '(' . JO_Json::encode($return) . ')';
     } else {
         $response->addHeader('Cache-Control: no-cache, must-revalidate');
         $response->addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
         $response->addHeader('Content-type: application/json; charset=utf-8');
         $return = JO_Json::encode($return);
     }
     $response->appendBody($return);
 }
 public function instagram_connectAction()
 {
     $request = $this->getRequest();
     if (!JO_Session::get('user[user_id]')) {
         if (!$request->isXmlHttpRequest()) {
             $this->redirect(WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=settings'));
         }
         exit('[]');
     }
     if ($request->getQuery('state') && $request->getQuery('state') == JO_Session::get('state')) {
         $state = JO_Session::get('state');
     } else {
         $state = md5(uniqid(rand(), TRUE));
         JO_Session::set('state', $state);
     }
     $config = array('client_id' => JO_Registry::get('oauth_in_key'), 'client_secret' => JO_Registry::get('oauth_in_secret'), 'grant_type' => 'authorization_code', 'redirect_uri' => WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=instagram&next=' . urlencode(WM_Router::create($request->getBaseUrl() . '?controller=settings&action=instagram_connect&state=' . $state))));
     $instagram = new WM_Instagram($config);
     $InstagramAccessToken = $instagram->getAccessToken();
     $user_data = JO_Json::decode($instagram->getUser(), true);
     if (isset($user_data['meta']['code']) && $user_data['meta']['code'] == 200) {
         JO_Session::set('InstagramAccessToken', $InstagramAccessToken);
     } elseif ($InstagramAccessToken) {
         JO_Session::set('InstagramAccessToken', $InstagramAccessToken);
         $instagram->setAccessToken($InstagramAccessToken);
     } elseif (JO_Session::get('InstagramAccessToken')) {
         $instagram->setAccessToken(JO_Session::get('InstagramAccessToken'));
     } elseif (JO_Session::get('user[instagram_token]')) {
         JO_Session::set('InstagramAccessToken', JO_Session::get('user[instagram_token]'));
         $instagram->setAccessToken(JO_Session::get('user[instagram_token]'));
     }
     if (!isset($user_data['meta']['code']) || $user_data['meta']['code'] != 200) {
         $user_data = JO_Json::decode($instagram->getUser(), true);
     }
     if ($request->getQuery('state') && $request->getQuery('state') == JO_Session::get('state') && isset($user_data['meta']['code']) && $user_data['meta']['code'] == 200) {
         JO_Session::clear('state');
         Model_Users::edit2(JO_Session::get('user[user_id]'), array('instagram_connect' => '1', 'instagram_profile_id' => $user_data['data']['id'], 'instagram_token' => (string) JO_Session::get('InstagramAccessToken')));
         $this->redirect(WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=settings'));
         exit;
     }
     if ($request->getPost('instagram_connect') == 'on') {
         if (isset($user_data['meta']['code']) && $user_data['meta']['code'] == 200) {
             Model_Users::edit2(JO_Session::get('user[user_id]'), array('instagram_connect' => '1', 'instagram_profile_id' => $user_data['data']['id'], 'instagram_token' => (string) JO_Session::get('InstagramAccessToken')));
         } else {
             JO_Session::set('InstagramAccessToken', false);
             JO_Session::set('user[instagram_token]', array_merge((array) JO_Session::get('user'), array('instagram_token' => null)));
             $this->view->login = WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=instagram&next=' . urlencode(WM_Router::create($request->getBaseUrl() . '?controller=settings&action=instagram_connect&state=' . $state)));
         }
     } else {
         Model_Users::edit2(JO_Session::get('user[user_id]'), array('instagram_connect' => '0', 'instagram_profile_id' => '0', 'instagram_token' => ''));
     }
     if (!$this->view->login) {
         $ud = Model_Users::getUser(JO_Session::get('user[user_id]'), true);
         if ($ud) {
             $this->view->connected = $ud['instagram_connect'] ? 'on' : 'off';
         } else {
             JO_Session::set('InstagramAccessToken', false);
             JO_Session::set('user[instagram_token]', array_merge((array) JO_Session::get('user'), array('instagram_token' => null)));
             $this->view->connected = 'off';
         }
     }
     if (!$request->isXmlHttpRequest()) {
         $this->redirect(WM_Router::create($this->getRequest()->getBaseUrl() . '?controller=settings'));
         exit;
     }
     echo $this->renderScript('json');
 }
Exemple #10
0
 /**
  * Proccess client request and output json
  *
  * @return void
  **/
 public function run()
 {
     if (!function_exists('json_encode')) {
         exit('{"error":"PHP JSON module not installed"}');
     }
     if (empty($this->_options['root']) || !is_dir($this->_options['root'])) {
         exit(JO_Json::encode(array('error' => 'Invalid backend configuration')));
     }
     if (!$this->_isAllowed($this->_options['root'], 'read')) {
         exit(JO_Json::encode(array('error' => 'Access denied')));
     }
     $cmd = '';
     if (!empty($_POST['cmd'])) {
         $cmd = trim($_POST['cmd']);
     } elseif (!empty($_GET['cmd'])) {
         $cmd = trim($_GET['cmd']);
     }
     if (!$cmd && $_SERVER["REQUEST_METHOD"] == 'POST') {
         header("Content-Type: text/html");
         $this->_result['error'] = 'Data exceeds the maximum allowed size';
         exit(JO_Json::encode($this->_result));
     }
     if ($cmd && (empty($this->_commands[$cmd]) || !method_exists($this, $this->_commands[$cmd]))) {
         exit(JO_Json::encode(array('error' => 'Unknown command')));
     }
     if (isset($_GET['init'])) {
         $ts = $this->_utime();
         $this->_result['disabled'] = array_values($this->_options['disabled']);
         $this->_result['params'] = array('dotFiles' => $this->_options['dotFiles'], 'uplMaxSize' => ini_get('upload_max_filesize'), 'archives' => array(), 'extract' => array(), 'url' => $this->_options['fileURL'] ? $this->_options['URL'] : '');
         if (isset($this->_commands['archive']) || isset($this->_commands['extract'])) {
             $this->_checkArchivers();
             if (isset($this->_commands['archive'])) {
                 $this->_result['params']['archives'] = $this->_options['archiveMimes'];
             }
             if (isset($this->_commands['extract']) && isset($this->_options['archivers']['extract'])) {
                 $this->_result['params']['extract'] = array_keys($this->_options['archivers']['extract']);
             }
         }
         // clean thumbnails dir
         if ($this->_options['tmbDir']) {
             srand((double) microtime() * 1000000);
             if (rand(1, 200) <= $this->_options['tmbCleanProb']) {
                 $ts2 = $this->_utime();
                 $ls = scandir($this->_options['tmbDir']);
                 for ($i = 0, $s = count($ls); $i < $s; $i++) {
                     if ('.' != $ls[$i] && '..' != $ls[$i]) {
                         @unlink($this->_options['tmbDir'] . DIRECTORY_SEPARATOR . $ls[$i]);
                     }
                 }
             }
         }
     }
     if ($this->_options['debug']) {
         $this->_result['debug'] = array('time' => $this->_utime() - $this->_time, 'mimeDetect' => $this->_options['mimeDetect'], 'imgLib' => $this->_options['imgLib']);
         if ($this->_options['dirSize']) {
             $this->_result['debug']['dirSize'] = true;
             $this->_result['debug']['du'] = @$this->_options['du'];
         }
     }
     if ($cmd) {
         $this->{$this->_commands[$cmd]}();
     } else {
         $this->_open();
     }
     header("Content-Type: " . ($cmd == 'upload' ? 'text/html' : 'application/json'));
     header("Connection: close");
     echo JO_Json::encode($this->_result);
     if (!empty($this->_options['logger']) && in_array($cmd, $this->_loggedCommands)) {
         $this->_options['logger']->log($cmd, empty($this->_result['error']), $this->_logContext, !empty($this->_result['error']) ? $this->_result['error'] : '', !empty($this->_result['errorData']) ? $this->_result['errorData'] : array());
     }
     exit;
 }
 public function urlinfoAction()
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $array['url'] = $request->getQuery('url');
     $array['status'] = 'success';
     $array['pinnable'] = 'true';
     $this->noViewRenderer(true);
     $response->addHeader('Cache-Control: no-cache, must-revalidate');
     $response->addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     if ($request->getQuery('callback')) {
         unset($array['status']);
         $response->addHeader('Content-type: application/javascript');
         echo $request->getQuery('callback') . '(' . JO_Json::encode($array) . ')';
     } else {
         $response->addHeader('Content-type: application/json');
         echo JO_Json::encode($array);
     }
 }
Exemple #12
0
 public function liveSearchAction()
 {
     $this->noViewRenderer();
     $request = $this->getRequest();
     $type = $request->getQuery('filter');
     $json = array();
     switch ($type) {
         case 'item':
             $items = Model_Items::getItems(array('start' => 0, 'limit' => 100, 'filter_name' => $request->getQuery('term'), 'filter_status' => 'active'));
             if ($items) {
                 $cache = array();
                 foreach ($items as $item) {
                     if (!isset($cache[$item['name']])) {
                         $json[] = array('id' => $item['id'], 'label' => $item['name'], 'value' => $item['name']);
                         $cache[$item['name']] = true;
                     }
                 }
             }
             break;
         case 'user':
             $users = Model_Users::getUsers(array('start' => 0, 'limit' => 100, 'filter_username' => $request->getQuery('term')));
             if ($users) {
                 $cache = array();
                 foreach ($users as $user) {
                     if (!isset($cache[$user['username']])) {
                         $json[] = array('id' => $user['user_id'], 'label' => $user['username'], 'value' => $user['username']);
                         $cache[$user['username']] = true;
                     }
                 }
             }
             break;
         case 'tags':
             $tags = Model_Tags::getTags(array('start' => 0, 'limit' => 100, 'filter_name' => $request->getQuery('term')));
             if ($tags) {
                 $cache = array();
                 foreach ($tags as $tag) {
                     if (!isset($cache[$tag['name']])) {
                         $json[] = array('id' => $tag['id'], 'label' => $tag['name'], 'value' => $tag['name']);
                         $cache[$tag['name']] = true;
                     }
                 }
             }
             break;
     }
     $response = $this->getResponse();
     $response->addHeader('Cache-Control: no-cache, must-revalidate');
     $response->addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     $response->addHeader('Content-type: application/json');
     echo JO_Json::encode($json);
 }
Exemple #13
0
 public function __construct($view)
 {
     $this->data = JO_Json::encode($view->getAll());
 }
Exemple #14
0
 public function upload_mobileAction()
 {
     $this->noViewRenderer(true);
     $this->noLayout(true);
     $request = $this->getRequest();
     if (JO_Registry::get('isMobile') && JO_Session::get('upload_from_file') && file_exists(BASE_PATH . JO_Session::get('upload_from_file'))) {
         $image = "<img src='" . JO_Session::get('upload_from_file') . "'>";
         $boards = Model_Boards::getBoards(array('filter_user_id' => JO_Session::get('user[user_id]'), 'order' => 'boards.sort_order', 'sort' => 'ASC', 'friendly' => JO_Session::get('user[user_id]')));
         $data['boards'] = $boards;
         $data['image'] = $image;
         $data['phrases'] = array('create_board' => $this->translate("Create New Board"), 'upload_button' => $this->translate("Upload"), 'select_board' => $this->translate("Select Board"), 'textarea_validation' => $this->translate("Please add a description"), 'board_validation' => $this->translate("Please add a board title"), 'notEmptyMsg' => $this->translate("Please choose board"));
         echo JO_Json::encode((object) $data);
     }
 }
Exemple #15
0
 public function create_mobileAction()
 {
     $this->noLayout(true);
     $this->noViewRenderer(true);
     $request = $this->getRequest();
     if ($request->isXmlHttpRequest()) {
         if (trim($request->getPost('title'))) {
             $data = Model_Boards::createBoard(array('title' => trim($request->getPost('title'))));
             if ($data) {
                 echo JO_Json::encode($data);
             } else {
                 echo JO_Json::encode(array('error' => $this->translate("Oooops..! For some reason we couldn't create a new board")));
             }
         }
     }
 }
Exemple #16
0
 public function deleteCommentAction()
 {
     $request = $this->getRequest();
     $comment_id = $request->getRequest('comment_id');
     $comment_info = new Model_Pins_GetComment($comment_id);
     $response = array();
     if ($comment_info->count()) {
         $comment_info = $comment_info->data;
         $enable_delete = false;
         if (JO_Session::get('user[is_admin]')) {
             $enable_delete = true;
         } elseif (JO_Session::get('user[is_developer]')) {
             $enable_delete = true;
         } elseif (JO_Session::get('user[user_id]') == $comment_info['user_id']) {
             $enable_delete = true;
         } else {
             $pin_info = new Model_Pins_Pin($comment_info['pin_id']);
             if ($pin_info->count()) {
                 $pin_info = $pin_info->data;
                 if ($pin_info['user_user_id'] == JO_Session::get('user[user_id]')) {
                     $enable_delete = true;
                 }
             }
         }
         if ($enable_delete) {
             $deleted = new Model_Pins_DeleteComment($comment_id);
             if ($deleted->affected_rows) {
                 $response = array('ok' => true, 'total_comments' => (int) $pin_info['pin_comments'], 'stats' => $this->getPinStat($comment_info['pin_id']));
             } else {
                 $response['error'] = $this->translate('There was a problem with the record. Please try again!');
             }
         } else {
             $response['error'] = $this->translate('You do not have permission to delete this comment!');
         }
     } else {
         $response['error'] = $this->translate('There was a problem with the record. Please try again!');
     }
     $this->noViewRenderer(true);
     echo JO_Json::encode($response);
 }
Exemple #17
0
 public function responseJsonCallback($return)
 {
     $request = $this->getRequest();
     $response = $this->getResponse();
     $callback = $request->getRequest('callback');
     if (!preg_match('/^([a-z0-9_.]{1,})$/i', $callback)) {
         $callback = false;
     }
     if ($callback) {
         $return = $callback . '(' . JO_Json::encode($return) . ')';
     } else {
         $response->addHeader('Cache-Control: no-cache, must-revalidate');
         $response->addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
         $response->addHeader('Content-type: application/json');
         $return = JO_Json::encode($return);
     }
     $response->appendBody($return);
 }
Exemple #18
0
 private function setPopularCache($data)
 {
     $cache_live = (int) JO_Registry::get('config_cache_live');
     if (!$cache_live) {
         return;
     }
     $db = JO_Db::getDefaultAdapter();
     $db->delete('cache_popular', array('start_limit = ?' => $data['start_limit']));
     $db->insert('cache_popular', array('start_limit' => $data['start_limit'], 'date' => time() + $cache_live, 'data' => JO_Json::encode($data['pins'])));
 }
Exemple #19
0
 public function get($key)
 {
     $db = JO_Db::getDefaultAdapter();
     $query = $db->select()->from($this->getTable(), $this->getData())->where($this->getMd5Key() . ' = ?', md5($key));
     $result = $db->fetchOne($query);
     if ($result) {
         return JO_Json::decode($result, true);
     }
     return false;
 }
Exemple #20
0
 public function getUserDataAction()
 {
     $request = $this->getRequest();
     $this->noViewRenderer(true);
     $json = array();
     if ($request->getQuery('openId') && strlen($request->getQuery('openId')) == 32) {
         $referer = $request->getQuery('referer');
         $domain = $request->getQuery('domain');
         if (!$referer) {
             return;
         } elseif (!$domain) {
             return;
         } elseif ($referer == $domain) {
             return;
         } elseif (!self::allowledReferal($domain)) {
             return;
         }
         $result = Model_Extensions_Singlesignon::checkUser($referer, $domain, $request->getQuery('openId'));
         if ($result && $result['status'] == 'activate') {
             $json['username'] = $result['username'];
             $json['password'] = $result['password'];
             $json['email'] = $result['email'];
             $json['firstname'] = $result['firstname'];
             $json['lastname'] = $result['lastname'];
             if ($result['avatar'] && file_exists(BASE_PATH . '/uploads/' . $result['avatar'])) {
                 $json['avatar'] = $request->getBaseUrl() . '/uploads/' . $result['avatar'];
             } else {
                 $json['avatar'] = '';
             }
             if ($result['homeimage'] && file_exists(BASE_PATH . '/uploads/' . $result['homeimage'])) {
                 $json['homeimage'] = $request->getBaseUrl() . '/uploads/' . $result['homeimage'];
             } else {
                 $json['homeimage'] = '';
             }
             $json['firmname'] = $result['firmname'];
             $json['profile_title'] = $result['profile_title'];
             $json['profile_desc'] = $result['profile_desc'];
             $json['register_datetime'] = $result['register_datetime'];
         }
     }
     $this->getResponse()->appendBody(JO_Encrypt_Md5::encrypt(JO_Json::encode($json), $domain));
 }
 private function getMediaData($user_id, $timeout = 30, array $params)
 {
     $curl = new JO_Http();
     $curl->initialize(array('target' => 'https://api.instagram.com/v1/users/' . $user_id . '/media/recent', 'method' => 'GET', 'timeout' => $timeout, 'params' => $params));
     $curl->useCurl(true);
     $curl->execute();
     return JO_Json::decode($curl->result, true);
 }