/**
 * Contruct a tree structure
 * @return json with the tree structure 
 */
function evocwidget_dynamic_get_full_classes_tree()
{
    $nodes = array();
    $node = $_POST['node'];
    $nodes = array();
    $current_values = explode(',', $_POST['arrayOfValues']);
    if ($node == 'root') {
        $classes = db_query(db_rewrite_sql("SELECT prefix, id, comment FROM {evoc_rdf_classes}"));
        $root_superclasses = array();
        while ($class = db_fetch_object($classes)) {
            $class->prefix = trim($class->prefix);
            $class->id = trim($class->id);
            $root_superclasses = evocwidget_dynamic_get_root_superclasses($class->prefix . ':' . $class->id);
        }
        foreach ($root_superclasses as $class) {
            $leaf = count($children_of_children = evocwidget_dynamic_gateway_get_children($class)) == 0;
            $checked = FALSE;
            if (!empty($current_values)) {
                if (in_array($class, $current_values)) {
                    $checked = TRUE;
                }
            }
            $nodes[] = array('text' => $class, 'id' => $class, 'leaf' => $leaf, 'iconCls' => 'class-samevoc', 'checked' => $checked, 'qtip' => 'there is no information available yet...');
        }
    } else {
        $children = evocwidget_dynamic_gateway_get_children($node);
        foreach ($children as $child) {
            $class_qname = $child['prefix'] . ':' . $child['id'];
            $leaf = count($children_of_children = evocwidget_dynamic_gateway_get_children($class_qname)) == 0;
            $checked = FALSE;
            if (!empty($current_values)) {
                if (in_array($class_qname, $current_values)) {
                    $checked = TRUE;
                }
            }
            $nodes[] = array('text' => $class_qname, 'id' => $class_qname, 'leaf' => $leaf, 'iconCls' => 'class-samevoc', 'checked' => $checked);
        }
    }
    drupal_json($nodes);
}
Ejemplo n.º 2
0
 /**
  * TODO: improve this!
  */
 protected function outputError()
 {
     drupal_json(array('status' => FALSE, 'data' => '<div>Error occurred...</div>'));
 }
Ejemplo n.º 3
0
/**
 * Construct the tree structure for a Tree using ExtJS Tree structure
 * @return json with the tree structure 
 */
function neologism_gateway_get_full_properties_tree()
{
    $nodes = array();
    $node = $_REQUEST['node'];
    $array_references = array();
    $array_inverses = array();
    if ($node == 'root') {
        $properties = db_query(db_rewrite_sql("SELECT * FROM {evoc_rdf_properties} where superproperties = '0'"));
        while ($property = db_fetch_object($properties)) {
            $qname = $property->prefix . ':' . $property->id;
            $array_domain = array();
            if ($property->domains > 0) {
                $array_domain = _neologism_get_domain_terms($property->prefix, $property->id);
            }
            $array_ranges = array();
            if ($property->ranges > 0) {
                $array_ranges = _neologism_get_range_terms($property->prefix, $property->id);
            }
            // fetch the inverses
            $inverses = array();
            if ($property->inverses > 0) {
                $inverses = _neologism_get_inverseof_terms($property->prefix, $property->id);
                // add inverses to the main array to use it after build the nodes
                $array_inverses[$qname] = $inverses;
            }
            _neologism_gateway_create_property_treenode($nodes, $node, $property, $array_domain, $array_ranges, $inverses, $array_inverses, $array_references);
        }
        $properties = db_query(db_rewrite_sql("SELECT DISTINCT superproperty FROM {evoc_rdf_superproperties sp} WHERE \r\n    \tNOT EXISTS (SELECT * FROM {evoc_rdf_properties} p WHERE sp.superproperty = CONCAT(p.prefix, ':', p.id))"));
        while ($row = db_fetch_object($properties)) {
            _neologism_gateway_create_property_treenode($nodes, $node, $row, array(), array(), array(), $array_inverses, $array_references);
        }
        $nodes[0]['references'] = $array_references;
        // infer disjointness between classes
        _neologism_infer_inverses($nodes, $array_inverses);
    }
    drupal_json($nodes);
}
Ejemplo n.º 4
0
/**
 * Auto complete function for the form to add to an existing node
 */
function _nodereferrer_create_autocomplete($type, $filter)
{
    $matches = array();
    // Only query nodes where we have update rights
    $update_where = _node_access_where_sql('update', 'ndrfc_node_access');
    if ($update_where) {
        $update_where = '(' . $update_where . ') AND ';
    }
    $res = db_query("\n    SELECT node.nid \n      FROM {node} AS node\n    INNER JOIN {node_access} AS ndrfc_node_access ON ndrfc_node_access.nid = node.nid\n    WHERE {$update_where}\n          type='%s' AND title LIKE '%%%s%%'\n  ", $type, $filter);
    while ($nid = db_fetch_object($res)) {
        $node = node_load($nid->nid);
        $matches[$node->title . ' [nid:' . $node->nid . ']'] = $node->title;
    }
    drupal_json($matches);
}
 /**
  * Constructs an option question object
  *
  * @param CqUserAnswerInterface $userAnswer
  *   The CqUserAnswerInterface to use for storing the student's answer.
  * @param object $node
  *   Drupal node object that this question belongs to.
  */
 public function __construct(CqUserAnswerInterface &$userAnswer, &$node)
 {
     parent::__construct();
     $this->userAnswer =& $userAnswer;
     $this->node =& $node;
     if (isset($_REQUEST['action'])) {
         if (strtolower($_REQUEST['action']) == 'getanswer') {
             echo $this->userAnswer->getAnswer();
             die;
         }
         if (strtolower($_REQUEST['action']) == 'getdata') {
             echo $this->userAnswer->getData('data');
             die;
         }
         if (strtolower($_REQUEST['action']) == 'getinfo') {
             global $user;
             profile_load_profile(&$user);
             $info = array();
             $info['username'] = $user->name;
             if (isset($user->profile_firstname)) {
                 $info['firstname'] = $user->profile_firstname;
             }
             if (isset($user->profile_middlename)) {
                 $info['middlename'] = $user->profile_middlename;
             }
             if (isset($user->profile_lastname)) {
                 $info['lastname'] = $user->profile_lastname;
             }
             $info['tries'] = $this->userAnswer->getTries();
             $info['onceCorrect'] = $this->userAnswer->onceCorrect();
             $format = '';
             if (isset($_REQUEST['format'])) {
                 $format = strtolower($_REQUEST['format']);
             }
             switch ($format) {
                 case 'xml':
                     $dom = new DOMDocument('1.0', 'utf-8');
                     $root = $dom->createElement('data');
                     $dom->appendChild($root);
                     foreach ($info as $key => $value) {
                         $node = $dom->createElement($key, $value);
                         $root->appendChild($node);
                     }
                     echo $dom->saveXML();
                     die;
                     break;
                 case 'json':
                     drupal_json($info);
                     die;
                     break;
                 case 'flash':
                 default:
                     foreach ($info as $key => $value) {
                         echo '&' . $key . '=' . urlencode($value) . '&';
                     }
                     die;
                     break;
             }
         }
     }
     if (isset($_POST['action'])) {
         if (strtolower($_POST['action']) == 'store') {
             if (isset($_POST['answer'])) {
                 $this->userAnswer->setAnswer($_POST['answer']);
             }
             if (isset($_POST['data'])) {
                 $this->userAnswer->setData('data', $_POST['data']);
             }
             if (isset($_POST['tries'])) {
                 $this->userAnswer->setTries($_POST['tries']);
             }
             if (isset($_POST['correct'])) {
                 $this->userAnswer->setCorrect($_POST['correct']);
                 $this->userAnswer->setData('correct', $_POST['correct']);
             }
             switch ($format) {
                 case 'xml':
                     $dom = new DOMDocument('1.0', 'utf-8');
                     $root = $dom->createElement('result');
                     $dom->appendChild($root);
                     $node = $dom->createElement('success', 'true');
                     $root->appendChild($node);
                     echo $dom->saveXML();
                     die;
                     break;
                 case 'json':
                     drupal_json(array('success' => TRUE));
                     die;
                     break;
                 case 'flash':
                 default:
                     echo '&success=true&';
                     die;
                     break;
             }
         }
     }
 }
Ejemplo n.º 6
0
// Set node counter.
if (boost_stats_variable_get('statistics_count_content_views')) {
    boost_stats_update_node_counter();
}
// Set access log.
if (boost_stats_variable_get('statistics_enable_access_log')) {
    boost_stats_add_access_log();
}
if (isset($_GET['js'])) {
    if ($_GET['js'] == 1) {
        $json = array();
        // Get stats block html.
        $json = array_merge($json, boost_stats_output_stats_block());
        // Send JSON Back
        if (!empty($json)) {
            drupal_json($json);
        }
    } elseif ($_GET['js'] == 2) {
        echo array_pop(boost_stats_output_stats_block());
    }
}
// end of script, exit.
exit;
function boost_stats_async_image()
{
    // Script should take under 1MB of memory to work.
    // Prime php for background operations
    while (ob_get_level()) {
        ob_end_clean();
    }
    header("Connection: close");
Ejemplo n.º 7
0
/**
 * Construct a tree structure for an specific vocabulary. This' the gateway for the treeview
 * @return json with the tree structure 
 */
function neologism_gateway_get_classes_tree_old()
{
    $voc['id'] = $_POST['voc_id'];
    $voc['title'] = $_POST['voc_title'];
    $node = $_POST['node'];
    $nodes = array();
    if ($node == 'super') {
        $classes = db_query(db_rewrite_sql('select * from {evoc_rdf_classes} where superclasses = "0"'));
        while ($class = db_fetch_object($classes)) {
            $qname = $class->prefix . ':' . $class->id;
            $children = neologism_gateway_get_class_children($qname, $voc['title']);
            if ($class->prefix == $voc['title'] || _neologism_gateway_in_nodes($voc['title'], $children)) {
                $qtip = '<b>' . $class->label . '</b><br/>' . $class->comment;
                $leaf = count($children) == 0;
                $nodes[] = array('text' => $qname, 'id' => $qname, 'leaf' => $leaf, 'iconCls' => $class->prefix == $voc['title'] ? 'class-samevoc' : 'class-diffvoc', 'cls' => $class->prefix == $voc['title'] ? 'currentvoc' : '', 'children' => $children, 'qtip' => $qtip);
            }
        }
    }
    drupal_json($nodes);
}
Ejemplo n.º 8
0
/**
 * Add domain
 *
 * URL: http://guifi.net/guifi/js/add-domain
 */
function guifi_ahah_add_domain()
{
    $form_state = array('storage' => NULL, 'submitted' => FALSE);
    $form_build_id = $_POST['form_build_id'];
    $form = form_get_cache($form_build_id, $form_state);
    $args = $form['#parameters'];
    $form_id = array_shift($args);
    $form_state['post'] = $form['#post'] = $_POST;
    $form['#programmed'] = $form['#redirect'] = FALSE;
    drupal_process_form($form_id, $form, $form_state);
    $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
    $textfields = $form['domain_type_form'];
    $output = drupal_render($textfields);
    // Final rendering callback.
    print drupal_json(array('status' => TRUE, 'data' => $output));
    exit;
}