Example #1
0
 function MenuData($data)
 {
     $data = common::JsonEncode($data);
     echo '<span style="display:none">' . htmlspecialchars($data, ENT_NOQUOTES) . '</span>';
 }
 /**
  * Output Sortable Menu Link and data about the title or external link
  *
  */
 function MenuLink($data, $external = false)
 {
     $class = 'gp_label sort';
     if ($external) {
         $class .= ' external';
     }
     $json = common::JsonEncode($data);
     echo '<a class="' . $class . '" data-cmd="menu_info" data-arg="' . str_replace('&', '&amp;', $data['key']) . '" data-json=\'' . htmlspecialchars($json, ENT_QUOTES & ~ENT_COMPAT) . '\'>';
 }
Example #3
0
 static function InlineEdit($section_data)
 {
     $section_data += array('type' => '', 'content' => '');
     $scripts = array();
     $scripts[] = '/include/js/inline_edit/inline_editing.js';
     $type = 'text';
     if (!empty($section_data['type'])) {
         $type = $section_data['type'];
     }
     switch ($type) {
         case 'gallery':
             $scripts = gpAjax::InlineEdit_Gallery($scripts);
             break;
         case 'include':
             $scripts = gpAjax::InlineEdit_Include($scripts);
             break;
         case 'text':
             $scripts = gpAjax::InlineEdit_Text($scripts);
             break;
         case 'image':
             echo 'var gp_blank_img = ' . gpAjax::quote(common::GetDir('/include/imgs/blank.gif')) . ';';
             $scripts[] = '/include/js/jquery.auto_upload.js';
             $scripts[] = '/include/js/inline_edit/image_common.js';
             $scripts[] = '/include/js/inline_edit/image_edit.js';
             break;
     }
     $scripts = gpPlugin::Filter('InlineEdit_Scripts', array($scripts, $type));
     self::SendScripts($scripts);
     //replace resized images with their originals
     if (isset($section_data['resized_imgs']) && is_array($section_data['resized_imgs']) && count($section_data['resized_imgs'])) {
         includeFile('tool/editing.php');
         $section_data['content'] = gp_edit::RestoreImages($section_data['content'], $section_data['resized_imgs']);
     }
     //create the section object that will be passed to gp_init_inline_edit
     $section_object = common::JsonEncode($section_data);
     //send call to gp_init_inline_edit()
     echo ';if( typeof(gp_init_inline_edit) == "function" ){';
     echo 'gp_init_inline_edit(';
     echo gpAjax::quote($_GET['area_id']);
     echo ',' . $section_object;
     echo ');';
     echo '}else{alert("gp_init_inline_edit() is not defined");}';
 }
Example #4
0
 /**
  * A more functional JSON Encode function for gpEasy than php's json_encode
  * @param mixed $data
  *
  */
 static function JsonEncode($data)
 {
     static $search = array('\\', '"', "\n", "\r", "\t", '<script', '</script>');
     static $repl = array('\\\\', '\\"', '\\n', '\\r', '\\t', '<"+"script', '<"+"/script>');
     $type = gettype($data);
     switch ($type) {
         case 'NULL':
             return 'null';
         case 'boolean':
             return $data ? 'true' : 'false';
         case 'integer':
         case 'double':
         case 'float':
             return $data;
         case 'string':
             return '"' . str_replace($search, $repl, $data) . '"';
         case 'object':
             $data = get_object_vars($data);
         case 'array':
             $output_index_count = 0;
             $output_indexed = array();
             $output_associative = array();
             foreach ($data as $key => $value) {
                 $output_indexed[] = common::JsonEncode($value);
                 $output_associative[] = common::JsonEncode($key) . ':' . common::JsonEncode($value);
                 if ($output_index_count !== NULL && $output_index_count++ !== $key) {
                     $output_index_count = NULL;
                 }
             }
             if ($output_index_count !== NULL) {
                 return '[' . implode(',', $output_indexed) . ']';
             } else {
                 return '{' . implode(',', $output_associative) . '}';
             }
         default:
             return '';
             // Not supported
     }
 }
Example #5
0
 function InlineEdit($section_data)
 {
     global $dataDir, $dirPrefix;
     $section_data += array('type' => '', 'content' => '');
     header('Content-type: application/x-javascript');
     $type = $section_data['type'];
     $scripts = array();
     $scripts[] = '/include/js/inline_edit/inline_editing.js';
     //$scripts[] = '/include/thirdparty/jquery_ui/jquery-ui.custom.min.js';
     $type = 'text';
     if (!empty($section_data['type'])) {
         $type = $section_data['type'];
     }
     switch ($section_data['type']) {
         case 'gallery':
             $scripts = gpAjax::InlineEdit_Gallery($scripts);
             break;
         case 'include':
             $scripts = gpAjax::InlineEdit_Include($scripts);
             break;
         case 'text':
             $scripts = gpAjax::InlineEdit_Text($scripts);
             break;
     }
     $scripts = gpPlugin::Filter('InlineEdit_Scripts', array($scripts, $type));
     $scripts = array_unique($scripts);
     //send all scripts
     foreach ($scripts as $script) {
         //absolute paths don't need $dataDir
         $full_path = $script;
         if (strpos($script, $dataDir) !== 0) {
             //fix addon paths that use $addonRelativeCode
             if (!empty($dirPrefix) && strpos($script, $dirPrefix) === 0) {
                 $script = substr($script, strlen($dirPrefix));
             }
             $full_path = $dataDir . $script;
         }
         if (!file_exists($full_path)) {
             echo 'if(isadmin){alert("Admin Notice: The following file could not be found: \\n\\n' . addslashes($full_path) . '");}';
             continue;
         }
         echo ';';
         //echo "\n/**\n* $script\n*\n*/\n";
         readfile($full_path);
     }
     //replace resized images with their originals
     if (is_array($section_data['resized_imgs']) && count($section_data['resized_imgs'])) {
         includeFile('tool/editing.php');
         $section_data['content'] = gp_edit::RestoreImages($section_data['content'], $section_data['resized_imgs']);
     }
     //create the section object that will be passed to gp_init_inline_edit
     $section_object = common::JsonEncode($section_data);
     //send call to gp_init_inline_edit()
     echo ';if( typeof(gp_init_inline_edit) == "function" ){';
     echo 'gp_init_inline_edit(';
     echo gpAjax::quote($_GET['area_id']);
     echo ',' . $section_object;
     echo ');';
     echo '}else{alert("gp_init_inline_edit() is not defined");}';
 }