/**
  * Recorre los datos y llena el excel
  * @param array $data
  * @param array $json_fields
  */
 public function setData($data, $json_fields = array())
 {
     if (count($data) > 0) {
         $j = 2;
         foreach ($data as $row) {
             $json_data = array();
             if (count($json_fields) > 0) {
                 foreach ($json_fields as $json) {
                     $json_data = array_merge(Zend_Json::decode($row[$json]), $json_data);
                 }
             }
             $i = 0;
             foreach ($this->_columnas as $columna => $valores) {
                 $ok = true;
                 if (isset($valir["permiso"]) && !$valir["permiso"]) {
                     $ok = false;
                 }
                 if ($ok) {
                     $this->_excel->setActiveSheetIndex(0)->setCellValueByColumnAndRow($i, $j, trim($this->_procesaValor($valores, $row, $json_data)));
                     $i++;
                 }
             }
             $j++;
         }
     }
 }
예제 #2
0
 /**
  * update to 5.1
  *  - move task status to key field config
  */
 public function update_0()
 {
     $tasksAppId = Tinebase_Application::getInstance()->getApplicationByName('Tasks')->getId();
     // remove status_id keys
     $this->_backend->dropForeignKey('tasks', 'tasks::status_id--tasks_status::id');
     $this->_backend->dropIndex('tasks', 'status_id');
     // need to replace all NULL values first
     $this->_db->update(SQL_TABLE_PREFIX . 'tasks', array('status_id' => 1), "`status_id` IS NULL");
     // alter status_id -> status
     $declaration = new Setup_Backend_Schema_Field_Xml('
         <field>
             <name>status</name>
             <type>text</type>
             <length>40</length>
             <default>NEEDS-ACTION</default>
             <notnull>true</notnull>
         </field>');
     $this->_backend->alterCol('tasks', $declaration, 'status_id');
     // get all current status datas and drop old status table
     $stmt = $this->_db->query("SELECT * FROM `" . SQL_TABLE_PREFIX . "tasks_status`");
     $statusDatas = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
     $this->_backend->dropTable('tasks_status', $tasksAppId);
     // update task table
     $statusMap = array();
     // oldId => newId
     foreach ($statusDatas as $statusData) {
         $statusMap[$statusData['id']] = $statusData['status_name'];
         $this->_db->update(SQL_TABLE_PREFIX . 'tasks', array('status' => $statusData['status_name']), "`status` = '{$statusData['id']}'");
     }
     // create status config
     $cb = new Tinebase_Backend_Sql(array('modelName' => 'Tinebase_Model_Config', 'tableName' => 'config'));
     $tasksStatusConfig = array('name' => Tasks_Config::TASK_STATUS, 'records' => array(array('id' => 'NEEDS-ACTION', 'value' => 'No response', 'is_open' => 1, 'icon' => 'images/oxygen/16x16/actions/mail-mark-unread-new.png', 'system' => true), array('id' => 'COMPLETED', 'value' => 'Completed', 'is_open' => 0, 'icon' => 'images/oxygen/16x16/actions/ok.png', 'system' => true), array('id' => 'CANCELLED', 'value' => 'Cancelled', 'is_open' => 0, 'icon' => 'images/oxygen/16x16/actions/dialog-cancel.png', 'system' => true), array('id' => 'IN-PROCESS', 'value' => 'In process', 'is_open' => 1, 'icon' => 'images/oxygen/16x16/actions/view-refresh.png', 'system' => true)));
     // add non system custom status
     foreach ($statusDatas as $statusData) {
         if (!in_array($statusData['status_name'], array('NEEDS-ACTION', 'COMPLETED', 'CANCELLED', 'IN-PROCESS'))) {
             $tasksStatusConfig['records'][] = array('id' => $statusData['status_name'], 'value' => $statusData['status_name'], 'is_open' => $statusData['status_is_open'], 'icon' => $statusData['status_icon']);
         }
     }
     $cb->create(new Tinebase_Model_Config(array('application_id' => $tasksAppId, 'name' => Tasks_Config::TASK_STATUS, 'value' => json_encode($tasksStatusConfig))));
     // update persistent filters
     $stmt = $this->_db->query("SELECT * FROM `" . SQL_TABLE_PREFIX . "filter` WHERE " . "`application_id` = '" . $tasksAppId . "' AND " . "`model` = 'Tasks_Model_TaskFilter'");
     $pfiltersDatas = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
     foreach ($pfiltersDatas as $pfilterData) {
         $filtersData = Zend_Json::decode($pfilterData['filters']);
         foreach ($filtersData as &$filterData) {
             if (array_key_exists('field', $filterData) && $filterData['field'] == 'status_id') {
                 $filterData['field'] = 'status';
                 $newStatusIds = array();
                 foreach ((array) $filterData['value'] as $oldStatusId) {
                     $newStatusIds[] = $statusMap[$oldStatusId];
                 }
                 $filterData['value'] = is_array($filterData['value']) ? $newStatusIds : $newStatusIds[0];
                 Tinebase_Core::getLogger()->ERR(print_r($filterData, TRUE));
             }
         }
         $this->_db->update(SQL_TABLE_PREFIX . 'filter', array('filters' => Zend_Json::encode($filtersData)), "`id` LIKE '{$pfilterData['id']}'");
     }
     $this->setTableVersion('tasks', '4');
     $this->setApplicationVersion('Tasks', '5.1');
 }
예제 #3
0
 /**
  * The default action - show the home page
  */
 public function studentAction()
 {
     $this->_helper->viewRenderer->setNoRender(false);
     $request = $this->getRequest();
     $department = $request->getParam('department_id');
     $degree = $request->getParam('degree_id');
     $batch = $request->getParam('batch');
     if (isset($degree) and isset($department) and isset($batch)) {
         $client = new Zend_Http_Client('http://' . CORE_SERVER . '/batch/getbatchstudent' . "?department_id={$department}" . "&degree_id={$degree}" . "&batch_id={$batch}");
         $client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
         $response = $client->request();
         if ($response->isError()) {
             $remoteErr = 'REMOTE ERROR: (' . $response->getStatus() . ') ' . $response->getHeader('Message');
             throw new Zend_Exception($remoteErr, Zend_Log::ERR);
         } else {
             $jsonContent = $response->getBody($response);
             $students = Zend_Json::decode($jsonContent);
             $this->_helper->logger($jsonContent);
             $this->view->assign('students', $students);
             $this->view->assign('department', $department);
             $this->view->assign('degree', $degree);
             $this->view->assign('batch', $batch);
         }
     }
 }
예제 #4
0
 /**
  * Get key value (otherwise default value)
  */
 function get($key, $defvalue = '')
 {
     $value = $defvalue;
     if (isset($this->valuemap[$key])) {
         $value = $this->valuemap[$key];
     }
     if ($value === '' && isset($this->defaultmap[$key])) {
         $value = $this->defaultmap[$key];
     }
     $isJSON = false;
     if (is_string($value)) {
         // NOTE: Zend_Json or json_decode gets confused with big-integers (when passed as string)
         // and convert them to ugly exponential format - to overcome this we are performin a pre-check
         if (strpos($value, "[") === 0 || strpos($value, "{") === 0) {
             $isJSON = true;
         }
     }
     if ($isJSON) {
         $oldValue = Zend_Json::$useBuiltinEncoderDecoder;
         Zend_Json::$useBuiltinEncoderDecoder = false;
         $decodeValue = Zend_Json::decode($value);
         if (isset($decodeValue)) {
             $value = $decodeValue;
         }
         Zend_Json::$useBuiltinEncoderDecoder = $oldValue;
     }
     //Handled for null because vtlib_purify returns empty string
     if (!empty($value)) {
         $value = vtlib_purify($value);
     }
     return $value;
 }
예제 #5
0
 /**
  * @param \Magento\Customer\Controller\Ajax\Login $subject
  * @param \Closure $proceed
  * @return $this
  * @throws \Zend_Json_Exception
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function aroundExecute(\Magento\Customer\Controller\Ajax\Login $subject, \Closure $proceed)
 {
     $captchaFormIdField = 'captcha_form_id';
     $captchaInputName = 'captcha_string';
     /** @var \Magento\Framework\App\RequestInterface $request */
     $request = $subject->getRequest();
     $loginParams = [];
     $content = $request->getContent();
     if ($content) {
         $loginParams = \Zend_Json::decode($content);
     }
     $username = isset($loginParams['username']) ? $loginParams['username'] : null;
     $captchaString = isset($loginParams[$captchaInputName]) ? $loginParams[$captchaInputName] : null;
     $loginFormId = isset($loginParams[$captchaFormIdField]) ? $loginParams[$captchaFormIdField] : null;
     foreach ($this->formIds as $formId) {
         $captchaModel = $this->helper->getCaptcha($formId);
         if ($captchaModel->isRequired($username) && !in_array($loginFormId, $this->formIds)) {
             $resultJson = $this->resultJsonFactory->create();
             return $resultJson->setData(['errors' => true, 'message' => __('Provided form does not exist')]);
         }
         if ($formId == $loginFormId) {
             $captchaModel->logAttempt($username);
             if (!$captchaModel->isCorrect($captchaString)) {
                 $this->sessionManager->setUsername($username);
                 /** @var \Magento\Framework\Controller\Result\Json $resultJson */
                 $resultJson = $this->resultJsonFactory->create();
                 return $resultJson->setData(['errors' => true, 'message' => __('Incorrect CAPTCHA')]);
             }
         }
     }
     return $proceed();
 }
예제 #6
0
 public function removeAction()
 {
     $customerGroupIds = Zend_Json::decode($this->_getParam('data'));
     $isValid = true;
     if (in_array(Axis_Account_Model_Customer_Group::GROUP_GUEST_ID, $customerGroupIds)) {
         $isValid = false;
         Axis::message()->addError(Axis::translate('admin')->__("Your can't delete default Guest group id: %s ", Axis_Account_Model_Customer_Group));
     }
     if (in_array(Axis_Account_Model_Customer_Group::GROUP_ALL_ID, $customerGroupIds)) {
         $isValid = false;
         Axis::message()->addError(Axis::translate('admin')->__("Your can't delete default All group id: %s ", Axis_Account_Model_Customer_Group::GROUP_ALL_ID));
     }
     if (true === in_array(Axis::config()->account->main->defaultCustomerGroup, $customerGroupIds)) {
         $isValid = false;
         Axis::message()->addError(Axis::translate('admin')->__("Your can't delete default customer group id: %s ", $id));
     }
     if (!sizeof($customerGroupIds)) {
         $isValid = false;
         Axis::message()->addError(Axis::translate('admin')->__('No data to delete'));
     }
     if ($isValid) {
         Axis::single('account/customer_group')->delete($this->db->quoteInto('id IN(?)', $customerGroupIds));
         Axis::message()->addSuccess(Axis::translate('admin')->__('Group was deleted successfully'));
     }
     $this->_helper->json->sendJson(array('success' => $isValid));
 }
예제 #7
0
 public function process(Vtiger_Request $request)
 {
     $viewer = $this->getViewer($request);
     $moduleName = $request->getModule();
     $qualifiedModuleName = $request->getModule(false);
     if (!$request->get("label") && !$request->get("block") || !$request->get("languages")) {
         //Make JSON response
         $response = new Vtiger_Response();
         $response->setError('error-param', getTranslatedString("LBL_ERROR_PARAM", $moduleName));
         $response->emit();
         exit;
     }
     $languages = trim($request->get("languages"));
     $a_languages = explode(",", $languages);
     $a_block = $request->get("block");
     //Repair bug with utf8 characters
     if (!is_array($a_block)) {
         $oldValue = Zend_Json::$useBuiltinEncoderDecoder;
         Zend_Json::$useBuiltinEncoderDecoder = true;
         $a_block = Zend_Json::decode($a_block);
         Zend_Json::$useBuiltinEncoderDecoder = $oldValue;
         foreach ($a_block as &$val) {
             $val = utf8_encode($val);
         }
     }
     $viewer->assign('MODULE', $moduleName);
     $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName);
     $viewer->assign('LIST_PARENT_TABS', $a_parent_tabs);
     $viewer->assign('LIST_MODULES', $a_modules);
     $viewer->assign('LIST_MANIFEST_TEMPLATES', $a_manifest_templates);
     $viewer->assign('LIST_DIR_TEMPLATES', $a_dir_templates);
     $viewer->assign('a_block', $a_block);
     $viewer->assign('a_languages', $a_languages);
     echo $viewer->view('EditBlockPopup.tpl', $qualifiedModuleName, true);
 }
예제 #8
0
 public function calculationSettingsChangeAction()
 {
     $this->getHelper('viewRenderer')->setNoRender();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post = $request->getPost();
         if (!isset($post['changeSet']) || empty($post['changeSet'])) {
             $this->ajaxException("Nieprawidłowa wartość parametrów");
             return;
         } else {
             $data = Zend_Json::decode($post['changeSet']);
             for ($i = 0; $i < $data['formsCount']; $i++) {
                 $form = $data[$i];
                 if (count($form['changes']) == 0) {
                     Logic_FormsTracker::invalidate(Zend_Session::getId() . '_' . $form['trackingName'], Zend_Auth::getInstance()->getIdentity()->id);
                 } else {
                     Logic_FormsTracker::store(Zend_Session::getId(), $form['trackingName'], $form['changes']);
                 }
             }
             echo Zend_Json::encode(array('result' => 'success', 'message' => 'ok'));
         }
     } else {
         $this->ajaxException("Bad request");
         return;
     }
 }
예제 #9
0
 public function removeAction()
 {
     $data = Zend_Json::decode($this->_getParam('data'));
     Axis::model('account/customer_valueSet')->delete($this->db->quoteInto('id IN (?)', $data));
     Axis::message()->addSuccess(Axis::translate('admin')->__('Group was deleted successfully'));
     return $this->_helper->json->sendSuccess();
 }
예제 #10
0
 public function removeAction()
 {
     $data = Zend_Json::decode($this->_getParam('data'));
     Axis::single('import/profile')->delete($data);
     Axis::message()->addSuccess(Axis::translate('admin')->__('Profile was deleted successfully'));
     return $this->_helper->json->sendSuccess();
 }
예제 #11
0
 /**     
  * @param   request data  tax rows information (if 'id'=0 this is a new row)
  * @see plugins/taxes/js/edit.js
  * @return 	json    json array information: success or failure
  */
 function updateJsonAction()
 {
     $dataJson = $this->_getParam('data', '[]');
     $data = Zend_Json::decode($dataJson);
     $iso = $this->_getParam('iso', RM_Environment::getInstance()->getLocale());
     $unitTaxesModel = new RM_UnitTaxes();
     $model = new RM_Taxes();
     foreach ($data as $row) {
         if (isset($row['name'])) {
             $row[$iso] = $row['name'];
             unset($row['name']);
         }
         $unitIDs = explode(',', $row['units']);
         unset($row['units']);
         if ($row['id'] == 0) {
             unset($row['id']);
             $taxID = $model->insert($row);
             $tax = $model->find($taxID)->current();
         } else {
             $tax = $model->find($row['id'])->current();
             if ($tax == null) {
                 continue;
             }
             foreach ($row as $key => $value) {
                 $tax->{$key} = $value;
             }
             $tax->save();
         }
         $unitTaxesModel->insertRows($tax, $unitIDs);
     }
     return array('data' => array('success' => true));
 }
예제 #12
0
 /**
  * Update setting action called through an ajax request
  */
 public function ajaxUpdateAction()
 {
     // Disable view & layout output
     $this->_disableDisplay();
     // Alwasy set response type to json
     $this->_response->setHeader('Content-Type', 'application/json', true);
     // Try to get the data from the request body
     try {
         $data = Zend_Json::decode($this->_request->getRawBody(), Zend_Json::TYPE_OBJECT);
     } catch (Zend_Json_Exception $exception) {
         $this->_response->setHttpResponseCode(500);
         $this->_response->setBody(Zend_Json::encode(array('status' => 'error', 'message' => 'data decoding failed')));
         return;
     }
     // Retrieve the setting
     $setting = Setting::getKey($data->settingKey, $data->component);
     if (null === $setting) {
         $this->_response->setHttpResponseCode(404);
         $this->_response->setBody(Zend_Json::encode(array('status' => 'error', 'message' => 'setting key/component pair not found')));
         return;
     }
     // Update the setting
     $setting->value = $data->value;
     $success = $setting->trySave();
     if (false === $success) {
         $this->_response->setHttpResponseCode(500);
         $this->_response->setBody(Zend_Json::encode(array('status' => 'error', 'message' => 'saving failed due to validation errors')));
         return;
     }
     // Return success response
     $this->_response->setHttpResponseCode(200);
     $this->_response->setBody(Zend_Json::encode(array('status' => 'success', 'message' => 'setting saved')));
 }
예제 #13
0
 public function saveAction()
 {
     $id = $this->_getParam("id");
     $table = new Formbuilder_Formbuilder();
     $name = $table->getName($id);
     $configuration = Zend_Json::decode($this->_getParam("configuration"));
     $values = Zend_Json::decode($this->_getParam("values"));
     if ($values["name"] != $name) {
         $values["name"] = $this->correctClassname($values["name"]);
         $table = new Formbuilder_Formbuilder();
         $table->rename($id, $values["name"]);
     }
     if (!is_dir(PIMCORE_PLUGINS_PATH . "/Zendformbuilder/data/")) {
         mkdir(PIMCORE_PLUGINS_PATH . "/Zendformbuilder/data/");
     }
     if (file_exists(PIMCORE_PLUGINS_PATH . "/Zendformbuilder/data/main_" . $id . ".json")) {
         unlink(PIMCORE_PLUGINS_PATH . "/Zendformbuilder/data/main_" . $id . ".json");
     }
     $settings = $values;
     $settings["mainDefinitions"] = $configuration;
     $config = new Zend_Config($settings, true);
     $writer = new Zend_Config_Writer_Json(array("config" => $config, "filename" => PIMCORE_PLUGINS_PATH . "/Zendformbuilder/data/main_" . $id . ".json"));
     $writer->write();
     $builder = new Formbuilder_Builder();
     $builder->setDatas($config->toArray());
     $builder->buildForm($id);
     $this->removeViewRenderer();
 }
예제 #14
0
 function updatePleiadesData($uri)
 {
     $output = false;
     $db = $this->startDB();
     $uri = $this->cleanPleiadesURI($uri);
     if ($uri != false) {
         $sql = "SELECT id FROM gap_gazuris WHERE uri = '{$uri}' LIMIT 1;";
         $result = $db->fetchAll($sql, 2);
         if ($result) {
             $jsonURI = $uri . "/json";
             @($jsonStringData = file_get_contents($jsonURI));
             if ($jsonStringData) {
                 @($jsonData = Zend_Json::decode($jsonStringData));
                 if (is_array($jsonData)) {
                     $where = "uri = '{$uri}' ";
                     $data = array();
                     $data["label"] = $jsonData["title"];
                     if ($jsonData["reprPoint"][1] != 0 && $jsonData["reprPoint"][0] != 0) {
                         $data["latitude"] = $jsonData["reprPoint"][1];
                         $data["longitude"] = $jsonData["reprPoint"][0];
                     }
                     $db->update('gap_gazuris', $data, $where);
                     $output = true;
                 } else {
                     $this->noteError("Pleiades not responding with usable data for '{$uri}'.");
                 }
             } else {
                 $this->noteError("Pleiades not recognizing '{$uri}' as a valid URI.");
             }
         }
     } else {
         $this->noteError("Not a valid Pleiades Place URI");
     }
     return $output;
 }
예제 #15
0
 /**
  * Perform an API request to Amazon
  *
  * @param string $path
  *    REST path e.g. user/profile
  * @param array $postParams
  *    POST paramaters
  * @return result
  */
 public function request($path, array $postParams = array())
 {
     $sandbox = Mage::getStoreConfig('payment/amazon_payments/sandbox') ? 'sandbox.' : '';
     $client = new Zend_Http_Client();
     $client->setUri("https://api.{$sandbox}amazon.com/{$path}");
     $client->setConfig($this->http_client_config);
     $client->setMethod($postParams ? 'POST' : 'GET');
     foreach ($postParams as $key => $value) {
         $client->setParameterPost($key, $value);
     }
     try {
         $response = $client->request();
     } catch (Zend_Http_Client_Adapter_Exception $e) {
         Mage::logException($e);
         return;
     }
     $data = $response->getBody();
     try {
         $data = Zend_Json::decode($data, true);
     } catch (Exception $e) {
         Mage::logException($e);
     }
     if (empty($data)) {
         return false;
     } else {
         return $data;
     }
 }
예제 #16
0
 protected function setValuesToDocument(Document\Link $link)
 {
     // data
     if ($this->getParam("data")) {
         $data = \Zend_Json::decode($this->getParam("data"));
         if (!empty($data["path"])) {
             if ($document = Document::getByPath($data["path"])) {
                 $data["linktype"] = "internal";
                 $data["internalType"] = "document";
                 $data["internal"] = $document->getId();
             } elseif ($asset = Asset::getByPath($data["path"])) {
                 $data["linktype"] = "internal";
                 $data["internalType"] = "asset";
                 $data["internal"] = $asset->getId();
             } else {
                 $data["linktype"] = "direct";
                 $data["direct"] = $data["path"];
             }
         } else {
             // clear content of link
             $data["linktype"] = "internal";
             $data["direct"] = "";
             $data["internalType"] = null;
             $data["internal"] = null;
         }
         unset($data["path"]);
         $link->setValues($data);
     }
     $this->addPropertiesToDocument($link);
 }
 public function removeAction()
 {
     $data = Zend_Json::decode($this->_getParam('data'));
     Axis::single('catalog/product_option')->delete($this->db->quoteInto('id IN (?)', $data));
     Axis::message()->addSuccess(Axis::translate('catalog')->__('Option was deleted successfully'));
     return $this->_helper->json->sendSuccess();
 }
예제 #18
0
 function process(Mobile_API_Request $request)
 {
     $values = Zend_Json::decode($request->get('values'));
     $relatedTo = $values['related_to'];
     $commentContent = $values['commentcontent'];
     $user = $this->getActiveUser();
     $targetModule = '';
     if (!empty($relatedTo) && Mobile_WS_Utils::detectModulenameFromRecordId($relatedTo) == 'HelpDesk') {
         $targetModule = 'HelpDesk';
     } else {
         $targetModule = 'ModComments';
     }
     $response = false;
     if ($targetModule == 'HelpDesk') {
         $response = $this->saveCommentToHelpDesk($commentContent, $relatedTo, $user);
     } else {
         if (vtlib_isModuleActive($targetModule)) {
             $request->set('module', $targetModule);
             $values['assigned_user_id'] = sprintf('%sx%s', Mobile_WS_Utils::getEntityModuleWSId('Users'), $user->id);
             $request->set('values', Zend_Json::encode($values));
             $response = parent::process($request);
         }
     }
     return $response;
 }
예제 #19
0
 public function postAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         $customer = new Customer_Model_Customer();
         try {
             if (!Zend_Validate::is($data['email'], 'EmailAddress')) {
                 throw new Exception($this->_('Please enter a valid email address'));
             }
             $dummy = new Customer_Model_Customer();
             $dummy->find(array('email' => $data['email'], "app_id" => $this->getApplication()->getId()));
             if ($dummy->getId()) {
                 throw new Exception($this->_('We are sorry but this address is already used.'));
             }
             if (empty($data['show_in_social_gaming'])) {
                 $data['show_in_social_gaming'] = 0;
             }
             if (empty($data['password'])) {
                 throw new Exception($this->_('Please enter a password'));
             }
             $customer->setData($data)->setAppId($this->getApplication()->getId())->setPassword($data['password'])->save();
             $this->getSession()->setCustomer($customer);
             $this->_sendNewAccountEmail($customer, $data['password']);
             $html = array('success' => 1, 'customer_id' => $customer->getId(), 'can_access_locked_features' => $customer->canAccessLockedFeatures());
         } catch (Exception $e) {
             $html = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->_sendHtml($html);
     }
 }
예제 #20
0
 public function __construct($response)
 {
     if (!$response) {
         throw new Exception("Response cannot be null");
     }
     $this->_response = Zend_Json::decode($response->getBody());
 }
예제 #21
0
 /**
  * Show extended information on a user
  *
  * @param  int|string $id User ID or name
  * @throws Zend_Http_Client_Exception if HTTP request fails or times out
  * @return stdClass
  */
 public function userShow($id)
 {
     $this->_init();
     $path = '1.1/users/show.json';
     $response = $this->_get($path, array('id' => $id));
     return Zend_Json::decode($response->getBody(), Zend_Json::TYPE_OBJECT);
 }
예제 #22
0
 /**
  * Test encoding and decoding in a single step
  * @param array $values   array of values to test against encode/decode 
  */
 protected function _testJson($values)
 {
     foreach ($values as $value) {
         $encoded = Zend_Json::encode($value);
         $this->assertEquals($value, Zend_Json::decode($encoded));
     }
 }
예제 #23
0
 public function getWorkflowQuery($workflow)
 {
     $conditions = Zend_Json::decode(decode_html($workflow->test));
     $moduleName = $workflow->moduleName;
     $queryGenerator = new QueryGenerator($moduleName, $this->user);
     $queryGenerator->setFields(array('id'));
     $this->addWorkflowConditionsToQueryGenerator($queryGenerator, $conditions);
     if ($moduleName == 'Calendar' || $moduleName == 'Events') {
         if ($conditions) {
             $queryGenerator->addConditionGlue('AND');
         }
         // We should only get the records related to proper activity type
         if ($moduleName == 'Calendar') {
             $queryGenerator->addCondition('activitytype', 'Emails', 'n');
             $queryGenerator->addCondition('activitytype', 'Task', 'e', 'AND');
         } else {
             if ($moduleName == "Events") {
                 $queryGenerator->addCondition('activitytype', 'Emails', 'n');
                 $queryGenerator->addCondition('activitytype', 'Task', 'n', 'AND');
             }
         }
     }
     $query = $queryGenerator->getQuery();
     return $query;
 }
 public function getLatLng($address)
 {
     # address identifier
     $address_identifier = 'latlng_' . str_replace(array(' '), array('_'), $address);
     $address_identifier = preg_replace('/[^a-z0-9_]+/i', '', $address);
     # registry
     $registry = Zend_Registry::getInstance();
     # caching
     $frontendOptions = array('lifetime' => 2592000, 'automatic_serialization' => true);
     $backendOptions = array('cache_dir' => $registry->config->application->logs->tmpDir . '/cache/');
     $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     # get data
     if (($data = $cache->load($address_identifier)) === false) {
         new Custom_Logging('Hit Google: Lat/Lng for ' . $address, Zend_Log::INFO);
         $client = new Zend_Http_Client('http://maps.google.com/maps/geo?q=' . urlencode($address), array('maxredirects' => 0, 'timeout' => 30));
         $request = $client->request();
         $response = Zend_Http_Response::fromString($request);
         $body = Zend_Json::decode($response->getBody());
         $data = array();
         $data['latitude'] = !empty($body['Placemark'][0]['Point']['coordinates'][1]) ? $body['Placemark'][0]['Point']['coordinates'][1] : null;
         $data['longitude'] = !empty($body['Placemark'][0]['Point']['coordinates'][0]) ? $body['Placemark'][0]['Point']['coordinates'][0] : null;
         $cache->save($data, $address_identifier);
     } else {
         new Custom_Logging('(local cache) Hit Google: Lat/Lng for ' . $address, Zend_Log::INFO);
     }
     return $data;
 }
예제 #25
0
 public function toOptionArray()
 {
     /** @var Mage_Core_Model_Cache */
     $cache = Mage::app()->getCacheInstance();
     if (!($fonts = $cache->load(self::CACHE_KEY))) {
         $ch = curl_init($this->googlefonts_url);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $fonts = curl_exec($ch);
         curl_close($ch);
         $fonts = Zend_Json::decode($fonts);
         $options = array();
         if (!isset($fonts['items'])) {
             return $options;
         }
         // can't connect to google font
         foreach ($fonts['items'] as $item) {
             $options[$item['family']] = array('value' => $item['family'], 'label' => $item['family']);
         }
         ksort($options);
         $options = array_values($options);
         $cache->save(serialize($options), self::CACHE_KEY, array(), self::CACHE_LIFETIME);
         return $options;
     } else {
         return unserialize($fonts);
     }
 }
예제 #26
0
 /**
  * Called from the event manager before the dispatch process.
  * Parse the json input data, when it was activated.
  *
  * @param   Enlight_Event_EventArgs $args
  * @return  bool
  */
 public function onPreDispatch(Enlight_Event_EventArgs $args)
 {
     /** @var $subject Enlight_Controller_Action */
     $subject = $args->get('subject');
     $request = $subject->Request();
     // Parses the json input data, if the content type is correct
     if ($this->parseInput === true && ($contentType = $request->getHeader('Content-Type')) !== false && strpos($contentType, 'application/json') === 0 && ($input = file_get_contents('php://input')) !== false) {
         $input = Zend_Json::decode($input);
         foreach ((array) $input as $key => $value) {
             if ($value !== null) {
                 $request->setPost($key, $value);
             }
         }
     }
     // Parse the json Params
     if (count($this->parseParams)) {
         foreach ($this->parseParams as $Param) {
             if (($value = $request->getParam($Param)) !== null) {
                 $value = Zend_Json::decode($value);
                 $request->setParam($Param, $value);
             }
         }
     }
     // Rests the configuration for the next dispatch
     $this->parseInput = false;
     $this->parseParams = array();
 }
예제 #27
0
파일: Api.php 프로젝트: baphled/boodah
 /**
  * Gets our JSON response
  * 
  * @param  String		$url		Url to query
  * @return Zend_Json	$result		Our JSON response
  * 
  */
 protected function _getJsonResponse($url)
 {
     $client = new Zend_Http_Client($url);
     $response = $client->request();
     $this->_checkResponse($response);
     return Zend_Json::decode($response->getBody(), Zend_Json::TYPE_OBJECT);
 }
예제 #28
0
 public function isAllowedToView(User_Model_User $user)
 {
     // Check level
     $selectedLevels = Zend_Json::decode($this->level);
     if (!empty($selectedLevels) && is_array($selectedLevels)) {
         // Get user level
         $levelIdentity = null;
         if (!$user->getIdentity()) {
             $levelIdentity = Engine_Api::_()->getDbtable('levels', 'authorization')->getPublicLevel()->level_id;
         } else {
             $levelIdentity = $user->level_id;
         }
         if (in_array($levelIdentity, $selectedLevels)) {
             return true;
         }
     }
     // Check network
     if ($user->getIdentity()) {
         $selectedNetworks = Zend_Json::decode($this->network);
         if (!empty($selectedNetworks) && is_array($selectedNetworks)) {
             $userNetworks = Engine_Api::_()->getDbtable('membership', 'network')->getMembershipsOfIds($user, null);
             if (count(array_intersect($userNetworks, $selectedNetworks)) > 0) {
                 return true;
             }
         }
     }
     return false;
 }
예제 #29
0
파일: MainMenu.php 프로젝트: dewawi/dewawi
 public function getMainMenu()
 {
     $modulesDb = new Application_Model_DbTable_Module();
     $modules = $modulesDb->fetchAll();
     $mainmenu = array();
     foreach ($modules as $module) {
         if ($module->active && $module->menu) {
             $data = Zend_Json::decode($module->menu);
             foreach ($data as $key => $value) {
                 if (isset($mainmenu[$key]['childs'])) {
                     foreach ($value['childs'] as $ordering => $child) {
                         $mainmenu[$key]['childs'][$ordering] = $child;
                     }
                 } else {
                     $mainmenu[$key] = $value;
                 }
             }
         }
     }
     foreach ($mainmenu as $key => $value) {
         if (isset($value['childs'])) {
             ksort($mainmenu[$key]['childs']);
         }
     }
     return $mainmenu;
 }
 /**
  * Procesar
  */
 public function process()
 {
     foreach (glob($this->_dir_temp . "/*.kml") as $filename) {
         //convertir KML a array
         $data = Zend_Json::decode(Zend_Json::fromXml(file_get_contents($filename), false));
         $this->_findPlacemarks($data);
         $this->_findStyles($data);
         $this->_findStylesMap($data);
     }
     if (count($this->_placemarks) > 0) {
         foreach ($this->_placemarks as $key => $placemark) {
             if (isset($placemark[0])) {
                 foreach ($placemark as $elemento) {
                     $this->_procesaPunto($elemento);
                     $this->_procesaPoligono($elemento);
                     $this->_procesaMultiPoligono($elemento);
                     $this->_procesaLinea($elemento);
                     $this->_procesaMultiLinea($elemento);
                 }
             } else {
                 $this->_procesaPunto($placemark);
                 $this->_procesaPoligono($placemark);
                 $this->_procesaMultiPoligono($placemark);
                 $this->_procesaLinea($placemark);
                 $this->_procesaMultiLinea($placemark);
             }
         }
     }
     //se agregan los elementos al cache que contiene el archivo
     $cache = Cache::iniciar();
     $data = $cache->load($this->_hash);
     $data["elementos"] = $this->_elementos;
     $cache->save($data, $this->_hash);
     return $this->_elementos;
 }