예제 #1
0
 /**
  * Send the HTTP request via cURL
  *
  * @return SiftResponse
  */
 public function send()
 {
     $json = new Services_JSON();
     $propertiesString = http_build_query($this->properties);
     $curlUrl = $this->url;
     if ($this->method == self::GET) {
         $curlUrl .= '?' . $propertiesString;
     }
     // Mock the request if self::$mock exists
     if (self::$mock) {
         if (self::$mock['url'] == $curlUrl && self::$mock['method'] == $this->method) {
             return self::$mock['response'];
         }
         return null;
     }
     // Open and configure curl connection
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_URL, $curlUrl);
     curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
     if ($this->method == self::POST) {
         $jsonString = $json->encodeUnsafe($this->properties);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($jsonString), 'User-Agent: SiftScience/v' . SiftClient::API_VERSION . ' sift-php/' . SiftClient::VERSION));
     }
     // Send the request using curl and parse result
     $result = curl_exec($ch);
     $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     // Close the curl connection
     curl_close($ch);
     return new SiftResponse($result, $httpStatusCode, $this);
 }
예제 #2
0
파일: compat.php 프로젝트: boonebgorges/wp
 function test_json_encode_decode()
 {
     require_once ABSPATH . WPINC . '/class-json.php';
     $json = new Services_JSON();
     // Super basic test to verify Services_JSON is intact and working.
     $this->assertEquals('["foo"]', $json->encodeUnsafe(array('foo')));
     $this->assertEquals(array('foo'), $json->decode('["foo"]'));
 }
예제 #3
0
    public static function languageSelect($attributes = array(), $lang = null)
    {
        $json = new Services_JSON();
        $configs = Gio_Core_Config_Xml::getConfig();
        $defaultLang = $configs->localization->languages->default;
        $selectedId = isset($attributes['selected']) ? $attributes['selected'] : $defaultLang;
        $disableId = isset($attributes['disabled']) ? $attributes['disabled'] : null;
        $elementDisabled = isset($attributes['disabled']) && $attributes['disabled'] === true ? ' disabled="disabled"' : '';
        $name = isset($attributes['name']) ? $attributes['name'] : null;
        $id = isset($attributes['id']) ? $attributes['id'] : null;
        $output = sprintf("<select name='%s' id='%s' viewHelperClass='%s' viewHelperAttributes='%s'%s>", $name, $id, 'Modules_Core_Services_Language::languageSelect', $json->encodeUnsafe($attributes), $elementDisabled) . self::EOL . '<option value="">---</option>' . self::EOL;
        if (isset($configs->localization->languages->list)) {
            foreach (explode(',', $configs->localization->languages->list) as $l) {
                $languages[$l] = explode('|', $configs->localization->languages->details->{$l});
            }
        }
        foreach ($languages as $index => $language) {
            $selected = $selectedId == null || $selectedId != $language[0] ? '' : ' selected="selected"';
            $disable = $disableId == null || $disableId != $language[0] ? '' : ' disabled';
            $output .= sprintf('<option value="%s"%s%s>%s (%s)</option>', $index, $selected, $disable, $language[1], $language[2]) . self::EOL;
        }
        $output .= '</select>' . self::EOL;
        $viewHelperUrl = Gio_Core_View::getInstance()->url('core_locale_viewhelper');
        $scripts = <<<END
\t\t<script type="text/javascript">
\t\t\$('#{$id}').bind('change', function() {
\t\tvar lang  = \$(this).val();
\t\tvar total = \$('.g_a_translatable').length;
\t\tvar moduleId = \$('#module_id').val();
\t\tif (lang != '') {
\t\t\t\$('.g_a_translatable').each(function(index) {
\t\t\t\tvar self    = this;
\t\t\t\tvar element = \$(this).children()[0];
\t\t\t\t\$(self).addClass('g_a_ajax_loading');
\t\t\t\tvar data    = { 
\t\t\t\t\tid: \$(element).attr('id'), 
\t\t\t\t\tname: \$(element).attr('name'), 
\t\t\t\t\tlanguage: lang, 
\t\t\t\t\tmoduleId: moduleId,
\t\t\t\t\tviewHelperClass: \$(element).attr('viewHelperClass'), 
\t\t\t\t\tviewHelperAttributes: \$(element).attr('viewHelperAttributes') 
\t\t\t\t};
\t\t\t
\t\t\t\t\$.ajaxq('core_locale', {
\t\t\t\t\ttype: 'post',
\t\t\t\t\turl: '{$viewHelperUrl}',
\t\t\t\t\tdata: data,
\t\t\t\t\tsuccess: function(response) {
\t\t\t\t\t\t\$(self).html(response).removeClass('g_a_ajax_loading');
\t\t\t\t\t}
\t\t\t\t});
\t\t\t});
\t\t}
\t});
\t\t</script>
END;
        return $output . $scripts;
    }
예제 #4
0
 function json_encode($string)
 {
     global $json;
     if (!is_a($json, 'Services_JSON')) {
         require_once W3TC_LIB_DIR . '/JSON.php';
         $json = new Services_JSON();
     }
     return $json->encodeUnsafe($string);
 }
예제 #5
0
 function json_encode($string)
 {
     global $nxt_json;
     if (!is_a($nxt_json, 'Services_JSON')) {
         require_once ABSPATH . nxtINC . '/class-json.php';
         $nxt_json = new Services_JSON();
     }
     return $nxt_json->encodeUnsafe($string);
 }
예제 #6
0
 function json_encode($string)
 {
     global $wp_json;
     if (!$wp_json instanceof Services_JSON) {
         require_once ABSPATH . WPINC . '/class-json.php';
         $wp_json = new Services_JSON();
     }
     return $wp_json->encodeUnsafe($string);
 }
예제 #7
0
 function json_encode($string)
 {
     global $json_obj;
     if (!is_a($json_obj, 'Services_JSON')) {
         require_once 'class-json.php';
         $json_obj = new Services_JSON();
     }
     return $json_obj->encodeUnsafe($string);
 }
예제 #8
0
 /**
  * Send the HTTP request via cURL
  *
  * @return SiftResponse
  */
 public function send()
 {
     $curlUrl = $this->url;
     // Mock the request if self::$mock exists
     if (self::$mock) {
         if (self::$mock['url'] == $curlUrl && self::$mock['method'] == $this->method) {
             return self::$mock['response'];
         }
         return null;
     }
     // Open and configure curl connection
     $ch = curl_init();
     $headers = array('Authorization: Basic ' . $this->apiKey, 'User-Agent: SiftScience/v' . SiftClient::API_VERSION . ' sift-partner-php/' . Sift::VERSION);
     //GET Specific setup.  The check for null is in the case that we don't add any parameters.
     if ($this->method == self::GET) {
         if ($this->properties !== null) {
             $propertiesString = http_build_query($this->properties);
             $curlUrl .= '?' . $propertiesString;
         }
     } else {
         // POST specific setup
         if ($this->method == self::POST) {
             curl_setopt($ch, CURLOPT_POST, 1);
         } else {
             if ($this->method == self::PUT) {
                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
             }
         }
         // shared by POST and PUT setup
         if (function_exists('json_encode')) {
             $jsonString = json_encode($this->properties);
         } else {
             require_once dirname(__FILE__) . '/Services_JSON-1.0.3/JSON.php';
             $json = new Services_JSON();
             $jsonString = $json->encodeUnsafe($this->properties);
         }
         curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
         /**
          * add 'Content-Type: application/json',
          *      'Content-Length: ' . strlen($jsonString),
          */
         array_push($headers, 'Content-Type: application/json');
         array_push($headers, 'Content-Length: ' . strlen($jsonString));
     }
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_URL, $curlUrl);
     curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
     // Set the header
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     // Send the request using curl and parse result
     $result = curl_exec($ch);
     $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     // Close the curl connection
     curl_close($ch);
     return new SiftResponse($result, $httpStatusCode, $this);
 }
예제 #9
0
 public static function set($name, $value = null, $sessionId = null)
 {
     $session = self::getSessionById($sessionId);
     if ($session != null) {
         $json = new Services_JSON();
         $data = $json->encodeUnsafe($value);
         self::update($data, $sessionId);
     }
     return null;
 }
예제 #10
0
 /**
  * Send the HTTP request via cURL
  *
  * @return SiftResponse
  */
 public function send()
 {
     $curlUrl = $this->url;
     if ($this->params) {
         $queryString = http_build_query($this->params);
         $separator = parse_url($curlUrl, PHP_URL_QUERY) ? '&' : '?';
         $curlUrl .= $separator . $queryString;
     }
     // Mock the request if self::$mock exists
     if (self::$mock) {
         if (self::$mock['url'] == $curlUrl && self::$mock['method'] == $this->method) {
             return self::$mock['response'];
         }
         return null;
     }
     // Open and configure curl connection
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_URL, $curlUrl);
     curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
     $headers = array('User-Agent: SiftScience/v' . $this->version . ' sift-php/' . Sift::VERSION);
     if ($this->auth) {
         curl_setopt($ch, CURLOPT_USERPWD, $this->auth);
     }
     // HTTP-method-specific configuration.
     if ($this->method == self::POST) {
         if (function_exists('json_encode')) {
             $jsonString = json_encode($this->body);
         } else {
             require_once dirname(__FILE__) . '/Services_JSON-1.0.3/JSON.php';
             $json = new Services_JSON();
             $jsonString = $json->encodeUnsafe($this->body);
         }
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
         $headers += array('Content-Type: application/json', 'Content-Length: ' . strlen($jsonString));
     } else {
         if ($this->method == self::DELETE) {
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
         }
     }
     // Send the request using curl and parse result
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     $result = curl_exec($ch);
     $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     // Close the curl connection
     curl_close($ch);
     return new SiftResponse($result, $httpStatusCode, $this);
 }
예제 #11
0
파일: Tag.php 프로젝트: piratevn/cms-gio
 public function addAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $type = strtolower($request->getPost('type'));
         switch ($type) {
             case 'ajax':
                 $this->disableLayout();
                 $this->setNoRender();
                 $tagText = trim($request->getPost('tag_text'));
                 $tagText = $this->view->STRING->escape($tagText);
                 //$tagText = Gio_Core_String::stripTags($tagText, array('.'));
                 $response = array('status' => 'RESULT_NOT_OK', 'tag_text' => null, 'tag_id' => null);
                 $json = new Services_JSON();
                 if ($tagText) {
                     if (Modules_Tag_Services_Tag::checkExist($tagText)) {
                         $response['status'] = 'RESULT_EXIST';
                     } else {
                         $tag = array('tag_text' => $tagText, 'slug' => Gio_Core_String::removeSign($tagText, '-', true), 'created_date' => date('Y-m-d H:i:s'));
                         $tagId = Modules_Tag_Services_Tag::add($tag);
                         $response['status'] = 'RESULT_OK';
                         $response['tag_text'] = $tagText;
                         $response['tag_id'] = $tagId;
                     }
                 }
                 $this->getResponse()->setBody($json->encodeUnsafe($response));
                 return;
                 break;
             default:
                 $tagData = $request->getPost('tag');
                 $tagData = Modules_Tag_Services_Tag::validate($tagData);
                 if (isset($tagData['messages_error']) && $tagData['messages_error']) {
                     $this->view->errorMessages = $tagData['messages'];
                     $this->view->tagData = $tagData;
                     return;
                 }
                 if (Modules_Tag_Services_Tag::checkExist($tagData['tag_text'])) {
                     $this->view->tagData = $tagData;
                     $this->view->existMessage = true;
                     return;
                 }
                 $tag = array('tag_text' => $this->view->STRING->escape($tagData['tag_text']), 'slug' => $tagData['slug'], 'created_date' => date('Y-m-d H:i:s'));
                 $tagId = Modules_Tag_Services_Tag::add($tag);
                 Gio_Core_Messenger::getInstance()->addMessage($this->view->TRANSLATOR->translator('tag_actions_add_success'));
                 $this->redirect($this->view->url('tag_tag_add'));
                 break;
         }
     }
 }
예제 #12
0
파일: Module.php 프로젝트: piratevn/cms-gio
 public static function moduleSelect($attributes = array())
 {
     $json = new Services_JSON();
     $view = Gio_Core_View::getInstance();
     $selectedId = isset($attributes['selected']) ? $attributes['selected'] : null;
     $disableId = isset($attributes['disable']) ? $attributes['disable'] : null;
     $elementDisabled = isset($attributes['disabled']) && $attributes['disabled'] === true ? ' disabled="disabled"' : '';
     $output = sprintf("<select name='%s' id='%s' viewHelperClass='%s' viewHelperAttributes='%s'%s>", $attributes['name'], $attributes['id'], 'Modules_Core_Services_Module', $json->encodeUnsafe($attributes), $elementDisabled) . self::EOL . '<option value="">---</option>' . self::EOL;
     $modules = self::getModulesInstalled();
     foreach ($modules as $module) {
         $selected = $selectedId == null || $selectedId != $module['module_id'] ? '' : ' selected="selected"';
         $disable = $disableId == null || $disableId != $module['module_id'] ? '' : ' disabled';
         $output .= sprintf('<option value="%s"%s%s>%s</option>', $module['module_id'], $selected, $disable, $view->TRANSLATOR->translator('about_' . $module['description'] . '_title', $module['module_id'])) . self::EOL;
     }
     $output .= '</select>' . self::EOL;
     return $output;
 }
예제 #13
0
파일: Widget.php 프로젝트: piratevn/cms-gio
 public function showAction()
 {
     $perPage = $this->getParam('limit', 10);
     $this->view->limit = $perPage;
     $pageIndex = $this->getParam('pageIndex', 1);
     $offset = ($pageIndex - 1) * $perPage;
     $request = Gio_Core_Request::getInstance();
     $json = new Services_JSON();
     $params = $request->getParams();
     $paramString = base64_encode($json->encodeUnsafe($params));
     $this->view->paramString = $paramString;
     /**
      * Get comments by paramString
      */
     $numComments = Modules_Comment_Services_Comment::countThreadComments($paramString, 'active');
     $comments = Modules_Comment_Services_Comment::getThreadComments($offset, $perPage, $paramString, 'active');
     $this->view->comments = $comments;
     $this->view->numComments = $numComments;
     // Pager
     require_once LIB_DIR . DS . 'PEAR' . DS . 'Pager' . DS . 'Sliding.php';
     $pagerOptions = array('mode' => 'Sliding', 'append' => false, 'perPage' => $perPage, 'delta' => 3, 'urlVar' => 'page', 'path' => '', 'fileName' => 'javascript: Comment.Widgets.Comment.loadComments(%d)', 'separator' => '', 'nextImg' => '<small class="icon arrow_right"></small>', 'prevImg' => '<small class="icon arrow_left"></small>', 'altNext' => '', 'altPrev' => '', 'altPage' => '', 'totalItems' => $numComments, 'currentPage' => $pageIndex, 'urlSeparator' => '/', 'spacesBeforeSeparator' => 0, 'spacesAfterSeparator' => 0, 'curPageSpanPre' => '<a href="javascript: void();" class="current">', 'curPageSpanPost' => '</a>');
     $pager = new Pager_Sliding($pagerOptions);
     $this->view->pager = $pager;
 }
예제 #14
0
 function json_encode($string)
 {
     global $wp_json;
     if (!is_a($wp_json, 'Services_JSON')) {
         require_once 'class-json.php';
         $wp_json = new Services_JSON();
     }
     return $wp_json->encodeUnsafe($string);
 }
예제 #15
0
 function json_encode($content)
 {
     require_once 'JSON.php';
     $json = new Services_JSON();
     return $json->encodeUnsafe($content);
 }
예제 #16
0
 *
 *      http://m.institution.edu/api/?ua=user+agent+string
 *
 * NOTE: the user agent string must be url encoded.
 * 
 * This will return a JSON object with the following info:
 *
 *   - device name + any special version info (e.g. android22)
 *   - the name of the templates it'd be shown in mobile web osp (e.g. webkit)
 *   - true or false for if it's a computer, an android device, an ios device, an iphone, or an ipod
 *
 */
// require the detection class
require_once "../page_builder/detection.php";
// require the JSON service
require_once "../../lib/Services_JSON-1.0.2/JSON.php";
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if (!empty($_REQUEST['ua'])) {
    $user_agent = urldecode($_REQUEST['ua']);
}
$device = Device::classify($user_agent);
$templates = Device::templates($user_agent);
$device_info = array("device" => $device, "templates" => $templates, "is_computer" => Device::is_computer(), "is_android" => Device::is_android(), "is_ios" => Device::is_ios(), "is_iphone" => Device::is_iphone(), "is_ipod" => Device::is_ipod());
$json = new Services_JSON();
// if you're going to use JS to grab this data make sure to include a callback, jQuery does it
// auto-magically if you use json-p functions
if (!empty($_REQUEST['callback'])) {
    echo $_REQUEST['callback'] . '(' . $json->encodeUnsafe($device_info) . ')';
} else {
    echo $json->encodeUnsafe($device_info);
}
예제 #17
0
 function json_encode($string)
 {
     global $wp_hotfix_json;
     if (!is_a($wp_hotfix_json, 'Services_JSON')) {
         require_once dirname(__FILE__) . '/inc/class-json.php';
         $wp_hotfix_json = new Services_JSON();
     }
     return $wp_hotfix_json->encodeUnsafe($string);
 }
예제 #18
0
파일: index.php 프로젝트: brownell/get311
        echo "Error: No Key";
    } else {
        if (strlen($search_term) > 50) {
            echo "Error: Too much data";
        } else {
            if (strlen($key) > 32) {
                echo "Error: Too much data";
            } else {
                if ($key == md5($search_term . $secret_word)) {
                    $raw_people = mit_search($_REQUEST['q']);
                    $people = array();
                    foreach ($raw_people as $raw_person) {
                        $person = array();
                        foreach ($raw_person as $attribute => $value) {
                            if ($value) {
                                $person[$attribute] = $value;
                            }
                        }
                        $people[] = $person;
                    }
                    $total = count($people);
                    $result = array('resultSet' => array('totalResultsAvailable' => $total, 'totalResultsReturned' => $total, 'firstResultPosition' => 1, 'result' => $people));
                    $json = new Services_JSON();
                    echo $json->encodeUnsafe($result);
                } else {
                    echo "Error: Bad Key";
                }
            }
        }
    }
}
 /**
  * Back-wards compatible json_encode(). Used to encode link data before
  * passing it to the JavaScript that actually creates the links.
  * 
  * @param mixed $data
  * @return string
  */
 function json_encode($data)
 {
     if (function_exists('json_encode')) {
         return json_encode($data);
     } else {
         $json = new Services_JSON();
         return $json->encodeUnsafe($data);
     }
 }
예제 #20
0
 $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
 if (isset($_REQUEST['search_sort'])) {
     $posted_query_json = $_SESSION['lastquery_assign_' . $experiment_id];
     $query_id = $_SESSION['lastqueryid_assign_' . $experiment_id];
     $posted_query = $json->decode($posted_query_json);
     $sort = query__get_sort('assign', $_REQUEST['search_sort']);
     // sanitize sort
 } else {
     // store new query in session
     $query_id = time();
     if (isset($_REQUEST['form'])) {
         $posted_query = $_REQUEST['form'];
     } else {
         $posted_query = array('query' => array());
     }
     $posted_query_json = $json->encodeUnsafe($posted_query);
     $_SESSION['lastquery_assign_' . $experiment_id] = $posted_query_json;
     $_SESSION['lastqueryid_assign_' . $experiment_id] = $query_id;
     $sort = query__load_default_sort('assign', $experiment_id);
 }
 if (check_allow('participants_edit')) {
     echo javascript__edit_popup();
 }
 // show query in human-readable form
 $pseudo_query_array = query__get_pseudo_query_array($posted_query['query']);
 $pseudo_query_display = query__display_pseudo_query($pseudo_query_array, true);
 echo '<TABLE border=0>';
 echo '<TR><TD style="outline: 1px solid black; background: ' . $color['search__pseudo_query_background'] . '">';
 echo $pseudo_query_display;
 echo '</TD><TD align="center">';
 // permanent query button
예제 #21
0
파일: File.php 프로젝트: piratevn/cms-gio
 public function uploadAction()
 {
     $this->disableLayout();
     $this->setNoRender();
     $request = $this->getRequest();
     if (!$request->isPost()) {
         exit;
     }
     /**
      * Authentication
      */
     $phpSessionId = $request->getPost('PHPSESSID');
     $session = Gio_Core_Session::getSessionById($phpSessionId);
     $json = new Services_JSON();
     $user = null == $session || null == $session['data'] ? null : $json->decode($session['data']);
     if (null == $user) {
         return;
     }
     /**
      * Get config
      */
     $configFile = MOD_DIR . DS . 'upload' . DS . 'configs' . DS . 'config.ini';
     $iniArray = @parse_ini_file($configFile, true);
     $tool = isset($iniArray['thumbnail']['tool']) ? $iniArray['thumbnail']['tool'] : 'gd';
     $sizes = array();
     foreach ($iniArray['size'] as $key => $value) {
         list($method, $width, $height) = explode('_', $value);
         $sizes[$key] = array('method' => $method, 'width' => $width, 'height' => $height);
     }
     $user = (array) $user;
     $userName = $user['username'];
     $module = $request->getPost('mod');
     $thumbnailSizes = $request->getPost('thumbnails', null);
     /**
      * Prepare folders
      */
     $dir = ROOT_DIR . DS . 'upload';
     $path = implode(DS, array($module, $userName, date('Y'), date('m')));
     Gio_Core_File::createDirs($dir, $path);
     /**
      * Upload file
      */
     $ext = explode('.', $_FILES['Filedata']['name']);
     $extension = $ext[count($ext) - 1];
     unset($ext[count($ext) - 1]);
     $fileName = date('YmdHis_') . implode('', $ext);
     $file = $dir . DS . $path . DS . $fileName . '.' . $extension;
     move_uploaded_file($_FILES['Filedata']['tmp_name'], $file);
     /**
      * Water mark
      * @since 2.0.4
      */
     $watermark = $request->getParam('watermark');
     $overlayText = $color = $overlayImage = $position = $sizesApplied = null;
     if ((bool) $watermark) {
         $overlayText = $request->getParam('text');
         $color = $request->getParam('color');
         $overlayImage = $request->getParam('image');
         $position = $request->getParam('position');
         $sizesApplied = $request->getParam('sizes');
         $sizesApplied = explode(',', $sizesApplied);
     }
     /**
      * Generate thumbnails if requested
      */
     if (!isset($thumbnailSizes) || $thumbnailSizes == null) {
         $thumbnailSizes = array_keys($sizes);
     } else {
         if ($thumbnailSizes != 'none') {
             $thumbnailSizes = explode(',', $thumbnailSizes);
         }
     }
     $service = null;
     switch (strtolower($tool)) {
         case 'imagemagick':
             $service = new Gio_Image_ImageMagick();
             break;
         case 'gd':
             $service = new Gio_Image_GD();
             break;
     }
     $ret = array();
     /**
      * Remove script filename from base URL
      */
     $baseUrl = $request->getBaseUrl();
     $prefixUrl = rtrim($baseUrl, '/') . '/upload/' . $module . '/' . $userName . '/' . date('Y') . '/' . date('m');
     $ret['original'] = array('url' => $prefixUrl . '/' . $fileName . '.' . $extension, 'size' => null);
     if ($thumbnailSizes != 'none') {
         $service->setFile($file);
         $ret['original']['size'] = $service->getWidth() . ' x ' . $service->getHeight();
         foreach ($thumbnailSizes as $s) {
             $service->setFile($file);
             $method = $sizes[$s]['method'];
             $width = $sizes[$s]['width'];
             $height = $sizes[$s]['height'];
             $f = $fileName . '_' . $s . '.' . $extension;
             $newFile = $dir . DS . $path . DS . $f;
             /**
              * Create thumbnail
              */
             switch ($method) {
                 case 'resize':
                     $service->resizeLimit($newFile, $width, $height);
                     break;
                 case 'crop':
                     $service->crop($newFile, $width, $height);
                     break;
             }
             /**
              * Create watermark if requested
              */
             if ((bool) $watermark) {
                 $service->setWatermarkFont(ROOT_DIR . DS . 'data' . DS . 'upload' . DS . self::WATERMARK_FONT);
                 $service->setFile($newFile);
                 if ($overlayText && in_array($s, $sizesApplied)) {
                     $service->watermarkText($overlayText, $position, array('color' => $color, 'rotation' => 0, 'opacity' => 50, 'size' => null));
                 }
                 if ($overlayImage && in_array($s, $sizesApplied)) {
                     $overlay = explode('/', $overlayImage);
                     $n = count($overlay);
                     $overlay = implode(DS, array($dir, 'multimedia', $overlay[$n - 4], $overlay[$n - 3], $overlay[$n - 2], $overlay[$n - 1]));
                     $service->watermarkImage($overlay, $position);
                 }
             }
             $ret[$s] = array('url' => $prefixUrl . '/' . $f, 'size' => $width . ' x ' . $height);
         }
     }
     /**
      * Return the reponse
      */
     $json = new Services_JSON();
     $this->getResponse()->setBody($json->encodeUnsafe($ret));
 }
예제 #22
0
 public function listAction()
 {
     $request = $this->getRequest();
     $perPage = 20;
     $pageIndex = (int) $request->getParam('page_index');
     if (null == $pageIndex || '' == $pageIndex || $pageIndex < 0) {
         $pageIndex = 1;
     }
     $start = ($pageIndex - 1) * $perPage;
     $this->view->pageIndex = $pageIndex;
     $condition = array('status' => null);
     $json = new Services_JSON();
     if ($request->isPost()) {
         $condition = $request->getPost('condition');
         $params = rawurlencode(base64_encode($json->encodeUnsafe($condition)));
     } else {
         $params = $request->getParam('q');
         $params != null ? $condition = (array) $json->decode(rawurldecode(base64_decode($params))) : ($params = rawurlencode(base64_encode($json->encodeUnsafe($condition))));
     }
     $params = empty($condition) ? null : $params;
     $this->view->condition = $condition;
     $comments = Modules_Comment_Services_Comment::find($start, $perPage, $condition);
     $numComments = Modules_Comment_Services_Comment::count($condition);
     $this->view->comments = $comments;
     // Pager
     require_once LIB_DIR . DS . 'PEAR' . DS . 'Pager' . DS . 'Sliding.php';
     $pagerPath = $this->view->url('comment_comment_list');
     $pagerOptions = array('mode' => 'Sliding', 'append' => false, 'perPage' => $perPage, 'delta' => 3, 'urlVar' => 'page', 'path' => $pagerPath, 'fileName' => null == $params ? 'page-%d' : 'page-%d' . '/?q=' . $params, 'separator' => '', 'nextImg' => '<small class="icon arrow_right"></small>', 'prevImg' => '<small class="icon arrow_left"></small>', 'altNext' => '', 'altPrev' => '', 'altPage' => '', 'totalItems' => $numComments, 'currentPage' => $pageIndex, 'urlSeparator' => '/', 'spacesBeforeSeparator' => 0, 'spacesAfterSeparator' => 0, 'curPageSpanPre' => '<a href="javascript: void();" class="current">', 'curPageSpanPost' => '</a>');
     $pager = new Pager_Sliding($pagerOptions);
     $this->view->pager = $pager;
 }
예제 #23
0
파일: query.php 프로젝트: danorama/orsee
function query__resulthead_participantsearch()
{
    global $color;
    echo '<TABLE border="0" width="95%"><TR>';
    $bulkactions = query__get_bulkactions();
    if (count($bulkactions) > 0) {
        $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
        echo '<div id="bulkPopupDiv" class="bulkpopupDiv" style=" background: ' . $color['popup_bgcolor'] . '; color: ' . $color['popup_text'] . ';">
                <div align="right"><button class="b-close button fa-backward popupBack">' . lang('back_to_results') . '</button></div>
                <div id="bulkPopupContent" style="margin-left: 20px; margin-top: 0px;"></div>
            </div>
            <script type="text/javascript">
                var bulkactions = ';
        echo $json->encodeUnsafe($bulkactions);
        echo ';
                $(document).ready(function(){
                    $.each(bulkactions, function(actionName, action){
                        var item = $.parseHTML("<li><a>" + action.display_text + "</a></li>");
                        $(item).on("click", function(){
                            bulkaction(actionName);
                        });
                        $("#bulkDropdown").append(item);
                    });
                });
                var bulkBpopup;
                function bulkaction(act){
                    var participant_count = $("input[name*=\'sel[\']:checked").length;
                    var parstr = participant_count + " ' . lang('selected_participants') . '";
                    var str = bulkactions[act].html;
                    str = str.replace("#xyz_participants#", parstr);
                    $("#bulkPopupContent").html("");
                    $("#bulkPopupContent").append($.parseHTML(str));
                    bulkBpopup = $("#bulkPopupDiv").bPopup({
                        contentContainer: "#bulkPopupContent",
                        amsl: 50,
                        positionStyle: "fixed",
                        modalColor: "' . $color['popup_modal_color'] . '",
                        opacity: 0.8
                        });
                    $("#popupsubmit").click(function(event){
                        event.preventDefault();
                        $(".bforminput").each(function(){
                            var $input = $( this );
                            var tval = "";
                            if ($input.is(":checkbox")) {
                                if ($input.prop("checked")) tval="y";
                                else tval="n";
                            } else {
                                tval=$input.val();
                            }
                            var tstr = \'<input type="hidden" name="\'+$input.prop("name")+\'" value="\'+tval+\'" />\';
                            $("#bulkactionform").append($.parseHTML(tstr));
                        });
                        bulkBpopup.close();
                        $("#bulkactionform").submit();
                    });
                }
            </script>';
        echo '<TD>';
        echo '<TABLE border="0" class="or_panel" style="width: auto;">';
        echo '<TR><TD>' . lang('for_all_selected_participants') . '</TD>
                <TD><ul id="bulkactionDropdown" class="bulkaction">
                        <li><A HREF="#" class="button fa-group">' . lang('do___') . '</A>
                            <ul id="bulkDropdown">

                            </ul>
                        </li>
                    </ul>
                </TD>';
        echo '</TR>';
        echo '</TABLE>';
        echo '
        <script type="text/javascript">
        $(document).ready(function(){
            $("#bulkactionDropdown").dropit(
                {
                    action: "mouseenter",
                    beforeShow: function(){
                        $("#bulkactionDropdown .dropit-submenu").css("width", "250px");
                    }
                }
            )
        });
        </script>';
        echo '</TD>';
    }
    echo '<TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>';
    // back to query form button
    $cgivars = array();
    if (isset($_REQUEST['active']) && $_REQUEST['active']) {
        $cgivars[] = 'active=true';
    }
    if (isset($_REQUEST['experiment_id']) && $_REQUEST['experiment_id']) {
        $cgivars[] = 'experiment_id=' . $_REQUEST['experiment_id'];
    }
    echo '<TD><A HREF="' . thisdoc();
    if (count($cgivars) > 0) {
        echo '?' . implode("&", $cgivars);
    }
    echo '" class="button fa-backward" style="font-size: 8pt">' . lang('back_to_query_form') . '</A>';
    echo '</TD>';
    // save query button
    $cgivars = array();
    $cgivars[] = "save_query=true";
    if (isset($_REQUEST['search_sort'])) {
        $cgivars[] = 'search_sort=' . urlencode($_REQUEST['search_sort']);
    }
    if (isset($_REQUEST['active']) && $_REQUEST['active']) {
        $cgivars[] = 'active=true';
    }
    if (isset($_REQUEST['experiment_id']) && $_REQUEST['experiment_id']) {
        $cgivars[] = 'experiment_id=' . $_REQUEST['experiment_id'];
    }
    echo '<TD><A HREF="' . thisdoc();
    if (count($cgivars) > 0) {
        echo '?' . implode("&", $cgivars);
    }
    echo '" class="button fa-floppy-o">' . lang('save_query') . '</A>';
    echo '</TD>';
    echo '</TR></TABLE>';
}
예제 #24
0
 function json_encode($var)
 {
     $JSON = new Services_JSON();
     return $JSON->encodeUnsafe($var);
 }
예제 #25
0
파일: Widget.php 프로젝트: piratevn/cms-gio
 public function dispatch()
 {
     $cacheType = 'widgets';
     $request = $this->_request;
     /**
      * XML
      */
     $xmlFilename = array($this->_module, $this->_widget, $this->_action);
     $xmlFilename = implode('_', $xmlFilename);
     /**
      * Check file html cache 
      */
     $globalConfig = Gio_Core_Config_Xml::getConfig();
     $configs = Gio_Core_Config_Xml::getConfig('cache');
     $checkCache = false;
     if ($configs->enable == 'true' && $this->_cacheEnable == true) {
         $cacheName = $xmlFilename;
         $postParams = $request->getPostParams();
         $getParams = $request->getParams();
         $widgetParams = $this->_params;
         $json = new Services_JSON();
         $cacheParams = !empty($postParams) ? base64_encode($json->encodeUnsafe($postParams)) : null;
         $cacheParams = !empty($getParams) ? base64_encode($json->encodeUnsafe($getParams)) : null;
         $cacheParams = !empty($widgetParams) ? base64_encode($json->encodeUnsafe($widgetParams)) : null;
         $cacheKey = md5($cacheName . $this->_template . $cacheParams . base64_encode($json->encodeUnsafe($globalConfig)));
         $cacheTimeout = $this->_cacheTimeout ? $this->_cacheTimeout : 3600;
         /**
          * Create html file cache
          */
         if ($checkCache = Gio_Core_Cache::isCached($cacheType, $cacheKey, $cacheTimeout)) {
             $html = $this->view->render(Gio_Core_Cache::_generateFileName($cacheType, $cacheKey));
             return $html;
         }
     }
     /**
      * Localization config 
      */
     $aboutFile = ROOT_DIR . DS . 'modules' . DS . $this->_module . DS . 'widgets' . DS . $this->_widget . DS . 'about.xml';
     if (file_exists($aboutFile)) {
         $info = @simplexml_load_file($aboutFile);
         $localization = $info->localization['enable'];
         if ($localization != null && 'true' == (string) $localization) {
             $idClass = (string) $info->localization->identifier['class'];
             $idParam = (string) $info->localization->identifier['param'];
             $this->_params[$idParam] = isset($this->_params[$idParam]) ? $this->_params[$idParam] : null;
             $conn = Gio_Db_Connection::getConnection();
             $this->_translationDao->setConnection($conn);
             $items = $this->_translationDao->getItems($this->_params[$idParam], $idClass, $request->getParam('lang'));
             if ($items != null && 1 == count($items)) {
                 $this->_params[$idParam] = $items[0]['item_id'];
             }
         }
     }
     $ucfModule = ucfirst($this->_module);
     $ucfWidget = ucfirst($this->_widget);
     $widgetClassName = array('Modules', $ucfModule, 'Widgets', $ucfWidget, 'Widget');
     $widgetClassName = implode('_', $widgetClassName);
     $widgetClass = new $widgetClassName();
     if (!method_exists($widgetClass, $this->_action . 'Action')) {
         return;
     }
     $widgetClass->setParams($this->_params);
     call_user_func(array($widgetClass, $this->_action . 'Action'));
     $widgetDefaultViewFile = MOD_DIR . DS . $this->_module . DS . 'widgets' . DS . $this->_widget . DS . $this->_action . '.phtml';
     $widgetViewFile = TEMPLATE_DIR . DS . $this->_template . DS . 'modules' . DS . $this->_module . DS . 'widgets' . DS . $this->_widget . DS . $this->_action . '.phtml';
     $widgetViewFile = file_exists($widgetViewFile) ? $widgetViewFile : $widgetDefaultViewFile;
     $widgetClass->view->cacheEnable = $this->_cacheEnable;
     $widgetClass->view->cacheTimeout = $this->_cacheTimeout;
     $return = $widgetClass->view->render($widgetViewFile);
     if (!isset($this->_params['load']) || $this->_params['load'] != 'ajax') {
         $jsCss = array('cssFiles' => array(), 'jsFiles' => array());
         $search = array('{APP_WEB_URL}', '{APP_STATIC_SERVER}', '{WIDGET_URL}');
         $replace = array($this->view->APP_WEB_URL, $this->view->APP_STATIC_SERVER, $this->view->APP_STATIC_SERVER . DS . 'modules' . DS . strtolower($this->_module) . DS . 'widgets' . DS . strtolower($this->_widget));
         $configFile = ROOT_DIR . DS . 'modules' . DS . strtolower($this->_module) . DS . 'widgets' . DS . strtolower($this->_widget) . DS . 'about.xml';
         if (file_exists($configFile)) {
             $widgetConfig = @simplexml_load_file($configFile);
             if ($resources = $widgetConfig->resources) {
                 if ($resources = $resources->resource) {
                     foreach ($resources as $resource) {
                         $attr = $resource->attributes();
                         switch ((string) $attr['type']) {
                             case 'css':
                                 $jsCss['cssFiles'][] = str_replace($search, $replace, (string) $attr['src']);
                                 break;
                             case 'javascript':
                                 $jsCss['jsFiles'][] = str_replace($search, $replace, (string) $attr['src']);
                                 break;
                         }
                     }
                 }
             }
         }
         if ($jsCss['cssFiles']) {
             foreach ($jsCss['cssFiles'] as $index => $file) {
                 Gio_Core_View::getInstance()->headStyle($file);
             }
         }
         if ($jsCss['jsFiles']) {
             foreach ($jsCss['jsFiles'] as $index => $file) {
                 Gio_Core_View::getInstance()->headScript($file);
             }
         }
     }
     if (!$checkCache && $configs->enable == 'true' && $this->_cacheEnable == true) {
         $cacheCompress = isset($configs->compress) && $configs->compress == 'true' ? true : false;
         $cacheContent = Gio_Core_View::getInstance()->generateScripts() . Gio_Core_View::getInstance()->generateStyles() . $return;
         /**
          * HTML Compress
          */
         if (isset($configs->compress) && $configs->compress == 'true') {
             $cacheContent = Gio_Core_HtmlCompress::compress($cacheContent);
         }
         Gio_Core_Cache::cache($cacheType, $cacheKey, $cacheContent, $cacheCompress);
     }
     return $return;
 }
예제 #26
0
파일: Auth.php 프로젝트: piratevn/cms-gio
 public function myopenidAction()
 {
     $this->disableLayout();
     $this->setNoRender();
     $request = Gio_Core_Request::getInstance();
     $this->setLayout('login');
     require_once LIB_DIR . DS . 'openid' . DS . 'class.openid.v2.php';
     if ($request->isPost()) {
         $openidUrl = $request->getPost('openid_url');
         $openidUrl = rtrim($openidUrl, '/');
         $openid = new OpenIDService();
         $openid->SetIdentity($openidUrl);
         $openid->SetTrustRoot($request->getBaseUrl());
         $openid->SetRequiredFields(array('email', 'fullname'));
         $openid->SetOptionalFields(array('dob', 'gender', 'country'));
         if ($openid->GetOpenIDServer()) {
             $openid->SetApprovedURL($this->view->url('core_auth_myopenid'));
             $openid->Redirect();
         } else {
             $error = $openid->GetError();
             $error_code = $error["code"];
             $error_string = $error["description"];
         }
     } elseif ($request->getParam('openid_mode') == 'id_res') {
         $openid = new OpenIDService();
         $openidUrl = $request->getParam('openid_identity');
         $openidUrl = rtrim($openidUrl, '/');
         $openid->SetIdentity($openidUrl);
         $openid_validation_result = $openid->ValidateWithServer();
         /**
          * Login success
          */
         if ($openid_validation_result == true) {
             $user = Modules_Core_Services_User::getByOpenID($openidUrl);
             if ($user) {
                 $user['last_login'] = date('Y-m-d H:i:s');
                 Modules_Core_Services_User::setLastLogin($user);
                 $configs = Gio_Core_Config_Xml::getConfig('session');
                 $json = new Services_JSON();
                 $sessionId = session_id();
                 $session = array('session_id' => $sessionId, 'created_date' => strtotime(date('Y-m-d H:i:s')), 'last_update' => strtotime(date('Y-m-d H:i:s')), 'lifetime' => isset($configs->lifetime) ? $configs->lifetime : 3600, 'inactive_time' => isset($configs->inactive_time) ? $configs->inactive_time : 120, 'data' => $json->encodeUnsafe($user), 'status' => 'active');
                 Gio_Core_Session::add($session);
                 $this->redirect($this->view->url('core_dashboard_index'));
             }
         }
     }
 }
예제 #27
0
 /**
  * Backwards compatible json_encode.
  *
  * @param mixed $data
  * @return string
  */
 function json_encode($data)
 {
     if (function_exists('json_encode')) {
         return json_encode($data);
     }
     if (class_exists('Services_JSON')) {
         $json = new Services_JSON();
         return $json->encodeUnsafe($data);
     } elseif (class_exists('Moxiecode_JSON')) {
         $json = new Moxiecode_JSON();
         return $json->encode($data);
     } else {
         trigger_error('No JSON parser available', E_USER_ERROR);
         return '';
     }
 }
/**
* @desc Output Plugin Options as json
* @author Georg Leciejewski
* @param array $args 	- array with VALID widget options
* @return string json
*/
function king_export_json($args)
{
    $json = new Services_JSON();
    return $json->encodeUnsafe($args);
}
예제 #29
0
 /**
  * Test database connection
  * 
  * @return void
  */
 private function _testdbconn()
 {
     $request = $this->getRequest();
     if (!$request->isPost()) {
         return;
     }
     $conn = Gio_Db_Mysql::getInstance();
     $options = array('host' => $request->getPost('host'), 'port' => $request->getPost('port'), 'username' => $request->getPost('username'), 'password' => $request->getPost('password'));
     $success = $conn->testConnection($options);
     if ($success) {
         $databases = $conn->getDatabases($options);
         $return = array('result' => 'RESULT_OK', 'databases' => $databases);
     } else {
         $return = array('result' => 'RESULT_ERROR', 'databases' => null);
     }
     $json = new Services_JSON();
     $this->getResponse()->setBody($json->encodeUnsafe($return));
 }
예제 #30
0
파일: User.php 프로젝트: piratevn/cms-gio
 /**
  * Provide the link (via email) for user to reset the password
  * 
  * @param string $username
  * @param string $email
  * @return bool Returns false if user is not found or can not send email, 
  * true otherwise
  */
 public static function sendPassword($username, $email, $code)
 {
     $criteria = array('username' => $username, 'email' => $email);
     $users = self::find($criteria, null, null);
     if ($users == null || count($users) == 0) {
         return false;
     }
     /**
      * Send the confirmation link to reset password via email 
      */
     $user = $users[0];
     $template = Modules_Mail_Services_Template::getByName(Modules_Mail_Models_Template::TEMPLATE_FORGOT_PASSWORD);
     if ($template == null) {
         throw new Exception('MAIL_TEMPLATE_NOT_FOUND');
     }
     $search = array(Modules_Mail_Models_Mail::MAIL_VARIABLE_EMAIL, Modules_Mail_Models_Mail::MAIL_VARIABLE_USERNAME);
     $replace = array($user['email'], $user['username']);
     $subject = str_replace($search, $replace, $template['subject']);
     $content = str_replace($search, $replace, $template['body']);
     /**
      * Replace the reset password link
      * @TODO: Add security key?
      */
     $view = Gio_Core_View::getInstance();
     $json = new Services_JSON();
     $encodedLink = array('username' => $username, 'email' => $email, 'code' => $code);
     $encodedLink = base64_encode(urlencode($json->encodeUnsafe($encodedLink)));
     $link = $view->url('core_user_resetpassword', array('encoded_link' => $encodedLink));
     $content = str_replace('%reset_link%', $link, $content);
     /**
      * Get mail transport instance
      */
     $mailer = Modules_Mail_Services_Mailer::getMailTransport();
     $mailer->From = $template['from_mail'];
     $mailer->FromName = $template['from_name'];
     $mailer->AddAddress($user['email'], $user['username']);
     $mailer->AddReplyTo($template['reply_to_mail'], $template['reply_to_name']);
     $mailer->WordWrap = 50;
     // set word wrap
     $mailer->IsHTML(true);
     // send as HTML
     $mailer->Subject = $subject;
     $mailer->Body = $content;
     //HTML Body
     $mailer->AltBody = "";
     //Text Body
     if (!$mailer->Send()) {
         return false;
     } else {
         return true;
     }
 }