Пример #1
0
/**
 * The main query function. Runs the SQL on the connection and handles errors.
 * @param string $sql sql code
 * @param bool $errorstop set to false to supress the error message
 * @return results of the sql statements
 * @since 0.6
 */
function query($sql, $errorstop = true)
{
    global $_zp_DB_connection, $_zp_DB_details;
    if (EXPLAIN_SELECTS && strpos($sql, 'SELECT') !== false) {
        $result = $_zp_DB_connection->query('EXPLAIN ' . $sql);
        if ($result) {
            $explaination = array();
            while ($row = $result->fetch_assoc()) {
                $explaination[] = $row;
            }
        }
        debugLogVar("EXPLAIN {$sql}", $explaination);
    }
    if ($result = @$_zp_DB_connection->query($sql)) {
        return $result;
    }
    if ($errorstop) {
        $sql = str_replace('`' . $_zp_DB_details['mysql_prefix'], '`[' . gettext('prefix') . ']', $sql);
        $sql = str_replace($_zp_DB_details['mysql_database'], '[' . gettext('DB') . ']', $sql);
        trigger_error(sprintf(gettext('%1$s Error: ( %2$s ) failed. %1$s returned the error %3$s'), DATABASE_SOFTWARE, $sql, db_error()), E_USER_ERROR);
    }
    return false;
}
Пример #2
0
/**
 * The main query function. Runs the SQL on the connection and handles errors.
 * @param string $sql sql code
 * @param bool $errorstop set to false to supress the error message
 * @return results of the sql statements
 * @since 0.6
 */
function query($sql, $errorstop = true)
{
    global $_zp_DB_connection, $_zp_DB_details;
    if ($_zp_DB_connection) {
        if (EXPLAIN_SELECTS && strpos($sql, 'SELECT') !== false) {
            $result = $_zp_DB_connection->query('EXPLAIN ' . $sql);
            if ($result) {
                $explaination = array();
                while ($row = $result->fetch_assoc()) {
                    $explaination[] = $row;
                }
            }
            debugLogVar("EXPLAIN {$sql}", $explaination);
        }
        if ($result = @$_zp_DB_connection->query($sql)) {
            return $result;
        }
    }
    if ($errorstop) {
        dbErrorReport($sql);
    }
    return false;
}
Пример #3
0
                             $commentcount++;
                         } else {
                             $postinfo .= '<li class="import-error">' . gettext('Comment could not be assigned!') . '</li>';
                         }
                     }
                 }
                 if ($commentexists_count != 0) {
                     $postinfo .= '<li class="import-exists">' . sprintf(ngettext('%1$u comment already exists.', '%1$u comments already exist.', $commentexists_count), $commentexists_count) . '</li>';
                 }
                 if ($commentcount != 0) {
                     $postinfo .= '<li class="import-success">' . sprintf(ngettext('%1$u comment imported.', '%1$u comments imported.', $commentcount), $commentcount) . '</li>';
                 }
             } else {
                 $postinfo .= '<ul><li class="import-nothing">' . gettext('No comments to import') . '</li>';
             }
             debugLogVar('Wordpress import - Comments for "' . $post['title'] . '" (' . $post['type'] . ')', $comments);
             $postinfo .= '</ul></li>';
             $postcount++;
         }
         // posts foreach
         $metaURL = 'wordpress_import.php?refresh=' . $postcount . '&amp;dbname=' . $wp_dbname . '&amp;dbuser=' . $wp_dbbuser . '&amp;dbpass=' . $wp_dbpassword . '&amp;dbhost=' . $wp_dbhost . '&amp;tableprefix=' . $wp_prefix . '&amp;convertlinefeeds=' . getcheckboxState('convertlinefeeds') . '&amp;XSRFToken=' . getXSRFToken('wordpress');
     } else {
         // if posts are available at all
         $metaURL = '';
         // to be sure...
         $postinfo .= "<li class='import-nothing'>" . gettext("No posts or pages to import.") . "</li>";
     }
 }
 // if db data set
 $zenphoto_tabs['overview']['subtabs'] = array(gettext('Wordpress') => '');
 printAdminHeader('overview', 'wordpress');
Пример #4
0
/**
 * This function will parse a given HTTP Accepted language instruction
 * (or retrieve it from $_SERVER if not provided) and will return a sorted
 * array. For example, it will parse fr;en-us;q=0.8
 *
 * Thanks to Fredbird.org for this code.
 *
 * @param string $str optional language string
 * @return array
 */
function parseHttpAcceptLanguage($str = NULL)
{
    // getting http instruction if not provided
    if (!$str) {
        $str = @$_SERVER['HTTP_ACCEPT_LANGUAGE'];
    }
    if (!is_string($str)) {
        return array();
    }
    $langs = explode(',', $str);
    // creating output list
    $accepted = array();
    foreach ($langs as $lang) {
        // parsing language preference instructions
        // 2_digit_code[-longer_code][;q=coefficient]
        if (preg_match('/([A-Za-z]{1,2})(-([A-Za-z0-9]+))?(;q=([0-9\\.]+))?/', $lang, $found)) {
            // 2 digit lang code
            $code = $found[1];
            // lang code complement
            $morecode = array_key_exists(3, $found) ? $found[3] : false;
            // full lang code
            $fullcode = $morecode ? $code . '_' . $morecode : $code;
            // coefficient (preference value, will be used in sorting the list)
            $coef = sprintf('%3.1f', array_key_exists(5, $found) ? $found[5] : '1');
            // for sorting by coefficient
            if ($coef) {
                //	q=0 means do not supply this language
                // adding
                $accepted[$coef . '-' . $code] = array('code' => $code, 'coef' => $coef, 'morecode' => $morecode, 'fullcode' => $fullcode);
            }
        }
    }
    // sorting the list by coefficient desc
    krsort($accepted);
    if (DEBUG_LOCALE) {
        debugLog("parseHttpAcceptLanguage({$str})");
        debugLogVar('parseHttpAcceptLanguage::$accepted', $accepted);
    }
    return $accepted;
}
Пример #5
0
 /**
  * Uptates the database with all changes
  */
 function save()
 {
     global $_zp_gallery;
     if (DEBUG_LOGIN) {
         debugLogVar("Zenphoto_Administrator->save()", $this);
     }
     $objects = $this->getObjects();
     if (is_null($this->get('date'))) {
         $this->set('date', date('Y-m-d H:i:s'));
     }
     parent::save();
     $id = $this->getID();
     if (is_array($objects)) {
         $sql = "DELETE FROM " . prefix('admin_to_object') . ' WHERE `adminid`=' . $id;
         $result = query($sql, false);
         foreach ($objects as $object) {
             $edit = MANAGED_OBJECT_MEMBER;
             if (array_key_exists('edit', $object)) {
                 $edit = $object['edit'] | MANAGED_OBJECT_MEMBER;
             }
             switch ($object['type']) {
                 case 'album':
                     $album = newAlbum($object['data']);
                     $albumid = $album->getID();
                     $sql = "INSERT INTO " . prefix('admin_to_object') . " (adminid, objectid, type, edit) VALUES ({$id}, {$albumid}, 'albums', {$edit})";
                     $result = query($sql);
                     break;
                 case 'pages':
                     $sql = 'SELECT * FROM ' . prefix('pages') . ' WHERE `titlelink`=' . db_quote($object['data']);
                     $result = query_single_row($sql);
                     if (is_array($result)) {
                         $objectid = $result['id'];
                         $sql = "INSERT INTO " . prefix('admin_to_object') . " (adminid, objectid, type, edit) VALUES ({$id}, {$objectid}, 'pages', {$edit})";
                         $result = query($sql);
                     }
                     break;
                 case 'news':
                     if ($object['data'] == '`') {
                         $result = array('id' => 0);
                     } else {
                         $sql = 'SELECT * FROM ' . prefix('news_categories') . ' WHERE `titlelink`=' . db_quote($object['data']);
                         $result = query_single_row($sql);
                     }
                     if (is_array($result)) {
                         $objectid = $result['id'];
                         $sql = "INSERT INTO " . prefix('admin_to_object') . " (adminid, objectid, type, edit) VALUES ({$id}, {$objectid}, 'news', {$edit})";
                         $result = query($sql);
                     }
                     break;
             }
         }
     }
 }
Пример #6
0
}
if (!file_exists($imgfile)) {
    if (isset($_GET['z'])) {
        //	flagged as a special image
        $args[3] = $args[4] = 0;
        $args[5] = 1;
        // full crops for these default images
        $args[9] = NULL;
        if (DEBUG_IMAGE) {
            debugLog("Transient image:{$rimage}=>{$newfile}");
        }
        $imgfile = SERVERPATH . '/' . sanitize_path($_GET['z']);
    }
    if (!file_exists($imgfile)) {
        if (DEBUG_IMAGE) {
            debugLogVar('image not found', $args);
        }
        imageError('404 Not Found', sprintf(gettext("Image not found; file %s does not exist."), html_encode(filesystemToInternal($album . '/' . $image))), 'err-imagenotfound.png');
    }
}
// Make the directories for the albums in the cache, recursively.
// Skip this for safe_mode, where we can't write to directories we create!
if (!SAFE_MODE) {
    $albumdirs = getAlbumArray($album, true);
    foreach ($albumdirs as $dir) {
        $dir = internalToFilesystem($dir);
        $dir = SERVERCACHE . '/' . $dir;
        if (!is_dir($dir)) {
            @mkdir($dir, FOLDER_MOD);
            @chmod($dir, FOLDER_MOD);
        } else {
Пример #7
0
 static function setupUser($ad, $userData)
 {
     global $_zp_authority;
     $user = $userData['uid'][0];
     $id = $userData['uidnumber'][0] + LDAP_ID_OFFSET;
     $name = $userData['cn'][0];
     $groups = self::getZPGroups($ad, $user);
     $adminObj = Zenphoto_Authority::newAdministrator('');
     $adminObj->setID($id);
     $adminObj->transient = true;
     if (isset($userData['email'][0])) {
         $adminObj->setEmail($userData['email'][0]);
     }
     $adminObj->setUser($user);
     $adminObj->setName($name);
     $adminObj->setPass(serialize($userData));
     if (class_exists('user_groups')) {
         user_groups::merge_rights($adminObj, $groups, array());
         if (DEBUG_LOGIN) {
             debugLogVar("LDAsetupUser: groups:", $adminObj->getGroup());
         }
         $rights = $adminObj->getRights() & ~USER_RIGHTS;
         $adminObj->setRights($rights);
     } else {
         $rights = DEFAULT_RIGHTS & ~USER_RIGHTS;
         $adminObj->setRights(DEFAULT_RIGHTS & ~USER_RIGHTS);
     }
     if ($rights) {
         $_zp_authority->addOtherUser($adminObj);
         return $adminObj;
     }
     return NULL;
 }