コード例 #1
0
ファイル: Request.php プロジェクト: ClaireBrione/textpattern
 /**
  * Gets a HTTP post parameter.
  *
  * @param  string $name The parameter name
  * @return mixed
  */
 public function getPost($name)
 {
     $out = '';
     if (isset($_POST[$name])) {
         $out = $_POST[$name];
         if ($this->magicQuotesGpc) {
             $out = doStrip($out);
         }
     }
     return doArray($out, 'deNull');
 }
コード例 #2
0
ファイル: txplib_misc.php プロジェクト: bgarrels/textpattern
function quote_list($in)
{
    $out = doSlash($in);
    return doArray($out, 'doQuote');
}
コード例 #3
0
ファイル: pdo_sqlite.php プロジェクト: bgarrels/textpattern
function db_column_list($tbl, $res = 0)
{
    global $mdb_res;
    $res = $res ? $res : $mdb_res;
    /* @var $res PDO */
    $st = $res->query("SELECT * FROM {$tbl} LIMIT 1");
    /* @var $res PDOStatement */
    $c = $st->columnCount();
    if ($c > 0) {
        for ($i = 0; $i < $c; $i++) {
            $meta = $st->getColumnMeta($i);
            $cols[$meta['name']] = $meta['sqlite:decl_type'];
        }
        # getColumnMeta does not work with empty tables:
        if (sizeof($cols) != $c) {
            unset($cols);
            $st2 = $res->query("SELECT sql FROM sqlite_master WHERE type='table' AND tbl_name='{$tbl}'");
            /* @var $st PDOStatement */
            if ($st2 !== false) {
                $sql = $st2->fetch(PDO::FETCH_ASSOC);
                extract($sql);
                $sql = substr($sql, strpos($sql, '(') + 1);
                $cls = explode(',', $sql);
                $cls = doArray($cls, 'trim');
                foreach ($cls as $val) {
                    $col = explode(' ', $val);
                    $cols[$col[0]] = $col[1];
                }
                # remove any primary key sentence and keep the lenght equal to the columns number
                $cols = array_slice($cols, 0, $c);
            }
        }
    }
    return $cols ? $cols : array();
}
コード例 #4
0
ファイル: txplib_misc.php プロジェクト: bgarrels/textpattern
function doSpecial($in)
{
    return doArray($in, 'htmlspecialchars');
}
コード例 #5
0
/**
 * Validates article data.
 *
 * @param  array        $rs  Article data
 * @param  string|array $msg Initial message
 * @return string HTML
 */
function article_validate($rs, &$msg)
{
    global $prefs, $step, $statuses;
    if (!empty($msg)) {
        return false;
    }
    $constraints = array('Status' => new ChoiceConstraint($rs['Status'], array('choices' => array_keys($statuses), 'message' => 'invalid_status')), 'Section' => new SectionConstraint($rs['Section']), 'Category1' => new CategoryConstraint($rs['Category1'], array('type' => 'article')), 'Category2' => new CategoryConstraint($rs['Category2'], array('type' => 'article')), 'textile_body' => new \Textpattern\Textfilter\Constraint($rs['textile_body'], array('message' => 'invalid_textfilter_body')), 'textile_excerpt' => new \Textpattern\Textfilter\Constraint($rs['textile_excerpt'], array('message' => 'invalid_textfilter_excerpt')));
    if (!$prefs['articles_use_excerpts']) {
        $constraints['excerpt_blank'] = new BlankConstraint($rs['Excerpt'], array('message' => 'excerpt_not_blank'));
    }
    if (!$prefs['use_comments']) {
        $constraints['annotate_invite_blank'] = new BlankConstraint($rs['AnnotateInvite'], array('message' => 'invite_not_blank'));
        $constraints['annotate_false'] = new FalseConstraint($rs['Annotate'], array('message' => 'comments_are_on'));
    }
    if ($prefs['allow_form_override']) {
        $constraints['override_form'] = new FormConstraint($rs['override_form'], array('type' => 'article'));
    } else {
        $constraints['override_form'] = new BlankConstraint($rs['override_form'], array('message' => 'override_form_not_blank'));
    }
    callback_event_ref('article_ui', "validate_{$step}", 0, $rs, $constraints);
    $validator = new Validator($constraints);
    if ($validator->validate()) {
        $msg = '';
        return true;
    } else {
        $msg = doArray($validator->getMessages(), 'gTxt');
        $msg = array(join(', ', $msg), E_ERROR);
        return false;
    }
}
コード例 #6
0
ファイル: import_wp.php プロジェクト: bgarrels/textpattern
function undoSlash($in)
{
    return doArray($in, 'stripslashes');
}
コード例 #7
0
ファイル: index.php プロジェクト: bgarrels/textpattern
function sDoSlash($in)
{
    if (phpversion() >= "4.3.0") {
        return doArray($in, 'mysql_real_escape_string');
    } else {
        return doArray($in, 'mysql_escape_string');
    }
}
コード例 #8
0
ファイル: taghandlers.php プロジェクト: bgarrels/textpattern
function file_download_list($atts, $thing = NULL)
{
    global $s, $c, $context, $thisfile, $thispage, $pretext;
    extract(lAtts(array('break' => br, 'category' => '', 'author' => '', 'realname' => '', 'auto_detect' => 'category, author', 'class' => __FUNCTION__, 'form' => 'files', 'id' => '', 'label' => '', 'labeltag' => '', 'pageby' => '', 'limit' => 10, 'offset' => 0, 'sort' => 'filename asc', 'wraptag' => '', 'status' => '4'), $atts));
    if (!is_numeric($status)) {
        $status = getStatusNum($status);
    }
    // N.B. status treated slightly differently
    $where = $statwhere = array();
    $filters = isset($atts['id']) || isset($atts['category']) || isset($atts['author']) || isset($atts['realname']) || isset($atts['status']);
    $context_list = empty($auto_detect) || $filters ? array() : do_list($auto_detect);
    $pageby = $pageby == 'limit' ? $limit : $pageby;
    if ($category) {
        $where[] = "category IN ('" . join("','", doSlash(do_list($category))) . "')";
    }
    $ids = array_map('intval', do_list($id));
    if ($id) {
        $where[] = "id IN ('" . join("','", $ids) . "')";
    }
    if ($status) {
        $statwhere[] = "status = '" . doSlash($status) . "'";
    }
    if ($author) {
        $where[] = "author IN ('" . join("','", doSlash(do_list($author))) . "')";
    }
    if ($realname) {
        $authorlist = safe_column('name', 'txp_users', "RealName IN ('" . join("','", doArray(doSlash(do_list($realname)), 'urldecode')) . "')");
        $where[] = "author IN ('" . join("','", doSlash($authorlist)) . "')";
    }
    // If no files are selected, try...
    if (!$where && !$filters) {
        foreach ($context_list as $ctxt) {
            switch ($ctxt) {
                case 'category':
                    // ... the global category in the URL
                    if ($context == 'file' && !empty($c)) {
                        $where[] = "category = '" . doSlash($c) . "'";
                    }
                    break;
                case 'author':
                    // ... the global author in the URL
                    if ($context == 'file' && !empty($pretext['author'])) {
                        $where[] = "author = '" . doSlash($pretext['author']) . "'";
                    }
                    break;
            }
            // Only one context can be processed
            if ($where) {
                break;
            }
        }
    }
    if (!$where && !$statwhere && $filters) {
        return '';
        // If nothing matches, output nothing
    }
    if (!$where) {
        $where[] = "1=1";
        // If nothing matches, start with all files
    }
    $where = join(' AND ', array_merge($where, $statwhere));
    // Set up paging if required
    if ($limit && $pageby) {
        $grand_total = safe_count('txp_file', $where);
        $total = $grand_total - $offset;
        $numPages = $pageby > 0 ? ceil($total / $pageby) : 1;
        $pg = !$pretext['pg'] ? 1 : $pretext['pg'];
        $pgoffset = $offset + ($pg - 1) * $pageby;
        // send paging info to txp:newer and txp:older
        $pageout['pg'] = $pg;
        $pageout['numPages'] = $numPages;
        $pageout['s'] = $s;
        $pageout['c'] = $c;
        $pageout['context'] = 'file';
        $pageout['grand_total'] = $grand_total;
        $pageout['total'] = $total;
        if (empty($thispage)) {
            $thispage = $pageout;
        }
    } else {
        $pgoffset = $offset;
    }
    // preserve order of custom file ids unless 'sort' attribute is set
    if (!empty($atts['id']) && empty($atts['sort'])) {
        $safe_sort = 'field(id, ' . join(',', $ids) . ')';
    } else {
        $safe_sort = doSlash($sort);
    }
    $qparts = array('order by ' . $safe_sort, $limit ? 'limit ' . intval($pgoffset) . ', ' . intval($limit) : '');
    $rs = safe_rows_start('*', 'txp_file', $where . ' ' . join(' ', $qparts));
    if ($rs) {
        $out = array();
        while ($a = nextRow($rs)) {
            $thisfile = file_download_format_info($a);
            $out[] = $thing ? parse($thing) : parse_form($form);
            $thisfile = '';
        }
        if ($out) {
            return doLabel($label, $labeltag) . doWrap($out, $wraptag, $break, $class);
        }
    }
    return '';
}
コード例 #9
0
ファイル: txplib_db.php プロジェクト: bgarrels/textpattern
/**
 * Locks a table.
 *
 * The $table argument accepts comma-separated
 * list of table names, if you need to lock
 * multiple tables at once.
 *
 * @param  string $table The table
 * @param  string $type  The lock type
 * @param  bool   $debug Dump the query
 * @return bool   TRUE if the tables are locked
 * @since  4.6.0
 * @example
 * if (safe_lock('myTable'))
 * {
 *     echo "'myTable' is 'write' locked.";
 * }
 */
function safe_lock($table, $type = 'write', $debug = false)
{
    return (bool) safe_query('lock tables ' . join(' ' . $type . ', ', doArray(do_list($table), 'safe_pfx')) . ' ' . $type, $debug);
}
コード例 #10
0
ファイル: l10n_bom_file.php プロジェクト: netcarver/mlp_pack
 function get_site_langs($set_if_empty = false)
 {
     /*
     Returns an array of the languages the public site supports.
     */
     global $prefs;
     $exists = array_key_exists(L10N_PREFS_LANGUAGES, $prefs);
     if ($set_if_empty and !$exists) {
         $prefs[L10N_PREFS_LANGUAGES] = array(LANG);
         $exists = true;
     }
     if ($exists) {
         $lang_codes = $prefs[L10N_PREFS_LANGUAGES];
         if (!is_array($lang_codes)) {
             $lang_codes = explode(',', $lang_codes);
         }
         $lang_codes = doArray($lang_codes, 'trim');
     } else {
         $lang_codes = NULL;
     }
     return $lang_codes;
 }
コード例 #11
0
/**
 * Locks a table.
 *
 * The $table argument accepts comma-separated list of table names, if you need
 * to lock multiple tables at once.
 *
 * @param  string $table The table
 * @param  string $type  The lock type
 * @param  bool   $debug Dump the query
 * @return bool TRUE if the tables are locked
 * @since  4.6.0
 * @example
 * if (safe_lock('myTable'))
 * {
 *     echo "'myTable' is 'write' locked.";
 * }
 */
function safe_lock($table, $type = 'write', $debug = false)
{
    return (bool) safe_query("LOCK TABLES " . join(' ' . $type . ', ', doArray(do_list_unique($table), 'safe_pfx')) . ' ' . $type, $debug);
}
コード例 #12
0
 function search_for_names()
 {
     #
     #	Start our XML output...
     #
     ob_start();
     header("Content-Type: text/xml");
     print '<?xml version=\'1.0\' encoding=\'utf-8\'?>' . n;
     #
     #	Grab the names of every string in the system...
     #
     $admin_langs = MLPLanguageHandler::get_installation_langs();
     $stats = array();
     if ($this->pref('l10n-search_public_strings_only')) {
         $where = '`event` in ("public","common")';
     } else {
         $where = '1=1';
     }
     $full_names = safe_rows_start('name,lang', 'txp_lang', $where . ' ORDER BY name ASC');
     $names = MLPStrings::get_strings($full_names, $stats);
     $num_names = count($names);
     if (!$names || $num_names == 0) {
         exit;
     }
     #
     #	Grab the search term...
     #
     $search_term = gps('l10n-sfn');
     $out = array();
     switch ($search_term) {
         case '':
         case 'undefined':
             #
             #	send a full list of strings...
             #
             foreach ($names as $string => $value) {
                 $out[] = '<li id="' . $string . '" class="l10n_hidden"><a href="' . hu . '" onClick="do_string_edit(\'' . $string . '\'); return false;">' . $string . '</a></li>';
             }
             break;
         case '-':
             #
             #	send those missing a rendition in any language...
             #
             foreach ($names as $string => $value) {
                 $lang_classes = '';
                 $vals = explode(',', $value);
                 $vals = doArray($vals, 'trim');
                 $missing = array_diff($admin_langs, $vals);
                 if (!empty($missing)) {
                     $out[] = '<li id="' . $string . '" class="l10n_hidden"><a href="' . hu . '" onClick="do_string_edit(\'' . $string . '\'); return false;">' . $string . ' [' . join(', ', $missing) . ']</a></li>';
                 }
             }
             break;
         default:
             #
             #	send those missing a rendition in the specified language...
             #
             foreach ($names as $string => $value) {
                 $lang_classes = '';
                 $vals = explode(',', $value);
                 $vals = doArray($vals, 'trim');
                 $missing = array_diff($admin_langs, $vals);
                 if (!empty($missing)) {
                     foreach ($missing as $l) {
                         if ($l === $search_term) {
                             $out[] = '<li id="' . $string . '" class="l10n_hidden"><a href="' . hu . '" onClick="do_string_edit(\'' . $string . '\'); return false;">' . $string . '</a></li>';
                         }
                     }
                 }
             }
             break;
     }
     $subs['{interface}'] = $this->pref('l10n-search_public_strings_only') ? 'public' : '';
     print graf('<span id="l10n_result_count">' . $search_term . '</span>/' . count($out) . ' ' . gTxt('l10n-strings_match', $subs)) . n;
     print '<ul id="l10n_sbn_result_list" class="l10n_visible" >';
     print join('', $out);
     print '</ul>' . n;
     #
     #	Done; send it out...
     #
     exit;
 }
コード例 #13
0
ファイル: controller.php プロジェクト: bgarrels/textpattern
 function sDoSlash($in)
 {
     global $DB;
     return doArray($in, array($DB, 'escape'));
 }
コード例 #14
0
ファイル: smd_ebook.php プロジェクト: Bloke/smd_ebook
function smd_ebook_generate($listfile = '', $opf_file = '', $booktype = '', $ebook_folder = '')
{
    global $smd_ebook_prefs, $img_dir;
    $report = array();
    $retval = NULL;
    // Use passed in values in lieu of the one in the form
    $opf_file = $opf_file ? $opf_file : ps('smd_ebook_opf_file');
    $listfile = $listfile ? $listfile : ps('smd_ebook_listfile');
    $booktype = $booktype ? $booktype : ps('smd_ebook_type');
    $ebook_folder = $ebook_folder ? $ebook_folder : ps('smd_ebook_folder');
    $is_mobi = $booktype === 'mobi';
    $is_epub = $booktype === 'zip';
    // File credentials
    $outpath = get_pref('tempdir') . DS . $ebook_folder . DS;
    $outfile = ps('smd_ebook_pubfile');
    if (empty($outfile)) {
        $info = explode('.', $listfile);
        $basepart = array_slice($info, 0, count($info) - 1);
        $outfile = join('', $basepart);
    }
    $outfile .= $is_epub ? '.epub' : ($is_mobi ? '.mobi' : '');
    $downloadit = ps('smd_ebook_download');
    $fileit = ps('smd_ebook_to_files');
    if ($downloadit) {
        smd_ebook_download($outpath . $outfile);
    } elseif ($fileit) {
        @(include_once txpath . '/include/txp_file.php');
        // Copy the file to the files area
        $destfilepath = get_pref('file_base_path') . DS . $outfile;
        $filesize = filesize($outpath . $outfile);
        copy($outpath . $outfile, $destfilepath);
        // Get the file category
        $filecat = get_pref('smd_ebook_file_cat', $smd_ebook_prefs['smd_ebook_file_cat']['default']);
        // Read description and title from .opf
        $doc = new DOMDocument();
        $content = file_get_contents(get_pref('tempdir') . DS . $ebook_folder . DS . $opf_file);
        $dom_ok = $doc->loadXML($content);
        $description = $title = '';
        if ($dom_ok) {
            $items = $doc->getElementsByTagName('*');
            foreach ($items as $item) {
                if ($item->nodeName === 'dc:title') {
                    $title = $item->nodeValue;
                }
                if ($item->nodeName === 'dc:description') {
                    $description = $item->nodeValue;
                }
            }
        }
        $curid = safe_field('id', 'txp_file', "filename='" . doSlash($outfile) . "'");
        if ($curid) {
            // Update existing database entry
            $ret = safe_update('txp_file', "\n                    title='" . doSlash($title) . "',\n                    category='" . doSlash($filecat) . "',\n                    description='" . doSlash($description) . "',\n                    size='" . doSlash($filesize) . "',\n                    modified= now()\n                ", "id='" . doSlash($curid) . "'");
            if ($ret) {
                $msg = gTxt('smd_ebook_updated', array('{id}' => $curid));
            } else {
                $msg = gTxt('smd_ebook_not_filed');
            }
        } else {
            // Make a new entry in the database for it
            $newid = file_db_add(doSlash($outfile), doSlash($filecat), '', doSlash($description), doSlash($filesize), doSlash($title));
            if ($newid) {
                $msg = gTxt('smd_ebook_filed', array('{id}' => $newid));
            } else {
                $msg = gTxt('smd_ebook_not_filed');
            }
        }
    } else {
        // (Re)generate the book
        $msg = '';
        $master_img_list = array();
        switch ($booktype) {
            case 'mobi':
                list($report, $retval) = smd_ebook_kindlegen($opf_file, $ebook_folder);
                if ($retval > 1) {
                    $msg = gTxt('smd_ebook_generate_failed', array('{code}' => $retval));
                } else {
                    $msg = gTxt('smd_ebook_generate_ok');
                }
                break;
            case 'zip':
                // All the files are currently in a flat file structure (for ease of browsing/editing).
                // To add them to the zip, they need to be put in a specific file tree.
                $base_dir = get_pref('tempdir') . DS . $ebook_folder . DS;
                $dest_dir = $base_dir . 'zipped' . DS;
                $meta_dir = $dest_dir . 'META-INF';
                $oebps_dir = $dest_dir . 'OEBPS';
                $oebps_img_dir = $oebps_dir . DS . 'images';
                $report[] = 'Files in base folder: ' . $base_dir;
                $zip = new smd_crunch_dZip($outpath . $outfile);
                // Add the static files and folder structure
                $static_files = array('mimetype' => $dest_dir, 'container.xml' => $meta_dir . DS, 'cover.html' => $oebps_dir . DS, '' => $oebps_img_dir . DS);
                foreach ($static_files as $fn => $to) {
                    if (!is_readable($to)) {
                        if (mkdir($to)) {
                            $report[] = 'Created folder: ' . $to;
                        } else {
                            $report[] = 'Failed to create folder: ' . $to;
                        }
                    }
                    $add_to_zip = str_replace($dest_dir, '', $to);
                    if ($add_to_zip !== '') {
                        $zip->addDir($add_to_zip);
                    }
                    if ($fn !== '') {
                        if (copy($base_dir . $fn, $to . $fn)) {
                            $destfile = str_replace($dest_dir, '', $to) . $fn;
                            $zip->addFile($to . $fn, $destfile);
                            $report[] = 'Added file: ' . $destfile;
                        } else {
                            $report[] = 'Failed to add file: ' . $destfile;
                        }
                    }
                }
                // Add each file given in the .smd master file
                $files = file($base_dir . $listfile);
                $files = doArray($files, 'trim');
                foreach ($files as $file) {
                    $info = explode('.', $file);
                    $lastpart = count($info) - 1;
                    $ext = trim($info[$lastpart]);
                    switch ($ext) {
                        case 'html':
                        case 'css':
                        case 'ncx':
                        case 'opf':
                            $destfile = $oebps_dir . DS . $file;
                            if (copy($base_dir . $file, $destfile)) {
                                // Translate fixed (image) paths into relative ones
                                if ($ext === 'html') {
                                    $content = file_get_contents($destfile);
                                    $content = str_replace(get_pref('path_to_site') . DS . $img_dir . DS, 'images' . DS, $content);
                                    $fh = fopen($destfile, 'w');
                                    fwrite($fh, $content);
                                    fclose($fh);
                                }
                                $zip->addFile($oebps_dir . DS . $file, 'OEBPS' . DS . $file);
                                $report[] = 'Added file: OEBPS' . DS . $file;
                            }
                            break;
                        case 'jpg':
                        case 'jpeg':
                        case 'gif':
                        case 'png':
                            if (strpos($file, 'cover') === 0) {
                                $picdir = $oebps_dir;
                            } else {
                                $picdir = $oebps_img_dir;
                            }
                            $destfile = $picdir . DS . $file;
                            $rel_dir = str_replace($dest_dir, '', $picdir);
                            if (!file_exists($destfile) && copy($base_dir . $file, $destfile)) {
                                $report[] = 'Added file: ' . $rel_dir . DS . $file;
                            }
                            // Guard against adding the same image twice
                            if (!in_array($file, $master_img_list)) {
                                $zip->addFile($destfile, $rel_dir . DS . $file);
                                $master_img_list[] = $file;
                            }
                            break;
                    }
                }
                $zip->save();
                $report[] = 'Generated final ePub file: ' . $outpath . $outfile;
                $msg = gTxt('smd_ebook_generate_ok');
                $retval = 0;
                // Success! TODO: trap errors and report failure
                break;
        }
    }
    smd_ebook_ui($msg, $listfile, join(n, $report), $retval, $ebook_folder);
}
コード例 #15
0
ファイル: zem_event.php プロジェクト: gbp/zem_event
function zem_event_available_locations()
{
    $form = @fetch_form('zem_event_locations');
    // prepare form for use
    $form = str_replace(array("\r\n", "\r"), "\n", $form);
    $list = explode("\n", $form);
    $available_locations = array();
    foreach ($list as $key => $val) {
        $location = explode('=', $val);
        // only add to the list if both a name and title were supplied
        if ($location[0] and $location[1]) {
            list($name, $title) = doArray($location, 'trim');
            $available_locations[$name] = $title;
        }
    }
    return $available_locations;
}