Exemplo n.º 1
0
 public function process()
 {
     $where = array('namespace' => $this->getProperty('namespace'), 'topic' => $this->getProperty('topic'), 'language' => $this->getProperty('language'));
     $search = $this->getProperty('search');
     if (!empty($search)) {
         $where[] = array('name:LIKE' => '%' . $search . '%', 'OR:value:LIKE' => '%' . $search . '%');
     }
     /* setup query for db based lexicons */
     $c = $this->modx->newQuery('modLexiconEntry');
     $c->where($where);
     $c->sortby('name', 'ASC');
     $results = $this->modx->getCollection('modLexiconEntry', $c);
     $dbEntries = array();
     /** @var modLexiconEntry $r */
     foreach ($results as $r) {
         $dbEntries[$r->get('name')] = $r->toArray();
     }
     /* first get file-based lexicon */
     $entries = $this->modx->lexicon->getFileTopic($this->getProperty('language'), $this->getProperty('namespace'), $this->getProperty('topic'));
     $entries = is_array($entries) ? $entries : array();
     /* if searching */
     if (!empty($search)) {
         function parseArray($needle, array $haystack = array())
         {
             if (!is_array($haystack)) {
                 return false;
             }
             $results = array();
             foreach ($haystack as $key => $value) {
                 if (strpos($key, $needle) !== false || strpos($value, $needle) !== false) {
                     $results[$key] = $value;
                 }
             }
             return $results;
         }
         $entries = parseArray($search, $entries);
     }
     /* add in unique entries */
     $es = array_diff(array_keys($dbEntries), array_keys($entries));
     foreach ($es as $n) {
         $entries[$n] = $dbEntries[$n]['value'];
     }
     $count = count($entries);
     ksort($entries);
     $entries = array_slice($entries, $this->getProperty('start'), $this->getProperty('limit'), true);
     /* loop through */
     $list = array();
     foreach ($entries as $name => $value) {
         $entryArray = array('name' => $name, 'value' => $value, 'namespace' => $this->getProperty('namespace'), 'topic' => $this->getProperty('topic'), 'language' => $this->getProperty('language'), 'createdon' => null, 'editedon' => null, 'overridden' => 0);
         /* if override in db, load */
         if (array_key_exists($name, $dbEntries)) {
             $entryArray = array_merge($entryArray, $dbEntries[$name]);
             $entryArray['editedon'] = $entryArray['editedon'] == '0000-00-00 00:00:00' || $entryArray['editedon'] == '-001-11-30 00:00:00' || empty($entryArray['editedon']) ? strftime('%b %d, %Y %I:%M %p', strtotime($entryArray['createdon'])) : strftime('%b %d, %Y %I:%M %p', strtotime($entryArray['editedon']));
             $entryArray['overridden'] = 1;
         }
         $list[] = $entryArray;
     }
     return $this->outputArray($list, $count);
 }
Exemplo n.º 2
0
        } else {
            if ($ifNoMatchReturnFalse === true) {
                return false;
            } else {
                $format = str_replace($match[0], null, $format);
            }
        }
    }
    return $format;
}
//$input = "poziom 0 [%(gzip_buffers) [poziom 2[poziom 3]%(gzip_buffers_inny)] poziom 1] poziom 0 [znowu poziom 1] 0 [poziom 1 %(dupeczka)[znowu poziom 2 [znowu poziom 3]]] koncowkaLVL0";
//$formatArray = StackUp($input);
$listFormat = array("gzip_buffers" => 40, "gzip_yeah" => 'yeah!');
$toFormat = '[[gzip_buffers %(gzip_buffers)[[ %(gzip_yeah)]]; this should still be here]]';
$formatArray = StackUp($toFormat, '[[', ']]');
$parsed = parseArray($formatArray, $listFormat);
echo r_implode(null, $parsed);
//var_dump($formatArray);
//var_dump($parsed);
//$out = parse('kapucha %(gzip_buffers)s %(gzip_buffers_inny)s', $listFormat);
//echo $out;
//unset($output[2]);
//echo r_implode( '', $output ) . "\n";
//$input = "poziom 0 [poziom 1 [poziom 2[poziom 3]poziom 2] poziom 1] poziom 0 [jeszcze inno] [innoLVL1 [wnetrzeLVL2] zewnetrzeLVL1] i zero";
//$input = "poziom 0 [poziom 1 [poziom 2 [poziom 3] 2 [inny poziom 3] poziom 2] 1 [alt2 [trzy] poziom 2 alt [trzy alt] alt2] poziom 1] poziom 0";
//$input = "0[1]0[1]0[1]0[1[2]1]";
//$toFormat = '[[gzip_buffers %(gzip_buffers_num)s %(gzip_buffers_size)s;]]';
//$toFormat = '[[ gzip_buffers %(gzip_buffers)s[[ %(gzip_buffers_s)s]]; this should here ]]';
$toFormat = ' [[a[[balabolka]][[c[[xawery]]C]]AB]] [[lolzS [[masakra]] lolzZ]] [[d[[e]]f]] tu tez';
//ParseTools::sprintfnnew($toFormat, $listFormat);
//ParseTools::RemoveBracket($toFormat, 1);
Exemplo n.º 3
0
 public function process()
 {
     $amountCultureKeys = $this->modx->getCount('modContextSetting', array('key' => 'cultureKey'));
     if ($amountCultureKeys == 0) {
         return;
     }
     $ckObject = $this->modx->getObject('modContextSetting', array('key' => 'cultureKey', 'context_key' => 'web'));
     $defaultCultureKey = 'en';
     if ($ckObject) {
         $defaultCultureKey = $ckObject->get('value');
     }
     $defaultEntries = $this->modx->lexicon->getFileTopic($defaultCultureKey, $this->getProperty('namespace'), $this->getProperty('topic'));
     $defaultEntries = is_array($defaultEntries) ? $defaultEntries : array();
     foreach ($defaultEntries as $name => $value) {
         $defEntryArray = array('name' => $name, 'value' => $value, 'namespace' => $this->getProperty('namespace'), 'topic' => $this->getProperty('topic'), 'language' => $this->getProperty('language'), 'createdon' => null, 'editedon' => null, 'overridden' => 0);
         //Check if lexicon already exists inside DB
         $check = $this->modx->getObject('modLexiconEntry', array('name' => $name, 'namespace' => $this->getProperty('namespace'), 'topic' => $this->getProperty('topic'), 'language' => $this->getProperty('language')));
         if ($check) {
             continue;
         }
         $new = $this->modx->newObject('modLexiconEntry');
         $new->fromArray($defEntryArray);
         $new->save();
     }
     $where = array('namespace' => $this->getProperty('namespace'), 'topic' => $this->getProperty('topic'), 'language' => $this->getProperty('language'));
     $search = $this->getProperty('search');
     if (!empty($search)) {
         $where[] = array('name:LIKE' => '%' . $search . '%', 'OR:value:LIKE' => '%' . $search . '%');
     }
     /* setup query for db based lexicons */
     $c = $this->modx->newQuery('modLexiconEntry');
     $c->where($where);
     $c->sortby('name', 'ASC');
     $results = $this->modx->getCollection('modLexiconEntry', $c);
     $dbEntries = array();
     /** @var modLexiconEntry $r */
     foreach ($results as $r) {
         $dbEntries[$r->get('name')] = $r->toArray();
     }
     /* first get file-based lexicon */
     $entries = $this->modx->lexicon->getFileTopic($this->getProperty('language'), $this->getProperty('namespace'), $this->getProperty('topic'));
     $entries = is_array($entries) ? $entries : array();
     /* if searching */
     if (!empty($search)) {
         function parseArray($needle, array $haystack = array())
         {
             if (!is_array($haystack)) {
                 return false;
             }
             $results = array();
             foreach ($haystack as $key => $value) {
                 if (strpos($key, $needle) !== false || strpos($value, $needle) !== false) {
                     $results[$key] = $value;
                 }
             }
             return $results;
         }
         $entries = parseArray($search, $entries);
     }
     /* add in unique entries */
     $es = array_diff(array_keys($dbEntries), array_keys($entries));
     foreach ($es as $n) {
         $entries[$n] = $dbEntries[$n]['value'];
     }
     $count = count($entries);
     ksort($entries);
     $entries = array_slice($entries, $this->getProperty('start'), $this->getProperty('limit'), true);
     /* loop through */
     $list = array();
     foreach ($entries as $name => $value) {
         $entryArray = array('name' => $name, 'value' => $value, 'namespace' => $this->getProperty('namespace'), 'topic' => $this->getProperty('topic'), 'language' => $this->getProperty('language'), 'createdon' => null, 'editedon' => null, 'overridden' => 0);
         /* if override in db, load */
         if (array_key_exists($name, $dbEntries)) {
             $entryArray = array_merge($entryArray, $dbEntries[$name]);
             $entryArray['editedon'] = strtotime($entryArray['editedon']) ? strtotime($entryArray['editedon']) : strtotime($entryArray['createdon']);
             $entryArray['overridden'] = 1;
         }
         $list[] = $entryArray;
     }
     return $this->outputArray($list, $count);
 }
Exemplo n.º 4
0
/**
 * Parses a fetch response, currently it can hande FLAGS, HEADERS, RFC822.SIZE, INTERNALDATE and UID
 * @param array    $aResponse Imap response
 * @param array    $aMessageList Placeholder array for results. The keys of the
 *                 placeholder array should be the UID so we can reconstruct the order.
 * @return array   $aMessageList associative array with messages. Key is the UID, value is an associative array
 * @author Marc Groot Koerkamp
 */
function parseFetch(&$aResponse, $aMessageList = array())
{
    for ($j = 0, $iCnt = count($aResponse); $j < $iCnt; ++$j) {
        $aMsg = array();
        $read = implode('', $aResponse[$j]);
        // free up memmory
        unset($aResponse[$j]);
        /* unset does not reindex the array. the for loop is safe */
        /*
         * #id<space>FETCH<space>(
         */
        /* extract the message id */
        $i_space = strpos($read, ' ', 2);
        /* position 2ed <space> */
        $id = substr($read, 2, $i_space - 2);
        $aMsg['ID'] = $id;
        $fetch = substr($read, $i_space + 1, 5);
        if (!is_numeric($id) && $fetch !== 'FETCH') {
            $aMsg['ERROR'] = $read;
            // sm_encode_html_special_chars should be done just before display. this is backend code
            break;
        }
        $i = strpos($read, '(', $i_space + 5);
        $read = substr($read, $i + 1);
        $i_len = strlen($read);
        $i = 0;
        while ($i < $i_len && $i !== false) {
            /* get argument */
            $read = trim(substr($read, $i));
            $i_len = strlen($read);
            $i = strpos($read, ' ');
            $arg = substr($read, 0, $i);
            ++$i;
            /*
             * use allcaps for imap items and lowcaps for headers as key for the $aMsg array
             */
            switch ($arg) {
                case 'UID':
                    $i_pos = strpos($read, ' ', $i);
                    if (!$i_pos) {
                        $i_pos = strpos($read, ')', $i);
                    }
                    if ($i_pos) {
                        $unique_id = substr($read, $i, $i_pos - $i);
                        $i = $i_pos + 1;
                    } else {
                        break 3;
                    }
                    break;
                case 'FLAGS':
                    $flags = parseArray($read, $i);
                    if (!$flags) {
                        break 3;
                    }
                    $aFlags = array();
                    foreach ($flags as $flag) {
                        $flag = strtolower($flag);
                        $aFlags[$flag] = true;
                    }
                    $aMsg['FLAGS'] = $aFlags;
                    break;
                case 'RFC822.SIZE':
                    $i_pos = strpos($read, ' ', $i);
                    if (!$i_pos) {
                        $i_pos = strpos($read, ')', $i);
                    }
                    if ($i_pos) {
                        $aMsg['SIZE'] = substr($read, $i, $i_pos - $i);
                        $i = $i_pos + 1;
                    } else {
                        break 3;
                    }
                    break;
                case 'ENVELOPE':
                    // sqimap_parse_address($read,$i,$aMsg);
                    break;
                    // to be implemented, moving imap code out of the Message class
                // to be implemented, moving imap code out of the Message class
                case 'BODYSTRUCTURE':
                    break;
                    // to be implemented, moving imap code out of the Message class
                // to be implemented, moving imap code out of the Message class
                case 'INTERNALDATE':
                    $aMsg['INTERNALDATE'] = trim(str_replace('  ', ' ', parseString($read, $i)));
                    break;
                case 'BODY.PEEK[HEADER.FIELDS':
                case 'BODY[HEADER.FIELDS':
                    $i = strpos($read, '{', $i);
                    // header is always returned as literal because it contain \n characters
                    $header = parseString($read, $i);
                    if ($header === false) {
                        break 2;
                    }
                    /* First we replace all \r\n by \n, and unfold the header */
                    $hdr = trim(str_replace(array("\r\n", "\n\t", "\n "), array("\n", ' ', ' '), $header));
                    /* Now we can make a new header array with
                       each element representing a headerline  */
                    $aHdr = explode("\n", $hdr);
                    $aReceived = array();
                    foreach ($aHdr as $line) {
                        $pos = strpos($line, ':');
                        if ($pos > 0) {
                            $field = strtolower(substr($line, 0, $pos));
                            if (!strstr($field, ' ')) {
                                /* valid field */
                                $value = trim(substr($line, $pos + 1));
                                switch ($field) {
                                    case 'date':
                                        $aMsg['date'] = trim(str_replace('  ', ' ', $value));
                                        break;
                                    case 'x-priority':
                                        $aMsg['x-priority'] = $value ? (int) $value[0] : 3;
                                        break;
                                    case 'priority':
                                    case 'importance':
                                        // duplicate code with Rfc822Header.cls:parsePriority()
                                        if (!isset($aMsg['x-priority'])) {
                                            $aPrio = preg_split('/\\s/', trim($value));
                                            $sPrio = strtolower(array_shift($aPrio));
                                            if (is_numeric($sPrio)) {
                                                $iPrio = (int) $sPrio;
                                            } elseif ($sPrio == 'non-urgent' || $sPrio == 'low') {
                                                $iPrio = 5;
                                            } elseif ($sPrio == 'urgent' || $sPrio == 'high') {
                                                $iPrio = 1;
                                            } else {
                                                // default is normal priority
                                                $iPrio = 3;
                                            }
                                            $aMsg['x-priority'] = $iPrio;
                                        }
                                        break;
                                    case 'content-type':
                                        $type = $value;
                                        if ($pos = strpos($type, ";")) {
                                            $type = substr($type, 0, $pos);
                                        }
                                        $type = explode("/", $type);
                                        if (!is_array($type) || count($type) < 2) {
                                            $aMsg['content-type'] = array('text', 'plain');
                                        } else {
                                            $aMsg['content-type'] = array(strtolower($type[0]), strtolower($type[1]));
                                        }
                                        break;
                                    case 'received':
                                        $aMsg['received'][] = $value;
                                        break;
                                    default:
                                        $aMsg[$field] = $value;
                                        break;
                                }
                            }
                        }
                    }
                    break;
                default:
                    ++$i;
                    break;
            }
        }
        if (!empty($unique_id)) {
            $msgi = "{$unique_id}";
            $aMsg['UID'] = $unique_id;
        } else {
            $msgi = '';
        }
        $aMessageList[$msgi] = $aMsg;
        $aResponse[$j] = NULL;
    }
    return $aMessageList;
}
Exemplo n.º 5
0
/* if searching */
if (!empty($scriptProperties['search'])) {
    function parseArray($needle, array $haystack = array())
    {
        if (!is_array($haystack)) {
            return false;
        }
        $results = array();
        foreach ($haystack as $key => $value) {
            if (strpos($key, $needle) !== false || strpos($value, $needle) !== false) {
                $results[$key] = $value;
            }
        }
        return $results;
    }
    $entries = parseArray($scriptProperties['search'], $entries);
    $where[] = array('name:LIKE' => '%' . $scriptProperties['search'] . '%', 'OR:value:LIKE' => '%' . $scriptProperties['search'] . '%');
}
$count = count($entries);
/* add in unique entries */
$es = array_diff_assoc($dbEntries, $entries);
foreach ($es as $n => $entryArray) {
    $entries[$n] = $entryArray['value'];
}
ksort($entries);
$entries = array_slice($entries, $start, $limit, true);
/* loop through */
$list = array();
foreach ($entries as $name => $value) {
    $entryArray = array('name' => $name, 'value' => $value, 'namespace' => $namespace, 'topic' => $topic, 'language' => $language, 'createdon' => null, 'editedon' => null, 'overridden' => 0);
    /* if override in db, load */
Exemplo n.º 6
0
/**
 * Retrieves a list with headers, flags, size or internaldate from the imap server
 */
function sqimap_get_small_header_list($imap_stream, $msg_list, $show_num = false)
{
    global $squirrelmail_language, $color, $data_dir, $username, $imap_server_type;
    global $uid_support, $allow_server_sort;
    /* Get the small headers for each message in $msg_list */
    $maxmsg = sizeof($msg_list);
    if ($show_num != '999999') {
        $msgs_str = sqimap_message_list_squisher($msg_list);
    } else {
        $msgs_str = '1:*';
    }
    $messages = array();
    $read_list = array();
    /*
     * We need to return the data in the same order as the caller supplied
     * in $msg_list, but IMAP servers are free to return responses in
     * whatever order they wish... So we need to re-sort manually
     */
    for ($i = 0; $i < sizeof($msg_list); $i++) {
        $messages["{$msg_list[$i]}"] = array();
    }
    $internaldate = getPref($data_dir, $username, 'internal_date_sort', SMPREF_ON);
    if ($internaldate) {
        $query = "FETCH {$msgs_str} (FLAGS UID RFC822.SIZE INTERNALDATE BODY.PEEK[HEADER.FIELDS (Date To Cc From Subject X-Priority Importance Priority Content-Type)])";
    } else {
        $query = "FETCH {$msgs_str} (FLAGS UID RFC822.SIZE BODY.PEEK[HEADER.FIELDS (Date To Cc From Subject X-Priority Importance Priority Content-Type)])";
    }
    $read_list = sqimap_run_command_list($imap_stream, $query, true, $response, $message, $uid_support);
    $i = 0;
    foreach ($read_list as $r) {
        /* initialize/reset vars */
        $subject = _("(no subject)");
        $from = _("Unknown Sender");
        $priority = 0;
        $messageid = '<>';
        $type = array('', '');
        $cc = $to = $inrepto = '';
        $size = 0;
        // use unset because we do isset below
        unset($date);
        $flag_seen = $flag_answered = $flag_deleted = $flag_flagged = false;
        $read = implode('', $r);
        /*
         * #id<space>FETCH<space>(
         */
        /* extract the message id */
        $i_space = strpos($read, ' ', 2);
        $id = substr($read, 2, $i_space - 2);
        $fetch = substr($read, $i_space + 1, 5);
        if (!is_numeric($id) && $fetch !== 'FETCH') {
            set_up_language($squirrelmail_language);
            echo '<br /><b><font color="' . $color[2] . '">' . _("ERROR: Could not complete request.") . '</b><br />' . _("Unknown response from IMAP server:") . ' 1.' . htmlspecialchars($read) . "</font><br />\n";
            break;
        }
        $i = strpos($read, '(', $i_space + 5);
        $read = substr($read, $i + 1);
        $i_len = strlen($read);
        $i = 0;
        while ($i < $i_len && $i !== false) {
            /* get argument */
            $read = trim(substr($read, $i));
            $i_len = strlen($read);
            $i = strpos($read, ' ');
            $arg = substr($read, 0, $i);
            ++$i;
            switch ($arg) {
                case 'UID':
                    $i_pos = strpos($read, ' ', $i);
                    if (!$i_pos) {
                        $i_pos = strpos($read, ')', $i);
                    }
                    if ($i_pos) {
                        $unique_id = substr($read, $i, $i_pos - $i);
                        $i = $i_pos + 1;
                    } else {
                        break 3;
                    }
                    break;
                case 'FLAGS':
                    $flags = parseArray($read, $i);
                    if (!$flags) {
                        break 3;
                    }
                    foreach ($flags as $flag) {
                        $flag = strtolower($flag);
                        switch ($flag) {
                            case '\\seen':
                                $flag_seen = true;
                                break;
                            case '\\answered':
                                $flag_answered = true;
                                break;
                            case '\\deleted':
                                $flag_deleted = true;
                                break;
                            case '\\flagged':
                                $flag_flagged = true;
                                break;
                            default:
                                break;
                        }
                    }
                    break;
                case 'RFC822.SIZE':
                    $i_pos = strpos($read, ' ', $i);
                    if (!$i_pos) {
                        $i_pos = strpos($read, ')', $i);
                    }
                    if ($i_pos) {
                        $size = substr($read, $i, $i_pos - $i);
                        $i = $i_pos + 1;
                    } else {
                        break 3;
                    }
                    break;
                case 'INTERNALDATE':
                    $date = parseString($read, $i);
                    //if ($tmpdate === false) break 3;
                    //$tmpdate = str_replace('  ',' ',$tmpdate);
                    //$tmpdate = explode(' ',$tmpdate);
                    //$date = str_replace('-',' ',$tmpdate[0]) . " " .
                    //                            $tmpdate[1] . ' ' . $tmpdate[2];
                    break;
                case 'BODY.PEEK[HEADER.FIELDS':
                case 'BODY[HEADER.FIELDS':
                    $i = strpos($read, '{', $i);
                    $header = parseString($read, $i);
                    if ($header === false) {
                        break 2;
                    }
                    /* First we replace all \r\n by \n, and unfold the header */
                    $hdr = trim(str_replace(array("\r\n", "\n\t", "\n "), array("\n", ' ', ' '), $header));
                    /* Now we can make a new header array with */
                    /* each element representing a headerline  */
                    $hdr = explode("\n", $hdr);
                    foreach ($hdr as $line) {
                        $pos = strpos($line, ':');
                        if ($pos > 0) {
                            $field = strtolower(substr($line, 0, $pos));
                            if (!strstr($field, ' ')) {
                                /* valid field */
                                $value = trim(substr($line, $pos + 1));
                                switch ($field) {
                                    case 'to':
                                        $to = $value;
                                        break;
                                    case 'cc':
                                        $cc = $value;
                                        break;
                                    case 'from':
                                        $from = $value;
                                        break;
                                    case 'date':
                                        $date = $value;
                                        break;
                                    case 'x-priority':
                                    case 'importance':
                                    case 'priority':
                                        $priority = parsePriority($value);
                                        break;
                                    case 'subject':
                                        $subject = $value;
                                        if ($subject == "") {
                                            $subject = _("(no subject)");
                                        }
                                        break;
                                    case 'content-type':
                                        $type = strtolower($value);
                                        if ($pos = strpos($type, ";")) {
                                            $type = substr($type, 0, $pos);
                                        }
                                        $type = explode("/", $type);
                                        if (empty($type[0])) {
                                            $type[0] = 'text';
                                            // I had this added, but not committed to CVS.... did it help fix something?
                                            //                                    $type[1] = 'plain';
                                        }
                                        if (empty($type[1])) {
                                            $type[1] = 'plain';
                                        }
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }
                    }
                    break;
                default:
                    ++$i;
                    break;
            }
        }
        if (isset($date)) {
            $date = str_replace('  ', ' ', $date);
            $tmpdate = explode(' ', trim($date));
        } else {
            $tmpdate = $date = array();
        }
        if ($uid_support) {
            $msgi = "{$unique_id}";
            $messages[$msgi]['ID'] = $unique_id;
        } else {
            $msgi = "{$id}";
            $messages[$msgi]['ID'] = $id;
        }
        $messages[$msgi]['TIME_STAMP'] = getTimeStamp($tmpdate);
        $messages[$msgi]['DATE_STRING'] = getDateString($messages[$msgi]['TIME_STAMP']);
        $messages[$msgi]['FROM'] = $from;
        //parseAddress($from);
        $messages[$msgi]['SUBJECT'] = $subject;
        //        if (handleAsSent($mailbox)) {
        $messages[$msgi]['TO'] = $to;
        //parseAddress($to);
        //        }
        $messages[$msgi]['PRIORITY'] = $priority;
        $messages[$msgi]['CC'] = $cc;
        //parseAddress($cc);
        $messages[$msgi]['SIZE'] = $size;
        $messages[$msgi]['TYPE0'] = $type[0];
        $messages[$msgi]['TYPE1'] = $type[1];
        $messages[$msgi]['FLAG_DELETED'] = $flag_deleted;
        $messages[$msgi]['FLAG_ANSWERED'] = $flag_answered;
        $messages[$msgi]['FLAG_SEEN'] = $flag_seen;
        $messages[$msgi]['FLAG_FLAGGED'] = $flag_flagged;
        /* non server sort stuff */
        if (!$allow_server_sort) {
            $from = parseAddress($from);
            if ($from[0][1]) {
                $from = decodeHeader($from[0][1], true, false);
            } else {
                $from = $from[0][0];
            }
            $messages[$msgi]['FROM-SORT'] = $from;
            $subject_sort = strtolower(decodeHeader($subject, true, false));
            if (preg_match("/^(?:(?:vedr|sv|re|aw|fw|fwd|\\[\\w\\]):\\s*)*\\s*(.*)\$/si", $subject_sort, $matches)) {
                $messages[$msgi]['SUBJECT-SORT'] = $matches[1];
            } else {
                $messages[$msgi]['SUBJECT-SORT'] = $subject_sort;
            }
        }
        ++$msgi;
    }
    array_reverse($messages);
    $new_messages = array();
    foreach ($messages as $i => $message) {
        $new_messages[] = $message;
    }
    return $new_messages;
}
 public static function requestUpdateCategoria()
 {
     try {
         $categoria = $_POST['categoria'];
         $id_empreendimento = $_POST['id_empreendimento'];
         $CategoriaTO = new CategoriaTO();
         $CategoriaDao = new CategoriaDao();
         $ReferenciaIntegracaoDao = new ReferenciaIntegracaoDao();
         $ReferenciaIntegracaoTO = new ReferenciaIntegracaoTO();
         $ReferenciaIntegracaoTO->sistema_integrado = 'PrestaShop';
         $ReferenciaIntegracaoTO->tabela = 'tbl_categorias';
         $ReferenciaIntegracaoTO->id_item_referencia = $categoria['id'];
         $ReferenciaIntegracaoTO->tipo = 'categoria';
         $ReferenciaIntegracaoTO->id_empreendimento = $id_empreendimento;
         $referencia = $ReferenciaIntegracaoDao->refExists($ReferenciaIntegracaoTO, true);
         if ($categoria['id_parent'] > 2) {
             $ReferenciaIntegracaoParentTO = new ReferenciaIntegracaoTO();
             $ReferenciaIntegracaoParentTO->sistema_integrado = 'PrestaShop';
             $ReferenciaIntegracaoParentTO->tabela = 'tbl_categorias';
             $ReferenciaIntegracaoParentTO->id_item_referencia = $categoria['id_parent'];
             $ReferenciaIntegracaoParentTO->tipo = 'categoria';
             $ReferenciaIntegracaoParentTO->id_empreendimento = $id_empreendimento;
             $referenciaParent = $ReferenciaIntegracaoDao->refExists($ReferenciaIntegracaoParentTO, true);
         } else {
             $referenciaParent = array('id_item' => NULL);
         }
         if ($referencia && ($categoria['id_parent'] > 2 && $referenciaParent) || $referencia && $categoria['id_parent'] == 2) {
             $CategoriaTO = new CategoriaTO();
             $CategoriaDao = new CategoriaDao();
             $names = parseArray($categoria['name']);
             echo $referencia['id_item'];
             $CategoriaTO->id = $referencia['id_item'];
             $CategoriaTO->descricao_categoria = $names[1];
             $CategoriaTO->id_empreendimento = $id_empreendimento;
             $CategoriaTO->id_pai = !empty($categoria['id_parent']) ? $referenciaParent['id_item'] : NULL;
             if (!$CategoriaDao->updateCategoria($CategoriaTO)) {
                 throw new Exception('Erro ao atualizar categoria', 1);
             }
         } else {
             if (!$referencia) {
                 self::requestSaveCategoria();
                 return;
                 //throw new Exception('Não existe uma referencia para a categoria #'.$categoria['id'], 1);
             } else {
                 throw new Exception('Não existe uma referencia para a categoria pai #' . $categoria['id'], 1);
             }
         }
     } catch (Exception $e) {
         $log = new KLogger("logs/logErrorPrestaShop.txt", KLogger::DEBUG);
         $log->LogError($e->getMessage() . ' - line:' . $e->getLine());
         $log->LogDebug(json_encode($_POST));
         $log->LogJunp();
         Flight::halt(500, $e->getMessage());
     }
 }
/**
 * Parses a fetch response, currently it can hande FLAGS, HEADERS, RFC822.SIZE, INTERNALDATE and UID
 * @param array    $aResponse Imap response
 * @param array    $aMessageList Placeholder array for results. The keys of the
 *                 placeholder array should be the UID so we can reconstruct the order.
 * @return array   $aMessageList associative array with messages. Key is the UID, value is an associative array
 * @author Marc Groot Koerkamp
 */
function parseFetch($aResponse, $aMessageList = array())
{
    foreach ($aResponse as $r) {
        $msg = array();
        // use unset because we do isset below
        $read = implode('', $r);
        /*
         * #id<space>FETCH<space>(
         */
        /* extract the message id */
        $i_space = strpos($read, ' ', 2);
        $id = substr($read, 2, $i_space - 2);
        $msg['ID'] = $id;
        $fetch = substr($read, $i_space + 1, 5);
        if (!is_numeric($id) && $fetch !== 'FETCH') {
            $msg['ERROR'] = $read;
            // htmlspecialchars should be done just before display. this is backend code
            break;
        }
        $i = strpos($read, '(', $i_space + 5);
        $read = substr($read, $i + 1);
        $i_len = strlen($read);
        $i = 0;
        while ($i < $i_len && $i !== false) {
            /* get argument */
            $read = trim(substr($read, $i));
            $i_len = strlen($read);
            $i = strpos($read, ' ');
            $arg = substr($read, 0, $i);
            ++$i;
            switch ($arg) {
                case 'UID':
                    $i_pos = strpos($read, ' ', $i);
                    if (!$i_pos) {
                        $i_pos = strpos($read, ')', $i);
                    }
                    if ($i_pos) {
                        $unique_id = substr($read, $i, $i_pos - $i);
                        $i = $i_pos + 1;
                    } else {
                        break 3;
                    }
                    break;
                case 'FLAGS':
                    $flags = parseArray($read, $i);
                    if (!$flags) {
                        break 3;
                    }
                    $aFlags = array();
                    foreach ($flags as $flag) {
                        $flag = strtolower($flag);
                        $aFlags[$flag] = true;
                    }
                    $msg['FLAGS'] = $aFlags;
                    break;
                case 'RFC822.SIZE':
                    $i_pos = strpos($read, ' ', $i);
                    if (!$i_pos) {
                        $i_pos = strpos($read, ')', $i);
                    }
                    if ($i_pos) {
                        $msg['SIZE'] = substr($read, $i, $i_pos - $i);
                        $i = $i_pos + 1;
                    } else {
                        break 3;
                    }
                    break;
                case 'ENVELOPE':
                    break;
                    // to be implemented, moving imap code out of the nessages class
                    sqimap_parse_address($read, $i, $msg);
                    break;
                    // to be implemented, moving imap code out of the nessages class
                // to be implemented, moving imap code out of the nessages class
                case 'BODYSTRUCTURE':
                    break;
                case 'INTERNALDATE':
                    $msg['INTERNALDATE'] = str_replace('  ', ' ', parseString($read, $i));
                    break;
                case 'BODY.PEEK[HEADER.FIELDS':
                case 'BODY[HEADER.FIELDS':
                    $i = strpos($read, '{', $i);
                    $header = parseString($read, $i);
                    if ($header === false) {
                        break 2;
                    }
                    /* First we replace all \r\n by \n, and unfold the header */
                    $hdr = trim(str_replace(array("\r\n", "\n\t", "\n "), array("\n", ' ', ' '), $header));
                    /* Now we can make a new header array with */
                    /* each element representing a headerline  */
                    $hdr = explode("\n", $hdr);
                    $aReceived = array();
                    foreach ($hdr as $line) {
                        $pos = strpos($line, ':');
                        if ($pos > 0) {
                            $field = strtolower(substr($line, 0, $pos));
                            if (!strstr($field, ' ')) {
                                /* valid field */
                                $value = trim(substr($line, $pos + 1));
                                switch ($field) {
                                    case 'to':
                                        $msg['TO'] = $value;
                                        break;
                                    case 'cc':
                                        $msg['CC'] = $value;
                                        break;
                                    case 'from':
                                        $msg['FROM'] = $value;
                                        break;
                                    case 'date':
                                        $msg['DATE'] = str_replace('  ', ' ', $value);
                                        break;
                                    case 'x-priority':
                                        $msg['PRIORITY'] = $value;
                                        break;
                                    case 'subject':
                                        $msg['SUBJECT'] = $value;
                                        break;
                                    case 'content-type':
                                        $type = $value;
                                        if ($pos = strpos($type, ";")) {
                                            $type = substr($type, 0, $pos);
                                        }
                                        $type = explode("/", $type);
                                        if (!is_array($type) || count($type) < 2) {
                                            $msg['TYPE0'] = 'text';
                                            $msg['TYPE1'] = 'plain';
                                        } else {
                                            $msg['TYPE0'] = strtolower($type[0]);
                                            $msg['TYPE1'] = strtolower($type[1]);
                                        }
                                        break;
                                    case 'received':
                                        $aReceived[] = $value;
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }
                    }
                    if (count($aReceived)) {
                        $msg['RECEIVED'] = $aReceived;
                    }
                    break;
                default:
                    ++$i;
                    break;
            }
        }
        $msgi = "{$unique_id}";
        $msg['UID'] = $unique_id;
        $aMessageList[$msgi] = $msg;
        ++$msgi;
    }
    return $aMessageList;
}
Exemplo n.º 9
0
foreach ($categoryIDs as $categoryIndex => $categoryID) {
    if (in_array((int) $categoryID, array(131, 161, 62, 37, 52, 16, 68, 49, 147, 159))) {
        $groupIndex++;
    }
    echo "\n\nNow looking: /" . $groupMnemonics[$groupIndex] . " (" . $groupIndex . ")\n";
    $page = get_url($curl, "http://www.universal-optica.ru/catalog?category_id=" . $categoryID . "&page=shop.browse&limitstart=0&limit=400");
    $productUrl = parseArray($page, '<a class="product_link" href="', '">');
    $productName = parseArray($page, '<h3>', '</h3>');
    $productsImages = parseArray($page, 'http://universal-optica\\.ru/components/com_virtuemart/shop_image/product/', '\\.(jpg|png)"');
    $productPrice = parseArray($page, '<span class="product_price">', ' руб.</span>');
    $categoryMnemonic = strtr($categoryName[$categoryIndex], "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщьыъэюяABCDEFGHIJKLMNOPQRSTUVWXYZ()-/ ,&=", "abvgdeejziyklmnoprstufhc4w6yyyeuaabvgdeejziyklmnoprstufhc4w6yyyeuaabcdefghijklmnopqrstuvwxyz________");
    $k = 0;
    foreach ($productName as $productIndex => $t) {
        $page = get_url($curl, "http://www.universal-optica.ru" . $productUrl[$productIndex]);
        $sellingProposition = parseArray($page, '<h3>', '</h3>');
        $sellingPropositionPrices = parseArray($page, '<span class="product_price">', ' руб.</span>');
        // or die('Prices are empty!')
        if (preg_match_all('!<description>\\s*(.*)\\s*</description>!', $page, $result)) {
            $desc = trim($result[0][0]);
            $p1 = strpos($desc, '<description>');
            $p2 = strpos($desc, '</description>');
            $desc = trim(substr($desc, $p1 + 13, $p2 - $p1 - 14));
        } else {
            $desc = "";
        }
        $productLine = $goodViewedIndex . ";" . $goodViewedIndex . ";";
        $productLine .= $groupNames[$groupIndex] . ";" . $groupMnemonics[$groupIndex] . ";";
        $productLine .= $categoryName[$categoryIndex] . ";" . $categoryMnemonic . ";";
        $productLine .= $productName[$productIndex] . ";" . $productPrice[$productIndex] . ";" . $desc . ";";
        echo "\t" . $goodViewedIndex . " : /" . $categoryMnemonic . "\n";
        $flagNotResize = true;
Exemplo n.º 10
0
Connection:keep-alive
Cookie:virtuemart=n2o7r88fvic4dr8v4t3alqh7l6; 2bcb939887c372b902fac972a173fcc6=iikvns9so2hp5fh2j843kdtig2; 73ba353457a9efbcf176deb336df4660=+25951+A494A+B+F591442425D455C595A+31A+D15+A53+3+A171F4D471751+3231A+25E565C4919114315+A4B+D+A+2151659451547+D4754175E44+E5C+943283752+5+0+97A6441+D4A
Host:universal-optica.ru
If-Modified-Since:Mon, 10 Mar 2014 00:03:00 GMT
Referer:http://universal-optica.ru/
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36');
$curl = curl_init();
curl_setopt($curl, CURLOPT_HEADER, 1);
// we need header
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// don't print page, save it to var. (see $page)
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
// simulate browser headers vs cookie & user-agent& referer etc (just copy request header from you agent as is when you already authorized on site)
$page = get_url($curl, $_POST['url'] ? $_POST['url'] : "http://www.universal-optica.ru/catalog?category_id=95");
// get some secure content from site
$productPrice = parseArray($page, $_POST['from'] ? $_POST['from'] : '<span class="product_price">', $_POST['to'] ? $_POST['to'] : ' руб.</span>');
echo 'result of code that you see:<br>';
print_r($productPrice);
curl_close($curl);
function parseArray($from, $begin, $end)
{
    preg_match_all('!' . $begin . '(.*)' . $end . '!U', $from, $result);
    return array_map('trim', $result[1]);
}
function get_url($curl, $url)
{
    curl_setopt($curl, CURLOPT_URL, $url);
    $page = curl_exec($curl);
    // if $url charset != parser encoding: change cp1251 to parser encoding & utf8 to site charset
    // $page = mb_convert_encoding($page, "Windows-1251", "UTF-8");
    if ($pos = strpos($page, 'Set-Cookie: ') !== FALSE && $pos < 2000) {