/**
 * @param string[] $argv
 * @return int
 */
function main(array $argv)
{
    if (!isset($argv[1])) {
        echo 'This script requires 1 argument (the directory containing .php files)';
        return 1;
    } else {
        $dir = $argv[1];
    }
    foreach (php_files($dir) as $file) {
        print "{$file}\n";
        $nodes = parse_php(file_get_contents($dir . DIRECTORY_SEPARATOR . $file));
        print pretty_print($nodes);
        print "\n";
    }
    return 0;
}
function display($persona)
{
    global $service;
    $json = new Services_JSON();
    $persona->get_configuration_data();
    $service = $persona->configuration_data->service;
    $properties =& PersonaProperty::load_persona_properties($persona->persona_id);
    $propertyCount = count($properties);
    echo '<p class="header">' . $persona->name . ' (' . $service . ')</p>';
    if (!$propertyCount) {
        echo "<p>No data available</p>";
    } else {
        echo '<ul class="personaproperties" id="' . $service . '">';
        foreach ($properties as $k => $property) {
            $content = $json->decode($property->content);
            if (count($content)) {
                $viewer = $property->viewer;
                if ($service == 'Facebook' && $viewer == 'Friends') {
                    $content = reformat_facebook($content);
                    $viewer = 'FriendList';
                } else {
                    if ($service == 'Flickr' && $viewer == 'Friends') {
                        $content = reformat_flickr($content);
                        $viewer = 'FriendList';
                    } else {
                        if ($property->name == 'Status') {
                            $viewer = 'Status';
                        }
                    }
                }
                echo '<li><p class="header">' . $property->name . " (type: " . $viewer . "): </p>";
                // primitive adaptive rendering:
                if (is_callable($viewer)) {
                    // do we have a function of that name?
                    $viewer($content);
                } else {
                    pretty_print($content);
                }
                echo '</li>';
            }
        }
        echo '</ul>';
    }
}
Example #3
0
 /**
  * Runs Custom or Visual SQL query
  */
 public function runquery()
 {
     $printArray = '';
     $query = $_POST['cquery'];
     if (isset($_POST['printArray'])) {
         $printArray = pretty_print($_POST, false, true);
     }
     // table columns
     $stmt = Flight::get('db')->query("DESCRIBE " . Flight::get('lastSegment'));
     $columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
     //pretty_print($columns);
     $fields = array();
     foreach ($columns as $values) {
         if (isset($values['Field'])) {
             $fields[] = $values['Field'];
         }
     }
     //pretty_print($fields);
     // for custom query
     if ($query) {
         self::runQueryWithView($query, $fields, $printArray);
     } else {
         $query = 'SELECT ';
         // find out which fields to SELECT
         if (array_key_exists('fields', $_POST) && count($_POST['fields'])) {
             $total = count($_POST['fields']);
             $duplicateNameFields = array();
             $counter = 0;
             foreach ($_POST['fields'] as $value) {
                 $counter++;
                 if ($value) {
                     $duplicateNameFields[] = $value;
                     // apply AS keyword for same field names from different tables
                     if (in_array($value, $duplicateNameFields)) {
                         $fieldArray = explode('.', $value);
                         $tableName = $fieldArray[0];
                         $fieldName = $fieldArray[1];
                         $value = $value . ' AS ' . $tableName . '_' . $fieldName;
                     }
                     if ($total === $counter) {
                         $query .= $value;
                     } else {
                         $query .= $value . ', ';
                     }
                 }
             }
         }
         $query .= ' FROM `' . Flight::get('lastSegment') . '`';
         // find out which tables to JOIN
         if (array_key_exists('jointype', $_POST) && count($_POST['jointype'])) {
             $counter = 0;
             foreach ($_POST['jointype'] as $key => $value) {
                 $counter++;
                 if (!$value) {
                     continue;
                 }
                 $primaryTable = Flight::get('lastSegment');
                 $query .= ' ' . $value . ' ';
                 // build ON table join clause
                 if ($_POST['jointable'][$key]) {
                     $query .= $_POST['jointable'][$key];
                     $query .= ' ON ' . $primaryTable . '.`' . $_POST['joinfieldp'][$key] . '` = ' . $_POST['jointable'][$key] . '.`' . $_POST['joinfield'][$key] . '`';
                 }
             }
         }
         // find out which fields/conditions to put in in WHERE clause
         if (array_key_exists('fname', $_POST) && count($_POST['fname'])) {
             $total = count($_POST['fname']);
             $query .= ' WHERE ';
             $counter = 0;
             foreach ($_POST['fname'] as $key => $value) {
                 $counter++;
                 if ($_POST['fvalue'][$key]) {
                     if ($total === $counter) {
                         $query .= $value . $_POST['fvalue'][$key];
                     } else {
                         $query .= $value . $_POST['fvalue'][$key] . ' ' . $_POST['ftype'][$key + 1] . ' ';
                     }
                 }
             }
         }
         // find out GROUP BY fields
         if (array_key_exists('groupfields', $_POST) && count($_POST['groupfields'])) {
             $query .= ' GROUP BY ';
             $query .= implode(', ', $_POST['groupfields']);
         }
         // find out ORDER BY fields
         if (array_key_exists('orderfields', $_POST) && count($_POST['orderfields'])) {
             $query .= ' ORDER BY ';
             $query .= implode(', ', $_POST['orderfields']);
             if (array_key_exists('chkDescending', $_POST) && $_POST['chkDescending']) {
                 $query .= ' DESC ';
             }
         }
         // find out LIMIT clause details
         if (array_key_exists('limitStart', $_POST) && $_POST['limitStart']) {
             $query .= ' LIMIT ' . $_POST['limitStart'];
             if (array_key_exists('limitNumRows', $_POST) && $_POST['limitNumRows']) {
                 $query .= ', ' . $_POST['limitNumRows'];
             }
         }
         $query = self::fixQuery($query);
         // run query and render view
         self::runQueryWithView($query, $fields, $printArray);
     }
 }
Example #4
0
 protected function output_container($pp, $level, &$var)
 {
     parent::output_container($pp, $level + 1, $var);
     if ($this->issued) {
         pretty_print("<dcterms:issued>" . $this->issued . "</dcterms:issued>", $pp, $level + 1, $var);
     }
     if ($this->publisher) {
         pretty_print("<dcterms:publisher>" . my_escape($this->publisher) . "</dcterms:publisher>", $pp, $level + 1, $var);
     }
     foreach ($this->categories as &$category) {
         $str = "<category term='" . my_escape($category["term"]) . "'";
         if ($category["scheme"]) {
             $str .= " scheme='" . my_escape($category["scheme"]) . "'";
         }
         if ($category["label"]) {
             $str .= " label='" . my_escape($category["label"]) . "'";
         }
         $str .= "/>";
         pretty_print($str, $pp, $level + 1, $var);
     }
     unset($category);
     foreach ($this->subjects as &$subject) {
         if ($subject["type"]) {
             pretty_print("<dcterms:subject xsi:type='" . $subject["type"] . "'>" . my_escape($subject["subject"]) . "</dcterms:subject>", $pp, $level + 1, $var);
         } else {
             pretty_print("<dcterms:subject>" . my_escape($subject["subject"]) . "</dcterms:subject>", $pp, $level + 1, $var);
         }
     }
     unset($subject);
     foreach ($this->summaries as &$summary) {
         pretty_print("<summary type='" . $summary["type"] . "'>" . my_escape($summary["summary"]) . "</summary>", $pp, $level + 1, $var);
     }
     unset($summary);
 }
Example #5
0
function lookup($sourceId, $cuv, $fd)
{
    if (!source_exists($sourceId)) {
        socket_write($fd, "550 invalid database, use SHOW DB for a list\r\n");
        return;
    }
    if ($sourceId == '*' || $sourceId == '!') {
        $sourceId = 0;
    }
    $cuv = StringUtil::cleanupQuery($cuv);
    $arr = StringUtil::analyzeQuery($cuv);
    $field = $arr[0] ? 'formNoAccent' : 'formUtf8General';
    $lexems = db_find(new Lexem(), "{$field} = '{$cuv}' order by formNoAccent");
    $definitions = Definition::loadForLexems($lexems, $sourceId, $cuv);
    $searchResults = SearchResult::mapDefinitionArray($definitions);
    if (!count($definitions)) {
        socket_write($fd, "552 no match\r\n");
        return;
    }
    socket_write($fd, "150 " . count($definitions) . " definition(s) found\r\n");
    foreach ($searchResults as $sr) {
        $def = pretty_print($sr->definition->internalRep);
        socket_write($fd, "151 \"" . $cuv . "\" " . $sr->source->id . " \"" . $sr->source->name . "\"\r\n");
        socket_write($fd, "{$cuv}\r\n{$def}");
        socket_write($fd, ".\r\n");
    }
    socket_write($fd, "250 ok\r\n");
}
Example #6
0
            $json = $RamcoAPI->sendMessage();
            $class_result = json_decode($json, true);
        }
        if (!isset($classes["Data"][$i]["MAR_checkinlink"])) {
            echo "wheres my checkin";
            $guid = $classes['Data'][$i]['cobalt_classId'];
            $shorturl_mobile = shortURL(MOBILE_CHECKIN_LINK . "?guid=" . $guid . "&type=class");
            echo "<br>Short Mobile Checkin link: {$shorturl_mobile}  <br>";
            $RamcoAPI->clearVars();
            $RamcoAPI->setOperation("UpdateEntity");
            $RamcoAPI->setGUID($guid);
            $RamcoAPI->setEntity("cobalt_class");
            $RamcoAPI->setAttributeValues("MAR_checkinlink={$shorturl_mobile}");
            $json = $RamcoAPI->sendMessage();
            $class_mobile_result = json_decode($json, true);
            pretty_print($class_mobile_result);
        }
    }
}
// Output a message at the end of the file
echo "<br>End of file.<br />";
function shortURL($longURL)
{
    // This is the URL you want to shorten
    // Get API key from : http://code.google.com/apis/console/
    $apiKey = '';
    $postData = array('longUrl' => $longURL, 'key' => $apiKey);
    $jsonData = json_encode($postData);
    $curlObj = curl_init();
    curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key=' . $apiKey);
    curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
Example #7
0
// if you SET the PARAMETER equal to something it will be the DEFAULT ARGUMENT ex) 'buddy'
function say_hello($name_ex = 'buddy')
{
    // $name is the value we would accept from the say_hello function (PARAMETER)
    return "Hi, there {$name_ex} <br>";
}
$greeting = say_hello();
// We can pass in a value to the say_hello function (ARGUMENT)
echo $greeting;
// EXAMPLE #2:
// Real world example: We don't want to echo a <pre></pre> EVERY TIME we need to do the below (in comments)
$arr = array('name' => 'Joe', 'age' => 40, 'occupation' => 'teacher');
// echo '<pre>'; // Recognizes code formatting
// print_r($arr);
// echo '</pre>';
pretty_print($arr);
// Call the function (in functions.php) and pass in the $arr
// EXAMPLE #3
// MULTI-DIMENSIONAL ARRAY that gets the names "plucked" from them
$people = array(array('name' => 'Lucas', 'age' => 29, 'occupation' => 'software developer'), array('name' => 'Joe', 'age' => 50, 'occupation' => 'teacher'), array('name' => 'Jane', 'age' => 30, 'occupation' => 'marketting'));
// If we change the 1st ARGUMENT,  we can get any one of the KEYS (name, age, or occupation) from the Multi. Dimens. Array
$plucked = array_pluck('name', $people);
// Figure out how you want to CALL the FUNCTION BEFORE you right the logic for it
// Ideally we want to return an array('Lucas', 'Joe', 'Jane')
print_r($plucked);
// print the $plucked variable to the screen
// EXAMPLE #4
// MULTI-DIMENSIONAL ARRAY version 2 --- USING ARRAYMAP()
// ARRAYMAP() - gives us a function we can execute each time, which gives us a function to manipulate
// Function declared in this file for convenience
function array_grab($toGrab, $arr2)
Example #8
0
function plagiarism_urkund_pretty_print($arr)
{
    if (is_object($arr)) {
        $arr = (array) $arr;
    }
    $retstr = '<table class="generaltable">';
    $retstr .= '<tr><th width=20%>Key</th><th width=80%>Value</th></tr>';
    if (is_array($arr)) {
        foreach ($arr as $key => $val) {
            if (is_object($val)) {
                $val = (array) $val;
            }
            if (is_array($val)) {
                $retstr .= '<tr><td>' . $key . '</td><td>' . pretty_print($val) . '</td></tr>';
            } else {
                $retstr .= '<tt><td>' . $key . '</td><td>' . ($val == '' ? '""' : $val) . '</td></tr>';
            }
        }
    }
    $retstr .= '</table>';
    return $retstr;
}
Example #9
0
 public function twitter_auth()
 {
     $this->load->library("TwitterAuth");
     # The TwitterOAuth instance
     $twitteroauth = new TwitterOAuth($this->twitter_consumer_key, $this->twitter_secret_key);
     # Requesting authentication tokens, the parameter is the URL we will be redirected to
     $request_token = $twitteroauth->getRequestToken('http://jagamana.besaba.com/oauth/twitter_oauth');
     pretty_print($request_token);
     # Saving them into the session
     $this->session->set_userdata("oauth_token", $request_token['oauth_token']);
     $this->session->set_userdata("oauth_token_secret", $request_token['oauth_token_secret']);
     # If everything goes well..
     if ($twitteroauth->http_code == 200) {
         # Let's generate the URL and redirect
         $url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
         //redirect($url);
     } else {
         # It's a bad idea to kill the script, but we've got to know when there's an error.
         die('Something wrong happened.');
     }
 }