We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26709
    • 4 Posts
    Всем привет!

    Недавно я нашел снипет из etomite, предназначенный для управления статьями и который, если его немного переделать, очень подходит для разработки каталога предприятий, доски объявлений и т.д. Но как только я решил его испытать, ничего не получилось. Когда я размещаю его нас странице и запускаю ее, выдает ошибка про то, что есть синтаксическая ошибка в MySql запросе.

    Я очень прошу Вас, помогите мне просто переделать код снипета, чтобы он заработал без ошибки. А уже потом я его буду доводить до ума. В свою очередь обязуюсь, если получится, поделиться созданным каталогом предприятий.

    Заранее благодарю за помощь. Вот сам код снипета:
    // Blogger Snippet
    // Created By: Ralph Dahlgren
    // Based on the original EtoBlog snippet created by hugelmopf
    // Last Modified: 2005-12-21
    // Purpose: Creates and/or maintains a table of blog entries categorized by document id and can also be used to maintain multiple blog tables
    // Use: [!Blogger!] - uses the table named etoblog for storage
    // Use: [!Blogger?blog=blogtable!] - uses the table named blogtable for storage
    // Use: [!Blogger?blog=blogtable&showAuthor=true&showDate=true&dateFormat=m/d/Y&height=400px&width=400px&permissions=edit_document&users=winkum,blinkum,nod!] - uses all available options
    
    // Database table to use for storage (shouldn't need to be changed)
    // entries will be grouped by document id so multiple blogs can use one table
    $blog = isset($blog) ? $blog : "etoblog";
    $tbl = $etomite->db.$blog;
    
    // Should the authors name be displayed? Defaults to true
    $showAuthor = isset($showAuthor) ? $showAuthor : "true";
    
    // Should the last modified date be displayed? Editing an entry changes the date to the current time
    $showDate = isset($showDate) ? $showDate : "true";
    
    // Custom date formate based on the PHP date() function
    $dateFormat = "l F jS, Y g:i a"; // Monday October 10th, 2005 4:37 pm
    
    // Set the height of the WYSIWYG editor
    $height = isset($height) ? $height : "400px";
    
    // Set the width of the WYSIWYG editor (can be in px or %)
    $width = isset($width) ? $width : "98%";
    
    // Set to desired permission level (based on user role permissions settings)
    $permissions = "edit_document"; // Set $permissions = ""; to allow full public access
    
    // Check to see if $username was passed to the snippet and authorize if logged in
    if(in_array($_SESSION['shortname'], explode(",",$users))) $authorized = true;
    
    // Should embedded Etomite system variable tags be made inactive? Defaults to true
    $stoptags = (isset($stoptags)) ? $stoptags : "true";
    
    // Text for various page elements
    $text['Save_changes'] = "Save changes";
    $text['Entry_added'] = "Entry added.";
    $text['Entry_deleted'] = "Entry deleted.";
    $text['Changes_saved'] = "Changes saved.";
    $text['Action_cancelled'] = "Action Cancelled.";
    $text['Add_entry'] = "Add entry";
    $text['Cancel'] = "Cancel";
    $text['Author'] = "Author";
    $text['Edit'] = "Edit";
    $text['Delete'] = "Delete";
    $text['Title'] = "Title: ";
    
    // Style information - can be inline styles or CSS component related
    $entry_box_css = "style='background-color:#FFFFFF; border:1px solid black; margin-bottom:10px;'";
    $title_css = "style='color:red; font-weight:bold; display:block;'";
    $title_css = "class='titlebg'";
    $author_css = "style='color:#000000; font-weight:bold; display:inline;'";
    $date_css = "style='color:green; display:inline;'";
    $parent_css = "color:#FFA500; font-weight:bold'";
    $text_css = "style='color:black; font-weight:normal; margin-top:.5em; padding:0px 5px 0px 5px;'";
    $more_css = "style='float:right; color:#FFA500; font-weight:bold;'";
    
    // Determine which Etomite variable tags to make inactive (adds blank space in leading tags)
    $oldtags = array("[[","[!","{{","[~","[*","[(","[^");
    $newtags = array("[ [","[ !","{ {","[ ~","[ *","[ (","[ ^");
    if($stoptags == "true") {
      $title = str_replace($oldtags,$newtags,$_REQUEST['title']);
      $blogText = str_replace($oldtags,$newtags,$_REQUEST['text']);
    }
    
    // No variable changes should be required below this point
    $phpself = $etomite->makeUrl($etomite->documentIdentifier);
    $phpself = "[~".$etomite->documentIdentifier."~]";
    
    // Calculate path to Xinha directory
    $pieces = explode("/",$_SERVER['SERVER_PROTOCOL']);
    $protocol = $pieces[0];
    $pieces = explode("/",$_SERVER['PHP_SELF']);
    $count = count($pieces);
    for($i=0; $i<$count-1; $i++) $tmpUrl .= $pieces[$i] . "/";
    $editorUrl = $protocol."://".$_SERVER['HTTP_HOST'].$tmpUrl."manager/media/xinha/";
    //echo $editorUrl;
    
    // If blog table has not been created yet, create it now:
    $exist = mysql_query("SELECT COUNT(*) FROM $tbl");
    if(!$exist) {
      $sql = "CREATE TABLE $tbl (
                `entryid` int(10) unsigned NOT NULL auto_increment,
               `blog_id` int(10) unsigned NOT NULL default '0',
               `title` text NOT NULL,
               `text` text NOT NULL,
               `internalKey` int(10) NOT NULL default '0',
               `date` datetime NOT NULL default '0000-00-00 00:00:00',
                PRIMARY KEY  (`entryid`)
              ) TYPE=MyISAM AUTO_INCREMENT=1 ;";
      $create = $etomite->dbQuery($sql);
    }
    
    // check permissions on the document - $etomite->documentIdentifier
    if( $etomite->checkPermissions($permissions) || $authorized ) {
      $access = 1;
      
      // Create the javascript that configures the Xinha WYSIWYG editor
      $jscript = "
        <script type=\"text/javascript\">
          var EtoRoot = '<?php echo $etomite_root; ?>';
          _editor_url  = \"manager/media/xinha/\"; // (preferably absolute) URL (including trailing slash) where Xinha is installed
          _editor_lang = \"en\";
          _editor_skin = \"blue-look\";
        </script>
        <script type=\"text/javascript\" src=\"manager/media/xinha/htmlarea.js\"></script>
        <script type=\"text/javascript\">
          xinha_editors = null;
          xinha_init    = null;
          xinha_config  = null;
          xinha_plugins = null;
          xinha_init = xinha_init ? xinha_init : function() {
            //xinha_plugins = xinha_plugins ? xinha_plugins : ['ImageManager'];
            //xinha_plugins = xinha_plugins ? xinha_plugins : [];
            xinha_plugins = xinha_plugins ? xinha_plugins : ['ImageManager'];
            xinha_plugins = xinha_plugins ? xinha_plugins : '';
            if(!HTMLArea.loadPlugins(xinha_plugins, xinha_init)) return;
            xinha_editors = xinha_editors ? xinha_editors : ['text'];
            xinha_config = xinha_config ? xinha_config() : new HTMLArea.Config();
            xinha_config.height = '" . $height . "';
            xinha_config.width = '" . $width . "';
            xinha_editors = HTMLArea.makeEditors(xinha_editors, xinha_config, xinha_plugins);
            HTMLArea.startEditors(xinha_editors);
          }
          window.onload = xinha_init;
        </script>";
      
      // Decide what action should be taken
      if(!isset($_REQUEST['cancel'])) {
        switch($_REQUEST['action']) {
          case "edit_entry":
            $action = "save_entry";
            $actionText = $text['Save_changes'];
            $perm = $etomite->dbQuery("SELECT * FROM " . $tbl . " WHERE blog_id='" . $etomite->documentIdentifier . "' AND entryid='".$_REQUEST['entryid']."'");
            $entry = $etomite->fetchRow($perm);
            break;
          case "add_entry":
            $admin = $etomite->dbQuery("INSERT INTO " . $tbl . " (blog_id,title,text,internalKey,date) VALUES('" . $etomite->documentIdentifier . "','" . addslashes($title) . "','" . addslashes($blogText) . "','" . $_SESSION['internalKey'] . "',NOW() )");
            break;
          case "delete_entry":
            $perm = $etomite->dbQuery("DELETE FROM $tbl WHERE entryid='" . $_REQUEST['entryid'] . "'");
            break;
          case "save_entry":
            $admin = $etomite->dbQuery("UPDATE {$tbl} SET title='" . addslashes($title) . "',text='" . addslashes($blogText) . "', internalKey='" . $_SESSION['internalKey'] ."', date=NOW() WHERE entryid={$_REQUEST['entryid']};");
            break;
          default :
            $action = "add_entry";
            $actionText = $text['Add_entry'];
            break;
        }
      }
        $action = isset($action) ? $action : "add_entry";
        $actionText = isset($actionText) ? $actionText : $text['Add_entry'];
        $title = stripslashes($entry['title']);
        $entryText = stripslashes($entry['text']);
        
        // Format the WYSIWYG entry form
        // START : inputTpl
        $output .= '
        <form action="'.$phpself.'" method="post">
        <input type="hidden" name="action" value="'.$action.'">
        <input type="hidden" name="entryid" value="'.$entry['entryid'].'">
        <div>
          <div>
            '.$text['Title'].'
            <input type="text" name="title" style="width:400px; height:1.5em; padding:2px; border:1px solid #000000;" value="'.$title.'">
            <input type="submit" name="submit" value="'.$actionText.'"><input type="submit" name="cancel" value="'.$text['Cancel'].'">
          </div>
          <textarea name="text" id="text" style="width:'.$width.'; height:'.$height.';">
            '.$entryText.'
          </textarea>
        </div>
        </form>
        <div style="height:10px;"> </div>
        ';
        // END : inputTpl
        $output .= $jscript;
    }
    
    // Get existing entries for this blog from the blog table based on document id
    $entries = $etomite->getIntTableRows("*", $blog, "blog_id='" . $etomite->documentIdentifier . "'","date","DESC");
    
    // Calculate what should be displayed and build the output data
    foreach($entries as $entry) {
      $author = $etomite->getAuthorData($entry['internalKey']);
      $title = htmlentities(stripslashes($entry['title']));
      $entryText = stripslashes($entry['text']);
      if($showAuthor == "true") $authorText = $text['Author'].": <span $author_css>".$author['fullname']."</span> ";
      if($showDate == "true") $dateText = "<span $date_css>".date($dateFormat,strtotime($entry['date']))."</span>";
      if(($access == 1) && ($etomite->checkPermissions("edit_document"))) {
        $editButton = "  <span><a href=\"".$phpself."?action=edit_entry&entryid=".$entry['entryid']."\">".$text['Edit']."</a></span>";
      }
      if(($access == 1) && ($etomite->checkPermissions("delete_document"))) {
        $deleteButton = "<span> : <a href=\"".$phpself."?action=delete_entry&entryid=".$entry['entryid']."\">".$text['Delete']."</a></span> ";
      }
      
      // Format each blog entry for display based on this template code
      // START : outTpl
      $output .= "
        <div $entry_box_css>
          <div $title_css>$title</div>
          <div $text_css>$entryText</div>
          <div style='height:10px;'> </div>
          <div style='text-align:right;'>
            $authorText $dateText  $editButton$deleteButton 
          </div>
        </div>
      ";
      // END : outTpl
    }
    
    // Return the generated HTML code for display
    return $output;
    
      • 19164
      • 1,215 Posts
      Что есть такого в этом сниппете, чего не сможет Ditto?
        DirectResize 0.9 beta. PHPThumb, sets of configurations, configuration, binded to specific path. No backward compatibility. | DirectResize 0.9. PHPThumb, наборы параметров, параметры, привязанные к определенным путям. Без обратной совместимости.

        Unfortunately, DirectResize project is closed. If you want to continue development, PM me for access to project page on Google Code. К сожалению, проект DirectResize закрыт. Если вы желаете продолжить разработки, обращайтесь через ПМ для получения доступа к репозиторию на Google Code.

        [PLUGIN] DirectResize - as Maxigallery but for single images :: Download :: [url=http://modxcms.com/forums/index.php/topic,21490]
        • 26709
        • 4 Posts
        Против Дитто я ничего не имею - сам его юзаю и очень доволен. Но этот снипет отличается от Дитто тем, что позволяет редактировать, добавлять, удалять, скрывать, показывать блоги. А мне как раз и надо это
          • 897
          • 1,620 Posts
          ошибка как выглядит?
            "Und wenn du lange in einen Abgrund blickst, blickt der Abgrund auch in dich hinein."

            Не используйте Revo для "просто сайтов". Используйте Evo

            Who can defeat the Russian bear?
            • 26709
            • 4 Posts
            Вот ошибка :

            « MODx Parse Error »
            MODx encountered the following error while attempting to parse the requested resource:
            « Execution of a query to the database failed - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’id #2etoblog ( `entryid` int(10) unsigned NOT NULL »
            SQL: CREATE TABLE Object id #2etoblog ( `entryid` int(10) unsigned NOT NULL auto_increment, `blog_id` int(10) unsigned NOT NULL default ’0’, `title` text NOT NULL, `text` text NOT NULL, `internalKey` int(10) NOT NULL default ’0’, `date` datetime NOT NULL default ’0000-00-00 00:00:00’, PRIMARY KEY (`entryid`) ) TYPE=MyISAM AUTO_INCREMENT=1 ;
              • 897
              • 1,620 Posts
              http://www.mysql.ru/docs/man/CREATE_TABLE.html

              CREATE TABLE Object id #2etoblog
              видимо должно быть
              CREATE TABLE Object_id_#2etoblog
                "Und wenn du lange in einen Abgrund blickst, blickt der Abgrund auch in dich hinein."

                Не используйте Revo для "просто сайтов". Используйте Evo

                Who can defeat the Russian bear?
                • 897
                • 1,620 Posts
                позырал код сниппета. видимо ошибка где-то здесь


                // Database table to use for storage (shouldn’t need to be changed)
                // entries will be grouped by document id so multiple blogs can use one table
                $blog = isset($blog) ? $blog : "etoblog";
                $tbl = $etomite->db.$blog;
                а именно в том что надо делать eval для $etomite->db.$blog; потому что php тупо склеивает id объекта $etomite->db со строкой ’etoblog’.
                  "Und wenn du lange in einen Abgrund blickst, blickt der Abgrund auch in dich hinein."

                  Не используйте Revo для "просто сайтов". Используйте Evo

                  Who can defeat the Russian bear?
                  • 897
                  • 1,620 Posts
                  http://modxcms.com/dbapi-query.html

                  $table = $modx->getFullTableName("table_name");
                    "Und wenn du lange in einen Abgrund blickst, blickt der Abgrund auch in dich hinein."

                    Не используйте Revo для "просто сайтов". Используйте Evo

                    Who can defeat the Russian bear?
                    • 26709
                    • 4 Posts
                    Спасибо за подсказку. Уже начал понимать, в чем загвоздка. Только я не очень соображаю в тонкостях MySql. Как именно должен выглядеть уже исправленный код?
                      • 897
                      • 1,620 Posts
                      CREATE TABLE <modx table prefix>_<table name> ( 
                      `entryid` int(10) unsigned NOT NULL auto_increment, 
                      `blog_id` int(10) unsigned NOT NULL default '0', 
                      `title` text NOT NULL, 
                      `text` text NOT NULL, 
                      `internalKey` int(10) NOT NULL default '0', 
                      `date` datetime NOT NULL default '0000-00-00 00:00:00', 
                      PRIMARY KEY (`entryid`) 
                      ) TYPE=MyISAM AUTO_INCREMENT=1 ;


                      а код сниппета

                      $blog = isset($blog) ? $blog : "etoblog";
                      $tbl = $modx->getFullTableName($blog);


                      примерно так.
                        "Und wenn du lange in einen Abgrund blickst, blickt der Abgrund auch in dich hinein."

                        Не используйте Revo для "просто сайтов". Используйте Evo

                        Who can defeat the Russian bear?