Ejemplo n.º 1
0
function thumbnail_external_replace($html, $post_id)
{
    $url = get_post_meta($post_id, '_thumbnail_ext_url', TRUE);
    if (empty($url) || !url_is_image($url)) {
        return $html;
    }
    $alt = get_post_field('post_title', $post_id) . ' ' . __('thumbnail', 'txtdomain');
    $attr = array('alt' => $alt);
    $attr = apply_filters('wp_get_attachment_image_attributes', $attr, NULL);
    $attr = array_map('esc_attr', $attr);
    $html = sprintf('<img src="%s"', esc_url($url));
    foreach ($attr as $name => $value) {
        $html .= " {$name}=" . '"' . $value . '"';
    }
    $html .= ' />';
    return $html;
}
Ejemplo n.º 2
0
 function test()
 {
     $this->load->library('unit_test');
     //$test = 1 + 1;
     //$expected_result = 2;
     //$test_name = 'Adds one plus one';
     //$this->unit->run($test, $expected_result, $test_name);
     $this->load->helper('kals');
     $this->unit->run(get_referer_url(), 'http://localhost/CodeIgniter_1.7.2/unit_test', '取得參考的網址!' . get_referer_url());
     $this->unit->run(parse_host(get_referer_url()), $this->host, '取得參考的HOST!' . parse_host());
     $this->unit->run(parse_uri('http://localhost/CodeIgniter_1.7.2/index.php/ut_misc/ut_kals_helper/test'), '/CodeIgniter_1.7.2/index.php/ut_misc/ut_kals_helper/test', '取得參考的URI!' . parse_uri());
     $this->unit->run(url_is_link('http://images.plurk.com/1422855_79bdc93f1317c2a7b8c9f0c5d51586c9.jpg'), TRUE, '確認是否是連結');
     $this->unit->run(url_is_image('http://images.plurk.com/1422855_79bdc93f1317c2a7b8c9f0c5d51586c9.jpg'), TRUE, '確認是否是圖片');
     $this->unit->run(url_is_link('http://www.plurk.com/p/5u89gi#response-1629050986'), TRUE, '確認是否是連結');
     $this->unit->run(url_is_image('http://www.plurk.com/p/5u89gi#response-1629050986'), FALSE, '確認是否是圖片');
     $this->unit->run(parse_email_name('*****@*****.**'), 'puddingchen.35', '取出email的名字');
     $this->unit->run(retrieve_title('http://www.plurk.com/p/5uuz7o#response-1632175301'), 'JS布丁 正在 [CODING D2] http://www.youtube.com/watch?v=c8I_WPonFHE  進度:2/182 - #5uuz7o', '取得網頁的title');
     $data = array('title' => get_class($this), 'unit' => $this->unit);
     $this->load->view('misc/unit_test', $data);
 }
function checkLinks()
{
    global $auth, $cfgClient, $client, $cfg, $cronjob, $db, $aErrors, $lang, $langart, $whitelist;
    global $aSearchIDInfosArt, $aSearchIDInfosCat, $aSearchIDInfosCatArt, $aSearchIDInfosNonID;
    if (count($aSearchIDInfosArt) > 0) {
        // Checks idarts
        for ($i = 0; $i < count($aSearchIDInfosArt); $i++) {
            if ($i == 0) {
                $sSearch = Contenido_Security::toInteger($aSearchIDInfosArt[$i]['id']);
            } else {
                $sSearch .= ", " . Contenido_Security::toInteger($aSearchIDInfosArt[$i]['id']);
            }
        }
        // Check articles
        $aFind = array();
        $sql = "SELECT idart, online FROM " . $cfg['tab']['art_lang'] . " WHERE idart IN (" . $sSearch . ")";
        $db->query($sql);
        while ($db->next_record()) {
            $aFind[$db->f("idart")] = array("online" => $db->f("online"));
        }
        for ($i = 0; $i < count($aSearchIDInfosArt); $i++) {
            if (isset($aFind[$aSearchIDInfosArt[$i]['id']]) && $aFind[$aSearchIDInfosArt[$i]['id']]['online'] == 0) {
                $aErrors['art'][] = array_merge($aSearchIDInfosArt[$i], array("error_type" => "offline"));
            } elseif (!isset($aFind[$aSearchIDInfosArt[$i]['id']])) {
                $aErrors['art'][] = array_merge($aSearchIDInfosArt[$i], array("error_type" => "unknown"));
            }
        }
    }
    if (count($aSearchIDInfosCat) > 0) {
        // Checks idcats
        for ($i = 0; $i < count($aSearchIDInfosCat); $i++) {
            if ($i == 0) {
                $sSearch = $aSearchIDInfosCat[$i]['id'];
            } else {
                $sSearch .= ", " . $aSearchIDInfosCat[$i]['id'];
            }
        }
        // Check categorys
        $aFind = array();
        $sql = "SELECT idcat, startidartlang, visible FROM " . $cfg['tab']['cat_lang'] . " WHERE idcat IN (" . $sSearch . ") AND idlang = '" . Contenido_Security::toInteger($lang) . "'";
        $db->query($sql);
        while ($db->next_record()) {
            $aFind[$db->f("idcat")] = array("online" => $db->f("visible"), "startidart" => $db->f("startidartlang"));
        }
        for ($i = 0; $i < count($aSearchIDInfosCat); $i++) {
            if (is_array($aFind[$aSearchIDInfosCat[$i]['id']]) && $aFind[$aSearchIDInfosCat[$i]['id']]['startidart'] == 0) {
                $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array("error_type" => "startart"));
            } elseif (is_array($aFind[$aSearchIDInfosCat[$i]['id']]) && $aFind[$aSearchIDInfosCat[$i]['id']]['online'] == 0) {
                $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array("error_type" => "offline"));
            } elseif (!is_array($aFind[$aSearchIDInfosCat[$i]['id']])) {
                $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array("error_type" => "unknown"));
            }
            if (is_array($aFind[$aSearchIDInfosCat[$i]['id']]) && $aFind[$aSearchIDInfosCat[$i]['id']]['startidart'] != 0) {
                $sql = "SELECT idart FROM " . $cfg['tab']['art_lang'] . " WHERE idartlang = '" . $aFind[$aSearchIDInfosCat[$i]['id']]['startidart'] . "' AND online = '1'";
                $db->query($sql);
                if ($db->num_rows() == 0) {
                    $aErrors['cat'][] = array_merge($aSearchIDInfosCat[$i], array("error_type" => "startart"));
                }
            }
        }
    }
    if (count($aSearchIDInfosCatArt) > 0) {
        // Checks idcatarts
        for ($i = 0; $i < count($aSearchIDInfosCatArt); $i++) {
            if ($i == 0) {
                $sSearch = Contenido_Security::toInteger($aSearchIDInfosCatArt[$i]['id']);
            } else {
                $sSearch .= ", " . Contenido_Security::toInteger($aSearchIDInfosCatArt[$i]['id']);
            }
        }
        // Check articles
        $aFind = array();
        $sql = "SELECT idcatart FROM " . $cfg['tab']['cat_art'] . " WHERE idcatart IN (" . $sSearch . ")";
        $db->query($sql);
        while ($db->next_record()) {
            $aFind[] = $db->f("idcatart");
        }
        for ($i = 0; $i < count($aSearchIDInfosCatArt); $i++) {
            if (!in_array($aSearchIDInfosCatArt[$i]['id'], $aFind)) {
                $aErrors['art'][] = array_merge($aSearchIDInfosCatArt[$i], array("error_type" => "unknown"));
            }
        }
    }
    if (count($aSearchIDInfosNonID) != 0) {
        // Checks other links (e. g. http, www, dfbs)
        // Select userrights (is the user admin or sysadmin?)
        $sql = "SELECT username FROM " . $cfg['tab']['phplib_auth_user_md5'] . " WHERE user_id='" . Contenido_Security::escapeDB($auth->auth['uid'], $db) . "' AND perms LIKE '%admin%'";
        $db->query($sql);
        if ($db->num_rows() > 0 || $cronjob == true) {
            // User is admin when he is or when he run the cronjob
            $iAdmin = true;
        }
        for ($i = 0; $i < count($aSearchIDInfosNonID); $i++) {
            if (url_is_uri($aSearchIDInfosNonID[$i]['url'])) {
                if (substr($aSearchIDInfosNonID[$i]['url'], 0, strlen($aSearchIDInfosNonID[$i]['url'])) == $cfgClient[$client]['path']['htmlpath']) {
                    $iPing = @file_exists(str_replace($cfgClient[$client]['path']['htmlpath'], $cfgClient[$client]['path']['frontend'], $aSearchIDInfosNonID[$i]['url']));
                } else {
                    $iPing = @fopen($aSearchIDInfosNonID[$i]['url'], 'r');
                }
                if (!$iPing) {
                    if (url_is_image($aSearchIDInfosNonID[$i]['url'])) {
                        $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "unknown"));
                    } else {
                        $aErrors['others'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "unknown"));
                    }
                }
            } elseif (substr($aSearchIDInfosNonID[$i]['url'], strlen($aSearchIDInfosNonID[$i]['url']) - 5, 5) == ".html") {
                $iPing = @file_exists($cfgClient[$client]['path']['htmlpath'] . $aSearchIDInfosNonID[$i]['url']);
                if (!$iPing) {
                    $aErrors['art'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "unknown"));
                }
            } elseif (substr($aSearchIDInfosNonID[$i]['url'], 0, 20) == "dbfs.php?file=dbfs:/") {
                $sDBurl = substr($aSearchIDInfosNonID[$i]['url'], 20, strlen($aSearchIDInfosNonID[$i]['url']));
                $iPos = strrpos($sDBurl, '/');
                $sDirname = substr($sDBurl, 0, $iPos);
                $sFilename = substr($sDBurl, $iPos + 1);
                // Check categorys
                $sql = "SELECT iddbfs FROM " . $cfg['tab']['dbfs'] . " WHERE dirname IN('" . $sDirname . "', '" . html_entity_decode($sDirname) . "', '" . urldecode($sDirname) . "') AND filename = '" . $sFilename . "'";
                $db->query($sql);
                if ($db->num_rows() == 0) {
                    $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "dbfs"));
                }
            } else {
                if (!file_exists($cfgClient[$client]['path']['frontend'] . $aSearchIDInfosNonID[$i]['url'])) {
                    if (url_is_image($aSearchIDInfosNonID[$i]['url'])) {
                        $aErrors['docimages'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "unknown"));
                    } else {
                        $aErrors['others'][] = array_merge($aSearchIDInfosNonID[$i], array("error_type" => "unknown"));
                    }
                }
            }
        }
    }
    return $aErrors;
}